2 * Raphael 1.0 - 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 = {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 = {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"];
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.isArray = function (arr) {
30 return Object.prototype.toString.call(arr) == "[object Array]";
32 R.setWindow = function (newwin) {
37 R.hsb2rgb = function (hue, saturation, brightness) {
38 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
46 if (brightness == 0) {
47 return {r: 0, g: 0, b: 0, hex: "#000"};
49 if (hue > 1 || saturation > 1 || brightness > 1) {
54 var i = Math.floor(hue * 6),
56 p = brightness * (1 - saturation),
57 q = brightness * (1 - (saturation * f)),
58 t = brightness * (1 - (saturation * (1 - f)));
59 red = [brightness, q, p, p, t, brightness, brightness][i];
60 green = [t, brightness, brightness, q, p, p, t][i];
61 blue = [p, p, t, brightness, brightness, q, p][i];
65 var rgb = {r: red, g: green, b: blue},
66 r = Math.round(red).toString(16),
67 g = Math.round(green).toString(16),
68 b = Math.round(blue).toString(16);
78 rgb.hex = "#" + r + g + b;
81 R.rgb2hsb = function (red, green, blue) {
82 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
87 if (typeof red == "string") {
88 var clr = R.getRGB(red);
93 if (red > 1 || green > 1 || blue > 1) {
98 var max = Math.max(red, green, blue),
99 min = Math.min(red, green, blue),
104 return {h: 0, s: 0, b: max};
106 var delta = (max - min);
107 saturation = delta / max;
109 hue = (green - blue) / delta;
110 } else if (green == max) {
111 hue = 2 + ((blue - red) / delta);
113 hue = 4 + ((red - green) / delta);
123 return {h: hue, s: saturation, b: brightness};
125 var getRGBcache = {},
127 R.getRGB = function (colour) {
128 if (colour in getRGBcache) {
129 return getRGBcache[colour];
131 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"},
133 if ((colour + "").toLowerCase() in htmlcolors) {
134 colour = htmlcolors[colour.toString().toLowerCase()];
137 return {r: 0, g: 0, b: 0, hex: "#000"};
139 if (colour == "none") {
140 return {r: -1, g: -1, b: -1, hex: "none"};
145 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);
148 blue = parseInt(rgb[2].substring(5), 16);
149 green = parseInt(rgb[2].substring(3, 5), 16);
150 red = parseInt(rgb[2].substring(1, 3), 16);
153 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
154 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
155 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
158 rgb = rgb[4].split(/\s*,\s*/);
159 red = parseFloat(rgb[0]);
160 green = parseFloat(rgb[1]);
161 blue = parseFloat(rgb[2]);
164 rgb = rgb[5].split(/\s*,\s*/);
165 red = parseFloat(rgb[0]) * 2.55;
166 green = parseFloat(rgb[1]) * 2.55;
167 blue = parseFloat(rgb[2]) * 2.55;
170 rgb = rgb[6].split(/\s*,\s*/);
171 red = parseFloat(rgb[0]);
172 green = parseFloat(rgb[1]);
173 blue = parseFloat(rgb[2]);
174 return R.hsb2rgb(red, green, blue);
177 rgb = rgb[7].split(/\s*,\s*/);
178 red = parseFloat(rgb[0]) * 2.55;
179 green = parseFloat(rgb[1]) * 2.55;
180 blue = parseFloat(rgb[2]) * 2.55;
181 return R.hsb2rgb(red, green, blue);
183 var rgb = {r: red, g: green, b: blue},
184 r = Math.round(red).toString(16),
185 g = Math.round(green).toString(16),
186 b = Math.round(blue).toString(16);
187 (r.length == 1) && (r = "0" + r);
188 (g.length == 1) && (g = "0" + g);
189 (b.length == 1) && (b = "0" + b);
190 rgb.hex = "#" + r + g + b;
193 res = {r: -1, g: -1, b: -1, hex: "none"};
195 if (getRGBcount.length > 20) {
196 delete getRGBcache[getRGBcount.unshift()];
198 getRGBcount.push(colour);
199 getRGBcache[colour] = res;
202 R.getColor = function (value) {
203 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
204 rgb = this.hsb2rgb(start.h, start.s, start.b);
210 this.getColor.start = {h: 0, s: 1, b: start.b};
215 R.getColor.reset = function () {
220 absolutely: function () {
221 this.isAbsolute = true;
224 relatively: function () {
225 this.isAbsolute = false;
228 moveTo: function (x, y) {
229 var d = this.isAbsolute ? "M" : "m";
230 d += +parseFloat(x).toFixed(3) + " " + (+parseFloat(y).toFixed(3)) + " ";
231 this.attr({path: this.attrs.path + d});
234 lineTo: function (x, y) {
235 var d = this.isAbsolute ? "L" : "l";
236 d += +parseFloat(x).toFixed(3) + " " + (+parseFloat(y).toFixed(3)) + " ";
237 this.attr({path: this.attrs.path + d});
240 arcTo: function (rx, ry, large_arc_flag, sweep_flag, x, y) {
241 var d = this.isAbsolute ? "A" : "a";
242 d += [+parseFloat(rx).toFixed(3), +parseFloat(ry).toFixed(3), 0, large_arc_flag, sweep_flag, +parseFloat(x).toFixed(3), +parseFloat(y).toFixed(3)].join(" ");
243 this.attr({path: this.attrs.path + d});
246 curveTo: function () {
247 var args = Array.prototype.splice.call(arguments, 0, arguments.length),
248 d = [0, 0, 0, 0, "s", 0, "c"][args.length] || "";
249 if (this.isAbsolute) {
252 this.attr({path: this.attrs.path + d + args});
255 qcurveTo: function () {
256 var d = [0, 1, "t", 3, "q"][arguments.length],
257 args = Array.prototype.splice.call(arguments, 0, arguments.length);
258 if (this.isAbsolute) {
261 this.attr({path: this.attrs.path + d + args});
264 addRoundedCorner: function (r, dir) {
265 var rollback = this.isAbsolute,
269 rollback = function () {
273 rollback = function () {};
275 this.arcTo(r, r, 0, {"lu": 1, "rd": 1, "ur": 1, "dl": 1}[dir] || 0, r * (!!(dir.indexOf("r") + 1) * 2 - 1), r * (!!(dir.indexOf("d") + 1) * 2 - 1));
279 andClose: function () {
280 this.attr({path: this.attrs.path + "z"});
283 getPathArray: function () {
284 return R.parsePathString(this.attrs.path);
288 path2string = function () {
290 for (var i = 0, ii = this.length; i < ii; i++) {
291 res += this[i][0] + this[i].join(",").substring(2);
293 return res.replace(/,(?=-)/g, "");
296 R.parsePathString = function (pathString) {
297 if (pathString in pathcache) {
298 return pathcache[pathString];
300 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
302 if (pathString.toString == path2string) {
306 (pathString + "").replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, function (a, b, c) {
308 name = b.toLowerCase();
309 c.replace(/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig, function (a, b) {
310 b && params.push(+b);
312 while (params.length >= paramCounts[name]) {
313 data.push([b].concat(params.splice(0, paramCounts[name])));
314 if (!paramCounts[name]) {
319 data.toString = path2string;
321 if (pathcount.length > 20) {
322 delete pathcache[pathcount.unshift()];
324 pathcount.push(pathString);
325 pathcache[pathString] = data;
328 var pathDimensions = function (path) {
329 var pathArray = path;
330 pathArray = pathToAbsolute(pathArray);
334 for (var i = 0, ii = pathArray.length; i < ii; i++) {
335 var pa = pathArray[i];
340 x.push(pa[pa.length - 2]);
341 y.push(pa[pa.length - 1]);
344 for (var j = 1, jj = pa.length; j < jj; j++) {
345 (j % 2 ? x : y).push(pa[j]);
349 var minx = Math.min.apply(Math, x),
350 miny = Math.min.apply(Math, y);
364 width: Math.max.apply(Math, x) - minx,
365 height: Math.max.apply(Math, y) - miny,
371 pathToRelative = function (pathArray) {
376 if (typeof pathArray == "string") {
377 pathArray = R.parsePathString(pathArray);
379 if (pathArray[0][0] == "M") {
383 res.push(["M", x, y]);
385 for (var i = start, ii = pathArray.length; i < ii; i++) {
388 if (pa[0] != pa[0].toLowerCase()) {
389 r[0] = pa[0].toLowerCase();
397 r[6] = +(pa[6] - x).toFixed(3);
398 r[7] = +(pa[7] - y).toFixed(3);
401 r[1] = +(pa[1] - y).toFixed(3);
404 for (var j = 1, jj = pa.length; j < jj; j++) {
405 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
410 for (var k = 0, kk = pa.length; k < kk; k++) {
414 var len = res[i].length;
419 x += +res[i][len - 1];
422 y += +res[i][len - 1];
425 x += +res[i][len - 2];
426 y += +res[i][len - 1];
429 res.toString = pathArray.toString;
432 pathToAbsolute = function (pathArray) {
437 if (typeof pathArray == "string") {
438 pathArray = R.parsePathString(pathArray);
440 if (pathArray[0][0] == "M") {
441 x = +pathArray[0][1];
442 y = +pathArray[0][2];
444 res[0] = ["M", x, y];
446 for (var i = start, ii = pathArray.length; i < ii; i++) {
449 if (pa[0] != (pa[0] + "").toUpperCase()) {
450 r[0] = (pa[0] + "").toUpperCase();
458 r[6] = +(pa[6] + x).toFixed(3);
459 r[7] = +(pa[7] + y).toFixed(3);
468 for (var j = 1, jj = pa.length; j < jj; j++) {
469 r[j] = +pa[j] + ((j % 2) ? x : y);
474 for (var k = 0, kk = pa.length; k < kk; k++) {
488 x = res[i][res[i].length - 2];
489 y = res[i][res[i].length - 1];
492 res.toString = pathArray.toString;
495 l2c = function (x1, y1, x2, y2) {
496 return [x1, y1, x2, y2, x2, y2];
498 q2c = function (x1, y1, ax, ay, x2, y2) {
500 2 / 3 * x1 + 1 / 3 * ax,
501 2 / 3 * y1 + 1 / 3 * ay,
502 2 / 3 * x1 + 1 / 3 * x2,
503 2 / 3 * y1 + 1 / 3 * y2,
508 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
509 // for more information of where this math came from visit:
510 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
511 var _120 = Math.PI * 120 / 180,
514 var x = (x1 - x2) / 2,
518 k = (large_arc_flag == sweep_flag ? -1 : 1) *
519 Math.sqrt(Math.abs(rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)),
520 cx = k * rx * y / ry + (x1 + x2) / 2,
521 cy = k * -ry * x / rx + (y1 + y2) / 2,
522 f1 = Math.asin((y1 - cy) / ry),
523 f2 = Math.asin((y2 - cy) / ry);
525 f1 = x1 < cx ? Math.PI - f1 : f1;
526 f2 = x2 < cx ? Math.PI - f2 : f2;
527 f1 < 0 && (f1 = Math.PI * 2 + f1);
528 f2 < 0 && (f2 = Math.PI * 2 + f2);
529 if (sweep_flag && f1 > f2) {
530 f1 = f1 - Math.PI * 2;
532 if (!sweep_flag && f2 > f1) {
533 f2 = f2 - Math.PI * 2;
542 if (Math.abs(df) > _120) {
546 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
547 x2 = cx + rx * Math.cos(f2);
548 y2 = cy + ry * Math.sin(f2);
549 res = arguments.callee(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
551 var c1 = Math.cos(f1),
556 t = Math.tan(df / 4),
560 m2 = [x1 + hx * s1, y1 - hy * c1],
561 m3 = [x2 + hx * s2, y2 - hy * c2],
563 m2[0] = 2 * m1[0] - m2[0];
564 m2[1] = 2 * m1[1] - m2[1];
566 return [m2, m3, m4].concat(res);
568 res = [m2, m3, m4].concat(res).join(",").split(",");
569 for (var i = res.length; i--;) {
575 findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
576 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,
577 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,
578 mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
579 my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
580 nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
581 ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
582 ax = (1 - t) * p1x + t * c1x,
583 ay = (1 - t) * p1y + t * c1y,
584 cx = (1 - t) * c2x + t * p2x,
585 cy = (1 - t) * c2y + t * p2y;
586 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}};
588 path2curve = function (path, path2) {
589 path2curve.cache = path2curve.cache || {};
590 path2curve.count = path2curve.count || [];
591 if (path in path2curve.cache) {
592 return path2curve.cache[path + "&" + path2];
594 var p = pathToAbsolute(path),
595 p2 = path2 && pathToAbsolute(path2),
596 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0},
597 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0},
598 processPath = function (path, d) {
600 return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
608 path = ["C"].concat(a2c(d.x, d.y, path[1], path[2], path[3], path[4], path[5], path[6], path[7]));
611 var nx = d.x + (d.x - (d.bx || d.x)),
612 ny = d.y + (d.y - (d.by || d.y));
613 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
616 var nx = d.x + (d.x - (d.bx || d.x)),
617 ny = d.y + (d.y - (d.by || d.y));
618 path = ["C"].concat(q2c(d.x, d.y, nx, ny, path[1], path[2]));
621 path = ["C"].concat(q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
624 path = ["C"].concat(l2c(d.x, d.y, path[1], path[2]));
627 path = ["C"].concat(l2c(d.x, d.y, path[1], d.y));
630 path = ["C"].concat(l2c(d.x, d.y, d.x, path[1]));
633 path = ["C"].concat(l2c(d.x, d.y, d.X, d.Y));
638 fixArc = function (pp, i) {
639 if (pp[i].length > 7) {
643 pp.splice(i++, 0, ["C"].concat(pi.splice(0, 6)));
646 ii = Math.max(p.length, p2 && p2.length || 0);
649 fixM = function (path1, path2, a1, a2, i) {
650 if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
651 path2.splice(i, 0, ["M", a2.x, a2.y]);
656 ii = Math.max(p.length, p2 && p2.length || 0);
659 for (var i = 0, ii = Math.max(p.length, p2 && p2.length || 0); i < ii; i++) {
660 p[i] = processPath(p[i], attrs);
662 p2 && (p2[i] = processPath(p2[i], attrs2));
664 fixM(p, p2, attrs, attrs2, i);
665 fixM(p2, p, attrs2, attrs, i);
669 seg2len = p2 && seg2.length;
670 attrs.bx = seg[seglen - 4] || 0;
671 attrs.by = seg[seglen - 3] || 0;
672 attrs.x = seg[seglen - 2];
673 attrs.y = seg[seglen - 1];
674 attrs2.bx = p2 && (seg2[seg2len - 4] || 0);
675 attrs2.by = p2 && (seg2[seg2len - 3] || 0);
676 attrs2.x = p2 && seg2[seg2len - 2];
677 attrs2.y = p2 && seg2[seg2len - 1];
679 if (path2curve.count.length > 100) {
680 delete path2curve.cache[path2curve.count.unshift()];
682 path2curve.count.push(path + "&" + path2);
683 return (path2curve.cache[path + "&" + path2] = p2 ? [p, p2] : p);
685 toGradient = function (gradient) {
686 if (typeof gradient == "string") {
687 gradient = gradient.split(/\s*\-\s*/);
688 var angle = gradient.shift();
689 if (angle.toLowerCase() == "v") {
691 } else if (angle.toLowerCase() == "h") {
694 angle = parseFloat(angle);
697 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)]},
698 max = 1 / (Math.max(Math.abs(grobj.vector[2]), Math.abs(grobj.vector[3])) || 1);
699 grobj.vector[2] *= max;
700 grobj.vector[3] *= max;
701 if (grobj.vector[2] < 0) {
702 grobj.vector[0] = -grobj.vector[2];
705 if (grobj.vector[3] < 0) {
706 grobj.vector[1] = -grobj.vector[3];
709 grobj.vector[0] = grobj.vector[0].toFixed(3);
710 grobj.vector[1] = grobj.vector[1].toFixed(3);
711 grobj.vector[2] = grobj.vector[2].toFixed(3);
712 grobj.vector[3] = grobj.vector[3].toFixed(3);
713 for (var i = 0, ii = gradient.length; i < ii; i++) {
715 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
716 dot.color = R.getRGB(par[1]).hex;
717 par[2] && (dot.offset = par[2] + "%");
718 grobj.dots.push(dot);
720 for (var i = 1, ii = grobj.dots.length - 1; i < ii; i++) {
721 if (!grobj.dots[i].offset) {
722 var start = parseFloat(grobj.dots[i - 1].offset || 0),
724 for (var j = i + 1; j < ii; j++) {
725 if (grobj.dots[j].offset) {
726 end = grobj.dots[j].offset;
734 end = parseFloat(end);
735 var d = (end - start) / (j - i + 1);
738 grobj.dots[i].offset = start + "%";
747 getContainer = function () {
753 if (typeof arguments[0] == "string" || typeof arguments[0] == "object") {
754 if (typeof arguments[0] == "string") {
755 container = doc.getElementById(arguments[0]);
757 container = arguments[0];
759 if (container.tagName) {
760 if (arguments[1] == null) {
762 container: container,
763 width: container.style.pixelWidth || container.offsetWidth,
764 height: container.style.pixelHeight || container.offsetHeight
767 return {container: container, width: arguments[1], height: arguments[2]};
770 } else if (typeof arguments[0] == "number" && arguments.length > 3) {
771 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
774 plugins = function (con, add) {
776 for (var prop in add) if (add.hasOwnProperty(prop) && !(prop in con)) {
777 switch (typeof add[prop]) {
780 con[prop] = con === that ? f : function () { return f.apply(that, arguments); };
784 con[prop] = con[prop] || {};
785 plugins.call(this, con[prop], add[prop]);
788 con[prop] = add[prop];
796 R.toString = function () {
797 return "Your browser supports SVG.\nYou are running Rapha\u00ebl " + this.version;
799 var thePath = function (params, pathString, SVG) {
800 var el = doc.createElementNS(SVG.svgns, "path");
802 SVG.canvas.appendChild(el);
804 var p = new Element(el, SVG);
806 for (var method in pathMethods) {
807 p[method] = pathMethods[method];
810 p.attrs.path = "" + (pathString || "");
811 pathString && p.node.setAttribute("d", R.parsePathString(pathString));
813 !params.gradient && (params.fill = params.fill || "none");
814 params.stroke = params.stroke || "#000";
816 params = {fill: "none", stroke: "#000"};
818 setFillAndStroke(p, params);
821 var addGradientFill = function (o, gradient, SVG) {
822 gradient = toGradient(gradient);
823 var el = doc.createElementNS(SVG.svgns, (gradient.type || "linear") + "Gradient");
824 el.id = "raphael-gradient-" + R.idGenerator++;
825 if (gradient.vector && gradient.vector.length) {
826 el.setAttribute("x1", gradient.vector[0]);
827 el.setAttribute("y1", gradient.vector[1]);
828 el.setAttribute("x2", gradient.vector[2]);
829 el.setAttribute("y2", gradient.vector[3]);
831 SVG.defs.appendChild(el);
832 var isopacity = true;
833 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
834 var stop = doc.createElementNS(SVG.svgns, "stop");
835 if (gradient.dots[i].offset) {
838 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
839 stop.setAttribute("stop-color", R.getRGB(gradient.dots[i].color).hex || "#fff");
840 // ignoring opacity for internal points, because VML doesn't support it
841 el.appendChild(stop);
843 if (isopacity && typeof gradient.dots[ii - 1].opacity != "undefined") {
844 stop.setAttribute("stop-opacity", gradient.dots[ii - 1].opacity);
846 o.setAttribute("fill", "url(#" + el.id + ")");
849 o.style.fillOpacity = 1;
850 o.setAttribute("opacity", 1);
851 o.setAttribute("fill-opacity", 1);
853 var updatePosition = function (o) {
855 var bbox = o.getBBox();
856 o.pattern.setAttribute("patternTransform", "translate(".concat(bbox.x, ",", bbox.y, ")"));
859 var setFillAndStroke = function (o, params) {
866 "-..": [3, 1, 1, 1, 1, 1],
872 "--..": [8, 3, 1, 3, 1, 3]
876 rot = o.attr("rotation"),
877 addDashes = function (o, value) {
878 value = dasharray[(value + "").toLowerCase()];
880 var width = o.attrs["stroke-width"] || "1",
881 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
883 for (var i = 0, ii = value.length; i < ii; i++) {
884 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
886 value = dashes.join(",");
887 node.setAttribute("stroke-dasharray", value);
891 for (var att in params) {
892 if (!(att in availableAttrs)) {
895 var value = params[att];
902 var pn = node.parentNode;
903 if (pn.tagName.toLowerCase() != "a") {
904 var hl = doc.createElementNS(o.paper.svgns, "a");
905 pn.insertBefore(hl, node);
906 hl.appendChild(node);
909 pn.setAttributeNS(o.paper.xlink, att, value);
912 if (o.type == "path") {
913 node.setAttribute("d", R.parsePathString(value));
916 node.setAttribute(att, value);
925 value = -attrs.x - (attrs.width || 0);
929 node.setAttribute(att, value);
933 node.setAttribute(att, value);
942 value = -attrs.y - (attrs.height || 0);
946 node.setAttribute(att, value);
950 if (o.type == "rect") {
951 node.setAttribute("rx", value);
952 node.setAttribute("ry", value);
954 node.setAttribute(att, value);
958 if (o.type == "image") {
959 node.setAttributeNS(o.paper.xlink, "href", value);
963 node.style.strokeWidth = value;
964 // Need following line for Firefox
965 node.setAttribute(att, value);
966 if (attrs["stroke-dasharray"]) {
967 addDashes(o, attrs["stroke-dasharray"]);
970 case "stroke-dasharray":
975 o.rotate(value, true);
978 var xy = (value + "").split(separator);
979 o.translate((+xy[0] + 1 || 2) - 1, (+xy[1] + 1 || 2) - 1);
982 var xy = (value + "").split(separator);
983 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
986 var isURL = (value + "").match(/^url\(([^\)]+)\)$/i);
988 var el = doc.createElementNS(o.paper.svgns, "pattern"),
989 ig = doc.createElementNS(o.paper.svgns, "image");
990 el.id = "raphael-pattern-" + R.idGenerator++;
991 el.setAttribute("x", 0);
992 el.setAttribute("y", 0);
993 el.setAttribute("patternUnits", "userSpaceOnUse");
994 ig.setAttribute("x", 0);
995 ig.setAttribute("y", 0);
996 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
999 var img = doc.createElement("img");
1000 img.style.position = "absolute";
1001 img.style.top = "-9999em";
1002 img.style.left = "-9999em";
1003 img.onload = function () {
1004 el.setAttribute("width", this.offsetWidth);
1005 el.setAttribute("height", this.offsetHeight);
1006 ig.setAttribute("width", this.offsetWidth);
1007 ig.setAttribute("height", this.offsetHeight);
1008 doc.body.removeChild(this);
1011 doc.body.appendChild(img);
1013 o.paper.defs.appendChild(el);
1014 node.style.fill = "url(#" + el.id + ")";
1015 node.setAttribute("fill", "url(#" + el.id + ")");
1020 delete params.gradient;
1021 delete attrs.gradient;
1022 if (typeof attrs.opacity != "undefined" && typeof params.opacity == "undefined" ) {
1023 node.style.opacity = attrs.opacity;
1024 // Need following line for Firefox
1025 node.setAttribute("opacity", attrs.opacity);
1027 if (typeof attrs["fill-opacity"] != "undefined" && typeof params["fill-opacity"] == "undefined" ) {
1028 node.style.fillOpacity = o.attrs["fill-opacity"];
1029 // Need following line for Firefox
1030 node.setAttribute("fill-opacity", attrs["fill-opacity"]);
1033 node.style[att] = R.getRGB(value).hex;
1034 // Need following line for Firefox
1035 node.setAttribute(att, R.getRGB(value).hex);
1038 addGradientFill(node, value, o.paper);
1041 case "fill-opacity":
1042 if (attrs.gradient) {
1043 var gradient = doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
1045 var stops = gradient.getElementsByTagName("stop");
1046 stops[stops.length - 1].setAttribute("stop-opacity", value);
1051 var cssrule = att.replace(/(\-.)/g, function (w) {
1052 return w.substring(1).toUpperCase();
1054 node.style[cssrule] = value;
1055 // Need following line for Firefox
1056 node.setAttribute(att, value);
1061 tuneText(o, params);
1062 o.rotate(rot, true);
1065 var tuneText = function (el, params) {
1066 if (el.type != "text" || !("text" in params || "font" in params || "font-size" in params || "x" in params || "y" in params)) {
1071 fontSize = node.firstChild ? parseInt(doc.defaultView.getComputedStyle(node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
1073 if ("text" in params) {
1074 while (node.firstChild) {
1075 node.removeChild(node.firstChild);
1077 var texts = (params.text + "").split("\n");
1078 for (var i = 0, ii = texts.length; i < ii; i++) {
1079 var tspan = doc.createElementNS(el.paper.svgns, "tspan");
1080 i && tspan.setAttribute("dy", fontSize * leading);
1081 i && tspan.setAttribute("x", a.x);
1082 tspan.appendChild(doc.createTextNode(texts[i]));
1083 node.appendChild(tspan);
1086 var texts = node.getElementsByTagName("tspan");
1087 for (var i = 0, ii = texts.length; i < ii; i++) {
1088 i && texts[i].setAttribute("dy", fontSize * leading);
1089 i && texts[i].setAttribute("x", a.x);
1092 node.setAttribute("y", a.y);
1093 var bb = el.getBBox(),
1094 dif = a.y - (bb.y + bb.height / 2);
1095 dif && node.setAttribute("y", a.y + dif);
1097 var Element = function (node, svg) {
1103 this.attrs = this.attrs || {};
1104 this.transformations = []; // rotate, translate, scale
1108 rt: {deg: 0, x: 0, y: 0},
1113 Element.prototype.rotate = function (deg, cx, cy) {
1116 return [this._.rt.deg, this._.rt.cx, this._.rt.cy].join(" ");
1118 return this._.rt.deg;
1120 var bbox = this.getBBox();
1121 deg = (deg + "").split(separator);
1122 if (deg.length - 1) {
1123 cx = parseFloat(deg[1]);
1124 cy = parseFloat(deg[2]);
1126 deg = parseFloat(deg[0]);
1128 this._.rt.deg = deg;
1130 this._.rt.deg += deg;
1132 (cy == null) && (cx = null);
1135 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1136 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1137 if (this._.rt.deg) {
1138 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
1140 this.transformations[0] = "";
1142 this.node.setAttribute("transform", this.transformations.join(" "));
1145 Element.prototype.hide = function () {
1146 this.node.style.display = "none";
1149 Element.prototype.show = function () {
1150 this.node.style.display = "block";
1153 Element.prototype.remove = function () {
1154 this.node.parentNode.removeChild(this.node);
1156 Element.prototype.getBBox = function () {
1157 if (this.node.style.display == "none") {
1163 bbox = this.node.getBBox();
1165 // Firefox 3.0.x plays badly here
1169 if (this.type == "text") {
1170 bbox = {x: bbox.x, y: Infinity, width: bbox.width, height: 0};
1171 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1172 var bb = this.node.getExtentOfChar(i);
1173 (bb.y < bbox.y) && (bbox.y = bb.y);
1174 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1177 hide && this.hide();
1180 Element.prototype.attr = function () {
1181 if (arguments.length == 1 && typeof arguments[0] == "string") {
1182 if (arguments[0] == "translation") {
1183 return this.translate();
1185 if (arguments[0] == "rotation") {
1186 return this.rotate();
1188 if (arguments[0] == "scale") {
1189 return this.scale();
1191 return this.attrs[arguments[0]];
1193 if (arguments.length == 1 && R.isArray(arguments[0])) {
1195 for (var j in arguments[0]) {
1196 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1200 if (arguments.length == 2) {
1202 params[arguments[0]] = arguments[1];
1203 setFillAndStroke(this, params);
1204 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1205 setFillAndStroke(this, arguments[0]);
1209 Element.prototype.toFront = function () {
1210 this.node.parentNode.appendChild(this.node);
1213 Element.prototype.toBack = function () {
1214 if (this.node.parentNode.firstChild != this.node) {
1215 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1219 Element.prototype.insertAfter = function (element) {
1220 if (element.node.nextSibling) {
1221 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1223 element.node.parentNode.appendChild(this.node);
1227 Element.prototype.insertBefore = function (element) {
1228 var node = element.node;
1229 node.parentNode.insertBefore(this.node, node);
1232 var theCircle = function (svg, x, y, r) {
1233 var el = doc.createElementNS(svg.svgns, "circle");
1234 el.setAttribute("cx", x);
1235 el.setAttribute("cy", y);
1236 el.setAttribute("r", r);
1237 el.setAttribute("fill", "none");
1238 el.setAttribute("stroke", "#000");
1240 svg.canvas.appendChild(el);
1242 var res = new Element(el, svg);
1243 res.attrs = res.attrs || {};
1247 res.attrs.stroke = "#000";
1248 res.type = "circle";
1251 var theRect = function (svg, x, y, w, h, r) {
1252 var el = doc.createElementNS(svg.svgns, "rect");
1253 el.setAttribute("x", x);
1254 el.setAttribute("y", y);
1255 el.setAttribute("width", w);
1256 el.setAttribute("height", h);
1258 el.setAttribute("rx", r);
1259 el.setAttribute("ry", r);
1261 el.setAttribute("fill", "none");
1262 el.setAttribute("stroke", "#000");
1264 svg.canvas.appendChild(el);
1266 var res = new Element(el, svg);
1267 res.attrs = res.attrs || {};
1270 res.attrs.width = w;
1271 res.attrs.height = h;
1272 res.attrs.stroke = "#000";
1274 res.attrs.rx = res.attrs.ry = r;
1279 var theEllipse = function (svg, x, y, rx, ry) {
1280 var el = doc.createElementNS(svg.svgns, "ellipse");
1281 el.setAttribute("cx", x);
1282 el.setAttribute("cy", y);
1283 el.setAttribute("rx", rx);
1284 el.setAttribute("ry", ry);
1285 el.setAttribute("fill", "none");
1286 el.setAttribute("stroke", "#000");
1288 svg.canvas.appendChild(el);
1290 var res = new Element(el, svg);
1291 res.attrs = res.attrs || {};
1296 res.attrs.stroke = "#000";
1297 res.type = "ellipse";
1300 var theImage = function (svg, src, x, y, w, h) {
1301 var el = doc.createElementNS(svg.svgns, "image");
1302 el.setAttribute("x", x);
1303 el.setAttribute("y", y);
1304 el.setAttribute("width", w);
1305 el.setAttribute("height", h);
1306 el.setAttribute("preserveAspectRatio", "none");
1307 el.setAttributeNS(svg.xlink, "href", src);
1309 svg.canvas.appendChild(el);
1311 var res = new Element(el, svg);
1312 res.attrs = res.attrs || {};
1313 res.attrs.src = src;
1316 res.attrs.width = w;
1317 res.attrs.height = h;
1321 var theText = function (svg, x, y, text) {
1322 var el = doc.createElementNS(svg.svgns, "text");
1323 el.setAttribute("x", x);
1324 el.setAttribute("y", y);
1325 el.setAttribute("text-anchor", "middle");
1327 svg.canvas.appendChild(el);
1329 var res = new Element(el, svg);
1330 res.attrs = res.attrs || {};
1331 res.attrs.text = text;
1335 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000", text: text});
1338 var setSize = function (width, height) {
1339 this.width = width || this.width;
1340 this.height = height || this.height;
1341 this.canvas.setAttribute("width", this.width);
1342 this.canvas.setAttribute("height", this.height);
1345 var create = function () {
1346 var con = getContainer.apply(null, arguments),
1347 container = con.container,
1351 height = con.height;
1353 throw new Error("SVG container not found.");
1355 paper.canvas = doc.createElementNS(paper.svgns, "svg");
1356 paper.canvas.setAttribute("width", width || 512);
1357 paper.width = width || 512;
1358 paper.canvas.setAttribute("height", height || 342);
1359 paper.height = height || 342;
1360 if (container == 1) {
1361 doc.body.appendChild(paper.canvas);
1362 paper.canvas.style.position = "absolute";
1363 paper.canvas.style.left = x + "px";
1364 paper.canvas.style.top = y + "px";
1366 if (container.firstChild) {
1367 container.insertBefore(paper.canvas, container.firstChild);
1369 container.appendChild(paper.canvas);
1373 canvas: paper.canvas,
1374 clear: function () {
1375 while (this.canvas.firstChild) {
1376 this.canvas.removeChild(this.canvas.firstChild);
1378 this.defs = doc.createElementNS(paper.svgns, "defs");
1379 this.canvas.appendChild(this.defs);
1382 for (var prop in paper) {
1383 if (prop != "create") {
1384 container[prop] = paper[prop];
1387 plugins.call(container, container, R.fn);
1389 container.raphael = R;
1392 paper.remove = function () {
1393 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1395 paper.svgns = "http://www.w3.org/2000/svg";
1396 paper.xlink = "http://www.w3.org/1999/xlink";
1397 paper.safari = function () {
1398 if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) {
1399 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1400 setTimeout(function () {rect.remove();});
1407 var path2vml = function (path) {
1408 var pa = path2curve(path);
1409 for (var i = 0, ii = pa.length; i < ii; i++) {
1410 for (var j = 0, jj = pa[i].length; j < jj; j++) {
1411 pa[i][j] = isNaN(pa[i][j]) ? pa[i][j] : Math.round(pa[i][j]);
1414 return (pa + "").toLowerCase().replace(/z/g, "x");
1416 R.toString = function () {
1417 return "Your browser doesn\u2019t support SVG. Assuming it is Internet Explorer and falling down to VML.\nYou are running Rapha\u00ebl " + this.version;
1419 var thePath = function (params, pathString, VML) {
1420 var g = createNode("group"), gl = g.style;
1421 gl.position = "absolute";
1424 gl.width = VML.width + "px";
1425 gl.height = VML.height + "px";
1426 g.coordsize = VML.coordsize;
1427 g.coordorigin = VML.coordorigin;
1428 var el = createNode("shape"), ol = el.style;
1429 ol.width = VML.width + "px";
1430 ol.height = VML.height + "px";
1432 if (params["class"]) {
1433 el.className = "rvml " + params["class"];
1435 el.coordsize = this.coordsize;
1436 el.coordorigin = this.coordorigin;
1438 var p = new Element(el, g, VML);
1439 p.isAbsolute = true;
1442 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1444 for (var method in pathMethods) {
1445 p[method] = pathMethods[method];
1449 params.fill = params.fill || "none";
1450 params.stroke = params.stroke || "#000";
1452 params = {fill: "none", stroke: "#000"};
1455 p.node.path = path2vml(pathString);
1456 p.attrs.path = pathString;
1458 setFillAndStroke(p, params);
1459 if (params.gradient) {
1460 addGradientFill(p, params.gradient);
1463 VML.canvas.appendChild(g);
1466 var setFillAndStroke = function (o, params) {
1471 o.attrs = o.attrs || {};
1472 for (var par in params) {
1473 o.attrs[par] = params[par];
1475 params.href && (node.href = params.href);
1476 params.title && (node.title = params.title);
1477 params.target && (node.target = params.target);
1478 if (params.path && o.type == "path") {
1479 o.node.path = path2vml(params.path);
1481 if (params.rotation != null) {
1482 o.rotate(params.rotation, true);
1484 if (params.translation) {
1485 xy = (params.translation + "").split(separator);
1486 o.translate(xy[0], xy[1]);
1489 xy = (params.scale + "").split(separator);
1490 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1492 if (o.type == "image" && params.src) {
1493 node.src = params.src;
1495 if (o.type == "image" && params.opacity) {
1496 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1497 node.style.filter = (node.filterMatrix || "") + (node.filterOpacity || "");
1499 params.font && (s.font = params.font);
1500 params["font-family"] && (s.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, "") + '"');
1501 params["font-size"] && (s.fontSize = params["font-size"]);
1502 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1503 params["font-style"] && (s.fontStyle = params["font-style"]);
1504 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["fill-opacity"] || params["stroke-dasharray"] || params["stroke-miterlimit"] || params["stroke-linejoin"] || params["stroke-linecap"]) {
1505 o = o.shape || node;
1506 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || createNode("fill");
1507 if ("fill-opacity" in params || "opacity" in params) {
1508 var opacity = ((+params["fill-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1509 opacity < 0 && (opacity = 0);
1510 opacity > 1 && (opacity = 1);
1511 fill.opacity = opacity;
1513 params.fill && (fill.on = true);
1514 if (typeof fill.on == "undefined" || params.fill == "none") {
1517 if (fill.on && params.fill) {
1518 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1520 fill.src = isURL[1];
1523 fill.color = R.getRGB(params.fill).hex;
1525 fill.type = "solid";
1528 o.appendChild(fill);
1529 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || createNode("stroke");
1530 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"]) {
1533 if (params.stroke == "none" || typeof stroke.on == "undefined" || params.stroke == 0) {
1536 if (stroke.on && params.stroke) {
1537 stroke.color = R.getRGB(params.stroke).hex;
1539 var opacity = ((+params["stroke-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1540 opacity < 0 && (opacity = 0);
1541 opacity > 1 && (opacity = 1);
1542 stroke.opacity = opacity;
1543 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1544 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1545 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1546 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"]) || 1) * 12 / 16);
1547 if (params["stroke-dasharray"]) {
1551 "-.": "shortdashdot",
1552 "-..": "shortdashdotdot",
1557 "--.": "longdashdot",
1558 "--..": "longdashdotdot"
1560 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1562 o.appendChild(stroke);
1564 if (res.type == "text") {
1565 var s = paper.span.style,
1567 a.font && (s.font = a.font);
1568 a["font-family"] && (s.fontFamily = a["font-family"]);
1569 a["font-size"] && (s.fontSize = a["font-size"]);
1570 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1571 a["font-style"] && (s.fontStyle = a["font-style"]);
1572 paper.span.innerHTML = "";
1573 paper.span.appendChild(doc.createTextNode(res.node.string));
1574 res.W = a.w = paper.span.offsetWidth;
1575 res.H = a.h = paper.span.offsetHeight;
1577 res.Y = a.y + Math.round(res.H / 2);
1579 // text-anchor emulation
1580 switch (a["text-anchor"]) {
1582 res.node.style["v-text-align"] = "left";
1583 res.bbx = Math.round(res.W / 2);
1586 res.node.style["v-text-align"] = "right";
1587 res.bbx = -Math.round(res.W / 2);
1590 res.node.style["v-text-align"] = "center";
1595 var getAngle = function (a, b, c, d) {
1596 var angle = Math.round(Math.atan((parseFloat(c) - parseFloat(a)) / (parseFloat(d) - parseFloat(b))) * 57.29) || 0;
1597 if (!angle && parseFloat(a) < parseFloat(b)) {
1606 var addGradientFill = function (o, gradient) {
1607 gradient = toGradient(gradient);
1608 o.attrs = o.attrs || {};
1609 var attrs = o.attrs,
1610 fill = o.node.getElementsByTagName("fill");
1611 o.attrs.gradient = gradient;
1612 o = o.shape || o.node;
1616 fill = createNode("fill");
1618 if (gradient.dots.length) {
1620 fill.method = "none";
1621 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1622 if (typeof gradient.dots[0].color != "undefined") {
1623 fill.color = R.getRGB(gradient.dots[0].color).hex;
1625 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1626 fill.color2 = R.getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1629 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1630 if (gradient.dots[i].offset) {
1631 clrs.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
1634 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;
1636 fill.colors.value = clrs.join(",");
1637 fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
1639 fill.colors && (fill.colors.value = "0% " + fill.color);
1641 fill.opacity = fillOpacity;
1642 if (typeof gradient.angle != "undefined") {
1643 fill.angle = (-gradient.angle + 270) % 360;
1644 } else if (gradient.vector) {
1645 fill.angle = getAngle.apply(null, gradient.vector);
1647 if ((gradient.type + "").toLowerCase() == "radial") {
1648 fill.focus = "100%";
1649 fill.focusposition = "0.5 0.5";
1653 var Element = function (node, group, vml) {
1673 Element.prototype.rotate = function (deg, cx, cy) {
1676 return [this._.rt.deg, this._.rt.cx, this._.rt.cy].join(" ");
1678 return this._.rt.deg;
1680 deg = (deg + "").split(separator);
1681 if (deg.length - 1) {
1682 cx = parseFloat(deg[1]);
1683 cy = parseFloat(deg[2]);
1685 deg = parseFloat(deg[0]);
1687 this._.rt.deg = deg;
1689 this._.rt.deg += deg;
1691 (cy == null) && (cx = null);
1694 this.setBox(this.attrs, cx, cy);
1695 this.Group.style.rotation = this._.rt.deg;
1696 // gradient fix for rotation. TODO
1697 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1698 // fill = fill[0] || {};
1699 // var b = ((360 - this._.rt.deg) - 270) % 360;
1700 // typeof fill.angle != "undefined" && (fill.angle = b);
1703 Element.prototype.setBox = function (params, cx, cy) {
1704 var gs = this.Group.style,
1705 os = (this.shape && this.shape.style) || this.node.style;
1706 params = params || {};
1707 for (var i in params) {
1708 this.attrs[i] = params[i];
1710 cx = cx || this._.rt.cx;
1711 cy = cy || this._.rt.cy;
1712 var attr = this.attrs,
1717 switch (this.type) {
1719 x = attr.cx - attr.r;
1720 y = attr.cy - attr.r;
1724 x = attr.cx - attr.rx;
1725 y = attr.cy - attr.ry;
1733 w = attr.width || 0;
1734 h = attr.height || 0;
1737 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("");
1738 x = attr.x - Math.round(this.W / 2);
1739 y = attr.y - this.H / 2;
1744 if (!this.attrs.path) {
1747 w = this.paper.width;
1748 h = this.paper.height;
1750 var dim = pathDimensions(this.attrs.path),
1760 w = this.paper.width;
1761 h = this.paper.height;
1764 cx = (cx == null) ? x + w / 2 : cx;
1765 cy = (cy == null) ? y + h / 2 : cy;
1766 var left = cx - this.paper.width / 2,
1767 top = cy - this.paper.height / 2;
1768 if (this.type == "path" || this.type == "text") {
1769 (gs.left != left + "px") && (gs.left = left + "px");
1770 (gs.top != top + "px") && (gs.top = top + "px");
1771 this.X = this.type == "text" ? x : -left;
1772 this.Y = this.type == "text" ? y : -top;
1775 (os.left != -left + "px") && (os.left = -left + "px");
1776 (os.top != -top + "px") && (os.top = -top + "px");
1778 (gs.left != left + "px") && (gs.left = left + "px");
1779 (gs.top != top + "px") && (gs.top = top + "px");
1784 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
1785 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
1786 (os.left != x - left + "px") && (os.left = x - left + "px");
1787 (os.top != y - top + "px") && (os.top = y - top + "px");
1788 (os.width != w + "px") && (os.width = w + "px");
1789 (os.height != h + "px") && (os.height = h + "px");
1790 var arcsize = (+params.r || 0) / (Math.min(w, h));
1791 if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
1792 // We should replace element with the new one
1793 var o = createNode(arcsize ? "roundrect" : "rect");
1794 o.arcsize = arcsize;
1795 this.Group.appendChild(o);
1796 this.node.parentNode.removeChild(this.node);
1798 this.arcsize = arcsize;
1799 setFillAndStroke(this, this.attrs);
1800 this.setBox(this.attrs);
1804 Element.prototype.hide = function () {
1805 this.Group.style.display = "none";
1808 Element.prototype.show = function () {
1809 this.Group.style.display = "block";
1812 Element.prototype.getBBox = function () {
1813 if (this.type == "path") {
1814 return pathDimensions(this.attr("path"));
1817 x: this.X + (this.bbx || 0),
1823 Element.prototype.remove = function () {
1824 this[0].parentNode.removeChild(this[0]);
1825 this.Group.parentNode.removeChild(this.Group);
1826 this.shape && this.shape.parentNode.removeChild(this.shape);
1828 Element.prototype.attr = function () {
1829 if (arguments.length == 1 && typeof arguments[0] == "string") {
1830 if (arguments[0] == "translation") {
1831 return this.translate();
1833 if (arguments[0] == "rotation") {
1834 return this.rotate();
1836 if (arguments[0] == "scale") {
1837 return this.scale();
1839 return this.attrs[arguments[0]];
1841 if (this.attrs && arguments.length == 1 && R.isArray(arguments[0])) {
1843 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1844 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1849 if (arguments.length == 2) {
1851 params[arguments[0]] = arguments[1];
1853 if (arguments.length == 1 && typeof arguments[0] == "object") {
1854 params = arguments[0];
1857 if (params.gradient) {
1858 addGradientFill(this, params.gradient);
1860 if (params.text && this.type == "text") {
1861 this.node.string = params.text;
1863 setFillAndStroke(this, params);
1864 this.setBox(this.attrs);
1868 Element.prototype.toFront = function () {
1869 this.Group.parentNode.appendChild(this.Group);
1872 Element.prototype.toBack = function () {
1873 if (this.Group.parentNode.firstChild != this.Group) {
1874 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
1878 Element.prototype.insertAfter = function (element) {
1879 if (element.Group.nextSibling) {
1880 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
1882 element.Group.parentNode.appendChild(this.Group);
1886 Element.prototype.insertBefore = function (element) {
1887 element.Group.parentNode.insertBefore(this.Group, element.Group);
1890 var theCircle = function (vml, x, y, r) {
1891 var g = createNode("group"),
1893 o = createNode("oval"),
1895 gl.position = "absolute";
1898 gl.width = vml.width + "px";
1899 gl.height = vml.height + "px";
1900 g.coordsize = vml.coordsize;
1901 g.coordorigin = vml.coordorigin;
1903 var res = new Element(o, g, vml);
1904 res.type = "circle";
1905 setFillAndStroke(res, {stroke: "#000", fill: "none"});
1909 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
1910 vml.canvas.appendChild(g);
1913 var theRect = function (vml, x, y, w, h, r) {
1914 var g = createNode("group"),
1916 o = createNode(r ? "roundrect" : "rect"),
1917 arcsize = (+r || 0) / (Math.min(w, h));
1918 o.arcsize = arcsize;
1919 gl.position = "absolute";
1922 gl.width = vml.width + "px";
1923 gl.height = vml.height + "px";
1924 g.coordsize = vml.coordsize;
1925 g.coordorigin = vml.coordorigin;
1927 var res = new Element(o, g, vml);
1929 setFillAndStroke(res, {stroke: "#000"});
1930 res.arcsize = arcsize;
1931 res.setBox({x: x, y: y, width: w, height: h, r: +r});
1932 vml.canvas.appendChild(g);
1935 var theEllipse = function (vml, x, y, rx, ry) {
1936 var g = createNode("group"),
1938 o = createNode("oval"),
1940 gl.position = "absolute";
1943 gl.width = vml.width + "px";
1944 gl.height = vml.height + "px";
1945 g.coordsize = vml.coordsize;
1946 g.coordorigin = vml.coordorigin;
1948 var res = new Element(o, g, vml);
1949 res.type = "ellipse";
1950 setFillAndStroke(res, {stroke: "#000"});
1955 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
1956 vml.canvas.appendChild(g);
1959 var theImage = function (vml, src, x, y, w, h) {
1960 var g = createNode("group"),
1962 o = createNode("image"),
1964 gl.position = "absolute";
1967 gl.width = vml.width + "px";
1968 gl.height = vml.height + "px";
1969 g.coordsize = vml.coordsize;
1970 g.coordorigin = vml.coordorigin;
1973 var res = new Element(o, g, vml);
1975 res.attrs.src = src;
1980 res.setBox({x: x, y: y, width: w, height: h});
1981 vml.canvas.appendChild(g);
1984 var theText = function (vml, x, y, text) {
1985 var g = createNode("group"),
1987 el = createNode("shape"),
1989 path = createNode("path"),
1991 o = createNode("textpath");
1992 gs.position = "absolute";
1995 gs.width = vml.width + "px";
1996 gs.height = vml.height + "px";
1997 g.coordsize = vml.coordsize;
1998 g.coordorigin = vml.coordorigin;
1999 path.v = ["m", Math.round(x), ", ", Math.round(y), "l", Math.round(x) + 1, ", ", Math.round(y)].join("");
2000 path.textpathok = true;
2001 ol.width = vml.width;
2002 ol.height = vml.height;
2003 gs.position = "absolute";
2006 gs.width = vml.width;
2007 gs.height = vml.height;
2011 el.appendChild(path);
2013 var res = new Element(o, g, vml);
2015 res.textpath = path;
2017 res.attrs.text = text;
2022 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2024 vml.canvas.appendChild(g);
2027 var setSize = function (width, height) {
2028 var cs = this.canvas.style;
2029 this.width = width || this.width;
2030 this.height = height || this.height;
2031 cs.width = this.width + "px";
2032 cs.height = this.height + "px";
2033 cs.clip = "rect(0 " + this.width + "px " + this.height + "px 0)";
2034 this.canvas.coordsize = this.width + " " + this.height;
2037 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2039 if (!doc.namespaces.rvml) {
2040 doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2042 var createNode = function (tagName) {
2043 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2046 var createNode = function (tagName) {
2047 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2050 var create = function () {
2051 var con = getContainer.apply(null, arguments),
2052 container = con.container,
2057 height = con.height;
2059 throw new Error("VML container not found.");
2061 var c = paper.canvas = doc.createElement("div"),
2063 width = parseFloat(width) || "512px";
2064 height = parseFloat(height) || "342px";
2065 paper.width = width;
2066 paper.height = height;
2067 paper.coordsize = width + " " + height;
2068 paper.coordorigin = "0 0";
2069 paper.span = doc.createElement("span");
2070 s = paper.span.style;
2071 c.appendChild(paper.span);
2072 s.position = "absolute";
2073 s.left = "-99999px";
2078 s.display = "inline";
2079 cs.width = width + "px";
2080 cs.height = height + "px";
2081 cs.position = "absolute";
2082 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2083 if (container == 1) {
2084 doc.body.appendChild(c);
2094 container.style.width = width;
2095 container.style.height = height;
2096 if (container.firstChild) {
2097 container.insertBefore(c, container.firstChild);
2099 container.appendChild(c);
2102 for (var prop in paper) {
2103 container[prop] = paper[prop];
2105 plugins.call(container, container, R.fn);
2106 container.clear = function () {
2107 while (c.firstChild) {
2108 c.removeChild(c.firstChild);
2111 container.raphael = R;
2114 paper.remove = function () {
2115 this.canvas.parentNode.removeChild(this.canvas);
2117 paper.safari = function () {};
2123 var addEvent = (function () {
2124 if (doc.addEventListener) {
2125 return function (obj, type, fn, element) {
2126 var f = function (e) {
2127 return fn.call(element, e);
2129 obj.addEventListener(type, f, false);
2130 return function () {
2131 obj.removeEventListener(type, f, false);
2135 } else if (doc.attachEvent) {
2136 return function (obj, type, fn, element) {
2137 var f = function (e) {
2138 return fn.call(element, e || win.event);
2140 obj.attachEvent("on" + type, f);
2141 var detacher = function () {
2142 obj.detachEvent("on" + type, f);
2145 if (type == "mouseover") {
2146 obj.attachEvent("onmouseenter", f);
2147 return function () {
2148 obj.detachEvent("onmouseenter", f);
2151 } else if (type == "mouseout") {
2152 obj.attachEvent("onmouseleave", f);
2153 return function () {
2154 obj.detachEvent("onmouseleave", f);
2162 for (var i = events.length; i--;) {
2163 (function (eventName) {
2164 Element.prototype[eventName] = function (fn) {
2165 if (typeof fn == "function") {
2166 this.events = this.events || {};
2167 this.events[eventName] = this.events[eventName] || {};
2168 this.events[eventName][fn] = this.events[eventName][fn] || [];
2169 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2173 Element.prototype["un" + eventName] = function (fn) {
2175 this.events[eventName] &&
2176 this.events[eventName][fn] &&
2177 this.events[eventName][fn].length &&
2178 this.events[eventName][fn].shift()() &&
2179 !this.events[eventName][fn].length &&
2180 delete this.events[eventName][fn];
2185 paper.circle = function (x, y, r) {
2186 return theCircle(this, x, y, r);
2188 paper.rect = function (x, y, w, h, r) {
2189 return theRect(this, x, y, w, h, r);
2191 paper.ellipse = function (x, y, rx, ry) {
2192 return theEllipse(this, x, y, rx, ry);
2194 paper.path = function (params, pathString) {
2195 if (typeof params == "string" && !pathString) {
2196 pathString = params;
2199 params = params || {};
2200 return thePath(params, pathString, this);
2202 paper.image = function (src, x, y, w, h) {
2203 return theImage(this, src, x, y, w, h);
2205 paper.text = function (x, y, text) {
2206 return theText(this, x, y, text);
2208 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
2209 color = color || "#000";
2210 var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
2212 columnWidth = w / wv;
2213 for (var i = 1; i < hv; i++) {
2214 path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
2216 for (var i = 1; i < wv; i++) {
2217 path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
2219 return this.path({stroke: color, "stroke-width": 1}, path.join(","));
2221 paper.set = function (itemsArray) {
2222 return new Set(itemsArray);
2224 paper.setSize = setSize;
2225 Element.prototype.stop = function () {
2226 clearTimeout(this.animation_in_progress);
2228 Element.prototype.scale = function (x, y, cx, cy) {
2229 if (x == null && y == null) {
2230 return {x: this._.sx, y: this._.sy, toString: function () { return +this.x.toFixed(3) + " " + (+this.y.toFixed(3)); }};
2240 var bb = this.type == "path" ? pathDimensions(a.path) : this.getBBox(),
2241 rcx = bb.x + bb.width / 2,
2242 rcy = bb.y + bb.height / 2,
2245 cx = (+cx || cx == 0) ? cx : rcx;
2246 cy = (+cy || cy == 0) ? cy : rcy;
2247 var dirx = Math.round(x / Math.abs(x)),
2248 diry = Math.round(y / Math.abs(y)),
2249 s = this.node.style,
2250 ncx = cx + (rcx - cx) * dirx * kx,
2251 ncy = cy + (rcy - cy) * diry * ky;
2252 switch (this.type) {
2255 var neww = a.width * dirx * kx,
2256 newh = a.height * diry * ky,
2257 newx = ncx - neww / 2,
2258 newy = ncy - newh / 2;
2277 var path = pathToRelative(a.path),
2279 for (var i = 0, ii = path.length; i < ii; i++) {
2281 if (p[0].toUpperCase() == "M" && skip) {
2286 if (R.svg && p[0].toUpperCase() == "A") {
2287 p[path[i].length - 2] *= kx;
2288 p[path[i].length - 1] *= ky;
2291 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2293 for (var j = 1, jj = p.length; j < jj; j++) {
2294 p[j] *= (j % 2) ? kx : ky;
2298 var dim2 = pathDimensions(path),
2299 dx = ncx - dim2.x - dim2.width / 2,
2300 dy = ncy - dim2.y - dim2.height / 2;
2301 path = pathToRelative(path);
2305 this.attr({path: path.join(" ")});
2308 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2309 if (this.transformations) {
2310 this.transformations[2] = "scale(".concat(dirx, ",", diry, ")");
2311 this.node.setAttribute("transform", this.transformations.join(" "));
2312 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2313 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2314 this.attr({x: dx, y: dy});
2318 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=".concat(dirx,
2319 ", M12=0, M21=0, M22=", diry,
2320 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2321 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2324 if (this.transformations) {
2325 this.transformations[2] = "";
2326 this.node.setAttribute("transform", this.transformations.join(" "));
2330 this.node.filterMatrix = "";
2331 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2334 a.scale = [x, y, cx, cy].join(" ");
2341 R.easing_formulas = {
2342 linear: function (n) {
2346 return Math.pow(n, 3);
2349 return Math.pow(n - 1, 3) + 1;
2351 "<>": function (n) {
2354 return Math.pow(n, 3) / 2;
2357 return (Math.pow(n, 3) + 2) / 2;
2359 backIn: function (n) {
2361 return Math.pow(n, 2) * ((s + 1) * n - s);
2363 backOut: function (n) {
2366 return Math.pow(n, 2) * ((s + 1) * n + s) + 1;
2368 elastic: function (n) {
2369 if (n == 0 || n == 1) {
2374 return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1;
2376 bounce: function (n) {
2381 l = s * Math.pow(n, 2);
2385 l = s * Math.pow(n, 2) + .75;
2387 if (n < (2.5 / p)) {
2389 l = s * Math.pow(n, 2) + .9375;
2392 l = s * Math.pow(n, 2) + .984375;
2400 // animation easing formulas
2401 R.easing = function(easing, n) {
2402 return R.easing_formulas[easing] ? R.easing_formulas[easing](n) : n;
2405 Element.prototype.animate = function (params, ms, easing, callback) {
2406 clearTimeout(this.animation_in_progress);
2407 if (typeof easing == "function" || !easing) {
2408 callback = easing || null;
2415 for (var attr in params) {
2416 if (attr in availableAnimAttrs) {
2417 from[attr] = this.attr(attr);
2418 (typeof from[attr] == "undefined") && (from[attr] = availableAttrs[attr]);
2419 to[attr] = params[attr];
2420 switch (availableAnimAttrs[attr]) {
2422 diff[attr] = (to[attr] - from[attr]) / ms;
2425 from[attr] = R.getRGB(from[attr]);
2426 var toColour = R.getRGB(to[attr]);
2428 r: (toColour.r - from[attr].r) / ms,
2429 g: (toColour.g - from[attr].g) / ms,
2430 b: (toColour.b - from[attr].b) / ms
2434 var pathes = path2curve(from[attr], to[attr]);
2435 from[attr] = pathes[0];
2436 to[attr] = pathes[1];
2438 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2439 diff[attr][i] = [0];
2440 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2441 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2446 var values = (params[attr] + "").split(separator),
2447 from2 = (from[attr] + "").split(separator);
2450 from[attr] = [0, 0];
2451 diff[attr] = [values[0] / ms, values[1] / ms];
2454 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2455 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2458 params[attr] = values;
2459 from[attr] = (from[attr] + "").split(separator);
2460 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2466 var start = +new Date,
2470 var time = new Date - start,
2474 pos = R.easing(easing, time / ms);
2475 for (var attr in from) {
2476 switch (availableAnimAttrs[attr]) {
2478 now = +from[attr] + pos * ms * diff[attr];
2482 Math.round(from[attr].r + pos * ms * diff[attr].r),
2483 Math.round(from[attr].g + pos * ms * diff[attr].g),
2484 Math.round(from[attr].b + pos * ms * diff[attr].b)
2489 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2490 now[i] = [from[attr][i][0]];
2491 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2492 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
2494 now[i] = now[i].join(" ");
2496 now = now.join(" ");
2501 var x = diff[attr][0] * (time - prev),
2502 y = diff[attr][1] * (time - prev);
2505 now = [x, y].join(" ");
2508 now = +from[attr][0] + pos * ms * diff[attr][0];
2509 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2512 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(" ");
2516 if (attr == "font-size") {
2517 set[attr] = now + "px";
2523 that.animation_in_progress = setTimeout(tick);
2524 R.svg && paper.safari();
2526 (t.x || t.y) && that.translate(-t.x, -t.y);
2528 clearTimeout(that.animation_in_progress);
2529 R.svg && paper.safari();
2530 (typeof callback == "function") && callback.call(that);
2536 Element.prototype.translate = function (x, y) {
2538 return {x: this._.tx, y: this._.ty};
2542 switch (this.type) {
2545 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
2550 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
2553 var path = pathToRelative(this.attrs.path);
2556 this.attr({path: path.join(" ")});
2563 var Set = function (items) {
2567 for (var i = 0, ii = items.length; i < ii; i++) {
2568 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
2569 this[this.items.length] = this.items[this.items.length] = items[i];
2575 Set.prototype.push = function () {
2578 for (var i = 0, ii = arguments.length; i < ii; i++) {
2579 item = arguments[i];
2580 if (item && (item.constructor == Element || item.constructor == Set)) {
2581 len = this.items.length;
2582 this[len] = this.items[len] = item;
2588 Set.prototype.pop = function (id) {
2589 var res = this.items.splice(id, 1)[0];
2590 for (var j = id, jj = this.items.length; j < jj; j++) {
2591 this[j] = this[j + 1];
2593 delete this[jj + 1];
2597 for (var method in Element.prototype) {
2598 Set.prototype[method] = (function (methodname) {
2599 return function () {
2600 for (var i = 0, ii = this.items.length; i < ii; i++) {
2601 this.items[i][methodname].apply(this.items[i], arguments);
2607 Set.prototype.attr = function (name, value) {
2608 if (name && R.isArray(name) && typeof name[0] == "object") {
2609 for (var j = 0, jj = name.length; j < jj; j++) {
2610 this.items[j].attr(name[j]);
2613 for (var i = 0, ii = this.items.length; i < ii; i++) {
2614 this.items[i].attr.apply(this.items[i], arguments);
2620 Set.prototype.getBBox = function () {
2625 for (var i = this.items.length; i--;) {
2626 var box = this.items[i].getBBox();
2629 w.push(box.x + box.width);
2630 h.push(box.y + box.height);
2632 x = Math.min.apply(Math, x);
2633 y = Math.min.apply(Math, y);
2637 width: Math.max.apply(Math, w) - x,
2638 height: Math.max.apply(Math, h) - y
2642 R.registerFont = function (font) {
2646 this.fonts = this.fonts || {};
2652 family = font.face["font-family"];
2653 for (var prop in font.face) {
2654 fontcopy.face[prop] = font.face[prop];
2656 if (this.fonts[family]) {
2657 this.fonts[family].push(fontcopy);
2659 this.fonts[family] = [fontcopy];
2662 fontcopy.face["units-per-em"] = parseInt(font.face["units-per-em"], 10);
2663 for (var glyph in font.glyphs) {
2664 var path = font.glyphs[glyph];
2665 fontcopy.glyphs[glyph] = {
2668 d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
2669 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
2673 for (var k in path.k) {
2674 fontcopy.glyphs[glyph].k[k] = path.k[k];
2681 paper.getFont = function (family, weight, style, stretch) {
2682 stretch = stretch || "normal";
2683 style = style || "normal";
2684 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
2685 var font = R.fonts[family];
2687 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, "") + "(\\s|$)", "i");
2688 for (var fontName in R.fonts) {
2689 if (name.test(fontName)) {
2690 font = R.fonts[fontName];
2697 for (var i = 0, ii = font.length; i < ii; i++) {
2699 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
2706 paper.print = function (x, y, string, font, size) {
2707 var out = this.set(),
2708 letters = (string + "").split(""),
2713 scale = (size || 16) / font.face["units-per-em"];
2714 for (var i = 0, ii = letters.length; i < ii; i++) {
2715 var prev = i && font.glyphs[letters[i - 1]] || {},
2716 curr = font.glyphs[letters[i]];
2717 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
2718 curr && curr.d && out.push(this.path({fill: "#000", stroke: "none"}, curr.d).translate(shift, 0));
2720 out.scale(scale, scale, 0, y).translate(x, (size || 16) / 2);
2725 R.ninja = function () {
2726 var r = window.Raphael;
2727 if (oldRaphael.was) {
2728 window.Raphael = oldRaphael.is;
2731 delete window.Raphael;
2733 window.Raphael = void(0);
2738 R.el = Element.prototype;