2 * Raphael 0.5.8b - 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) + _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, 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) + _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.x = (this.isAbsolute ? 0 : this.last.x) + _getX(parseFloat(arguments[4], 10));
157 this.last.y = (this.isAbsolute ? 0 : this.last.y) + _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;
235 if (C.pathfinder[path[i]]) {
236 i = C.pathfinder[path[i]](p, path, i);
243 var setFillAndStroke = function (o, params) {
245 o.attrs = o.attrs || {};
246 for (var par in params) {
247 o.attrs[par] = params[par];
249 params["font-family"] && (s.fontFamily = params["font-family"]);
250 params["font-size"] && (s.fontSize = params["font-size"]);
251 params["font"] && (s.font = params["font"]);
252 params["font-weight"] && (s.fontWeight = params["font-weight"]);
253 if (typeof params.opacity != "undefined" || typeof params["stroke-width"] != "undefined" || typeof params.fill != "undefined" || typeof params.stroke != "undefined") {
255 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || document.createElement("rvml:fill");
256 if ("fill-opacity" in params || "opacity" in params) {
257 fill.opacity = ((params["fill-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
262 if (fill.on == undefined || params.fill == "none") {
265 if (fill.on && params.fill) {
266 fill.color = params.fill;
269 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || document.createElement("rvml:stroke");
270 if ((params.stroke && params.stroke != "none") || params["stroke-width"] || params["stroke-opacity"] || params["stroke-dasharray"]) {
273 if (params.stroke == "none" || typeof stroke.on == "undefined") {
276 if (stroke.on && params.stroke) {
277 stroke.color = params.stroke;
279 stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
280 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
281 stroke.miterlimit = params["stroke-miterlimit"] || 8;
282 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
283 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"], 10) || 1) * 12 / 16);
284 if (params["stroke-dasharray"]) {
285 var dashes = params["stroke-dasharray"].replace(" ", ",").split(","),
288 for (var i = 0, ii = dashes.length; i < ii; i++) {
289 var res = dashes[i] / str;
294 stroke.dashstyle = dashesn.join(" ");
296 o.appendChild(stroke);
299 var addGrdientFill = function (o, gradient) {
300 o.attrs = o.attrs || {};
301 o.attrs.gradient = gradient;
303 var fill = o.getElementsByTagName("fill");
307 fill = document.createElement("rvml:fill");
309 if (gradient.dots.length) {
311 fill.type = (gradient.type.toLowerCase() == "linear") ? "gradient" : "gradientradial";
312 if (typeof gradient.dots[0].color != "undefined") {
313 fill.color = gradient.dots[0].color || "#000";
315 if (typeof gradient.dots[0].opacity != "undefined") {
316 fill.opacity = gradient.dots[0].opacity;
318 if (typeof gradient.dots[gradient.dots.length - 1].opacity != "undefined") {
319 fill.opacity2 = gradient.dots[gradient.dots.length - 1].opacity;
321 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
322 fill.color2 = gradient.dots[gradient.dots.length - 1].color || "#000";
325 for (var i = 1, ii = gradient.dots.length - 1; i < ii; i++) {
326 colors += gradient.dots[i].offset + " " + gradient.dots[i].color;
332 fill.colors = colors;
334 if (gradient.vector) {
335 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;
336 fill.angle = angle + 90;
338 if (gradient.type.toLowerCase() == "radial") {
339 fill.focusposition = "0.5, 0.5";
340 fill.focussize = "0, 0";
341 fill.method = "none";
345 var Element = function (node, group, vml) {
356 this.rotate = function (deg) {
357 if (deg == undefined) {
361 this.Group.style.rotation = Rotation;
365 Element.prototype.setBox = function (params) {
366 var gs = this.Group.style,
368 for (var i in params) {
369 this.attrs[i] = params[i];
371 var attr = this.attrs, x, y, w, h;
374 x = attr.cx - attr.r;
375 y = attr.cy - attr.r;
379 x = attr.cx - attr.rx;
380 y = attr.cy - attr.ry;
392 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("");
397 var left = this.vml.width / 2 - w / 2,
398 top = this.vml.height / 2 - h / 2;
399 gs.position = "absolute";
400 gs.left = x - left + "px";
401 gs.top = y - top + "px";
406 gs.width = this.vml.width + "px";
407 gs.height = this.vml.height + "px";
408 os.position = "absolute";
410 os.left = left + "px";
412 os.height = h + "px";
414 Element.prototype.hide = function () {
415 this.Group.style.display = "none";
418 Element.prototype.show = function () {
419 this.Group.style.display = "block";
422 Element.prototype.translate = function (x, y) {
423 if (x == undefined && y == undefined) {
424 return {x: this.X, y: this.Y};
428 this.Group.style.left = this.X + "px";
429 this.Group.style.top = this.Y + "px";
433 Element.prototype.matrix = function (xx, xy, yx, yy, dx, dy) {
434 tMatrix = new Matrix(xx, xy, yx, yy, dx, dy);
435 this.Group.style.filter = tMatrix;
438 Element.prototype.scale = function (x, y) {
439 if (x == undefined && y == undefined) {
444 if (x != 0 && !(x == 1 && y == 1)) {
445 var dirx = Math.round(x / Math.abs(x)),
446 diry = Math.round(y / Math.abs(y)),
448 if (dirx != 1 || diry != 1) {
449 s.filter = new Matrix(dirx, 0, 0, diry, 0, 0);
451 var width = parseInt(s.width, 10) * x * dirx;
452 var height = parseInt(s.height, 10) * y * diry;
453 var left = parseInt(s.left, 10);
454 var top = parseInt(s.top, 10);
455 s.left = this.X = left + this.W / 2 - width / 2;
456 s.top = this.Y = top + this.H / 2 - height / 2;
457 s.width = this.W = width;
458 s.height = this.H = height;
462 Element.prototype.getBBox = function () {
464 x: this.Group.offsetLeft,
465 y: this.Group.offsetTop,
466 width: this.Group.offsetWidth,
467 height: this.Group.offsetHeight
470 Element.prototype.remove = function () {
471 this[0].parentNode.removeChild(this[0]);
472 this.Group.parentNode.removeChild(this.Group);
473 this.shape && this.shape.parentNode.removeChild(this.shape);
475 Element.prototype.attr = function () {
476 if (arguments.length == 1 && typeof arguments[0] == "string") {
477 return this.attrs[arguments[0]];
479 if (this.attrs && arguments.length == 1 && arguments[0] instanceof Array) {
481 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
482 values[arguments[0][i]] = this.attrs[arguments[0][i]];
486 if (this[0].tagName.toLowerCase() == "group") {
487 var children = this[0].childNodes;
488 this.attrs = this.attrs || {};
489 if (arguments.length == 2) {
490 this.attrs[arguments[0]] = arguments[1];
491 } else if (arguments.length == 1 || typeof arguments[0] == "object") {
492 for (var j in arguments[0]) {
493 this.attrs[j] = arguments[0][j];
496 for (var i = 0, ii = children.length; i < ii; i++) {
497 this.attr.apply(new item(children[i], this[0], this.vml), arguments);
501 if (arguments.length == 2) {
503 params[arguments[0]] = arguments[1];
505 if (arguments.length == 1 && typeof arguments[0] == "object") {
506 params = arguments[0];
509 setFillAndStroke(this, params);
511 if (params.gradient) {
512 addGrdientFill(this, params.gradient);
514 if (params.text && this.type == "text") {
515 this[0].string = params.text;
518 this[0].id = params.id;
524 Element.prototype.toFront = function () {
525 this.Group.parentNode.appendChild(this.Group);
528 Element.prototype.toBack = function () {
529 if (this.Group.parentNode.firstChild != this.Group) {
530 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
534 var theCircle = function (vml, x, y, r) {
535 var g = document.createElement("rvml:group");
536 var o = document.createElement("rvml:oval");
538 vml.canvas.appendChild(g);
539 var res = new Element(o, g, vml);
540 setFillAndStroke(res, {stroke: "#000", fill: "none"});
541 res.setBox({x: x - r, y: y - r, w: r * 2, h: r * 2});
548 var theRect = function (vml, x, y, w, h, r) {
549 var g = document.createElement("rvml:group");
550 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect");
552 o.arcsize = r / (Math.min(w, h));
555 vml.canvas.appendChild(g);
556 var res = new Element(o, g, vml);
557 setFillAndStroke(res, {stroke: "#000"});
558 res.setBox({x: x, y: y, w: w, h: h});
567 var theEllipse = function (vml, x, y, rx, ry) {
568 var g = document.createElement("rvml:group");
569 var o = document.createElement("rvml:oval");
571 vml.canvas.appendChild(g);
572 var res = new Element(o, g, vml);
573 setFillAndStroke(res, {stroke: "#000"});
574 res.setBox({x: x - rx, y: y - ry, w: rx * 2, h: ry * 2});
579 res.type = "ellipse";
582 var theImage = function (vml, src, x, y, w, h) {
583 var g = document.createElement("rvml:group");
584 var o = document.createElement("rvml:image");
587 vml.canvas.appendChild(g);
588 var res = new Element(o, g, vml);
590 res.setBox({x: x, y: y, w: w, h: h});
597 var theText = function (vml, x, y, text) {
599 var g = document.createElement("rvml:group"), gs = g.style;
600 var el = document.createElement("rvml:shape"), ol = el.style;
601 var path = document.createElement("rvml:path"), ps = path.style;
602 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
603 path.textpathok = true;
604 ol.width = vml.width;
605 ol.height = vml.height;
606 gs.position = "absolute";
609 gs.width = vml.width;
610 gs.height = vml.height;
611 var o = document.createElement("rvml:textpath");
614 o.coordsize = vml.coordsize;
615 o.coordorigin = vml.coordorigin;
617 el.appendChild(path);
619 vml.canvas.appendChild(g);
620 var res = new Element(o, g, vml);
630 var theGroup = function (vml) {
631 var el = document.createElement("rvml:group"), els = el.style;
632 els.position = "absolute";
635 els.width = vml.width;
636 els.height = vml.height;
638 vml.canvas.appendChild(el);
640 var res = new Element(el, el, vml);
642 if (f.charAt(0) != "_" && typeof vml[f] == "function") {
643 res[f] = (function (f) {
645 var e = vml[f].apply(vml, arguments);
646 el.appendChild(e[0].parentNode);
655 r._create = function () {
656 // container, width, height
657 // x, y, width, height
658 var container, width, height;
659 if (typeof arguments[0] == "string") {
660 container = document.getElementById(arguments[0]);
661 width = arguments[1];
662 height = arguments[2];
664 if (typeof arguments[0] == "object") {
665 container = arguments[0];
666 width = arguments[1];
667 height = arguments[2];
669 if (typeof arguments[0] == "number") {
673 width = arguments[2];
674 height = arguments[3];
677 throw new Error("VML container not found.");
679 if (!document.namespaces["rvml"]) {
680 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
681 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
683 var c = document.createElement("div"),
684 r = C.canvas = document.createElement("rvml:group"),
685 cs = c.style, rs = r.style;
688 width = width || "320px";
689 height = height || "200px";
690 cs.clip = "rect(0 " + width + " " + height + " 0)";
691 cs.position = "absolute";
694 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
695 r.coordorigin = "0 0";
697 var b = document.createElement("rvml:rect"), bs = b.style;
698 bs.left = bs.top = 0;
700 bs.height = rs.height;
701 b.filled = b.stroked = "f";
705 if (container == 1) {
706 document.body.appendChild(c);
707 cs.position = "absolute";
719 cs.width = container.style.width = width;
720 cs.height = container.style.height = height;
721 if (container.firstChild) {
722 container.insertBefore(c, container.firstChild);
724 container.appendChild(c);
727 for (var prop in C) {
728 container[prop] = C[prop];
730 container.clear = function () {
732 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
733 if (r.childNodes[i] != b) {
734 todel.push(r.childNodes[i]);
737 for (i = 0, ii = todel.length; i < ii; i++) {
738 r.removeChild(todel[i]);
743 C.remove = function () {
744 C.canvas.parentNode.parentNode.removeChild(C.canvas.parentNode);
748 Matrix.prototype.toString = function () {
749 return "matrix(" + this.m[0][0] +
750 ", " + this.m[1][0] + ", " + this.m[0][1] + ", " + this.m[1][1] +
751 ", " + this.m[2][0] + ", " + this.m[2][1] + ")";
753 var thePath = function (params, pathString, SVG) {
754 var el = document.createElementNS(SVG.svgns, "path");
755 el.setAttribute("fill", "none");
757 for (var attr in params) {
758 if (params.gradient) {
759 addGrdientFill(el, params.gradient, SVG);
761 el.setAttribute(attr, params[attr]);
766 SVG.canvas.appendChild(el);
768 var p = new Element(el, SVG);
769 for (var attr in params) {
770 p.attrs[attr] = params[attr];
774 p.last = {x: 0, y: 0, bx: 0, by: 0};
775 p.absolutely = function () {
776 this.isAbsolute = true;
779 p.relatively = function () {
780 this.isAbsolute = false;
783 p.redraw = function () {
784 this[0].setAttribute("d", "M0 0");
785 var oldPath = this.path;
787 for (var i = 0, ii = oldPath.length; i < ii; i++) {
788 if (oldPath[i].type != "end") {
789 this[oldPath[i].type + "To"].apply(this, oldPath[i].arg);
796 p.moveTo = function (x, y) {
797 var d = this.isAbsolute?"M":"m";
798 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
799 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
800 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
801 var oldD = this[0].getAttribute("d") || "";
802 this[0].setAttribute("d", oldD + d);
803 this.last.x = (this.isAbsolute ? 0 : this.last.x) + SVG._getX(parseFloat(x, 10));
804 this.last.y = (this.isAbsolute ? 0 : this.last.y) + SVG._getY(parseFloat(y, 10));
805 this.path.push({type: "move", arg: arguments, pos: this.isAbsolute});
808 p.lineTo = function (x, y) {
809 this.last.x = (this.isAbsolute ? 0 : this.last.x) + SVG._getX(parseFloat(x, 10));
810 this.last.y = (this.isAbsolute ? 0 : this.last.y) + SVG._getY(parseFloat(y, 10));
811 var d = this.isAbsolute?"L":"l";
812 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
813 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
814 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
815 var oldD = this[0].getAttribute("d") || "";
816 this[0].setAttribute("d", oldD + d);
817 this.path.push({type: "line", arg: arguments, pos: this.isAbsolute});
820 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
821 var d = this.isAbsolute ? "A" : "a";
822 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
823 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
824 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(" ");
825 var oldD = this[0].getAttribute("d") || "";
826 this[0].setAttribute("d", oldD + d);
827 this.last.x = SVG._getX(parseFloat(x, 10));
828 this.last.y = SVG._getY(parseFloat(y, 10));
829 this.path.push({type: "arc", arg: arguments, pos: this.isAbsolute});
832 p.cplineTo = function (x1, y1, w1) {
834 return this.lineTo(x1, y1);
837 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
838 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
839 var x = p._getX(Math.round(parseFloat(x1, 10) * 100) / 100);
840 var y = p._getY(Math.round(parseFloat(y1, 10) * 100) / 100);
841 var w = SVG._getW(Math.round(parseFloat(w1, 10) * 100) / 100);
842 var d = this.isAbsolute?"C":"c";
843 var attr = [this.last.x + w, this.last.y, x - w, y, x, y];
844 for (var i = 0, ii = attr.length; i < ii; i++) {
847 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
848 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
849 this.last.bx = attr[2];
850 this.last.by = attr[3];
851 var oldD = this[0].getAttribute("d") || "";
852 this[0].setAttribute("d", oldD + d);
853 this.path.push({type: "cpline", arg: arguments, pos: this.isAbsolute});
857 p.curveTo = function () {
859 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
860 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
861 if (arguments.length == 6) {
862 var d = this.isAbsolute?"C":"c";
863 for (var i = 0, ii = arguments.length; i < ii; i++) {
864 d += p[(i % 2 == 0) ? "_getX" : "_getY"](Math.round(parseFloat(arguments[i], 10) * 100) / 100) + " ";
866 this.last.x = (this.isAbsolute ? 0 : this.last.x) + p._getX((parseFloat(arguments[4], 10) * 100) / 100);
867 this.last.y = (this.isAbsolute ? 0 : this.last.y) + p._getY((parseFloat(arguments[5], 10) * 100) / 100);
868 this.last.bx = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
869 this.last.by = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
871 if (arguments.length == 4) {
872 var d = this.isAbsolute?"S":"s";
873 for (var i = 0, ii = arguments.length; i < ii; i++) {
874 d += p[i % 2 == 0 ? "_getX" : "_getY"]((parseFloat(arguments[i], 10) * 100) / 100) + " ";
877 this.last.x = (this.isAbsolute ? 0 : this.last.x) + p._getX((parseFloat(arguments[2], 10) * 100) / 100);
878 this.last.y = (this.isAbsolute ? 0 : this.last.y) + p._getY((parseFloat(arguments[3], 10) * 100) / 100);
879 this.last.bx = p._getX((parseFloat(arguments[0], 10) * 100) / 100);
880 this.last.by = p._getY((parseFloat(arguments[1], 10) * 100) / 100);
882 var oldD = this[0].getAttribute("d") || "";
883 this[0].setAttribute("d", oldD + d);
884 this.path.push({type: "curve", arg: arguments, pos: this.isAbsolute});
887 p.addRoundedCorner = function (r, dir) {
888 var R = .5522 * r, rollback = this.isAbsolute, o = this;
891 rollback = function () {
895 rollback = function () {};
901 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
904 o.curveTo(-R, 0, -r, r - R, -r, r);
911 o.curveTo(R, 0, r, -(r - R), r, -r);
914 o.curveTo(R, 0, r, r - R, r, r);
921 o.curveTo(0, -R, -(R - r), -r, r, -r);
924 o.curveTo(0, -R, R - r, -r, -r, -r);
931 o.curveTo(0, R, -(R - r), r, r, r);
934 o.curveTo(0, R, R - r, r, -r, r);
939 actions[dir[0]]()[dir[1]]();
943 p.andClose = function () {
944 var oldD = this[0].getAttribute("d") || "";
945 this[0].setAttribute("d", oldD + "Z ");
946 this.path.push({type: "end"});
949 if (typeof pathString == "string") {
950 pathString = pathString.replace(/([mzlhvcsqta])/ig, ",$1,").replace(/([^,])\-/ig, "$1,-");
951 path = pathString.split(",");
952 var i = 1, ii = path.length;
955 if (C.pathfinder[path[i]]) {
956 i = C.pathfinder[path[i]](p, path, i);
963 var addGrdientFill = function (o, gradient, SVG) {
964 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
965 el.id = "raphael-gradient-" + SVG.gradients++;
966 if (gradient.vector && gradient.vector.length) {
967 el.setAttribute("x1", gradient.vector[0]);
968 el.setAttribute("y1", gradient.vector[1]);
969 el.setAttribute("x2", gradient.vector[2]);
970 el.setAttribute("y2", gradient.vector[3]);
972 SVG.defs.appendChild(el);
973 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
974 var stop = document.createElementNS(SVG.svgns, "stop");
975 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
976 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
977 if (typeof gradient.dots[i].opacity != "undefined") {
978 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
980 el.appendChild(stop);
982 o.setAttribute("fill", "url(#" + el.id + ")");
984 var Element = function (node, svg) {
987 Rotation = {deg: 0, x: 0, y: 0},
993 this.attrs = this.attrs || {};
994 this.transformations = []; // rotate, translate, scale, matrix
995 this.rotate = function (deg) {
996 if (deg == undefined) {
999 var bbox = this.getBBox();
1000 Rotation.deg += deg;
1002 this.transformations[0] = ("rotate(" + Rotation.deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
1004 this.transformations[0] = "";
1006 this[0].setAttribute("transform", this.transformations.join(" "));
1009 this.translate = function (x, y) {
1010 if (x == undefined && y == undefined) {
1011 return {x: X, y: Y};
1016 this.transformations[1] = "translate(" + X + "," + Y + ")";
1018 this.transformations[1] = "";
1020 this[0].setAttribute("transform", this.transformations.join(" "));
1023 this.scale = function (x, y) {
1024 if (x == undefined && y == undefined) {
1025 return {x: ScaleX, y: ScaleY};
1028 if (x != 0 && !(x == 1 && y == 1)) {
1031 if (!(ScaleX == 1 && ScaleY == 1)) {
1032 var bbox = this.getBBox(),
1033 dx = bbox.x * (1 - ScaleX) + (bbox.width / 2 - bbox.width * ScaleX / 2),
1034 dy = bbox.y * (1 - ScaleY) + (bbox.height / 2 - bbox.height * ScaleY / 2);
1035 this.transformations[2] = new Matrix(ScaleX, 0, 0, ScaleY, dx, dy);
1037 this.transformations[2] = "";
1039 this[0].setAttribute("transform", this.transformations.join(" "));
1044 Element.prototype.hide = function () {
1045 this[0].style.display = "none";
1048 Element.prototype.show = function () {
1049 this[0].style.display = "block";
1053 Element.prototype.matrix = function (xx, xy, yx, yy, dx, dy) {
1054 this.transformations[3] = new Matrix(xx, xy, yx, yy, dx, dy);
1055 this[0].setAttribute("transform", this.transformations.join(" "));
1058 Element.prototype.remove = function () {
1059 this[0].parentNode.removeChild(this[0]);
1061 Element.prototype.getBBox = function () {
1062 return this[0].getBBox();
1064 Element.prototype.attr = function () {
1065 if (arguments.length == 1 && typeof arguments[0] == "string") {
1066 return this[0].getAttribute(arguments[0]);
1068 if (arguments.length == 1 && arguments[0] instanceof Array) {
1070 for (var j in arguments[0]) {
1071 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1075 if (arguments.length == 2) {
1076 var att = arguments[0],
1077 value = arguments[1];
1079 this.attrs[att] = value;
1084 this[0].setAttribute(att, this.svg._getX(value));
1089 this[0].setAttribute(att, this.svg._getY(value));
1092 this[0].setAttribute(att, this.svg._getW(value));
1095 this[0].setAttribute(att, this.svg._getH(value));
1098 addGrdientFill(this[0], value, this.svg);
1100 case "stroke-dasharray":
1101 this[0].setAttribute(att, value.replace(" ", ","));
1104 if (this.type == "text") {
1105 this[0].removeChild(this[0].firstChild);
1106 this[0].appendChild(document.createTextNode(value));
1110 var cssrule = att.replace(/(\-.)/g, function (w) {
1111 return w.substring(1).toUpperCase();
1113 this[0].style[cssrule] = value;
1114 // Need following line for Firefox
1115 this[0].setAttribute(att, value);
1118 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1119 var params = arguments[0];
1120 for (var attr in params) {
1121 this.attrs[attr] = params[attr];
1122 if (attr == "stroke-dasharray") {
1123 this[0].setAttribute(attr, params[attr].replace(" ", ","));
1124 } else if (attr == "text" && this.type == "text") {
1125 this[0].removeChild(this[0].firstChild);
1126 this[0].appendChild(document.createTextNode(params[attr]));
1128 var cssrule = attr.replace(/(\-.)/g, function (w) {
1129 return w.substring(1).toUpperCase();
1131 this[0].style[cssrule] = params[attr];
1132 // Need following line for Firefox
1133 this[0].setAttribute(attr, params[attr]);
1136 if (params.gradient) {
1137 this.attrs.gradient = params.gradient;
1138 addGrdientFill(this[0], params.gradient, this.svg);
1143 Element.prototype.toFront = function () {
1144 this[0].parentNode.appendChild(this[0]);
1147 Element.prototype.toBack = function () {
1148 if (this[0].parentNode.firstChild != this[0]) {
1149 this[0].parentNode.insertBefore(this[0], this[0].parentNode.firstChild);
1153 var theCircle = function (svg, x, y, r) {
1154 var el = document.createElementNS(svg.svgns, "circle");
1155 el.setAttribute("cx", svg._getX(x));
1156 el.setAttribute("cy", svg._getY(y));
1157 el.setAttribute("r", r);
1158 el.setAttribute("fill", "none");
1159 el.setAttribute("stroke", "#000");
1161 svg.canvas.appendChild(el);
1163 var res = new Element(el, svg);
1164 res.attrs = res.attrs || {};
1168 res.attrs.stroke = "#000";
1169 res.type = "circle";
1172 var theRect = function (svg, x, y, w, h, r) {
1173 var el = document.createElementNS(svg.svgns, "rect");
1174 el.setAttribute("x", svg._getX(x));
1175 el.setAttribute("y", svg._getY(y));
1176 el.setAttribute("width", svg._getW(w));
1177 el.setAttribute("height", svg._getH(h));
1179 el.setAttribute("rx", r);
1180 el.setAttribute("ry", r);
1182 el.setAttribute("fill", "none");
1183 el.setAttribute("stroke", "#000");
1185 svg.canvas.appendChild(el);
1187 var res = new Element(el, svg);
1188 res.attrs = res.attrs || {};
1191 res.attrs.width = w;
1192 res.attrs.height = h;
1193 res.attrs.stroke = "#000";
1195 res.attrs.rx = res.attrs.ry = r;
1200 var theEllipse = function (svg, x, y, rx, ry) {
1201 var el = document.createElementNS(svg.svgns, "ellipse");
1202 el.setAttribute("cx", svg._getX(x));
1203 el.setAttribute("cy", svg._getY(y));
1204 el.setAttribute("rx", svg._getW(rx));
1205 el.setAttribute("ry", svg._getH(ry));
1206 el.setAttribute("fill", "none");
1207 el.setAttribute("stroke", "#000");
1209 svg.canvas.appendChild(el);
1211 var res = new Element(el, svg);
1212 res.attrs = res.attrs || {};
1217 res.attrs.stroke = "#000";
1218 res.type = "ellipse";
1221 var theImage = function (svg, src, x, y, w, h) {
1222 var el = document.createElementNS(svg.svgns, "image");
1223 el.setAttribute("x", svg._getX(x));
1224 el.setAttribute("y", svg._getY(y));
1225 el.setAttribute("width", svg._getW(w));
1226 el.setAttribute("height", svg._getH(h));
1227 el.setAttributeNS(svg.xlink, "href", src);
1229 svg.canvas.appendChild(el);
1231 var res = new Element(el, svg);
1232 res.attrs = res.attrs || {};
1235 res.attrs.width = w;
1236 res.attrs.height = h;
1240 var theText = function (svg, x, y, text) {
1241 var el = document.createElementNS(svg.svgns, "text");
1242 el.setAttribute("x", x);
1243 el.setAttribute("y", y);
1244 el.setAttribute("text-anchor", "middle");
1245 el.setAttribute("fill", "#000");
1247 el.appendChild(document.createTextNode(text));
1250 svg.canvas.appendChild(el);
1252 var res = new Element(el, svg);
1253 res.attrs = res.attrs || {};
1256 res.attrs.fill = "#000";
1260 var theGroup = function (svg) {
1261 var el = document.createElementNS(svg.svgns, "g");
1263 svg.canvas.appendChild(el);
1265 var i = new Element(el, svg);
1266 for (var f in svg) {
1267 if (f[0] != "_" && typeof svg[f] == "function") {
1268 i[f] = (function (f) {
1269 return function () {
1270 var e = svg[f].apply(svg, arguments);
1271 el.appendChild(e[0]);
1280 r._create = function () {
1281 // container, width, height
1282 // x, y, width, height
1283 if (typeof arguments[0] == "string") {
1284 var container = document.getElementById(arguments[0]);
1285 var width = arguments[1];
1286 var height = arguments[2];
1288 if (typeof arguments[0] == "object") {
1289 var container = arguments[0];
1290 var width = arguments[1];
1291 var height = arguments[2];
1293 if (typeof arguments[0] == "number") {
1297 width = arguments[2],
1298 height = arguments[3];
1301 throw new Error("SVG container not found.");
1303 C.canvas = document.createElementNS(C.svgns, "svg");
1304 C.canvas.setAttribute("width", width || 320);
1305 C.width = width || 320;
1306 C.canvas.setAttribute("height", height || 200);
1307 C.height = height || 200;
1308 if (container == 1) {
1309 document.body.appendChild(C.canvas);
1310 C.canvas.style.position = "absolute";
1311 C.canvas.style.left = x + "px";
1312 C.canvas.style.top = y + "px";
1314 if (container.firstChild) {
1315 container.insertBefore(C.canvas, container.firstChild);
1317 container.appendChild(C.canvas);
1322 clear: function () {
1323 while (this.canvas.firstChild) {
1324 this.canvas.removeChild(this.canvas.firstChild);
1326 this.defs = document.createElementNS(C.svgns, "defs");
1328 this.canvas.appendChild(this.defs);
1331 for (var prop in C) {
1332 if (prop != "create") {
1333 container[prop] = C[prop];
1339 C.remove = function () {
1340 C.canvas.parentNode.removeChild(C.canvas);
1342 C.svgns = "http://www.w3.org/2000/svg";
1343 C.xlink = "http://www.w3.org/1999/xlink";
1345 if (type == "VML" || type == "SVG") {
1346 C.circle = function (x, y, r) {
1347 return theCircle(this, x, y, r);
1349 C.rect = function (x, y, w, h, r) {
1350 return theRect(this, x, y, w, h, r);
1352 C.ellipse = function (x, y, rx, ry) {
1353 return theEllipse(this, x, y, rx, ry);
1355 C.path = function (params, pathString) {
1356 return thePath(params, pathString, this);
1358 C.image = function (src, x, y, w, h) {
1359 return theImage(this, src, x, y, w, h);
1361 C.text = function (x, y, text) {
1362 return theText(this, x, y, text);
1364 C.group = function () {
1365 return theGroup(this);
1367 C.linerect = function (x, y, w, h, r) {
1368 if (r && parseInt(r, 10)) {
1369 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();
1371 return this.path({stroke: "#000"}).moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).andClose();
1373 C.drawGrid = function (x, y, w, h, wv, hv, color) {
1374 color = color || "#000";
1375 var p = this.path({stroke: color, "stroke-width": 1})
1376 .moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).lineTo(x, y);
1377 for (var i = 1; i < hv; i++) {
1378 p.moveTo(x, y + i * Math.round(h / hv)).lineTo(x + w, y + i * Math.round(h / hv));
1380 for (var i = 1; i < wv; i++) {
1381 p.moveTo(x + i * Math.round(w / wv), y).lineTo(x + i * Math.round(w / wv), y + h);
1385 C.setGrid = function (xmin, ymin, xmax, ymax, w, h) {
1386 var xc = (xmax - xmin) / w;
1387 var yc = (ymax - ymin) / h;
1388 this._getX = function (x) {
1389 return xmin + x * xc;
1391 this._getY = function (y) {
1392 return ymin + y * yc;
1394 this._getW = function (w) {
1397 this._getH = function (h) {
1401 C.clearGrid = function () {
1402 this._getX = this._getY = this._getW = this._getH = function (x) { return x; };
1404 C.safari = function () {
1405 if (r.type == "SVG") {
1406 var rect = C.rect(-C.width, -C.height, C.width * 3, C.height * 3).attr({stroke: "none"});
1407 setTimeout(function () {rect.remove();}, 0);
1410 Element.prototype.animateTo = function (x, y, ms, callback) {
1411 clearTimeout(this.animation_in_progress);
1412 if ("cx" in this.attrs || "x" in this.attrs) {
1413 var is_round = ("cx" in this.attrs),
1414 X = this.attrs.cx || this.attrs.x,
1415 Y = this.attrs.cy || this.attrs.y;
1416 if (x == X && y == Y) {
1422 plus = Y - coeff * X,
1423 alpha = Math.atan(this.coeff);
1424 this.xs = this.step * Math.cos(alpha);
1428 var start = new Date(),
1431 var time = (new Date()).getTime() - start.getTime();
1433 var x1 = X + time * dx / ms;
1434 var y1 = x1 * coeff + plus;
1435 that.attr(is_round ? {cx: x1, cy: y1} : {x: x1, y: y1});
1436 that.animation_in_progress = setTimeout(arguments.callee, 1);
1439 that.attr(is_round ? {cx: x, cy: y} : {x: x, y: y});
1441 callback && callback.call(that);
1448 M: function (p, path, i) {
1449 p.moveTo(path[++i] * 1, path[++i] * 1);
1452 m: function (p, path, i) {
1453 p.moveTo(p.last.x + path[++i] * 1, p.last.y + path[++i] * 1);
1456 C: function (p, path, i) {
1457 p.curveTo(path[++i] * 1, path[++i] * 1, path[++i] * 1, path[++i] * 1, path[++i] * 1, path[++i] * 1);
1460 c: function (p, path, i) {
1461 p.curveTo(p.last.x + path[++i] * 1, p.last.y + path[++i] * 1, p.last.x + path[++i] * 1, p.last.y + path[++i] * 1, p.last.x + path[++i] * 1, p.last.y + path[++i] * 1);
1464 S: function (p, path, i) {
1465 p.curveTo(path[++i] * 1, path[++i] * 1, path[++i] * 1, path[++i] * 1);
1468 s: function (p, path, i) {
1469 p.curveTo(p.last.x + path[++i] * 1, p.last.y + path[++i] * 1, p.last.x + path[++i] * 1, p.last.y + path[++i] * 1);
1472 L: function (p, path, i) {
1473 p.lineTo(path[++i] * 1, path[++i] * 1);
1476 l: function (p, path, i) {
1477 p.lineTo(p.last.x + path[++i] * 1, p.last.y + path[++i] * 1);
1480 H: function (p, path, i) {
1481 p.lineTo(path[++i] * 1, p.last.y);
1484 h: function (p, path, i) {
1485 p.lineTo(p.last.x + path[++i] * 1, p.last.y);
1488 V: function (p, path, i) {
1489 p.lineTo(p.last.x, path[++i] * 1);
1492 v: function (p, path, i) {
1493 p.lineTo(p.last.x, p.last.y + path[++i] * 1);
1496 A: function (p, path, i) {
1497 p.arcTo(path[++i] * 1, path[++i] * 1, path[i += 2], path[++i] * 1, path[++i] * 1, path[++i] * 1, path[++i] * 1);
1500 a: function (p, path, i) {
1501 p.arcTo(p.last.x + path[++i] * 1, p.last.y + path[++i] * 1, path[i += 2] * 1, path[++i] * 1, path[++i] * 1, p.last.x + path[++i] * 1, p.last.y + path[++i] * 1);
1504 z: function (p, path, i) {
1511 return function () {};
1513 })((!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2)) ? "VML" : "SVG");
1516 Raphael.vml = !(Raphael.svg = (Raphael.type == "SVG"));
1517 if (Raphael.vml && window.CanvasRenderingContext2D) {
1518 Raphael.type = "Canvas only";
1519 Raphael.vml = Raphael.svg = false;
1521 Raphael.toString = function () {
1522 return "Your browser supports " + this.type;
1524 // generic utilities
1525 Raphael.hsb2rgb = function (hue, saturation, brightness) {
1526 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
1534 if (brightness == 0) {
1535 return {r: 0, g: 0, b: 0, hex: "#000"};
1537 var i = Math.floor(hue * 6),
1539 p = brightness * (1 - saturation),
1540 q = brightness * (1 - (saturation * f)),
1541 t = brightness * (1 - (saturation * (1 - f)));
1543 function () {red = brightness; green = t; blue = p;},
1544 function () {red = q; green = brightness; blue = p;},
1545 function () {red = p; green = brightness; blue = t;},
1546 function () {red = p; green = q; blue = brightness;},
1547 function () {red = t; green = p; blue = brightness;},
1548 function () {red = brightness; green = p; blue = q;},
1549 function () {red = brightness; green = t; blue = p;},
1552 var rgb = {r: red, g: green, b: blue};
1556 var r = Math.round(red).toString(16);
1557 if (r.length == 1) {
1560 var g = Math.round(green).toString(16);
1561 if (g.length == 1) {
1564 var b = Math.round(blue).toString(16);
1565 if (b.length == 1) {
1568 rgb.hex = "#" + r + g + b;
1571 Raphael.rgb2hsb = function (red, green, blue) {
1572 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
1577 if (red.charAt(0) == "#") {
1578 if (red.length == 4) {
1579 blue = parseInt(red.substring(3), 16);
1580 green = parseInt(red.substring(2, 3), 16);
1581 red = parseInt(red.substring(1, 2), 16);
1583 blue = parseInt(red.substring(5), 16);
1584 green = parseInt(red.substring(3, 5), 16);
1585 red = parseInt(red.substring(1, 3), 16);
1588 if (red > 1 || green > 1 || blue > 1) {
1593 var max = Math.max(red, green, blue),
1594 min = Math.min(red, green, blue),
1599 return {h: 0, s: 0, b: max};
1601 var delta = (max - min);
1602 saturation = delta / max;
1604 hue = (green - blue) / delta;
1605 } else if (green == max) {
1606 hue = 2 + ((blue - red) / delta);
1608 hue = 4 + ((red - green) / delta);
1618 return {h: hue, s: saturation, b: brightness};
1620 Raphael.getColor = function (value) {
1621 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
1622 var rgb = this.hsb2rgb(start.h, start.s, start.b);
1628 start = {h: 0, s: 1, b: start.b};
1633 Raphael.getColor.reset = function () {
1634 this.start = undefined;