2 * Raphael 0.6.3 - 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.
7 var Raphael = (function (type) {
9 return r._create.apply(r, arguments);
13 var availableAttrs = {cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '16px "Arial"', "font-family": '"Arial"', "font-size": "16", gradient: 0, height: 0, opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, translation: "0 0", width: 0, x: 0, y: 0},
14 availableAnimAttrs = {cx: "number", cy: "number", fill: "colour", "fill-opacity": "number", "font-size": "number", height: "number", opacity: "number", path: "path", r: "number", rotation: "number", rx: "number", ry: "number", scale: "csv", stroke: "colour", "stroke-opacity": "number", "stroke-width": "number", translation: "csv", width: "number", x: "number", y: "number"},
18 var thePath = function (params, pathString, VML) {
19 var g = document.createElement("rvml:group"), gl = g.style;
20 gl.position = "absolute";
23 gl.width = VML.width + "px";
24 gl.height = VML.height + "px";
25 var el = document.createElement("rvml:shape"), ol = el.style;
26 ol.width = VML.width + "px";
27 ol.height = VML.height + "px";
29 if (params["class"]) {
30 el.className = params["class"];
32 el.coordsize = this.coordsize;
33 el.coordorigin = this.coordorigin;
35 VML.canvas.appendChild(g);
36 var p = new Element(el, g, VML);
40 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
42 p.absolutely = function () {
43 this.isAbsolute = true;
46 p.relatively = function () {
47 this.isAbsolute = false;
50 p.moveTo = function (x, y) {
51 var d = this.isAbsolute?"m":"t";
52 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
53 this.node.path = this.Path += d;
54 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
55 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
56 this.last.isAbsolute = this.isAbsolute;
57 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
60 p.lineTo = function (x, y) {
61 var d = this.isAbsolute?"l":"r";
62 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
63 this[0].path = this.Path += d;
64 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
65 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
66 this.last.isAbsolute = this.isAbsolute;
67 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
70 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
71 // for more information of where this math came from visit:
72 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
73 x2 = (this.isAbsolute ? 0 : this.last.x) + x2;
74 y2 = (this.isAbsolute ? 0 : this.last.y) + y2;
79 k = (large_arc_flag == sweep_flag ? -1 : 1) *
80 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
81 cx = k * rx * y / ry + (x1 + x2) / 2,
82 cy = k * -ry * x / rx + (y1 + y2) / 2,
83 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
84 left = Math.round(cx - rx),
85 top = Math.round(cy - ry);
86 d += [left, top, Math.round(left + rx * 2), Math.round(top + ry * 2), Math.round(x1), Math.round(y1), Math.round(parseFloat(x2, 10)), Math.round(parseFloat(y2, 10))].join(", ");
87 this.node.path = this.Path += d;
88 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2, 10);
89 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2, 10);
90 this.last.isAbsolute = this.isAbsolute;
91 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
94 p.cplineTo = function (x1, y1, w1) {
96 return this.lineTo(x1, y1);
98 var x = Math.round(Math.round(parseFloat(x1, 10) * 100) / 100),
99 y = Math.round(Math.round(parseFloat(y1, 10) * 100) / 100),
100 w = Math.round(Math.round(parseFloat(w1, 10) * 100) / 100),
101 d = this.isAbsolute ? "c" : "v",
102 attr = [Math.round(this.last.x) + w, Math.round(this.last.y), x - w, y, x, y],
103 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
104 d += attr.join(" ") + " ";
105 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
106 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
107 this.last.bx = attr[2];
108 this.last.by = attr[3];
109 this.node.path = this.Path += d;
110 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
114 p.curveTo = function () {
115 var d = this.isAbsolute ? "c" : "v";
116 if (arguments.length == 6) {
117 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
118 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
119 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4], 10);
120 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5], 10);
121 d += [Math.round(parseFloat(arguments[0], 10)),
122 Math.round(parseFloat(arguments[1], 10)),
123 Math.round(parseFloat(arguments[2], 10)),
124 Math.round(parseFloat(arguments[3], 10)),
125 Math.round(parseFloat(arguments[4], 10)),
126 Math.round(parseFloat(arguments[5], 10))].join(" ") + " ";
127 this.last.isAbsolute = this.isAbsolute;
128 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
130 if (arguments.length == 4) {
131 var bx = this.last.x * 2 - this.last.bx;
132 var by = this.last.y * 2 - this.last.by;
133 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
134 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
135 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
136 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
137 d += [Math.round(bx), Math.round(by),
138 Math.round(parseFloat(arguments[0], 10)),
139 Math.round(parseFloat(arguments[1], 10)),
140 Math.round(parseFloat(arguments[2], 10)),
141 Math.round(parseFloat(arguments[3], 10))].join(" ") + " ";
142 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
144 this.node.path = this.Path += d;
147 p.qcurveTo = function () {
149 if (arguments.length == 4) {
150 this.last.qx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
151 this.last.qy = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
152 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
153 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
154 d += [Math.round(this.last.qx),
155 Math.round(this.last.qy),
156 Math.round(this.last.x),
157 Math.round(this.last.y)].join(" ") + " ";
158 this.last.isAbsolute = this.isAbsolute;
159 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
161 if (arguments.length == 2) {
162 this.last.qx = this.last.x * 2 - this.last.qx;
163 this.last.qy = this.last.y * 2 - this.last.qy;
164 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
165 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
166 d += [Math.round(this.last.qx),
167 Math.round(this.last.qy),
168 Math.round(this.last.x),
169 Math.round(this.last.y)].join(" ") + " ";
170 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
172 this.node.path = this.Path += d;
173 this.path.push({type: "qcurve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
176 p.addRoundedCorner = function (r, dir) {
177 var R = .5522 * r, rollback = this.isAbsolute, o = this;
180 rollback = function () {
184 rollback = function () {};
190 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
193 o.curveTo(-R, 0, -r, r - R, -r, r);
200 o.curveTo(R, 0, r, -(r - R), r, -r);
203 o.curveTo(R, 0, r, r - R, r, r);
210 o.curveTo(0, -R, -(R - r), -r, r, -r);
213 o.curveTo(0, -R, R - r, -r, -r, -r);
220 o.curveTo(0, R, -(R - r), r, r, r);
223 o.curveTo(0, R, R - r, r, -r, r);
228 actions[dir.charAt(0)]()[dir.charAt(1)]();
232 p.andClose = function () {
233 this.node.path = (this.Path += "x e");
234 this.attrs.path += "z";
237 if (typeof pathString == "string") {
240 C.pathfinder(p, pathString);
243 setFillAndStroke(p, params);
244 if (params.gradient) {
245 addGrdientFill(p, params.gradient);
249 var setFillAndStroke = function (o, params) {
251 o.attrs = o.attrs || {};
252 for (var par in params) {
253 o.attrs[par] = params[par];
255 if (params.path && o.type == "path") {
258 C.pathfinder(o, params.path);
260 if (params.rotation != null) {
261 o.Group.style.rotation = params.rotation;
263 if (params.translation) {
264 var xy = params.translation.split(/[, ]+/);
265 o.translate(xy[0], xy[1]);
268 var xy = params.scale.split(/[, ]+/);
269 o.scale(xy[0], xy[1]);
271 if (o.type == "image" && params.opacity) {
272 o.node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
273 o.node.style.filter = (o.node.filterMatrix || "") + (o.node.filterOpacity || "");
275 params["font-family"] && (s.fontFamily = params["font-family"]);
276 params["font-size"] && (s.fontSize = params["font-size"]);
277 params["font"] && (s.font = params["font"]);
278 params["font-weight"] && (s.fontWeight = params["font-weight"]);
279 if (typeof params.opacity != "undefined" || typeof params["stroke-width"] != "undefined" || typeof params.fill != "undefined" || typeof params.stroke != "undefined") {
280 o = o.shape || o.node;
281 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || document.createElement("rvml:fill");
282 if ("fill-opacity" in params || "opacity" in params) {
283 fill.opacity = ((params["fill-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
288 if (fill.on == undefined || params.fill == "none") {
291 if (fill.on && params.fill) {
292 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
297 fill.color = params.fill;
303 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || document.createElement("rvml:stroke");
304 if ((params.stroke && params.stroke != "none") || params["stroke-width"] || params["stroke-opacity"] || params["stroke-dasharray"]) {
307 if (params.stroke == "none" || typeof stroke.on == "undefined") {
310 if (stroke.on && params.stroke) {
311 stroke.color = params.stroke;
313 stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
314 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
315 stroke.miterlimit = params["stroke-miterlimit"] || 8;
316 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
317 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"], 10) || 1) * 12 / 16);
318 if (params["stroke-dasharray"]) {
322 "-.": "shortdashdot",
323 "-..": "shortdashdotdot",
328 "--.": "longdashdot",
329 "--..": "longdashdotdot"
331 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
333 o.appendChild(stroke);
336 var addGrdientFill = function (o, gradient) {
337 o.attrs = o.attrs || {};
338 o.attrs.gradient = gradient;
340 var fill = o.getElementsByTagName("fill");
344 fill = document.createElement("rvml:fill");
346 if (gradient.dots.length) {
348 fill.method = "none";
349 fill.type = (gradient.type.toLowerCase() == "linear") ? "gradient" : "gradientTitle";
350 if (typeof gradient.dots[0].color != "undefined") {
351 fill.color = gradient.dots[0].color || "#000";
353 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
354 fill.color2 = gradient.dots[gradient.dots.length - 1].color || "#000";
357 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
358 if (gradient.dots[i].offset) {
359 colors.push(gradient.dots[i].offset + " " + gradient.dots[i].color);
362 var fillOpacity = gradient.dots[0].opacity || 1;
363 var fillOpacity2 = gradient.dots[gradient.dots.length - 1].opacity || 1;
365 fill.colors.value = colors.join(",");
366 fillOpacity2 += fillOpacity;
367 fillOpacity = fillOpacity2 - fillOpacity;
368 fillOpacity2 -= fillOpacity;
370 fill.setAttribute("opacity", fillOpacity);
371 fill.setAttribute("opacity2", fillOpacity2);
372 if (gradient.vector) {
373 var angle = Math.round(Math.atan((parseFloat(gradient.vector[3], 10) - parseFloat(gradient.vector[1], 10)) / (parseFloat(gradient.vector[2], 10) - parseFloat(gradient.vector[0], 10))) * 57.29) || 0;
374 fill.angle = 270 - angle;
376 if (gradient.type.toLowerCase() == "radial") {
378 fill.focusposition = "0.5 0.5";
382 var Element = function (node, group, vml) {
402 Element.prototype.rotate = function (deg, isAbsolute) {
403 if (deg == undefined) {
411 this.Group.style.rotation = this._.rt;
414 Element.prototype.setBox = function (params) {
415 var gs = this.Group.style,
417 for (var i in params) {
418 this.attrs[i] = params[i];
420 var attr = this.attrs, x, y, w, h;
423 x = attr.cx - attr.r;
424 y = attr.cy - attr.r;
428 x = attr.cx - attr.rx;
429 y = attr.cy - attr.ry;
438 h = attr.height || 0;
441 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("");
444 if (!this.attrs.path) {
450 var dim = Raphael.pathDimensions(this.attrs.path),
464 if (this.type == "path") {
465 var left = Math.round(this.vml.width / 2 - w / 2 - x),
466 top = Math.round(this.vml.height / 2 - h / 2 - y);
467 gs.left = - left + "px";
468 gs.top = - top + "px";
474 os.left = left + "px";
476 var left = this.vml.width / 2 - w / 2,
477 top = this.vml.height / 2 - h / 2;
478 gs.position = "absolute";
479 gs.left = x - left + "px";
480 gs.top = y - top + "px";
485 gs.width = this.vml.width + "px";
486 gs.height = this.vml.height + "px";
487 os.position = "absolute";
489 os.left = left + "px";
491 os.height = h + "px";
494 Element.prototype.hide = function () {
495 this.Group.style.display = "none";
498 Element.prototype.show = function () {
499 this.Group.style.display = "block";
502 Element.prototype.translate = function (x, y) {
503 if (x == undefined && y == undefined) {
504 return {x: this._.tx, y: this._.ty};
508 if (this.type == "path") {
509 var path = this.attrs.path;
510 path = Raphael.pathToRelative(path);
513 this.attr({path: path.join(" ")});
515 this.setBox({x: this._.tx, y: this._.ty});
518 Element.prototype.getBBox = function () {
526 Element.prototype.remove = function () {
527 this[0].parentNode.removeChild(this[0]);
528 this.Group.parentNode.removeChild(this.Group);
529 this.shape && this.shape.parentNode.removeChild(this.shape);
531 Element.prototype.attr = function () {
532 if (arguments.length == 1 && typeof arguments[0] == "string") {
533 if (arguments[0] == "translation") {
534 return this.translate();
536 return this.attrs[arguments[0]];
538 if (this.attrs && arguments.length == 1 && arguments[0] instanceof Array) {
540 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
541 values[arguments[0][i]] = this.attrs[arguments[0][i]];
545 if (this[0].tagName.toLowerCase() == "group") {
546 var children = this[0].childNodes;
547 this.attrs = this.attrs || {};
548 if (arguments.length == 2) {
549 this.attrs[arguments[0]] = arguments[1];
550 } else if (arguments.length == 1 || typeof arguments[0] == "object") {
551 for (var j in arguments[0]) {
552 this.attrs[j] = arguments[0][j];
555 for (var i = 0, ii = children.length; i < ii; i++) {
556 this.attr.apply(new item(children[i], this[0], this.vml), arguments);
560 if (arguments.length == 2) {
562 params[arguments[0]] = arguments[1];
564 if (arguments.length == 1 && typeof arguments[0] == "object") {
565 params = arguments[0];
568 setFillAndStroke(this, params);
570 if (params.gradient) {
571 addGrdientFill(this, params.gradient);
573 if (params.text && this.type == "text") {
574 this[0].string = params.text;
577 this[0].id = params.id;
583 Element.prototype.toFront = function () {
584 this.Group.parentNode.appendChild(this.Group);
587 Element.prototype.toBack = function () {
588 if (this.Group.parentNode.firstChild != this.Group) {
589 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
593 var theCircle = function (vml, x, y, r) {
594 var g = document.createElement("rvml:group");
595 var o = document.createElement("rvml:oval");
597 vml.canvas.appendChild(g);
598 var res = new Element(o, g, vml);
599 setFillAndStroke(res, {stroke: "#000", fill: "none"});
600 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
607 var theRect = function (vml, x, y, w, h, r) {
608 var g = document.createElement("rvml:group");
609 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect");
611 o.arcsize = r / (Math.min(w, h));
614 vml.canvas.appendChild(g);
615 var res = new Element(o, g, vml);
616 setFillAndStroke(res, {stroke: "#000"});
617 res.setBox({x: x, y: y, width: w, height: h});
626 var theEllipse = function (vml, x, y, rx, ry) {
627 var g = document.createElement("rvml:group");
628 var o = document.createElement("rvml:oval");
630 vml.canvas.appendChild(g);
631 var res = new Element(o, g, vml);
632 setFillAndStroke(res, {stroke: "#000"});
633 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
638 res.type = "ellipse";
641 var theImage = function (vml, src, x, y, w, h) {
642 var g = document.createElement("rvml:group");
643 var o = document.createElement("rvml:image");
646 vml.canvas.appendChild(g);
647 var res = new Element(o, g, vml);
649 res.setBox({x: x, y: y, width: w, height: h});
656 var theText = function (vml, x, y, text) {
658 var g = document.createElement("rvml:group"), gs = g.style;
659 var el = document.createElement("rvml:shape"), ol = el.style;
660 var path = document.createElement("rvml:path"), ps = path.style;
661 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
662 path.textpathok = true;
663 ol.width = vml.width;
664 ol.height = vml.height;
665 gs.position = "absolute";
668 gs.width = vml.width;
669 gs.height = vml.height;
670 var o = document.createElement("rvml:textpath");
673 o.coordsize = vml.coordsize;
674 o.coordorigin = vml.coordorigin;
676 el.appendChild(path);
678 vml.canvas.appendChild(g);
679 var res = new Element(o, g, vml);
687 setFillAndStroke(res, {stroke: "none", fill: "#000"});
690 var theGroup = function (vml) {
691 var el = document.createElement("rvml:group"), els = el.style;
692 els.position = "absolute";
695 els.width = vml.width;
696 els.height = vml.height;
698 vml.canvas.appendChild(el);
700 var res = new Element(el, el, vml);
702 if (f.charAt(0) != "_" && typeof vml[f] == "function") {
703 res[f] = (function (f) {
705 var e = vml[f].apply(vml, arguments);
706 el.appendChild(e[0].parentNode);
715 r._create = function () {
716 // container, width, height
717 // x, y, width, height
718 var container, width, height;
719 if (typeof arguments[0] == "string") {
720 container = document.getElementById(arguments[0]);
721 width = arguments[1];
722 height = arguments[2];
724 if (typeof arguments[0] == "object") {
725 container = arguments[0];
726 width = arguments[1];
727 height = arguments[2];
729 if (typeof arguments[0] == "number") {
733 width = arguments[2];
734 height = arguments[3];
737 throw new Error("VML container not found.");
739 if (!document.namespaces["rvml"]) {
740 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
741 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
743 var c = document.createElement("div"),
744 r = C.canvas = document.createElement("rvml:group"),
745 cs = c.style, rs = r.style;
748 width = width || "320px";
749 height = height || "200px";
750 cs.clip = "rect(0 " + width + " " + height + " 0)";
753 cs.position = "relative";
756 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
757 r.coordorigin = "0 0";
759 var b = document.createElement("rvml:rect"), bs = b.style;
760 bs.left = bs.top = 0;
762 bs.height = rs.height;
763 b.filled = b.stroked = "f";
767 if (container == 1) {
768 document.body.appendChild(c);
769 cs.position = "absolute";
781 cs.width = container.style.width = width;
782 cs.height = container.style.height = height;
783 if (container.firstChild) {
784 container.insertBefore(c, container.firstChild);
786 container.appendChild(c);
789 for (var prop in C) {
790 container[prop] = C[prop];
792 container.clear = function () {
794 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
795 if (r.childNodes[i] != b) {
796 todel.push(r.childNodes[i]);
799 for (i = 0, ii = todel.length; i < ii; i++) {
800 r.removeChild(todel[i]);
805 C.remove = function () {
806 C.canvas.parentNode.parentNode.removeChild(C.canvas.parentNode);
810 var thePath = function (params, pathString, SVG) {
811 var el = document.createElementNS(SVG.svgns, "path");
812 el.setAttribute("fill", "none");
814 SVG.canvas.appendChild(el);
816 var p = new Element(el, SVG);
819 p.last = {x: 0, y: 0, bx: 0, by: 0};
820 p.absolutely = function () {
821 this.isAbsolute = true;
824 p.relatively = function () {
825 this.isAbsolute = false;
828 p.moveTo = function (x, y) {
829 var d = this.isAbsolute?"M":"m";
830 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
831 var oldD = this[0].getAttribute("d") || "";
832 (oldD == "M0,0") && (oldD = "");
833 this[0].setAttribute("d", oldD + d);
834 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
835 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
836 this.attrs.path = oldD + d;
839 p.lineTo = function (x, y) {
840 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
841 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
842 var d = this.isAbsolute?"L":"l";
843 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
844 var oldD = this[0].getAttribute("d") || "";
845 this[0].setAttribute("d", oldD + d);
846 this.attrs.path = oldD + d;
849 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
850 var d = this.isAbsolute ? "A" : "a";
851 d += [parseFloat(rx, 10).toFixed(3), parseFloat(ry, 10).toFixed(3), 0, large_arc_flag, sweep_flag, parseFloat(x, 10).toFixed(3), parseFloat(y, 10).toFixed(3)].join(" ");
852 var oldD = this[0].getAttribute("d") || "";
853 this[0].setAttribute("d", oldD + d);
854 this.last.x = parseFloat(x, 10);
855 this.last.y = parseFloat(y, 10);
856 this.attrs.path = oldD + d;
859 p.cplineTo = function (x1, y1, w1) {
861 return this.lineTo(x1, y1);
864 var x = parseFloat(x1, 10);
865 var y = parseFloat(y1, 10);
866 var w = parseFloat(w1, 10);
867 var d = this.isAbsolute?"C":"c";
868 var attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
869 for (var i = 0, ii = attr.length; i < ii; i++) {
870 d += attr[i].toFixed(3) + " ";
872 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
873 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
874 this.last.bx = attr[2];
875 this.last.by = attr[3];
876 var oldD = this[0].getAttribute("d") || "";
877 this[0].setAttribute("d", oldD + d);
878 this.attrs.path = oldD + d;
882 p.curveTo = function () {
884 command = [0, 1, 2, 3, "s", 5, "c"];
886 var d = command[arguments.length];
887 if (this.isAbsolute) {
890 for (var i = 0, ii = arguments.length; i < ii; i++) {
891 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
893 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
894 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
895 this.last.bx = parseFloat(arguments[arguments.length - 4], 10);
896 this.last.by = parseFloat(arguments[arguments.length - 3], 10);
897 var oldD = this.node.getAttribute("d") || "";
898 this.node.setAttribute("d", oldD + d);
899 this.attrs.path = oldD + d;
902 p.qcurveTo = function () {
904 command = [0, 1, "t", 3, "q"];
906 var d = command[arguments.length];
907 if (this.isAbsolute) {
910 for (var i = 0, ii = arguments.length; i < ii; i++) {
911 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
913 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
914 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
915 if (arguments.length != 2) {
916 this.last.qx = parseFloat(arguments[arguments.length - 4], 10);
917 this.last.qy = parseFloat(arguments[arguments.length - 3], 10);
919 var oldD = this.node.getAttribute("d") || "";
920 this.node.setAttribute("d", oldD + d);
921 this.attrs.path = oldD + d;
924 p.addRoundedCorner = function (r, dir) {
925 var R = .5522 * r, rollback = this.isAbsolute, o = this;
928 rollback = function () {
932 rollback = function () {};
938 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
941 o.curveTo(-R, 0, -r, r - R, -r, r);
948 o.curveTo(R, 0, r, -(r - R), r, -r);
951 o.curveTo(R, 0, r, r - R, r, r);
958 o.curveTo(0, -R, -(R - r), -r, r, -r);
961 o.curveTo(0, -R, R - r, -r, -r, -r);
968 o.curveTo(0, R, -(R - r), r, r, r);
971 o.curveTo(0, R, R - r, r, -r, r);
976 actions[dir[0]]()[dir[1]]();
980 p.andClose = function () {
981 var oldD = this[0].getAttribute("d") || "";
982 this[0].setAttribute("d", oldD + "Z ");
983 this.attrs.path = oldD + "Z ";
986 if (typeof pathString == "string") {
987 p.attrs.path = pathString;
989 C.pathfinder(p, pathString);
992 setFillAndStroke(p, params);
996 var addGrdientFill = function (o, gradient, SVG) {
997 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
998 el.id = "raphael-gradient-" + SVG.gradients++;
999 if (gradient.vector && gradient.vector.length) {
1000 el.setAttribute("x1", gradient.vector[0]);
1001 el.setAttribute("y1", gradient.vector[1]);
1002 el.setAttribute("x2", gradient.vector[2]);
1003 el.setAttribute("y2", gradient.vector[3]);
1005 SVG.defs.appendChild(el);
1006 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1007 var stop = document.createElementNS(SVG.svgns, "stop");
1008 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
1009 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
1010 if (typeof gradient.dots[i].opacity != "undefined") {
1011 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
1013 el.appendChild(stop);
1015 o.setAttribute("fill", "url(#" + el.id + ")");
1017 var updatePosition = function (o) {
1019 var bbox = o.node.getBBox();
1020 o.pattern.setAttribute("patternTransform", "translate(" + [bbox.x, bbox.y].join(",") + ")");
1023 var setFillAndStroke = function (o, params) {
1028 "-..": [3, 1, 1, 1, 1, 1],
1032 "- .": [4, 3, 1, 3],
1033 "--.": [8, 3, 1, 3],
1034 "--..": [8, 3, 1, 3, 1, 3]
1036 addDashes = function (o, value) {
1037 value = dasharray[value.toString().toLowerCase()];
1039 var width = o.attrs["stroke-width"] || "1",
1040 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
1042 for (var i = 0, ii = value.length; i < ii; i++) {
1043 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
1045 value = dashes.join(",");
1046 o.node.setAttribute("stroke-dasharray", value);
1049 for (var att in params) {
1050 var value = params[att];
1051 o.attrs[att] = value;
1054 if (o.type == "path") {
1055 o.node.setAttribute("d", "M0,0");
1056 C.pathfinder(o, value);
1061 o.node.setAttribute(att, value);
1067 o.node.setAttribute(att, value);
1071 o.node.setAttribute(att, value);
1074 o.node.setAttribute(att, value);
1077 addGrdientFill(o.node, value, o.svg);
1079 case "stroke-width":
1080 o.node.style.strokeWidth = value;
1081 // Need following line for Firefox
1082 o.node.setAttribute(att, value);
1083 if (o.attrs["stroke-dasharray"]) {
1084 addDashes(o, o.attrs["stroke-dasharray"]);
1087 case "stroke-dasharray":
1088 addDashes(o, value);
1091 if (o.type == "text") {
1092 o.node.childNodes.length && o.node.removeChild(o.node.firstChild);
1093 o.node.appendChild(document.createTextNode(value));
1097 o.rotate(value, true);
1100 var xy = value.split(/[, ]+/);
1101 o.translate(xy[0], xy[1]);
1104 var xy = value.split(/[, ]+/);
1105 o.scale(xy[0], xy[1]);
1108 var isURL = value.match(/^url\(([^\)]+)\)$/i);
1110 var el = document.createElementNS(o.svg.svgns, "pattern");
1111 var ig = document.createElementNS(o.svg.svgns, "image");
1112 el.id = "raphael-pattern-" + o.svg.gradients++;
1113 el.setAttribute("x", 0);
1114 el.setAttribute("y", 0);
1115 el.setAttribute("patternUnits", "userSpaceOnUse");
1116 ig.setAttribute("x", 0);
1117 ig.setAttribute("y", 0);
1118 ig.setAttributeNS(o.svg.xlink, "href", isURL[1]);
1121 var img = document.createElement("img");
1122 img.style.position = "absolute";
1123 img.style.top = "-9999em";
1124 img.style.left = "-9999em";
1125 img.onload = function () {
1126 el.setAttribute("width", this.offsetWidth);
1127 el.setAttribute("height", this.offsetHeight);
1128 ig.setAttribute("width", this.offsetWidth);
1129 ig.setAttribute("height", this.offsetHeight);
1130 document.body.removeChild(this);
1133 document.body.appendChild(img);
1135 o.svg.defs.appendChild(el);
1136 o.node.style.fill = "url(#" + el.id + ")";
1137 o.node.setAttribute("fill", "url(#" + el.id + ")");
1143 var cssrule = att.replace(/(\-.)/g, function (w) {
1144 return w.substring(1).toUpperCase();
1146 o.node.style[cssrule] = value;
1147 // Need following line for Firefox
1148 o.node.setAttribute(att, value);
1153 var Element = function (node, svg) {
1159 this.attrs = this.attrs || {};
1160 this.transformations = []; // rotate, translate, scale
1164 rt: {deg: 0, x: 0, y: 0},
1169 Element.prototype.translate = function (x, y) {
1170 if (x == undefined && y == undefined) {
1171 return {x: this._.tx, y: this._.ty};
1175 switch (this.type) {
1178 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
1183 this.attr({x: this.attrs.x + x, y: this.attrs.y + y});
1186 var path = Raphael.pathToRelative(this.attrs.path);
1189 this.attr({path: path.join(" ")});
1194 Element.prototype.rotate = function (deg, isAbsolute) {
1195 if (deg == undefined) {
1196 return this._.rt.deg;
1198 var bbox = this.getBBox();
1200 this._.rt.deg = deg;
1202 this._.rt.deg += deg;
1205 if (this._.rt.deg) {
1206 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
1208 this.transformations[0] = "";
1210 this.node.setAttribute("transform", this.transformations.join(" "));
1213 Element.prototype.hide = function () {
1214 this.node.style.display = "none";
1217 Element.prototype.show = function () {
1218 this.node.style.display = "block";
1221 Element.prototype.remove = function () {
1222 this.node.parentNode.removeChild(this.node);
1224 Element.prototype.getBBox = function () {
1225 return this.node.getBBox();
1227 Element.prototype.attr = function () {
1228 if (arguments.length == 1 && typeof arguments[0] == "string") {
1229 if (arguments[0] == "translation") {
1230 return this.translate();
1232 return this.attrs[arguments[0]];
1234 if (arguments.length == 1 && arguments[0] instanceof Array) {
1236 for (var j in arguments[0]) {
1237 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1241 if (arguments.length == 2) {
1243 params[arguments[0]] = arguments[1];
1244 setFillAndStroke(this, params);
1245 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1246 setFillAndStroke(this, arguments[0]);
1250 Element.prototype.toFront = function () {
1251 this.node.parentNode.appendChild(this.node);
1254 Element.prototype.toBack = function () {
1255 if (this.node.parentNode.firstChild != this.node) {
1256 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1260 var theCircle = function (svg, x, y, r) {
1261 var el = document.createElementNS(svg.svgns, "circle");
1262 el.setAttribute("cx", x);
1263 el.setAttribute("cy", y);
1264 el.setAttribute("r", r);
1265 el.setAttribute("fill", "none");
1266 el.setAttribute("stroke", "#000");
1268 svg.canvas.appendChild(el);
1270 var res = new Element(el, svg);
1271 res.attrs = res.attrs || {};
1275 res.attrs.stroke = "#000";
1276 res.type = "circle";
1279 var theRect = function (svg, x, y, w, h, r) {
1280 var el = document.createElementNS(svg.svgns, "rect");
1281 el.setAttribute("x", x);
1282 el.setAttribute("y", y);
1283 el.setAttribute("width", w);
1284 el.setAttribute("height", h);
1286 el.setAttribute("rx", r);
1287 el.setAttribute("ry", r);
1289 el.setAttribute("fill", "none");
1290 el.setAttribute("stroke", "#000");
1292 svg.canvas.appendChild(el);
1294 var res = new Element(el, svg);
1295 res.attrs = res.attrs || {};
1298 res.attrs.width = w;
1299 res.attrs.height = h;
1300 res.attrs.stroke = "#000";
1302 res.attrs.rx = res.attrs.ry = r;
1307 var theEllipse = function (svg, x, y, rx, ry) {
1308 var el = document.createElementNS(svg.svgns, "ellipse");
1309 el.setAttribute("cx", x);
1310 el.setAttribute("cy", y);
1311 el.setAttribute("rx", rx);
1312 el.setAttribute("ry", ry);
1313 el.setAttribute("fill", "none");
1314 el.setAttribute("stroke", "#000");
1316 svg.canvas.appendChild(el);
1318 var res = new Element(el, svg);
1319 res.attrs = res.attrs || {};
1324 res.attrs.stroke = "#000";
1325 res.type = "ellipse";
1328 var theImage = function (svg, src, x, y, w, h) {
1329 var el = document.createElementNS(svg.svgns, "image");
1330 el.setAttribute("x", x);
1331 el.setAttribute("y", y);
1332 el.setAttribute("width", w);
1333 el.setAttribute("height", h);
1334 el.setAttribute("preserveAspectRatio", "none");
1335 el.setAttributeNS(svg.xlink, "href", src);
1337 svg.canvas.appendChild(el);
1339 var res = new Element(el, svg);
1340 res.attrs = res.attrs || {};
1343 res.attrs.width = w;
1344 res.attrs.height = h;
1348 var theText = function (svg, x, y, text) {
1349 var el = document.createElementNS(svg.svgns, "text");
1350 el.setAttribute("x", x);
1351 el.setAttribute("y", y);
1352 el.setAttribute("text-anchor", "middle");
1353 el.setAttribute("fill", "#000");
1355 el.appendChild(document.createTextNode(text));
1358 svg.canvas.appendChild(el);
1360 var res = new Element(el, svg);
1361 res.attrs = res.attrs || {};
1364 res.attrs.fill = "#000";
1368 var theGroup = function (svg) {
1369 var el = document.createElementNS(svg.svgns, "g");
1371 svg.canvas.appendChild(el);
1373 var i = new Element(el, svg);
1374 for (var f in svg) {
1375 if (f[0] != "_" && typeof svg[f] == "function") {
1376 i[f] = (function (f) {
1377 return function () {
1378 var e = svg[f].apply(svg, arguments);
1379 el.appendChild(e[0]);
1388 r._create = function () {
1389 // container, width, height
1390 // x, y, width, height
1391 if (typeof arguments[0] == "string") {
1392 var container = document.getElementById(arguments[0]);
1393 var width = arguments[1];
1394 var height = arguments[2];
1396 if (typeof arguments[0] == "object") {
1397 var container = arguments[0];
1398 var width = arguments[1];
1399 var height = arguments[2];
1401 if (typeof arguments[0] == "number") {
1405 width = arguments[2],
1406 height = arguments[3];
1409 throw new Error("SVG container not found.");
1411 C.canvas = document.createElementNS(C.svgns, "svg");
1412 C.canvas.setAttribute("width", width || 320);
1413 C.width = width || 320;
1414 C.canvas.setAttribute("height", height || 200);
1415 C.height = height || 200;
1416 if (container == 1) {
1417 document.body.appendChild(C.canvas);
1418 C.canvas.style.position = "absolute";
1419 C.canvas.style.left = x + "px";
1420 C.canvas.style.top = y + "px";
1422 if (container.firstChild) {
1423 container.insertBefore(C.canvas, container.firstChild);
1425 container.appendChild(C.canvas);
1430 clear: function () {
1431 while (this.canvas.firstChild) {
1432 this.canvas.removeChild(this.canvas.firstChild);
1434 this.defs = document.createElementNS(C.svgns, "defs");
1436 this.canvas.appendChild(this.defs);
1439 for (var prop in C) {
1440 if (prop != "create") {
1441 container[prop] = C[prop];
1447 C.remove = function () {
1448 C.canvas.parentNode.removeChild(C.canvas);
1450 C.svgns = "http://www.w3.org/2000/svg";
1451 C.xlink = "http://www.w3.org/1999/xlink";
1453 if (type == "VML" || type == "SVG") {
1454 C.circle = function (x, y, r) {
1455 return theCircle(this, x, y, r);
1457 C.rect = function (x, y, w, h, r) {
1458 return theRect(this, x, y, w, h, r);
1460 C.ellipse = function (x, y, rx, ry) {
1461 return theEllipse(this, x, y, rx, ry);
1463 C.path = function (params, pathString) {
1464 return thePath(params, pathString, this);
1466 C.image = function (src, x, y, w, h) {
1467 return theImage(this, src, x, y, w, h);
1469 C.text = function (x, y, text) {
1470 return theText(this, x, y, text);
1472 C.group = function () {
1473 return theGroup(this);
1475 C.drawGrid = function (x, y, w, h, wv, hv, color) {
1476 color = color || "#000";
1477 var p = this.path({stroke: color, "stroke-width": 1})
1478 .moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).lineTo(x, y),
1480 columnWidth = w / wv;
1481 for (var i = 1; i < hv; i++) {
1482 p.moveTo(x, y + i * rowHeight).lineTo(x + w, y + i * rowHeight);
1484 for (var i = 1; i < wv; i++) {
1485 p.moveTo(x + i * columnWidth, y).lineTo(x + i * columnWidth, y + h);
1489 C.safari = function () {
1490 if (r.type == "SVG") {
1491 var rect = C.rect(-C.width, -C.height, C.width * 3, C.height * 3).attr({stroke: "none"});
1492 setTimeout(function () {rect.remove();}, 0);
1495 Element.prototype.stop = function () {
1496 clearTimeout(this.animation_in_progress);
1498 Element.prototype.scale = function (x, y) {
1499 if (x == undefined && y == undefined) {
1500 return {x: this._.sx, y: this._.sy};
1504 if (x != 0 && !(x == 1 && y == 1)) {
1505 var dirx = Math.round(x / Math.abs(x)),
1506 diry = Math.round(y / Math.abs(y)),
1507 s = this.node.style;
1508 dx = this.attr("x");
1509 dy = this.attr("y");
1510 cx = this.attr("cx");
1511 cy = this.attr("cy");
1512 if (dirx != 1 || diry != 1) {
1513 if (this.transformations) {
1514 this.transformations[2] = "scale(" + [dirx, diry] + ")";
1515 this.node.setAttribute("transform", this.transformations.join(" "));
1516 dx = (dirx < 0) ? -this.attr("x") - this.attrs.width * x * dirx / this._.sx : this.attr("x");
1517 dy = (diry < 0) ? -this.attr("y") - this.attrs.height * y * diry / this._.sy : this.attr("y");
1518 cx = this.attr("cx") * dirx;
1519 cy = this.attr("cy") * diry;
1521 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=" + dirx +
1522 ", M12=0, M21=0, M22=" + diry +
1523 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')";
1524 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
1527 if (this.transformations) {
1528 this.transformations[2] = "";
1529 this.node.setAttribute("transform", this.transformations.join(" "));
1531 this.node.filterMatrix = "";
1532 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
1535 switch (this.type) {
1539 width: this.attrs.width * x * dirx / this._.sx,
1540 height: this.attrs.height * y * diry / this._.sy,
1548 rx: this.attrs.rx * x * dirx / this._.sx,
1549 ry: this.attrs.ry * y * diry / this._.sy,
1550 r: this.attrs.r * x * diry / this._.sx,
1556 var path = Raphael.pathToRelative(Raphael.parsePathString(this.attr("path"))),
1558 dim = Raphael.pathDimensions(this.attrs.path),
1559 dx = -dim.width * (x - 1) / 2,
1560 dy = -dim.height * (y - 1) / 2;
1561 for (var i = 0, ii = path.length; i < ii; i++) {
1562 if (path[i][0].toUpperCase() == "M" && skip) {
1567 if (path[i][0].toUpperCase() == "A") {
1568 path[i][path[i].length - 2] *= x * dirx;
1569 path[i][path[i].length - 1] *= y * diry;
1571 for (var j = 1, jj = path[i].length; j < jj; j++) {
1572 path[i][j] *= (j % 2) ? x * dirx / this._.sx : y * diry / this._.sy;
1576 var dim2 = Raphael.pathDimensions(path),
1577 dx = dim.x + dim.width / 2 - dim2.x - dim2.width / 2,
1578 dy = dim.y + dim.height / 2 - dim2.y - dim2.height / 2;
1579 path = Raphael.pathToRelative(path);
1583 this.attr({path: path.join(" ")});
1590 Element.prototype.animate = function (params, ms, callback) {
1591 clearTimeout(this.animation_in_progress);
1592 var from = {}, to = {}, diff = {}, t = {x: 0, y: 0};
1593 for (var attr in params) {
1594 if (attr in availableAnimAttrs) {
1595 from[attr] = this.attr(attr);
1596 if (typeof from[attr] == "undefined") {
1597 from[attr] = availableAttrs[attr];
1599 to[attr] = params[attr];
1600 switch (availableAnimAttrs[attr]) {
1602 diff[attr] = (to[attr] - from[attr]) / ms;
1605 from[attr] = Raphael.getRGB(from[attr]);
1606 var toColour = Raphael.getRGB(to[attr]);
1608 r: (toColour.r - from[attr].r) / ms,
1609 g: (toColour.g - from[attr].g) / ms,
1610 b: (toColour.b - from[attr].b) / ms
1614 var pathes = Raphael.pathEqualiser(from[attr], to[attr]);
1615 from[attr] = pathes[0];
1616 to[attr] = pathes[1];
1618 for (var i = 0, ii = from[attr].length; i < ii; i++) {
1619 diff[attr][i] = [0];
1620 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
1621 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
1626 var values = params[attr].split(/[, ]+/);
1627 if (attr == "translation") {
1628 from[attr] = [0, 0];
1629 diff[attr] = [values[0] / ms, values[1] / ms];
1631 from[attr] = from[attr].split(/[, ]+/);
1632 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][0]) / ms];
1638 var start = new Date(),
1642 var time = (new Date()).getTime() - start.getTime(),
1646 for (var attr in from) {
1647 switch (availableAnimAttrs[attr]) {
1649 now = +from[attr] + time * diff[attr];
1653 Math.round(from[attr].r + time * diff[attr].r),
1654 Math.round(from[attr].g + time * diff[attr].g),
1655 Math.round(from[attr].b + time * diff[attr].b)
1660 for (var i = 0, ii = from[attr].length; i < ii; i++) {
1661 now[i] = [from[attr][i][0]];
1662 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
1663 now[i][j] = from[attr][i][j] + time * diff[attr][i][j];
1665 now[i] = now[i].join(" ");
1667 now = now.join(" ");
1670 if (attr == "translation") {
1671 var x = diff[attr][0] * (time - prev),
1672 y = diff[attr][1] * (time - prev);
1675 now = [x, y].join(" ");
1677 now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1]].join(" ");
1681 if (attr == "font-size") {
1682 set[attr] = now + "px";
1688 that.animation_in_progress = setTimeout(arguments.callee, 0);
1692 that.translate(-t.x, -t.y);
1695 clearTimeout(that.animation_in_progress);
1697 (typeof callback == "function") && callback.call(that);
1703 Element.prototype.insertAfter = function (element) {
1704 if (element.node.nextSibling) {
1705 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1707 element.node.parentNode.appendChild(this.node);
1710 Element.prototype.insertBefore = function (element) {
1711 element.node.parentNode.insertBefore(this.node, element.node);
1714 C.pathfinder = function (p, path) {
1716 M: function (x, y) {
1719 C: function (x1, y1, x2, y2, x3, y3) {
1720 this.curveTo(x1, y1, x2, y2, x3, y3);
1722 Q: function (x1, y1, x2, y2) {
1723 this.qcurveTo(x1, y1, x2, y2);
1725 T: function (x, y) {
1726 this.qcurveTo(x, y);
1728 S: function (x1, y1, x2, y2) {
1729 p.curveTo(x1, y1, x2, y2);
1731 L: function (x, y) {
1735 this.lineTo(x, this.last.y);
1738 this.lineTo(this.last.x, y);
1740 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
1741 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
1748 path = Raphael.pathToAbsolute(path);
1749 for (var i = 0, ii = path.length; i < ii; i++) {
1750 var b = path[i].shift();
1751 commands[b].apply(p, path[i]);
1756 return function () {};
1758 })((!window.SVGAngle) ? "VML" : "SVG");
1761 Raphael.vml = !(Raphael.svg = (Raphael.type == "SVG"));
1762 if (Raphael.vml && window.CanvasRenderingContext2D) {
1763 Raphael.type = "Canvas only";
1764 Raphael.vml = Raphael.svg = false;
1766 Raphael.toString = function () {
1767 return "Your browser " + (this.vml ? "doesn't ": "") + "support" + (this.svg ? "s": "") +
1768 " SVG.\nYou are running " + unescape("Rapha%EBl%20") + this.version;
1770 // generic utilities
1771 Raphael.hsb2rgb = function (hue, saturation, brightness) {
1772 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
1780 if (brightness == 0) {
1781 return {r: 0, g: 0, b: 0, hex: "#000"};
1783 var i = Math.floor(hue * 6),
1785 p = brightness * (1 - saturation),
1786 q = brightness * (1 - (saturation * f)),
1787 t = brightness * (1 - (saturation * (1 - f)));
1789 function () {red = brightness; green = t; blue = p;},
1790 function () {red = q; green = brightness; blue = p;},
1791 function () {red = p; green = brightness; blue = t;},
1792 function () {red = p; green = q; blue = brightness;},
1793 function () {red = t; green = p; blue = brightness;},
1794 function () {red = brightness; green = p; blue = q;},
1795 function () {red = brightness; green = t; blue = p;}
1798 var rgb = {r: red, g: green, b: blue};
1802 var r = Math.round(red).toString(16);
1803 if (r.length == 1) {
1806 var g = Math.round(green).toString(16);
1807 if (g.length == 1) {
1810 var b = Math.round(blue).toString(16);
1811 if (b.length == 1) {
1814 rgb.hex = "#" + r + g + b;
1817 Raphael.rgb2hsb = function (red, green, blue) {
1818 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
1823 if (typeof red == "string" && red.charAt(0) == "#") {
1824 if (red.length == 4) {
1825 blue = parseInt(red.substring(3), 16);
1826 green = parseInt(red.substring(2, 3), 16);
1827 red = parseInt(red.substring(1, 2), 16);
1829 blue = parseInt(red.substring(5), 16);
1830 green = parseInt(red.substring(3, 5), 16);
1831 red = parseInt(red.substring(1, 3), 16);
1834 if (red > 1 || green > 1 || blue > 1) {
1839 var max = Math.max(red, green, blue),
1840 min = Math.min(red, green, blue),
1845 return {h: 0, s: 0, b: max};
1847 var delta = (max - min);
1848 saturation = delta / max;
1850 hue = (green - blue) / delta;
1851 } else if (green == max) {
1852 hue = 2 + ((blue - red) / delta);
1854 hue = 4 + ((red - green) / delta);
1864 return {h: hue, s: saturation, b: brightness};
1866 Raphael.getRGB = function (colour) {
1867 var red, green, blue,
1868 rgb = colour.match(/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*(\d+,\s*\d+,\s*\d+)\s*\)|rgb\(\s*(\d+%,\s*\d+%,\s*\d+%)\s*\)|hsb\(\s*(\d+,\s*\d+,\s*\d+)\s*\)|hsb\(\s*(\d+%,\s*\d+%,\s*\d+%)\s*\))\s*$/i);
1871 blue = parseInt(rgb[2].substring(5), 16);
1872 green = parseInt(rgb[2].substring(3, 5), 16);
1873 red = parseInt(rgb[2].substring(1, 3), 16);
1876 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
1877 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
1878 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
1881 rgb = rgb[4].split(/\s*,\s*/);
1882 red = parseInt(rgb[0], 10);
1883 green = parseInt(rgb[1], 10);
1884 blue = parseInt(rgb[2], 10);
1887 rgb = rgb[5].split(/\s*,\s*/);
1888 red = parseInt(rgb[0], 10) * 2.55;
1889 green = parseInt(rgb[1], 10) * 2.55;
1890 blue = parseInt(rgb[2], 10) * 2.55;
1893 rgb = rgb[6].split(/\s*,\s*/);
1894 red = parseInt(rgb[0], 10);
1895 green = parseInt(rgb[1], 10);
1896 blue = parseInt(rgb[2], 10);
1897 return this.hsb2rgb(red, green, blue);
1900 rgb = rgb[7].split(/\s*,\s*/);
1901 red = parseInt(rgb[0], 10) * 2.55;
1902 green = parseInt(rgb[1], 10) * 2.55;
1903 blue = parseInt(rgb[2], 10) * 2.55;
1904 return this.hsb2rgb(red, green, blue);
1906 var rgb = {r: red, g: green, b: blue};
1907 var r = Math.round(red).toString(16);
1908 (r.length == 1) && (r = "0" + r);
1909 var g = Math.round(green).toString(16);
1910 (g.length == 1) && (g = "0" + g);
1911 var b = Math.round(blue).toString(16);
1912 (b.length == 1) && (b = "0" + b);
1913 rgb.hex = "#" + r + g + b;
1917 Raphael.getColor = function (value) {
1918 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
1919 var rgb = this.hsb2rgb(start.h, start.s, start.b);
1925 arguments.callee.start = {h: 0, s: 1, b: start.b};
1930 Raphael.getColor.reset = function () {
1931 this.start = undefined;
1933 Raphael.parsePathString = function (pathString) {
1934 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0};
1936 pathString.replace(/([achlmqstvz])\s*((-?\d*\.?\d*\s*,?\s*)+)/ig, function (a, b, c) {
1937 var params = [], name = b.toLowerCase();
1938 c.replace(/(-?\d*\.?\d*)\s*,?\s*/ig, function (a, b) {
1939 b && params.push(+b);
1941 while (params.length >= paramCounts[name]) {
1942 data.push([b].concat(params.splice(0, paramCounts[name])));
1943 if (!paramCounts[name]) {
1950 Raphael.pathDimensions = function (path) {
1951 var pathArray = path;
1952 if (typeof path == "string") {
1953 pathArray = this.parsePathString(path);
1955 pathArray = this.pathToAbsolute(pathArray);
1956 var x = [], y = [], length = 0;
1957 for (var i = 0, ii = pathArray.length; i < ii; i++) {
1958 switch (pathArray[i][0]) {
1962 x.push(pathArray[i][pathArray[i].length - 2]);
1963 y.push(pathArray[i][pathArray[i].length - 1]);
1966 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
1968 x.push(pathArray[i][j]);
1970 y.push(pathArray[i][j]);
1975 var minx = Math.min.apply(Math, x),
1976 miny = Math.min.apply(Math, y);
1980 width: Math.max.apply(Math, x) - minx,
1981 height: Math.max.apply(Math, y) - miny,
1986 Raphael.pathToRelative = function (pathArray) {
1988 if (typeof pathArray == "string") {
1989 pathArray = this.parsePathString(pathArray);
1991 var x = 0, y = 0, start = 0;
1992 if (pathArray[0][0] == "M") {
1993 x = pathArray[0][1];
1994 y = pathArray[0][2];
1996 res.push(pathArray[0]);
1998 for (var i = start, ii = pathArray.length; i < ii; i++) {
2000 if (pathArray[i][0] != pathArray[i][0].toLowerCase()) {
2001 res[i][0] = pathArray[i][0].toLowerCase();
2002 switch (res[i][0]) {
2004 res[i][1] = pathArray[i][1];
2005 res[i][2] = pathArray[i][2];
2007 res[i][4] = pathArray[i][4];
2008 res[i][5] = pathArray[i][5];
2009 res[i][6] = +(pathArray[i][6] - x).toFixed(3);
2010 res[i][7] = +(pathArray[i][7] - y).toFixed(3);
2013 res[i][1] = +(pathArray[i][1] - y).toFixed(3);
2016 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
2017 res[i][j] = +(pathArray[i][j] - ((j % 2) ? x : y)).toFixed(3);
2021 res[i] = pathArray[i];
2023 switch (res[i][0]) {
2027 x += res[i][res[i].length - 1];
2030 y += res[i][res[i].length - 1];
2033 x += res[i][res[i].length - 2];
2034 y += res[i][res[i].length - 1];
2039 Raphael.pathToAbsolute = function (pathArray) {
2041 if (typeof pathArray == "string") {
2042 pathArray = this.parsePathString(pathArray);
2044 var x = 0, y = 0, start = 0;
2045 if (pathArray[0][0] == "M") {
2046 x = +pathArray[0][1];
2047 y = +pathArray[0][2];
2049 res[0] = pathArray[0];
2051 for (var i = start, ii = pathArray.length; i < ii; i++) {
2053 if (pathArray[i][0] != pathArray[i][0].toUpperCase()) {
2054 res[i][0] = pathArray[i][0].toUpperCase();
2055 switch (res[i][0]) {
2057 res[i][1] = pathArray[i][1];
2058 res[i][2] = pathArray[i][2];
2060 res[i][4] = pathArray[i][4];
2061 res[i][5] = pathArray[i][5];
2062 res[i][6] = +(pathArray[i][6] + x).toFixed(3);
2063 res[i][7] = +(pathArray[i][7] + y).toFixed(3);
2066 res[i][1] = +pathArray[i][1] + y;
2069 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
2070 res[i][j] = +pathArray[i][j] + ((j % 2) ? x : y);
2074 res[i] = pathArray[i];
2076 switch (res[i][0]) {
2086 x = res[i][res[i].length - 2];
2087 y = res[i][res[i].length - 1];
2092 Raphael.pathEqualiser = function (path1, path2) {
2093 var data = [this.pathToAbsolute(this.parsePathString(path1)), this.pathToAbsolute(this.parsePathString(path2))],
2094 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}],
2095 processPath = function (path, d) {
2105 var nx = d.x + (d.x - (d.bx || d.x));
2106 var ny = d.y + (d.y - (d.by || d.y));
2107 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
2110 var nx = d.x + (d.x - (d.bx || d.x));
2111 var ny = d.y + (d.y - (d.by || d.y));
2112 path = ["Q", nx, ny, path[1], path[2]];
2115 path = ["L", path[1], d.y];
2118 path = ["L", d.x, path[1]];
2121 path = ["L", d.X, d.Y];
2126 edgeCases = function (a, b, i) {
2127 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
2128 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
2129 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
2130 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
2131 attrs[a].x = data[a][i][data[a][i].length - 2];
2132 attrs[a].y = data[a][i][data[a][i].length - 1];
2134 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
2135 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]];
2136 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
2137 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
2138 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
2139 var x = data[b][i][data[b][i].length - 2];
2140 var y = data[b][i][data[b][i].length - 1];
2141 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
2142 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
2144 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
2145 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
2146 attrs[b].x = data[b][i][data[b][i].length - 2];
2147 attrs[b].y = data[b][i][data[b][i].length - 1];
2149 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
2150 var x = data[b][i][data[b][i].length - 2];
2151 var y = data[b][i][data[b][i].length - 1];
2152 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
2153 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
2155 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
2156 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
2157 attrs[b].x = data[b][i][data[b][i].length - 2];
2158 attrs[b].y = data[b][i][data[b][i].length - 1];
2160 } else if (data[a][i][0] == "U") {
2161 data[a][i][0] = data[b][i][0];
2162 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
2163 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
2168 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
2169 data[0][i] = processPath(data[0][i], attrs[0]);
2170 data[1][i] = processPath(data[1][i], attrs[1]);
2171 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
2174 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
2175 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
2176 attrs[0].x = data[0][i][data[0][i].length - 2];
2177 attrs[0].y = data[0][i][data[0][i].length - 1];
2178 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
2179 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
2180 attrs[1].x = data[1][i][data[1][i].length - 2];
2181 attrs[1].y = data[1][i][data[1][i].length - 1];