2 * Raphael 0.8.2 - 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 var r = Math.round(red).toString(16);
67 var g = Math.round(green).toString(16);
71 var 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 = {}, getRGBcount = [];
123 R.getRGB = function (colour) {
124 if (colour in getRGBcache) {
125 return getRGBcache[colour];
127 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"},
129 if ((colour + "").toLowerCase() in htmlcolors) {
130 colour = htmlcolors[colour.toString().toLowerCase()];
133 return {r: 0, g: 0, b: 0, hex: "#000"};
135 if (colour == "none") {
136 return {r: -1, g: -1, b: -1, hex: "none"};
138 var red, green, blue,
139 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);
142 blue = parseInt(rgb[2].substring(5), 16);
143 green = parseInt(rgb[2].substring(3, 5), 16);
144 red = parseInt(rgb[2].substring(1, 3), 16);
147 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
148 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
149 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
152 rgb = rgb[4].split(/\s*,\s*/);
153 red = parseFloat(rgb[0]);
154 green = parseFloat(rgb[1]);
155 blue = parseFloat(rgb[2]);
158 rgb = rgb[5].split(/\s*,\s*/);
159 red = parseFloat(rgb[0]) * 2.55;
160 green = parseFloat(rgb[1]) * 2.55;
161 blue = parseFloat(rgb[2]) * 2.55;
164 rgb = rgb[6].split(/\s*,\s*/);
165 red = parseFloat(rgb[0]);
166 green = parseFloat(rgb[1]);
167 blue = parseFloat(rgb[2]);
168 return R.hsb2rgb(red, green, blue);
171 rgb = rgb[7].split(/\s*,\s*/);
172 red = parseFloat(rgb[0]) * 2.55;
173 green = parseFloat(rgb[1]) * 2.55;
174 blue = parseFloat(rgb[2]) * 2.55;
175 return R.hsb2rgb(red, green, blue);
177 var rgb = {r: red, g: green, b: blue};
178 var r = Math.round(red).toString(16);
179 (r.length == 1) && (r = "0" + r);
180 var g = Math.round(green).toString(16);
181 (g.length == 1) && (g = "0" + g);
182 var b = Math.round(blue).toString(16);
183 (b.length == 1) && (b = "0" + b);
184 rgb.hex = "#" + r + g + b;
187 res = {r: -1, g: -1, b: -1, hex: "none"};
189 if (getRGBcount.length > 20) {
190 delete getRGBcache[getRGBcount.unshift()];
192 getRGBcount.push(colour);
193 getRGBcache[colour] = res;
196 R.getColor = function (value) {
197 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
198 rgb = this.hsb2rgb(start.h, start.s, start.b);
204 this.getColor.start = {h: 0, s: 1, b: start.b};
209 R.getColor.reset = function () {
213 var pathcache = {}, pathcount = [];
214 R.parsePathString = function (pathString) {
215 if (pathString in pathcache) {
216 return pathcache[pathString];
218 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
220 toString = function () {
222 for (var i = 0, ii = this.length; i < ii; i++) {
223 res += this[i][0] + this[i].join(",").substring(2);
227 if (pathString.toString.toString() == toString.toString()) {
231 pathString.replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, function (a, b, c) {
232 var params = [], name = b.toLowerCase();
233 c.replace(/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig, function (a, b) {
234 b && params.push(+b);
236 while (params.length >= paramCounts[name]) {
237 data.push([b].concat(params.splice(0, paramCounts[name])));
238 if (!paramCounts[name]) {
243 data.toString = toString;
245 if (pathcount.length > 20) {
246 delete pathcache[pathcount.unshift()];
248 pathcount.push(pathString);
249 pathcache[pathString] = data;
252 var pathDimensions = function (path) {
253 var pathArray = path;
254 if (typeof path == "string") {
255 pathArray = R.parsePathString(path);
257 pathArray = pathToAbsolute(pathArray);
258 var x = [], y = [], length = 0;
259 for (var i = 0, ii = pathArray.length; i < ii; i++) {
260 var pa = pathArray[i];
265 x.push(pa[pa.length - 2]);
266 y.push(pa[pa.length - 1]);
269 for (var j = 1, jj = pa.length; j < jj; j++) {
270 (j % 2 ? x : y).push(pa[j]);
274 var minx = Math.min.apply(Math, x),
275 miny = Math.min.apply(Math, y);
289 width: Math.max.apply(Math, x) - minx,
290 height: Math.max.apply(Math, y) - miny,
296 pathToRelative = function (pathArray) {
298 if (typeof pathArray == "string") {
299 pathArray = R.parsePathString(pathArray);
301 var x = 0, y = 0, start = 0;
302 if (pathArray[0][0] == "M") {
306 res.push(["M", x, y]);
308 for (var i = start, ii = pathArray.length; i < ii; i++) {
311 if (pa[0] != pa[0].toLowerCase()) {
312 r[0] = pa[0].toLowerCase();
320 r[6] = +(pa[6] - x).toFixed(3);
321 r[7] = +(pa[7] - y).toFixed(3);
324 r[1] = (pa[1] - y).toFixed(3);
327 for (var j = 1, jj = pa.length; j < jj; j++) {
328 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
333 for (var k = 0, kk = pa.length; k < kk; k++) {
341 x += res[i][res[i].length - 1];
344 y += res[i][res[i].length - 1];
347 x += res[i][res[i].length - 2];
348 y += res[i][res[i].length - 1];
351 res.toString = pathArray.toString;
354 pathToAbsolute = function (pathArray) {
356 if (typeof pathArray == "string") {
357 pathArray = R.parsePathString(pathArray);
362 if (pathArray[0][0] == "M") {
363 x = +pathArray[0][1];
364 y = +pathArray[0][2];
366 res[0] = ["M", x, y];
368 for (var i = start, ii = pathArray.length; i < ii; i++) {
371 if (pa[0] != (pa[0] + "").toUpperCase()) {
372 r[0] = (pa[0] + "").toUpperCase();
380 r[6] = +(pa[6] + x).toFixed(3);
381 r[7] = +(pa[7] + y).toFixed(3);
390 for (var j = 1, jj = pa.length; j < jj; j++) {
391 r[j] = +pa[j] + ((j % 2) ? x : y);
396 for (var k = 0, kk = pa.length; k < kk; k++) {
410 x = res[i][res[i].length - 2];
411 y = res[i][res[i].length - 1];
414 res.toString = pathArray.toString;
417 pecache = {}, pecount = [],
418 pathEqualiser = function (path1, path2) {
419 if ((path1 + path2) in pecache) {
420 return pecache[path1 + path2];
422 var data = [pathToAbsolute(R.parsePathString(path1)), pathToAbsolute(R.parsePathString(path2))],
423 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}],
424 processPath = function (path, d) {
434 var nx = d.x + (d.x - (d.bx || d.x));
435 var ny = d.y + (d.y - (d.by || d.y));
436 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
439 var nx = d.x + (d.x - (d.bx || d.x));
440 var ny = d.y + (d.y - (d.by || d.y));
441 path = ["Q", nx, ny, path[1], path[2]];
444 path = ["L", path[1], d.y];
447 path = ["L", d.x, path[1]];
450 path = ["L", d.X, d.Y];
455 edgeCases = function (a, b, i) {
456 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
457 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
458 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
459 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
460 attrs[a].x = data[a][i][data[a][i].length - 2];
461 attrs[a].y = data[a][i][data[a][i].length - 1];
463 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
464 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]];
465 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
466 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
467 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
468 var x = data[b][i][data[b][i].length - 2];
469 var y = data[b][i][data[b][i].length - 1];
470 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
471 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
473 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
474 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
475 attrs[b].x = data[b][i][data[b][i].length - 2];
476 attrs[b].y = data[b][i][data[b][i].length - 1];
478 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
479 var x = data[b][i][data[b][i].length - 2];
480 var y = data[b][i][data[b][i].length - 1];
481 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
482 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
484 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
485 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
486 attrs[b].x = data[b][i][data[b][i].length - 2];
487 attrs[b].y = data[b][i][data[b][i].length - 1];
489 } else if (data[a][i][0] == "U") {
490 data[a][i][0] = data[b][i][0];
491 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
492 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
497 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
498 data[0][i] = processPath(data[0][i], attrs[0]);
499 data[1][i] = processPath(data[1][i], attrs[1]);
500 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
503 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
504 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
505 attrs[0].x = data[0][i][data[0][i].length - 2];
506 attrs[0].y = data[0][i][data[0][i].length - 1];
507 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
508 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
509 attrs[1].x = data[1][i][data[1][i].length - 2];
510 attrs[1].y = data[1][i][data[1][i].length - 1];
512 if (pecount.length > 20) {
513 delete pecache[pecount.unshift()];
515 pecount.push(path1 + path2);
516 pecache[path1 + path2] = data;
519 toGradient = function (gradient) {
520 if (typeof gradient == "string") {
521 gradient = gradient.split(/\s*\-\s*/);
522 var angle = gradient.shift();
523 if (angle.toLowerCase() == "v") {
525 } else if (angle.toLowerCase() == "h") {
528 angle = parseFloat(angle);
531 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)]};
532 var max = 1 / (Math.max(Math.abs(grobj.vector[2]), Math.abs(grobj.vector[3])) || 1);
533 grobj.vector[2] *= max;
534 grobj.vector[3] *= max;
535 if (grobj.vector[2] < 0) {
536 grobj.vector[0] = -grobj.vector[2];
539 if (grobj.vector[3] < 0) {
540 grobj.vector[1] = -grobj.vector[3];
543 grobj.vector[0] = grobj.vector[0].toFixed(3);
544 grobj.vector[1] = grobj.vector[1].toFixed(3);
545 grobj.vector[2] = grobj.vector[2].toFixed(3);
546 grobj.vector[3] = grobj.vector[3].toFixed(3);
547 for (var i = 0, ii = gradient.length; i < ii; i++) {
549 var par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
550 dot.color = R.getRGB(par[1]).hex;
551 par[2] && (dot.offset = par[2] + "%");
552 grobj.dots.push(dot);
554 for (var i = 1, ii = grobj.dots.length - 1; i < ii; i++) {
555 if (!grobj.dots[i].offset) {
556 var start = parseFloat(grobj.dots[i - 1].offset || 0),
558 for (var j = i + 1; j < ii; j++) {
559 if (grobj.dots[j].offset) {
560 end = grobj.dots[j].offset;
568 end = parseFloat(end);
569 var d = (end - start) / (j - i + 1);
572 grobj.dots[i].offset = start + "%";
581 getContainer = function () {
582 var container, x, y, width, height;
583 if (typeof arguments[0] == "string" || typeof arguments[0] == "object") {
584 if (typeof arguments[0] == "string") {
585 container = doc.getElementById(arguments[0]);
587 container = arguments[0];
589 if (container.tagName) {
590 if (arguments[1] == null) {
592 container: container,
593 width: container.style.pixelWidth || container.offsetWidth,
594 height: container.style.pixelHeight || container.offsetHeight
597 return {container: container, width: arguments[1], height: arguments[2]};
600 } else if (typeof arguments[0] == "number" && arguments.length > 3) {
601 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
604 plugins = function (con, add) {
606 for (var prop in add) if (add.hasOwnProperty(prop) && !(prop in con)) {
607 switch (typeof add[prop]) {
610 con[prop] = con === that ? f : function () { return f.apply(that, arguments); };
614 con[prop] = con[prop] || {};
615 plugins.call(this, con[prop], add[prop]);
618 con[prop] = add[prop];
626 R.toString = function () {
627 return "Your browser supports SVG.\nYou are running Rapha\u00ebl " + this.version;
629 var thePath = function (params, pathString, SVG) {
630 var el = doc.createElementNS(SVG.svgns, "path");
632 SVG.canvas.appendChild(el);
634 var p = new Element(el, SVG);
637 p.last = {x: 0, y: 0, bx: 0, by: 0};
638 p.absolutely = function () {
639 this.isAbsolute = true;
642 p.relatively = function () {
643 this.isAbsolute = false;
646 p.moveTo = function (x, y) {
647 var d = this.isAbsolute?"M":"m";
648 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
649 var oldD = this[0].getAttribute("d") || "";
650 (oldD == "M0,0") && (oldD = "");
651 this[0].setAttribute("d", oldD + d);
652 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
653 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
654 this.attrs.path = oldD + d;
657 p.lineTo = function (x, y) {
658 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
659 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
660 var d = this.isAbsolute?"L":"l";
661 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
662 var oldD = this[0].getAttribute("d") || "";
663 this[0].setAttribute("d", oldD + d);
664 this.attrs.path = oldD + d;
667 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
668 var d = this.isAbsolute ? "A" : "a";
669 d += [parseFloat(rx).toFixed(3), parseFloat(ry).toFixed(3), 0, large_arc_flag, sweep_flag, parseFloat(x).toFixed(3), parseFloat(y).toFixed(3)].join(" ");
670 var oldD = this[0].getAttribute("d") || "";
671 this[0].setAttribute("d", oldD + d);
672 this.last.x = parseFloat(x);
673 this.last.y = parseFloat(y);
674 this.attrs.path = oldD + d;
677 p.cplineTo = function (x1, y1, w1) {
679 return this.lineTo(x1, y1);
682 var x = parseFloat(x1);
683 var y = parseFloat(y1);
684 var w = parseFloat(w1);
685 var d = this.isAbsolute?"C":"c";
686 var attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
687 for (var i = 0, ii = attr.length; i < ii; i++) {
688 d += attr[i].toFixed(3) + " ";
690 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
691 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
692 this.last.bx = attr[2];
693 this.last.by = attr[3];
694 var oldD = this[0].getAttribute("d") || "";
695 this[0].setAttribute("d", oldD + d);
696 this.attrs.path = oldD + d;
700 p.curveTo = function () {
702 command = [0, 1, 2, 3, "s", 5, "c"];
704 var d = command[arguments.length];
705 if (this.isAbsolute) {
708 for (var i = 0, ii = arguments.length; i < ii; i++) {
709 d += parseFloat(arguments[i]).toFixed(3) + " ";
711 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
712 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
713 this.last.bx = parseFloat(arguments[arguments.length - 4]);
714 this.last.by = parseFloat(arguments[arguments.length - 3]);
715 var oldD = this.node.getAttribute("d") || "";
716 this.node.setAttribute("d", oldD + d);
717 this.attrs.path = oldD + d;
720 p.qcurveTo = function () {
722 command = [0, 1, "t", 3, "q"];
724 var d = command[arguments.length];
725 if (this.isAbsolute) {
728 for (var i = 0, ii = arguments.length; i < ii; i++) {
729 d += parseFloat(arguments[i]).toFixed(3) + " ";
731 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
732 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
733 if (arguments.length != 2) {
734 this.last.qx = parseFloat(arguments[arguments.length - 4]);
735 this.last.qy = parseFloat(arguments[arguments.length - 3]);
737 var oldD = this.node.getAttribute("d") || "";
738 this.node.setAttribute("d", oldD + d);
739 this.attrs.path = oldD + d;
742 p.addRoundedCorner = function (r, dir) {
743 var R = .5522 * r, rollback = this.isAbsolute, o = this;
746 rollback = function () {
750 rollback = function () {};
756 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
759 o.curveTo(-R, 0, -r, r - R, -r, r);
766 o.curveTo(R, 0, r, -(r - R), r, -r);
769 o.curveTo(R, 0, r, r - R, r, r);
776 o.curveTo(0, -R, -(R - r), -r, r, -r);
779 o.curveTo(0, -R, R - r, -r, -r, -r);
786 o.curveTo(0, R, -(R - r), r, r, r);
789 o.curveTo(0, R, R - r, r, -r, r);
794 actions[dir[0]]()[dir[1]]();
798 p.andClose = function () {
799 var oldD = this[0].getAttribute("d") || "";
800 this[0].setAttribute("d", oldD + "Z ");
801 this.attrs.path = oldD + "Z ";
805 p.attrs.path = "" + pathString;
807 paper.pathfinder(p, p.attrs.path);
810 !params.gradient && (params.fill = params.fill || "none");
811 params.stroke = params.stroke || "#000";
813 params = {fill: "none", stroke: "#000"};
815 setFillAndStroke(p, params);
818 var addGradientFill = function (o, gradient, SVG) {
819 gradient = toGradient(gradient);
820 var el = doc.createElementNS(SVG.svgns, (gradient.type || "linear") + "Gradient");
821 el.id = "raphael-gradient-" + R.idGenerator++;
822 if (gradient.vector && gradient.vector.length) {
823 el.setAttribute("x1", gradient.vector[0]);
824 el.setAttribute("y1", gradient.vector[1]);
825 el.setAttribute("x2", gradient.vector[2]);
826 el.setAttribute("y2", gradient.vector[3]);
828 SVG.defs.appendChild(el);
829 var isopacity = true;
830 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
831 var stop = doc.createElementNS(SVG.svgns, "stop");
832 if (gradient.dots[i].offset) {
835 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
836 stop.setAttribute("stop-color", R.getRGB(gradient.dots[i].color).hex || "#fff");
837 // ignoring opacity for internal points, because VML doesn't support it
838 el.appendChild(stop);
840 if (isopacity && typeof gradient.dots[ii - 1].opacity != "undefined") {
841 stop.setAttribute("stop-opacity", gradient.dots[ii - 1].opacity);
843 o.setAttribute("fill", "url(#" + el.id + ")");
846 o.style.fillOpacity = 1;
847 o.setAttribute("opacity", 1);
848 o.setAttribute("fill-opacity", 1);
850 var updatePosition = function (o) {
852 var bbox = o.getBBox();
853 o.pattern.setAttribute("patternTransform", "translate(".concat(bbox.x, ",", bbox.y, ")"));
856 var setFillAndStroke = function (o, params) {
861 "-..": [3, 1, 1, 1, 1, 1],
867 "--..": [8, 3, 1, 3, 1, 3]
871 addDashes = function (o, value) {
872 value = dasharray[value.toString().toLowerCase()];
874 var width = o.attrs["stroke-width"] || "1",
875 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
877 for (var i = 0, ii = value.length; i < ii; i++) {
878 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
880 value = dashes.join(",");
881 node.setAttribute("stroke-dasharray", value);
884 for (var att in params) {
885 if (!(att in availableAttrs)) {
888 var value = params[att];
895 var pn = node.parentNode;
896 if (pn.tagName.toLowerCase() != "a") {
897 var hl = doc.createElementNS(o.paper.svgns, "a");
898 pn.insertBefore(hl, node);
899 hl.appendChild(node);
902 pn.setAttributeNS(o.paper.xlink, att, value);
905 if (o.type == "path") {
906 node.setAttribute("d", "M0,0");
907 paper.pathfinder(o, value);
910 node.setAttribute(att, value);
919 value = -attrs.x - (attrs.width || 0);
923 node.setAttribute(att, value);
927 node.setAttribute(att, value);
936 value = -attrs.y - (attrs.height || 0);
940 node.setAttribute(att, value);
944 if (o.type == "rect") {
945 node.setAttribute("rx", value);
946 node.setAttribute("ry", value);
948 node.setAttribute(att, value);
952 if (o.type == "image") {
953 node.setAttributeNS(o.paper.xlink, "href", value);
957 node.style.strokeWidth = value;
958 // Need following line for Firefox
959 node.setAttribute(att, value);
960 if (attrs["stroke-dasharray"]) {
961 addDashes(o, attrs["stroke-dasharray"]);
964 case "stroke-dasharray":
968 o.rotate(value, true);
971 var xy = (value + "").split(separator);
972 o.translate((+xy[0] + 1 || 2) - 1, (+xy[1] + 1 || 2) - 1);
975 var xy = (value + "").split(separator);
976 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
979 var isURL = (value + "").match(/^url\(([^\)]+)\)$/i);
981 var el = doc.createElementNS(o.paper.svgns, "pattern");
982 var ig = doc.createElementNS(o.paper.svgns, "image");
983 el.id = "raphael-pattern-" + R.idGenerator++;
984 el.setAttribute("x", 0);
985 el.setAttribute("y", 0);
986 el.setAttribute("patternUnits", "userSpaceOnUse");
987 ig.setAttribute("x", 0);
988 ig.setAttribute("y", 0);
989 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
992 var img = doc.createElement("img");
993 img.style.position = "absolute";
994 img.style.top = "-9999em";
995 img.style.left = "-9999em";
996 img.onload = function () {
997 el.setAttribute("width", this.offsetWidth);
998 el.setAttribute("height", this.offsetHeight);
999 ig.setAttribute("width", this.offsetWidth);
1000 ig.setAttribute("height", this.offsetHeight);
1001 doc.body.removeChild(this);
1004 doc.body.appendChild(img);
1006 o.paper.defs.appendChild(el);
1007 node.style.fill = "url(#" + el.id + ")";
1008 node.setAttribute("fill", "url(#" + el.id + ")");
1013 delete params.gradient;
1014 delete attrs.gradient;
1015 if (typeof attrs.opacity != "undefined" && typeof params.opacity == "undefined" ) {
1016 node.style.opacity = attrs.opacity;
1017 // Need following line for Firefox
1018 node.setAttribute("opacity", attrs.opacity);
1020 if (typeof attrs["fill-opacity"] != "undefined" && typeof params["fill-opacity"] == "undefined" ) {
1021 node.style.fillOpacity = o.attrs["fill-opacity"];
1022 // Need following line for Firefox
1023 node.setAttribute("fill-opacity", attrs["fill-opacity"]);
1026 node.style[att] = R.getRGB(value).hex;
1027 // Need following line for Firefox
1028 node.setAttribute(att, R.getRGB(value).hex);
1031 addGradientFill(node, value, o.paper);
1034 case "fill-opacity":
1035 if (attrs.gradient) {
1036 var gradient = doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
1038 var stops = gradient.getElementsByTagName("stop");
1039 stops[stops.length - 1].setAttribute("stop-opacity", value);
1044 var cssrule = att.replace(/(\-.)/g, function (w) {
1045 return w.substring(1).toUpperCase();
1047 node.style[cssrule] = value;
1048 // Need following line for Firefox
1049 node.setAttribute(att, value);
1054 tuneText(o, params);
1057 var tuneText = function (el, params) {
1058 if (el.type != "text" || !("text" in params || "font" in params || "font-size" in params || "x" in params || "y" in params)) {
1063 fontSize = node.firstChild ? parseInt(doc.defaultView.getComputedStyle(node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
1065 if ("text" in params) {
1066 while (node.firstChild) {
1067 node.removeChild(node.firstChild);
1069 var texts = (params.text + "").split("\n");
1070 for (var i = 0, ii = texts.length; i < ii; i++) {
1071 var tspan = doc.createElementNS(el.paper.svgns, "tspan");
1072 i && tspan.setAttribute("dy", fontSize * leading);
1073 i && tspan.setAttribute("x", a.x);
1074 tspan.appendChild(doc.createTextNode(texts[i]));
1075 node.appendChild(tspan);
1078 var texts = node.getElementsByTagName("tspan");
1079 for (var i = 0, ii = texts.length; i < ii; i++) {
1080 i && texts[i].setAttribute("dy", fontSize * leading);
1081 i && texts[i].setAttribute("x", a.x);
1084 node.setAttribute("y", a.y);
1085 var bb = el.getBBox(),
1086 dif = a.y - (bb.y + bb.height / 2);
1087 dif && node.setAttribute("y", a.y + dif);
1089 var Element = function (node, svg) {
1095 this.attrs = this.attrs || {};
1096 this.transformations = []; // rotate, translate, scale
1100 rt: {deg: 0, x: 0, y: 0},
1105 Element.prototype.rotate = function (deg, cx, cy) {
1107 return this._.rt.deg;
1109 var bbox = this.getBBox();
1110 deg = deg.toString().split(separator);
1111 if (deg.length - 1) {
1112 cx = parseFloat(deg[1]);
1113 cy = parseFloat(deg[2]);
1115 deg = parseFloat(deg[0]);
1117 this._.rt.deg = deg;
1119 this._.rt.deg += deg;
1124 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1125 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1126 if (this._.rt.deg) {
1127 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
1129 this.transformations[0] = "";
1131 this.node.setAttribute("transform", this.transformations.join(" "));
1134 Element.prototype.hide = function () {
1135 this.node.style.display = "none";
1138 Element.prototype.show = function () {
1139 this.node.style.display = "block";
1142 Element.prototype.remove = function () {
1143 this.node.parentNode.removeChild(this.node);
1145 Element.prototype.getBBox = function () {
1146 var bbox = this.node.getBBox();
1147 if (this.type == "text") {
1148 bbox = {x: bbox.x, y: Infinity, width: bbox.width, height: 0};
1149 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1150 var bb = this.node.getExtentOfChar(i);
1151 (bb.y < bbox.y) && (bbox.y = bb.y);
1152 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1157 Element.prototype.attr = function () {
1158 if (arguments.length == 1 && typeof arguments[0] == "string") {
1159 if (arguments[0] == "translation") {
1160 return this.translate();
1162 return this.attrs[arguments[0]];
1164 if (arguments.length == 1 && arguments[0] instanceof win.Array) {
1166 for (var j in arguments[0]) {
1167 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1171 if (arguments.length == 2) {
1173 params[arguments[0]] = arguments[1];
1174 setFillAndStroke(this, params);
1175 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1176 setFillAndStroke(this, arguments[0]);
1180 Element.prototype.toFront = function () {
1181 this.node.parentNode.appendChild(this.node);
1184 Element.prototype.toBack = function () {
1185 if (this.node.parentNode.firstChild != this.node) {
1186 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1190 Element.prototype.insertAfter = function (element) {
1191 if (element.node.nextSibling) {
1192 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1194 element.node.parentNode.appendChild(this.node);
1198 Element.prototype.insertBefore = function (element) {
1199 element.node.parentNode.insertBefore(this.node, element.node);
1202 var theCircle = function (svg, x, y, r) {
1203 var el = doc.createElementNS(svg.svgns, "circle");
1204 el.setAttribute("cx", x);
1205 el.setAttribute("cy", y);
1206 el.setAttribute("r", r);
1207 el.setAttribute("fill", "none");
1208 el.setAttribute("stroke", "#000");
1210 svg.canvas.appendChild(el);
1212 var res = new Element(el, svg);
1213 res.attrs = res.attrs || {};
1217 res.attrs.stroke = "#000";
1218 res.type = "circle";
1221 var theRect = function (svg, x, y, w, h, r) {
1222 var el = doc.createElementNS(svg.svgns, "rect");
1223 el.setAttribute("x", x);
1224 el.setAttribute("y", y);
1225 el.setAttribute("width", w);
1226 el.setAttribute("height", h);
1228 el.setAttribute("rx", r);
1229 el.setAttribute("ry", r);
1231 el.setAttribute("fill", "none");
1232 el.setAttribute("stroke", "#000");
1234 svg.canvas.appendChild(el);
1236 var res = new Element(el, svg);
1237 res.attrs = res.attrs || {};
1240 res.attrs.width = w;
1241 res.attrs.height = h;
1242 res.attrs.stroke = "#000";
1244 res.attrs.rx = res.attrs.ry = r;
1249 var theEllipse = function (svg, x, y, rx, ry) {
1250 var el = doc.createElementNS(svg.svgns, "ellipse");
1251 el.setAttribute("cx", x);
1252 el.setAttribute("cy", y);
1253 el.setAttribute("rx", rx);
1254 el.setAttribute("ry", ry);
1255 el.setAttribute("fill", "none");
1256 el.setAttribute("stroke", "#000");
1258 svg.canvas.appendChild(el);
1260 var res = new Element(el, svg);
1261 res.attrs = res.attrs || {};
1266 res.attrs.stroke = "#000";
1267 res.type = "ellipse";
1270 var theImage = function (svg, src, x, y, w, h) {
1271 var el = doc.createElementNS(svg.svgns, "image");
1272 el.setAttribute("x", x);
1273 el.setAttribute("y", y);
1274 el.setAttribute("width", w);
1275 el.setAttribute("height", h);
1276 el.setAttribute("preserveAspectRatio", "none");
1277 el.setAttributeNS(svg.xlink, "href", src);
1279 svg.canvas.appendChild(el);
1281 var res = new Element(el, svg);
1282 res.attrs = res.attrs || {};
1285 res.attrs.width = w;
1286 res.attrs.height = h;
1290 var theText = function (svg, x, y, text) {
1291 var el = doc.createElementNS(svg.svgns, "text");
1292 el.setAttribute("x", x);
1293 el.setAttribute("y", y);
1294 el.setAttribute("text-anchor", "middle");
1296 svg.canvas.appendChild(el);
1298 var res = new Element(el, svg);
1299 res.attrs = res.attrs || {};
1303 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000", text: text});
1306 var setSize = function (width, height) {
1307 this.width = width || this.width;
1308 this.height = height || this.height;
1309 this.canvas.setAttribute("width", this.width);
1310 this.canvas.setAttribute("height", this.height);
1313 var create = function () {
1314 var con = getContainer.apply(null, arguments);
1315 var container = con.container,
1319 height = con.height;
1321 throw new Error("SVG container not found.");
1323 paper.canvas = doc.createElementNS(paper.svgns, "svg");
1324 paper.canvas.setAttribute("width", width || 512);
1325 paper.width = width || 512;
1326 paper.canvas.setAttribute("height", height || 342);
1327 paper.height = height || 342;
1328 if (container == 1) {
1329 doc.body.appendChild(paper.canvas);
1330 paper.canvas.style.position = "absolute";
1331 paper.canvas.style.left = x + "px";
1332 paper.canvas.style.top = y + "px";
1334 if (container.firstChild) {
1335 container.insertBefore(paper.canvas, container.firstChild);
1337 container.appendChild(paper.canvas);
1341 canvas: paper.canvas,
1342 clear: function () {
1343 while (this.canvas.firstChild) {
1344 this.canvas.removeChild(this.canvas.firstChild);
1346 this.defs = doc.createElementNS(paper.svgns, "defs");
1347 this.canvas.appendChild(this.defs);
1350 for (var prop in paper) {
1351 if (prop != "create") {
1352 container[prop] = paper[prop];
1355 plugins.call(container, container, R.fn);
1357 container.raphael = R;
1360 paper.remove = function () {
1361 this.canvas.parentNode.removeChild(this.canvas);
1363 paper.svgns = "http://www.w3.org/2000/svg";
1364 paper.xlink = "http://www.w3.org/1999/xlink";
1365 paper.safari = function () {
1366 if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) {
1367 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1368 setTimeout(function () {rect.remove();});
1375 R.toString = function () {
1376 return "Your browser doesn\u2019t support SVG.\nYou are running Rapha\u00ebl " + this.version;
1378 thePath = function (params, pathString, VML) {
1379 var g = createNode("group"), gl = g.style;
1380 gl.position = "absolute";
1383 gl.width = VML.width + "px";
1384 gl.height = VML.height + "px";
1385 var el = createNode("shape"), ol = el.style;
1386 ol.width = VML.width + "px";
1387 ol.height = VML.height + "px";
1389 if (params["class"]) {
1390 el.className = "rvml " + params["class"];
1392 el.coordsize = this.coordsize;
1393 el.coordorigin = this.coordorigin;
1395 var p = new Element(el, g, VML);
1396 p.isAbsolute = true;
1399 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1401 p.absolutely = function () {
1402 this.isAbsolute = true;
1405 p.relatively = function () {
1406 this.isAbsolute = false;
1409 p.moveTo = function (x, y) {
1410 var d = this.isAbsolute?"m":"t";
1411 d += Math.round(parseFloat(x)) + " " + Math.round(parseFloat(y));
1412 this.node.path = this.Path += d;
1413 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1414 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1415 this.last.isAbsolute = this.isAbsolute;
1416 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1419 p.lineTo = function (x, y) {
1420 var d = this.isAbsolute?"l":"r";
1421 d += Math.round(parseFloat(x)) + " " + Math.round(parseFloat(y));
1422 this[0].path = this.Path += d;
1423 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1424 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1425 this.last.isAbsolute = this.isAbsolute;
1426 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1429 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1430 // for more information of where this math came from visit:
1431 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1432 x2 = (this.isAbsolute ? 0 : this.last.x) + x2;
1433 y2 = (this.isAbsolute ? 0 : this.last.y) + y2;
1434 var x1 = this.last.x,
1438 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1439 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1440 cx = k * rx * y / ry + (x1 + x2) / 2,
1441 cy = k * -ry * x / rx + (y1 + y2) / 2,
1442 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1443 left = Math.round(cx - rx),
1444 top = Math.round(cy - ry);
1445 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(", ");
1446 this.node.path = this.Path += d;
1447 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2);
1448 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2);
1449 this.last.isAbsolute = this.isAbsolute;
1450 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1453 p.cplineTo = function (x1, y1, w1) {
1455 return this.lineTo(x1, y1);
1457 var x = Math.round(Math.round(parseFloat(x1) * 100) / 100),
1458 y = Math.round(Math.round(parseFloat(y1) * 100) / 100),
1459 w = Math.round(Math.round(parseFloat(w1) * 100) / 100),
1460 d = this.isAbsolute ? "c" : "v",
1461 attr = [Math.round(this.last.x) + w, Math.round(this.last.y), x - w, y, x, y],
1462 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1463 d += attr.join(" ") + " ";
1464 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1465 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1466 this.last.bx = attr[2];
1467 this.last.by = attr[3];
1468 this.node.path = this.Path += d;
1469 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1473 p.curveTo = function () {
1474 var d = this.isAbsolute ? "c" : "v";
1475 if (arguments.length == 6) {
1476 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1477 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1478 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4]);
1479 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5]);
1480 d += [Math.round(parseFloat(arguments[0])),
1481 Math.round(parseFloat(arguments[1])),
1482 Math.round(parseFloat(arguments[2])),
1483 Math.round(parseFloat(arguments[3])),
1484 Math.round(parseFloat(arguments[4])),
1485 Math.round(parseFloat(arguments[5]))].join(" ") + " ";
1486 this.last.isAbsolute = this.isAbsolute;
1487 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1489 if (arguments.length == 4) {
1490 var bx = this.last.x * 2 - this.last.bx;
1491 var by = this.last.y * 2 - this.last.by;
1492 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0]);
1493 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1]);
1494 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1495 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1496 d += [Math.round(bx), Math.round(by),
1497 Math.round(parseFloat(arguments[0])),
1498 Math.round(parseFloat(arguments[1])),
1499 Math.round(parseFloat(arguments[2])),
1500 Math.round(parseFloat(arguments[3]))].join(" ") + " ";
1501 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1503 this.node.path = this.Path += d;
1506 p.qcurveTo = function () {
1508 if (arguments.length == 4) {
1509 this.last.qx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0]);
1510 this.last.qy = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1]);
1511 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1512 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1513 d += [Math.round(this.last.qx),
1514 Math.round(this.last.qy),
1515 Math.round(this.last.x),
1516 Math.round(this.last.y)].join(" ") + " ";
1517 this.last.isAbsolute = this.isAbsolute;
1518 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1520 if (arguments.length == 2) {
1521 this.last.qx = this.last.x * 2 - this.last.qx;
1522 this.last.qy = this.last.y * 2 - this.last.qy;
1523 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1524 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1525 d += [Math.round(this.last.qx),
1526 Math.round(this.last.qy),
1527 Math.round(this.last.x),
1528 Math.round(this.last.y)].join(" ") + " ";
1529 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1531 this.node.path = this.Path += d;
1532 this.path.push({type: "qcurve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
1535 p.addRoundedCorner = function (r, dir) {
1536 var R = .5522 * r, rollback = this.isAbsolute, o = this;
1539 rollback = function () {
1543 rollback = function () {};
1549 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
1552 o.curveTo(-R, 0, -r, r - R, -r, r);
1559 o.curveTo(R, 0, r, -(r - R), r, -r);
1562 o.curveTo(R, 0, r, r - R, r, r);
1569 o.curveTo(0, -R, -(R - r), -r, r, -r);
1572 o.curveTo(0, -R, R - r, -r, -r, -r);
1579 o.curveTo(0, R, -(R - r), r, r, r);
1582 o.curveTo(0, R, R - r, r, -r, r);
1587 actions[dir.charAt(0)]()[dir.charAt(1)]();
1591 p.andClose = function () {
1592 this.node.path = (this.Path += "x");
1593 this.attrs.path += "z";
1599 paper.pathfinder(p, "" + pathString);
1602 params.fill = params.fill || "none";
1603 params.stroke = params.stroke || "#000";
1605 params = {fill: "none", stroke: "#000"};
1607 setFillAndStroke(p, params);
1608 if (params.gradient) {
1609 addGradientFill(p, params.gradient);
1611 VML.canvas.appendChild(g);
1614 var setFillAndStroke = function (o, params) {
1618 o.attrs = o.attrs || {};
1619 for (var par in params) {
1620 o.attrs[par] = params[par];
1622 params.href && (node.href = params.href);
1623 params.title && (node.title = params.title);
1624 params.target && (node.target = params.target);
1625 if (params.path && o.type == "path") {
1628 paper.pathfinder(o, params.path);
1630 if (params.rotation != null) {
1631 o.rotate(params.rotation, true);
1633 if (params.translation) {
1634 var xy = (params.translation + "").split(separator);
1635 o.translate(xy[0], xy[1]);
1638 var xy = (params.scale + "").split(separator);
1639 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1641 if (o.type == "image" && params.src) {
1642 node.src = params.src;
1644 if (o.type == "image" && params.opacity) {
1645 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1646 node.style.filter = (node.filterMatrix || "") + (node.filterOpacity || "");
1648 params.font && (s.font = params.font);
1649 params["font-family"] && (s.fontFamily = params["font-family"]);
1650 params["font-size"] && (s.fontSize = params["font-size"]);
1651 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1652 params["font-style"] && (s.fontStyle = params["font-style"]);
1653 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"]) {
1654 o = o.shape || node;
1655 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || createNode("fill");
1656 if ("fill-opacity" in params || "opacity" in params) {
1657 fill.opacity = ((+params["fill-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1659 params.fill && (fill.on = true);
1660 if (typeof fill.on == "undefined" || params.fill == "none") {
1663 if (fill.on && params.fill) {
1664 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1666 fill.src = isURL[1];
1669 fill.color = R.getRGB(params.fill).hex;
1671 fill.type = "solid";
1674 o.appendChild(fill);
1675 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || createNode("stroke");
1676 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"]) {
1679 if (params.stroke == "none" || typeof stroke.on == "undefined" || params.stroke == 0) {
1682 if (stroke.on && params.stroke) {
1683 stroke.color = R.getRGB(params.stroke).hex;
1685 stroke.opacity = ((+params["stroke-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1686 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1687 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1688 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1689 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"]) || 1) * 12 / 16);
1690 if (params["stroke-dasharray"]) {
1694 "-.": "shortdashdot",
1695 "-..": "shortdashdotdot",
1700 "--.": "longdashdot",
1701 "--..": "longdashdotdot"
1703 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1705 o.appendChild(stroke);
1707 if (res.type == "text") {
1708 var span = doc.createElement("span"),
1714 s.display = "inline";
1715 a.font && (s.font = a.font);
1716 a["font-family"] && (s.fontFamily = a["font-family"]);
1717 a["font-size"] && (s.fontSize = a["font-size"]);
1718 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1719 a["font-style"] && (s.fontStyle = a["font-style"]);
1720 res.node.parentNode.appendChild(span);
1721 span.innerText = res.node.string;
1722 res.W = a.w = span.offsetWidth;
1723 res.H = a.h = span.offsetHeight;
1725 res.Y = a.y + Math.round(res.H / 2);
1726 res.node.parentNode.removeChild(span);
1728 // text-anchor emulation
1729 switch (a["text-anchor"]) {
1731 res.node.style["v-text-align"] = "left";
1732 res.bbx = Math.round(res.W / 2);
1735 res.node.style["v-text-align"] = "right";
1736 res.bbx = -Math.round(res.W / 2);
1739 res.node.style["v-text-align"] = "center";
1744 var getAngle = function (a, b, c, d) {
1745 var angle = Math.round(Math.atan((parseFloat(c) - parseFloat(a)) / (parseFloat(d) - parseFloat(b))) * 57.29) || 0;
1746 if (!angle && parseFloat(a) < parseFloat(b)) {
1755 var addGradientFill = function (o, gradient) {
1756 gradient = toGradient(gradient);
1757 o.attrs = o.attrs || {};
1758 var attrs = o.attrs;
1759 o.attrs.gradient = gradient;
1760 o = o.shape || o[0];
1761 var fill = o.getElementsByTagName("fill");
1765 fill = createNode("fill");
1767 if (gradient.dots.length) {
1769 fill.method = "none";
1770 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1771 if (typeof gradient.dots[0].color != "undefined") {
1772 fill.color = R.getRGB(gradient.dots[0].color).hex;
1774 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1775 fill.color2 = R.getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1778 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1779 if (gradient.dots[i].offset) {
1780 clrs.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
1783 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;
1785 fill.colors.value = clrs.join(",");
1786 fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
1788 fill.colors && (fill.colors.value = "0% " + fill.color);
1790 fill.opacity = fillOpacity;
1791 if (typeof gradient.angle != "undefined") {
1792 fill.angle = (-gradient.angle + 270) % 360;
1793 } else if (gradient.vector) {
1794 fill.angle = getAngle.apply(null, gradient.vector);
1796 if ((gradient.type + "").toLowerCase() == "radial") {
1797 fill.focus = "100%";
1798 fill.focusposition = "0.5 0.5";
1802 var Element = function (node, group, vml) {
1822 Element.prototype.rotate = function (deg, cx, cy) {
1824 return this._.rt.deg;
1826 deg = deg.toString().split(separator);
1827 if (deg.length - 1) {
1828 cx = parseFloat(deg[1]);
1829 cy = parseFloat(deg[2]);
1831 deg = parseFloat(deg[0]);
1833 this._.rt.deg = deg;
1835 this._.rt.deg += deg;
1842 this.setBox(null, cx, cy);
1843 this.Group.style.rotation = this._.rt.deg;
1844 // gradient fix for rotation. TODO
1845 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1846 // fill = fill[0] || {};
1847 // var b = ((360 - this._.rt.deg) - 270) % 360;
1848 // typeof fill.angle != "undefined" && (fill.angle = b);
1851 Element.prototype.setBox = function (params, cx, cy) {
1852 var gs = this.Group.style,
1853 os = (this.shape && this.shape.style) || this.node.style;
1854 params = params || {};
1855 for (var i in params) {
1856 this.attrs[i] = params[i];
1858 cx = cx || this._.rt.cx;
1859 cy = cy || this._.rt.cy;
1860 var attr = this.attrs, x, y, w, h;
1861 switch (this.type) {
1863 x = attr.cx - attr.r;
1864 y = attr.cy - attr.r;
1868 x = attr.cx - attr.rx;
1869 y = attr.cy - attr.ry;
1877 w = attr.width || 0;
1878 h = attr.height || 0;
1881 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("");
1882 x = attr.x - Math.round(this.W / 2);
1883 y = attr.y - this.H / 2;
1888 if (!this.attrs.path) {
1891 w = this.paper.width;
1892 h = this.paper.height;
1894 var dim = pathDimensions(this.attrs.path),
1904 w = this.paper.width;
1905 h = this.paper.height;
1908 cx = (cx == null) ? x + w / 2 : cx;
1909 cy = (cy == null) ? y + h / 2 : cy;
1910 var left = cx - this.paper.width / 2,
1911 top = cy - this.paper.height / 2;
1912 if (this.type == "path" || this.type == "text") {
1913 (gs.left != left + "px") && (gs.left = left + "px");
1914 (gs.top != top + "px") && (gs.top = top + "px");
1915 this.X = this.type == "text" ? x : -left;
1916 this.Y = this.type == "text" ? y : -top;
1919 (os.left != -left + "px") && (os.left = -left + "px");
1920 (os.top != -top + "px") && (os.top = -top + "px");
1922 (gs.left != left + "px") && (gs.left = left + "px");
1923 (gs.top != top + "px") && (gs.top = top + "px");
1928 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
1929 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
1930 (os.left != x - left + "px") && (os.left = x - left + "px");
1931 (os.top != y - top + "px") && (os.top = y - top + "px");
1932 (os.width != w + "px") && (os.width = w + "px");
1933 (os.height != h + "px") && (os.height = h + "px");
1934 var arcsize = (+params.r || 0) / (Math.min(w, h));
1935 if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
1936 // We should replace element with the new one
1937 var o = createNode(arcsize ? "roundrect" : "rect");
1938 o.arcsize = arcsize;
1939 this.Group.appendChild(o);
1940 this.node.parentNode.removeChild(this.node);
1942 this.arcsize = arcsize;
1943 setFillAndStroke(this, this.attrs);
1944 this.setBox(this.attrs);
1948 Element.prototype.hide = function () {
1949 this.Group.style.display = "none";
1952 Element.prototype.show = function () {
1953 this.Group.style.display = "block";
1956 Element.prototype.getBBox = function () {
1957 if (this.type == "path") {
1958 return pathDimensions(this.attr("path"));
1961 x: this.X + (this.bbx || 0),
1967 Element.prototype.remove = function () {
1968 this[0].parentNode.removeChild(this[0]);
1969 this.Group.parentNode.removeChild(this.Group);
1970 this.shape && this.shape.parentNode.removeChild(this.shape);
1972 Element.prototype.attr = function () {
1973 if (arguments.length == 1 && typeof arguments[0] == "string") {
1974 if (arguments[0] == "translation") {
1975 return this.translate();
1977 return this.attrs[arguments[0]];
1979 if (this.attrs && arguments.length == 1 && arguments[0] instanceof win.Array) {
1981 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1982 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1987 if (arguments.length == 2) {
1989 params[arguments[0]] = arguments[1];
1991 if (arguments.length == 1 && typeof arguments[0] == "object") {
1992 params = arguments[0];
1995 if (params.gradient) {
1996 addGradientFill(this, params.gradient);
1998 if (params.text && this.type == "text") {
1999 this.node.string = params.text;
2002 this.node.id = params.id;
2004 setFillAndStroke(this, params);
2005 this.setBox(params);
2009 Element.prototype.toFront = function () {
2010 this.Group.parentNode.appendChild(this.Group);
2013 Element.prototype.toBack = function () {
2014 if (this.Group.parentNode.firstChild != this.Group) {
2015 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2019 Element.prototype.insertAfter = function (element) {
2020 if (element.Group.nextSibling) {
2021 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2023 element.Group.parentNode.appendChild(this.Group);
2027 Element.prototype.insertBefore = function (element) {
2028 element.Group.parentNode.insertBefore(this.Group, element.Group);
2031 var theCircle = function (vml, x, y, r) {
2032 var g = createNode("group");
2033 var o = createNode("oval");
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"),
2047 o = createNode(r ? "roundrect" : "rect"),
2048 arcsize = (+r || 0) / (Math.min(w, h));
2049 o.arcsize = arcsize;
2051 var res = new Element(o, g, vml);
2053 setFillAndStroke(res, {stroke: "#000"});
2059 res.arcsize = arcsize;
2060 res.setBox({x: x, y: y, width: w, height: h});
2061 vml.canvas.appendChild(g);
2064 var theEllipse = function (vml, x, y, rx, ry) {
2065 var g = createNode("group");
2066 var o = createNode("oval");
2068 var res = new Element(o, g, vml);
2069 res.type = "ellipse";
2070 setFillAndStroke(res, {stroke: "#000"});
2075 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2076 vml.canvas.appendChild(g);
2079 var theImage = function (vml, src, x, y, w, h) {
2080 var g = createNode("group");
2081 var o = createNode("image");
2084 var res = new Element(o, g, vml);
2090 res.setBox({x: x, y: y, width: w, height: h});
2091 vml.canvas.appendChild(g);
2094 var theText = function (vml, x, y, text) {
2095 var g = createNode("group"), gs = g.style;
2096 var el = createNode("shape"), ol = el.style;
2097 var path = createNode("path"), ps = path.style;
2098 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
2099 path.textpathok = true;
2100 ol.width = vml.width;
2101 ol.height = vml.height;
2102 gs.position = "absolute";
2105 gs.width = vml.width;
2106 gs.height = vml.height;
2107 var o = createNode("textpath");
2110 o.coordsize = vml.coordsize;
2111 o.coordorigin = vml.coordorigin;
2113 el.appendChild(path);
2115 var res = new Element(o, g, vml);
2117 res.textpath = path;
2123 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2125 vml.canvas.appendChild(g);
2128 var setSize = function (width, height) {
2129 this.width = width || this.width;
2130 this.height = height || this.height;
2131 this.canvas.style.width = this.width + "px";
2132 this.canvas.style.height = this.height + "px";
2133 this.canvas.parentNode.style.clip = "rect(0 " + this.width + "px " + this.height + "px 0)";
2134 this.canvas.coordsize = this.width + " " + this.height;
2137 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2139 if (!doc.namespaces.rvml) {
2140 doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2142 var createNode = function (tagName) {
2143 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2146 var createNode = function (tagName) {
2147 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2150 var create = function () {
2151 var con = getContainer.apply(null, arguments);
2152 var container = con.container,
2156 height = con.height;
2158 throw new Error("VML container not found.");
2160 var c = doc.createElement("div"),
2161 d = doc.createElement("div"),
2162 r = paper.canvas = createNode("group"),
2163 cs = c.style, rs = r.style;
2164 paper.width = width;
2165 paper.height = height;
2166 width = width || "512px";
2167 height = height || "342px";
2168 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2171 cs.position = "absolute";
2172 rs.position = "absolute";
2173 d.style.position = "relative";
2176 r.coordsize = (/%$/.test(width) ? width : parseFloat(width)) + " " + (/%$/.test(height) ? height : parseFloat(height));
2177 r.coordorigin = "0 0";
2179 var b = createNode("rect"), bs = b.style;
2180 bs.left = bs.top = 0;
2181 bs.width = rs.width;
2182 bs.height = rs.height;
2183 b.filled = b.stroked = "f";
2188 if (container == 1) {
2189 doc.body.appendChild(d);
2190 cs.position = "absolute";
2202 cs.width = container.style.width = width;
2203 cs.height = container.style.height = height;
2204 if (container.firstChild) {
2205 container.insertBefore(d, container.firstChild);
2207 container.appendChild(d);
2210 for (var prop in paper) {
2211 container[prop] = paper[prop];
2213 plugins.call(container, container, R.fn);
2214 container.clear = function () {
2216 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
2217 if (r.childNodes[i] != b) {
2218 todel.push(r.childNodes[i]);
2221 for (i = 0, ii = todel.length; i < ii; i++) {
2222 r.removeChild(todel[i]);
2225 container.raphael = R;
2228 paper.remove = function () {
2229 this.canvas.parentNode.parentNode.parentNode.removeChild(this.canvas.parentNode.parentNode);
2231 paper.safari = function () {};
2237 var addEvent = (function () {
2238 if (doc.addEventListener) {
2239 return function (obj, type, fn, element) {
2240 var f = function (e) {
2241 return fn.call(element, e);
2243 obj.addEventListener(type, f, false);
2244 return function () {
2245 obj.removeEventListener(type, f, false);
2249 } else if (doc.attachEvent) {
2250 return function (obj, type, fn, element) {
2251 var f = function (e) {
2252 return fn.call(element, e || win.event);
2254 obj.attachEvent("on" + type, f);
2255 var detacher = function () {
2256 obj.detachEvent("on" + type, f);
2259 if (type == "mouseover") {
2260 obj.attachEvent("onmouseenter", f);
2261 return function () {
2262 obj.detachEvent("onmouseenter", f);
2265 } else if (type == "mouseout") {
2266 obj.attachEvent("onmouseleave", f);
2267 return function () {
2268 obj.detachEvent("onmouseleave", f);
2276 for (var i = events.length; i--;) {
2277 (function (eventName) {
2278 Element.prototype[eventName] = function (fn) {
2279 if (typeof fn == "function") {
2280 this.events = this.events || {};
2281 this.events[eventName] = this.events[eventName] || {};
2282 this.events[eventName][fn] = this.events[eventName][fn] || [];
2283 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2287 Element.prototype["un" + eventName] = function (fn) {
2289 this.events[eventName] &&
2290 this.events[eventName][fn] &&
2291 this.events[eventName][fn].length &&
2292 this.events[eventName][fn].shift()() &&
2293 !this.events[eventName][fn].length &&
2294 delete this.events[eventName][fn];
2299 paper.circle = function (x, y, r) {
2300 return theCircle(this, x, y, r);
2302 paper.rect = function (x, y, w, h, r) {
2303 return theRect(this, x, y, w, h, r);
2305 paper.ellipse = function (x, y, rx, ry) {
2306 return theEllipse(this, x, y, rx, ry);
2308 paper.path = function (params, pathString) {
2309 return thePath(params, pathString, this);
2311 paper.image = function (src, x, y, w, h) {
2312 return theImage(this, src, x, y, w, h);
2314 paper.text = function (x, y, text) {
2315 return theText(this, x, y, text);
2317 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
2318 color = color || "#000";
2319 var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
2321 columnWidth = w / wv;
2322 for (var i = 1; i < hv; i++) {
2323 path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
2325 for (var i = 1; i < wv; i++) {
2326 path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
2328 return this.path({stroke: color, "stroke-width": 1}, path.join(","));
2330 paper.pathfinder = function (p, path) {
2332 M: function (x, y) {
2335 C: function (x1, y1, x2, y2, x3, y3) {
2336 this.curveTo(x1, y1, x2, y2, x3, y3);
2338 Q: function (x1, y1, x2, y2) {
2339 this.qcurveTo(x1, y1, x2, y2);
2341 T: function (x, y) {
2342 this.qcurveTo(x, y);
2344 S: function (x1, y1, x2, y2) {
2345 p.curveTo(x1, y1, x2, y2);
2347 L: function (x, y) {
2351 this.lineTo(x, this.last.y);
2354 this.lineTo(this.last.x, y);
2356 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2357 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2364 path = pathToAbsolute(path);
2365 for (var i = 0, ii = path.length; i < ii; i++) {
2366 var b = path[i].shift();
2367 commands[b].apply(p, path[i]);
2371 paper.set = function (itemsArray) {
2372 return new Set(itemsArray);
2374 paper.setSize = setSize;
2375 Element.prototype.stop = function () {
2376 clearTimeout(this.animation_in_progress);
2378 Element.prototype.scale = function (x, y, cx, cy) {
2379 if (x == null && y == null) {
2380 return {x: this._.sx, y: this._.sy, toString: function () { return this.x.toFixed(3) + " " + this.y.toFixed(3); }};
2384 var dx, dy, dcx, dcy, a = this.attrs;
2386 var bb = this.type == "path" ? pathDimensions(a.path) : this.getBBox(),
2387 rcx = bb.x + bb.width / 2,
2388 rcy = bb.y + bb.height / 2;
2389 cx = (+cx || cx == 0) ? cx : rcx;
2390 cy = (+cy || cy == 0) ? cy : rcy;
2391 var dirx = Math.round(x / Math.abs(x)),
2392 diry = Math.round(y / Math.abs(y)),
2393 s = this.node.style,
2394 ncx = cx + (rcx - cx) * x * dirx / this._.sx,
2395 ncy = cy + (rcy - cy) * y * diry / this._.sy;
2396 switch (this.type) {
2399 var neww = a.width * x * dirx / this._.sx,
2400 newh = a.height * y * diry / this._.sy,
2401 newx = ncx - neww / 2,
2402 newy = ncy - newh / 2;
2413 rx: a.rx * x / this._.sx,
2414 ry: a.ry * y / this._.sy,
2415 r: a.r * x / this._.sx,
2421 var path = pathToRelative(a.path),
2423 for (var i = 0, ii = path.length; i < ii; i++) {
2425 if (p[0].toUpperCase() == "M" && skip) {
2430 if (R.svg && p[0].toUpperCase() == "A") {
2431 p[path[i].length - 2] *= x / this._.sx;
2432 p[path[i].length - 1] *= y / this._.sy;
2433 p[1] *= x / this._.sx;
2434 p[2] *= y / this._.sy;
2435 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2437 for (var j = 1, jj = p.length; j < jj; j++) {
2438 p[j] *= (j % 2) ? x / this._.sx : y / this._.sy;
2442 var dim2 = pathDimensions(path),
2443 dx = ncx - dim2.x - dim2.width / 2,
2444 dy = ncy - dim2.y - dim2.height / 2;
2445 path = pathToRelative(path);
2449 this.attr({path: path.join(" ")});
2452 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2453 if (this.transformations) {
2454 this.transformations[2] = "scale(".concat(dirx, ",", diry, ")");
2455 this.node.setAttribute("transform", this.transformations.join(" "));
2456 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2457 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2458 this.attr({x: dx, y: dy});
2462 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=".concat(dirx,
2463 ", M12=0, M21=0, M22=", diry,
2464 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2465 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2468 if (this.transformations) {
2469 this.transformations[2] = "";
2470 this.node.setAttribute("transform", this.transformations.join(" "));
2474 this.node.filterMatrix = "";
2475 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2478 a.scale = [x, y, cx, cy].join(" ");
2485 R.easing_formulas = {
2486 linear: function( time, beg, diff, dur ) {
2487 return beg + diff * time;
2489 "<": function (time, beg, diff, dur) {
2490 return diff * (time /= dur) * time + beg;
2492 ">": function (time, beg, diff, dur) {
2493 return -diff * (time /= dur) * (time - 2) + beg;
2495 "<>": function (time, beg, diff, dur) {
2496 if ((time /= dur/2) < 1) {
2497 return diff / 2 * time * time + beg;
2499 return -diff / 2 * ((--time) * (time - 2) - 1) + beg;
2501 bounce: function (time, beg, diff, dur) {
2502 if ((time /= dur) < (1 / 2.75)) {
2503 return diff * (7.5625 * time * time) + beg;
2504 } else if (time < (2 / 2.75)) {
2505 return diff * (7.5625 * (time -= (1.5 / 2.75)) * time + .75) + beg;
2506 } else if (time < (2.5 / 2.75)) {
2507 return diff * (7.5625 * (time -= (2.25 / 2.75)) * time + .9375) + beg;
2509 return diff * (7.5625 * (time -= (2.625 / 2.75)) * time + .984375) + beg;
2514 // animation easing formulas
2515 R.easing = function(easing, time, beg, diff, dur) {
2516 return (R.easing_formulas[easing] || R.easing_formulas.linear)(time, beg, diff, dur);
2519 Element.prototype.animate = function (params, ms, easing, callback) {
2520 clearTimeout(this.animation_in_progress);
2521 if (typeof easing == "function" || !easing) {
2522 callback = easing || null;
2529 for (var attr in params) {
2530 if (attr in availableAnimAttrs) {
2531 from[attr] = this.attr(attr);
2532 (typeof from[attr] == "undefined") && (from[attr] = availableAttrs[attr]);
2533 to[attr] = params[attr];
2534 switch (availableAnimAttrs[attr]) {
2536 diff[attr] = (to[attr] - from[attr]) / ms;
2539 from[attr] = R.getRGB(from[attr]);
2540 var toColour = R.getRGB(to[attr]);
2542 r: (toColour.r - from[attr].r) / ms,
2543 g: (toColour.g - from[attr].g) / ms,
2544 b: (toColour.b - from[attr].b) / ms
2548 var pathes = pathEqualiser(from[attr], to[attr]);
2549 from[attr] = pathes[0];
2550 to[attr] = pathes[1];
2552 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2553 diff[attr][i] = [0];
2554 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2555 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2560 var values = (params[attr] + "").split(separator),
2561 from2 = (from[attr] + "").split(separator);
2564 from[attr] = [0, 0];
2565 diff[attr] = [values[0] / ms, values[1] / ms];
2568 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2569 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2572 params[attr] = values;
2573 from[attr] = (from[attr] + "").split(separator);
2574 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2580 var start = +new Date,
2584 var time = new Date - start,
2588 pos = R.easing(easing, time, 0, 1, ms);
2589 for (var attr in from) {
2590 switch (availableAnimAttrs[attr]) {
2592 now = +from[attr] + pos * ms * diff[attr];
2596 Math.round(from[attr].r + pos * ms * diff[attr].r),
2597 Math.round(from[attr].g + pos * ms * diff[attr].g),
2598 Math.round(from[attr].b + pos * ms * diff[attr].b)
2603 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2604 now[i] = [from[attr][i][0]];
2605 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2606 now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
2608 now[i] = now[i].join(" ");
2610 now = now.join(" ");
2615 var x = diff[attr][0] * (time - prev),
2616 y = diff[attr][1] * (time - prev);
2619 now = [x, y].join(" ");
2622 now = +from[attr][0] + pos * ms * diff[attr][0];
2623 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2626 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(" ");
2630 if (attr == "font-size") {
2631 set[attr] = now + "px";
2637 that.animation_in_progress = setTimeout(tick);
2640 (t.x || t.y) && that.translate(-t.x, -t.y);
2642 clearTimeout(that.animation_in_progress);
2644 (typeof callback == "function") && callback.call(that);
2650 Element.prototype.translate = function (x, y) {
2652 return {x: this._.tx, y: this._.ty};
2656 switch (this.type) {
2659 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
2664 this.attr({x: this.attrs.x + (+x), y: this.attrs.y + (+y)});
2667 var path = pathToRelative(this.attrs.path);
2670 this.attr({path: path.join(" ")});
2677 var Set = function () {
2680 for (var i = 0, ii = arguments.length; i < ii; i++) {
2681 if (arguments[i] && (arguments[i].constructor == Element || arguments[i].constructor == Set)) {
2682 this[this.items.length] = this.items[this.items.length] = arguments[i];
2687 Set.prototype.push = function (item) {
2688 if (item && item.constructor == Element || item.constructor == Set) {
2689 var len = this.items.length;
2690 this[len] = this.items[len] = item;
2695 Set.prototype.pull = function (id) {
2696 var res = this.items.splice(id, 1)[0];
2697 for (var j = id, jj = this.items.length; j < jj; j++) {
2698 this[j] = this[j + 1];
2700 delete this[jj + 1];
2704 for (var method in Element.prototype) {
2705 Set.prototype[method] = (function (methodname) {
2706 return function () {
2707 for (var i = 0, ii = this.items.length; i < ii; i++) {
2708 this.items[i][methodname].apply(this.items[i], arguments);
2714 Set.prototype.attr = function (name, value) {
2715 if (name && name instanceof Array && typeof name[0] == "object") {
2716 for (var j = 0, jj = name.length; j < jj; j++) {
2717 this.items[j].attr(name[j]);
2720 for (var i = 0, ii = this.items.length; i < ii; i++) {
2721 this.items[i].attr.apply(this.items[i], arguments);
2727 Set.prototype.getBBox = function () {
2728 var x = [], y = [], w = [], h = [];
2729 for (var i = this.items.length; i--;) {
2730 var box = this.items[i].getBBox();
2733 w.push(box.x + box.width);
2734 h.push(box.y + box.height);
2736 x = Math.min.apply(Math, x);
2737 y = Math.min.apply(Math, y);
2741 width: Math.max.apply(Math, w) - x,
2742 height: Math.max.apply(Math, h) - y
2746 R.registerFont = function (font) {
2750 this.fonts = this.fonts || {};
2751 if (this.fonts[font.face["font-family"]]) {
2752 this.fonts[font.face["font-family"]].push(font);
2754 this.fonts[font.face["font-family"]] = [font];
2757 font.face["units-per-em"] = parseInt(font.face["units-per-em"], 10);
2759 for (var glyph in font.glyphs) {
2760 var path = font.glyphs[glyph];
2762 path.d = "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
2763 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
2769 paper.getFont = function (family, weight, style, stretch) {
2770 stretch = stretch || "normal";
2771 style = style || "normal";
2772 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
2773 var font = R.fonts[family];
2775 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, "") + "(\\s|$)", "i");
2776 for (var fontName in R.fonts) {
2777 if (name.test(fontName)) {
2778 font = R.fonts[fontName];
2785 for (var i = 0, ii = font.length; i < ii; i++) {
2787 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
2794 paper.print = function (x, y, string, font, size) {
2795 var out = this.set(),
2796 letters = (string + "").split(""),
2801 scale = (size || 16) / font.face["units-per-em"];
2802 for (var i = 0, ii = letters.length; i < ii; i++) {
2803 var prev = i && font.glyphs[letters[i - 1]] || {},
2804 curr = font.glyphs[letters[i]];
2805 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
2806 curr && curr.d && out.push(this.path({fill: "#000", stroke: "none"}, curr.d).translate(shift, 0));
2808 out.scale(scale, scale, 0, y).translate(x, (size || 16) / 2);
2813 R.ninja = function () {
2814 var r = window.Raphael;
2815 if (oldRaphael.was) {
2816 window.Raphael = oldRaphael.is;
2819 delete window.Raphael;
2821 window.Raphael = void(0);
2826 R.el = Element.prototype;