2 * Raphael 1.0 RC1.6 - 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 window.Raphael = (function () {
10 var separator = /[, ]+/,
14 was: "Raphael" in window,
18 return create.apply(R, arguments);
21 availableAttrs = {"clip-rect": "0 0 10e9 10e9", cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, 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},
22 availableAnimAttrs = {"clip-rect": "csv", 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"},
23 events = ["click", "dblclick", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup"];
24 R.version = "1.0 RC1.6";
25 R.type = (window.SVGAngle || document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
26 R.svg = !(R.vml = R.type == "VML");
29 R.is = function (o, type) {
30 type = (type + "").toLowerCase();
31 if ((type == "object" || type == "undefined") && typeof o == type) {
34 if (o == null && type == "null") {
37 return Object.prototype.toString.call(o).replace(/^\[object\s+|\]$/gi, "").toLowerCase() == type;
39 R.setWindow = function (newwin) {
44 R.hsb2rgb = cacher(function (hue, saturation, brightness) {
45 if (R.is(hue, "object") && "h" in hue && "s" in hue && "b" in hue) {
53 if (brightness == 0) {
54 return {r: 0, g: 0, b: 0, hex: "#000"};
56 if (hue > 1 || saturation > 1 || brightness > 1) {
61 var i = Math.floor(hue * 6),
63 p = brightness * (1 - saturation),
64 q = brightness * (1 - (saturation * f)),
65 t = brightness * (1 - (saturation * (1 - f)));
66 red = [brightness, q, p, p, t, brightness, brightness][i];
67 green = [t, brightness, brightness, q, p, p, t][i];
68 blue = [p, p, t, brightness, brightness, q, p][i];
72 var rgb = {r: red, g: green, b: blue},
73 r = Math.round(red).toString(16),
74 g = Math.round(green).toString(16),
75 b = Math.round(blue).toString(16);
85 rgb.hex = "#" + r + g + b;
88 R.rgb2hsb = cacher(function (red, green, blue) {
89 if (R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
94 if (R.is(red, "string")) {
95 var clr = R.getRGB(red);
100 if (red > 1 || green > 1 || blue > 1) {
105 var max = Math.max(red, green, blue),
106 min = Math.min(red, green, blue),
111 return {h: 0, s: 0, b: max};
113 var delta = (max - min);
114 saturation = delta / max;
116 hue = (green - blue) / delta;
117 } else if (green == max) {
118 hue = 2 + ((blue - red) / delta);
120 hue = 4 + ((red - green) / delta);
130 return {h: hue, s: saturation, b: brightness};
132 R._path2string = function () {
135 for (var i = 0, ii = this.length; i < ii; i++) {
136 for (var j = 0, jj = this[i].length; j < jj; j++) {
138 j && j != jj - 1 && (res += ",");
140 i != ii - 1 && (res += "\n");
142 return res.replace(/,(?=-)/g, "");
144 function cacher(f, scope, postprocessor) {
146 var arg = Array.prototype.splice.call(arguments, 0, arguments.length),
147 args = arg.join("\u25ba");
148 newf.cache = newf.cache || {};
149 newf.count = newf.count || [];
150 if (args in newf.cache) {
151 return postprocessor ? postprocessor(newf.cache[args]) : newf.cache[args];
153 if (newf.count.length > 1000) {
154 delete newf.cache[newf.count.unshift()];
156 newf.count.push(args);
157 newf.cache[args] = f.apply(scope, arg);
158 return postprocessor ? postprocessor(newf.cache[args]) : newf.cache[args];
163 R.getRGB = cacher(function (colour) {
164 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"},
166 if ((colour + "").toLowerCase() in htmlcolors) {
167 colour = htmlcolors[(colour + "").toLowerCase()];
170 return {r: 0, g: 0, b: 0, hex: "#000"};
172 if (colour == "none") {
173 return {r: -1, g: -1, b: -1, hex: "none"};
178 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*\)|hs[bl]\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hs[bl]\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i);
181 blue = parseInt(rgb[2].substring(5), 16);
182 green = parseInt(rgb[2].substring(3, 5), 16);
183 red = parseInt(rgb[2].substring(1, 3), 16);
186 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
187 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
188 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
191 rgb = rgb[4].split(/\s*,\s*/);
192 red = parseFloat(rgb[0]);
193 green = parseFloat(rgb[1]);
194 blue = parseFloat(rgb[2]);
197 rgb = rgb[5].split(/\s*,\s*/);
198 red = parseFloat(rgb[0]) * 2.55;
199 green = parseFloat(rgb[1]) * 2.55;
200 blue = parseFloat(rgb[2]) * 2.55;
203 rgb = rgb[6].split(/\s*,\s*/);
204 red = parseFloat(rgb[0]);
205 green = parseFloat(rgb[1]);
206 blue = parseFloat(rgb[2]);
207 return R.hsb2rgb(red, green, blue);
210 rgb = rgb[7].split(/\s*,\s*/);
211 red = parseFloat(rgb[0]) * 2.55;
212 green = parseFloat(rgb[1]) * 2.55;
213 blue = parseFloat(rgb[2]) * 2.55;
214 return R.hsb2rgb(red, green, blue);
216 rgb = {r: red, g: green, b: blue};
217 var r = Math.round(red).toString(16),
218 g = Math.round(green).toString(16),
219 b = Math.round(blue).toString(16);
220 (r.length == 1) && (r = "0" + r);
221 (g.length == 1) && (g = "0" + g);
222 (b.length == 1) && (b = "0" + b);
223 rgb.hex = "#" + r + g + b;
226 res = {r: -1, g: -1, b: -1, hex: "none", error: 1};
230 R.getColor = function (value) {
231 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
232 rgb = this.hsb2rgb(start.h, start.s, start.b);
238 this.getColor.start = {h: 0, s: 1, b: start.b};
243 R.getColor.reset = function () {
247 R.parsePathString = cacher(function (pathString) {
251 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
253 if (R.is(pathString, "array") && R.is(pathString[0], "array")) { // rough assumption
254 data = pathClone(pathString);
257 (pathString + "").replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, function (a, b, c) {
259 name = b.toLowerCase();
260 c.replace(/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig, function (a, b) {
261 b && params.push(+b);
263 while (params.length >= paramCounts[name]) {
264 data.push([b].concat(params.splice(0, paramCounts[name])));
265 if (!paramCounts[name]) {
271 data.toString = R._path2string;
274 var pathDimensions = cacher(function (path) {
276 return {x: 0, y: 0, width: 0, height: 0};
278 path = path2curve(path);
283 for (var i = 0, ii = path.length; i < ii; i++) {
284 if (path[i][0] == "M") {
290 var dim = curveDim(x, y, path[i][1], path[i][2], path[i][3], path[i][4], path[i][5], path[i][6]);
291 X = X.concat(dim.min.x, dim.max.x);
292 Y = Y.concat(dim.min.y, dim.max.y);
295 var xmin = Math.min.apply(0, X),
296 ymin = Math.min.apply(0, Y);
300 width: Math.max.apply(0, X) - xmin,
301 height: Math.max.apply(0, Y) - ymin
304 pathClone = function (pathArray) {
306 if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption
307 pathArray = R.parsePathString(pathArray);
309 for (var i = 0, ii = pathArray.length; i < ii; i++) {
311 for (var j = 0, jj = pathArray[i].length; j < jj; j++) {
312 res[i][j] = pathArray[i][j];
315 res.toString = R._path2string;
318 pathToRelative = cacher(function (pathArray) {
319 if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption
320 pathArray = R.parsePathString(pathArray);
328 if (pathArray[0][0] == "M") {
334 res.push(["M", x, y]);
336 for (var i = start, ii = pathArray.length; i < ii; i++) {
339 if (pa[0] != pa[0].toLowerCase()) {
340 r[0] = pa[0].toLowerCase();
348 r[6] = +(pa[6] - x).toFixed(3);
349 r[7] = +(pa[7] - y).toFixed(3);
352 r[1] = +(pa[1] - y).toFixed(3);
358 for (var j = 1, jj = pa.length; j < jj; j++) {
359 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
368 for (var k = 0, kk = pa.length; k < kk; k++) {
372 var len = res[i].length;
379 x += +res[i][len - 1];
382 y += +res[i][len - 1];
385 x += +res[i][len - 2];
386 y += +res[i][len - 1];
389 res.toString = R._path2string;
392 pathToAbsolute = cacher(function (pathArray) {
393 if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption
394 pathArray = R.parsePathString(pathArray);
402 if (pathArray[0][0] == "M") {
403 x = +pathArray[0][1];
404 y = +pathArray[0][2];
408 res[0] = ["M", x, y];
410 for (var i = start, ii = pathArray.length; i < ii; i++) {
413 if (pa[0] != (pa[0] + "").toUpperCase()) {
414 r[0] = (pa[0] + "").toUpperCase();
435 for (var j = 1, jj = pa.length; j < jj; j++) {
436 r[j] = +pa[j] + ((j % 2) ? x : y);
440 for (var k = 0, kk = pa.length; k < kk; k++) {
456 x = res[i][res[i].length - 2];
457 y = res[i][res[i].length - 1];
460 res.toString = R._path2string;
463 l2c = function (x1, y1, x2, y2) {
464 return [x1, y1, x2, y2, x2, y2];
466 q2c = function (x1, y1, ax, ay, x2, y2) {
478 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
479 // for more information of where this math came from visit:
480 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
481 var _120 = Math.PI * 120 / 180,
482 rad = Math.PI / 180 * (+angle || 0),
485 rotate = cacher(function (x, y, rad) {
486 var X = x * Math.cos(rad) - y * Math.sin(rad),
487 Y = x * Math.sin(rad) + y * Math.cos(rad);
491 xy = rotate(x1, y1, -rad);
494 xy = rotate(x2, y2, -rad);
497 var cos = Math.cos(Math.PI / 180 * angle),
498 sin = Math.sin(Math.PI / 180 * angle),
501 rx = Math.max(rx, Math.abs(x));
502 ry = Math.max(ry, Math.abs(y));
505 k = (large_arc_flag == sweep_flag ? -1 : 1) *
506 Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
507 cx = k * rx * y / ry + (x1 + x2) / 2,
508 cy = k * -ry * x / rx + (y1 + y2) / 2,
509 f1 = Math.asin((y1 - cy) / ry),
510 f2 = Math.asin((y2 - cy) / ry);
512 f1 = x1 < cx ? Math.PI - f1 : f1;
513 f2 = x2 < cx ? Math.PI - f2 : f2;
514 f1 < 0 && (f1 = Math.PI * 2 + f1);
515 f2 < 0 && (f2 = Math.PI * 2 + f2);
516 if (sweep_flag && f1 > f2) {
517 f1 = f1 - Math.PI * 2;
519 if (!sweep_flag && f2 > f1) {
520 f2 = f2 - Math.PI * 2;
529 if (Math.abs(df) > _120) {
533 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
534 x2 = cx + rx * Math.cos(f2);
535 y2 = cy + ry * Math.sin(f2);
536 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
539 var c1 = Math.cos(f1),
543 t = Math.tan(df / 4),
547 m2 = [x1 + hx * s1, y1 - hy * c1],
548 m3 = [x2 + hx * s2, y2 - hy * c2],
550 m2[0] = 2 * m1[0] - m2[0];
551 m2[1] = 2 * m1[1] - m2[1];
553 return [m2, m3, m4].concat(res);
555 res = [m2, m3, m4].concat(res).join(",").split(",");
557 for (var i = 0, ii = res.length; i < ii; i++) {
558 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
563 findDotAtSegment = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
564 var x = Math.pow(1 - t, 3) * p1x + Math.pow(1 - t, 2) * 3 * t * c1x + (1 - t) * 3 * t * t * c2x + Math.pow(t, 3) * p2x,
565 y = Math.pow(1 - t, 3) * p1y + Math.pow(1 - t, 2) * 3 * t * c1y + (1 - t) * 3 * t * t * c2y + Math.pow(t, 3) * p2y,
566 mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
567 my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
568 nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
569 ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
570 ax = (1 - t) * p1x + t * c1x,
571 ay = (1 - t) * p1y + t * c1y,
572 cx = (1 - t) * c2x + t * p2x,
573 cy = (1 - t) * c2y + t * p2y;
574 return {x: x, y: y, m: {x: mx, y: my}, n: {x: nx, y: ny}, start: {x: ax, y: ay}, end: {x: cx, y: cy}};
576 curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
577 var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
578 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
580 t1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 / a,
581 t2 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2 / a,
584 dot1 = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1 > 0 && t1 < 1 ? t1 : 0),
585 dot2 = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2 > 0 && t2 < 1 ? t2 : 0);
586 x = x.concat(dot1.x, dot2.x);
587 y = y.concat(dot1.y, dot2.y);
588 a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
589 b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
591 t1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 / a;
592 t2 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2 / a;
593 dot1 = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1 > 0 && t1 < 1 ? t1 : 0);
594 dot2 = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2 > 0 && t2 < 1 ? t2 : 0);
595 x = x.concat(dot1.x, dot2.x);
596 y = y.concat(dot1.y, dot2.y);
598 min: {x: Math.min.apply(Math, x), y: Math.min.apply(Math, y)},
599 max: {x: Math.max.apply(Math, x), y: Math.max.apply(Math, y)}
602 path2curve = cacher(function (path, path2) {
603 var p = pathToAbsolute(path),
604 p2 = path2 && pathToAbsolute(path2),
605 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
606 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
607 processPath = function (path, d) {
610 return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
612 !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
619 path = ["C"].concat(a2c.apply(0, [d.x, d.y].concat(path.slice(1))));
622 nx = d.x + (d.x - (d.bx || d.x));
623 ny = d.y + (d.y - (d.by || d.y));
624 path = ["C", nx, ny].concat(path.slice(1));
627 d.qx = d.x + (d.x - (d.qx || d.x));
628 d.qy = d.y + (d.y - (d.qy || d.y));
629 path = ["C"].concat(q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
634 path = ["C"].concat(q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
637 path = ["C"].concat(l2c(d.x, d.y, path[1], path[2]));
640 path = ["C"].concat(l2c(d.x, d.y, path[1], d.y));
643 path = ["C"].concat(l2c(d.x, d.y, d.x, path[1]));
646 path = ["C"].concat(l2c(d.x, d.y, d.X, d.Y));
651 fixArc = function (pp, i) {
652 if (pp[i].length > 7) {
656 pp.splice(i++, 0, ["C"].concat(pi.splice(0, 6)));
659 ii = Math.max(p.length, p2 && p2.length || 0);
662 fixM = function (path1, path2, a1, a2, i) {
663 if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
664 path2.splice(i, 0, ["M", a2.x, a2.y]);
669 ii = Math.max(p.length, p2 && p2.length || 0);
672 for (var i = 0, ii = Math.max(p.length, p2 && p2.length || 0); i < ii; i++) {
673 p[i] = processPath(p[i], attrs);
675 p2 && (p2[i] = processPath(p2[i], attrs2));
677 fixM(p, p2, attrs, attrs2, i);
678 fixM(p2, p, attrs2, attrs, i);
682 seg2len = p2 && seg2.length;
683 attrs.x = seg[seglen - 2];
684 attrs.y = seg[seglen - 1];
685 attrs.bx = parseFloat(seg[seglen - 4]) || attrs.x;
686 attrs.by = parseFloat(seg[seglen - 3]) || attrs.y;
687 attrs2.bx = p2 && (parseFloat(seg2[seg2len - 4]) || attrs2.x);
688 attrs2.by = p2 && (parseFloat(seg2[seg2len - 3]) || attrs2.y);
689 attrs2.x = p2 && seg2[seg2len - 2];
690 attrs2.y = p2 && seg2[seg2len - 1];
692 return p2 ? [p, p2] : p;
694 parseDots = cacher(function (gradient) {
696 for (var i = 0, ii = gradient.length; i < ii; i++) {
698 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
699 dot.color = R.getRGB(par[1]);
700 if (dot.color.error) {
703 dot.color = dot.color.hex;
704 par[2] && (dot.offset = par[2] + "%");
707 for (var i = 1, ii = dots.length - 1; i < ii; i++) {
708 if (!dots[i].offset) {
709 var start = parseFloat(dots[i - 1].offset || 0),
711 for (var j = i + 1; j < ii; j++) {
712 if (dots[j].offset) {
713 end = dots[j].offset;
721 end = parseFloat(end);
722 var d = (end - start) / (j - i + 1);
725 dots[i].offset = start + "%";
731 getContainer = function () {
737 if (R.is(arguments[0], "string") || R.is(arguments[0], "object")) {
738 if (R.is(arguments[0], "string")) {
739 container = doc.getElementById(arguments[0]);
741 container = arguments[0];
743 if (container.tagName) {
744 if (arguments[1] == null) {
746 container: container,
747 width: container.style.pixelWidth || container.offsetWidth,
748 height: container.style.pixelHeight || container.offsetHeight
751 return {container: container, width: arguments[1], height: arguments[2]};
754 } else if (R.is(arguments[0], "number") && arguments.length > 3) {
755 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
758 plugins = function (con, add) {
760 for (var prop in add) if (add.hasOwnProperty(prop) && !(prop in con)) {
761 switch (typeof add[prop]) {
764 con[prop] = con === that ? f : function () { return f.apply(that, arguments); };
768 con[prop] = con[prop] || {};
769 plugins.call(this, con[prop], add[prop]);
772 con[prop] = add[prop];
780 paper.svgns = "http://www.w3.org/2000/svg";
781 paper.xlink = "http://www.w3.org/1999/xlink";
782 var round = function (num) {
783 return +num + (Math.floor(num) == num) * .5;
785 var roundPath = function (path) {
786 for (var i = 0, ii = path.length; i < ii; i++) {
787 if (path[i][0].toLowerCase() != "a") {
788 for (var j = 1, jj = path[i].length; j < jj; j++) {
789 path[i][j] = round(path[i][j]);
792 path[i][6] = round(path[i][6]);
793 path[i][7] = round(path[i][7]);
798 var $ = function (el, attr) {
800 for (var key in attr) if (attr.hasOwnProperty(key)) {
801 el.setAttribute(key, attr[key]);
804 return doc.createElementNS(paper.svgns, el);
807 R.toString = function () {
808 return "Your browser supports SVG.\nYou are running Rapha\u00ebl " + this.version;
810 var thePath = function (pathString, SVG) {
812 SVG.canvas && SVG.canvas.appendChild(el);
813 var p = new Element(el, SVG);
815 setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
818 var addGradientFill = function (o, gradient, SVG) {
822 gradient = (gradient + "").replace(/^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/, function (all, _fx, _fy) {
825 fx = parseFloat(_fx);
826 fy = parseFloat(_fy);
827 if (Math.pow(fx - .5, 2) + Math.pow(fy - .5, 2) > .25) {
828 fy = Math.sqrt(.25 - Math.pow(fx - .5, 2)) + .5;
833 gradient = gradient.split(/\s*\-\s*/);
834 if (type == "linear") {
835 var angle = gradient.shift();
836 angle = -parseFloat(angle);
840 var vector = [0, 0, Math.cos(angle * Math.PI / 180), Math.sin(angle * Math.PI / 180)],
841 max = 1 / (Math.max(Math.abs(vector[2]), Math.abs(vector[3])) || 1);
845 vector[0] = -vector[2];
849 vector[1] = -vector[3];
853 var dots = parseDots(gradient);
857 var el = $(type + "Gradient");
858 el.id = "r" + (R.idGenerator++).toString(36);
859 type == "radial" ? $(el, {fx: fx, fy: fy}) : $(el, {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]});
860 SVG.defs.appendChild(el);
861 for (var i = 0, ii = dots.length; i < ii; i++) {
862 var stop = $("stop");
864 offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%",
865 "stop-color": dots[i].color || "#fff"
867 el.appendChild(stop);
870 fill: "url(#" + el.id + ")",
879 var updatePosition = function (o) {
880 var bbox = o.getBBox();
881 $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
883 var setFillAndStroke = function (o, params) {
890 "-..": [3, 1, 1, 1, 1, 1],
896 "--..": [8, 3, 1, 3, 1, 3]
900 rot = o.attr("rotation"),
901 addDashes = function (o, value) {
902 value = dasharray[(value + "").toLowerCase()];
904 var width = o.attrs["stroke-width"] || "1",
905 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
907 var i = value.length;
909 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
911 $(node, {"stroke-dasharray": dashes.join(",")});
914 parseFloat(rot) && o.rotate(0, true);
915 for (var att in params) if (params.hasOwnProperty(att)) {
916 if (!(att in availableAttrs)) {
919 var value = params[att];
926 var pn = node.parentNode;
927 if (pn.tagName.toLowerCase() != "a") {
929 pn.insertBefore(hl, node);
930 hl.appendChild(node);
933 pn.setAttributeNS(o.paper.xlink, att, value);
936 var rect = (value + "").split(separator);
937 if (rect.length == 4) {
938 o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
939 var el = $("clipPath"),
941 el.id = "r" + (R.idGenerator++).toString(36);
949 o.paper.defs.appendChild(el);
950 $(node, {"clip-path": "url(#" + el.id + ")"});
954 var clip = doc.getElementById(node.getAttribute("clip-path").replace(/(^url\(#|\)$)/g, ""));
955 clip && clip.parentNode.removeChild(clip);
956 $(node, {"clip-path": ""});
961 if (value && o.type == "path") {
962 attrs.path = roundPath(pathToAbsolute(value));
963 $(node, {d: attrs.path});
967 node.setAttribute(att, value);
976 value = -attrs.x - (attrs.width || 0);
979 if (att == "rx" && o.type == "rect") {
983 node.setAttribute(att, value);
984 o.pattern && updatePosition(o);
987 node.setAttribute(att, value);
996 value = -attrs.y - (attrs.height || 0);
999 if (att == "ry" && o.type == "rect") {
1003 node.setAttribute(att, value);
1004 o.pattern && updatePosition(o);
1007 if (o.type == "rect") {
1008 $(node, {rx: value, ry: value});
1010 node.setAttribute(att, value);
1014 if (o.type == "image") {
1015 node.setAttributeNS(o.paper.xlink, "href", value);
1018 case "stroke-width":
1019 node.style.strokeWidth = value;
1020 // Need following line for Firefox
1021 node.setAttribute(att, value);
1022 if (attrs["stroke-dasharray"]) {
1023 addDashes(o, attrs["stroke-dasharray"]);
1026 case "stroke-dasharray":
1027 addDashes(o, value);
1031 o.rotate(value, true);
1034 var xy = (value + "").split(separator);
1035 o.translate((+xy[0] + 1 || 2) - 1, (+xy[1] + 1 || 2) - 1);
1038 var xy = (value + "").split(separator);
1039 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1042 var isURL = (value + "").match(/^url\(['"]?([^\)]+)['"]?\)$/i);
1044 var el = $("pattern"),
1046 el.id = "r" + (R.idGenerator++).toString(36);
1047 $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse"});
1049 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1052 var img = doc.createElement("img");
1053 img.style.position = "absolute";
1054 img.style.top = "-9999em";
1055 img.style.left = "-9999em";
1056 img.onload = function () {
1057 $(el, {width: this.offsetWidth, height: this.offsetHeight});
1058 $(ig, {width: this.offsetWidth, height: this.offsetHeight});
1059 doc.body.removeChild(this);
1062 doc.body.appendChild(img);
1064 o.paper.defs.appendChild(el);
1065 node.style.fill = "url(#" + el.id + ")";
1066 $(node, {fill: "url(#" + el.id + ")"});
1068 o.pattern && updatePosition(o);
1071 if (!R.getRGB(value).error) {
1072 delete params.gradient;
1073 delete attrs.gradient;
1074 if (!R.is(attrs.opacity, "undefined") && R.is(params.opacity, "undefined") ) {
1075 node.style.opacity = attrs.opacity;
1076 // Need following line for Firefox
1077 $(node, {opacity: attrs.opacity});
1079 if (!R.is(attrs["fill-opacity"], "undefined") && R.is(params["fill-opacity"], "undefined") ) {
1080 node.style.fillOpacity = attrs["fill-opacity"];
1081 // Need following line for Firefox
1082 $(node, {"fill-opacity": attrs["fill-opacity"]});
1084 } else if ((o.type in {circle: 1, ellipse: 1} || (value + "").charAt(0) != "r") && addGradientFill(node, value, o.paper)) {
1085 attrs.gradient = value;
1086 attrs.fill = "none";
1090 node.style[att] = R.getRGB(value).hex;
1091 // Need following line for Firefox
1092 node.setAttribute(att, R.getRGB(value).hex);
1095 (o.type in {circle: 1, ellipse: 1} || (value + "").charAt(0) != "r") && addGradientFill(node, value, o.paper);
1098 case "fill-opacity":
1099 if (attrs.gradient) {
1100 var gradient = doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
1102 var stops = gradient.getElementsByTagName("stop");
1103 stops[stops.length - 1].setAttribute("stop-opacity", value);
1108 att == "font-size" && (value = parseInt(value, 10) + "px");
1109 var cssrule = att.replace(/(\-.)/g, function (w) {
1110 return w.substring(1).toUpperCase();
1112 node.style[cssrule] = value;
1113 // Need following line for Firefox
1114 node.setAttribute(att, value);
1119 tuneText(o, params);
1120 parseInt(rot, 10) && o.rotate(rot, true);
1123 var tuneText = function (el, params) {
1124 if (el.type != "text" || !("text" in params || "font" in params || "font-size" in params || "x" in params || "y" in params)) {
1129 fontSize = node.firstChild ? parseInt(doc.defaultView.getComputedStyle(node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
1131 if ("text" in params) {
1132 while (node.firstChild) {
1133 node.removeChild(node.firstChild);
1135 var texts = (params.text + "").split("\n");
1136 for (var i = 0, ii = texts.length; i < ii; i++) {
1137 var tspan = $("tspan");
1138 i && $(tspan, {dy: fontSize * leading, x: a.x});
1139 tspan.appendChild(doc.createTextNode(texts[i]));
1140 node.appendChild(tspan);
1143 var texts = node.getElementsByTagName("tspan");
1144 for (var i = 0, ii = texts.length; i < ii; i++) {
1145 i && $(texts[i], {dy: fontSize * leading, x: a.x});
1149 var bb = el.getBBox(),
1150 dif = a.y - (bb.y + bb.height / 2);
1151 dif && $(node, {y: a.y + dif});
1153 var Element = function (node, svg) {
1158 node.raphael = this;
1160 this.attrs = this.attrs || {};
1161 this.transformations = []; // rotate, translate, scale
1165 rt: {deg: 0, cx: 0, cy: 0},
1170 Element.prototype.rotate = function (deg, cx, cy) {
1173 return [this._.rt.deg, this._.rt.cx, this._.rt.cy].join(" ");
1175 return this._.rt.deg;
1177 var bbox = this.getBBox();
1178 deg = (deg + "").split(separator);
1179 if (deg.length - 1) {
1180 cx = parseFloat(deg[1]);
1181 cy = parseFloat(deg[2]);
1183 deg = parseFloat(deg[0]);
1185 this._.rt.deg = deg;
1187 this._.rt.deg += deg;
1189 (cy == null) && (cx = null);
1192 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1193 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1194 if (this._.rt.deg) {
1195 this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
1196 this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
1198 this.transformations[0] = "";
1199 this.clip && $(this.clip, {transform: ""});
1201 $(this.node, {transform: this.transformations.join(" ")});
1204 Element.prototype.hide = function () {
1205 this.node.style.display = "none";
1208 Element.prototype.show = function () {
1209 this.node.style.display = "block";
1212 Element.prototype.remove = function () {
1213 this.node.parentNode.removeChild(this.node);
1215 Element.prototype.getBBox = function () {
1216 if (this.type == "path") {
1217 return pathDimensions(this.attrs.path);
1219 if (this.node.style.display == "none") {
1225 bbox = this.node.getBBox();
1227 // Firefox 3.0.x plays badly here
1231 if (this.type == "text") {
1232 bbox = {x: bbox.x, y: Infinity, width: bbox.width, height: 0};
1233 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1234 var bb = this.node.getExtentOfChar(i);
1235 (bb.y < bbox.y) && (bbox.y = bb.y);
1236 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1239 hide && this.hide();
1242 Element.prototype.attr = function () {
1243 if (arguments.length == 1 && R.is(arguments[0], "string")) {
1244 if (arguments[0] == "translation") {
1245 return this.translate();
1247 if (arguments[0] == "rotation") {
1248 return this.rotate();
1250 if (arguments[0] == "scale") {
1251 return this.scale();
1253 return this.attrs[arguments[0]];
1255 if (arguments.length == 1 && R.is(arguments[0], "array")) {
1257 for (var j in arguments[0]) if (arguments[0].hasOwnProperty(j)) {
1258 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1262 if (arguments.length == 2) {
1264 params[arguments[0]] = arguments[1];
1265 setFillAndStroke(this, params);
1266 } else if (arguments.length == 1 && R.is(arguments[0], "object")) {
1267 setFillAndStroke(this, arguments[0]);
1271 Element.prototype.toFront = function () {
1272 this.node.parentNode.appendChild(this.node);
1275 Element.prototype.toBack = function () {
1276 if (this.node.parentNode.firstChild != this.node) {
1277 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1281 Element.prototype.insertAfter = function (element) {
1282 if (element.node.nextSibling) {
1283 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1285 element.node.parentNode.appendChild(this.node);
1289 Element.prototype.insertBefore = function (element) {
1290 var node = element.node;
1291 node.parentNode.insertBefore(this.node, node);
1295 var theCircle = function (svg, x, y, r) {
1298 var el = $("circle");
1299 svg.canvas && svg.canvas.appendChild(el);
1300 var res = new Element(el, svg);
1301 res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1302 res.type = "circle";
1306 var theRect = function (svg, x, y, w, h, r) {
1310 svg.canvas && svg.canvas.appendChild(el);
1311 var res = new Element(el, svg);
1312 res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1317 var theEllipse = function (svg, x, y, rx, ry) {
1320 var el = $("ellipse");
1321 svg.canvas && svg.canvas.appendChild(el);
1322 var res = new Element(el, svg);
1323 res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1324 res.type = "ellipse";
1328 var theImage = function (svg, src, x, y, w, h) {
1329 var el = $("image");
1330 $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1331 el.setAttributeNS(svg.xlink, "href", src);
1332 svg.canvas && svg.canvas.appendChild(el);
1333 var res = new Element(el, svg);
1334 res.attrs = {x: x, y: y, width: w, height: h, src: src};
1338 var theText = function (svg, x, y, text) {
1340 $(el, {x: x, y: y, "text-anchor": "middle"});
1341 svg.canvas && svg.canvas.appendChild(el);
1342 var res = new Element(el, svg);
1343 res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
1345 setFillAndStroke(res, res.attrs);
1348 var setSize = function (width, height) {
1349 this.width = width || this.width;
1350 this.height = height || this.height;
1351 this.canvas.setAttribute("width", this.width);
1352 this.canvas.setAttribute("height", this.height);
1355 var create = function () {
1356 var con = getContainer.apply(null, arguments),
1357 container = con && con.container,
1361 height = con.height;
1363 throw new Error("SVG container not found.");
1365 paper.canvas = $("svg");
1366 var cnvs = paper.canvas,
1368 cnvs.setAttribute("width", width || 512);
1369 paper.width = width || 512;
1370 cnvs.setAttribute("height", height || 342);
1371 paper.height = height || 342;
1372 if (container == 1) {
1373 doc.body.appendChild(cnvs);
1374 stl.position = "absolute";
1375 stl.left = x + "px";
1378 if (container.firstChild) {
1379 container.insertBefore(cnvs, container.firstChild);
1381 container.appendChild(cnvs);
1386 clear: function () {
1387 while (this.canvas.firstChild) {
1388 this.canvas.removeChild(this.canvas.firstChild);
1390 this.desc = $("desc");
1391 this.defs = $("defs");
1392 this.desc.appendChild(doc.createTextNode("Created with Rapha\u00ebl"));
1393 this.canvas.appendChild(this.desc);
1394 this.canvas.appendChild(this.defs);
1397 for (var prop in paper) if (paper.hasOwnProperty(prop)) {
1398 if (prop != "create") {
1399 container[prop] = paper[prop];
1402 plugins.call(container, container, R.fn);
1404 container.raphael = R;
1407 paper.remove = function () {
1408 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1414 var path2vml = function (path) {
1415 var pa = path2curve(path);
1416 for (var i = 0, ii = pa.length; i < ii; i++) {
1417 pa[i][0] = (pa[i][0] + "").toLowerCase();
1418 pa[i][0] == "z" && (pa[i][0] = "x");
1419 for (var j = 1, jj = pa[i].length; j < jj; j++) {
1420 pa[i][j] = Math.round(pa[i][j]);
1425 R.toString = function () {
1426 return "Your browser doesn\u2019t support SVG. Assuming it is Internet Explorer and falling down to VML.\nYou are running Rapha\u00ebl " + this.version;
1428 var thePath = function (pathString, VML) {
1429 var g = createNode("group"), gl = g.style;
1430 gl.position = "absolute";
1433 gl.width = VML.width + "px";
1434 gl.height = VML.height + "px";
1435 g.coordsize = VML.coordsize;
1436 g.coordorigin = VML.coordorigin;
1437 var el = createNode("shape"), ol = el.style;
1438 ol.width = VML.width + "px";
1439 ol.height = VML.height + "px";
1441 el.coordsize = this.coordsize;
1442 el.coordorigin = this.coordorigin;
1444 var p = new Element(el, g, VML);
1445 p.isAbsolute = true;
1450 p.attrs.path = R.parsePathString(pathString);
1451 p.node.path = path2vml(p.attrs.path);
1453 setFillAndStroke(p, {fill: "none", stroke: "#000"});
1455 VML.canvas.appendChild(g);
1458 var setFillAndStroke = function (o, params) {
1459 o.attrs = o.attrs || {};
1465 for (var par in params) if (params.hasOwnProperty(par)) {
1466 a[par] = params[par];
1468 params.href && (node.href = params.href);
1469 params.title && (node.title = params.title);
1470 params.target && (node.target = params.target);
1471 if (params.path && o.type == "path") {
1472 a.path = R.parsePathString(params.path);
1473 node.path = path2vml(a.path);
1475 if (params.rotation != null) {
1476 o.rotate(params.rotation, true);
1478 if (params.translation) {
1479 xy = (params.translation + "").split(separator);
1480 o.translate(xy[0], xy[1]);
1483 xy = (params.scale + "").split(separator);
1484 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1486 if ("clip-rect" in params) {
1487 var rect = (params["clip-rect"] + "").split(separator);
1488 if (rect.length == 4) {
1489 rect[2] = +rect[2] + (+rect[0]);
1490 rect[3] = +rect[3] + (+rect[1]);
1491 var div = node.clipRect || doc.createElement("div"),
1493 group = node.parentNode;
1494 dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
1495 if (!node.clipRect) {
1496 dstyle.position = "absolute";
1499 dstyle.width = o.paper.width + "px";
1500 dstyle.height = o.paper.height + "px";
1501 group.parentNode.insertBefore(div, group);
1502 div.appendChild(group);
1503 node.clipRect = div;
1506 if (!params["clip-rect"]) {
1507 node.clipRect && (node.clipRect.style.clip = "");
1510 if (o.type == "image" && params.src) {
1511 node.src = params.src;
1513 if (o.type == "image" && params.opacity) {
1514 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1515 s.filter = (node.filterMatrix || "") + (node.filterOpacity || "");
1517 params.font && (s.font = params.font);
1518 params["font-family"] && (s.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, "") + '"');
1519 params["font-size"] && (s.fontSize = params["font-size"]);
1520 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1521 params["font-style"] && (s.fontStyle = params["font-style"]);
1522 if (params.opacity != null ||
1523 params["stroke-width"] != null ||
1524 params.fill != null ||
1525 params.stroke != null ||
1526 params["stroke-width"] != null ||
1527 params["stroke-opacity"] != null ||
1528 params["fill-opacity"] != null ||
1529 params["stroke-dasharray"] != null ||
1530 params["stroke-miterlimit"] != null ||
1531 params["stroke-linejoin"] != null ||
1532 params["stroke-linecap"] != null) {
1533 node = o.shape || node;
1534 var fill = (node.getElementsByTagName("fill") && node.getElementsByTagName("fill")[0]),
1536 !fill && (newfill = fill = createNode("fill"));
1537 if ("fill-opacity" in params || "opacity" in params) {
1538 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1);
1539 opacity < 0 && (opacity = 0);
1540 opacity > 1 && (opacity = 1);
1541 fill.opacity = opacity;
1543 params.fill && (fill.on = true);
1544 if (fill.on == null || params.fill == "none") {
1547 if (fill.on && params.fill) {
1548 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1550 fill.src = isURL[1];
1553 fill.color = R.getRGB(params.fill).hex;
1555 fill.type = "solid";
1556 if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || (params.fill + "").charAt(0) != "r") && addGradientFill(res, params.fill)) {
1558 a.gradient = params.fill;
1562 newfill && node.appendChild(fill);
1563 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
1565 !stroke && (newstroke = stroke = createNode("stroke"));
1566 if ((params.stroke && params.stroke != "none") ||
1567 params["stroke-width"] ||
1568 params["stroke-opacity"] != null ||
1569 params["stroke-dasharray"] ||
1570 params["stroke-miterlimit"] ||
1571 params["stroke-linejoin"] ||
1572 params["stroke-linecap"]) {
1575 (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
1576 stroke.on && params.stroke && (stroke.color = R.getRGB(params.stroke).hex);
1577 var opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1);
1578 opacity < 0 && (opacity = 0);
1579 opacity > 1 && (opacity = 1);
1580 stroke.opacity = opacity;
1581 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1582 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1583 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1584 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"]) || 1) * 12 / 16);
1585 if (params["stroke-dasharray"]) {
1589 "-.": "shortdashdot",
1590 "-..": "shortdashdotdot",
1595 "--.": "longdashdot",
1596 "--..": "longdashdotdot"
1598 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1600 newstroke && node.appendChild(stroke);
1602 if (res.type == "text") {
1603 var s = paper.span.style;
1604 a.font && (s.font = a.font);
1605 a["font-family"] && (s.fontFamily = a["font-family"]);
1606 a["font-size"] && (s.fontSize = a["font-size"]);
1607 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1608 a["font-style"] && (s.fontStyle = a["font-style"]);
1609 res.node.string && (paper.span.innerHTML = res.node.string.replace(/</g, "<").replace(/&/g, "&").replace(/\n/g, "<br>"));
1610 res.W = a.w = paper.span.offsetWidth;
1611 res.H = a.h = paper.span.offsetHeight;
1613 res.Y = a.y + Math.round(res.H / 2);
1615 // text-anchor emulation
1616 switch (a["text-anchor"]) {
1618 res.node.style["v-text-align"] = "left";
1619 res.bbx = Math.round(res.W / 2);
1622 res.node.style["v-text-align"] = "right";
1623 res.bbx = -Math.round(res.W / 2);
1626 res.node.style["v-text-align"] = "center";
1631 var addGradientFill = function (o, gradient) {
1632 o.attrs = o.attrs || {};
1633 var attrs = o.attrs,
1634 fill = o.node.getElementsByTagName("fill"),
1637 o.attrs.gradient = gradient;
1638 gradient = (gradient + "").replace(/^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/, function (all, fx, fy) {
1641 fx = parseFloat(fx);
1642 fy = parseFloat(fy);
1643 if (Math.pow(fx - .5, 2) + Math.pow(fy - .5, 2) > .25) {
1644 fy = Math.sqrt(.25 - Math.pow(fx - .5, 2)) + .5;
1646 fxfy = fx + " " + fy;
1650 gradient = gradient.split(/\s*\-\s*/);
1651 if (type == "linear") {
1652 var angle = gradient.shift();
1653 angle = -parseFloat(angle);
1658 var dots = parseDots(gradient);
1662 o = o.shape || o.node;
1663 fill = fill[0] || createNode("fill");
1666 fill.method = "none";
1667 fill.type = (type == "radial") ? "gradientradial" : "gradient";
1668 fill.color = dots[0].color;
1669 fill.color2 = dots[dots.length - 1].color;
1671 for (var i = 0, ii = dots.length; i < ii; i++) {
1672 dots[i].offset && clrs.push(dots[i].offset + " " + dots[i].color);
1675 fill.colors.value = clrs.join(",");
1677 fill.colors && (fill.colors.value = "0% " + fill.color);
1679 if (type == "radial") {
1680 fill.focus = "100%";
1681 fill.focussize = fxfy;
1682 fill.focusposition = fxfy;
1684 fill.angle = (270 - angle) % 360;
1689 var Element = function (node, group, vml) {
1696 node.raphael = this;
1710 Element.prototype.rotate = function (deg, cx, cy) {
1713 return [this._.rt.deg, this._.rt.cx, this._.rt.cy].join(" ");
1715 return this._.rt.deg;
1717 deg = (deg + "").split(separator);
1718 if (deg.length - 1) {
1719 cx = parseFloat(deg[1]);
1720 cy = parseFloat(deg[2]);
1722 deg = parseFloat(deg[0]);
1724 this._.rt.deg = deg;
1726 this._.rt.deg += deg;
1728 cy == null && (cx = null);
1731 this.setBox(this.attrs, cx, cy);
1732 this.Group.style.rotation = this._.rt.deg;
1733 // gradient fix for rotation. TODO
1734 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1735 // fill = fill[0] || {};
1736 // var b = ((360 - this._.rt.deg) - 270) % 360;
1737 // !R.is(fill.angle, "undefined") && (fill.angle = b);
1740 Element.prototype.setBox = function (params, cx, cy) {
1741 var gs = this.Group.style,
1742 os = (this.shape && this.shape.style) || this.node.style;
1743 params = params || {};
1744 for (var i in params) if (params.hasOwnProperty(i)) {
1745 this.attrs[i] = params[i];
1747 cx = cx || this._.rt.cx;
1748 cy = cy || this._.rt.cy;
1749 var attr = this.attrs,
1754 switch (this.type) {
1756 x = attr.cx - attr.r;
1757 y = attr.cy - attr.r;
1761 x = attr.cx - attr.rx;
1762 y = attr.cy - attr.ry;
1770 w = attr.width || 0;
1771 h = attr.height || 0;
1774 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("");
1775 x = attr.x - Math.round(this.W / 2);
1776 y = attr.y - this.H / 2;
1781 if (!this.attrs.path) {
1784 w = this.paper.width;
1785 h = this.paper.height;
1787 var dim = pathDimensions(this.attrs.path);
1797 w = this.paper.width;
1798 h = this.paper.height;
1801 cx = (cx == null) ? x + w / 2 : cx;
1802 cy = (cy == null) ? y + h / 2 : cy;
1803 var left = cx - this.paper.width / 2,
1804 top = cy - this.paper.height / 2;
1805 if (this.type == "path" || this.type == "text") {
1806 (gs.left != left + "px") && (gs.left = left + "px");
1807 (gs.top != top + "px") && (gs.top = top + "px");
1808 this.X = this.type == "text" ? x : -left;
1809 this.Y = this.type == "text" ? y : -top;
1812 (os.left != -left + "px") && (os.left = -left + "px");
1813 (os.top != -top + "px") && (os.top = -top + "px");
1815 (gs.left != left + "px") && (gs.left = left + "px");
1816 (gs.top != top + "px") && (gs.top = top + "px");
1821 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
1822 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
1823 (os.left != x - left + "px") && (os.left = x - left + "px");
1824 (os.top != y - top + "px") && (os.top = y - top + "px");
1825 (os.width != w + "px") && (os.width = w + "px");
1826 (os.height != h + "px") && (os.height = h + "px");
1827 var arcsize = (+params.r || 0) / (Math.min(w, h));
1828 if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
1829 // We should replace element with the new one
1830 var o = createNode(arcsize ? "roundrect" : "rect");
1831 o.arcsize = arcsize;
1832 this.Group.appendChild(o);
1833 this.node.parentNode.removeChild(this.node);
1835 this.arcsize = arcsize;
1836 setFillAndStroke(this, this.attrs);
1837 this.setBox(this.attrs);
1841 Element.prototype.hide = function () {
1842 this.Group.style.display = "none";
1845 Element.prototype.show = function () {
1846 this.Group.style.display = "block";
1849 Element.prototype.getBBox = function () {
1850 if (this.type == "path") {
1851 return pathDimensions(this.attrs.path);
1854 x: this.X + (this.bbx || 0),
1860 Element.prototype.remove = function () {
1861 this[0].parentNode.removeChild(this[0]);
1862 this.Group.parentNode.removeChild(this.Group);
1863 this.shape && this.shape.parentNode.removeChild(this.shape);
1865 Element.prototype.attr = function () {
1866 if (arguments.length == 1 && R.is(arguments[0], "string")) {
1867 if (arguments[0] == "translation") {
1868 return this.translate();
1870 if (arguments[0] == "rotation") {
1871 return this.rotate();
1873 if (arguments[0] == "scale") {
1874 return this.scale();
1876 return this.attrs[arguments[0]];
1878 if (this.attrs && arguments.length == 1 && R.is(arguments[0], "array")) {
1880 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1881 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1886 if (arguments.length == 2) {
1888 params[arguments[0]] = arguments[1];
1890 if (arguments.length == 1 && R.is(arguments[0], "object")) {
1891 params = arguments[0];
1894 if (params.gradient && (this.type in {circle: 1, ellipse: 1} || (params.gradient + "").charAt(0) != "r")) {
1895 addGradientFill(this, params.gradient);
1897 if (params.text && this.type == "text") {
1898 this.node.string = params.text;
1900 setFillAndStroke(this, params);
1901 this.setBox(this.attrs);
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);
1928 var theCircle = function (vml, x, y, r) {
1929 var g = createNode("group"),
1931 o = createNode("oval"),
1933 gl.position = "absolute";
1936 gl.width = vml.width + "px";
1937 gl.height = vml.height + "px";
1938 g.coordsize = vml.coordsize;
1939 g.coordorigin = vml.coordorigin;
1941 var res = new Element(o, g, vml);
1942 res.type = "circle";
1943 setFillAndStroke(res, {stroke: "#000", fill: "none"});
1947 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
1948 vml.canvas.appendChild(g);
1951 var theRect = function (vml, x, y, w, h, r) {
1952 var g = createNode("group"),
1954 o = createNode(r ? "roundrect" : "rect"),
1955 arcsize = (+r || 0) / (Math.min(w, h));
1956 o.arcsize = arcsize;
1957 gl.position = "absolute";
1960 gl.width = vml.width + "px";
1961 gl.height = vml.height + "px";
1962 g.coordsize = vml.coordsize;
1963 g.coordorigin = vml.coordorigin;
1965 var res = new Element(o, g, vml);
1967 setFillAndStroke(res, {stroke: "#000"});
1968 res.arcsize = arcsize;
1969 res.setBox({x: x, y: y, width: w, height: h, r: +r});
1970 vml.canvas.appendChild(g);
1973 var theEllipse = function (vml, x, y, rx, ry) {
1974 var g = createNode("group"),
1976 o = createNode("oval"),
1978 gl.position = "absolute";
1981 gl.width = vml.width + "px";
1982 gl.height = vml.height + "px";
1983 g.coordsize = vml.coordsize;
1984 g.coordorigin = vml.coordorigin;
1986 var res = new Element(o, g, vml);
1987 res.type = "ellipse";
1988 setFillAndStroke(res, {stroke: "#000"});
1993 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
1994 vml.canvas.appendChild(g);
1997 var theImage = function (vml, src, x, y, w, h) {
1998 var g = createNode("group"),
2000 o = createNode("image"),
2002 gl.position = "absolute";
2005 gl.width = vml.width + "px";
2006 gl.height = vml.height + "px";
2007 g.coordsize = vml.coordsize;
2008 g.coordorigin = vml.coordorigin;
2011 var res = new Element(o, g, vml);
2013 res.attrs.src = src;
2018 res.setBox({x: x, y: y, width: w, height: h});
2019 vml.canvas.appendChild(g);
2022 var theText = function (vml, x, y, text) {
2023 var g = createNode("group"),
2025 el = createNode("shape"),
2027 path = createNode("path"),
2029 o = createNode("textpath");
2030 gs.position = "absolute";
2033 gs.width = vml.width + "px";
2034 gs.height = vml.height + "px";
2035 g.coordsize = vml.coordsize;
2036 g.coordorigin = vml.coordorigin;
2037 path.v = ["m", Math.round(x), ", ", Math.round(y), "l", Math.round(x) + 1, ", ", Math.round(y)].join("");
2038 path.textpathok = true;
2039 ol.width = vml.width;
2040 ol.height = vml.height;
2041 gs.position = "absolute";
2044 gs.width = vml.width;
2045 gs.height = vml.height;
2049 el.appendChild(path);
2051 var res = new Element(o, g, vml);
2053 res.textpath = path;
2055 res.attrs.text = text;
2060 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2062 vml.canvas.appendChild(g);
2065 var setSize = function (width, height) {
2066 var cs = this.canvas.style;
2067 this.width = parseFloat(width || this.width);
2068 this.height = parseFloat(height || this.height);
2069 cs.width = this.width + "px";
2070 cs.height = this.height + "px";
2071 cs.clip = "rect(0 " + this.width + "px " + this.height + "px 0)";
2072 this.coordsize = this.width + " " + this.height;
2075 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2077 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2078 var createNode = function (tagName) {
2079 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2082 var createNode = function (tagName) {
2083 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2086 var create = function () {
2087 var con = getContainer.apply(null, arguments),
2088 container = con.container,
2089 height = con.height,
2095 throw new Error("VML container not found.");
2098 c = res.canvas = doc.createElement("div"),
2100 width = parseFloat(width) || 512;
2101 height = parseFloat(height) || 342;
2103 res.height = height;
2104 res.coordsize = width + " " + height;
2105 res.coordorigin = "0 0";
2106 res.span = doc.createElement("span");
2108 c.appendChild(res.span);
2109 s.position = "absolute";
2110 s.left = "-99999px";
2115 s.display = "inline";
2116 cs.width = width + "px";
2117 cs.height = height + "px";
2118 cs.position = "absolute";
2119 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2120 if (container == 1) {
2121 doc.body.appendChild(c);
2131 container.style.width = width;
2132 container.style.height = height;
2133 if (container.firstChild) {
2134 container.insertBefore(c, container.firstChild);
2136 container.appendChild(c);
2139 for (var prop in paper) if (paper.hasOwnProperty(prop)) {
2140 res[prop] = paper[prop];
2142 plugins.call(res, res, R.fn);
2143 res.clear = function () {
2144 while (c.firstChild) {
2145 c.removeChild(c.firstChild);
2151 paper.remove = function () {
2152 this.canvas.parentNode.removeChild(this.canvas);
2157 // Safari or Chrome (WebKit)
2158 if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) {
2159 paper.safari = function () {
2160 var rect = this.rect(-99, -99, this.width + 99, this.height + 99);
2161 setTimeout(function () {rect.remove();});
2164 paper.safari = function () {};
2168 var addEvent = (function () {
2169 if (doc.addEventListener) {
2170 return function (obj, type, fn, element) {
2171 var f = function (e) {
2172 return fn.call(element, e);
2174 obj.addEventListener(type, f, false);
2175 return function () {
2176 obj.removeEventListener(type, f, false);
2180 } else if (doc.attachEvent) {
2181 return function (obj, type, fn, element) {
2182 var f = function (e) {
2183 return fn.call(element, e || win.event);
2185 obj.attachEvent("on" + type, f);
2186 var detacher = function () {
2187 obj.detachEvent("on" + type, f);
2190 if (type == "mouseover") {
2191 obj.attachEvent("onmouseenter", f);
2192 return function () {
2193 obj.detachEvent("onmouseenter", f);
2196 } else if (type == "mouseout") {
2197 obj.attachEvent("onmouseleave", f);
2198 return function () {
2199 obj.detachEvent("onmouseleave", f);
2207 for (var i = events.length; i--;) {
2208 (function (eventName) {
2209 Element.prototype[eventName] = function (fn) {
2210 if (R.is(fn, "function")) {
2211 this.events = this.events || {};
2212 this.events[eventName] = this.events[eventName] || {};
2213 this.events[eventName][fn] = this.events[eventName][fn] || [];
2214 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2218 Element.prototype["un" + eventName] = function (fn) {
2220 this.events[eventName] &&
2221 this.events[eventName][fn] &&
2222 this.events[eventName][fn].length &&
2223 this.events[eventName][fn].shift()() &&
2224 !this.events[eventName][fn].length &&
2225 delete this.events[eventName][fn];
2230 paper.circle = function (x, y, r) {
2231 return theCircle(this, x, y, r);
2233 paper.rect = function (x, y, w, h, r) {
2234 return theRect(this, x, y, w, h, r);
2236 paper.ellipse = function (x, y, rx, ry) {
2237 return theEllipse(this, x, y, rx, ry);
2239 paper.path = function (pathString) {
2240 pathString && !R.is(pathString, "string") && !R.is(pathString[0], "array") && (pathString += "");
2241 return thePath(R.format.apply(R, arguments), this);
2243 paper.image = function (src, x, y, w, h) {
2244 return theImage(this, src, x, y, w, h);
2246 paper.text = function (x, y, text) {
2247 return theText(this, x, y, text);
2249 paper.set = function (itemsArray) {
2250 arguments.length > 1 && (itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length));
2251 return new Set(itemsArray);
2253 paper.setSize = setSize;
2254 Element.prototype.stop = function () {
2255 clearTimeout(this.animation_in_progress);
2258 Element.prototype.scale = function (x, y, cx, cy) {
2259 if (x == null && y == null) {
2260 return {x: this._.sx, y: this._.sy, toString: function () { return this.x + " " + this.y; }};
2270 var bb = this.getBBox(),
2271 rcx = bb.x + bb.width / 2,
2272 rcy = bb.y + bb.height / 2,
2275 cx = (+cx || cx == 0) ? cx : rcx;
2276 cy = (+cy || cy == 0) ? cy : rcy;
2277 var dirx = Math.round(x / Math.abs(x)),
2278 diry = Math.round(y / Math.abs(y)),
2279 s = this.node.style,
2280 ncx = cx + (rcx - cx) * dirx * kx,
2281 ncy = cy + (rcy - cy) * diry * ky;
2282 switch (this.type) {
2285 var neww = a.width * dirx * kx,
2286 newh = a.height * diry * ky,
2287 newr = a.r * Math.min(kx, ky),
2288 newx = ncx - neww / 2,
2289 newy = ncy - newh / 2;
2303 r: a.r * Math.min(kx, ky),
2309 var path = pathToRelative(a.path),
2311 for (var i = 0, ii = path.length; i < ii; i++) {
2313 if (p[0].toUpperCase() == "M" && skip) {
2318 if (R.svg && p[0].toUpperCase() == "A") {
2319 p[path[i].length - 2] *= kx;
2320 p[path[i].length - 1] *= ky;
2323 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2325 for (var j = 1, jj = p.length; j < jj; j++) {
2326 p[j] *= (j % 2) ? kx : ky;
2330 var dim2 = pathDimensions(path),
2331 dx = ncx - dim2.x - dim2.width / 2,
2332 dy = ncy - dim2.y - dim2.height / 2;
2336 this.attr({path: path});
2339 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2340 if (this.transformations) {
2341 this.transformations[2] = "scale(".concat(dirx, ",", diry, ")");
2342 this.node.setAttribute("transform", this.transformations.join(" "));
2343 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2344 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2345 this.attr({x: dx, y: dy});
2349 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=".concat(dirx,
2350 ", M12=0, M21=0, M22=", diry,
2351 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2352 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2355 if (this.transformations) {
2356 this.transformations[2] = "";
2357 this.node.setAttribute("transform", this.transformations.join(" "));
2361 this.node.filterMatrix = "";
2362 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2365 a.scale = [x, y, cx, cy].join(" ");
2372 // animation easing formulas
2373 R.easing_formulas = {
2374 linear: function (n) {
2378 return Math.pow(n, 3);
2381 return Math.pow(n - 1, 3) + 1;
2383 "<>": function (n) {
2386 return Math.pow(n, 3) / 2;
2389 return (Math.pow(n, 3) + 2) / 2;
2391 backIn: function (n) {
2393 return n * n * ((s + 1) * n - s);
2395 backOut: function (n) {
2398 return n * n * ((s + 1) * n + s) + 1;
2400 elastic: function (n) {
2401 if (n == 0 || n == 1) {
2406 return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1;
2408 bounce: function (n) {
2417 l = s * n * n + .75;
2419 if (n < (2.5 / p)) {
2421 l = s * n * n + .9375;
2424 l = s * n * n + .984375;
2432 Element.prototype.animate = function (params, ms, easing, callback) {
2433 clearTimeout(this.animation_in_progress);
2434 if (R.is(easing, "function") || !easing) {
2435 callback = easing || null;
2441 for (var attr in params) if (params.hasOwnProperty(attr)) {
2442 if (attr in availableAnimAttrs) {
2443 from[attr] = this.attr(attr);
2444 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
2445 to[attr] = params[attr];
2446 switch (availableAnimAttrs[attr]) {
2448 diff[attr] = (to[attr] - from[attr]) / ms;
2451 from[attr] = R.getRGB(from[attr]);
2452 var toColour = R.getRGB(to[attr]);
2454 r: (toColour.r - from[attr].r) / ms,
2455 g: (toColour.g - from[attr].g) / ms,
2456 b: (toColour.b - from[attr].b) / ms
2460 var pathes = path2curve(from[attr], to[attr]);
2461 from[attr] = pathes[0];
2462 to[attr] = pathes[1];
2464 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2465 diff[attr][i] = [0];
2466 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2467 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2472 var values = (params[attr] + "").split(separator),
2473 from2 = (from[attr] + "").split(separator);
2476 from[attr] = [0, 0];
2477 diff[attr] = [values[0] / ms, values[1] / ms];
2480 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2481 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2484 params[attr] = values;
2485 from[attr] = (from[attr] + "").split(separator);
2486 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2489 from[attr] = (from[attr] + "").split(separator);
2493 diff[attr][i] = (values[i] - from[attr][i]) / ms;
2501 var start = +new Date,
2503 upto255 = function (color) {
2504 return +color > 255 ? 255 : +color;
2508 var time = new Date - start,
2512 var pos = R.easing_formulas[easing] ? R.easing_formulas[easing](time / ms) : time / ms;
2513 for (var attr in from) if (from.hasOwnProperty(attr)) {
2514 switch (availableAnimAttrs[attr]) {
2516 now = +from[attr] + pos * ms * diff[attr];
2520 upto255(Math.round(from[attr].r + pos * ms * diff[attr].r)),
2521 upto255(Math.round(from[attr].g + pos * ms * diff[attr].g)),
2522 upto255(Math.round(from[attr].b + pos * ms * diff[attr].b))
2527 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2528 now[i] = [from[attr][i][0]];
2529 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2530 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
2532 now[i] = now[i].join(" ");
2534 now = now.join(" ");
2539 var x = diff[attr][0] * (time - prev),
2540 y = diff[attr][1] * (time - prev);
2543 now = [x, y].join(" ");
2546 now = +from[attr][0] + pos * ms * diff[attr][0];
2547 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2550 now = [+from[attr][0] + pos * ms * diff[attr][0], +from[attr][1] + pos * ms * diff[attr][1], (2 in params[attr] ? params[attr][2] : ""), (3 in params[attr] ? params[attr][3] : "")].join(" ");
2556 now[i] = +from[attr][i] + pos * ms * diff[attr][i];
2565 that.animation_in_progress = setTimeout(tick);
2566 R.svg && paper.safari();
2568 (t.x || t.y) && that.translate(-t.x, -t.y);
2570 clearTimeout(that.animation_in_progress);
2571 R.svg && paper.safari();
2572 (R.is(callback, "function")) && callback.call(that);
2578 Element.prototype.translate = function (x, y) {
2580 return {x: this._.tx, y: this._.ty};
2584 switch (this.type) {
2587 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
2592 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
2595 var path = pathToRelative(this.attrs.path);
2598 this.attr({path: path});
2603 Element.prototype.toString = function () {
2604 return "Rapha\u00ebl\u2019s object";
2609 var Set = function (items) {
2613 for (var i = 0, ii = items.length; i < ii; i++) {
2614 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
2615 this[this.items.length] = this.items[this.items.length] = items[i];
2621 Set.prototype.push = function () {
2624 for (var i = 0, ii = arguments.length; i < ii; i++) {
2625 item = arguments[i];
2626 if (item && (item.constructor == Element || item.constructor == Set)) {
2627 len = this.items.length;
2628 this[len] = this.items[len] = item;
2634 Set.prototype.pop = function () {
2635 delete this[this.length--];
2636 return this.items.pop();
2638 for (var method in Element.prototype) if (Element.prototype.hasOwnProperty(method)) {
2639 Set.prototype[method] = (function (methodname) {
2640 return function () {
2641 for (var i = 0, ii = this.items.length; i < ii; i++) {
2642 this.items[i][methodname].apply(this.items[i], arguments);
2648 Set.prototype.attr = function (name, value) {
2649 if (name && R.is(name, "array") && R.is(name[0], "object")) {
2650 for (var j = 0, jj = name.length; j < jj; j++) {
2651 this.items[j].attr(name[j]);
2654 for (var i = 0, ii = this.items.length; i < ii; i++) {
2655 this.items[i].attr.apply(this.items[i], arguments);
2661 Set.prototype.getBBox = function () {
2666 for (var i = this.items.length; i--;) {
2667 var box = this.items[i].getBBox();
2670 w.push(box.x + box.width);
2671 h.push(box.y + box.height);
2673 x = Math.min.apply(Math, x);
2674 y = Math.min.apply(Math, y);
2678 width: Math.max.apply(Math, w) - x,
2679 height: Math.max.apply(Math, h) - y
2683 R.registerFont = function (font) {
2687 this.fonts = this.fonts || {};
2693 family = font.face["font-family"];
2694 for (var prop in font.face) if (font.face.hasOwnProperty(prop)) {
2695 fontcopy.face[prop] = font.face[prop];
2697 if (this.fonts[family]) {
2698 this.fonts[family].push(fontcopy);
2700 this.fonts[family] = [fontcopy];
2703 fontcopy.face["units-per-em"] = parseInt(font.face["units-per-em"], 10);
2704 for (var glyph in font.glyphs) if (font.glyphs.hasOwnProperty(glyph)) {
2705 var path = font.glyphs[glyph];
2706 fontcopy.glyphs[glyph] = {
2709 d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
2710 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
2714 for (var k in path.k) if (path.hasOwnProperty(k)) {
2715 fontcopy.glyphs[glyph].k[k] = path.k[k];
2722 paper.getFont = function (family, weight, style, stretch) {
2723 stretch = stretch || "normal";
2724 style = style || "normal";
2725 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
2726 var font = R.fonts[family];
2728 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, "") + "(\\s|$)", "i");
2729 for (var fontName in R.fonts) if (R.fonts.hasOwnProperty(fontName)) {
2730 if (name.test(fontName)) {
2731 font = R.fonts[fontName];
2738 for (var i = 0, ii = font.length; i < ii; i++) {
2740 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
2747 paper.print = function (x, y, string, font, size) {
2748 var out = this.set(),
2749 letters = (string + "").split(""),
2753 R.is(font, "string") && (font = this.getFont(font));
2755 scale = (size || 16) / font.face["units-per-em"];
2756 for (var i = 0, ii = letters.length; i < ii; i++) {
2757 var prev = i && font.glyphs[letters[i - 1]] || {},
2758 curr = font.glyphs[letters[i]];
2759 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
2760 curr && curr.d && out.push(this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
2762 out.scale(scale, scale, 0, y).translate(x, (size || 16) / 2);
2767 R.format = function (token) {
2768 var args = R.is(arguments[1], "array") ? [0].concat(arguments[1]) : arguments;
2769 token && R.is(token, "string") && args.length - 1 && (token = token.replace(/\{(\d+)\}/g, function (str, i) {
2770 return args[++i] == null ? "" : args[i];
2774 R.ninja = function () {
2775 var r = window.Raphael, u;
2776 if (oldRaphael.was) {
2777 window.Raphael = oldRaphael.is;
2780 delete window.Raphael;
2787 R.el = Element.prototype;