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],
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, 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 fill.color = params.fill;
277 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || document.createElement("rvml:stroke");
278 if ((params.stroke && params.stroke != "none") || params["stroke-width"] || params["stroke-opacity"] || params["stroke-dasharray"]) {
281 if (params.stroke == "none" || typeof stroke.on == "undefined") {
284 if (stroke.on && params.stroke) {
285 stroke.color = params.stroke;
287 stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
288 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
289 stroke.miterlimit = params["stroke-miterlimit"] || 8;
290 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
291 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"], 10) || 1) * 12 / 16);
292 if (params["stroke-dasharray"]) {
293 var dashes = params["stroke-dasharray"].replace(" ", ",").split(","),
296 for (var i = 0, ii = dashes.length; i < ii; i++) {
297 var res = dashes[i] / str;
302 stroke.dashstyle = dashesn.join(" ");
304 o.appendChild(stroke);
307 var addGrdientFill = function (o, gradient) {
308 o.attrs = o.attrs || {};
309 o.attrs.gradient = gradient;
311 var fill = o.getElementsByTagName("fill");
315 fill = document.createElement("rvml:fill");
317 if (gradient.dots.length) {
319 fill.type = (gradient.type.toLowerCase() == "linear") ? "gradient" : "gradientradial";
320 if (typeof gradient.dots[0].color != "undefined") {
321 fill.color = gradient.dots[0].color || "#000";
323 if (typeof gradient.dots[0].opacity != "undefined") {
324 fill.opacity = gradient.dots[0].opacity;
326 if (typeof gradient.dots[gradient.dots.length - 1].opacity != "undefined") {
327 fill.opacity2 = gradient.dots[gradient.dots.length - 1].opacity;
329 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
330 fill.color2 = gradient.dots[gradient.dots.length - 1].color || "#000";
333 for (var i = 1, ii = gradient.dots.length - 1; i < ii; i++) {
334 colors += gradient.dots[i].offset + " " + gradient.dots[i].color;
340 fill.colors = colors;
342 if (gradient.vector) {
343 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;
344 fill.angle = angle + 90;
346 if (gradient.type.toLowerCase() == "radial") {
347 fill.focusposition = "0.5, 0.5";
348 fill.focussize = "0, 0";
349 fill.method = "none";
353 var Element = function (node, group, vml) {
365 this.rotate = function (deg) {
366 if (deg == undefined) {
370 this.Group.style.rotation = Rotation;
374 Element.prototype.setBox = function (params) {
375 var gs = this.Group.style,
377 for (var i in params) {
378 this.attrs[i] = params[i];
380 var attr = this.attrs, x, y, w, h;
383 x = attr.cx - attr.r;
384 y = attr.cy - attr.r;
388 x = attr.cx - attr.rx;
389 y = attr.cy - attr.ry;
401 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("");
406 var left = this.vml.width / 2 - w / 2,
407 top = this.vml.height / 2 - h / 2;
408 gs.position = "absolute";
409 gs.left = x - left + "px";
410 gs.top = y - top + "px";
415 gs.width = this.vml.width + "px";
416 gs.height = this.vml.height + "px";
417 os.position = "absolute";
419 os.left = left + "px";
421 os.height = h + "px";
423 Element.prototype.hide = function () {
424 this.Group.style.display = "none";
427 Element.prototype.show = function () {
428 this.Group.style.display = "block";
431 Element.prototype.translate = function (x, y) {
432 if (x == undefined && y == undefined) {
433 return {x: this.X, y: this.Y};
437 this.Group.style.left = this.X + "px";
438 this.Group.style.top = this.Y + "px";
442 Element.prototype.matrix = function (xx, xy, yx, yy, dx, dy) {
443 tMatrix = new Matrix(xx, xy, yx, yy, dx, dy);
444 this.Group.style.filter = tMatrix;
447 Element.prototype.scale = function (x, y) {
448 if (x == undefined && y == undefined) {
453 if (x != 0 && !(x == 1 && y == 1)) {
454 var dirx = Math.round(x / Math.abs(x)),
455 diry = Math.round(y / Math.abs(y)),
457 if (dirx != 1 || diry != 1) {
458 s.filter = new Matrix(dirx, 0, 0, diry, 0, 0);
460 var width = parseInt(s.width, 10) * x * dirx;
461 var height = parseInt(s.height, 10) * y * diry;
462 var left = parseInt(s.left, 10);
463 var top = parseInt(s.top, 10);
464 s.left = this.X = left + this.W / 2 - width / 2;
465 s.top = this.Y = top + this.H / 2 - height / 2;
466 s.width = this.W = width;
467 s.height = this.H = height;
471 Element.prototype.getBBox = function () {
473 x: this.Group.offsetLeft,
474 y: this.Group.offsetTop,
475 width: this.Group.offsetWidth,
476 height: this.Group.offsetHeight
479 Element.prototype.remove = function () {
480 this[0].parentNode.removeChild(this[0]);
481 this.Group.parentNode.removeChild(this.Group);
482 this.shape && this.shape.parentNode.removeChild(this.shape);
484 Element.prototype.attr = function () {
485 if (arguments.length == 1 && typeof arguments[0] == "string") {
486 return this.attrs[arguments[0]];
488 if (this.attrs && arguments.length == 1 && arguments[0] instanceof Array) {
490 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
491 values[arguments[0][i]] = this.attrs[arguments[0][i]];
495 if (this[0].tagName.toLowerCase() == "group") {
496 var children = this[0].childNodes;
497 this.attrs = this.attrs || {};
498 if (arguments.length == 2) {
499 this.attrs[arguments[0]] = arguments[1];
500 } else if (arguments.length == 1 || typeof arguments[0] == "object") {
501 for (var j in arguments[0]) {
502 this.attrs[j] = arguments[0][j];
505 for (var i = 0, ii = children.length; i < ii; i++) {
506 this.attr.apply(new item(children[i], this[0], this.vml), arguments);
510 if (arguments.length == 2) {
512 params[arguments[0]] = arguments[1];
514 if (arguments.length == 1 && typeof arguments[0] == "object") {
515 params = arguments[0];
518 setFillAndStroke(this, params);
520 if (params.gradient) {
521 addGrdientFill(this, params.gradient);
523 if (params.text && this.type == "text") {
524 this[0].string = params.text;
527 this[0].id = params.id;
533 Element.prototype.toFront = function () {
534 this.Group.parentNode.appendChild(this.Group);
537 Element.prototype.toBack = function () {
538 if (this.Group.parentNode.firstChild != this.Group) {
539 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
543 var theCircle = function (vml, x, y, r) {
544 var g = document.createElement("rvml:group");
545 var o = document.createElement("rvml:oval");
547 vml.canvas.appendChild(g);
548 var res = new Element(o, g, vml);
549 setFillAndStroke(res, {stroke: "#000", fill: "none"});
550 res.setBox({x: x - r, y: y - r, w: r * 2, h: r * 2});
557 var theRect = function (vml, x, y, w, h, r) {
558 var g = document.createElement("rvml:group");
559 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect");
561 o.arcsize = r / (Math.min(w, h));
564 vml.canvas.appendChild(g);
565 var res = new Element(o, g, vml);
566 setFillAndStroke(res, {stroke: "#000"});
567 res.setBox({x: x, y: y, w: w, h: h});
576 var theEllipse = function (vml, x, y, rx, ry) {
577 var g = document.createElement("rvml:group");
578 var o = document.createElement("rvml:oval");
580 vml.canvas.appendChild(g);
581 var res = new Element(o, g, vml);
582 setFillAndStroke(res, {stroke: "#000"});
583 res.setBox({x: x - rx, y: y - ry, w: rx * 2, h: ry * 2});
588 res.type = "ellipse";
591 var theImage = function (vml, src, x, y, w, h) {
592 var g = document.createElement("rvml:group");
593 var o = document.createElement("rvml:image");
596 vml.canvas.appendChild(g);
597 var res = new Element(o, g, vml);
599 res.setBox({x: x, y: y, w: w, h: h});
606 var theText = function (vml, x, y, text) {
608 var g = document.createElement("rvml:group"), gs = g.style;
609 var el = document.createElement("rvml:shape"), ol = el.style;
610 var path = document.createElement("rvml:path"), ps = path.style;
611 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
612 path.textpathok = true;
613 ol.width = vml.width;
614 ol.height = vml.height;
615 gs.position = "absolute";
618 gs.width = vml.width;
619 gs.height = vml.height;
620 var o = document.createElement("rvml:textpath");
623 o.coordsize = vml.coordsize;
624 o.coordorigin = vml.coordorigin;
626 el.appendChild(path);
628 vml.canvas.appendChild(g);
629 var res = new Element(o, g, vml);
639 var theGroup = function (vml) {
640 var el = document.createElement("rvml:group"), els = el.style;
641 els.position = "absolute";
644 els.width = vml.width;
645 els.height = vml.height;
647 vml.canvas.appendChild(el);
649 var res = new Element(el, el, vml);
651 if (f.charAt(0) != "_" && typeof vml[f] == "function") {
652 res[f] = (function (f) {
654 var e = vml[f].apply(vml, arguments);
655 el.appendChild(e[0].parentNode);
664 r._create = function () {
665 // container, width, height
666 // x, y, width, height
667 var container, width, height;
668 if (typeof arguments[0] == "string") {
669 container = document.getElementById(arguments[0]);
670 width = arguments[1];
671 height = arguments[2];
673 if (typeof arguments[0] == "object") {
674 container = arguments[0];
675 width = arguments[1];
676 height = arguments[2];
678 if (typeof arguments[0] == "number") {
682 width = arguments[2];
683 height = arguments[3];
686 throw new Error("VML container not found.");
688 if (!document.namespaces["rvml"]) {
689 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
690 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
692 var c = document.createElement("div"),
693 r = C.canvas = document.createElement("rvml:group"),
694 cs = c.style, rs = r.style;
697 width = width || "320px";
698 height = height || "200px";
699 cs.clip = "rect(0 " + width + " " + height + " 0)";
700 cs.position = "absolute";
703 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
704 r.coordorigin = "0 0";
706 var b = document.createElement("rvml:rect"), bs = b.style;
707 bs.left = bs.top = 0;
709 bs.height = rs.height;
710 b.filled = b.stroked = "f";
714 if (container == 1) {
715 document.body.appendChild(c);
716 cs.position = "absolute";
728 cs.width = container.style.width = width;
729 cs.height = container.style.height = height;
730 if (container.firstChild) {
731 container.insertBefore(c, container.firstChild);
733 container.appendChild(c);
736 for (var prop in C) {
737 container[prop] = C[prop];
739 container.clear = function () {
741 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
742 if (r.childNodes[i] != b) {
743 todel.push(r.childNodes[i]);
746 for (i = 0, ii = todel.length; i < ii; i++) {
747 r.removeChild(todel[i]);
752 C.remove = function () {
753 C.canvas.parentNode.parentNode.removeChild(C.canvas.parentNode);
757 Matrix.prototype.toString = function () {
758 return "matrix(" + this.m[0][0] +
759 ", " + this.m[1][0] + ", " + this.m[0][1] + ", " + this.m[1][1] +
760 ", " + this.m[2][0] + ", " + this.m[2][1] + ")";
762 var thePath = function (params, pathString, SVG) {
763 var el = document.createElementNS(SVG.svgns, "path");
764 el.setAttribute("fill", "none");
766 for (var attr in params) {
767 if (params.gradient) {
768 addGrdientFill(el, params.gradient, SVG);
770 el.setAttribute(attr, params[attr]);
775 SVG.canvas.appendChild(el);
777 var p = new Element(el, SVG);
778 for (var attr in params) {
779 p.attrs[attr] = params[attr];
783 p.last = {x: 0, y: 0, bx: 0, by: 0};
784 p.absolutely = function () {
785 this.isAbsolute = true;
788 p.relatively = function () {
789 this.isAbsolute = false;
792 p.redraw = function () {
793 this[0].setAttribute("d", "M0 0");
794 var oldPath = this.path;
796 for (var i = 0, ii = oldPath.length; i < ii; i++) {
797 if (oldPath[i].type != "end") {
798 this[oldPath[i].type + "To"].apply(this, oldPath[i].arg);
805 p.moveTo = function (x, y) {
806 var d = this.isAbsolute?"M":"m";
807 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
808 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
809 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
810 var oldD = this[0].getAttribute("d") || "";
811 this[0].setAttribute("d", oldD + d);
812 this.last.x = (this.isAbsolute ? 0 : this.last.x) + SVG._getX(parseFloat(x, 10));
813 this.last.y = (this.isAbsolute ? 0 : this.last.y) + SVG._getY(parseFloat(y, 10));
814 this.path.push({type: "move", arg: arguments, pos: this.isAbsolute});
817 p.lineTo = function (x, y) {
818 this.last.x = (this.isAbsolute ? 0 : this.last.x) + SVG._getX(parseFloat(x, 10));
819 this.last.y = (this.isAbsolute ? 0 : this.last.y) + SVG._getY(parseFloat(y, 10));
820 var d = this.isAbsolute?"L":"l";
821 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
822 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
823 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
824 var oldD = this[0].getAttribute("d") || "";
825 this[0].setAttribute("d", oldD + d);
826 this.path.push({type: "line", arg: arguments, pos: this.isAbsolute});
829 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
830 var d = this.isAbsolute ? "A" : "a";
831 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
832 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
833 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(" ");
834 var oldD = this[0].getAttribute("d") || "";
835 this[0].setAttribute("d", oldD + d);
836 this.last.x = SVG._getX(parseFloat(x, 10));
837 this.last.y = SVG._getY(parseFloat(y, 10));
838 this.path.push({type: "arc", arg: arguments, pos: this.isAbsolute});
841 p.cplineTo = function (x1, y1, w1) {
843 return this.lineTo(x1, y1);
846 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
847 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
848 var x = p._getX(Math.round(parseFloat(x1, 10) * 100) / 100);
849 var y = p._getY(Math.round(parseFloat(y1, 10) * 100) / 100);
850 var w = SVG._getW(Math.round(parseFloat(w1, 10) * 100) / 100);
851 var d = this.isAbsolute?"C":"c";
852 var attr = [this.last.x + w, this.last.y, x - w, y, x, y];
853 for (var i = 0, ii = attr.length; i < ii; i++) {
856 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
857 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
858 this.last.bx = attr[2];
859 this.last.by = attr[3];
860 var oldD = this[0].getAttribute("d") || "";
861 this[0].setAttribute("d", oldD + d);
862 this.path.push({type: "cpline", arg: arguments, pos: this.isAbsolute});
866 p.curveTo = function () {
868 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
869 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
870 if (arguments.length == 6) {
871 var d = this.isAbsolute?"C":"c";
872 for (var i = 0, ii = arguments.length; i < ii; i++) {
873 d += p[(i % 2 == 0) ? "_getX" : "_getY"](Math.round(parseFloat(arguments[i], 10) * 100) / 100) + " ";
875 this.last.x = (this.isAbsolute ? 0 : this.last.x) + p._getX((parseFloat(arguments[4], 10) * 100) / 100);
876 this.last.y = (this.isAbsolute ? 0 : this.last.y) + p._getY((parseFloat(arguments[5], 10) * 100) / 100);
877 this.last.bx = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
878 this.last.by = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
880 if (arguments.length == 4) {
881 var d = this.isAbsolute?"S":"s";
882 for (var i = 0, ii = arguments.length; i < ii; i++) {
883 d += p[i % 2 == 0 ? "_getX" : "_getY"]((parseFloat(arguments[i], 10) * 100) / 100) + " ";
886 this.last.x = (this.isAbsolute ? 0 : this.last.x) + p._getX((parseFloat(arguments[2], 10) * 100) / 100);
887 this.last.y = (this.isAbsolute ? 0 : this.last.y) + p._getY((parseFloat(arguments[3], 10) * 100) / 100);
888 this.last.bx = p._getX((parseFloat(arguments[0], 10) * 100) / 100);
889 this.last.by = p._getY((parseFloat(arguments[1], 10) * 100) / 100);
891 var oldD = this[0].getAttribute("d") || "";
892 this[0].setAttribute("d", oldD + d);
893 this.path.push({type: "curve", arg: arguments, pos: this.isAbsolute});
896 p.addRoundedCorner = function (r, dir) {
897 var R = .5522 * r, rollback = this.isAbsolute, o = this;
900 rollback = function () {
904 rollback = function () {};
910 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
913 o.curveTo(-R, 0, -r, r - R, -r, r);
920 o.curveTo(R, 0, r, -(r - R), r, -r);
923 o.curveTo(R, 0, r, r - R, r, r);
930 o.curveTo(0, -R, -(R - r), -r, r, -r);
933 o.curveTo(0, -R, R - r, -r, -r, -r);
940 o.curveTo(0, R, -(R - r), r, r, r);
943 o.curveTo(0, R, R - r, r, -r, r);
948 actions[dir[0]]()[dir[1]]();
952 p.andClose = function () {
953 var oldD = this[0].getAttribute("d") || "";
954 this[0].setAttribute("d", oldD + "Z ");
955 this.path.push({type: "end"});
958 if (typeof pathString == "string") {
960 C.pathfinder(p, pathString);
964 var addGrdientFill = function (o, gradient, SVG) {
965 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
966 el.id = "raphael-gradient-" + SVG.gradients++;
967 if (gradient.vector && gradient.vector.length) {
968 el.setAttribute("x1", gradient.vector[0]);
969 el.setAttribute("y1", gradient.vector[1]);
970 el.setAttribute("x2", gradient.vector[2]);
971 el.setAttribute("y2", gradient.vector[3]);
973 SVG.defs.appendChild(el);
974 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
975 var stop = document.createElementNS(SVG.svgns, "stop");
976 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
977 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
978 if (typeof gradient.dots[i].opacity != "undefined") {
979 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
981 el.appendChild(stop);
983 o.setAttribute("fill", "url(#" + el.id + ")");
985 var Element = function (node, svg) {
988 Rotation = {deg: 0, x: 0, y: 0},
995 this.attrs = this.attrs || {};
996 this.transformations = []; // rotate, translate, scale, matrix
997 this.rotate = function (deg) {
998 if (deg == undefined) {
1001 var bbox = this.getBBox();
1002 Rotation.deg += deg;
1004 this.transformations[0] = ("rotate(" + Rotation.deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
1006 this.transformations[0] = "";
1008 this[0].setAttribute("transform", this.transformations.join(" "));
1011 this.translate = function (x, y) {
1012 if (x == undefined && y == undefined) {
1013 return {x: X, y: Y};
1018 this.transformations[1] = "translate(" + X + "," + Y + ")";
1020 this.transformations[1] = "";
1022 this[0].setAttribute("transform", this.transformations.join(" "));
1025 this.scale = function (x, y) {
1026 if (x == undefined && y == undefined) {
1027 return {x: ScaleX, y: ScaleY};
1030 if (x != 0 && !(x == 1 && y == 1)) {
1033 if (!(ScaleX == 1 && ScaleY == 1)) {
1034 var bbox = this.getBBox(),
1035 dx = bbox.x * (1 - ScaleX) + (bbox.width / 2 - bbox.width * ScaleX / 2),
1036 dy = bbox.y * (1 - ScaleY) + (bbox.height / 2 - bbox.height * ScaleY / 2);
1037 this.transformations[2] = new Matrix(ScaleX, 0, 0, ScaleY, dx, dy);
1039 this.transformations[2] = "";
1041 this[0].setAttribute("transform", this.transformations.join(" "));
1046 Element.prototype.hide = function () {
1047 this[0].style.display = "none";
1050 Element.prototype.show = function () {
1051 this[0].style.display = "block";
1055 Element.prototype.matrix = function (xx, xy, yx, yy, dx, dy) {
1056 this.transformations[3] = new Matrix(xx, xy, yx, yy, dx, dy);
1057 this[0].setAttribute("transform", this.transformations.join(" "));
1060 Element.prototype.remove = function () {
1061 this[0].parentNode.removeChild(this[0]);
1063 Element.prototype.getBBox = function () {
1064 return this[0].getBBox();
1066 Element.prototype.attr = function () {
1067 if (arguments.length == 1 && typeof arguments[0] == "string") {
1068 return this[0].getAttribute(arguments[0]);
1070 if (arguments.length == 1 && arguments[0] instanceof Array) {
1072 for (var j in arguments[0]) {
1073 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1077 if (arguments.length == 2) {
1078 var att = arguments[0],
1079 value = arguments[1];
1081 this.attrs[att] = value;
1086 this[0].setAttribute(att, this.svg._getX(value));
1091 this[0].setAttribute(att, this.svg._getY(value));
1094 this[0].setAttribute(att, this.svg._getW(value));
1097 this[0].setAttribute(att, this.svg._getH(value));
1100 addGrdientFill(this[0], value, this.svg);
1102 case "stroke-dasharray":
1103 this[0].setAttribute(att, value.replace(" ", ","));
1106 if (this.type == "text") {
1107 this[0].removeChild(this[0].firstChild);
1108 this[0].appendChild(document.createTextNode(value));
1112 var cssrule = att.replace(/(\-.)/g, function (w) {
1113 return w.substring(1).toUpperCase();
1115 this[0].style[cssrule] = value;
1116 // Need following line for Firefox
1117 this[0].setAttribute(att, value);
1120 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
1121 var params = arguments[0];
1122 for (var attr in params) {
1123 this.attrs[attr] = params[attr];
1124 if (attr == "stroke-dasharray") {
1125 this[0].setAttribute(attr, params[attr].replace(" ", ","));
1126 } else if (attr == "text" && this.type == "text") {
1127 this[0].childNodes.length && this[0].removeChild(this[0].firstChild);
1128 this[0].appendChild(document.createTextNode(params.text));
1130 var cssrule = attr.replace(/(\-.)/g, function (w) {
1131 return w.substring(1).toUpperCase();
1133 this[0].style[cssrule] = params[attr];
1134 // Need following line for Firefox
1135 this[0].setAttribute(attr, params[attr]);
1138 if (params.gradient) {
1139 this.attrs.gradient = params.gradient;
1140 addGrdientFill(this[0], params.gradient, this.svg);
1145 Element.prototype.toFront = function () {
1146 this[0].parentNode.appendChild(this[0]);
1149 Element.prototype.toBack = function () {
1150 if (this[0].parentNode.firstChild != this[0]) {
1151 this[0].parentNode.insertBefore(this[0], this[0].parentNode.firstChild);
1155 var theCircle = function (svg, x, y, r) {
1156 var el = document.createElementNS(svg.svgns, "circle");
1157 el.setAttribute("cx", svg._getX(x));
1158 el.setAttribute("cy", svg._getY(y));
1159 el.setAttribute("r", r);
1160 el.setAttribute("fill", "none");
1161 el.setAttribute("stroke", "#000");
1163 svg.canvas.appendChild(el);
1165 var res = new Element(el, svg);
1166 res.attrs = res.attrs || {};
1170 res.attrs.stroke = "#000";
1171 res.type = "circle";
1174 var theRect = function (svg, x, y, w, h, r) {
1175 var el = document.createElementNS(svg.svgns, "rect");
1176 el.setAttribute("x", svg._getX(x));
1177 el.setAttribute("y", svg._getY(y));
1178 el.setAttribute("width", svg._getW(w));
1179 el.setAttribute("height", svg._getH(h));
1181 el.setAttribute("rx", r);
1182 el.setAttribute("ry", r);
1184 el.setAttribute("fill", "none");
1185 el.setAttribute("stroke", "#000");
1187 svg.canvas.appendChild(el);
1189 var res = new Element(el, svg);
1190 res.attrs = res.attrs || {};
1193 res.attrs.width = w;
1194 res.attrs.height = h;
1195 res.attrs.stroke = "#000";
1197 res.attrs.rx = res.attrs.ry = r;
1202 var theEllipse = function (svg, x, y, rx, ry) {
1203 var el = document.createElementNS(svg.svgns, "ellipse");
1204 el.setAttribute("cx", svg._getX(x));
1205 el.setAttribute("cy", svg._getY(y));
1206 el.setAttribute("rx", svg._getW(rx));
1207 el.setAttribute("ry", svg._getH(ry));
1208 el.setAttribute("fill", "none");
1209 el.setAttribute("stroke", "#000");
1211 svg.canvas.appendChild(el);
1213 var res = new Element(el, svg);
1214 res.attrs = res.attrs || {};
1219 res.attrs.stroke = "#000";
1220 res.type = "ellipse";
1223 var theImage = function (svg, src, x, y, w, h) {
1224 var el = document.createElementNS(svg.svgns, "image");
1225 el.setAttribute("x", svg._getX(x));
1226 el.setAttribute("y", svg._getY(y));
1227 el.setAttribute("width", svg._getW(w));
1228 el.setAttribute("height", svg._getH(h));
1229 el.setAttributeNS(svg.xlink, "href", src);
1231 svg.canvas.appendChild(el);
1233 var res = new Element(el, svg);
1234 res.attrs = res.attrs || {};
1237 res.attrs.width = w;
1238 res.attrs.height = h;
1242 var theText = function (svg, x, y, text) {
1243 var el = document.createElementNS(svg.svgns, "text");
1244 el.setAttribute("x", x);
1245 el.setAttribute("y", y);
1246 el.setAttribute("text-anchor", "middle");
1247 el.setAttribute("fill", "#000");
1249 el.appendChild(document.createTextNode(text));
1252 svg.canvas.appendChild(el);
1254 var res = new Element(el, svg);
1255 res.attrs = res.attrs || {};
1258 res.attrs.fill = "#000";
1262 var theGroup = function (svg) {
1263 var el = document.createElementNS(svg.svgns, "g");
1265 svg.canvas.appendChild(el);
1267 var i = new Element(el, svg);
1268 for (var f in svg) {
1269 if (f[0] != "_" && typeof svg[f] == "function") {
1270 i[f] = (function (f) {
1271 return function () {
1272 var e = svg[f].apply(svg, arguments);
1273 el.appendChild(e[0]);
1282 r._create = function () {
1283 // container, width, height
1284 // x, y, width, height
1285 if (typeof arguments[0] == "string") {
1286 var container = document.getElementById(arguments[0]);
1287 var width = arguments[1];
1288 var height = arguments[2];
1290 if (typeof arguments[0] == "object") {
1291 var container = arguments[0];
1292 var width = arguments[1];
1293 var height = arguments[2];
1295 if (typeof arguments[0] == "number") {
1299 width = arguments[2],
1300 height = arguments[3];
1303 throw new Error("SVG container not found.");
1305 C.canvas = document.createElementNS(C.svgns, "svg");
1306 C.canvas.setAttribute("width", width || 320);
1307 C.width = width || 320;
1308 C.canvas.setAttribute("height", height || 200);
1309 C.height = height || 200;
1310 if (container == 1) {
1311 document.body.appendChild(C.canvas);
1312 C.canvas.style.position = "absolute";
1313 C.canvas.style.left = x + "px";
1314 C.canvas.style.top = y + "px";
1316 if (container.firstChild) {
1317 container.insertBefore(C.canvas, container.firstChild);
1319 container.appendChild(C.canvas);
1324 clear: function () {
1325 while (this.canvas.firstChild) {
1326 this.canvas.removeChild(this.canvas.firstChild);
1328 this.defs = document.createElementNS(C.svgns, "defs");
1330 this.canvas.appendChild(this.defs);
1333 for (var prop in C) {
1334 if (prop != "create") {
1335 container[prop] = C[prop];
1341 C.remove = function () {
1342 C.canvas.parentNode.removeChild(C.canvas);
1344 C.svgns = "http://www.w3.org/2000/svg";
1345 C.xlink = "http://www.w3.org/1999/xlink";
1347 if (type == "VML" || type == "SVG") {
1348 C.circle = function (x, y, r) {
1349 return theCircle(this, x, y, r);
1351 C.rect = function (x, y, w, h, r) {
1352 return theRect(this, x, y, w, h, r);
1354 C.ellipse = function (x, y, rx, ry) {
1355 return theEllipse(this, x, y, rx, ry);
1357 C.path = function (params, pathString) {
1358 return thePath(params, pathString, this);
1360 C.image = function (src, x, y, w, h) {
1361 return theImage(this, src, x, y, w, h);
1363 C.text = function (x, y, text) {
1364 return theText(this, x, y, text);
1366 C.group = function () {
1367 return theGroup(this);
1369 C.linerect = function (x, y, w, h, r) {
1370 if (r && parseInt(r, 10)) {
1371 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();
1373 return this.path({stroke: "#000"}).moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).andClose();
1375 C.drawGrid = function (x, y, w, h, wv, hv, color) {
1376 color = color || "#000";
1377 var p = this.path({stroke: color, "stroke-width": 1})
1378 .moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).lineTo(x, y);
1379 for (var i = 1; i < hv; i++) {
1380 p.moveTo(x, y + i * Math.round(h / hv)).lineTo(x + w, y + i * Math.round(h / hv));
1382 for (var i = 1; i < wv; i++) {
1383 p.moveTo(x + i * Math.round(w / wv), y).lineTo(x + i * Math.round(w / wv), y + h);
1387 C.setGrid = function (xmin, ymin, xmax, ymax, w, h) {
1388 var xc = (xmax - xmin) / w;
1389 var yc = (ymax - ymin) / h;
1390 this._getX = function (x) {
1391 return xmin + x * xc;
1393 this._getY = function (y) {
1394 return ymin + y * yc;
1396 this._getW = function (w) {
1399 this._getH = function (h) {
1403 C.clearGrid = function () {
1404 this._getX = this._getY = this._getW = this._getH = function (x) { return x; };
1406 C.safari = function () {
1407 if (r.type == "SVG") {
1408 var rect = C.rect(-C.width, -C.height, C.width * 3, C.height * 3).attr({stroke: "none"});
1409 setTimeout(function () {rect.remove();}, 0);
1412 Element.prototype.animateTo = function (x, y, ms, callback) {
1413 clearTimeout(this.animation_in_progress);
1414 if ("cx" in this.attrs || "x" in this.attrs) {
1415 var is_round = ("cx" in this.attrs),
1416 X = this.attrs.cx || this.attrs.x,
1417 Y = this.attrs.cy || this.attrs.y;
1418 if (x == X && y == Y) {
1424 plus = Y - coeff * X,
1425 alpha = Math.atan(this.coeff);
1426 this.xs = this.step * Math.cos(alpha);
1430 var start = new Date(),
1433 var time = (new Date()).getTime() - start.getTime();
1435 var x1 = X + time * dx / ms;
1436 var y1 = x1 * coeff + plus;
1437 that.attr(is_round ? {cx: x1, cy: y1} : {x: x1, y: y1});
1438 that.animation_in_progress = setTimeout(arguments.callee, 1);
1441 that.attr(is_round ? {cx: x, cy: y} : {x: x, y: y});
1443 callback && callback.call(that);
1449 C.pathfinder = function (p, path) {
1451 M: function (x, y) {
1454 m: function (x, y) {
1455 this.moveTo(this.last.x + x, this.last.y + y);
1457 C: function (x1, y1, x2, y2, x3, y3) {
1458 this.curveTo(x1, y1, x2, y2, x3, y3);
1460 c: function (x1, y1, x2, y2, x3, y3) {
1461 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);
1463 S: function (x1, y1, x2, y2) {
1464 p.curveTo(x1, y1, x2, y2);
1466 s: function (x1, y1, x2, y2) {
1467 this.curveTo(this.last.x + x1, this.last.y + y1, this.last.x + x2, this.last.y + y2);
1469 L: function (x, y) {
1472 l: function (x, y) {
1473 this.lineTo(this.last.x + x, this.last.y + y);
1476 this.lineTo(x, this.last.y);
1479 this.lineTo(this.last.x + x, this.last.y);
1482 this.lineTo(this.last.x, y);
1485 this.lineTo(this.last.x, this.last.y + y);
1487 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
1488 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
1490 a: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
1491 this.arcTo(this.last.x + rx, this.last.y + ry, largearcflag, sweethisflag, this.last.x + x, this.last.y + y);
1497 path.replace(/([mzlhvcsqta])\s*((-?\d*\.?\d*\s*,?\s*)+)/ig, function (a, b, c) {
1499 c.replace(/(-?\d*\.?\d*)\s*,?\s*/ig, function (a, b) {
1500 b && params.push(+b);
1502 while (params.length >= commands[b].length) {
1503 commands[b].apply(p, params.splice(0, commands[b].length));
1504 if (!commands[b].length) {
1512 return function () {};
1514 })((!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2)) ? "VML" : "SVG");
1517 Raphael.vml = !(Raphael.svg = (Raphael.type == "SVG"));
1518 if (Raphael.vml && window.CanvasRenderingContext2D) {
1519 Raphael.type = "Canvas only";
1520 Raphael.vml = Raphael.svg = false;
1522 Raphael.toString = function () {
1523 return "Your browser supports " + this.type + ".\nYou are running " + unescape("Rapha%EBl%20") + this.version;
1525 // generic utilities
1526 Raphael.hsb2rgb = function (hue, saturation, brightness) {
1527 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
1535 if (brightness == 0) {
1536 return {r: 0, g: 0, b: 0, hex: "#000"};
1538 var i = Math.floor(hue * 6),
1540 p = brightness * (1 - saturation),
1541 q = brightness * (1 - (saturation * f)),
1542 t = brightness * (1 - (saturation * (1 - f)));
1544 function () {red = brightness; green = t; blue = p;},
1545 function () {red = q; green = brightness; blue = p;},
1546 function () {red = p; green = brightness; blue = t;},
1547 function () {red = p; green = q; blue = brightness;},
1548 function () {red = t; green = p; blue = brightness;},
1549 function () {red = brightness; green = p; blue = q;},
1550 function () {red = brightness; green = t; blue = p;},
1553 var rgb = {r: red, g: green, b: blue};
1557 var r = Math.round(red).toString(16);
1558 if (r.length == 1) {
1561 var g = Math.round(green).toString(16);
1562 if (g.length == 1) {
1565 var b = Math.round(blue).toString(16);
1566 if (b.length == 1) {
1569 rgb.hex = "#" + r + g + b;
1572 Raphael.rgb2hsb = function (red, green, blue) {
1573 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
1578 if (typeof red == "string" && red.charAt(0) == "#") {
1579 if (red.length == 4) {
1580 blue = parseInt(red.substring(3), 16);
1581 green = parseInt(red.substring(2, 3), 16);
1582 red = parseInt(red.substring(1, 2), 16);
1584 blue = parseInt(red.substring(5), 16);
1585 green = parseInt(red.substring(3, 5), 16);
1586 red = parseInt(red.substring(1, 3), 16);
1589 if (red > 1 || green > 1 || blue > 1) {
1594 var max = Math.max(red, green, blue),
1595 min = Math.min(red, green, blue),
1600 return {h: 0, s: 0, b: max};
1602 var delta = (max - min);
1603 saturation = delta / max;
1605 hue = (green - blue) / delta;
1606 } else if (green == max) {
1607 hue = 2 + ((blue - red) / delta);
1609 hue = 4 + ((red - green) / delta);
1619 return {h: hue, s: saturation, b: brightness};
1621 Raphael.getColor = function (value) {
1622 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
1623 var rgb = this.hsb2rgb(start.h, start.s, start.b);
1629 arguments.callee.start = {h: 0, s: 1, b: start.b};
1634 Raphael.getColor.reset = function () {
1635 this.start = undefined;