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 Element.prototype.insertAfter = function (element) {
594 if (element.Group.nextSibling) {
595 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
597 element.Group.parentNode.appendChild(this.Group);
601 Element.prototype.insertBefore = function (element) {
602 element.Group.parentNode.insertBefore(this.Group, element.Group);
605 var theCircle = function (vml, x, y, r) {
606 var g = document.createElement("rvml:group");
607 var o = document.createElement("rvml:oval");
609 vml.canvas.appendChild(g);
610 var res = new Element(o, g, vml);
611 setFillAndStroke(res, {stroke: "#000", fill: "none"});
612 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
619 var theRect = function (vml, x, y, w, h, r) {
620 var g = document.createElement("rvml:group");
621 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect");
623 o.arcsize = r / (Math.min(w, h));
626 vml.canvas.appendChild(g);
627 var res = new Element(o, g, vml);
628 setFillAndStroke(res, {stroke: "#000"});
629 res.setBox({x: x, y: y, width: w, height: h});
638 var theEllipse = function (vml, x, y, rx, ry) {
639 var g = document.createElement("rvml:group");
640 var o = document.createElement("rvml:oval");
642 vml.canvas.appendChild(g);
643 var res = new Element(o, g, vml);
644 setFillAndStroke(res, {stroke: "#000"});
645 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
650 res.type = "ellipse";
653 var theImage = function (vml, src, x, y, w, h) {
654 var g = document.createElement("rvml:group");
655 var o = document.createElement("rvml:image");
658 vml.canvas.appendChild(g);
659 var res = new Element(o, g, vml);
661 res.setBox({x: x, y: y, width: w, height: h});
668 var theText = function (vml, x, y, text) {
670 var g = document.createElement("rvml:group"), gs = g.style;
671 var el = document.createElement("rvml:shape"), ol = el.style;
672 var path = document.createElement("rvml:path"), ps = path.style;
673 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
674 path.textpathok = true;
675 ol.width = vml.width;
676 ol.height = vml.height;
677 gs.position = "absolute";
680 gs.width = vml.width;
681 gs.height = vml.height;
682 var o = document.createElement("rvml:textpath");
685 o.coordsize = vml.coordsize;
686 o.coordorigin = vml.coordorigin;
688 el.appendChild(path);
690 vml.canvas.appendChild(g);
691 var res = new Element(o, g, vml);
699 setFillAndStroke(res, {stroke: "none", fill: "#000"});
702 var theGroup = function (vml) {
703 var el = document.createElement("rvml:group"), els = el.style;
704 els.position = "absolute";
707 els.width = vml.width;
708 els.height = vml.height;
710 vml.canvas.appendChild(el);
712 var res = new Element(el, el, vml);
714 if (f.charAt(0) != "_" && typeof vml[f] == "function") {
715 res[f] = (function (f) {
717 var e = vml[f].apply(vml, arguments);
718 el.appendChild(e[0].parentNode);
727 r._create = function () {
728 // container, width, height
729 // x, y, width, height
730 var container, width, height;
731 if (typeof arguments[0] == "string") {
732 container = document.getElementById(arguments[0]);
733 width = arguments[1];
734 height = arguments[2];
736 if (typeof arguments[0] == "object") {
737 container = arguments[0];
738 width = arguments[1];
739 height = arguments[2];
741 if (typeof arguments[0] == "number") {
745 width = arguments[2];
746 height = arguments[3];
749 throw new Error("VML container not found.");
751 if (!document.namespaces["rvml"]) {
752 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
753 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
755 var c = document.createElement("div"),
756 r = C.canvas = document.createElement("rvml:group"),
757 cs = c.style, rs = r.style;
760 width = width || "320px";
761 height = height || "200px";
762 cs.clip = "rect(0 " + width + " " + height + " 0)";
765 cs.position = "relative";
768 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
769 r.coordorigin = "0 0";
771 var b = document.createElement("rvml:rect"), bs = b.style;
772 bs.left = bs.top = 0;
774 bs.height = rs.height;
775 b.filled = b.stroked = "f";
779 if (container == 1) {
780 document.body.appendChild(c);
781 cs.position = "absolute";
793 cs.width = container.style.width = width;
794 cs.height = container.style.height = height;
795 if (container.firstChild) {
796 container.insertBefore(c, container.firstChild);
798 container.appendChild(c);
801 for (var prop in C) {
802 container[prop] = C[prop];
804 container.clear = function () {
806 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
807 if (r.childNodes[i] != b) {
808 todel.push(r.childNodes[i]);
811 for (i = 0, ii = todel.length; i < ii; i++) {
812 r.removeChild(todel[i]);
817 C.remove = function () {
818 C.canvas.parentNode.parentNode.removeChild(C.canvas.parentNode);
822 var thePath = function (params, pathString, SVG) {
823 var el = document.createElementNS(SVG.svgns, "path");
824 el.setAttribute("fill", "none");
826 SVG.canvas.appendChild(el);
828 var p = new Element(el, SVG);
831 p.last = {x: 0, y: 0, bx: 0, by: 0};
832 p.absolutely = function () {
833 this.isAbsolute = true;
836 p.relatively = function () {
837 this.isAbsolute = false;
840 p.moveTo = function (x, y) {
841 var d = this.isAbsolute?"M":"m";
842 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
843 var oldD = this[0].getAttribute("d") || "";
844 (oldD == "M0,0") && (oldD = "");
845 this[0].setAttribute("d", oldD + d);
846 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
847 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
848 this.attrs.path = oldD + d;
851 p.lineTo = function (x, y) {
852 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
853 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
854 var d = this.isAbsolute?"L":"l";
855 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
856 var oldD = this[0].getAttribute("d") || "";
857 this[0].setAttribute("d", oldD + d);
858 this.attrs.path = oldD + d;
861 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
862 var d = this.isAbsolute ? "A" : "a";
863 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(" ");
864 var oldD = this[0].getAttribute("d") || "";
865 this[0].setAttribute("d", oldD + d);
866 this.last.x = parseFloat(x, 10);
867 this.last.y = parseFloat(y, 10);
868 this.attrs.path = oldD + d;
871 p.cplineTo = function (x1, y1, w1) {
873 return this.lineTo(x1, y1);
876 var x = parseFloat(x1, 10);
877 var y = parseFloat(y1, 10);
878 var w = parseFloat(w1, 10);
879 var d = this.isAbsolute?"C":"c";
880 var attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
881 for (var i = 0, ii = attr.length; i < ii; i++) {
882 d += attr[i].toFixed(3) + " ";
884 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
885 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
886 this.last.bx = attr[2];
887 this.last.by = attr[3];
888 var oldD = this[0].getAttribute("d") || "";
889 this[0].setAttribute("d", oldD + d);
890 this.attrs.path = oldD + d;
894 p.curveTo = function () {
896 command = [0, 1, 2, 3, "s", 5, "c"];
898 var d = command[arguments.length];
899 if (this.isAbsolute) {
902 for (var i = 0, ii = arguments.length; i < ii; i++) {
903 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
905 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
906 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
907 this.last.bx = parseFloat(arguments[arguments.length - 4], 10);
908 this.last.by = parseFloat(arguments[arguments.length - 3], 10);
909 var oldD = this.node.getAttribute("d") || "";
910 this.node.setAttribute("d", oldD + d);
911 this.attrs.path = oldD + d;
914 p.qcurveTo = function () {
916 command = [0, 1, "t", 3, "q"];
918 var d = command[arguments.length];
919 if (this.isAbsolute) {
922 for (var i = 0, ii = arguments.length; i < ii; i++) {
923 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
925 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
926 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
927 if (arguments.length != 2) {
928 this.last.qx = parseFloat(arguments[arguments.length - 4], 10);
929 this.last.qy = parseFloat(arguments[arguments.length - 3], 10);
931 var oldD = this.node.getAttribute("d") || "";
932 this.node.setAttribute("d", oldD + d);
933 this.attrs.path = oldD + d;
936 p.addRoundedCorner = function (r, dir) {
937 var R = .5522 * r, rollback = this.isAbsolute, o = this;
940 rollback = function () {
944 rollback = function () {};
950 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
953 o.curveTo(-R, 0, -r, r - R, -r, r);
960 o.curveTo(R, 0, r, -(r - R), r, -r);
963 o.curveTo(R, 0, r, r - R, r, r);
970 o.curveTo(0, -R, -(R - r), -r, r, -r);
973 o.curveTo(0, -R, R - r, -r, -r, -r);
980 o.curveTo(0, R, -(R - r), r, r, r);
983 o.curveTo(0, R, R - r, r, -r, r);
988 actions[dir[0]]()[dir[1]]();
992 p.andClose = function () {
993 var oldD = this[0].getAttribute("d") || "";
994 this[0].setAttribute("d", oldD + "Z ");
995 this.attrs.path = oldD + "Z ";
998 if (typeof pathString == "string") {
999 p.attrs.path = pathString;
1001 C.pathfinder(p, pathString);
1004 setFillAndStroke(p, params);
1008 var addGrdientFill = function (o, gradient, SVG) {
1009 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
1010 el.id = "raphael-gradient-" + SVG.gradients++;
1011 if (gradient.vector && gradient.vector.length) {
1012 el.setAttribute("x1", gradient.vector[0]);
1013 el.setAttribute("y1", gradient.vector[1]);
1014 el.setAttribute("x2", gradient.vector[2]);
1015 el.setAttribute("y2", gradient.vector[3]);
1017 SVG.defs.appendChild(el);
1018 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1019 var stop = document.createElementNS(SVG.svgns, "stop");
1020 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
1021 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
1022 if (typeof gradient.dots[i].opacity != "undefined") {
1023 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
1025 el.appendChild(stop);
1027 o.setAttribute("fill", "url(#" + el.id + ")");
1029 var updatePosition = function (o) {
1031 var bbox = o.node.getBBox();
1032 o.pattern.setAttribute("patternTransform", "translate(" + [bbox.x, bbox.y].join(",") + ")");
1035 var setFillAndStroke = function (o, params) {
1040 "-..": [3, 1, 1, 1, 1, 1],
1044 "- .": [4, 3, 1, 3],
1045 "--.": [8, 3, 1, 3],
1046 "--..": [8, 3, 1, 3, 1, 3]
1048 addDashes = function (o, value) {
1049 value = dasharray[value.toString().toLowerCase()];
1051 var width = o.attrs["stroke-width"] || "1",
1052 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
1054 for (var i = 0, ii = value.length; i < ii; i++) {
1055 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
1057 value = dashes.join(",");
1058 o.node.setAttribute("stroke-dasharray", value);
1061 for (var att in params) {
1062 var value = params[att];
1063 o.attrs[att] = value;
1066 if (o.type == "path") {
1067 o.node.setAttribute("d", "M0,0");
1068 C.pathfinder(o, value);
1073 o.node.setAttribute(att, value);
1079 o.node.setAttribute(att, value);
1083 o.node.setAttribute(att, value);
1086 o.node.setAttribute(att, value);
1089 addGrdientFill(o.node, value, o.svg);
1091 case "stroke-width":
1092 o.node.style.strokeWidth = value;
1093 // Need following line for Firefox
1094 o.node.setAttribute(att, value);
1095 if (o.attrs["stroke-dasharray"]) {
1096 addDashes(o, o.attrs["stroke-dasharray"]);
1099 case "stroke-dasharray":
1100 addDashes(o, value);
1103 if (o.type == "text") {
1104 o.node.childNodes.length && o.node.removeChild(o.node.firstChild);
1105 o.node.appendChild(document.createTextNode(value));
1109 o.rotate(value, true);
1112 var xy = value.split(/[, ]+/);
1113 o.translate(xy[0], xy[1]);
1116 var xy = value.split(/[, ]+/);
1117 o.scale(xy[0], xy[1]);
1120 var isURL = value.match(/^url\(([^\)]+)\)$/i);
1122 var el = document.createElementNS(o.svg.svgns, "pattern");
1123 var ig = document.createElementNS(o.svg.svgns, "image");
1124 el.id = "raphael-pattern-" + o.svg.gradients++;
1125 el.setAttribute("x", 0);
1126 el.setAttribute("y", 0);
1127 el.setAttribute("patternUnits", "userSpaceOnUse");
1128 ig.setAttribute("x", 0);
1129 ig.setAttribute("y", 0);
1130 ig.setAttributeNS(o.svg.xlink, "href", isURL[1]);
1133 var img = document.createElement("img");
1134 img.style.position = "absolute";
1135 img.style.top = "-9999em";
1136 img.style.left = "-9999em";
1137 img.onload = function () {
1138 el.setAttribute("width", this.offsetWidth);
1139 el.setAttribute("height", this.offsetHeight);
1140 ig.setAttribute("width", this.offsetWidth);
1141 ig.setAttribute("height", this.offsetHeight);
1142 document.body.removeChild(this);
1145 document.body.appendChild(img);
1147 o.svg.defs.appendChild(el);
1148 o.node.style.fill = "url(#" + el.id + ")";
1149 o.node.setAttribute("fill", "url(#" + el.id + ")");
1155 var cssrule = att.replace(/(\-.)/g, function (w) {
1156 return w.substring(1).toUpperCase();
1158 o.node.style[cssrule] = value;
1159 // Need following line for Firefox
1160 o.node.setAttribute(att, value);
1165 var Element = function (node, svg) {
1171 this.attrs = this.attrs || {};
1172 this.transformations = []; // rotate, translate, scale
1176 rt: {deg: 0, x: 0, y: 0},
1181 Element.prototype.translate = function (x, y) {
1182 if (x == undefined && y == undefined) {
1183 return {x: this._.tx, y: this._.ty};
1187 switch (this.type) {
1190 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
1195 this.attr({x: this.attrs.x + x, y: this.attrs.y + y});
1198 var path = Raphael.pathToRelative(this.attrs.path);
1201 this.attr({path: path.join(" ")});
1206 Element.prototype.rotate = function (deg, isAbsolute) {
1207 if (deg == undefined) {
1208 return this._.rt.deg;
1210 var bbox = this.getBBox();
1212 this._.rt.deg = deg;
1214 this._.rt.deg += deg;
1217 if (this._.rt.deg) {
1218 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
1220 this.transformations[0] = "";
1222 this.node.setAttribute("transform", this.transformations.join(" "));
1225 Element.prototype.hide = function () {
1226 this.node.style.display = "none";
1229 Element.prototype.show = function () {
1230 this.node.style.display = "block";
1233 Element.prototype.remove = function () {
1234 this.node.parentNode.removeChild(this.node);
1236 Element.prototype.getBBox = function () {
1237 return this.node.getBBox();
1239 Element.prototype.attr = function () {
1240 if (arguments.length == 1 && typeof arguments[0] == "string") {
1241 if (arguments[0] == "translation") {
1242 return this.translate();
1244 return this.attrs[arguments[0]];
1246 if (arguments.length == 1 && arguments[0] instanceof Array) {
1248 for (var j in arguments[0]) {
1249 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1253 if (arguments.length == 2) {
1255 params[arguments[0]] = arguments[1];
1256 setFillAndStroke(this, params);
1257 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1258 setFillAndStroke(this, arguments[0]);
1262 Element.prototype.toFront = function () {
1263 this.node.parentNode.appendChild(this.node);
1266 Element.prototype.toBack = function () {
1267 if (this.node.parentNode.firstChild != this.node) {
1268 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1272 Element.prototype.insertAfter = function (element) {
1273 if (element.node.nextSibling) {
1274 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1276 element.node.parentNode.appendChild(this.node);
1280 Element.prototype.insertBefore = function (element) {
1281 element.node.parentNode.insertBefore(this.node, element.node);
1284 var theCircle = function (svg, x, y, r) {
1285 var el = document.createElementNS(svg.svgns, "circle");
1286 el.setAttribute("cx", x);
1287 el.setAttribute("cy", y);
1288 el.setAttribute("r", 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 || {};
1299 res.attrs.stroke = "#000";
1300 res.type = "circle";
1303 var theRect = function (svg, x, y, w, h, r) {
1304 var el = document.createElementNS(svg.svgns, "rect");
1305 el.setAttribute("x", x);
1306 el.setAttribute("y", y);
1307 el.setAttribute("width", w);
1308 el.setAttribute("height", h);
1310 el.setAttribute("rx", r);
1311 el.setAttribute("ry", r);
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 || {};
1322 res.attrs.width = w;
1323 res.attrs.height = h;
1324 res.attrs.stroke = "#000";
1326 res.attrs.rx = res.attrs.ry = r;
1331 var theEllipse = function (svg, x, y, rx, ry) {
1332 var el = document.createElementNS(svg.svgns, "ellipse");
1333 el.setAttribute("cx", x);
1334 el.setAttribute("cy", y);
1335 el.setAttribute("rx", rx);
1336 el.setAttribute("ry", ry);
1337 el.setAttribute("fill", "none");
1338 el.setAttribute("stroke", "#000");
1340 svg.canvas.appendChild(el);
1342 var res = new Element(el, svg);
1343 res.attrs = res.attrs || {};
1348 res.attrs.stroke = "#000";
1349 res.type = "ellipse";
1352 var theImage = function (svg, src, x, y, w, h) {
1353 var el = document.createElementNS(svg.svgns, "image");
1354 el.setAttribute("x", x);
1355 el.setAttribute("y", y);
1356 el.setAttribute("width", w);
1357 el.setAttribute("height", h);
1358 el.setAttribute("preserveAspectRatio", "none");
1359 el.setAttributeNS(svg.xlink, "href", src);
1361 svg.canvas.appendChild(el);
1363 var res = new Element(el, svg);
1364 res.attrs = res.attrs || {};
1367 res.attrs.width = w;
1368 res.attrs.height = h;
1372 var theText = function (svg, x, y, text) {
1373 var el = document.createElementNS(svg.svgns, "text");
1374 el.setAttribute("x", x);
1375 el.setAttribute("y", y);
1376 el.setAttribute("text-anchor", "middle");
1377 el.setAttribute("fill", "#000");
1379 el.appendChild(document.createTextNode(text));
1382 svg.canvas.appendChild(el);
1384 var res = new Element(el, svg);
1385 res.attrs = res.attrs || {};
1388 res.attrs.fill = "#000";
1392 var theGroup = function (svg) {
1393 var el = document.createElementNS(svg.svgns, "g");
1395 svg.canvas.appendChild(el);
1397 var i = new Element(el, svg);
1398 for (var f in svg) {
1399 if (f[0] != "_" && typeof svg[f] == "function") {
1400 i[f] = (function (f) {
1401 return function () {
1402 var e = svg[f].apply(svg, arguments);
1403 el.appendChild(e[0]);
1412 r._create = function () {
1413 // container, width, height
1414 // x, y, width, height
1415 if (typeof arguments[0] == "string") {
1416 var container = document.getElementById(arguments[0]);
1417 var width = arguments[1];
1418 var height = arguments[2];
1420 if (typeof arguments[0] == "object") {
1421 var container = arguments[0];
1422 var width = arguments[1];
1423 var height = arguments[2];
1425 if (typeof arguments[0] == "number") {
1429 width = arguments[2],
1430 height = arguments[3];
1433 throw new Error("SVG container not found.");
1435 C.canvas = document.createElementNS(C.svgns, "svg");
1436 C.canvas.setAttribute("width", width || 320);
1437 C.width = width || 320;
1438 C.canvas.setAttribute("height", height || 200);
1439 C.height = height || 200;
1440 if (container == 1) {
1441 document.body.appendChild(C.canvas);
1442 C.canvas.style.position = "absolute";
1443 C.canvas.style.left = x + "px";
1444 C.canvas.style.top = y + "px";
1446 if (container.firstChild) {
1447 container.insertBefore(C.canvas, container.firstChild);
1449 container.appendChild(C.canvas);
1454 clear: function () {
1455 while (this.canvas.firstChild) {
1456 this.canvas.removeChild(this.canvas.firstChild);
1458 this.defs = document.createElementNS(C.svgns, "defs");
1460 this.canvas.appendChild(this.defs);
1463 for (var prop in C) {
1464 if (prop != "create") {
1465 container[prop] = C[prop];
1471 C.remove = function () {
1472 C.canvas.parentNode.removeChild(C.canvas);
1474 C.svgns = "http://www.w3.org/2000/svg";
1475 C.xlink = "http://www.w3.org/1999/xlink";
1477 if (type == "VML" || type == "SVG") {
1478 C.circle = function (x, y, r) {
1479 return theCircle(this, x, y, r);
1481 C.rect = function (x, y, w, h, r) {
1482 return theRect(this, x, y, w, h, r);
1484 C.ellipse = function (x, y, rx, ry) {
1485 return theEllipse(this, x, y, rx, ry);
1487 C.path = function (params, pathString) {
1488 return thePath(params, pathString, this);
1490 C.image = function (src, x, y, w, h) {
1491 return theImage(this, src, x, y, w, h);
1493 C.text = function (x, y, text) {
1494 return theText(this, x, y, text);
1496 C.group = function () {
1497 return theGroup(this);
1499 C.drawGrid = function (x, y, w, h, wv, hv, color) {
1500 color = color || "#000";
1501 var p = this.path({stroke: color, "stroke-width": 1})
1502 .moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).lineTo(x, y),
1504 columnWidth = w / wv;
1505 for (var i = 1; i < hv; i++) {
1506 p.moveTo(x, y + i * rowHeight).lineTo(x + w, y + i * rowHeight);
1508 for (var i = 1; i < wv; i++) {
1509 p.moveTo(x + i * columnWidth, y).lineTo(x + i * columnWidth, y + h);
1513 C.safari = function () {
1514 if (r.type == "SVG") {
1515 var rect = C.rect(-C.width, -C.height, C.width * 3, C.height * 3).attr({stroke: "none"});
1516 setTimeout(function () {rect.remove();}, 0);
1519 Element.prototype.stop = function () {
1520 clearTimeout(this.animation_in_progress);
1522 Element.prototype.scale = function (x, y) {
1523 if (x == undefined && y == undefined) {
1524 return {x: this._.sx, y: this._.sy};
1528 if (x != 0 && !(x == 1 && y == 1)) {
1529 var dirx = Math.round(x / Math.abs(x)),
1530 diry = Math.round(y / Math.abs(y)),
1531 s = this.node.style;
1532 dx = this.attr("x");
1533 dy = this.attr("y");
1534 cx = this.attr("cx");
1535 cy = this.attr("cy");
1536 if (dirx != 1 || diry != 1) {
1537 if (this.transformations) {
1538 this.transformations[2] = "scale(" + [dirx, diry] + ")";
1539 this.node.setAttribute("transform", this.transformations.join(" "));
1540 dx = (dirx < 0) ? -this.attr("x") - this.attrs.width * x * dirx / this._.sx : this.attr("x");
1541 dy = (diry < 0) ? -this.attr("y") - this.attrs.height * y * diry / this._.sy : this.attr("y");
1542 cx = this.attr("cx") * dirx;
1543 cy = this.attr("cy") * diry;
1545 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=" + dirx +
1546 ", M12=0, M21=0, M22=" + diry +
1547 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')";
1548 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
1551 if (this.transformations) {
1552 this.transformations[2] = "";
1553 this.node.setAttribute("transform", this.transformations.join(" "));
1555 this.node.filterMatrix = "";
1556 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
1559 switch (this.type) {
1563 width: this.attrs.width * x * dirx / this._.sx,
1564 height: this.attrs.height * y * diry / this._.sy,
1572 rx: this.attrs.rx * x * dirx / this._.sx,
1573 ry: this.attrs.ry * y * diry / this._.sy,
1574 r: this.attrs.r * x * diry / this._.sx,
1580 var path = Raphael.pathToRelative(Raphael.parsePathString(this.attr("path"))),
1582 dim = Raphael.pathDimensions(this.attrs.path),
1583 dx = -dim.width * (x - 1) / 2,
1584 dy = -dim.height * (y - 1) / 2;
1585 for (var i = 0, ii = path.length; i < ii; i++) {
1586 if (path[i][0].toUpperCase() == "M" && skip) {
1591 if (path[i][0].toUpperCase() == "A") {
1592 path[i][path[i].length - 2] *= x * dirx;
1593 path[i][path[i].length - 1] *= y * diry;
1595 for (var j = 1, jj = path[i].length; j < jj; j++) {
1596 path[i][j] *= (j % 2) ? x * dirx / this._.sx : y * diry / this._.sy;
1600 var dim2 = Raphael.pathDimensions(path),
1601 dx = dim.x + dim.width / 2 - dim2.x - dim2.width / 2,
1602 dy = dim.y + dim.height / 2 - dim2.y - dim2.height / 2;
1603 path = Raphael.pathToRelative(path);
1607 this.attr({path: path.join(" ")});
1614 Element.prototype.animate = function (params, ms, callback) {
1615 clearTimeout(this.animation_in_progress);
1616 var from = {}, to = {}, diff = {}, t = {x: 0, y: 0};
1617 for (var attr in params) {
1618 if (attr in availableAnimAttrs) {
1619 from[attr] = this.attr(attr);
1620 if (typeof from[attr] == "undefined") {
1621 from[attr] = availableAttrs[attr];
1623 to[attr] = params[attr];
1624 switch (availableAnimAttrs[attr]) {
1626 diff[attr] = (to[attr] - from[attr]) / ms;
1629 from[attr] = Raphael.getRGB(from[attr]);
1630 var toColour = Raphael.getRGB(to[attr]);
1632 r: (toColour.r - from[attr].r) / ms,
1633 g: (toColour.g - from[attr].g) / ms,
1634 b: (toColour.b - from[attr].b) / ms
1638 var pathes = Raphael.pathEqualiser(from[attr], to[attr]);
1639 from[attr] = pathes[0];
1640 to[attr] = pathes[1];
1642 for (var i = 0, ii = from[attr].length; i < ii; i++) {
1643 diff[attr][i] = [0];
1644 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
1645 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
1650 var values = params[attr].split(/[, ]+/);
1651 if (attr == "translation") {
1652 from[attr] = [0, 0];
1653 diff[attr] = [values[0] / ms, values[1] / ms];
1655 from[attr] = from[attr].split(/[, ]+/);
1656 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][0]) / ms];
1662 var start = new Date(),
1666 var time = (new Date()).getTime() - start.getTime(),
1670 for (var attr in from) {
1671 switch (availableAnimAttrs[attr]) {
1673 now = +from[attr] + time * diff[attr];
1677 Math.round(from[attr].r + time * diff[attr].r),
1678 Math.round(from[attr].g + time * diff[attr].g),
1679 Math.round(from[attr].b + time * diff[attr].b)
1684 for (var i = 0, ii = from[attr].length; i < ii; i++) {
1685 now[i] = [from[attr][i][0]];
1686 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
1687 now[i][j] = from[attr][i][j] + time * diff[attr][i][j];
1689 now[i] = now[i].join(" ");
1691 now = now.join(" ");
1694 if (attr == "translation") {
1695 var x = diff[attr][0] * (time - prev),
1696 y = diff[attr][1] * (time - prev);
1699 now = [x, y].join(" ");
1701 now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1]].join(" ");
1705 if (attr == "font-size") {
1706 set[attr] = now + "px";
1712 that.animation_in_progress = setTimeout(arguments.callee, 0);
1716 that.translate(-t.x, -t.y);
1719 clearTimeout(that.animation_in_progress);
1721 (typeof callback == "function") && callback.call(that);
1728 C.pathfinder = function (p, path) {
1730 M: function (x, y) {
1733 C: function (x1, y1, x2, y2, x3, y3) {
1734 this.curveTo(x1, y1, x2, y2, x3, y3);
1736 Q: function (x1, y1, x2, y2) {
1737 this.qcurveTo(x1, y1, x2, y2);
1739 T: function (x, y) {
1740 this.qcurveTo(x, y);
1742 S: function (x1, y1, x2, y2) {
1743 p.curveTo(x1, y1, x2, y2);
1745 L: function (x, y) {
1749 this.lineTo(x, this.last.y);
1752 this.lineTo(this.last.x, y);
1754 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
1755 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
1762 path = Raphael.pathToAbsolute(path);
1763 for (var i = 0, ii = path.length; i < ii; i++) {
1764 var b = path[i].shift();
1765 commands[b].apply(p, path[i]);
1770 return function () {};
1772 })((!window.SVGAngle) ? "VML" : "SVG");
1775 Raphael.vml = !(Raphael.svg = (Raphael.type == "SVG"));
1776 if (Raphael.vml && window.CanvasRenderingContext2D) {
1777 Raphael.type = "Canvas only";
1778 Raphael.vml = Raphael.svg = false;
1780 Raphael.toString = function () {
1781 return "Your browser " + (this.vml ? "doesn't ": "") + "support" + (this.svg ? "s": "") +
1782 " SVG.\nYou are running " + unescape("Rapha%EBl%20") + this.version;
1784 // generic utilities
1785 Raphael.hsb2rgb = function (hue, saturation, brightness) {
1786 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
1794 if (brightness == 0) {
1795 return {r: 0, g: 0, b: 0, hex: "#000"};
1797 var i = Math.floor(hue * 6),
1799 p = brightness * (1 - saturation),
1800 q = brightness * (1 - (saturation * f)),
1801 t = brightness * (1 - (saturation * (1 - f)));
1803 function () {red = brightness; green = t; blue = p;},
1804 function () {red = q; green = brightness; blue = p;},
1805 function () {red = p; green = brightness; blue = t;},
1806 function () {red = p; green = q; blue = brightness;},
1807 function () {red = t; green = p; blue = brightness;},
1808 function () {red = brightness; green = p; blue = q;},
1809 function () {red = brightness; green = t; blue = p;}
1812 var rgb = {r: red, g: green, b: blue};
1816 var r = Math.round(red).toString(16);
1817 if (r.length == 1) {
1820 var g = Math.round(green).toString(16);
1821 if (g.length == 1) {
1824 var b = Math.round(blue).toString(16);
1825 if (b.length == 1) {
1828 rgb.hex = "#" + r + g + b;
1831 Raphael.rgb2hsb = function (red, green, blue) {
1832 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
1837 if (typeof red == "string" && red.charAt(0) == "#") {
1838 if (red.length == 4) {
1839 blue = parseInt(red.substring(3), 16);
1840 green = parseInt(red.substring(2, 3), 16);
1841 red = parseInt(red.substring(1, 2), 16);
1843 blue = parseInt(red.substring(5), 16);
1844 green = parseInt(red.substring(3, 5), 16);
1845 red = parseInt(red.substring(1, 3), 16);
1848 if (red > 1 || green > 1 || blue > 1) {
1853 var max = Math.max(red, green, blue),
1854 min = Math.min(red, green, blue),
1859 return {h: 0, s: 0, b: max};
1861 var delta = (max - min);
1862 saturation = delta / max;
1864 hue = (green - blue) / delta;
1865 } else if (green == max) {
1866 hue = 2 + ((blue - red) / delta);
1868 hue = 4 + ((red - green) / delta);
1878 return {h: hue, s: saturation, b: brightness};
1880 Raphael.getRGB = function (colour) {
1881 var red, green, blue,
1882 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);
1885 blue = parseInt(rgb[2].substring(5), 16);
1886 green = parseInt(rgb[2].substring(3, 5), 16);
1887 red = parseInt(rgb[2].substring(1, 3), 16);
1890 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
1891 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
1892 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
1895 rgb = rgb[4].split(/\s*,\s*/);
1896 red = parseInt(rgb[0], 10);
1897 green = parseInt(rgb[1], 10);
1898 blue = parseInt(rgb[2], 10);
1901 rgb = rgb[5].split(/\s*,\s*/);
1902 red = parseInt(rgb[0], 10) * 2.55;
1903 green = parseInt(rgb[1], 10) * 2.55;
1904 blue = parseInt(rgb[2], 10) * 2.55;
1907 rgb = rgb[6].split(/\s*,\s*/);
1908 red = parseInt(rgb[0], 10);
1909 green = parseInt(rgb[1], 10);
1910 blue = parseInt(rgb[2], 10);
1911 return this.hsb2rgb(red, green, blue);
1914 rgb = rgb[7].split(/\s*,\s*/);
1915 red = parseInt(rgb[0], 10) * 2.55;
1916 green = parseInt(rgb[1], 10) * 2.55;
1917 blue = parseInt(rgb[2], 10) * 2.55;
1918 return this.hsb2rgb(red, green, blue);
1920 var rgb = {r: red, g: green, b: blue};
1921 var r = Math.round(red).toString(16);
1922 (r.length == 1) && (r = "0" + r);
1923 var g = Math.round(green).toString(16);
1924 (g.length == 1) && (g = "0" + g);
1925 var b = Math.round(blue).toString(16);
1926 (b.length == 1) && (b = "0" + b);
1927 rgb.hex = "#" + r + g + b;
1931 Raphael.getColor = function (value) {
1932 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
1933 var rgb = this.hsb2rgb(start.h, start.s, start.b);
1939 arguments.callee.start = {h: 0, s: 1, b: start.b};
1944 Raphael.getColor.reset = function () {
1945 this.start = undefined;
1947 Raphael.parsePathString = function (pathString) {
1948 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0};
1950 pathString.replace(/([achlmqstvz])\s*((-?\d*\.?\d*\s*,?\s*)+)/ig, function (a, b, c) {
1951 var params = [], name = b.toLowerCase();
1952 c.replace(/(-?\d*\.?\d*)\s*,?\s*/ig, function (a, b) {
1953 b && params.push(+b);
1955 while (params.length >= paramCounts[name]) {
1956 data.push([b].concat(params.splice(0, paramCounts[name])));
1957 if (!paramCounts[name]) {
1964 Raphael.pathDimensions = function (path) {
1965 var pathArray = path;
1966 if (typeof path == "string") {
1967 pathArray = this.parsePathString(path);
1969 pathArray = this.pathToAbsolute(pathArray);
1970 var x = [], y = [], length = 0;
1971 for (var i = 0, ii = pathArray.length; i < ii; i++) {
1972 switch (pathArray[i][0]) {
1976 x.push(pathArray[i][pathArray[i].length - 2]);
1977 y.push(pathArray[i][pathArray[i].length - 1]);
1980 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
1982 x.push(pathArray[i][j]);
1984 y.push(pathArray[i][j]);
1989 var minx = Math.min.apply(Math, x),
1990 miny = Math.min.apply(Math, y);
1994 width: Math.max.apply(Math, x) - minx,
1995 height: Math.max.apply(Math, y) - miny,
2000 Raphael.pathToRelative = function (pathArray) {
2002 if (typeof pathArray == "string") {
2003 pathArray = this.parsePathString(pathArray);
2005 var x = 0, y = 0, start = 0;
2006 if (pathArray[0][0] == "M") {
2007 x = pathArray[0][1];
2008 y = pathArray[0][2];
2010 res.push(pathArray[0]);
2012 for (var i = start, ii = pathArray.length; i < ii; i++) {
2014 if (pathArray[i][0] != pathArray[i][0].toLowerCase()) {
2015 res[i][0] = pathArray[i][0].toLowerCase();
2016 switch (res[i][0]) {
2018 res[i][1] = pathArray[i][1];
2019 res[i][2] = pathArray[i][2];
2021 res[i][4] = pathArray[i][4];
2022 res[i][5] = pathArray[i][5];
2023 res[i][6] = +(pathArray[i][6] - x).toFixed(3);
2024 res[i][7] = +(pathArray[i][7] - y).toFixed(3);
2027 res[i][1] = +(pathArray[i][1] - y).toFixed(3);
2030 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
2031 res[i][j] = +(pathArray[i][j] - ((j % 2) ? x : y)).toFixed(3);
2035 res[i] = pathArray[i];
2037 switch (res[i][0]) {
2041 x += res[i][res[i].length - 1];
2044 y += res[i][res[i].length - 1];
2047 x += res[i][res[i].length - 2];
2048 y += res[i][res[i].length - 1];
2053 Raphael.pathToAbsolute = function (pathArray) {
2055 if (typeof pathArray == "string") {
2056 pathArray = this.parsePathString(pathArray);
2058 var x = 0, y = 0, start = 0;
2059 if (pathArray[0][0] == "M") {
2060 x = +pathArray[0][1];
2061 y = +pathArray[0][2];
2063 res[0] = pathArray[0];
2065 for (var i = start, ii = pathArray.length; i < ii; i++) {
2067 if (pathArray[i][0] != pathArray[i][0].toUpperCase()) {
2068 res[i][0] = pathArray[i][0].toUpperCase();
2069 switch (res[i][0]) {
2071 res[i][1] = pathArray[i][1];
2072 res[i][2] = pathArray[i][2];
2074 res[i][4] = pathArray[i][4];
2075 res[i][5] = pathArray[i][5];
2076 res[i][6] = +(pathArray[i][6] + x).toFixed(3);
2077 res[i][7] = +(pathArray[i][7] + y).toFixed(3);
2080 res[i][1] = +pathArray[i][1] + y;
2083 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
2084 res[i][j] = +pathArray[i][j] + ((j % 2) ? x : y);
2088 res[i] = pathArray[i];
2090 switch (res[i][0]) {
2100 x = res[i][res[i].length - 2];
2101 y = res[i][res[i].length - 1];
2106 Raphael.pathEqualiser = function (path1, path2) {
2107 var data = [this.pathToAbsolute(this.parsePathString(path1)), this.pathToAbsolute(this.parsePathString(path2))],
2108 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}],
2109 processPath = function (path, d) {
2119 var nx = d.x + (d.x - (d.bx || d.x));
2120 var ny = d.y + (d.y - (d.by || d.y));
2121 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
2124 var nx = d.x + (d.x - (d.bx || d.x));
2125 var ny = d.y + (d.y - (d.by || d.y));
2126 path = ["Q", nx, ny, path[1], path[2]];
2129 path = ["L", path[1], d.y];
2132 path = ["L", d.x, path[1]];
2135 path = ["L", d.X, d.Y];
2140 edgeCases = function (a, b, i) {
2141 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
2142 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
2143 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
2144 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
2145 attrs[a].x = data[a][i][data[a][i].length - 2];
2146 attrs[a].y = data[a][i][data[a][i].length - 1];
2148 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
2149 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]];
2150 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
2151 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
2152 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
2153 var x = data[b][i][data[b][i].length - 2];
2154 var y = data[b][i][data[b][i].length - 1];
2155 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
2156 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
2158 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
2159 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
2160 attrs[b].x = data[b][i][data[b][i].length - 2];
2161 attrs[b].y = data[b][i][data[b][i].length - 1];
2163 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
2164 var x = data[b][i][data[b][i].length - 2];
2165 var y = data[b][i][data[b][i].length - 1];
2166 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
2167 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
2169 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
2170 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
2171 attrs[b].x = data[b][i][data[b][i].length - 2];
2172 attrs[b].y = data[b][i][data[b][i].length - 1];
2174 } else if (data[a][i][0] == "U") {
2175 data[a][i][0] = data[b][i][0];
2176 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
2177 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
2182 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
2183 data[0][i] = processPath(data[0][i], attrs[0]);
2184 data[1][i] = processPath(data[1][i], attrs[1]);
2185 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
2188 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
2189 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
2190 attrs[0].x = data[0][i][data[0][i].length - 2];
2191 attrs[0].y = data[0][i][data[0][i].length - 1];
2192 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
2193 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
2194 attrs[1].x = data[1][i][data[1][i].length - 2];
2195 attrs[1].y = data[1][i][data[1][i].length - 1];