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
1184 if (this.type == "text") {
1185 bbox = {x: bbox.x, y: Infinity, width: bbox.width, height: 0};
1186 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1187 var bb = this.node.getExtentOfChar(i);
1188 (bb.y < bbox.y) && (bbox.y = bb.y);
1189 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1192 hide && this.hide();
1195 Element.prototype.attr = function () {
1196 if (arguments.length == 1 && typeof arguments[0] == "string") {
1197 if (arguments[0] == "translation") {
1198 return this.translate();
1200 return this.attrs[arguments[0]];
1202 if (arguments.length == 1 && R.isArray(arguments[0])) {
1204 for (var j in arguments[0]) {
1205 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1209 if (arguments.length == 2) {
1211 params[arguments[0]] = arguments[1];
1212 setFillAndStroke(this, params);
1213 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1214 setFillAndStroke(this, arguments[0]);
1218 Element.prototype.toFront = function () {
1219 this.node.parentNode.appendChild(this.node);
1222 Element.prototype.toBack = function () {
1223 if (this.node.parentNode.firstChild != this.node) {
1224 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1228 Element.prototype.insertAfter = function (element) {
1229 if (element.node.nextSibling) {
1230 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1232 element.node.parentNode.appendChild(this.node);
1236 Element.prototype.insertBefore = function (element) {
1237 var node = element.node;
1238 node.parentNode.insertBefore(this.node, node);
1241 var theCircle = function (svg, x, y, r) {
1242 var el = doc.createElementNS(svg.svgns, "circle");
1243 el.setAttribute("cx", x);
1244 el.setAttribute("cy", y);
1245 el.setAttribute("r", r);
1246 el.setAttribute("fill", "none");
1247 el.setAttribute("stroke", "#000");
1249 svg.canvas.appendChild(el);
1251 var res = new Element(el, svg);
1252 res.attrs = res.attrs || {};
1256 res.attrs.stroke = "#000";
1257 res.type = "circle";
1260 var theRect = function (svg, x, y, w, h, r) {
1261 var el = doc.createElementNS(svg.svgns, "rect");
1262 el.setAttribute("x", x);
1263 el.setAttribute("y", y);
1264 el.setAttribute("width", w);
1265 el.setAttribute("height", h);
1267 el.setAttribute("rx", r);
1268 el.setAttribute("ry", r);
1270 el.setAttribute("fill", "none");
1271 el.setAttribute("stroke", "#000");
1273 svg.canvas.appendChild(el);
1275 var res = new Element(el, svg);
1276 res.attrs = res.attrs || {};
1279 res.attrs.width = w;
1280 res.attrs.height = h;
1281 res.attrs.stroke = "#000";
1283 res.attrs.rx = res.attrs.ry = r;
1288 var theEllipse = function (svg, x, y, rx, ry) {
1289 var el = doc.createElementNS(svg.svgns, "ellipse");
1290 el.setAttribute("cx", x);
1291 el.setAttribute("cy", y);
1292 el.setAttribute("rx", rx);
1293 el.setAttribute("ry", ry);
1294 el.setAttribute("fill", "none");
1295 el.setAttribute("stroke", "#000");
1297 svg.canvas.appendChild(el);
1299 var res = new Element(el, svg);
1300 res.attrs = res.attrs || {};
1305 res.attrs.stroke = "#000";
1306 res.type = "ellipse";
1309 var theImage = function (svg, src, x, y, w, h) {
1310 var el = doc.createElementNS(svg.svgns, "image");
1311 el.setAttribute("x", x);
1312 el.setAttribute("y", y);
1313 el.setAttribute("width", w);
1314 el.setAttribute("height", h);
1315 el.setAttribute("preserveAspectRatio", "none");
1316 el.setAttributeNS(svg.xlink, "href", src);
1318 svg.canvas.appendChild(el);
1320 var res = new Element(el, svg);
1321 res.attrs = res.attrs || {};
1324 res.attrs.width = w;
1325 res.attrs.height = h;
1329 var theText = function (svg, x, y, text) {
1330 var el = doc.createElementNS(svg.svgns, "text");
1331 el.setAttribute("x", x);
1332 el.setAttribute("y", y);
1333 el.setAttribute("text-anchor", "middle");
1335 svg.canvas.appendChild(el);
1337 var res = new Element(el, svg);
1338 res.attrs = res.attrs || {};
1342 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000", text: text});
1345 var setSize = function (width, height) {
1346 this.width = width || this.width;
1347 this.height = height || this.height;
1348 this.canvas.setAttribute("width", this.width);
1349 this.canvas.setAttribute("height", this.height);
1352 var create = function () {
1353 var con = getContainer.apply(null, arguments),
1354 container = con.container,
1358 height = con.height;
1360 throw new Error("SVG container not found.");
1362 paper.canvas = doc.createElementNS(paper.svgns, "svg");
1363 paper.canvas.setAttribute("width", width || 512);
1364 paper.width = width || 512;
1365 paper.canvas.setAttribute("height", height || 342);
1366 paper.height = height || 342;
1367 if (container == 1) {
1368 doc.body.appendChild(paper.canvas);
1369 paper.canvas.style.position = "absolute";
1370 paper.canvas.style.left = x + "px";
1371 paper.canvas.style.top = y + "px";
1373 if (container.firstChild) {
1374 container.insertBefore(paper.canvas, container.firstChild);
1376 container.appendChild(paper.canvas);
1380 canvas: paper.canvas,
1381 clear: function () {
1382 while (this.canvas.firstChild) {
1383 this.canvas.removeChild(this.canvas.firstChild);
1385 this.defs = doc.createElementNS(paper.svgns, "defs");
1386 this.canvas.appendChild(this.defs);
1389 for (var prop in paper) {
1390 if (prop != "create") {
1391 container[prop] = paper[prop];
1394 plugins.call(container, container, R.fn);
1396 container.raphael = R;
1399 paper.remove = function () {
1400 this.canvas.parentNode.removeChild(this.canvas);
1402 paper.svgns = "http://www.w3.org/2000/svg";
1403 paper.xlink = "http://www.w3.org/1999/xlink";
1404 paper.safari = function () {
1405 if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) {
1406 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1407 setTimeout(function () {rect.remove();});
1414 R.toString = function () {
1415 return "Your browser doesn\u2019t support SVG. Assuming it is Internet Explorer and falling down to VML.\nYou are running Rapha\u00ebl " + this.version;
1418 absolutely: function () {
1419 this.isAbsolute = true;
1422 relatively: function () {
1423 this.isAbsolute = false;
1426 moveTo: function (x, y) {
1427 var X = Math.round(parseFloat(x)) - 1,
1428 Y = Math.round(parseFloat(y)) - 1,
1429 d = this.isAbsolute ? "m" : "t";
1431 this.node.path = this.Path += d;
1432 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1433 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1434 this.last.isAbsolute = this.isAbsolute;
1435 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1438 lineTo: function (x, y) {
1439 var X = Math.round(parseFloat(x)) - 1,
1440 Y = Math.round(parseFloat(y)) - 1,
1441 d = this.isAbsolute ? "l" : "r";
1443 this.node.path = this.Path += d;
1444 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1445 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1446 this.last.isAbsolute = this.isAbsolute;
1447 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1450 arcTo: function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1451 // for more information of where this math came from visit:
1452 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1453 var x22 = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2) - 1,
1454 y22 = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2) - 1,
1455 x1 = this.last.x - 1,
1456 y1 = this.last.y - 1,
1459 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1460 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1461 cx = k * rx * y / ry + (x1 + x22) / 2,
1462 cy = k * -ry * x / rx + (y1 + y22) / 2,
1463 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1464 left = Math.round(cx - rx),
1465 top = Math.round(cy - ry);
1466 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(", ");
1467 this.node.path = this.Path += d;
1468 this.last.x = (this.isAbsolute ? 0 : this.last.x) + x2;
1469 this.last.y = (this.isAbsolute ? 0 : this.last.y) + y2;
1470 this.last.isAbsolute = this.isAbsolute;
1471 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1474 cplineTo: function (x1, y1, w1) {
1476 return this.lineTo(x1, y1);
1478 var x = Math.round(parseFloat(x1)) - 1,
1479 y = Math.round(parseFloat(y1)) - 1,
1480 w = Math.round(parseFloat(w1)),
1481 d = this.isAbsolute ? "c" : "v",
1482 attr = [Math.round(this.last.x) - 1 + w, Math.round(this.last.y) - 1, x - w, y, x, y],
1483 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1484 d += attr.join(" ") + " ";
1485 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1486 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1487 this.last.bx = attr[2];
1488 this.last.by = attr[3];
1489 this.node.path = this.Path += d;
1490 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1494 curveTo: function () {
1495 var d = this.isAbsolute ? "c" : "v";
1496 if (arguments.length == 6) {
1497 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1498 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1499 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4]);
1500 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5]);
1501 d += [Math.round(parseFloat(arguments[0])) - 1,
1502 Math.round(parseFloat(arguments[1])) - 1,
1503 Math.round(parseFloat(arguments[2])) - 1,
1504 Math.round(parseFloat(arguments[3])) - 1,
1505 Math.round(parseFloat(arguments[4])) - 1,
1506 Math.round(parseFloat(arguments[5])) - 1].join(" ") + " ";
1507 this.last.isAbsolute = this.isAbsolute;
1508 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1510 if (arguments.length == 4) {
1511 var bx = this.last.x * 2 - this.last.bx,
1512 by = this.last.y * 2 - this.last.by;
1513 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0]);
1514 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1]);
1515 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1516 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1517 d += [Math.round(bx) - 1, Math.round(by) - 1,
1518 Math.round(parseFloat(arguments[0])) - 1,
1519 Math.round(parseFloat(arguments[1])) - 1,
1520 Math.round(parseFloat(arguments[2])) - 1,
1521 Math.round(parseFloat(arguments[3])) - 1].join(" ") + " ";
1522 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1524 this.node.path = this.Path += d;
1527 qcurveTo: function () {
1528 var lx = Math.round(this.last.x) - 1,
1529 ly = Math.round(this.last.y) - 1,
1531 if (arguments.length == 4) {
1532 this.last.qx = (!this.isAbsolute * this.last.x) + parseFloat(arguments[0]);
1533 this.last.qy = (!this.isAbsolute * this.last.y) + parseFloat(arguments[1]);
1534 this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(arguments[2]);
1535 this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(arguments[3]);
1536 res = [this.last.qx, this.last.qy, this.last.x, this.last.y];
1537 this.last.isAbsolute = this.isAbsolute;
1538 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1540 if (arguments.length == 2) {
1541 this.last.qx = this.last.x * 2 - this.last.qx;
1542 this.last.qy = this.last.y * 2 - this.last.qy;
1543 this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(arguments[2]);
1544 this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(arguments[3]);
1545 res = [this.last.qx, this.last.qy, this.last.x, this.last.y];
1546 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1549 Math.round(2 / 3 * res[0] + 1 / 3 * lx) - 1,
1550 Math.round(2 / 3 * res[1] + 1 / 3 * ly) - 1,
1551 Math.round(2 / 3 * res[0] + 1 / 3 * res[2]) - 1,
1552 Math.round(2 / 3 * res[1] + 1 / 3 * res[3]) - 1,
1553 Math.round(res[2]) - 1,
1554 Math.round(res[3]) - 1
1556 this.node.path = this.Path += d;
1559 addRoundedCorner: addRoundedCorner,
1560 andClose: function () {
1561 this.node.path = (this.Path += "x");
1562 this.attrs.path += "z";
1566 var thePath = function (params, pathString, VML) {
1567 params = params || {};
1568 var g = createNode("group"), gl = g.style;
1569 gl.position = "absolute";
1572 gl.width = VML.width + "px";
1573 gl.height = VML.height + "px";
1574 g.coordsize = VML.coordsize;
1575 g.coordorigin = VML.coordorigin;
1576 var el = createNode("shape"), ol = el.style;
1577 ol.width = VML.width + "px";
1578 ol.height = VML.height + "px";
1580 if (params["class"]) {
1581 el.className = "rvml " + params["class"];
1583 el.coordsize = this.coordsize;
1584 el.coordorigin = this.coordorigin;
1586 var p = new Element(el, g, VML);
1587 p.isAbsolute = true;
1590 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1592 for (var method in pathMethods) {
1593 p[method] = pathMethods[method];
1599 paper.pathfinder(p, "" + pathString);
1602 params.fill = params.fill || "none";
1603 params.stroke = params.stroke || "#000";
1605 params = {fill: "none", stroke: "#000"};
1607 setFillAndStroke(p, params);
1608 if (params.gradient) {
1609 addGradientFill(p, params.gradient);
1612 VML.canvas.appendChild(g);
1615 var setFillAndStroke = function (o, params) {
1620 o.attrs = o.attrs || {};
1621 for (var par in params) {
1622 o.attrs[par] = params[par];
1624 params.href && (node.href = params.href);
1625 params.title && (node.title = params.title);
1626 params.target && (node.target = params.target);
1627 if (params.path && o.type == "path") {
1631 paper.pathfinder(o, params.path);
1633 if (params.rotation != null) {
1634 o.rotate(params.rotation, true);
1636 if (params.translation) {
1637 xy = (params.translation + "").split(separator);
1638 o.translate(xy[0], xy[1]);
1641 xy = (params.scale + "").split(separator);
1642 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1644 if (o.type == "image" && params.src) {
1645 node.src = params.src;
1647 if (o.type == "image" && params.opacity) {
1648 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1649 node.style.filter = (node.filterMatrix || "") + (node.filterOpacity || "");
1651 params.font && (s.font = params.font);
1652 params["font-family"] && (s.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, "") + '"');
1653 params["font-size"] && (s.fontSize = params["font-size"]);
1654 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1655 params["font-style"] && (s.fontStyle = params["font-style"]);
1656 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"]) {
1657 o = o.shape || node;
1658 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || createNode("fill");
1659 if ("fill-opacity" in params || "opacity" in params) {
1660 var opacity = ((+params["fill-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1661 opacity < 0 && (opacity = 0);
1662 opacity > 1 && (opacity = 1);
1663 fill.opacity = opacity;
1665 params.fill && (fill.on = true);
1666 if (typeof fill.on == "undefined" || params.fill == "none") {
1669 if (fill.on && params.fill) {
1670 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1672 fill.src = isURL[1];
1675 fill.color = R.getRGB(params.fill).hex;
1677 fill.type = "solid";
1680 o.appendChild(fill);
1681 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || createNode("stroke");
1682 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"]) {
1685 if (params.stroke == "none" || typeof stroke.on == "undefined" || params.stroke == 0) {
1688 if (stroke.on && params.stroke) {
1689 stroke.color = R.getRGB(params.stroke).hex;
1691 var opacity = ((+params["stroke-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1692 opacity < 0 && (opacity = 0);
1693 opacity > 1 && (opacity = 1);
1694 stroke.opacity = opacity;
1695 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1696 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1697 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1698 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"]) || 1) * 12 / 16);
1699 if (params["stroke-dasharray"]) {
1703 "-.": "shortdashdot",
1704 "-..": "shortdashdotdot",
1709 "--.": "longdashdot",
1710 "--..": "longdashdotdot"
1712 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1714 o.appendChild(stroke);
1716 if (res.type == "text") {
1717 var s = paper.span.style,
1719 a.font && (s.font = a.font);
1720 a["font-family"] && (s.fontFamily = a["font-family"]);
1721 a["font-size"] && (s.fontSize = a["font-size"]);
1722 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1723 a["font-style"] && (s.fontStyle = a["font-style"]);
1724 paper.span.innerText = res.node.string;
1725 res.W = a.w = paper.span.offsetWidth;
1726 res.H = a.h = paper.span.offsetHeight;
1728 res.Y = a.y + Math.round(res.H / 2);
1730 // text-anchor emulation
1731 switch (a["text-anchor"]) {
1733 res.node.style["v-text-align"] = "left";
1734 res.bbx = Math.round(res.W / 2);
1737 res.node.style["v-text-align"] = "right";
1738 res.bbx = -Math.round(res.W / 2);
1741 res.node.style["v-text-align"] = "center";
1746 var getAngle = function (a, b, c, d) {
1747 var angle = Math.round(Math.atan((parseFloat(c) - parseFloat(a)) / (parseFloat(d) - parseFloat(b))) * 57.29) || 0;
1748 if (!angle && parseFloat(a) < parseFloat(b)) {
1757 var addGradientFill = function (o, gradient) {
1758 gradient = toGradient(gradient);
1759 o.attrs = o.attrs || {};
1760 var attrs = o.attrs,
1761 fill = o.node.getElementsByTagName("fill");
1762 o.attrs.gradient = gradient;
1763 o = o.shape || o.node;
1767 fill = createNode("fill");
1769 if (gradient.dots.length) {
1771 fill.method = "none";
1772 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1773 if (typeof gradient.dots[0].color != "undefined") {
1774 fill.color = R.getRGB(gradient.dots[0].color).hex;
1776 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1777 fill.color2 = R.getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1780 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1781 if (gradient.dots[i].offset) {
1782 clrs.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
1785 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;
1787 fill.colors.value = clrs.join(",");
1788 fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
1790 fill.colors && (fill.colors.value = "0% " + fill.color);
1792 fill.opacity = fillOpacity;
1793 if (typeof gradient.angle != "undefined") {
1794 fill.angle = (-gradient.angle + 270) % 360;
1795 } else if (gradient.vector) {
1796 fill.angle = getAngle.apply(null, gradient.vector);
1798 if ((gradient.type + "").toLowerCase() == "radial") {
1799 fill.focus = "100%";
1800 fill.focusposition = "0.5 0.5";
1804 var Element = function (node, group, vml) {
1824 Element.prototype.rotate = function (deg, cx, cy) {
1826 return this._.rt.deg;
1828 deg = (deg + "").split(separator);
1829 if (deg.length - 1) {
1830 cx = parseFloat(deg[1]);
1831 cy = parseFloat(deg[2]);
1833 deg = parseFloat(deg[0]);
1835 this._.rt.deg = deg;
1837 this._.rt.deg += deg;
1844 this.setBox(this.attrs, cx, cy);
1845 this.Group.style.rotation = this._.rt.deg;
1846 // gradient fix for rotation. TODO
1847 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1848 // fill = fill[0] || {};
1849 // var b = ((360 - this._.rt.deg) - 270) % 360;
1850 // typeof fill.angle != "undefined" && (fill.angle = b);
1853 Element.prototype.setBox = function (params, cx, cy) {
1854 var gs = this.Group.style,
1855 os = (this.shape && this.shape.style) || this.node.style;
1856 params = params || {};
1857 for (var i in params) {
1858 this.attrs[i] = params[i];
1860 cx = cx || this._.rt.cx;
1861 cy = cy || this._.rt.cy;
1862 var attr = this.attrs,
1867 switch (this.type) {
1869 x = attr.cx - attr.r;
1870 y = attr.cy - attr.r;
1874 x = attr.cx - attr.rx;
1875 y = attr.cy - attr.ry;
1883 w = attr.width || 0;
1884 h = attr.height || 0;
1887 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("");
1888 x = attr.x - Math.round(this.W / 2);
1889 y = attr.y - this.H / 2;
1894 if (!this.attrs.path) {
1897 w = this.paper.width;
1898 h = this.paper.height;
1900 var dim = pathDimensions(this.attrs.path),
1910 w = this.paper.width;
1911 h = this.paper.height;
1914 cx = (cx == null) ? x + w / 2 : cx;
1915 cy = (cy == null) ? y + h / 2 : cy;
1916 var left = cx - this.paper.width / 2,
1917 top = cy - this.paper.height / 2;
1918 if (this.type == "path" || this.type == "text") {
1919 (gs.left != left + "px") && (gs.left = left + "px");
1920 (gs.top != top + "px") && (gs.top = top + "px");
1921 this.X = this.type == "text" ? x : -left;
1922 this.Y = this.type == "text" ? y : -top;
1925 (os.left != -left + "px") && (os.left = -left + "px");
1926 (os.top != -top + "px") && (os.top = -top + "px");
1928 (gs.left != left + "px") && (gs.left = left + "px");
1929 (gs.top != top + "px") && (gs.top = top + "px");
1934 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
1935 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
1936 (os.left != x - left + "px") && (os.left = x - left + "px");
1937 (os.top != y - top + "px") && (os.top = y - top + "px");
1938 (os.width != w + "px") && (os.width = w + "px");
1939 (os.height != h + "px") && (os.height = h + "px");
1940 var arcsize = (+params.r || 0) / (Math.min(w, h));
1941 if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
1942 // We should replace element with the new one
1943 var o = createNode(arcsize ? "roundrect" : "rect");
1944 o.arcsize = arcsize;
1945 this.Group.appendChild(o);
1946 this.node.parentNode.removeChild(this.node);
1948 this.arcsize = arcsize;
1949 setFillAndStroke(this, this.attrs);
1950 this.setBox(this.attrs);
1954 Element.prototype.hide = function () {
1955 this.Group.style.display = "none";
1958 Element.prototype.show = function () {
1959 this.Group.style.display = "block";
1962 Element.prototype.getBBox = function () {
1963 if (this.type == "path") {
1964 return pathDimensions(this.attr("path"));
1967 x: this.X + (this.bbx || 0),
1973 Element.prototype.remove = function () {
1974 this[0].parentNode.removeChild(this[0]);
1975 this.Group.parentNode.removeChild(this.Group);
1976 this.shape && this.shape.parentNode.removeChild(this.shape);
1978 Element.prototype.attr = function () {
1979 if (arguments.length == 1 && typeof arguments[0] == "string") {
1980 if (arguments[0] == "translation") {
1981 return this.translate();
1983 return this.attrs[arguments[0]];
1985 if (this.attrs && arguments.length == 1 && R.isArray(arguments[0])) {
1987 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1988 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1993 if (arguments.length == 2) {
1995 params[arguments[0]] = arguments[1];
1997 if (arguments.length == 1 && typeof arguments[0] == "object") {
1998 params = arguments[0];
2001 if (params.gradient) {
2002 addGradientFill(this, params.gradient);
2004 if (params.text && this.type == "text") {
2005 this.node.string = params.text;
2007 setFillAndStroke(this, params);
2008 this.setBox(this.attrs);
2012 Element.prototype.toFront = function () {
2013 this.Group.parentNode.appendChild(this.Group);
2016 Element.prototype.toBack = function () {
2017 if (this.Group.parentNode.firstChild != this.Group) {
2018 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2022 Element.prototype.insertAfter = function (element) {
2023 if (element.Group.nextSibling) {
2024 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2026 element.Group.parentNode.appendChild(this.Group);
2030 Element.prototype.insertBefore = function (element) {
2031 element.Group.parentNode.insertBefore(this.Group, element.Group);
2034 var theCircle = function (vml, x, y, r) {
2035 var g = createNode("group"),
2037 o = createNode("oval"),
2039 gl.position = "absolute";
2042 gl.width = vml.width + "px";
2043 gl.height = vml.height + "px";
2044 g.coordsize = vml.coordsize;
2045 g.coordorigin = vml.coordorigin;
2047 var res = new Element(o, g, vml);
2048 res.type = "circle";
2049 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2053 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2054 vml.canvas.appendChild(g);
2057 var theRect = function (vml, x, y, w, h, r) {
2058 var g = createNode("group"),
2060 o = createNode(r ? "roundrect" : "rect"),
2061 arcsize = (+r || 0) / (Math.min(w, h));
2062 o.arcsize = arcsize;
2063 gl.position = "absolute";
2066 gl.width = vml.width + "px";
2067 gl.height = vml.height + "px";
2068 g.coordsize = vml.coordsize;
2069 g.coordorigin = vml.coordorigin;
2071 var res = new Element(o, g, vml);
2073 setFillAndStroke(res, {stroke: "#000"});
2074 res.arcsize = arcsize;
2075 res.setBox({x: x, y: y, width: w, height: h, r: +r});
2076 vml.canvas.appendChild(g);
2079 var theEllipse = function (vml, x, y, rx, ry) {
2080 var g = createNode("group"),
2082 o = createNode("oval"),
2084 gl.position = "absolute";
2087 gl.width = vml.width + "px";
2088 gl.height = vml.height + "px";
2089 g.coordsize = vml.coordsize;
2090 g.coordorigin = vml.coordorigin;
2092 var res = new Element(o, g, vml);
2093 res.type = "ellipse";
2094 setFillAndStroke(res, {stroke: "#000"});
2099 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2100 vml.canvas.appendChild(g);
2103 var theImage = function (vml, src, x, y, w, h) {
2104 var g = createNode("group"),
2106 o = createNode("image"),
2108 gl.position = "absolute";
2111 gl.width = vml.width + "px";
2112 gl.height = vml.height + "px";
2113 g.coordsize = vml.coordsize;
2114 g.coordorigin = vml.coordorigin;
2117 var res = new Element(o, g, vml);
2123 res.setBox({x: x, y: y, width: w, height: h});
2124 vml.canvas.appendChild(g);
2127 var theText = function (vml, x, y, text) {
2128 var g = createNode("group"),
2130 el = createNode("shape"),
2132 path = createNode("path"),
2134 o = createNode("textpath");
2135 gs.position = "absolute";
2138 gs.width = vml.width + "px";
2139 gs.height = vml.height + "px";
2140 g.coordsize = vml.coordsize;
2141 g.coordorigin = vml.coordorigin;
2142 path.v = ["m", Math.round(x), ", ", Math.round(y), "l", Math.round(x) + 1, ", ", Math.round(y)].join("");
2143 path.textpathok = true;
2144 ol.width = vml.width;
2145 ol.height = vml.height;
2146 gs.position = "absolute";
2149 gs.width = vml.width;
2150 gs.height = vml.height;
2154 el.appendChild(path);
2156 var res = new Element(o, g, vml);
2158 res.textpath = path;
2164 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2166 vml.canvas.appendChild(g);
2169 var setSize = function (width, height) {
2170 var cs = this.canvas.style;
2171 this.width = width || this.width;
2172 this.height = height || this.height;
2173 cs.width = this.width + "px";
2174 cs.height = this.height + "px";
2175 cs.clip = "rect(0 " + this.width + "px " + this.height + "px 0)";
2176 this.canvas.coordsize = this.width + " " + this.height;
2179 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2181 if (!doc.namespaces.rvml) {
2182 doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2184 var createNode = function (tagName) {
2185 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2188 var createNode = function (tagName) {
2189 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2192 var create = function () {
2193 var con = getContainer.apply(null, arguments),
2194 container = con.container,
2199 height = con.height;
2201 throw new Error("VML container not found.");
2203 var c = paper.canvas = doc.createElement("div"),
2205 width = parseFloat(width) || "512px";
2206 height = parseFloat(height) || "342px";
2207 paper.width = width;
2208 paper.height = height;
2209 paper.coordsize = width + " " + height;
2210 paper.coordorigin = "0 0";
2211 paper.span = doc.createElement("span");
2212 s = paper.span.style;
2213 c.appendChild(paper.span);
2214 s.position = "absolute";
2215 s.left = "-99999px";
2220 s.display = "inline";
2221 cs.width = width + "px";
2222 cs.height = height + "px";
2223 cs.position = "absolute";
2224 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2225 if (container == 1) {
2226 doc.body.appendChild(c);
2236 container.style.width = width;
2237 container.style.height = height;
2238 if (container.firstChild) {
2239 container.insertBefore(c, container.firstChild);
2241 container.appendChild(c);
2244 for (var prop in paper) {
2245 container[prop] = paper[prop];
2247 plugins.call(container, container, R.fn);
2248 container.clear = function () {
2249 while (c.firstChild) {
2250 c.removeChild(c.firstChild);
2253 container.raphael = R;
2256 paper.remove = function () {
2257 this.canvas.parentNode.removeChild(this.canvas);
2259 paper.safari = function () {};
2265 var addEvent = (function () {
2266 if (doc.addEventListener) {
2267 return function (obj, type, fn, element) {
2268 var f = function (e) {
2269 return fn.call(element, e);
2271 obj.addEventListener(type, f, false);
2272 return function () {
2273 obj.removeEventListener(type, f, false);
2277 } else if (doc.attachEvent) {
2278 return function (obj, type, fn, element) {
2279 var f = function (e) {
2280 return fn.call(element, e || win.event);
2282 obj.attachEvent("on" + type, f);
2283 var detacher = function () {
2284 obj.detachEvent("on" + type, f);
2287 if (type == "mouseover") {
2288 obj.attachEvent("onmouseenter", f);
2289 return function () {
2290 obj.detachEvent("onmouseenter", f);
2293 } else if (type == "mouseout") {
2294 obj.attachEvent("onmouseleave", f);
2295 return function () {
2296 obj.detachEvent("onmouseleave", f);
2304 for (var i = events.length; i--;) {
2305 (function (eventName) {
2306 Element.prototype[eventName] = function (fn) {
2307 if (typeof fn == "function") {
2308 this.events = this.events || {};
2309 this.events[eventName] = this.events[eventName] || {};
2310 this.events[eventName][fn] = this.events[eventName][fn] || [];
2311 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2315 Element.prototype["un" + eventName] = function (fn) {
2317 this.events[eventName] &&
2318 this.events[eventName][fn] &&
2319 this.events[eventName][fn].length &&
2320 this.events[eventName][fn].shift()() &&
2321 !this.events[eventName][fn].length &&
2322 delete this.events[eventName][fn];
2327 paper.circle = function (x, y, r) {
2328 return theCircle(this, x, y, r);
2330 paper.rect = function (x, y, w, h, r) {
2331 return theRect(this, x, y, w, h, r);
2333 paper.ellipse = function (x, y, rx, ry) {
2334 return theEllipse(this, x, y, rx, ry);
2336 paper.path = function (params, pathString) {
2337 return thePath(params, pathString, this);
2339 paper.image = function (src, x, y, w, h) {
2340 return theImage(this, src, x, y, w, h);
2342 paper.text = function (x, y, text) {
2343 return theText(this, x, y, text);
2345 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
2346 color = color || "#000";
2347 var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
2349 columnWidth = w / wv;
2350 for (var i = 1; i < hv; i++) {
2351 path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
2353 for (var i = 1; i < wv; i++) {
2354 path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
2356 return this.path({stroke: color, "stroke-width": 1}, path.join(","));
2358 paper.pathfinder = function (p, path) {
2360 M: function (x, y) {
2363 C: function (x1, y1, x2, y2, x3, y3) {
2364 this.curveTo(x1, y1, x2, y2, x3, y3);
2366 Q: function (x1, y1, x2, y2) {
2367 this.qcurveTo(x1, y1, x2, y2);
2369 T: function (x, y) {
2370 this.qcurveTo(x, y);
2372 S: function (x1, y1, x2, y2) {
2373 p.curveTo(x1, y1, x2, y2);
2375 L: function (x, y) {
2379 this.lineTo(x, this.last.y);
2382 this.lineTo(this.last.x, y);
2384 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2385 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2392 path = pathToAbsolute(path);
2393 for (var i = 0, ii = path.length; i < ii; i++) {
2394 var b = path[i].shift();
2395 commands[b].apply(p, path[i]);
2399 paper.set = function (itemsArray) {
2400 return new Set(itemsArray);
2402 paper.setSize = setSize;
2403 Element.prototype.stop = function () {
2404 clearTimeout(this.animation_in_progress);
2406 Element.prototype.scale = function (x, y, cx, cy) {
2407 if (x == null && y == null) {
2408 return {x: this._.sx, y: this._.sy, toString: function () { return this.x.toFixed(3) + " " + this.y.toFixed(3); }};
2418 var bb = this.type == "path" ? pathDimensions(a.path) : this.getBBox(),
2419 rcx = bb.x + bb.width / 2,
2420 rcy = bb.y + bb.height / 2,
2423 cx = (+cx || cx == 0) ? cx : rcx;
2424 cy = (+cy || cy == 0) ? cy : rcy;
2425 var dirx = Math.round(x / Math.abs(x)),
2426 diry = Math.round(y / Math.abs(y)),
2427 s = this.node.style,
2428 ncx = cx + (rcx - cx) * dirx * kx,
2429 ncy = cy + (rcy - cy) * diry * ky;
2430 switch (this.type) {
2433 var neww = a.width * dirx * kx,
2434 newh = a.height * diry * ky,
2435 newx = ncx - neww / 2,
2436 newy = ncy - newh / 2;
2455 var path = pathToRelative(a.path),
2457 for (var i = 0, ii = path.length; i < ii; i++) {
2459 if (p[0].toUpperCase() == "M" && skip) {
2464 if (R.svg && p[0].toUpperCase() == "A") {
2465 p[path[i].length - 2] *= kx;
2466 p[path[i].length - 1] *= ky;
2469 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2471 for (var j = 1, jj = p.length; j < jj; j++) {
2472 p[j] *= (j % 2) ? kx : ky;
2476 var dim2 = pathDimensions(path),
2477 dx = ncx - dim2.x - dim2.width / 2,
2478 dy = ncy - dim2.y - dim2.height / 2;
2479 path = pathToRelative(path);
2483 this.attr({path: path.join(" ")});
2486 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2487 if (this.transformations) {
2488 this.transformations[2] = "scale(".concat(dirx, ",", diry, ")");
2489 this.node.setAttribute("transform", this.transformations.join(" "));
2490 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2491 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2492 this.attr({x: dx, y: dy});
2496 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=".concat(dirx,
2497 ", M12=0, M21=0, M22=", diry,
2498 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2499 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2502 if (this.transformations) {
2503 this.transformations[2] = "";
2504 this.node.setAttribute("transform", this.transformations.join(" "));
2508 this.node.filterMatrix = "";
2509 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2512 a.scale = [x, y, cx, cy].join(" ");
2519 R.easing_formulas = {
2520 linear: function (n) {
2524 return Math.pow(n, 3);
2527 return Math.pow(n - 1, 3) + 1;
2529 "<>": function (n) {
2532 return Math.pow(n, 3) / 2;
2535 return (Math.pow(n, 3) + 2) / 2;
2537 backIn: function (n) {
2539 return Math.pow(n, 2) * ((s + 1) * n - s);
2541 backOut: function (n) {
2544 return Math.pow(n, 2) * ((s + 1) * n + s) + 1;
2546 elastic: function (n) {
2547 if (n == 0 || n == 1) {
2552 return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1;
2554 bounce: function (n) {
2559 l = s * Math.pow(n, 2);
2563 l = s * Math.pow(n, 2) + .75;
2565 if (n < (2.5 / p)) {
2567 l = s * Math.pow(n, 2) + .9375;
2570 l = s * Math.pow(n, 2) + .984375;
2578 // animation easing formulas
2579 R.easing = function(easing, n) {
2580 return R.easing_formulas[easing] ? R.easing_formulas[easing](n) : n;
2583 Element.prototype.animate = function (params, ms, easing, callback) {
2584 clearTimeout(this.animation_in_progress);
2585 if (typeof easing == "function" || !easing) {
2586 callback = easing || null;
2593 for (var attr in params) {
2594 if (attr in availableAnimAttrs) {
2595 from[attr] = this.attr(attr);
2596 (typeof from[attr] == "undefined") && (from[attr] = availableAttrs[attr]);
2597 to[attr] = params[attr];
2598 switch (availableAnimAttrs[attr]) {
2600 diff[attr] = (to[attr] - from[attr]) / ms;
2603 from[attr] = R.getRGB(from[attr]);
2604 var toColour = R.getRGB(to[attr]);
2606 r: (toColour.r - from[attr].r) / ms,
2607 g: (toColour.g - from[attr].g) / ms,
2608 b: (toColour.b - from[attr].b) / ms
2612 var pathes = pathEqualiser(from[attr], to[attr]);
2613 from[attr] = pathes[0];
2614 to[attr] = pathes[1];
2616 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2617 diff[attr][i] = [0];
2618 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2619 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2624 var values = (params[attr] + "").split(separator),
2625 from2 = (from[attr] + "").split(separator);
2628 from[attr] = [0, 0];
2629 diff[attr] = [values[0] / ms, values[1] / ms];
2632 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2633 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2636 params[attr] = values;
2637 from[attr] = (from[attr] + "").split(separator);
2638 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2644 var start = +new Date,
2648 var time = new Date - start,
2652 pos = R.easing(easing, time / ms);
2653 for (var attr in from) {
2654 switch (availableAnimAttrs[attr]) {
2656 now = +from[attr] + pos * ms * diff[attr];
2660 Math.round(from[attr].r + pos * ms * diff[attr].r),
2661 Math.round(from[attr].g + pos * ms * diff[attr].g),
2662 Math.round(from[attr].b + pos * ms * diff[attr].b)
2667 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2668 now[i] = [from[attr][i][0]];
2669 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2670 now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
2672 now[i] = now[i].join(" ");
2674 now = now.join(" ");
2679 var x = diff[attr][0] * (time - prev),
2680 y = diff[attr][1] * (time - prev);
2683 now = [x, y].join(" ");
2686 now = +from[attr][0] + pos * ms * diff[attr][0];
2687 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2690 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(" ");
2694 if (attr == "font-size") {
2695 set[attr] = now + "px";
2701 that.animation_in_progress = setTimeout(tick);
2702 R.svg && paper.safari();
2704 (t.x || t.y) && that.translate(-t.x, -t.y);
2706 clearTimeout(that.animation_in_progress);
2708 (typeof callback == "function") && callback.call(that);
2714 Element.prototype.translate = function (x, y) {
2716 return {x: this._.tx, y: this._.ty};
2720 switch (this.type) {
2723 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
2728 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
2731 var path = pathToRelative(this.attrs.path);
2734 this.attr({path: path.join(" ")});
2741 var Set = function (items) {
2745 for (var i = 0, ii = items.length; i < ii; i++) {
2746 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
2747 this[this.items.length] = this.items[this.items.length] = items[i];
2753 Set.prototype.push = function () {
2756 for (var i = 0, ii = arguments.length; i < ii; i++) {
2757 item = arguments[i];
2758 if (item && (item.constructor == Element || item.constructor == Set)) {
2759 len = this.items.length;
2760 this[len] = this.items[len] = item;
2766 Set.prototype.pop = function (id) {
2767 var res = this.items.splice(id, 1)[0];
2768 for (var j = id, jj = this.items.length; j < jj; j++) {
2769 this[j] = this[j + 1];
2771 delete this[jj + 1];
2775 for (var method in Element.prototype) {
2776 Set.prototype[method] = (function (methodname) {
2777 return function () {
2778 for (var i = 0, ii = this.items.length; i < ii; i++) {
2779 this.items[i][methodname].apply(this.items[i], arguments);
2785 Set.prototype.attr = function (name, value) {
2786 if (name && R.isArray(name) && typeof name[0] == "object") {
2787 for (var j = 0, jj = name.length; j < jj; j++) {
2788 this.items[j].attr(name[j]);
2791 for (var i = 0, ii = this.items.length; i < ii; i++) {
2792 this.items[i].attr.apply(this.items[i], arguments);
2798 Set.prototype.getBBox = function () {
2803 for (var i = this.items.length; i--;) {
2804 var box = this.items[i].getBBox();
2807 w.push(box.x + box.width);
2808 h.push(box.y + box.height);
2810 x = Math.min.apply(Math, x);
2811 y = Math.min.apply(Math, y);
2815 width: Math.max.apply(Math, w) - x,
2816 height: Math.max.apply(Math, h) - y
2820 R.registerFont = function (font) {
2824 this.fonts = this.fonts || {};
2830 family = font.face["font-family"];
2831 for (var prop in font.face) {
2832 fontcopy.face[prop] = font.face[prop];
2834 if (this.fonts[family]) {
2835 this.fonts[family].push(fontcopy);
2837 this.fonts[family] = [fontcopy];
2840 fontcopy.face["units-per-em"] = parseInt(font.face["units-per-em"], 10);
2841 for (var glyph in font.glyphs) {
2842 var path = font.glyphs[glyph];
2843 fontcopy.glyphs[glyph] = {
2846 d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
2847 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
2851 for (var k in path.k) {
2852 fontcopy.glyphs[glyph].k[k] = path.k[k];
2859 paper.getFont = function (family, weight, style, stretch) {
2860 stretch = stretch || "normal";
2861 style = style || "normal";
2862 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
2863 var font = R.fonts[family];
2865 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, "") + "(\\s|$)", "i");
2866 for (var fontName in R.fonts) {
2867 if (name.test(fontName)) {
2868 font = R.fonts[fontName];
2875 for (var i = 0, ii = font.length; i < ii; i++) {
2877 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
2884 paper.print = function (x, y, string, font, size) {
2885 var out = this.set(),
2886 letters = (string + "").split(""),
2891 scale = (size || 16) / font.face["units-per-em"];
2892 for (var i = 0, ii = letters.length; i < ii; i++) {
2893 var prev = i && font.glyphs[letters[i - 1]] || {},
2894 curr = font.glyphs[letters[i]];
2895 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
2896 curr && curr.d && out.push(this.path({fill: "#000", stroke: "none"}, curr.d).translate(shift, 0));
2898 out.scale(scale, scale, 0, y).translate(x, (size || 16) / 2);
2903 R.ninja = function () {
2904 var r = window.Raphael;
2905 if (oldRaphael.was) {
2906 window.Raphael = oldRaphael.is;
2909 delete window.Raphael;
2911 window.Raphael = void(0);
2916 R.el = Element.prototype;