2 * Raphael 0.7.dev - 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);
17 R.version = "0.7.dev";
18 R.type = (win.SVGAngle ? "SVG" : "VML");
19 R.svg = !(R.vml = R.type == "VML");
23 var availableAttrs = {cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '16px "Arial"', "font-family": '"Arial"', "font-size": "16", gradient: 0, height: 0, 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, translation: "0 0", width: 0, x: 0, y: 0},
24 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"};
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" && red.charAt(0) == "#") {
86 if (red.length == 4) {
87 blue = parseInt(red.substring(3), 16);
88 green = parseInt(red.substring(2, 3), 16);
89 red = parseInt(red.substring(1, 2), 16);
91 blue = parseInt(red.substring(5), 16);
92 green = parseInt(red.substring(3, 5), 16);
93 red = parseInt(red.substring(1, 3), 16);
96 if (red > 1 || green > 1 || blue > 1) {
101 var max = Math.max(red, green, blue),
102 min = Math.min(red, green, blue),
107 return {h: 0, s: 0, b: max};
109 var delta = (max - min);
110 saturation = delta / max;
112 hue = (green - blue) / delta;
113 } else if (green == max) {
114 hue = 2 + ((blue - red) / delta);
116 hue = 4 + ((red - green) / delta);
126 return {h: hue, s: saturation, b: brightness};
128 var getRGB = function (colour) {
129 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"};
130 if (colour.toString().toLowerCase() in htmlcolors) {
131 colour = htmlcolors[colour.toString().toLowerCase()];
134 return {r: 0, g: 0, b: 0, hex: "#000"};
136 if (colour == "none") {
137 return {r: -1, g: -1, b: -1, hex: "none"};
139 var red, green, blue,
140 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);
143 blue = parseInt(rgb[2].substring(5), 16);
144 green = parseInt(rgb[2].substring(3, 5), 16);
145 red = parseInt(rgb[2].substring(1, 3), 16);
148 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
149 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
150 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
153 rgb = rgb[4].split(/\s*,\s*/);
154 red = parseFloat(rgb[0], 10);
155 green = parseFloat(rgb[1], 10);
156 blue = parseFloat(rgb[2], 10);
159 rgb = rgb[5].split(/\s*,\s*/);
160 red = parseFloat(rgb[0], 10) * 2.55;
161 green = parseFloat(rgb[1], 10) * 2.55;
162 blue = parseFloat(rgb[2], 10) * 2.55;
165 rgb = rgb[6].split(/\s*,\s*/);
166 red = parseFloat(rgb[0], 10);
167 green = parseFloat(rgb[1], 10);
168 blue = parseFloat(rgb[2], 10);
169 return Raphael.hsb2rgb(red, green, blue);
172 rgb = rgb[7].split(/\s*,\s*/);
173 red = parseFloat(rgb[0], 10) * 2.55;
174 green = parseFloat(rgb[1], 10) * 2.55;
175 blue = parseFloat(rgb[2], 10) * 2.55;
176 return Raphael.hsb2rgb(red, green, blue);
178 var rgb = {r: red, g: green, b: blue};
179 var r = Math.round(red).toString(16);
180 (r.length == 1) && (r = "0" + r);
181 var g = Math.round(green).toString(16);
182 (g.length == 1) && (g = "0" + g);
183 var b = Math.round(blue).toString(16);
184 (b.length == 1) && (b = "0" + b);
185 rgb.hex = "#" + r + g + b;
188 return {r: -1, g: -1, b: -1, hex: "none"};
191 R.getColor = function (value) {
192 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
193 var rgb = Raphael.hsb2rgb(start.h, start.s, start.b);
199 arguments.callee.start = {h: 0, s: 1, b: start.b};
204 R.getColor.reset = function () {
205 this.start = undefined;
208 R.parsePathString = function (pathString) {
209 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
211 toString = function () {
213 for (var i = 0, ii = this.length; i < ii; i++) {
214 res += this[i][0] + this[i].join(",").substring(2);
218 if (pathString.toString.toString() == toString.toString()) {
221 pathString.replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*\s*,?\s*)+)/ig, function (a, b, c) {
222 var params = [], name = b.toLowerCase();
223 c.replace(/(-?\d*\.?\d*)\s*,?\s*/ig, function (a, b) {
224 b && params.push(+b);
226 while (params.length >= paramCounts[name]) {
227 data.push([b].concat(params.splice(0, paramCounts[name])));
228 if (!paramCounts[name]) {
233 data.toString = toString;
236 var pathDimensions = function (path) {
237 var pathArray = path;
238 if (typeof path == "string") {
239 pathArray = Raphael.parsePathString(path);
241 pathArray = pathToAbsolute(pathArray);
242 var x = [], y = [], length = 0;
243 for (var i = 0, ii = pathArray.length; i < ii; i++) {
244 switch (pathArray[i][0]) {
248 x.push(pathArray[i][pathArray[i].length - 2]);
249 y.push(pathArray[i][pathArray[i].length - 1]);
252 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
254 x.push(pathArray[i][j]);
256 y.push(pathArray[i][j]);
261 var minx = Math.min.apply(Math, x),
262 miny = Math.min.apply(Math, y);
266 width: Math.max.apply(Math, x) - minx,
267 height: Math.max.apply(Math, y) - miny,
272 var pathToRelative = function (pathArray) {
274 if (typeof pathArray == "string") {
275 pathArray = R.parsePathString(pathArray);
277 var x = 0, y = 0, start = 0;
278 if (pathArray[0][0] == "M") {
282 res.push(pathArray[0]);
284 for (var i = start, ii = pathArray.length; i < ii; i++) {
286 if (pathArray[i][0] != pathArray[i][0].toLowerCase()) {
287 res[i][0] = pathArray[i][0].toLowerCase();
290 res[i][1] = pathArray[i][1];
291 res[i][2] = pathArray[i][2];
293 res[i][4] = pathArray[i][4];
294 res[i][5] = pathArray[i][5];
295 res[i][6] = +(pathArray[i][6] - x).toFixed(3);
296 res[i][7] = +(pathArray[i][7] - y).toFixed(3);
299 res[i][1] = +(pathArray[i][1] - y).toFixed(3);
302 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
303 res[i][j] = +(pathArray[i][j] - ((j % 2) ? x : y)).toFixed(3);
307 res[i] = pathArray[i];
313 x += res[i][res[i].length - 1];
316 y += res[i][res[i].length - 1];
319 x += res[i][res[i].length - 2];
320 y += res[i][res[i].length - 1];
323 res.toString = pathArray.toString;
326 var pathToAbsolute = function (pathArray) {
328 if (typeof pathArray == "string") {
329 pathArray = R.parsePathString(pathArray);
331 var x = 0, y = 0, start = 0;
332 if (pathArray[0][0] == "M") {
333 x = +pathArray[0][1];
334 y = +pathArray[0][2];
336 res[0] = pathArray[0];
338 for (var i = start, ii = pathArray.length; i < ii; i++) {
340 if (pathArray[i][0] != pathArray[i][0].toUpperCase()) {
341 res[i][0] = pathArray[i][0].toUpperCase();
344 res[i][1] = pathArray[i][1];
345 res[i][2] = pathArray[i][2];
347 res[i][4] = pathArray[i][4];
348 res[i][5] = pathArray[i][5];
349 res[i][6] = +(pathArray[i][6] + x).toFixed(3);
350 res[i][7] = +(pathArray[i][7] + y).toFixed(3);
353 res[i][1] = +pathArray[i][1] + y;
356 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
357 res[i][j] = +pathArray[i][j] + ((j % 2) ? x : y);
361 res[i] = pathArray[i];
373 x = res[i][res[i].length - 2];
374 y = res[i][res[i].length - 1];
377 res.toString = pathArray.toString;
380 var pathEqualiser = function (path1, path2) {
381 var data = [pathToAbsolute(Raphael.parsePathString(path1)), pathToAbsolute(Raphael.parsePathString(path2))],
382 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}],
383 processPath = function (path, d) {
393 var nx = d.x + (d.x - (d.bx || d.x));
394 var ny = d.y + (d.y - (d.by || d.y));
395 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
398 var nx = d.x + (d.x - (d.bx || d.x));
399 var ny = d.y + (d.y - (d.by || d.y));
400 path = ["Q", nx, ny, path[1], path[2]];
403 path = ["L", path[1], d.y];
406 path = ["L", d.x, path[1]];
409 path = ["L", d.X, d.Y];
414 edgeCases = function (a, b, i) {
415 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
416 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
417 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
418 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
419 attrs[a].x = data[a][i][data[a][i].length - 2];
420 attrs[a].y = data[a][i][data[a][i].length - 1];
422 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
423 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]];
424 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
425 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
426 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
427 var x = data[b][i][data[b][i].length - 2];
428 var y = data[b][i][data[b][i].length - 1];
429 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
430 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
432 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
433 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
434 attrs[b].x = data[b][i][data[b][i].length - 2];
435 attrs[b].y = data[b][i][data[b][i].length - 1];
437 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
438 var x = data[b][i][data[b][i].length - 2];
439 var y = data[b][i][data[b][i].length - 1];
440 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
441 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
443 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
444 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
445 attrs[b].x = data[b][i][data[b][i].length - 2];
446 attrs[b].y = data[b][i][data[b][i].length - 1];
448 } else if (data[a][i][0] == "U") {
449 data[a][i][0] = data[b][i][0];
450 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
451 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
456 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
457 data[0][i] = processPath(data[0][i], attrs[0]);
458 data[1][i] = processPath(data[1][i], attrs[1]);
459 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
462 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
463 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
464 attrs[0].x = data[0][i][data[0][i].length - 2];
465 attrs[0].y = data[0][i][data[0][i].length - 1];
466 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
467 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
468 attrs[1].x = data[1][i][data[1][i].length - 2];
469 attrs[1].y = data[1][i][data[1][i].length - 1];
473 var toGradient = function (gradient) {
474 if (typeof gradient == "string") {
475 gradient = gradient.split(/\s*\/\s*/);
476 var angle = gradient.shift();
477 if (angle.toLowerCase() == "v") {
479 } else if (angle.toLowerCase() == "h") {
482 angle = parseFloat(angle, 10);
485 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)]};
486 var max = 1 / (Math.max(Math.abs(grobj.vector[2]), Math.abs(grobj.vector[3])) || 1);
487 grobj.vector[2] *= max;
488 grobj.vector[3] *= max;
489 if (grobj.vector[2] < 0) {
490 grobj.vector[0] = -grobj.vector[2];
493 if (grobj.vector[3] < 0) {
494 grobj.vector[1] = -grobj.vector[3];
497 grobj.vector[0] = grobj.vector[0].toFixed(3);
498 grobj.vector[1] = grobj.vector[1].toFixed(3);
499 grobj.vector[2] = grobj.vector[2].toFixed(3);
500 grobj.vector[3] = grobj.vector[3].toFixed(3);
501 for (var i = 0, ii = gradient.length; i < ii; i++) {
503 var par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
504 dot.color = getRGB(par[1]).hex;
505 par[2] && (dot.offset = par[2] + "%");
506 grobj.dots.push(dot);
508 for (var i = 1, ii = grobj.dots.length - 1; i < ii; i++) {
509 if (!grobj.dots[i].offset) {
510 var start = parseFloat(grobj.dots[i - 1].offset || 0, 10),
512 for (var j = i + 1; j < ii; j++) {
513 if (grobj.dots[j].offset) {
514 end = grobj.dots[j].offset;
522 end = parseFloat(end, 10);
523 var d = (end - start) / (j - i + 1);
526 grobj.dots[i].offset = start + "%";
538 var thePath = function (params, pathString, SVG) {
539 var el = doc.createElementNS(SVG.svgns, "path");
540 el.setAttribute("fill", "none");
542 SVG.canvas.appendChild(el);
544 var p = new Element(el, SVG);
547 p.last = {x: 0, y: 0, bx: 0, by: 0};
548 p.absolutely = function () {
549 this.isAbsolute = true;
552 p.relatively = function () {
553 this.isAbsolute = false;
556 p.moveTo = function (x, y) {
557 var d = this.isAbsolute?"M":"m";
558 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
559 var oldD = this[0].getAttribute("d") || "";
560 (oldD == "M0,0") && (oldD = "");
561 this[0].setAttribute("d", oldD + d);
562 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
563 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
564 this.attrs.path = oldD + d;
567 p.lineTo = function (x, y) {
568 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
569 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
570 var d = this.isAbsolute?"L":"l";
571 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
572 var oldD = this[0].getAttribute("d") || "";
573 this[0].setAttribute("d", oldD + d);
574 this.attrs.path = oldD + d;
577 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
578 var d = this.isAbsolute ? "A" : "a";
579 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(" ");
580 var oldD = this[0].getAttribute("d") || "";
581 this[0].setAttribute("d", oldD + d);
582 this.last.x = parseFloat(x, 10);
583 this.last.y = parseFloat(y, 10);
584 this.attrs.path = oldD + d;
587 p.cplineTo = function (x1, y1, w1) {
589 return this.lineTo(x1, y1);
592 var x = parseFloat(x1, 10);
593 var y = parseFloat(y1, 10);
594 var w = parseFloat(w1, 10);
595 var d = this.isAbsolute?"C":"c";
596 var attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
597 for (var i = 0, ii = attr.length; i < ii; i++) {
598 d += attr[i].toFixed(3) + " ";
600 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
601 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
602 this.last.bx = attr[2];
603 this.last.by = attr[3];
604 var oldD = this[0].getAttribute("d") || "";
605 this[0].setAttribute("d", oldD + d);
606 this.attrs.path = oldD + d;
610 p.curveTo = function () {
612 command = [0, 1, 2, 3, "s", 5, "c"];
614 var d = command[arguments.length];
615 if (this.isAbsolute) {
618 for (var i = 0, ii = arguments.length; i < ii; i++) {
619 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
621 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
622 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
623 this.last.bx = parseFloat(arguments[arguments.length - 4], 10);
624 this.last.by = parseFloat(arguments[arguments.length - 3], 10);
625 var oldD = this.node.getAttribute("d") || "";
626 this.node.setAttribute("d", oldD + d);
627 this.attrs.path = oldD + d;
630 p.qcurveTo = function () {
632 command = [0, 1, "t", 3, "q"];
634 var d = command[arguments.length];
635 if (this.isAbsolute) {
638 for (var i = 0, ii = arguments.length; i < ii; i++) {
639 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
641 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
642 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
643 if (arguments.length != 2) {
644 this.last.qx = parseFloat(arguments[arguments.length - 4], 10);
645 this.last.qy = parseFloat(arguments[arguments.length - 3], 10);
647 var oldD = this.node.getAttribute("d") || "";
648 this.node.setAttribute("d", oldD + d);
649 this.attrs.path = oldD + d;
652 p.addRoundedCorner = function (r, dir) {
653 var R = .5522 * r, rollback = this.isAbsolute, o = this;
656 rollback = function () {
660 rollback = function () {};
666 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
669 o.curveTo(-R, 0, -r, r - R, -r, r);
676 o.curveTo(R, 0, r, -(r - R), r, -r);
679 o.curveTo(R, 0, r, r - R, r, r);
686 o.curveTo(0, -R, -(R - r), -r, r, -r);
689 o.curveTo(0, -R, R - r, -r, -r, -r);
696 o.curveTo(0, R, -(R - r), r, r, r);
699 o.curveTo(0, R, R - r, r, -r, r);
704 actions[dir[0]]()[dir[1]]();
708 p.andClose = function () {
709 var oldD = this[0].getAttribute("d") || "";
710 this[0].setAttribute("d", oldD + "Z ");
711 this.attrs.path = oldD + "Z ";
715 p.attrs.path = "" + pathString;
717 paper.pathfinder(p, p.attrs.path);
720 setFillAndStroke(p, params);
724 var addGrdientFill = function (o, gradient, SVG) {
725 gradient = toGradient(gradient);
726 var el = doc.createElementNS(SVG.svgns, (gradient.type || "linear") + "Gradient");
727 el.id = "raphael-gradient-" + Raphael.idGenerator++;
728 if (gradient.vector && gradient.vector.length) {
729 el.setAttribute("x1", gradient.vector[0]);
730 el.setAttribute("y1", gradient.vector[1]);
731 el.setAttribute("x2", gradient.vector[2]);
732 el.setAttribute("y2", gradient.vector[3]);
734 SVG.defs.appendChild(el);
735 var isopacity = true;
736 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
737 var stop = doc.createElementNS(SVG.svgns, "stop");
738 if (gradient.dots[i].offset) {
741 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
742 stop.setAttribute("stop-color", getRGB(gradient.dots[i].color).hex || "#fff");
743 // ignoring opacity for internal points, because VML doesn't support it
744 el.appendChild(stop);
746 if (isopacity && typeof gradient.dots[ii - 1].opacity != "undefined") {
747 stop.setAttribute("stop-opacity", gradient.dots[ii - 1].opacity);
749 o.setAttribute("fill", "url(#" + el.id + ")");
751 o.style.fillOpacity = 1;
752 o.setAttribute("opacity", 1);
753 o.setAttribute("fill-opacity", 1);
755 var updatePosition = function (o) {
757 var bbox = o.node.getBBox();
758 o.pattern.setAttribute("patternTransform", "translate(" + [bbox.x, bbox.y].join(",") + ")");
761 var setFillAndStroke = function (o, params) {
766 "-..": [3, 1, 1, 1, 1, 1],
772 "--..": [8, 3, 1, 3, 1, 3]
774 addDashes = function (o, value) {
775 value = dasharray[value.toString().toLowerCase()];
777 var width = o.attrs["stroke-width"] || "1",
778 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
780 for (var i = 0, ii = value.length; i < ii; i++) {
781 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
783 value = dashes.join(",");
784 o.node.setAttribute("stroke-dasharray", value);
787 for (var att in params) {
788 var value = params[att];
789 o.attrs[att] = value;
792 if (o.type == "path") {
793 o.node.setAttribute("d", "M0,0");
794 paper.pathfinder(o, value);
799 o.node.setAttribute(att, value);
805 o.node.setAttribute(att, value);
809 o.node.setAttribute(att, value);
812 o.node.setAttribute(att, value);
815 if (o.type == "image") {
816 o.node.setAttributeNS(svg.xlink, "href", value);
820 o.node.style.strokeWidth = value;
821 // Need following line for Firefox
822 o.node.setAttribute(att, value);
823 if (o.attrs["stroke-dasharray"]) {
824 addDashes(o, o.attrs["stroke-dasharray"]);
827 case "stroke-dasharray":
831 // if (o.type == "text") {
832 // o.node.childNodes.length && o.node.removeChild(o.node.firstChild);
833 // o.node.appendChild(doc.createTextNode(value));
837 o.rotate(value, true);
840 var xy = value.split(separator);
841 o.translate(xy[0], xy[1]);
844 var xy = value.split(separator);
845 o.scale(xy[0], xy[1]);
848 var isURL = value.match(/^url\(([^\)]+)\)$/i);
850 var el = doc.createElementNS(o.svg.svgns, "pattern");
851 var ig = doc.createElementNS(o.svg.svgns, "image");
852 el.id = "raphael-pattern-" + Raphael.idGenerator++;
853 el.setAttribute("x", 0);
854 el.setAttribute("y", 0);
855 el.setAttribute("patternUnits", "userSpaceOnUse");
856 ig.setAttribute("x", 0);
857 ig.setAttribute("y", 0);
858 ig.setAttributeNS(o.svg.xlink, "href", isURL[1]);
861 var img = doc.createElement("img");
862 img.style.position = "absolute";
863 img.style.top = "-9999em";
864 img.style.left = "-9999em";
865 img.onload = function () {
866 el.setAttribute("width", this.offsetWidth);
867 el.setAttribute("height", this.offsetHeight);
868 ig.setAttribute("width", this.offsetWidth);
869 ig.setAttribute("height", this.offsetHeight);
870 doc.body.removeChild(this);
873 doc.body.appendChild(img);
875 o.svg.defs.appendChild(el);
876 o.node.style.fill = "url(#" + el.id + ")";
877 o.node.setAttribute("fill", "url(#" + el.id + ")");
882 delete params.gradient;
883 delete o.attrs.gradient;
884 if (typeof o.attrs.opacity != "undefined" && typeof params.opacity == "undefined" ) {
885 o.node.style.opacity = o.attrs.opacity;
886 // Need following line for Firefox
887 o.node.setAttribute("opacity", o.attrs.opacity);
889 if (typeof o.attrs["fill-opacity"] != "undefined" && typeof params["fill-opacity"] == "undefined" ) {
890 o.node.style.fillOpacity = o.attrs["fill-opacity"];
891 // Need following line for Firefox
892 o.node.setAttribute("fill-opacity", o.attrs["fill-opacity"]);
895 o.node.style[att] = getRGB(value).hex;
896 // Need following line for Firefox
897 o.node.setAttribute(att, getRGB(value).hex);
900 addGrdientFill(o.node, value, o.svg);
904 if (o.attrs.gradient) {
905 var gradient = document.getElementById(o.node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
907 var stops = gradient.getElementsByTagName("stop");
908 stops[stops.length - 1].setAttribute("stop-opacity", value);
913 var cssrule = att.replace(/(\-.)/g, function (w) {
914 return w.substring(1).toUpperCase();
916 o.node.style[cssrule] = value;
917 // Need following line for Firefox
918 o.node.setAttribute(att, value);
924 var Element = function (node, svg) {
930 this.attrs = this.attrs || {};
931 this.transformations = []; // rotate, translate, scale
935 rt: {deg: 0, x: 0, y: 0},
940 Element.prototype.translate = function (x, y) {
941 if (x == undefined && y == undefined) {
942 return {x: this._.tx, y: this._.ty};
949 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
954 this.attr({x: this.attrs.x + +x, y: this.attrs.y + +y});
957 var path = pathToRelative(this.attrs.path);
960 this.attr({path: path.join(" ")});
965 Element.prototype.rotate = function (deg, cx, cy) {
967 return this._.rt.deg;
969 var bbox = this.getBBox();
970 deg = deg.toString().split(separator);
971 if (deg.length - 1) {
972 cx = parseFloat(deg[1], 10);
973 cy = parseFloat(deg[2], 10);
975 deg = parseFloat(deg[0], 10);
979 this._.rt.deg += deg;
984 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
985 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
987 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
989 this.transformations[0] = "";
991 this.node.setAttribute("transform", this.transformations.join(" "));
994 Element.prototype.hide = function () {
995 this.node.style.display = "none";
998 Element.prototype.show = function () {
999 this.node.style.display = "block";
1002 Element.prototype.remove = function () {
1003 this.node.parentNode.removeChild(this.node);
1005 Element.prototype.getBBox = function () {
1006 return this.node.getBBox();
1008 Element.prototype.attr = function () {
1009 if (arguments.length == 1 && typeof arguments[0] == "string") {
1010 if (arguments[0] == "translation") {
1011 return this.translate();
1013 return this.attrs[arguments[0]];
1015 if (arguments.length == 1 && arguments[0] instanceof Array) {
1017 for (var j in arguments[0]) {
1018 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1022 if (arguments.length == 2) {
1024 params[arguments[0]] = arguments[1];
1025 setFillAndStroke(this, params);
1026 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1027 setFillAndStroke(this, arguments[0]);
1031 Element.prototype.toFront = function () {
1032 this.node.parentNode.appendChild(this.node);
1035 Element.prototype.toBack = function () {
1036 if (this.node.parentNode.firstChild != this.node) {
1037 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1041 Element.prototype.insertAfter = function (element) {
1042 if (element.node.nextSibling) {
1043 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1045 element.node.parentNode.appendChild(this.node);
1049 Element.prototype.insertBefore = function (element) {
1050 element.node.parentNode.insertBefore(this.node, element.node);
1053 var theCircle = function (svg, x, y, r) {
1054 var el = doc.createElementNS(svg.svgns, "circle");
1055 el.setAttribute("cx", x);
1056 el.setAttribute("cy", y);
1057 el.setAttribute("r", r);
1058 el.setAttribute("fill", "none");
1059 el.setAttribute("stroke", "#000");
1061 svg.canvas.appendChild(el);
1063 var res = new Element(el, svg);
1064 res.attrs = res.attrs || {};
1068 res.attrs.stroke = "#000";
1069 res.type = "circle";
1072 var theRect = function (svg, x, y, w, h, r) {
1073 var el = doc.createElementNS(svg.svgns, "rect");
1074 el.setAttribute("x", x);
1075 el.setAttribute("y", y);
1076 el.setAttribute("width", w);
1077 el.setAttribute("height", h);
1079 el.setAttribute("rx", r);
1080 el.setAttribute("ry", r);
1082 el.setAttribute("fill", "none");
1083 el.setAttribute("stroke", "#000");
1085 svg.canvas.appendChild(el);
1087 var res = new Element(el, svg);
1088 res.attrs = res.attrs || {};
1091 res.attrs.width = w;
1092 res.attrs.height = h;
1093 res.attrs.stroke = "#000";
1095 res.attrs.rx = res.attrs.ry = r;
1100 var theEllipse = function (svg, x, y, rx, ry) {
1101 var el = doc.createElementNS(svg.svgns, "ellipse");
1102 el.setAttribute("cx", x);
1103 el.setAttribute("cy", y);
1104 el.setAttribute("rx", rx);
1105 el.setAttribute("ry", ry);
1106 el.setAttribute("fill", "none");
1107 el.setAttribute("stroke", "#000");
1109 svg.canvas.appendChild(el);
1111 var res = new Element(el, svg);
1112 res.attrs = res.attrs || {};
1117 res.attrs.stroke = "#000";
1118 res.type = "ellipse";
1121 var theImage = function (svg, src, x, y, w, h) {
1122 var el = doc.createElementNS(svg.svgns, "image");
1123 el.setAttribute("x", x);
1124 el.setAttribute("y", y);
1125 el.setAttribute("width", w);
1126 el.setAttribute("height", h);
1127 el.setAttribute("preserveAspectRatio", "none");
1128 el.setAttributeNS(svg.xlink, "href", src);
1130 svg.canvas.appendChild(el);
1132 var res = new Element(el, svg);
1133 res.attrs = res.attrs || {};
1136 res.attrs.width = w;
1137 res.attrs.height = h;
1142 var tuneText = function (element, params) {
1143 if (element.type != "text") {
1146 var fontSize = element.node.firstChild ? parseInt(doc.defaultView.getComputedStyle(element.node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
1149 if ("text" in params) {
1150 while (element.node.firstChild) {
1151 element.node.removeChild(element.node.firstChild);
1153 var texts = (params.text + "").split("\n");
1154 for (var i = 0, ii = texts.length; i < ii; i++) {
1155 var tspan = doc.createElementNS(element.svg.svgns, "tspan");
1156 i && tspan.setAttribute("dy", fontSize * leading);
1157 tspan.setAttribute("x", element.attrs.x);
1158 tspan.appendChild(doc.createTextNode(texts[i]));
1159 element.node.appendChild(tspan);
1160 height += fontSize * leading;
1162 } else if ("font" in params || "font-size" in params) {
1163 var texts = element.node.getElementsByTagName("tspan");
1164 for (var i = 0, ii = texts.length; i < ii; i++) {
1165 i && texts[i].setAttribute("dy", fontSize * leading);
1166 height += fontSize * leading;
1169 height -= fontSize * (leading - 1);
1170 var dif = height / 2 - fontSize;
1172 element.node.setAttribute("y", element.attrs.y - dif);
1174 setTimeout(function () {
1177 var theText = function (svg, x, y, text) {
1178 var el = doc.createElementNS(svg.svgns, "text");
1179 el.setAttribute("x", x);
1180 el.setAttribute("y", y);
1181 el.setAttribute("text-anchor", "middle");
1183 svg.canvas.appendChild(el);
1185 var res = new Element(el, svg);
1186 res.attrs = res.attrs || {};
1190 setFillAndStroke(res, {font: '10px "Arial"', stroke: "none", fill: "#000", text: text});
1193 var theGroup = function (svg) {
1194 var el = doc.createElementNS(svg.svgns, "g");
1196 svg.canvas.appendChild(el);
1198 var i = new Element(el, svg);
1199 for (var f in svg) {
1200 if (f[0] != "_" && typeof svg[f] == "function") {
1201 i[f] = (function (f) {
1202 return function () {
1203 var e = svg[f].apply(svg, arguments);
1204 el.appendChild(e[0]);
1213 var setSize = function (width, height) {
1214 this.width = width || this.width;
1215 this.height = height || this.height;
1216 this.canvas.setAttribute("width", this.width);
1217 this.canvas.setAttribute("height", this.height);
1220 create = function () {
1221 // container, width, height
1222 // x, y, width, height
1223 if (typeof arguments[0] == "string") {
1224 var container = doc.getElementById(arguments[0]);
1225 var width = arguments[1];
1226 var height = arguments[2];
1228 if (typeof arguments[0] == "object") {
1229 var container = arguments[0];
1230 var width = arguments[1];
1231 var height = arguments[2];
1233 if (typeof arguments[0] == "number") {
1237 width = arguments[2],
1238 height = arguments[3];
1241 throw new Error("SVG container not found.");
1243 paper.canvas = doc.createElementNS(paper.svgns, "svg");
1244 paper.canvas.setAttribute("width", width || 320);
1245 paper.width = width || 320;
1246 paper.canvas.setAttribute("height", height || 200);
1247 paper.height = height || 200;
1248 if (container == 1) {
1249 doc.body.appendChild(paper.canvas);
1250 paper.canvas.style.position = "absolute";
1251 paper.canvas.style.left = x + "px";
1252 paper.canvas.style.top = y + "px";
1254 if (container.firstChild) {
1255 container.insertBefore(paper.canvas, container.firstChild);
1257 container.appendChild(paper.canvas);
1261 canvas: paper.canvas,
1262 clear: function () {
1263 while (this.canvas.firstChild) {
1264 this.canvas.removeChild(this.canvas.firstChild);
1266 this.defs = doc.createElementNS(paper.svgns, "defs");
1267 this.canvas.appendChild(this.defs);
1270 for (var prop in paper) {
1271 if (prop != "create") {
1272 container[prop] = paper[prop];
1275 for (var prop in R.fn) {
1276 if (!container[prop]) {
1277 container[prop] = R.fn[prop];
1283 paper.remove = function () {
1284 this.canvas.parentNode.removeChild(this.canvas);
1286 paper.svgns = "http://www.w3.org/2000/svg";
1287 paper.xlink = "http://www.w3.org/1999/xlink";
1288 paper.safari = function () {
1289 if (navigator.vendor == "Apple Computer, Inc.") {
1290 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1291 setTimeout(function () {rect.remove();}, 0);
1298 thePath = function (params, pathString, VML) {
1299 var g = doc.createElement("rvml:group"), gl = g.style;
1300 gl.position = "absolute";
1303 gl.width = VML.width + "px";
1304 gl.height = VML.height + "px";
1305 var el = doc.createElement("rvml:shape"), ol = el.style;
1306 ol.width = VML.width + "px";
1307 ol.height = VML.height + "px";
1309 if (params["class"]) {
1310 el.className = params["class"];
1312 el.coordsize = this.coordsize;
1313 el.coordorigin = this.coordorigin;
1315 VML.canvas.appendChild(g);
1316 var p = new Element(el, g, VML);
1317 p.isAbsolute = true;
1320 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1322 p.absolutely = function () {
1323 this.isAbsolute = true;
1326 p.relatively = function () {
1327 this.isAbsolute = false;
1330 p.moveTo = function (x, y) {
1331 var d = this.isAbsolute?"m":"t";
1332 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
1333 this.node.path = this.Path += d;
1334 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
1335 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
1336 this.last.isAbsolute = this.isAbsolute;
1337 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1340 p.lineTo = function (x, y) {
1341 var d = this.isAbsolute?"l":"r";
1342 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
1343 this[0].path = this.Path += d;
1344 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
1345 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
1346 this.last.isAbsolute = this.isAbsolute;
1347 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1350 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1351 // for more information of where this math came from visit:
1352 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1353 x2 = (this.isAbsolute ? 0 : this.last.x) + x2;
1354 y2 = (this.isAbsolute ? 0 : this.last.y) + y2;
1355 var x1 = this.last.x,
1359 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1360 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1361 cx = k * rx * y / ry + (x1 + x2) / 2,
1362 cy = k * -ry * x / rx + (y1 + y2) / 2,
1363 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1364 left = Math.round(cx - rx),
1365 top = Math.round(cy - ry);
1366 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(", ");
1367 this.node.path = this.Path += d;
1368 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2, 10);
1369 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2, 10);
1370 this.last.isAbsolute = this.isAbsolute;
1371 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1374 p.cplineTo = function (x1, y1, w1) {
1376 return this.lineTo(x1, y1);
1378 var x = Math.round(Math.round(parseFloat(x1, 10) * 100) / 100),
1379 y = Math.round(Math.round(parseFloat(y1, 10) * 100) / 100),
1380 w = Math.round(Math.round(parseFloat(w1, 10) * 100) / 100),
1381 d = this.isAbsolute ? "c" : "v",
1382 attr = [Math.round(this.last.x) + w, Math.round(this.last.y), x - w, y, x, y],
1383 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1384 d += attr.join(" ") + " ";
1385 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1386 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1387 this.last.bx = attr[2];
1388 this.last.by = attr[3];
1389 this.node.path = this.Path += d;
1390 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1394 p.curveTo = function () {
1395 var d = this.isAbsolute ? "c" : "v";
1396 if (arguments.length == 6) {
1397 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1398 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1399 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4], 10);
1400 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5], 10);
1401 d += [Math.round(parseFloat(arguments[0], 10)),
1402 Math.round(parseFloat(arguments[1], 10)),
1403 Math.round(parseFloat(arguments[2], 10)),
1404 Math.round(parseFloat(arguments[3], 10)),
1405 Math.round(parseFloat(arguments[4], 10)),
1406 Math.round(parseFloat(arguments[5], 10))].join(" ") + " ";
1407 this.last.isAbsolute = this.isAbsolute;
1408 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1410 if (arguments.length == 4) {
1411 var bx = this.last.x * 2 - this.last.bx;
1412 var by = this.last.y * 2 - this.last.by;
1413 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
1414 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
1415 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1416 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1417 d += [Math.round(bx), Math.round(by),
1418 Math.round(parseFloat(arguments[0], 10)),
1419 Math.round(parseFloat(arguments[1], 10)),
1420 Math.round(parseFloat(arguments[2], 10)),
1421 Math.round(parseFloat(arguments[3], 10))].join(" ") + " ";
1422 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1424 this.node.path = this.Path += d;
1427 p.qcurveTo = function () {
1429 if (arguments.length == 4) {
1430 this.last.qx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
1431 this.last.qy = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
1432 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1433 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1434 d += [Math.round(this.last.qx),
1435 Math.round(this.last.qy),
1436 Math.round(this.last.x),
1437 Math.round(this.last.y)].join(" ") + " ";
1438 this.last.isAbsolute = this.isAbsolute;
1439 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1441 if (arguments.length == 2) {
1442 this.last.qx = this.last.x * 2 - this.last.qx;
1443 this.last.qy = this.last.y * 2 - this.last.qy;
1444 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1445 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1446 d += [Math.round(this.last.qx),
1447 Math.round(this.last.qy),
1448 Math.round(this.last.x),
1449 Math.round(this.last.y)].join(" ") + " ";
1450 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1452 this.node.path = this.Path += d;
1453 this.path.push({type: "qcurve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
1456 p.addRoundedCorner = function (r, dir) {
1457 var R = .5522 * r, rollback = this.isAbsolute, o = this;
1460 rollback = function () {
1464 rollback = function () {};
1470 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
1473 o.curveTo(-R, 0, -r, r - R, -r, r);
1480 o.curveTo(R, 0, r, -(r - R), r, -r);
1483 o.curveTo(R, 0, r, r - R, r, r);
1490 o.curveTo(0, -R, -(R - r), -r, r, -r);
1493 o.curveTo(0, -R, R - r, -r, -r, -r);
1500 o.curveTo(0, R, -(R - r), r, r, r);
1503 o.curveTo(0, R, R - r, r, -r, r);
1508 actions[dir.charAt(0)]()[dir.charAt(1)]();
1512 p.andClose = function () {
1513 this.node.path = (this.Path += "x e");
1514 this.attrs.path += "z";
1520 paper.pathfinder(p, "" + pathString);
1523 setFillAndStroke(p, params);
1524 if (params.gradient) {
1525 addGrdientFill(p, params.gradient);
1529 var setFillAndStroke = function (o, params) {
1530 var s = o.node.style,
1532 o.attrs = o.attrs || {};
1533 for (var par in params) {
1534 o.attrs[par] = params[par];
1536 if (params.path && o.type == "path") {
1539 paper.pathfinder(o, params.path);
1541 if (params.rotation != null) {
1542 o.rotate(params.rotation, true);
1544 if (params.translation) {
1545 var xy = params.translation.split(separator);
1546 o.translate(xy[0], xy[1]);
1549 var xy = params.scale.split(separator);
1550 o.scale(xy[0], xy[1]);
1552 if (o.type == "image" && params.src) {
1553 o.node.src = params.src;
1555 if (o.type == "image" && params.opacity) {
1556 o.node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1557 o.node.style.filter = (o.node.filterMatrix || "") + (o.node.filterOpacity || "");
1559 params.font && (s.font = params.font);
1560 params["font-family"] && (s.fontFamily = params["font-family"]);
1561 params["font-size"] && (s.fontSize = params["font-size"]);
1562 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1563 params["font-style"] && (s.fontStyle = params["font-style"]);
1564 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"]) {
1565 o = o.shape || o.node;
1566 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || doc.createElement("rvml:fill");
1567 if ("fill-opacity" in params || "opacity" in params) {
1568 fill.opacity = ((params["fill-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
1573 if (typeof fill.on == "undefined" || params.fill == "none") {
1576 if (fill.on && params.fill) {
1577 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1579 fill.src = isURL[1];
1582 fill.color = getRGB(params.fill).hex;
1584 fill.type = "solid";
1587 o.appendChild(fill);
1588 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || doc.createElement("rvml:stroke");
1589 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"]) {
1592 if (params.stroke == "none" || typeof stroke.on == "undefined" || params.stroke == 0) {
1595 if (stroke.on && params.stroke) {
1596 stroke.color = getRGB(params.stroke).hex;
1598 stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
1599 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1600 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1601 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1602 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"], 10) || 1) * 12 / 16);
1603 if (params["stroke-dasharray"]) {
1607 "-.": "shortdashdot",
1608 "-..": "shortdashdotdot",
1613 "--.": "longdashdot",
1614 "--..": "longdashdotdot"
1616 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1618 o.appendChild(stroke);
1620 if (res.type == "text") {
1621 var span = doc.createElement("span"),
1623 res.attrs.font && (s.font = res.attrs.font);
1624 res.attrs["font-family"] && (s.fontFamily = res.attrs["font-family"]);
1625 res.attrs["font-size"] && (s.fontSize = res.attrs["font-size"]);
1626 res.attrs["font-weight"] && (s.fontWeight = res.attrs["font-weight"]);
1627 res.attrs["font-style"] && (s.fontStyle = res.attrs["font-style"]);
1628 res.node.parentNode.appendChild(span);
1629 span.innerText = res.node.string;
1630 res.W = res.attrs.w = span.offsetWidth;
1631 res.H = res.attrs.h = span.offsetHeight;
1632 res.X = res.attrs.x - Math.round(res.W / 2);
1633 res.Y = res.attrs.y - Math.round(res.H / 2);
1634 res.node.parentNode.removeChild(span);
1637 var getAngle = function (a, b, c, d) {
1638 var angle = Math.round(Math.atan((parseFloat(c, 10) - parseFloat(a, 10)) / (parseFloat(d, 10) - parseFloat(b, 10))) * 57.29) || 0;
1639 if (!angle && parseFloat(a, 10) < parseFloat(b, 10)) {
1648 var addGrdientFill = function (o, gradient) {
1649 gradient = toGradient(gradient);
1650 o.attrs = o.attrs || {};
1651 var attrs = o.attrs;
1652 o.attrs.gradient = gradient;
1653 o = o.shape || o[0];
1654 var fill = o.getElementsByTagName("fill");
1658 fill = doc.createElement("rvml:fill");
1660 if (gradient.dots.length) {
1662 fill.method = "none";
1663 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1664 if (typeof gradient.dots[0].color != "undefined") {
1665 fill.color = getRGB(gradient.dots[0].color).hex;
1667 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1668 fill.color2 = getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1671 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1672 if (gradient.dots[i].offset) {
1673 colors.push(gradient.dots[i].offset + " " + getRGB(gradient.dots[i].color).hex);
1676 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;
1677 if (colors.length) {
1678 fill.colors.value = colors.join(",");
1679 fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
1681 fill.colors.value = "0% " + fill.color;
1683 fill.opacity = fillOpacity;
1684 if (typeof gradient.angle != "undefined") {
1685 fill.angle = (-gradient.angle + 270) % 360;
1686 } else if (gradient.vector) {
1687 fill.angle = getAngle.apply(null, gradient.vector);
1689 if ((gradient.type + "").toLowerCase() == "radial") {
1690 fill.focus = "100%";
1691 fill.focusposition = "0.5 0.5";
1695 var Element = function (node, group, vml) {
1715 Element.prototype.rotate = function (deg, cx, cy) {
1717 return this._.rt.deg;
1719 deg = deg.toString().split(separator);
1720 if (deg.length - 1) {
1721 cx = parseFloat(deg[1], 10);
1722 cy = parseFloat(deg[2], 10);
1724 deg = parseFloat(deg[0], 10);
1729 this._.rt.deg = deg;
1731 this._.rt.deg += deg;
1735 this.setBox(null, cx, cy);
1736 this.Group.style.rotation = this._.rt.deg;
1739 Element.prototype.setBox = function (params, cx, cy) {
1740 var gs = this.Group.style,
1741 os = (this.shape && this.shape.style) || this.node.style;
1742 for (var i in params) {
1743 this.attrs[i] = params[i];
1745 cx = cx || this._.rt.cx;
1746 cy = cy || this._.rt.cy;
1747 var attr = this.attrs, x, y, w, h;
1748 switch (this.type) {
1750 x = attr.cx - attr.r;
1751 y = attr.cy - attr.r;
1755 x = attr.cx - attr.rx;
1756 y = attr.cy - attr.ry;
1764 w = attr.width || 0;
1765 h = attr.height || 0;
1768 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("");
1769 x = attr.x - Math.round(this.W / 2);
1770 y = attr.y - this.H / 2;
1775 if (!this.attrs.path) {
1779 h = this.vml.height;
1781 var dim = pathDimensions(this.attrs.path),
1792 h = this.vml.height;
1795 cx = (cx == null) ? x + w / 2 : cx;
1796 cy = (cy == null) ? y + h / 2 : cy;
1797 var left = cx - this.vml.width / 2,
1798 top = cy - this.vml.height / 2;
1799 if (this.type == "path" || this.type == "text") {
1800 gs.left = left + "px";
1801 gs.top = top + "px";
1802 this.X = this.type == "text" ? x : -left;
1803 this.Y = this.type == "text" ? y : -top;
1806 os.left = -left + "px";
1807 os.top = -top + "px";
1809 gs.left = left + "px";
1810 gs.top = top + "px";
1815 gs.width = this.vml.width + "px";
1816 gs.height = this.vml.height + "px";
1817 os.left = x - left + "px";
1818 os.top = y - top + "px";
1819 os.width = w + "px";
1820 os.height = h + "px";
1823 Element.prototype.hide = function () {
1824 this.Group.style.display = "none";
1827 Element.prototype.show = function () {
1828 this.Group.style.display = "block";
1831 Element.prototype.translate = function (x, y) {
1832 if (x == undefined && y == undefined) {
1833 return {x: this._.tx, y: this._.ty};
1837 if (this.type == "path") {
1838 var path = this.attrs.path;
1839 path = pathToRelative(path);
1842 this.attr({path: path.join(" ")});
1844 this.setBox({x: this._.tx, y: this._.ty});
1847 Element.prototype.getBBox = function () {
1855 Element.prototype.remove = function () {
1856 this[0].parentNode.removeChild(this[0]);
1857 this.Group.parentNode.removeChild(this.Group);
1858 this.shape && this.shape.parentNode.removeChild(this.shape);
1860 Element.prototype.attr = function () {
1861 if (arguments.length == 1 && typeof arguments[0] == "string") {
1862 if (arguments[0] == "translation") {
1863 return this.translate();
1865 return this.attrs[arguments[0]];
1867 if (this.attrs && arguments.length == 1 && arguments[0] instanceof Array) {
1869 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1870 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1875 if (arguments.length == 2) {
1877 params[arguments[0]] = arguments[1];
1879 if (arguments.length == 1 && typeof arguments[0] == "object") {
1880 params = arguments[0];
1883 if (params.gradient) {
1884 addGrdientFill(this, params.gradient);
1886 if (params.text && this.type == "text") {
1887 this.node.string = params.text;
1890 this.node.id = params.id;
1892 setFillAndStroke(this, params);
1893 this.setBox(params);
1897 Element.prototype.toFront = function () {
1898 this.Group.parentNode.appendChild(this.Group);
1901 Element.prototype.toBack = function () {
1902 if (this.Group.parentNode.firstChild != this.Group) {
1903 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
1907 Element.prototype.insertAfter = function (element) {
1908 if (element.Group.nextSibling) {
1909 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
1911 element.Group.parentNode.appendChild(this.Group);
1915 Element.prototype.insertBefore = function (element) {
1916 element.Group.parentNode.insertBefore(this.Group, element.Group);
1919 var theCircle = function (vml, x, y, r) {
1920 var g = doc.createElement("rvml:group");
1921 var o = doc.createElement("rvml:oval");
1923 vml.canvas.appendChild(g);
1924 var res = new Element(o, g, vml);
1925 res.type = "circle";
1926 setFillAndStroke(res, {stroke: "#000", fill: "none"});
1930 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
1933 var theRect = function (vml, x, y, w, h, r) {
1934 var g = doc.createElement("rvml:group");
1935 var o = doc.createElement(r ? "rvml:roundrect" : "rvml:rect");
1937 o.arcsize = r / (Math.min(w, h));
1940 vml.canvas.appendChild(g);
1941 var res = new Element(o, g, vml);
1943 setFillAndStroke(res, {stroke: "#000"});
1949 res.setBox({x: x, y: y, width: w, height: h});
1952 var theEllipse = function (vml, x, y, rx, ry) {
1953 var g = doc.createElement("rvml:group");
1954 var o = doc.createElement("rvml:oval");
1956 vml.canvas.appendChild(g);
1957 var res = new Element(o, g, vml);
1958 res.type = "ellipse";
1959 setFillAndStroke(res, {stroke: "#000"});
1964 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
1967 var theImage = function (vml, src, x, y, w, h) {
1968 var g = doc.createElement("rvml:group");
1969 var o = doc.createElement("rvml:image");
1972 vml.canvas.appendChild(g);
1973 var res = new Element(o, g, vml);
1979 res.setBox({x: x, y: y, width: w, height: h});
1982 var theText = function (vml, x, y, text) {
1983 var g = doc.createElement("rvml:group"), gs = g.style;
1984 var el = doc.createElement("rvml:shape"), ol = el.style;
1985 var path = doc.createElement("rvml:path"), ps = path.style;
1986 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
1987 path.textpathok = true;
1988 ol.width = vml.width;
1989 ol.height = vml.height;
1990 gs.position = "absolute";
1993 gs.width = vml.width;
1994 gs.height = vml.height;
1995 var o = doc.createElement("rvml:textpath");
1998 o.coordsize = vml.coordsize;
1999 o.coordorigin = vml.coordorigin;
2001 el.appendChild(path);
2003 vml.canvas.appendChild(g);
2004 var res = new Element(o, g, vml);
2006 res.textpath = path;
2012 setFillAndStroke(res, {font: '10px "Arial"', stroke: "none", fill: "#000"});
2015 var setSize = function (width, height) {
2016 this.width = width || this.width;
2017 this.height = height || this.height;
2018 this.canvas.style.width = this.width + "px";
2019 this.canvas.style.height = this.height + "px";
2020 this.canvas.parentNode.style.clip = "rect(0 " + this.width + " " + this.height + " 0)";
2021 this.canvas.coordsize = this.width + " " + this.height;
2024 create = function () {
2025 // container, width, height
2026 // x, y, width, height
2027 var container, width, height;
2028 if (typeof arguments[0] == "string") {
2029 container = doc.getElementById(arguments[0]);
2030 width = arguments[1];
2031 height = arguments[2];
2033 if (typeof arguments[0] == "object") {
2034 container = arguments[0];
2035 width = arguments[1];
2036 height = arguments[2];
2038 if (typeof arguments[0] == "number") {
2042 width = arguments[2];
2043 height = arguments[3];
2046 throw new Error("VML container not found.");
2048 if (!doc.namespaces["rvml"]) {
2049 doc.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
2050 doc.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
2052 var c = doc.createElement("div"),
2053 d = doc.createElement("div"),
2054 r = paper.canvas = doc.createElement("rvml:group"),
2055 cs = c.style, rs = r.style;
2056 paper.width = width;
2057 paper.height = height;
2058 width = width || "320px";
2059 height = height || "200px";
2060 cs.clip = "rect(0 " + width + " " + height + " 0)";
2063 cs.position = "absolute";
2064 rs.position = "absolute";
2065 d.style.position = "relative";
2068 r.coordsize = (/%$/.test(width) ? width : parseFloat(width, 10)) + " " + (/%$/.test(height) ? height : parseFloat(height, 10));
2069 r.coordorigin = "0 0";
2071 var b = doc.createElement("rvml:rect"), bs = b.style;
2072 bs.left = bs.top = 0;
2073 bs.width = rs.width;
2074 bs.height = rs.height;
2075 b.filled = b.stroked = "f";
2080 if (container == 1) {
2081 doc.body.appendChild(d);
2082 cs.position = "absolute";
2094 cs.width = container.style.width = width;
2095 cs.height = container.style.height = height;
2096 if (container.firstChild) {
2097 container.insertBefore(d, container.firstChild);
2099 container.appendChild(d);
2102 for (var prop in paper) {
2103 container[prop] = paper[prop];
2105 for (var prop in R.fn) {
2106 if (!container[prop]) {
2107 container[prop] = R.fn[prop];
2110 container.clear = function () {
2112 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
2113 if (r.childNodes[i] != b) {
2114 todel.push(r.childNodes[i]);
2117 for (i = 0, ii = todel.length; i < ii; i++) {
2118 r.removeChild(todel[i]);
2123 paper.remove = function () {
2124 this.canvas.parentNode.parentNode.parentNode.removeChild(this.canvas.parentNode.parentNode);
2126 paper.safari = function () {};
2132 var addEvent = (function () {
2133 if (doc.addEventListener) {
2134 return function (obj, type, fn, element) {
2135 obj.addEventListener(type, function (e) {
2136 return fn.call(element, e);
2139 } else if (doc.attachEvent) {
2140 return function (obj, type, fn, element) {
2141 obj.attachEvent("on" + type, function (e) {
2142 return fn.call(element, e || win.event);
2147 var events = ["click", "dblclick", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup"];
2148 for (var i = events.length; i--;) {
2149 (function (eventName) {
2150 Element.prototype[eventName] = function (fn) {
2151 (typeof fn == "function") && addEvent(this.node, eventName, fn, this);
2156 paper.circle = function (x, y, r) {
2157 return theCircle(this, x, y, r);
2159 paper.rect = function (x, y, w, h, r) {
2160 return theRect(this, x, y, w, h, r);
2162 paper.ellipse = function (x, y, rx, ry) {
2163 return theEllipse(this, x, y, rx, ry);
2165 paper.path = function (params, pathString) {
2166 return thePath(params, pathString, this);
2168 paper.image = function (src, x, y, w, h) {
2169 return theImage(this, src, x, y, w, h);
2171 paper.text = function (x, y, text) {
2172 return theText(this, x, y, text);
2174 paper.group = function () {
2177 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
2178 color = color || "#000";
2179 var p = this.path({stroke: color, "stroke-width": 1})
2180 .moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).lineTo(x, y),
2182 columnWidth = w / wv;
2183 for (var i = 1; i < hv; i++) {
2184 p.moveTo(x, y + i * rowHeight).lineTo(x + w, y + i * rowHeight);
2186 for (var i = 1; i < wv; i++) {
2187 p.moveTo(x + i * columnWidth, y).lineTo(x + i * columnWidth, y + h);
2191 paper.pathfinder = function (p, path) {
2193 M: function (x, y) {
2196 C: function (x1, y1, x2, y2, x3, y3) {
2197 this.curveTo(x1, y1, x2, y2, x3, y3);
2199 Q: function (x1, y1, x2, y2) {
2200 this.qcurveTo(x1, y1, x2, y2);
2202 T: function (x, y) {
2203 this.qcurveTo(x, y);
2205 S: function (x1, y1, x2, y2) {
2206 p.curveTo(x1, y1, x2, y2);
2208 L: function (x, y) {
2212 this.lineTo(x, this.last.y);
2215 this.lineTo(this.last.x, y);
2217 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2218 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2225 path = pathToAbsolute(path);
2226 for (var i = 0, ii = path.length; i < ii; i++) {
2227 var b = path[i].shift();
2228 commands[b].apply(p, path[i]);
2231 paper.set = function (itemsArray) {
2232 return new Set(itemsArray);
2234 paper.setSize = setSize;
2235 Element.prototype.stop = function () {
2236 clearTimeout(this.animation_in_progress);
2238 Element.prototype.scale = function (x, y) {
2239 if (x == undefined && y == undefined) {
2240 return {x: this._.sx, y: this._.sy};
2245 var dirx = Math.round(x / Math.abs(x)),
2246 diry = Math.round(y / Math.abs(y)),
2247 s = this.node.style;
2248 dx = this.attr("x");
2249 dy = this.attr("y");
2250 cx = this.attr("cx");
2251 cy = this.attr("cy");
2252 if (dirx != 1 || diry != 1) {
2253 if (this.transformations) {
2254 this.transformations[2] = "scale(" + [dirx, diry] + ")";
2255 this.node.setAttribute("transform", this.transformations.join(" "));
2256 dx = (dirx < 0) ? -this.attr("x") - this.attrs.width * x * dirx / this._.sx : this.attr("x");
2257 dy = (diry < 0) ? -this.attr("y") - this.attrs.height * y * diry / this._.sy : this.attr("y");
2258 cx = this.attr("cx") * dirx;
2259 cy = this.attr("cy") * diry;
2261 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=" + dirx +
2262 ", M12=0, M21=0, M22=" + diry +
2263 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')";
2264 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2267 if (this.transformations) {
2268 this.transformations[2] = "";
2269 this.node.setAttribute("transform", this.transformations.join(" "));
2271 this.node.filterMatrix = "";
2272 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2275 switch (this.type) {
2279 width: this.attrs.width * x * dirx / this._.sx,
2280 height: this.attrs.height * y * diry / this._.sy,
2288 rx: this.attrs.rx * x * dirx / this._.sx,
2289 ry: this.attrs.ry * y * diry / this._.sy,
2290 r: this.attrs.r * x * diry / this._.sx,
2296 var path = pathToRelative(Raphael.parsePathString(this.attr("path"))),
2298 dim = pathDimensions(this.attrs.path),
2299 dx = -dim.width * (x - 1) / 2,
2300 dy = -dim.height * (y - 1) / 2;
2301 for (var i = 0, ii = path.length; i < ii; i++) {
2302 if (path[i][0].toUpperCase() == "M" && skip) {
2307 if (path[i][0].toUpperCase() == "A") {
2308 path[i][path[i].length - 2] *= x * dirx;
2309 path[i][path[i].length - 1] *= y * diry;
2311 for (var j = 1, jj = path[i].length; j < jj; j++) {
2312 path[i][j] *= (j % 2) ? x * dirx / this._.sx : y * diry / this._.sy;
2316 var dim2 = pathDimensions(path),
2317 dx = dim.x + dim.width / 2 - dim2.x - dim2.width / 2,
2318 dy = dim.y + dim.height / 2 - dim2.y - dim2.height / 2;
2319 path = pathToRelative(path);
2323 this.attr({path: path.join(" ")});
2330 Element.prototype.animate = function (params, ms, callback) {
2331 clearTimeout(this.animation_in_progress);
2336 for (var attr in params) {
2337 if (attr in availableAnimAttrs) {
2338 from[attr] = this.attr(attr);
2339 if (typeof from[attr] == "undefined") {
2340 from[attr] = availableAttrs[attr];
2342 to[attr] = params[attr];
2343 switch (availableAnimAttrs[attr]) {
2345 diff[attr] = (to[attr] - from[attr]) / ms;
2348 from[attr] = getRGB(from[attr]);
2349 var toColour = getRGB(to[attr]);
2351 r: (toColour.r - from[attr].r) / ms,
2352 g: (toColour.g - from[attr].g) / ms,
2353 b: (toColour.b - from[attr].b) / ms
2357 var pathes = pathEqualiser(from[attr], to[attr]);
2358 from[attr] = pathes[0];
2359 to[attr] = pathes[1];
2361 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2362 diff[attr][i] = [0];
2363 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2364 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2369 var values = params[attr].toString().split(separator),
2370 from2 = from[attr].toString().split(separator);
2371 if (attr == "translation") {
2372 from[attr] = [0, 0];
2373 diff[attr] = [values[0] / ms, values[1] / ms];
2374 } else if (attr == "rotation") {
2375 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2376 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2378 from[attr] = from[attr].split(separator);
2379 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][0]) / ms];
2385 var start = new Date(),
2389 var time = (new Date()).getTime() - start.getTime(),
2393 for (var attr in from) {
2394 switch (availableAnimAttrs[attr]) {
2396 now = +from[attr] + time * diff[attr];
2400 Math.round(from[attr].r + time * diff[attr].r),
2401 Math.round(from[attr].g + time * diff[attr].g),
2402 Math.round(from[attr].b + time * diff[attr].b)
2407 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2408 now[i] = [from[attr][i][0]];
2409 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2410 now[i][j] = from[attr][i][j] + time * diff[attr][i][j];
2412 now[i] = now[i].join(" ");
2414 now = now.join(" ");
2417 if (attr == "translation") {
2418 var x = diff[attr][0] * (time - prev),
2419 y = diff[attr][1] * (time - prev);
2422 now = [x, y].join(" ");
2423 } else if (attr == "rotation") {
2424 now = +from[attr][0] + time * diff[attr][0];
2425 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2427 now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1]].join(" ");
2431 if (attr == "font-size") {
2432 set[attr] = now + "px";
2438 that.animation_in_progress = setTimeout(arguments.callee, 0);
2441 (t.x || t.y) && that.translate(-t.x, -t.y);
2443 clearTimeout(that.animation_in_progress);
2445 (typeof callback == "function") && callback.call(that);
2453 var Set = function (itemsArray) {
2455 if (itemsArray && itemsArray.constructor == Array) {
2456 for (var i = itemsArray.length; i--;) {
2457 if (itemsArray[i].constructor == Element) {
2458 this.items[this.items.length] = itemsArray[i];
2463 Set.prototype.push = function (item) {
2464 if (item && item.constructor == Element) {
2465 var len = this.items.length;
2466 this.items[len] = item;
2471 Set.prototype.pull = function (id) {
2472 var res = this.items.splice(id, 1)[0];
2473 for (var j = id, jj = this.items.length; j < jj; j++) {
2474 this[j] = this[j + 1];
2476 delete this[jj + 1];
2479 for (var method in Element.prototype) {
2480 Set.prototype[method] = (function (methodname) {
2481 return function () {
2482 for (var i = this.items.length; i--;) {
2483 this.items[i][methodname].apply(this.items[i], arguments);
2489 Set.prototype.getBBox = function () {
2490 var x = [], y = [], w = [], h = [];
2491 for (var i = this.items.length; i--;) {
2492 var box = this.items[i].getBBox();
2495 w.push(box.x + box.width);
2496 h.push(box.y + box.height);
2498 x = Math.min.apply(Math, x);
2499 y = Math.min.apply(Math, y);
2503 width: Math.max.apply(Math, w) - x,
2504 height: Math.max.apply(Math, h) - y