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);
373 for (var j = 1, jj = pa.length; j < jj; j++) {
374 r[j] = +pa[j] + ((j % 2) ? x : y);
390 x = res[i][res[i].length - 2];
391 y = res[i][res[i].length - 1];
394 res.toString = pathArray.toString;
397 pecache = {}, pecount = [],
398 pathEqualiser = function (path1, path2) {
399 if ((path1 + path2) in pecache) {
400 return pecache[path1 + path2];
402 var data = [pathToAbsolute(R.parsePathString(path1)), pathToAbsolute(R.parsePathString(path2))],
403 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}],
404 processPath = function (path, d) {
414 var nx = d.x + (d.x - (d.bx || d.x));
415 var ny = d.y + (d.y - (d.by || d.y));
416 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
419 var nx = d.x + (d.x - (d.bx || d.x));
420 var ny = d.y + (d.y - (d.by || d.y));
421 path = ["Q", nx, ny, path[1], path[2]];
424 path = ["L", path[1], d.y];
427 path = ["L", d.x, path[1]];
430 path = ["L", d.X, d.Y];
435 edgeCases = function (a, b, i) {
436 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
437 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
438 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
439 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
440 attrs[a].x = data[a][i][data[a][i].length - 2];
441 attrs[a].y = data[a][i][data[a][i].length - 1];
443 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
444 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]];
445 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
446 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
447 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
448 var x = data[b][i][data[b][i].length - 2];
449 var y = data[b][i][data[b][i].length - 1];
450 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
451 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
453 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
454 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
455 attrs[b].x = data[b][i][data[b][i].length - 2];
456 attrs[b].y = data[b][i][data[b][i].length - 1];
458 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
459 var x = data[b][i][data[b][i].length - 2];
460 var y = data[b][i][data[b][i].length - 1];
461 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
462 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
464 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
465 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
466 attrs[b].x = data[b][i][data[b][i].length - 2];
467 attrs[b].y = data[b][i][data[b][i].length - 1];
469 } else if (data[a][i][0] == "U") {
470 data[a][i][0] = data[b][i][0];
471 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
472 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
477 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
478 data[0][i] = processPath(data[0][i], attrs[0]);
479 data[1][i] = processPath(data[1][i], attrs[1]);
480 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
483 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
484 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
485 attrs[0].x = data[0][i][data[0][i].length - 2];
486 attrs[0].y = data[0][i][data[0][i].length - 1];
487 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
488 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
489 attrs[1].x = data[1][i][data[1][i].length - 2];
490 attrs[1].y = data[1][i][data[1][i].length - 1];
492 if (pecount.length > 20) {
493 delete pecache[pecount.unshift()];
495 pecount.push(path1 + path2);
496 pecache[path1 + path2] = data;
499 toGradient = function (gradient) {
500 if (typeof gradient == "string") {
501 gradient = gradient.split(/\s*\-\s*/);
502 var angle = gradient.shift();
503 if (angle.toLowerCase() == "v") {
505 } else if (angle.toLowerCase() == "h") {
508 angle = parseFloat(angle);
511 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)]};
512 var max = 1 / (Math.max(Math.abs(grobj.vector[2]), Math.abs(grobj.vector[3])) || 1);
513 grobj.vector[2] *= max;
514 grobj.vector[3] *= max;
515 if (grobj.vector[2] < 0) {
516 grobj.vector[0] = -grobj.vector[2];
519 if (grobj.vector[3] < 0) {
520 grobj.vector[1] = -grobj.vector[3];
523 grobj.vector[0] = grobj.vector[0].toFixed(3);
524 grobj.vector[1] = grobj.vector[1].toFixed(3);
525 grobj.vector[2] = grobj.vector[2].toFixed(3);
526 grobj.vector[3] = grobj.vector[3].toFixed(3);
527 for (var i = 0, ii = gradient.length; i < ii; i++) {
529 var par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
530 dot.color = R.getRGB(par[1]).hex;
531 par[2] && (dot.offset = par[2] + "%");
532 grobj.dots.push(dot);
534 for (var i = 1, ii = grobj.dots.length - 1; i < ii; i++) {
535 if (!grobj.dots[i].offset) {
536 var start = parseFloat(grobj.dots[i - 1].offset || 0),
538 for (var j = i + 1; j < ii; j++) {
539 if (grobj.dots[j].offset) {
540 end = grobj.dots[j].offset;
548 end = parseFloat(end);
549 var d = (end - start) / (j - i + 1);
552 grobj.dots[i].offset = start + "%";
561 getContainer = function () {
562 var container, x, y, width, height;
563 if (typeof arguments[0] == "string" || typeof arguments[0] == "object") {
564 if (typeof arguments[0] == "string") {
565 container = doc.getElementById(arguments[0]);
567 container = arguments[0];
569 if (container.tagName) {
570 if (arguments[1] == null) {
572 container: container,
573 width: container.style.pixelWidth || container.offsetWidth,
574 height: container.style.pixelHeight || container.offsetHeight
577 return {container: container, width: arguments[1], height: arguments[2]};
580 } else if (typeof arguments[0] == "number" && arguments.length > 3) {
581 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
584 plugins = function (con, add) {
585 for (var prop in add) if (add.hasOwnProperty(prop) && !(prop in con)) {
586 switch (typeof add[prop]) {
588 con[prop] = con === this ? add[prop] : function () { return add[prop].apply(this, arguments); };
592 plugins.call(this, con[prop], add[prop]);
595 con[prop] = add[prop];
603 R.toString = function () {
604 return "Your browser supports SVG.\nYou are running Rapha\u00ebl " + this.version;
606 var thePath = function (params, pathString, SVG) {
607 var el = doc.createElementNS(SVG.svgns, "path");
609 SVG.canvas.appendChild(el);
611 var p = new Element(el, SVG);
614 p.last = {x: 0, y: 0, bx: 0, by: 0};
615 p.absolutely = function () {
616 this.isAbsolute = true;
619 p.relatively = function () {
620 this.isAbsolute = false;
623 p.moveTo = function (x, y) {
624 var d = this.isAbsolute?"M":"m";
625 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
626 var oldD = this[0].getAttribute("d") || "";
627 (oldD == "M0,0") && (oldD = "");
628 this[0].setAttribute("d", oldD + d);
629 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
630 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
631 this.attrs.path = oldD + d;
634 p.lineTo = function (x, y) {
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 var d = this.isAbsolute?"L":"l";
638 d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
639 var oldD = this[0].getAttribute("d") || "";
640 this[0].setAttribute("d", oldD + d);
641 this.attrs.path = oldD + d;
644 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
645 var d = this.isAbsolute ? "A" : "a";
646 d += [parseFloat(rx).toFixed(3), parseFloat(ry).toFixed(3), 0, large_arc_flag, sweep_flag, parseFloat(x).toFixed(3), parseFloat(y).toFixed(3)].join(" ");
647 var oldD = this[0].getAttribute("d") || "";
648 this[0].setAttribute("d", oldD + d);
649 this.last.x = parseFloat(x);
650 this.last.y = parseFloat(y);
651 this.attrs.path = oldD + d;
654 p.cplineTo = function (x1, y1, w1) {
656 return this.lineTo(x1, y1);
659 var x = parseFloat(x1);
660 var y = parseFloat(y1);
661 var w = parseFloat(w1);
662 var d = this.isAbsolute?"C":"c";
663 var attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
664 for (var i = 0, ii = attr.length; i < ii; i++) {
665 d += attr[i].toFixed(3) + " ";
667 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
668 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
669 this.last.bx = attr[2];
670 this.last.by = attr[3];
671 var oldD = this[0].getAttribute("d") || "";
672 this[0].setAttribute("d", oldD + d);
673 this.attrs.path = oldD + d;
677 p.curveTo = function () {
679 command = [0, 1, 2, 3, "s", 5, "c"];
681 var d = command[arguments.length];
682 if (this.isAbsolute) {
685 for (var i = 0, ii = arguments.length; i < ii; i++) {
686 d += parseFloat(arguments[i]).toFixed(3) + " ";
688 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
689 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
690 this.last.bx = parseFloat(arguments[arguments.length - 4]);
691 this.last.by = parseFloat(arguments[arguments.length - 3]);
692 var oldD = this.node.getAttribute("d") || "";
693 this.node.setAttribute("d", oldD + d);
694 this.attrs.path = oldD + d;
697 p.qcurveTo = function () {
699 command = [0, 1, "t", 3, "q"];
701 var d = command[arguments.length];
702 if (this.isAbsolute) {
705 for (var i = 0, ii = arguments.length; i < ii; i++) {
706 d += parseFloat(arguments[i]).toFixed(3) + " ";
708 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
709 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
710 if (arguments.length != 2) {
711 this.last.qx = parseFloat(arguments[arguments.length - 4]);
712 this.last.qy = parseFloat(arguments[arguments.length - 3]);
714 var oldD = this.node.getAttribute("d") || "";
715 this.node.setAttribute("d", oldD + d);
716 this.attrs.path = oldD + d;
719 p.addRoundedCorner = function (r, dir) {
720 var R = .5522 * r, rollback = this.isAbsolute, o = this;
723 rollback = function () {
727 rollback = function () {};
733 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
736 o.curveTo(-R, 0, -r, r - R, -r, r);
743 o.curveTo(R, 0, r, -(r - R), r, -r);
746 o.curveTo(R, 0, r, r - R, r, r);
753 o.curveTo(0, -R, -(R - r), -r, r, -r);
756 o.curveTo(0, -R, R - r, -r, -r, -r);
763 o.curveTo(0, R, -(R - r), r, r, r);
766 o.curveTo(0, R, R - r, r, -r, r);
771 actions[dir[0]]()[dir[1]]();
775 p.andClose = function () {
776 var oldD = this[0].getAttribute("d") || "";
777 this[0].setAttribute("d", oldD + "Z ");
778 this.attrs.path = oldD + "Z ";
782 p.attrs.path = "" + pathString;
784 paper.pathfinder(p, p.attrs.path);
787 !params.gradient && (params.fill = params.fill || "none");
788 params.stroke = params.stroke || "#000";
790 params = {fill: "none", stroke: "#000"};
792 setFillAndStroke(p, params);
795 var addGradientFill = function (o, gradient, SVG) {
796 gradient = toGradient(gradient);
797 var el = doc.createElementNS(SVG.svgns, (gradient.type || "linear") + "Gradient");
798 el.id = "raphael-gradient-" + R.idGenerator++;
799 if (gradient.vector && gradient.vector.length) {
800 el.setAttribute("x1", gradient.vector[0]);
801 el.setAttribute("y1", gradient.vector[1]);
802 el.setAttribute("x2", gradient.vector[2]);
803 el.setAttribute("y2", gradient.vector[3]);
805 SVG.defs.appendChild(el);
806 var isopacity = true;
807 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
808 var stop = doc.createElementNS(SVG.svgns, "stop");
809 if (gradient.dots[i].offset) {
812 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
813 stop.setAttribute("stop-color", R.getRGB(gradient.dots[i].color).hex || "#fff");
814 // ignoring opacity for internal points, because VML doesn't support it
815 el.appendChild(stop);
817 if (isopacity && typeof gradient.dots[ii - 1].opacity != "undefined") {
818 stop.setAttribute("stop-opacity", gradient.dots[ii - 1].opacity);
820 o.setAttribute("fill", "url(#" + el.id + ")");
823 o.style.fillOpacity = 1;
824 o.setAttribute("opacity", 1);
825 o.setAttribute("fill-opacity", 1);
827 var updatePosition = function (o) {
829 var bbox = o.getBBox();
830 o.pattern.setAttribute("patternTransform", "translate(".concat(bbox.x, ",", bbox.y, ")"));
833 var setFillAndStroke = function (o, params) {
838 "-..": [3, 1, 1, 1, 1, 1],
844 "--..": [8, 3, 1, 3, 1, 3]
848 addDashes = function (o, value) {
849 value = dasharray[value.toString().toLowerCase()];
851 var width = o.attrs["stroke-width"] || "1",
852 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
854 for (var i = 0, ii = value.length; i < ii; i++) {
855 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
857 value = dashes.join(",");
858 node.setAttribute("stroke-dasharray", value);
861 for (var att in params) {
862 if (!(att in availableAttrs)) {
865 var value = params[att];
872 var pn = node.parentNode;
873 if (pn.tagName.toLowerCase() != "a") {
874 var hl = doc.createElementNS(o.paper.svgns, "a");
875 pn.insertBefore(hl, node);
876 hl.appendChild(node);
879 pn.setAttributeNS(o.paper.xlink, att, value);
882 if (o.type == "path") {
883 node.setAttribute("d", "M0,0");
884 paper.pathfinder(o, value);
887 node.setAttribute(att, value);
896 value = -attrs.x - (attrs.width || 0);
900 node.setAttribute(att, value);
904 node.setAttribute(att, value);
913 value = -attrs.y - (attrs.height || 0);
917 node.setAttribute(att, value);
921 if (o.type == "rect") {
922 node.setAttribute("rx", value);
923 node.setAttribute("ry", value);
925 node.setAttribute(att, value);
929 if (o.type == "image") {
930 node.setAttributeNS(o.paper.xlink, "href", value);
934 node.style.strokeWidth = value;
935 // Need following line for Firefox
936 node.setAttribute(att, value);
937 if (attrs["stroke-dasharray"]) {
938 addDashes(o, attrs["stroke-dasharray"]);
941 case "stroke-dasharray":
945 o.rotate(value, true);
948 var xy = (value + "").split(separator);
949 o.translate((+xy[0] + 1 || 2) - 1, (+xy[1] + 1 || 2) - 1);
952 var xy = (value + "").split(separator);
953 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
956 var isURL = value.match(/^url\(([^\)]+)\)$/i);
958 var el = doc.createElementNS(o.paper.svgns, "pattern");
959 var ig = doc.createElementNS(o.paper.svgns, "image");
960 el.id = "raphael-pattern-" + R.idGenerator++;
961 el.setAttribute("x", 0);
962 el.setAttribute("y", 0);
963 el.setAttribute("patternUnits", "userSpaceOnUse");
964 ig.setAttribute("x", 0);
965 ig.setAttribute("y", 0);
966 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
969 var img = doc.createElement("img");
970 img.style.position = "absolute";
971 img.style.top = "-9999em";
972 img.style.left = "-9999em";
973 img.onload = function () {
974 el.setAttribute("width", this.offsetWidth);
975 el.setAttribute("height", this.offsetHeight);
976 ig.setAttribute("width", this.offsetWidth);
977 ig.setAttribute("height", this.offsetHeight);
978 doc.body.removeChild(this);
981 doc.body.appendChild(img);
983 o.paper.defs.appendChild(el);
984 node.style.fill = "url(#" + el.id + ")";
985 node.setAttribute("fill", "url(#" + el.id + ")");
990 delete params.gradient;
991 delete attrs.gradient;
992 if (typeof attrs.opacity != "undefined" && typeof params.opacity == "undefined" ) {
993 node.style.opacity = attrs.opacity;
994 // Need following line for Firefox
995 node.setAttribute("opacity", attrs.opacity);
997 if (typeof attrs["fill-opacity"] != "undefined" && typeof params["fill-opacity"] == "undefined" ) {
998 node.style.fillOpacity = o.attrs["fill-opacity"];
999 // Need following line for Firefox
1000 node.setAttribute("fill-opacity", attrs["fill-opacity"]);
1003 node.style[att] = R.getRGB(value).hex;
1004 // Need following line for Firefox
1005 node.setAttribute(att, R.getRGB(value).hex);
1008 addGradientFill(node, value, o.paper);
1011 case "fill-opacity":
1012 if (attrs.gradient) {
1013 var gradient = doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, ""));
1015 var stops = gradient.getElementsByTagName("stop");
1016 stops[stops.length - 1].setAttribute("stop-opacity", value);
1021 var cssrule = att.replace(/(\-.)/g, function (w) {
1022 return w.substring(1).toUpperCase();
1024 node.style[cssrule] = value;
1025 // Need following line for Firefox
1026 node.setAttribute(att, value);
1031 tuneText(o, params);
1034 var tuneText = function (el, params) {
1035 if (el.type != "text" || !("text" in params || "font" in params || "font-size" in params || "x" in params || "y" in params)) {
1040 fontSize = node.firstChild ? parseInt(doc.defaultView.getComputedStyle(node.firstChild, "").getPropertyValue("font-size"), 10) : 10;
1042 if ("text" in params) {
1043 while (node.firstChild) {
1044 node.removeChild(node.firstChild);
1046 var texts = (params.text + "").split("\n");
1047 for (var i = 0, ii = texts.length; i < ii; i++) {
1048 var tspan = doc.createElementNS(el.paper.svgns, "tspan");
1049 i && tspan.setAttribute("dy", fontSize * leading);
1050 i && tspan.setAttribute("x", a.x);
1051 tspan.appendChild(doc.createTextNode(texts[i]));
1052 node.appendChild(tspan);
1055 var texts = node.getElementsByTagName("tspan");
1056 for (var i = 0, ii = texts.length; i < ii; i++) {
1057 i && texts[i].setAttribute("dy", fontSize * leading);
1058 i && texts[i].setAttribute("x", a.x);
1061 node.setAttribute("y", a.y);
1062 var bb = el.getBBox(),
1063 dif = a.y - (bb.y + bb.height / 2);
1064 dif && node.setAttribute("y", a.y + dif);
1066 var Element = function (node, svg) {
1072 this.attrs = this.attrs || {};
1073 this.transformations = []; // rotate, translate, scale
1077 rt: {deg: 0, x: 0, y: 0},
1082 Element.prototype.rotate = function (deg, cx, cy) {
1084 return this._.rt.deg;
1086 var bbox = this.getBBox();
1087 deg = deg.toString().split(separator);
1088 if (deg.length - 1) {
1089 cx = parseFloat(deg[1]);
1090 cy = parseFloat(deg[2]);
1092 deg = parseFloat(deg[0]);
1094 this._.rt.deg = deg;
1096 this._.rt.deg += deg;
1101 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1102 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1103 if (this._.rt.deg) {
1104 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
1106 this.transformations[0] = "";
1108 this.node.setAttribute("transform", this.transformations.join(" "));
1111 Element.prototype.hide = function () {
1112 this.node.style.display = "none";
1115 Element.prototype.show = function () {
1116 this.node.style.display = "block";
1119 Element.prototype.remove = function () {
1120 this.node.parentNode.removeChild(this.node);
1122 Element.prototype.getBBox = function () {
1123 var bbox = this.node.getBBox();
1124 if (this.type == "text") {
1125 bbox = {x: bbox.x, y: Infinity, width: bbox.width, height: 0};
1126 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1127 var bb = this.node.getExtentOfChar(i);
1128 (bb.y < bbox.y) && (bbox.y = bb.y);
1129 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1134 Element.prototype.attr = function () {
1135 if (arguments.length == 1 && typeof arguments[0] == "string") {
1136 if (arguments[0] == "translation") {
1137 return this.translate();
1139 return this.attrs[arguments[0]];
1141 if (arguments.length == 1 && arguments[0] instanceof win.Array) {
1143 for (var j in arguments[0]) {
1144 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1148 if (arguments.length == 2) {
1150 params[arguments[0]] = arguments[1];
1151 setFillAndStroke(this, params);
1152 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1153 setFillAndStroke(this, arguments[0]);
1157 Element.prototype.toFront = function () {
1158 this.node.parentNode.appendChild(this.node);
1161 Element.prototype.toBack = function () {
1162 if (this.node.parentNode.firstChild != this.node) {
1163 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1167 Element.prototype.insertAfter = function (element) {
1168 if (element.node.nextSibling) {
1169 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1171 element.node.parentNode.appendChild(this.node);
1175 Element.prototype.insertBefore = function (element) {
1176 element.node.parentNode.insertBefore(this.node, element.node);
1179 var theCircle = function (svg, x, y, r) {
1180 var el = doc.createElementNS(svg.svgns, "circle");
1181 el.setAttribute("cx", x);
1182 el.setAttribute("cy", y);
1183 el.setAttribute("r", r);
1184 el.setAttribute("fill", "none");
1185 el.setAttribute("stroke", "#000");
1187 svg.canvas.appendChild(el);
1189 var res = new Element(el, svg);
1190 res.attrs = res.attrs || {};
1194 res.attrs.stroke = "#000";
1195 res.type = "circle";
1198 var theRect = function (svg, x, y, w, h, r) {
1199 var el = doc.createElementNS(svg.svgns, "rect");
1200 el.setAttribute("x", x);
1201 el.setAttribute("y", y);
1202 el.setAttribute("width", w);
1203 el.setAttribute("height", h);
1205 el.setAttribute("rx", r);
1206 el.setAttribute("ry", r);
1208 el.setAttribute("fill", "none");
1209 el.setAttribute("stroke", "#000");
1211 svg.canvas.appendChild(el);
1213 var res = new Element(el, svg);
1214 res.attrs = res.attrs || {};
1217 res.attrs.width = w;
1218 res.attrs.height = h;
1219 res.attrs.stroke = "#000";
1221 res.attrs.rx = res.attrs.ry = r;
1226 var theEllipse = function (svg, x, y, rx, ry) {
1227 var el = doc.createElementNS(svg.svgns, "ellipse");
1228 el.setAttribute("cx", x);
1229 el.setAttribute("cy", y);
1230 el.setAttribute("rx", rx);
1231 el.setAttribute("ry", ry);
1232 el.setAttribute("fill", "none");
1233 el.setAttribute("stroke", "#000");
1235 svg.canvas.appendChild(el);
1237 var res = new Element(el, svg);
1238 res.attrs = res.attrs || {};
1243 res.attrs.stroke = "#000";
1244 res.type = "ellipse";
1247 var theImage = function (svg, src, x, y, w, h) {
1248 var el = doc.createElementNS(svg.svgns, "image");
1249 el.setAttribute("x", x);
1250 el.setAttribute("y", y);
1251 el.setAttribute("width", w);
1252 el.setAttribute("height", h);
1253 el.setAttribute("preserveAspectRatio", "none");
1254 el.setAttributeNS(svg.xlink, "href", src);
1256 svg.canvas.appendChild(el);
1258 var res = new Element(el, svg);
1259 res.attrs = res.attrs || {};
1262 res.attrs.width = w;
1263 res.attrs.height = h;
1267 var theText = function (svg, x, y, text) {
1268 var el = doc.createElementNS(svg.svgns, "text");
1269 el.setAttribute("x", x);
1270 el.setAttribute("y", y);
1271 el.setAttribute("text-anchor", "middle");
1273 svg.canvas.appendChild(el);
1275 var res = new Element(el, svg);
1276 res.attrs = res.attrs || {};
1280 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000", text: text});
1283 var setSize = function (width, height) {
1284 this.width = width || this.width;
1285 this.height = height || this.height;
1286 this.canvas.setAttribute("width", this.width);
1287 this.canvas.setAttribute("height", this.height);
1290 var create = function () {
1291 var con = getContainer.apply(null, arguments);
1292 var container = con.container,
1296 height = con.height;
1298 throw new Error("SVG container not found.");
1300 paper.canvas = doc.createElementNS(paper.svgns, "svg");
1301 paper.canvas.setAttribute("width", width || 512);
1302 paper.width = width || 512;
1303 paper.canvas.setAttribute("height", height || 342);
1304 paper.height = height || 342;
1305 if (container == 1) {
1306 doc.body.appendChild(paper.canvas);
1307 paper.canvas.style.position = "absolute";
1308 paper.canvas.style.left = x + "px";
1309 paper.canvas.style.top = y + "px";
1311 if (container.firstChild) {
1312 container.insertBefore(paper.canvas, container.firstChild);
1314 container.appendChild(paper.canvas);
1318 canvas: paper.canvas,
1319 clear: function () {
1320 while (this.canvas.firstChild) {
1321 this.canvas.removeChild(this.canvas.firstChild);
1323 this.defs = doc.createElementNS(paper.svgns, "defs");
1324 this.canvas.appendChild(this.defs);
1327 for (var prop in paper) {
1328 if (prop != "create") {
1329 container[prop] = paper[prop];
1332 plugins.call(container, container, R.fn);
1334 container.raphael = R;
1337 paper.remove = function () {
1338 this.canvas.parentNode.removeChild(this.canvas);
1340 paper.svgns = "http://www.w3.org/2000/svg";
1341 paper.xlink = "http://www.w3.org/1999/xlink";
1342 paper.safari = function () {
1343 if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor]) {
1344 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1345 setTimeout(function () {rect.remove();});
1352 R.toString = function () {
1353 return "Your browser doesn\u2019t support SVG.\nYou are running Rapha\u00ebl " + this.version;
1355 thePath = function (params, pathString, VML) {
1356 var g = createNode("group"), gl = g.style;
1357 gl.position = "absolute";
1360 gl.width = VML.width + "px";
1361 gl.height = VML.height + "px";
1362 var el = createNode("shape"), ol = el.style;
1363 ol.width = VML.width + "px";
1364 ol.height = VML.height + "px";
1366 if (params["class"]) {
1367 el.className = "rvml " + params["class"];
1369 el.coordsize = this.coordsize;
1370 el.coordorigin = this.coordorigin;
1372 var p = new Element(el, g, VML);
1373 p.isAbsolute = true;
1376 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1378 p.absolutely = function () {
1379 this.isAbsolute = true;
1382 p.relatively = function () {
1383 this.isAbsolute = false;
1386 p.moveTo = function (x, y) {
1387 var d = this.isAbsolute?"m":"t";
1388 d += Math.round(parseFloat(x)) + " " + Math.round(parseFloat(y));
1389 this.node.path = this.Path += d;
1390 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1391 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1392 this.last.isAbsolute = this.isAbsolute;
1393 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1396 p.lineTo = function (x, y) {
1397 var d = this.isAbsolute?"l":"r";
1398 d += Math.round(parseFloat(x)) + " " + Math.round(parseFloat(y));
1399 this[0].path = this.Path += d;
1400 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
1401 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
1402 this.last.isAbsolute = this.isAbsolute;
1403 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1406 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1407 // for more information of where this math came from visit:
1408 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1409 x2 = (this.isAbsolute ? 0 : this.last.x) + x2;
1410 y2 = (this.isAbsolute ? 0 : this.last.y) + y2;
1411 var x1 = this.last.x,
1415 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1416 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1417 cx = k * rx * y / ry + (x1 + x2) / 2,
1418 cy = k * -ry * x / rx + (y1 + y2) / 2,
1419 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1420 left = Math.round(cx - rx),
1421 top = Math.round(cy - ry);
1422 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(", ");
1423 this.node.path = this.Path += d;
1424 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2);
1425 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2);
1426 this.last.isAbsolute = this.isAbsolute;
1427 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1430 p.cplineTo = function (x1, y1, w1) {
1432 return this.lineTo(x1, y1);
1434 var x = Math.round(Math.round(parseFloat(x1) * 100) / 100),
1435 y = Math.round(Math.round(parseFloat(y1) * 100) / 100),
1436 w = Math.round(Math.round(parseFloat(w1) * 100) / 100),
1437 d = this.isAbsolute ? "c" : "v",
1438 attr = [Math.round(this.last.x) + w, Math.round(this.last.y), x - w, y, x, y],
1439 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1440 d += attr.join(" ") + " ";
1441 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1442 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1443 this.last.bx = attr[2];
1444 this.last.by = attr[3];
1445 this.node.path = this.Path += d;
1446 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1450 p.curveTo = function () {
1451 var d = this.isAbsolute ? "c" : "v";
1452 if (arguments.length == 6) {
1453 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1454 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1455 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4]);
1456 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5]);
1457 d += [Math.round(parseFloat(arguments[0])),
1458 Math.round(parseFloat(arguments[1])),
1459 Math.round(parseFloat(arguments[2])),
1460 Math.round(parseFloat(arguments[3])),
1461 Math.round(parseFloat(arguments[4])),
1462 Math.round(parseFloat(arguments[5]))].join(" ") + " ";
1463 this.last.isAbsolute = this.isAbsolute;
1464 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1466 if (arguments.length == 4) {
1467 var bx = this.last.x * 2 - this.last.bx;
1468 var by = this.last.y * 2 - this.last.by;
1469 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0]);
1470 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1]);
1471 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1472 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1473 d += [Math.round(bx), Math.round(by),
1474 Math.round(parseFloat(arguments[0])),
1475 Math.round(parseFloat(arguments[1])),
1476 Math.round(parseFloat(arguments[2])),
1477 Math.round(parseFloat(arguments[3]))].join(" ") + " ";
1478 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1480 this.node.path = this.Path += d;
1483 p.qcurveTo = function () {
1485 if (arguments.length == 4) {
1486 this.last.qx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0]);
1487 this.last.qy = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1]);
1488 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1489 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1490 d += [Math.round(this.last.qx),
1491 Math.round(this.last.qy),
1492 Math.round(this.last.x),
1493 Math.round(this.last.y)].join(" ") + " ";
1494 this.last.isAbsolute = this.isAbsolute;
1495 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1497 if (arguments.length == 2) {
1498 this.last.qx = this.last.x * 2 - this.last.qx;
1499 this.last.qy = this.last.y * 2 - this.last.qy;
1500 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2]);
1501 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3]);
1502 d += [Math.round(this.last.qx),
1503 Math.round(this.last.qy),
1504 Math.round(this.last.x),
1505 Math.round(this.last.y)].join(" ") + " ";
1506 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1508 this.node.path = this.Path += d;
1509 this.path.push({type: "qcurve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
1512 p.addRoundedCorner = function (r, dir) {
1513 var R = .5522 * r, rollback = this.isAbsolute, o = this;
1516 rollback = function () {
1520 rollback = function () {};
1526 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
1529 o.curveTo(-R, 0, -r, r - R, -r, r);
1536 o.curveTo(R, 0, r, -(r - R), r, -r);
1539 o.curveTo(R, 0, r, r - R, r, r);
1546 o.curveTo(0, -R, -(R - r), -r, r, -r);
1549 o.curveTo(0, -R, R - r, -r, -r, -r);
1556 o.curveTo(0, R, -(R - r), r, r, r);
1559 o.curveTo(0, R, R - r, r, -r, r);
1564 actions[dir.charAt(0)]()[dir.charAt(1)]();
1568 p.andClose = function () {
1569 this.node.path = (this.Path += "x");
1570 this.attrs.path += "z";
1576 paper.pathfinder(p, "" + pathString);
1579 params.fill = params.fill || "none";
1580 params.stroke = params.stroke || "#000";
1582 params = {fill: "none", stroke: "#000"};
1584 setFillAndStroke(p, params);
1585 if (params.gradient) {
1586 addGradientFill(p, params.gradient);
1588 VML.canvas.appendChild(g);
1591 var setFillAndStroke = function (o, params) {
1595 o.attrs = o.attrs || {};
1596 for (var par in params) {
1597 o.attrs[par] = params[par];
1599 params.href && (node.href = params.href);
1600 params.title && (node.title = params.title);
1601 params.target && (node.target = params.target);
1602 if (params.path && o.type == "path") {
1605 paper.pathfinder(o, params.path);
1607 if (params.rotation != null) {
1608 o.rotate(params.rotation, true);
1610 if (params.translation) {
1611 var xy = (params.translation + "").split(separator);
1612 o.translate(xy[0], xy[1]);
1615 var xy = (params.scale + "").split(separator);
1616 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1618 if (o.type == "image" && params.src) {
1619 node.src = params.src;
1621 if (o.type == "image" && params.opacity) {
1622 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1623 node.style.filter = (node.filterMatrix || "") + (node.filterOpacity || "");
1625 params.font && (s.font = params.font);
1626 params["font-family"] && (s.fontFamily = params["font-family"]);
1627 params["font-size"] && (s.fontSize = params["font-size"]);
1628 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1629 params["font-style"] && (s.fontStyle = params["font-style"]);
1630 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"]) {
1631 o = o.shape || node;
1632 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || createNode("fill");
1633 if ("fill-opacity" in params || "opacity" in params) {
1634 fill.opacity = ((+params["fill-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1636 params.fill && (fill.on = true);
1637 if (typeof fill.on == "undefined" || params.fill == "none") {
1640 if (fill.on && params.fill) {
1641 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1643 fill.src = isURL[1];
1646 fill.color = R.getRGB(params.fill).hex;
1648 fill.type = "solid";
1651 o.appendChild(fill);
1652 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || createNode("stroke");
1653 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"]) {
1656 if (params.stroke == "none" || typeof stroke.on == "undefined" || params.stroke == 0) {
1659 if (stroke.on && params.stroke) {
1660 stroke.color = R.getRGB(params.stroke).hex;
1662 stroke.opacity = ((+params["stroke-opacity"] + 1 || 2) - 1) * ((+params.opacity + 1 || 2) - 1);
1663 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1664 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1665 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1666 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"]) || 1) * 12 / 16);
1667 if (params["stroke-dasharray"]) {
1671 "-.": "shortdashdot",
1672 "-..": "shortdashdotdot",
1677 "--.": "longdashdot",
1678 "--..": "longdashdotdot"
1680 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1682 o.appendChild(stroke);
1684 if (res.type == "text") {
1685 var span = doc.createElement("span"),
1691 s.display = "inline";
1692 a.font && (s.font = a.font);
1693 a["font-family"] && (s.fontFamily = a["font-family"]);
1694 a["font-size"] && (s.fontSize = a["font-size"]);
1695 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1696 a["font-style"] && (s.fontStyle = a["font-style"]);
1697 res.node.parentNode.appendChild(span);
1698 span.innerText = res.node.string;
1699 res.W = a.w = span.offsetWidth;
1700 res.H = a.h = span.offsetHeight;
1702 res.Y = a.y + Math.round(res.H / 2);
1703 res.node.parentNode.removeChild(span);
1705 // text-anchor emulation
1706 switch (a["text-anchor"]) {
1708 res.node.style["v-text-align"] = "left";
1709 res.bbx = Math.round(res.W / 2);
1712 res.node.style["v-text-align"] = "right";
1713 res.bbx = -Math.round(res.W / 2);
1716 res.node.style["v-text-align"] = "center";
1721 var getAngle = function (a, b, c, d) {
1722 var angle = Math.round(Math.atan((parseFloat(c) - parseFloat(a)) / (parseFloat(d) - parseFloat(b))) * 57.29) || 0;
1723 if (!angle && parseFloat(a) < parseFloat(b)) {
1732 var addGradientFill = function (o, gradient) {
1733 gradient = toGradient(gradient);
1734 o.attrs = o.attrs || {};
1735 var attrs = o.attrs;
1736 o.attrs.gradient = gradient;
1737 o = o.shape || o[0];
1738 var fill = o.getElementsByTagName("fill");
1742 fill = createNode("fill");
1744 if (gradient.dots.length) {
1746 fill.method = "none";
1747 fill.type = ((gradient.type + "").toLowerCase() == "radial") ? "gradientTitle" : "gradient";
1748 if (typeof gradient.dots[0].color != "undefined") {
1749 fill.color = R.getRGB(gradient.dots[0].color).hex;
1751 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1752 fill.color2 = R.getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1755 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1756 if (gradient.dots[i].offset) {
1757 clrs.push(gradient.dots[i].offset + " " + R.getRGB(gradient.dots[i].color).hex);
1760 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;
1762 fill.colors.value = clrs.join(",");
1763 fillOpacity = typeof attrs.opacity == "undefined" ? 1 : attrs.opacity;
1765 fill.colors && (fill.colors.value = "0% " + fill.color);
1767 fill.opacity = fillOpacity;
1768 if (typeof gradient.angle != "undefined") {
1769 fill.angle = (-gradient.angle + 270) % 360;
1770 } else if (gradient.vector) {
1771 fill.angle = getAngle.apply(null, gradient.vector);
1773 if ((gradient.type + "").toLowerCase() == "radial") {
1774 fill.focus = "100%";
1775 fill.focusposition = "0.5 0.5";
1779 var Element = function (node, group, vml) {
1799 Element.prototype.rotate = function (deg, cx, cy) {
1801 return this._.rt.deg;
1803 deg = deg.toString().split(separator);
1804 if (deg.length - 1) {
1805 cx = parseFloat(deg[1]);
1806 cy = parseFloat(deg[2]);
1808 deg = parseFloat(deg[0]);
1810 this._.rt.deg = deg;
1812 this._.rt.deg += deg;
1819 this.setBox(null, cx, cy);
1820 this.Group.style.rotation = this._.rt.deg;
1821 // gradient fix for rotation. TODO
1822 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1823 // fill = fill[0] || {};
1824 // var b = ((360 - this._.rt.deg) - 270) % 360;
1825 // typeof fill.angle != "undefined" && (fill.angle = b);
1828 Element.prototype.setBox = function (params, cx, cy) {
1829 var gs = this.Group.style,
1830 os = (this.shape && this.shape.style) || this.node.style;
1831 params = params || {};
1832 for (var i in params) {
1833 this.attrs[i] = params[i];
1835 cx = cx || this._.rt.cx;
1836 cy = cy || this._.rt.cy;
1837 var attr = this.attrs, x, y, w, h;
1838 switch (this.type) {
1840 x = attr.cx - attr.r;
1841 y = attr.cy - attr.r;
1845 x = attr.cx - attr.rx;
1846 y = attr.cy - attr.ry;
1854 w = attr.width || 0;
1855 h = attr.height || 0;
1858 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("");
1859 x = attr.x - Math.round(this.W / 2);
1860 y = attr.y - this.H / 2;
1865 if (!this.attrs.path) {
1868 w = this.paper.width;
1869 h = this.paper.height;
1871 var dim = pathDimensions(this.attrs.path),
1881 w = this.paper.width;
1882 h = this.paper.height;
1885 cx = (cx == null) ? x + w / 2 : cx;
1886 cy = (cy == null) ? y + h / 2 : cy;
1887 var left = cx - this.paper.width / 2,
1888 top = cy - this.paper.height / 2;
1889 if (this.type == "path" || this.type == "text") {
1890 (gs.left != left + "px") && (gs.left = left + "px");
1891 (gs.top != top + "px") && (gs.top = top + "px");
1892 this.X = this.type == "text" ? x : -left;
1893 this.Y = this.type == "text" ? y : -top;
1896 (os.left != -left + "px") && (os.left = -left + "px");
1897 (os.top != -top + "px") && (os.top = -top + "px");
1899 (gs.left != left + "px") && (gs.left = left + "px");
1900 (gs.top != top + "px") && (gs.top = top + "px");
1905 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
1906 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
1907 (os.left != x - left + "px") && (os.left = x - left + "px");
1908 (os.top != y - top + "px") && (os.top = y - top + "px");
1909 (os.width != w + "px") && (os.width = w + "px");
1910 (os.height != h + "px") && (os.height = h + "px");
1911 var arcsize = (+params.r || 0) / (Math.min(w, h));
1912 if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) {
1913 // We should replace element with the new one
1914 var o = createNode(arcsize ? "roundrect" : "rect");
1915 o.arcsize = arcsize;
1916 this.Group.appendChild(o);
1917 this.node.parentNode.removeChild(this.node);
1919 this.arcsize = arcsize;
1920 setFillAndStroke(this, this.attrs);
1921 this.setBox(this.attrs);
1925 Element.prototype.hide = function () {
1926 this.Group.style.display = "none";
1929 Element.prototype.show = function () {
1930 this.Group.style.display = "block";
1933 Element.prototype.getBBox = function () {
1934 if (this.type == "path") {
1935 return pathDimensions(this.attr("path"));
1938 x: this.X + (this.bbx || 0),
1944 Element.prototype.remove = function () {
1945 this[0].parentNode.removeChild(this[0]);
1946 this.Group.parentNode.removeChild(this.Group);
1947 this.shape && this.shape.parentNode.removeChild(this.shape);
1949 Element.prototype.attr = function () {
1950 if (arguments.length == 1 && typeof arguments[0] == "string") {
1951 if (arguments[0] == "translation") {
1952 return this.translate();
1954 return this.attrs[arguments[0]];
1956 if (this.attrs && arguments.length == 1 && arguments[0] instanceof win.Array) {
1958 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1959 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1964 if (arguments.length == 2) {
1966 params[arguments[0]] = arguments[1];
1968 if (arguments.length == 1 && typeof arguments[0] == "object") {
1969 params = arguments[0];
1972 if (params.gradient) {
1973 addGradientFill(this, params.gradient);
1975 if (params.text && this.type == "text") {
1976 this.node.string = params.text;
1979 this.node.id = params.id;
1981 setFillAndStroke(this, params);
1982 this.setBox(params);
1986 Element.prototype.toFront = function () {
1987 this.Group.parentNode.appendChild(this.Group);
1990 Element.prototype.toBack = function () {
1991 if (this.Group.parentNode.firstChild != this.Group) {
1992 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
1996 Element.prototype.insertAfter = function (element) {
1997 if (element.Group.nextSibling) {
1998 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2000 element.Group.parentNode.appendChild(this.Group);
2004 Element.prototype.insertBefore = function (element) {
2005 element.Group.parentNode.insertBefore(this.Group, element.Group);
2008 var theCircle = function (vml, x, y, r) {
2009 var g = createNode("group");
2010 var o = createNode("oval");
2012 var res = new Element(o, g, vml);
2013 res.type = "circle";
2014 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2018 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2019 vml.canvas.appendChild(g);
2022 var theRect = function (vml, x, y, w, h, r) {
2023 var g = createNode("group"),
2024 o = createNode(r ? "roundrect" : "rect"),
2025 arcsize = (+r || 0) / (Math.min(w, h));
2026 o.arcsize = arcsize;
2028 var res = new Element(o, g, vml);
2030 setFillAndStroke(res, {stroke: "#000"});
2036 res.arcsize = arcsize;
2037 res.setBox({x: x, y: y, width: w, height: h});
2038 vml.canvas.appendChild(g);
2041 var theEllipse = function (vml, x, y, rx, ry) {
2042 var g = createNode("group");
2043 var o = createNode("oval");
2045 var res = new Element(o, g, vml);
2046 res.type = "ellipse";
2047 setFillAndStroke(res, {stroke: "#000"});
2052 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2053 vml.canvas.appendChild(g);
2056 var theImage = function (vml, src, x, y, w, h) {
2057 var g = createNode("group");
2058 var o = createNode("image");
2061 var res = new Element(o, g, vml);
2067 res.setBox({x: x, y: y, width: w, height: h});
2068 vml.canvas.appendChild(g);
2071 var theText = function (vml, x, y, text) {
2072 var g = createNode("group"), gs = g.style;
2073 var el = createNode("shape"), ol = el.style;
2074 var path = createNode("path"), ps = path.style;
2075 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
2076 path.textpathok = true;
2077 ol.width = vml.width;
2078 ol.height = vml.height;
2079 gs.position = "absolute";
2082 gs.width = vml.width;
2083 gs.height = vml.height;
2084 var o = createNode("textpath");
2087 o.coordsize = vml.coordsize;
2088 o.coordorigin = vml.coordorigin;
2090 el.appendChild(path);
2092 var res = new Element(o, g, vml);
2094 res.textpath = path;
2100 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2102 vml.canvas.appendChild(g);
2105 var setSize = function (width, height) {
2106 this.width = width || this.width;
2107 this.height = height || this.height;
2108 this.canvas.style.width = this.width + "px";
2109 this.canvas.style.height = this.height + "px";
2110 this.canvas.parentNode.style.clip = "rect(0 " + this.width + "px " + this.height + "px 0)";
2111 this.canvas.coordsize = this.width + " " + this.height;
2114 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2116 if (!doc.namespaces.rvml) {
2117 doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2119 var createNode = function (tagName) {
2120 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2123 var createNode = function (tagName) {
2124 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2127 var create = function () {
2128 var con = getContainer.apply(null, arguments);
2129 var container = con.container,
2133 height = con.height;
2135 throw new Error("VML container not found.");
2137 var c = doc.createElement("div"),
2138 d = doc.createElement("div"),
2139 r = paper.canvas = createNode("group"),
2140 cs = c.style, rs = r.style;
2141 paper.width = width;
2142 paper.height = height;
2143 width = width || "512px";
2144 height = height || "342px";
2145 cs.clip = "rect(0 " + width + "px " + height + "px 0)";
2148 cs.position = "absolute";
2149 rs.position = "absolute";
2150 d.style.position = "relative";
2153 r.coordsize = (/%$/.test(width) ? width : parseFloat(width)) + " " + (/%$/.test(height) ? height : parseFloat(height));
2154 r.coordorigin = "0 0";
2156 var b = createNode("rect"), bs = b.style;
2157 bs.left = bs.top = 0;
2158 bs.width = rs.width;
2159 bs.height = rs.height;
2160 b.filled = b.stroked = "f";
2165 if (container == 1) {
2166 doc.body.appendChild(d);
2167 cs.position = "absolute";
2179 cs.width = container.style.width = width;
2180 cs.height = container.style.height = height;
2181 if (container.firstChild) {
2182 container.insertBefore(d, container.firstChild);
2184 container.appendChild(d);
2187 for (var prop in paper) {
2188 container[prop] = paper[prop];
2190 plugins.call(container, container, R.fn);
2191 container.clear = function () {
2193 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
2194 if (r.childNodes[i] != b) {
2195 todel.push(r.childNodes[i]);
2198 for (i = 0, ii = todel.length; i < ii; i++) {
2199 r.removeChild(todel[i]);
2202 container.raphael = R;
2205 paper.remove = function () {
2206 this.canvas.parentNode.parentNode.parentNode.removeChild(this.canvas.parentNode.parentNode);
2208 paper.safari = function () {};
2214 var addEvent = (function () {
2215 if (doc.addEventListener) {
2216 return function (obj, type, fn, element) {
2217 var f = function (e) {
2218 return fn.call(element, e);
2220 obj.addEventListener(type, f, false);
2221 return function () {
2222 obj.removeEventListener(type, f, false);
2226 } else if (doc.attachEvent) {
2227 return function (obj, type, fn, element) {
2228 var f = function (e) {
2229 return fn.call(element, e || win.event);
2231 obj.attachEvent("on" + type, f);
2232 var detacher = function () {
2233 obj.detachEvent("on" + type, f);
2236 if (type == "mouseover") {
2237 obj.attachEvent("onmouseenter", f);
2238 return function () {
2239 obj.detachEvent("onmouseenter", f);
2242 } else if (type == "mouseout") {
2243 obj.attachEvent("onmouseleave", f);
2244 return function () {
2245 obj.detachEvent("onmouseleave", f);
2253 for (var i = events.length; i--;) {
2254 (function (eventName) {
2255 Element.prototype[eventName] = function (fn) {
2256 if (typeof fn == "function") {
2257 this.events = this.events || {};
2258 this.events[eventName] = this.events[eventName] || {};
2259 this.events[eventName][fn] = this.events[eventName][fn] || [];
2260 this.events[eventName][fn].push(addEvent(this.shape || this.node, eventName, fn, this));
2264 Element.prototype["un" + eventName] = function (fn) {
2266 this.events[eventName] &&
2267 this.events[eventName][fn] &&
2268 this.events[eventName][fn].length &&
2269 this.events[eventName][fn].shift()() &&
2270 !this.events[eventName][fn].length &&
2271 delete this.events[eventName][fn];
2276 paper.circle = function (x, y, r) {
2277 return theCircle(this, x, y, r);
2279 paper.rect = function (x, y, w, h, r) {
2280 return theRect(this, x, y, w, h, r);
2282 paper.ellipse = function (x, y, rx, ry) {
2283 return theEllipse(this, x, y, rx, ry);
2285 paper.path = function (params, pathString) {
2286 return thePath(params, pathString, this);
2288 paper.image = function (src, x, y, w, h) {
2289 return theImage(this, src, x, y, w, h);
2291 paper.text = function (x, y, text) {
2292 return theText(this, x, y, text);
2294 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
2295 color = color || "#000";
2296 var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
2298 columnWidth = w / wv;
2299 for (var i = 1; i < hv; i++) {
2300 path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
2302 for (var i = 1; i < wv; i++) {
2303 path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
2305 return this.path({stroke: color, "stroke-width": 1}, path.join(","));
2307 paper.pathfinder = function (p, path) {
2309 M: function (x, y) {
2312 C: function (x1, y1, x2, y2, x3, y3) {
2313 this.curveTo(x1, y1, x2, y2, x3, y3);
2315 Q: function (x1, y1, x2, y2) {
2316 this.qcurveTo(x1, y1, x2, y2);
2318 T: function (x, y) {
2319 this.qcurveTo(x, y);
2321 S: function (x1, y1, x2, y2) {
2322 p.curveTo(x1, y1, x2, y2);
2324 L: function (x, y) {
2328 this.lineTo(x, this.last.y);
2331 this.lineTo(this.last.x, y);
2333 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2334 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2341 path = pathToAbsolute(path);
2342 for (var i = 0, ii = path.length; i < ii; i++) {
2343 var b = path[i].shift();
2344 commands[b].apply(p, path[i]);
2348 paper.set = function (itemsArray) {
2349 return new Set(itemsArray);
2351 paper.setSize = setSize;
2352 Element.prototype.stop = function () {
2353 clearTimeout(this.animation_in_progress);
2355 Element.prototype.scale = function (x, y, cx, cy) {
2356 if (x == null && y == null) {
2357 return {x: this._.sx, y: this._.sy, toString: function () { return this.x.toFixed(3) + " " + this.y.toFixed(3); }};
2361 var dx, dy, dcx, dcy, a = this.attrs;
2363 var bb = this.type == "path" ? pathDimensions(a.path) : this.getBBox(),
2364 rcx = bb.x + bb.width / 2,
2365 rcy = bb.y + bb.height / 2;
2366 cx = (+cx || cx == 0) ? cx : rcx;
2367 cy = (+cy || cy == 0) ? cy : rcy;
2368 var dirx = Math.round(x / Math.abs(x)),
2369 diry = Math.round(y / Math.abs(y)),
2370 s = this.node.style,
2371 ncx = cx + (rcx - cx) * x * dirx / this._.sx,
2372 ncy = cy + (rcy - cy) * y * diry / this._.sy;
2373 switch (this.type) {
2376 var neww = a.width * x * dirx / this._.sx,
2377 newh = a.height * y * diry / this._.sy,
2378 newx = ncx - neww / 2,
2379 newy = ncy - newh / 2;
2390 rx: a.rx * x / this._.sx,
2391 ry: a.ry * y / this._.sy,
2392 r: a.r * x / this._.sx,
2398 var path = pathToRelative(a.path),
2400 for (var i = 0, ii = path.length; i < ii; i++) {
2402 if (p[0].toUpperCase() == "M" && skip) {
2407 if (R.svg && p[0].toUpperCase() == "A") {
2408 p[path[i].length - 2] *= x / this._.sx;
2409 p[path[i].length - 1] *= y / this._.sy;
2410 p[1] *= x / this._.sx;
2411 p[2] *= y / this._.sy;
2412 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2414 for (var j = 1, jj = p.length; j < jj; j++) {
2415 p[j] *= (j % 2) ? x / this._.sx : y / this._.sy;
2419 var dim2 = pathDimensions(path),
2420 dx = ncx - dim2.x - dim2.width / 2,
2421 dy = ncy - dim2.y - dim2.height / 2;
2422 path = pathToRelative(path);
2426 this.attr({path: path.join(" ")});
2429 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2430 if (this.transformations) {
2431 this.transformations[2] = "scale(".concat(dirx, ",", diry, ")");
2432 this.node.setAttribute("transform", this.transformations.join(" "));
2433 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2434 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2435 this.attr({x: dx, y: dy});
2439 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=".concat(dirx,
2440 ", M12=0, M21=0, M22=", diry,
2441 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2442 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2445 if (this.transformations) {
2446 this.transformations[2] = "";
2447 this.node.setAttribute("transform", this.transformations.join(" "));
2451 this.node.filterMatrix = "";
2452 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2455 a.scale = [x, y, cx, cy].join(" ");
2461 Element.prototype.animate = function (params, ms, callback) {
2462 clearTimeout(this.animation_in_progress);
2467 for (var attr in params) {
2468 if (attr in availableAnimAttrs) {
2469 from[attr] = this.attr(attr);
2470 (typeof from[attr] == "undefined") && (from[attr] = availableAttrs[attr]);
2471 to[attr] = params[attr];
2472 switch (availableAnimAttrs[attr]) {
2474 diff[attr] = (to[attr] - from[attr]) / ms;
2477 from[attr] = R.getRGB(from[attr]);
2478 var toColour = R.getRGB(to[attr]);
2480 r: (toColour.r - from[attr].r) / ms,
2481 g: (toColour.g - from[attr].g) / ms,
2482 b: (toColour.b - from[attr].b) / ms
2486 var pathes = pathEqualiser(from[attr], to[attr]);
2487 from[attr] = pathes[0];
2488 to[attr] = pathes[1];
2490 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2491 diff[attr][i] = [0];
2492 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2493 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2498 var values = (params[attr] + "").split(separator),
2499 from2 = (from[attr] + "").split(separator);
2502 from[attr] = [0, 0];
2503 diff[attr] = [values[0] / ms, values[1] / ms];
2506 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2507 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2510 params[attr] = values;
2511 from[attr] = (from[attr] + "").split(separator);
2512 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2518 var start = +new Date,
2522 var time = new Date - start,
2526 for (var attr in from) {
2527 switch (availableAnimAttrs[attr]) {
2529 now = +from[attr] + time * diff[attr];
2533 Math.round(from[attr].r + time * diff[attr].r),
2534 Math.round(from[attr].g + time * diff[attr].g),
2535 Math.round(from[attr].b + time * diff[attr].b)
2540 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2541 now[i] = [from[attr][i][0]];
2542 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2543 now[i][j] = from[attr][i][j] + time * diff[attr][i][j];
2545 now[i] = now[i].join(" ");
2547 now = now.join(" ");
2552 var x = diff[attr][0] * (time - prev),
2553 y = diff[attr][1] * (time - prev);
2556 now = [x, y].join(" ");
2559 now = +from[attr][0] + time * diff[attr][0];
2560 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2563 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(" ");
2567 if (attr == "font-size") {
2568 set[attr] = now + "px";
2574 that.animation_in_progress = setTimeout(tick);
2577 (t.x || t.y) && that.translate(-t.x, -t.y);
2579 clearTimeout(that.animation_in_progress);
2581 (typeof callback == "function") && callback.call(that);
2587 Element.prototype.translate = function (x, y) {
2589 return {x: this._.tx, y: this._.ty};
2593 switch (this.type) {
2596 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
2601 this.attr({x: this.attrs.x + (+x), y: this.attrs.y + (+y)});
2604 var path = pathToRelative(this.attrs.path);
2607 this.attr({path: path.join(" ")});
2614 var Set = function (itemsArray) {
2616 this.length = (itemsArray && itemsArray.length) || 0;
2617 if (itemsArray && itemsArray.constructor == Array) {
2618 for (var i = itemsArray.length; i--;) {
2619 if (itemsArray[i].constructor == Element) {
2620 this.items[this.items.length] = itemsArray[i];
2625 Set.prototype.push = function (item) {
2626 if (item && item.constructor == Element) {
2627 var len = this.items.length;
2628 this.items[len] = item;
2634 Set.prototype.pull = function (id) {
2635 var res = this.items.splice(id, 1)[0];
2636 for (var j = id, jj = this.items.length; j < jj; j++) {
2637 this[j] = this[j + 1];
2639 delete this[jj + 1];
2643 for (var method in Element.prototype) {
2644 Set.prototype[method] = (function (methodname) {
2645 return function () {
2646 for (var i = this.items.length; i--;) {
2647 this.items[i][methodname].apply(this.items[i], arguments);
2653 Set.prototype.getBBox = function () {
2654 var x = [], y = [], w = [], h = [];
2655 for (var i = this.items.length; i--;) {
2656 var box = this.items[i].getBBox();
2659 w.push(box.x + box.width);
2660 h.push(box.y + box.height);
2662 x = Math.min.apply(Math, x);
2663 y = Math.min.apply(Math, y);
2667 width: Math.max.apply(Math, w) - x,
2668 height: Math.max.apply(Math, h) - y
2672 R.registerFont = function (font) {
2676 this.fonts = this.fonts || {};
2677 if (this.fonts[font.face["font-family"]]) {
2678 this.fonts[font.face["font-family"]].push(font);
2680 this.fonts[font.face["font-family"]] = [font];
2683 font.face["units-per-em"] = parseInt(font.face["units-per-em"], 10);
2685 for (var glyph in font.glyphs) {
2686 var path = font.glyphs[glyph];
2688 path.d = "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
2689 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
2695 paper.getFont = function (family, weight, style, stretch) {
2696 stretch = stretch || "normal";
2697 style = style || "normal";
2698 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
2699 var font = R.fonts[family];
2701 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, "") + "(\\s|$)", "i");
2702 for (var fontName in R.fonts) {
2703 if (name.test(fontName)) {
2704 font = R.fonts[fontName];
2711 for (var i = 0, ii = font.length; i < ii; i++) {
2713 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
2720 paper.print = function (x, y, string, font, size) {
2721 var out = this.set(),
2722 letters = (string + "").split(""),
2727 scale = (size || 16) / font.face["units-per-em"];
2728 for (var i = 0, ii = letters.length; i < ii; i++) {
2729 var prev = i && font.glyphs[letters[i - 1]] || {},
2730 curr = font.glyphs[letters[i]];
2731 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
2732 curr && curr.d && out.push(this.path({fill: "#000", stroke: "none"}, curr.d).translate(shift, 0));
2734 out.scale(scale, scale, 0, y).translate(x, (size || 16) / 2);
2739 R.ninja = function () {
2740 var r = window.Raphael;
2741 if (oldRaphael.was) {
2742 window.Raphael = oldRaphael.is;
2745 delete window.Raphael;
2747 window.Raphael = void(0);
2752 R.el = Element.prototype;