2 * Raphael 0.6.4 - 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";
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 d = document.createElement("div"),
757 r = C.canvas = document.createElement("rvml:group"),
758 cs = c.style, rs = r.style;
761 width = width || "320px";
762 height = height || "200px";
763 cs.clip = "rect(0 " + width + " " + height + " 0)";
766 cs.position = "absolute";
767 rs.position = "absolute";
768 d.style.position = "relative";
771 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
772 r.coordorigin = "0 0";
774 var b = document.createElement("rvml:rect"), bs = b.style;
775 bs.left = bs.top = 0;
777 bs.height = rs.height;
778 b.filled = b.stroked = "f";
783 if (container == 1) {
784 document.body.appendChild(d);
785 cs.position = "absolute";
797 cs.width = container.style.width = width;
798 cs.height = container.style.height = height;
799 if (container.firstChild) {
800 container.insertBefore(d, container.firstChild);
802 container.appendChild(d);
805 for (var prop in C) {
806 container[prop] = C[prop];
808 container.clear = function () {
810 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
811 if (r.childNodes[i] != b) {
812 todel.push(r.childNodes[i]);
815 for (i = 0, ii = todel.length; i < ii; i++) {
816 r.removeChild(todel[i]);
821 C.remove = function () {
822 C.canvas.parentNode.parentNode.parentNode.removeChild(C.canvas.parentNode.parentNode);
826 var thePath = function (params, pathString, SVG) {
827 var el = document.createElementNS(SVG.svgns, "path");
828 el.setAttribute("fill", "none");
830 SVG.canvas.appendChild(el);
832 var p = new Element(el, SVG);
835 p.last = {x: 0, y: 0, bx: 0, by: 0};
836 p.absolutely = function () {
837 this.isAbsolute = true;
840 p.relatively = function () {
841 this.isAbsolute = false;
844 p.moveTo = function (x, y) {
845 var d = this.isAbsolute?"M":"m";
846 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
847 var oldD = this[0].getAttribute("d") || "";
848 (oldD == "M0,0") && (oldD = "");
849 this[0].setAttribute("d", oldD + d);
850 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
851 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
852 this.attrs.path = oldD + d;
855 p.lineTo = function (x, y) {
856 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
857 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
858 var d = this.isAbsolute?"L":"l";
859 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
860 var oldD = this[0].getAttribute("d") || "";
861 this[0].setAttribute("d", oldD + d);
862 this.attrs.path = oldD + d;
865 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
866 var d = this.isAbsolute ? "A" : "a";
867 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(" ");
868 var oldD = this[0].getAttribute("d") || "";
869 this[0].setAttribute("d", oldD + d);
870 this.last.x = parseFloat(x, 10);
871 this.last.y = parseFloat(y, 10);
872 this.attrs.path = oldD + d;
875 p.cplineTo = function (x1, y1, w1) {
877 return this.lineTo(x1, y1);
880 var x = parseFloat(x1, 10);
881 var y = parseFloat(y1, 10);
882 var w = parseFloat(w1, 10);
883 var d = this.isAbsolute?"C":"c";
884 var attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
885 for (var i = 0, ii = attr.length; i < ii; i++) {
886 d += attr[i].toFixed(3) + " ";
888 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
889 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
890 this.last.bx = attr[2];
891 this.last.by = attr[3];
892 var oldD = this[0].getAttribute("d") || "";
893 this[0].setAttribute("d", oldD + d);
894 this.attrs.path = oldD + d;
898 p.curveTo = function () {
900 command = [0, 1, 2, 3, "s", 5, "c"];
902 var d = command[arguments.length];
903 if (this.isAbsolute) {
906 for (var i = 0, ii = arguments.length; i < ii; i++) {
907 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
909 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
910 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
911 this.last.bx = parseFloat(arguments[arguments.length - 4], 10);
912 this.last.by = parseFloat(arguments[arguments.length - 3], 10);
913 var oldD = this.node.getAttribute("d") || "";
914 this.node.setAttribute("d", oldD + d);
915 this.attrs.path = oldD + d;
918 p.qcurveTo = function () {
920 command = [0, 1, "t", 3, "q"];
922 var d = command[arguments.length];
923 if (this.isAbsolute) {
926 for (var i = 0, ii = arguments.length; i < ii; i++) {
927 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
929 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
930 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
931 if (arguments.length != 2) {
932 this.last.qx = parseFloat(arguments[arguments.length - 4], 10);
933 this.last.qy = parseFloat(arguments[arguments.length - 3], 10);
935 var oldD = this.node.getAttribute("d") || "";
936 this.node.setAttribute("d", oldD + d);
937 this.attrs.path = oldD + d;
940 p.addRoundedCorner = function (r, dir) {
941 var R = .5522 * r, rollback = this.isAbsolute, o = this;
944 rollback = function () {
948 rollback = function () {};
954 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
957 o.curveTo(-R, 0, -r, r - R, -r, r);
964 o.curveTo(R, 0, r, -(r - R), r, -r);
967 o.curveTo(R, 0, r, r - R, r, r);
974 o.curveTo(0, -R, -(R - r), -r, r, -r);
977 o.curveTo(0, -R, R - r, -r, -r, -r);
984 o.curveTo(0, R, -(R - r), r, r, r);
987 o.curveTo(0, R, R - r, r, -r, r);
992 actions[dir[0]]()[dir[1]]();
996 p.andClose = function () {
997 var oldD = this[0].getAttribute("d") || "";
998 this[0].setAttribute("d", oldD + "Z ");
999 this.attrs.path = oldD + "Z ";
1003 p.attrs.path = "" + pathString;
1005 C.pathfinder(p, p.attrs.path);
1008 setFillAndStroke(p, params);
1012 var addGrdientFill = function (o, gradient, SVG) {
1013 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
1014 el.id = "raphael-gradient-" + SVG.gradients++;
1015 if (gradient.vector && gradient.vector.length) {
1016 el.setAttribute("x1", gradient.vector[0]);
1017 el.setAttribute("y1", gradient.vector[1]);
1018 el.setAttribute("x2", gradient.vector[2]);
1019 el.setAttribute("y2", gradient.vector[3]);
1021 SVG.defs.appendChild(el);
1022 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1023 var stop = document.createElementNS(SVG.svgns, "stop");
1024 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
1025 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
1026 if (typeof gradient.dots[i].opacity != "undefined") {
1027 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
1029 el.appendChild(stop);
1031 o.setAttribute("fill", "url(#" + el.id + ")");
1033 var updatePosition = function (o) {
1035 var bbox = o.node.getBBox();
1036 o.pattern.setAttribute("patternTransform", "translate(" + [bbox.x, bbox.y].join(",") + ")");
1039 var setFillAndStroke = function (o, params) {
1044 "-..": [3, 1, 1, 1, 1, 1],
1048 "- .": [4, 3, 1, 3],
1049 "--.": [8, 3, 1, 3],
1050 "--..": [8, 3, 1, 3, 1, 3]
1052 addDashes = function (o, value) {
1053 value = dasharray[value.toString().toLowerCase()];
1055 var width = o.attrs["stroke-width"] || "1",
1056 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
1058 for (var i = 0, ii = value.length; i < ii; i++) {
1059 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
1061 value = dashes.join(",");
1062 o.node.setAttribute("stroke-dasharray", value);
1065 for (var att in params) {
1066 var value = params[att];
1067 o.attrs[att] = value;
1070 if (o.type == "path") {
1071 o.node.setAttribute("d", "M0,0");
1072 C.pathfinder(o, value);
1077 o.node.setAttribute(att, value);
1083 o.node.setAttribute(att, value);
1087 o.node.setAttribute(att, value);
1090 o.node.setAttribute(att, value);
1093 addGrdientFill(o.node, value, o.svg);
1095 case "stroke-width":
1096 o.node.style.strokeWidth = value;
1097 // Need following line for Firefox
1098 o.node.setAttribute(att, value);
1099 if (o.attrs["stroke-dasharray"]) {
1100 addDashes(o, o.attrs["stroke-dasharray"]);
1103 case "stroke-dasharray":
1104 addDashes(o, value);
1107 if (o.type == "text") {
1108 o.node.childNodes.length && o.node.removeChild(o.node.firstChild);
1109 o.node.appendChild(document.createTextNode(value));
1113 o.rotate(value, true);
1116 var xy = value.split(/[, ]+/);
1117 o.translate(xy[0], xy[1]);
1120 var xy = value.split(/[, ]+/);
1121 o.scale(xy[0], xy[1]);
1124 var isURL = value.match(/^url\(([^\)]+)\)$/i);
1126 var el = document.createElementNS(o.svg.svgns, "pattern");
1127 var ig = document.createElementNS(o.svg.svgns, "image");
1128 el.id = "raphael-pattern-" + o.svg.gradients++;
1129 el.setAttribute("x", 0);
1130 el.setAttribute("y", 0);
1131 el.setAttribute("patternUnits", "userSpaceOnUse");
1132 ig.setAttribute("x", 0);
1133 ig.setAttribute("y", 0);
1134 ig.setAttributeNS(o.svg.xlink, "href", isURL[1]);
1137 var img = document.createElement("img");
1138 img.style.position = "absolute";
1139 img.style.top = "-9999em";
1140 img.style.left = "-9999em";
1141 img.onload = function () {
1142 el.setAttribute("width", this.offsetWidth);
1143 el.setAttribute("height", this.offsetHeight);
1144 ig.setAttribute("width", this.offsetWidth);
1145 ig.setAttribute("height", this.offsetHeight);
1146 document.body.removeChild(this);
1149 document.body.appendChild(img);
1151 o.svg.defs.appendChild(el);
1152 o.node.style.fill = "url(#" + el.id + ")";
1153 o.node.setAttribute("fill", "url(#" + el.id + ")");
1159 var cssrule = att.replace(/(\-.)/g, function (w) {
1160 return w.substring(1).toUpperCase();
1162 o.node.style[cssrule] = value;
1163 // Need following line for Firefox
1164 o.node.setAttribute(att, value);
1169 var Element = function (node, svg) {
1175 this.attrs = this.attrs || {};
1176 this.transformations = []; // rotate, translate, scale
1180 rt: {deg: 0, x: 0, y: 0},
1185 Element.prototype.translate = function (x, y) {
1186 if (x == undefined && y == undefined) {
1187 return {x: this._.tx, y: this._.ty};
1191 switch (this.type) {
1194 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
1199 this.attr({x: this.attrs.x + x, y: this.attrs.y + y});
1202 var path = Raphael.pathToRelative(this.attrs.path);
1205 this.attr({path: path.join(" ")});
1210 Element.prototype.rotate = function (deg, isAbsolute) {
1211 if (deg == undefined) {
1212 return this._.rt.deg;
1214 var bbox = this.getBBox();
1216 this._.rt.deg = deg;
1218 this._.rt.deg += deg;
1221 if (this._.rt.deg) {
1222 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
1224 this.transformations[0] = "";
1226 this.node.setAttribute("transform", this.transformations.join(" "));
1229 Element.prototype.hide = function () {
1230 this.node.style.display = "none";
1233 Element.prototype.show = function () {
1234 this.node.style.display = "block";
1237 Element.prototype.remove = function () {
1238 this.node.parentNode.removeChild(this.node);
1240 Element.prototype.getBBox = function () {
1241 return this.node.getBBox();
1243 Element.prototype.attr = function () {
1244 if (arguments.length == 1 && typeof arguments[0] == "string") {
1245 if (arguments[0] == "translation") {
1246 return this.translate();
1248 return this.attrs[arguments[0]];
1250 if (arguments.length == 1 && arguments[0] instanceof Array) {
1252 for (var j in arguments[0]) {
1253 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1257 if (arguments.length == 2) {
1259 params[arguments[0]] = arguments[1];
1260 setFillAndStroke(this, params);
1261 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1262 setFillAndStroke(this, arguments[0]);
1266 Element.prototype.toFront = function () {
1267 this.node.parentNode.appendChild(this.node);
1270 Element.prototype.toBack = function () {
1271 if (this.node.parentNode.firstChild != this.node) {
1272 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1276 Element.prototype.insertAfter = function (element) {
1277 if (element.node.nextSibling) {
1278 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
1280 element.node.parentNode.appendChild(this.node);
1284 Element.prototype.insertBefore = function (element) {
1285 element.node.parentNode.insertBefore(this.node, element.node);
1288 var theCircle = function (svg, x, y, r) {
1289 var el = document.createElementNS(svg.svgns, "circle");
1290 el.setAttribute("cx", x);
1291 el.setAttribute("cy", y);
1292 el.setAttribute("r", r);
1293 el.setAttribute("fill", "none");
1294 el.setAttribute("stroke", "#000");
1296 svg.canvas.appendChild(el);
1298 var res = new Element(el, svg);
1299 res.attrs = res.attrs || {};
1303 res.attrs.stroke = "#000";
1304 res.type = "circle";
1307 var theRect = function (svg, x, y, w, h, r) {
1308 var el = document.createElementNS(svg.svgns, "rect");
1309 el.setAttribute("x", x);
1310 el.setAttribute("y", y);
1311 el.setAttribute("width", w);
1312 el.setAttribute("height", h);
1314 el.setAttribute("rx", r);
1315 el.setAttribute("ry", r);
1317 el.setAttribute("fill", "none");
1318 el.setAttribute("stroke", "#000");
1320 svg.canvas.appendChild(el);
1322 var res = new Element(el, svg);
1323 res.attrs = res.attrs || {};
1326 res.attrs.width = w;
1327 res.attrs.height = h;
1328 res.attrs.stroke = "#000";
1330 res.attrs.rx = res.attrs.ry = r;
1335 var theEllipse = function (svg, x, y, rx, ry) {
1336 var el = document.createElementNS(svg.svgns, "ellipse");
1337 el.setAttribute("cx", x);
1338 el.setAttribute("cy", y);
1339 el.setAttribute("rx", rx);
1340 el.setAttribute("ry", ry);
1341 el.setAttribute("fill", "none");
1342 el.setAttribute("stroke", "#000");
1344 svg.canvas.appendChild(el);
1346 var res = new Element(el, svg);
1347 res.attrs = res.attrs || {};
1352 res.attrs.stroke = "#000";
1353 res.type = "ellipse";
1356 var theImage = function (svg, src, x, y, w, h) {
1357 var el = document.createElementNS(svg.svgns, "image");
1358 el.setAttribute("x", x);
1359 el.setAttribute("y", y);
1360 el.setAttribute("width", w);
1361 el.setAttribute("height", h);
1362 el.setAttribute("preserveAspectRatio", "none");
1363 el.setAttributeNS(svg.xlink, "href", src);
1365 svg.canvas.appendChild(el);
1367 var res = new Element(el, svg);
1368 res.attrs = res.attrs || {};
1371 res.attrs.width = w;
1372 res.attrs.height = h;
1376 var theText = function (svg, x, y, text) {
1377 var el = document.createElementNS(svg.svgns, "text");
1378 el.setAttribute("x", x);
1379 el.setAttribute("y", y);
1380 el.setAttribute("text-anchor", "middle");
1381 el.setAttribute("fill", "#000");
1383 el.appendChild(document.createTextNode(text));
1386 svg.canvas.appendChild(el);
1388 var res = new Element(el, svg);
1389 res.attrs = res.attrs || {};
1392 res.attrs.fill = "#000";
1396 var theGroup = function (svg) {
1397 var el = document.createElementNS(svg.svgns, "g");
1399 svg.canvas.appendChild(el);
1401 var i = new Element(el, svg);
1402 for (var f in svg) {
1403 if (f[0] != "_" && typeof svg[f] == "function") {
1404 i[f] = (function (f) {
1405 return function () {
1406 var e = svg[f].apply(svg, arguments);
1407 el.appendChild(e[0]);
1416 r._create = function () {
1417 // container, width, height
1418 // x, y, width, height
1419 if (typeof arguments[0] == "string") {
1420 var container = document.getElementById(arguments[0]);
1421 var width = arguments[1];
1422 var height = arguments[2];
1424 if (typeof arguments[0] == "object") {
1425 var container = arguments[0];
1426 var width = arguments[1];
1427 var height = arguments[2];
1429 if (typeof arguments[0] == "number") {
1433 width = arguments[2],
1434 height = arguments[3];
1437 throw new Error("SVG container not found.");
1439 C.canvas = document.createElementNS(C.svgns, "svg");
1440 C.canvas.setAttribute("width", width || 320);
1441 C.width = width || 320;
1442 C.canvas.setAttribute("height", height || 200);
1443 C.height = height || 200;
1444 if (container == 1) {
1445 document.body.appendChild(C.canvas);
1446 C.canvas.style.position = "absolute";
1447 C.canvas.style.left = x + "px";
1448 C.canvas.style.top = y + "px";
1450 if (container.firstChild) {
1451 container.insertBefore(C.canvas, container.firstChild);
1453 container.appendChild(C.canvas);
1458 clear: function () {
1459 while (this.canvas.firstChild) {
1460 this.canvas.removeChild(this.canvas.firstChild);
1462 this.defs = document.createElementNS(C.svgns, "defs");
1464 this.canvas.appendChild(this.defs);
1467 for (var prop in C) {
1468 if (prop != "create") {
1469 container[prop] = C[prop];
1475 C.remove = function () {
1476 C.canvas.parentNode.removeChild(C.canvas);
1478 C.svgns = "http://www.w3.org/2000/svg";
1479 C.xlink = "http://www.w3.org/1999/xlink";
1481 if (type == "VML" || type == "SVG") {
1482 C.circle = function (x, y, r) {
1483 return theCircle(this, x, y, r);
1485 C.rect = function (x, y, w, h, r) {
1486 return theRect(this, x, y, w, h, r);
1488 C.ellipse = function (x, y, rx, ry) {
1489 return theEllipse(this, x, y, rx, ry);
1491 C.path = function (params, pathString) {
1492 return thePath(params, pathString, this);
1494 C.image = function (src, x, y, w, h) {
1495 return theImage(this, src, x, y, w, h);
1497 C.text = function (x, y, text) {
1498 return theText(this, x, y, text);
1500 C.group = function () {
1501 return theGroup(this);
1503 C.drawGrid = function (x, y, w, h, wv, hv, color) {
1504 color = color || "#000";
1505 var p = this.path({stroke: color, "stroke-width": 1})
1506 .moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).lineTo(x, y),
1508 columnWidth = w / wv;
1509 for (var i = 1; i < hv; i++) {
1510 p.moveTo(x, y + i * rowHeight).lineTo(x + w, y + i * rowHeight);
1512 for (var i = 1; i < wv; i++) {
1513 p.moveTo(x + i * columnWidth, y).lineTo(x + i * columnWidth, y + h);
1517 C.safari = function () {
1518 if (navigator.vendor == "Apple Computer, Inc.") {
1519 var rect = C.rect(-C.width, -C.height, C.width * 3, C.height * 3).attr({stroke: "none"});
1520 setTimeout(function () {rect.remove();}, 0);
1523 Element.prototype.stop = function () {
1524 clearTimeout(this.animation_in_progress);
1526 Element.prototype.scale = function (x, y) {
1527 if (x == undefined && y == undefined) {
1528 return {x: this._.sx, y: this._.sy};
1532 if (x != 0 && !(x == 1 && y == 1)) {
1533 var dirx = Math.round(x / Math.abs(x)),
1534 diry = Math.round(y / Math.abs(y)),
1535 s = this.node.style;
1536 dx = this.attr("x");
1537 dy = this.attr("y");
1538 cx = this.attr("cx");
1539 cy = this.attr("cy");
1540 if (dirx != 1 || diry != 1) {
1541 if (this.transformations) {
1542 this.transformations[2] = "scale(" + [dirx, diry] + ")";
1543 this.node.setAttribute("transform", this.transformations.join(" "));
1544 dx = (dirx < 0) ? -this.attr("x") - this.attrs.width * x * dirx / this._.sx : this.attr("x");
1545 dy = (diry < 0) ? -this.attr("y") - this.attrs.height * y * diry / this._.sy : this.attr("y");
1546 cx = this.attr("cx") * dirx;
1547 cy = this.attr("cy") * diry;
1549 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=" + dirx +
1550 ", M12=0, M21=0, M22=" + diry +
1551 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')";
1552 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
1555 if (this.transformations) {
1556 this.transformations[2] = "";
1557 this.node.setAttribute("transform", this.transformations.join(" "));
1559 this.node.filterMatrix = "";
1560 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
1563 switch (this.type) {
1567 width: this.attrs.width * x * dirx / this._.sx,
1568 height: this.attrs.height * y * diry / this._.sy,
1576 rx: this.attrs.rx * x * dirx / this._.sx,
1577 ry: this.attrs.ry * y * diry / this._.sy,
1578 r: this.attrs.r * x * diry / this._.sx,
1584 var path = Raphael.pathToRelative(Raphael.parsePathString(this.attr("path"))),
1586 dim = Raphael.pathDimensions(this.attrs.path),
1587 dx = -dim.width * (x - 1) / 2,
1588 dy = -dim.height * (y - 1) / 2;
1589 for (var i = 0, ii = path.length; i < ii; i++) {
1590 if (path[i][0].toUpperCase() == "M" && skip) {
1595 if (path[i][0].toUpperCase() == "A") {
1596 path[i][path[i].length - 2] *= x * dirx;
1597 path[i][path[i].length - 1] *= y * diry;
1599 for (var j = 1, jj = path[i].length; j < jj; j++) {
1600 path[i][j] *= (j % 2) ? x * dirx / this._.sx : y * diry / this._.sy;
1604 var dim2 = Raphael.pathDimensions(path),
1605 dx = dim.x + dim.width / 2 - dim2.x - dim2.width / 2,
1606 dy = dim.y + dim.height / 2 - dim2.y - dim2.height / 2;
1607 path = Raphael.pathToRelative(path);
1611 this.attr({path: path.join(" ")});
1618 Element.prototype.animate = function (params, ms, callback) {
1619 clearTimeout(this.animation_in_progress);
1620 var from = {}, to = {}, diff = {}, t = {x: 0, y: 0};
1621 for (var attr in params) {
1622 if (attr in availableAnimAttrs) {
1623 from[attr] = this.attr(attr);
1624 if (typeof from[attr] == "undefined") {
1625 from[attr] = availableAttrs[attr];
1627 to[attr] = params[attr];
1628 switch (availableAnimAttrs[attr]) {
1630 diff[attr] = (to[attr] - from[attr]) / ms;
1633 from[attr] = Raphael.getRGB(from[attr]);
1634 var toColour = Raphael.getRGB(to[attr]);
1636 r: (toColour.r - from[attr].r) / ms,
1637 g: (toColour.g - from[attr].g) / ms,
1638 b: (toColour.b - from[attr].b) / ms
1642 var pathes = Raphael.pathEqualiser(from[attr], to[attr]);
1643 from[attr] = pathes[0];
1644 to[attr] = pathes[1];
1646 for (var i = 0, ii = from[attr].length; i < ii; i++) {
1647 diff[attr][i] = [0];
1648 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
1649 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
1654 var values = params[attr].split(/[, ]+/);
1655 if (attr == "translation") {
1656 from[attr] = [0, 0];
1657 diff[attr] = [values[0] / ms, values[1] / ms];
1659 from[attr] = from[attr].split(/[, ]+/);
1660 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][0]) / ms];
1666 var start = new Date(),
1670 var time = (new Date()).getTime() - start.getTime(),
1674 for (var attr in from) {
1675 switch (availableAnimAttrs[attr]) {
1677 now = +from[attr] + time * diff[attr];
1681 Math.round(from[attr].r + time * diff[attr].r),
1682 Math.round(from[attr].g + time * diff[attr].g),
1683 Math.round(from[attr].b + time * diff[attr].b)
1688 for (var i = 0, ii = from[attr].length; i < ii; i++) {
1689 now[i] = [from[attr][i][0]];
1690 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
1691 now[i][j] = from[attr][i][j] + time * diff[attr][i][j];
1693 now[i] = now[i].join(" ");
1695 now = now.join(" ");
1698 if (attr == "translation") {
1699 var x = diff[attr][0] * (time - prev),
1700 y = diff[attr][1] * (time - prev);
1703 now = [x, y].join(" ");
1705 now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1]].join(" ");
1709 if (attr == "font-size") {
1710 set[attr] = now + "px";
1716 that.animation_in_progress = setTimeout(arguments.callee, 0);
1720 that.translate(-t.x, -t.y);
1723 clearTimeout(that.animation_in_progress);
1725 (typeof callback == "function") && callback.call(that);
1732 C.pathfinder = function (p, path) {
1734 M: function (x, y) {
1737 C: function (x1, y1, x2, y2, x3, y3) {
1738 this.curveTo(x1, y1, x2, y2, x3, y3);
1740 Q: function (x1, y1, x2, y2) {
1741 this.qcurveTo(x1, y1, x2, y2);
1743 T: function (x, y) {
1744 this.qcurveTo(x, y);
1746 S: function (x1, y1, x2, y2) {
1747 p.curveTo(x1, y1, x2, y2);
1749 L: function (x, y) {
1753 this.lineTo(x, this.last.y);
1756 this.lineTo(this.last.x, y);
1758 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
1759 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
1766 path = Raphael.pathToAbsolute(path);
1767 for (var i = 0, ii = path.length; i < ii; i++) {
1768 var b = path[i].shift();
1769 commands[b].apply(p, path[i]);
1774 return function () {};
1776 })((!window.SVGAngle) ? "VML" : "SVG");
1779 Raphael.vml = !(Raphael.svg = (Raphael.type == "SVG"));
1780 if (Raphael.vml && window.CanvasRenderingContext2D) {
1781 Raphael.type = "Canvas only";
1782 Raphael.vml = Raphael.svg = false;
1784 Raphael.toString = function () {
1785 return "Your browser " + (this.vml ? "doesn't ": "") + "support" + (this.svg ? "s": "") +
1786 " SVG.\nYou are running " + unescape("Rapha%EBl%20") + this.version;
1788 // generic utilities
1789 Raphael.hsb2rgb = function (hue, saturation, brightness) {
1790 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
1798 if (brightness == 0) {
1799 return {r: 0, g: 0, b: 0, hex: "#000"};
1801 var i = Math.floor(hue * 6),
1803 p = brightness * (1 - saturation),
1804 q = brightness * (1 - (saturation * f)),
1805 t = brightness * (1 - (saturation * (1 - f)));
1807 function () {red = brightness; green = t; blue = p;},
1808 function () {red = q; green = brightness; blue = p;},
1809 function () {red = p; green = brightness; blue = t;},
1810 function () {red = p; green = q; blue = brightness;},
1811 function () {red = t; green = p; blue = brightness;},
1812 function () {red = brightness; green = p; blue = q;},
1813 function () {red = brightness; green = t; blue = p;}
1816 var rgb = {r: red, g: green, b: blue};
1820 var r = Math.round(red).toString(16);
1821 if (r.length == 1) {
1824 var g = Math.round(green).toString(16);
1825 if (g.length == 1) {
1828 var b = Math.round(blue).toString(16);
1829 if (b.length == 1) {
1832 rgb.hex = "#" + r + g + b;
1835 Raphael.rgb2hsb = function (red, green, blue) {
1836 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
1841 if (typeof red == "string" && red.charAt(0) == "#") {
1842 if (red.length == 4) {
1843 blue = parseInt(red.substring(3), 16);
1844 green = parseInt(red.substring(2, 3), 16);
1845 red = parseInt(red.substring(1, 2), 16);
1847 blue = parseInt(red.substring(5), 16);
1848 green = parseInt(red.substring(3, 5), 16);
1849 red = parseInt(red.substring(1, 3), 16);
1852 if (red > 1 || green > 1 || blue > 1) {
1857 var max = Math.max(red, green, blue),
1858 min = Math.min(red, green, blue),
1863 return {h: 0, s: 0, b: max};
1865 var delta = (max - min);
1866 saturation = delta / max;
1868 hue = (green - blue) / delta;
1869 } else if (green == max) {
1870 hue = 2 + ((blue - red) / delta);
1872 hue = 4 + ((red - green) / delta);
1882 return {h: hue, s: saturation, b: brightness};
1884 Raphael.getRGB = function (colour) {
1885 var red, green, blue,
1886 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);
1889 blue = parseInt(rgb[2].substring(5), 16);
1890 green = parseInt(rgb[2].substring(3, 5), 16);
1891 red = parseInt(rgb[2].substring(1, 3), 16);
1894 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
1895 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
1896 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
1899 rgb = rgb[4].split(/\s*,\s*/);
1900 red = parseInt(rgb[0], 10);
1901 green = parseInt(rgb[1], 10);
1902 blue = parseInt(rgb[2], 10);
1905 rgb = rgb[5].split(/\s*,\s*/);
1906 red = parseInt(rgb[0], 10) * 2.55;
1907 green = parseInt(rgb[1], 10) * 2.55;
1908 blue = parseInt(rgb[2], 10) * 2.55;
1911 rgb = rgb[6].split(/\s*,\s*/);
1912 red = parseInt(rgb[0], 10);
1913 green = parseInt(rgb[1], 10);
1914 blue = parseInt(rgb[2], 10);
1915 return this.hsb2rgb(red, green, blue);
1918 rgb = rgb[7].split(/\s*,\s*/);
1919 red = parseInt(rgb[0], 10) * 2.55;
1920 green = parseInt(rgb[1], 10) * 2.55;
1921 blue = parseInt(rgb[2], 10) * 2.55;
1922 return this.hsb2rgb(red, green, blue);
1924 var rgb = {r: red, g: green, b: blue};
1925 var r = Math.round(red).toString(16);
1926 (r.length == 1) && (r = "0" + r);
1927 var g = Math.round(green).toString(16);
1928 (g.length == 1) && (g = "0" + g);
1929 var b = Math.round(blue).toString(16);
1930 (b.length == 1) && (b = "0" + b);
1931 rgb.hex = "#" + r + g + b;
1935 Raphael.getColor = function (value) {
1936 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
1937 var rgb = this.hsb2rgb(start.h, start.s, start.b);
1943 arguments.callee.start = {h: 0, s: 1, b: start.b};
1948 Raphael.getColor.reset = function () {
1949 this.start = undefined;
1951 Raphael.parsePathString = function (pathString) {
1952 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
1954 toString = function () {
1956 for (var i = 0, ii = this.length; i < ii; i++) {
1957 res += this[i][0] + this[i].join(",").substring(2);
1961 if (pathString.toString.toString() == toString.toString()) {
1964 pathString.replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*\s*,?\s*)+)/ig, function (a, b, c) {
1965 var params = [], name = b.toLowerCase();
1966 c.replace(/(-?\d*\.?\d*)\s*,?\s*/ig, function (a, b) {
1967 b && params.push(+b);
1969 while (params.length >= paramCounts[name]) {
1970 data.push([b].concat(params.splice(0, paramCounts[name])));
1971 if (!paramCounts[name]) {
1976 data.toString = toString;
1979 Raphael.pathDimensions = function (path) {
1980 var pathArray = path;
1981 if (typeof path == "string") {
1982 pathArray = this.parsePathString(path);
1984 pathArray = this.pathToAbsolute(pathArray);
1985 var x = [], y = [], length = 0;
1986 for (var i = 0, ii = pathArray.length; i < ii; i++) {
1987 switch (pathArray[i][0]) {
1991 x.push(pathArray[i][pathArray[i].length - 2]);
1992 y.push(pathArray[i][pathArray[i].length - 1]);
1995 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
1997 x.push(pathArray[i][j]);
1999 y.push(pathArray[i][j]);
2004 var minx = Math.min.apply(Math, x),
2005 miny = Math.min.apply(Math, y);
2009 width: Math.max.apply(Math, x) - minx,
2010 height: Math.max.apply(Math, y) - miny,
2015 Raphael.pathToRelative = function (pathArray) {
2017 if (typeof pathArray == "string") {
2018 pathArray = this.parsePathString(pathArray);
2020 var x = 0, y = 0, start = 0;
2021 if (pathArray[0][0] == "M") {
2022 x = pathArray[0][1];
2023 y = pathArray[0][2];
2025 res.push(pathArray[0]);
2027 for (var i = start, ii = pathArray.length; i < ii; i++) {
2029 if (pathArray[i][0] != pathArray[i][0].toLowerCase()) {
2030 res[i][0] = pathArray[i][0].toLowerCase();
2031 switch (res[i][0]) {
2033 res[i][1] = pathArray[i][1];
2034 res[i][2] = pathArray[i][2];
2036 res[i][4] = pathArray[i][4];
2037 res[i][5] = pathArray[i][5];
2038 res[i][6] = +(pathArray[i][6] - x).toFixed(3);
2039 res[i][7] = +(pathArray[i][7] - y).toFixed(3);
2042 res[i][1] = +(pathArray[i][1] - y).toFixed(3);
2045 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
2046 res[i][j] = +(pathArray[i][j] - ((j % 2) ? x : y)).toFixed(3);
2050 res[i] = pathArray[i];
2052 switch (res[i][0]) {
2056 x += res[i][res[i].length - 1];
2059 y += res[i][res[i].length - 1];
2062 x += res[i][res[i].length - 2];
2063 y += res[i][res[i].length - 1];
2066 res.toString = pathArray.toString;
2069 Raphael.pathToAbsolute = function (pathArray) {
2071 if (typeof pathArray == "string") {
2072 pathArray = this.parsePathString(pathArray);
2074 var x = 0, y = 0, start = 0;
2075 if (pathArray[0][0] == "M") {
2076 x = +pathArray[0][1];
2077 y = +pathArray[0][2];
2079 res[0] = pathArray[0];
2081 for (var i = start, ii = pathArray.length; i < ii; i++) {
2083 if (pathArray[i][0] != pathArray[i][0].toUpperCase()) {
2084 res[i][0] = pathArray[i][0].toUpperCase();
2085 switch (res[i][0]) {
2087 res[i][1] = pathArray[i][1];
2088 res[i][2] = pathArray[i][2];
2090 res[i][4] = pathArray[i][4];
2091 res[i][5] = pathArray[i][5];
2092 res[i][6] = +(pathArray[i][6] + x).toFixed(3);
2093 res[i][7] = +(pathArray[i][7] + y).toFixed(3);
2096 res[i][1] = +pathArray[i][1] + y;
2099 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
2100 res[i][j] = +pathArray[i][j] + ((j % 2) ? x : y);
2104 res[i] = pathArray[i];
2106 switch (res[i][0]) {
2116 x = res[i][res[i].length - 2];
2117 y = res[i][res[i].length - 1];
2120 res.toString = pathArray.toString;
2123 Raphael.pathEqualiser = function (path1, path2) {
2124 var data = [this.pathToAbsolute(this.parsePathString(path1)), this.pathToAbsolute(this.parsePathString(path2))],
2125 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}],
2126 processPath = function (path, d) {
2136 var nx = d.x + (d.x - (d.bx || d.x));
2137 var ny = d.y + (d.y - (d.by || d.y));
2138 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
2141 var nx = d.x + (d.x - (d.bx || d.x));
2142 var ny = d.y + (d.y - (d.by || d.y));
2143 path = ["Q", nx, ny, path[1], path[2]];
2146 path = ["L", path[1], d.y];
2149 path = ["L", d.x, path[1]];
2152 path = ["L", d.X, d.Y];
2157 edgeCases = function (a, b, i) {
2158 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
2159 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
2160 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
2161 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
2162 attrs[a].x = data[a][i][data[a][i].length - 2];
2163 attrs[a].y = data[a][i][data[a][i].length - 1];
2165 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
2166 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]];
2167 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
2168 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
2169 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
2170 var x = data[b][i][data[b][i].length - 2];
2171 var y = data[b][i][data[b][i].length - 1];
2172 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
2173 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
2175 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
2176 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
2177 attrs[b].x = data[b][i][data[b][i].length - 2];
2178 attrs[b].y = data[b][i][data[b][i].length - 1];
2180 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
2181 var x = data[b][i][data[b][i].length - 2];
2182 var y = data[b][i][data[b][i].length - 1];
2183 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
2184 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
2186 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
2187 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
2188 attrs[b].x = data[b][i][data[b][i].length - 2];
2189 attrs[b].y = data[b][i][data[b][i].length - 1];
2191 } else if (data[a][i][0] == "U") {
2192 data[a][i][0] = data[b][i][0];
2193 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
2194 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
2199 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
2200 data[0][i] = processPath(data[0][i], attrs[0]);
2201 data[1][i] = processPath(data[1][i], attrs[1]);
2202 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
2205 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
2206 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
2207 attrs[0].x = data[0][i][data[0][i].length - 2];
2208 attrs[0].y = data[0][i][data[0][i].length - 1];
2209 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
2210 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
2211 attrs[1].x = data[1][i][data[1][i].length - 2];
2212 attrs[1].y = data[1][i][data[1][i].length - 1];