source: [view]
if(!fill){
// don't fill
this.fillStyle = null;
this.rawNode.setAttribute("fill", "none");
this.rawNode.setAttribute("fill-opacity", 0);
return this;
}
var f;
// FIXME: slightly magical. We're using the outer scope's "f", but setting it later
var setter = function(x){
// we assume that we're executing in the scope of the node to mutate
this.setAttribute(x, f[x].toFixed(8));
};
if(typeof(fill) == "object" && "type" in fill){
// gradient
switch(fill.type){
case "linear":
f = g.makeParameters(g.defaultLinearGradient, fill);
var gradient = this._setFillObject(f, "linearGradient");
d.forEach(["x1", "y1", "x2", "y2"], setter, gradient);
break;
case "radial":
f = g.makeParameters(g.defaultRadialGradient, fill);
var gradient = this._setFillObject(f, "radialGradient");
d.forEach(["cx", "cy", "r"], setter, gradient);
break;
case "pattern":
f = g.makeParameters(g.defaultPattern, fill);
var pattern = this._setFillObject(f, "pattern");
d.forEach(["x", "y", "width", "height"], setter, pattern);
break;
}
this.fillStyle = f;
return this;
}
// color object
var f = g.normalizeColor(fill);
this.fillStyle = f;
this.rawNode.setAttribute("fill", f.toCss());
this.rawNode.setAttribute("fill-opacity", f.a);
this.rawNode.setAttribute("fill-rule", "evenodd");
return this; // self