2 * Raphael 0.8 - 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.toString().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);
279 width: Math.max.apply(Math, x) - minx,
280 height: Math.max.apply(Math, y) - miny,
285 pathToRelative = function (pathArray) {
287 if (typeof pathArray == "string") {
288 pathArray = R.parsePathString(pathArray);
290 var x = 0, y = 0, start = 0;
291 if (pathArray[0][0] == "M") {
295 res.push(["M", x, y]);
297 for (var i = start, ii = pathArray.length; i < ii; i++) {
300 if (pa[0] != pa[0].toLowerCase()) {
301 r[0] = pa[0].toLowerCase();
309 r[6] = +(pa[6] - x).toFixed(3);
310 r[7] = +(pa[7] - y).toFixed(3);
313 r[1] = (pa[1] - y).toFixed(3);
316 for (var j = 1, jj = pa.length; j < jj; j++) {
317 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
327 x += res[i][res[i].length - 1];
330 y += res[i][res[i].length - 1];
333 x += res[i][res[i].length - 2];
334 y += res[i][res[i].length - 1];
337 res.toString = pathArray.toString;
340 pathToAbsolute = function (pathArray) {
342 if (typeof pathArray == "string") {
343 pathArray = R.parsePathString(pathArray);
348 if (pathArray[0][0] == "M") {
349 x = +pathArray[0][1];
350 y = +pathArray[0][2];
352 res[0] = ["M", x, y];
354 for (var i = start, ii = pathArray.length; i < ii; i++) {
357 if (pa[0] != (pa[0] + "").toUpperCase()) {
358 r[0] = (pa[0] + "").toUpperCase();
366 r[6] = +(pa[6] + x).toFixed(3);
367 r[7] = +(pa[7] + y).toFixed(3);
376 for (var j = 1, jj = pa.length; j < jj; j++) {
377 r[j] = +pa[j] + ((j % 2) ? x : y);
382 for (var k = 0, kk = pa.length; k < kk; k++) {
396 x = res[i][res[i].length - 2];
397 y = res[i][res[i].length - 1];
400 res.toString = pathArray.toString;
403 pecache = {}, pecount = [],
404 pathEqualiser = function (path1, path2) {
405 if ((path1 + path2) in pecache) {
406 return pecache[path1 + path2];
408 var data = [pathToAbsolute(R.parsePathString(path1)), pathToAbsolute(R.parsePathString(path2))],
409 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}],
410 processPath = function (path, d) {
420 var nx = d.x + (d.x - (d.bx || d.x));
421 var ny = d.y + (d.y - (d.by || d.y));
422 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
425 var nx = d.x + (d.x - (d.bx || d.x));
426 var ny = d.y + (d.y - (d.by || d.y));
427 path = ["Q", nx, ny, path[1], path[2]];
430 path = ["L", path[1], d.y];
433 path = ["L", d.x, path[1]];
436 path = ["L", d.X, d.Y];
441 edgeCases = function (a, b, i) {
442 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
443 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
444 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
445 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
446 attrs[a].x = data[a][i][data[a][i].length - 2];
447 attrs[a].y = data[a][i][data[a][i].length - 1];
449 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
450 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]];
451 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
452 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
453 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
454 var x = data[b][i][data[b][i].length - 2];
455 var y = data[b][i][data[b][i].length - 1];
456 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
457 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
459 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
460 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
461 attrs[b].x = data[b][i][data[b][i].length - 2];
462 attrs[b].y = data[b][i][data[b][i].length - 1];
464 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
465 var x = data[b][i][data[b][i].length - 2];
466 var y = data[b][i][data[b][i].length - 1];
467 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
468 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
470 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
471 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
472 attrs[b].x = data[b][i][data[b][i].length - 2];
473 attrs[b].y = data[b][i][data[b][i].length - 1];
475 } else if (data[a][i][0] == "U") {
476 data[a][i][0] = data[b][i][0];
477 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
478 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
483 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
484 data[0][i] = processPath(data[0][i], attrs[0]);
485 data[1][i] = processPath(data[1][i], attrs[1]);
486 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
489 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
490 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
491 attrs[0].x = data[0][i][data[0][i].length - 2];
492 attrs[0].y = data[0][i][data[0][i].length - 1];
493 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
494 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
495 attrs[1].x = data[1][i][data[1][i].length - 2];
496 attrs[1].y = data[1][i][data[1][i].length - 1];
498 if (pecount.length > 20) {
499 delete pecache[pecount.unshift()];
501 pecount.push(path1 + path2);
502 pecache[path1 + path2] = data;
505 toGradient = function (gradient) {
506 if (typeof gradient == "string") {
507 gradient = gradient.split(/\s*\-\s*/);
508 var angle = gradient.shift();
509 if (angle.toLowerCase() == "v") {
511 } else if (angle.toLowerCase() == "h") {
514 angle = parseFloat(angle);
517 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)]};
518 var max = 1 / (Math.max(Math.abs(grobj.vector[2]), Math.abs(grobj.vector[3])) || 1);
519 grobj.vector[2] *= max;
520 grobj.vector[3] *= max;
521 if (grobj.vector[2] < 0) {
522 grobj.vector[0] = -grobj.vector[2];
525 if (grobj.vector[3] < 0) {
526 grobj.vector[1] = -grobj.vector[3];
529 grobj.vector[0] = grobj.vector[0].toFixed(3);
530 grobj.vector[1] = grobj.vector[1].toFixed(3);
531 grobj.vector[2] = grobj.vector[2].toFixed(3);
532 grobj.vector[3] = grobj.vector[3].toFixed(3);
533 for (var i = 0, ii = gradient.length; i < ii; i++) {
535 var par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
536 dot.color = R.getRGB(par[1]).hex;
537 par[2] && (dot.offset = par[2] + "%");
538 grobj.dots.push(dot);
540 for (var i = 1, ii = grobj.dots.length - 1; i < ii; i++) {
541 if (!grobj.dots[i].offset) {
542 var start = parseFloat(grobj.dots[i - 1].offset || 0),
544 for (var j = i + 1; j < ii; j++) {
545 if (grobj.dots[j].offset) {
546 end = grobj.dots[j].offset;
554 end = parseFloat(end);
555 var d = (end - start) / (j - i + 1);
558 grobj.dots[i].offset = start + "%";
567 getContainer = function () {
568 var container, x, y, width, height;
569 if (typeof arguments[0] == "string" || typeof arguments[0] == "object") {
570 if (typeof arguments[0] == "string") {
571 container = doc.getElementById(arguments[0]);
573 container = arguments[0];
575 if (container.tagName) {
576 if (arguments[1] == null) {
578 container: container,
579 width: container.style.pixelWidth || container.offsetWidth,
580 height: container.style.pixelHeight || container.offsetHeight
583 return {container: container, width: arguments[1], height: arguments[2]};
586 } else if (typeof arguments[0] == "number" && arguments.length > 3) {
587 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
590 plugins = function (con, add) {
591 for (var prop in add) if (add.hasOwnProperty(prop) && !(prop in con)) {
592 switch (typeof add[prop]) {
594 con[prop] = con === this ? add[prop] : function () { return add[prop].apply(this, arguments); };
598 plugins.call(this, con[prop], add[prop]);
601 con[prop] = add[prop];
609 R.toString = function () {
610 return "Your browser supports SVG.\nYou are running Rapha\u00ebl " + this.version;
612 var thePath = function (params, pathString, SVG) {
613 var el = doc.createElementNS(SVG.svgns, "path");
615 SVG.canvas.appendChild(el);
617 var p = new Element(el, SVG);
620 p.last = {x: 0, y: 0, bx: 0, by: 0};
621 p.absolutely = function () {
622 this.isAbsolute = true;
625 p.relatively = function () {
626 this.isAbsolute = false;
629 p.moveTo = function (x, y) {
630 var d = this.isAbsolute?"M":"m";
631 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
632 var oldD = this[0].getAttribute("d") || "";
633 (oldD == "M0,0") && (oldD = "");
634 this[0].setAttribute("d", oldD + d);
635 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
636 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
637 this.attrs.path = oldD + d;
640 p.lineTo = function (x, y) {
641 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
642 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
643 var d = this.isAbsolute?"L":"l";
644 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
645 var oldD = this[0].getAttribute("d") || "";
646 this[0].setAttribute("d", oldD + d);
647 this.attrs.path = oldD + d;
650 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
651 var d = this.isAbsolute ? "A" : "a";
652 d += [parseFloat(rx).toFixed(3), parseFloat(ry).toFixed(3), 0, large_arc_flag, sweep_flag, parseFloat(x).toFixed(3), parseFloat(y).toFixed(3)].join(" ");
653 var oldD = this[0].getAttribute("d") || "";
654 this[0].setAttribute("d", oldD + d);
655 this.last.x = parseFloat(x);
656 this.last.y = parseFloat(y);
657 this.attrs.path = oldD + d;
660 p.cplineTo = function (x1, y1, w1) {
662 return this.lineTo(x1, y1);
665 var x = parseFloat(x1);
666 var y = parseFloat(y1);
667 var w = parseFloat(w1);
668 var d = this.isAbsolute?"C":"c";
669 var attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
670 for (var i = 0, ii = attr.length; i < ii; i++) {
671 d += attr[i].toFixed(3) + " ";
673 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
674 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
675 this.last.bx = attr[2];
676 this.last.by = attr[3];
677 var oldD = this[0].getAttribute("d") || "";
678 this[0].setAttribute("d", oldD + d);
679 this.attrs.path = oldD + d;
683 p.curveTo = function () {
685 command = [0, 1, 2, 3, "s", 5, "c"];
687 var d = command[arguments.length];
688 if (this.isAbsolute) {
691 for (var i = 0, ii = arguments.length; i < ii; i++) {
692 d += parseFloat(arguments[i]).toFixed(3) + " ";
694 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
695 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
696 this.last.bx = parseFloat(arguments[arguments.length - 4]);
697 this.last.by = parseFloat(arguments[arguments.length - 3]);
698 var oldD = this.node.getAttribute("d") || "";
699 this.node.setAttribute("d", oldD + d);
700 this.attrs.path = oldD + d;
703 p.qcurveTo = function () {
705 command = [0, 1, "t", 3, "q"];
707 var d = command[arguments.length];
708 if (this.isAbsolute) {
711 for (var i = 0, ii = arguments.length; i < ii; i++) {
712 d += parseFloat(arguments[i]).toFixed(3) + " ";
714 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
715 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
716 if (arguments.length != 2) {
717 this.last.qx = parseFloat(arguments[arguments.length - 4]);
718 this.last.qy = parseFloat(arguments[arguments.length - 3]);
720 var oldD = this.node.getAttribute("d") || "";
721 this.node.setAttribute("d", oldD + d);
722 this.attrs.path = oldD + d;
725 p.addRoundedCorner = function (r, dir) {
726 var R = .5522 * r, rollback = this.isAbsolute, o = this;
729 rollback = function () {
733 rollback = function () {};
739 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
742 o.curveTo(-R, 0, -r, r - R, -r, r);
749 o.curveTo(R, 0, r, -(r - R), r, -r);
752 o.curveTo(R, 0, r, r - R, r, r);
759 o.curveTo(0, -R, -(R - r), -r, r, -r);
762 o.curveTo(0, -R, R - r, -r, -r, -r);
769 o.curveTo(0, R, -(R - r), r, r, r);
772 o.curveTo(0, R, R - r, r, -r, r);
777 actions[dir[0]]()[dir[1]]();
781 p.andClose = function () {
782 var oldD = this[0].getAttribute("d") || "";
783 this[0].setAttribute("d", oldD + "Z ");
784 this.attrs.path = oldD + "Z ";
788 p.attrs.path = "" + pathString;
790 paper.pathfinder(p, p.attrs.path);
793 !params.gradient && (params.fill = params.fill || "none");
794 params.stroke = params.stroke || "#000";
796 params = {fill: "none", stroke: "#000"};
798 setFillAndStroke(p, params);
801 var addGradientFill = function (o, gradient, SVG) {
802 gradient = toGradient(gradient);
803 var el = doc.createElementNS(SVG.svgns, (gradient.type || "linear") + "Gradient");
804 el.id = "raphael-gradient-" + R.idGenerator++;
805 if (gradient.vector && gradient.vector.length) {
806 el.setAttribute("x1", gradient.vector[0]);
807 el.setAttribute("y1", gradient.vector[1]);
808 el.setAttribute("x2", gradient.vector[2]);
809 el.setAttribute("y2", gradient.vector[3]);
811 SVG.defs.appendChild(el);
812 var isopacity = true;
813 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
814 var stop = doc.createElementNS(SVG.svgns, "stop");
815 if (gradient.dots[i].offset) {
818 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
819 stop.setAttribute("stop-color", R.getRGB(gradient.dots[i].color).hex || "#fff");
820 // ignoring opacity for internal points, because VML doesn't support it
821 el.appendChild(stop);
823 if (isopacity && typeof gradient.dots[ii - 1].opacity != "undefined") {
824 stop.setAttribute("stop-opacity", gradient.dots[ii - 1].opacity);
826 o.setAttribute("fill", "url(#" + el.id + ")");
829 o.style.fillOpacity = 1;
830 o.setAttribute("opacity", 1);
831 o.setAttribute("fill-opacity", 1);
833 var updatePosition = function (o) {
835 var bbox = o.getBBox();
836 o.pattern.setAttribute("patternTransform", "translate(".concat(bbox.x, ",", bbox.y, ")"));
839 var setFillAndStroke = function (o, params) {
844 "-..": [3, 1, 1, 1, 1, 1],
850 "--..": [8, 3, 1, 3, 1, 3]
854 addDashes = function (o, value) {
855 value = dasharray[value.toString().toLowerCase()];
857 var width = o.attrs["stroke-width"] || "1",
858 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
860 for (var i = 0, ii = value.length; i < ii; i++) {
861 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
863 value = dashes.join(",");
864 node.setAttribute("stroke-dasharray", value);
867 for (var att in params) {
868 if (!(att in availableAttrs)) {
871 var value = params[att];
878 var pn = node.parentNode;
879 if (pn.tagName.toLowerCase() != "a") {
880 var hl = doc.createElementNS(o.paper.svgns, "a");
881 pn.insertBefore(hl, node);
882 hl.appendChild(node);
885 pn.setAttributeNS(o.paper.xlink, att, value);
888 if (o.type == "path") {
889 node.setAttribute("d", "M0,0");
890 paper.pathfinder(o, value);
893 node.setAttribute(att, value);
902 value = -attrs.x - (attrs.width || 0);
906 node.setAttribute(att, value);
910 node.setAttribute(att, value);
919 value = -attrs.y - (attrs.height || 0);
923 node.setAttribute(att, value);
927 if (o.type == "rect") {
928 node.setAttribute("rx", value);
929 node.setAttribute("ry", value);
931 node.setAttribute(att, value);
935 if (o.type == "image") {
936 node.setAttributeNS(o.paper.xlink, "href", value);
940 node.style.strokeWidth = value;
941 // Need following line for Firefox
942 node.setAttribute(att, value);
943 if (attrs["stroke-dasharray"]) {
944 addDashes(o, attrs["stroke-dasharray"]);
947 case "stroke-dasharray":
951 o.rotate(value, true);
954 var xy = (value + "").split(separator);
955 o.translate((+xy[0] + 1 || 2) - 1, (+xy[1] + 1 || 2) - 1);
958 var xy = (value + "").split(separator);
959 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
962 var isURL = value.match(/^url\(([^\)]+)\)$/i);
964 var el = doc.createElementNS(o.paper.svgns, "pattern");
965 var ig = doc.createElementNS(o.paper.svgns, "image");
966 el.id = "raphael-pattern-" + R.idGenerator++;
967 el.setAttribute("x", 0);
968 el.setAttribute("y", 0);
969 el.setAttribute("patternUnits", "userSpaceOnUse");
970 ig.setAttribute("x", 0);
971 ig.setAttribute("y", 0);
972 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
975 var img = doc.createElement("img");
976 img.style.position = "absolute";
977 img.style.top = "-9999em";
978 img.style.left = "-9999em";
979 img.onload = function () {
980 el.setAttribute("width", this.offsetWidth);
981 el.setAttribute("height", this.offsetHeight);
982 ig.setAttribute("width", this.offsetWidth);
983 ig.setAttribute("height", this.offsetHeight);
984 doc.body.removeChild(this);
987 doc.body.appendChild(img);
989 o.paper.defs.appendChild(el);
990 node.style.fill = "url(#" + el.id + ")";
991 node.setAttribute("fill", "url(#" + el.id + ")");
996 delete params.gradient;
997 delete attrs.gradient;
998 if (typeof attrs.opacity != "undefined" && typeof params.opacity == "undefined" ) {
999 node.style.opacity = attrs.opacity;
1000 // Need following line for Firefox
1001 node.setAttribute("opacity", attrs.opacity);
1003 if (typeof attrs["fill-opacity"] != "undefined" && typeof params["fill-opacity"] == "undefined" ) {
1004 node.style.fillOpacity = o.attrs["fill-opacity"];
1005 // Need following line for Firefox
1006 node.setAttribute("fill-opacity", attrs["fill-opacity"]);
1009 node.style[att] = R.getRGB(value).hex;
1010 // Need following line for Firefox
1011 node.setAttribute(att, R.getRGB(value).hex);
1014 addGradientFill(node, value, o.paper);
1017 case "fill-opacity":
1018 if (attrs.gradient) {
1019 var gradient = doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
1021 var stops = gradient.getElementsByTagName("stop");
1022 stops[stops.length - 1].setAttribute("stop-opacity", value);
1027 var cssrule = att.replace(/(\-.)/g, function (w) {
1028 return w.substring(1).toUpperCase();
1030 node.style[cssrule] = value;
1031 // Need following line for Firefox
1032 node.setAttribute(att, value);
1037 tuneText(o, params);
1040 var tuneText = function (el, params) {
1041 if (el.type != "text" || !("text" in params || "font" in params || "font-size" in params || "x" in params || "y" in params)) {
1046 fontSize = node.firstChild ? parseInt(doc.defaultView.getComputedStyle(node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
1048 if ("text" in params) {
1049 while (node.firstChild) {
1050 node.removeChild(node.firstChild);
1052 var texts = (params.text + "").split("\n");
1053 for (var i = 0, ii = texts.length; i < ii; i++) {
1054 var tspan = doc.createElementNS(el.paper.svgns, "tspan");
1055 i && tspan.setAttribute("dy", fontSize * leading);
1056 i && tspan.setAttribute("x", a.x);
1057 tspan.appendChild(doc.createTextNode(texts[i]));
1058 node.appendChild(tspan);
1061 var texts = node.getElementsByTagName("tspan");
1062 for (var i = 0, ii = texts.length; i < ii; i++) {
1063 i && texts[i].setAttribute("dy", fontSize * leading);
1064 i && texts[i].setAttribute("x", a.x);
1067 node.setAttribute("y", a.y);
1068 var bb = el.getBBox(),
1069 dif = a.y - (bb.y + bb.height / 2);
1070 dif && node.setAttribute("y", a.y + dif);
1072 var Element = function (node, svg) {
1078 this.attrs = this.attrs || {};
1079 this.transformations = []; // rotate, translate, scale
1083 rt: {deg: 0, x: 0, y: 0},
1088 Element.prototype.rotate = function (deg, cx, cy) {
1090 return this._.rt.deg;
1092 var bbox = this.getBBox();
1093 deg = deg.toString().split(separator);
1094 if (deg.length - 1) {
1095 cx = parseFloat(deg[1]);
1096 cy = parseFloat(deg[2]);
1098 deg = parseFloat(deg[0]);
1100 this._.rt.deg = deg;
1102 this._.rt.deg += deg;
1107 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1108 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1109 if (this._.rt.deg) {
1110 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
1112 this.transformations[0] = "";
1114 this.node.setAttribute("transform", this.transformations.join(" "));
1117 Element.prototype.hide = function () {
1118 this.node.style.display = "none";
1121 Element.prototype.show = function () {
1122 this.node.style.display = "block";
1125 Element.prototype.remove = function () {
1126 this.node.parentNode.removeChild(this.node);
1128 Element.prototype.getBBox = function () {
1129 var bbox = this.node.getBBox();
1130 if (this.type == "text") {
1131 bbox = {x: bbox.x, y: Infinity, width: bbox.width, height: 0};
1132 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1133 var bb = this.node.getExtentOfChar(i);
1134 (bb.y < bbox.y) && (bbox.y = bb.y);
1135 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1140 Element.prototype.attr = function () {
1141 if (arguments.length == 1 && typeof arguments[0] == "string") {
1142 if (arguments[0] == "translation") {
1143 return this.translate();
1145 return this.attrs[arguments[0]];
1147 if (arguments.length == 1 && arguments[0] instanceof win.Array) {
1149 for (var j in arguments[0]) {
1150 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1154 if (arguments.length == 2) {
1156 params[arguments[0]] = arguments[1];
1157 setFillAndStroke(this, params);
1158 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1159 setFillAndStroke(this, arguments[0]);
1163 Element.prototype.toFront = function () {
1164 this.node.parentNode.appendChild(this.node);
1167 Element.prototype.toBack = function () {
1168 if (this.node.parentNode.firstChild != this.node) {
1169 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1173 Element.prototype.insertAfter = function (element) {
1174 if (element.node.nextSibling) {
1175 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1177 element.node.parentNode.appendChild(this.node);
1181 Element.prototype.insertBefore = function (element) {
1182 element.node.parentNode.insertBefore(this.node, element.node);
1185 var theCircle = function (svg, x, y, r) {
1186 var el = doc.createElementNS(svg.svgns, "circle");
1187 el.setAttribute("cx", x);
1188 el.setAttribute("cy", y);
1189 el.setAttribute("r", r);
1190 el.setAttribute("fill", "none");
1191 el.setAttribute("stroke", "#000");
1193 svg.canvas.appendChild(el);
1195 var res = new Element(el, svg);
1196 res.attrs = res.attrs || {};
1200 res.attrs.stroke = "#000";
1201 res.type = "circle";
1204 var theRect = function (svg, x, y, w, h, r) {
1205 var el = doc.createElementNS(svg.svgns, "rect");
1206 el.setAttribute("x", x);
1207 el.setAttribute("y", y);
1208 el.setAttribute("width", w);
1209 el.setAttribute("height", h);
1211 el.setAttribute("rx", r);
1212 el.setAttribute("ry", r);
1214 el.setAttribute("fill", "none");
1215 el.setAttribute("stroke", "#000");
1217 svg.canvas.appendChild(el);
1219 var res = new Element(el, svg);
1220 res.attrs = res.attrs || {};
1223 res.attrs.width = w;
1224 res.attrs.height = h;
1225 res.attrs.stroke = "#000";
1227 res.attrs.rx = res.attrs.ry = r;
1232 var theEllipse = function (svg, x, y, rx, ry) {
1233 var el = doc.createElementNS(svg.svgns, "ellipse");
1234 el.setAttribute("cx", x);
1235 el.setAttribute("cy", y);
1236 el.setAttribute("rx", rx);
1237 el.setAttribute("ry", ry);
1238 el.setAttribute("fill", "none");
1239 el.setAttribute("stroke", "#000");
1241 svg.canvas.appendChild(el);
1243 var res = new Element(el, svg);
1244 res.attrs = res.attrs || {};
1249 res.attrs.stroke = "#000";
1250 res.type = "ellipse";
1253 var theImage = function (svg, src, x, y, w, h) {
1254 var el = doc.createElementNS(svg.svgns, "image");
1255 el.setAttribute("x", x);
1256 el.setAttribute("y", y);
1257 el.setAttribute("width", w);
1258 el.setAttribute("height", h);
1259 el.setAttribute("preserveAspectRatio", "none");
1260 el.setAttributeNS(svg.xlink, "href", src);
1262 svg.canvas.appendChild(el);
1264 var res = new Element(el, svg);
1265 res.attrs = res.attrs || {};
1268 res.attrs.width = w;
1269 res.attrs.height = h;
1273 var theText = function (svg, x, y, text) {
1274 var el = doc.createElementNS(svg.svgns, "text");
1275 el.setAttribute("x", x);
1276 el.setAttribute("y", y);
1277 el.setAttribute("text-anchor", "middle");
1279 svg.canvas.appendChild(el);
1281 var res = new Element(el, svg);
1282 res.attrs = res.attrs || {};
1286 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000", text: text});
1289 var setSize = function (width, height) {
1290 this.width = width || this.width;
1291 this.height = height || this.height;
1292 this.canvas.setAttribute("width", this.width);
1293 this.canvas.setAttribute("height", this.height);
1296 var create = function () {
1297 var con = getContainer.apply(null, arguments);
1298 var container = con.container,
1302 height = con.height;
1304 throw new Error("SVG container not found.");
1306 paper.canvas = doc.createElementNS(paper.svgns, "svg");
1307 paper.canvas.setAttribute("width", width || 512);
1308 paper.width = width || 512;
1309 paper.canvas.setAttribute("height", height || 342);
1310 paper.height = height || 342;
1311 if (container == 1) {
1312 doc.body.appendChild(paper.canvas);
1313 paper.canvas.style.position = "absolute";
1314 paper.canvas.style.left = x + "px";
1315 paper.canvas.style.top = y + "px";
1317 if (container.firstChild) {
1318 container.insertBefore(paper.canvas, container.firstChild);
1320 container.appendChild(paper.canvas);
1324 canvas: paper.canvas,
1325 clear: function () {
1326 while (this.canvas.firstChild) {
1327 this.canvas.removeChild(this.canvas.firstChild);
1329 this.defs = doc.createElementNS(paper.svgns, "defs");
1330 this.canvas.appendChild(this.defs);
1333 for (var prop in paper) {
1334 if (prop != "create") {
1335 container[prop] = paper[prop];
1338 plugins.call(container, container, R.fn);
1340 container.raphael = R;
1343 paper.remove = function () {
1344 this.canvas.parentNode.removeChild(this.canvas);
1346 paper.svgns = "http://www.w3.org/2000/svg";
1347 paper.xlink = "http://www.w3.org/1999/xlink";
1348 paper.safari = function () {
1349 if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) {
1350 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1351 setTimeout(function () {rect.remove();});
1358 R.toString = function () {
1359 return "Your browser doesn\u2019t support SVG.\nYou are running Rapha\u00ebl " + this.version;
1361 thePath = function (params, pathString, VML) {
1362 var g = createNode("group"), gl = g.style;
1363 gl.position = "absolute";
1366 gl.width = VML.width + "px";
1367 gl.height = VML.height + "px";
1368 var el = createNode("shape"), ol = el.style;
1369 ol.width = VML.width + "px";
1370 ol.height = VML.height + "px";
1372 if (params["class"]) {
1373 el.className = "rvml " + params["class"];
1375 el.coordsize = this.coordsize;
1376 el.coordorigin = this.coordorigin;
1378 var p = new Element(el, g, VML);
1379 p.isAbsolute = true;
1382 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1384 p.absolutely = function () {
1385 this.isAbsolute = true;
1388 p.relatively = function () {
1389 this.isAbsolute = false;
1392 p.moveTo = function (x, y) {
1393 var d = this.isAbsolute?"m":"t";
1394 d += Math.round(parseFloat(x)) + " " + Math.round(parseFloat(y));
1395 this.node.path = this.Path += d;
1396 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1397 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1398 this.last.isAbsolute = this.isAbsolute;
1399 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1402 p.lineTo = function (x, y) {
1403 var d = this.isAbsolute?"l":"r";
1404 d += Math.round(parseFloat(x)) + " " + Math.round(parseFloat(y));
1405 this[0].path = this.Path += d;
1406 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1407 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1408 this.last.isAbsolute = this.isAbsolute;
1409 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1412 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1413 // for more information of where this math came from visit:
1414 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1415 x2 = (this.isAbsolute ? 0 : this.last.x) + x2;
1416 y2 = (this.isAbsolute ? 0 : this.last.y) + y2;
1417 var x1 = this.last.x,
1421 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1422 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1423 cx = k * rx * y / ry + (x1 + x2) / 2,
1424 cy = k * -ry * x / rx + (y1 + y2) / 2,
1425 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1426 left = Math.round(cx - rx),
1427 top = Math.round(cy - ry);
1428 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(", ");
1429 this.node.path = this.Path += d;
1430 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2);
1431 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2);
1432 this.last.isAbsolute = this.isAbsolute;
1433 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1436 p.cplineTo = function (x1, y1, w1) {
1438 return this.lineTo(x1, y1);
1440 var x = Math.round(Math.round(parseFloat(x1) * 100) / 100),
1441 y = Math.round(Math.round(parseFloat(y1) * 100) / 100),
1442 w = Math.round(Math.round(parseFloat(w1) * 100) / 100),
1443 d = this.isAbsolute ? "c" : "v",
1444 attr = [Math.round(this.last.x) + w, Math.round(this.last.y), x - w, y, x, y],
1445 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1446 d += attr.join(" ") + " ";
1447 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1448 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1449 this.last.bx = attr[2];
1450 this.last.by = attr[3];
1451 this.node.path = this.Path += d;
1452 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1456 p.curveTo = function () {
1457 var d = this.isAbsolute ? "c" : "v";
1458 if (arguments.length == 6) {
1459 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1460 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1461 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4]);
1462 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5]);
1463 d += [Math.round(parseFloat(arguments[0])),
1464 Math.round(parseFloat(arguments[1])),
1465 Math.round(parseFloat(arguments[2])),
1466 Math.round(parseFloat(arguments[3])),
1467 Math.round(parseFloat(arguments[4])),
1468 Math.round(parseFloat(arguments[5]))].join(" ") + " ";
1469 this.last.isAbsolute = this.isAbsolute;
1470 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1472 if (arguments.length == 4) {
1473 var bx = this.last.x * 2 - this.last.bx;
1474 var by = this.last.y * 2 - this.last.by;
1475 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0]);
1476 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1]);
1477 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1478 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1479 d += [Math.round(bx), Math.round(by),
1480 Math.round(parseFloat(arguments[0])),
1481 Math.round(parseFloat(arguments[1])),
1482 Math.round(parseFloat(arguments[2])),
1483 Math.round(parseFloat(arguments[3]))].join(" ") + " ";
1484 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1486 this.node.path = this.Path += d;
1489 p.qcurveTo = function () {
1491 if (arguments.length == 4) {
1492 this.last.qx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0]);
1493 this.last.qy = (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(this.last.qx),
1497 Math.round(this.last.qy),
1498 Math.round(this.last.x),
1499 Math.round(this.last.y)].join(" ") + " ";
1500 this.last.isAbsolute = this.isAbsolute;
1501 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1503 if (arguments.length == 2) {
1504 this.last.qx = this.last.x * 2 - this.last.qx;
1505 this.last.qy = this.last.y * 2 - this.last.qy;
1506 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1507 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1508 d += [Math.round(this.last.qx),
1509 Math.round(this.last.qy),
1510 Math.round(this.last.x),
1511 Math.round(this.last.y)].join(" ") + " ";
1512 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1514 this.node.path = this.Path += d;
1515 this.path.push({type: "qcurve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
1518 p.addRoundedCorner = function (r, dir) {
1519 var R = .5522 * r, rollback = this.isAbsolute, o = this;
1522 rollback = function () {
1526 rollback = function () {};
1532 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
1535 o.curveTo(-R, 0, -r, r - R, -r, r);
1542 o.curveTo(R, 0, r, -(r - R), r, -r);
1545 o.curveTo(R, 0, r, r - R, r, r);
1552 o.curveTo(0, -R, -(R - r), -r, r, -r);
1555 o.curveTo(0, -R, R - r, -r, -r, -r);
1562 o.curveTo(0, R, -(R - r), r, r, r);
1565 o.curveTo(0, R, R - r, r, -r, r);
1570 actions[dir.charAt(0)]()[dir.charAt(1)]();
1574 p.andClose = function () {
1575 this.node.path = (this.Path += "x");
1576 this.attrs.path += "z";
1582 paper.pathfinder(p, "" + pathString);
1585 params.fill = params.fill || "none";
1586 params.stroke = params.stroke || "#000";
1588 params = {fill: "none", stroke: "#000"};
1590 setFillAndStroke(p, params);
1591 if (params.gradient) {
1592 addGradientFill(p, params.gradient);
1594 VML.canvas.appendChild(g);
1597 var setFillAndStroke = function (o, params) {
1601 o.attrs = o.attrs || {};
1602 for (var par in params) {
1603 o.attrs[par] = params[par];
1605 params.href && (node.href = params.href);
1606 params.title && (node.title = params.title);
1607 params.target && (node.target = params.target);
1608 if (params.path && o.type == "path") {
1611 paper.pathfinder(o, params.path);
1613 if (params.rotation != null) {
1614 o.rotate(params.rotation, true);
1616 if (params.translation) {
1617 var xy = (params.translation + "").split(separator);
1618 o.translate(xy[0], xy[1]);
1621 var xy = (params.scale + "").split(separator);
1622 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1624 if (o.type == "image" && params.src) {
1625 node.src = params.src;
1627 if (o.type == "image" && params.opacity) {
1628 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1629 node.style.filter = (node.filterMatrix || "") + (node.filterOpacity || "");
1631 params.font && (s.font = params.font);
1632 params["font-family"] && (s.fontFamily = params["font-family"]);
1633 params["font-size"] && (s.fontSize = params["font-size"]);
1634 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1635 params["font-style"] && (s.fontStyle = params["font-style"]);
1636 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"]) {
1637 o = o.shape || node;
1638 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || createNode("fill");
1639 if ("fill-opacity" in params || "opacity" in params) {
1640 fill.opacity = ((+params["fill-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1642 params.fill && (fill.on = true);
1643 if (typeof fill.on == "undefined" || params.fill == "none") {
1646 if (fill.on && params.fill) {
1647 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1649 fill.src = isURL[1];
1652 fill.color = R.getRGB(params.fill).hex;
1654 fill.type = "solid";
1657 o.appendChild(fill);
1658 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || createNode("stroke");
1659 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"]) {
1662 if (params.stroke == "none" || typeof stroke.on == "undefined" || params.stroke == 0) {
1665 if (stroke.on && params.stroke) {
1666 stroke.color = R.getRGB(params.stroke).hex;
1668 stroke.opacity = ((+params["stroke-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1669 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1670 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1671 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1672 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"]) || 1) * 12 / 16);
1673 if (params["stroke-dasharray"]) {
1677 "-.": "shortdashdot",
1678 "-..": "shortdashdotdot",
1683 "--.": "longdashdot",
1684 "--..": "longdashdotdot"
1686 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1688 o.appendChild(stroke);
1690 if (res.type == "text") {
1691 var span = doc.createElement("span"),
1697 s.display = "inline";
1698 a.font && (s.font = a.font);
1699 a["font-family"] && (s.fontFamily = a["font-family"]);
1700 a["font-size"] && (s.fontSize = a["font-size"]);
1701 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1702 a["font-style"] && (s.fontStyle = a["font-style"]);
1703 res.node.parentNode.appendChild(span);
1704 span.innerText = res.node.string;
1705 res.W = a.w = span.offsetWidth;
1706 res.H = a.h = span.offsetHeight;
1708 res.Y = a.y + Math.round(res.H / 2);
1709 res.node.parentNode.removeChild(span);
1711 // text-anchor emulation
1712 switch (a["text-anchor"]) {
1714 res.node.style["v-text-align"] = "left";
1715 res.bbx = Math.round(res.W / 2);
1718 res.node.style["v-text-align"] = "right";
1719 res.bbx = -Math.round(res.W / 2);
1722 res.node.style["v-text-align"] = "center";
1727 var getAngle = function (a, b, c, d) {
1728 var angle = Math.round(Math.atan((parseFloat(c) - parseFloat(a)) / (parseFloat(d) - parseFloat(b))) * 57.29) || 0;
1729 if (!angle && parseFloat(a) < parseFloat(b)) {
1738 var addGradientFill = function (o, gradient) {
1739 gradient = toGradient(gradient);
1740 o.attrs = o.attrs || {};
1741 var attrs = o.attrs;
1742 o.attrs.gradient = gradient;
1743 o = o.shape || o[0];
1744 var fill = o.getElementsByTagName("fill");
1748 fill = createNode("fill");
1750 if (gradient.dots.length) {
1752 fill.method = "none";
1753 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1754 if (typeof gradient.dots[0].color != "undefined") {
1755 fill.color = R.getRGB(gradient.dots[0].color).hex;
1757 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1758 fill.color2 = R.getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1761 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1762 if (gradient.dots[i].offset) {
1763 clrs.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
1766 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;
1768 fill.colors.value = clrs.join(",");
1769 fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
1771 fill.colors && (fill.colors.value = "0% " + fill.color);
1773 fill.opacity = fillOpacity;
1774 if (typeof gradient.angle != "undefined") {
1775 fill.angle = (-gradient.angle + 270) % 360;
1776 } else if (gradient.vector) {
1777 fill.angle = getAngle.apply(null, gradient.vector);
1779 if ((gradient.type + "").toLowerCase() == "radial") {
1780 fill.focus = "100%";
1781 fill.focusposition = "0.5 0.5";
1785 var Element = function (node, group, vml) {
1805 Element.prototype.rotate = function (deg, cx, cy) {
1807 return this._.rt.deg;
1809 deg = deg.toString().split(separator);
1810 if (deg.length - 1) {
1811 cx = parseFloat(deg[1]);
1812 cy = parseFloat(deg[2]);
1814 deg = parseFloat(deg[0]);
1816 this._.rt.deg = deg;
1818 this._.rt.deg += deg;
1825 this.setBox(null, cx, cy);
1826 this.Group.style.rotation = this._.rt.deg;
1827 // gradient fix for rotation. TODO
1828 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1829 // fill = fill[0] || {};
1830 // var b = ((360 - this._.rt.deg) - 270) % 360;
1831 // typeof fill.angle != "undefined" && (fill.angle = b);
1834 Element.prototype.setBox = function (params, cx, cy) {
1835 var gs = this.Group.style,
1836 os = (this.shape && this.shape.style) || this.node.style;
1837 params = params || {};
1838 for (var i in params) {
1839 this.attrs[i] = params[i];
1841 cx = cx || this._.rt.cx;
1842 cy = cy || this._.rt.cy;
1843 var attr = this.attrs, x, y, w, h;
1844 switch (this.type) {
1846 x = attr.cx - attr.r;
1847 y = attr.cy - attr.r;
1851 x = attr.cx - attr.rx;
1852 y = attr.cy - attr.ry;
1860 w = attr.width || 0;
1861 h = attr.height || 0;
1864 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("");
1865 x = attr.x - Math.round(this.W / 2);
1866 y = attr.y - this.H / 2;
1871 if (!this.attrs.path) {
1874 w = this.paper.width;
1875 h = this.paper.height;
1877 var dim = pathDimensions(this.attrs.path),
1887 w = this.paper.width;
1888 h = this.paper.height;
1891 cx = (cx == null) ? x + w / 2 : cx;
1892 cy = (cy == null) ? y + h / 2 : cy;
1893 var left = cx - this.paper.width / 2,
1894 top = cy - this.paper.height / 2;
1895 if (this.type == "path" || this.type == "text") {
1896 (gs.left != left + "px") && (gs.left = left + "px");
1897 (gs.top != top + "px") && (gs.top = top + "px");
1898 this.X = this.type == "text" ? x : -left;
1899 this.Y = this.type == "text" ? y : -top;
1902 (os.left != -left + "px") && (os.left = -left + "px");
1903 (os.top != -top + "px") && (os.top = -top + "px");
1905 (gs.left != left + "px") && (gs.left = left + "px");
1906 (gs.top != top + "px") && (gs.top = top + "px");
1911 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
1912 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
1913 (os.left != x - left + "px") && (os.left = x - left + "px");
1914 (os.top != y - top + "px") && (os.top = y - top + "px");
1915 (os.width != w + "px") && (os.width = w + "px");
1916 (os.height != h + "px") && (os.height = h + "px");
1917 var arcsize = (+params.r || 0) / (Math.min(w, h));
1918 if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
1919 // We should replace element with the new one
1920 var o = createNode(arcsize ? "roundrect" : "rect");
1921 o.arcsize = arcsize;
1922 this.Group.appendChild(o);
1923 this.node.parentNode.removeChild(this.node);
1925 this.arcsize = arcsize;
1926 setFillAndStroke(this, this.attrs);
1927 this.setBox(this.attrs);
1931 Element.prototype.hide = function () {
1932 this.Group.style.display = "none";
1935 Element.prototype.show = function () {
1936 this.Group.style.display = "block";
1939 Element.prototype.getBBox = function () {
1940 if (this.type == "path") {
1941 return pathDimensions(this.attr("path"));
1944 x: this.X + (this.bbx || 0),
1950 Element.prototype.remove = function () {
1951 this[0].parentNode.removeChild(this[0]);
1952 this.Group.parentNode.removeChild(this.Group);
1953 this.shape && this.shape.parentNode.removeChild(this.shape);
1955 Element.prototype.attr = function () {
1956 if (arguments.length == 1 && typeof arguments[0] == "string") {
1957 if (arguments[0] == "translation") {
1958 return this.translate();
1960 return this.attrs[arguments[0]];
1962 if (this.attrs && arguments.length == 1 && arguments[0] instanceof win.Array) {
1964 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1965 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1970 if (arguments.length == 2) {
1972 params[arguments[0]] = arguments[1];
1974 if (arguments.length == 1 && typeof arguments[0] == "object") {
1975 params = arguments[0];
1978 if (params.gradient) {
1979 addGradientFill(this, params.gradient);
1981 if (params.text && this.type == "text") {
1982 this.node.string = params.text;
1985 this.node.id = params.id;
1987 setFillAndStroke(this, params);
1988 this.setBox(params);
1992 Element.prototype.toFront = function () {
1993 this.Group.parentNode.appendChild(this.Group);
1996 Element.prototype.toBack = function () {
1997 if (this.Group.parentNode.firstChild != this.Group) {
1998 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2002 Element.prototype.insertAfter = function (element) {
2003 if (element.Group.nextSibling) {
2004 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2006 element.Group.parentNode.appendChild(this.Group);
2010 Element.prototype.insertBefore = function (element) {
2011 element.Group.parentNode.insertBefore(this.Group, element.Group);
2014 var theCircle = function (vml, x, y, r) {
2015 var g = createNode("group");
2016 var o = createNode("oval");
2018 var res = new Element(o, g, vml);
2019 res.type = "circle";
2020 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2024 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2025 vml.canvas.appendChild(g);
2028 var theRect = function (vml, x, y, w, h, r) {
2029 var g = createNode("group"),
2030 o = createNode(r ? "roundrect" : "rect"),
2031 arcsize = (+r || 0) / (Math.min(w, h));
2032 o.arcsize = arcsize;
2034 var res = new Element(o, g, vml);
2036 setFillAndStroke(res, {stroke: "#000"});
2042 res.arcsize = arcsize;
2043 res.setBox({x: x, y: y, width: w, height: h});
2044 vml.canvas.appendChild(g);
2047 var theEllipse = function (vml, x, y, rx, ry) {
2048 var g = createNode("group");
2049 var o = createNode("oval");
2051 var res = new Element(o, g, vml);
2052 res.type = "ellipse";
2053 setFillAndStroke(res, {stroke: "#000"});
2058 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2059 vml.canvas.appendChild(g);
2062 var theImage = function (vml, src, x, y, w, h) {
2063 var g = createNode("group");
2064 var o = createNode("image");
2067 var res = new Element(o, g, vml);
2073 res.setBox({x: x, y: y, width: w, height: h});
2074 vml.canvas.appendChild(g);
2077 var theText = function (vml, x, y, text) {
2078 var g = createNode("group"), gs = g.style;
2079 var el = createNode("shape"), ol = el.style;
2080 var path = createNode("path"), ps = path.style;
2081 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
2082 path.textpathok = true;
2083 ol.width = vml.width;
2084 ol.height = vml.height;
2085 gs.position = "absolute";
2088 gs.width = vml.width;
2089 gs.height = vml.height;
2090 var o = createNode("textpath");
2093 o.coordsize = vml.coordsize;
2094 o.coordorigin = vml.coordorigin;
2096 el.appendChild(path);
2098 var res = new Element(o, g, vml);
2100 res.textpath = path;
2106 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2108 vml.canvas.appendChild(g);
2111 var setSize = function (width, height) {
2112 this.width = width || this.width;
2113 this.height = height || this.height;
2114 this.canvas.style.width = this.width + "px";
2115 this.canvas.style.height = this.height + "px";
2116 this.canvas.parentNode.style.clip = "rect(0 " + this.width + "px " + this.height + "px 0)";
2117 this.canvas.coordsize = this.width + " " + this.height;
2120 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2122 if (!doc.namespaces.rvml) {
2123 doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2125 var createNode = function (tagName) {
2126 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2129 var createNode = function (tagName) {
2130 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2133 var create = function () {
2134 var con = getContainer.apply(null, arguments);
2135 var container = con.container,
2139 height = con.height;
2141 throw new Error("VML container not found.");
2143 var c = doc.createElement("div"),
2144 d = doc.createElement("div"),
2145 r = paper.canvas = createNode("group"),
2146 cs = c.style, rs = r.style;
2147 paper.width = width;
2148 paper.height = height;
2149 width = width || "512px";
2150 height = height || "342px";
2151 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2154 cs.position = "absolute";
2155 rs.position = "absolute";
2156 d.style.position = "relative";
2159 r.coordsize = (/%$/.test(width) ? width : parseFloat(width)) + " " + (/%$/.test(height) ? height : parseFloat(height));
2160 r.coordorigin = "0 0";
2162 var b = createNode("rect"), bs = b.style;
2163 bs.left = bs.top = 0;
2164 bs.width = rs.width;
2165 bs.height = rs.height;
2166 b.filled = b.stroked = "f";
2171 if (container == 1) {
2172 doc.body.appendChild(d);
2173 cs.position = "absolute";
2185 cs.width = container.style.width = width;
2186 cs.height = container.style.height = height;
2187 if (container.firstChild) {
2188 container.insertBefore(d, container.firstChild);
2190 container.appendChild(d);
2193 for (var prop in paper) {
2194 container[prop] = paper[prop];
2196 plugins.call(container, container, R.fn);
2197 container.clear = function () {
2199 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
2200 if (r.childNodes[i] != b) {
2201 todel.push(r.childNodes[i]);
2204 for (i = 0, ii = todel.length; i < ii; i++) {
2205 r.removeChild(todel[i]);
2208 container.raphael = R;
2211 paper.remove = function () {
2212 this.canvas.parentNode.parentNode.parentNode.removeChild(this.canvas.parentNode.parentNode);
2214 paper.safari = function () {};
2220 var addEvent = (function () {
2221 if (doc.addEventListener) {
2222 return function (obj, type, fn, element) {
2223 var f = function (e) {
2224 return fn.call(element, e);
2226 obj.addEventListener(type, f, false);
2227 return function () {
2228 obj.removeEventListener(type, f, false);
2232 } else if (doc.attachEvent) {
2233 return function (obj, type, fn, element) {
2234 var f = function (e) {
2235 return fn.call(element, e || win.event);
2237 obj.attachEvent("on" + type, f);
2238 var detacher = function () {
2239 obj.detachEvent("on" + type, f);
2242 if (type == "mouseover") {
2243 obj.attachEvent("onmouseenter", f);
2244 return function () {
2245 obj.detachEvent("onmouseenter", f);
2248 } else if (type == "mouseout") {
2249 obj.attachEvent("onmouseleave", f);
2250 return function () {
2251 obj.detachEvent("onmouseleave", f);
2259 for (var i = events.length; i--;) {
2260 (function (eventName) {
2261 Element.prototype[eventName] = function (fn) {
2262 if (typeof fn == "function") {
2263 this.events = this.events || {};
2264 this.events[eventName] = this.events[eventName] || {};
2265 this.events[eventName][fn] = this.events[eventName][fn] || [];
2266 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2270 Element.prototype["un" + eventName] = function (fn) {
2272 this.events[eventName] &&
2273 this.events[eventName][fn] &&
2274 this.events[eventName][fn].length &&
2275 this.events[eventName][fn].shift()() &&
2276 !this.events[eventName][fn].length &&
2277 delete this.events[eventName][fn];
2282 paper.circle = function (x, y, r) {
2283 return theCircle(this, x, y, r);
2285 paper.rect = function (x, y, w, h, r) {
2286 return theRect(this, x, y, w, h, r);
2288 paper.ellipse = function (x, y, rx, ry) {
2289 return theEllipse(this, x, y, rx, ry);
2291 paper.path = function (params, pathString) {
2292 return thePath(params, pathString, this);
2294 paper.image = function (src, x, y, w, h) {
2295 return theImage(this, src, x, y, w, h);
2297 paper.text = function (x, y, text) {
2298 return theText(this, x, y, text);
2300 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
2301 color = color || "#000";
2302 var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
2304 columnWidth = w / wv;
2305 for (var i = 1; i < hv; i++) {
2306 path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
2308 for (var i = 1; i < wv; i++) {
2309 path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
2311 return this.path({stroke: color, "stroke-width": 1}, path.join(","));
2313 paper.pathfinder = function (p, path) {
2315 M: function (x, y) {
2318 C: function (x1, y1, x2, y2, x3, y3) {
2319 this.curveTo(x1, y1, x2, y2, x3, y3);
2321 Q: function (x1, y1, x2, y2) {
2322 this.qcurveTo(x1, y1, x2, y2);
2324 T: function (x, y) {
2325 this.qcurveTo(x, y);
2327 S: function (x1, y1, x2, y2) {
2328 p.curveTo(x1, y1, x2, y2);
2330 L: function (x, y) {
2334 this.lineTo(x, this.last.y);
2337 this.lineTo(this.last.x, y);
2339 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2340 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2347 path = pathToAbsolute(path);
2348 for (var i = 0, ii = path.length; i < ii; i++) {
2349 var b = path[i].shift();
2350 commands[b].apply(p, path[i]);
2354 paper.set = function (itemsArray) {
2355 return new Set(itemsArray);
2357 paper.setSize = setSize;
2358 Element.prototype.stop = function () {
2359 clearTimeout(this.animation_in_progress);
2361 Element.prototype.scale = function (x, y, cx, cy) {
2362 if (x == null && y == null) {
2363 return {x: this._.sx, y: this._.sy, toString: function () { return this.x.toFixed(3) + " " + this.y.toFixed(3); }};
2367 var dx, dy, dcx, dcy, a = this.attrs;
2369 var bb = this.type == "path" ? pathDimensions(a.path) : this.getBBox(),
2370 rcx = bb.x + bb.width / 2,
2371 rcy = bb.y + bb.height / 2;
2372 cx = (+cx || cx == 0) ? cx : rcx;
2373 cy = (+cy || cy == 0) ? cy : rcy;
2374 var dirx = Math.round(x / Math.abs(x)),
2375 diry = Math.round(y / Math.abs(y)),
2376 s = this.node.style,
2377 ncx = cx + (rcx - cx) * x * dirx / this._.sx,
2378 ncy = cy + (rcy - cy) * y * diry / this._.sy;
2379 switch (this.type) {
2382 var neww = a.width * x * dirx / this._.sx,
2383 newh = a.height * y * diry / this._.sy,
2384 newx = ncx - neww / 2,
2385 newy = ncy - newh / 2;
2396 rx: a.rx * x / this._.sx,
2397 ry: a.ry * y / this._.sy,
2398 r: a.r * x / this._.sx,
2404 var path = pathToRelative(a.path),
2406 for (var i = 0, ii = path.length; i < ii; i++) {
2408 if (p[0].toUpperCase() == "M" && skip) {
2413 if (R.svg && p[0].toUpperCase() == "A") {
2414 p[path[i].length - 2] *= x / this._.sx;
2415 p[path[i].length - 1] *= y / this._.sy;
2416 p[1] *= x / this._.sx;
2417 p[2] *= y / this._.sy;
2418 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2420 for (var j = 1, jj = p.length; j < jj; j++) {
2421 p[j] *= (j % 2) ? x / this._.sx : y / this._.sy;
2425 var dim2 = pathDimensions(path),
2426 dx = ncx - dim2.x - dim2.width / 2,
2427 dy = ncy - dim2.y - dim2.height / 2;
2428 path = pathToRelative(path);
2432 this.attr({path: path.join(" ")});
2435 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2436 if (this.transformations) {
2437 this.transformations[2] = "scale(".concat(dirx, ",", diry, ")");
2438 this.node.setAttribute("transform", this.transformations.join(" "));
2439 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2440 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2441 this.attr({x: dx, y: dy});
2445 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=".concat(dirx,
2446 ", M12=0, M21=0, M22=", diry,
2447 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2448 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2451 if (this.transformations) {
2452 this.transformations[2] = "";
2453 this.node.setAttribute("transform", this.transformations.join(" "));
2457 this.node.filterMatrix = "";
2458 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2461 a.scale = [x, y, cx, cy].join(" ");
2467 Element.prototype.animate = function (params, ms, callback) {
2468 clearTimeout(this.animation_in_progress);
2473 for (var attr in params) {
2474 if (attr in availableAnimAttrs) {
2475 from[attr] = this.attr(attr);
2476 (typeof from[attr] == "undefined") && (from[attr] = availableAttrs[attr]);
2477 to[attr] = params[attr];
2478 switch (availableAnimAttrs[attr]) {
2480 diff[attr] = (to[attr] - from[attr]) / ms;
2483 from[attr] = R.getRGB(from[attr]);
2484 var toColour = R.getRGB(to[attr]);
2486 r: (toColour.r - from[attr].r) / ms,
2487 g: (toColour.g - from[attr].g) / ms,
2488 b: (toColour.b - from[attr].b) / ms
2492 var pathes = pathEqualiser(from[attr], to[attr]);
2493 from[attr] = pathes[0];
2494 to[attr] = pathes[1];
2496 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2497 diff[attr][i] = [0];
2498 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2499 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2504 var values = (params[attr] + "").split(separator),
2505 from2 = (from[attr] + "").split(separator);
2508 from[attr] = [0, 0];
2509 diff[attr] = [values[0] / ms, values[1] / ms];
2512 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2513 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2516 params[attr] = values;
2517 from[attr] = (from[attr] + "").split(separator);
2518 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2524 var start = +new Date,
2528 var time = new Date - start,
2532 for (var attr in from) {
2533 switch (availableAnimAttrs[attr]) {
2535 now = +from[attr] + time * diff[attr];
2539 Math.round(from[attr].r + time * diff[attr].r),
2540 Math.round(from[attr].g + time * diff[attr].g),
2541 Math.round(from[attr].b + time * diff[attr].b)
2546 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2547 now[i] = [from[attr][i][0]];
2548 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2549 now[i][j] = from[attr][i][j] + time * diff[attr][i][j];
2551 now[i] = now[i].join(" ");
2553 now = now.join(" ");
2558 var x = diff[attr][0] * (time - prev),
2559 y = diff[attr][1] * (time - prev);
2562 now = [x, y].join(" ");
2565 now = +from[attr][0] + time * diff[attr][0];
2566 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2569 now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1], (2 in params[attr] ? params[attr][2] : ""), (3 in params[attr] ? params[attr][3] : "")].join(" ");
2573 if (attr == "font-size") {
2574 set[attr] = now + "px";
2580 that.animation_in_progress = setTimeout(tick);
2583 (t.x || t.y) && that.translate(-t.x, -t.y);
2585 clearTimeout(that.animation_in_progress);
2587 (typeof callback == "function") && callback.call(that);
2593 Element.prototype.translate = function (x, y) {
2595 return {x: this._.tx, y: this._.ty};
2599 switch (this.type) {
2602 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
2607 this.attr({x: this.attrs.x + (+x), y: this.attrs.y + (+y)});
2610 var path = pathToRelative(this.attrs.path);
2613 this.attr({path: path.join(" ")});
2620 var Set = function (itemsArray) {
2622 this.length = (itemsArray && itemsArray.length) || 0;
2623 if (itemsArray && itemsArray.constructor == Array) {
2624 for (var i = itemsArray.length; i--;) {
2625 if (itemsArray[i].constructor == Element) {
2626 this.items[this.items.length] = itemsArray[i];
2631 Set.prototype.push = function (item) {
2632 if (item && item.constructor == Element) {
2633 var len = this.items.length;
2634 this.items[len] = item;
2640 Set.prototype.pull = function (id) {
2641 var res = this.items.splice(id, 1)[0];
2642 for (var j = id, jj = this.items.length; j < jj; j++) {
2643 this[j] = this[j + 1];
2645 delete this[jj + 1];
2649 for (var method in Element.prototype) {
2650 Set.prototype[method] = (function (methodname) {
2651 return function () {
2652 for (var i = this.items.length; i--;) {
2653 this.items[i][methodname].apply(this.items[i], arguments);
2659 Set.prototype.getBBox = function () {
2660 var x = [], y = [], w = [], h = [];
2661 for (var i = this.items.length; i--;) {
2662 var box = this.items[i].getBBox();
2665 w.push(box.x + box.width);
2666 h.push(box.y + box.height);
2668 x = Math.min.apply(Math, x);
2669 y = Math.min.apply(Math, y);
2673 width: Math.max.apply(Math, w) - x,
2674 height: Math.max.apply(Math, h) - y
2678 R.registerFont = function (font) {
2682 this.fonts = this.fonts || {};
2683 if (this.fonts[font.face["font-family"]]) {
2684 this.fonts[font.face["font-family"]].push(font);
2686 this.fonts[font.face["font-family"]] = [font];
2689 font.face["units-per-em"] = parseInt(font.face["units-per-em"], 10);
2691 for (var glyph in font.glyphs) {
2692 var path = font.glyphs[glyph];
2694 path.d = "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
2695 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
2701 paper.getFont = function (family, weight, style, stretch) {
2702 stretch = stretch || "normal";
2703 style = style || "normal";
2704 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
2705 var font = R.fonts[family];
2707 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, "") + "(\\s|$)", "i");
2708 for (var fontName in R.fonts) {
2709 if (name.test(fontName)) {
2710 font = R.fonts[fontName];
2717 for (var i = 0, ii = font.length; i < ii; i++) {
2719 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
2726 paper.print = function (x, y, string, font, size) {
2727 var out = this.set(),
2728 letters = (string + "").split(""),
2733 scale = (size || 16) / font.face["units-per-em"];
2734 for (var i = 0, ii = letters.length; i < ii; i++) {
2735 var prev = i && font.glyphs[letters[i - 1]] || {},
2736 curr = font.glyphs[letters[i]];
2737 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
2738 curr && curr.d && out.push(this.path({fill: "#000", stroke: "none"}, curr.d).translate(shift, 0));
2740 out.scale(scale, scale, 0, y).translate(x, (size || 16) / 2);
2745 R.ninja = function () {
2746 var r = window.Raphael;
2747 if (oldRaphael.was) {
2748 window.Raphael = oldRaphael.is;
2751 delete window.Raphael;
2753 window.Raphael = void(0);
2758 R.el = Element.prototype;