2 * Raphael 0.5.10 - JavaScript Vector Library
4 * Copyright (c) 2008 Dmitry Baranovskiy (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);
14 function Matrix(m11, m12, m21, m22, dx, dy) {
16 [m11 || 1, m12 || 0, 0],
17 [m21 || 0, m22 || 1, 0],
22 C._getX = C._getY = C._getW = C._getH = function (x) { return x; };
25 Matrix.prototype.toString = function () {
26 return "progid:DXImageTransform.Microsoft.Matrix(M11=" + this.m[0][0] +
27 ", M12=" + this.m[1][0] + ", M21=" + this.m[0][1] + ", M22=" + this.m[1][1] +
28 ", Dx=" + this.m[2][0] + ", Dy=" + this.m[2][1] + ", sizingmethod='auto expand', filtertype='bilinear')";
30 var thePath = function (params, pathString, VML) {
31 var g = document.createElement("rvml:group"), gl = g.style;
32 gl.position = "absolute";
35 gl.width = VML.width + "px";
36 gl.height = VML.height + "px";
37 var el = document.createElement("rvml:shape"), ol = el.style;
38 ol.width = VML.width + "px";
39 ol.height = VML.height + "px";
41 if (params["class"]) {
42 el.className = params["class"];
44 el.coordsize = this.coordsize;
45 el.coordorigin = this.coordorigin;
47 VML.canvas.appendChild(g);
48 var p = new Element(el, g, VML);
49 setFillAndStroke(p, params);
50 if (params.gradient) {
51 addGrdientFill(p, params.gradient);
56 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
58 p.absolutely = function () {
59 this.isAbsolute = true;
62 p.relatively = function () {
63 this.isAbsolute = false;
66 p.redraw = function () {
68 var oldPath = this.path;
70 for (var i = 0, ii = oldPath.length; i < ii; i++) {
71 if (oldPath[i].type != "end") {
72 this[oldPath[i].type + "To"].apply(this, oldPath[i].arg);
79 p.moveTo = function (x, y) {
80 var d = this.isAbsolute?"m":"t";
81 var _getX = this.isAbsolute ? VML._getX : VML._getW;
82 var _getY = this.isAbsolute ? VML._getY : VML._getH;
83 d += Math.round(_getX(parseFloat(x, 10))) + " " + Math.round(_getY(parseFloat(y, 10)));
84 this[0].path = this.Path += d;
85 this.last.x = (this.isAbsolute ? 0 : this.last.x) + _getX(parseFloat(x, 10));
86 this.last.y = (this.isAbsolute ? 0 : this.last.y) + _getY(parseFloat(y, 10));
87 this.last.isAbsolute = this.isAbsolute;
88 this.path.push({type: "move", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
91 p.lineTo = function (x, y) {
92 var d = this.isAbsolute?"l":"r";
93 var _getX = this.isAbsolute ? VML._getX : VML._getW;
94 var _getY = this.isAbsolute ? VML._getY : VML._getH;
95 d += Math.round(_getX(parseFloat(x, 10))) + " " + Math.round(_getY(parseFloat(y, 10)));
96 this[0].path = this.Path += d;
97 this.last.x = (this.isAbsolute ? 0 : this.last.x) + _getX(parseFloat(x, 10));
98 this.last.y = (this.isAbsolute ? 0 : this.last.y) + _getY(parseFloat(y, 10));
99 this.last.isAbsolute = this.isAbsolute;
100 this.path.push({type: "line", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
103 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
104 // for more information of where this math came from visit:
105 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
106 x2 = (this.isAbsolute ? 0 : this.last.x) + x2;
107 y2 = (this.isAbsolute ? 0 : this.last.y) + y2;
108 var x1 = this.last.x,
112 k = (large_arc_flag == sweep_flag ? -1 : 1) *
113 Math.sqrt((rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
114 cx = k * rx * y / ry + (x1 + x2) / 2,
115 cy = k * -ry * x / rx + (y1 + y2) / 2,
116 d = sweep_flag ? (this.isAbsolute?"wa":"wr") : (this.isAbsolute?"at":"ar"),
117 _getX = this.isAbsolute ? VML._getX : VML._getW,
118 _getY = this.isAbsolute ? VML._getY : VML._getH,
119 left = Math.round(cx - rx),
120 top = Math.round(cy - ry);
121 d += [left, top, Math.round(left + rx * 2), Math.round(top + ry * 2), Math.round(x1), Math.round(y1), Math.round(_getX(parseFloat(x2, 10))), Math.round(_getX(parseFloat(y2, 10)))].join(", ");
122 this[0].path = this.Path += d;
123 this.last.x = (this.isAbsolute ? 0 : this.last.x) + _getX(parseFloat(x2, 10));
124 this.last.y = (this.isAbsolute ? 0 : this.last.y) + _getY(parseFloat(y2, 10));
125 this.last.isAbsolute = this.isAbsolute;
126 this.path.push({type: "arc", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
129 p.cplineTo = function (x1, y1, w1) {
131 return this.lineTo(x1, y1);
134 p._getX = this.isAbsolute ? VML._getX : VML._getW;
135 p._getY = this.isAbsolute ? VML._getY : VML._getH;
136 var x = Math.round(p._getX(Math.round(parseFloat(x1, 10) * 100) / 100));
137 var y = Math.round(p._getY(Math.round(parseFloat(y1, 10) * 100) / 100));
138 var w = Math.round(VML._getW(Math.round(parseFloat(w1, 10) * 100) / 100));
139 var d = this.isAbsolute?"c":"v";
140 var attr = [Math.round(this.last.x) + w, Math.round(this.last.y), x - w, y, x, y];
141 d += attr.join(" ") + " ";
142 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
143 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
144 this.last.bx = attr[2];
145 this.last.by = attr[3];
146 this[0].path = this.Path += d;
147 this.path.push({type: "cpline", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
151 p.curveTo = function () {
152 var d = this.isAbsolute?"c":"v";
153 var _getX = this.isAbsolute ? VML._getX : VML._getW;
154 var _getY = this.isAbsolute ? VML._getY : VML._getH;
155 if (arguments.length == 6) {
156 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + _getX(parseFloat(arguments[2], 10));
157 this.last.by = (this.isAbsolute ? 0 : this.last.y) + _getY(parseFloat(arguments[3], 10));
158 this.last.x = (this.isAbsolute ? 0 : this.last.x) + _getX(parseFloat(arguments[4], 10));
159 this.last.y = (this.isAbsolute ? 0 : this.last.y) + _getY(parseFloat(arguments[5], 10));
160 d += Math.round(_getX(parseFloat(arguments[0], 10))) + " " +
161 Math.round(_getY(parseFloat(arguments[1], 10))) + " " +
162 Math.round(_getX(parseFloat(arguments[2], 10))) + " " +
163 Math.round(_getY(parseFloat(arguments[3], 10))) + " " +
164 Math.round(_getX(parseFloat(arguments[4], 10))) + " " +
165 Math.round(_getY(parseFloat(arguments[5], 10))) + " ";
166 this.last.isAbsolute = this.isAbsolute;
168 if (arguments.length == 4) {
169 var bx = this.last.x * 2 - this.last.bx;
170 var by = this.last.y * 2 - this.last.by;
171 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + _getX(parseFloat(arguments[0], 10));
172 this.last.by = (this.isAbsolute ? 0 : this.last.y) + _getY(parseFloat(arguments[1], 10));
173 this.last.x = (this.isAbsolute ? 0 : this.last.x) + _getX(parseFloat(arguments[2], 10));
174 this.last.y = (this.isAbsolute ? 0 : this.last.y) + _getY(parseFloat(arguments[3], 10));
175 d += [Math.round(bx), Math.round(by),
176 Math.round(_getX(parseFloat(arguments[0], 10))),
177 Math.round(_getY(parseFloat(arguments[1], 10))),
178 Math.round(_getX(parseFloat(arguments[2], 10))),
179 Math.round(_getY(parseFloat(arguments[3], 10)))].join(" ");
181 this[0].path = this.Path += d;
182 this.path.push({type: "curve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
185 p.addRoundedCorner = function (r, dir) {
186 var R = .5522 * r, rollback = this.isAbsolute, o = this;
189 rollback = function () {
193 rollback = function () {};
199 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
202 o.curveTo(-R, 0, -r, r - R, -r, r);
209 o.curveTo(R, 0, r, -(r - R), r, -r);
212 o.curveTo(R, 0, r, r - R, r, r);
219 o.curveTo(0, -R, -(R - r), -r, r, -r);
222 o.curveTo(0, -R, R - r, -r, -r, -r);
229 o.curveTo(0, R, -(R - r), r, r, r);
232 o.curveTo(0, R, R - r, r, -r, r);
237 actions[dir.charAt(0)]()[dir.charAt(1)]();
241 p.andClose = function () {
242 this[0].path = (this.Path += "x e");
245 if (typeof pathString == "string") {
247 C.pathfinder(p, pathString);
251 var setFillAndStroke = function (o, params) {
253 o.attrs = o.attrs || {};
254 for (var par in params) {
255 o.attrs[par] = params[par];
257 params["font-family"] && (s.fontFamily = params["font-family"]);
258 params["font-size"] && (s.fontSize = params["font-size"]);
259 params["font"] && (s.font = params["font"]);
260 params["font-weight"] && (s.fontWeight = params["font-weight"]);
261 if (typeof params.opacity != "undefined" || typeof params["stroke-width"] != "undefined" || typeof params.fill != "undefined" || typeof params.stroke != "undefined") {
263 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || document.createElement("rvml:fill");
264 if ("fill-opacity" in params || "opacity" in params) {
265 fill.opacity = ((params["fill-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
270 if (fill.on == undefined || params.fill == "none") {
273 if (fill.on && params.fill) {
274 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
279 fill.color = params.fill;
285 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || document.createElement("rvml:stroke");
286 if ((params.stroke && params.stroke != "none") || params["stroke-width"] || params["stroke-opacity"] || params["stroke-dasharray"]) {
289 if (params.stroke == "none" || typeof stroke.on == "undefined") {
292 if (stroke.on && params.stroke) {
293 stroke.color = params.stroke;
295 stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
296 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
297 stroke.miterlimit = params["stroke-miterlimit"] || 8;
298 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
299 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"], 10) || 1) * 12 / 16);
300 if (params["stroke-dasharray"]) {
304 "-.": "shortdashdot",
305 "-..": "shortdashdotdot",
310 "--.": "longdashdot",
311 "--..": "longdashdotdot"
313 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
315 o.appendChild(stroke);
318 var addGrdientFill = function (o, gradient) {
319 o.attrs = o.attrs || {};
320 o.attrs.gradient = gradient;
322 var fill = o.getElementsByTagName("fill");
326 fill = document.createElement("rvml:fill");
328 if (gradient.dots.length) {
330 fill.method = "none";
331 fill.type = (gradient.type.toLowerCase() == "linear") ? "gradient" : "gradientTitle";
332 if (typeof gradient.dots[0].color != "undefined") {
333 fill.color = gradient.dots[0].color || "#000";
335 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
336 fill.color2 = gradient.dots[gradient.dots.length - 1].color || "#000";
339 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
340 if (gradient.dots[i].offset) {
341 colors.push(gradient.dots[i].offset + " " + gradient.dots[i].color);
344 var fillOpacity = gradient.dots[0].opacity || 1;
345 var fillOpacity2 = gradient.dots[gradient.dots.length - 1].opacity || 1;
347 fill.colors.value = colors.join(",");
348 fillOpacity2 += fillOpacity;
349 fillOpacity = fillOpacity2 - fillOpacity;
350 fillOpacity2 -= fillOpacity;
352 fill.setAttribute("opacity", fillOpacity);
353 fill.setAttribute("opacity2", fillOpacity2);
354 if (gradient.vector) {
355 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;
356 fill.angle = 270 - angle;
358 if (gradient.type.toLowerCase() == "radial") {
360 fill.focusposition = "0.5 0.5";
364 var Element = function (node, group, vml) {
376 this.rotate = function (deg) {
377 if (deg == undefined) {
381 this.Group.style.rotation = Rotation;
385 Element.prototype.setBox = function (params) {
386 var gs = this.Group.style,
388 for (var i in params) {
389 this.attrs[i] = params[i];
391 var attr = this.attrs, x, y, w, h;
394 x = attr.cx - attr.r;
395 y = attr.cy - attr.r;
399 x = attr.cx - attr.rx;
400 y = attr.cy - attr.ry;
412 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("");
417 var left = this.vml.width / 2 - w / 2,
418 top = this.vml.height / 2 - h / 2;
419 gs.position = "absolute";
420 gs.left = x - left + "px";
421 gs.top = y - top + "px";
426 gs.width = this.vml.width + "px";
427 gs.height = this.vml.height + "px";
428 os.position = "absolute";
430 os.left = left + "px";
432 os.height = h + "px";
434 Element.prototype.hide = function () {
435 this.Group.style.display = "none";
438 Element.prototype.show = function () {
439 this.Group.style.display = "block";
442 Element.prototype.translate = function (x, y) {
443 if (x == undefined && y == undefined) {
444 return {x: this.X, y: this.Y};
448 this.Group.style.left = this.X + "px";
449 this.Group.style.top = this.Y + "px";
453 Element.prototype.matrix = function (xx, xy, yx, yy, dx, dy) {
454 tMatrix = new Matrix(xx, xy, yx, yy, dx, dy);
455 this.Group.style.filter = tMatrix;
458 Element.prototype.scale = function (x, y) {
459 if (x == undefined && y == undefined) {
464 if (x != 0 && !(x == 1 && y == 1)) {
465 var dirx = Math.round(x / Math.abs(x)),
466 diry = Math.round(y / Math.abs(y)),
468 if (dirx != 1 || diry != 1) {
469 s.filter = new Matrix(dirx, 0, 0, diry, 0, 0);
471 var width = parseInt(s.width, 10) * x * dirx;
472 var height = parseInt(s.height, 10) * y * diry;
473 var left = parseInt(s.left, 10);
474 var top = parseInt(s.top, 10);
475 s.left = this.X = left + this.W / 2 - width / 2;
476 s.top = this.Y = top + this.H / 2 - height / 2;
477 s.width = this.W = width;
478 s.height = this.H = height;
482 Element.prototype.getBBox = function () {
484 x: this.Group.offsetLeft,
485 y: this.Group.offsetTop,
486 width: this.Group.offsetWidth,
487 height: this.Group.offsetHeight
490 Element.prototype.remove = function () {
491 this[0].parentNode.removeChild(this[0]);
492 this.Group.parentNode.removeChild(this.Group);
493 this.shape && this.shape.parentNode.removeChild(this.shape);
495 Element.prototype.attr = function () {
496 if (arguments.length == 1 && typeof arguments[0] == "string") {
497 return this.attrs[arguments[0]];
499 if (this.attrs && arguments.length == 1 && arguments[0] instanceof Array) {
501 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
502 values[arguments[0][i]] = this.attrs[arguments[0][i]];
506 if (this[0].tagName.toLowerCase() == "group") {
507 var children = this[0].childNodes;
508 this.attrs = this.attrs || {};
509 if (arguments.length == 2) {
510 this.attrs[arguments[0]] = arguments[1];
511 } else if (arguments.length == 1 || typeof arguments[0] == "object") {
512 for (var j in arguments[0]) {
513 this.attrs[j] = arguments[0][j];
516 for (var i = 0, ii = children.length; i < ii; i++) {
517 this.attr.apply(new item(children[i], this[0], this.vml), arguments);
521 if (arguments.length == 2) {
523 params[arguments[0]] = arguments[1];
525 if (arguments.length == 1 && typeof arguments[0] == "object") {
526 params = arguments[0];
529 setFillAndStroke(this, params);
531 if (params.gradient) {
532 addGrdientFill(this, params.gradient);
534 if (params.text && this.type == "text") {
535 this[0].string = params.text;
538 this[0].id = params.id;
544 Element.prototype.toFront = function () {
545 this.Group.parentNode.appendChild(this.Group);
548 Element.prototype.toBack = function () {
549 if (this.Group.parentNode.firstChild != this.Group) {
550 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
554 var theCircle = function (vml, x, y, r) {
555 var g = document.createElement("rvml:group");
556 var o = document.createElement("rvml:oval");
558 vml.canvas.appendChild(g);
559 var res = new Element(o, g, vml);
560 setFillAndStroke(res, {stroke: "#000", fill: "none"});
561 res.setBox({x: x - r, y: y - r, w: r * 2, h: r * 2});
568 var theRect = function (vml, x, y, w, h, r) {
569 var g = document.createElement("rvml:group");
570 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect");
572 o.arcsize = r / (Math.min(w, h));
575 vml.canvas.appendChild(g);
576 var res = new Element(o, g, vml);
577 setFillAndStroke(res, {stroke: "#000"});
578 res.setBox({x: x, y: y, w: w, h: h});
587 var theEllipse = function (vml, x, y, rx, ry) {
588 var g = document.createElement("rvml:group");
589 var o = document.createElement("rvml:oval");
591 vml.canvas.appendChild(g);
592 var res = new Element(o, g, vml);
593 setFillAndStroke(res, {stroke: "#000"});
594 res.setBox({x: x - rx, y: y - ry, w: rx * 2, h: ry * 2});
599 res.type = "ellipse";
602 var theImage = function (vml, src, x, y, w, h) {
603 var g = document.createElement("rvml:group");
604 var o = document.createElement("rvml:image");
607 vml.canvas.appendChild(g);
608 var res = new Element(o, g, vml);
610 res.setBox({x: x, y: y, w: w, h: h});
617 var theText = function (vml, x, y, text) {
619 var g = document.createElement("rvml:group"), gs = g.style;
620 var el = document.createElement("rvml:shape"), ol = el.style;
621 var path = document.createElement("rvml:path"), ps = path.style;
622 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
623 path.textpathok = true;
624 ol.width = vml.width;
625 ol.height = vml.height;
626 gs.position = "absolute";
629 gs.width = vml.width;
630 gs.height = vml.height;
631 var o = document.createElement("rvml:textpath");
634 o.coordsize = vml.coordsize;
635 o.coordorigin = vml.coordorigin;
637 el.appendChild(path);
639 vml.canvas.appendChild(g);
640 var res = new Element(o, g, vml);
650 var theGroup = function (vml) {
651 var el = document.createElement("rvml:group"), els = el.style;
652 els.position = "absolute";
655 els.width = vml.width;
656 els.height = vml.height;
658 vml.canvas.appendChild(el);
660 var res = new Element(el, el, vml);
662 if (f.charAt(0) != "_" && typeof vml[f] == "function") {
663 res[f] = (function (f) {
665 var e = vml[f].apply(vml, arguments);
666 el.appendChild(e[0].parentNode);
675 r._create = function () {
676 // container, width, height
677 // x, y, width, height
678 var container, width, height;
679 if (typeof arguments[0] == "string") {
680 container = document.getElementById(arguments[0]);
681 width = arguments[1];
682 height = arguments[2];
684 if (typeof arguments[0] == "object") {
685 container = arguments[0];
686 width = arguments[1];
687 height = arguments[2];
689 if (typeof arguments[0] == "number") {
693 width = arguments[2];
694 height = arguments[3];
697 throw new Error("VML container not found.");
699 if (!document.namespaces["rvml"]) {
700 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
701 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
703 var c = document.createElement("div"),
704 r = C.canvas = document.createElement("rvml:group"),
705 cs = c.style, rs = r.style;
708 width = width || "320px";
709 height = height || "200px";
710 cs.clip = "rect(0 " + width + " " + height + " 0)";
711 cs.position = "absolute";
714 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
715 r.coordorigin = "0 0";
717 var b = document.createElement("rvml:rect"), bs = b.style;
718 bs.left = bs.top = 0;
720 bs.height = rs.height;
721 b.filled = b.stroked = "f";
725 if (container == 1) {
726 document.body.appendChild(c);
727 cs.position = "absolute";
739 cs.width = container.style.width = width;
740 cs.height = container.style.height = height;
741 if (container.firstChild) {
742 container.insertBefore(c, container.firstChild);
744 container.appendChild(c);
747 for (var prop in C) {
748 container[prop] = C[prop];
750 container.clear = function () {
752 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
753 if (r.childNodes[i] != b) {
754 todel.push(r.childNodes[i]);
757 for (i = 0, ii = todel.length; i < ii; i++) {
758 r.removeChild(todel[i]);
763 C.remove = function () {
764 C.canvas.parentNode.parentNode.removeChild(C.canvas.parentNode);
768 Matrix.prototype.toString = function () {
769 return "matrix(" + this.m[0][0] +
770 ", " + this.m[1][0] + ", " + this.m[0][1] + ", " + this.m[1][1] +
771 ", " + this.m[2][0] + ", " + this.m[2][1] + ")";
773 var thePath = function (params, pathString, SVG) {
774 var el = document.createElementNS(SVG.svgns, "path");
775 el.setAttribute("fill", "none");
777 SVG.canvas.appendChild(el);
779 var p = new Element(el, SVG);
781 setFillAndStroke(p, params);
782 // for (var attr in params) {
783 // if (params.gradient) {
784 // addGrdientFill(el, params.gradient, SVG);
786 // el.setAttribute(attr, params[attr]);
790 // for (var attr in params) {
791 // p.attrs[attr] = params[attr];
795 p.last = {x: 0, y: 0, bx: 0, by: 0};
796 p.absolutely = function () {
797 this.isAbsolute = true;
800 p.relatively = function () {
801 this.isAbsolute = false;
804 p.redraw = function () {
805 this[0].setAttribute("d", "M0 0");
806 var oldPath = this.path;
808 for (var i = 0, ii = oldPath.length; i < ii; i++) {
809 if (oldPath[i].type != "end") {
810 this[oldPath[i].type + "To"].apply(this, oldPath[i].arg);
817 p.moveTo = function (x, y) {
818 var d = this.isAbsolute?"M":"m";
819 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
820 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
821 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
822 var oldD = this[0].getAttribute("d") || "";
823 this[0].setAttribute("d", oldD + d);
824 this.last.x = (this.isAbsolute ? 0 : this.last.x) + SVG._getX(parseFloat(x, 10));
825 this.last.y = (this.isAbsolute ? 0 : this.last.y) + SVG._getY(parseFloat(y, 10));
826 this.path.push({type: "move", arg: arguments, pos: this.isAbsolute});
829 p.lineTo = function (x, y) {
830 this.last.x = (this.isAbsolute ? 0 : this.last.x) + SVG._getX(parseFloat(x, 10));
831 this.last.y = (this.isAbsolute ? 0 : this.last.y) + SVG._getY(parseFloat(y, 10));
832 var d = this.isAbsolute?"L":"l";
833 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
834 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
835 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
836 var oldD = this[0].getAttribute("d") || "";
837 this[0].setAttribute("d", oldD + d);
838 this.path.push({type: "line", arg: arguments, pos: this.isAbsolute});
841 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
842 var d = this.isAbsolute ? "A" : "a";
843 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
844 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
845 d += [SVG._getW(parseFloat(rx, 10)), SVG._getH(parseFloat(ry, 10)), 0, large_arc_flag, sweep_flag, _getX(parseFloat(x, 10)), _getY(parseFloat(y, 10))].join(" ");
846 var oldD = this[0].getAttribute("d") || "";
847 this[0].setAttribute("d", oldD + d);
848 this.last.x = SVG._getX(parseFloat(x, 10));
849 this.last.y = SVG._getY(parseFloat(y, 10));
850 this.path.push({type: "arc", arg: arguments, pos: this.isAbsolute});
853 p.cplineTo = function (x1, y1, w1) {
855 return this.lineTo(x1, y1);
858 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
859 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
860 var x = p._getX(Math.round(parseFloat(x1, 10) * 100) / 100);
861 var y = p._getY(Math.round(parseFloat(y1, 10) * 100) / 100);
862 var w = SVG._getW(Math.round(parseFloat(w1, 10) * 100) / 100);
863 var d = this.isAbsolute?"C":"c";
864 var attr = [this.last.x + w, this.last.y, x - w, y, x, y];
865 for (var i = 0, ii = attr.length; i < ii; i++) {
868 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
869 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
870 this.last.bx = attr[2];
871 this.last.by = attr[3];
872 var oldD = this[0].getAttribute("d") || "";
873 this[0].setAttribute("d", oldD + d);
874 this.path.push({type: "cpline", arg: arguments, pos: this.isAbsolute});
878 p.curveTo = function () {
880 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
881 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
882 if (arguments.length == 6) {
883 var d = this.isAbsolute?"C":"c";
884 for (var i = 0, ii = arguments.length; i < ii; i++) {
885 d += p[(i % 2 == 0) ? "_getX" : "_getY"](Math.round(parseFloat(arguments[i], 10) * 100) / 100) + " ";
887 this.last.x = (this.isAbsolute ? 0 : this.last.x) + p._getX((parseFloat(arguments[4], 10) * 100) / 100);
888 this.last.y = (this.isAbsolute ? 0 : this.last.y) + p._getY((parseFloat(arguments[5], 10) * 100) / 100);
889 this.last.bx = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
890 this.last.by = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
892 if (arguments.length == 4) {
893 var d = this.isAbsolute?"S":"s";
894 for (var i = 0, ii = arguments.length; i < ii; i++) {
895 d += p[i % 2 == 0 ? "_getX" : "_getY"]((parseFloat(arguments[i], 10) * 100) / 100) + " ";
898 this.last.x = (this.isAbsolute ? 0 : this.last.x) + p._getX((parseFloat(arguments[2], 10) * 100) / 100);
899 this.last.y = (this.isAbsolute ? 0 : this.last.y) + p._getY((parseFloat(arguments[3], 10) * 100) / 100);
900 this.last.bx = p._getX((parseFloat(arguments[0], 10) * 100) / 100);
901 this.last.by = p._getY((parseFloat(arguments[1], 10) * 100) / 100);
903 var oldD = this[0].getAttribute("d") || "";
904 this[0].setAttribute("d", oldD + d);
905 this.path.push({type: "curve", arg: arguments, pos: this.isAbsolute});
908 p.addRoundedCorner = function (r, dir) {
909 var R = .5522 * r, rollback = this.isAbsolute, o = this;
912 rollback = function () {
916 rollback = function () {};
922 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
925 o.curveTo(-R, 0, -r, r - R, -r, r);
932 o.curveTo(R, 0, r, -(r - R), r, -r);
935 o.curveTo(R, 0, r, r - R, r, r);
942 o.curveTo(0, -R, -(R - r), -r, r, -r);
945 o.curveTo(0, -R, R - r, -r, -r, -r);
952 o.curveTo(0, R, -(R - r), r, r, r);
955 o.curveTo(0, R, R - r, r, -r, r);
960 actions[dir[0]]()[dir[1]]();
964 p.andClose = function () {
965 var oldD = this[0].getAttribute("d") || "";
966 this[0].setAttribute("d", oldD + "Z ");
967 this.path.push({type: "end"});
970 if (typeof pathString == "string") {
972 C.pathfinder(p, pathString);
976 var addGrdientFill = function (o, gradient, SVG) {
977 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
978 el.id = "raphael-gradient-" + SVG.gradients++;
979 if (gradient.vector && gradient.vector.length) {
980 el.setAttribute("x1", gradient.vector[0]);
981 el.setAttribute("y1", gradient.vector[1]);
982 el.setAttribute("x2", gradient.vector[2]);
983 el.setAttribute("y2", gradient.vector[3]);
985 SVG.defs.appendChild(el);
986 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
987 var stop = document.createElementNS(SVG.svgns, "stop");
988 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
989 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
990 if (typeof gradient.dots[i].opacity != "undefined") {
991 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
993 el.appendChild(stop);
995 o.setAttribute("fill", "url(#" + el.id + ")");
997 var setFillAndStroke = function (o, params) {
1002 "-..": [3, 1, 1, 1, 1, 1],
1006 "- .": [4, 3, 1, 3],
1007 "--.": [8, 3, 1, 3],
1008 "--..": [8, 3, 1, 3, 1, 3]
1010 for (var att in params) {
1011 var value = params[att];
1012 o.attrs[att] = value;
1017 o[0].setAttribute(att, o.svg._getX(value));
1022 o[0].setAttribute(att, o.svg._getY(value));
1025 o[0].setAttribute(att, o.svg._getW(value));
1028 o[0].setAttribute(att, o.svg._getH(value));
1031 addGrdientFill(o[0], value, o.svg);
1033 case "stroke-dasharray":
1034 value = dasharray[value.toLowerCase()];
1036 var width = params["stroke-width"] || o.attr("stroke-width") || "1",
1037 butt = {round: width, square: width, butt: 0}[o.attr("stroke-linecap")] || 0,
1039 for (var i = 0, ii = value.length; i < ii; i++) {
1040 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
1042 value = dashes.join(",");
1043 o[0].setAttribute(att, value);
1047 if (o.type == "text") {
1048 o[0].childNodes.length && o[0].removeChild(o[0].firstChild);
1049 o[0].appendChild(document.createTextNode(value));
1053 var isURL = value.match(/^url\(([^\)]+)\)$/i);
1055 var el = document.createElementNS(o.svg.svgns, "pattern");
1056 var ig = document.createElementNS(o.svg.svgns, "image");
1058 el.id = "raphael-pattern-" + o.svg.gradients++;
1059 el.setAttribute("x", 0);
1060 el.setAttribute("y", 0);
1061 el.setAttribute("patternUnits", "userSpaceOnUse");
1062 ig.setAttribute("x", 0);
1063 ig.setAttribute("y", 0);
1064 ig.setAttributeNS(o.svg.xlink, "href", isURL[1]);
1066 var img = document.createElement("img");
1068 img.style.position = "absolute";
1069 img.style.top = "-9999em";
1070 img.style.left = "-9999em";
1071 img.onload = function () {
1072 el.setAttribute("width", this.offsetWidth);
1073 el.setAttribute("height", this.offsetHeight);
1074 ig.setAttribute("width", this.offsetWidth);
1075 ig.setAttribute("height", this.offsetHeight);
1076 document.body.removeChild(this);
1078 document.body.appendChild(img);
1079 o.svg.defs.appendChild(el);
1080 o[0].style.fill = "url(#" + el.id + ")";
1081 o[0].setAttribute("fill", "url(#" + el.id + ")");
1085 var cssrule = att.replace(/(\-.)/g, function (w) {
1086 return w.substring(1).toUpperCase();
1088 o[0].style[cssrule] = value;
1089 // Need following line for Firefox
1090 o[0].setAttribute(att, value);
1095 var Element = function (node, svg) {
1098 Rotation = {deg: 0, x: 0, y: 0},
1105 this.attrs = this.attrs || {};
1106 this.transformations = []; // rotate, translate, scale, matrix
1107 this.rotate = function (deg) {
1108 if (deg == undefined) {
1109 return Rotation.deg;
1111 var bbox = this.getBBox();
1112 Rotation.deg += deg;
1114 this.transformations[0] = ("rotate(" + Rotation.deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
1116 this.transformations[0] = "";
1118 this[0].setAttribute("transform", this.transformations.join(" "));
1121 this.translate = function (x, y) {
1122 if (x == undefined && y == undefined) {
1123 return {x: X, y: Y};
1128 this.transformations[1] = "translate(" + X + "," + Y + ")";
1130 this.transformations[1] = "";
1132 this[0].setAttribute("transform", this.transformations.join(" "));
1135 this.scale = function (x, y) {
1136 if (x == undefined && y == undefined) {
1137 return {x: ScaleX, y: ScaleY};
1140 if (x != 0 && !(x == 1 && y == 1)) {
1143 if (!(ScaleX == 1 && ScaleY == 1)) {
1144 var bbox = this.getBBox(),
1145 dx = bbox.x * (1 - ScaleX) + (bbox.width / 2 - bbox.width * ScaleX / 2),
1146 dy = bbox.y * (1 - ScaleY) + (bbox.height / 2 - bbox.height * ScaleY / 2);
1147 this.transformations[2] = new Matrix(ScaleX, 0, 0, ScaleY, dx, dy);
1149 this.transformations[2] = "";
1151 this[0].setAttribute("transform", this.transformations.join(" "));
1156 Element.prototype.hide = function () {
1157 this[0].style.display = "none";
1160 Element.prototype.show = function () {
1161 this[0].style.display = "block";
1165 Element.prototype.matrix = function (xx, xy, yx, yy, dx, dy) {
1166 this.transformations[3] = new Matrix(xx, xy, yx, yy, dx, dy);
1167 this[0].setAttribute("transform", this.transformations.join(" "));
1170 Element.prototype.remove = function () {
1171 this[0].parentNode.removeChild(this[0]);
1173 Element.prototype.getBBox = function () {
1174 return this[0].getBBox();
1176 Element.prototype.attr = function () {
1177 if (arguments.length == 1 && typeof arguments[0] == "string") {
1178 return this[0].getAttribute(arguments[0]);
1180 if (arguments.length == 1 && arguments[0] instanceof Array) {
1182 for (var j in arguments[0]) {
1183 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1187 if (arguments.length == 2) {
1189 params[arguments[0]] = arguments[1];
1190 setFillAndStroke(this, params);
1191 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1192 setFillAndStroke(this, arguments[0]);
1196 Element.prototype.toFront = function () {
1197 this[0].parentNode.appendChild(this[0]);
1200 Element.prototype.toBack = function () {
1201 if (this[0].parentNode.firstChild != this[0]) {
1202 this[0].parentNode.insertBefore(this[0], this[0].parentNode.firstChild);
1206 var theCircle = function (svg, x, y, r) {
1207 var el = document.createElementNS(svg.svgns, "circle");
1208 el.setAttribute("cx", svg._getX(x));
1209 el.setAttribute("cy", svg._getY(y));
1210 el.setAttribute("r", r);
1211 el.setAttribute("fill", "none");
1212 el.setAttribute("stroke", "#000");
1214 svg.canvas.appendChild(el);
1216 var res = new Element(el, svg);
1217 res.attrs = res.attrs || {};
1221 res.attrs.stroke = "#000";
1222 res.type = "circle";
1225 var theRect = function (svg, x, y, w, h, r) {
1226 var el = document.createElementNS(svg.svgns, "rect");
1227 el.setAttribute("x", svg._getX(x));
1228 el.setAttribute("y", svg._getY(y));
1229 el.setAttribute("width", svg._getW(w));
1230 el.setAttribute("height", svg._getH(h));
1232 el.setAttribute("rx", r);
1233 el.setAttribute("ry", r);
1235 el.setAttribute("fill", "none");
1236 el.setAttribute("stroke", "#000");
1238 svg.canvas.appendChild(el);
1240 var res = new Element(el, svg);
1241 res.attrs = res.attrs || {};
1244 res.attrs.width = w;
1245 res.attrs.height = h;
1246 res.attrs.stroke = "#000";
1248 res.attrs.rx = res.attrs.ry = r;
1253 var theEllipse = function (svg, x, y, rx, ry) {
1254 var el = document.createElementNS(svg.svgns, "ellipse");
1255 el.setAttribute("cx", svg._getX(x));
1256 el.setAttribute("cy", svg._getY(y));
1257 el.setAttribute("rx", svg._getW(rx));
1258 el.setAttribute("ry", svg._getH(ry));
1259 el.setAttribute("fill", "none");
1260 el.setAttribute("stroke", "#000");
1262 svg.canvas.appendChild(el);
1264 var res = new Element(el, svg);
1265 res.attrs = res.attrs || {};
1270 res.attrs.stroke = "#000";
1271 res.type = "ellipse";
1274 var theImage = function (svg, src, x, y, w, h) {
1275 var el = document.createElementNS(svg.svgns, "image");
1276 el.setAttribute("x", svg._getX(x));
1277 el.setAttribute("y", svg._getY(y));
1278 el.setAttribute("width", svg._getW(w));
1279 el.setAttribute("height", svg._getH(h));
1280 el.setAttributeNS(svg.xlink, "href", src);
1282 svg.canvas.appendChild(el);
1284 var res = new Element(el, svg);
1285 res.attrs = res.attrs || {};
1288 res.attrs.width = w;
1289 res.attrs.height = h;
1293 var theText = function (svg, x, y, text) {
1294 var el = document.createElementNS(svg.svgns, "text");
1295 el.setAttribute("x", x);
1296 el.setAttribute("y", y);
1297 el.setAttribute("text-anchor", "middle");
1298 el.setAttribute("fill", "#000");
1300 el.appendChild(document.createTextNode(text));
1303 svg.canvas.appendChild(el);
1305 var res = new Element(el, svg);
1306 res.attrs = res.attrs || {};
1309 res.attrs.fill = "#000";
1313 var theGroup = function (svg) {
1314 var el = document.createElementNS(svg.svgns, "g");
1316 svg.canvas.appendChild(el);
1318 var i = new Element(el, svg);
1319 for (var f in svg) {
1320 if (f[0] != "_" && typeof svg[f] == "function") {
1321 i[f] = (function (f) {
1322 return function () {
1323 var e = svg[f].apply(svg, arguments);
1324 el.appendChild(e[0]);
1333 r._create = function () {
1334 // container, width, height
1335 // x, y, width, height
1336 if (typeof arguments[0] == "string") {
1337 var container = document.getElementById(arguments[0]);
1338 var width = arguments[1];
1339 var height = arguments[2];
1341 if (typeof arguments[0] == "object") {
1342 var container = arguments[0];
1343 var width = arguments[1];
1344 var height = arguments[2];
1346 if (typeof arguments[0] == "number") {
1350 width = arguments[2],
1351 height = arguments[3];
1354 throw new Error("SVG container not found.");
1356 C.canvas = document.createElementNS(C.svgns, "svg");
1357 C.canvas.setAttribute("width", width || 320);
1358 C.width = width || 320;
1359 C.canvas.setAttribute("height", height || 200);
1360 C.height = height || 200;
1361 if (container == 1) {
1362 document.body.appendChild(C.canvas);
1363 C.canvas.style.position = "absolute";
1364 C.canvas.style.left = x + "px";
1365 C.canvas.style.top = y + "px";
1367 if (container.firstChild) {
1368 container.insertBefore(C.canvas, container.firstChild);
1370 container.appendChild(C.canvas);
1375 clear: function () {
1376 while (this.canvas.firstChild) {
1377 this.canvas.removeChild(this.canvas.firstChild);
1379 this.defs = document.createElementNS(C.svgns, "defs");
1381 this.canvas.appendChild(this.defs);
1384 for (var prop in C) {
1385 if (prop != "create") {
1386 container[prop] = C[prop];
1392 C.remove = function () {
1393 C.canvas.parentNode.removeChild(C.canvas);
1395 C.svgns = "http://www.w3.org/2000/svg";
1396 C.xlink = "http://www.w3.org/1999/xlink";
1398 if (type == "VML" || type == "SVG") {
1399 C.circle = function (x, y, r) {
1400 return theCircle(this, x, y, r);
1402 C.rect = function (x, y, w, h, r) {
1403 return theRect(this, x, y, w, h, r);
1405 C.ellipse = function (x, y, rx, ry) {
1406 return theEllipse(this, x, y, rx, ry);
1408 C.path = function (params, pathString) {
1409 return thePath(params, pathString, this);
1411 C.image = function (src, x, y, w, h) {
1412 return theImage(this, src, x, y, w, h);
1414 C.text = function (x, y, text) {
1415 return theText(this, x, y, text);
1417 C.group = function () {
1418 return theGroup(this);
1420 C.linerect = function (x, y, w, h, r) {
1421 if (r && parseInt(r, 10)) {
1422 return this.path({stroke: "#000"}).moveTo(x + r, y).lineTo(x + w - r, y).addRoundedCorner(r, "rd").lineTo(x + w, y + h - r).addRoundedCorner(r, "dl").lineTo(x + r, y + h).addRoundedCorner(r, "lu").lineTo(x, y + r).addRoundedCorner(r, "ur").andClose();
1424 return this.path({stroke: "#000"}).moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).andClose();
1426 C.drawGrid = function (x, y, w, h, wv, hv, color) {
1427 color = color || "#000";
1428 var p = this.path({stroke: color, "stroke-width": 1})
1429 .moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).lineTo(x, y);
1430 for (var i = 1; i < hv; i++) {
1431 p.moveTo(x, y + i * Math.round(h / hv)).lineTo(x + w, y + i * Math.round(h / hv));
1433 for (var i = 1; i < wv; i++) {
1434 p.moveTo(x + i * Math.round(w / wv), y).lineTo(x + i * Math.round(w / wv), y + h);
1438 C.setGrid = function (xmin, ymin, xmax, ymax, w, h) {
1439 var xc = (xmax - xmin) / w;
1440 var yc = (ymax - ymin) / h;
1441 this._getX = function (x) {
1442 return xmin + x * xc;
1444 this._getY = function (y) {
1445 return ymin + y * yc;
1447 this._getW = function (w) {
1450 this._getH = function (h) {
1454 C.clearGrid = function () {
1455 this._getX = this._getY = this._getW = this._getH = function (x) { return x; };
1457 C.safari = function () {
1458 if (r.type == "SVG") {
1459 var rect = C.rect(-C.width, -C.height, C.width * 3, C.height * 3).attr({stroke: "none"});
1460 setTimeout(function () {rect.remove();}, 0);
1463 Element.prototype.animateTo = function (x, y, ms, callback) {
1464 clearTimeout(this.animation_in_progress);
1465 if ("cx" in this.attrs || "x" in this.attrs) {
1466 var is_round = ("cx" in this.attrs),
1467 X = this.attrs.cx || this.attrs.x,
1468 Y = this.attrs.cy || this.attrs.y;
1469 if (x == X && y == Y) {
1475 plus = Y - coeff * X,
1476 alpha = Math.atan(this.coeff);
1477 this.xs = this.step * Math.cos(alpha);
1481 var start = new Date(),
1484 var time = (new Date()).getTime() - start.getTime();
1486 var x1 = X + time * dx / ms;
1487 var y1 = x1 * coeff + plus;
1488 that.attr(is_round ? {cx: x1, cy: y1} : {x: x1, y: y1});
1489 that.animation_in_progress = setTimeout(arguments.callee, 1);
1492 that.attr(is_round ? {cx: x, cy: y} : {x: x, y: y});
1494 callback && callback.call(that);
1500 C.pathfinder = function (p, path) {
1502 M: function (x, y) {
1505 m: function (x, y) {
1506 this.moveTo(this.last.x + x, this.last.y + y);
1508 C: function (x1, y1, x2, y2, x3, y3) {
1509 this.curveTo(x1, y1, x2, y2, x3, y3);
1511 c: function (x1, y1, x2, y2, x3, y3) {
1512 this.curveTo(this.last.x + x1, this.last.y + y1, this.last.x + x2, this.last.y + y2, this.last.x + x3, this.last.y + y3);
1514 S: function (x1, y1, x2, y2) {
1515 p.curveTo(x1, y1, x2, y2);
1517 s: function (x1, y1, x2, y2) {
1518 this.curveTo(this.last.x + x1, this.last.y + y1, this.last.x + x2, this.last.y + y2);
1520 L: function (x, y) {
1523 l: function (x, y) {
1524 this.lineTo(this.last.x + x, this.last.y + y);
1527 this.lineTo(x, this.last.y);
1530 this.lineTo(this.last.x + x, this.last.y);
1533 this.lineTo(this.last.x, y);
1536 this.lineTo(this.last.x, this.last.y + y);
1538 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
1539 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
1541 a: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
1542 this.arcTo(this.last.x + rx, this.last.y + ry, largearcflag, sweethisflag, this.last.x + x, this.last.y + y);
1548 path.replace(/([mzlhvcsqta])\s*((-?\d*\.?\d*\s*,?\s*)+)/ig, function (a, b, c) {
1550 c.replace(/(-?\d*\.?\d*)\s*,?\s*/ig, function (a, b) {
1551 b && params.push(+b);
1553 while (params.length >= commands[b].length) {
1554 commands[b].apply(p, params.splice(0, commands[b].length));
1555 if (!commands[b].length) {
1563 return function () {};
1565 })((!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2)) ? "VML" : "SVG");
1568 Raphael.vml = !(Raphael.svg = (Raphael.type == "SVG"));
1569 if (Raphael.vml && window.CanvasRenderingContext2D) {
1570 Raphael.type = "Canvas only";
1571 Raphael.vml = Raphael.svg = false;
1573 Raphael.toString = function () {
1574 return "Your browser supports " + this.type + ".\nYou are running " + unescape("Rapha%EBl%20") + this.version;
1576 // generic utilities
1577 Raphael.hsb2rgb = function (hue, saturation, brightness) {
1578 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
1586 if (brightness == 0) {
1587 return {r: 0, g: 0, b: 0, hex: "#000"};
1589 var i = Math.floor(hue * 6),
1591 p = brightness * (1 - saturation),
1592 q = brightness * (1 - (saturation * f)),
1593 t = brightness * (1 - (saturation * (1 - f)));
1595 function () {red = brightness; green = t; blue = p;},
1596 function () {red = q; green = brightness; blue = p;},
1597 function () {red = p; green = brightness; blue = t;},
1598 function () {red = p; green = q; blue = brightness;},
1599 function () {red = t; green = p; blue = brightness;},
1600 function () {red = brightness; green = p; blue = q;},
1601 function () {red = brightness; green = t; blue = p;}
1604 var rgb = {r: red, g: green, b: blue};
1608 var r = Math.round(red).toString(16);
1609 if (r.length == 1) {
1612 var g = Math.round(green).toString(16);
1613 if (g.length == 1) {
1616 var b = Math.round(blue).toString(16);
1617 if (b.length == 1) {
1620 rgb.hex = "#" + r + g + b;
1623 Raphael.rgb2hsb = function (red, green, blue) {
1624 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
1629 if (typeof red == "string" && red.charAt(0) == "#") {
1630 if (red.length == 4) {
1631 blue = parseInt(red.substring(3), 16);
1632 green = parseInt(red.substring(2, 3), 16);
1633 red = parseInt(red.substring(1, 2), 16);
1635 blue = parseInt(red.substring(5), 16);
1636 green = parseInt(red.substring(3, 5), 16);
1637 red = parseInt(red.substring(1, 3), 16);
1640 if (red > 1 || green > 1 || blue > 1) {
1645 var max = Math.max(red, green, blue),
1646 min = Math.min(red, green, blue),
1651 return {h: 0, s: 0, b: max};
1653 var delta = (max - min);
1654 saturation = delta / max;
1656 hue = (green - blue) / delta;
1657 } else if (green == max) {
1658 hue = 2 + ((blue - red) / delta);
1660 hue = 4 + ((red - green) / delta);
1670 return {h: hue, s: saturation, b: brightness};
1672 Raphael.getColor = function (value) {
1673 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
1674 var rgb = this.hsb2rgb(start.h, start.s, start.b);
1680 arguments.callee.start = {h: 0, s: 1, b: start.b};
1685 Raphael.getColor.reset = function () {
1686 this.start = undefined;