2 * Raphael 1.0 RC1.4 - JavaScript Vector Library
4 * Copyright (c) 2008 - 2009 Dmitry Baranovskiy (http://raphaeljs.com)
5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
9 window.Raphael = (function () {
10 var separator = /[, ]+/,
14 was: "Raphael" in window,
18 return create.apply(R, arguments);
21 availableAttrs = {"clip-rect": "0 0 10e9 10e9", cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0},
22 availableAnimAttrs = {"clip-rect": "csv", cx: "number", cy: "number", fill: "colour", "fill-opacity": "number", "font-size": "number", height: "number", opacity: "number", path: "path", r: "number", rotation: "csv", rx: "number", ry: "number", scale: "csv", stroke: "colour", "stroke-opacity": "number", "stroke-width": "number", translation: "csv", width: "number", x: "number", y: "number"},
23 events = ["click", "dblclick", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup"];
24 R.version = "1.0 RC1.4";
25 R.type = (window.SVGAngle || document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
26 R.svg = !(R.vml = R.type == "VML");
29 R.is = function (o, type) {
30 type = (type + "").toLowerCase();
31 if (type == "undefined" && typeof o == "undefined") {
34 if (o == null && type == "null") {
37 return Object.prototype.toString.call(o).replace(/^\[object\s+|\]$/gi, "").toLowerCase() == type;
39 R.setWindow = function (newwin) {
44 R.hsb2rgb = cacher(function (hue, saturation, brightness) {
45 if (R.is(hue, "object") && "h" in hue && "s" in hue && "b" in hue) {
53 if (brightness == 0) {
54 return {r: 0, g: 0, b: 0, hex: "#000"};
56 if (hue > 1 || saturation > 1 || brightness > 1) {
61 var i = Math.floor(hue * 6),
63 p = brightness * (1 - saturation),
64 q = brightness * (1 - (saturation * f)),
65 t = brightness * (1 - (saturation * (1 - f)));
66 red = [brightness, q, p, p, t, brightness, brightness][i];
67 green = [t, brightness, brightness, q, p, p, t][i];
68 blue = [p, p, t, brightness, brightness, q, p][i];
72 var rgb = {r: red, g: green, b: blue},
73 r = Math.round(red).toString(16),
74 g = Math.round(green).toString(16),
75 b = Math.round(blue).toString(16);
85 rgb.hex = "#" + r + g + b;
88 R.rgb2hsb = cacher(function (red, green, blue) {
89 if (R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
94 if (R.is(red, "string")) {
95 var clr = R.getRGB(red);
100 if (red > 1 || green > 1 || blue > 1) {
105 var max = Math.max(red, green, blue),
106 min = Math.min(red, green, blue),
111 return {h: 0, s: 0, b: max};
113 var delta = (max - min);
114 saturation = delta / max;
116 hue = (green - blue) / delta;
117 } else if (green == max) {
118 hue = 2 + ((blue - red) / delta);
120 hue = 4 + ((red - green) / delta);
130 return {h: hue, s: saturation, b: brightness};
132 R._path2string = function () {
135 for (var i = 0, ii = this.length; i < ii; i++) {
136 for (var j = 0, jj = this[i].length; j < jj; j++) {
138 j && j != jj - 1 && (res += ",");
140 i != ii - 1 && (res += "\n");
142 return res.replace(/,(?=-)/g, "");
144 function cacher(f, scope, postprocessor) {
146 var arg = Array.prototype.splice.call(arguments, 0, arguments.length),
147 args = arg.join("\u25ba");
148 newf.cache = newf.cache || {};
149 newf.count = newf.count || [];
150 if (args in newf.cache) {
151 return postprocessor ? postprocessor(newf.cache[args]) : newf.cache[args];
153 if (newf.count.length > 1000) {
154 delete newf.cache[newf.count.unshift()];
156 newf.count.push(args);
157 newf.cache[args] = f.apply(scope, arg);
158 return postprocessor ? postprocessor(newf.cache[args]) : newf.cache[args];
163 R.getRGB = cacher(function (colour) {
164 var htmlcolors = {aliceblue: "#f0f8ff", amethyst: "#96c", antiquewhite: "#faebd7", aqua: "#0ff", aquamarine: "#7fffd4", azure: "#f0ffff", beige: "#f5f5dc", bisque: "#ffe4c4", black: "#000", blanchedalmond: "#ffebcd", blue: "#00f", blueviolet: "#8a2be2", brown: "#a52a2a", burlywood: "#deb887", cadetblue: "#5f9ea0", chartreuse: "#7fff00", chocolate: "#d2691e", coral: "#ff7f50", cornflowerblue: "#6495ed", cornsilk: "#fff8dc", crimson: "#dc143c", cyan: "#0ff", darkblue: "#00008b", darkcyan: "#008b8b", darkgoldenrod: "#b8860b", darkgray: "#a9a9a9", darkgreen: "#006400", darkkhaki: "#bdb76b", darkmagenta: "#8b008b", darkolivegreen: "#556b2f", darkorange: "#ff8c00", darkorchid: "#9932cc", darkred: "#8b0000", darksalmon: "#e9967a", darkseagreen: "#8fbc8f", darkslateblue: "#483d8b", darkslategray: "#2f4f4f", darkturquoise: "#00ced1", darkviolet: "#9400d3", deeppink: "#ff1493", deepskyblue: "#00bfff", dimgray: "#696969", dodgerblue: "#1e90ff", firebrick: "#b22222", floralwhite: "#fffaf0", forestgreen: "#228b22", fuchsia: "#f0f", gainsboro: "#dcdcdc", ghostwhite: "#f8f8ff", gold: "#ffd700", goldenrod: "#daa520", gray: "#808080", green: "#008000", greenyellow: "#adff2f", honeydew: "#f0fff0", hotpink: "#ff69b4", indianred: "#cd5c5c", indigo: "#4b0082", ivory: "#fffff0", khaki: "#f0e68c", lavender: "#e6e6fa", lavenderblush: "#fff0f5", lawngreen: "#7cfc00", lemonchiffon: "#fffacd", lightblue: "#add8e6", lightcoral: "#f08080", lightcyan: "#e0ffff", lightgoldenrodyellow: "#fafad2", lightgreen: "#90ee90", lightgrey: "#d3d3d3", lightpink: "#ffb6c1", lightsalmon: "#ffa07a", lightsalmon: "#ffa07a", lightseagreen: "#20b2aa", lightskyblue: "#87cefa", lightslategray: "#789", lightsteelblue: "#b0c4de", lightyellow: "#ffffe0", lime: "#0f0", limegreen: "#32cd32", linen: "#faf0e6", magenta: "#f0f", maroon: "#800000", mediumaquamarine: "#66cdaa", mediumblue: "#0000cd", mediumorchid: "#ba55d3", mediumpurple: "#9370db", mediumseagreen: "#3cb371", mediumslateblue: "#7b68ee", mediumslateblue: "#7b68ee", mediumspringgreen: "#00fa9a", mediumturquoise: "#48d1cc", mediumvioletred: "#c71585", midnightblue: "#191970", mintcream: "#f5fffa", mistyrose: "#ffe4e1", moccasin: "#ffe4b5", navajowhite: "#ffdead", navy: "#000080", oldlace: "#fdf5e6", olive: "#808000", olivedrab: "#6b8e23", orange: "#ffa500", orangered: "#ff4500", orchid: "#da70d6", palegoldenrod: "#eee8aa", palegreen: "#98fb98", paleturquoise: "#afeeee", palevioletred: "#db7093", papayawhip: "#ffefd5", peachpuff: "#ffdab9", peru: "#cd853f", pink: "#ffc0cb", plum: "#dda0dd", powderblue: "#b0e0e6", purple: "#800080", red: "#f00", rosybrown: "#bc8f8f", royalblue: "#4169e1", saddlebrown: "#8b4513", salmon: "#fa8072", sandybrown: "#f4a460", seagreen: "#2e8b57", seashell: "#fff5ee", sienna: "#a0522d", silver: "#c0c0c0", skyblue: "#87ceeb", slateblue: "#6a5acd", slategray: "#708090", snow: "#fffafa", springgreen: "#00ff7f", steelblue: "#4682b4", tan: "#d2b48c", teal: "#008080", thistle: "#d8bfd8", tomato: "#ff6347", turquoise: "#40e0d0", violet: "#ee82ee", wheat: "#f5deb3", white: "#fff", whitesmoke: "#f5f5f5", yellow: "#ff0", yellowgreen: "#9acd32"},
166 if ((colour + "").toLowerCase() in htmlcolors) {
167 colour = htmlcolors[colour.toString().toLowerCase()];
170 return {r: 0, g: 0, b: 0, hex: "#000"};
172 if (colour == "none") {
173 return {r: -1, g: -1, b: -1, hex: "none"};
178 rgb = (colour + "").match(/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|rgb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hs[bl]\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hs[bl]\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i);
181 blue = parseInt(rgb[2].substring(5), 16);
182 green = parseInt(rgb[2].substring(3, 5), 16);
183 red = parseInt(rgb[2].substring(1, 3), 16);
186 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
187 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
188 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
191 rgb = rgb[4].split(/\s*,\s*/);
192 red = parseFloat(rgb[0]);
193 green = parseFloat(rgb[1]);
194 blue = parseFloat(rgb[2]);
197 rgb = rgb[5].split(/\s*,\s*/);
198 red = parseFloat(rgb[0]) * 2.55;
199 green = parseFloat(rgb[1]) * 2.55;
200 blue = parseFloat(rgb[2]) * 2.55;
203 rgb = rgb[6].split(/\s*,\s*/);
204 red = parseFloat(rgb[0]);
205 green = parseFloat(rgb[1]);
206 blue = parseFloat(rgb[2]);
207 return R.hsb2rgb(red, green, blue);
210 rgb = rgb[7].split(/\s*,\s*/);
211 red = parseFloat(rgb[0]) * 2.55;
212 green = parseFloat(rgb[1]) * 2.55;
213 blue = parseFloat(rgb[2]) * 2.55;
214 return R.hsb2rgb(red, green, blue);
216 rgb = {r: red, g: green, b: blue};
217 var r = Math.round(red).toString(16),
218 g = Math.round(green).toString(16),
219 b = Math.round(blue).toString(16);
220 (r.length == 1) && (r = "0" + r);
221 (g.length == 1) && (g = "0" + g);
222 (b.length == 1) && (b = "0" + b);
223 rgb.hex = "#" + r + g + b;
226 res = {r: -1, g: -1, b: -1, hex: "none"};
230 R.getColor = function (value) {
231 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
232 rgb = this.hsb2rgb(start.h, start.s, start.b);
238 this.getColor.start = {h: 0, s: 1, b: start.b};
243 R.getColor.reset = function () {
247 R.parsePathString = cacher(function (pathString) {
251 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
253 if (R.is(pathString, "array") && R.is(pathString[0], "array")) { // rough assumption
254 data = pathClone(pathString);
257 (pathString + "").replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, function (a, b, c) {
259 name = b.toLowerCase();
260 c.replace(/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig, function (a, b) {
261 b && params.push(+b);
263 while (params.length >= paramCounts[name]) {
264 data.push([b].concat(params.splice(0, paramCounts[name])));
265 if (!paramCounts[name]) {
271 data.toString = R._path2string;
274 var pathDimensions = cacher(function (path) {
276 return {x: 0, y: 0, width: 0, height: 0};
278 path = path2curve(path);
283 for (var i = 0, ii = path.length; i < ii; i++) {
284 if (path[i][0] == "M") {
290 var dim = curveDim(x, y, path[i][1], path[i][2], path[i][3], path[i][4], path[i][5], path[i][6]);
291 X = X.concat(dim.min.x, dim.max.x);
292 Y = Y.concat(dim.min.y, dim.max.y);
295 var xmin = Math.min.apply(0, X),
296 ymin = Math.min.apply(0, Y);
300 width: Math.max.apply(0, X) - xmin,
301 height: Math.max.apply(0, Y) - ymin
304 pathClone = function (pathArray) {
306 if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption
307 pathArray = R.parsePathString(pathArray);
309 for (var i = 0, ii = pathArray.length; i < ii; i++) {
311 for (var j = 0, jj = pathArray[i].length; j < jj; j++) {
312 res[i][j] = pathArray[i][j];
315 res.toString = R._path2string;
318 pathToRelative = cacher(function (pathArray) {
319 if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption
320 pathArray = R.parsePathString(pathArray);
328 if (pathArray[0][0] == "M") {
334 res.push(["M", x, y]);
336 for (var i = start, ii = pathArray.length; i < ii; i++) {
339 if (pa[0] != pa[0].toLowerCase()) {
340 r[0] = pa[0].toLowerCase();
348 r[6] = +(pa[6] - x).toFixed(3);
349 r[7] = +(pa[7] - y).toFixed(3);
352 r[1] = +(pa[1] - y).toFixed(3);
358 for (var j = 1, jj = pa.length; j < jj; j++) {
359 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
368 for (var k = 0, kk = pa.length; k < kk; k++) {
372 var len = res[i].length;
379 x += +res[i][len - 1];
382 y += +res[i][len - 1];
385 x += +res[i][len - 2];
386 y += +res[i][len - 1];
389 res.toString = R._path2string;
392 pathToAbsolute = cacher(function (pathArray) {
393 if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption
394 pathArray = R.parsePathString(pathArray);
402 if (pathArray[0][0] == "M") {
403 x = +pathArray[0][1];
404 y = +pathArray[0][2];
408 res[0] = ["M", x, y];
410 for (var i = start, ii = pathArray.length; i < ii; i++) {
413 if (pa[0] != (pa[0] + "").toUpperCase()) {
414 r[0] = (pa[0] + "").toUpperCase();
435 for (var j = 1, jj = pa.length; j < jj; j++) {
436 r[j] = +pa[j] + ((j % 2) ? x : y);
440 for (var k = 0, kk = pa.length; k < kk; k++) {
456 x = res[i][res[i].length - 2];
457 y = res[i][res[i].length - 1];
460 res.toString = R._path2string;
463 l2c = function (x1, y1, x2, y2) {
464 return [x1, y1, x2, y2, x2, y2];
466 q2c = function (x1, y1, ax, ay, x2, y2) {
468 2 / 3 * x1 + 1 / 3 * ax,
469 2 / 3 * y1 + 1 / 3 * ay,
470 2 / 3 * x1 + 1 / 3 * x2,
471 2 / 3 * y1 + 1 / 3 * y2,
476 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
477 // for more information of where this math came from visit:
478 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
479 var _120 = Math.PI * 120 / 180,
480 rad = Math.PI / 180 * (+angle || 0),
483 rotate = cacher(function (x, y, rad) {
484 var X = x * Math.cos(rad) - y * Math.sin(rad),
485 Y = x * Math.sin(rad) + y * Math.cos(rad);
489 xy = rotate(x1, y1, -rad);
492 xy = rotate(x2, y2, -rad);
495 var cos = Math.cos(Math.PI / 180 * angle),
496 sin = Math.sin(Math.PI / 180 * angle),
499 rx = Math.max(rx, Math.abs(x));
500 ry = Math.max(ry, Math.abs(y));
503 k = (large_arc_flag == sweep_flag ? -1 : 1) *
504 Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
505 cx = k * rx * y / ry + (x1 + x2) / 2,
506 cy = k * -ry * x / rx + (y1 + y2) / 2,
507 f1 = Math.asin((y1 - cy) / ry),
508 f2 = Math.asin((y2 - cy) / ry);
510 f1 = x1 < cx ? Math.PI - f1 : f1;
511 f2 = x2 < cx ? Math.PI - f2 : f2;
512 f1 < 0 && (f1 = Math.PI * 2 + f1);
513 f2 < 0 && (f2 = Math.PI * 2 + f2);
514 if (sweep_flag && f1 > f2) {
515 f1 = f1 - Math.PI * 2;
517 if (!sweep_flag && f2 > f1) {
518 f2 = f2 - Math.PI * 2;
527 if (Math.abs(df) > _120) {
531 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
532 x2 = cx + rx * Math.cos(f2);
533 y2 = cy + ry * Math.sin(f2);
534 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
537 var c1 = Math.cos(f1),
541 t = Math.tan(df / 4),
545 m2 = [x1 + hx * s1, y1 - hy * c1],
546 m3 = [x2 + hx * s2, y2 - hy * c2],
548 m2[0] = 2 * m1[0] - m2[0];
549 m2[1] = 2 * m1[1] - m2[1];
551 return [m2, m3, m4].concat(res);
553 res = [m2, m3, m4].concat(res).join(",").split(",");
555 for (var i = 0, ii = res.length; i < ii; i++) {
556 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
561 findDotAtSegment = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
562 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,
563 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,
564 mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
565 my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
566 nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
567 ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
568 ax = (1 - t) * p1x + t * c1x,
569 ay = (1 - t) * p1y + t * c1y,
570 cx = (1 - t) * c2x + t * p2x,
571 cy = (1 - t) * c2y + t * p2y;
572 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}};
574 curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
575 var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
576 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
578 t1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 / a,
579 t2 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2 / a,
582 dot1 = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1 > 0 && t1 < 1 ? t1 : 0),
583 dot2 = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2 > 0 && t2 < 1 ? t2 : 0);
584 x = x.concat(dot1.x, dot2.x);
585 y = y.concat(dot1.y, dot2.y);
586 a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
587 b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
589 t1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 / a;
590 t2 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2 / a;
591 dot1 = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1 > 0 && t1 < 1 ? t1 : 0);
592 dot2 = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2 > 0 && t2 < 1 ? t2 : 0);
593 x = x.concat(dot1.x, dot2.x);
594 y = y.concat(dot1.y, dot2.y);
596 min: {x: Math.min.apply(Math, x), y: Math.min.apply(Math, y)},
597 max: {x: Math.max.apply(Math, x), y: Math.max.apply(Math, y)}
600 path2curve = cacher(function (path, path2) {
601 var p = pathToAbsolute(path),
602 p2 = path2 && pathToAbsolute(path2),
603 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0},
604 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0},
605 processPath = function (path, d) {
608 return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
616 path = ["C"].concat(a2c.apply(0, [d.x, d.y].concat(path.slice(1))));
619 nx = d.x + (d.x - (d.bx || d.x));
620 ny = d.y + (d.y - (d.by || d.y));
621 path = ["C", nx, ny].concat(path.slice(1));
624 nx = d.x + (d.x - (d.bx || d.x));
625 ny = d.y + (d.y - (d.by || d.y));
626 path = ["C"].concat(q2c(d.x, d.y, nx, ny, path[1], path[2]));
629 path = ["C"].concat(q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
632 path = ["C"].concat(l2c(d.x, d.y, path[1], path[2]));
635 path = ["C"].concat(l2c(d.x, d.y, path[1], d.y));
638 path = ["C"].concat(l2c(d.x, d.y, d.x, path[1]));
641 path = ["C"].concat(l2c(d.x, d.y, d.X, d.Y));
646 fixArc = function (pp, i) {
647 if (pp[i].length > 7) {
651 pp.splice(i++, 0, ["C"].concat(pi.splice(0, 6)));
654 ii = Math.max(p.length, p2 && p2.length || 0);
657 fixM = function (path1, path2, a1, a2, i) {
658 if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
659 path2.splice(i, 0, ["M", a2.x, a2.y]);
664 ii = Math.max(p.length, p2 && p2.length || 0);
667 for (var i = 0, ii = Math.max(p.length, p2 && p2.length || 0); i < ii; i++) {
668 p[i] = processPath(p[i], attrs);
670 p2 && (p2[i] = processPath(p2[i], attrs2));
672 fixM(p, p2, attrs, attrs2, i);
673 fixM(p2, p, attrs2, attrs, i);
677 seg2len = p2 && seg2.length;
678 attrs.bx = seg[seglen - 4] || 0;
679 attrs.by = seg[seglen - 3] || 0;
680 attrs.x = seg[seglen - 2];
681 attrs.y = seg[seglen - 1];
682 attrs2.bx = p2 && (seg2[seg2len - 4] || 0);
683 attrs2.by = p2 && (seg2[seg2len - 3] || 0);
684 attrs2.x = p2 && seg2[seg2len - 2];
685 attrs2.y = p2 && seg2[seg2len - 1];
687 return p2 ? [p, p2] : p;
689 toGradient = cacher(function (gradient) {
690 if (R.is(gradient, "string")) {
691 gradient = gradient.split(/\s*\-\s*/);
692 var angle = gradient.shift();
693 if (angle.toLowerCase() == "v") {
695 } else if (angle.toLowerCase() == "h") {
698 angle = parseFloat(angle);
701 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)]},
702 max = 1 / (Math.max(Math.abs(grobj.vector[2]), Math.abs(grobj.vector[3])) || 1);
703 grobj.vector[2] *= max;
704 grobj.vector[3] *= max;
705 if (grobj.vector[2] < 0) {
706 grobj.vector[0] = -grobj.vector[2];
709 if (grobj.vector[3] < 0) {
710 grobj.vector[1] = -grobj.vector[3];
713 grobj.vector[0] = grobj.vector[0];
714 grobj.vector[1] = grobj.vector[1];
715 grobj.vector[2] = grobj.vector[2];
716 grobj.vector[3] = grobj.vector[3];
717 for (var i = 0, ii = gradient.length; i < ii; i++) {
719 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
720 dot.color = R.getRGB(par[1]).hex;
721 par[2] && (dot.offset = par[2] + "%");
722 grobj.dots.push(dot);
724 for (var i = 1, ii = grobj.dots.length - 1; i < ii; i++) {
725 if (!grobj.dots[i].offset) {
726 var start = parseFloat(grobj.dots[i - 1].offset || 0),
728 for (var j = i + 1; j < ii; j++) {
729 if (grobj.dots[j].offset) {
730 end = grobj.dots[j].offset;
738 end = parseFloat(end);
739 var d = (end - start) / (j - i + 1);
742 grobj.dots[i].offset = start + "%";
751 getContainer = function () {
757 if (R.is(arguments[0], "string") || R.is(arguments[0], "object")) {
758 if (R.is(arguments[0], "string")) {
759 container = doc.getElementById(arguments[0]);
761 container = arguments[0];
763 if (container.tagName) {
764 if (arguments[1] == null) {
766 container: container,
767 width: container.style.pixelWidth || container.offsetWidth,
768 height: container.style.pixelHeight || container.offsetHeight
771 return {container: container, width: arguments[1], height: arguments[2]};
774 } else if (R.is(arguments[0], "number") && arguments.length > 3) {
775 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
778 plugins = function (con, add) {
780 for (var prop in add) if (add.hasOwnProperty(prop) && !(prop in con)) {
781 switch (typeof add[prop]) {
784 con[prop] = con === that ? f : function () { return f.apply(that, arguments); };
788 con[prop] = con[prop] || {};
789 plugins.call(this, con[prop], add[prop]);
792 con[prop] = add[prop];
800 paper.svgns = "http://www.w3.org/2000/svg";
801 paper.xlink = "http://www.w3.org/1999/xlink";
802 var round = function (num) {
803 return +num + (Math.floor(num) == num) * .5;
805 var roundPath = function (path) {
806 for (var i = 0, ii = path.length; i < ii; i++) {
807 if (path[i][0].toLowerCase() != "a") {
808 for (var j = 1, jj = path[i].length; j < jj; j++) {
809 path[i][j] = round(path[i][j]);
812 path[i][6] = round(path[i][6]);
813 path[i][7] = round(path[i][7]);
818 var $ = function (el, attr) {
820 for (var key in attr) if (attr.hasOwnProperty(key)) {
821 el.setAttribute(key, attr[key]);
824 return doc.createElementNS(paper.svgns, el);
827 R.toString = function () {
828 return "Your browser supports SVG.\nYou are running Rapha\u00ebl " + this.version;
830 var thePath = function (pathString, SVG) {
832 SVG.canvas && SVG.canvas.appendChild(el);
833 var p = new Element(el, SVG);
835 setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
838 var addGradientFill = function (o, gradient, SVG) {
839 gradient = toGradient(gradient);
840 var el = $((gradient.type || "linear") + "Gradient");
841 el.id = "r" + (R.idGenerator++).toString(36);
842 if (gradient.vector && gradient.vector.length) {
844 x1: gradient.vector[0],
845 y1: gradient.vector[1],
846 x2: gradient.vector[2],
847 y2: gradient.vector[3]
850 SVG.defs.appendChild(el);
851 var isopacity = true;
852 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
853 var stop = $("stop");
854 if (gradient.dots[i].offset) {
858 offset: gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%",
859 "stop-color": R.getRGB(gradient.dots[i].color).hex || "#fff"
861 // ignoring opacity for internal points, because VML doesn't support it
862 el.appendChild(stop);
864 if (isopacity && gradient.dots[ii - 1].opacity != null) {
865 $(stop, {"stop-opacity": gradient.dots[ii - 1].opacity});
868 fill: "url(#" + el.id + ")",
874 o.style.fillOpacity = 1;
876 var updatePosition = function (o) {
877 var bbox = o.getBBox();
878 $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
880 var setFillAndStroke = function (o, params) {
887 "-..": [3, 1, 1, 1, 1, 1],
893 "--..": [8, 3, 1, 3, 1, 3]
897 rot = o.attr("rotation"),
898 addDashes = function (o, value) {
899 value = dasharray[(value + "").toLowerCase()];
901 var width = o.attrs["stroke-width"] || "1",
902 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
904 var i = value.length;
906 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
908 $(node, {"stroke-dasharray": dashes.join(",")});
911 parseFloat(rot) && o.rotate(0, true);
912 for (var att in params) if (params.hasOwnProperty(att)) {
913 if (!(att in availableAttrs)) {
916 var value = params[att];
923 var pn = node.parentNode;
924 if (pn.tagName.toLowerCase() != "a") {
926 pn.insertBefore(hl, node);
927 hl.appendChild(node);
930 pn.setAttributeNS(o.paper.xlink, att, value);
933 var rect = (value + "").split(separator);
934 if (rect.length == 4) {
935 o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
936 var el = $("clipPath"),
938 el.id = "r" + (R.idGenerator++).toString(36);
946 o.paper.defs.appendChild(el);
947 $(node, {"clip-path": "url(#" + el.id + ")"});
951 var clip = doc.getElementById(node.getAttribute("clip-path").replace(/(^url\(#|\)$)/g, ""));
952 clip && clip.parentNode.removeChild(clip);
953 $(node, {"clip-path": ""});
958 if (value && o.type == "path") {
959 attrs.path = roundPath(pathToAbsolute(value));
960 $(node, {d: attrs.path});
963 node.setAttribute(att, value);
972 value = -attrs.x - (attrs.width || 0);
975 if (att == "rx" && o.type == "rect") {
979 node.setAttribute(att, value);
980 o.pattern && updatePosition(o);
983 node.setAttribute(att, value);
992 value = -attrs.y - (attrs.height || 0);
995 if (att == "ry" && o.type == "rect") {
999 node.setAttribute(att, value);
1000 o.pattern && updatePosition(o);
1003 if (o.type == "rect") {
1004 $(node, {rx: value, ry: value});
1006 node.setAttribute(att, value);
1010 if (o.type == "image") {
1011 node.setAttributeNS(o.paper.xlink, "href", value);
1014 case "stroke-width":
1015 node.style.strokeWidth = value;
1016 // Need following line for Firefox
1017 node.setAttribute(att, value);
1018 if (attrs["stroke-dasharray"]) {
1019 addDashes(o, attrs["stroke-dasharray"]);
1022 case "stroke-dasharray":
1023 addDashes(o, value);
1027 o.rotate(value, true);
1030 var xy = (value + "").split(separator);
1031 o.translate((+xy[0] + 1 || 2) - 1, (+xy[1] + 1 || 2) - 1);
1034 var xy = (value + "").split(separator);
1035 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1038 var isURL = (value + "").match(/^url\(['"]?([^\)]+)['"]?\)$/i);
1040 var el = $("pattern"),
1042 el.id = "r" + (R.idGenerator++).toString(36);
1043 $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse"});
1045 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1048 var img = doc.createElement("img");
1049 img.style.position = "absolute";
1050 img.style.top = "-9999em";
1051 img.style.left = "-9999em";
1052 img.onload = function () {
1053 $(el, {width: this.offsetWidth, height: this.offsetHeight});
1054 $(ig, {width: this.offsetWidth, height: this.offsetHeight});
1055 doc.body.removeChild(this);
1058 doc.body.appendChild(img);
1060 o.paper.defs.appendChild(el);
1061 node.style.fill = "url(#" + el.id + ")";
1062 $(node, {fill: "url(#" + el.id + ")"});
1064 o.pattern && updatePosition(o);
1067 delete params.gradient;
1068 delete attrs.gradient;
1069 if (!R.is(attrs.opacity, "undefined") && R.is(params.opacity, "undefined") ) {
1070 node.style.opacity = attrs.opacity;
1071 // Need following line for Firefox
1072 $(node, {opacity: attrs.opacity});
1074 if (!R.is(attrs["fill-opacity"], "undefined") && R.is(params["fill-opacity"], "undefined") ) {
1075 node.style.fillOpacity = attrs["fill-opacity"];
1076 // Need following line for Firefox
1077 $(node, {"fill-opacity": attrs["fill-opacity"]});
1080 node.style[att] = R.getRGB(value).hex;
1081 // Need following line for Firefox
1082 node.setAttribute(att, R.getRGB(value).hex);
1085 addGradientFill(node, value, o.paper);
1088 case "fill-opacity":
1089 if (attrs.gradient) {
1090 var gradient = doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
1092 var stops = gradient.getElementsByTagName("stop");
1093 stops[stops.length - 1].setAttribute("stop-opacity", value);
1098 att == "font-size" && (value = parseInt(value, 10) + "px");
1099 var cssrule = att.replace(/(\-.)/g, function (w) {
1100 return w.substring(1).toUpperCase();
1102 node.style[cssrule] = value;
1103 // Need following line for Firefox
1104 node.setAttribute(att, value);
1109 tuneText(o, params);
1110 parseInt(rot, 10) && o.rotate(rot, true);
1113 var tuneText = function (el, params) {
1114 if (el.type != "text" || !("text" in params || "font" in params || "font-size" in params || "x" in params || "y" in params)) {
1119 fontSize = node.firstChild ? parseInt(doc.defaultView.getComputedStyle(node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
1121 if ("text" in params) {
1122 while (node.firstChild) {
1123 node.removeChild(node.firstChild);
1125 var texts = (params.text + "").split("\n");
1126 for (var i = 0, ii = texts.length; i < ii; i++) {
1127 var tspan = $("tspan");
1128 i && $(tspan, {dy: fontSize * leading, x: a.x});
1129 tspan.appendChild(doc.createTextNode(texts[i]));
1130 node.appendChild(tspan);
1133 var texts = node.getElementsByTagName("tspan");
1134 for (var i = 0, ii = texts.length; i < ii; i++) {
1135 i && $(texts[i], {dy: fontSize * leading, x: a.x});
1139 var bb = el.getBBox(),
1140 dif = a.y - (bb.y + bb.height / 2);
1141 dif && $(node, {y: a.y + dif});
1143 var Element = function (node, svg) {
1149 this.attrs = this.attrs || {};
1150 this.transformations = []; // rotate, translate, scale
1154 rt: {deg: 0, cx: 0, cy: 0},
1159 Element.prototype.rotate = function (deg, cx, cy) {
1162 return [this._.rt.deg, this._.rt.cx, this._.rt.cy].join(" ");
1164 return this._.rt.deg;
1166 var bbox = this.getBBox();
1167 deg = (deg + "").split(separator);
1168 if (deg.length - 1) {
1169 cx = parseFloat(deg[1]);
1170 cy = parseFloat(deg[2]);
1172 deg = parseFloat(deg[0]);
1174 this._.rt.deg = deg;
1176 this._.rt.deg += deg;
1178 (cy == null) && (cx = null);
1181 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1182 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1183 if (this._.rt.deg) {
1184 this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
1185 this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
1187 this.transformations[0] = "";
1188 this.clip && $(this.clip, {transform: ""});
1190 $(this.node, {transform: this.transformations.join(" ")});
1193 Element.prototype.hide = function () {
1194 this.node.style.display = "none";
1197 Element.prototype.show = function () {
1198 this.node.style.display = "block";
1201 Element.prototype.remove = function () {
1202 this.node.parentNode.removeChild(this.node);
1204 Element.prototype.getBBox = function () {
1205 if (this.type == "path") {
1206 return pathDimensions(this.attrs.path);
1208 if (this.node.style.display == "none") {
1214 bbox = this.node.getBBox();
1216 // Firefox 3.0.x plays badly here
1220 if (this.type == "text") {
1221 bbox = {x: bbox.x, y: Infinity, width: bbox.width, height: 0};
1222 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1223 var bb = this.node.getExtentOfChar(i);
1224 (bb.y < bbox.y) && (bbox.y = bb.y);
1225 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1228 hide && this.hide();
1231 Element.prototype.attr = function () {
1232 if (arguments.length == 1 && R.is(arguments[0], "string")) {
1233 if (arguments[0] == "translation") {
1234 return this.translate();
1236 if (arguments[0] == "rotation") {
1237 return this.rotate();
1239 if (arguments[0] == "scale") {
1240 return this.scale();
1242 return this.attrs[arguments[0]];
1244 if (arguments.length == 1 && R.is(arguments[0], "array")) {
1246 for (var j in arguments[0]) if (arguments[0].hasOwnProperty(j)) {
1247 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1251 if (arguments.length == 2) {
1253 params[arguments[0]] = arguments[1];
1254 setFillAndStroke(this, params);
1255 } else if (arguments.length == 1 && R.is(arguments[0], "object")) {
1256 setFillAndStroke(this, arguments[0]);
1260 Element.prototype.toFront = function () {
1261 this.node.parentNode.appendChild(this.node);
1264 Element.prototype.toBack = function () {
1265 if (this.node.parentNode.firstChild != this.node) {
1266 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1270 Element.prototype.insertAfter = function (element) {
1271 if (element.node.nextSibling) {
1272 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1274 element.node.parentNode.appendChild(this.node);
1278 Element.prototype.insertBefore = function (element) {
1279 var node = element.node;
1280 node.parentNode.insertBefore(this.node, node);
1283 Element.prototype.blur = function (size) {
1284 // Experimental. No WebKit support.
1285 if (size != "none") {
1286 var fltr = $("filter"),
1287 blur = $("feGaussianBlur");
1288 fltr.id = "r" + (R.idGenerator++).toString(36);
1289 $(blur, {stdDeviation: +size || 1.5});
1290 fltr.appendChild(blur);
1291 this.paper.defs.appendChild(fltr);
1293 $(this.node, {filter: "url(#" + fltr.id + ")"});
1296 this._blur.parentNode.removeChild(this._blur);
1299 this.node.removeAttribute("filter");
1303 var theCircle = function (svg, x, y, r) {
1306 var el = $("circle");
1307 svg.canvas && svg.canvas.appendChild(el);
1308 var res = new Element(el, svg);
1309 res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1310 res.type = "circle";
1314 var theRect = function (svg, x, y, w, h, r) {
1318 svg.canvas && svg.canvas.appendChild(el);
1319 var res = new Element(el, svg);
1320 res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1325 var theEllipse = function (svg, x, y, rx, ry) {
1328 var el = $("ellipse");
1329 svg.canvas && svg.canvas.appendChild(el);
1330 var res = new Element(el, svg);
1331 res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1332 res.type = "ellipse";
1336 var theImage = function (svg, src, x, y, w, h) {
1337 var el = $("image");
1338 $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1339 el.setAttributeNS(svg.xlink, "href", src);
1340 svg.canvas && svg.canvas.appendChild(el);
1341 var res = new Element(el, svg);
1342 res.attrs = {x: x, y: y, width: w, height: h, src: src};
1346 var theText = function (svg, x, y, text) {
1348 $(el, {x: x, y: y, "text-anchor": "middle"});
1349 svg.canvas && svg.canvas.appendChild(el);
1350 var res = new Element(el, svg);
1351 res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
1353 setFillAndStroke(res, res.attrs);
1356 var setSize = function (width, height) {
1357 this.width = width || this.width;
1358 this.height = height || this.height;
1359 this.canvas.setAttribute("width", this.width);
1360 this.canvas.setAttribute("height", this.height);
1363 var create = function () {
1364 var con = getContainer.apply(null, arguments),
1365 container = con.container,
1369 height = con.height;
1371 throw new Error("SVG container not found.");
1373 paper.canvas = $("svg");
1374 var cnvs = paper.canvas,
1376 cnvs.setAttribute("width", width || 512);
1377 paper.width = width || 512;
1378 cnvs.setAttribute("height", height || 342);
1379 paper.height = height || 342;
1380 if (container == 1) {
1381 doc.body.appendChild(cnvs);
1382 stl.position = "absolute";
1383 stl.left = x + "px";
1386 if (container.firstChild) {
1387 container.insertBefore(cnvs, container.firstChild);
1389 container.appendChild(cnvs);
1394 clear: function () {
1395 while (this.canvas.firstChild) {
1396 this.canvas.removeChild(this.canvas.firstChild);
1398 this.desc = $("desc");
1399 this.defs = $("defs");
1400 this.desc.appendChild(doc.createTextNode("Created with Rapha\u00ebl"));
1401 this.canvas.appendChild(this.desc);
1402 this.canvas.appendChild(this.defs);
1405 for (var prop in paper) if (paper.hasOwnProperty(prop)) {
1406 if (prop != "create") {
1407 container[prop] = paper[prop];
1410 plugins.call(container, container, R.fn);
1412 container.raphael = R;
1415 paper.remove = function () {
1416 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1418 if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) { // Safari or Chrome (WebKit)
1419 paper.safari = function () {
1420 var rect = this.rect(-99, -99, this.width + 99, this.height + 99);
1421 setTimeout(function () {rect.remove();});
1424 paper.safari = function () {};
1430 var path2vml = function (path) {
1431 var pa = path2curve(path);
1432 for (var i = 0, ii = pa.length; i < ii; i++) {
1433 pa[i][0] = (pa[i][0] + "").toLowerCase();
1434 pa[i][0] == "z" && (pa[i][0] = "x");
1435 for (var j = 1, jj = pa[i].length; j < jj; j++) {
1436 pa[i][j] = Math.round(pa[i][j]);
1441 R.toString = function () {
1442 return "Your browser doesn\u2019t support SVG. Assuming it is Internet Explorer and falling down to VML.\nYou are running Rapha\u00ebl " + this.version;
1444 var thePath = function (pathString, VML) {
1445 var g = createNode("group"), gl = g.style;
1446 gl.position = "absolute";
1449 gl.width = VML.width + "px";
1450 gl.height = VML.height + "px";
1451 g.coordsize = VML.coordsize;
1452 g.coordorigin = VML.coordorigin;
1453 var el = createNode("shape"), ol = el.style;
1454 ol.width = VML.width + "px";
1455 ol.height = VML.height + "px";
1457 el.coordsize = this.coordsize;
1458 el.coordorigin = this.coordorigin;
1460 var p = new Element(el, g, VML);
1461 p.isAbsolute = true;
1464 // p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1467 p.attrs.path = R.parsePathString(pathString);
1468 p.node.path = path2vml(p.attrs.path);
1470 setFillAndStroke(p, {fill: "none", stroke: "#000"});
1472 VML.canvas.appendChild(g);
1475 var setFillAndStroke = function (o, params) {
1476 o.attrs = o.attrs || {};
1482 for (var par in params) if (params.hasOwnProperty(par)) {
1483 a[par] = params[par];
1485 params.href && (node.href = params.href);
1486 params.title && (node.title = params.title);
1487 params.target && (node.target = params.target);
1488 if (params.path && o.type == "path") {
1489 a.path = R.parsePathString(params.path);
1490 node.path = path2vml(a.path);
1492 if (params.rotation != null) {
1493 o.rotate(params.rotation, true);
1495 if (params.translation) {
1496 xy = (params.translation + "").split(separator);
1497 o.translate(xy[0], xy[1]);
1500 xy = (params.scale + "").split(separator);
1501 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1503 if ("clip-rect" in params) {
1504 var rect = (params["clip-rect"] + "").split(separator);
1505 if (rect.length == 4) {
1506 rect[2] = +rect[2] + (+rect[0]);
1507 rect[3] = +rect[3] + (+rect[1]);
1508 var div = node.clipRect || doc.createElement("div"),
1510 group = node.parentNode;
1511 dstyle.clip = R.format("rect({0}px {2}px {3}px {1}px)", rect);
1512 if (!node.clipRect) {
1513 dstyle.position = "absolute";
1516 dstyle.width = o.paper.width + "px";
1517 dstyle.height = o.paper.height + "px";
1518 group.parentNode.insertBefore(div, group);
1519 div.appendChild(group);
1520 node.clipRect = div;
1523 if (!params["clip-rect"]) {
1524 node.clipRect && (node.clipRect.style.clip = "");
1527 if (o.type == "image" && params.src) {
1528 node.src = params.src;
1530 if (o.type == "image" && params.opacity) {
1531 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1532 s.filter = (node.filterMatrix || "") + (node.filterOpacity || "");
1534 params.font && (s.font = params.font);
1535 params["font-family"] && (s.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, "") + '"');
1536 params["font-size"] && (s.fontSize = params["font-size"]);
1537 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1538 params["font-style"] && (s.fontStyle = params["font-style"]);
1539 if (params.opacity != null ||
1540 params["stroke-width"] != null ||
1541 params.fill != null ||
1542 params.stroke != null ||
1543 params["stroke-width"] != null ||
1544 params["stroke-opacity"] != null ||
1545 params["fill-opacity"] != null ||
1546 params["stroke-dasharray"] != null ||
1547 params["stroke-miterlimit"] != null ||
1548 params["stroke-linejoin"] != null ||
1549 params["stroke-linecap"] != null) {
1550 node = o.shape || node;
1551 var fill = (node.getElementsByTagName("fill") && node.getElementsByTagName("fill")[0]),
1553 !fill && (newfill = fill = createNode("fill"));
1554 if ("fill-opacity" in params || "opacity" in params) {
1555 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1);
1556 opacity < 0 && (opacity = 0);
1557 opacity > 1 && (opacity = 1);
1558 fill.opacity = opacity;
1560 params.fill && (fill.on = true);
1561 if (fill.on == null || params.fill == "none") {
1564 if (fill.on && params.fill) {
1565 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1567 fill.src = isURL[1];
1570 fill.color = R.getRGB(params.fill).hex;
1572 fill.type = "solid";
1575 newfill && node.appendChild(fill);
1576 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
1578 !stroke && (newstroke = stroke = createNode("stroke"));
1579 if ((params.stroke && params.stroke != "none") ||
1580 params["stroke-width"] ||
1581 params["stroke-opacity"] != null ||
1582 params["stroke-dasharray"] ||
1583 params["stroke-miterlimit"] ||
1584 params["stroke-linejoin"] ||
1585 params["stroke-linecap"]) {
1588 (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
1589 stroke.on && params.stroke && (stroke.color = R.getRGB(params.stroke).hex);
1590 var opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1);
1591 opacity < 0 && (opacity = 0);
1592 opacity > 1 && (opacity = 1);
1593 stroke.opacity = opacity;
1594 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1595 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1596 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1597 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"]) || 1) * 12 / 16);
1598 if (params["stroke-dasharray"]) {
1602 "-.": "shortdashdot",
1603 "-..": "shortdashdotdot",
1608 "--.": "longdashdot",
1609 "--..": "longdashdotdot"
1611 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1613 newstroke && node.appendChild(stroke);
1615 if (res.type == "text") {
1616 var s = paper.span.style;
1617 a.font && (s.font = a.font);
1618 a["font-family"] && (s.fontFamily = a["font-family"]);
1619 a["font-size"] && (s.fontSize = a["font-size"]);
1620 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1621 a["font-style"] && (s.fontStyle = a["font-style"]);
1622 paper.span.innerHTML = res.node.string.replace(/</g, "<").replace(/&/g, "&").replace(/\n/g, "<br>");
1623 res.W = a.w = paper.span.offsetWidth;
1624 res.H = a.h = paper.span.offsetHeight;
1626 res.Y = a.y + Math.round(res.H / 2);
1628 // text-anchor emulation
1629 switch (a["text-anchor"]) {
1631 res.node.style["v-text-align"] = "left";
1632 res.bbx = Math.round(res.W / 2);
1635 res.node.style["v-text-align"] = "right";
1636 res.bbx = -Math.round(res.W / 2);
1639 res.node.style["v-text-align"] = "center";
1644 var getAngle = function (a, b, c, d) {
1645 var angle = Math.round(Math.atan((parseFloat(c) - parseFloat(a)) / (parseFloat(d) - parseFloat(b))) * 57.29) || 0;
1646 if (!angle && parseFloat(a) < parseFloat(b)) {
1655 var addGradientFill = function (o, gradient) {
1656 gradient = toGradient(gradient);
1657 o.attrs = o.attrs || {};
1658 var attrs = o.attrs,
1659 fill = o.node.getElementsByTagName("fill");
1660 o.attrs.gradient = gradient;
1661 o = o.shape || o.node;
1665 fill = createNode("fill");
1667 if (gradient.dots.length) {
1669 fill.method = "none";
1670 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1671 if (!R.is(gradient.dots[0].color, "undefined")) {
1672 fill.color = R.getRGB(gradient.dots[0].color).hex;
1674 if (!R.is(gradient.dots[gradient.dots.length - 1].color, "undefined")) {
1675 fill.color2 = R.getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1678 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1679 if (gradient.dots[i].offset) {
1680 clrs.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
1683 var fillOpacity = R.is(gradient.dots[gradient.dots.length - 1].opacity, "undefined") ? (R.is(attrs.opacity, "undefined") ? 1 : attrs.opacity) : gradient.dots[gradient.dots.length - 1].opacity;
1685 fill.colors.value = clrs.join(",");
1686 fillOpacity = R.is(attrs.opacity, "undefined") ? 1 : attrs.opacity;
1688 fill.colors && (fill.colors.value = "0% " + fill.color);
1690 fill.opacity = fillOpacity;
1691 if (!R.is(gradient.angle, "undefined")) {
1692 fill.angle = (-gradient.angle + 270) % 360;
1693 } else if (gradient.vector) {
1694 fill.angle = getAngle.apply(null, gradient.vector);
1696 if ((gradient.type + "").toLowerCase() == "radial") {
1697 fill.focus = "100%";
1698 fill.focusposition = "0.5 0.5";
1702 var Element = function (node, group, vml) {
1722 Element.prototype.rotate = function (deg, cx, cy) {
1725 return [this._.rt.deg, this._.rt.cx, this._.rt.cy].join(" ");
1727 return this._.rt.deg;
1729 deg = (deg + "").split(separator);
1730 if (deg.length - 1) {
1731 cx = parseFloat(deg[1]);
1732 cy = parseFloat(deg[2]);
1734 deg = parseFloat(deg[0]);
1736 this._.rt.deg = deg;
1738 this._.rt.deg += deg;
1740 (cy == null) && (cx = null);
1743 this.setBox(this.attrs, cx, cy);
1744 this.Group.style.rotation = this._.rt.deg;
1745 // gradient fix for rotation. TODO
1746 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1747 // fill = fill[0] || {};
1748 // var b = ((360 - this._.rt.deg) - 270) % 360;
1749 // !R.is(fill.angle, "undefined") && (fill.angle = b);
1752 Element.prototype.setBox = function (params, cx, cy) {
1753 var gs = this.Group.style,
1754 os = (this.shape && this.shape.style) || this.node.style;
1755 params = params || {};
1756 for (var i in params) if (params.hasOwnProperty(i)) {
1757 this.attrs[i] = params[i];
1759 cx = cx || this._.rt.cx;
1760 cy = cy || this._.rt.cy;
1761 var attr = this.attrs,
1766 switch (this.type) {
1768 x = attr.cx - attr.r;
1769 y = attr.cy - attr.r;
1773 x = attr.cx - attr.rx;
1774 y = attr.cy - attr.ry;
1782 w = attr.width || 0;
1783 h = attr.height || 0;
1786 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("");
1787 x = attr.x - Math.round(this.W / 2);
1788 y = attr.y - this.H / 2;
1793 if (!this.attrs.path) {
1796 w = this.paper.width;
1797 h = this.paper.height;
1799 var dim = pathDimensions(this.attrs.path);
1809 w = this.paper.width;
1810 h = this.paper.height;
1813 cx = (cx == null) ? x + w / 2 : cx;
1814 cy = (cy == null) ? y + h / 2 : cy;
1815 var left = cx - this.paper.width / 2,
1816 top = cy - this.paper.height / 2;
1817 if (this.type == "path" || this.type == "text") {
1818 (gs.left != left + "px") && (gs.left = left + "px");
1819 (gs.top != top + "px") && (gs.top = top + "px");
1820 this.X = this.type == "text" ? x : -left;
1821 this.Y = this.type == "text" ? y : -top;
1824 (os.left != -left + "px") && (os.left = -left + "px");
1825 (os.top != -top + "px") && (os.top = -top + "px");
1827 (gs.left != left + "px") && (gs.left = left + "px");
1828 (gs.top != top + "px") && (gs.top = top + "px");
1833 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
1834 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
1835 (os.left != x - left + "px") && (os.left = x - left + "px");
1836 (os.top != y - top + "px") && (os.top = y - top + "px");
1837 (os.width != w + "px") && (os.width = w + "px");
1838 (os.height != h + "px") && (os.height = h + "px");
1839 var arcsize = (+params.r || 0) / (Math.min(w, h));
1840 if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
1841 // We should replace element with the new one
1842 var o = createNode(arcsize ? "roundrect" : "rect");
1843 o.arcsize = arcsize;
1844 this.Group.appendChild(o);
1845 this.node.parentNode.removeChild(this.node);
1847 this.arcsize = arcsize;
1848 setFillAndStroke(this, this.attrs);
1849 this.setBox(this.attrs);
1853 Element.prototype.hide = function () {
1854 this.Group.style.display = "none";
1857 Element.prototype.show = function () {
1858 this.Group.style.display = "block";
1861 Element.prototype.getBBox = function () {
1862 if (this.type == "path") {
1863 return pathDimensions(this.attrs.path);
1866 x: this.X + (this.bbx || 0),
1872 Element.prototype.remove = function () {
1873 this[0].parentNode.removeChild(this[0]);
1874 this.Group.parentNode.removeChild(this.Group);
1875 this.shape && this.shape.parentNode.removeChild(this.shape);
1877 Element.prototype.attr = function () {
1878 if (arguments.length == 1 && R.is(arguments[0], "string")) {
1879 if (arguments[0] == "translation") {
1880 return this.translate();
1882 if (arguments[0] == "rotation") {
1883 return this.rotate();
1885 if (arguments[0] == "scale") {
1886 return this.scale();
1888 return this.attrs[arguments[0]];
1890 if (this.attrs && arguments.length == 1 && R.is(arguments[0], "array")) {
1892 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1893 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1898 if (arguments.length == 2) {
1900 params[arguments[0]] = arguments[1];
1902 if (arguments.length == 1 && R.is(arguments[0], "object")) {
1903 params = arguments[0];
1906 if (params.gradient) {
1907 addGradientFill(this, params.gradient);
1909 if (params.text && this.type == "text") {
1910 this.node.string = params.text;
1912 setFillAndStroke(this, params);
1913 this.setBox(this.attrs);
1917 Element.prototype.toFront = function () {
1918 this.Group.parentNode.appendChild(this.Group);
1921 Element.prototype.toBack = function () {
1922 if (this.Group.parentNode.firstChild != this.Group) {
1923 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
1927 Element.prototype.insertAfter = function (element) {
1928 if (element.Group.nextSibling) {
1929 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
1931 element.Group.parentNode.appendChild(this.Group);
1935 Element.prototype.insertBefore = function (element) {
1936 element.Group.parentNode.insertBefore(this.Group, element.Group);
1939 Element.prototype.blur = function (size) {
1940 var s = this.node.style,
1942 f = f.replace(/progid:DXImageTransform\.Microsoft\.Blur\(pixelradius\=[^\)]+\)/g, "");
1943 if (size != "none") {
1944 s.filter = f + " progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (+size || 1.5) + ")";
1945 s.margin = R.format("-{0}px 0 0 -{0}px", Math.round(+size || 1.5));
1952 var theCircle = function (vml, x, y, r) {
1953 var g = createNode("group"),
1955 o = createNode("oval"),
1957 gl.position = "absolute";
1960 gl.width = vml.width + "px";
1961 gl.height = vml.height + "px";
1962 g.coordsize = vml.coordsize;
1963 g.coordorigin = vml.coordorigin;
1965 var res = new Element(o, g, vml);
1966 res.type = "circle";
1967 setFillAndStroke(res, {stroke: "#000", fill: "none"});
1971 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
1972 vml.canvas.appendChild(g);
1975 var theRect = function (vml, x, y, w, h, r) {
1976 var g = createNode("group"),
1978 o = createNode(r ? "roundrect" : "rect"),
1979 arcsize = (+r || 0) / (Math.min(w, h));
1980 o.arcsize = arcsize;
1981 gl.position = "absolute";
1984 gl.width = vml.width + "px";
1985 gl.height = vml.height + "px";
1986 g.coordsize = vml.coordsize;
1987 g.coordorigin = vml.coordorigin;
1989 var res = new Element(o, g, vml);
1991 setFillAndStroke(res, {stroke: "#000"});
1992 res.arcsize = arcsize;
1993 res.setBox({x: x, y: y, width: w, height: h, r: +r});
1994 vml.canvas.appendChild(g);
1997 var theEllipse = function (vml, x, y, rx, ry) {
1998 var g = createNode("group"),
2000 o = createNode("oval"),
2002 gl.position = "absolute";
2005 gl.width = vml.width + "px";
2006 gl.height = vml.height + "px";
2007 g.coordsize = vml.coordsize;
2008 g.coordorigin = vml.coordorigin;
2010 var res = new Element(o, g, vml);
2011 res.type = "ellipse";
2012 setFillAndStroke(res, {stroke: "#000"});
2017 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2018 vml.canvas.appendChild(g);
2021 var theImage = function (vml, src, x, y, w, h) {
2022 var g = createNode("group"),
2024 o = createNode("image"),
2026 gl.position = "absolute";
2029 gl.width = vml.width + "px";
2030 gl.height = vml.height + "px";
2031 g.coordsize = vml.coordsize;
2032 g.coordorigin = vml.coordorigin;
2035 var res = new Element(o, g, vml);
2037 res.attrs.src = src;
2042 res.setBox({x: x, y: y, width: w, height: h});
2043 vml.canvas.appendChild(g);
2046 var theText = function (vml, x, y, text) {
2047 var g = createNode("group"),
2049 el = createNode("shape"),
2051 path = createNode("path"),
2053 o = createNode("textpath");
2054 gs.position = "absolute";
2057 gs.width = vml.width + "px";
2058 gs.height = vml.height + "px";
2059 g.coordsize = vml.coordsize;
2060 g.coordorigin = vml.coordorigin;
2061 path.v = ["m", Math.round(x), ", ", Math.round(y), "l", Math.round(x) + 1, ", ", Math.round(y)].join("");
2062 path.textpathok = true;
2063 ol.width = vml.width;
2064 ol.height = vml.height;
2065 gs.position = "absolute";
2068 gs.width = vml.width;
2069 gs.height = vml.height;
2073 el.appendChild(path);
2075 var res = new Element(o, g, vml);
2077 res.textpath = path;
2079 res.attrs.text = text;
2084 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2086 vml.canvas.appendChild(g);
2089 var setSize = function (width, height) {
2090 var cs = this.canvas.style;
2091 this.width = parseFloat(width || this.width);
2092 this.height = parseFloat(height || this.height);
2093 cs.width = this.width + "px";
2094 cs.height = this.height + "px";
2095 cs.clip = "rect(0 " + this.width + "px " + this.height + "px 0)";
2096 this.coordsize = this.width + " " + this.height;
2099 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2101 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2102 var createNode = function (tagName) {
2103 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2106 var createNode = function (tagName) {
2107 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2110 var create = function () {
2111 var con = getContainer.apply(null, arguments),
2112 container = con.container,
2113 height = con.height,
2119 throw new Error("VML container not found.");
2121 var c = paper.canvas = doc.createElement("div"),
2123 width = parseFloat(width) || "512px";
2124 height = parseFloat(height) || "342px";
2125 paper.width = width;
2126 paper.height = height;
2127 paper.coordsize = width + " " + height;
2128 paper.coordorigin = "0 0";
2129 paper.span = doc.createElement("span");
2130 s = paper.span.style;
2131 c.appendChild(paper.span);
2132 s.position = "absolute";
2133 s.left = "-99999px";
2138 s.display = "inline";
2139 cs.width = width + "px";
2140 cs.height = height + "px";
2141 cs.position = "absolute";
2142 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2143 if (container == 1) {
2144 doc.body.appendChild(c);
2154 container.style.width = width;
2155 container.style.height = height;
2156 if (container.firstChild) {
2157 container.insertBefore(c, container.firstChild);
2159 container.appendChild(c);
2162 for (var prop in paper) if (paper.hasOwnProperty(prop)) {
2163 container[prop] = paper[prop];
2165 plugins.call(container, container, R.fn);
2166 container.clear = function () {
2167 while (c.firstChild) {
2168 c.removeChild(c.firstChild);
2171 container.raphael = R;
2174 paper.remove = function () {
2175 this.canvas.parentNode.removeChild(this.canvas);
2177 paper.safari = function () {};
2183 var addEvent = (function () {
2184 if (doc.addEventListener) {
2185 return function (obj, type, fn, element) {
2186 var f = function (e) {
2187 return fn.call(element, e);
2189 obj.addEventListener(type, f, false);
2190 return function () {
2191 obj.removeEventListener(type, f, false);
2195 } else if (doc.attachEvent) {
2196 return function (obj, type, fn, element) {
2197 var f = function (e) {
2198 return fn.call(element, e || win.event);
2200 obj.attachEvent("on" + type, f);
2201 var detacher = function () {
2202 obj.detachEvent("on" + type, f);
2205 if (type == "mouseover") {
2206 obj.attachEvent("onmouseenter", f);
2207 return function () {
2208 obj.detachEvent("onmouseenter", f);
2211 } else if (type == "mouseout") {
2212 obj.attachEvent("onmouseleave", f);
2213 return function () {
2214 obj.detachEvent("onmouseleave", f);
2222 for (var i = events.length; i--;) {
2223 (function (eventName) {
2224 Element.prototype[eventName] = function (fn) {
2225 if (R.is(fn, "function")) {
2226 this.events = this.events || {};
2227 this.events[eventName] = this.events[eventName] || {};
2228 this.events[eventName][fn] = this.events[eventName][fn] || [];
2229 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2233 Element.prototype["un" + eventName] = function (fn) {
2235 this.events[eventName] &&
2236 this.events[eventName][fn] &&
2237 this.events[eventName][fn].length &&
2238 this.events[eventName][fn].shift()() &&
2239 !this.events[eventName][fn].length &&
2240 delete this.events[eventName][fn];
2245 paper.circle = function (x, y, r) {
2246 return theCircle(this, x, y, r);
2248 paper.rect = function (x, y, w, h, r) {
2249 return theRect(this, x, y, w, h, r);
2251 paper.ellipse = function (x, y, rx, ry) {
2252 return theEllipse(this, x, y, rx, ry);
2254 paper.path = function (pathString) {
2255 pathString && !R.is(pathString, "string") && !R.is(pathString[0], "array") && (pathString += "");
2256 return thePath(R.format.apply(R, arguments), this);
2258 paper.image = function (src, x, y, w, h) {
2259 return theImage(this, src, x, y, w, h);
2261 paper.text = function (x, y, text) {
2262 return theText(this, x, y, text);
2264 paper.set = function (itemsArray) {
2265 arguments.length > 1 && (itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length));
2266 return new Set(itemsArray);
2268 paper.setSize = setSize;
2269 Element.prototype.stop = function () {
2270 clearTimeout(this.animation_in_progress);
2273 Element.prototype.scale = function (x, y, cx, cy) {
2274 if (x == null && y == null) {
2275 return {x: this._.sx, y: this._.sy, toString: function () { return this.x + " " + this.y; }};
2285 var bb = this.getBBox(),
2286 rcx = bb.x + bb.width / 2,
2287 rcy = bb.y + bb.height / 2,
2290 cx = (+cx || cx == 0) ? cx : rcx;
2291 cy = (+cy || cy == 0) ? cy : rcy;
2292 var dirx = Math.round(x / Math.abs(x)),
2293 diry = Math.round(y / Math.abs(y)),
2294 s = this.node.style,
2295 ncx = cx + (rcx - cx) * dirx * kx,
2296 ncy = cy + (rcy - cy) * diry * ky;
2297 switch (this.type) {
2300 var neww = a.width * dirx * kx,
2301 newh = a.height * diry * ky,
2302 newx = ncx - neww / 2,
2303 newy = ncy - newh / 2;
2322 var path = pathToRelative(a.path),
2324 for (var i = 0, ii = path.length; i < ii; i++) {
2326 if (p[0].toUpperCase() == "M" && skip) {
2331 if (R.svg && p[0].toUpperCase() == "A") {
2332 p[path[i].length - 2] *= kx;
2333 p[path[i].length - 1] *= ky;
2336 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2338 for (var j = 1, jj = p.length; j < jj; j++) {
2339 p[j] *= (j % 2) ? kx : ky;
2343 var dim2 = pathDimensions(path),
2344 dx = ncx - dim2.x - dim2.width / 2,
2345 dy = ncy - dim2.y - dim2.height / 2;
2346 path = pathToRelative(path);
2350 this.attr({path: path.join(" ")});
2353 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2354 if (this.transformations) {
2355 this.transformations[2] = "scale(".concat(dirx, ",", diry, ")");
2356 this.node.setAttribute("transform", this.transformations.join(" "));
2357 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2358 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2359 this.attr({x: dx, y: dy});
2363 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=".concat(dirx,
2364 ", M12=0, M21=0, M22=", diry,
2365 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2366 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2369 if (this.transformations) {
2370 this.transformations[2] = "";
2371 this.node.setAttribute("transform", this.transformations.join(" "));
2375 this.node.filterMatrix = "";
2376 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2379 a.scale = [x, y, cx, cy].join(" ");
2386 // animation easing formulas
2387 R.easing_formulas = {
2388 linear: function (n) {
2392 return Math.pow(n, 3);
2395 return Math.pow(n - 1, 3) + 1;
2397 "<>": function (n) {
2400 return Math.pow(n, 3) / 2;
2403 return (Math.pow(n, 3) + 2) / 2;
2405 backIn: function (n) {
2407 return n * n * ((s + 1) * n - s);
2409 backOut: function (n) {
2412 return n * n * ((s + 1) * n + s) + 1;
2414 elastic: function (n) {
2415 if (n == 0 || n == 1) {
2420 return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1;
2422 bounce: function (n) {
2431 l = s * n * n + .75;
2433 if (n < (2.5 / p)) {
2435 l = s * n * n + .9375;
2438 l = s * n * n + .984375;
2446 Element.prototype.animate = function (params, ms, easing, callback) {
2447 clearTimeout(this.animation_in_progress);
2448 if (R.is(easing, "function") || !easing) {
2449 callback = easing || null;
2455 for (var attr in params) if (params.hasOwnProperty(attr)) {
2456 if (attr in availableAnimAttrs) {
2457 from[attr] = this.attr(attr);
2458 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
2459 to[attr] = params[attr];
2460 switch (availableAnimAttrs[attr]) {
2462 diff[attr] = (to[attr] - from[attr]) / ms;
2465 from[attr] = R.getRGB(from[attr]);
2466 var toColour = R.getRGB(to[attr]);
2468 r: (toColour.r - from[attr].r) / ms,
2469 g: (toColour.g - from[attr].g) / ms,
2470 b: (toColour.b - from[attr].b) / ms
2474 var pathes = path2curve(from[attr], to[attr]);
2475 from[attr] = pathes[0];
2476 to[attr] = pathes[1];
2478 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2479 diff[attr][i] = [0];
2480 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2481 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2486 var values = (params[attr] + "").split(separator),
2487 from2 = (from[attr] + "").split(separator);
2490 from[attr] = [0, 0];
2491 diff[attr] = [values[0] / ms, values[1] / ms];
2494 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2495 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2498 params[attr] = values;
2499 from[attr] = (from[attr] + "").split(separator);
2500 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2503 from[attr] = (from[attr] + "").split(separator);
2507 diff[attr][i] = (values[i] - from[attr][i]) / ms;
2515 var start = +new Date,
2517 upto255 = function (color) {
2518 return +color > 255 ? 255 : +color;
2522 var time = new Date - start,
2526 var pos = R.easing_formulas[easing] ? R.easing_formulas[easing](time / ms) : time / ms;
2527 for (var attr in from) if (from.hasOwnProperty(attr)) {
2528 switch (availableAnimAttrs[attr]) {
2530 now = +from[attr] + pos * ms * diff[attr];
2534 upto255(Math.round(from[attr].r + pos * ms * diff[attr].r)),
2535 upto255(Math.round(from[attr].g + pos * ms * diff[attr].g)),
2536 upto255(Math.round(from[attr].b + pos * ms * diff[attr].b))
2541 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2542 now[i] = [from[attr][i][0]];
2543 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2544 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
2546 now[i] = now[i].join(" ");
2548 now = now.join(" ");
2553 var x = diff[attr][0] * (time - prev),
2554 y = diff[attr][1] * (time - prev);
2557 now = [x, y].join(" ");
2560 now = +from[attr][0] + pos * ms * diff[attr][0];
2561 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2564 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(" ");
2570 now[i] = +from[attr][i] + pos * ms * diff[attr][i];
2579 that.animation_in_progress = setTimeout(tick);
2580 R.svg && paper.safari();
2582 (t.x || t.y) && that.translate(-t.x, -t.y);
2584 clearTimeout(that.animation_in_progress);
2585 R.svg && paper.safari();
2586 (R.is(callback, "function")) && callback.call(that);
2592 Element.prototype.translate = function (x, y) {
2594 return {x: this._.tx, y: this._.ty};
2598 switch (this.type) {
2601 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
2606 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
2609 var path = pathToRelative(this.attrs.path);
2612 this.attr({path: path});
2619 var Set = function (items) {
2623 for (var i = 0, ii = items.length; i < ii; i++) {
2624 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
2625 this[this.items.length] = this.items[this.items.length] = items[i];
2631 Set.prototype.push = function () {
2634 for (var i = 0, ii = arguments.length; i < ii; i++) {
2635 item = arguments[i];
2636 if (item && (item.constructor == Element || item.constructor == Set)) {
2637 len = this.items.length;
2638 this[len] = this.items[len] = item;
2644 Set.prototype.pop = function () {
2645 delete this[this.length--];
2646 return this.items.pop();
2648 for (var method in Element.prototype) if (Element.prototype.hasOwnProperty(method)) {
2649 Set.prototype[method] = (function (methodname) {
2650 return function () {
2651 for (var i = 0, ii = this.items.length; i < ii; i++) {
2652 this.items[i][methodname].apply(this.items[i], arguments);
2658 Set.prototype.attr = function (name, value) {
2659 if (name && R.is(name, "array") && R.is(name[0], "object")) {
2660 for (var j = 0, jj = name.length; j < jj; j++) {
2661 this.items[j].attr(name[j]);
2664 for (var i = 0, ii = this.items.length; i < ii; i++) {
2665 this.items[i].attr.apply(this.items[i], arguments);
2671 Set.prototype.getBBox = function () {
2676 for (var i = this.items.length; i--;) {
2677 var box = this.items[i].getBBox();
2680 w.push(box.x + box.width);
2681 h.push(box.y + box.height);
2683 x = Math.min.apply(Math, x);
2684 y = Math.min.apply(Math, y);
2688 width: Math.max.apply(Math, w) - x,
2689 height: Math.max.apply(Math, h) - y
2693 R.registerFont = function (font) {
2697 this.fonts = this.fonts || {};
2703 family = font.face["font-family"];
2704 for (var prop in font.face) if (font.face.hasOwnProperty(prop)) {
2705 fontcopy.face[prop] = font.face[prop];
2707 if (this.fonts[family]) {
2708 this.fonts[family].push(fontcopy);
2710 this.fonts[family] = [fontcopy];
2713 fontcopy.face["units-per-em"] = parseInt(font.face["units-per-em"], 10);
2714 for (var glyph in font.glyphs) if (font.glyphs.hasOwnProperty(glyph)) {
2715 var path = font.glyphs[glyph];
2716 fontcopy.glyphs[glyph] = {
2719 d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
2720 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
2724 for (var k in path.k) if (path.hasOwnProperty(k)) {
2725 fontcopy.glyphs[glyph].k[k] = path.k[k];
2732 paper.getFont = function (family, weight, style, stretch) {
2733 stretch = stretch || "normal";
2734 style = style || "normal";
2735 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
2736 var font = R.fonts[family];
2738 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, "") + "(\\s|$)", "i");
2739 for (var fontName in R.fonts) if (R.fonts.hasOwnProperty(fontName)) {
2740 if (name.test(fontName)) {
2741 font = R.fonts[fontName];
2748 for (var i = 0, ii = font.length; i < ii; i++) {
2750 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
2757 paper.print = function (x, y, string, font, size) {
2758 var out = this.set(),
2759 letters = (string + "").split(""),
2763 R.is(font, "string") && (font = this.getFont(font));
2765 scale = (size || 16) / font.face["units-per-em"];
2766 for (var i = 0, ii = letters.length; i < ii; i++) {
2767 var prev = i && font.glyphs[letters[i - 1]] || {},
2768 curr = font.glyphs[letters[i]];
2769 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
2770 curr && curr.d && out.push(this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
2772 out.scale(scale, scale, 0, y).translate(x, (size || 16) / 2);
2777 R.format = function (token) {
2778 var args = R.is(arguments[1], "array") ? [0].concat(arguments[1]) : arguments;
2779 token && R.is(token, "string") && args.length - 1 && (token = token.replace(/\{(\d+)\}/g, function (str, i) {
2780 return args[++i] == null ? "" : args[i];
2784 R.ninja = function () {
2785 var r = window.Raphael, u;
2786 if (oldRaphael.was) {
2787 window.Raphael = oldRaphael.is;
2790 delete window.Raphael;
2797 R.el = Element.prototype;