return {r: -1, g: -1, b: -1, hex: "none"};
}
var red, green, blue,
- rgb = colour.match(/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|rgb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hsb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i);
+ rgb = (colour + "").match(/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|rgb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hsb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i);
if (rgb) {
if (rgb[2]) {
blue = parseInt(rgb[2].substring(5), 16);
var pathcache = {}, pathcount = [];
R.parsePathString = function (pathString) {
if (pathString in pathcache) {
- console.log("cache1:" + pathString);
- console.log("cache2:" + pathcache[pathString]);
return pathcache[pathString];
}
var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
delete pathcache[pathcount.unshift()];
}
pathcount.push(pathString);
- // console.log("data:" + pathString + ":" + data);
pathcache[pathString] = data;
return data;
};
};
},
pathToRelative = function (pathArray) {
- var res = [];
- if (typeof pathArray == "string") {
- pathArray = R.parsePathString(pathArray);
- }
- var x = 0, y = 0, start = 0;
- if (pathArray[0][0] == "M") {
- x = pathArray[0][1];
- y = pathArray[0][2];
- start++;
- res.push(["M", x, y]);
- }
- for (var i = start, ii = pathArray.length; i < ii; i++) {
- var r = res[i] = [],
- pa = pathArray[i];
- if (pa[0] != pa[0].toLowerCase()) {
- r[0] = pa[0].toLowerCase();
- switch (r[0]) {
- case "a":
- r[1] = pa[1];
- r[2] = pa[2];
- r[3] = 0;
- r[4] = pa[4];
- r[5] = pa[5];
- r[6] = +(pa[6] - x).toFixed(3);
- r[7] = +(pa[7] - y).toFixed(3);
+ var res = [];
+ if (typeof pathArray == "string") {
+ pathArray = R.parsePathString(pathArray);
+ }
+ var x = 0, y = 0, start = 0;
+ if (pathArray[0][0] == "M") {
+ x = pathArray[0][1];
+ y = pathArray[0][2];
+ start++;
+ res.push(["M", x, y]);
+ }
+ for (var i = start, ii = pathArray.length; i < ii; i++) {
+ var r = res[i] = [],
+ pa = pathArray[i];
+ if (pa[0] != pa[0].toLowerCase()) {
+ r[0] = pa[0].toLowerCase();
+ switch (r[0]) {
+ case "a":
+ r[1] = pa[1];
+ r[2] = pa[2];
+ r[3] = 0;
+ r[4] = pa[4];
+ r[5] = pa[5];
+ r[6] = +(pa[6] - x).toFixed(3);
+ r[7] = +(pa[7] - y).toFixed(3);
+ break;
+ case "v":
+ r[1] = (pa[1] - y).toFixed(3);
+ break;
+ default:
+ for (var j = 1, jj = pa.length; j < jj; j++) {
+ r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
+ }
+ }
+ } else {
+ res[i] = pa;
+ }
+ switch (res[i][0]) {
+ case "z":
+ break;
+ case "h":
+ x += res[i][res[i].length - 1];
break;
case "v":
- r[1] = +(pa[1] - y).toFixed(3);
+ y += res[i][res[i].length - 1];
break;
default:
- for (var j = 1, jj = pa.length; j < jj; j++) {
- r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
- }
+ x += res[i][res[i].length - 2];
+ y += res[i][res[i].length - 1];
}
- } else {
- res[i] = pa;
- }
- switch (res[i][0]) {
- case "z":
- break;
- case "h":
- x += res[i][res[i].length - 1];
- break;
- case "v":
- y += res[i][res[i].length - 1];
- break;
- default:
- x += res[i][res[i].length - 2];
- y += res[i][res[i].length - 1];
}
- }
- res.toString = pathArray.toString;
- return res;
- },
+ res.toString = pathArray.toString;
+ return res;
+ },
pathToAbsolute = function (pathArray) {
- var res = [];
- if (typeof pathArray == "string") {
- pathArray = R.parsePathString(pathArray);
- }
- var x = 0,
- y = 0,
- start = 0;
- if (pathArray[0][0] == "M") {
- x = +pathArray[0][1];
- y = +pathArray[0][2];
- start++;
- res[0] = ["M", x, y];
- }
- for (var i = start, ii = pathArray.length; i < ii; i++) {
- var r = res[i] = [],
- pa = pathArray[i];
- if (pa[0] != (pa[0] + "").toUpperCase()) {
- r[0] = (pa[0] + "").toUpperCase();
+ var res = [];
+ if (typeof pathArray == "string") {
+ pathArray = R.parsePathString(pathArray);
+ }
+ var x = 0,
+ y = 0,
+ start = 0;
+ if (pathArray[0][0] == "M") {
+ x = +pathArray[0][1];
+ y = +pathArray[0][2];
+ start++;
+ res[0] = ["M", x, y];
+ }
+ for (var i = start, ii = pathArray.length; i < ii; i++) {
+ var r = res[i] = [],
+ pa = pathArray[i];
+ if (pa[0] != (pa[0] + "").toUpperCase()) {
+ r[0] = (pa[0] + "").toUpperCase();
+ switch (r[0]) {
+ case "A":
+ r[1] = pa[1];
+ r[2] = pa[2];
+ r[3] = 0;
+ r[4] = pa[4];
+ r[5] = pa[5];
+ r[6] = +(pa[6] + x).toFixed(3);
+ r[7] = +(pa[7] + y).toFixed(3);
+ break;
+ case "V":
+ r[1] = +pa[1] + y;
+ break;
+ case "H":
+ r[1] = +pa[1] + x;
+ break;
+ default:
+ for (var j = 1, jj = pa.length; j < jj; j++) {
+ r[j] = +pa[j] + ((j % 2) ? x : y);
+ }
+ }
+ } else {
+ r = res[i] = [];
+ for (var k = 0, kk = pa.length; k < kk; k++) {
+ res[i][k] = pa[k];
+ }
+ }
switch (r[0]) {
- case "A":
- r[1] = pa[1];
- r[2] = pa[2];
- r[3] = 0;
- r[4] = pa[4];
- r[5] = pa[5];
- r[6] = +(pa[6] + x).toFixed(3);
- r[7] = +(pa[7] + y).toFixed(3);
+ case "Z":
+ break;
+ case "H":
+ x = r[1];
break;
case "V":
- r[1] = +pa[1] + y;
+ y = r[1];
break;
default:
- for (var j = 1, jj = pa.length; j < jj; j++) {
- r[j] = +pa[j] + ((j % 2) ? x : y);
- }
+ x = res[i][res[i].length - 2];
+ y = res[i][res[i].length - 1];
}
- } else {
- res[i] = pa;
}
- switch (r[0]) {
- case "Z":
- break;
- case "H":
- x = r[1];
- break;
- case "V":
- y = r[1];
- break;
- default:
- x = res[i][res[i].length - 2];
- y = res[i][res[i].length - 1];
- }
- }
- res.toString = pathArray.toString;
- return res;
- },
+ res.toString = pathArray.toString;
+ return res;
+ },
pecache = {}, pecount = [],
pathEqualiser = function (path1, path2) {
- if ((path1 + path2) in pecache) {
- return pecache[path1 + path2];
- }
- var data = [pathToAbsolute(R.parsePathString(path1)), pathToAbsolute(R.parsePathString(path2))],
- attrs = [{x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0}, {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0}],
- processPath = function (path, d) {
- if (!path) {
- return ["U"];
- }
- switch (path[0]) {
- case "M":
- d.X = path[1];
- d.Y = path[2];
- break;
- case "S":
- var nx = d.x + (d.x - (d.bx || d.x));
- var ny = d.y + (d.y - (d.by || d.y));
- path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
- break;
- case "T":
- var nx = d.x + (d.x - (d.bx || d.x));
- var ny = d.y + (d.y - (d.by || d.y));
- path = ["Q", nx, ny, path[1], path[2]];
- break;
- case "H":
- path = ["L", path[1], d.y];
- break;
- case "V":
- path = ["L", d.x, path[1]];
- break;
- case "Z":
- path = ["L", d.X, d.Y];
- break;
- }
- return path;
- },
- edgeCases = function (a, b, i) {
- if (data[a][i][0] == "M" && data[b][i][0] != "M") {
- data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
- attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
- attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
- attrs[a].x = data[a][i][data[a][i].length - 2];
- attrs[a].y = data[a][i][data[a][i].length - 1];
- return true;
- } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
- data[a][i] = ["C", attrs[a].x, attrs[a].y, data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
- } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
- data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
- } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
- var x = data[b][i][data[b][i].length - 2];
- var y = data[b][i][data[b][i].length - 1];
- data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
- data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
- i++;
- attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
- attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
- attrs[b].x = data[b][i][data[b][i].length - 2];
- attrs[b].y = data[b][i][data[b][i].length - 1];
- return true;
- } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
- var x = data[b][i][data[b][i].length - 2];
- var y = data[b][i][data[b][i].length - 1];
- data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
- data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
- i++;
- attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
- attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
- attrs[b].x = data[b][i][data[b][i].length - 2];
- attrs[b].y = data[b][i][data[b][i].length - 1];
- return true;
- } else if (data[a][i][0] == "U") {
- data[a][i][0] = data[b][i][0];
- for (var j = 1, jj = data[b][i].length; j < jj; j++) {
- data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
+ if ((path1 + path2) in pecache) {
+ return pecache[path1 + path2];
+ }
+ var data = [pathToAbsolute(R.parsePathString(path1)), pathToAbsolute(R.parsePathString(path2))],
+ attrs = [{x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0}, {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0}],
+ processPath = function (path, d) {
+ if (!path) {
+ return ["U"];
}
+ switch (path[0]) {
+ case "M":
+ d.X = path[1];
+ d.Y = path[2];
+ break;
+ case "S":
+ var nx = d.x + (d.x - (d.bx || d.x));
+ var ny = d.y + (d.y - (d.by || d.y));
+ path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
+ break;
+ case "T":
+ var nx = d.x + (d.x - (d.bx || d.x));
+ var ny = d.y + (d.y - (d.by || d.y));
+ path = ["Q", nx, ny, path[1], path[2]];
+ break;
+ case "H":
+ path = ["L", path[1], d.y];
+ break;
+ case "V":
+ path = ["L", d.x, path[1]];
+ break;
+ case "Z":
+ path = ["L", d.X, d.Y];
+ break;
+ }
+ return path;
+ },
+ edgeCases = function (a, b, i) {
+ if (data[a][i][0] == "M" && data[b][i][0] != "M") {
+ data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
+ attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
+ attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
+ attrs[a].x = data[a][i][data[a][i].length - 2];
+ attrs[a].y = data[a][i][data[a][i].length - 1];
+ return true;
+ } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
+ data[a][i] = ["C", attrs[a].x, attrs[a].y, data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
+ } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
+ data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
+ } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
+ var x = data[b][i][data[b][i].length - 2];
+ var y = data[b][i][data[b][i].length - 1];
+ data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
+ data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
+ i++;
+ attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
+ attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
+ attrs[b].x = data[b][i][data[b][i].length - 2];
+ attrs[b].y = data[b][i][data[b][i].length - 1];
+ return true;
+ } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
+ var x = data[b][i][data[b][i].length - 2];
+ var y = data[b][i][data[b][i].length - 1];
+ data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
+ data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
+ i++;
+ attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
+ attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
+ attrs[b].x = data[b][i][data[b][i].length - 2];
+ attrs[b].y = data[b][i][data[b][i].length - 1];
+ return true;
+ } else if (data[a][i][0] == "U") {
+ data[a][i][0] = data[b][i][0];
+ for (var j = 1, jj = data[b][i].length; j < jj; j++) {
+ data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
+ }
+ }
+ return false;
+ };
+ for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
+ data[0][i] = processPath(data[0][i], attrs[0]);
+ data[1][i] = processPath(data[1][i], attrs[1]);
+ if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
+ continue;
}
- return false;
- };
- for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
- data[0][i] = processPath(data[0][i], attrs[0]);
- data[1][i] = processPath(data[1][i], attrs[1]);
- if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
- continue;
- }
- attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
- attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
- attrs[0].x = data[0][i][data[0][i].length - 2];
- attrs[0].y = data[0][i][data[0][i].length - 1];
- attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
- attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
- attrs[1].x = data[1][i][data[1][i].length - 2];
- attrs[1].y = data[1][i][data[1][i].length - 1];
- }
- if (pecount.length > 20) {
- delete pecache[pecount.unshift()];
- }
- pecount.push(path1 + path2);
- pecache[path1 + path2] = data;
- return data;
- },
+ attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
+ attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
+ attrs[0].x = data[0][i][data[0][i].length - 2];
+ attrs[0].y = data[0][i][data[0][i].length - 1];
+ attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
+ attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
+ attrs[1].x = data[1][i][data[1][i].length - 2];
+ attrs[1].y = data[1][i][data[1][i].length - 1];
+ }
+ if (pecount.length > 20) {
+ delete pecache[pecount.unshift()];
+ }
+ pecount.push(path1 + path2);
+ pecache[path1 + path2] = data;
+ return data;
+ },
toGradient = function (gradient) {
if (typeof gradient == "string") {
gradient = gradient.split(/\s*\-\s*/);
for (var prop in add) if (add.hasOwnProperty(prop) && !(prop in con)) {
switch (typeof add[prop]) {
case "function":
- con[prop] = con === paper ? add[prop] : function () { return add[prop].apply(paper, arguments); };
+ con[prop] = con === this ? add[prop] : function () { return add[prop].apply(this, arguments); };
break;
case "object":
con[prop] = {};
- plugins(con[prop], add[prop]);
+ plugins.call(this, con[prop], add[prop]);
break;
default:
con[prop] = add[prop];
paper.pathfinder(p, p.attrs.path);
}
if (params) {
- params.fill = params.fill || "none";
+ !params.gradient && (params.fill = params.fill || "none");
params.stroke = params.stroke || "#000";
} else {
params = {fill: "none", stroke: "#000"};
setFillAndStroke(p, params);
return p;
};
- var addGrdientFill = function (o, gradient, SVG) {
+ var addGradientFill = function (o, gradient, SVG) {
gradient = toGradient(gradient);
var el = doc.createElementNS(SVG.svgns, (gradient.type || "linear") + "Gradient");
el.id = "raphael-gradient-" + R.idGenerator++;
stop.setAttribute("stop-opacity", gradient.dots[ii - 1].opacity);
}
o.setAttribute("fill", "url(#" + el.id + ")");
+ o.style.fill = "";
o.style.opacity = 1;
o.style.fillOpacity = 1;
o.setAttribute("opacity", 1);
case "target":
var pn = node.parentNode;
if (pn.tagName.toLowerCase() != "a") {
- var hl = doc.createElementNS(o.svg.svgns, "a");
+ var hl = doc.createElementNS(o.paper.svgns, "a");
pn.insertBefore(hl, node);
hl.appendChild(node);
pn = hl;
}
- pn.setAttributeNS(o.svg.xlink, att, value);
+ pn.setAttributeNS(o.paper.xlink, att, value);
break;
case "path":
if (o.type == "path") {
break;
case "src":
if (o.type == "image") {
- node.setAttributeNS(o.svg.xlink, "href", value);
+ node.setAttributeNS(o.paper.xlink, "href", value);
}
break;
case "stroke-width":
case "fill":
var isURL = value.match(/^url\(([^\)]+)\)$/i);
if (isURL) {
- var el = doc.createElementNS(o.svg.svgns, "pattern");
- var ig = doc.createElementNS(o.svg.svgns, "image");
+ var el = doc.createElementNS(o.paper.svgns, "pattern");
+ var ig = doc.createElementNS(o.paper.svgns, "image");
el.id = "raphael-pattern-" + R.idGenerator++;
el.setAttribute("x", 0);
el.setAttribute("y", 0);
el.setAttribute("patternUnits", "userSpaceOnUse");
ig.setAttribute("x", 0);
ig.setAttribute("y", 0);
- ig.setAttributeNS(o.svg.xlink, "href", isURL[1]);
+ ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
el.appendChild(ig);
var img = doc.createElement("img");
};
doc.body.appendChild(img);
img.src = isURL[1];
- o.svg.defs.appendChild(el);
+ o.paper.defs.appendChild(el);
node.style.fill = "url(#" + el.id + ")";
node.setAttribute("fill", "url(#" + el.id + ")");
o.pattern = el;
node.setAttribute(att, R.getRGB(value).hex);
break;
case "gradient":
- addGrdientFill(node, value, o.svg);
+ addGradientFill(node, value, o.paper);
break;
case "opacity":
case "fill-opacity":
}
var texts = (params.text + "").split("\n");
for (var i = 0, ii = texts.length; i < ii; i++) {
- var tspan = doc.createElementNS(el.svg.svgns, "tspan");
+ var tspan = doc.createElementNS(el.paper.svgns, "tspan");
i && tspan.setAttribute("dy", fontSize * leading);
i && tspan.setAttribute("x", a.x);
tspan.appendChild(doc.createTextNode(texts[i]));
Y = 0;
this[0] = node;
this.node = node;
- this.svg = svg;
+ this.paper = svg;
this.attrs = this.attrs || {};
this.transformations = []; // rotate, translate, scale
this._ = {
throw new Error("SVG container not found.");
}
paper.canvas = doc.createElementNS(paper.svgns, "svg");
- paper.canvas.setAttribute("width", width || 320);
- paper.width = width || 320;
- paper.canvas.setAttribute("height", height || 200);
- paper.height = height || 200;
+ paper.canvas.setAttribute("width", width || 512);
+ paper.width = width || 512;
+ paper.canvas.setAttribute("height", height || 342);
+ paper.height = height || 342;
if (container == 1) {
doc.body.appendChild(paper.canvas);
paper.canvas.style.position = "absolute";
container[prop] = paper[prop];
}
}
- plugins(container, R.fn);
+ plugins.call(container, container, R.fn);
container.clear();
+ container.raphael = R;
return container;
};
paper.remove = function () {
paper.svgns = "http://www.w3.org/2000/svg";
paper.xlink = "http://www.w3.org/1999/xlink";
paper.safari = function () {
- if (navigator.vendor == "Apple Computer, Inc.") {
+ if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) {
var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
- setTimeout(function () {rect.remove();}, 0);
+ setTimeout(function () {rect.remove();});
}
};
}
}
setFillAndStroke(p, params);
if (params.gradient) {
- addGrdientFill(p, params.gradient);
+ addGradientFill(p, params.gradient);
}
VML.canvas.appendChild(g);
return p;
}
return angle;
};
- var addGrdientFill = function (o, gradient) {
+ var addGradientFill = function (o, gradient) {
gradient = toGradient(gradient);
o.attrs = o.attrs || {};
var attrs = o.attrs;
if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
fill.color2 = R.getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
}
- var colors = [];
+ var clrs = [];
for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
if (gradient.dots[i].offset) {
- colors.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
+ clrs.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
}
};
var fillOpacity = typeof gradient.dots[gradient.dots.length - 1].opacity == "undefined" ? (typeof attrs.opacity == "undefined" ? 1 : attrs.opacity) : gradient.dots[gradient.dots.length - 1].opacity;
- if (colors.length) {
- fill.colors.value = colors.join(",");
+ if (clrs.length) {
+ fill.colors.value = clrs.join(",");
fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
} else {
- fill.colors.value = "0% " + fill.color;
+ fill.colors && (fill.colors.value = "0% " + fill.color);
}
fill.opacity = fillOpacity;
if (typeof gradient.angle != "undefined") {
this.Y = 0;
this.attrs = {};
this.Group = group;
- this.vml = vml;
+ this.paper = vml;
this._ = {
tx: 0,
ty: 0,
this._.rt.cy = cy;
this.setBox(null, cx, cy);
this.Group.style.rotation = this._.rt.deg;
+ // gradient fix for rotation. TODO
+ // var fill = (this.shape || this.node).getElementsByTagName("fill");
+ // fill = fill[0] || {};
+ // var b = ((360 - this._.rt.deg) - 270) % 360;
+ // typeof fill.angle != "undefined" && (fill.angle = b);
return this;
};
Element.prototype.setBox = function (params, cx, cy) {
if (!this.attrs.path) {
x = 0;
y = 0;
- w = this.vml.width;
- h = this.vml.height;
+ w = this.paper.width;
+ h = this.paper.height;
} else {
var dim = pathDimensions(this.attrs.path),
x = dim.x;
default:
x = 0;
y = 0;
- w = this.vml.width;
- h = this.vml.height;
+ w = this.paper.width;
+ h = this.paper.height;
break;
}
cx = (cx == null) ? x + w / 2 : cx;
cy = (cy == null) ? y + h / 2 : cy;
- var left = cx - this.vml.width / 2,
- top = cy - this.vml.height / 2;
+ var left = cx - this.paper.width / 2,
+ top = cy - this.paper.height / 2;
if (this.type == "path" || this.type == "text") {
(gs.left != left + "px") && (gs.left = left + "px");
(gs.top != top + "px") && (gs.top = top + "px");
this.Y = y;
this.W = w;
this.H = h;
- (gs.width != this.vml.width + "px") && (gs.width = this.vml.width + "px");
- (gs.height != this.vml.height + "px") && (gs.height = this.vml.height + "px");
+ (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
+ (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
(os.left != x - left + "px") && (os.left = x - left + "px");
(os.top != y - top + "px") && (os.top = y - top + "px");
(os.width != w + "px") && (os.width = w + "px");
var arcsize = (+params.r || 0) / (Math.min(w, h));
if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
// We should replace element with the new one
- var o = createNode("roundrect");
+ var o = createNode(arcsize ? "roundrect" : "rect");
o.arcsize = arcsize;
this.Group.appendChild(o);
this.node.parentNode.removeChild(this.node);
}
if (params) {
if (params.gradient) {
- addGrdientFill(this, params.gradient);
+ addGradientFill(this, params.gradient);
}
if (params.text && this.type == "text") {
this.node.string = params.text;
};
var theRect = function (vml, x, y, w, h, r) {
var g = createNode("group"),
- o = createNode("roundrect"),
+ o = createNode(r ? "roundrect" : "rect"),
arcsize = (+r || 0) / (Math.min(w, h));
o.arcsize = arcsize;
g.appendChild(o);
doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
try {
if (!doc.namespaces.rvml) {
- doc.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
+ doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
}
var createNode = function (tagName) {
return doc.createElement('<rvml:' + tagName + ' class="rvml">');
cs = c.style, rs = r.style;
paper.width = width;
paper.height = height;
- width = width || "320px";
- height = height || "200px";
+ width = width || "512px";
+ height = height || "342px";
cs.clip = "rect(0 " + width + "px " + height + "px 0)";
cs.top = "-2px";
cs.left = "-2px";
for (var prop in paper) {
container[prop] = paper[prop];
}
- plugins(container, R.fn);
+ plugins.call(container, container, R.fn);
container.clear = function () {
var todel = [];
for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
r.removeChild(todel[i]);
}
};
+ container.raphael = R;
return container;
};
paper.remove = function () {
} else {
skip = false;
}
- if (this.svg && p[0].toUpperCase() == "A") {
- p[path[i].length - 2] *= x;
- p[path[i].length - 1] *= y;
- p[1] *= x;
- p[2] *= y;
+ if (R.svg && p[0].toUpperCase() == "A") {
+ p[path[i].length - 2] *= x / this._.sx;
+ p[path[i].length - 1] *= y / this._.sy;
+ p[1] *= x / this._.sx;
+ p[2] *= y / this._.sy;
+ p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
} else {
for (var j = 1, jj = p.length; j < jj; j++) {
p[j] *= (j % 2) ? x / this._.sx : y / this._.sy;
s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
}
}
+ a.scale = [x, y, cx, cy].join(" ");
+ this._.sx = x;
+ this._.sy = y;
}
- this._.sx = x;
- this._.sy = y;
return this;
};
Element.prototype.animate = function (params, ms, callback) {
for (var attr in params) {
if (attr in availableAnimAttrs) {
from[attr] = this.attr(attr);
- if (typeof from[attr] == "undefined") {
- from[attr] = availableAttrs[attr];
- }
+ (typeof from[attr] == "undefined") && (from[attr] = availableAttrs[attr]);
to[attr] = params[attr];
switch (availableAnimAttrs[attr]) {
case "number":
}
break;
case "csv":
- var values = params[attr].toString().split(separator),
- from2 = from[attr].toString().split(separator);
- if (attr == "translation") {
- from[attr] = [0, 0];
- diff[attr] = [values[0] / ms, values[1] / ms];
- } else if (attr == "rotation") {
- from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
- diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
- } else {
- from[attr] = (from[attr] + "").split(separator);
- diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][0]) / ms];
+ var values = (params[attr] + "").split(separator),
+ from2 = (from[attr] + "").split(separator);
+ switch (attr) {
+ case "translation":
+ from[attr] = [0, 0];
+ diff[attr] = [values[0] / ms, values[1] / ms];
+ break;
+ case "rotation":
+ from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
+ diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
+ break;
+ case "scale":
+ params[attr] = values;
+ from[attr] = (from[attr] + "").split(separator);
+ diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
}
to[attr] = values;
}
var start = +new Date,
prev = 0,
that = this;
- (function () {
- var time = +new Date - start,
+ (function tick() {
+ var time = new Date - start,
set = {},
now;
if (time < ms) {
now = now.join(" ");
break;
case "csv":
- if (attr == "translation") {
- var x = diff[attr][0] * (time - prev),
- y = diff[attr][1] * (time - prev);
- t.x += x;
- t.y += y;
- now = [x, y].join(" ");
- } else if (attr == "rotation") {
- now = +from[attr][0] + time * diff[attr][0];
- from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
- } else {
- now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1]].join(" ");
+ switch (attr) {
+ case "translation":
+ var x = diff[attr][0] * (time - prev),
+ y = diff[attr][1] * (time - prev);
+ t.x += x;
+ t.y += y;
+ now = [x, y].join(" ");
+ break;
+ case "rotation":
+ now = +from[attr][0] + time * diff[attr][0];
+ from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
+ break;
+ case "scale":
+ now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1], (2 in params[attr] ? params[attr][2] : ""), (3 in params[attr] ? params[attr][3] : "")].join(" ");
}
break;
}
}
}
that.attr(set);
- that.animation_in_progress = setTimeout(arguments.callee, 0);
+ that.animation_in_progress = setTimeout(tick);
paper.safari();
} else {
(t.x || t.y) && that.translate(-t.x, -t.y);
R.ninja = function () {
var r = window.Raphael;
- delete window.Raphael;
if (oldRaphael.was) {
window.Raphael = oldRaphael.is;
+ } else {
+ try {
+ delete window.Raphael;
+ } catch (e) {
+ window.Raphael = void(0);
+ }
}
return r;
};