2 * Raphael 0.8.4 - JavaScript Vector Library
4 * Copyright (c) 2008 - 2009 Dmitry Baranovskiy (http://raphaeljs.com)
5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
9 window.Raphael = (function () {
10 var separator = /[, ]+/,
14 was: "Raphael" in window,
18 return create.apply(R, arguments);
21 availableAttrs = {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.setWindow = function (newwin) {
34 R.hsb2rgb = function (hue, saturation, brightness) {
35 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
43 if (brightness == 0) {
44 return {r: 0, g: 0, b: 0, hex: "#000"};
46 if (hue > 1 || saturation > 1 || brightness > 1) {
51 var i = Math.floor(hue * 6),
53 p = brightness * (1 - saturation),
54 q = brightness * (1 - (saturation * f)),
55 t = brightness * (1 - (saturation * (1 - f)));
56 red = [brightness, q, p, p, t, brightness, brightness][i];
57 green = [t, brightness, brightness, q, p, p, t][i];
58 blue = [p, p, t, brightness, brightness, q, p][i];
62 var rgb = {r: red, g: green, b: blue},
63 r = Math.round(red).toString(16),
64 g = Math.round(green).toString(16),
65 b = Math.round(blue).toString(16);
75 rgb.hex = "#" + r + g + b;
78 R.rgb2hsb = function (red, green, blue) {
79 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
84 if (typeof red == "string") {
85 var clr = R.getRGB(red);
90 if (red > 1 || green > 1 || blue > 1) {
95 var max = Math.max(red, green, blue),
96 min = Math.min(red, green, blue),
101 return {h: 0, s: 0, b: max};
103 var delta = (max - min);
104 saturation = delta / max;
106 hue = (green - blue) / delta;
107 } else if (green == max) {
108 hue = 2 + ((blue - red) / delta);
110 hue = 4 + ((red - green) / delta);
120 return {h: hue, s: saturation, b: brightness};
122 var getRGBcache = {},
124 R.getRGB = function (colour) {
125 if (colour in getRGBcache) {
126 return getRGBcache[colour];
128 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"},
130 if ((colour + "").toLowerCase() in htmlcolors) {
131 colour = htmlcolors[colour.toString().toLowerCase()];
134 return {r: 0, g: 0, b: 0, hex: "#000"};
136 if (colour == "none") {
137 return {r: -1, g: -1, b: -1, hex: "none"};
142 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);
145 blue = parseInt(rgb[2].substring(5), 16);
146 green = parseInt(rgb[2].substring(3, 5), 16);
147 red = parseInt(rgb[2].substring(1, 3), 16);
150 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
151 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
152 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
155 rgb = rgb[4].split(/\s*,\s*/);
156 red = parseFloat(rgb[0]);
157 green = parseFloat(rgb[1]);
158 blue = parseFloat(rgb[2]);
161 rgb = rgb[5].split(/\s*,\s*/);
162 red = parseFloat(rgb[0]) * 2.55;
163 green = parseFloat(rgb[1]) * 2.55;
164 blue = parseFloat(rgb[2]) * 2.55;
167 rgb = rgb[6].split(/\s*,\s*/);
168 red = parseFloat(rgb[0]);
169 green = parseFloat(rgb[1]);
170 blue = parseFloat(rgb[2]);
171 return R.hsb2rgb(red, green, blue);
174 rgb = rgb[7].split(/\s*,\s*/);
175 red = parseFloat(rgb[0]) * 2.55;
176 green = parseFloat(rgb[1]) * 2.55;
177 blue = parseFloat(rgb[2]) * 2.55;
178 return R.hsb2rgb(red, green, blue);
180 var rgb = {r: red, g: green, b: blue},
181 r = Math.round(red).toString(16),
182 g = Math.round(green).toString(16),
183 b = Math.round(blue).toString(16);
184 (r.length == 1) && (r = "0" + r);
185 (g.length == 1) && (g = "0" + g);
186 (b.length == 1) && (b = "0" + b);
187 rgb.hex = "#" + r + g + b;
190 res = {r: -1, g: -1, b: -1, hex: "none"};
192 if (getRGBcount.length > 20) {
193 delete getRGBcache[getRGBcount.unshift()];
195 getRGBcount.push(colour);
196 getRGBcache[colour] = res;
199 R.getColor = function (value) {
200 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
201 rgb = this.hsb2rgb(start.h, start.s, start.b);
207 this.getColor.start = {h: 0, s: 1, b: start.b};
212 R.getColor.reset = function () {
218 R.parsePathString = function (pathString) {
219 if (pathString in pathcache) {
220 return pathcache[pathString];
222 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
224 toString = function () {
226 for (var i = 0, ii = this.length; i < ii; i++) {
227 res += this[i][0] + this[i].join(",").substring(2);
231 if (pathString.toString.toString() == toString.toString()) {
235 pathString.replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, function (a, b, c) {
237 name = b.toLowerCase();
238 c.replace(/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig, function (a, b) {
239 b && params.push(+b);
241 while (params.length >= paramCounts[name]) {
242 data.push([b].concat(params.splice(0, paramCounts[name])));
243 if (!paramCounts[name]) {
248 data.toString = toString;
250 if (pathcount.length > 20) {
251 delete pathcache[pathcount.unshift()];
253 pathcount.push(pathString);
254 pathcache[pathString] = data;
257 var pathDimensions = function (path) {
258 var pathArray = path;
259 if (typeof path == "string") {
260 pathArray = R.parsePathString(path);
262 pathArray = pathToAbsolute(pathArray);
266 for (var i = 0, ii = pathArray.length; i < ii; i++) {
267 var pa = pathArray[i];
272 x.push(pa[pa.length - 2]);
273 y.push(pa[pa.length - 1]);
276 for (var j = 1, jj = pa.length; j < jj; j++) {
277 (j % 2 ? x : y).push(pa[j]);
281 var minx = Math.min.apply(Math, x),
282 miny = Math.min.apply(Math, y);
296 width: Math.max.apply(Math, x) - minx,
297 height: Math.max.apply(Math, y) - miny,
303 addRoundedCorner = function (r, dir) {
305 rollback = this.isAbsolute,
309 rollback = function () {
313 rollback = function () {};
319 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
322 o.curveTo(-R, 0, -r, r - R, -r, r);
329 o.curveTo(R, 0, r, -(r - R), r, -r);
332 o.curveTo(R, 0, r, r - R, r, r);
339 o.curveTo(0, -R, -(R - r), -r, r, -r);
342 o.curveTo(0, -R, R - r, -r, -r, -r);
349 o.curveTo(0, R, -(R - r), r, r, r);
352 o.curveTo(0, R, R - r, r, -r, r);
357 actions[dir.charAt(0)]()[dir.charAt(1)]();
361 pathToRelative = function (pathArray) {
366 if (typeof pathArray == "string") {
367 pathArray = R.parsePathString(pathArray);
369 if (pathArray[0][0] == "M") {
373 res.push(["M", x, y]);
375 for (var i = start, ii = pathArray.length; i < ii; i++) {
378 if (pa[0] != pa[0].toLowerCase()) {
379 r[0] = pa[0].toLowerCase();
387 r[6] = +(pa[6] - x).toFixed(3);
388 r[7] = +(pa[7] - y).toFixed(3);
391 r[1] = (pa[1] - y).toFixed(3);
394 for (var j = 1, jj = pa.length; j < jj; j++) {
395 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
400 for (var k = 0, kk = pa.length; k < kk; k++) {
408 x += res[i][res[i].length - 1];
411 y += res[i][res[i].length - 1];
414 x += res[i][res[i].length - 2];
415 y += res[i][res[i].length - 1];
418 res.toString = pathArray.toString;
421 pathToAbsolute = function (pathArray) {
423 if (typeof pathArray == "string") {
424 pathArray = R.parsePathString(pathArray);
429 if (pathArray[0][0] == "M") {
430 x = +pathArray[0][1];
431 y = +pathArray[0][2];
433 res[0] = ["M", x, y];
435 for (var i = start, ii = pathArray.length; i < ii; i++) {
438 if (pa[0] != (pa[0] + "").toUpperCase()) {
439 r[0] = (pa[0] + "").toUpperCase();
447 r[6] = +(pa[6] + x).toFixed(3);
448 r[7] = +(pa[7] + y).toFixed(3);
457 for (var j = 1, jj = pa.length; j < jj; j++) {
458 r[j] = +pa[j] + ((j % 2) ? x : y);
463 for (var k = 0, kk = pa.length; k < kk; k++) {
477 x = res[i][res[i].length - 2];
478 y = res[i][res[i].length - 1];
481 res.toString = pathArray.toString;
484 pecache = {}, pecount = [],
485 pathEqualiser = function (path1, path2) {
486 if ((path1 + path2) in pecache) {
487 return pecache[path1 + path2];
489 var data = [pathToAbsolute(R.parsePathString(path1)), pathToAbsolute(R.parsePathString(path2))],
490 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}],
491 processPath = function (path, d) {
501 var nx = d.x + (d.x - (d.bx || d.x)),
502 ny = d.y + (d.y - (d.by || d.y));
503 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
506 var nx = d.x + (d.x - (d.bx || d.x)),
507 ny = d.y + (d.y - (d.by || d.y));
508 path = ["Q", nx, ny, path[1], path[2]];
511 path = ["L", path[1], d.y];
514 path = ["L", d.x, path[1]];
517 path = ["L", d.X, d.Y];
522 edgeCases = function (a, b, i) {
523 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
524 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
525 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
526 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
527 attrs[a].x = data[a][i][data[a][i].length - 2];
528 attrs[a].y = data[a][i][data[a][i].length - 1];
530 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
531 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]];
532 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
533 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
534 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
535 var x = data[b][i][data[b][i].length - 2],
536 y = data[b][i][data[b][i].length - 1];
537 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
538 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
540 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
541 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
542 attrs[b].x = data[b][i][data[b][i].length - 2];
543 attrs[b].y = data[b][i][data[b][i].length - 1];
545 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
546 var x = data[b][i][data[b][i].length - 2],
547 y = data[b][i][data[b][i].length - 1];
548 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
549 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
551 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
552 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
553 attrs[b].x = data[b][i][data[b][i].length - 2];
554 attrs[b].y = data[b][i][data[b][i].length - 1];
556 } else if (data[a][i][0] == "U") {
557 data[a][i][0] = data[b][i][0];
558 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
559 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
564 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
565 data[0][i] = processPath(data[0][i], attrs[0]);
566 data[1][i] = processPath(data[1][i], attrs[1]);
567 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
570 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
571 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
572 attrs[0].x = data[0][i][data[0][i].length - 2];
573 attrs[0].y = data[0][i][data[0][i].length - 1];
574 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
575 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
576 attrs[1].x = data[1][i][data[1][i].length - 2];
577 attrs[1].y = data[1][i][data[1][i].length - 1];
579 if (pecount.length > 20) {
580 delete pecache[pecount.unshift()];
582 pecount.push(path1 + path2);
583 pecache[path1 + path2] = data;
586 toGradient = function (gradient) {
587 if (typeof gradient == "string") {
588 gradient = gradient.split(/\s*\-\s*/);
589 var angle = gradient.shift();
590 if (angle.toLowerCase() == "v") {
592 } else if (angle.toLowerCase() == "h") {
595 angle = parseFloat(angle);
598 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)]},
599 max = 1 / (Math.max(Math.abs(grobj.vector[2]), Math.abs(grobj.vector[3])) || 1);
600 grobj.vector[2] *= max;
601 grobj.vector[3] *= max;
602 if (grobj.vector[2] < 0) {
603 grobj.vector[0] = -grobj.vector[2];
606 if (grobj.vector[3] < 0) {
607 grobj.vector[1] = -grobj.vector[3];
610 grobj.vector[0] = grobj.vector[0].toFixed(3);
611 grobj.vector[1] = grobj.vector[1].toFixed(3);
612 grobj.vector[2] = grobj.vector[2].toFixed(3);
613 grobj.vector[3] = grobj.vector[3].toFixed(3);
614 for (var i = 0, ii = gradient.length; i < ii; i++) {
616 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
617 dot.color = R.getRGB(par[1]).hex;
618 par[2] && (dot.offset = par[2] + "%");
619 grobj.dots.push(dot);
621 for (var i = 1, ii = grobj.dots.length - 1; i < ii; i++) {
622 if (!grobj.dots[i].offset) {
623 var start = parseFloat(grobj.dots[i - 1].offset || 0),
625 for (var j = i + 1; j < ii; j++) {
626 if (grobj.dots[j].offset) {
627 end = grobj.dots[j].offset;
635 end = parseFloat(end);
636 var d = (end - start) / (j - i + 1);
639 grobj.dots[i].offset = start + "%";
648 getContainer = function () {
654 if (typeof arguments[0] == "string" || typeof arguments[0] == "object") {
655 if (typeof arguments[0] == "string") {
656 container = doc.getElementById(arguments[0]);
658 container = arguments[0];
660 if (container.tagName) {
661 if (arguments[1] == null) {
663 container: container,
664 width: container.style.pixelWidth || container.offsetWidth,
665 height: container.style.pixelHeight || container.offsetHeight
668 return {container: container, width: arguments[1], height: arguments[2]};
671 } else if (typeof arguments[0] == "number" && arguments.length > 3) {
672 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
675 plugins = function (con, add) {
677 for (var prop in add) if (add.hasOwnProperty(prop) && !(prop in con)) {
678 switch (typeof add[prop]) {
681 con[prop] = con === that ? f : function () { return f.apply(that, arguments); };
685 con[prop] = con[prop] || {};
686 plugins.call(this, con[prop], add[prop]);
689 con[prop] = add[prop];
697 R.toString = function () {
698 return "Your browser supports SVG.\nYou are running Rapha\u00ebl " + this.version;
701 absolutely: function () {
702 this.isAbsolute = true;
705 relatively: function () {
706 this.isAbsolute = false;
709 moveTo: function (x, y) {
710 var d = this.isAbsolute ? "M" : "m";
711 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
712 var oldD = this[0].getAttribute("d") || "";
713 (oldD == "M0,0") && (oldD = "");
714 this[0].setAttribute("d", oldD + d);
715 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
716 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
717 this.attrs.path = oldD + d;
720 lineTo: function (x, y) {
721 this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(x);
722 this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(y);
723 var d = this.isAbsolute ? "L" : "l";
724 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
725 var oldD = this.node.getAttribute("d") || "";
726 this.node.setAttribute("d", oldD + d);
727 this.attrs.path = oldD + d;
730 arcTo: function (rx, ry, large_arc_flag, sweep_flag, x, y) {
731 var d = this.isAbsolute ? "A" : "a";
732 d += [parseFloat(rx).toFixed(3), parseFloat(ry).toFixed(3), 0, large_arc_flag, sweep_flag, parseFloat(x).toFixed(3), parseFloat(y).toFixed(3)].join(" ");
733 var oldD = this[0].getAttribute("d") || "";
734 this.node.setAttribute("d", oldD + d);
735 this.last.x = parseFloat(x);
736 this.last.y = parseFloat(y);
737 this.attrs.path = oldD + d;
740 cplineTo: function (x1, y1, w1) {
742 return this.lineTo(x1, y1);
748 d = this.isAbsolute ? "C" : "c",
749 attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
750 for (var i = 0, ii = attr.length; i < ii; i++) {
753 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
754 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
755 this.last.bx = attr[2];
756 this.last.by = attr[3];
757 var oldD = this.node.getAttribute("d") || "";
758 this.node.setAttribute("d", oldD + d);
759 this.attrs.path = oldD + d;
763 curveTo: function () {
765 d = [0, 1, 2, 3, "s", 5, "c"][arguments.length];
766 if (this.isAbsolute) {
769 for (var i = 0, ii = arguments.length; i < ii; i++) {
770 d += parseFloat(arguments[i]).toFixed(3) + " ";
772 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
773 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
774 this.last.bx = parseFloat(arguments[arguments.length - 4]);
775 this.last.by = parseFloat(arguments[arguments.length - 3]);
776 var oldD = this.node.getAttribute("d") || "";
777 this.node.setAttribute("d", oldD + d);
778 this.attrs.path = oldD + d;
781 qcurveTo: function () {
783 d = [0, 1, "t", 3, "q"][arguments.length];
784 if (this.isAbsolute) {
787 for (var i = 0, ii = arguments.length; i < ii; i++) {
788 d += parseFloat(arguments[i]).toFixed(3) + " ";
790 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
791 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
792 if (arguments.length != 2) {
793 this.last.qx = parseFloat(arguments[arguments.length - 4]);
794 this.last.qy = parseFloat(arguments[arguments.length - 3]);
796 var oldD = this.node.getAttribute("d") || "";
797 this.node.setAttribute("d", oldD + d);
798 this.attrs.path = oldD + d;
801 addRoundedCorner: addRoundedCorner,
802 andClose: function () {
803 var oldD = this[0].getAttribute("d") || "";
804 this[0].setAttribute("d", oldD + "Z ");
805 this.attrs.path = oldD + "Z ";
809 var thePath = function (params, pathString, SVG) {
810 var el = doc.createElementNS(SVG.svgns, "path");
812 SVG.canvas.appendChild(el);
814 var p = new Element(el, SVG);
816 for (var method in pathMethods) {
817 p[method] = pathMethods[method];
820 p.last = {x: 0, y: 0, bx: 0, by: 0};
822 p.attrs.path = "" + pathString;
824 paper.pathfinder(p, p.attrs.path);
827 !params.gradient && (params.fill = params.fill || "none");
828 params.stroke = params.stroke || "#000";
830 params = {fill: "none", stroke: "#000"};
832 setFillAndStroke(p, params);
835 var addGradientFill = function (o, gradient, SVG) {
836 gradient = toGradient(gradient);
837 var el = doc.createElementNS(SVG.svgns, (gradient.type || "linear") + "Gradient");
838 el.id = "raphael-gradient-" + R.idGenerator++;
839 if (gradient.vector && gradient.vector.length) {
840 el.setAttribute("x1", gradient.vector[0]);
841 el.setAttribute("y1", gradient.vector[1]);
842 el.setAttribute("x2", gradient.vector[2]);
843 el.setAttribute("y2", gradient.vector[3]);
845 SVG.defs.appendChild(el);
846 var isopacity = true;
847 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
848 var stop = doc.createElementNS(SVG.svgns, "stop");
849 if (gradient.dots[i].offset) {
852 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
853 stop.setAttribute("stop-color", R.getRGB(gradient.dots[i].color).hex || "#fff");
854 // ignoring opacity for internal points, because VML doesn't support it
855 el.appendChild(stop);
857 if (isopacity && typeof gradient.dots[ii - 1].opacity != "undefined") {
858 stop.setAttribute("stop-opacity", gradient.dots[ii - 1].opacity);
860 o.setAttribute("fill", "url(#" + el.id + ")");
863 o.style.fillOpacity = 1;
864 o.setAttribute("opacity", 1);
865 o.setAttribute("fill-opacity", 1);
867 var updatePosition = function (o) {
869 var bbox = o.getBBox();
870 o.pattern.setAttribute("patternTransform", "translate(".concat(bbox.x, ",", bbox.y, ")"));
873 var setFillAndStroke = function (o, params) {
878 "-..": [3, 1, 1, 1, 1, 1],
884 "--..": [8, 3, 1, 3, 1, 3]
888 rot = attrs.rotation,
889 addDashes = function (o, value) {
890 value = dasharray[value.toString().toLowerCase()];
892 var width = o.attrs["stroke-width"] || "1",
893 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
895 for (var i = 0, ii = value.length; i < ii; i++) {
896 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
898 value = dashes.join(",");
899 node.setAttribute("stroke-dasharray", value);
903 for (var att in params) {
904 if (!(att in availableAttrs)) {
907 var value = params[att];
914 var pn = node.parentNode;
915 if (pn.tagName.toLowerCase() != "a") {
916 var hl = doc.createElementNS(o.paper.svgns, "a");
917 pn.insertBefore(hl, node);
918 hl.appendChild(node);
921 pn.setAttributeNS(o.paper.xlink, att, value);
924 if (o.type == "path") {
925 node.setAttribute("d", "M0,0");
926 paper.pathfinder(o, value);
929 node.setAttribute(att, value);
938 value = -attrs.x - (attrs.width || 0);
942 node.setAttribute(att, value);
946 node.setAttribute(att, value);
955 value = -attrs.y - (attrs.height || 0);
959 node.setAttribute(att, value);
963 if (o.type == "rect") {
964 node.setAttribute("rx", value);
965 node.setAttribute("ry", value);
967 node.setAttribute(att, value);
971 if (o.type == "image") {
972 node.setAttributeNS(o.paper.xlink, "href", value);
976 node.style.strokeWidth = value;
977 // Need following line for Firefox
978 node.setAttribute(att, value);
979 if (attrs["stroke-dasharray"]) {
980 addDashes(o, attrs["stroke-dasharray"]);
983 case "stroke-dasharray":
987 o.rotate(value, true);
990 var xy = (value + "").split(separator);
991 o.translate((+xy[0] + 1 || 2) - 1, (+xy[1] + 1 || 2) - 1);
994 var xy = (value + "").split(separator);
995 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
998 var isURL = (value + "").match(/^url\(([^\)]+)\)$/i);
1000 var el = doc.createElementNS(o.paper.svgns, "pattern"),
1001 ig = doc.createElementNS(o.paper.svgns, "image");
1002 el.id = "raphael-pattern-" + R.idGenerator++;
1003 el.setAttribute("x", 0);
1004 el.setAttribute("y", 0);
1005 el.setAttribute("patternUnits", "userSpaceOnUse");
1006 ig.setAttribute("x", 0);
1007 ig.setAttribute("y", 0);
1008 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1011 var img = doc.createElement("img");
1012 img.style.position = "absolute";
1013 img.style.top = "-9999em";
1014 img.style.left = "-9999em";
1015 img.onload = function () {
1016 el.setAttribute("width", this.offsetWidth);
1017 el.setAttribute("height", this.offsetHeight);
1018 ig.setAttribute("width", this.offsetWidth);
1019 ig.setAttribute("height", this.offsetHeight);
1020 doc.body.removeChild(this);
1023 doc.body.appendChild(img);
1025 o.paper.defs.appendChild(el);
1026 node.style.fill = "url(#" + el.id + ")";
1027 node.setAttribute("fill", "url(#" + el.id + ")");
1032 delete params.gradient;
1033 delete attrs.gradient;
1034 if (typeof attrs.opacity != "undefined" && typeof params.opacity == "undefined" ) {
1035 node.style.opacity = attrs.opacity;
1036 // Need following line for Firefox
1037 node.setAttribute("opacity", attrs.opacity);
1039 if (typeof attrs["fill-opacity"] != "undefined" && typeof params["fill-opacity"] == "undefined" ) {
1040 node.style.fillOpacity = o.attrs["fill-opacity"];
1041 // Need following line for Firefox
1042 node.setAttribute("fill-opacity", attrs["fill-opacity"]);
1045 node.style[att] = R.getRGB(value).hex;
1046 // Need following line for Firefox
1047 node.setAttribute(att, R.getRGB(value).hex);
1050 addGradientFill(node, value, o.paper);
1053 case "fill-opacity":
1054 if (attrs.gradient) {
1055 var gradient = doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
1057 var stops = gradient.getElementsByTagName("stop");
1058 stops[stops.length - 1].setAttribute("stop-opacity", value);
1063 var cssrule = att.replace(/(\-.)/g, function (w) {
1064 return w.substring(1).toUpperCase();
1066 node.style[cssrule] = value;
1067 // Need following line for Firefox
1068 node.setAttribute(att, value);
1073 tuneText(o, params);
1074 o.rotate(attrs.rotation, true);
1077 var tuneText = function (el, params) {
1078 if (el.type != "text" || !("text" in params || "font" in params || "font-size" in params || "x" in params || "y" in params)) {
1083 fontSize = node.firstChild ? parseInt(doc.defaultView.getComputedStyle(node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
1085 if ("text" in params) {
1086 while (node.firstChild) {
1087 node.removeChild(node.firstChild);
1089 var texts = (params.text + "").split("\n");
1090 for (var i = 0, ii = texts.length; i < ii; i++) {
1091 var tspan = doc.createElementNS(el.paper.svgns, "tspan");
1092 i && tspan.setAttribute("dy", fontSize * leading);
1093 i && tspan.setAttribute("x", a.x);
1094 tspan.appendChild(doc.createTextNode(texts[i]));
1095 node.appendChild(tspan);
1098 var texts = node.getElementsByTagName("tspan");
1099 for (var i = 0, ii = texts.length; i < ii; i++) {
1100 i && texts[i].setAttribute("dy", fontSize * leading);
1101 i && texts[i].setAttribute("x", a.x);
1104 node.setAttribute("y", a.y);
1105 var bb = el.getBBox(),
1106 dif = a.y - (bb.y + bb.height / 2);
1107 dif && node.setAttribute("y", a.y + dif);
1109 var Element = function (node, svg) {
1115 this.attrs = this.attrs || {};
1116 this.transformations = []; // rotate, translate, scale
1120 rt: {deg: 0, x: 0, y: 0},
1125 Element.prototype.rotate = function (deg, cx, cy) {
1127 return this._.rt.deg;
1129 var bbox = this.getBBox();
1130 deg = deg.toString().split(separator);
1131 if (deg.length - 1) {
1132 cx = parseFloat(deg[1]);
1133 cy = parseFloat(deg[2]);
1135 deg = parseFloat(deg[0]);
1137 this._.rt.deg = deg;
1139 this._.rt.deg += deg;
1144 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1145 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1146 if (this._.rt.deg) {
1147 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
1149 this.transformations[0] = "";
1151 this.node.setAttribute("transform", this.transformations.join(" "));
1154 Element.prototype.hide = function () {
1155 this.node.style.display = "none";
1158 Element.prototype.show = function () {
1159 this.node.style.display = "block";
1162 Element.prototype.remove = function () {
1163 this.node.parentNode.removeChild(this.node);
1165 Element.prototype.getBBox = function () {
1166 if (this.node.style.display == "none") {
1170 var bbox = this.node.getBBox() || {};
1171 if (this.type == "text") {
1172 bbox = {x: bbox.x, y: Infinity, width: bbox.width, height: 0};
1173 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1174 var bb = this.node.getExtentOfChar(i);
1175 (bb.y < bbox.y) && (bbox.y = bb.y);
1176 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1179 hide && this.hide();
1182 Element.prototype.attr = function () {
1183 if (arguments.length == 1 && typeof arguments[0] == "string") {
1184 if (arguments[0] == "translation") {
1185 return this.translate();
1187 return this.attrs[arguments[0]];
1189 if (arguments.length == 1 && arguments[0] instanceof win.Array) {
1191 for (var j in arguments[0]) {
1192 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1196 if (arguments.length == 2) {
1198 params[arguments[0]] = arguments[1];
1199 setFillAndStroke(this, params);
1200 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1201 setFillAndStroke(this, arguments[0]);
1205 Element.prototype.toFront = function () {
1206 this.node.parentNode.appendChild(this.node);
1209 Element.prototype.toBack = function () {
1210 if (this.node.parentNode.firstChild != this.node) {
1211 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1215 Element.prototype.insertAfter = function (element) {
1216 if (element.node.nextSibling) {
1217 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1219 element.node.parentNode.appendChild(this.node);
1223 Element.prototype.insertBefore = function (element) {
1224 element.node.parentNode.insertBefore(this.node, element.node);
1227 var theCircle = function (svg, x, y, r) {
1228 var el = doc.createElementNS(svg.svgns, "circle");
1229 el.setAttribute("cx", x);
1230 el.setAttribute("cy", y);
1231 el.setAttribute("r", r);
1232 el.setAttribute("fill", "none");
1233 el.setAttribute("stroke", "#000");
1235 svg.canvas.appendChild(el);
1237 var res = new Element(el, svg);
1238 res.attrs = res.attrs || {};
1242 res.attrs.stroke = "#000";
1243 res.type = "circle";
1246 var theRect = function (svg, x, y, w, h, r) {
1247 var el = doc.createElementNS(svg.svgns, "rect");
1248 el.setAttribute("x", x);
1249 el.setAttribute("y", y);
1250 el.setAttribute("width", w);
1251 el.setAttribute("height", h);
1253 el.setAttribute("rx", r);
1254 el.setAttribute("ry", r);
1256 el.setAttribute("fill", "none");
1257 el.setAttribute("stroke", "#000");
1259 svg.canvas.appendChild(el);
1261 var res = new Element(el, svg);
1262 res.attrs = res.attrs || {};
1265 res.attrs.width = w;
1266 res.attrs.height = h;
1267 res.attrs.stroke = "#000";
1269 res.attrs.rx = res.attrs.ry = r;
1274 var theEllipse = function (svg, x, y, rx, ry) {
1275 var el = doc.createElementNS(svg.svgns, "ellipse");
1276 el.setAttribute("cx", x);
1277 el.setAttribute("cy", y);
1278 el.setAttribute("rx", rx);
1279 el.setAttribute("ry", ry);
1280 el.setAttribute("fill", "none");
1281 el.setAttribute("stroke", "#000");
1283 svg.canvas.appendChild(el);
1285 var res = new Element(el, svg);
1286 res.attrs = res.attrs || {};
1291 res.attrs.stroke = "#000";
1292 res.type = "ellipse";
1295 var theImage = function (svg, src, x, y, w, h) {
1296 var el = doc.createElementNS(svg.svgns, "image");
1297 el.setAttribute("x", x);
1298 el.setAttribute("y", y);
1299 el.setAttribute("width", w);
1300 el.setAttribute("height", h);
1301 el.setAttribute("preserveAspectRatio", "none");
1302 el.setAttributeNS(svg.xlink, "href", src);
1304 svg.canvas.appendChild(el);
1306 var res = new Element(el, svg);
1307 res.attrs = res.attrs || {};
1310 res.attrs.width = w;
1311 res.attrs.height = h;
1315 var theText = function (svg, x, y, text) {
1316 var el = doc.createElementNS(svg.svgns, "text");
1317 el.setAttribute("x", x);
1318 el.setAttribute("y", y);
1319 el.setAttribute("text-anchor", "middle");
1321 svg.canvas.appendChild(el);
1323 var res = new Element(el, svg);
1324 res.attrs = res.attrs || {};
1328 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000", text: text});
1331 var setSize = function (width, height) {
1332 this.width = width || this.width;
1333 this.height = height || this.height;
1334 this.canvas.setAttribute("width", this.width);
1335 this.canvas.setAttribute("height", this.height);
1338 var create = function () {
1339 var con = getContainer.apply(null, arguments),
1340 container = con.container,
1344 height = con.height;
1346 throw new Error("SVG container not found.");
1348 paper.canvas = doc.createElementNS(paper.svgns, "svg");
1349 paper.canvas.setAttribute("width", width || 512);
1350 paper.width = width || 512;
1351 paper.canvas.setAttribute("height", height || 342);
1352 paper.height = height || 342;
1353 if (container == 1) {
1354 doc.body.appendChild(paper.canvas);
1355 paper.canvas.style.position = "absolute";
1356 paper.canvas.style.left = x + "px";
1357 paper.canvas.style.top = y + "px";
1359 if (container.firstChild) {
1360 container.insertBefore(paper.canvas, container.firstChild);
1362 container.appendChild(paper.canvas);
1366 canvas: paper.canvas,
1367 clear: function () {
1368 while (this.canvas.firstChild) {
1369 this.canvas.removeChild(this.canvas.firstChild);
1371 this.defs = doc.createElementNS(paper.svgns, "defs");
1372 this.canvas.appendChild(this.defs);
1375 for (var prop in paper) {
1376 if (prop != "create") {
1377 container[prop] = paper[prop];
1380 plugins.call(container, container, R.fn);
1382 container.raphael = R;
1385 paper.remove = function () {
1386 this.canvas.parentNode.removeChild(this.canvas);
1388 paper.svgns = "http://www.w3.org/2000/svg";
1389 paper.xlink = "http://www.w3.org/1999/xlink";
1390 paper.safari = function () {
1391 if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) {
1392 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1393 setTimeout(function () {rect.remove();});
1400 R.toString = function () {
1401 return "Your browser doesn\u2019t support SVG. Assuming it is Internet Explorer and falling down to VML.\nYou are running Rapha\u00ebl " + this.version;
1404 absolutely: function () {
1405 this.isAbsolute = true;
1408 relatively: function () {
1409 this.isAbsolute = false;
1412 moveTo: function (x, y) {
1413 var X = Math.round(parseFloat(x)) - 1,
1414 Y = Math.round(parseFloat(y)) - 1,
1415 d = this.isAbsolute ? "m" : "t";
1417 this.node.path = this.Path += d;
1418 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1419 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1420 this.last.isAbsolute = this.isAbsolute;
1421 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1424 lineTo: function (x, y) {
1425 var X = Math.round(parseFloat(x)) - 1,
1426 Y = Math.round(parseFloat(y)) - 1,
1427 d = this.isAbsolute ? "l" : "r";
1429 this.node.path = this.Path += d;
1430 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1431 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1432 this.last.isAbsolute = this.isAbsolute;
1433 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1436 arcTo: function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1437 // for more information of where this math came from visit:
1438 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1439 x2 = (this.isAbsolute ? 0 : this.last.x) + x2 - 1;
1440 y2 = (this.isAbsolute ? 0 : this.last.y) + y2 - 1;
1441 var x1 = this.last.x - 1,
1442 y1 = this.last.y - 1,
1445 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1446 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1447 cx = k * rx * y / ry + (x1 + x2) / 2,
1448 cy = k * -ry * x / rx + (y1 + y2) / 2,
1449 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1450 left = Math.round(cx - rx),
1451 top = Math.round(cy - ry);
1452 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(", ");
1453 this.node.path = this.Path += d;
1454 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2);
1455 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2);
1456 this.last.isAbsolute = this.isAbsolute;
1457 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1460 cplineTo: function (x1, y1, w1) {
1462 return this.lineTo(x1, y1);
1464 var x = Math.round(parseFloat(x1)) - 1,
1465 y = Math.round(parseFloat(y1)) - 1,
1466 w = Math.round(parseFloat(w1)),
1467 d = this.isAbsolute ? "c" : "v",
1468 attr = [Math.round(this.last.x) - 1 + w, Math.round(this.last.y) - 1, x - w, y, x, y],
1469 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1470 d += attr.join(" ") + " ";
1471 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1472 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1473 this.last.bx = attr[2];
1474 this.last.by = attr[3];
1475 this.node.path = this.Path += d;
1476 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1480 curveTo: function () {
1481 var d = this.isAbsolute ? "c" : "v";
1482 if (arguments.length == 6) {
1483 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1484 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1485 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4]);
1486 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5]);
1487 d += [Math.round(parseFloat(arguments[0])) - 1,
1488 Math.round(parseFloat(arguments[1])) - 1,
1489 Math.round(parseFloat(arguments[2])) - 1,
1490 Math.round(parseFloat(arguments[3])) - 1,
1491 Math.round(parseFloat(arguments[4])) - 1,
1492 Math.round(parseFloat(arguments[5])) - 1].join(" ") + " ";
1493 this.last.isAbsolute = this.isAbsolute;
1494 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1496 if (arguments.length == 4) {
1497 var bx = this.last.x * 2 - this.last.bx,
1498 by = this.last.y * 2 - this.last.by;
1499 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0]);
1500 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1]);
1501 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1502 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1503 d += [Math.round(bx) - 1, Math.round(by) - 1,
1504 Math.round(parseFloat(arguments[0])) - 1,
1505 Math.round(parseFloat(arguments[1])) - 1,
1506 Math.round(parseFloat(arguments[2])) - 1,
1507 Math.round(parseFloat(arguments[3])) - 1].join(" ") + " ";
1508 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1510 this.node.path = this.Path += d;
1513 qcurveTo: function () {
1514 var lx = Math.round(this.last.x) - 1,
1515 ly = Math.round(this.last.y) - 1,
1517 if (arguments.length == 4) {
1518 this.last.qx = (!this.isAbsolute * this.last.x) + parseFloat(arguments[0]);
1519 this.last.qy = (!this.isAbsolute * this.last.y) + parseFloat(arguments[1]);
1520 this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(arguments[2]);
1521 this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(arguments[3]);
1522 res = [this.last.qx, this.last.qy, this.last.x, this.last.y];
1523 this.last.isAbsolute = this.isAbsolute;
1524 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1526 if (arguments.length == 2) {
1527 this.last.qx = this.last.x * 2 - this.last.qx;
1528 this.last.qy = this.last.y * 2 - this.last.qy;
1529 this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(arguments[2]);
1530 this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(arguments[3]);
1531 res = [this.last.qx, this.last.qy, this.last.x, this.last.y];
1532 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1535 Math.round(2 / 3 * res[0] + 1 / 3 * lx) - 1,
1536 Math.round(2 / 3 * res[1] + 1 / 3 * ly) - 1,
1537 Math.round(2 / 3 * res[0] + 1 / 3 * res[2]) - 1,
1538 Math.round(2 / 3 * res[1] + 1 / 3 * res[3]) - 1,
1539 Math.round(res[2]) - 1,
1540 Math.round(res[3]) - 1
1542 this.node.path = this.Path += d;
1545 addRoundedCorner: addRoundedCorner,
1546 andClose: function () {
1547 this.node.path = (this.Path += "x");
1548 this.attrs.path += "z";
1552 var thePath = function (params, pathString, VML) {
1553 var g = createNode("group"), gl = g.style;
1554 gl.position = "absolute";
1557 gl.width = VML.width + "px";
1558 gl.height = VML.height + "px";
1559 g.coordsize = VML.coordsize;
1560 g.coordorigin = VML.coordorigin;
1561 var el = createNode("shape"), ol = el.style;
1562 ol.width = VML.width + "px";
1563 ol.height = VML.height + "px";
1565 if (params["class"]) {
1566 el.className = "rvml " + params["class"];
1568 el.coordsize = this.coordsize;
1569 el.coordorigin = this.coordorigin;
1571 var p = new Element(el, g, VML);
1572 p.isAbsolute = true;
1575 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1577 for (var method in pathMethods) {
1578 p[method] = pathMethods[method];
1584 paper.pathfinder(p, "" + pathString);
1587 params.fill = params.fill || "none";
1588 params.stroke = params.stroke || "#000";
1590 params = {fill: "none", stroke: "#000"};
1592 setFillAndStroke(p, params);
1593 if (params.gradient) {
1594 addGradientFill(p, params.gradient);
1597 VML.canvas.appendChild(g);
1600 var setFillAndStroke = function (o, params) {
1605 o.attrs = o.attrs || {};
1606 for (var par in params) {
1607 o.attrs[par] = params[par];
1609 params.href && (node.href = params.href);
1610 params.title && (node.title = params.title);
1611 params.target && (node.target = params.target);
1612 if (params.path && o.type == "path") {
1615 paper.pathfinder(o, params.path);
1617 if (params.rotation != null) {
1618 o.rotate(params.rotation, true);
1620 if (params.translation) {
1621 xy = (params.translation + "").split(separator);
1622 o.translate(xy[0], xy[1]);
1625 xy = (params.scale + "").split(separator);
1626 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1628 if (o.type == "image" && params.src) {
1629 node.src = params.src;
1631 if (o.type == "image" && params.opacity) {
1632 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1633 node.style.filter = (node.filterMatrix || "") + (node.filterOpacity || "");
1635 params.font && (s.font = params.font);
1636 params["font-family"] && (s.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, "") + '"');
1637 params["font-size"] && (s.fontSize = params["font-size"]);
1638 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1639 params["font-style"] && (s.fontStyle = params["font-style"]);
1640 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"]) {
1641 o = o.shape || node;
1642 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || createNode("fill");
1643 if ("fill-opacity" in params || "opacity" in params) {
1644 fill.opacity = ((+params["fill-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1646 params.fill && (fill.on = true);
1647 if (typeof fill.on == "undefined" || params.fill == "none") {
1650 if (fill.on && params.fill) {
1651 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1653 fill.src = isURL[1];
1656 fill.color = R.getRGB(params.fill).hex;
1658 fill.type = "solid";
1661 o.appendChild(fill);
1662 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || createNode("stroke");
1663 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"]) {
1666 if (params.stroke == "none" || typeof stroke.on == "undefined" || params.stroke == 0) {
1669 if (stroke.on && params.stroke) {
1670 stroke.color = R.getRGB(params.stroke).hex;
1672 stroke.opacity = ((+params["stroke-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1673 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1674 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1675 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1676 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"]) || 1) * 12 / 16);
1677 if (params["stroke-dasharray"]) {
1681 "-.": "shortdashdot",
1682 "-..": "shortdashdotdot",
1687 "--.": "longdashdot",
1688 "--..": "longdashdotdot"
1690 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1692 o.appendChild(stroke);
1694 if (res.type == "text") {
1695 var span = doc.createElement("span"),
1701 s.display = "inline";
1702 a.font && (s.font = a.font);
1703 a["font-family"] && (s.fontFamily = a["font-family"]);
1704 a["font-size"] && (s.fontSize = a["font-size"]);
1705 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1706 a["font-style"] && (s.fontStyle = a["font-style"]);
1707 res.node.parentNode.appendChild(span);
1708 span.innerText = res.node.string;
1709 res.W = a.w = span.offsetWidth;
1710 res.H = a.h = span.offsetHeight;
1712 res.Y = a.y + Math.round(res.H / 2);
1713 res.node.parentNode.removeChild(span);
1715 // text-anchor emulation
1716 switch (a["text-anchor"]) {
1718 res.node.style["v-text-align"] = "left";
1719 res.bbx = Math.round(res.W / 2);
1722 res.node.style["v-text-align"] = "right";
1723 res.bbx = -Math.round(res.W / 2);
1726 res.node.style["v-text-align"] = "center";
1731 var getAngle = function (a, b, c, d) {
1732 var angle = Math.round(Math.atan((parseFloat(c) - parseFloat(a)) / (parseFloat(d) - parseFloat(b))) * 57.29) || 0;
1733 if (!angle && parseFloat(a) < parseFloat(b)) {
1742 var addGradientFill = function (o, gradient) {
1743 gradient = toGradient(gradient);
1744 o.attrs = o.attrs || {};
1745 var attrs = o.attrs,
1746 fill = o.getElementsByTagName("fill");
1747 o.attrs.gradient = gradient;
1748 o = o.shape || o[0];
1752 fill = createNode("fill");
1754 if (gradient.dots.length) {
1756 fill.method = "none";
1757 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1758 if (typeof gradient.dots[0].color != "undefined") {
1759 fill.color = R.getRGB(gradient.dots[0].color).hex;
1761 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1762 fill.color2 = R.getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1765 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1766 if (gradient.dots[i].offset) {
1767 clrs.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
1770 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;
1772 fill.colors.value = clrs.join(",");
1773 fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
1775 fill.colors && (fill.colors.value = "0% " + fill.color);
1777 fill.opacity = fillOpacity;
1778 if (typeof gradient.angle != "undefined") {
1779 fill.angle = (-gradient.angle + 270) % 360;
1780 } else if (gradient.vector) {
1781 fill.angle = getAngle.apply(null, gradient.vector);
1783 if ((gradient.type + "").toLowerCase() == "radial") {
1784 fill.focus = "100%";
1785 fill.focusposition = "0.5 0.5";
1789 var Element = function (node, group, vml) {
1809 Element.prototype.rotate = function (deg, cx, cy) {
1811 return this._.rt.deg;
1813 deg = (deg + "").split(separator);
1814 if (deg.length - 1) {
1815 cx = parseFloat(deg[1]);
1816 cy = parseFloat(deg[2]);
1818 deg = parseFloat(deg[0]);
1820 this._.rt.deg = deg;
1822 this._.rt.deg += deg;
1829 this.setBox(this.attrs, cx, cy);
1830 this.Group.style.rotation = this._.rt.deg;
1831 // gradient fix for rotation. TODO
1832 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1833 // fill = fill[0] || {};
1834 // var b = ((360 - this._.rt.deg) - 270) % 360;
1835 // typeof fill.angle != "undefined" && (fill.angle = b);
1838 Element.prototype.setBox = function (params, cx, cy) {
1839 var gs = this.Group.style,
1840 os = (this.shape && this.shape.style) || this.node.style;
1841 params = params || {};
1842 for (var i in params) {
1843 this.attrs[i] = params[i];
1845 cx = cx || this._.rt.cx;
1846 cy = cy || this._.rt.cy;
1847 var attr = this.attrs,
1852 switch (this.type) {
1854 x = attr.cx - attr.r;
1855 y = attr.cy - attr.r;
1859 x = attr.cx - attr.rx;
1860 y = attr.cy - attr.ry;
1868 w = attr.width || 0;
1869 h = attr.height || 0;
1872 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("");
1873 x = attr.x - Math.round(this.W / 2);
1874 y = attr.y - this.H / 2;
1879 if (!this.attrs.path) {
1882 w = this.paper.width;
1883 h = this.paper.height;
1885 var dim = pathDimensions(this.attrs.path),
1895 w = this.paper.width;
1896 h = this.paper.height;
1899 cx = (cx == null) ? x + w / 2 : cx;
1900 cy = (cy == null) ? y + h / 2 : cy;
1901 var left = cx - this.paper.width / 2,
1902 top = cy - this.paper.height / 2;
1903 if (this.type == "path" || this.type == "text") {
1904 (gs.left != left + "px") && (gs.left = left + "px");
1905 (gs.top != top + "px") && (gs.top = top + "px");
1906 this.X = this.type == "text" ? x : -left;
1907 this.Y = this.type == "text" ? y : -top;
1910 (os.left != -left + "px") && (os.left = -left + "px");
1911 (os.top != -top + "px") && (os.top = -top + "px");
1913 (gs.left != left + "px") && (gs.left = left + "px");
1914 (gs.top != top + "px") && (gs.top = top + "px");
1919 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
1920 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
1921 (os.left != x - left + "px") && (os.left = x - left + "px");
1922 (os.top != y - top + "px") && (os.top = y - top + "px");
1923 (os.width != w + "px") && (os.width = w + "px");
1924 (os.height != h + "px") && (os.height = h + "px");
1925 var arcsize = (+params.r || 0) / (Math.min(w, h));
1926 if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
1927 // We should replace element with the new one
1928 var o = createNode(arcsize ? "roundrect" : "rect");
1929 o.arcsize = arcsize;
1930 this.Group.appendChild(o);
1931 this.node.parentNode.removeChild(this.node);
1933 this.arcsize = arcsize;
1934 setFillAndStroke(this, this.attrs);
1935 this.setBox(this.attrs);
1939 Element.prototype.hide = function () {
1940 this.Group.style.display = "none";
1943 Element.prototype.show = function () {
1944 this.Group.style.display = "block";
1947 Element.prototype.getBBox = function () {
1948 if (this.type == "path") {
1949 return pathDimensions(this.attr("path"));
1952 x: this.X + (this.bbx || 0),
1958 Element.prototype.remove = function () {
1959 this[0].parentNode.removeChild(this[0]);
1960 this.Group.parentNode.removeChild(this.Group);
1961 this.shape && this.shape.parentNode.removeChild(this.shape);
1963 Element.prototype.attr = function () {
1964 if (arguments.length == 1 && typeof arguments[0] == "string") {
1965 if (arguments[0] == "translation") {
1966 return this.translate();
1968 return this.attrs[arguments[0]];
1970 if (this.attrs && arguments.length == 1 && arguments[0] instanceof win.Array) {
1972 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1973 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1978 if (arguments.length == 2) {
1980 params[arguments[0]] = arguments[1];
1982 if (arguments.length == 1 && typeof arguments[0] == "object") {
1983 params = arguments[0];
1986 if (params.gradient) {
1987 addGradientFill(this, params.gradient);
1989 if (params.text && this.type == "text") {
1990 this.node.string = params.text;
1992 setFillAndStroke(this, params);
1993 this.setBox(this.attrs);
1997 Element.prototype.toFront = function () {
1998 this.Group.parentNode.appendChild(this.Group);
2001 Element.prototype.toBack = function () {
2002 if (this.Group.parentNode.firstChild != this.Group) {
2003 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2007 Element.prototype.insertAfter = function (element) {
2008 if (element.Group.nextSibling) {
2009 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2011 element.Group.parentNode.appendChild(this.Group);
2015 Element.prototype.insertBefore = function (element) {
2016 element.Group.parentNode.insertBefore(this.Group, element.Group);
2019 var theCircle = function (vml, x, y, r) {
2020 var g = createNode("group"),
2022 o = createNode("oval"),
2024 gl.position = "absolute";
2027 gl.width = vml.width + "px";
2028 gl.height = vml.height + "px";
2029 g.coordsize = vml.coordsize;
2030 g.coordorigin = vml.coordorigin;
2032 var res = new Element(o, g, vml);
2033 res.type = "circle";
2034 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2038 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2039 vml.canvas.appendChild(g);
2042 var theRect = function (vml, x, y, w, h, r) {
2043 var g = createNode("group"),
2045 o = createNode(r ? "roundrect" : "rect"),
2046 arcsize = (+r || 0) / (Math.min(w, h));
2047 o.arcsize = arcsize;
2048 gl.position = "absolute";
2051 gl.width = vml.width + "px";
2052 gl.height = vml.height + "px";
2053 g.coordsize = vml.coordsize;
2054 g.coordorigin = vml.coordorigin;
2056 var res = new Element(o, g, vml);
2058 setFillAndStroke(res, {stroke: "#000"});
2059 res.arcsize = arcsize;
2060 res.setBox({x: x, y: y, width: w, height: h, r: +r});
2061 vml.canvas.appendChild(g);
2064 var theEllipse = function (vml, x, y, rx, ry) {
2065 var g = createNode("group"),
2067 o = createNode("oval"),
2069 gl.position = "absolute";
2072 gl.width = vml.width + "px";
2073 gl.height = vml.height + "px";
2074 g.coordsize = vml.coordsize;
2075 g.coordorigin = vml.coordorigin;
2077 var res = new Element(o, g, vml);
2078 res.type = "ellipse";
2079 setFillAndStroke(res, {stroke: "#000"});
2084 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2085 vml.canvas.appendChild(g);
2088 var theImage = function (vml, src, x, y, w, h) {
2089 var g = createNode("group"),
2091 o = createNode("image"),
2093 gl.position = "absolute";
2096 gl.width = vml.width + "px";
2097 gl.height = vml.height + "px";
2098 g.coordsize = vml.coordsize;
2099 g.coordorigin = vml.coordorigin;
2102 var res = new Element(o, g, vml);
2108 res.setBox({x: x, y: y, width: w, height: h});
2109 vml.canvas.appendChild(g);
2112 var theText = function (vml, x, y, text) {
2113 var g = createNode("group"),
2115 el = createNode("shape"),
2117 path = createNode("path"),
2119 o = createNode("textpath");
2120 gs.position = "absolute";
2123 gs.width = vml.width + "px";
2124 gs.height = vml.height + "px";
2125 g.coordsize = vml.coordsize;
2126 g.coordorigin = vml.coordorigin;
2127 path.v = ["m", Math.round(x), ", ", Math.round(y), "l", Math.round(x) + 1, ", ", Math.round(y)].join("");
2128 path.textpathok = true;
2129 ol.width = vml.width;
2130 ol.height = vml.height;
2131 gs.position = "absolute";
2134 gs.width = vml.width;
2135 gs.height = vml.height;
2139 el.appendChild(path);
2141 var res = new Element(o, g, vml);
2143 res.textpath = path;
2149 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2151 vml.canvas.appendChild(g);
2154 var setSize = function (width, height) {
2155 var cs = this.canvas.style;
2156 this.width = width || this.width;
2157 this.height = height || this.height;
2158 cs.width = this.width + "px";
2159 cs.height = this.height + "px";
2160 cs.clip = "rect(0 " + this.width + "px " + this.height + "px 0)";
2161 this.canvas.coordsize = this.width + " " + this.height;
2164 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2166 if (!doc.namespaces.rvml) {
2167 doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2169 var createNode = function (tagName) {
2170 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2173 var createNode = function (tagName) {
2174 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2177 var create = function () {
2178 var con = getContainer.apply(null, arguments),
2179 container = con.container,
2183 height = con.height;
2185 throw new Error("VML container not found.");
2187 var c = paper.canvas = doc.createElement("div"),
2189 width = parseFloat(width) || "512px";
2190 height = parseFloat(height) || "342px";
2191 paper.width = width;
2192 paper.height = height;
2193 paper.coordsize = width + " " + height;
2194 paper.coordorigin = "0 0";
2195 cs.width = width + "px";
2196 cs.height = height + "px";
2197 cs.position = "absolute";
2198 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2199 if (container == 1) {
2200 doc.body.appendChild(c);
2210 container.style.width = width;
2211 container.style.height = height;
2212 if (container.firstChild) {
2213 container.insertBefore(c, container.firstChild);
2215 container.appendChild(c);
2218 for (var prop in paper) {
2219 container[prop] = paper[prop];
2221 plugins.call(container, container, R.fn);
2222 container.clear = function () {
2223 while (c.firstChild) {
2224 c.removeChild(c.firstChild);
2227 container.raphael = R;
2230 paper.remove = function () {
2231 this.canvas.parentNode.removeChild(this.canvas);
2233 paper.safari = function () {};
2239 var addEvent = (function () {
2240 if (doc.addEventListener) {
2241 return function (obj, type, fn, element) {
2242 var f = function (e) {
2243 return fn.call(element, e);
2245 obj.addEventListener(type, f, false);
2246 return function () {
2247 obj.removeEventListener(type, f, false);
2251 } else if (doc.attachEvent) {
2252 return function (obj, type, fn, element) {
2253 var f = function (e) {
2254 return fn.call(element, e || win.event);
2256 obj.attachEvent("on" + type, f);
2257 var detacher = function () {
2258 obj.detachEvent("on" + type, f);
2261 if (type == "mouseover") {
2262 obj.attachEvent("onmouseenter", f);
2263 return function () {
2264 obj.detachEvent("onmouseenter", f);
2267 } else if (type == "mouseout") {
2268 obj.attachEvent("onmouseleave", f);
2269 return function () {
2270 obj.detachEvent("onmouseleave", f);
2278 for (var i = events.length; i--;) {
2279 (function (eventName) {
2280 Element.prototype[eventName] = function (fn) {
2281 if (typeof fn == "function") {
2282 this.events = this.events || {};
2283 this.events[eventName] = this.events[eventName] || {};
2284 this.events[eventName][fn] = this.events[eventName][fn] || [];
2285 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2289 Element.prototype["un" + eventName] = function (fn) {
2291 this.events[eventName] &&
2292 this.events[eventName][fn] &&
2293 this.events[eventName][fn].length &&
2294 this.events[eventName][fn].shift()() &&
2295 !this.events[eventName][fn].length &&
2296 delete this.events[eventName][fn];
2301 paper.circle = function (x, y, r) {
2302 return theCircle(this, x, y, r);
2304 paper.rect = function (x, y, w, h, r) {
2305 return theRect(this, x, y, w, h, r);
2307 paper.ellipse = function (x, y, rx, ry) {
2308 return theEllipse(this, x, y, rx, ry);
2310 paper.path = function (params, pathString) {
2311 return thePath(params, pathString, this);
2313 paper.image = function (src, x, y, w, h) {
2314 return theImage(this, src, x, y, w, h);
2316 paper.text = function (x, y, text) {
2317 return theText(this, x, y, text);
2319 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
2320 color = color || "#000";
2321 var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
2323 columnWidth = w / wv;
2324 for (var i = 1; i < hv; i++) {
2325 path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
2327 for (var i = 1; i < wv; i++) {
2328 path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
2330 return this.path({stroke: color, "stroke-width": 1}, path.join(","));
2332 paper.pathfinder = function (p, path) {
2334 M: function (x, y) {
2337 C: function (x1, y1, x2, y2, x3, y3) {
2338 this.curveTo(x1, y1, x2, y2, x3, y3);
2340 Q: function (x1, y1, x2, y2) {
2341 this.qcurveTo(x1, y1, x2, y2);
2343 T: function (x, y) {
2344 this.qcurveTo(x, y);
2346 S: function (x1, y1, x2, y2) {
2347 p.curveTo(x1, y1, x2, y2);
2349 L: function (x, y) {
2353 this.lineTo(x, this.last.y);
2356 this.lineTo(this.last.x, y);
2358 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2359 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2366 path = pathToAbsolute(path);
2367 for (var i = 0, ii = path.length; i < ii; i++) {
2368 var b = path[i].shift();
2369 commands[b].apply(p, path[i]);
2373 paper.set = function (itemsArray) {
2374 return new Set(itemsArray);
2376 paper.setSize = setSize;
2377 Element.prototype.stop = function () {
2378 clearTimeout(this.animation_in_progress);
2380 Element.prototype.scale = function (x, y, cx, cy) {
2381 if (x == null && y == null) {
2382 return {x: this._.sx, y: this._.sy, toString: function () { return this.x.toFixed(3) + " " + this.y.toFixed(3); }};
2392 var bb = this.type == "path" ? pathDimensions(a.path) : this.getBBox(),
2393 rcx = bb.x + bb.width / 2,
2394 rcy = bb.y + bb.height / 2;
2395 cx = (+cx || cx == 0) ? cx : rcx;
2396 cy = (+cy || cy == 0) ? cy : rcy;
2397 var dirx = Math.round(x / Math.abs(x)),
2398 diry = Math.round(y / Math.abs(y)),
2399 s = this.node.style,
2400 ncx = cx + (rcx - cx) * x * dirx / this._.sx,
2401 ncy = cy + (rcy - cy) * y * diry / this._.sy;
2402 switch (this.type) {
2405 var neww = a.width * x * dirx / this._.sx,
2406 newh = a.height * y * diry / this._.sy,
2407 newx = ncx - neww / 2,
2408 newy = ncy - newh / 2;
2419 rx: a.rx * x / this._.sx,
2420 ry: a.ry * y / this._.sy,
2421 r: a.r * x / this._.sx,
2427 var path = pathToRelative(a.path),
2429 for (var i = 0, ii = path.length; i < ii; i++) {
2431 if (p[0].toUpperCase() == "M" && skip) {
2436 if (R.svg && p[0].toUpperCase() == "A") {
2437 p[path[i].length - 2] *= x / this._.sx;
2438 p[path[i].length - 1] *= y / this._.sy;
2439 p[1] *= x / this._.sx;
2440 p[2] *= y / this._.sy;
2441 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2443 for (var j = 1, jj = p.length; j < jj; j++) {
2444 p[j] *= (j % 2) ? x / this._.sx : y / this._.sy;
2448 var dim2 = pathDimensions(path),
2449 dx = ncx - dim2.x - dim2.width / 2,
2450 dy = ncy - dim2.y - dim2.height / 2;
2451 path = pathToRelative(path);
2455 this.attr({path: path.join(" ")});
2458 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2459 if (this.transformations) {
2460 this.transformations[2] = "scale(".concat(dirx, ",", diry, ")");
2461 this.node.setAttribute("transform", this.transformations.join(" "));
2462 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2463 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2464 this.attr({x: dx, y: dy});
2468 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=".concat(dirx,
2469 ", M12=0, M21=0, M22=", diry,
2470 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2471 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2474 if (this.transformations) {
2475 this.transformations[2] = "";
2476 this.node.setAttribute("transform", this.transformations.join(" "));
2480 this.node.filterMatrix = "";
2481 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2484 a.scale = [x, y, cx, cy].join(" ");
2491 R.easing_formulas = {
2492 linear: function (time, beg, diff, dur) {
2495 "<": function (time, beg, diff, dur) {
2496 return diff * (time /= dur) * time + beg;
2498 ">": function (time, beg, diff, dur) {
2499 return -diff * (time /= dur) * (time - 2) + beg;
2501 "<>": function (time, beg, diff, dur) {
2502 if ((time /= dur/2) < 1) {
2503 return diff / 2 * time * time + beg;
2505 return -diff / 2 * ((--time) * (time - 2) - 1) + beg;
2507 bounce: function (time, beg, diff, dur) {
2508 if ((time /= dur) < (1 / 2.75)) {
2509 return diff * (7.5625 * time * time) + beg;
2510 } else if (time < (2 / 2.75)) {
2511 return diff * (7.5625 * (time -= (1.5 / 2.75)) * time + .75) + beg;
2512 } else if (time < (2.5 / 2.75)) {
2513 return diff * (7.5625 * (time -= (2.25 / 2.75)) * time + .9375) + beg;
2515 return diff * (7.5625 * (time -= (2.625 / 2.75)) * time + .984375) + beg;
2518 elastic: function (time, beg, diff, dur) {
2526 if ((time /= dur) == 1) {
2532 if (a < Math.abs(diff)) {
2536 s = p / (2 * Math.PI) * Math.asin(diff / a);
2538 return a * Math.pow(2, -10 * time) * Math.sin((time * dur - s) * (2 * Math.PI) / p) + diff + beg;
2542 // animation easing formulas
2543 R.easing = function(easing, time, beg, diff, dur) {
2544 return (R.easing_formulas[easing] || R.easing_formulas.linear)(time, beg, diff, dur);
2547 Element.prototype.animate = function (params, ms, easing, callback) {
2548 clearTimeout(this.animation_in_progress);
2549 if (typeof easing == "function" || !easing) {
2550 callback = easing || null;
2557 for (var attr in params) {
2558 if (attr in availableAnimAttrs) {
2559 from[attr] = this.attr(attr);
2560 (typeof from[attr] == "undefined") && (from[attr] = availableAttrs[attr]);
2561 to[attr] = params[attr];
2562 switch (availableAnimAttrs[attr]) {
2564 diff[attr] = (to[attr] - from[attr]) / ms;
2567 from[attr] = R.getRGB(from[attr]);
2568 var toColour = R.getRGB(to[attr]);
2570 r: (toColour.r - from[attr].r) / ms,
2571 g: (toColour.g - from[attr].g) / ms,
2572 b: (toColour.b - from[attr].b) / ms
2576 var pathes = pathEqualiser(from[attr], to[attr]);
2577 from[attr] = pathes[0];
2578 to[attr] = pathes[1];
2580 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2581 diff[attr][i] = [0];
2582 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2583 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2588 var values = (params[attr] + "").split(separator),
2589 from2 = (from[attr] + "").split(separator);
2592 from[attr] = [0, 0];
2593 diff[attr] = [values[0] / ms, values[1] / ms];
2596 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2597 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2600 params[attr] = values;
2601 from[attr] = (from[attr] + "").split(separator);
2602 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2608 var start = +new Date,
2612 var time = new Date - start,
2616 pos = R.easing(easing, time, 0, 1, ms);
2617 for (var attr in from) {
2618 switch (availableAnimAttrs[attr]) {
2620 now = +from[attr] + pos * ms * diff[attr];
2624 Math.round(from[attr].r + pos * ms * diff[attr].r),
2625 Math.round(from[attr].g + pos * ms * diff[attr].g),
2626 Math.round(from[attr].b + pos * ms * diff[attr].b)
2631 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2632 now[i] = [from[attr][i][0]];
2633 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2634 now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
2636 now[i] = now[i].join(" ");
2638 now = now.join(" ");
2643 var x = diff[attr][0] * (time - prev),
2644 y = diff[attr][1] * (time - prev);
2647 now = [x, y].join(" ");
2650 now = +from[attr][0] + pos * ms * diff[attr][0];
2651 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2654 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(" ");
2658 if (attr == "font-size") {
2659 set[attr] = now + "px";
2665 that.animation_in_progress = setTimeout(tick);
2668 (t.x || t.y) && that.translate(-t.x, -t.y);
2670 clearTimeout(that.animation_in_progress);
2672 (typeof callback == "function") && callback.call(that);
2678 Element.prototype.translate = function (x, y) {
2680 return {x: this._.tx, y: this._.ty};
2684 switch (this.type) {
2687 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
2692 this.attr({x: this.attrs.x + (+x), y: this.attrs.y + (+y)});
2695 var path = pathToRelative(this.attrs.path);
2698 this.attr({path: path.join(" ")});
2705 var Set = function (items) {
2709 for (var i = 0, ii = items.length; i < ii; i++) {
2710 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
2711 this[this.items.length] = this.items[this.items.length] = items[i];
2717 Set.prototype.push = function () {
2720 for (var i = 0, ii = arguments.length; i < ii; i++) {
2721 item = arguments[i];
2722 if (item && (item.constructor == Element || item.constructor == Set)) {
2723 len = this.items.length;
2724 this[len] = this.items[len] = item;
2730 Set.prototype.pop = function (id) {
2731 var res = this.items.splice(id, 1)[0];
2732 for (var j = id, jj = this.items.length; j < jj; j++) {
2733 this[j] = this[j + 1];
2735 delete this[jj + 1];
2739 for (var method in Element.prototype) {
2740 Set.prototype[method] = (function (methodname) {
2741 return function () {
2742 for (var i = 0, ii = this.items.length; i < ii; i++) {
2743 this.items[i][methodname].apply(this.items[i], arguments);
2749 Set.prototype.attr = function (name, value) {
2750 if (name && name instanceof Array && typeof name[0] == "object") {
2751 for (var j = 0, jj = name.length; j < jj; j++) {
2752 this.items[j].attr(name[j]);
2755 for (var i = 0, ii = this.items.length; i < ii; i++) {
2756 this.items[i].attr.apply(this.items[i], arguments);
2762 Set.prototype.getBBox = function () {
2767 for (var i = this.items.length; i--;) {
2768 var box = this.items[i].getBBox();
2771 w.push(box.x + box.width);
2772 h.push(box.y + box.height);
2774 x = Math.min.apply(Math, x);
2775 y = Math.min.apply(Math, y);
2779 width: Math.max.apply(Math, w) - x,
2780 height: Math.max.apply(Math, h) - y
2784 R.registerFont = function (font) {
2788 this.fonts = this.fonts || {};
2794 family = font.face["font-family"];
2795 for (var prop in font.face) {
2796 fontcopy.face[prop] = font.face[prop];
2798 if (this.fonts[family]) {
2799 this.fonts[family].push(fontcopy);
2801 this.fonts[family] = [fontcopy];
2804 fontcopy.face["units-per-em"] = parseInt(font.face["units-per-em"], 10);
2805 for (var glyph in font.glyphs) {
2806 var path = font.glyphs[glyph];
2807 fontcopy.glyphs[glyph] = {
2810 d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
2811 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
2815 for (var k in path.k) {
2816 fontcopy.glyphs[glyph].k[k] = path.k[k];
2823 paper.getFont = function (family, weight, style, stretch) {
2824 stretch = stretch || "normal";
2825 style = style || "normal";
2826 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
2827 var font = R.fonts[family];
2829 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, "") + "(\\s|$)", "i");
2830 for (var fontName in R.fonts) {
2831 if (name.test(fontName)) {
2832 font = R.fonts[fontName];
2839 for (var i = 0, ii = font.length; i < ii; i++) {
2841 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
2848 paper.print = function (x, y, string, font, size) {
2849 var out = this.set(),
2850 letters = (string + "").split(""),
2855 scale = (size || 16) / font.face["units-per-em"];
2856 for (var i = 0, ii = letters.length; i < ii; i++) {
2857 var prev = i && font.glyphs[letters[i - 1]] || {},
2858 curr = font.glyphs[letters[i]];
2859 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
2860 curr && curr.d && out.push(this.path({fill: "#000", stroke: "none"}, curr.d).translate(shift, 0));
2862 out.scale(scale, scale, 0, y).translate(x, (size || 16) / 2);
2867 R.ninja = function () {
2868 var r = window.Raphael;
2869 if (oldRaphael.was) {
2870 window.Raphael = oldRaphael.is;
2873 delete window.Raphael;
2875 window.Raphael = void(0);
2880 R.el = Element.prototype;