2 * Raphael 1.0 RC1.1 - 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"];
24 R.version = "1.0 RC1.1";
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 = cacher(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 = cacher(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 R._path2string = function () {
128 for (var i = 0, ii = this.length; i < ii; i++) {
129 for (var j = 0, jj = this[i].length; j < jj; j++) {
131 j && j != jj - 1 && (res += ",");
133 i != ii - 1 && (res += "\n");
135 return res.replace(/,(?=-)/g, "");
137 function cacher(f, scope, postprocessor) {
139 var arg = Array.prototype.splice.call(arguments, 0, arguments.length),
140 args = arg.join("\u25ba");
141 newf.cache = newf.cache || {};
142 newf.count = newf.count || [];
143 if (args in newf.cache) {
144 return postprocessor ? postprocessor(newf.cache[args]) : newf.cache[args];
146 if (newf.count.length > 1000) {
147 delete newf.cache[newf.count.unshift()];
149 newf.count.push(args);
150 newf.cache[args] = f.apply(scope, arg);
151 return postprocessor ? postprocessor(newf.cache[args]) : newf.cache[args];
156 R.getRGB = cacher(function (colour) {
157 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"},
159 if ((colour + "").toLowerCase() in htmlcolors) {
160 colour = htmlcolors[colour.toString().toLowerCase()];
163 return {r: 0, g: 0, b: 0, hex: "#000"};
165 if (colour == "none") {
166 return {r: -1, g: -1, b: -1, hex: "none"};
171 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);
174 blue = parseInt(rgb[2].substring(5), 16);
175 green = parseInt(rgb[2].substring(3, 5), 16);
176 red = parseInt(rgb[2].substring(1, 3), 16);
179 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
180 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
181 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
184 rgb = rgb[4].split(/\s*,\s*/);
185 red = parseFloat(rgb[0]);
186 green = parseFloat(rgb[1]);
187 blue = parseFloat(rgb[2]);
190 rgb = rgb[5].split(/\s*,\s*/);
191 red = parseFloat(rgb[0]) * 2.55;
192 green = parseFloat(rgb[1]) * 2.55;
193 blue = parseFloat(rgb[2]) * 2.55;
196 rgb = rgb[6].split(/\s*,\s*/);
197 red = parseFloat(rgb[0]);
198 green = parseFloat(rgb[1]);
199 blue = parseFloat(rgb[2]);
200 return R.hsb2rgb(red, green, blue);
203 rgb = rgb[7].split(/\s*,\s*/);
204 red = parseFloat(rgb[0]) * 2.55;
205 green = parseFloat(rgb[1]) * 2.55;
206 blue = parseFloat(rgb[2]) * 2.55;
207 return R.hsb2rgb(red, green, blue);
209 var rgb = {r: red, g: green, b: blue},
210 r = Math.round(red).toString(16),
211 g = Math.round(green).toString(16),
212 b = Math.round(blue).toString(16);
213 (r.length == 1) && (r = "0" + r);
214 (g.length == 1) && (g = "0" + g);
215 (b.length == 1) && (b = "0" + b);
216 rgb.hex = "#" + r + g + b;
219 res = {r: -1, g: -1, b: -1, hex: "none"};
223 R.getColor = function (value) {
224 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
225 rgb = this.hsb2rgb(start.h, start.s, start.b);
231 this.getColor.start = {h: 0, s: 1, b: start.b};
236 R.getColor.reset = function () {
240 R.parsePathString = cacher(function (pathString) {
244 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
246 if (R.isArray(pathString) && R.isArray(pathString[0])) { // rough assumption
247 data = pathClone(pathString);
250 (pathString + "").replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, function (a, b, c) {
252 name = b.toLowerCase();
253 c.replace(/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig, function (a, b) {
254 b && params.push(+b);
256 while (params.length >= paramCounts[name]) {
257 data.push([b].concat(params.splice(0, paramCounts[name])));
258 if (!paramCounts[name]) {
264 data.toString = R._path2string;
267 var pathDimensions = cacher(function (path) {
269 return {x: 0, y: 0, width: 0, height: 0};
271 path = path2curve(path);
276 for (var i = 0, ii = path.length; i < ii; i++) {
277 if (path[i][0] == "M") {
283 var dim = curveDim(x, y, path[i][1], path[i][2], path[i][3], path[i][4], path[i][5], path[i][6]);
284 X = X.concat(dim.min.x, dim.max.x);
285 Y = Y.concat(dim.min.y, dim.max.y);
288 var xmin = Math.min.apply(0, X),
289 ymin = Math.min.apply(0, Y);
293 width: Math.max.apply(0, X) - xmin,
294 height: Math.max.apply(0, Y) - ymin
297 pathClone = function (pathArray) {
299 if (!R.isArray(pathArray) || !R.isArray(pathArray && pathArray[0])) { // rough assumption
300 pathArray = R.parsePathString(pathArray);
302 for (var i = 0, ii = pathArray.length; i < ii; i++) {
304 for (var j = 0, jj = pathArray[i].length; j < jj; j++) {
305 res[i][j] = pathArray[i][j];
308 res.toString = R._path2string;
311 pathToRelative = cacher(function (pathArray) {
312 if (!R.isArray(pathArray) || !R.isArray(pathArray && pathArray[0])) { // rough assumption
313 pathArray = R.parsePathString(pathArray);
321 if (pathArray[0][0] == "M") {
327 res.push(["M", x, y]);
329 for (var i = start, ii = pathArray.length; i < ii; i++) {
332 if (pa[0] != pa[0].toLowerCase()) {
333 r[0] = pa[0].toLowerCase();
341 r[6] = +(pa[6] - x).toFixed(3);
342 r[7] = +(pa[7] - y).toFixed(3);
345 r[1] = +(pa[1] - y).toFixed(3);
351 for (var j = 1, jj = pa.length; j < jj; j++) {
352 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
361 for (var k = 0, kk = pa.length; k < kk; k++) {
365 var len = res[i].length;
372 x += +res[i][len - 1];
375 y += +res[i][len - 1];
378 x += +res[i][len - 2];
379 y += +res[i][len - 1];
382 res.toString = R._path2string;
385 pathToAbsolute = cacher(function (pathArray) {
386 if (!R.isArray(pathArray) || !R.isArray(pathArray && pathArray[0])) { // rough assumption
387 pathArray = R.parsePathString(pathArray);
395 if (pathArray[0][0] == "M") {
396 x = +pathArray[0][1];
397 y = +pathArray[0][2];
401 res[0] = ["M", x, y];
403 for (var i = start, ii = pathArray.length; i < ii; i++) {
406 if (pa[0] != (pa[0] + "").toUpperCase()) {
407 r[0] = (pa[0] + "").toUpperCase();
428 for (var j = 1, jj = pa.length; j < jj; j++) {
429 r[j] = +pa[j] + ((j % 2) ? x : y);
433 for (var k = 0, kk = pa.length; k < kk; k++) {
449 x = res[i][res[i].length - 2];
450 y = res[i][res[i].length - 1];
453 res.toString = R._path2string;
456 l2c = function (x1, y1, x2, y2) {
457 return [x1, y1, x2, y2, x2, y2];
459 q2c = function (x1, y1, ax, ay, x2, y2) {
461 2 / 3 * x1 + 1 / 3 * ax,
462 2 / 3 * y1 + 1 / 3 * ay,
463 2 / 3 * x1 + 1 / 3 * x2,
464 2 / 3 * y1 + 1 / 3 * y2,
469 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
470 // for more information of where this math came from visit:
471 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
472 var _120 = Math.PI * 120 / 180,
473 rad = Math.PI / 180 * (+angle || 0),
476 rotate = cacher(function (x, y, rad) {
477 var X = x * Math.cos(rad) - y * Math.sin(rad),
478 Y = x * Math.sin(rad) + y * Math.cos(rad);
482 xy = rotate(x1, y1, -rad);
485 xy = rotate(x2, y2, -rad);
488 var cos = Math.cos(Math.PI / 180 * angle),
489 sin = Math.sin(Math.PI / 180 * angle),
492 rx = Math.max(rx, Math.abs(x));
493 ry = Math.max(ry, Math.abs(y));
496 k = (large_arc_flag == sweep_flag ? -1 : 1) *
497 Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
498 cx = k * rx * y / ry + (x1 + x2) / 2,
499 cy = k * -ry * x / rx + (y1 + y2) / 2,
500 f1 = Math.asin((y1 - cy) / ry),
501 f2 = Math.asin((y2 - cy) / ry);
503 f1 = x1 < cx ? Math.PI - f1 : f1;
504 f2 = x2 < cx ? Math.PI - f2 : f2;
505 f1 < 0 && (f1 = Math.PI * 2 + f1);
506 f2 < 0 && (f2 = Math.PI * 2 + f2);
507 if (sweep_flag && f1 > f2) {
508 f1 = f1 - Math.PI * 2;
510 if (!sweep_flag && f2 > f1) {
511 f2 = f2 - Math.PI * 2;
520 if (Math.abs(df) > _120) {
524 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
525 x2 = cx + rx * Math.cos(f2);
526 y2 = cy + ry * Math.sin(f2);
527 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
529 var c1 = Math.cos(f1),
534 t = Math.tan(df / 4),
538 m2 = [x1 + hx * s1, y1 - hy * c1],
539 m3 = [x2 + hx * s2, y2 - hy * c2],
541 m2[0] = 2 * m1[0] - m2[0];
542 m2[1] = 2 * m1[1] - m2[1];
544 return [m2, m3, m4].concat(res);
546 res = [m2, m3, m4].concat(res).join(",").split(",");
548 for (var i = 0, ii = res.length; i < ii; i++) {
549 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
554 findDotAtSegment = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
555 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,
556 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,
557 mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
558 my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
559 nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
560 ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
561 ax = (1 - t) * p1x + t * c1x,
562 ay = (1 - t) * p1y + t * c1y,
563 cx = (1 - t) * c2x + t * p2x,
564 cy = (1 - t) * c2y + t * p2y;
565 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}};
567 curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
568 var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
569 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
571 t1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 / a,
572 t2 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2 / a,
575 dot1 = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1 > 0 && t1 < 1 ? t1 : 0),
576 dot2 = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2 > 0 && t2 < 1 ? t2 : 0);
577 x = x.concat(dot1.x, dot2.x);
578 y = y.concat(dot1.y, dot2.y);
579 a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
580 b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
582 t1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 / a;
583 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);
589 min: {x: Math.min.apply(Math, x), y: Math.min.apply(Math, y)},
590 max: {x: Math.max.apply(Math, x), y: Math.max.apply(Math, y)}
593 path2curve = cacher(function (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 return p2 ? [p, p2] : p;
681 toGradient = cacher(function (gradient) {
682 if (typeof gradient == "string") {
683 gradient = gradient.split(/\s*\-\s*/);
684 var angle = gradient.shift();
685 if (angle.toLowerCase() == "v") {
687 } else if (angle.toLowerCase() == "h") {
690 angle = parseFloat(angle);
693 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)]},
694 max = 1 / (Math.max(Math.abs(grobj.vector[2]), Math.abs(grobj.vector[3])) || 1);
695 grobj.vector[2] *= max;
696 grobj.vector[3] *= max;
697 if (grobj.vector[2] < 0) {
698 grobj.vector[0] = -grobj.vector[2];
701 if (grobj.vector[3] < 0) {
702 grobj.vector[1] = -grobj.vector[3];
705 grobj.vector[0] = grobj.vector[0];
706 grobj.vector[1] = grobj.vector[1];
707 grobj.vector[2] = grobj.vector[2];
708 grobj.vector[3] = grobj.vector[3];
709 for (var i = 0, ii = gradient.length; i < ii; i++) {
711 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
712 dot.color = R.getRGB(par[1]).hex;
713 par[2] && (dot.offset = par[2] + "%");
714 grobj.dots.push(dot);
716 for (var i = 1, ii = grobj.dots.length - 1; i < ii; i++) {
717 if (!grobj.dots[i].offset) {
718 var start = parseFloat(grobj.dots[i - 1].offset || 0),
720 for (var j = i + 1; j < ii; j++) {
721 if (grobj.dots[j].offset) {
722 end = grobj.dots[j].offset;
730 end = parseFloat(end);
731 var d = (end - start) / (j - i + 1);
734 grobj.dots[i].offset = start + "%";
743 getContainer = function () {
749 if (typeof arguments[0] == "string" || typeof arguments[0] == "object") {
750 if (typeof arguments[0] == "string") {
751 container = doc.getElementById(arguments[0]);
753 container = arguments[0];
755 if (container.tagName) {
756 if (arguments[1] == null) {
758 container: container,
759 width: container.style.pixelWidth || container.offsetWidth,
760 height: container.style.pixelHeight || container.offsetHeight
763 return {container: container, width: arguments[1], height: arguments[2]};
766 } else if (typeof arguments[0] == "number" && arguments.length > 3) {
767 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
770 plugins = function (con, add) {
772 for (var prop in add) if (add.hasOwnProperty(prop) && !(prop in con)) {
773 switch (typeof add[prop]) {
776 con[prop] = con === that ? f : function () { return f.apply(that, arguments); };
780 con[prop] = con[prop] || {};
781 plugins.call(this, con[prop], add[prop]);
784 con[prop] = add[prop];
792 var round = function (num) {
793 return +num + (Math.floor(num) == num) * .5;
795 var roundPath = function (path) {
796 for (var i = 0, ii = path.length; i < ii; i++) {
797 if (path[i][0].toLowerCase() != "a") {
798 for (var j = 1, jj = path[i].length; j < jj; j++) {
799 path[i][j] = round(path[i][j]);
802 path[i][6] = round(path[i][6]);
803 path[i][7] = round(path[i][7]);
808 R.toString = function () {
809 return "Your browser supports SVG.\nYou are running Rapha\u00ebl " + this.version;
811 var thePath = function (pathString, SVG) {
812 var el = doc.createElementNS(SVG.svgns, "path");
813 SVG.canvas && SVG.canvas.appendChild(el);
814 var p = new Element(el, SVG);
816 setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
819 var addGradientFill = function (o, gradient, SVG) {
820 gradient = toGradient(gradient);
821 var el = doc.createElementNS(SVG.svgns, (gradient.type || "linear") + "Gradient");
822 el.id = "r" + (R.idGenerator++).toString(36);
823 if (gradient.vector && gradient.vector.length) {
824 el.setAttribute("x1", gradient.vector[0]);
825 el.setAttribute("y1", gradient.vector[1]);
826 el.setAttribute("x2", gradient.vector[2]);
827 el.setAttribute("y2", gradient.vector[3]);
829 SVG.defs.appendChild(el);
830 var isopacity = true;
831 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
832 var stop = doc.createElementNS(SVG.svgns, "stop");
833 if (gradient.dots[i].offset) {
836 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
837 stop.setAttribute("stop-color", R.getRGB(gradient.dots[i].color).hex || "#fff");
838 // ignoring opacity for internal points, because VML doesn't support it
839 el.appendChild(stop);
841 if (isopacity && typeof gradient.dots[ii - 1].opacity != "undefined") {
842 stop.setAttribute("stop-opacity", gradient.dots[ii - 1].opacity);
844 o.setAttribute("fill", "url(#" + el.id + ")");
847 o.style.fillOpacity = 1;
848 o.setAttribute("opacity", 1);
849 o.setAttribute("fill-opacity", 1);
851 var updatePosition = function (o) {
852 var bbox = o.getBBox();
853 o.pattern.setAttribute("patternTransform", "translate(".concat(bbox.x, ",", bbox.y, ")"));
855 var setFillAndStroke = function (o, params) {
862 "-..": [3, 1, 1, 1, 1, 1],
868 "--..": [8, 3, 1, 3, 1, 3]
872 rot = o.attr("rotation"),
873 addDashes = function (o, value) {
874 value = dasharray[(value + "").toLowerCase()];
876 var width = o.attrs["stroke-width"] || "1",
877 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
879 for (var i = 0, ii = value.length; i < ii; i++) {
880 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
882 value = dashes.join(",");
883 node.setAttribute("stroke-dasharray", value);
886 parseInt(rot, 10) && o.rotate(0, true);
887 for (var att in params) {
888 if (!(att in availableAttrs)) {
891 var value = params[att];
898 var pn = node.parentNode;
899 if (pn.tagName.toLowerCase() != "a") {
900 var hl = doc.createElementNS(o.paper.svgns, "a");
901 pn.insertBefore(hl, node);
902 hl.appendChild(node);
905 pn.setAttributeNS(o.paper.xlink, att, value);
908 if (value && o.type == "path") {
909 attrs.path = roundPath(pathToAbsolute(value));
910 node.setAttribute("d", attrs.path);
913 node.setAttribute(att, value);
922 value = -attrs.x - (attrs.width || 0);
926 node.setAttribute(att, value);
927 o.pattern && updatePosition(o);
930 node.setAttribute(att, value);
939 value = -attrs.y - (attrs.height || 0);
943 node.setAttribute(att, value);
944 o.pattern && updatePosition(o);
947 if (o.type == "rect") {
948 node.setAttribute("rx", value);
949 node.setAttribute("ry", value);
951 node.setAttribute(att, value);
955 if (o.type == "image") {
956 node.setAttributeNS(o.paper.xlink, "href", value);
960 node.style.strokeWidth = value;
961 // Need following line for Firefox
962 node.setAttribute(att, value);
963 if (attrs["stroke-dasharray"]) {
964 addDashes(o, attrs["stroke-dasharray"]);
967 case "stroke-dasharray":
972 o.rotate(value, true);
975 var xy = (value + "").split(separator);
976 o.translate((+xy[0] + 1 || 2) - 1, (+xy[1] + 1 || 2) - 1);
979 var xy = (value + "").split(separator);
980 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
983 var isURL = (value + "").match(/^url\(['"]?([^\)]+)['"]?\)$/i);
985 var el = doc.createElementNS(o.paper.svgns, "pattern"),
986 ig = doc.createElementNS(o.paper.svgns, "image");
987 el.id = "r" + (R.idGenerator++).toString(36);
988 el.setAttribute("x", 0);
989 el.setAttribute("y", 0);
990 el.setAttribute("patternUnits", "userSpaceOnUse");
991 ig.setAttribute("x", 0);
992 ig.setAttribute("y", 0);
993 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
996 var img = doc.createElement("img");
997 img.style.position = "absolute";
998 img.style.top = "-9999em";
999 img.style.left = "-9999em";
1000 img.onload = function () {
1001 el.setAttribute("width", this.offsetWidth);
1002 el.setAttribute("height", this.offsetHeight);
1003 ig.setAttribute("width", this.offsetWidth);
1004 ig.setAttribute("height", this.offsetHeight);
1005 doc.body.removeChild(this);
1008 doc.body.appendChild(img);
1010 o.paper.defs.appendChild(el);
1011 node.style.fill = "url(#" + el.id + ")";
1012 node.setAttribute("fill", "url(#" + el.id + ")");
1014 o.pattern && updatePosition(o);
1017 delete params.gradient;
1018 delete attrs.gradient;
1019 if (typeof attrs.opacity != "undefined" && typeof params.opacity == "undefined" ) {
1020 node.style.opacity = attrs.opacity;
1021 // Need following line for Firefox
1022 node.setAttribute("opacity", attrs.opacity);
1024 if (typeof attrs["fill-opacity"] != "undefined" && typeof params["fill-opacity"] == "undefined" ) {
1025 node.style.fillOpacity = attrs["fill-opacity"];
1026 // Need following line for Firefox
1027 node.setAttribute("fill-opacity", attrs["fill-opacity"]);
1030 node.style[att] = R.getRGB(value).hex;
1031 // Need following line for Firefox
1032 node.setAttribute(att, R.getRGB(value).hex);
1035 addGradientFill(node, value, o.paper);
1038 case "fill-opacity":
1039 if (attrs.gradient) {
1040 var gradient = doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
1042 var stops = gradient.getElementsByTagName("stop");
1043 stops[stops.length - 1].setAttribute("stop-opacity", value);
1048 att == "font-size" && (value = parseInt(value, 10) + "px");
1049 var cssrule = att.replace(/(\-.)/g, function (w) {
1050 return w.substring(1).toUpperCase();
1052 node.style[cssrule] = value;
1053 // Need following line for Firefox
1054 node.setAttribute(att, value);
1059 tuneText(o, params);
1060 parseInt(rot, 10) && o.rotate(rot, true);
1063 var tuneText = function (el, params) {
1064 if (el.type != "text" || !("text" in params || "font" in params || "font-size" in params || "x" in params || "y" in params)) {
1069 fontSize = node.firstChild ? parseInt(doc.defaultView.getComputedStyle(node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
1071 if ("text" in params) {
1072 while (node.firstChild) {
1073 node.removeChild(node.firstChild);
1075 var texts = (params.text + "").split("\n");
1076 for (var i = 0, ii = texts.length; i < ii; i++) {
1077 var tspan = doc.createElementNS(el.paper.svgns, "tspan");
1078 i && tspan.setAttribute("dy", fontSize * leading);
1079 i && tspan.setAttribute("x", a.x);
1080 tspan.appendChild(doc.createTextNode(texts[i]));
1081 node.appendChild(tspan);
1084 var texts = node.getElementsByTagName("tspan");
1085 for (var i = 0, ii = texts.length; i < ii; i++) {
1086 i && texts[i].setAttribute("dy", fontSize * leading);
1087 i && texts[i].setAttribute("x", a.x);
1090 node.setAttribute("y", a.y);
1091 var bb = el.getBBox(),
1092 dif = a.y - (bb.y + bb.height / 2);
1093 dif && node.setAttribute("y", a.y + dif);
1095 var Element = function (node, svg) {
1101 this.attrs = this.attrs || {};
1102 this.transformations = []; // rotate, translate, scale
1106 rt: {deg: 0, cx: 0, cy: 0},
1111 Element.prototype.rotate = function (deg, cx, cy) {
1114 return [this._.rt.deg, this._.rt.cx, this._.rt.cy].join(" ");
1116 return this._.rt.deg;
1118 var bbox = this.getBBox();
1119 deg = (deg + "").split(separator);
1120 if (deg.length - 1) {
1121 cx = parseFloat(deg[1]);
1122 cy = parseFloat(deg[2]);
1124 deg = parseFloat(deg[0]);
1126 this._.rt.deg = deg;
1128 this._.rt.deg += deg;
1130 (cy == null) && (cx = null);
1133 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1134 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1135 if (this._.rt.deg) {
1136 this.transformations[0] = "rotate(".concat(this._.rt.deg, " ", cx, " ", cy, ")");
1138 this.transformations[0] = "";
1140 this.node.setAttribute("transform", this.transformations.join(" "));
1143 Element.prototype.hide = function () {
1144 this.node.style.display = "none";
1147 Element.prototype.show = function () {
1148 this.node.style.display = "block";
1151 Element.prototype.remove = function () {
1152 this.node.parentNode.removeChild(this.node);
1154 Element.prototype.getBBox = function () {
1155 if (this.type == "path") {
1156 return pathDimensions(this.attrs.path);
1158 if (this.node.style.display == "none") {
1164 bbox = this.node.getBBox();
1166 // Firefox 3.0.x plays badly here
1170 if (this.type == "text") {
1171 bbox = {x: bbox.x, y: Infinity, width: bbox.width, height: 0};
1172 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1173 var bb = this.node.getExtentOfChar(i);
1174 (bb.y < bbox.y) && (bbox.y = bb.y);
1175 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1178 hide && this.hide();
1181 Element.prototype.attr = function () {
1182 if (arguments.length == 1 && typeof arguments[0] == "string") {
1183 if (arguments[0] == "translation") {
1184 return this.translate();
1186 if (arguments[0] == "rotation") {
1187 return this.rotate();
1189 if (arguments[0] == "scale") {
1190 return this.scale();
1192 return this.attrs[arguments[0]];
1194 if (arguments.length == 1 && R.isArray(arguments[0])) {
1196 for (var j in arguments[0]) {
1197 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1201 if (arguments.length == 2) {
1203 params[arguments[0]] = arguments[1];
1204 setFillAndStroke(this, params);
1205 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1206 setFillAndStroke(this, arguments[0]);
1210 Element.prototype.toFront = function () {
1211 this.node.parentNode.appendChild(this.node);
1214 Element.prototype.toBack = function () {
1215 if (this.node.parentNode.firstChild != this.node) {
1216 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1220 Element.prototype.insertAfter = function (element) {
1221 if (element.node.nextSibling) {
1222 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1224 element.node.parentNode.appendChild(this.node);
1228 Element.prototype.insertBefore = function (element) {
1229 var node = element.node;
1230 node.parentNode.insertBefore(this.node, node);
1233 var theCircle = function (svg, x, y, r) {
1236 var el = doc.createElementNS(svg.svgns, "circle");
1237 el.setAttribute("cx", x);
1238 el.setAttribute("cy", y);
1239 el.setAttribute("r", r);
1240 el.setAttribute("fill", "none");
1241 el.setAttribute("stroke", "#000");
1243 svg.canvas.appendChild(el);
1245 var res = new Element(el, svg);
1246 res.attrs = res.attrs || {};
1250 res.attrs.stroke = "#000";
1251 res.type = "circle";
1254 var theRect = function (svg, x, y, w, h, r) {
1257 var el = doc.createElementNS(svg.svgns, "rect");
1258 el.setAttribute("x", x);
1259 el.setAttribute("y", y);
1260 el.setAttribute("width", w);
1261 el.setAttribute("height", h);
1263 el.setAttribute("rx", r);
1264 el.setAttribute("ry", r);
1266 el.setAttribute("fill", "none");
1267 el.setAttribute("stroke", "#000");
1269 svg.canvas.appendChild(el);
1271 var res = new Element(el, svg);
1272 res.attrs = res.attrs || {};
1275 res.attrs.width = w;
1276 res.attrs.height = h;
1277 res.attrs.stroke = "#000";
1279 res.attrs.rx = res.attrs.ry = r;
1284 var theEllipse = function (svg, x, y, rx, ry) {
1287 var el = doc.createElementNS(svg.svgns, "ellipse");
1288 el.setAttribute("cx", x);
1289 el.setAttribute("cy", y);
1290 el.setAttribute("rx", rx);
1291 el.setAttribute("ry", ry);
1292 el.setAttribute("fill", "none");
1293 el.setAttribute("stroke", "#000");
1295 svg.canvas.appendChild(el);
1297 var res = new Element(el, svg);
1298 res.attrs = res.attrs || {};
1303 res.attrs.stroke = "#000";
1304 res.type = "ellipse";
1307 var theImage = function (svg, src, x, y, w, h) {
1308 var el = doc.createElementNS(svg.svgns, "image");
1309 el.setAttribute("x", x);
1310 el.setAttribute("y", y);
1311 el.setAttribute("width", w);
1312 el.setAttribute("height", h);
1313 el.setAttribute("preserveAspectRatio", "none");
1314 el.setAttributeNS(svg.xlink, "href", src);
1316 svg.canvas.appendChild(el);
1318 var res = new Element(el, svg);
1319 res.attrs = res.attrs || {};
1320 res.attrs.src = src;
1323 res.attrs.width = w;
1324 res.attrs.height = h;
1328 var theText = function (svg, x, y, text) {
1329 var el = doc.createElementNS(svg.svgns, "text");
1330 el.setAttribute("x", x);
1331 el.setAttribute("y", y);
1332 el.setAttribute("text-anchor", "middle");
1334 svg.canvas.appendChild(el);
1336 var res = new Element(el, svg);
1337 res.attrs = res.attrs || {};
1338 res.attrs.text = text;
1342 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000", text: text});
1345 var setSize = function (width, height) {
1346 this.width = width || this.width;
1347 this.height = height || this.height;
1348 this.canvas.setAttribute("width", this.width);
1349 this.canvas.setAttribute("height", this.height);
1352 var create = function () {
1353 var con = getContainer.apply(null, arguments),
1354 container = con.container,
1358 height = con.height;
1360 throw new Error("SVG container not found.");
1362 paper.canvas = doc.createElementNS(paper.svgns, "svg");
1363 paper.canvas.setAttribute("width", width || 512);
1364 paper.width = width || 512;
1365 paper.canvas.setAttribute("height", height || 342);
1366 paper.height = height || 342;
1367 if (container == 1) {
1368 doc.body.appendChild(paper.canvas);
1369 paper.canvas.style.position = "absolute";
1370 paper.canvas.style.left = x + "px";
1371 paper.canvas.style.top = y + "px";
1373 if (container.firstChild) {
1374 container.insertBefore(paper.canvas, container.firstChild);
1376 container.appendChild(paper.canvas);
1380 canvas: paper.canvas,
1381 clear: function () {
1382 while (this.canvas.firstChild) {
1383 this.canvas.removeChild(this.canvas.firstChild);
1385 this.defs = doc.createElementNS(paper.svgns, "defs");
1386 this.canvas.appendChild(this.defs);
1389 for (var prop in paper) {
1390 if (prop != "create") {
1391 container[prop] = paper[prop];
1394 plugins.call(container, container, R.fn);
1396 container.raphael = R;
1399 paper.remove = function () {
1400 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1402 paper.svgns = "http://www.w3.org/2000/svg";
1403 paper.xlink = "http://www.w3.org/1999/xlink";
1404 paper.safari = function () {
1405 if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) {
1406 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1407 setTimeout(function () {rect.remove();});
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;
1448 // p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1451 p.attrs.path = R.parsePathString(pathString);
1452 p.node.path = path2vml(p.attrs.path);
1454 setFillAndStroke(p, {fill: "none", stroke: "#000"});
1456 VML.canvas.appendChild(g);
1459 var setFillAndStroke = function (o, params) {
1460 o.attrs = o.attrs || {};
1466 for (var par in params) {
1467 a[par] = params[par];
1469 params.href && (node.href = params.href);
1470 params.title && (node.title = params.title);
1471 params.target && (node.target = params.target);
1472 if (params.path && o.type == "path") {
1473 a.path = R.parsePathString(params.path);
1474 node.path = path2vml(a.path);
1476 if (params.rotation != null) {
1477 o.rotate(params.rotation, true);
1479 if (params.translation) {
1480 xy = (params.translation + "").split(separator);
1481 o.translate(xy[0], xy[1]);
1484 xy = (params.scale + "").split(separator);
1485 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1487 if (o.type == "image" && params.src) {
1488 node.src = params.src;
1490 if (o.type == "image" && params.opacity) {
1491 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1492 s.filter = (node.filterMatrix || "") + (node.filterOpacity || "");
1494 params.font && (s.font = params.font);
1495 params["font-family"] && (s.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, "") + '"');
1496 params["font-size"] && (s.fontSize = params["font-size"]);
1497 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1498 params["font-style"] && (s.fontStyle = params["font-style"]);
1499 if (params.opacity != null ||
1500 params["stroke-width"] != null ||
1501 params.fill != null ||
1502 params.stroke != null ||
1503 params["stroke-width"] != null ||
1504 params["stroke-opacity"] != null ||
1505 params["fill-opacity"] != null ||
1506 params["stroke-dasharray"] != null ||
1507 params["stroke-miterlimit"] != null ||
1508 params["stroke-linejoin"] != null ||
1509 params["stroke-linecap"] != null) {
1510 node = o.shape || node;
1511 var fill = (node.getElementsByTagName("fill") && node.getElementsByTagName("fill")[0]),
1513 !fill && (newfill = fill = createNode("fill"));
1514 if ("fill-opacity" in params || "opacity" in params) {
1515 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1);
1516 opacity < 0 && (opacity = 0);
1517 opacity > 1 && (opacity = 1);
1518 fill.opacity = opacity;
1520 params.fill && (fill.on = true);
1521 if (fill.on == null || params.fill == "none") {
1524 if (fill.on && params.fill) {
1525 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1527 fill.src = isURL[1];
1530 fill.color = R.getRGB(params.fill).hex;
1532 fill.type = "solid";
1535 newfill && node.appendChild(fill);
1536 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
1538 !stroke && (newstroke = stroke = createNode("stroke"));
1539 if ((params.stroke && params.stroke != "none") ||
1540 params["stroke-width"] ||
1541 params["stroke-opacity"] != null ||
1542 params["stroke-dasharray"] ||
1543 params["stroke-miterlimit"] ||
1544 params["stroke-linejoin"] ||
1545 params["stroke-linecap"]) {
1548 (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
1549 stroke.on && params.stroke && (stroke.color = R.getRGB(params.stroke).hex);
1550 var opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1);
1551 opacity < 0 && (opacity = 0);
1552 opacity > 1 && (opacity = 1);
1553 stroke.opacity = opacity;
1554 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1555 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1556 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1557 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"]) || 1) * 12 / 16);
1558 if (params["stroke-dasharray"]) {
1562 "-.": "shortdashdot",
1563 "-..": "shortdashdotdot",
1568 "--.": "longdashdot",
1569 "--..": "longdashdotdot"
1571 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1573 newstroke && node.appendChild(stroke);
1575 if (res.type == "text") {
1576 var s = paper.span.style;
1577 a.font && (s.font = a.font);
1578 a["font-family"] && (s.fontFamily = a["font-family"]);
1579 a["font-size"] && (s.fontSize = a["font-size"]);
1580 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1581 a["font-style"] && (s.fontStyle = a["font-style"]);
1582 paper.span.innerHTML = res.node.string.replace(/</g, "<").replace(/&/g, "&").replace(/\n/g, "<br>");
1583 res.W = a.w = paper.span.offsetWidth;
1584 res.H = a.h = paper.span.offsetHeight;
1586 res.Y = a.y + Math.round(res.H / 2);
1588 // text-anchor emulation
1589 switch (a["text-anchor"]) {
1591 res.node.style["v-text-align"] = "left";
1592 res.bbx = Math.round(res.W / 2);
1595 res.node.style["v-text-align"] = "right";
1596 res.bbx = -Math.round(res.W / 2);
1599 res.node.style["v-text-align"] = "center";
1604 var getAngle = function (a, b, c, d) {
1605 var angle = Math.round(Math.atan((parseFloat(c) - parseFloat(a)) / (parseFloat(d) - parseFloat(b))) * 57.29) || 0;
1606 if (!angle && parseFloat(a) < parseFloat(b)) {
1615 var addGradientFill = function (o, gradient) {
1616 gradient = toGradient(gradient);
1617 o.attrs = o.attrs || {};
1618 var attrs = o.attrs,
1619 fill = o.node.getElementsByTagName("fill");
1620 o.attrs.gradient = gradient;
1621 o = o.shape || o.node;
1625 fill = createNode("fill");
1627 if (gradient.dots.length) {
1629 fill.method = "none";
1630 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1631 if (typeof gradient.dots[0].color != "undefined") {
1632 fill.color = R.getRGB(gradient.dots[0].color).hex;
1634 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1635 fill.color2 = R.getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1638 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1639 if (gradient.dots[i].offset) {
1640 clrs.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
1643 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;
1645 fill.colors.value = clrs.join(",");
1646 fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
1648 fill.colors && (fill.colors.value = "0% " + fill.color);
1650 fill.opacity = fillOpacity;
1651 if (typeof gradient.angle != "undefined") {
1652 fill.angle = (-gradient.angle + 270) % 360;
1653 } else if (gradient.vector) {
1654 fill.angle = getAngle.apply(null, gradient.vector);
1656 if ((gradient.type + "").toLowerCase() == "radial") {
1657 fill.focus = "100%";
1658 fill.focusposition = "0.5 0.5";
1662 var Element = function (node, group, vml) {
1682 Element.prototype.rotate = function (deg, cx, cy) {
1685 return [this._.rt.deg, this._.rt.cx, this._.rt.cy].join(" ");
1687 return this._.rt.deg;
1689 deg = (deg + "").split(separator);
1690 if (deg.length - 1) {
1691 cx = parseFloat(deg[1]);
1692 cy = parseFloat(deg[2]);
1694 deg = parseFloat(deg[0]);
1696 this._.rt.deg = deg;
1698 this._.rt.deg += deg;
1700 (cy == null) && (cx = null);
1703 this.setBox(this.attrs, cx, cy);
1704 this.Group.style.rotation = this._.rt.deg;
1705 // gradient fix for rotation. TODO
1706 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1707 // fill = fill[0] || {};
1708 // var b = ((360 - this._.rt.deg) - 270) % 360;
1709 // typeof fill.angle != "undefined" && (fill.angle = b);
1712 Element.prototype.setBox = function (params, cx, cy) {
1713 var gs = this.Group.style,
1714 os = (this.shape && this.shape.style) || this.node.style;
1715 params = params || {};
1716 for (var i in params) {
1717 this.attrs[i] = params[i];
1719 cx = cx || this._.rt.cx;
1720 cy = cy || this._.rt.cy;
1721 var attr = this.attrs,
1726 switch (this.type) {
1728 x = attr.cx - attr.r;
1729 y = attr.cy - attr.r;
1733 x = attr.cx - attr.rx;
1734 y = attr.cy - attr.ry;
1742 w = attr.width || 0;
1743 h = attr.height || 0;
1746 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("");
1747 x = attr.x - Math.round(this.W / 2);
1748 y = attr.y - this.H / 2;
1753 if (!this.attrs.path) {
1756 w = this.paper.width;
1757 h = this.paper.height;
1759 var dim = pathDimensions(this.attrs.path);
1769 w = this.paper.width;
1770 h = this.paper.height;
1773 cx = (cx == null) ? x + w / 2 : cx;
1774 cy = (cy == null) ? y + h / 2 : cy;
1775 var left = cx - this.paper.width / 2,
1776 top = cy - this.paper.height / 2;
1777 if (this.type == "path" || this.type == "text") {
1778 (gs.left != left + "px") && (gs.left = left + "px");
1779 (gs.top != top + "px") && (gs.top = top + "px");
1780 this.X = this.type == "text" ? x : -left;
1781 this.Y = this.type == "text" ? y : -top;
1784 (os.left != -left + "px") && (os.left = -left + "px");
1785 (os.top != -top + "px") && (os.top = -top + "px");
1787 (gs.left != left + "px") && (gs.left = left + "px");
1788 (gs.top != top + "px") && (gs.top = top + "px");
1793 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
1794 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
1795 (os.left != x - left + "px") && (os.left = x - left + "px");
1796 (os.top != y - top + "px") && (os.top = y - top + "px");
1797 (os.width != w + "px") && (os.width = w + "px");
1798 (os.height != h + "px") && (os.height = h + "px");
1799 var arcsize = (+params.r || 0) / (Math.min(w, h));
1800 if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
1801 // We should replace element with the new one
1802 var o = createNode(arcsize ? "roundrect" : "rect");
1803 o.arcsize = arcsize;
1804 this.Group.appendChild(o);
1805 this.node.parentNode.removeChild(this.node);
1807 this.arcsize = arcsize;
1808 setFillAndStroke(this, this.attrs);
1809 this.setBox(this.attrs);
1813 Element.prototype.hide = function () {
1814 this.Group.style.display = "none";
1817 Element.prototype.show = function () {
1818 this.Group.style.display = "block";
1821 Element.prototype.getBBox = function () {
1822 if (this.type == "path") {
1823 return pathDimensions(this.attrs.path);
1826 x: this.X + (this.bbx || 0),
1832 Element.prototype.remove = function () {
1833 this[0].parentNode.removeChild(this[0]);
1834 this.Group.parentNode.removeChild(this.Group);
1835 this.shape && this.shape.parentNode.removeChild(this.shape);
1837 Element.prototype.attr = function () {
1838 if (arguments.length == 1 && typeof arguments[0] == "string") {
1839 if (arguments[0] == "translation") {
1840 return this.translate();
1842 if (arguments[0] == "rotation") {
1843 return this.rotate();
1845 if (arguments[0] == "scale") {
1846 return this.scale();
1848 return this.attrs[arguments[0]];
1850 if (this.attrs && arguments.length == 1 && R.isArray(arguments[0])) {
1852 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1853 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1858 if (arguments.length == 2) {
1860 params[arguments[0]] = arguments[1];
1862 if (arguments.length == 1 && typeof arguments[0] == "object") {
1863 params = arguments[0];
1866 if (params.gradient) {
1867 addGradientFill(this, params.gradient);
1869 if (params.text && this.type == "text") {
1870 this.node.string = params.text;
1872 setFillAndStroke(this, params);
1873 this.setBox(this.attrs);
1877 Element.prototype.toFront = function () {
1878 this.Group.parentNode.appendChild(this.Group);
1881 Element.prototype.toBack = function () {
1882 if (this.Group.parentNode.firstChild != this.Group) {
1883 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
1887 Element.prototype.insertAfter = function (element) {
1888 if (element.Group.nextSibling) {
1889 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
1891 element.Group.parentNode.appendChild(this.Group);
1895 Element.prototype.insertBefore = function (element) {
1896 element.Group.parentNode.insertBefore(this.Group, element.Group);
1899 var theCircle = function (vml, x, y, r) {
1900 var g = createNode("group"),
1902 o = createNode("oval"),
1904 gl.position = "absolute";
1907 gl.width = vml.width + "px";
1908 gl.height = vml.height + "px";
1909 g.coordsize = vml.coordsize;
1910 g.coordorigin = vml.coordorigin;
1912 var res = new Element(o, g, vml);
1913 res.type = "circle";
1914 setFillAndStroke(res, {stroke: "#000", fill: "none"});
1918 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
1919 vml.canvas.appendChild(g);
1922 var theRect = function (vml, x, y, w, h, r) {
1923 var g = createNode("group"),
1925 o = createNode(r ? "roundrect" : "rect"),
1926 arcsize = (+r || 0) / (Math.min(w, h));
1927 o.arcsize = arcsize;
1928 gl.position = "absolute";
1931 gl.width = vml.width + "px";
1932 gl.height = vml.height + "px";
1933 g.coordsize = vml.coordsize;
1934 g.coordorigin = vml.coordorigin;
1936 var res = new Element(o, g, vml);
1938 setFillAndStroke(res, {stroke: "#000"});
1939 res.arcsize = arcsize;
1940 res.setBox({x: x, y: y, width: w, height: h, r: +r});
1941 vml.canvas.appendChild(g);
1944 var theEllipse = function (vml, x, y, rx, ry) {
1945 var g = createNode("group"),
1947 o = createNode("oval"),
1949 gl.position = "absolute";
1952 gl.width = vml.width + "px";
1953 gl.height = vml.height + "px";
1954 g.coordsize = vml.coordsize;
1955 g.coordorigin = vml.coordorigin;
1957 var res = new Element(o, g, vml);
1958 res.type = "ellipse";
1959 setFillAndStroke(res, {stroke: "#000"});
1964 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
1965 vml.canvas.appendChild(g);
1968 var theImage = function (vml, src, x, y, w, h) {
1969 var g = createNode("group"),
1971 o = createNode("image"),
1973 gl.position = "absolute";
1976 gl.width = vml.width + "px";
1977 gl.height = vml.height + "px";
1978 g.coordsize = vml.coordsize;
1979 g.coordorigin = vml.coordorigin;
1982 var res = new Element(o, g, vml);
1984 res.attrs.src = src;
1989 res.setBox({x: x, y: y, width: w, height: h});
1990 vml.canvas.appendChild(g);
1993 var theText = function (vml, x, y, text) {
1994 var g = createNode("group"),
1996 el = createNode("shape"),
1998 path = createNode("path"),
2000 o = createNode("textpath");
2001 gs.position = "absolute";
2004 gs.width = vml.width + "px";
2005 gs.height = vml.height + "px";
2006 g.coordsize = vml.coordsize;
2007 g.coordorigin = vml.coordorigin;
2008 path.v = ["m", Math.round(x), ", ", Math.round(y), "l", Math.round(x) + 1, ", ", Math.round(y)].join("");
2009 path.textpathok = true;
2010 ol.width = vml.width;
2011 ol.height = vml.height;
2012 gs.position = "absolute";
2015 gs.width = vml.width;
2016 gs.height = vml.height;
2020 el.appendChild(path);
2022 var res = new Element(o, g, vml);
2024 res.textpath = path;
2026 res.attrs.text = text;
2031 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2033 vml.canvas.appendChild(g);
2036 var setSize = function (width, height) {
2037 var cs = this.canvas.style;
2038 this.width = width || this.width;
2039 this.height = height || this.height;
2040 cs.width = this.width + "px";
2041 cs.height = this.height + "px";
2042 cs.clip = "rect(0 " + this.width + "px " + this.height + "px 0)";
2043 this.canvas.coordsize = this.width + " " + this.height;
2046 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2048 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2049 var createNode = function (tagName) {
2050 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2053 var createNode = function (tagName) {
2054 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2057 var create = function () {
2058 var con = getContainer.apply(null, arguments),
2059 container = con.container,
2060 height = con.height,
2066 throw new Error("VML container not found.");
2068 var c = paper.canvas = doc.createElement("div"),
2070 width = parseFloat(width) || "512px";
2071 height = parseFloat(height) || "342px";
2072 paper.width = width;
2073 paper.height = height;
2074 paper.coordsize = width + " " + height;
2075 paper.coordorigin = "0 0";
2076 paper.span = doc.createElement("span");
2077 s = paper.span.style;
2078 c.appendChild(paper.span);
2079 s.position = "absolute";
2080 s.left = "-99999px";
2085 s.display = "inline";
2086 cs.width = width + "px";
2087 cs.height = height + "px";
2088 cs.position = "absolute";
2089 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2090 if (container == 1) {
2091 doc.body.appendChild(c);
2101 container.style.width = width;
2102 container.style.height = height;
2103 if (container.firstChild) {
2104 container.insertBefore(c, container.firstChild);
2106 container.appendChild(c);
2109 for (var prop in paper) {
2110 container[prop] = paper[prop];
2112 plugins.call(container, container, R.fn);
2113 container.clear = function () {
2114 while (c.firstChild) {
2115 c.removeChild(c.firstChild);
2118 container.raphael = R;
2121 paper.remove = function () {
2122 this.canvas.parentNode.removeChild(this.canvas);
2124 paper.safari = function () {};
2130 var addEvent = (function () {
2131 if (doc.addEventListener) {
2132 return function (obj, type, fn, element) {
2133 var f = function (e) {
2134 return fn.call(element, e);
2136 obj.addEventListener(type, f, false);
2137 return function () {
2138 obj.removeEventListener(type, f, false);
2142 } else if (doc.attachEvent) {
2143 return function (obj, type, fn, element) {
2144 var f = function (e) {
2145 return fn.call(element, e || win.event);
2147 obj.attachEvent("on" + type, f);
2148 var detacher = function () {
2149 obj.detachEvent("on" + type, f);
2152 if (type == "mouseover") {
2153 obj.attachEvent("onmouseenter", f);
2154 return function () {
2155 obj.detachEvent("onmouseenter", f);
2158 } else if (type == "mouseout") {
2159 obj.attachEvent("onmouseleave", f);
2160 return function () {
2161 obj.detachEvent("onmouseleave", f);
2169 for (var i = events.length; i--;) {
2170 (function (eventName) {
2171 Element.prototype[eventName] = function (fn) {
2172 if (typeof fn == "function") {
2173 this.events = this.events || {};
2174 this.events[eventName] = this.events[eventName] || {};
2175 this.events[eventName][fn] = this.events[eventName][fn] || [];
2176 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2180 Element.prototype["un" + eventName] = function (fn) {
2182 this.events[eventName] &&
2183 this.events[eventName][fn] &&
2184 this.events[eventName][fn].length &&
2185 this.events[eventName][fn].shift()() &&
2186 !this.events[eventName][fn].length &&
2187 delete this.events[eventName][fn];
2192 paper.circle = function (x, y, r) {
2193 return theCircle(this, x, y, r);
2195 paper.rect = function (x, y, w, h, r) {
2196 return theRect(this, x, y, w, h, r);
2198 paper.ellipse = function (x, y, rx, ry) {
2199 return theEllipse(this, x, y, rx, ry);
2201 paper.path = function (pathString) {
2202 return thePath(R.format.apply(R, arguments), this);
2204 paper.image = function (src, x, y, w, h) {
2205 return theImage(this, src, x, y, w, h);
2207 paper.text = function (x, y, text) {
2208 return theText(this, x, y, text);
2210 paper.set = function (itemsArray) {
2211 arguments.length > 1 && (itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length));
2212 return new Set(itemsArray);
2214 paper.setSize = setSize;
2215 Element.prototype.stop = function () {
2216 clearTimeout(this.animation_in_progress);
2219 Element.prototype.scale = function (x, y, cx, cy) {
2220 if (x == null && y == null) {
2221 return {x: this._.sx, y: this._.sy, toString: function () { return +this.x.toFixed(3) + " " + (+this.y.toFixed(3)); }};
2231 var bb = this.getBBox(),
2232 rcx = bb.x + bb.width / 2,
2233 rcy = bb.y + bb.height / 2,
2236 cx = (+cx || cx == 0) ? cx : rcx;
2237 cy = (+cy || cy == 0) ? cy : rcy;
2238 var dirx = Math.round(x / Math.abs(x)),
2239 diry = Math.round(y / Math.abs(y)),
2240 s = this.node.style,
2241 ncx = cx + (rcx - cx) * dirx * kx,
2242 ncy = cy + (rcy - cy) * diry * ky;
2243 switch (this.type) {
2246 var neww = a.width * dirx * kx,
2247 newh = a.height * diry * ky,
2248 newx = ncx - neww / 2,
2249 newy = ncy - newh / 2;
2268 var path = pathToRelative(a.path),
2270 for (var i = 0, ii = path.length; i < ii; i++) {
2272 if (p[0].toUpperCase() == "M" && skip) {
2277 if (R.svg && p[0].toUpperCase() == "A") {
2278 p[path[i].length - 2] *= kx;
2279 p[path[i].length - 1] *= ky;
2282 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2284 for (var j = 1, jj = p.length; j < jj; j++) {
2285 p[j] *= (j % 2) ? kx : ky;
2289 var dim2 = pathDimensions(path),
2290 dx = ncx - dim2.x - dim2.width / 2,
2291 dy = ncy - dim2.y - dim2.height / 2;
2292 path = pathToRelative(path);
2296 this.attr({path: path.join(" ")});
2299 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2300 if (this.transformations) {
2301 this.transformations[2] = "scale(".concat(dirx, ",", diry, ")");
2302 this.node.setAttribute("transform", this.transformations.join(" "));
2303 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2304 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2305 this.attr({x: dx, y: dy});
2309 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=".concat(dirx,
2310 ", M12=0, M21=0, M22=", diry,
2311 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2312 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2315 if (this.transformations) {
2316 this.transformations[2] = "";
2317 this.node.setAttribute("transform", this.transformations.join(" "));
2321 this.node.filterMatrix = "";
2322 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2325 a.scale = [x, y, cx, cy].join(" ");
2332 // animation easing formulas
2333 R.easing_formulas = {
2334 linear: function (n) {
2338 return Math.pow(n, 3);
2341 return Math.pow(n - 1, 3) + 1;
2343 "<>": function (n) {
2346 return Math.pow(n, 3) / 2;
2349 return (Math.pow(n, 3) + 2) / 2;
2351 backIn: function (n) {
2353 return n * n * ((s + 1) * n - s);
2355 backOut: function (n) {
2358 return n * n * ((s + 1) * n + s) + 1;
2360 elastic: function (n) {
2361 if (n == 0 || n == 1) {
2366 return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1;
2368 bounce: function (n) {
2377 l = s * n * n + .75;
2379 if (n < (2.5 / p)) {
2381 l = s * n * n + .9375;
2384 l = s * n * n + .984375;
2392 Element.prototype.animate = function (params, ms, easing, callback) {
2393 clearTimeout(this.animation_in_progress);
2394 if (typeof easing == "function" || !easing) {
2395 callback = easing || null;
2401 for (var attr in params) {
2402 if (attr in availableAnimAttrs) {
2403 from[attr] = this.attr(attr);
2404 (typeof from[attr] == "undefined") && (from[attr] = availableAttrs[attr]);
2405 to[attr] = params[attr];
2406 switch (availableAnimAttrs[attr]) {
2408 diff[attr] = (to[attr] - from[attr]) / ms;
2411 from[attr] = R.getRGB(from[attr]);
2412 var toColour = R.getRGB(to[attr]);
2414 r: (toColour.r - from[attr].r) / ms,
2415 g: (toColour.g - from[attr].g) / ms,
2416 b: (toColour.b - from[attr].b) / ms
2420 var pathes = path2curve(from[attr], to[attr]);
2421 from[attr] = pathes[0];
2422 to[attr] = pathes[1];
2424 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2425 diff[attr][i] = [0];
2426 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2427 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2432 var values = (params[attr] + "").split(separator),
2433 from2 = (from[attr] + "").split(separator);
2436 from[attr] = [0, 0];
2437 diff[attr] = [values[0] / ms, values[1] / ms];
2440 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2441 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2444 params[attr] = values;
2445 from[attr] = (from[attr] + "").split(separator);
2446 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2452 var start = +new Date,
2454 upto255 = function (color) {
2455 return +color > 255 ? 255 : +color;
2459 var time = new Date - start,
2463 var pos = R.easing_formulas[easing] ? R.easing_formulas[easing](time / ms) : time / ms;
2464 for (var attr in from) {
2465 switch (availableAnimAttrs[attr]) {
2467 now = +from[attr] + pos * ms * diff[attr];
2471 upto255(Math.round(from[attr].r + pos * ms * diff[attr].r)),
2472 upto255(Math.round(from[attr].g + pos * ms * diff[attr].g)),
2473 upto255(Math.round(from[attr].b + pos * ms * diff[attr].b))
2478 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2479 now[i] = [from[attr][i][0]];
2480 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2481 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
2483 now[i] = now[i].join(" ");
2485 now = now.join(" ");
2490 var x = diff[attr][0] * (time - prev),
2491 y = diff[attr][1] * (time - prev);
2494 now = [x, y].join(" ");
2497 now = +from[attr][0] + pos * ms * diff[attr][0];
2498 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2501 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(" ");
2508 that.animation_in_progress = setTimeout(tick);
2509 R.svg && paper.safari();
2511 (t.x || t.y) && that.translate(-t.x, -t.y);
2513 clearTimeout(that.animation_in_progress);
2514 R.svg && paper.safari();
2515 (typeof callback == "function") && callback.call(that);
2521 Element.prototype.translate = function (x, y) {
2523 return {x: this._.tx, y: this._.ty};
2527 switch (this.type) {
2530 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
2535 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
2538 var path = pathToRelative(this.attrs.path);
2541 this.attr({path: path});
2548 var Set = function (items) {
2552 for (var i = 0, ii = items.length; i < ii; i++) {
2553 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
2554 this[this.items.length] = this.items[this.items.length] = items[i];
2560 Set.prototype.push = function () {
2563 for (var i = 0, ii = arguments.length; i < ii; i++) {
2564 item = arguments[i];
2565 if (item && (item.constructor == Element || item.constructor == Set)) {
2566 len = this.items.length;
2567 this[len] = this.items[len] = item;
2573 Set.prototype.pop = function () {
2574 delete this[this.length--];
2575 return this.items.pop();
2577 for (var method in Element.prototype) {
2578 Set.prototype[method] = (function (methodname) {
2579 return function () {
2580 for (var i = 0, ii = this.items.length; i < ii; i++) {
2581 this.items[i][methodname].apply(this.items[i], arguments);
2587 Set.prototype.attr = function (name, value) {
2588 if (name && R.isArray(name) && typeof name[0] == "object") {
2589 for (var j = 0, jj = name.length; j < jj; j++) {
2590 this.items[j].attr(name[j]);
2593 for (var i = 0, ii = this.items.length; i < ii; i++) {
2594 this.items[i].attr.apply(this.items[i], arguments);
2600 Set.prototype.getBBox = function () {
2605 for (var i = this.items.length; i--;) {
2606 var box = this.items[i].getBBox();
2609 w.push(box.x + box.width);
2610 h.push(box.y + box.height);
2612 x = Math.min.apply(Math, x);
2613 y = Math.min.apply(Math, y);
2617 width: Math.max.apply(Math, w) - x,
2618 height: Math.max.apply(Math, h) - y
2622 R.registerFont = function (font) {
2626 this.fonts = this.fonts || {};
2632 family = font.face["font-family"];
2633 for (var prop in font.face) {
2634 fontcopy.face[prop] = font.face[prop];
2636 if (this.fonts[family]) {
2637 this.fonts[family].push(fontcopy);
2639 this.fonts[family] = [fontcopy];
2642 fontcopy.face["units-per-em"] = parseInt(font.face["units-per-em"], 10);
2643 for (var glyph in font.glyphs) {
2644 var path = font.glyphs[glyph];
2645 fontcopy.glyphs[glyph] = {
2648 d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
2649 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
2653 for (var k in path.k) {
2654 fontcopy.glyphs[glyph].k[k] = path.k[k];
2661 paper.getFont = function (family, weight, style, stretch) {
2662 stretch = stretch || "normal";
2663 style = style || "normal";
2664 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
2665 var font = R.fonts[family];
2667 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, "") + "(\\s|$)", "i");
2668 for (var fontName in R.fonts) {
2669 if (name.test(fontName)) {
2670 font = R.fonts[fontName];
2677 for (var i = 0, ii = font.length; i < ii; i++) {
2679 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
2686 paper.print = function (x, y, string, font, size) {
2687 var out = this.set(),
2688 letters = (string + "").split(""),
2692 typeof font == "string" && (font = this.getFont(font));
2694 scale = (size || 16) / font.face["units-per-em"];
2695 for (var i = 0, ii = letters.length; i < ii; i++) {
2696 var prev = i && font.glyphs[letters[i - 1]] || {},
2697 curr = font.glyphs[letters[i]];
2698 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
2699 curr && curr.d && out.push(this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
2701 out.scale(scale, scale, 0, y).translate(x, (size || 16) / 2);
2706 R.format = function (token) {
2707 var args = R.isArray(arguments[1]) ? [0].concat(arguments[1]) : arguments;
2708 token && typeof token == "string" && args.length - 1 && (token = token.replace(/\{(\d+)\}/g, function (str, i) {
2709 return args[++i] || "";
2713 R.ninja = function () {
2714 var r = window.Raphael;
2715 if (oldRaphael.was) {
2716 window.Raphael = oldRaphael.is;
2719 delete window.Raphael;
2721 window.Raphael = void(0);
2726 R.el = Element.prototype;