2 * Raphael 0.7.3 - JavaScript Vector Library
4 * Copyright (c) 2008 – 2009 Dmitry Baranovskiy (http://raphaeljs.com)
5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
9 var Raphael = (function () {
10 var separator = /[, ]+/,
15 return create.apply(R, arguments);
18 availableAttrs = {cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0},
19 availableAnimAttrs = {cx: "number", cy: "number", fill: "colour", "fill-opacity": "number", "font-size": "number", height: "number", opacity: "number", path: "path", r: "number", rotation: "csv", rx: "number", ry: "number", scale: "csv", stroke: "colour", "stroke-opacity": "number", "stroke-width": "number", translation: "csv", width: "number", x: "number", y: "number"},
20 events = ["click", "dblclick", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup"];
22 R.type = (window.SVGAngle ? "SVG" : "VML");
23 R.svg = !(R.vml = R.type == "VML");
26 R.toString = function () {
27 return "Your browser " + (this.vml ? "doesn't ": "") + "support" + (this.svg ? "s": "") +
28 " SVG.\nYou are running " + unescape("Rapha%EBl%20") + this.version;
30 R.setWindow = function (newwin) {
35 R.hsb2rgb = function (hue, saturation, brightness) {
36 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
44 if (brightness == 0) {
45 return {r: 0, g: 0, b: 0, hex: "#000"};
47 if (hue > 1 || saturation > 1 || brightness > 1) {
52 var i = Math.floor(hue * 6),
54 p = brightness * (1 - saturation),
55 q = brightness * (1 - (saturation * f)),
56 t = brightness * (1 - (saturation * (1 - f)));
57 red = [brightness, q, p, p, t, brightness, brightness][i];
58 green = [t, brightness, brightness, q, p, p, t][i];
59 blue = [p, p, t, brightness, brightness, q, p][i];
63 var rgb = {r: red, g: green, b: blue};
64 var r = Math.round(red).toString(16);
68 var g = Math.round(green).toString(16);
72 var b = Math.round(blue).toString(16);
76 rgb.hex = "#" + r + g + b;
79 R.rgb2hsb = function (red, green, blue) {
80 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
85 if (typeof red == "string") {
86 var clr = getRGB(red);
91 if (red > 1 || green > 1 || blue > 1) {
96 var max = Math.max(red, green, blue),
97 min = Math.min(red, green, blue),
102 return {h: 0, s: 0, b: max};
104 var delta = (max - min);
105 saturation = delta / max;
107 hue = (green - blue) / delta;
108 } else if (green == max) {
109 hue = 2 + ((blue - red) / delta);
111 hue = 4 + ((red - green) / delta);
121 return {h: hue, s: saturation, b: brightness};
123 var getRGB = function (colour) {
124 var htmlcolors = {aliceblue: "#f0f8ff", amethyst: "#96c", antiquewhite: "#faebd7", aqua: "#0ff", aquamarine: "#7fffd4", azure: "#f0ffff", beige: "#f5f5dc", bisque: "#ffe4c4", black: "#000", blanchedalmond: "#ffebcd", blue: "#00f", blueviolet: "#8a2be2", brown: "#a52a2a", burlywood: "#deb887", cadetblue: "#5f9ea0", chartreuse: "#7fff00", chocolate: "#d2691e", coral: "#ff7f50", cornflowerblue: "#6495ed", cornsilk: "#fff8dc", crimson: "#dc143c", cyan: "#0ff", darkblue: "#00008b", darkcyan: "#008b8b", darkgoldenrod: "#b8860b", darkgray: "#a9a9a9", darkgreen: "#006400", darkkhaki: "#bdb76b", darkmagenta: "#8b008b", darkolivegreen: "#556b2f", darkorange: "#ff8c00", darkorchid: "#9932cc", darkred: "#8b0000", darksalmon: "#e9967a", darkseagreen: "#8fbc8f", darkslateblue: "#483d8b", darkslategray: "#2f4f4f", darkturquoise: "#00ced1", darkviolet: "#9400d3", deeppink: "#ff1493", deepskyblue: "#00bfff", dimgray: "#696969", dodgerblue: "#1e90ff", firebrick: "#b22222", floralwhite: "#fffaf0", forestgreen: "#228b22", fuchsia: "#f0f", gainsboro: "#dcdcdc", ghostwhite: "#f8f8ff", gold: "#ffd700", goldenrod: "#daa520", gray: "#808080", green: "#008000", greenyellow: "#adff2f", honeydew: "#f0fff0", hotpink: "#ff69b4", indianred: "#cd5c5c", indigo: "#4b0082", ivory: "#fffff0", khaki: "#f0e68c", lavender: "#e6e6fa", lavenderblush: "#fff0f5", lawngreen: "#7cfc00", lemonchiffon: "#fffacd", lightblue: "#add8e6", lightcoral: "#f08080", lightcyan: "#e0ffff", lightgoldenrodyellow: "#fafad2", lightgreen: "#90ee90", lightgrey: "#d3d3d3", lightpink: "#ffb6c1", lightsalmon: "#ffa07a", lightsalmon: "#ffa07a", lightseagreen: "#20b2aa", lightskyblue: "#87cefa", lightslategray: "#789", lightsteelblue: "#b0c4de", lightyellow: "#ffffe0", lime: "#0f0", limegreen: "#32cd32", linen: "#faf0e6", magenta: "#f0f", maroon: "#800000", mediumaquamarine: "#66cdaa", mediumblue: "#0000cd", mediumorchid: "#ba55d3", mediumpurple: "#9370db", mediumseagreen: "#3cb371", mediumslateblue: "#7b68ee", mediumslateblue: "#7b68ee", mediumspringgreen: "#00fa9a", mediumturquoise: "#48d1cc", mediumvioletred: "#c71585", midnightblue: "#191970", mintcream: "#f5fffa", mistyrose: "#ffe4e1", moccasin: "#ffe4b5", navajowhite: "#ffdead", navy: "#000080", oldlace: "#fdf5e6", olive: "#808000", olivedrab: "#6b8e23", orange: "#ffa500", orangered: "#ff4500", orchid: "#da70d6", palegoldenrod: "#eee8aa", palegreen: "#98fb98", paleturquoise: "#afeeee", palevioletred: "#db7093", papayawhip: "#ffefd5", peachpuff: "#ffdab9", peru: "#cd853f", pink: "#ffc0cb", plum: "#dda0dd", powderblue: "#b0e0e6", purple: "#800080", red: "#f00", rosybrown: "#bc8f8f", royalblue: "#4169e1", saddlebrown: "#8b4513", salmon: "#fa8072", sandybrown: "#f4a460", seagreen: "#2e8b57", seashell: "#fff5ee", sienna: "#a0522d", silver: "#c0c0c0", skyblue: "#87ceeb", slateblue: "#6a5acd", slategray: "#708090", snow: "#fffafa", springgreen: "#00ff7f", steelblue: "#4682b4", tan: "#d2b48c", teal: "#008080", thistle: "#d8bfd8", tomato: "#ff6347", turquoise: "#40e0d0", violet: "#ee82ee", wheat: "#f5deb3", white: "#fff", whitesmoke: "#f5f5f5", yellow: "#ff0", yellowgreen: "#9acd32"};
125 if (colour.toString().toLowerCase() in htmlcolors) {
126 colour = htmlcolors[colour.toString().toLowerCase()];
129 return {r: 0, g: 0, b: 0, hex: "#000"};
131 if (colour == "none") {
132 return {r: -1, g: -1, b: -1, hex: "none"};
134 var red, green, blue,
135 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);
138 blue = parseInt(rgb[2].substring(5), 16);
139 green = parseInt(rgb[2].substring(3, 5), 16);
140 red = parseInt(rgb[2].substring(1, 3), 16);
143 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
144 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
145 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
148 rgb = rgb[4].split(/\s*,\s*/);
149 red = parseFloat(rgb[0], 10);
150 green = parseFloat(rgb[1], 10);
151 blue = parseFloat(rgb[2], 10);
154 rgb = rgb[5].split(/\s*,\s*/);
155 red = parseFloat(rgb[0], 10) * 2.55;
156 green = parseFloat(rgb[1], 10) * 2.55;
157 blue = parseFloat(rgb[2], 10) * 2.55;
160 rgb = rgb[6].split(/\s*,\s*/);
161 red = parseFloat(rgb[0], 10);
162 green = parseFloat(rgb[1], 10);
163 blue = parseFloat(rgb[2], 10);
164 return Raphael.hsb2rgb(red, green, blue);
167 rgb = rgb[7].split(/\s*,\s*/);
168 red = parseFloat(rgb[0], 10) * 2.55;
169 green = parseFloat(rgb[1], 10) * 2.55;
170 blue = parseFloat(rgb[2], 10) * 2.55;
171 return Raphael.hsb2rgb(red, green, blue);
173 var rgb = {r: red, g: green, b: blue};
174 var r = Math.round(red).toString(16);
175 (r.length == 1) && (r = "0" + r);
176 var g = Math.round(green).toString(16);
177 (g.length == 1) && (g = "0" + g);
178 var b = Math.round(blue).toString(16);
179 (b.length == 1) && (b = "0" + b);
180 rgb.hex = "#" + r + g + b;
183 return {r: -1, g: -1, b: -1, hex: "none"};
186 R.getColor = function (value) {
187 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
188 var rgb = Raphael.hsb2rgb(start.h, start.s, start.b);
194 arguments.callee.start = {h: 0, s: 1, b: start.b};
199 R.getColor.reset = function () {
203 R.parsePathString = function (pathString) {
204 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
206 toString = function () {
208 for (var i = 0, ii = this.length; i < ii; i++) {
209 res += this[i][0] + this[i].join(",").substring(2);
213 if (pathString.toString.toString() == toString.toString()) {
216 pathString.replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, function (a, b, c) {
217 var params = [], name = b.toLowerCase();
218 c.replace(/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig, function (a, b) {
219 b && params.push(+b);
221 while (params.length >= paramCounts[name]) {
222 data.push([b].concat(params.splice(0, paramCounts[name])));
223 if (!paramCounts[name]) {
228 data.toString = toString;
231 var pathDimensions = function (path) {
232 var pathArray = path;
233 if (typeof path == "string") {
234 pathArray = Raphael.parsePathString(path);
236 pathArray = pathToAbsolute(pathArray);
237 var x = [], y = [], length = 0;
238 for (var i = 0, ii = pathArray.length; i < ii; i++) {
239 switch (pathArray[i][0]) {
243 x.push(pathArray[i][pathArray[i].length - 2]);
244 y.push(pathArray[i][pathArray[i].length - 1]);
247 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
249 x.push(pathArray[i][j]);
251 y.push(pathArray[i][j]);
256 var minx = Math.min.apply(Math, x),
257 miny = Math.min.apply(Math, y);
261 width: Math.max.apply(Math, x) - minx,
262 height: Math.max.apply(Math, y) - miny,
267 var pathToRelative = function (pathArray) {
269 if (typeof pathArray == "string") {
270 pathArray = R.parsePathString(pathArray);
272 var x = 0, y = 0, start = 0;
273 if (pathArray[0][0] == "M") {
277 res.push(pathArray[0]);
279 for (var i = start, ii = pathArray.length; i < ii; i++) {
281 if (pathArray[i][0] != pathArray[i][0].toLowerCase()) {
282 res[i][0] = pathArray[i][0].toLowerCase();
285 res[i][1] = pathArray[i][1];
286 res[i][2] = pathArray[i][2];
288 res[i][4] = pathArray[i][4];
289 res[i][5] = pathArray[i][5];
290 res[i][6] = +(pathArray[i][6] - x).toFixed(3);
291 res[i][7] = +(pathArray[i][7] - y).toFixed(3);
294 res[i][1] = +(pathArray[i][1] - y).toFixed(3);
297 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
298 res[i][j] = +(pathArray[i][j] - ((j % 2) ? x : y)).toFixed(3);
302 res[i] = pathArray[i];
308 x += res[i][res[i].length - 1];
311 y += res[i][res[i].length - 1];
314 x += res[i][res[i].length - 2];
315 y += res[i][res[i].length - 1];
318 res.toString = pathArray.toString;
321 var pathToAbsolute = function (pathArray) {
323 if (typeof pathArray == "string") {
324 pathArray = R.parsePathString(pathArray);
329 if (pathArray[0][0] == "M") {
330 x = +pathArray[0][1];
331 y = +pathArray[0][2];
333 res[0] = pathArray[0];
335 for (var i = start, ii = pathArray.length; i < ii; i++) {
337 if (pathArray[i][0] != (pathArray[i][0] + "").toUpperCase()) {
338 res[i][0] = (pathArray[i][0] + "").toUpperCase();
341 res[i][1] = pathArray[i][1];
342 res[i][2] = pathArray[i][2];
344 res[i][4] = pathArray[i][4];
345 res[i][5] = pathArray[i][5];
346 res[i][6] = +(pathArray[i][6] + x).toFixed(3);
347 res[i][7] = +(pathArray[i][7] + y).toFixed(3);
350 res[i][1] = +pathArray[i][1] + y;
353 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
354 res[i][j] = +pathArray[i][j] + ((j % 2) ? x : y);
358 res[i] = pathArray[i];
370 x = res[i][res[i].length - 2];
371 y = res[i][res[i].length - 1];
374 res.toString = pathArray.toString;
377 var pathEqualiser = function (path1, path2) {
378 var data = [pathToAbsolute(Raphael.parsePathString(path1)), pathToAbsolute(Raphael.parsePathString(path2))],
379 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}],
380 processPath = function (path, d) {
390 var nx = d.x + (d.x - (d.bx || d.x));
391 var ny = d.y + (d.y - (d.by || d.y));
392 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
395 var nx = d.x + (d.x - (d.bx || d.x));
396 var ny = d.y + (d.y - (d.by || d.y));
397 path = ["Q", nx, ny, path[1], path[2]];
400 path = ["L", path[1], d.y];
403 path = ["L", d.x, path[1]];
406 path = ["L", d.X, d.Y];
411 edgeCases = function (a, b, i) {
412 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
413 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
414 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
415 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
416 attrs[a].x = data[a][i][data[a][i].length - 2];
417 attrs[a].y = data[a][i][data[a][i].length - 1];
419 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
420 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]];
421 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
422 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
423 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
424 var x = data[b][i][data[b][i].length - 2];
425 var y = data[b][i][data[b][i].length - 1];
426 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
427 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
429 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
430 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
431 attrs[b].x = data[b][i][data[b][i].length - 2];
432 attrs[b].y = data[b][i][data[b][i].length - 1];
434 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
435 var x = data[b][i][data[b][i].length - 2];
436 var y = data[b][i][data[b][i].length - 1];
437 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
438 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
440 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
441 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
442 attrs[b].x = data[b][i][data[b][i].length - 2];
443 attrs[b].y = data[b][i][data[b][i].length - 1];
445 } else if (data[a][i][0] == "U") {
446 data[a][i][0] = data[b][i][0];
447 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
448 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
453 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
454 data[0][i] = processPath(data[0][i], attrs[0]);
455 data[1][i] = processPath(data[1][i], attrs[1]);
456 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
459 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
460 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
461 attrs[0].x = data[0][i][data[0][i].length - 2];
462 attrs[0].y = data[0][i][data[0][i].length - 1];
463 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
464 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
465 attrs[1].x = data[1][i][data[1][i].length - 2];
466 attrs[1].y = data[1][i][data[1][i].length - 1];
470 var toGradient = function (gradient) {
471 if (typeof gradient == "string") {
472 gradient = gradient.split(/\s*\-\s*/);
473 var angle = gradient.shift();
474 if (angle.toLowerCase() == "v") {
476 } else if (angle.toLowerCase() == "h") {
479 angle = parseFloat(angle, 10);
482 var grobj = {angle: angle, type: "linear", dots: [], vector: [0, 0, Math.cos(angle * Math.PI / 180).toFixed(3), Math.sin(angle * Math.PI / 180).toFixed(3)]};
483 var max = 1 / (Math.max(Math.abs(grobj.vector[2]), Math.abs(grobj.vector[3])) || 1);
484 grobj.vector[2] *= max;
485 grobj.vector[3] *= max;
486 if (grobj.vector[2] < 0) {
487 grobj.vector[0] = -grobj.vector[2];
490 if (grobj.vector[3] < 0) {
491 grobj.vector[1] = -grobj.vector[3];
494 grobj.vector[0] = grobj.vector[0].toFixed(3);
495 grobj.vector[1] = grobj.vector[1].toFixed(3);
496 grobj.vector[2] = grobj.vector[2].toFixed(3);
497 grobj.vector[3] = grobj.vector[3].toFixed(3);
498 for (var i = 0, ii = gradient.length; i < ii; i++) {
500 var par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
501 dot.color = getRGB(par[1]).hex;
502 par[2] && (dot.offset = par[2] + "%");
503 grobj.dots.push(dot);
505 for (var i = 1, ii = grobj.dots.length - 1; i < ii; i++) {
506 if (!grobj.dots[i].offset) {
507 var start = parseFloat(grobj.dots[i - 1].offset || 0, 10),
509 for (var j = i + 1; j < ii; j++) {
510 if (grobj.dots[j].offset) {
511 end = grobj.dots[j].offset;
519 end = parseFloat(end, 10);
520 var d = (end - start) / (j - i + 1);
523 grobj.dots[i].offset = start + "%";
532 var getContainer = function () {
533 var container, x, y, width, height;
534 if (typeof arguments[0] == "string" || typeof arguments[0] == "object") {
535 if (typeof arguments[0] == "string") {
536 container = doc.getElementById(arguments[0]);
538 container = arguments[0];
540 if (container.tagName) {
541 if (arguments[1] == null) {
543 container: container,
544 width: container.style.pixelWidth || container.offsetWidth,
545 height: container.style.pixelHeight || container.offsetHeight
548 return {container: container, width: arguments[1], height: arguments[2]};
551 } else if (typeof arguments[0] == "number" && arguments.length > 3) {
552 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
555 var plugins = function (con, scope, add) {
556 for (var prop in add) if (!(prop in con)) {
557 switch (typeof add[prop]) {
559 con[prop] = con === scope ? add[prop] : function () { add[prop].apply(scope, arguments); };
563 plugins(con[prop], con, add[prop]);
566 con[prop] = add[prop];
574 var thePath = function (params, pathString, SVG) {
575 var el = doc.createElementNS(SVG.svgns, "path");
576 el.setAttribute("fill", "none");
578 SVG.canvas.appendChild(el);
580 var p = new Element(el, SVG);
583 p.last = {x: 0, y: 0, bx: 0, by: 0};
584 p.absolutely = function () {
585 this.isAbsolute = true;
588 p.relatively = function () {
589 this.isAbsolute = false;
592 p.moveTo = function (x, y) {
593 var d = this.isAbsolute?"M":"m";
594 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
595 var oldD = this[0].getAttribute("d") || "";
596 (oldD == "M0,0") && (oldD = "");
597 this[0].setAttribute("d", oldD + d);
598 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
599 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
600 this.attrs.path = oldD + d;
603 p.lineTo = function (x, y) {
604 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
605 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
606 var d = this.isAbsolute?"L":"l";
607 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
608 var oldD = this[0].getAttribute("d") || "";
609 this[0].setAttribute("d", oldD + d);
610 this.attrs.path = oldD + d;
613 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
614 var d = this.isAbsolute ? "A" : "a";
615 d += [parseFloat(rx, 10).toFixed(3), parseFloat(ry, 10).toFixed(3), 0, large_arc_flag, sweep_flag, parseFloat(x, 10).toFixed(3), parseFloat(y, 10).toFixed(3)].join(" ");
616 var oldD = this[0].getAttribute("d") || "";
617 this[0].setAttribute("d", oldD + d);
618 this.last.x = parseFloat(x, 10);
619 this.last.y = parseFloat(y, 10);
620 this.attrs.path = oldD + d;
623 p.cplineTo = function (x1, y1, w1) {
625 return this.lineTo(x1, y1);
628 var x = parseFloat(x1, 10);
629 var y = parseFloat(y1, 10);
630 var w = parseFloat(w1, 10);
631 var d = this.isAbsolute?"C":"c";
632 var attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
633 for (var i = 0, ii = attr.length; i < ii; i++) {
634 d += attr[i].toFixed(3) + " ";
636 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
637 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
638 this.last.bx = attr[2];
639 this.last.by = attr[3];
640 var oldD = this[0].getAttribute("d") || "";
641 this[0].setAttribute("d", oldD + d);
642 this.attrs.path = oldD + d;
646 p.curveTo = function () {
648 command = [0, 1, 2, 3, "s", 5, "c"];
650 var d = command[arguments.length];
651 if (this.isAbsolute) {
654 for (var i = 0, ii = arguments.length; i < ii; i++) {
655 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
657 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
658 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
659 this.last.bx = parseFloat(arguments[arguments.length - 4], 10);
660 this.last.by = parseFloat(arguments[arguments.length - 3], 10);
661 var oldD = this.node.getAttribute("d") || "";
662 this.node.setAttribute("d", oldD + d);
663 this.attrs.path = oldD + d;
666 p.qcurveTo = function () {
668 command = [0, 1, "t", 3, "q"];
670 var d = command[arguments.length];
671 if (this.isAbsolute) {
674 for (var i = 0, ii = arguments.length; i < ii; i++) {
675 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
677 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
678 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
679 if (arguments.length != 2) {
680 this.last.qx = parseFloat(arguments[arguments.length - 4], 10);
681 this.last.qy = parseFloat(arguments[arguments.length - 3], 10);
683 var oldD = this.node.getAttribute("d") || "";
684 this.node.setAttribute("d", oldD + d);
685 this.attrs.path = oldD + d;
688 p.addRoundedCorner = function (r, dir) {
689 var R = .5522 * r, rollback = this.isAbsolute, o = this;
692 rollback = function () {
696 rollback = function () {};
702 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
705 o.curveTo(-R, 0, -r, r - R, -r, r);
712 o.curveTo(R, 0, r, -(r - R), r, -r);
715 o.curveTo(R, 0, r, r - R, r, r);
722 o.curveTo(0, -R, -(R - r), -r, r, -r);
725 o.curveTo(0, -R, R - r, -r, -r, -r);
732 o.curveTo(0, R, -(R - r), r, r, r);
735 o.curveTo(0, R, R - r, r, -r, r);
740 actions[dir[0]]()[dir[1]]();
744 p.andClose = function () {
745 var oldD = this[0].getAttribute("d") || "";
746 this[0].setAttribute("d", oldD + "Z ");
747 this.attrs.path = oldD + "Z ";
751 p.attrs.path = "" + pathString;
753 paper.pathfinder(p, p.attrs.path);
756 setFillAndStroke(p, params);
760 var addGrdientFill = function (o, gradient, SVG) {
761 gradient = toGradient(gradient);
762 var el = doc.createElementNS(SVG.svgns, (gradient.type || "linear") + "Gradient");
763 el.id = "raphael-gradient-" + Raphael.idGenerator++;
764 if (gradient.vector && gradient.vector.length) {
765 el.setAttribute("x1", gradient.vector[0]);
766 el.setAttribute("y1", gradient.vector[1]);
767 el.setAttribute("x2", gradient.vector[2]);
768 el.setAttribute("y2", gradient.vector[3]);
770 SVG.defs.appendChild(el);
771 var isopacity = true;
772 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
773 var stop = doc.createElementNS(SVG.svgns, "stop");
774 if (gradient.dots[i].offset) {
777 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
778 stop.setAttribute("stop-color", getRGB(gradient.dots[i].color).hex || "#fff");
779 // ignoring opacity for internal points, because VML doesn't support it
780 el.appendChild(stop);
782 if (isopacity && typeof gradient.dots[ii - 1].opacity != "undefined") {
783 stop.setAttribute("stop-opacity", gradient.dots[ii - 1].opacity);
785 o.setAttribute("fill", "url(#" + el.id + ")");
787 o.style.fillOpacity = 1;
788 o.setAttribute("opacity", 1);
789 o.setAttribute("fill-opacity", 1);
791 var updatePosition = function (o) {
793 var bbox = o.node.getBBox();
794 o.pattern.setAttribute("patternTransform", "translate(" + [bbox.x, bbox.y].join(",") + ")");
797 var setFillAndStroke = function (o, params) {
802 "-..": [3, 1, 1, 1, 1, 1],
808 "--..": [8, 3, 1, 3, 1, 3]
810 addDashes = function (o, value) {
811 value = dasharray[value.toString().toLowerCase()];
813 var width = o.attrs["stroke-width"] || "1",
814 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
816 for (var i = 0, ii = value.length; i < ii; i++) {
817 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
819 value = dashes.join(",");
820 o.node.setAttribute("stroke-dasharray", value);
823 for (var att in params) {
824 if (!(att in availableAttrs)) {
827 var value = params[att];
828 o.attrs[att] = value;
834 var pn = o.node.parentNode;
835 if (pn.tagName.toLowerCase() != "a") {
836 var hl = doc.createElementNS(o.svg.svgns, "a");
837 pn.insertBefore(hl, o.node);
838 hl.appendChild(o.node);
841 pn.setAttributeNS(o.svg.xlink, att, value);
844 if (o.type == "path") {
845 o.node.setAttribute("d", "M0,0");
846 paper.pathfinder(o, value);
851 o.node.setAttribute(att, value);
857 o.node.setAttribute(att, value);
861 o.node.setAttribute(att, value);
864 o.node.setAttribute(att, value);
867 if (o.type == "image") {
868 o.node.setAttributeNS(svg.xlink, "href", value);
872 o.node.style.strokeWidth = value;
873 // Need following line for Firefox
874 o.node.setAttribute(att, value);
875 if (o.attrs["stroke-dasharray"]) {
876 addDashes(o, o.attrs["stroke-dasharray"]);
879 case "stroke-dasharray":
883 o.rotate(value, true);
886 var xy = (value + "").split(separator);
887 o.translate((+xy[0] + 1 || 2) - 1, (+xy[1] + 1 || 2) - 1);
890 var xy = (value + "").split(separator);
891 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1);
894 var isURL = value.match(/^url\(([^\)]+)\)$/i);
896 var el = doc.createElementNS(o.svg.svgns, "pattern");
897 var ig = doc.createElementNS(o.svg.svgns, "image");
898 el.id = "raphael-pattern-" + Raphael.idGenerator++;
899 el.setAttribute("x", 0);
900 el.setAttribute("y", 0);
901 el.setAttribute("patternUnits", "userSpaceOnUse");
902 ig.setAttribute("x", 0);
903 ig.setAttribute("y", 0);
904 ig.setAttributeNS(o.svg.xlink, "href", isURL[1]);
907 var img = doc.createElement("img");
908 img.style.position = "absolute";
909 img.style.top = "-9999em";
910 img.style.left = "-9999em";
911 img.onload = function () {
912 el.setAttribute("width", this.offsetWidth);
913 el.setAttribute("height", this.offsetHeight);
914 ig.setAttribute("width", this.offsetWidth);
915 ig.setAttribute("height", this.offsetHeight);
916 doc.body.removeChild(this);
919 doc.body.appendChild(img);
921 o.svg.defs.appendChild(el);
922 o.node.style.fill = "url(#" + el.id + ")";
923 o.node.setAttribute("fill", "url(#" + el.id + ")");
928 delete params.gradient;
929 delete o.attrs.gradient;
930 if (typeof o.attrs.opacity != "undefined" && typeof params.opacity == "undefined" ) {
931 o.node.style.opacity = o.attrs.opacity;
932 // Need following line for Firefox
933 o.node.setAttribute("opacity", o.attrs.opacity);
935 if (typeof o.attrs["fill-opacity"] != "undefined" && typeof params["fill-opacity"] == "undefined" ) {
936 o.node.style.fillOpacity = o.attrs["fill-opacity"];
937 // Need following line for Firefox
938 o.node.setAttribute("fill-opacity", o.attrs["fill-opacity"]);
941 o.node.style[att] = getRGB(value).hex;
942 // Need following line for Firefox
943 o.node.setAttribute(att, getRGB(value).hex);
946 addGrdientFill(o.node, value, o.svg);
950 if (o.attrs.gradient) {
951 var gradient = doc.getElementById(o.node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
953 var stops = gradient.getElementsByTagName("stop");
954 stops[stops.length - 1].setAttribute("stop-opacity", value);
959 var cssrule = att.replace(/(\-.)/g, function (w) {
960 return w.substring(1).toUpperCase();
962 o.node.style[cssrule] = value;
963 // Need following line for Firefox
964 o.node.setAttribute(att, value);
971 var tuneText = function (element, params) {
972 if (element.type != "text" || !("text" in params || "font" in params || "font-size" in params || "x" in params)) {
975 var fontSize = element.node.firstChild ? parseInt(doc.defaultView.getComputedStyle(element.node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
978 if ("text" in params) {
979 while (element.node.firstChild) {
980 element.node.removeChild(element.node.firstChild);
982 var texts = (params.text + "").split("\n");
983 for (var i = 0, ii = texts.length; i < ii; i++) {
984 var tspan = doc.createElementNS(element.svg.svgns, "tspan");
985 i && tspan.setAttribute("dy", fontSize * leading);
986 i && tspan.setAttribute("x", element.attrs.x);
987 tspan.appendChild(doc.createTextNode(texts[i]));
988 element.node.appendChild(tspan);
989 height += fontSize * leading;
992 var texts = element.node.getElementsByTagName("tspan");
993 for (var i = 0, ii = texts.length; i < ii; i++) {
994 i && texts[i].setAttribute("dy", fontSize * leading);
995 i && texts[i].setAttribute("x", element.attrs.x);
996 height += fontSize * leading;
999 height -= fontSize * (leading - 1);
1000 var dif = height / 2 - fontSize;
1002 element.node.setAttribute("y", element.attrs.y - dif);
1004 setTimeout(function () {
1007 var Element = function (node, svg) {
1013 this.attrs = this.attrs || {};
1014 this.transformations = []; // rotate, translate, scale
1018 rt: {deg: 0, x: 0, y: 0},
1023 Element.prototype.rotate = function (deg, cx, cy) {
1025 return this._.rt.deg;
1027 var bbox = this.getBBox();
1028 deg = deg.toString().split(separator);
1029 if (deg.length - 1) {
1030 cx = parseFloat(deg[1], 10);
1031 cy = parseFloat(deg[2], 10);
1033 deg = parseFloat(deg[0], 10);
1035 this._.rt.deg = deg;
1037 this._.rt.deg += deg;
1042 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1043 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1044 if (this._.rt.deg) {
1045 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
1047 this.transformations[0] = "";
1049 this.node.setAttribute("transform", this.transformations.join(" "));
1052 Element.prototype.hide = function () {
1053 this.node.style.display = "none";
1056 Element.prototype.show = function () {
1057 this.node.style.display = "block";
1060 Element.prototype.remove = function () {
1061 this.node.parentNode.removeChild(this.node);
1063 Element.prototype.getBBox = function () {
1064 return this.node.getBBox();
1066 Element.prototype.attr = function () {
1067 if (arguments.length == 1 && typeof arguments[0] == "string") {
1068 if (arguments[0] == "translation") {
1069 return this.translate();
1071 return this.attrs[arguments[0]];
1073 if (arguments.length == 1 && arguments[0] instanceof Array) {
1075 for (var j in arguments[0]) {
1076 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1080 if (arguments.length == 2) {
1082 params[arguments[0]] = arguments[1];
1083 setFillAndStroke(this, params);
1084 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1085 setFillAndStroke(this, arguments[0]);
1089 Element.prototype.toFront = function () {
1090 this.node.parentNode.appendChild(this.node);
1093 Element.prototype.toBack = function () {
1094 if (this.node.parentNode.firstChild != this.node) {
1095 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1099 Element.prototype.insertAfter = function (element) {
1100 if (element.node.nextSibling) {
1101 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1103 element.node.parentNode.appendChild(this.node);
1107 Element.prototype.insertBefore = function (element) {
1108 element.node.parentNode.insertBefore(this.node, element.node);
1111 var theCircle = function (svg, x, y, r) {
1112 var el = doc.createElementNS(svg.svgns, "circle");
1113 el.setAttribute("cx", x);
1114 el.setAttribute("cy", y);
1115 el.setAttribute("r", r);
1116 el.setAttribute("fill", "none");
1117 el.setAttribute("stroke", "#000");
1119 svg.canvas.appendChild(el);
1121 var res = new Element(el, svg);
1122 res.attrs = res.attrs || {};
1126 res.attrs.stroke = "#000";
1127 res.type = "circle";
1130 var theRect = function (svg, x, y, w, h, r) {
1131 var el = doc.createElementNS(svg.svgns, "rect");
1132 el.setAttribute("x", x);
1133 el.setAttribute("y", y);
1134 el.setAttribute("width", w);
1135 el.setAttribute("height", h);
1137 el.setAttribute("rx", r);
1138 el.setAttribute("ry", r);
1140 el.setAttribute("fill", "none");
1141 el.setAttribute("stroke", "#000");
1143 svg.canvas.appendChild(el);
1145 var res = new Element(el, svg);
1146 res.attrs = res.attrs || {};
1149 res.attrs.width = w;
1150 res.attrs.height = h;
1151 res.attrs.stroke = "#000";
1153 res.attrs.rx = res.attrs.ry = r;
1158 var theEllipse = function (svg, x, y, rx, ry) {
1159 var el = doc.createElementNS(svg.svgns, "ellipse");
1160 el.setAttribute("cx", x);
1161 el.setAttribute("cy", y);
1162 el.setAttribute("rx", rx);
1163 el.setAttribute("ry", ry);
1164 el.setAttribute("fill", "none");
1165 el.setAttribute("stroke", "#000");
1167 svg.canvas.appendChild(el);
1169 var res = new Element(el, svg);
1170 res.attrs = res.attrs || {};
1175 res.attrs.stroke = "#000";
1176 res.type = "ellipse";
1179 var theImage = function (svg, src, x, y, w, h) {
1180 var el = doc.createElementNS(svg.svgns, "image");
1181 el.setAttribute("x", x);
1182 el.setAttribute("y", y);
1183 el.setAttribute("width", w);
1184 el.setAttribute("height", h);
1185 el.setAttribute("preserveAspectRatio", "none");
1186 el.setAttributeNS(svg.xlink, "href", src);
1188 svg.canvas.appendChild(el);
1190 var res = new Element(el, svg);
1191 res.attrs = res.attrs || {};
1194 res.attrs.width = w;
1195 res.attrs.height = h;
1199 var theText = function (svg, x, y, text) {
1200 var el = doc.createElementNS(svg.svgns, "text");
1201 el.setAttribute("x", x);
1202 el.setAttribute("y", y);
1203 el.setAttribute("text-anchor", "middle");
1205 svg.canvas.appendChild(el);
1207 var res = new Element(el, svg);
1208 res.attrs = res.attrs || {};
1212 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000", text: text});
1215 var theGroup = function (svg) {
1216 var el = doc.createElementNS(svg.svgns, "g");
1218 svg.canvas.appendChild(el);
1220 var i = new Element(el, svg);
1221 for (var f in svg) {
1222 if (f[0] != "_" && typeof svg[f] == "function") {
1223 i[f] = (function (f) {
1224 return function () {
1225 var e = svg[f].apply(svg, arguments);
1226 el.appendChild(e[0]);
1235 var setSize = function (width, height) {
1236 this.width = width || this.width;
1237 this.height = height || this.height;
1238 this.canvas.setAttribute("width", this.width);
1239 this.canvas.setAttribute("height", this.height);
1242 var create = function () {
1243 var con = getContainer.apply(null, arguments);
1244 var container = con.container,
1248 height = con.height;
1250 throw new Error("SVG container not found.");
1252 paper.canvas = doc.createElementNS(paper.svgns, "svg");
1253 paper.canvas.setAttribute("width", width || 320);
1254 paper.width = width || 320;
1255 paper.canvas.setAttribute("height", height || 200);
1256 paper.height = height || 200;
1257 if (container == 1) {
1258 doc.body.appendChild(paper.canvas);
1259 paper.canvas.style.position = "absolute";
1260 paper.canvas.style.left = x + "px";
1261 paper.canvas.style.top = y + "px";
1263 if (container.firstChild) {
1264 container.insertBefore(paper.canvas, container.firstChild);
1266 container.appendChild(paper.canvas);
1270 canvas: paper.canvas,
1271 clear: function () {
1272 while (this.canvas.firstChild) {
1273 this.canvas.removeChild(this.canvas.firstChild);
1275 this.defs = doc.createElementNS(paper.svgns, "defs");
1276 this.canvas.appendChild(this.defs);
1279 for (var prop in paper) {
1280 if (prop != "create") {
1281 container[prop] = paper[prop];
1284 plugins(container, container, R.fn);
1288 paper.remove = function () {
1289 this.canvas.parentNode.removeChild(this.canvas);
1291 paper.svgns = "http://www.w3.org/2000/svg";
1292 paper.xlink = "http://www.w3.org/1999/xlink";
1293 paper.safari = function () {
1294 if (navigator.vendor == "Apple Computer, Inc.") {
1295 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1296 setTimeout(function () {rect.remove();}, 0);
1303 thePath = function (params, pathString, VML) {
1304 var g = createNode("group"), gl = g.style;
1305 gl.position = "absolute";
1308 gl.width = VML.width + "px";
1309 gl.height = VML.height + "px";
1310 var el = createNode("shape"), ol = el.style;
1311 ol.width = VML.width + "px";
1312 ol.height = VML.height + "px";
1314 if (params["class"]) {
1315 el.className = "rvml " + params["class"];
1317 el.coordsize = this.coordsize;
1318 el.coordorigin = this.coordorigin;
1320 VML.canvas.appendChild(g);
1321 var p = new Element(el, g, VML);
1322 p.isAbsolute = true;
1325 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1327 p.absolutely = function () {
1328 this.isAbsolute = true;
1331 p.relatively = function () {
1332 this.isAbsolute = false;
1335 p.moveTo = function (x, y) {
1336 var d = this.isAbsolute?"m":"t";
1337 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
1338 this.node.path = this.Path += d;
1339 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
1340 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
1341 this.last.isAbsolute = this.isAbsolute;
1342 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1345 p.lineTo = function (x, y) {
1346 var d = this.isAbsolute?"l":"r";
1347 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
1348 this[0].path = this.Path += d;
1349 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
1350 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
1351 this.last.isAbsolute = this.isAbsolute;
1352 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1355 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1356 // for more information of where this math came from visit:
1357 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1358 x2 = (this.isAbsolute ? 0 : this.last.x) + x2;
1359 y2 = (this.isAbsolute ? 0 : this.last.y) + y2;
1360 var x1 = this.last.x,
1364 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1365 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1366 cx = k * rx * y / ry + (x1 + x2) / 2,
1367 cy = k * -ry * x / rx + (y1 + y2) / 2,
1368 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1369 left = Math.round(cx - rx),
1370 top = Math.round(cy - ry);
1371 d += [left, top, Math.round(left + rx * 2), Math.round(top + ry * 2), Math.round(x1), Math.round(y1), Math.round(parseFloat(x2, 10)), Math.round(parseFloat(y2, 10))].join(", ");
1372 this.node.path = this.Path += d;
1373 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2, 10);
1374 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2, 10);
1375 this.last.isAbsolute = this.isAbsolute;
1376 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1379 p.cplineTo = function (x1, y1, w1) {
1381 return this.lineTo(x1, y1);
1383 var x = Math.round(Math.round(parseFloat(x1, 10) * 100) / 100),
1384 y = Math.round(Math.round(parseFloat(y1, 10) * 100) / 100),
1385 w = Math.round(Math.round(parseFloat(w1, 10) * 100) / 100),
1386 d = this.isAbsolute ? "c" : "v",
1387 attr = [Math.round(this.last.x) + w, Math.round(this.last.y), x - w, y, x, y],
1388 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1389 d += attr.join(" ") + " ";
1390 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1391 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1392 this.last.bx = attr[2];
1393 this.last.by = attr[3];
1394 this.node.path = this.Path += d;
1395 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1399 p.curveTo = function () {
1400 var d = this.isAbsolute ? "c" : "v";
1401 if (arguments.length == 6) {
1402 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1403 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1404 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4], 10);
1405 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5], 10);
1406 d += [Math.round(parseFloat(arguments[0], 10)),
1407 Math.round(parseFloat(arguments[1], 10)),
1408 Math.round(parseFloat(arguments[2], 10)),
1409 Math.round(parseFloat(arguments[3], 10)),
1410 Math.round(parseFloat(arguments[4], 10)),
1411 Math.round(parseFloat(arguments[5], 10))].join(" ") + " ";
1412 this.last.isAbsolute = this.isAbsolute;
1413 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1415 if (arguments.length == 4) {
1416 var bx = this.last.x * 2 - this.last.bx;
1417 var by = this.last.y * 2 - this.last.by;
1418 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
1419 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
1420 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1421 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1422 d += [Math.round(bx), Math.round(by),
1423 Math.round(parseFloat(arguments[0], 10)),
1424 Math.round(parseFloat(arguments[1], 10)),
1425 Math.round(parseFloat(arguments[2], 10)),
1426 Math.round(parseFloat(arguments[3], 10))].join(" ") + " ";
1427 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1429 this.node.path = this.Path += d;
1432 p.qcurveTo = function () {
1434 if (arguments.length == 4) {
1435 this.last.qx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
1436 this.last.qy = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
1437 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1438 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1439 d += [Math.round(this.last.qx),
1440 Math.round(this.last.qy),
1441 Math.round(this.last.x),
1442 Math.round(this.last.y)].join(" ") + " ";
1443 this.last.isAbsolute = this.isAbsolute;
1444 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1446 if (arguments.length == 2) {
1447 this.last.qx = this.last.x * 2 - this.last.qx;
1448 this.last.qy = this.last.y * 2 - this.last.qy;
1449 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1450 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1451 d += [Math.round(this.last.qx),
1452 Math.round(this.last.qy),
1453 Math.round(this.last.x),
1454 Math.round(this.last.y)].join(" ") + " ";
1455 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1457 this.node.path = this.Path += d;
1458 this.path.push({type: "qcurve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
1461 p.addRoundedCorner = function (r, dir) {
1462 var R = .5522 * r, rollback = this.isAbsolute, o = this;
1465 rollback = function () {
1469 rollback = function () {};
1475 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
1478 o.curveTo(-R, 0, -r, r - R, -r, r);
1485 o.curveTo(R, 0, r, -(r - R), r, -r);
1488 o.curveTo(R, 0, r, r - R, r, r);
1495 o.curveTo(0, -R, -(R - r), -r, r, -r);
1498 o.curveTo(0, -R, R - r, -r, -r, -r);
1505 o.curveTo(0, R, -(R - r), r, r, r);
1508 o.curveTo(0, R, R - r, r, -r, r);
1513 actions[dir.charAt(0)]()[dir.charAt(1)]();
1517 p.andClose = function () {
1518 this.node.path = (this.Path += "x e");
1519 this.attrs.path += "z";
1525 paper.pathfinder(p, "" + pathString);
1528 setFillAndStroke(p, params);
1529 if (params.gradient) {
1530 addGrdientFill(p, params.gradient);
1534 var setFillAndStroke = function (o, params) {
1535 var s = o.node.style,
1537 o.attrs = o.attrs || {};
1538 for (var par in params) {
1539 o.attrs[par] = params[par];
1541 params.href && (o.node.href = params.href);
1542 params.title && (o.node.title = params.title);
1543 params.target && (o.node.target = params.target);
1544 if (params.path && o.type == "path") {
1547 paper.pathfinder(o, params.path);
1549 if (params.rotation != null) {
1550 o.rotate(params.rotation, true);
1552 if (params.translation) {
1553 var xy = (params.translation + "").split(separator);
1554 o.translate(xy[0], xy[1]);
1557 var xy = (params.scale + "").split(separator);
1558 o.scale(xy[0], xy[1]);
1560 if (o.type == "image" && params.src) {
1561 o.node.src = params.src;
1563 if (o.type == "image" && params.opacity) {
1564 o.node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1565 o.node.style.filter = (o.node.filterMatrix || "") + (o.node.filterOpacity || "");
1567 params.font && (s.font = params.font);
1568 params["font-family"] && (s.fontFamily = params["font-family"]);
1569 params["font-size"] && (s.fontSize = params["font-size"]);
1570 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1571 params["font-style"] && (s.fontStyle = params["font-style"]);
1572 if (typeof params.opacity != "undefined" || typeof params["stroke-width"] != "undefined" || typeof params.fill != "undefined" || typeof params.stroke != "undefined" || params["stroke-width"] || params["stroke-opacity"] || params["stroke-dasharray"] || params["stroke-miterlimit"] || params["stroke-linejoin"] || params["stroke-linecap"]) {
1573 o = o.shape || o.node;
1574 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || createNode("fill");
1575 if ("fill-opacity" in params || "opacity" in params) {
1576 fill.opacity = ((+params["fill-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1581 if (typeof fill.on == "undefined" || params.fill == "none") {
1584 if (fill.on && params.fill) {
1585 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1587 fill.src = isURL[1];
1590 fill.color = getRGB(params.fill).hex;
1592 fill.type = "solid";
1595 o.appendChild(fill);
1596 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || createNode("stroke");
1597 if ((params.stroke && params.stroke != "none") || params["stroke-width"] || typeof params["stroke-opacity"] != "undefined" || params["stroke-dasharray"] || params["stroke-miterlimit"] || params["stroke-linejoin"] || params["stroke-linecap"]) {
1600 if (params.stroke == "none" || typeof stroke.on == "undefined" || params.stroke == 0) {
1603 if (stroke.on && params.stroke) {
1604 stroke.color = getRGB(params.stroke).hex;
1606 stroke.opacity = ((+params["stroke-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1607 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1608 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1609 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1610 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"], 10) || 1) * 12 / 16);
1611 if (params["stroke-dasharray"]) {
1615 "-.": "shortdashdot",
1616 "-..": "shortdashdotdot",
1621 "--.": "longdashdot",
1622 "--..": "longdashdotdot"
1624 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1626 o.appendChild(stroke);
1628 if (res.type == "text") {
1629 var span = doc.createElement("span"),
1631 res.attrs.font && (s.font = res.attrs.font);
1632 res.attrs["font-family"] && (s.fontFamily = res.attrs["font-family"]);
1633 res.attrs["font-size"] && (s.fontSize = res.attrs["font-size"]);
1634 res.attrs["font-weight"] && (s.fontWeight = res.attrs["font-weight"]);
1635 res.attrs["font-style"] && (s.fontStyle = res.attrs["font-style"]);
1636 res.node.parentNode.appendChild(span);
1637 span.innerText = res.node.string;
1638 res.W = res.attrs.w = span.offsetWidth;
1639 res.H = res.attrs.h = span.offsetHeight;
1640 res.X = res.attrs.x;
1641 res.Y = res.attrs.y + Math.round(res.H / 2);
1642 res.node.parentNode.removeChild(span);
1644 // text-anchor emulation
1645 switch(res.attrs["text-anchor"]) {
1647 res.node.style["v-text-align"] = "left";
1648 res.bbx = Math.round(res.W / 2);
1651 res.node.style["v-text-align"] = "right";
1652 res.bbx = -Math.round(res.W / 2);
1655 res.node.style["v-text-align"] = "center";
1660 var getAngle = function (a, b, c, d) {
1661 var angle = Math.round(Math.atan((parseFloat(c, 10) - parseFloat(a, 10)) / (parseFloat(d, 10) - parseFloat(b, 10))) * 57.29) || 0;
1662 if (!angle && parseFloat(a, 10) < parseFloat(b, 10)) {
1671 var addGrdientFill = function (o, gradient) {
1672 gradient = toGradient(gradient);
1673 o.attrs = o.attrs || {};
1674 var attrs = o.attrs;
1675 o.attrs.gradient = gradient;
1676 o = o.shape || o[0];
1677 var fill = o.getElementsByTagName("fill");
1681 fill = createNode("fill");
1683 if (gradient.dots.length) {
1685 fill.method = "none";
1686 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1687 if (typeof gradient.dots[0].color != "undefined") {
1688 fill.color = getRGB(gradient.dots[0].color).hex;
1690 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1691 fill.color2 = getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1694 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1695 if (gradient.dots[i].offset) {
1696 colors.push(gradient.dots[i].offset + " " + getRGB(gradient.dots[i].color).hex);
1699 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;
1700 if (colors.length) {
1701 fill.colors.value = colors.join(",");
1702 fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
1704 fill.colors.value = "0% " + fill.color;
1706 fill.opacity = fillOpacity;
1707 if (typeof gradient.angle != "undefined") {
1708 fill.angle = (-gradient.angle + 270) % 360;
1709 } else if (gradient.vector) {
1710 fill.angle = getAngle.apply(null, gradient.vector);
1712 if ((gradient.type + "").toLowerCase() == "radial") {
1713 fill.focus = "100%";
1714 fill.focusposition = "0.5 0.5";
1718 var Element = function (node, group, vml) {
1738 Element.prototype.rotate = function (deg, cx, cy) {
1740 return this._.rt.deg;
1742 deg = deg.toString().split(separator);
1743 if (deg.length - 1) {
1744 cx = parseFloat(deg[1], 10);
1745 cy = parseFloat(deg[2], 10);
1747 deg = parseFloat(deg[0], 10);
1749 this._.rt.deg = deg;
1751 this._.rt.deg += deg;
1758 this.setBox(null, cx, cy);
1759 this.Group.style.rotation = this._.rt.deg;
1762 Element.prototype.setBox = function (params, cx, cy) {
1763 var gs = this.Group.style,
1764 os = (this.shape && this.shape.style) || this.node.style;
1765 for (var i in params) {
1766 this.attrs[i] = params[i];
1768 cx = cx || this._.rt.cx;
1769 cy = cy || this._.rt.cy;
1770 var attr = this.attrs, x, y, w, h;
1771 switch (this.type) {
1773 x = attr.cx - attr.r;
1774 y = attr.cy - attr.r;
1778 x = attr.cx - attr.rx;
1779 y = attr.cy - attr.ry;
1787 w = attr.width || 0;
1788 h = attr.height || 0;
1791 this.textpath.v = ["m", Math.round(attr.x), ", ", Math.round(attr.y - 2), "l", Math.round(attr.x) + 1, ", ", Math.round(attr.y - 2)].join("");
1792 x = attr.x - Math.round(this.W / 2);
1793 y = attr.y - this.H / 2;
1798 if (!this.attrs.path) {
1802 h = this.vml.height;
1804 var dim = pathDimensions(this.attrs.path),
1815 h = this.vml.height;
1818 cx = (cx == null) ? x + w / 2 : cx;
1819 cy = (cy == null) ? y + h / 2 : cy;
1820 var left = cx - this.vml.width / 2,
1821 top = cy - this.vml.height / 2;
1822 if (this.type == "path" || this.type == "text") {
1823 gs.left = left + "px";
1824 gs.top = top + "px";
1825 this.X = this.type == "text" ? x : -left;
1826 this.Y = this.type == "text" ? y : -top;
1829 os.left = -left + "px";
1830 os.top = -top + "px";
1832 gs.left = left + "px";
1833 gs.top = top + "px";
1838 gs.width = this.vml.width + "px";
1839 gs.height = this.vml.height + "px";
1840 os.left = x - left + "px";
1841 os.top = y - top + "px";
1842 os.width = w + "px";
1843 os.height = h + "px";
1846 Element.prototype.hide = function () {
1847 this.Group.style.display = "none";
1850 Element.prototype.show = function () {
1851 this.Group.style.display = "block";
1854 Element.prototype.getBBox = function () {
1855 this.bbx = this.bbx || 0;
1857 x: this.X + this.bbx,
1863 Element.prototype.remove = function () {
1864 this[0].parentNode.removeChild(this[0]);
1865 this.Group.parentNode.removeChild(this.Group);
1866 this.shape && this.shape.parentNode.removeChild(this.shape);
1868 Element.prototype.attr = function () {
1869 if (arguments.length == 1 && typeof arguments[0] == "string") {
1870 if (arguments[0] == "translation") {
1871 return this.translate();
1873 return this.attrs[arguments[0]];
1875 if (this.attrs && arguments.length == 1 && arguments[0] instanceof Array) {
1877 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1878 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1883 if (arguments.length == 2) {
1885 params[arguments[0]] = arguments[1];
1887 if (arguments.length == 1 && typeof arguments[0] == "object") {
1888 params = arguments[0];
1891 if (params.gradient) {
1892 addGrdientFill(this, params.gradient);
1894 if (params.text && this.type == "text") {
1895 this.node.string = params.text;
1898 this.node.id = params.id;
1900 setFillAndStroke(this, params);
1901 this.setBox(params);
1905 Element.prototype.toFront = function () {
1906 this.Group.parentNode.appendChild(this.Group);
1909 Element.prototype.toBack = function () {
1910 if (this.Group.parentNode.firstChild != this.Group) {
1911 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
1915 Element.prototype.insertAfter = function (element) {
1916 if (element.Group.nextSibling) {
1917 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
1919 element.Group.parentNode.appendChild(this.Group);
1923 Element.prototype.insertBefore = function (element) {
1924 element.Group.parentNode.insertBefore(this.Group, element.Group);
1927 var theCircle = function (vml, x, y, r) {
1928 var g = createNode("group");
1929 var o = createNode("oval");
1931 vml.canvas.appendChild(g);
1932 var res = new Element(o, g, vml);
1933 res.type = "circle";
1934 setFillAndStroke(res, {stroke: "#000", fill: "none"});
1938 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
1941 var theRect = function (vml, x, y, w, h, r) {
1942 var g = createNode("group");
1943 var o = createNode(r ? "roundrect" : "rect");
1945 o.arcsize = r / (Math.min(w, h));
1948 vml.canvas.appendChild(g);
1949 var res = new Element(o, g, vml);
1951 setFillAndStroke(res, {stroke: "#000"});
1957 res.setBox({x: x, y: y, width: w, height: h});
1960 var theEllipse = function (vml, x, y, rx, ry) {
1961 var g = createNode("group");
1962 var o = createNode("oval");
1964 vml.canvas.appendChild(g);
1965 var res = new Element(o, g, vml);
1966 res.type = "ellipse";
1967 setFillAndStroke(res, {stroke: "#000"});
1972 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
1975 var theImage = function (vml, src, x, y, w, h) {
1976 var g = createNode("group");
1977 var o = createNode("image");
1980 vml.canvas.appendChild(g);
1981 var res = new Element(o, g, vml);
1987 res.setBox({x: x, y: y, width: w, height: h});
1990 var theText = function (vml, x, y, text) {
1991 var g = createNode("group"), gs = g.style;
1992 var el = createNode("shape"), ol = el.style;
1993 var path = createNode("path"), ps = path.style;
1994 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
1995 path.textpathok = true;
1996 ol.width = vml.width;
1997 ol.height = vml.height;
1998 gs.position = "absolute";
2001 gs.width = vml.width;
2002 gs.height = vml.height;
2003 var o = createNode("textpath");
2006 o.coordsize = vml.coordsize;
2007 o.coordorigin = vml.coordorigin;
2009 el.appendChild(path);
2011 vml.canvas.appendChild(g);
2012 var res = new Element(o, g, vml);
2014 res.textpath = path;
2020 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2023 var setSize = function (width, height) {
2024 this.width = width || this.width;
2025 this.height = height || this.height;
2026 this.canvas.style.width = this.width + "px";
2027 this.canvas.style.height = this.height + "px";
2028 this.canvas.parentNode.style.clip = "rect(0 " + this.width + " " + this.height + " 0)";
2029 this.canvas.coordsize = this.width + " " + this.height;
2032 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2034 if (!doc.namespaces.rvml) {
2035 doc.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
2037 var createNode = function (tagName) {
2038 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2041 var createNode = function (tagName) {
2042 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2045 var create = function () {
2046 var con = getContainer.apply(null, arguments);
2047 var container = con.container,
2051 height = con.height;
2053 throw new Error("VML container not found.");
2055 var c = doc.createElement("div"),
2056 d = doc.createElement("div"),
2057 r = paper.canvas = createNode("group"),
2058 cs = c.style, rs = r.style;
2059 paper.width = width;
2060 paper.height = height;
2061 width = width || "320px";
2062 height = height || "200px";
2063 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2066 cs.position = "absolute";
2067 rs.position = "absolute";
2068 d.style.position = "relative";
2071 r.coordsize = (/%$/.test(width) ? width : parseFloat(width, 10)) + " " + (/%$/.test(height) ? height : parseFloat(height, 10));
2072 r.coordorigin = "0 0";
2074 var b = createNode("rect"), bs = b.style;
2075 bs.left = bs.top = 0;
2076 bs.width = rs.width;
2077 bs.height = rs.height;
2078 b.filled = b.stroked = "f";
2083 if (container == 1) {
2084 doc.body.appendChild(d);
2085 cs.position = "absolute";
2097 cs.width = container.style.width = width;
2098 cs.height = container.style.height = height;
2099 if (container.firstChild) {
2100 container.insertBefore(d, container.firstChild);
2102 container.appendChild(d);
2105 for (var prop in paper) {
2106 container[prop] = paper[prop];
2108 plugins(container, container, R.fn);
2109 container.clear = function () {
2111 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
2112 if (r.childNodes[i] != b) {
2113 todel.push(r.childNodes[i]);
2116 for (i = 0, ii = todel.length; i < ii; i++) {
2117 r.removeChild(todel[i]);
2122 paper.remove = function () {
2123 this.canvas.parentNode.parentNode.parentNode.removeChild(this.canvas.parentNode.parentNode);
2125 paper.safari = function () {};
2131 var addEvent = (function () {
2132 if (doc.addEventListener) {
2133 return function (obj, type, fn, element) {
2134 var f = function (e) {
2135 return fn.call(element, e);
2137 obj.addEventListener(type, f, false);
2138 return function () {
2139 obj.removeEventListener(type, f, false);
2143 } else if (doc.attachEvent) {
2144 return function (obj, type, fn, element) {
2145 var f = function (e) {
2146 return fn.call(element, e || win.event);
2148 obj.attachEvent("on" + type, f);
2149 var detacher = function () {
2150 obj.detachEvent("on" + type, f);
2153 if (type == "mouseover") {
2154 obj.attachEvent("onmouseenter", f);
2155 return function () {
2156 obj.detachEvent("onmouseenter", f);
2159 } else if (type == "mouseout") {
2160 obj.attachEvent("onmouseleave", f);
2161 return function () {
2162 obj.detachEvent("onmouseleave", f);
2170 for (var i = events.length; i--;) {
2171 (function (eventName) {
2172 Element.prototype[eventName] = function (fn) {
2173 if (typeof fn == "function") {
2174 this.events = this.events || {};
2175 this.events[eventName] = this.events[eventName] || {};
2176 this.events[eventName][fn] = this.events[eventName][fn] || [];
2177 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2181 Element.prototype["un" + eventName] = function (fn) {
2183 this.events[eventName] &&
2184 this.events[eventName][fn] &&
2185 this.events[eventName][fn].length &&
2186 this.events[eventName][fn].shift()() &&
2187 !this.events[eventName][fn].length &&
2188 delete this.events[eventName][fn];
2193 paper.circle = function (x, y, r) {
2194 return theCircle(this, x, y, r);
2196 paper.rect = function (x, y, w, h, r) {
2197 return theRect(this, x, y, w, h, r);
2199 paper.ellipse = function (x, y, rx, ry) {
2200 return theEllipse(this, x, y, rx, ry);
2202 paper.path = function (params, pathString) {
2203 return thePath(params, pathString, this);
2205 paper.image = function (src, x, y, w, h) {
2206 return theImage(this, src, x, y, w, h);
2208 paper.text = function (x, y, text) {
2209 return theText(this, x, y, text);
2211 paper.group = function () {
2214 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
2215 color = color || "#000";
2216 var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
2218 columnWidth = w / wv;
2219 for (var i = 1; i < hv; i++) {
2220 path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
2222 for (var i = 1; i < wv; i++) {
2223 path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
2225 return this.path({stroke: color, "stroke-width": 1}, path.join(","));
2227 paper.pathfinder = function (p, path) {
2229 M: function (x, y) {
2232 C: function (x1, y1, x2, y2, x3, y3) {
2233 this.curveTo(x1, y1, x2, y2, x3, y3);
2235 Q: function (x1, y1, x2, y2) {
2236 this.qcurveTo(x1, y1, x2, y2);
2238 T: function (x, y) {
2239 this.qcurveTo(x, y);
2241 S: function (x1, y1, x2, y2) {
2242 p.curveTo(x1, y1, x2, y2);
2244 L: function (x, y) {
2248 this.lineTo(x, this.last.y);
2251 this.lineTo(this.last.x, y);
2253 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2254 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2261 path = pathToAbsolute(path);
2262 for (var i = 0, ii = path.length; i < ii; i++) {
2263 var b = path[i].shift();
2264 commands[b].apply(p, path[i]);
2267 paper.set = function (itemsArray) {
2268 return new Set(itemsArray);
2270 paper.setSize = setSize;
2271 Element.prototype.stop = function () {
2272 clearTimeout(this.animation_in_progress);
2274 Element.prototype.scale = function (x, y) {
2275 if (x == null && y == null) {
2276 return {x: this._.sx, y: this._.sy};
2279 // following line is for IE, apparently NaN is not always falsy
2280 isNaN(y) && (y = x);
2283 var dirx = Math.round(x / Math.abs(x)),
2284 diry = Math.round(y / Math.abs(y)),
2285 s = this.node.style;
2286 dx = this.attr("x");
2287 dy = this.attr("y");
2288 cx = this.attr("cx");
2289 cy = this.attr("cy");
2290 if (dirx != 1 || diry != 1) {
2291 if (this.transformations) {
2292 this.transformations[2] = "scale(" + [dirx, diry] + ")";
2293 this.node.setAttribute("transform", this.transformations.join(" "));
2294 dx = (dirx < 0) ? -this.attr("x") - this.attrs.width * x * dirx / this._.sx : this.attr("x");
2295 dy = (diry < 0) ? -this.attr("y") - this.attrs.height * y * diry / this._.sy : this.attr("y");
2296 cx = this.attr("cx") * dirx;
2297 cy = this.attr("cy") * diry;
2299 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=" + dirx +
2300 ", M12=0, M21=0, M22=" + diry +
2301 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')";
2302 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2305 if (this.transformations) {
2306 this.transformations[2] = "";
2307 this.node.setAttribute("transform", this.transformations.join(" "));
2309 this.node.filterMatrix = "";
2310 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2313 switch (this.type) {
2317 width: this.attrs.width * x * dirx / this._.sx,
2318 height: this.attrs.height * y * diry / this._.sy,
2326 rx: this.attrs.rx * x * dirx / this._.sx,
2327 ry: this.attrs.ry * y * diry / this._.sy,
2328 r: this.attrs.r * x * diry / this._.sx,
2334 var path = pathToRelative(Raphael.parsePathString(this.attr("path"))),
2336 dim = pathDimensions(this.attrs.path);
2337 for (var i = 0, ii = path.length; i < ii; i++) {
2338 if (path[i][0].toUpperCase() == "M" && skip) {
2343 if (this.svg && path[i][0].toUpperCase() == "A") {
2344 path[i][path[i].length - 2] *= x * dirx;
2345 path[i][path[i].length - 1] *= y * diry;
2349 for (var j = 1, jj = path[i].length; j < jj; j++) {
2350 path[i][j] *= (j % 2) ? x * dirx / this._.sx : y * diry / this._.sy;
2354 var dim2 = pathDimensions(path),
2355 dx = dim.x + dim.width / 2 - dim2.x - dim2.width / 2,
2356 dy = dim.y + dim.height / 2 - dim2.y - dim2.height / 2;
2357 path = pathToRelative(path);
2361 this.attr({path: path.join(" ")});
2368 Element.prototype.animate = function (params, ms, callback) {
2369 clearTimeout(this.animation_in_progress);
2374 for (var attr in params) {
2375 if (attr in availableAnimAttrs) {
2376 from[attr] = this.attr(attr);
2377 if (typeof from[attr] == "undefined") {
2378 from[attr] = availableAttrs[attr];
2380 to[attr] = params[attr];
2381 switch (availableAnimAttrs[attr]) {
2383 diff[attr] = (to[attr] - from[attr]) / ms;
2386 from[attr] = getRGB(from[attr]);
2387 var toColour = getRGB(to[attr]);
2389 r: (toColour.r - from[attr].r) / ms,
2390 g: (toColour.g - from[attr].g) / ms,
2391 b: (toColour.b - from[attr].b) / ms
2395 var pathes = pathEqualiser(from[attr], to[attr]);
2396 from[attr] = pathes[0];
2397 to[attr] = pathes[1];
2399 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2400 diff[attr][i] = [0];
2401 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2402 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2407 var values = params[attr].toString().split(separator),
2408 from2 = from[attr].toString().split(separator);
2409 if (attr == "translation") {
2410 from[attr] = [0, 0];
2411 diff[attr] = [values[0] / ms, values[1] / ms];
2412 } else if (attr == "rotation") {
2413 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2414 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2416 from[attr] = (from[attr] + "").split(separator);
2417 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][0]) / ms];
2423 var start = new Date(),
2427 var time = (new Date()).getTime() - start.getTime(),
2431 for (var attr in from) {
2432 switch (availableAnimAttrs[attr]) {
2434 now = +from[attr] + time * diff[attr];
2438 Math.round(from[attr].r + time * diff[attr].r),
2439 Math.round(from[attr].g + time * diff[attr].g),
2440 Math.round(from[attr].b + time * diff[attr].b)
2445 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2446 now[i] = [from[attr][i][0]];
2447 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2448 now[i][j] = from[attr][i][j] + time * diff[attr][i][j];
2450 now[i] = now[i].join(" ");
2452 now = now.join(" ");
2455 if (attr == "translation") {
2456 var x = diff[attr][0] * (time - prev),
2457 y = diff[attr][1] * (time - prev);
2460 now = [x, y].join(" ");
2461 } else if (attr == "rotation") {
2462 now = +from[attr][0] + time * diff[attr][0];
2463 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2465 now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1]].join(" ");
2469 if (attr == "font-size") {
2470 set[attr] = now + "px";
2476 that.animation_in_progress = setTimeout(arguments.callee, 0);
2479 (t.x || t.y) && that.translate(-t.x, -t.y);
2481 clearTimeout(that.animation_in_progress);
2483 (typeof callback == "function") && callback.call(that);
2489 Element.prototype.translate = function (x, y) {
2491 return {x: this._.tx, y: this._.ty};
2495 switch (this.type) {
2498 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
2503 this.attr({x: this.attrs.x + +x, y: this.attrs.y + +y});
2506 var path = pathToRelative(this.attrs.path);
2509 this.attr({path: path.join(" ")});
2516 var Set = function (itemsArray) {
2518 this.length = (itemsArray && itemsArray.length) || 0;
2519 if (itemsArray && itemsArray.constructor == Array) {
2520 for (var i = itemsArray.length; i--;) {
2521 if (itemsArray[i].constructor == Element) {
2522 this.items[this.items.length] = itemsArray[i];
2527 Set.prototype.push = function (item) {
2528 if (item && item.constructor == Element) {
2529 var len = this.items.length;
2530 this.items[len] = item;
2536 Set.prototype.pull = function (id) {
2537 var res = this.items.splice(id, 1)[0];
2538 for (var j = id, jj = this.items.length; j < jj; j++) {
2539 this[j] = this[j + 1];
2541 delete this[jj + 1];
2545 for (var method in Element.prototype) {
2546 Set.prototype[method] = (function (methodname) {
2547 return function () {
2548 for (var i = this.items.length; i--;) {
2549 this.items[i][methodname].apply(this.items[i], arguments);
2555 Set.prototype.getBBox = function () {
2556 var x = [], y = [], w = [], h = [];
2557 for (var i = this.items.length; i--;) {
2558 var box = this.items[i].getBBox();
2561 w.push(box.x + box.width);
2562 h.push(box.y + box.height);
2564 x = Math.min.apply(Math, x);
2565 y = Math.min.apply(Math, y);
2569 width: Math.max.apply(Math, w) - x,
2570 height: Math.max.apply(Math, h) - y