2 * Raphael 0.8.6 - JavaScript Vector Library
4 * Copyright (c) 2008 - 2009 Dmitry Baranovskiy (http://raphaeljs.com)
5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
9 window.Raphael = (function () {
10 var separator = /[, ]+/,
14 was: "Raphael" in window,
18 return create.apply(R, arguments);
21 availableAttrs = {cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0},
22 availableAnimAttrs = {cx: "number", cy: "number", fill: "colour", "fill-opacity": "number", "font-size": "number", height: "number", opacity: "number", path: "path", r: "number", rotation: "csv", rx: "number", ry: "number", scale: "csv", stroke: "colour", "stroke-opacity": "number", "stroke-width": "number", translation: "csv", width: "number", x: "number", y: "number"},
23 events = ["click", "dblclick", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup"];
25 R.type = (window.SVGAngle || document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
26 R.svg = !(R.vml = R.type == "VML");
29 R.isArray = function (arr) {
30 return Object.prototype.toString.call(arr) == "[object Array]";
32 R.setWindow = function (newwin) {
37 R.hsb2rgb = function (hue, saturation, brightness) {
38 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
46 if (brightness == 0) {
47 return {r: 0, g: 0, b: 0, hex: "#000"};
49 if (hue > 1 || saturation > 1 || brightness > 1) {
54 var i = Math.floor(hue * 6),
56 p = brightness * (1 - saturation),
57 q = brightness * (1 - (saturation * f)),
58 t = brightness * (1 - (saturation * (1 - f)));
59 red = [brightness, q, p, p, t, brightness, brightness][i];
60 green = [t, brightness, brightness, q, p, p, t][i];
61 blue = [p, p, t, brightness, brightness, q, p][i];
65 var rgb = {r: red, g: green, b: blue},
66 r = Math.round(red).toString(16),
67 g = Math.round(green).toString(16),
68 b = Math.round(blue).toString(16);
78 rgb.hex = "#" + r + g + b;
81 R.rgb2hsb = function (red, green, blue) {
82 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
87 if (typeof red == "string") {
88 var clr = R.getRGB(red);
93 if (red > 1 || green > 1 || blue > 1) {
98 var max = Math.max(red, green, blue),
99 min = Math.min(red, green, blue),
104 return {h: 0, s: 0, b: max};
106 var delta = (max - min);
107 saturation = delta / max;
109 hue = (green - blue) / delta;
110 } else if (green == max) {
111 hue = 2 + ((blue - red) / delta);
113 hue = 4 + ((red - green) / delta);
123 return {h: hue, s: saturation, b: brightness};
125 var getRGBcache = {},
127 R.getRGB = function (colour) {
128 if (colour in getRGBcache) {
129 return getRGBcache[colour];
131 var htmlcolors = {aliceblue: "#f0f8ff", amethyst: "#96c", antiquewhite: "#faebd7", aqua: "#0ff", aquamarine: "#7fffd4", azure: "#f0ffff", beige: "#f5f5dc", bisque: "#ffe4c4", black: "#000", blanchedalmond: "#ffebcd", blue: "#00f", blueviolet: "#8a2be2", brown: "#a52a2a", burlywood: "#deb887", cadetblue: "#5f9ea0", chartreuse: "#7fff00", chocolate: "#d2691e", coral: "#ff7f50", cornflowerblue: "#6495ed", cornsilk: "#fff8dc", crimson: "#dc143c", cyan: "#0ff", darkblue: "#00008b", darkcyan: "#008b8b", darkgoldenrod: "#b8860b", darkgray: "#a9a9a9", darkgreen: "#006400", darkkhaki: "#bdb76b", darkmagenta: "#8b008b", darkolivegreen: "#556b2f", darkorange: "#ff8c00", darkorchid: "#9932cc", darkred: "#8b0000", darksalmon: "#e9967a", darkseagreen: "#8fbc8f", darkslateblue: "#483d8b", darkslategray: "#2f4f4f", darkturquoise: "#00ced1", darkviolet: "#9400d3", deeppink: "#ff1493", deepskyblue: "#00bfff", dimgray: "#696969", dodgerblue: "#1e90ff", firebrick: "#b22222", floralwhite: "#fffaf0", forestgreen: "#228b22", fuchsia: "#f0f", gainsboro: "#dcdcdc", ghostwhite: "#f8f8ff", gold: "#ffd700", goldenrod: "#daa520", gray: "#808080", green: "#008000", greenyellow: "#adff2f", honeydew: "#f0fff0", hotpink: "#ff69b4", indianred: "#cd5c5c", indigo: "#4b0082", ivory: "#fffff0", khaki: "#f0e68c", lavender: "#e6e6fa", lavenderblush: "#fff0f5", lawngreen: "#7cfc00", lemonchiffon: "#fffacd", lightblue: "#add8e6", lightcoral: "#f08080", lightcyan: "#e0ffff", lightgoldenrodyellow: "#fafad2", lightgreen: "#90ee90", lightgrey: "#d3d3d3", lightpink: "#ffb6c1", lightsalmon: "#ffa07a", lightsalmon: "#ffa07a", lightseagreen: "#20b2aa", lightskyblue: "#87cefa", lightslategray: "#789", lightsteelblue: "#b0c4de", lightyellow: "#ffffe0", lime: "#0f0", limegreen: "#32cd32", linen: "#faf0e6", magenta: "#f0f", maroon: "#800000", mediumaquamarine: "#66cdaa", mediumblue: "#0000cd", mediumorchid: "#ba55d3", mediumpurple: "#9370db", mediumseagreen: "#3cb371", mediumslateblue: "#7b68ee", mediumslateblue: "#7b68ee", mediumspringgreen: "#00fa9a", mediumturquoise: "#48d1cc", mediumvioletred: "#c71585", midnightblue: "#191970", mintcream: "#f5fffa", mistyrose: "#ffe4e1", moccasin: "#ffe4b5", navajowhite: "#ffdead", navy: "#000080", oldlace: "#fdf5e6", olive: "#808000", olivedrab: "#6b8e23", orange: "#ffa500", orangered: "#ff4500", orchid: "#da70d6", palegoldenrod: "#eee8aa", palegreen: "#98fb98", paleturquoise: "#afeeee", palevioletred: "#db7093", papayawhip: "#ffefd5", peachpuff: "#ffdab9", peru: "#cd853f", pink: "#ffc0cb", plum: "#dda0dd", powderblue: "#b0e0e6", purple: "#800080", red: "#f00", rosybrown: "#bc8f8f", royalblue: "#4169e1", saddlebrown: "#8b4513", salmon: "#fa8072", sandybrown: "#f4a460", seagreen: "#2e8b57", seashell: "#fff5ee", sienna: "#a0522d", silver: "#c0c0c0", skyblue: "#87ceeb", slateblue: "#6a5acd", slategray: "#708090", snow: "#fffafa", springgreen: "#00ff7f", steelblue: "#4682b4", tan: "#d2b48c", teal: "#008080", thistle: "#d8bfd8", tomato: "#ff6347", turquoise: "#40e0d0", violet: "#ee82ee", wheat: "#f5deb3", white: "#fff", whitesmoke: "#f5f5f5", yellow: "#ff0", yellowgreen: "#9acd32"},
133 if ((colour + "").toLowerCase() in htmlcolors) {
134 colour = htmlcolors[colour.toString().toLowerCase()];
137 return {r: 0, g: 0, b: 0, hex: "#000"};
139 if (colour == "none") {
140 return {r: -1, g: -1, b: -1, hex: "none"};
145 rgb = (colour + "").match(/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|rgb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hsb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i);
148 blue = parseInt(rgb[2].substring(5), 16);
149 green = parseInt(rgb[2].substring(3, 5), 16);
150 red = parseInt(rgb[2].substring(1, 3), 16);
153 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
154 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
155 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
158 rgb = rgb[4].split(/\s*,\s*/);
159 red = parseFloat(rgb[0]);
160 green = parseFloat(rgb[1]);
161 blue = parseFloat(rgb[2]);
164 rgb = rgb[5].split(/\s*,\s*/);
165 red = parseFloat(rgb[0]) * 2.55;
166 green = parseFloat(rgb[1]) * 2.55;
167 blue = parseFloat(rgb[2]) * 2.55;
170 rgb = rgb[6].split(/\s*,\s*/);
171 red = parseFloat(rgb[0]);
172 green = parseFloat(rgb[1]);
173 blue = parseFloat(rgb[2]);
174 return R.hsb2rgb(red, green, blue);
177 rgb = rgb[7].split(/\s*,\s*/);
178 red = parseFloat(rgb[0]) * 2.55;
179 green = parseFloat(rgb[1]) * 2.55;
180 blue = parseFloat(rgb[2]) * 2.55;
181 return R.hsb2rgb(red, green, blue);
183 var rgb = {r: red, g: green, b: blue},
184 r = Math.round(red).toString(16),
185 g = Math.round(green).toString(16),
186 b = Math.round(blue).toString(16);
187 (r.length == 1) && (r = "0" + r);
188 (g.length == 1) && (g = "0" + g);
189 (b.length == 1) && (b = "0" + b);
190 rgb.hex = "#" + r + g + b;
193 res = {r: -1, g: -1, b: -1, hex: "none"};
195 if (getRGBcount.length > 20) {
196 delete getRGBcache[getRGBcount.unshift()];
198 getRGBcount.push(colour);
199 getRGBcache[colour] = res;
202 R.getColor = function (value) {
203 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
204 rgb = this.hsb2rgb(start.h, start.s, start.b);
210 this.getColor.start = {h: 0, s: 1, b: start.b};
215 R.getColor.reset = function () {
221 R.parsePathString = function (pathString) {
222 if (pathString in pathcache) {
223 return pathcache[pathString];
225 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
227 toString = function () {
229 for (var i = 0, ii = this.length; i < ii; i++) {
230 res += this[i][0] + this[i].join(",").substring(2);
234 if (pathString.toString.toString() == toString.toString()) {
238 pathString.replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, function (a, b, c) {
240 name = b.toLowerCase();
241 c.replace(/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig, function (a, b) {
242 b && params.push(+b);
244 while (params.length >= paramCounts[name]) {
245 data.push([b].concat(params.splice(0, paramCounts[name])));
246 if (!paramCounts[name]) {
251 data.toString = toString;
253 if (pathcount.length > 20) {
254 delete pathcache[pathcount.unshift()];
256 pathcount.push(pathString);
257 pathcache[pathString] = data;
260 var pathDimensions = function (path) {
261 var pathArray = path;
262 if (typeof path == "string") {
263 pathArray = R.parsePathString(path);
265 pathArray = pathToAbsolute(pathArray);
269 for (var i = 0, ii = pathArray.length; i < ii; i++) {
270 var pa = pathArray[i];
275 x.push(pa[pa.length - 2]);
276 y.push(pa[pa.length - 1]);
279 for (var j = 1, jj = pa.length; j < jj; j++) {
280 (j % 2 ? x : y).push(pa[j]);
284 var minx = Math.min.apply(Math, x),
285 miny = Math.min.apply(Math, y);
299 width: Math.max.apply(Math, x) - minx,
300 height: Math.max.apply(Math, y) - miny,
306 addRoundedCorner = function (r, dir) {
308 rollback = this.isAbsolute,
312 rollback = function () {
316 rollback = function () {};
322 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
325 o.curveTo(-R, 0, -r, r - R, -r, r);
332 o.curveTo(R, 0, r, -(r - R), r, -r);
335 o.curveTo(R, 0, r, r - R, r, r);
342 o.curveTo(0, -R, -(R - r), -r, r, -r);
345 o.curveTo(0, -R, R - r, -r, -r, -r);
352 o.curveTo(0, R, -(R - r), r, r, r);
355 o.curveTo(0, R, R - r, r, -r, r);
360 actions[dir.charAt(0)]()[dir.charAt(1)]();
364 pathToRelative = function (pathArray) {
369 if (typeof pathArray == "string") {
370 pathArray = R.parsePathString(pathArray);
372 if (pathArray[0][0] == "M") {
376 res.push(["M", x, y]);
378 for (var i = start, ii = pathArray.length; i < ii; i++) {
381 if (pa[0] != pa[0].toLowerCase()) {
382 r[0] = pa[0].toLowerCase();
390 r[6] = +(pa[6] - x).toFixed(3);
391 r[7] = +(pa[7] - y).toFixed(3);
394 r[1] = +(pa[1] - y).toFixed(3);
397 for (var j = 1, jj = pa.length; j < jj; j++) {
398 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
403 for (var k = 0, kk = pa.length; k < kk; k++) {
407 var len = res[i].length;
412 x += +res[i][len - 1];
415 y += +res[i][len - 1];
418 x += +res[i][len - 2];
419 y += +res[i][len - 1];
422 res.toString = pathArray.toString;
425 pathToAbsolute = function (pathArray) {
427 if (typeof pathArray == "string") {
428 pathArray = R.parsePathString(pathArray);
433 if (pathArray[0][0] == "M") {
434 x = +pathArray[0][1];
435 y = +pathArray[0][2];
437 res[0] = ["M", x, y];
439 for (var i = start, ii = pathArray.length; i < ii; i++) {
442 if (pa[0] != (pa[0] + "").toUpperCase()) {
443 r[0] = (pa[0] + "").toUpperCase();
451 r[6] = +(pa[6] + x).toFixed(3);
452 r[7] = +(pa[7] + y).toFixed(3);
461 for (var j = 1, jj = pa.length; j < jj; j++) {
462 r[j] = +pa[j] + ((j % 2) ? x : y);
467 for (var k = 0, kk = pa.length; k < kk; k++) {
481 x = res[i][res[i].length - 2];
482 y = res[i][res[i].length - 1];
485 res.toString = pathArray.toString;
488 pecache = {}, pecount = [],
489 pathEqualiser = function (path1, path2) {
490 if ((path1 + path2) in pecache) {
491 return pecache[path1 + path2];
493 var data = [pathToAbsolute(R.parsePathString(path1)), pathToAbsolute(R.parsePathString(path2))],
494 attrs = [{x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0}, {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0}],
495 processPath = function (path, d) {
505 var nx = d.x + (d.x - (d.bx || d.x)),
506 ny = d.y + (d.y - (d.by || d.y));
507 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
510 var nx = d.x + (d.x - (d.bx || d.x)),
511 ny = d.y + (d.y - (d.by || d.y));
512 path = ["Q", nx, ny, path[1], path[2]];
515 path = ["L", path[1], d.y];
518 path = ["L", d.x, path[1]];
521 path = ["L", d.X, d.Y];
526 edgeCases = function (a, b, i) {
527 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
528 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
529 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
530 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
531 attrs[a].x = data[a][i][data[a][i].length - 2];
532 attrs[a].y = data[a][i][data[a][i].length - 1];
534 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
535 data[a][i] = ["C", attrs[a].x, attrs[a].y, data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
536 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
537 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
538 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
539 var x = data[b][i][data[b][i].length - 2],
540 y = data[b][i][data[b][i].length - 1];
541 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
542 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
544 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
545 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
546 attrs[b].x = data[b][i][data[b][i].length - 2];
547 attrs[b].y = data[b][i][data[b][i].length - 1];
549 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
550 var x = data[b][i][data[b][i].length - 2],
551 y = data[b][i][data[b][i].length - 1];
552 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
553 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
555 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
556 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
557 attrs[b].x = data[b][i][data[b][i].length - 2];
558 attrs[b].y = data[b][i][data[b][i].length - 1];
560 } else if (data[a][i][0] == "U") {
561 data[a][i][0] = data[b][i][0];
562 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
563 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
568 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
569 data[0][i] = processPath(data[0][i], attrs[0]);
570 data[1][i] = processPath(data[1][i], attrs[1]);
571 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
574 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
575 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
576 attrs[0].x = data[0][i][data[0][i].length - 2];
577 attrs[0].y = data[0][i][data[0][i].length - 1];
578 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
579 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
580 attrs[1].x = data[1][i][data[1][i].length - 2];
581 attrs[1].y = data[1][i][data[1][i].length - 1];
583 if (pecount.length > 20) {
584 delete pecache[pecount.unshift()];
586 pecount.push(path1 + path2);
587 pecache[path1 + path2] = data;
590 toGradient = function (gradient) {
591 if (typeof gradient == "string") {
592 gradient = gradient.split(/\s*\-\s*/);
593 var angle = gradient.shift();
594 if (angle.toLowerCase() == "v") {
596 } else if (angle.toLowerCase() == "h") {
599 angle = parseFloat(angle);
602 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)]},
603 max = 1 / (Math.max(Math.abs(grobj.vector[2]), Math.abs(grobj.vector[3])) || 1);
604 grobj.vector[2] *= max;
605 grobj.vector[3] *= max;
606 if (grobj.vector[2] < 0) {
607 grobj.vector[0] = -grobj.vector[2];
610 if (grobj.vector[3] < 0) {
611 grobj.vector[1] = -grobj.vector[3];
614 grobj.vector[0] = grobj.vector[0].toFixed(3);
615 grobj.vector[1] = grobj.vector[1].toFixed(3);
616 grobj.vector[2] = grobj.vector[2].toFixed(3);
617 grobj.vector[3] = grobj.vector[3].toFixed(3);
618 for (var i = 0, ii = gradient.length; i < ii; i++) {
620 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
621 dot.color = R.getRGB(par[1]).hex;
622 par[2] && (dot.offset = par[2] + "%");
623 grobj.dots.push(dot);
625 for (var i = 1, ii = grobj.dots.length - 1; i < ii; i++) {
626 if (!grobj.dots[i].offset) {
627 var start = parseFloat(grobj.dots[i - 1].offset || 0),
629 for (var j = i + 1; j < ii; j++) {
630 if (grobj.dots[j].offset) {
631 end = grobj.dots[j].offset;
639 end = parseFloat(end);
640 var d = (end - start) / (j - i + 1);
643 grobj.dots[i].offset = start + "%";
652 getContainer = function () {
658 if (typeof arguments[0] == "string" || typeof arguments[0] == "object") {
659 if (typeof arguments[0] == "string") {
660 container = doc.getElementById(arguments[0]);
662 container = arguments[0];
664 if (container.tagName) {
665 if (arguments[1] == null) {
667 container: container,
668 width: container.style.pixelWidth || container.offsetWidth,
669 height: container.style.pixelHeight || container.offsetHeight
672 return {container: container, width: arguments[1], height: arguments[2]};
675 } else if (typeof arguments[0] == "number" && arguments.length > 3) {
676 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
679 plugins = function (con, add) {
681 for (var prop in add) if (add.hasOwnProperty(prop) && !(prop in con)) {
682 switch (typeof add[prop]) {
685 con[prop] = con === that ? f : function () { return f.apply(that, arguments); };
689 con[prop] = con[prop] || {};
690 plugins.call(this, con[prop], add[prop]);
693 con[prop] = add[prop];
701 R.toString = function () {
702 return "Your browser supports SVG.\nYou are running Rapha\u00ebl " + this.version;
705 absolutely: function () {
706 this.isAbsolute = true;
709 relatively: function () {
710 this.isAbsolute = false;
713 moveTo: function (x, y) {
714 var d = this.isAbsolute ? "M" : "m";
715 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
716 var oldD = this[0].getAttribute("d") || "";
717 (oldD == "M0,0") && (oldD = "");
718 this[0].setAttribute("d", oldD + d);
719 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
720 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
721 this.attrs.path = oldD + d;
724 lineTo: function (x, y) {
725 this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(x);
726 this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(y);
727 var d = this.isAbsolute ? "L" : "l";
728 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
729 var oldD = this.node.getAttribute("d") || "";
730 this.node.setAttribute("d", oldD + d);
731 this.attrs.path = oldD + d;
734 arcTo: function (rx, ry, large_arc_flag, sweep_flag, x, y) {
735 var d = this.isAbsolute ? "A" : "a";
736 d += [parseFloat(rx).toFixed(3), parseFloat(ry).toFixed(3), 0, large_arc_flag, sweep_flag, parseFloat(x).toFixed(3), parseFloat(y).toFixed(3)].join(" ");
737 var oldD = this[0].getAttribute("d") || "";
738 this.node.setAttribute("d", oldD + d);
739 this.last.x = parseFloat(x);
740 this.last.y = parseFloat(y);
741 this.attrs.path = oldD + d;
744 cplineTo: function (x1, y1, w1) {
746 return this.lineTo(x1, y1);
752 d = this.isAbsolute ? "C" : "c",
753 attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
754 for (var i = 0, ii = attr.length; i < ii; i++) {
757 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
758 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
759 this.last.bx = attr[2];
760 this.last.by = attr[3];
761 var oldD = this.node.getAttribute("d") || "";
762 this.node.setAttribute("d", oldD + d);
763 this.attrs.path = oldD + d;
767 curveTo: function () {
769 d = [0, 1, 2, 3, "s", 5, "c"][arguments.length];
770 if (this.isAbsolute) {
773 for (var i = 0, ii = arguments.length; i < ii; i++) {
774 d += parseFloat(arguments[i]).toFixed(3) + " ";
776 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
777 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
778 this.last.bx = parseFloat(arguments[arguments.length - 4]);
779 this.last.by = parseFloat(arguments[arguments.length - 3]);
780 var oldD = this.node.getAttribute("d") || "";
781 this.node.setAttribute("d", oldD + d);
782 this.attrs.path = oldD + d;
785 qcurveTo: function () {
787 d = [0, 1, "t", 3, "q"][arguments.length];
788 if (this.isAbsolute) {
791 for (var i = 0, ii = arguments.length; i < ii; i++) {
792 d += parseFloat(arguments[i]).toFixed(3) + " ";
794 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
795 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
796 if (arguments.length != 2) {
797 this.last.qx = parseFloat(arguments[arguments.length - 4]);
798 this.last.qy = parseFloat(arguments[arguments.length - 3]);
800 var oldD = this.node.getAttribute("d") || "";
801 this.node.setAttribute("d", oldD + d);
802 this.attrs.path = oldD + d;
805 addRoundedCorner: addRoundedCorner,
806 andClose: function () {
807 var oldD = this[0].getAttribute("d") || "";
808 this[0].setAttribute("d", oldD + "Z ");
809 this.attrs.path = oldD + "Z ";
813 var thePath = function (params, pathString, SVG) {
814 params = params || {};
815 var el = doc.createElementNS(SVG.svgns, "path");
817 SVG.canvas.appendChild(el);
819 var p = new Element(el, SVG);
821 for (var method in pathMethods) {
822 p[method] = pathMethods[method];
825 p.last = {x: 0, y: 0, bx: 0, by: 0};
827 p.attrs.path = "" + pathString;
829 paper.pathfinder(p, p.attrs.path);
832 !params.gradient && (params.fill = params.fill || "none");
833 params.stroke = params.stroke || "#000";
835 params = {fill: "none", stroke: "#000"};
837 setFillAndStroke(p, params);
840 var addGradientFill = function (o, gradient, SVG) {
841 gradient = toGradient(gradient);
842 var el = doc.createElementNS(SVG.svgns, (gradient.type || "linear") + "Gradient");
843 el.id = "raphael-gradient-" + R.idGenerator++;
844 if (gradient.vector && gradient.vector.length) {
845 el.setAttribute("x1", gradient.vector[0]);
846 el.setAttribute("y1", gradient.vector[1]);
847 el.setAttribute("x2", gradient.vector[2]);
848 el.setAttribute("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 = doc.createElementNS(SVG.svgns, "stop");
854 if (gradient.dots[i].offset) {
857 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
858 stop.setAttribute("stop-color", R.getRGB(gradient.dots[i].color).hex || "#fff");
859 // ignoring opacity for internal points, because VML doesn't support it
860 el.appendChild(stop);
862 if (isopacity && typeof gradient.dots[ii - 1].opacity != "undefined") {
863 stop.setAttribute("stop-opacity", gradient.dots[ii - 1].opacity);
865 o.setAttribute("fill", "url(#" + el.id + ")");
868 o.style.fillOpacity = 1;
869 o.setAttribute("opacity", 1);
870 o.setAttribute("fill-opacity", 1);
872 var updatePosition = function (o) {
874 var bbox = o.getBBox();
875 o.pattern.setAttribute("patternTransform", "translate(".concat(bbox.x, ",", bbox.y, ")"));
878 var setFillAndStroke = function (o, params) {
885 "-..": [3, 1, 1, 1, 1, 1],
891 "--..": [8, 3, 1, 3, 1, 3]
895 rot = attrs.rotation,
896 addDashes = function (o, value) {
897 value = dasharray[value.toString().toLowerCase()];
899 var width = o.attrs["stroke-width"] || "1",
900 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
902 for (var i = 0, ii = value.length; i < ii; i++) {
903 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
905 value = dashes.join(",");
906 node.setAttribute("stroke-dasharray", value);
910 for (var att in params) {
911 if (!(att in availableAttrs)) {
914 var value = params[att];
921 var pn = node.parentNode;
922 if (pn.tagName.toLowerCase() != "a") {
923 var hl = doc.createElementNS(o.paper.svgns, "a");
924 pn.insertBefore(hl, node);
925 hl.appendChild(node);
928 pn.setAttributeNS(o.paper.xlink, att, value);
931 if (o.type == "path") {
932 node.setAttribute("d", "M0,0");
933 paper.pathfinder(o, value);
936 node.setAttribute(att, value);
945 value = -attrs.x - (attrs.width || 0);
949 node.setAttribute(att, value);
953 node.setAttribute(att, value);
962 value = -attrs.y - (attrs.height || 0);
966 node.setAttribute(att, value);
970 if (o.type == "rect") {
971 node.setAttribute("rx", value);
972 node.setAttribute("ry", value);
974 node.setAttribute(att, value);
978 if (o.type == "image") {
979 node.setAttributeNS(o.paper.xlink, "href", value);
983 node.style.strokeWidth = value;
984 // Need following line for Firefox
985 node.setAttribute(att, value);
986 if (attrs["stroke-dasharray"]) {
987 addDashes(o, attrs["stroke-dasharray"]);
990 case "stroke-dasharray":
994 o.rotate(value, true);
997 var xy = (value + "").split(separator);
998 o.translate((+xy[0] + 1 || 2) - 1, (+xy[1] + 1 || 2) - 1);
1001 var xy = (value + "").split(separator);
1002 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1005 var isURL = (value + "").match(/^url\(([^\)]+)\)$/i);
1007 var el = doc.createElementNS(o.paper.svgns, "pattern"),
1008 ig = doc.createElementNS(o.paper.svgns, "image");
1009 el.id = "raphael-pattern-" + R.idGenerator++;
1010 el.setAttribute("x", 0);
1011 el.setAttribute("y", 0);
1012 el.setAttribute("patternUnits", "userSpaceOnUse");
1013 ig.setAttribute("x", 0);
1014 ig.setAttribute("y", 0);
1015 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1018 var img = doc.createElement("img");
1019 img.style.position = "absolute";
1020 img.style.top = "-9999em";
1021 img.style.left = "-9999em";
1022 img.onload = function () {
1023 el.setAttribute("width", this.offsetWidth);
1024 el.setAttribute("height", this.offsetHeight);
1025 ig.setAttribute("width", this.offsetWidth);
1026 ig.setAttribute("height", this.offsetHeight);
1027 doc.body.removeChild(this);
1030 doc.body.appendChild(img);
1032 o.paper.defs.appendChild(el);
1033 node.style.fill = "url(#" + el.id + ")";
1034 node.setAttribute("fill", "url(#" + el.id + ")");
1039 delete params.gradient;
1040 delete attrs.gradient;
1041 if (typeof attrs.opacity != "undefined" && typeof params.opacity == "undefined" ) {
1042 node.style.opacity = attrs.opacity;
1043 // Need following line for Firefox
1044 node.setAttribute("opacity", attrs.opacity);
1046 if (typeof attrs["fill-opacity"] != "undefined" && typeof params["fill-opacity"] == "undefined" ) {
1047 node.style.fillOpacity = o.attrs["fill-opacity"];
1048 // Need following line for Firefox
1049 node.setAttribute("fill-opacity", attrs["fill-opacity"]);
1052 node.style[att] = R.getRGB(value).hex;
1053 // Need following line for Firefox
1054 node.setAttribute(att, R.getRGB(value).hex);
1057 addGradientFill(node, value, o.paper);
1060 case "fill-opacity":
1061 if (attrs.gradient) {
1062 var gradient = doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
1064 var stops = gradient.getElementsByTagName("stop");
1065 stops[stops.length - 1].setAttribute("stop-opacity", value);
1070 var cssrule = att.replace(/(\-.)/g, function (w) {
1071 return w.substring(1).toUpperCase();
1073 node.style[cssrule] = value;
1074 // Need following line for Firefox
1075 node.setAttribute(att, value);
1080 tuneText(o, params);
1081 o.rotate(attrs.rotation, true);
1084 var tuneText = function (el, params) {
1085 if (el.type != "text" || !("text" in params || "font" in params || "font-size" in params || "x" in params || "y" in params)) {
1090 fontSize = node.firstChild ? parseInt(doc.defaultView.getComputedStyle(node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
1092 if ("text" in params) {
1093 while (node.firstChild) {
1094 node.removeChild(node.firstChild);
1096 var texts = (params.text + "").split("\n");
1097 for (var i = 0, ii = texts.length; i < ii; i++) {
1098 var tspan = doc.createElementNS(el.paper.svgns, "tspan");
1099 i && tspan.setAttribute("dy", fontSize * leading);
1100 i && tspan.setAttribute("x", a.x);
1101 tspan.appendChild(doc.createTextNode(texts[i]));
1102 node.appendChild(tspan);
1105 var texts = node.getElementsByTagName("tspan");
1106 for (var i = 0, ii = texts.length; i < ii; i++) {
1107 i && texts[i].setAttribute("dy", fontSize * leading);
1108 i && texts[i].setAttribute("x", a.x);
1111 node.setAttribute("y", a.y);
1112 var bb = el.getBBox(),
1113 dif = a.y - (bb.y + bb.height / 2);
1114 dif && node.setAttribute("y", a.y + dif);
1116 var Element = function (node, svg) {
1122 this.attrs = this.attrs || {};
1123 this.transformations = []; // rotate, translate, scale
1127 rt: {deg: 0, x: 0, y: 0},
1132 Element.prototype.rotate = function (deg, cx, cy) {
1134 return this._.rt.deg;
1136 var bbox = this.getBBox();
1137 deg = deg.toString().split(separator);
1138 if (deg.length - 1) {
1139 cx = parseFloat(deg[1]);
1140 cy = parseFloat(deg[2]);
1142 deg = parseFloat(deg[0]);
1144 this._.rt.deg = deg;
1146 this._.rt.deg += deg;
1151 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1152 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1153 if (this._.rt.deg) {
1154 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
1156 this.transformations[0] = "";
1158 this.node.setAttribute("transform", this.transformations.join(" "));
1161 Element.prototype.hide = function () {
1162 this.node.style.display = "none";
1165 Element.prototype.show = function () {
1166 this.node.style.display = "block";
1169 Element.prototype.remove = function () {
1170 this.node.parentNode.removeChild(this.node);
1172 Element.prototype.getBBox = function () {
1173 if (this.node.style.display == "none") {
1179 bbox = this.node.getBBox();
1181 // Firefox 3.0.x plays badly here
1185 if (this.type == "text") {
1186 bbox = {x: bbox.x, y: Infinity, width: bbox.width, height: 0};
1187 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1188 var bb = this.node.getExtentOfChar(i);
1189 (bb.y < bbox.y) && (bbox.y = bb.y);
1190 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1193 hide && this.hide();
1196 Element.prototype.attr = function () {
1197 if (arguments.length == 1 && typeof arguments[0] == "string") {
1198 if (arguments[0] == "translation") {
1199 return this.translate();
1201 return this.attrs[arguments[0]];
1203 if (arguments.length == 1 && R.isArray(arguments[0])) {
1205 for (var j in arguments[0]) {
1206 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1210 if (arguments.length == 2) {
1212 params[arguments[0]] = arguments[1];
1213 setFillAndStroke(this, params);
1214 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1215 setFillAndStroke(this, arguments[0]);
1219 Element.prototype.toFront = function () {
1220 this.node.parentNode.appendChild(this.node);
1223 Element.prototype.toBack = function () {
1224 if (this.node.parentNode.firstChild != this.node) {
1225 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1229 Element.prototype.insertAfter = function (element) {
1230 if (element.node.nextSibling) {
1231 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1233 element.node.parentNode.appendChild(this.node);
1237 Element.prototype.insertBefore = function (element) {
1238 var node = element.node;
1239 node.parentNode.insertBefore(this.node, node);
1242 var theCircle = function (svg, x, y, r) {
1243 var el = doc.createElementNS(svg.svgns, "circle");
1244 el.setAttribute("cx", x);
1245 el.setAttribute("cy", y);
1246 el.setAttribute("r", r);
1247 el.setAttribute("fill", "none");
1248 el.setAttribute("stroke", "#000");
1250 svg.canvas.appendChild(el);
1252 var res = new Element(el, svg);
1253 res.attrs = res.attrs || {};
1257 res.attrs.stroke = "#000";
1258 res.type = "circle";
1261 var theRect = function (svg, x, y, w, h, r) {
1262 var el = doc.createElementNS(svg.svgns, "rect");
1263 el.setAttribute("x", x);
1264 el.setAttribute("y", y);
1265 el.setAttribute("width", w);
1266 el.setAttribute("height", h);
1268 el.setAttribute("rx", r);
1269 el.setAttribute("ry", r);
1271 el.setAttribute("fill", "none");
1272 el.setAttribute("stroke", "#000");
1274 svg.canvas.appendChild(el);
1276 var res = new Element(el, svg);
1277 res.attrs = res.attrs || {};
1280 res.attrs.width = w;
1281 res.attrs.height = h;
1282 res.attrs.stroke = "#000";
1284 res.attrs.rx = res.attrs.ry = r;
1289 var theEllipse = function (svg, x, y, rx, ry) {
1290 var el = doc.createElementNS(svg.svgns, "ellipse");
1291 el.setAttribute("cx", x);
1292 el.setAttribute("cy", y);
1293 el.setAttribute("rx", rx);
1294 el.setAttribute("ry", ry);
1295 el.setAttribute("fill", "none");
1296 el.setAttribute("stroke", "#000");
1298 svg.canvas.appendChild(el);
1300 var res = new Element(el, svg);
1301 res.attrs = res.attrs || {};
1306 res.attrs.stroke = "#000";
1307 res.type = "ellipse";
1310 var theImage = function (svg, src, x, y, w, h) {
1311 var el = doc.createElementNS(svg.svgns, "image");
1312 el.setAttribute("x", x);
1313 el.setAttribute("y", y);
1314 el.setAttribute("width", w);
1315 el.setAttribute("height", h);
1316 el.setAttribute("preserveAspectRatio", "none");
1317 el.setAttributeNS(svg.xlink, "href", src);
1319 svg.canvas.appendChild(el);
1321 var res = new Element(el, svg);
1322 res.attrs = res.attrs || {};
1325 res.attrs.width = w;
1326 res.attrs.height = h;
1330 var theText = function (svg, x, y, text) {
1331 var el = doc.createElementNS(svg.svgns, "text");
1332 el.setAttribute("x", x);
1333 el.setAttribute("y", y);
1334 el.setAttribute("text-anchor", "middle");
1336 svg.canvas.appendChild(el);
1338 var res = new Element(el, svg);
1339 res.attrs = res.attrs || {};
1343 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000", text: text});
1346 var setSize = function (width, height) {
1347 this.width = width || this.width;
1348 this.height = height || this.height;
1349 this.canvas.setAttribute("width", this.width);
1350 this.canvas.setAttribute("height", this.height);
1353 var create = function () {
1354 var con = getContainer.apply(null, arguments),
1355 container = con.container,
1359 height = con.height;
1361 throw new Error("SVG container not found.");
1363 paper.canvas = doc.createElementNS(paper.svgns, "svg");
1364 paper.canvas.setAttribute("width", width || 512);
1365 paper.width = width || 512;
1366 paper.canvas.setAttribute("height", height || 342);
1367 paper.height = height || 342;
1368 if (container == 1) {
1369 doc.body.appendChild(paper.canvas);
1370 paper.canvas.style.position = "absolute";
1371 paper.canvas.style.left = x + "px";
1372 paper.canvas.style.top = y + "px";
1374 if (container.firstChild) {
1375 container.insertBefore(paper.canvas, container.firstChild);
1377 container.appendChild(paper.canvas);
1381 canvas: paper.canvas,
1382 clear: function () {
1383 while (this.canvas.firstChild) {
1384 this.canvas.removeChild(this.canvas.firstChild);
1386 this.defs = doc.createElementNS(paper.svgns, "defs");
1387 this.canvas.appendChild(this.defs);
1390 for (var prop in paper) {
1391 if (prop != "create") {
1392 container[prop] = paper[prop];
1395 plugins.call(container, container, R.fn);
1397 container.raphael = R;
1400 paper.remove = function () {
1401 this.canvas.parentNode.removeChild(this.canvas);
1403 paper.svgns = "http://www.w3.org/2000/svg";
1404 paper.xlink = "http://www.w3.org/1999/xlink";
1405 paper.safari = function () {
1406 if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) {
1407 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1408 setTimeout(function () {rect.remove();});
1415 R.toString = function () {
1416 return "Your browser doesn\u2019t support SVG. Assuming it is Internet Explorer and falling down to VML.\nYou are running Rapha\u00ebl " + this.version;
1419 absolutely: function () {
1420 this.isAbsolute = true;
1423 relatively: function () {
1424 this.isAbsolute = false;
1427 moveTo: function (x, y) {
1428 var X = Math.round(parseFloat(x)) - 1,
1429 Y = Math.round(parseFloat(y)) - 1,
1430 d = this.isAbsolute ? "m" : "t";
1432 this.node.path = this.Path += d;
1433 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1434 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1435 this.last.isAbsolute = this.isAbsolute;
1436 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1439 lineTo: function (x, y) {
1440 var X = Math.round(parseFloat(x)) - 1,
1441 Y = Math.round(parseFloat(y)) - 1,
1442 d = this.isAbsolute ? "l" : "r";
1444 this.node.path = this.Path += d;
1445 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1446 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1447 this.last.isAbsolute = this.isAbsolute;
1448 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1451 arcTo: function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1452 // for more information of where this math came from visit:
1453 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1454 var x22 = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2) - 1,
1455 y22 = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2) - 1,
1456 x1 = this.last.x - 1,
1457 y1 = this.last.y - 1,
1460 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1461 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1462 cx = k * rx * y / ry + (x1 + x22) / 2,
1463 cy = k * -ry * x / rx + (y1 + y22) / 2,
1464 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1465 left = Math.round(cx - rx),
1466 top = Math.round(cy - ry);
1467 d += [left, top, Math.round(left + rx * 2), Math.round(top + ry * 2), Math.round(x1), Math.round(y1), Math.round(x22), Math.round(y22)].join(", ");
1468 this.node.path = this.Path += d;
1469 this.last.x = (this.isAbsolute ? 0 : this.last.x) + x2;
1470 this.last.y = (this.isAbsolute ? 0 : this.last.y) + y2;
1471 this.last.isAbsolute = this.isAbsolute;
1472 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1475 cplineTo: function (x1, y1, w1) {
1477 return this.lineTo(x1, y1);
1479 var x = Math.round(parseFloat(x1)) - 1,
1480 y = Math.round(parseFloat(y1)) - 1,
1481 w = Math.round(parseFloat(w1)),
1482 d = this.isAbsolute ? "c" : "v",
1483 attr = [Math.round(this.last.x) - 1 + w, Math.round(this.last.y) - 1, x - w, y, x, y],
1484 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1485 d += attr.join(" ") + " ";
1486 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1487 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1488 this.last.bx = attr[2];
1489 this.last.by = attr[3];
1490 this.node.path = this.Path += d;
1491 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1495 curveTo: function () {
1496 var d = this.isAbsolute ? "c" : "v";
1497 if (arguments.length == 6) {
1498 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1499 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1500 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4]);
1501 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5]);
1502 d += [Math.round(parseFloat(arguments[0])) - 1,
1503 Math.round(parseFloat(arguments[1])) - 1,
1504 Math.round(parseFloat(arguments[2])) - 1,
1505 Math.round(parseFloat(arguments[3])) - 1,
1506 Math.round(parseFloat(arguments[4])) - 1,
1507 Math.round(parseFloat(arguments[5])) - 1].join(" ") + " ";
1508 this.last.isAbsolute = this.isAbsolute;
1509 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1511 if (arguments.length == 4) {
1512 var bx = this.last.x * 2 - this.last.bx,
1513 by = this.last.y * 2 - this.last.by;
1514 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0]);
1515 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1]);
1516 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1517 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1518 d += [Math.round(bx) - 1, Math.round(by) - 1,
1519 Math.round(parseFloat(arguments[0])) - 1,
1520 Math.round(parseFloat(arguments[1])) - 1,
1521 Math.round(parseFloat(arguments[2])) - 1,
1522 Math.round(parseFloat(arguments[3])) - 1].join(" ") + " ";
1523 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1525 this.node.path = this.Path += d;
1528 qcurveTo: function () {
1529 var lx = Math.round(this.last.x) - 1,
1530 ly = Math.round(this.last.y) - 1,
1532 if (arguments.length == 4) {
1533 this.last.qx = (!this.isAbsolute * this.last.x) + parseFloat(arguments[0]);
1534 this.last.qy = (!this.isAbsolute * this.last.y) + parseFloat(arguments[1]);
1535 this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(arguments[2]);
1536 this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(arguments[3]);
1537 res = [this.last.qx, this.last.qy, this.last.x, this.last.y];
1538 this.last.isAbsolute = this.isAbsolute;
1539 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1541 if (arguments.length == 2) {
1542 this.last.qx = this.last.x * 2 - this.last.qx;
1543 this.last.qy = this.last.y * 2 - this.last.qy;
1544 this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(arguments[2]);
1545 this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(arguments[3]);
1546 res = [this.last.qx, this.last.qy, this.last.x, this.last.y];
1547 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1550 Math.round(2 / 3 * res[0] + 1 / 3 * lx) - 1,
1551 Math.round(2 / 3 * res[1] + 1 / 3 * ly) - 1,
1552 Math.round(2 / 3 * res[0] + 1 / 3 * res[2]) - 1,
1553 Math.round(2 / 3 * res[1] + 1 / 3 * res[3]) - 1,
1554 Math.round(res[2]) - 1,
1555 Math.round(res[3]) - 1
1557 this.node.path = this.Path += d;
1560 addRoundedCorner: addRoundedCorner,
1561 andClose: function () {
1562 this.node.path = (this.Path += "x");
1563 this.attrs.path += "z";
1567 var thePath = function (params, pathString, VML) {
1568 params = params || {};
1569 var g = createNode("group"), gl = g.style;
1570 gl.position = "absolute";
1573 gl.width = VML.width + "px";
1574 gl.height = VML.height + "px";
1575 g.coordsize = VML.coordsize;
1576 g.coordorigin = VML.coordorigin;
1577 var el = createNode("shape"), ol = el.style;
1578 ol.width = VML.width + "px";
1579 ol.height = VML.height + "px";
1581 if (params["class"]) {
1582 el.className = "rvml " + params["class"];
1584 el.coordsize = this.coordsize;
1585 el.coordorigin = this.coordorigin;
1587 var p = new Element(el, g, VML);
1588 p.isAbsolute = true;
1591 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1593 for (var method in pathMethods) {
1594 p[method] = pathMethods[method];
1600 paper.pathfinder(p, "" + pathString);
1603 params.fill = params.fill || "none";
1604 params.stroke = params.stroke || "#000";
1606 params = {fill: "none", stroke: "#000"};
1608 setFillAndStroke(p, params);
1609 if (params.gradient) {
1610 addGradientFill(p, params.gradient);
1613 VML.canvas.appendChild(g);
1616 var setFillAndStroke = function (o, params) {
1621 o.attrs = o.attrs || {};
1622 for (var par in params) {
1623 o.attrs[par] = params[par];
1625 params.href && (node.href = params.href);
1626 params.title && (node.title = params.title);
1627 params.target && (node.target = params.target);
1628 if (params.path && o.type == "path") {
1632 paper.pathfinder(o, params.path);
1634 if (params.rotation != null) {
1635 o.rotate(params.rotation, true);
1637 if (params.translation) {
1638 xy = (params.translation + "").split(separator);
1639 o.translate(xy[0], xy[1]);
1642 xy = (params.scale + "").split(separator);
1643 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1645 if (o.type == "image" && params.src) {
1646 node.src = params.src;
1648 if (o.type == "image" && params.opacity) {
1649 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1650 node.style.filter = (node.filterMatrix || "") + (node.filterOpacity || "");
1652 params.font && (s.font = params.font);
1653 params["font-family"] && (s.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, "") + '"');
1654 params["font-size"] && (s.fontSize = params["font-size"]);
1655 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1656 params["font-style"] && (s.fontStyle = params["font-style"]);
1657 if (typeof params.opacity != "undefined" || typeof params["stroke-width"] != "undefined" || typeof params.fill != "undefined" || typeof params.stroke != "undefined" || params["stroke-width"] || params["stroke-opacity"] || params["fill-opacity"] || params["stroke-dasharray"] || params["stroke-miterlimit"] || params["stroke-linejoin"] || params["stroke-linecap"]) {
1658 o = o.shape || node;
1659 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || createNode("fill");
1660 if ("fill-opacity" in params || "opacity" in params) {
1661 var opacity = ((+params["fill-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1662 opacity < 0 && (opacity = 0);
1663 opacity > 1 && (opacity = 1);
1664 fill.opacity = opacity;
1666 params.fill && (fill.on = true);
1667 if (typeof fill.on == "undefined" || params.fill == "none") {
1670 if (fill.on && params.fill) {
1671 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1673 fill.src = isURL[1];
1676 fill.color = R.getRGB(params.fill).hex;
1678 fill.type = "solid";
1681 o.appendChild(fill);
1682 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || createNode("stroke");
1683 if ((params.stroke && params.stroke != "none") || params["stroke-width"] || typeof params["stroke-opacity"] != "undefined" || params["stroke-dasharray"] || params["stroke-miterlimit"] || params["stroke-linejoin"] || params["stroke-linecap"]) {
1686 if (params.stroke == "none" || typeof stroke.on == "undefined" || params.stroke == 0) {
1689 if (stroke.on && params.stroke) {
1690 stroke.color = R.getRGB(params.stroke).hex;
1692 var opacity = ((+params["stroke-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1693 opacity < 0 && (opacity = 0);
1694 opacity > 1 && (opacity = 1);
1695 stroke.opacity = opacity;
1696 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1697 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1698 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1699 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"]) || 1) * 12 / 16);
1700 if (params["stroke-dasharray"]) {
1704 "-.": "shortdashdot",
1705 "-..": "shortdashdotdot",
1710 "--.": "longdashdot",
1711 "--..": "longdashdotdot"
1713 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1715 o.appendChild(stroke);
1717 if (res.type == "text") {
1718 var s = paper.span.style,
1720 a.font && (s.font = a.font);
1721 a["font-family"] && (s.fontFamily = a["font-family"]);
1722 a["font-size"] && (s.fontSize = a["font-size"]);
1723 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1724 a["font-style"] && (s.fontStyle = a["font-style"]);
1725 paper.span.innerText = res.node.string;
1726 res.W = a.w = paper.span.offsetWidth;
1727 res.H = a.h = paper.span.offsetHeight;
1729 res.Y = a.y + Math.round(res.H / 2);
1731 // text-anchor emulation
1732 switch (a["text-anchor"]) {
1734 res.node.style["v-text-align"] = "left";
1735 res.bbx = Math.round(res.W / 2);
1738 res.node.style["v-text-align"] = "right";
1739 res.bbx = -Math.round(res.W / 2);
1742 res.node.style["v-text-align"] = "center";
1747 var getAngle = function (a, b, c, d) {
1748 var angle = Math.round(Math.atan((parseFloat(c) - parseFloat(a)) / (parseFloat(d) - parseFloat(b))) * 57.29) || 0;
1749 if (!angle && parseFloat(a) < parseFloat(b)) {
1758 var addGradientFill = function (o, gradient) {
1759 gradient = toGradient(gradient);
1760 o.attrs = o.attrs || {};
1761 var attrs = o.attrs,
1762 fill = o.node.getElementsByTagName("fill");
1763 o.attrs.gradient = gradient;
1764 o = o.shape || o.node;
1768 fill = createNode("fill");
1770 if (gradient.dots.length) {
1772 fill.method = "none";
1773 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1774 if (typeof gradient.dots[0].color != "undefined") {
1775 fill.color = R.getRGB(gradient.dots[0].color).hex;
1777 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1778 fill.color2 = R.getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1781 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1782 if (gradient.dots[i].offset) {
1783 clrs.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
1786 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;
1788 fill.colors.value = clrs.join(",");
1789 fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
1791 fill.colors && (fill.colors.value = "0% " + fill.color);
1793 fill.opacity = fillOpacity;
1794 if (typeof gradient.angle != "undefined") {
1795 fill.angle = (-gradient.angle + 270) % 360;
1796 } else if (gradient.vector) {
1797 fill.angle = getAngle.apply(null, gradient.vector);
1799 if ((gradient.type + "").toLowerCase() == "radial") {
1800 fill.focus = "100%";
1801 fill.focusposition = "0.5 0.5";
1805 var Element = function (node, group, vml) {
1825 Element.prototype.rotate = function (deg, cx, cy) {
1827 return this._.rt.deg;
1829 deg = (deg + "").split(separator);
1830 if (deg.length - 1) {
1831 cx = parseFloat(deg[1]);
1832 cy = parseFloat(deg[2]);
1834 deg = parseFloat(deg[0]);
1836 this._.rt.deg = deg;
1838 this._.rt.deg += deg;
1845 this.setBox(this.attrs, cx, cy);
1846 this.Group.style.rotation = this._.rt.deg;
1847 // gradient fix for rotation. TODO
1848 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1849 // fill = fill[0] || {};
1850 // var b = ((360 - this._.rt.deg) - 270) % 360;
1851 // typeof fill.angle != "undefined" && (fill.angle = b);
1854 Element.prototype.setBox = function (params, cx, cy) {
1855 var gs = this.Group.style,
1856 os = (this.shape && this.shape.style) || this.node.style;
1857 params = params || {};
1858 for (var i in params) {
1859 this.attrs[i] = params[i];
1861 cx = cx || this._.rt.cx;
1862 cy = cy || this._.rt.cy;
1863 var attr = this.attrs,
1868 switch (this.type) {
1870 x = attr.cx - attr.r;
1871 y = attr.cy - attr.r;
1875 x = attr.cx - attr.rx;
1876 y = attr.cy - attr.ry;
1884 w = attr.width || 0;
1885 h = attr.height || 0;
1888 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("");
1889 x = attr.x - Math.round(this.W / 2);
1890 y = attr.y - this.H / 2;
1895 if (!this.attrs.path) {
1898 w = this.paper.width;
1899 h = this.paper.height;
1901 var dim = pathDimensions(this.attrs.path),
1911 w = this.paper.width;
1912 h = this.paper.height;
1915 cx = (cx == null) ? x + w / 2 : cx;
1916 cy = (cy == null) ? y + h / 2 : cy;
1917 var left = cx - this.paper.width / 2,
1918 top = cy - this.paper.height / 2;
1919 if (this.type == "path" || this.type == "text") {
1920 (gs.left != left + "px") && (gs.left = left + "px");
1921 (gs.top != top + "px") && (gs.top = top + "px");
1922 this.X = this.type == "text" ? x : -left;
1923 this.Y = this.type == "text" ? y : -top;
1926 (os.left != -left + "px") && (os.left = -left + "px");
1927 (os.top != -top + "px") && (os.top = -top + "px");
1929 (gs.left != left + "px") && (gs.left = left + "px");
1930 (gs.top != top + "px") && (gs.top = top + "px");
1935 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
1936 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
1937 (os.left != x - left + "px") && (os.left = x - left + "px");
1938 (os.top != y - top + "px") && (os.top = y - top + "px");
1939 (os.width != w + "px") && (os.width = w + "px");
1940 (os.height != h + "px") && (os.height = h + "px");
1941 var arcsize = (+params.r || 0) / (Math.min(w, h));
1942 if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
1943 // We should replace element with the new one
1944 var o = createNode(arcsize ? "roundrect" : "rect");
1945 o.arcsize = arcsize;
1946 this.Group.appendChild(o);
1947 this.node.parentNode.removeChild(this.node);
1949 this.arcsize = arcsize;
1950 setFillAndStroke(this, this.attrs);
1951 this.setBox(this.attrs);
1955 Element.prototype.hide = function () {
1956 this.Group.style.display = "none";
1959 Element.prototype.show = function () {
1960 this.Group.style.display = "block";
1963 Element.prototype.getBBox = function () {
1964 if (this.type == "path") {
1965 return pathDimensions(this.attr("path"));
1968 x: this.X + (this.bbx || 0),
1974 Element.prototype.remove = function () {
1975 this[0].parentNode.removeChild(this[0]);
1976 this.Group.parentNode.removeChild(this.Group);
1977 this.shape && this.shape.parentNode.removeChild(this.shape);
1979 Element.prototype.attr = function () {
1980 if (arguments.length == 1 && typeof arguments[0] == "string") {
1981 if (arguments[0] == "translation") {
1982 return this.translate();
1984 return this.attrs[arguments[0]];
1986 if (this.attrs && arguments.length == 1 && R.isArray(arguments[0])) {
1988 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1989 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1994 if (arguments.length == 2) {
1996 params[arguments[0]] = arguments[1];
1998 if (arguments.length == 1 && typeof arguments[0] == "object") {
1999 params = arguments[0];
2002 if (params.gradient) {
2003 addGradientFill(this, params.gradient);
2005 if (params.text && this.type == "text") {
2006 this.node.string = params.text;
2008 setFillAndStroke(this, params);
2009 this.setBox(this.attrs);
2013 Element.prototype.toFront = function () {
2014 this.Group.parentNode.appendChild(this.Group);
2017 Element.prototype.toBack = function () {
2018 if (this.Group.parentNode.firstChild != this.Group) {
2019 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2023 Element.prototype.insertAfter = function (element) {
2024 if (element.Group.nextSibling) {
2025 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2027 element.Group.parentNode.appendChild(this.Group);
2031 Element.prototype.insertBefore = function (element) {
2032 element.Group.parentNode.insertBefore(this.Group, element.Group);
2035 var theCircle = function (vml, x, y, r) {
2036 var g = createNode("group"),
2038 o = createNode("oval"),
2040 gl.position = "absolute";
2043 gl.width = vml.width + "px";
2044 gl.height = vml.height + "px";
2045 g.coordsize = vml.coordsize;
2046 g.coordorigin = vml.coordorigin;
2048 var res = new Element(o, g, vml);
2049 res.type = "circle";
2050 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2054 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2055 vml.canvas.appendChild(g);
2058 var theRect = function (vml, x, y, w, h, r) {
2059 var g = createNode("group"),
2061 o = createNode(r ? "roundrect" : "rect"),
2062 arcsize = (+r || 0) / (Math.min(w, h));
2063 o.arcsize = arcsize;
2064 gl.position = "absolute";
2067 gl.width = vml.width + "px";
2068 gl.height = vml.height + "px";
2069 g.coordsize = vml.coordsize;
2070 g.coordorigin = vml.coordorigin;
2072 var res = new Element(o, g, vml);
2074 setFillAndStroke(res, {stroke: "#000"});
2075 res.arcsize = arcsize;
2076 res.setBox({x: x, y: y, width: w, height: h, r: +r});
2077 vml.canvas.appendChild(g);
2080 var theEllipse = function (vml, x, y, rx, ry) {
2081 var g = createNode("group"),
2083 o = createNode("oval"),
2085 gl.position = "absolute";
2088 gl.width = vml.width + "px";
2089 gl.height = vml.height + "px";
2090 g.coordsize = vml.coordsize;
2091 g.coordorigin = vml.coordorigin;
2093 var res = new Element(o, g, vml);
2094 res.type = "ellipse";
2095 setFillAndStroke(res, {stroke: "#000"});
2100 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2101 vml.canvas.appendChild(g);
2104 var theImage = function (vml, src, x, y, w, h) {
2105 var g = createNode("group"),
2107 o = createNode("image"),
2109 gl.position = "absolute";
2112 gl.width = vml.width + "px";
2113 gl.height = vml.height + "px";
2114 g.coordsize = vml.coordsize;
2115 g.coordorigin = vml.coordorigin;
2118 var res = new Element(o, g, vml);
2124 res.setBox({x: x, y: y, width: w, height: h});
2125 vml.canvas.appendChild(g);
2128 var theText = function (vml, x, y, text) {
2129 var g = createNode("group"),
2131 el = createNode("shape"),
2133 path = createNode("path"),
2135 o = createNode("textpath");
2136 gs.position = "absolute";
2139 gs.width = vml.width + "px";
2140 gs.height = vml.height + "px";
2141 g.coordsize = vml.coordsize;
2142 g.coordorigin = vml.coordorigin;
2143 path.v = ["m", Math.round(x), ", ", Math.round(y), "l", Math.round(x) + 1, ", ", Math.round(y)].join("");
2144 path.textpathok = true;
2145 ol.width = vml.width;
2146 ol.height = vml.height;
2147 gs.position = "absolute";
2150 gs.width = vml.width;
2151 gs.height = vml.height;
2155 el.appendChild(path);
2157 var res = new Element(o, g, vml);
2159 res.textpath = path;
2165 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2167 vml.canvas.appendChild(g);
2170 var setSize = function (width, height) {
2171 var cs = this.canvas.style;
2172 this.width = width || this.width;
2173 this.height = height || this.height;
2174 cs.width = this.width + "px";
2175 cs.height = this.height + "px";
2176 cs.clip = "rect(0 " + this.width + "px " + this.height + "px 0)";
2177 this.canvas.coordsize = this.width + " " + this.height;
2180 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2182 if (!doc.namespaces.rvml) {
2183 doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2185 var createNode = function (tagName) {
2186 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2189 var createNode = function (tagName) {
2190 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2193 var create = function () {
2194 var con = getContainer.apply(null, arguments),
2195 container = con.container,
2200 height = con.height;
2202 throw new Error("VML container not found.");
2204 var c = paper.canvas = doc.createElement("div"),
2206 width = parseFloat(width) || "512px";
2207 height = parseFloat(height) || "342px";
2208 paper.width = width;
2209 paper.height = height;
2210 paper.coordsize = width + " " + height;
2211 paper.coordorigin = "0 0";
2212 paper.span = doc.createElement("span");
2213 s = paper.span.style;
2214 c.appendChild(paper.span);
2215 s.position = "absolute";
2216 s.left = "-99999px";
2221 s.display = "inline";
2222 cs.width = width + "px";
2223 cs.height = height + "px";
2224 cs.position = "absolute";
2225 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2226 if (container == 1) {
2227 doc.body.appendChild(c);
2237 container.style.width = width;
2238 container.style.height = height;
2239 if (container.firstChild) {
2240 container.insertBefore(c, container.firstChild);
2242 container.appendChild(c);
2245 for (var prop in paper) {
2246 container[prop] = paper[prop];
2248 plugins.call(container, container, R.fn);
2249 container.clear = function () {
2250 while (c.firstChild) {
2251 c.removeChild(c.firstChild);
2254 container.raphael = R;
2257 paper.remove = function () {
2258 this.canvas.parentNode.removeChild(this.canvas);
2260 paper.safari = function () {};
2266 var addEvent = (function () {
2267 if (doc.addEventListener) {
2268 return function (obj, type, fn, element) {
2269 var f = function (e) {
2270 return fn.call(element, e);
2272 obj.addEventListener(type, f, false);
2273 return function () {
2274 obj.removeEventListener(type, f, false);
2278 } else if (doc.attachEvent) {
2279 return function (obj, type, fn, element) {
2280 var f = function (e) {
2281 return fn.call(element, e || win.event);
2283 obj.attachEvent("on" + type, f);
2284 var detacher = function () {
2285 obj.detachEvent("on" + type, f);
2288 if (type == "mouseover") {
2289 obj.attachEvent("onmouseenter", f);
2290 return function () {
2291 obj.detachEvent("onmouseenter", f);
2294 } else if (type == "mouseout") {
2295 obj.attachEvent("onmouseleave", f);
2296 return function () {
2297 obj.detachEvent("onmouseleave", f);
2305 for (var i = events.length; i--;) {
2306 (function (eventName) {
2307 Element.prototype[eventName] = function (fn) {
2308 if (typeof fn == "function") {
2309 this.events = this.events || {};
2310 this.events[eventName] = this.events[eventName] || {};
2311 this.events[eventName][fn] = this.events[eventName][fn] || [];
2312 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2316 Element.prototype["un" + eventName] = function (fn) {
2318 this.events[eventName] &&
2319 this.events[eventName][fn] &&
2320 this.events[eventName][fn].length &&
2321 this.events[eventName][fn].shift()() &&
2322 !this.events[eventName][fn].length &&
2323 delete this.events[eventName][fn];
2328 paper.circle = function (x, y, r) {
2329 return theCircle(this, x, y, r);
2331 paper.rect = function (x, y, w, h, r) {
2332 return theRect(this, x, y, w, h, r);
2334 paper.ellipse = function (x, y, rx, ry) {
2335 return theEllipse(this, x, y, rx, ry);
2337 paper.path = function (params, pathString) {
2338 return thePath(params, pathString, this);
2340 paper.image = function (src, x, y, w, h) {
2341 return theImage(this, src, x, y, w, h);
2343 paper.text = function (x, y, text) {
2344 return theText(this, x, y, text);
2346 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
2347 color = color || "#000";
2348 var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
2350 columnWidth = w / wv;
2351 for (var i = 1; i < hv; i++) {
2352 path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
2354 for (var i = 1; i < wv; i++) {
2355 path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
2357 return this.path({stroke: color, "stroke-width": 1}, path.join(","));
2359 paper.pathfinder = function (p, path) {
2361 M: function (x, y) {
2364 C: function (x1, y1, x2, y2, x3, y3) {
2365 this.curveTo(x1, y1, x2, y2, x3, y3);
2367 Q: function (x1, y1, x2, y2) {
2368 this.qcurveTo(x1, y1, x2, y2);
2370 T: function (x, y) {
2371 this.qcurveTo(x, y);
2373 S: function (x1, y1, x2, y2) {
2374 p.curveTo(x1, y1, x2, y2);
2376 L: function (x, y) {
2380 this.lineTo(x, this.last.y);
2383 this.lineTo(this.last.x, y);
2385 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2386 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2393 path = pathToAbsolute(path);
2394 for (var i = 0, ii = path.length; i < ii; i++) {
2395 var b = path[i].shift();
2396 commands[b].apply(p, path[i]);
2400 paper.set = function (itemsArray) {
2401 return new Set(itemsArray);
2403 paper.setSize = setSize;
2404 Element.prototype.stop = function () {
2405 clearTimeout(this.animation_in_progress);
2407 Element.prototype.scale = function (x, y, cx, cy) {
2408 if (x == null && y == null) {
2409 return {x: this._.sx, y: this._.sy, toString: function () { return this.x.toFixed(3) + " " + this.y.toFixed(3); }};
2419 var bb = this.type == "path" ? pathDimensions(a.path) : this.getBBox(),
2420 rcx = bb.x + bb.width / 2,
2421 rcy = bb.y + bb.height / 2,
2424 cx = (+cx || cx == 0) ? cx : rcx;
2425 cy = (+cy || cy == 0) ? cy : rcy;
2426 var dirx = Math.round(x / Math.abs(x)),
2427 diry = Math.round(y / Math.abs(y)),
2428 s = this.node.style,
2429 ncx = cx + (rcx - cx) * dirx * kx,
2430 ncy = cy + (rcy - cy) * diry * ky;
2431 switch (this.type) {
2434 var neww = a.width * dirx * kx,
2435 newh = a.height * diry * ky,
2436 newx = ncx - neww / 2,
2437 newy = ncy - newh / 2;
2456 var path = pathToRelative(a.path),
2458 for (var i = 0, ii = path.length; i < ii; i++) {
2460 if (p[0].toUpperCase() == "M" && skip) {
2465 if (R.svg && p[0].toUpperCase() == "A") {
2466 p[path[i].length - 2] *= kx;
2467 p[path[i].length - 1] *= ky;
2470 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2472 for (var j = 1, jj = p.length; j < jj; j++) {
2473 p[j] *= (j % 2) ? kx : ky;
2477 var dim2 = pathDimensions(path),
2478 dx = ncx - dim2.x - dim2.width / 2,
2479 dy = ncy - dim2.y - dim2.height / 2;
2480 path = pathToRelative(path);
2484 this.attr({path: path.join(" ")});
2487 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2488 if (this.transformations) {
2489 this.transformations[2] = "scale(".concat(dirx, ",", diry, ")");
2490 this.node.setAttribute("transform", this.transformations.join(" "));
2491 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2492 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2493 this.attr({x: dx, y: dy});
2497 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=".concat(dirx,
2498 ", M12=0, M21=0, M22=", diry,
2499 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2500 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2503 if (this.transformations) {
2504 this.transformations[2] = "";
2505 this.node.setAttribute("transform", this.transformations.join(" "));
2509 this.node.filterMatrix = "";
2510 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2513 a.scale = [x, y, cx, cy].join(" ");
2520 R.easing_formulas = {
2521 linear: function (n) {
2525 return Math.pow(n, 3);
2528 return Math.pow(n - 1, 3) + 1;
2530 "<>": function (n) {
2533 return Math.pow(n, 3) / 2;
2536 return (Math.pow(n, 3) + 2) / 2;
2538 backIn: function (n) {
2540 return Math.pow(n, 2) * ((s + 1) * n - s);
2542 backOut: function (n) {
2545 return Math.pow(n, 2) * ((s + 1) * n + s) + 1;
2547 elastic: function (n) {
2548 if (n == 0 || n == 1) {
2553 return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1;
2555 bounce: function (n) {
2560 l = s * Math.pow(n, 2);
2564 l = s * Math.pow(n, 2) + .75;
2566 if (n < (2.5 / p)) {
2568 l = s * Math.pow(n, 2) + .9375;
2571 l = s * Math.pow(n, 2) + .984375;
2579 // animation easing formulas
2580 R.easing = function(easing, n) {
2581 return R.easing_formulas[easing] ? R.easing_formulas[easing](n) : n;
2584 Element.prototype.animate = function (params, ms, easing, callback) {
2585 clearTimeout(this.animation_in_progress);
2586 if (typeof easing == "function" || !easing) {
2587 callback = easing || null;
2594 for (var attr in params) {
2595 if (attr in availableAnimAttrs) {
2596 from[attr] = this.attr(attr);
2597 (typeof from[attr] == "undefined") && (from[attr] = availableAttrs[attr]);
2598 to[attr] = params[attr];
2599 switch (availableAnimAttrs[attr]) {
2601 diff[attr] = (to[attr] - from[attr]) / ms;
2604 from[attr] = R.getRGB(from[attr]);
2605 var toColour = R.getRGB(to[attr]);
2607 r: (toColour.r - from[attr].r) / ms,
2608 g: (toColour.g - from[attr].g) / ms,
2609 b: (toColour.b - from[attr].b) / ms
2613 var pathes = pathEqualiser(from[attr], to[attr]);
2614 from[attr] = pathes[0];
2615 to[attr] = pathes[1];
2617 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2618 diff[attr][i] = [0];
2619 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2620 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2625 var values = (params[attr] + "").split(separator),
2626 from2 = (from[attr] + "").split(separator);
2629 from[attr] = [0, 0];
2630 diff[attr] = [values[0] / ms, values[1] / ms];
2633 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2634 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2637 params[attr] = values;
2638 from[attr] = (from[attr] + "").split(separator);
2639 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2645 var start = +new Date,
2649 var time = new Date - start,
2653 pos = R.easing(easing, time / ms);
2654 for (var attr in from) {
2655 switch (availableAnimAttrs[attr]) {
2657 now = +from[attr] + pos * ms * diff[attr];
2661 Math.round(from[attr].r + pos * ms * diff[attr].r),
2662 Math.round(from[attr].g + pos * ms * diff[attr].g),
2663 Math.round(from[attr].b + pos * ms * diff[attr].b)
2668 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2669 now[i] = [from[attr][i][0]];
2670 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2671 now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
2673 now[i] = now[i].join(" ");
2675 now = now.join(" ");
2680 var x = diff[attr][0] * (time - prev),
2681 y = diff[attr][1] * (time - prev);
2684 now = [x, y].join(" ");
2687 now = +from[attr][0] + pos * ms * diff[attr][0];
2688 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2691 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(" ");
2695 if (attr == "font-size") {
2696 set[attr] = now + "px";
2702 that.animation_in_progress = setTimeout(tick);
2703 R.svg && paper.safari();
2705 (t.x || t.y) && that.translate(-t.x, -t.y);
2707 clearTimeout(that.animation_in_progress);
2709 (typeof callback == "function") && callback.call(that);
2715 Element.prototype.translate = function (x, y) {
2717 return {x: this._.tx, y: this._.ty};
2721 switch (this.type) {
2724 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
2729 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
2732 var path = pathToRelative(this.attrs.path);
2735 this.attr({path: path.join(" ")});
2742 var Set = function (items) {
2746 for (var i = 0, ii = items.length; i < ii; i++) {
2747 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
2748 this[this.items.length] = this.items[this.items.length] = items[i];
2754 Set.prototype.push = function () {
2757 for (var i = 0, ii = arguments.length; i < ii; i++) {
2758 item = arguments[i];
2759 if (item && (item.constructor == Element || item.constructor == Set)) {
2760 len = this.items.length;
2761 this[len] = this.items[len] = item;
2767 Set.prototype.pop = function (id) {
2768 var res = this.items.splice(id, 1)[0];
2769 for (var j = id, jj = this.items.length; j < jj; j++) {
2770 this[j] = this[j + 1];
2772 delete this[jj + 1];
2776 for (var method in Element.prototype) {
2777 Set.prototype[method] = (function (methodname) {
2778 return function () {
2779 for (var i = 0, ii = this.items.length; i < ii; i++) {
2780 this.items[i][methodname].apply(this.items[i], arguments);
2786 Set.prototype.attr = function (name, value) {
2787 if (name && R.isArray(name) && typeof name[0] == "object") {
2788 for (var j = 0, jj = name.length; j < jj; j++) {
2789 this.items[j].attr(name[j]);
2792 for (var i = 0, ii = this.items.length; i < ii; i++) {
2793 this.items[i].attr.apply(this.items[i], arguments);
2799 Set.prototype.getBBox = function () {
2804 for (var i = this.items.length; i--;) {
2805 var box = this.items[i].getBBox();
2808 w.push(box.x + box.width);
2809 h.push(box.y + box.height);
2811 x = Math.min.apply(Math, x);
2812 y = Math.min.apply(Math, y);
2816 width: Math.max.apply(Math, w) - x,
2817 height: Math.max.apply(Math, h) - y
2821 R.registerFont = function (font) {
2825 this.fonts = this.fonts || {};
2831 family = font.face["font-family"];
2832 for (var prop in font.face) {
2833 fontcopy.face[prop] = font.face[prop];
2835 if (this.fonts[family]) {
2836 this.fonts[family].push(fontcopy);
2838 this.fonts[family] = [fontcopy];
2841 fontcopy.face["units-per-em"] = parseInt(font.face["units-per-em"], 10);
2842 for (var glyph in font.glyphs) {
2843 var path = font.glyphs[glyph];
2844 fontcopy.glyphs[glyph] = {
2847 d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
2848 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
2852 for (var k in path.k) {
2853 fontcopy.glyphs[glyph].k[k] = path.k[k];
2860 paper.getFont = function (family, weight, style, stretch) {
2861 stretch = stretch || "normal";
2862 style = style || "normal";
2863 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
2864 var font = R.fonts[family];
2866 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, "") + "(\\s|$)", "i");
2867 for (var fontName in R.fonts) {
2868 if (name.test(fontName)) {
2869 font = R.fonts[fontName];
2876 for (var i = 0, ii = font.length; i < ii; i++) {
2878 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
2885 paper.print = function (x, y, string, font, size) {
2886 var out = this.set(),
2887 letters = (string + "").split(""),
2892 scale = (size || 16) / font.face["units-per-em"];
2893 for (var i = 0, ii = letters.length; i < ii; i++) {
2894 var prev = i && font.glyphs[letters[i - 1]] || {},
2895 curr = font.glyphs[letters[i]];
2896 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
2897 curr && curr.d && out.push(this.path({fill: "#000", stroke: "none"}, curr.d).translate(shift, 0));
2899 out.scale(scale, scale, 0, y).translate(x, (size || 16) / 2);
2904 R.ninja = function () {
2905 var r = window.Raphael;
2906 if (oldRaphael.was) {
2907 window.Raphael = oldRaphael.is;
2910 delete window.Raphael;
2912 window.Raphael = void(0);
2917 R.el = Element.prototype;