Skip to content

Instantly share code, notes, and snippets.

@nraynaud
Created April 18, 2014 12:20
Show Gist options
  • Save nraynaud/11041186 to your computer and use it in GitHub Desktop.
Save nraynaud/11041186 to your computer and use it in GitHub Desktop.
markers for svg.js
"use strict";
define(['libs/svg'], (function () {
SVG.Marker = SVG.invent({
create: 'marker',
inherit: SVG.Container,
extend: {
getRef: function () {
return 'url(#' + this.attr('id') + ')'
},
update: function (block) {
this.clear();
if (typeof block == 'function')
block.call(this, this)
return this
},
toString: function () {
return this.getRef()
}
},
construct: {
marker: function (refX, refY, width, height, block) {
return this.defs().marker(refX, refY, width, height, block)
}
}
});
SVG.extend(SVG.Defs, {
// Define gradient
marker: function (refX, refY, width, height, block) {
return this.put(new SVG.Marker).update(block).attr({
refX: refX, refY: refY, markerWidth: width, markerHeight: height, orient: 'auto'
})
}
});
SVG.extend(SVG.Container, {
// Define filter on defs
filter: function (block) {
return this.defs().filter(block)
}
});
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment