2 * Raphael 0.8.5 - 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++) {
411 x += res[i][res[i].length - 1];
414 y += res[i][res[i].length - 1];
417 x += res[i][res[i].length - 2];
418 y += res[i][res[i].length - 1];
421 res.toString = pathArray.toString;
424 pathToAbsolute = function (pathArray) {
426 if (typeof pathArray == "string") {
427 pathArray = R.parsePathString(pathArray);
432 if (pathArray[0][0] == "M") {
433 x = +pathArray[0][1];
434 y = +pathArray[0][2];
436 res[0] = ["M", x, y];
438 for (var i = start, ii = pathArray.length; i < ii; i++) {
441 if (pa[0] != (pa[0] + "").toUpperCase()) {
442 r[0] = (pa[0] + "").toUpperCase();
450 r[6] = +(pa[6] + x).toFixed(3);
451 r[7] = +(pa[7] + y).toFixed(3);
460 for (var j = 1, jj = pa.length; j < jj; j++) {
461 r[j] = +pa[j] + ((j % 2) ? x : y);
466 for (var k = 0, kk = pa.length; k < kk; k++) {
480 x = res[i][res[i].length - 2];
481 y = res[i][res[i].length - 1];
484 res.toString = pathArray.toString;
487 pecache = {}, pecount = [],
488 pathEqualiser = function (path1, path2) {
489 if ((path1 + path2) in pecache) {
490 return pecache[path1 + path2];
492 var data = [pathToAbsolute(R.parsePathString(path1)), pathToAbsolute(R.parsePathString(path2))],
493 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}],
494 processPath = function (path, d) {
504 var nx = d.x + (d.x - (d.bx || d.x)),
505 ny = d.y + (d.y - (d.by || d.y));
506 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
509 var nx = d.x + (d.x - (d.bx || d.x)),
510 ny = d.y + (d.y - (d.by || d.y));
511 path = ["Q", nx, ny, path[1], path[2]];
514 path = ["L", path[1], d.y];
517 path = ["L", d.x, path[1]];
520 path = ["L", d.X, d.Y];
525 edgeCases = function (a, b, i) {
526 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
527 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
528 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
529 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
530 attrs[a].x = data[a][i][data[a][i].length - 2];
531 attrs[a].y = data[a][i][data[a][i].length - 1];
533 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
534 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]];
535 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
536 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
537 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
538 var x = data[b][i][data[b][i].length - 2],
539 y = data[b][i][data[b][i].length - 1];
540 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
541 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
543 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
544 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
545 attrs[b].x = data[b][i][data[b][i].length - 2];
546 attrs[b].y = data[b][i][data[b][i].length - 1];
548 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
549 var x = data[b][i][data[b][i].length - 2],
550 y = data[b][i][data[b][i].length - 1];
551 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
552 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
554 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
555 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
556 attrs[b].x = data[b][i][data[b][i].length - 2];
557 attrs[b].y = data[b][i][data[b][i].length - 1];
559 } else if (data[a][i][0] == "U") {
560 data[a][i][0] = data[b][i][0];
561 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
562 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
567 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
568 data[0][i] = processPath(data[0][i], attrs[0]);
569 data[1][i] = processPath(data[1][i], attrs[1]);
570 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
573 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
574 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
575 attrs[0].x = data[0][i][data[0][i].length - 2];
576 attrs[0].y = data[0][i][data[0][i].length - 1];
577 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
578 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
579 attrs[1].x = data[1][i][data[1][i].length - 2];
580 attrs[1].y = data[1][i][data[1][i].length - 1];
582 if (pecount.length > 20) {
583 delete pecache[pecount.unshift()];
585 pecount.push(path1 + path2);
586 pecache[path1 + path2] = data;
589 toGradient = function (gradient) {
590 if (typeof gradient == "string") {
591 gradient = gradient.split(/\s*\-\s*/);
592 var angle = gradient.shift();
593 if (angle.toLowerCase() == "v") {
595 } else if (angle.toLowerCase() == "h") {
598 angle = parseFloat(angle);
601 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)]},
602 max = 1 / (Math.max(Math.abs(grobj.vector[2]), Math.abs(grobj.vector[3])) || 1);
603 grobj.vector[2] *= max;
604 grobj.vector[3] *= max;
605 if (grobj.vector[2] < 0) {
606 grobj.vector[0] = -grobj.vector[2];
609 if (grobj.vector[3] < 0) {
610 grobj.vector[1] = -grobj.vector[3];
613 grobj.vector[0] = grobj.vector[0].toFixed(3);
614 grobj.vector[1] = grobj.vector[1].toFixed(3);
615 grobj.vector[2] = grobj.vector[2].toFixed(3);
616 grobj.vector[3] = grobj.vector[3].toFixed(3);
617 for (var i = 0, ii = gradient.length; i < ii; i++) {
619 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
620 dot.color = R.getRGB(par[1]).hex;
621 par[2] && (dot.offset = par[2] + "%");
622 grobj.dots.push(dot);
624 for (var i = 1, ii = grobj.dots.length - 1; i < ii; i++) {
625 if (!grobj.dots[i].offset) {
626 var start = parseFloat(grobj.dots[i - 1].offset || 0),
628 for (var j = i + 1; j < ii; j++) {
629 if (grobj.dots[j].offset) {
630 end = grobj.dots[j].offset;
638 end = parseFloat(end);
639 var d = (end - start) / (j - i + 1);
642 grobj.dots[i].offset = start + "%";
651 getContainer = function () {
657 if (typeof arguments[0] == "string" || typeof arguments[0] == "object") {
658 if (typeof arguments[0] == "string") {
659 container = doc.getElementById(arguments[0]);
661 container = arguments[0];
663 if (container.tagName) {
664 if (arguments[1] == null) {
666 container: container,
667 width: container.style.pixelWidth || container.offsetWidth,
668 height: container.style.pixelHeight || container.offsetHeight
671 return {container: container, width: arguments[1], height: arguments[2]};
674 } else if (typeof arguments[0] == "number" && arguments.length > 3) {
675 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
678 plugins = function (con, add) {
680 for (var prop in add) if (add.hasOwnProperty(prop) && !(prop in con)) {
681 switch (typeof add[prop]) {
684 con[prop] = con === that ? f : function () { return f.apply(that, arguments); };
688 con[prop] = con[prop] || {};
689 plugins.call(this, con[prop], add[prop]);
692 con[prop] = add[prop];
700 R.toString = function () {
701 return "Your browser supports SVG.\nYou are running Rapha\u00ebl " + this.version;
704 absolutely: function () {
705 this.isAbsolute = true;
708 relatively: function () {
709 this.isAbsolute = false;
712 moveTo: function (x, y) {
713 var d = this.isAbsolute ? "M" : "m";
714 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
715 var oldD = this[0].getAttribute("d") || "";
716 (oldD == "M0,0") && (oldD = "");
717 this[0].setAttribute("d", oldD + d);
718 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
719 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
720 this.attrs.path = oldD + d;
723 lineTo: function (x, y) {
724 this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(x);
725 this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(y);
726 var d = this.isAbsolute ? "L" : "l";
727 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
728 var oldD = this.node.getAttribute("d") || "";
729 this.node.setAttribute("d", oldD + d);
730 this.attrs.path = oldD + d;
733 arcTo: function (rx, ry, large_arc_flag, sweep_flag, x, y) {
734 var d = this.isAbsolute ? "A" : "a";
735 d += [parseFloat(rx).toFixed(3), parseFloat(ry).toFixed(3), 0, large_arc_flag, sweep_flag, parseFloat(x).toFixed(3), parseFloat(y).toFixed(3)].join(" ");
736 var oldD = this[0].getAttribute("d") || "";
737 this.node.setAttribute("d", oldD + d);
738 this.last.x = parseFloat(x);
739 this.last.y = parseFloat(y);
740 this.attrs.path = oldD + d;
743 cplineTo: function (x1, y1, w1) {
745 return this.lineTo(x1, y1);
751 d = this.isAbsolute ? "C" : "c",
752 attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
753 for (var i = 0, ii = attr.length; i < ii; i++) {
756 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
757 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
758 this.last.bx = attr[2];
759 this.last.by = attr[3];
760 var oldD = this.node.getAttribute("d") || "";
761 this.node.setAttribute("d", oldD + d);
762 this.attrs.path = oldD + d;
766 curveTo: function () {
768 d = [0, 1, 2, 3, "s", 5, "c"][arguments.length];
769 if (this.isAbsolute) {
772 for (var i = 0, ii = arguments.length; i < ii; i++) {
773 d += parseFloat(arguments[i]).toFixed(3) + " ";
775 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
776 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
777 this.last.bx = parseFloat(arguments[arguments.length - 4]);
778 this.last.by = parseFloat(arguments[arguments.length - 3]);
779 var oldD = this.node.getAttribute("d") || "";
780 this.node.setAttribute("d", oldD + d);
781 this.attrs.path = oldD + d;
784 qcurveTo: function () {
786 d = [0, 1, "t", 3, "q"][arguments.length];
787 if (this.isAbsolute) {
790 for (var i = 0, ii = arguments.length; i < ii; i++) {
791 d += parseFloat(arguments[i]).toFixed(3) + " ";
793 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
794 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
795 if (arguments.length != 2) {
796 this.last.qx = parseFloat(arguments[arguments.length - 4]);
797 this.last.qy = parseFloat(arguments[arguments.length - 3]);
799 var oldD = this.node.getAttribute("d") || "";
800 this.node.setAttribute("d", oldD + d);
801 this.attrs.path = oldD + d;
804 addRoundedCorner: addRoundedCorner,
805 andClose: function () {
806 var oldD = this[0].getAttribute("d") || "";
807 this[0].setAttribute("d", oldD + "Z ");
808 this.attrs.path = oldD + "Z ";
812 var thePath = function (params, pathString, SVG) {
813 var el = doc.createElementNS(SVG.svgns, "path");
815 SVG.canvas.appendChild(el);
817 var p = new Element(el, SVG);
819 for (var method in pathMethods) {
820 p[method] = pathMethods[method];
823 p.last = {x: 0, y: 0, bx: 0, by: 0};
825 p.attrs.path = "" + pathString;
827 paper.pathfinder(p, p.attrs.path);
830 !params.gradient && (params.fill = params.fill || "none");
831 params.stroke = params.stroke || "#000";
833 params = {fill: "none", stroke: "#000"};
835 setFillAndStroke(p, params);
838 var addGradientFill = function (o, gradient, SVG) {
839 gradient = toGradient(gradient);
840 var el = doc.createElementNS(SVG.svgns, (gradient.type || "linear") + "Gradient");
841 el.id = "raphael-gradient-" + R.idGenerator++;
842 if (gradient.vector && gradient.vector.length) {
843 el.setAttribute("x1", gradient.vector[0]);
844 el.setAttribute("y1", gradient.vector[1]);
845 el.setAttribute("x2", gradient.vector[2]);
846 el.setAttribute("y2", gradient.vector[3]);
848 SVG.defs.appendChild(el);
849 var isopacity = true;
850 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
851 var stop = doc.createElementNS(SVG.svgns, "stop");
852 if (gradient.dots[i].offset) {
855 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
856 stop.setAttribute("stop-color", R.getRGB(gradient.dots[i].color).hex || "#fff");
857 // ignoring opacity for internal points, because VML doesn't support it
858 el.appendChild(stop);
860 if (isopacity && typeof gradient.dots[ii - 1].opacity != "undefined") {
861 stop.setAttribute("stop-opacity", gradient.dots[ii - 1].opacity);
863 o.setAttribute("fill", "url(#" + el.id + ")");
866 o.style.fillOpacity = 1;
867 o.setAttribute("opacity", 1);
868 o.setAttribute("fill-opacity", 1);
870 var updatePosition = function (o) {
872 var bbox = o.getBBox();
873 o.pattern.setAttribute("patternTransform", "translate(".concat(bbox.x, ",", bbox.y, ")"));
876 var setFillAndStroke = function (o, params) {
881 "-..": [3, 1, 1, 1, 1, 1],
887 "--..": [8, 3, 1, 3, 1, 3]
891 rot = attrs.rotation,
892 addDashes = function (o, value) {
893 value = dasharray[value.toString().toLowerCase()];
895 var width = o.attrs["stroke-width"] || "1",
896 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
898 for (var i = 0, ii = value.length; i < ii; i++) {
899 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
901 value = dashes.join(",");
902 node.setAttribute("stroke-dasharray", value);
906 for (var att in params) {
907 if (!(att in availableAttrs)) {
910 var value = params[att];
917 var pn = node.parentNode;
918 if (pn.tagName.toLowerCase() != "a") {
919 var hl = doc.createElementNS(o.paper.svgns, "a");
920 pn.insertBefore(hl, node);
921 hl.appendChild(node);
924 pn.setAttributeNS(o.paper.xlink, att, value);
927 if (o.type == "path") {
928 node.setAttribute("d", "M0,0");
929 paper.pathfinder(o, value);
932 node.setAttribute(att, value);
941 value = -attrs.x - (attrs.width || 0);
945 node.setAttribute(att, value);
949 node.setAttribute(att, value);
958 value = -attrs.y - (attrs.height || 0);
962 node.setAttribute(att, value);
966 if (o.type == "rect") {
967 node.setAttribute("rx", value);
968 node.setAttribute("ry", value);
970 node.setAttribute(att, value);
974 if (o.type == "image") {
975 node.setAttributeNS(o.paper.xlink, "href", value);
979 node.style.strokeWidth = value;
980 // Need following line for Firefox
981 node.setAttribute(att, value);
982 if (attrs["stroke-dasharray"]) {
983 addDashes(o, attrs["stroke-dasharray"]);
986 case "stroke-dasharray":
990 o.rotate(value, true);
993 var xy = (value + "").split(separator);
994 o.translate((+xy[0] + 1 || 2) - 1, (+xy[1] + 1 || 2) - 1);
997 var xy = (value + "").split(separator);
998 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1001 var isURL = (value + "").match(/^url\(([^\)]+)\)$/i);
1003 var el = doc.createElementNS(o.paper.svgns, "pattern"),
1004 ig = doc.createElementNS(o.paper.svgns, "image");
1005 el.id = "raphael-pattern-" + R.idGenerator++;
1006 el.setAttribute("x", 0);
1007 el.setAttribute("y", 0);
1008 el.setAttribute("patternUnits", "userSpaceOnUse");
1009 ig.setAttribute("x", 0);
1010 ig.setAttribute("y", 0);
1011 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1014 var img = doc.createElement("img");
1015 img.style.position = "absolute";
1016 img.style.top = "-9999em";
1017 img.style.left = "-9999em";
1018 img.onload = function () {
1019 el.setAttribute("width", this.offsetWidth);
1020 el.setAttribute("height", this.offsetHeight);
1021 ig.setAttribute("width", this.offsetWidth);
1022 ig.setAttribute("height", this.offsetHeight);
1023 doc.body.removeChild(this);
1026 doc.body.appendChild(img);
1028 o.paper.defs.appendChild(el);
1029 node.style.fill = "url(#" + el.id + ")";
1030 node.setAttribute("fill", "url(#" + el.id + ")");
1035 delete params.gradient;
1036 delete attrs.gradient;
1037 if (typeof attrs.opacity != "undefined" && typeof params.opacity == "undefined" ) {
1038 node.style.opacity = attrs.opacity;
1039 // Need following line for Firefox
1040 node.setAttribute("opacity", attrs.opacity);
1042 if (typeof attrs["fill-opacity"] != "undefined" && typeof params["fill-opacity"] == "undefined" ) {
1043 node.style.fillOpacity = o.attrs["fill-opacity"];
1044 // Need following line for Firefox
1045 node.setAttribute("fill-opacity", attrs["fill-opacity"]);
1048 node.style[att] = R.getRGB(value).hex;
1049 // Need following line for Firefox
1050 node.setAttribute(att, R.getRGB(value).hex);
1053 addGradientFill(node, value, o.paper);
1056 case "fill-opacity":
1057 if (attrs.gradient) {
1058 var gradient = doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
1060 var stops = gradient.getElementsByTagName("stop");
1061 stops[stops.length - 1].setAttribute("stop-opacity", value);
1066 var cssrule = att.replace(/(\-.)/g, function (w) {
1067 return w.substring(1).toUpperCase();
1069 node.style[cssrule] = value;
1070 // Need following line for Firefox
1071 node.setAttribute(att, value);
1076 tuneText(o, params);
1077 o.rotate(attrs.rotation, true);
1080 var tuneText = function (el, params) {
1081 if (el.type != "text" || !("text" in params || "font" in params || "font-size" in params || "x" in params || "y" in params)) {
1086 fontSize = node.firstChild ? parseInt(doc.defaultView.getComputedStyle(node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
1088 if ("text" in params) {
1089 while (node.firstChild) {
1090 node.removeChild(node.firstChild);
1092 var texts = (params.text + "").split("\n");
1093 for (var i = 0, ii = texts.length; i < ii; i++) {
1094 var tspan = doc.createElementNS(el.paper.svgns, "tspan");
1095 i && tspan.setAttribute("dy", fontSize * leading);
1096 i && tspan.setAttribute("x", a.x);
1097 tspan.appendChild(doc.createTextNode(texts[i]));
1098 node.appendChild(tspan);
1101 var texts = node.getElementsByTagName("tspan");
1102 for (var i = 0, ii = texts.length; i < ii; i++) {
1103 i && texts[i].setAttribute("dy", fontSize * leading);
1104 i && texts[i].setAttribute("x", a.x);
1107 node.setAttribute("y", a.y);
1108 var bb = el.getBBox(),
1109 dif = a.y - (bb.y + bb.height / 2);
1110 dif && node.setAttribute("y", a.y + dif);
1112 var Element = function (node, svg) {
1118 this.attrs = this.attrs || {};
1119 this.transformations = []; // rotate, translate, scale
1123 rt: {deg: 0, x: 0, y: 0},
1128 Element.prototype.rotate = function (deg, cx, cy) {
1130 return this._.rt.deg;
1132 var bbox = this.getBBox();
1133 deg = deg.toString().split(separator);
1134 if (deg.length - 1) {
1135 cx = parseFloat(deg[1]);
1136 cy = parseFloat(deg[2]);
1138 deg = parseFloat(deg[0]);
1140 this._.rt.deg = deg;
1142 this._.rt.deg += deg;
1147 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1148 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1149 if (this._.rt.deg) {
1150 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
1152 this.transformations[0] = "";
1154 this.node.setAttribute("transform", this.transformations.join(" "));
1157 Element.prototype.hide = function () {
1158 this.node.style.display = "none";
1161 Element.prototype.show = function () {
1162 this.node.style.display = "block";
1165 Element.prototype.remove = function () {
1166 this.node.parentNode.removeChild(this.node);
1168 Element.prototype.getBBox = function () {
1169 if (this.node.style.display == "none") {
1173 var bbox = this.node.getBBox() || {};
1174 if (this.type == "text") {
1175 bbox = {x: bbox.x, y: Infinity, width: bbox.width, height: 0};
1176 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1177 var bb = this.node.getExtentOfChar(i);
1178 (bb.y < bbox.y) && (bbox.y = bb.y);
1179 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1182 hide && this.hide();
1185 Element.prototype.attr = function () {
1186 if (arguments.length == 1 && typeof arguments[0] == "string") {
1187 if (arguments[0] == "translation") {
1188 return this.translate();
1190 return this.attrs[arguments[0]];
1192 if (arguments.length == 1 && R.isArray(arguments[0])) {
1194 for (var j in arguments[0]) {
1195 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1199 if (arguments.length == 2) {
1201 params[arguments[0]] = arguments[1];
1202 setFillAndStroke(this, params);
1203 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1204 setFillAndStroke(this, arguments[0]);
1208 Element.prototype.toFront = function () {
1209 this.node.parentNode.appendChild(this.node);
1212 Element.prototype.toBack = function () {
1213 if (this.node.parentNode.firstChild != this.node) {
1214 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1218 Element.prototype.insertAfter = function (element) {
1219 if (element.node.nextSibling) {
1220 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1222 element.node.parentNode.appendChild(this.node);
1226 Element.prototype.insertBefore = function (element) {
1227 var node = element.node;
1228 node.parentNode.insertBefore(this.node, node);
1231 var theCircle = function (svg, x, y, r) {
1232 var el = doc.createElementNS(svg.svgns, "circle");
1233 el.setAttribute("cx", x);
1234 el.setAttribute("cy", y);
1235 el.setAttribute("r", r);
1236 el.setAttribute("fill", "none");
1237 el.setAttribute("stroke", "#000");
1239 svg.canvas.appendChild(el);
1241 var res = new Element(el, svg);
1242 res.attrs = res.attrs || {};
1246 res.attrs.stroke = "#000";
1247 res.type = "circle";
1250 var theRect = function (svg, x, y, w, h, r) {
1251 var el = doc.createElementNS(svg.svgns, "rect");
1252 el.setAttribute("x", x);
1253 el.setAttribute("y", y);
1254 el.setAttribute("width", w);
1255 el.setAttribute("height", h);
1257 el.setAttribute("rx", r);
1258 el.setAttribute("ry", r);
1260 el.setAttribute("fill", "none");
1261 el.setAttribute("stroke", "#000");
1263 svg.canvas.appendChild(el);
1265 var res = new Element(el, svg);
1266 res.attrs = res.attrs || {};
1269 res.attrs.width = w;
1270 res.attrs.height = h;
1271 res.attrs.stroke = "#000";
1273 res.attrs.rx = res.attrs.ry = r;
1278 var theEllipse = function (svg, x, y, rx, ry) {
1279 var el = doc.createElementNS(svg.svgns, "ellipse");
1280 el.setAttribute("cx", x);
1281 el.setAttribute("cy", y);
1282 el.setAttribute("rx", rx);
1283 el.setAttribute("ry", ry);
1284 el.setAttribute("fill", "none");
1285 el.setAttribute("stroke", "#000");
1287 svg.canvas.appendChild(el);
1289 var res = new Element(el, svg);
1290 res.attrs = res.attrs || {};
1295 res.attrs.stroke = "#000";
1296 res.type = "ellipse";
1299 var theImage = function (svg, src, x, y, w, h) {
1300 var el = doc.createElementNS(svg.svgns, "image");
1301 el.setAttribute("x", x);
1302 el.setAttribute("y", y);
1303 el.setAttribute("width", w);
1304 el.setAttribute("height", h);
1305 el.setAttribute("preserveAspectRatio", "none");
1306 el.setAttributeNS(svg.xlink, "href", src);
1308 svg.canvas.appendChild(el);
1310 var res = new Element(el, svg);
1311 res.attrs = res.attrs || {};
1314 res.attrs.width = w;
1315 res.attrs.height = h;
1319 var theText = function (svg, x, y, text) {
1320 var el = doc.createElementNS(svg.svgns, "text");
1321 el.setAttribute("x", x);
1322 el.setAttribute("y", y);
1323 el.setAttribute("text-anchor", "middle");
1325 svg.canvas.appendChild(el);
1327 var res = new Element(el, svg);
1328 res.attrs = res.attrs || {};
1332 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000", text: text});
1335 var setSize = function (width, height) {
1336 this.width = width || this.width;
1337 this.height = height || this.height;
1338 this.canvas.setAttribute("width", this.width);
1339 this.canvas.setAttribute("height", this.height);
1342 var create = function () {
1343 var con = getContainer.apply(null, arguments),
1344 container = con.container,
1348 height = con.height;
1350 throw new Error("SVG container not found.");
1352 paper.canvas = doc.createElementNS(paper.svgns, "svg");
1353 paper.canvas.setAttribute("width", width || 512);
1354 paper.width = width || 512;
1355 paper.canvas.setAttribute("height", height || 342);
1356 paper.height = height || 342;
1357 if (container == 1) {
1358 doc.body.appendChild(paper.canvas);
1359 paper.canvas.style.position = "absolute";
1360 paper.canvas.style.left = x + "px";
1361 paper.canvas.style.top = y + "px";
1363 if (container.firstChild) {
1364 container.insertBefore(paper.canvas, container.firstChild);
1366 container.appendChild(paper.canvas);
1370 canvas: paper.canvas,
1371 clear: function () {
1372 while (this.canvas.firstChild) {
1373 this.canvas.removeChild(this.canvas.firstChild);
1375 this.defs = doc.createElementNS(paper.svgns, "defs");
1376 this.canvas.appendChild(this.defs);
1379 for (var prop in paper) {
1380 if (prop != "create") {
1381 container[prop] = paper[prop];
1384 plugins.call(container, container, R.fn);
1386 container.raphael = R;
1389 paper.remove = function () {
1390 this.canvas.parentNode.removeChild(this.canvas);
1392 paper.svgns = "http://www.w3.org/2000/svg";
1393 paper.xlink = "http://www.w3.org/1999/xlink";
1394 paper.safari = function () {
1395 if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) {
1396 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1397 setTimeout(function () {rect.remove();});
1404 R.toString = function () {
1405 return "Your browser doesn\u2019t support SVG. Assuming it is Internet Explorer and falling down to VML.\nYou are running Rapha\u00ebl " + this.version;
1408 absolutely: function () {
1409 this.isAbsolute = true;
1412 relatively: function () {
1413 this.isAbsolute = false;
1416 moveTo: function (x, y) {
1417 var X = Math.round(parseFloat(x)) - 1,
1418 Y = Math.round(parseFloat(y)) - 1,
1419 d = this.isAbsolute ? "m" : "t";
1421 this.node.path = this.Path += d;
1422 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1423 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1424 this.last.isAbsolute = this.isAbsolute;
1425 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1428 lineTo: function (x, y) {
1429 var X = Math.round(parseFloat(x)) - 1,
1430 Y = Math.round(parseFloat(y)) - 1,
1431 d = this.isAbsolute ? "l" : "r";
1433 this.node.path = this.Path += d;
1434 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1435 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1436 this.last.isAbsolute = this.isAbsolute;
1437 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1440 arcTo: function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1441 // for more information of where this math came from visit:
1442 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1443 x2 = (this.isAbsolute ? 0 : this.last.x) + x2 - 1;
1444 y2 = (this.isAbsolute ? 0 : this.last.y) + y2 - 1;
1445 var x1 = this.last.x - 1,
1446 y1 = this.last.y - 1,
1449 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1450 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1451 cx = k * rx * y / ry + (x1 + x2) / 2,
1452 cy = k * -ry * x / rx + (y1 + y2) / 2,
1453 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1454 left = Math.round(cx - rx),
1455 top = Math.round(cy - ry);
1456 d += [left, top, Math.round(left + rx * 2), Math.round(top + ry * 2), Math.round(x1), Math.round(y1), Math.round(parseFloat(x2)), Math.round(parseFloat(y2))].join(", ");
1457 this.node.path = this.Path += d;
1458 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2);
1459 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2);
1460 this.last.isAbsolute = this.isAbsolute;
1461 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1464 cplineTo: function (x1, y1, w1) {
1466 return this.lineTo(x1, y1);
1468 var x = Math.round(parseFloat(x1)) - 1,
1469 y = Math.round(parseFloat(y1)) - 1,
1470 w = Math.round(parseFloat(w1)),
1471 d = this.isAbsolute ? "c" : "v",
1472 attr = [Math.round(this.last.x) - 1 + w, Math.round(this.last.y) - 1, x - w, y, x, y],
1473 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1474 d += attr.join(" ") + " ";
1475 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1476 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1477 this.last.bx = attr[2];
1478 this.last.by = attr[3];
1479 this.node.path = this.Path += d;
1480 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1484 curveTo: function () {
1485 var d = this.isAbsolute ? "c" : "v";
1486 if (arguments.length == 6) {
1487 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1488 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1489 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4]);
1490 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5]);
1491 d += [Math.round(parseFloat(arguments[0])) - 1,
1492 Math.round(parseFloat(arguments[1])) - 1,
1493 Math.round(parseFloat(arguments[2])) - 1,
1494 Math.round(parseFloat(arguments[3])) - 1,
1495 Math.round(parseFloat(arguments[4])) - 1,
1496 Math.round(parseFloat(arguments[5])) - 1].join(" ") + " ";
1497 this.last.isAbsolute = this.isAbsolute;
1498 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1500 if (arguments.length == 4) {
1501 var bx = this.last.x * 2 - this.last.bx,
1502 by = this.last.y * 2 - this.last.by;
1503 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0]);
1504 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1]);
1505 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1506 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1507 d += [Math.round(bx) - 1, Math.round(by) - 1,
1508 Math.round(parseFloat(arguments[0])) - 1,
1509 Math.round(parseFloat(arguments[1])) - 1,
1510 Math.round(parseFloat(arguments[2])) - 1,
1511 Math.round(parseFloat(arguments[3])) - 1].join(" ") + " ";
1512 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1514 this.node.path = this.Path += d;
1517 qcurveTo: function () {
1518 var lx = Math.round(this.last.x) - 1,
1519 ly = Math.round(this.last.y) - 1,
1521 if (arguments.length == 4) {
1522 this.last.qx = (!this.isAbsolute * this.last.x) + parseFloat(arguments[0]);
1523 this.last.qy = (!this.isAbsolute * this.last.y) + parseFloat(arguments[1]);
1524 this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(arguments[2]);
1525 this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(arguments[3]);
1526 res = [this.last.qx, this.last.qy, this.last.x, this.last.y];
1527 this.last.isAbsolute = this.isAbsolute;
1528 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1530 if (arguments.length == 2) {
1531 this.last.qx = this.last.x * 2 - this.last.qx;
1532 this.last.qy = this.last.y * 2 - this.last.qy;
1533 this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(arguments[2]);
1534 this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(arguments[3]);
1535 res = [this.last.qx, this.last.qy, this.last.x, this.last.y];
1536 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1539 Math.round(2 / 3 * res[0] + 1 / 3 * lx) - 1,
1540 Math.round(2 / 3 * res[1] + 1 / 3 * ly) - 1,
1541 Math.round(2 / 3 * res[0] + 1 / 3 * res[2]) - 1,
1542 Math.round(2 / 3 * res[1] + 1 / 3 * res[3]) - 1,
1543 Math.round(res[2]) - 1,
1544 Math.round(res[3]) - 1
1546 this.node.path = this.Path += d;
1549 addRoundedCorner: addRoundedCorner,
1550 andClose: function () {
1551 this.node.path = (this.Path += "x");
1552 this.attrs.path += "z";
1556 var thePath = function (params, pathString, VML) {
1557 var g = createNode("group"), gl = g.style;
1558 gl.position = "absolute";
1561 gl.width = VML.width + "px";
1562 gl.height = VML.height + "px";
1563 g.coordsize = VML.coordsize;
1564 g.coordorigin = VML.coordorigin;
1565 var el = createNode("shape"), ol = el.style;
1566 ol.width = VML.width + "px";
1567 ol.height = VML.height + "px";
1569 if (params["class"]) {
1570 el.className = "rvml " + params["class"];
1572 el.coordsize = this.coordsize;
1573 el.coordorigin = this.coordorigin;
1575 var p = new Element(el, g, VML);
1576 p.isAbsolute = true;
1579 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1581 for (var method in pathMethods) {
1582 p[method] = pathMethods[method];
1588 paper.pathfinder(p, "" + pathString);
1591 params.fill = params.fill || "none";
1592 params.stroke = params.stroke || "#000";
1594 params = {fill: "none", stroke: "#000"};
1596 setFillAndStroke(p, params);
1597 if (params.gradient) {
1598 addGradientFill(p, params.gradient);
1601 VML.canvas.appendChild(g);
1604 var setFillAndStroke = function (o, params) {
1609 o.attrs = o.attrs || {};
1610 for (var par in params) {
1611 o.attrs[par] = params[par];
1613 params.href && (node.href = params.href);
1614 params.title && (node.title = params.title);
1615 params.target && (node.target = params.target);
1616 if (params.path && o.type == "path") {
1619 paper.pathfinder(o, params.path);
1621 if (params.rotation != null) {
1622 o.rotate(params.rotation, true);
1624 if (params.translation) {
1625 xy = (params.translation + "").split(separator);
1626 o.translate(xy[0], xy[1]);
1629 xy = (params.scale + "").split(separator);
1630 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1632 if (o.type == "image" && params.src) {
1633 node.src = params.src;
1635 if (o.type == "image" && params.opacity) {
1636 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1637 node.style.filter = (node.filterMatrix || "") + (node.filterOpacity || "");
1639 params.font && (s.font = params.font);
1640 params["font-family"] && (s.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, "") + '"');
1641 params["font-size"] && (s.fontSize = params["font-size"]);
1642 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1643 params["font-style"] && (s.fontStyle = params["font-style"]);
1644 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"]) {
1645 o = o.shape || node;
1646 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || createNode("fill");
1647 if ("fill-opacity" in params || "opacity" in params) {
1648 var opacity = ((+params["fill-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1649 opacity < 0 && (opacity = 0);
1650 opacity > 1 && (opacity = 1);
1651 fill.opacity = opacity;
1653 params.fill && (fill.on = true);
1654 if (typeof fill.on == "undefined" || params.fill == "none") {
1657 if (fill.on && params.fill) {
1658 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1660 fill.src = isURL[1];
1663 fill.color = R.getRGB(params.fill).hex;
1665 fill.type = "solid";
1668 o.appendChild(fill);
1669 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || createNode("stroke");
1670 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"]) {
1673 if (params.stroke == "none" || typeof stroke.on == "undefined" || params.stroke == 0) {
1676 if (stroke.on && params.stroke) {
1677 stroke.color = R.getRGB(params.stroke).hex;
1679 var opacity = ((+params["stroke-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1680 opacity < 0 && (opacity = 0);
1681 opacity > 1 && (opacity = 1);
1682 stroke.opacity = opacity;
1683 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1684 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1685 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1686 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"]) || 1) * 12 / 16);
1687 if (params["stroke-dasharray"]) {
1691 "-.": "shortdashdot",
1692 "-..": "shortdashdotdot",
1697 "--.": "longdashdot",
1698 "--..": "longdashdotdot"
1700 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1702 o.appendChild(stroke);
1704 if (res.type == "text") {
1705 var s = paper.span.style,
1707 a.font && (s.font = a.font);
1708 a["font-family"] && (s.fontFamily = a["font-family"]);
1709 a["font-size"] && (s.fontSize = a["font-size"]);
1710 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1711 a["font-style"] && (s.fontStyle = a["font-style"]);
1712 paper.span.innerText = res.node.string;
1713 res.W = a.w = paper.span.offsetWidth;
1714 res.H = a.h = paper.span.offsetHeight;
1716 res.Y = a.y + Math.round(res.H / 2);
1718 // text-anchor emulation
1719 switch (a["text-anchor"]) {
1721 res.node.style["v-text-align"] = "left";
1722 res.bbx = Math.round(res.W / 2);
1725 res.node.style["v-text-align"] = "right";
1726 res.bbx = -Math.round(res.W / 2);
1729 res.node.style["v-text-align"] = "center";
1734 var getAngle = function (a, b, c, d) {
1735 var angle = Math.round(Math.atan((parseFloat(c) - parseFloat(a)) / (parseFloat(d) - parseFloat(b))) * 57.29) || 0;
1736 if (!angle && parseFloat(a) < parseFloat(b)) {
1745 var addGradientFill = function (o, gradient) {
1746 gradient = toGradient(gradient);
1747 o.attrs = o.attrs || {};
1748 var attrs = o.attrs,
1749 fill = o.getElementsByTagName("fill");
1750 o.attrs.gradient = gradient;
1751 o = o.shape || o[0];
1755 fill = createNode("fill");
1757 if (gradient.dots.length) {
1759 fill.method = "none";
1760 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1761 if (typeof gradient.dots[0].color != "undefined") {
1762 fill.color = R.getRGB(gradient.dots[0].color).hex;
1764 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1765 fill.color2 = R.getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1768 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1769 if (gradient.dots[i].offset) {
1770 clrs.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
1773 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;
1775 fill.colors.value = clrs.join(",");
1776 fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
1778 fill.colors && (fill.colors.value = "0% " + fill.color);
1780 fill.opacity = fillOpacity;
1781 if (typeof gradient.angle != "undefined") {
1782 fill.angle = (-gradient.angle + 270) % 360;
1783 } else if (gradient.vector) {
1784 fill.angle = getAngle.apply(null, gradient.vector);
1786 if ((gradient.type + "").toLowerCase() == "radial") {
1787 fill.focus = "100%";
1788 fill.focusposition = "0.5 0.5";
1792 var Element = function (node, group, vml) {
1812 Element.prototype.rotate = function (deg, cx, cy) {
1814 return this._.rt.deg;
1816 deg = (deg + "").split(separator);
1817 if (deg.length - 1) {
1818 cx = parseFloat(deg[1]);
1819 cy = parseFloat(deg[2]);
1821 deg = parseFloat(deg[0]);
1823 this._.rt.deg = deg;
1825 this._.rt.deg += deg;
1832 this.setBox(this.attrs, cx, cy);
1833 this.Group.style.rotation = this._.rt.deg;
1834 // gradient fix for rotation. TODO
1835 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1836 // fill = fill[0] || {};
1837 // var b = ((360 - this._.rt.deg) - 270) % 360;
1838 // typeof fill.angle != "undefined" && (fill.angle = b);
1841 Element.prototype.setBox = function (params, cx, cy) {
1842 var gs = this.Group.style,
1843 os = (this.shape && this.shape.style) || this.node.style;
1844 params = params || {};
1845 for (var i in params) {
1846 this.attrs[i] = params[i];
1848 cx = cx || this._.rt.cx;
1849 cy = cy || this._.rt.cy;
1850 var attr = this.attrs,
1855 switch (this.type) {
1857 x = attr.cx - attr.r;
1858 y = attr.cy - attr.r;
1862 x = attr.cx - attr.rx;
1863 y = attr.cy - attr.ry;
1871 w = attr.width || 0;
1872 h = attr.height || 0;
1875 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("");
1876 x = attr.x - Math.round(this.W / 2);
1877 y = attr.y - this.H / 2;
1882 if (!this.attrs.path) {
1885 w = this.paper.width;
1886 h = this.paper.height;
1888 var dim = pathDimensions(this.attrs.path),
1898 w = this.paper.width;
1899 h = this.paper.height;
1902 cx = (cx == null) ? x + w / 2 : cx;
1903 cy = (cy == null) ? y + h / 2 : cy;
1904 var left = cx - this.paper.width / 2,
1905 top = cy - this.paper.height / 2;
1906 if (this.type == "path" || this.type == "text") {
1907 (gs.left != left + "px") && (gs.left = left + "px");
1908 (gs.top != top + "px") && (gs.top = top + "px");
1909 this.X = this.type == "text" ? x : -left;
1910 this.Y = this.type == "text" ? y : -top;
1913 (os.left != -left + "px") && (os.left = -left + "px");
1914 (os.top != -top + "px") && (os.top = -top + "px");
1916 (gs.left != left + "px") && (gs.left = left + "px");
1917 (gs.top != top + "px") && (gs.top = top + "px");
1922 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
1923 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
1924 (os.left != x - left + "px") && (os.left = x - left + "px");
1925 (os.top != y - top + "px") && (os.top = y - top + "px");
1926 (os.width != w + "px") && (os.width = w + "px");
1927 (os.height != h + "px") && (os.height = h + "px");
1928 var arcsize = (+params.r || 0) / (Math.min(w, h));
1929 if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
1930 // We should replace element with the new one
1931 var o = createNode(arcsize ? "roundrect" : "rect");
1932 o.arcsize = arcsize;
1933 this.Group.appendChild(o);
1934 this.node.parentNode.removeChild(this.node);
1936 this.arcsize = arcsize;
1937 setFillAndStroke(this, this.attrs);
1938 this.setBox(this.attrs);
1942 Element.prototype.hide = function () {
1943 this.Group.style.display = "none";
1946 Element.prototype.show = function () {
1947 this.Group.style.display = "block";
1950 Element.prototype.getBBox = function () {
1951 if (this.type == "path") {
1952 return pathDimensions(this.attr("path"));
1955 x: this.X + (this.bbx || 0),
1961 Element.prototype.remove = function () {
1962 this[0].parentNode.removeChild(this[0]);
1963 this.Group.parentNode.removeChild(this.Group);
1964 this.shape && this.shape.parentNode.removeChild(this.shape);
1966 Element.prototype.attr = function () {
1967 if (arguments.length == 1 && typeof arguments[0] == "string") {
1968 if (arguments[0] == "translation") {
1969 return this.translate();
1971 return this.attrs[arguments[0]];
1973 if (this.attrs && arguments.length == 1 && R.isArray(arguments[0])) {
1975 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1976 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1981 if (arguments.length == 2) {
1983 params[arguments[0]] = arguments[1];
1985 if (arguments.length == 1 && typeof arguments[0] == "object") {
1986 params = arguments[0];
1989 if (params.gradient) {
1990 addGradientFill(this, params.gradient);
1992 if (params.text && this.type == "text") {
1993 this.node.string = params.text;
1995 setFillAndStroke(this, params);
1996 this.setBox(this.attrs);
2000 Element.prototype.toFront = function () {
2001 this.Group.parentNode.appendChild(this.Group);
2004 Element.prototype.toBack = function () {
2005 if (this.Group.parentNode.firstChild != this.Group) {
2006 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2010 Element.prototype.insertAfter = function (element) {
2011 if (element.Group.nextSibling) {
2012 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2014 element.Group.parentNode.appendChild(this.Group);
2018 Element.prototype.insertBefore = function (element) {
2019 element.Group.parentNode.insertBefore(this.Group, element.Group);
2022 var theCircle = function (vml, x, y, r) {
2023 var g = createNode("group"),
2025 o = createNode("oval"),
2027 gl.position = "absolute";
2030 gl.width = vml.width + "px";
2031 gl.height = vml.height + "px";
2032 g.coordsize = vml.coordsize;
2033 g.coordorigin = vml.coordorigin;
2035 var res = new Element(o, g, vml);
2036 res.type = "circle";
2037 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2041 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2042 vml.canvas.appendChild(g);
2045 var theRect = function (vml, x, y, w, h, r) {
2046 var g = createNode("group"),
2048 o = createNode(r ? "roundrect" : "rect"),
2049 arcsize = (+r || 0) / (Math.min(w, h));
2050 o.arcsize = arcsize;
2051 gl.position = "absolute";
2054 gl.width = vml.width + "px";
2055 gl.height = vml.height + "px";
2056 g.coordsize = vml.coordsize;
2057 g.coordorigin = vml.coordorigin;
2059 var res = new Element(o, g, vml);
2061 setFillAndStroke(res, {stroke: "#000"});
2062 res.arcsize = arcsize;
2063 res.setBox({x: x, y: y, width: w, height: h, r: +r});
2064 vml.canvas.appendChild(g);
2067 var theEllipse = function (vml, x, y, rx, ry) {
2068 var g = createNode("group"),
2070 o = createNode("oval"),
2072 gl.position = "absolute";
2075 gl.width = vml.width + "px";
2076 gl.height = vml.height + "px";
2077 g.coordsize = vml.coordsize;
2078 g.coordorigin = vml.coordorigin;
2080 var res = new Element(o, g, vml);
2081 res.type = "ellipse";
2082 setFillAndStroke(res, {stroke: "#000"});
2087 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2088 vml.canvas.appendChild(g);
2091 var theImage = function (vml, src, x, y, w, h) {
2092 var g = createNode("group"),
2094 o = createNode("image"),
2096 gl.position = "absolute";
2099 gl.width = vml.width + "px";
2100 gl.height = vml.height + "px";
2101 g.coordsize = vml.coordsize;
2102 g.coordorigin = vml.coordorigin;
2105 var res = new Element(o, g, vml);
2111 res.setBox({x: x, y: y, width: w, height: h});
2112 vml.canvas.appendChild(g);
2115 var theText = function (vml, x, y, text) {
2116 var g = createNode("group"),
2118 el = createNode("shape"),
2120 path = createNode("path"),
2122 o = createNode("textpath");
2123 gs.position = "absolute";
2126 gs.width = vml.width + "px";
2127 gs.height = vml.height + "px";
2128 g.coordsize = vml.coordsize;
2129 g.coordorigin = vml.coordorigin;
2130 path.v = ["m", Math.round(x), ", ", Math.round(y), "l", Math.round(x) + 1, ", ", Math.round(y)].join("");
2131 path.textpathok = true;
2132 ol.width = vml.width;
2133 ol.height = vml.height;
2134 gs.position = "absolute";
2137 gs.width = vml.width;
2138 gs.height = vml.height;
2142 el.appendChild(path);
2144 var res = new Element(o, g, vml);
2146 res.textpath = path;
2152 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2154 vml.canvas.appendChild(g);
2157 var setSize = function (width, height) {
2158 var cs = this.canvas.style;
2159 this.width = width || this.width;
2160 this.height = height || this.height;
2161 cs.width = this.width + "px";
2162 cs.height = this.height + "px";
2163 cs.clip = "rect(0 " + this.width + "px " + this.height + "px 0)";
2164 this.canvas.coordsize = this.width + " " + this.height;
2167 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2169 if (!doc.namespaces.rvml) {
2170 doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2172 var createNode = function (tagName) {
2173 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2176 var createNode = function (tagName) {
2177 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2180 var create = function () {
2181 var con = getContainer.apply(null, arguments),
2182 container = con.container,
2187 height = con.height;
2189 throw new Error("VML container not found.");
2191 var c = paper.canvas = doc.createElement("div"),
2193 width = parseFloat(width) || "512px";
2194 height = parseFloat(height) || "342px";
2195 paper.width = width;
2196 paper.height = height;
2197 paper.coordsize = width + " " + height;
2198 paper.coordorigin = "0 0";
2199 paper.span = doc.createElement("span");
2200 s = paper.span.style;
2201 c.appendChild(paper.span);
2202 s.position = "absolute";
2203 s.left = "-99999px";
2208 s.display = "inline";
2209 cs.width = width + "px";
2210 cs.height = height + "px";
2211 cs.position = "absolute";
2212 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2213 if (container == 1) {
2214 doc.body.appendChild(c);
2224 container.style.width = width;
2225 container.style.height = height;
2226 if (container.firstChild) {
2227 container.insertBefore(c, container.firstChild);
2229 container.appendChild(c);
2232 for (var prop in paper) {
2233 container[prop] = paper[prop];
2235 plugins.call(container, container, R.fn);
2236 container.clear = function () {
2237 while (c.firstChild) {
2238 c.removeChild(c.firstChild);
2241 container.raphael = R;
2244 paper.remove = function () {
2245 this.canvas.parentNode.removeChild(this.canvas);
2247 paper.safari = function () {};
2253 var addEvent = (function () {
2254 if (doc.addEventListener) {
2255 return function (obj, type, fn, element) {
2256 var f = function (e) {
2257 return fn.call(element, e);
2259 obj.addEventListener(type, f, false);
2260 return function () {
2261 obj.removeEventListener(type, f, false);
2265 } else if (doc.attachEvent) {
2266 return function (obj, type, fn, element) {
2267 var f = function (e) {
2268 return fn.call(element, e || win.event);
2270 obj.attachEvent("on" + type, f);
2271 var detacher = function () {
2272 obj.detachEvent("on" + type, f);
2275 if (type == "mouseover") {
2276 obj.attachEvent("onmouseenter", f);
2277 return function () {
2278 obj.detachEvent("onmouseenter", f);
2281 } else if (type == "mouseout") {
2282 obj.attachEvent("onmouseleave", f);
2283 return function () {
2284 obj.detachEvent("onmouseleave", f);
2292 for (var i = events.length; i--;) {
2293 (function (eventName) {
2294 Element.prototype[eventName] = function (fn) {
2295 if (typeof fn == "function") {
2296 this.events = this.events || {};
2297 this.events[eventName] = this.events[eventName] || {};
2298 this.events[eventName][fn] = this.events[eventName][fn] || [];
2299 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2303 Element.prototype["un" + eventName] = function (fn) {
2305 this.events[eventName] &&
2306 this.events[eventName][fn] &&
2307 this.events[eventName][fn].length &&
2308 this.events[eventName][fn].shift()() &&
2309 !this.events[eventName][fn].length &&
2310 delete this.events[eventName][fn];
2315 paper.circle = function (x, y, r) {
2316 return theCircle(this, x, y, r);
2318 paper.rect = function (x, y, w, h, r) {
2319 return theRect(this, x, y, w, h, r);
2321 paper.ellipse = function (x, y, rx, ry) {
2322 return theEllipse(this, x, y, rx, ry);
2324 paper.path = function (params, pathString) {
2325 return thePath(params, pathString, this);
2327 paper.image = function (src, x, y, w, h) {
2328 return theImage(this, src, x, y, w, h);
2330 paper.text = function (x, y, text) {
2331 return theText(this, x, y, text);
2333 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
2334 color = color || "#000";
2335 var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
2337 columnWidth = w / wv;
2338 for (var i = 1; i < hv; i++) {
2339 path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
2341 for (var i = 1; i < wv; i++) {
2342 path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
2344 return this.path({stroke: color, "stroke-width": 1}, path.join(","));
2346 paper.pathfinder = function (p, path) {
2348 M: function (x, y) {
2351 C: function (x1, y1, x2, y2, x3, y3) {
2352 this.curveTo(x1, y1, x2, y2, x3, y3);
2354 Q: function (x1, y1, x2, y2) {
2355 this.qcurveTo(x1, y1, x2, y2);
2357 T: function (x, y) {
2358 this.qcurveTo(x, y);
2360 S: function (x1, y1, x2, y2) {
2361 p.curveTo(x1, y1, x2, y2);
2363 L: function (x, y) {
2367 this.lineTo(x, this.last.y);
2370 this.lineTo(this.last.x, y);
2372 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2373 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2380 path = pathToAbsolute(path);
2381 for (var i = 0, ii = path.length; i < ii; i++) {
2382 var b = path[i].shift();
2383 commands[b].apply(p, path[i]);
2387 paper.set = function (itemsArray) {
2388 return new Set(itemsArray);
2390 paper.setSize = setSize;
2391 Element.prototype.stop = function () {
2392 clearTimeout(this.animation_in_progress);
2394 Element.prototype.scale = function (x, y, cx, cy) {
2395 if (x == null && y == null) {
2396 return {x: this._.sx, y: this._.sy, toString: function () { return this.x.toFixed(3) + " " + this.y.toFixed(3); }};
2406 var bb = this.type == "path" ? pathDimensions(a.path) : this.getBBox(),
2407 rcx = bb.x + bb.width / 2,
2408 rcy = bb.y + bb.height / 2;
2409 cx = (+cx || cx == 0) ? cx : rcx;
2410 cy = (+cy || cy == 0) ? cy : rcy;
2411 var dirx = Math.round(x / Math.abs(x)),
2412 diry = Math.round(y / Math.abs(y)),
2413 s = this.node.style,
2414 ncx = cx + (rcx - cx) * x * dirx / this._.sx,
2415 ncy = cy + (rcy - cy) * y * diry / this._.sy;
2416 switch (this.type) {
2419 var neww = a.width * x * dirx / this._.sx,
2420 newh = a.height * y * diry / this._.sy,
2421 newx = ncx - neww / 2,
2422 newy = ncy - newh / 2;
2433 rx: a.rx * x / this._.sx,
2434 ry: a.ry * y / this._.sy,
2435 r: a.r * x / this._.sx,
2441 var path = pathToRelative(a.path),
2443 for (var i = 0, ii = path.length; i < ii; i++) {
2445 if (p[0].toUpperCase() == "M" && skip) {
2450 if (R.svg && p[0].toUpperCase() == "A") {
2451 p[path[i].length - 2] *= x / this._.sx;
2452 p[path[i].length - 1] *= y / this._.sy;
2453 p[1] *= x / this._.sx;
2454 p[2] *= y / this._.sy;
2455 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2457 for (var j = 1, jj = p.length; j < jj; j++) {
2458 p[j] *= (j % 2) ? x / this._.sx : y / this._.sy;
2462 var dim2 = pathDimensions(path),
2463 dx = ncx - dim2.x - dim2.width / 2,
2464 dy = ncy - dim2.y - dim2.height / 2;
2465 path = pathToRelative(path);
2469 this.attr({path: path.join(" ")});
2472 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2473 if (this.transformations) {
2474 this.transformations[2] = "scale(".concat(dirx, ",", diry, ")");
2475 this.node.setAttribute("transform", this.transformations.join(" "));
2476 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2477 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2478 this.attr({x: dx, y: dy});
2482 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=".concat(dirx,
2483 ", M12=0, M21=0, M22=", diry,
2484 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2485 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2488 if (this.transformations) {
2489 this.transformations[2] = "";
2490 this.node.setAttribute("transform", this.transformations.join(" "));
2494 this.node.filterMatrix = "";
2495 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2498 a.scale = [x, y, cx, cy].join(" ");
2505 R.easing_formulas = {
2506 linear: function(n) {
2511 return Math.pow(n, 3);
2514 return Math.pow(n - 1, 3) + 1;
2519 return Math.pow(n, 3) / 2;
2522 return (Math.pow(n, 3) + 2) / 2;
2525 backIn: function(n) {
2527 return Math.pow(n, 2) * ((s + 1) * n - s);
2529 backOut: function(n) {
2532 return Math.pow(n, 2) * ((s + 1) * n + s) + 1;
2534 elastic: function(n) {
2535 if (n == 0 || n == 1) {
2540 return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1;
2542 bounce: function(n) {
2547 l = s * Math.pow(n, 2);
2551 l = s * Math.pow(n, 2) + .75;
2553 if (n < (2.5 / p)) {
2555 l = s * Math.pow(n, 2) + .9375;
2558 l = s * Math.pow(n, 2) + .984375;
2566 // animation easing formulas
2567 R.easing = function(easing, n) {
2568 return R.easing_formulas[easing] ? R.easing_formulas[easing](n) : n;
2571 Element.prototype.animate = function (params, ms, easing, callback) {
2572 clearTimeout(this.animation_in_progress);
2573 if (typeof easing == "function" || !easing) {
2574 callback = easing || null;
2581 for (var attr in params) {
2582 if (attr in availableAnimAttrs) {
2583 from[attr] = this.attr(attr);
2584 (typeof from[attr] == "undefined") && (from[attr] = availableAttrs[attr]);
2585 to[attr] = params[attr];
2586 switch (availableAnimAttrs[attr]) {
2588 diff[attr] = (to[attr] - from[attr]) / ms;
2591 from[attr] = R.getRGB(from[attr]);
2592 var toColour = R.getRGB(to[attr]);
2594 r: (toColour.r - from[attr].r) / ms,
2595 g: (toColour.g - from[attr].g) / ms,
2596 b: (toColour.b - from[attr].b) / ms
2600 var pathes = pathEqualiser(from[attr], to[attr]);
2601 from[attr] = pathes[0];
2602 to[attr] = pathes[1];
2604 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2605 diff[attr][i] = [0];
2606 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2607 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2612 var values = (params[attr] + "").split(separator),
2613 from2 = (from[attr] + "").split(separator);
2616 from[attr] = [0, 0];
2617 diff[attr] = [values[0] / ms, values[1] / ms];
2620 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2621 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2624 params[attr] = values;
2625 from[attr] = (from[attr] + "").split(separator);
2626 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2632 var start = +new Date,
2636 var time = new Date - start,
2640 pos = R.easing(easing, time / ms);
2641 for (var attr in from) {
2642 switch (availableAnimAttrs[attr]) {
2644 now = +from[attr] + pos * ms * diff[attr];
2648 Math.round(from[attr].r + pos * ms * diff[attr].r),
2649 Math.round(from[attr].g + pos * ms * diff[attr].g),
2650 Math.round(from[attr].b + pos * ms * diff[attr].b)
2655 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2656 now[i] = [from[attr][i][0]];
2657 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2658 now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
2660 now[i] = now[i].join(" ");
2662 now = now.join(" ");
2667 var x = diff[attr][0] * (time - prev),
2668 y = diff[attr][1] * (time - prev);
2671 now = [x, y].join(" ");
2674 now = +from[attr][0] + pos * ms * diff[attr][0];
2675 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2678 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(" ");
2682 if (attr == "font-size") {
2683 set[attr] = now + "px";
2689 that.animation_in_progress = setTimeout(tick);
2692 (t.x || t.y) && that.translate(-t.x, -t.y);
2694 clearTimeout(that.animation_in_progress);
2696 (typeof callback == "function") && callback.call(that);
2702 Element.prototype.translate = function (x, y) {
2704 return {x: this._.tx, y: this._.ty};
2708 switch (this.type) {
2711 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
2716 this.attr({x: this.attrs.x + (+x), y: this.attrs.y + (+y)});
2719 var path = pathToRelative(this.attrs.path);
2722 this.attr({path: path.join(" ")});
2729 var Set = function (items) {
2733 for (var i = 0, ii = items.length; i < ii; i++) {
2734 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
2735 this[this.items.length] = this.items[this.items.length] = items[i];
2741 Set.prototype.push = function () {
2744 for (var i = 0, ii = arguments.length; i < ii; i++) {
2745 item = arguments[i];
2746 if (item && (item.constructor == Element || item.constructor == Set)) {
2747 len = this.items.length;
2748 this[len] = this.items[len] = item;
2754 Set.prototype.pop = function (id) {
2755 var res = this.items.splice(id, 1)[0];
2756 for (var j = id, jj = this.items.length; j < jj; j++) {
2757 this[j] = this[j + 1];
2759 delete this[jj + 1];
2763 for (var method in Element.prototype) {
2764 Set.prototype[method] = (function (methodname) {
2765 return function () {
2766 for (var i = 0, ii = this.items.length; i < ii; i++) {
2767 this.items[i][methodname].apply(this.items[i], arguments);
2773 Set.prototype.attr = function (name, value) {
2774 if (name && R.isArray(name) && typeof name[0] == "object") {
2775 for (var j = 0, jj = name.length; j < jj; j++) {
2776 this.items[j].attr(name[j]);
2779 for (var i = 0, ii = this.items.length; i < ii; i++) {
2780 this.items[i].attr.apply(this.items[i], arguments);
2786 Set.prototype.getBBox = function () {
2791 for (var i = this.items.length; i--;) {
2792 var box = this.items[i].getBBox();
2795 w.push(box.x + box.width);
2796 h.push(box.y + box.height);
2798 x = Math.min.apply(Math, x);
2799 y = Math.min.apply(Math, y);
2803 width: Math.max.apply(Math, w) - x,
2804 height: Math.max.apply(Math, h) - y
2808 R.registerFont = function (font) {
2812 this.fonts = this.fonts || {};
2818 family = font.face["font-family"];
2819 for (var prop in font.face) {
2820 fontcopy.face[prop] = font.face[prop];
2822 if (this.fonts[family]) {
2823 this.fonts[family].push(fontcopy);
2825 this.fonts[family] = [fontcopy];
2828 fontcopy.face["units-per-em"] = parseInt(font.face["units-per-em"], 10);
2829 for (var glyph in font.glyphs) {
2830 var path = font.glyphs[glyph];
2831 fontcopy.glyphs[glyph] = {
2834 d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
2835 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
2839 for (var k in path.k) {
2840 fontcopy.glyphs[glyph].k[k] = path.k[k];
2847 paper.getFont = function (family, weight, style, stretch) {
2848 stretch = stretch || "normal";
2849 style = style || "normal";
2850 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
2851 var font = R.fonts[family];
2853 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, "") + "(\\s|$)", "i");
2854 for (var fontName in R.fonts) {
2855 if (name.test(fontName)) {
2856 font = R.fonts[fontName];
2863 for (var i = 0, ii = font.length; i < ii; i++) {
2865 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
2872 paper.print = function (x, y, string, font, size) {
2873 var out = this.set(),
2874 letters = (string + "").split(""),
2879 scale = (size || 16) / font.face["units-per-em"];
2880 for (var i = 0, ii = letters.length; i < ii; i++) {
2881 var prev = i && font.glyphs[letters[i - 1]] || {},
2882 curr = font.glyphs[letters[i]];
2883 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
2884 curr && curr.d && out.push(this.path({fill: "#000", stroke: "none"}, curr.d).translate(shift, 0));
2886 out.scale(scale, scale, 0, y).translate(x, (size || 16) / 2);
2891 R.ninja = function () {
2892 var r = window.Raphael;
2893 if (oldRaphael.was) {
2894 window.Raphael = oldRaphael.is;
2897 delete window.Raphael;
2899 window.Raphael = void(0);
2904 R.el = Element.prototype;