Some extensions (filters, dash, shadow blur)
!function() {
var NS = 'http://www.w3.org/2000/svg', XLINK = 'http://www.w3.org/1999/xlink', UID = 0, createElement = function(tag){
return document.createElementNS(NS, tag);
};
ART.SVG.Base.implement({
dash: function(dash) {
if (dash) {
this.dashed = true;
this.element.setAttribute('stroke-dasharray', dash);
} else if (this.dashed) {
this.dashed = false;
this.element.removeAttribute('stroke-dasharray')
}
},
inject: function(container){
this.eject();
if (container instanceof ART.SVG.Group) container.children.push(this);
this.parent.apply(this, arguments);
this.container = container.defs ? container : container.container;
this._injectBrush('fill');
this._injectBrush('stroke');
this._injectFilter('blur');
return this;
},
strokeLinear: function(stops, angle){
var gradient = this._createGradient('stroke', 'linear', stops);
angle = ((angle == null) ? 270 : angle) * Math.PI / 180;
var x = Math.cos(angle), y = -Math.sin(angle),
l = (Math.abs(x) + Math.abs(y)) / 2;
x *= l; y *= l;
gradient.setAttribute('x1', 0.5 - x);
gradient.setAttribute('x2', 0.5 + x);
gradient.setAttribute('y1', 0.5 - y);
gradient.setAttribute('y2', 0.5 + y);
return this;
},
_writeTransform: function(){
if (Object.equals(this.transformed, this.transform)) return;
this.transformed = $unlink(this.transform);
var transforms = [];
for (var transform in this.transform) transforms.push(transform + '(' + this.transform[transform].join(',') + ')');
this.element.setAttribute('transform', transforms.join(' '));
},
blur: function(radius){
if (radius == null) radius = 4;
if (radius == this.blurred) return;
this.blurred = radius;
var filter = this._createFilter();
var blur = createElement('feGaussianBlur');
blur.setAttribute('stdDeviation', radius * 0.25);
blur.setAttribute('result', 'blur');
filter.appendChild(blur);
in=SourceGraphic stdDeviation=“4” result=“blur”
return this;
},
unblur: function() {
delete this.blurred;
this._ejectFilter();
},
_injectFilter: function(type){
if (!this.container) return;
var filter = this.filter;
if (filter) this.container.defs.appendChild(filter);
},
_ejectFilter: function(type){
if (!this.container) return;
var filter = this.filter;
delete this.filter;
if (filter) this.container.defs.removeChild(filter);
},
_createFilter: function(){
this._ejectFilter();
var filter = this.filter = createElement('filter');
var id = 'filter-e' + this.uid;
filter.setAttribute('id', id);
this._injectFilter();
this.element.setAttribute('filter', 'url(#' + id + ')');
return filter;
},
});
}();