2 return (function (r, args) {
5 function Matrix(m11, m12, m21, m22, dx, dy) {
7 [m11 || 1, m12 || 0, 0],
8 [m21 || 0, m22 || 1, 0],
13 C._getX = C._getY = C._getW = C._getH = function (x) { return x; };
16 Matrix.prototype.toString = function () {
17 return "progid:DXImageTransform.Microsoft.Matrix(M11=" + this.m[0][0] +
18 ", M12=" + this.m[1][0] + ", M21=" + this.m[0][1] + ", M22=" + this.m[1][1] +
19 ", Dx=" + this.m[2][0] + ", Dy=" + this.m[2][1] + ", sizingmethod='auto expand', filtertype='bilinear')";
21 var thePath = function (params, pathString, VML) {
22 var g = document.createElement("rvml:group"), gl = g.style;
23 gl.position = "absolute";
26 gl.width = VML.width + "px";
27 gl.height = VML.height + "px";
28 var el = document.createElement("rvml:shape"), ol = el.style;
29 ol.width = VML.width + "px";
30 ol.height = VML.height + "px";
32 if (params["class"]) {
33 el.className = params["class"];
35 el.coordsize = this.coordsize;
36 el.coordorigin = this.coordorigin;
38 VML.canvas.appendChild(g);
39 var p = new Element(el, g, VML);
40 setFillAndStroke(p, params);
41 if (params.gradient) {
42 addGrdientFill(p, params.gradient);
47 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
49 p.absolutely = function () {
50 this.isAbsolute = true;
53 p.relatively = function () {
54 this.isAbsolute = false;
57 p.redraw = function () {
59 var oldPath = this.path;
61 for (var i = 0, ii = oldPath.length; i < ii; i++) {
62 if (oldPath[i].type != "end") {
63 this[oldPath[i].type + "To"].apply(this, oldPath[i].arg);
69 p.moveTo = function (x, y) {
70 var d = this.isAbsolute?"m":"t";
71 var _getX = this.isAbsolute ? VML._getX : VML._getW;
72 var _getY = this.isAbsolute ? VML._getY : VML._getH;
73 d += Math.round(_getX(parseFloat(x, 10))) + " " + Math.round(_getY(parseFloat(y, 10)));
74 this[0].path = this.Path += d;
75 this.last.x = Math.round(_getX(parseFloat(x, 10)));
76 this.last.y = Math.round(_getY(parseFloat(y, 10)));
77 this.last.isAbsolute = this.isAbsolute;
78 this.path.push({type: "move", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
81 p.lineTo = function (x, y) {
82 var d = this.isAbsolute?"l":"r";
83 var _getX = this.isAbsolute ? VML._getX : VML._getW;
84 var _getY = this.isAbsolute ? VML._getY : VML._getH;
85 d += Math.round(_getX(parseFloat(x, 10))) + " " + Math.round(_getY(parseFloat(y, 10)));
86 this[0].path = this.Path += d;
87 this.last.x = Math.round(_getX(parseFloat(x, 10)));
88 this.last.y = Math.round(_getY(parseFloat(y, 10)));
89 this.last.isAbsolute = this.isAbsolute;
90 this.path.push({type: "line", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
93 p.cplineTo = function (x1, y1, w1) {
95 return this.lineTo(x1, y1);
98 p._getX = this.isAbsolute ? VML._getX : VML._getW;
99 p._getY = this.isAbsolute ? VML._getY : VML._getH;
100 var x = Math.round(p._getX(Math.round(parseFloat(x1, 10) * 100) / 100));
101 var y = Math.round(p._getY(Math.round(parseFloat(y1, 10) * 100) / 100));
102 var w = Math.round(VML._getW(Math.round(parseFloat(w1, 10) * 100) / 100));
103 var d = this.isAbsolute?"c":"v";
104 var attr = [this.last.x + w, this.last.y, x - w, y, x, y];
105 d += attr.join(" ") + " ";
106 this.last.x = attr[4];
107 this.last.y = attr[5];
108 this.last.bx = attr[2];
109 this.last.by = attr[3];
110 this[0].path = this.Path += d;
111 this.path.push({type: "cpline", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
115 p.curveTo = function () {
116 var d = this.isAbsolute?"c":"v";
117 var _getX = this.isAbsolute ? VML._getX : VML._getW;
118 var _getY = this.isAbsolute ? VML._getY : VML._getH;
119 if (arguments.length == 6) {
120 this.last.x = Math.round(_getX(parseFloat(arguments[4], 10)));
121 this.last.y = Math.round(_getY(parseFloat(arguments[5], 10)));
122 this.last.bx = Math.round(_getX(parseFloat(arguments[2], 10)));
123 this.last.by = Math.round(_getY(parseFloat(arguments[3], 10)));
124 d += Math.round(_getX(parseFloat(arguments[0], 10))) + " " + Math.round(_getY(parseFloat(arguments[1], 10))) + " " +
125 Math.round(_getX(parseFloat(arguments[2], 10))) + " " + Math.round(_getY(parseFloat(arguments[3], 10))) + " " +
126 Math.round(_getX(parseFloat(arguments[4], 10))) + " " + Math.round(_getY(parseFloat(arguments[5], 10))) + " ";
127 this.last.isAbsolute = this.isAbsolute;
129 this[0].path = this.Path += d;
130 this.path.push({type: "curve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
133 p.addRoundedCorner = function (r, dir) {
134 var R = .5522 * r, rollback = this.isAbsolute, o = this;
137 rollback = function () {
141 rollback = function () {};
147 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
150 o.curveTo(-R, 0, -r, r - R, -r, r);
157 o.curveTo(R, 0, r, -(r - R), r, -r);
160 o.curveTo(R, 0, r, r - R, r, r);
167 o.curveTo(0, -R, -(R - r), -r, r, -r);
170 o.curveTo(0, -R, R - r, -r, -r, -r);
177 o.curveTo(0, R, -(R - r), r, r, r);
180 o.curveTo(0, R, R - r, r, -r, r);
185 actions[dir.charAt(0)]()[dir.charAt(1)]();
189 p.andClose = function () {
190 this[0].path = (this.Path += "x e");
193 if (typeof pathString == "string") {
194 pathString = pathString.replace(/([mzlhvcsqta])/ig, ",$1,").replace(/([^,])\-/ig, "$1,-");
195 path = pathString.split(",");
196 var i = 1, ii = path.length;
200 p.absolutely().moveTo(path[++i], path[++i]);
203 p.relatively().moveTo(path[++i], path[++i]);
206 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
209 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
212 p.absolutely().lineTo(path[++i], path[++i]);
215 p.relatively().lineTo(path[++i], path[++i]);
218 p.absolutely().lineTo(path[++i], 0);
221 p.relatively().lineTo(path[++i], 0);
224 p.absolutely().lineTo(0, path[++i]);
227 p.relatively().lineTo(0, path[++i]);
239 var setFillAndStroke = function (o, params) {
240 o[0].attrs = o[0].attrs || {};
241 for (var par in params) {
242 o[0].attrs[par] = params[par];
244 params["font-family"] && (o[0].style.fontFamily = params["font-family"]);
245 params["font-size"] && (o[0].style.fontSize = params["font-size"]);
246 params["font"] && (o[0].style.font = params["font"]);
247 params["font-weight"] && (o[0].style.fontWeight = params["font-weight"]);
248 if (typeof params.opacity != "undefined" || typeof params["stroke-width"] != "undefined" || typeof params.fill != "undefined" || typeof params.stroke != "undefined") {
250 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || document.createElement("rvml:fill");
251 if ("fill-opacity" in params || "opacity" in params) {
252 fill.opacity = ((params["fill-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
254 params.fill && (fill.on = true);
256 fill.color = params.fill;
258 if (params.fill == "none") {
262 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || document.createElement("rvml:stroke");
263 stroke.on = !!(params.stroke || params["stroke-width"] || params["stroke-opacity"] || params["stroke-dasharray"]);
265 stroke.color = params.stroke;
267 stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
268 stroke.joinstyle = params["stroke-linejoin"] || "miter";
269 stroke.miterlimit = params["stroke-miterlimit"] || 8;
270 stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"] || "miter"];
271 stroke.weight = parseFloat(params["stroke-width"], 10) + "px" || "1px";
272 if (params["stroke-dasharray"]) {
273 var dashes = params["stroke-dasharray"].replace(" ", ",").split(","),
275 str = parseFloat(stroke.weight, 10);
276 for (var i = 0, ii = dashes.length; i < ii; i++) {
277 var res = dashes[i] / str;
282 stroke.dashstyle = dashesn.join(" ");
284 o.appendChild(stroke);
287 var addGrdientFill = function (o, gradient) {
288 o[0].attrs = o[0].attrs || {};
289 o[0].attrs.gradient = gradient;
291 var fill = o.getElementsByTagName("fill");
295 fill = document.createElement("rvml:fill");
297 if (gradient.dots.length) {
299 fill.type = (gradient.type.toLowerCase() == "linear") ? "gradient" : "gradientradial";
300 if (typeof gradient.dots[0].color != "undefined") {
301 fill.color = gradient.dots[0].color || "#000";
303 if (typeof gradient.dots[0].opacity != "undefined") {
304 fill.opacity = gradient.dots[0].opacity;
306 if (typeof gradient.dots[gradient.dots.length - 1].opacity != "undefined") {
307 fill.opacity2 = gradient.dots[gradient.dots.length - 1].opacity;
309 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
310 fill.color2 = gradient.dots[gradient.dots.length - 1].color || "#000";
313 for (var i = 1, ii = gradient.dots.length - 1; i < ii; i++) {
314 colors += gradient.dots[i].offset + " " + gradient.dots[i].color;
320 fill.colors = colors;
322 if (gradient.vector) {
323 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;
324 fill.angle = angle + 90;
326 if (gradient.type.toLowerCase() == "radial") {
327 fill.focusposition = "0.5, 0.5";
328 fill.focussize = "0, 0";
329 fill.method = "none";
333 var setTheBox = function (vml, o, x, y, w, h) {
334 o.origin = o.origin || {x: x, y: y, w: w, h: h};
335 var left = vml.width / 2 - o.origin.w / 2,
336 top = vml.height / 2 - o.origin.h / 2,
339 gs.position = "absolute";
340 gs.left = o.origin.x - left + "px";
341 gs.top = o.origin.y - top + "px";
342 o.X = o.origin.x - left;
343 o.Y = o.origin.y - top;
346 gs.width = vml.width + "px";
347 gs.height = vml.height + "px";
348 os.position = "absolute";
350 os.left = left + "px";
352 os.height = h + "px";
354 var Element = function (node, group, vml) {
362 arguments.callee.name = "Element";
365 this.hide = function () {
366 this.Group.style.display = "none";
369 this.show = function () {
370 this.Group.style.display = "block";
373 this.rotate = function (deg) {
375 this.Group.style.rotation = Rotation;
378 this.translate = function (x, y) {
381 this.Group.style.left = this.X + "px";
382 this.Group.style.top = this.Y + "px";
386 this.matrix = function (xx, xy, yx, yy, dx, dy) {
387 tMatrix = new Matrix(xx, xy, yx, yy, dx, dy);
388 this.Group.style.filter = tMatrix;
391 this.scale = function (x, y) {
393 if (x != 0 && !(x == 1 && y == 1)) {
394 var dirx = Math.round(x / Math.abs(x)),
395 diry = Math.round(y / Math.abs(y));
396 if (dirx != 1 || diry != 1) {
397 this[0].style.filter = new Matrix(dirx, 0, 0, diry, 0, 0);
399 var width = parseInt(this[0].style.width, 10) * x * dirx;
400 var height = parseInt(this[0].style.height, 10) * y * diry;
401 var left = parseInt(this[0].style.left, 10);
402 var top = parseInt(this[0].style.top, 10);
403 this[0].style.left = this.X = left + this.W / 2 - width / 2;
404 this[0].style.top = this.Y = top + this.H / 2 - height / 2;
405 this[0].style.width = this.W = width;
406 this[0].style.height = this.H = height;
410 this.getBBox = function () {
412 x: this.Group.offsetLeft,
413 y: this.Group.offsetTop,
414 width: this.Group.offsetWidth,
415 height: this.Group.offsetHeight
418 this.remove = function () {
419 this[0].parentNode.removeChild(this[0]);
420 this.Group.parentNode.removeChild(this.Group);
421 this.shape && this.shape.parentNode.removeChild(this.shape);
423 this.attr = function () {
424 if (arguments.length == 1 && typeof arguments[0] == "string") {
425 return this[0].attrs[arguments[0]];
427 if (this[0].attrs && arguments.length == 1 && arguments[0] instanceof Array) {
429 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
430 values[arguments[0][i]] = this[0].attrs[arguments[0][i]];
434 if (this[0].tagName.toLowerCase() == "group") {
435 var children = this[0].childNodes;
436 this[0].attrs = this[0].attrs || {};
437 if (arguments.length == 2) {
438 this[0].attrs[arguments[0]] = arguments[1];
439 } else if (arguments.length = 1 || typeof arguments[0] == "object") {
440 for (var j in arguments[0]) {
441 this[0].attrs[j] = arguments[0][j];
444 for (var i = 0, ii = children.length; i < ii; i++) {
445 this.attr.apply(new item(children[i], this[0], vml), arguments);
448 if (arguments.length == 2) {
449 var att = arguments[0],
450 value = arguments[1];
453 this[0].style.width = this[0].style.height = value * 2 + "px";
454 this[0].style.left = vml._getX(this.cx) - value + "px";
455 this[0].style.top = vml._getY(this.cy) - value + "px";
459 this[0].style.width = value * 2 + "px";
460 this[0].style.left = vml._getX(this.cx) - value + "px";
464 this[0].style.height = value * 2 + "px";
465 this[0].style.top = vml._getY(this.cy) - value + "px";
469 if (this.r || this.rx) {
470 this[0].style.left = vml._getX(value) - (this.r || vml._getW(this.rx)) + "px";
475 this[0].style.left = vml._getX(value) + "px";
478 if (this.r || this.ry) {
479 this[0].style.top = vml._getY(value) - (this.r || vml._getH(this.ry)) + "px";
484 this[0].style.top = vml._getY(value) + "px";
491 case "stroke-dasharray":
492 case "stroke-opacity":
496 setFillAndStroke(this, params);
504 this[0].style[att] = value;
510 if (this.type == "text") {
511 this[0].string = value;
515 addGrdientFill(this, value);
518 if (arguments.length == 1 && typeof arguments[0] == "object") {
519 var params = arguments[0];
520 setFillAndStroke(this, params);
521 if (params.gradient) {
522 addGrdientFill(this, params.gradient);
524 if (params.text && this.type == "text") {
525 this[0].string = params.text;
528 this[0].id = params.id;
534 this.toFront = function () {
535 this.Group.parentNode.appendChild(this.Group);
537 this.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"});
550 setTheBox(vml, res, x - r, y - r, r * 2, 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 setTheBox(vml, res, x, y, w, 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 setTheBox(vml, res, x - rx, y - ry, rx * 2, 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);
598 setTheBox(vml, res, x, y, w, h);
602 var theText = function (vml, x, y, text) {
604 var g = document.createElement("rvml:group"), gs = g.style;
605 var el = document.createElement("rvml:shape"), ol = el.style;
606 var path = document.createElement("rvml:path"), ps = path.style;
607 path.v = ["m", Math.round(x), ", ", Math.round(y), "l", Math.round(x) + 1, ", ", Math.round(y)].join("");
608 path.textpathok = true;
609 ol.width = vml.width;
610 ol.height = vml.height;
611 gs.position = "absolute";
614 gs.width = vml.width;
615 gs.height = vml.height;
616 var o = document.createElement("rvml:textpath");
619 o.coordsize = vml.coordsize;
620 o.coordorigin = vml.coordorigin;
622 el.appendChild(path);
624 vml.canvas.appendChild(g);
625 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 if (typeof arguments[0] == "string") {
659 var container = document.getElementById(arguments[0]);
660 var width = arguments[1];
661 var height = arguments[2];
663 if (typeof arguments[0] == "object") {
664 var container = arguments[0];
665 var width = arguments[1];
666 var height = arguments[2];
668 if (typeof arguments[0] == "number") {
672 width = arguments[2],
673 height = arguments[3];
676 throw new Error("VML container not found.");
678 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
679 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
680 var c = document.createElement("div"),
681 r = C.canvas = document.createElement("rvml:group"),
682 cs = c.style, rs = r.style;
685 width = width || "320px";
686 height = height || "200px";
687 cs.clip = "rect(0 " + width + " " + height + " 0)";
688 cs.position = "absolute";
691 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
692 r.coordorigin = "0 0";
694 var b = document.createElement("rvml:rect"), bs = b.style;
695 bs.left = bs.top = 0;
697 bs.height = rs.height;
698 b.filled = b.stroked = "f";
702 if (container == 1) {
703 document.body.appendChild(c);
704 cs.position = "absolute";
716 cs.width = container.style.width = width;
717 cs.height = container.style.height = height;
718 if (container.firstChild) {
719 container.insertBefore(c, container.firstChild);
721 container.appendChild(c);
724 for (var prop in C) {
725 container[prop] = C[prop];
727 container.clear = function () {
729 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
730 if (r.childNodes[i] != b) {
731 todel.push(r.childNodes[i]);
734 for (i = 0, ii = todel.length; i < ii; i++) {
735 r.removeChild(todel[i]);
742 Matrix.prototype.toString = function () {
743 return "matrix(" + this.m[0][0] +
744 ", " + this.m[1][0] + ", " + this.m[0][1] + ", " + this.m[1][1] +
745 ", " + this.m[2][0] + ", " + this.m[2][1] + ")";
747 var thePath = function (params, pathString, SVG) {
748 var el = document.createElementNS(SVG.svgns, "path");
749 el.setAttribute("fill", "none");
751 for (var attr in params) {
752 if (params.gradient) {
753 addGrdientFill(el, params.gradient, SVG);
755 el.setAttribute(attr, params[attr]);
760 SVG.canvas.appendChild(el);
762 var p = new Element(el, SVG);
763 for (var attr in params) {
764 p.attrs[attr] = params[attr];
768 p.last = {x: 0, y: 0, bx: 0, by: 0};
769 p.absolutely = function () {
770 this.isAbsolute = true;
773 p.relatively = function () {
774 this.isAbsolute = false;
777 p.redraw = function () {
778 this[0].setAttribute("d", "M0 0");
779 var oldPath = this.path;
781 for (var i = 0, ii = oldPath.length; i < ii; i++) {
782 if (oldPath[i].type != "end") {
783 this[oldPath[i].type + "To"].apply(this, oldPath[i].arg);
789 p.moveTo = function (x, y) {
790 var d = this.isAbsolute?"M":"m";
791 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
792 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
793 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
794 var oldD = this[0].getAttribute("d") || "";
795 this[0].setAttribute("d", oldD + d);
796 this.last.x = SVG._getX(parseFloat(x, 10));
797 this.last.y = SVG._getY(parseFloat(y, 10));
798 this.path.push({type: "move", arg: arguments, pos: this.isAbsolute});
801 p.lineTo = function (x, y) {
802 var d = this.isAbsolute?"L":"l";
803 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
804 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
805 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
806 var oldD = this[0].getAttribute("d") || "";
807 this[0].setAttribute("d", oldD + d);
808 this.last.x = SVG._getX(parseFloat(x, 10));
809 this.last.y = SVG._getY(parseFloat(y, 10));
810 this.path.push({type: "line", arg: arguments, pos: this.isAbsolute});
813 p.cplineTo = function (x1, y1, w1) {
815 return this.lineTo(x1, y1);
818 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
819 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
820 var x = p._getX(Math.round(parseFloat(x1, 10) * 100) / 100);
821 var y = p._getY(Math.round(parseFloat(y1, 10) * 100) / 100);
822 var w = SVG._getW(Math.round(parseFloat(w1, 10) * 100) / 100);
823 var d = this.isAbsolute?"C":"c";
824 var attr = [this.last.x + w, this.last.y, x - w, y, x, y];
825 for (var i = 0, ii = attr.length; i < ii; i++) {
828 this.last.x = attr[4];
829 this.last.y = attr[5];
830 this.last.bx = attr[2];
831 this.last.by = attr[3];
832 var oldD = this[0].getAttribute("d") || "";
833 this[0].setAttribute("d", oldD + d);
834 this.path.push({type: "cpline", arg: arguments, pos: this.isAbsolute});
838 p.curveTo = function () {
840 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
841 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
842 if (arguments.length == 6) {
843 var d = this.isAbsolute?"C":"c";
844 for (var i = 0, ii = arguments.length; i < ii; i++) {
845 d += p[(i % 2 == 0) ? "_getX" : "_getY"](Math.round(parseFloat(arguments[i], 10) * 100) / 100) + " ";
847 this.last.x = p._getX((parseFloat(arguments[4], 10) * 100) / 100);
848 this.last.y = p._getY((parseFloat(arguments[5], 10) * 100) / 100);
849 this.last.bx = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
850 this.last.by = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
852 if (arguments.length == 4) {
853 var d = this.isAbsolute?"S":"s";
854 for (var i = 0, ii = arguments.length; i < ii; i++) {
855 d += p[i % 2 == 0 ? "_getX" : "_getY"]((parseFloat(arguments[i], 10) * 100) / 100) + " ";
858 this.last.x = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
859 this.last.y = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
860 this.last.bx = p._getX((parseFloat(arguments[0], 10) * 100) / 100);
861 this.last.by = p._getY((parseFloat(arguments[1], 10) * 100) / 100);
863 var oldD = this[0].getAttribute("d") || "";
864 this[0].setAttribute("d", oldD + d);
865 this.path.push({type: "curve", arg: arguments, pos: this.isAbsolute});
868 p.addRoundedCorner = function (r, dir) {
869 var R = .5522 * r, rollback = this.isAbsolute, o = this;
872 rollback = function () {
876 rollback = function () {};
882 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
885 o.curveTo(-R, 0, -r, r - R, -r, r);
892 o.curveTo(R, 0, r, -(r - R), r, -r);
895 o.curveTo(R, 0, r, r - R, r, r);
902 o.curveTo(0, -R, -(R - r), -r, r, -r);
905 o.curveTo(0, -R, R - r, -r, -r, -r);
912 o.curveTo(0, R, -(R - r), r, r, r);
915 o.curveTo(0, R, R - r, r, -r, r);
920 actions[dir[0]]()[dir[1]]();
924 p.andClose = function () {
925 var oldD = this[0].getAttribute("d") || "";
926 this[0].setAttribute("d", oldD + "Z ");
927 this.path.push({type: "end"});
930 if (typeof pathString == "string") {
931 pathString = pathString.replace(/([mzlhvcsqta])/ig, ",$1,").replace(/([^,])\-/ig, "$1,-");
932 path = pathString.split(",");
933 var i = 1, ii = path.length;
937 p.absolutely().moveTo(path[++i], path[++i]);
940 p.relatively().moveTo(path[++i], path[++i]);
943 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
946 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
949 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i]);
952 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i]);
955 p.absolutely().lineTo(path[++i], path[++i]);
958 p.relatively().lineTo(path[++i], path[++i]);
961 p.absolutely().lineTo(path[++i], 0);
964 p.relatively().lineTo(path[++i], 0);
967 p.absolutely().lineTo(0, path[++i]);
970 p.relatively().lineTo(0, path[++i]);
981 var addGrdientFill = function (o, gradient, SVG) {
982 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
983 el.id = "raphael-gradient-" + SVG.gradients++;
984 if (gradient.vector && gradient.vector.length) {
985 el.setAttribute("x1", gradient.vector[0]);
986 el.setAttribute("y1", gradient.vector[1]);
987 el.setAttribute("x2", gradient.vector[2]);
988 el.setAttribute("y2", gradient.vector[3]);
990 SVG.defs.appendChild(el);
991 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
992 var stop = document.createElementNS(SVG.svgns, "stop");
993 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
994 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
995 if (typeof gradient.dots[i].opacity != "undefined") {
996 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
998 el.appendChild(stop);
1000 o.setAttribute("fill", "url(#" + el.id + ")");
1002 var Element = function (node, svg) {
1005 Rotation = {deg: 0, x: 0, y: 0},
1009 this.attrs = this.attrs || {};
1010 this.transformations = [];
1011 this.hide = function () {
1012 this[0].style.display = "none";
1015 this.show = function () {
1016 this[0].style.display = "block";
1019 this.rotate = function (deg) {
1020 var bbox = this.getBBox();
1021 this.transformations.push("rotate(" + deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
1022 this[0].setAttribute("transform", this.transformations.join(" "));
1025 this.translate = function (x, y) {
1026 this.transformations.push("translate(" + x + "," + y + ")");
1027 this[0].setAttribute("transform", this.transformations.join(" "));
1030 this.scale = function (x, y) {
1032 if (x != 0 && !(x == 1 && y == 1)) {
1033 var bbox = this.getBBox(),
1034 dx = bbox.x * (1 - x) + (bbox.width / 2 - bbox.width * x / 2),
1035 dy = bbox.y * (1 - y) + (bbox.height / 2 - bbox.height * y / 2);
1036 this.transformations.push(new Matrix(x, 0, 0, y, dx, dy));
1037 this[0].setAttribute("transform", this.transformations.join(" "));
1041 this.matrix = function (xx, xy, yx, yy, dx, dy) {
1042 this.transformations.push(new Matrix(xx, xy, yx, yy, dx, dy));
1043 this[0].setAttribute("transform", this.transformations.join(" "));
1046 this.remove = function () {
1047 this[0].parentNode.removeChild(this[0]);
1049 this.getBBox = function () {
1050 return this[0].getBBox();
1052 this.attr = function () {
1053 if (arguments.length == 1 && typeof arguments[0] == "string") {
1054 return this.attrs[arguments[0]];
1056 if (arguments.length == 1 && arguments[0] instanceof Array) {
1058 for (var j in arguments[0]) {
1059 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1063 if (arguments.length == 2) {
1064 var att = arguments[0],
1065 value = arguments[1];
1067 this.attrs[att] = value;
1072 this[0].setAttribute(att, svg._getX(value));
1077 this[0].setAttribute(att, svg._getY(value));
1080 this[0].setAttribute(att, svg._getW(value));
1083 this[0].setAttribute(att, svg._getH(value));
1086 addGrdientFill(this[0], params.gradient, svg);
1088 case "stroke-dasharray":
1089 this[0].setAttribute(att, value.replace(" ", ","));
1092 if (this.type == "text") {
1093 this[0].removeChild(this[0].firstChild);
1094 this[0].appendChild(document.createTextNode(value));
1098 var cssrule = att.replace(/(\-.)/g, function (w) {
1099 return w.substring(1).toUpperCase();
1101 this[0].style[cssrule] = value;
1102 // Need following line for Firefox
1103 this[0].setAttribute(att, value);
1105 } else if (arguments.length = 1 && typeof arguments[0] == "object") {
1106 var params = arguments[0];
1107 for (var attr in params) {
1108 this.attrs[attr] = params[attr];
1109 if (attr == "stroke-dasharray") {
1110 this[0].setAttribute(attr, params[attr].replace(" ", ","));
1111 } else if (attr == "text" && this.type == "text") {
1112 this[0].removeChild(this[0].firstChild);
1113 this[0].appendChild(document.createTextNode(params[attr]));
1115 var cssrule = attr.replace(/(\-.)/g, function (w) {
1116 return w.substring(1).toUpperCase();
1118 this[0].style[cssrule] = params[attr];
1119 // Need following line for Firefox
1120 this[0].setAttribute(attr, params[attr]);
1123 if (params.gradient) {
1124 this[0].attrs.gradient = params.gradient;
1125 addGrdientFill(this[0], params.gradient, svg);
1130 this.toFront = function () {
1131 this[0].parentNode.appendChild(this[0]);
1133 this.toBack = function () {
1134 if (this[0].parentNode.firstChild != this[0]) {
1135 this[0].parentNode.insertBefore(this[0], this[0].parentNode.firstChild);
1139 var theCircle = function (svg, x, y, r) {
1140 var el = document.createElementNS(svg.svgns, "circle");
1141 el.setAttribute("cx", svg._getX(x));
1142 el.setAttribute("cy", svg._getY(y));
1143 el.setAttribute("r", r);
1144 el.setAttribute("fill", "none");
1145 el.setAttribute("stroke", "#000");
1146 el.attrs = el.attrs || {};
1150 el.attrs.stroke = "#000";
1152 svg.canvas.appendChild(el);
1154 var res = new Element(el, svg);
1155 res.type = "circle";
1158 var theRect = function (svg, x, y, w, h, r) {
1159 var el = document.createElementNS(svg.svgns, "rect");
1160 el.setAttribute("x", svg._getX(x));
1161 el.setAttribute("y", svg._getY(y));
1162 el.setAttribute("width", svg._getW(w));
1163 el.setAttribute("height", svg._getH(h));
1164 el.attrs = el.attrs || {};
1168 el.attrs.height = h;
1170 el.setAttribute("rx", r);
1171 el.setAttribute("ry", r);
1172 el.attrs.rx = el.attrs.ry = r;
1174 el.setAttribute("fill", "none");
1175 el.setAttribute("stroke", "#000");
1176 el.attrs.stroke = "#000";
1178 svg.canvas.appendChild(el);
1180 var res = new Element(el, svg);
1184 var theEllipse = function (svg, x, y, rx, ry) {
1185 var el = document.createElementNS(svg.svgns, "ellipse");
1186 el.setAttribute("cx", svg._getX(x));
1187 el.setAttribute("cy", svg._getY(y));
1188 el.setAttribute("rx", svg._getW(rx));
1189 el.setAttribute("ry", svg._getH(ry));
1190 el.setAttribute("fill", "none");
1191 el.setAttribute("stroke", "#000");
1192 el.attrs = el.attrs || {};
1197 el.attrs.stroke = "#000";
1199 svg.canvas.appendChild(el);
1201 var res = new Element(el, svg);
1202 res.type = "ellipse";
1205 var theImage = function (svg, src, x, y, w, h) {
1206 var el = document.createElementNS(svg.svgns, "image");
1207 el.setAttribute("x", svg._getX(x));
1208 el.setAttribute("y", svg._getY(y));
1209 el.setAttribute("width", svg._getW(w));
1210 el.setAttribute("height", svg._getH(h));
1211 el.setAttributeNS(svg.xlink, "href", src);
1213 svg.canvas.appendChild(el);
1215 var res = new Element(el, svg);
1219 var theText = function (svg, x, y, text) {
1220 var el = document.createElementNS(svg.svgns, "text");
1221 el.setAttribute("x", x);
1222 el.setAttribute("y", y);
1223 el.setAttribute("text-anchor", "middle");
1224 el.setAttribute("fill", "#000");
1225 el.attrs = el.attrs || {};
1228 el.attrs.fill = "#000";
1230 el.appendChild(document.createTextNode(text));
1233 svg.canvas.appendChild(el);
1235 var res = new Element(el, svg);
1239 var theGroup = function (svg) {
1240 var el = document.createElementNS(svg.svgns, "g");
1242 svg.canvas.appendChild(el);
1244 var i = new Element(el, svg);
1245 for (var f in svg) {
1246 if (f[0] != "_" && typeof svg[f] == "function") {
1247 i[f] = (function (f) {
1248 return function () {
1249 var e = svg[f].apply(svg, arguments);
1250 el.appendChild(e[0]);
1259 r._create = function () {
1260 // container, width, height
1261 // x, y, width, height
1262 if (typeof arguments[0] == "string") {
1263 var container = document.getElementById(arguments[0]);
1264 var width = arguments[1];
1265 var height = arguments[2];
1267 if (typeof arguments[0] == "object") {
1268 var container = arguments[0];
1269 var width = arguments[1];
1270 var height = arguments[2];
1272 if (typeof arguments[0] == "number") {
1276 width = arguments[2],
1277 height = arguments[3];
1280 throw new Error("SVG container not found.");
1282 C.canvas = document.createElementNS(C.svgns, "svg");
1283 C.canvas.setAttribute("width", width || 320);
1284 C.width = width || 320;
1285 C.canvas.setAttribute("height", height || 200);
1286 C.height = height || 200;
1287 if (container == 1) {
1288 document.body.appendChild(C.canvas);
1289 C.canvas.style.position = "absolute";
1290 C.canvas.style.left = x + "px";
1291 C.canvas.style.top = y + "px";
1293 if (container.firstChild) {
1294 container.insertBefore(C.canvas, container.firstChild);
1296 container.appendChild(C.canvas);
1301 clear: function () {
1302 while (this.canvas.firstChild) {
1303 this.canvas.removeChild(this.canvas.firstChild);
1305 this.defs = document.createElementNS(C.svgns, "defs");
1307 this.canvas.appendChild(this.defs);
1310 for (var prop in C) {
1311 if (prop != "create") {
1312 container[prop] = C[prop];
1318 C.svgns = "http://www.w3.org/2000/svg";
1319 C.xlink = "http://www.w3.org/1999/xlink";
1321 if (r.vml || r.svg) {
1322 C.circle = function (x, y, r) {
1323 return theCircle(this, x, y, r);
1325 C.rect = function (x, y, w, h, r) {
1326 return theRect(this, x, y, w, h, r);
1328 C.ellipse = function (x, y, rx, ry) {
1329 return theEllipse(this, x, y, rx, ry);
1331 C.path = function (params, pathString) {
1332 return thePath(params, pathString, this);
1334 C.image = function (src, x, y, w, h) {
1335 return theImage(this, src, x, y, w, h);
1337 C.text = function (x, y, text) {
1338 return theText(this, x, y, text);
1340 C.group = function () {
1341 return theGroup(this);
1343 C.linerect = function (x, y, w, h, r) {
1344 if (r && parseInt(r, 10)) {
1345 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();
1347 return this.path({stroke: "#000"}).moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).andClose();
1349 C.drawGrid = function (x, y, w, h, wv, hv, color) {
1350 color = color || "#000";
1351 var res = this.group();
1352 var params = {stroke: color, "stroke-width": "1px", "stroke-opacity": .3};
1353 res.rect(x, y, w, h).attr(params);
1354 for (var i = 1; i < hv; i++) {
1355 var p = res.path(params);
1356 p.moveTo(x, y + i * Math.round(h / hv)).lineTo(x + w, y + i * Math.round(h / hv));
1358 for (var i = 1; i < wv; i++) {
1359 res.path(params).moveTo(x + i * Math.round(w / wv), y).lineTo(x + i * Math.round(w / wv), y + h);
1363 C.setGrid = function (xmin, ymin, xmax, ymax, w, h) {
1364 var xc = (xmax - xmin) / w;
1365 var yc = (ymax - ymin) / h;
1366 this._getX = function (x) {
1367 return xmin + x * xc;
1369 this._getY = function (y) {
1370 return ymin + y * yc;
1372 this._getW = function (w) {
1375 this._getH = function (h) {
1379 C.clearGrid = function () {
1380 this._getX = this._getY = this._getW = this._getH = function (x) { return x; };
1382 C.safari = function () {
1383 if (r.type == "SVG") {
1384 var rect = C.rect(0, 0, C.width, C.height).attr("stroke-width", 0);
1385 setTimeout(function () {rect.remove();}, 0);
1388 Raphael = function () {
1389 return r._create.apply(r, arguments);
1391 return r._create.apply(r, args);
1395 })(arguments.callee, arguments);
1399 Raphael.type = (!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2) && !(window.CanvasRenderingContext2D)) ? "VML" : "SVG";
1400 Raphael.vml = !(Raphael.svg = (Raphael.type == "SVG"));
1401 if (!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2) && window.CanvasRenderingContext2D) {
1402 Raphael.type = "Canvas only";
1403 Raphael.vml = Raphael.svg = false;
1405 Raphael.toString = function () {
1406 return "You browser supports " + this.type;