2 * Raphael 0.5.7b - 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],
18 [dx || 0, dy || 0, 1],
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) + Math.round(_getX(parseFloat(x, 10)));
86 this.last.y = (this.isAbsolute ? 0 : this.last.y) + Math.round(_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) + Math.round(_getX(parseFloat(x, 10)));
98 this.last.y = (this.isAbsolute ? 0 : this.last.y) + Math.round(_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, left + rx * 2, top + ry * 2, x1, 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) + Math.round(_getX(parseFloat(x2, 10)));
124 this.last.y = (this.isAbsolute ? 0 : this.last.y) + Math.round(_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 = [this.last.x + w, 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.x = (this.isAbsolute ? 0 : this.last.x) + Math.round(_getX(parseFloat(arguments[4], 10)));
157 this.last.y = (this.isAbsolute ? 0 : this.last.y) + Math.round(_getY(parseFloat(arguments[5], 10)));
158 this.last.bx = Math.round(_getX(parseFloat(arguments[2], 10)));
159 this.last.by = Math.round(_getY(parseFloat(arguments[3], 10)));
160 d += Math.round(_getX(parseFloat(arguments[0], 10))) + " " + Math.round(_getY(parseFloat(arguments[1], 10))) + " " +
161 Math.round(_getX(parseFloat(arguments[2], 10))) + " " + Math.round(_getY(parseFloat(arguments[3], 10))) + " " +
162 Math.round(_getX(parseFloat(arguments[4], 10))) + " " + Math.round(_getY(parseFloat(arguments[5], 10))) + " ";
163 this.last.isAbsolute = this.isAbsolute;
165 this[0].path = this.Path += d;
166 this.path.push({type: "curve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
169 p.addRoundedCorner = function (r, dir) {
170 var R = .5522 * r, rollback = this.isAbsolute, o = this;
173 rollback = function () {
177 rollback = function () {};
183 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
186 o.curveTo(-R, 0, -r, r - R, -r, r);
193 o.curveTo(R, 0, r, -(r - R), r, -r);
196 o.curveTo(R, 0, r, r - R, r, r);
203 o.curveTo(0, -R, -(R - r), -r, r, -r);
206 o.curveTo(0, -R, R - r, -r, -r, -r);
213 o.curveTo(0, R, -(R - r), r, r, r);
216 o.curveTo(0, R, R - r, r, -r, r);
221 actions[dir.charAt(0)]()[dir.charAt(1)]();
225 p.andClose = function () {
226 this[0].path = (this.Path += "x e");
229 if (typeof pathString == "string") {
230 pathString = pathString.replace(/([mzlhvcsqta])/ig, ",$1,").replace(/([^,])\-/ig, "$1,-");
231 path = pathString.split(",");
232 var i = 1, ii = path.length;
236 p.absolutely().moveTo(path[++i], path[++i]);
239 p.relatively().moveTo(path[++i], path[++i]);
242 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
245 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
248 p.absolutely().lineTo(path[++i], path[++i]);
251 p.relatively().lineTo(path[++i], path[++i]);
254 p.absolutely().lineTo(path[++i], 0);
257 p.relatively().lineTo(path[++i], 0);
260 p.absolutely().lineTo(0, path[++i]);
263 p.relatively().lineTo(0, path[++i]);
266 p.absolutely().arcTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
269 p.relatively().arcTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
281 var setFillAndStroke = function (o, params) {
283 o.attrs = o.attrs || {};
284 for (var par in params) {
285 o.attrs[par] = params[par];
287 params["font-family"] && (s.fontFamily = params["font-family"]);
288 params["font-size"] && (s.fontSize = params["font-size"]);
289 params["font"] && (s.font = params["font"]);
290 params["font-weight"] && (s.fontWeight = params["font-weight"]);
291 if (typeof params.opacity != "undefined" || typeof params["stroke-width"] != "undefined" || typeof params.fill != "undefined" || typeof params.stroke != "undefined") {
293 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || document.createElement("rvml:fill");
294 if ("fill-opacity" in params || "opacity" in params) {
295 fill.opacity = ((params["fill-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
300 if (fill.on == undefined || params.fill == "none") {
303 if (fill.on && params.fill) {
304 fill.color = params.fill;
307 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || document.createElement("rvml:stroke");
308 if ((params.stroke && params.stroke != "none") || params["stroke-width"] || params["stroke-opacity"] || params["stroke-dasharray"]) {
311 if (params.stroke == "none" || typeof stroke.on == "undefined") {
314 if (stroke.on && params.stroke) {
315 stroke.color = params.stroke;
317 stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
318 stroke.joinstyle && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
319 stroke.miterlimit = params["stroke-miterlimit"] || 8;
320 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
321 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"], 10) || 1) * 12 / 16);
322 if (params["stroke-dasharray"]) {
323 var dashes = params["stroke-dasharray"].replace(" ", ",").split(","),
326 for (var i = 0, ii = dashes.length; i < ii; i++) {
327 var res = dashes[i] / str;
332 stroke.dashstyle = dashesn.join(" ");
334 o.appendChild(stroke);
337 var addGrdientFill = function (o, gradient) {
338 o.attrs = o.attrs || {};
339 o.attrs.gradient = gradient;
341 var fill = o.getElementsByTagName("fill");
345 fill = document.createElement("rvml:fill");
347 if (gradient.dots.length) {
349 fill.type = (gradient.type.toLowerCase() == "linear") ? "gradient" : "gradientradial";
350 if (typeof gradient.dots[0].color != "undefined") {
351 fill.color = gradient.dots[0].color || "#000";
353 if (typeof gradient.dots[0].opacity != "undefined") {
354 fill.opacity = gradient.dots[0].opacity;
356 if (typeof gradient.dots[gradient.dots.length - 1].opacity != "undefined") {
357 fill.opacity2 = gradient.dots[gradient.dots.length - 1].opacity;
359 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
360 fill.color2 = gradient.dots[gradient.dots.length - 1].color || "#000";
363 for (var i = 1, ii = gradient.dots.length - 1; i < ii; i++) {
364 colors += gradient.dots[i].offset + " " + gradient.dots[i].color;
370 fill.colors = colors;
372 if (gradient.vector) {
373 var angle = Math.round(Math.atan((parseInt(gradient.vector[3], 10) - parseInt(gradient.vector[1], 10)) / (parseInt(gradient.vector[2], 10) - parseInt(gradient.vector[0], 10))) * 57.29) + 180;
374 fill.angle = angle + 90;
376 if (gradient.type.toLowerCase() == "radial") {
377 fill.focusposition = "0.5, 0.5";
378 fill.focussize = "0, 0";
379 fill.method = "none";
383 var Element = function (node, group, vml) {
394 this.rotate = function (deg) {
395 if (deg == undefined) {
399 this.Group.style.rotation = Rotation;
403 Element.prototype.setBox = function (params) {
404 var gs = this.Group.style,
406 for (var i in params) {
407 this.attrs[i] = params[i];
409 var attr = this.attrs, x, y, w, h;
412 x = attr.cx - attr.r;
413 y = attr.cy - attr.r;
417 x = attr.cx - attr.rx;
418 y = attr.cy - attr.ry;
430 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("");
435 var left = this.vml.width / 2 - w / 2,
436 top = this.vml.height / 2 - h / 2;
437 gs.position = "absolute";
438 gs.left = x - left + "px";
439 gs.top = y - top + "px";
444 gs.width = this.vml.width + "px";
445 gs.height = this.vml.height + "px";
446 os.position = "absolute";
448 os.left = left + "px";
450 os.height = h + "px";
452 Element.prototype.hide = function () {
453 this.Group.style.display = "none";
456 Element.prototype.show = function () {
457 this.Group.style.display = "block";
460 Element.prototype.translate = function (x, y) {
461 if (x == undefined && y == undefined) {
462 return {x: this.X, y: this.Y};
466 this.Group.style.left = this.X + "px";
467 this.Group.style.top = this.Y + "px";
471 Element.prototype.matrix = function (xx, xy, yx, yy, dx, dy) {
472 tMatrix = new Matrix(xx, xy, yx, yy, dx, dy);
473 this.Group.style.filter = tMatrix;
476 Element.prototype.scale = function (x, y) {
477 if (x == undefined && y == undefined) {
482 if (x != 0 && !(x == 1 && y == 1)) {
483 var dirx = Math.round(x / Math.abs(x)),
484 diry = Math.round(y / Math.abs(y)),
486 if (dirx != 1 || diry != 1) {
487 s.filter = new Matrix(dirx, 0, 0, diry, 0, 0);
489 var width = parseInt(s.width, 10) * x * dirx;
490 var height = parseInt(s.height, 10) * y * diry;
491 var left = parseInt(s.left, 10);
492 var top = parseInt(s.top, 10);
493 s.left = this.X = left + this.W / 2 - width / 2;
494 s.top = this.Y = top + this.H / 2 - height / 2;
495 s.width = this.W = width;
496 s.height = this.H = height;
500 Element.prototype.getBBox = function () {
502 x: this.Group.offsetLeft,
503 y: this.Group.offsetTop,
504 width: this.Group.offsetWidth,
505 height: this.Group.offsetHeight
508 Element.prototype.remove = function () {
509 this[0].parentNode.removeChild(this[0]);
510 this.Group.parentNode.removeChild(this.Group);
511 this.shape && this.shape.parentNode.removeChild(this.shape);
513 Element.prototype.attr = function () {
514 if (arguments.length == 1 && typeof arguments[0] == "string") {
515 return this.attrs[arguments[0]];
517 if (this.attrs && arguments.length == 1 && arguments[0] instanceof Array) {
519 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
520 values[arguments[0][i]] = this.attrs[arguments[0][i]];
524 if (this[0].tagName.toLowerCase() == "group") {
525 var children = this[0].childNodes;
526 this.attrs = this.attrs || {};
527 if (arguments.length == 2) {
528 this.attrs[arguments[0]] = arguments[1];
529 } else if (arguments.length == 1 || typeof arguments[0] == "object") {
530 for (var j in arguments[0]) {
531 this.attrs[j] = arguments[0][j];
534 for (var i = 0, ii = children.length; i < ii; i++) {
535 this.attr.apply(new item(children[i], this[0], this.vml), arguments);
539 if (arguments.length == 2) {
541 params[arguments[0]] = arguments[1];
543 if (arguments.length == 1 && typeof arguments[0] == "object") {
544 params = arguments[0];
547 setFillAndStroke(this, params);
549 if (params.gradient) {
550 addGrdientFill(this, params.gradient);
552 if (params.text && this.type == "text") {
553 this[0].string = params.text;
556 this[0].id = params.id;
562 Element.prototype.toFront = function () {
563 this.Group.parentNode.appendChild(this.Group);
566 Element.prototype.toBack = function () {
567 if (this.Group.parentNode.firstChild != this.Group) {
568 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
572 var theCircle = function (vml, x, y, r) {
573 var g = document.createElement("rvml:group");
574 var o = document.createElement("rvml:oval");
576 vml.canvas.appendChild(g);
577 var res = new Element(o, g, vml);
578 setFillAndStroke(res, {stroke: "#000", fill: "none"});
579 res.setBox({x: x - r, y: y - r, w: r * 2, h: r * 2});
586 var theRect = function (vml, x, y, w, h, r) {
587 var g = document.createElement("rvml:group");
588 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect");
590 o.arcsize = r / (Math.min(w, h));
593 vml.canvas.appendChild(g);
594 var res = new Element(o, g, vml);
595 setFillAndStroke(res, {stroke: "#000"});
596 res.setBox({x: x, y: y, w: w, h: h});
605 var theEllipse = function (vml, x, y, rx, ry) {
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"});
612 res.setBox({x: x - rx, y: y - ry, w: rx * 2, h: ry * 2});
617 res.type = "ellipse";
620 var theImage = function (vml, src, x, y, w, h) {
621 var g = document.createElement("rvml:group");
622 var o = document.createElement("rvml:image");
625 vml.canvas.appendChild(g);
626 var res = new Element(o, g, vml);
628 res.setBox({x: x, y: y, w: w, h: h});
635 var theText = function (vml, x, y, text) {
637 var g = document.createElement("rvml:group"), gs = g.style;
638 var el = document.createElement("rvml:shape"), ol = el.style;
639 var path = document.createElement("rvml:path"), ps = path.style;
640 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
641 path.textpathok = true;
642 ol.width = vml.width;
643 ol.height = vml.height;
644 gs.position = "absolute";
647 gs.width = vml.width;
648 gs.height = vml.height;
649 var o = document.createElement("rvml:textpath");
652 o.coordsize = vml.coordsize;
653 o.coordorigin = vml.coordorigin;
655 el.appendChild(path);
657 vml.canvas.appendChild(g);
658 var res = new Element(o, g, vml);
668 var theGroup = function (vml) {
669 var el = document.createElement("rvml:group"), els = el.style;
670 els.position = "absolute";
673 els.width = vml.width;
674 els.height = vml.height;
676 vml.canvas.appendChild(el);
678 var res = new Element(el, el, vml);
680 if (f.charAt(0) != "_" && typeof vml[f] == "function") {
681 res[f] = (function (f) {
683 var e = vml[f].apply(vml, arguments);
684 el.appendChild(e[0].parentNode);
693 r._create = function () {
694 // container, width, height
695 // x, y, width, height
696 var container, width, height;
697 if (typeof arguments[0] == "string") {
698 container = document.getElementById(arguments[0]);
699 width = arguments[1];
700 height = arguments[2];
702 if (typeof arguments[0] == "object") {
703 container = arguments[0];
704 width = arguments[1];
705 height = arguments[2];
707 if (typeof arguments[0] == "number") {
711 width = arguments[2];
712 height = arguments[3];
715 throw new Error("VML container not found.");
717 if (!document.namespaces["rvml"]) {
718 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
719 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
721 var c = document.createElement("div"),
722 r = C.canvas = document.createElement("rvml:group"),
723 cs = c.style, rs = r.style;
726 width = width || "320px";
727 height = height || "200px";
728 cs.clip = "rect(0 " + width + " " + height + " 0)";
729 cs.position = "absolute";
732 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
733 r.coordorigin = "0 0";
735 var b = document.createElement("rvml:rect"), bs = b.style;
736 bs.left = bs.top = 0;
738 bs.height = rs.height;
739 b.filled = b.stroked = "f";
743 if (container == 1) {
744 document.body.appendChild(c);
745 cs.position = "absolute";
757 cs.width = container.style.width = width;
758 cs.height = container.style.height = height;
759 if (container.firstChild) {
760 container.insertBefore(c, container.firstChild);
762 container.appendChild(c);
765 for (var prop in C) {
766 container[prop] = C[prop];
768 container.clear = function () {
770 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
771 if (r.childNodes[i] != b) {
772 todel.push(r.childNodes[i]);
775 for (i = 0, ii = todel.length; i < ii; i++) {
776 r.removeChild(todel[i]);
781 C.remove = function () {
782 C.canvas.parentNode.parentNode.removeChild(C.canvas.parentNode);
786 Matrix.prototype.toString = function () {
787 return "matrix(" + this.m[0][0] +
788 ", " + this.m[1][0] + ", " + this.m[0][1] + ", " + this.m[1][1] +
789 ", " + this.m[2][0] + ", " + this.m[2][1] + ")";
791 var thePath = function (params, pathString, SVG) {
792 var el = document.createElementNS(SVG.svgns, "path");
793 el.setAttribute("fill", "none");
795 for (var attr in params) {
796 if (params.gradient) {
797 addGrdientFill(el, params.gradient, SVG);
799 el.setAttribute(attr, params[attr]);
804 SVG.canvas.appendChild(el);
806 var p = new Element(el, SVG);
807 for (var attr in params) {
808 p.attrs[attr] = params[attr];
812 p.last = {x: 0, y: 0, bx: 0, by: 0};
813 p.absolutely = function () {
814 this.isAbsolute = true;
817 p.relatively = function () {
818 this.isAbsolute = false;
821 p.redraw = function () {
822 this[0].setAttribute("d", "M0 0");
823 var oldPath = this.path;
825 for (var i = 0, ii = oldPath.length; i < ii; i++) {
826 if (oldPath[i].type != "end") {
827 this[oldPath[i].type + "To"].apply(this, oldPath[i].arg);
834 p.moveTo = function (x, y) {
835 var d = this.isAbsolute?"M":"m";
836 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
837 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
838 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
839 var oldD = this[0].getAttribute("d") || "";
840 this[0].setAttribute("d", oldD + d);
841 this.last.x = SVG._getX(parseFloat(x, 10));
842 this.last.y = SVG._getY(parseFloat(y, 10));
843 this.path.push({type: "move", arg: arguments, pos: this.isAbsolute});
846 p.lineTo = function (x, y) {
847 var d = this.isAbsolute?"L":"l";
848 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
849 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
850 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
851 var oldD = this[0].getAttribute("d") || "";
852 this[0].setAttribute("d", oldD + d);
853 this.last.x = SVG._getX(parseFloat(x, 10));
854 this.last.y = SVG._getY(parseFloat(y, 10));
855 this.path.push({type: "line", arg: arguments, pos: this.isAbsolute});
858 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
859 var d = this.isAbsolute ? "A" : "a";
860 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
861 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
862 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(" ");
863 var oldD = this[0].getAttribute("d") || "";
864 this[0].setAttribute("d", oldD + d);
865 this.last.x = SVG._getX(parseFloat(x, 10));
866 this.last.y = SVG._getY(parseFloat(y, 10));
867 this.path.push({type: "arc", arg: arguments, pos: this.isAbsolute});
870 p.cplineTo = function (x1, y1, w1) {
872 return this.lineTo(x1, y1);
875 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
876 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
877 var x = p._getX(Math.round(parseFloat(x1, 10) * 100) / 100);
878 var y = p._getY(Math.round(parseFloat(y1, 10) * 100) / 100);
879 var w = SVG._getW(Math.round(parseFloat(w1, 10) * 100) / 100);
880 var d = this.isAbsolute?"C":"c";
881 var attr = [this.last.x + w, this.last.y, x - w, y, x, y];
882 for (var i = 0, ii = attr.length; i < ii; i++) {
885 this.last.x = attr[4];
886 this.last.y = attr[5];
887 this.last.bx = attr[2];
888 this.last.by = attr[3];
889 var oldD = this[0].getAttribute("d") || "";
890 this[0].setAttribute("d", oldD + d);
891 this.path.push({type: "cpline", arg: arguments, pos: this.isAbsolute});
895 p.curveTo = function () {
897 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
898 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
899 if (arguments.length == 6) {
900 var d = this.isAbsolute?"C":"c";
901 for (var i = 0, ii = arguments.length; i < ii; i++) {
902 d += p[(i % 2 == 0) ? "_getX" : "_getY"](Math.round(parseFloat(arguments[i], 10) * 100) / 100) + " ";
904 this.last.x = p._getX((parseFloat(arguments[4], 10) * 100) / 100);
905 this.last.y = p._getY((parseFloat(arguments[5], 10) * 100) / 100);
906 this.last.bx = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
907 this.last.by = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
909 if (arguments.length == 4) {
910 var d = this.isAbsolute?"S":"s";
911 for (var i = 0, ii = arguments.length; i < ii; i++) {
912 d += p[i % 2 == 0 ? "_getX" : "_getY"]((parseFloat(arguments[i], 10) * 100) / 100) + " ";
915 this.last.x = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
916 this.last.y = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
917 this.last.bx = p._getX((parseFloat(arguments[0], 10) * 100) / 100);
918 this.last.by = p._getY((parseFloat(arguments[1], 10) * 100) / 100);
920 var oldD = this[0].getAttribute("d") || "";
921 this[0].setAttribute("d", oldD + d);
922 this.path.push({type: "curve", arg: arguments, pos: this.isAbsolute});
925 p.addRoundedCorner = function (r, dir) {
926 var R = .5522 * r, rollback = this.isAbsolute, o = this;
929 rollback = function () {
933 rollback = function () {};
939 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
942 o.curveTo(-R, 0, -r, r - R, -r, r);
949 o.curveTo(R, 0, r, -(r - R), r, -r);
952 o.curveTo(R, 0, r, r - R, r, r);
959 o.curveTo(0, -R, -(R - r), -r, r, -r);
962 o.curveTo(0, -R, R - r, -r, -r, -r);
969 o.curveTo(0, R, -(R - r), r, r, r);
972 o.curveTo(0, R, R - r, r, -r, r);
977 actions[dir[0]]()[dir[1]]();
981 p.andClose = function () {
982 var oldD = this[0].getAttribute("d") || "";
983 this[0].setAttribute("d", oldD + "Z ");
984 this.path.push({type: "end"});
987 if (typeof pathString == "string") {
988 pathString = pathString.replace(/([mzlhvcsqta])/ig, ",$1,").replace(/([^,])\-/ig, "$1,-");
989 path = pathString.split(",");
990 var i = 1, ii = path.length;
994 p.absolutely().moveTo(path[++i], path[++i]);
997 p.relatively().moveTo(path[++i], path[++i]);
1000 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
1003 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
1006 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i]);
1009 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i]);
1012 p.absolutely().lineTo(path[++i], path[++i]);
1015 p.relatively().lineTo(path[++i], path[++i]);
1018 p.absolutely().lineTo(path[++i], 0);
1021 p.relatively().lineTo(path[++i], 0);
1024 p.absolutely().lineTo(0, path[++i]);
1027 p.relatively().lineTo(0, path[++i]);
1030 p.absolutely().arcTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
1033 p.relatively().arcTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
1044 var addGrdientFill = function (o, gradient, SVG) {
1045 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
1046 el.id = "raphael-gradient-" + SVG.gradients++;
1047 if (gradient.vector && gradient.vector.length) {
1048 el.setAttribute("x1", gradient.vector[0]);
1049 el.setAttribute("y1", gradient.vector[1]);
1050 el.setAttribute("x2", gradient.vector[2]);
1051 el.setAttribute("y2", gradient.vector[3]);
1053 SVG.defs.appendChild(el);
1054 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1055 var stop = document.createElementNS(SVG.svgns, "stop");
1056 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
1057 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
1058 if (typeof gradient.dots[i].opacity != "undefined") {
1059 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
1061 el.appendChild(stop);
1063 o.setAttribute("fill", "url(#" + el.id + ")");
1065 var Element = function (node, svg) {
1068 Rotation = {deg: 0, x: 0, y: 0},
1074 this.attrs = this.attrs || {};
1075 this.transformations = []; // rotate, translate, scale, matrix
1076 this.rotate = function (deg) {
1077 if (deg == undefined) {
1078 return Rotation.deg;
1080 var bbox = this.getBBox();
1081 Rotation.deg += deg;
1083 this.transformations[0] = ("rotate(" + Rotation.deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
1085 this.transformations[0] = "";
1087 this[0].setAttribute("transform", this.transformations.join(" "));
1090 this.translate = function (x, y) {
1091 if (x == undefined && y == undefined) {
1092 return {x: X, y: Y};
1097 this.transformations[1] = "translate(" + X + "," + Y + ")";
1099 this.transformations[1] = "";
1101 this[0].setAttribute("transform", this.transformations.join(" "));
1104 this.scale = function (x, y) {
1105 if (x == undefined && y == undefined) {
1106 return {x: ScaleX, y: ScaleY};
1109 if (x != 0 && !(x == 1 && y == 1)) {
1112 if (!(ScaleX == 1 && ScaleY == 1)) {
1113 var bbox = this.getBBox(),
1114 dx = bbox.x * (1 - ScaleX) + (bbox.width / 2 - bbox.width * ScaleX / 2),
1115 dy = bbox.y * (1 - ScaleY) + (bbox.height / 2 - bbox.height * ScaleY / 2);
1116 this.transformations[2] = new Matrix(ScaleX, 0, 0, ScaleY, dx, dy);
1118 this.transformations[2] = "";
1120 this[0].setAttribute("transform", this.transformations.join(" "));
1125 Element.prototype.hide = function () {
1126 this[0].style.display = "none";
1129 Element.prototype.show = function () {
1130 this[0].style.display = "block";
1134 Element.prototype.matrix = function (xx, xy, yx, yy, dx, dy) {
1135 this.transformations[3] = new Matrix(xx, xy, yx, yy, dx, dy);
1136 this[0].setAttribute("transform", this.transformations.join(" "));
1139 Element.prototype.remove = function () {
1140 this[0].parentNode.removeChild(this[0]);
1142 Element.prototype.getBBox = function () {
1143 return this[0].getBBox();
1145 Element.prototype.attr = function () {
1146 if (arguments.length == 1 && typeof arguments[0] == "string") {
1147 return this[0].getAttribute(arguments[0]);
1149 if (arguments.length == 1 && arguments[0] instanceof Array) {
1151 for (var j in arguments[0]) {
1152 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1156 if (arguments.length == 2) {
1157 var att = arguments[0],
1158 value = arguments[1];
1160 this.attrs[att] = value;
1165 this[0].setAttribute(att, this.svg._getX(value));
1170 this[0].setAttribute(att, this.svg._getY(value));
1173 this[0].setAttribute(att, this.svg._getW(value));
1176 this[0].setAttribute(att, this.svg._getH(value));
1179 addGrdientFill(this[0], value, this.svg);
1181 case "stroke-dasharray":
1182 this[0].setAttribute(att, value.replace(" ", ","));
1185 if (this.type == "text") {
1186 this[0].removeChild(this[0].firstChild);
1187 this[0].appendChild(document.createTextNode(value));
1191 var cssrule = att.replace(/(\-.)/g, function (w) {
1192 return w.substring(1).toUpperCase();
1194 this[0].style[cssrule] = value;
1195 // Need following line for Firefox
1196 this[0].setAttribute(att, value);
1199 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1200 var params = arguments[0];
1201 for (var attr in params) {
1202 this.attrs[attr] = params[attr];
1203 if (attr == "stroke-dasharray") {
1204 this[0].setAttribute(attr, params[attr].replace(" ", ","));
1205 } else if (attr == "text" && this.type == "text") {
1206 this[0].removeChild(this[0].firstChild);
1207 this[0].appendChild(document.createTextNode(params[attr]));
1209 var cssrule = attr.replace(/(\-.)/g, function (w) {
1210 return w.substring(1).toUpperCase();
1212 this[0].style[cssrule] = params[attr];
1213 // Need following line for Firefox
1214 this[0].setAttribute(attr, params[attr]);
1217 if (params.gradient) {
1218 this.attrs.gradient = params.gradient;
1219 addGrdientFill(this[0], params.gradient, this.svg);
1224 Element.prototype.toFront = function () {
1225 this[0].parentNode.appendChild(this[0]);
1228 Element.prototype.toBack = function () {
1229 if (this[0].parentNode.firstChild != this[0]) {
1230 this[0].parentNode.insertBefore(this[0], this[0].parentNode.firstChild);
1234 var theCircle = function (svg, x, y, r) {
1235 var el = document.createElementNS(svg.svgns, "circle");
1236 el.setAttribute("cx", svg._getX(x));
1237 el.setAttribute("cy", svg._getY(y));
1238 el.setAttribute("r", r);
1239 el.setAttribute("fill", "none");
1240 el.setAttribute("stroke", "#000");
1242 svg.canvas.appendChild(el);
1244 var res = new Element(el, svg);
1245 res.attrs = res.attrs || {};
1249 res.attrs.stroke = "#000";
1250 res.type = "circle";
1253 var theRect = function (svg, x, y, w, h, r) {
1254 var el = document.createElementNS(svg.svgns, "rect");
1255 el.setAttribute("x", svg._getX(x));
1256 el.setAttribute("y", svg._getY(y));
1257 el.setAttribute("width", svg._getW(w));
1258 el.setAttribute("height", svg._getH(h));
1260 el.setAttribute("rx", r);
1261 el.setAttribute("ry", r);
1263 el.setAttribute("fill", "none");
1264 el.setAttribute("stroke", "#000");
1266 svg.canvas.appendChild(el);
1268 var res = new Element(el, svg);
1269 res.attrs = res.attrs || {};
1272 res.attrs.width = w;
1273 res.attrs.height = h;
1274 res.attrs.stroke = "#000";
1276 res.attrs.rx = res.attrs.ry = r;
1281 var theEllipse = function (svg, x, y, rx, ry) {
1282 var el = document.createElementNS(svg.svgns, "ellipse");
1283 el.setAttribute("cx", svg._getX(x));
1284 el.setAttribute("cy", svg._getY(y));
1285 el.setAttribute("rx", svg._getW(rx));
1286 el.setAttribute("ry", svg._getH(ry));
1287 el.setAttribute("fill", "none");
1288 el.setAttribute("stroke", "#000");
1290 svg.canvas.appendChild(el);
1292 var res = new Element(el, svg);
1293 res.attrs = res.attrs || {};
1298 res.attrs.stroke = "#000";
1299 res.type = "ellipse";
1302 var theImage = function (svg, src, x, y, w, h) {
1303 var el = document.createElementNS(svg.svgns, "image");
1304 el.setAttribute("x", svg._getX(x));
1305 el.setAttribute("y", svg._getY(y));
1306 el.setAttribute("width", svg._getW(w));
1307 el.setAttribute("height", svg._getH(h));
1308 el.setAttributeNS(svg.xlink, "href", src);
1310 svg.canvas.appendChild(el);
1312 var res = new Element(el, svg);
1313 res.attrs = res.attrs || {};
1316 res.attrs.width = w;
1317 res.attrs.height = h;
1321 var theText = function (svg, x, y, text) {
1322 var el = document.createElementNS(svg.svgns, "text");
1323 el.setAttribute("x", x);
1324 el.setAttribute("y", y);
1325 el.setAttribute("text-anchor", "middle");
1326 el.setAttribute("fill", "#000");
1328 el.appendChild(document.createTextNode(text));
1331 svg.canvas.appendChild(el);
1333 var res = new Element(el, svg);
1334 res.attrs = res.attrs || {};
1337 res.attrs.fill = "#000";
1341 var theGroup = function (svg) {
1342 var el = document.createElementNS(svg.svgns, "g");
1344 svg.canvas.appendChild(el);
1346 var i = new Element(el, svg);
1347 for (var f in svg) {
1348 if (f[0] != "_" && typeof svg[f] == "function") {
1349 i[f] = (function (f) {
1350 return function () {
1351 var e = svg[f].apply(svg, arguments);
1352 el.appendChild(e[0]);
1361 r._create = function () {
1362 // container, width, height
1363 // x, y, width, height
1364 if (typeof arguments[0] == "string") {
1365 var container = document.getElementById(arguments[0]);
1366 var width = arguments[1];
1367 var height = arguments[2];
1369 if (typeof arguments[0] == "object") {
1370 var container = arguments[0];
1371 var width = arguments[1];
1372 var height = arguments[2];
1374 if (typeof arguments[0] == "number") {
1378 width = arguments[2],
1379 height = arguments[3];
1382 throw new Error("SVG container not found.");
1384 C.canvas = document.createElementNS(C.svgns, "svg");
1385 C.canvas.setAttribute("width", width || 320);
1386 C.width = width || 320;
1387 C.canvas.setAttribute("height", height || 200);
1388 C.height = height || 200;
1389 if (container == 1) {
1390 document.body.appendChild(C.canvas);
1391 C.canvas.style.position = "absolute";
1392 C.canvas.style.left = x + "px";
1393 C.canvas.style.top = y + "px";
1395 if (container.firstChild) {
1396 container.insertBefore(C.canvas, container.firstChild);
1398 container.appendChild(C.canvas);
1403 clear: function () {
1404 while (this.canvas.firstChild) {
1405 this.canvas.removeChild(this.canvas.firstChild);
1407 this.defs = document.createElementNS(C.svgns, "defs");
1409 this.canvas.appendChild(this.defs);
1412 for (var prop in C) {
1413 if (prop != "create") {
1414 container[prop] = C[prop];
1420 C.remove = function () {
1421 C.canvas.parentNode.removeChild(C.canvas);
1423 C.svgns = "http://www.w3.org/2000/svg";
1424 C.xlink = "http://www.w3.org/1999/xlink";
1426 if (type == "VML" || type == "SVG") {
1427 C.circle = function (x, y, r) {
1428 return theCircle(this, x, y, r);
1430 C.rect = function (x, y, w, h, r) {
1431 return theRect(this, x, y, w, h, r);
1433 C.ellipse = function (x, y, rx, ry) {
1434 return theEllipse(this, x, y, rx, ry);
1436 C.path = function (params, pathString) {
1437 return thePath(params, pathString, this);
1439 C.image = function (src, x, y, w, h) {
1440 return theImage(this, src, x, y, w, h);
1442 C.text = function (x, y, text) {
1443 return theText(this, x, y, text);
1445 C.group = function () {
1446 return theGroup(this);
1448 C.linerect = function (x, y, w, h, r) {
1449 if (r && parseInt(r, 10)) {
1450 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();
1452 return this.path({stroke: "#000"}).moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).andClose();
1454 C.drawGrid = function (x, y, w, h, wv, hv, color) {
1455 color = color || "#000";
1456 var p = this.path({stroke: color, "stroke-width": 1})
1457 .moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).lineTo(x, y);
1458 for (var i = 1; i < hv; i++) {
1459 p.moveTo(x, y + i * Math.round(h / hv)).lineTo(x + w, y + i * Math.round(h / hv));
1461 for (var i = 1; i < wv; i++) {
1462 p.moveTo(x + i * Math.round(w / wv), y).lineTo(x + i * Math.round(w / wv), y + h);
1466 C.setGrid = function (xmin, ymin, xmax, ymax, w, h) {
1467 var xc = (xmax - xmin) / w;
1468 var yc = (ymax - ymin) / h;
1469 this._getX = function (x) {
1470 return xmin + x * xc;
1472 this._getY = function (y) {
1473 return ymin + y * yc;
1475 this._getW = function (w) {
1478 this._getH = function (h) {
1482 C.clearGrid = function () {
1483 this._getX = this._getY = this._getW = this._getH = function (x) { return x; };
1485 C.safari = function () {
1486 if (r.type == "SVG") {
1487 var rect = C.rect(-C.width, -C.height, C.width * 3, C.height * 3).attr({stroke: "none"});
1488 setTimeout(function () {rect.remove();}, 0);
1491 Element.prototype.animateTo = function (x, y, ms, callback) {
1492 clearTimeout(this.animation_in_progress);
1493 if ("cx" in this.attrs || "x" in this.attrs) {
1494 var is_round = ("cx" in this.attrs),
1495 X = this.attrs.cx || this.attrs.x,
1496 Y = this.attrs.cy || this.attrs.y;
1497 if (x == X && y == Y) {
1503 plus = Y - coeff * X,
1504 alpha = Math.atan(this.coeff);
1505 this.xs = this.step * Math.cos(alpha);
1509 var start = new Date(),
1512 var time = (new Date()).getTime() - start.getTime();
1514 var x1 = X + time * dx / ms;
1515 var y1 = x1 * coeff + plus;
1516 that.attr(is_round ? {cx: x1, cy: y1} : {x: x1, y: y1});
1517 that.animation_in_progress = setTimeout(arguments.callee, 1);
1520 that.attr(is_round ? {cx: x, cy: y} : {x: x, y: y});
1522 callback && callback.call(that);
1531 return function () {};
1533 })((!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2)) ? "VML" : "SVG");
1536 Raphael.vml = !(Raphael.svg = (Raphael.type == "SVG"));
1537 if (Raphael.vml && window.CanvasRenderingContext2D) {
1538 Raphael.type = "Canvas only";
1539 Raphael.vml = Raphael.svg = false;
1541 Raphael.toString = function () {
1542 return "Your browser supports " + this.type;
1544 // generic utilities
1545 Raphael.hsb2rgb = function (hue, saturation, brightness) {
1546 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
1554 if (brightness == 0) {
1555 return {r: 0, g: 0, b: 0, hex: "#000"};
1557 var i = Math.floor(hue * 6),
1559 p = brightness * (1 - saturation),
1560 q = brightness * (1 - (saturation * f)),
1561 t = brightness * (1 - (saturation * (1 - f)));
1563 function () {red = brightness; green = t; blue = p;},
1564 function () {red = q; green = brightness; blue = p;},
1565 function () {red = p; green = brightness; blue = t;},
1566 function () {red = p; green = q; blue = brightness;},
1567 function () {red = t; green = p; blue = brightness;},
1568 function () {red = brightness; green = p; blue = q;},
1569 function () {red = brightness; green = t; blue = p;},
1572 var rgb = {r: red, g: green, b: blue};
1576 var r = Math.round(red).toString(16);
1577 if (r.length == 1) {
1580 var g = Math.round(green).toString(16);
1581 if (g.length == 1) {
1584 var b = Math.round(blue).toString(16);
1585 if (b.length == 1) {
1588 rgb.hex = "#" + r + g + b;
1591 Raphael.rgb2hsb = function (red, green, blue) {
1592 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
1597 if (red.charAt(0) == "#") {
1598 if (red.length == 4) {
1599 blue = parseInt(red.substring(3), 16);
1600 green = parseInt(red.substring(2, 3), 16);
1601 red = parseInt(red.substring(1, 2), 16);
1603 blue = parseInt(red.substring(5), 16);
1604 green = parseInt(red.substring(3, 5), 16);
1605 red = parseInt(red.substring(1, 3), 16);
1608 if (red > 1 || green > 1 || blue > 1) {
1613 var max = Math.max(red, green, blue),
1614 min = Math.min(red, green, blue),
1619 return {h: 0, s: 0, b: max};
1621 var delta = (max - min);
1622 saturation = delta / max;
1624 hue = (green - blue) / delta;
1625 } else if (green == max) {
1626 hue = 2 + ((blue - red) / delta);
1628 hue = 4 + ((red - green) / delta);
1638 return {h: hue, s: saturation, b: brightness};
1640 Raphael.getColor = function (value) {
1641 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
1642 var rgb = this.hsb2rgb(start.h, start.s, start.b);
1648 start = {h: 0, s: 1, b: start.b};
1653 Raphael.getColor.reset = function () {
1654 this.start = undefined;