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 params["font-family"] && (o[0].style.fontFamily = params["font-family"]);
241 params["font-size"] && (o[0].style.fontSize = params["font-size"]);
242 params["font"] && (o[0].style.font = params["font"]);
243 params["font-weight"] && (o[0].style.fontWeight = params["font-weight"]);
244 if (typeof params.opacity != "undefined" || typeof params["stroke-width"] != "undefined" || typeof params.fill != "undefined" || typeof params.stroke != "undefined") {
246 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || document.createElement("rvml:fill");
247 if ("fill-opacity" in params || "opacity" in params) {
248 fill.opacity = ((params["fill-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
250 params.fill && (fill.on = true);
252 fill.color = params.fill;
255 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || document.createElement("rvml:stroke");
256 stroke.on = !!(params.stroke || params["stroke-width"] || params["stroke-opacity"] || params["stroke-dasharray"]);
258 stroke.color = params.stroke;
260 stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
261 stroke.joinstyle = params["stroke-linejoin"] || "miter";
262 stroke.miterlimit = params["stroke-miterlimit"] || 8;
263 stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"] || "miter"];
264 stroke.weight = parseFloat(params["stroke-width"], 10) + "px" || "1px";
265 if (params["stroke-dasharray"]) {
266 var dashes = params["stroke-dasharray"].replace(" ", ",").split(","),
268 str = parseFloat(stroke.weight, 10);
269 for (var i = 0, ii = dashes.length; i < ii; i++) {
270 var res = dashes[i] / str;
275 stroke.dashstyle = dashesn.join(" ");
277 o.appendChild(stroke);
280 var addGrdientFill = function (o, gradient) {
282 var fill = o.getElementsByTagName("fill");
286 fill = document.createElement("rvml:fill");
288 if (gradient.dots.length) {
290 fill.type = (gradient.type.toLowerCase() == "linear") ? "gradient" : "gradientradial";
291 if (typeof gradient.dots[0].color != "undefined") {
292 fill.color = gradient.dots[0].color || "#000";
294 if (typeof gradient.dots[0].opacity != "undefined") {
295 fill.opacity = gradient.dots[0].opacity;
297 if (typeof gradient.dots[gradient.dots.length - 1].opacity != "undefined") {
298 fill.opacity2 = gradient.dots[gradient.dots.length - 1].opacity;
300 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
301 fill.color2 = gradient.dots[gradient.dots.length - 1].color || "#000";
304 for (var i = 1, ii = gradient.dots.length - 1; i < ii; i++) {
305 colors += gradient.dots[i].offset + " " + gradient.dots[i].color;
311 fill.colors = colors;
313 if (gradient.vector) {
314 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;
315 fill.angle = angle + 90;
317 if (gradient.type.toLowerCase() == "radial") {
318 fill.focusposition = "0.5, 0.5";
319 fill.focussize = "0, 0";
320 fill.method = "none";
324 var Element = function (node, group, vml) {
332 arguments.callee.name = "Element";
334 this.rotate = function (deg, x, y) {
336 var alpha = Rotation * Math.PI / 180,
339 this.Group.style.left = 0;
340 this.Group.style.top = 0;
341 this.Group.style.rotation = 0;
342 var cx = vml.width / 2,
344 bbox = this.getBBox(),
345 dx = cx - (bbox.x + bbox.width / 2),
346 dy = cy - (bbox.y + bbox.height / 2),
347 phi = Math.atan(dy / dx),
348 g = Math.sqrt(dx * dx + dy * dy);
349 RotX = -Math.round(dx - g * Math.cos(alpha + phi));
350 RotY = -Math.round(dy - g * Math.sin(alpha + phi));
351 this.Group.style.left = X + RotX;
352 this.Group.style.top = Y + RotY;
353 this.Group.style.rotation = Rotation;
356 this.translate = function (x, y) {
359 this.Group.style.left = X + RotX;
360 this.Group.style.top = Y + RotY;
363 this.matrix = function (xx, xy, yx, yy, dx, dy) {
364 tMatrix = new Matrix(xx, xy, yx, yy, dx, dy);
365 this[0].style.filter = tMatrix;
368 this.scale = function (times) {
371 this[0].style.width = parseInt(this[0].style.width, 10) * Scale;
372 this[0].style.height = parseInt(this[0].style.height, 10) * Scale;
376 this.getBBox = function () {
378 x: this.Group.offsetLeft,
379 y: this.Group.offsetTop,
380 width: this.Group.offsetWidth,
381 height: this.Group.offsetHeight
384 this.remove = function () {
385 this[0].parentNode.removeChild(this[0]);
386 this.Group.parentNode.removeChild(this.Group);
387 this.shape && this.shape.parentNode.removeChild(this.shape);
389 this.attr = function () {
390 if (this[0].tagName.toLowerCase() == "group") {
391 var children = this[0].childNodes;
392 for (var i = 0, ii = children.length; i < ii; i++) {
393 this.attr.apply(new item(children[i], this[0], vml), arguments);
396 if (arguments.length == 2) {
397 var att = arguments[0],
398 value = arguments[1];
401 this[0].style.width = this[0].style.height = value * 2 + "px";
402 this[0].style.left = vml._getX(this.cx) - value + "px";
403 this[0].style.top = vml._getY(this.cy) - value + "px";
407 this[0].style.width = value * 2 + "px";
408 this[0].style.left = vml._getX(this.cx) - value + "px";
412 this[0].style.height = value * 2 + "px";
413 this[0].style.top = vml._getY(this.cy) - value + "px";
417 if (this.r || this.rx) {
418 this[0].style.left = vml._getX(value) - (this.r || vml._getW(this.rx)) + "px";
423 this[0].style.left = vml._getX(value) + "px";
426 if (this.r || this.ry) {
427 this[0].style.top = vml._getY(value) - (this.r || vml._getH(this.ry)) + "px";
432 this[0].style.top = vml._getY(value) + "px";
439 case "stroke-dasharray":
440 case "stroke-opacity":
444 setFillAndStroke(this, params);
452 this[0].style[att] = value;
458 addGrdientFill(this, value);
461 if (arguments.length == 1 && typeof arguments[0] == "object") {
462 var params = arguments[0];
463 setFillAndStroke(this, params);
464 if (params.gradient) {
465 addGrdientFill(this, params.gradient);
468 this[0].id = params.id;
474 this.toFront = function () {
475 this.Group.parentNode.appendChild(this.Group);
478 var theCircle = function (vml, x, y, r) {
479 var g = document.createElement("rvml:group"), gl = g.style;
480 gl.position = "absolute";
483 gl.width = vml.width;
484 gl.height = vml.height;
485 var o = document.createElement("rvml:oval"), ol = o.style;
486 ol.width = ol.height = r * 2 + "px";
487 ol.top = vml._getY(y) - r + "px";
488 ol.left = vml._getX(x) - r + "px";
490 vml.canvas.appendChild(g);
491 var res = new Element(o, g, vml);
492 setFillAndStroke(res, {stroke: "#000"});
499 var theRect = function (vml, x, y, w, h, r) {
500 var g = document.createElement("rvml:group"), gl = g.style;
501 gl.position = "absolute";
504 gl.width = vml.width;
505 gl.height = vml.height;
506 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect"), ol = o.style;
507 ol.height = vml._getH(h) + "px";
508 ol.width = vml._getW(w) + "px";
509 ol.top = vml._getY(y) + "px";
510 ol.left = vml._getX(x) + "px";
512 o.arcsize = r / (Math.min(w, h));
515 vml.canvas.appendChild(g);
516 var res = new Element(o, g, vml);
517 setFillAndStroke(res, {stroke: "#000"});
524 var theEllipse = function (vml, x, y, rx, ry) {
525 var g = document.createElement("rvml:group"), gl = g.style;
526 gl.position = "absolute";
529 gl.width = vml.width;
530 gl.height = vml.height;
531 var o = document.createElement("rvml:oval"), ol = o.style;
532 ol.width = rx * 2 + "px";
533 ol.height = ry * 2 + "px";
534 ol.top = y - ry + "px";
535 ol.left = x - rx + "px";
537 vml.canvas.appendChild(g);
538 var res = new Element(o, g, vml);
539 setFillAndStroke(res, {stroke: "#000"});
544 res.type = "ellipse";
547 var theImage = function (vml, src, x, y, w, h) {
548 var g = document.createElement("rvml:group");
549 g.style.position = "absolute";
552 g.style.width = vml.width;
553 g.style.height = vml.height;
554 g.coordsize = vml.coordsize;
555 g.coordorigin = vml.coordorigin;
556 var o = document.createElement("rvml:image");
558 o.style.position = "absolute";
559 o.style.width = w + "px";
560 o.style.height = h + "px";
561 o.style.top = y + "px";
562 o.style.left = x + "px";
563 o.coordsize = vml.coordsize;
564 o.coordorigin = vml.coordorigin;
566 vml.canvas.appendChild(g);
567 var res = new Element(o, g, vml);
571 var theText = function (vml, x, y, text) {
572 var g = document.createElement("rvml:group"), gs = g.style;
573 var el = document.createElement("rvml:shape"), ol = el.style;
574 var path = document.createElement("rvml:path"), ps = path.style;
575 path.v = ["m", x, ", ", y, "l", x + 1, ", ", y].join("");
576 path.textpathok = true;
577 ps.position = "absolute";
580 ol.width = vml.width + "px";
581 ol.height = vml.height + "px";
582 gs.position = "absolute";
585 gs.width = vml.width;
586 gs.height = vml.height;
587 g.coordsize = vml.coordsize;
588 g.coordorigin = vml.coordorigin;
589 var o = document.createElement("rvml:textpath");
592 o.coordsize = vml.coordsize;
593 o.coordorigin = vml.coordorigin;
595 el.appendChild(path);
597 vml.canvas.appendChild(g);
598 var res = new Element(o, g, vml);
603 var theText2 = function (vml, x, y, text) {
604 var g = document.createElement("rvml:group");
605 g.style.position = "absolute";
608 g.style.width = vml.width;
609 g.style.height = vml.height;
610 g.coordsize = vml.coordsize;
611 g.coordorigin = vml.coordorigin;
612 var o = document.createElement("rvml:textbox");
613 o.style.position = "absolute";
614 o.style.top = y + "px";
615 o.style.left = x + "px";
616 o.innerHTML = "<div>" + text + "</div>";
617 o.coordsize = vml.coordsize;
618 o.coordorigin = vml.coordorigin;
620 vml.canvas.appendChild(g);
621 var res = new Element(o, g, vml);
625 var theGroup = function (vml) {
626 var el = document.createElement("rvml:group"), els = el.style;
627 els.position = "absolute";
630 els.width = vml.width;
631 els.height = vml.height;
633 vml.canvas.appendChild(el);
635 var res = new Element(el, el, vml);
637 if (f.charAt(0) != "_" && typeof vml[f] == "function") {
638 res[f] = (function (f) {
640 var e = vml[f].apply(vml, arguments);
641 el.appendChild(e[0].parentNode);
650 r._create = function () {
651 // container, width, height
652 // x, y, width, height
653 if (typeof arguments[0] == "string") {
654 var container = document.getElementById(arguments[0]);
655 var width = arguments[1];
656 var height = arguments[2];
658 if (typeof arguments[0] == "object") {
659 var container = arguments[0];
660 var width = arguments[1];
661 var height = arguments[2];
663 if (typeof arguments[0] == "number") {
667 width = arguments[2],
668 height = arguments[3];
671 throw new Error("VML container not found.");
673 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
674 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
675 var c = document.createElement("div"),
676 r = C.canvas = document.createElement("rvml:group"),
677 cs = c.style, rs = r.style;
680 width = width || "320px";
681 height = height || "200px";
682 cs.clip = "rect(0 " + width + " " + height + " 0)";
683 cs.position = "absolute";
686 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
687 r.coordorigin = "0 0";
689 var b = document.createElement("rvml:rect"), bs = b.style;
690 bs.left = bs.top = 0;
692 bs.height = rs.height;
693 b.filled = b.stroked = "f";
697 if (container == 1) {
698 document.body.appendChild(c);
699 cs.position = "absolute";
711 cs.width = container.style.width = width;
712 cs.height = container.style.height = height;
713 if (container.firstChild) {
714 container.insertBefore(c, container.firstChild);
716 container.appendChild(c);
719 for (var prop in C) {
720 container[prop] = C[prop];
722 container.clear = function () {
724 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
725 if (r.childNodes[i] != b) {
726 todel.push(r.childNodes[i]);
729 for (i = 0, ii = todel.length; i < ii; i++) {
730 r.removeChild(todel[i]);
737 Matrix.prototype.toString = function () {
738 return "matrix(" + this.m[0][0] +
739 ", " + this.m[1][0] + ", " + this.m[0][1] + ", " + this.m[1][1] +
740 ", " + this.m[2][0] + ", " + this.m[2][1] + ")";
742 var thePath = function (params, pathString, SVG) {
743 var el = document.createElementNS(SVG.svgns, "path");
744 el.setAttribute("fill", "none");
746 for (var attr in params) {
747 if (params.gradient) {
748 addGrdientFill(el, params.gradient, SVG);
750 el.setAttribute(attr, params[attr]);
755 SVG.canvas.appendChild(el);
757 var p = new Element(el, SVG);
760 p.last = {x: 0, y: 0, bx: 0, by: 0};
761 p.absolutely = function () {
762 this.isAbsolute = true;
765 p.relatively = function () {
766 this.isAbsolute = false;
769 p.redraw = function () {
770 this[0].setAttribute("d", "M0 0");
771 var oldPath = this.path;
773 for (var i = 0, ii = oldPath.length; i < ii; i++) {
774 if (oldPath[i].type != "end") {
775 this[oldPath[i].type + "To"].apply(this, oldPath[i].arg);
781 p.moveTo = function (x, y) {
782 var d = this.isAbsolute?"M":"m";
783 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
784 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
785 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
786 var oldD = this[0].getAttribute("d") || "";
787 this[0].setAttribute("d", oldD + d);
788 this.last.x = SVG._getX(parseFloat(x, 10));
789 this.last.y = SVG._getY(parseFloat(y, 10));
790 this.path.push({type: "move", arg: arguments, pos: this.isAbsolute});
793 p.lineTo = function (x, y) {
794 var d = this.isAbsolute?"L":"l";
795 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
796 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
797 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
798 var oldD = this[0].getAttribute("d") || "";
799 this[0].setAttribute("d", oldD + d);
800 this.last.x = SVG._getX(parseFloat(x, 10));
801 this.last.y = SVG._getY(parseFloat(y, 10));
802 this.path.push({type: "line", arg: arguments, pos: this.isAbsolute});
805 p.cplineTo = function (x1, y1, w1) {
807 return this.lineTo(x1, y1);
810 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
811 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
812 var x = p._getX(Math.round(parseFloat(x1, 10) * 100) / 100);
813 var y = p._getY(Math.round(parseFloat(y1, 10) * 100) / 100);
814 var w = SVG._getW(Math.round(parseFloat(w1, 10) * 100) / 100);
815 var d = this.isAbsolute?"C":"c";
816 var attr = [this.last.x + w, this.last.y, x - w, y, x, y];
817 for (var i = 0, ii = attr.length; i < ii; i++) {
820 this.last.x = attr[4];
821 this.last.y = attr[5];
822 this.last.bx = attr[2];
823 this.last.by = attr[3];
824 var oldD = this[0].getAttribute("d") || "";
825 this[0].setAttribute("d", oldD + d);
826 this.path.push({type: "cpline", arg: arguments, pos: this.isAbsolute});
830 p.curveTo = function () {
832 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
833 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
834 if (arguments.length == 6) {
835 var d = this.isAbsolute?"C":"c";
836 for (var i = 0, ii = arguments.length; i < ii; i++) {
837 d += p[(i % 2 == 0) ? "_getX" : "_getY"](Math.round(parseFloat(arguments[i], 10) * 100) / 100) + " ";
839 this.last.x = p._getX((parseFloat(arguments[4], 10) * 100) / 100);
840 this.last.y = p._getY((parseFloat(arguments[5], 10) * 100) / 100);
841 this.last.bx = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
842 this.last.by = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
844 if (arguments.length == 4) {
845 var d = this.isAbsolute?"S":"s";
846 for (var i = 0, ii = arguments.length; i < ii; i++) {
847 d += p[i % 2 == 0 ? "_getX" : "_getY"]((parseFloat(arguments[i], 10) * 100) / 100) + " ";
850 this.last.x = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
851 this.last.y = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
852 this.last.bx = p._getX((parseFloat(arguments[0], 10) * 100) / 100);
853 this.last.by = p._getY((parseFloat(arguments[1], 10) * 100) / 100);
855 var oldD = this[0].getAttribute("d") || "";
856 this[0].setAttribute("d", oldD + d);
857 this.path.push({type: "curve", arg: arguments, pos: this.isAbsolute});
860 p.addRoundedCorner = function (r, dir) {
861 var R = .5522 * r, rollback = this.isAbsolute, o = this;
864 rollback = function () {
868 rollback = function () {};
874 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
877 o.curveTo(-R, 0, -r, r - R, -r, r);
884 o.curveTo(R, 0, r, -(r - R), r, -r);
887 o.curveTo(R, 0, r, r - R, r, r);
894 o.curveTo(0, -R, -(R - r), -r, r, -r);
897 o.curveTo(0, -R, R - r, -r, -r, -r);
904 o.curveTo(0, R, -(R - r), r, r, r);
907 o.curveTo(0, R, R - r, r, -r, r);
912 actions[dir[0]]()[dir[1]]();
916 p.andClose = function () {
917 var oldD = this[0].getAttribute("d") || "";
918 this[0].setAttribute("d", oldD + "Z ");
919 this.path.push({type: "end"});
922 if (typeof pathString == "string") {
923 pathString = pathString.replace(/([mzlhvcsqta])/ig, ",$1,").replace(/([^,])\-/ig, "$1,-");
924 path = pathString.split(",");
925 console.log(params.fill);
927 var i = 1, ii = path.length;
931 p.absolutely().moveTo(path[++i], path[++i]);
934 p.relatively().moveTo(path[++i], path[++i]);
937 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
940 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
943 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i]);
946 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i]);
949 p.absolutely().lineTo(path[++i], path[++i]);
952 p.relatively().lineTo(path[++i], path[++i]);
955 p.absolutely().lineTo(path[++i], 0);
958 p.relatively().lineTo(path[++i], 0);
961 p.absolutely().lineTo(0, path[++i]);
964 p.relatively().lineTo(0, path[++i]);
975 var addGrdientFill = function (o, gradient, SVG) {
976 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
977 el.id = "raphael-gradient-" + SVG.gradients++;
978 if (gradient.vector && gradient.vector.length) {
979 el.setAttribute("x1", gradient.vector[0]);
980 el.setAttribute("y1", gradient.vector[1]);
981 el.setAttribute("x2", gradient.vector[2]);
982 el.setAttribute("y2", gradient.vector[3]);
984 SVG.defs.appendChild(el);
985 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
986 var stop = document.createElementNS(SVG.svgns, "stop");
987 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
988 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
989 if (typeof gradient.dots[i].opacity != "undefined") {
990 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
992 el.appendChild(stop);
994 o.setAttribute("fill", "url(#" + el.id + ")");
996 var Element = function (node, svg) {
999 Rotation = {deg: 0, x: 0, y: 0},
1003 this.rotate = function (deg) {
1004 var tr = ((X || Y) ? "translate(" + X + "," + Y + ")" : "") +
1005 ((Scale - 1) ? " scale(" + Scale + ")" : "") +
1006 (tMatrix ? " " + tMatrix : "");
1007 var bbox = this.getBBox();
1008 Rotation.x = (bbox.x + bbox.width / 2);
1009 Rotation.y = (bbox.y + bbox.height / 2);
1010 Rotation.deg += deg;
1011 this[0].setAttribute("transform", tr + " rotate(" + Rotation.deg + " " + Rotation.x + " " + Rotation.y + ")");
1014 this.translate = function (x, y) {
1017 var tr = ((Scale - 1) ? " scale(" + Scale + ")" : "") +
1018 (tMatrix ? " " + tMatrix : "") +
1019 (Rotation.deg ? " rotate(" + Rotation.deg + " " + (X + Rotation.x) + " " + (Y + Rotation.y) + ")" : "");
1020 this[0].setAttribute("transform", tr + " translate(" + X + "," + Y + ")");
1025 this.scale = function (times) {
1026 var tr = ((X || Y) ? "translate(" + X + "," + Y + ")" : "") +
1027 (tMatrix ? " " + tMatrix : "");
1029 this[0].setAttribute("transform", tr + " scale(" + Scale + ")");
1030 Rotation.x = (this.getBBox().x + this.getBBox().width / 2);
1031 Rotation.y = (this.getBBox().y + this.getBBox().height / 2);
1032 var tr = ((X || Y) ? "translate(" + X + "," + Y + ")" : "") + " scale(" + Scale + ")" +
1033 (tMatrix ? " " + tMatrix : "") +
1034 (Rotation.deg ? " rotate(" + Rotation.deg + " " + Rotation.x + " " + Rotation.y + ")" : "");
1037 this.matrix = function (xx, xy, yx, yy, dx, dy) {
1038 var tr = ((X || Y) ? "translate(" + X + "," + Y + ")" : "") +
1039 ((Scale - 1) ? " scale(" + Scale + ")" : "") +
1040 (Rotation.deg ? " rotate(" + Rotation.deg + " " + Rotation.x + " " + Rotation.y + ")" : "");
1041 tMatrix = new Matrix(xx, xy, yx, yy, dx, dy);
1042 this[0].setAttribute("transform", tr + " " + tMatrix);
1045 this.remove = function () {
1046 this[0].parentNode.removeChild(this[0]);
1048 this.getBBox = function () {
1049 return this[0].getBBox();
1051 this.attr = function () {
1052 if (arguments.length == 2) {
1053 var att = arguments[0],
1054 value = arguments[1];
1060 this[0].setAttribute(att, svg._getX(value));
1065 this[0].setAttribute(att, svg._getY(value));
1069 this[0].setAttribute(att, svg._getW(value));
1073 this[0].setAttribute(att, svg._getH(value));
1076 addGrdientFill(this[0], params.gradient, svg);
1078 case "stroke-dasharray":
1079 this[0].setAttribute(att, value.replace(" ", ","));
1082 var cssrule = att.replace(/(\-.)/g, function (w) {
1083 return w.substring(1).toUpperCase();
1085 this[0].style[cssrule] = value;
1086 // Need following line for Firefox
1087 this[0].setAttribute(att, value);
1089 } else if (arguments.length = 1 && typeof arguments[0] == "object") {
1090 var params = arguments[0];
1092 for (var attr in params) {
1093 if (attr == "stroke-dasharray") {
1094 this[0].setAttribute(attr, params[attr].replace(" ", ","));
1096 var cssrule = attr.replace(/(\-.)/g, function (w) {
1097 return w.substring(1).toUpperCase();
1099 this[0].style[cssrule] = params[attr];
1100 // Need following line for Firefox
1101 this[0].setAttribute(attr, params[attr]);
1105 if (params.gradient) {
1106 addGrdientFill(this[0], params.gradient, svg);
1111 this.toFront = function () {
1112 this[0].parentNode.appendChild(this[0]);
1115 var theCircle = function (svg, x, y, r) {
1116 var el = document.createElementNS(svg.svgns, "circle");
1117 el.setAttribute("cx", svg._getX(x));
1118 el.setAttribute("cy", svg._getY(y));
1119 el.setAttribute("r", r);
1120 el.setAttribute("fill", "none");
1121 el.setAttribute("stroke", "#000");
1123 svg.canvas.appendChild(el);
1125 var res = new Element(el, svg);
1126 res.type = "circle";
1129 var theRect = function (svg, x, y, w, h, r) {
1130 var el = document.createElementNS(svg.svgns, "rect");
1131 el.setAttribute("x", svg._getX(x));
1132 el.setAttribute("y", svg._getY(y));
1133 el.setAttribute("width", svg._getW(w));
1134 el.setAttribute("height", svg._getH(h));
1136 el.setAttribute("rx", r);
1137 el.setAttribute("ry", r);
1139 el.setAttribute("fill", "none");
1140 el.setAttribute("stroke", "#000");
1142 svg.canvas.appendChild(el);
1144 var res = new Element(el, svg);
1148 var theEllipse = function (svg, x, y, rx, ry) {
1149 var el = document.createElementNS(svg.svgns, "ellipse");
1150 el.setAttribute("cx", svg._getX(x));
1151 el.setAttribute("cy", svg._getY(y));
1152 el.setAttribute("rx", svg._getW(rx));
1153 el.setAttribute("ry", svg._getH(ry));
1154 el.setAttribute("fill", "none");
1155 el.setAttribute("stroke", "#000");
1157 svg.canvas.appendChild(el);
1159 var res = new Element(el, svg);
1160 res.type = "ellipse";
1163 var theImage = function (svg, src, x, y, w, h) {
1164 var el = document.createElementNS(svg.svgns, "image");
1165 el.setAttribute("x", svg._getX(x));
1166 el.setAttribute("y", svg._getY(y));
1167 el.setAttribute("width", svg._getW(w));
1168 el.setAttribute("height", svg._getH(h));
1169 el.setAttributeNS(svg.xlink, "href", src);
1171 svg.canvas.appendChild(el);
1173 var res = new Element(el, svg);
1177 var theText = function (svg, x, y, text) {
1178 var el = document.createElementNS(svg.svgns, "text");
1179 el.setAttribute("x", x);
1180 el.setAttribute("y", y);
1181 el.setAttribute("text-anchor", "middle");
1182 el.appendChild(document.createTextNode(text));
1184 svg.canvas.appendChild(el);
1186 var res = new Element(el, svg);
1190 var theGroup = function (svg) {
1191 var el = document.createElementNS(svg.svgns, "g");
1193 svg.canvas.appendChild(el);
1195 var i = new Element(el, svg);
1196 for (var f in svg) {
1197 if (f[0] != "_" && typeof svg[f] == "function") {
1198 i[f] = (function (f) {
1199 return function () {
1200 var e = svg[f].apply(svg, arguments);
1201 el.appendChild(e[0]);
1210 r._create = function () {
1211 // container, width, height
1212 // x, y, width, height
1213 if (typeof arguments[0] == "string") {
1214 var container = document.getElementById(arguments[0]);
1215 var width = arguments[1];
1216 var height = arguments[2];
1218 if (typeof arguments[0] == "object") {
1219 var container = arguments[0];
1220 var width = arguments[1];
1221 var height = arguments[2];
1223 if (typeof arguments[0] == "number") {
1227 width = arguments[2],
1228 height = arguments[3];
1231 throw new Error("SVG container not found.");
1233 C.canvas = document.createElementNS(C.svgns, "svg");
1234 C.canvas.setAttribute("width", width || 320);
1235 C.width = width || 320;
1236 C.canvas.setAttribute("height", height || 200);
1237 C.height = height || 200;
1238 if (container == 1) {
1239 document.body.appendChild(C.canvas);
1240 C.canvas.style.position = "absolute";
1241 C.canvas.style.left = x + "px";
1242 C.canvas.style.top = y + "px";
1244 if (container.firstChild) {
1245 container.insertBefore(C.canvas, container.firstChild);
1247 container.appendChild(C.canvas);
1252 clear: function () {
1253 while (this.canvas.firstChild) {
1254 this.canvas.removeChild(this.canvas.firstChild);
1256 this.defs = document.createElementNS(C.svgns, "defs");
1258 this.canvas.appendChild(this.defs);
1261 for (var prop in C) {
1262 if (prop != "create") {
1263 container[prop] = C[prop];
1269 C.svgns = "http://www.w3.org/2000/svg";
1270 C.xlink = "http://www.w3.org/1999/xlink";
1272 if (r.vml || r.svg) {
1273 C.circle = function (x, y, r) {
1274 return theCircle(this, x, y, r);
1276 C.rect = function (x, y, w, h, r) {
1277 return theRect(this, x, y, w, h, r);
1279 C.ellipse = function (x, y, rx, ry) {
1280 return theEllipse(this, x, y, rx, ry);
1282 C.path = function (params, pathString) {
1283 return thePath(params, pathString, this);
1285 C.image = function (src, x, y, w, h) {
1286 return theImage(this, src, x, y, w, h);
1288 C.text = function (x, y, text) {
1289 return theText(this, x, y, text);
1291 C.group = function () {
1292 return theGroup(this);
1294 C.linerect = function (x, y, w, h, r) {
1295 if (r && parseInt(r, 10)) {
1296 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();
1298 return this.path({stroke: "#000"}).moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).andClose();
1300 C.drawGrid = function (x, y, w, h, wv, hv, color) {
1301 color = color || "#000";
1302 var res = this.group();
1303 var params = {stroke: color, "stroke-width": "1px", "stroke-opacity": .3};
1304 res.rect(x, y, w, h).attr(params);
1305 for (var i = 1; i < hv; i++) {
1306 var p = res.path(params);
1307 p.moveTo(x, y + i * Math.round(h / hv)).lineTo(x + w, y + i * Math.round(h / hv));
1309 for (var i = 1; i < wv; i++) {
1310 res.path(params).moveTo(x + i * Math.round(w / wv), y).lineTo(x + i * Math.round(w / wv), y + h);
1314 C.setGrid = function (xmin, ymin, xmax, ymax, w, h) {
1315 var xc = (xmax - xmin) / w;
1316 var yc = (ymax - ymin) / h;
1317 this._getX = function (x) {
1318 return xmin + x * xc;
1320 this._getY = function (y) {
1321 return ymin + y * yc;
1323 this._getW = function (w) {
1326 this._getH = function (h) {
1330 C.clearGrid = function () {
1331 this._getX = this._getY = this._getW = this._getH = function (x) { return x; };
1333 C.safari = function () {
1334 if (this.type == "SVG") {
1335 var rect = C.rect(0, 0, C.width, C.height).attr("stroke-width", 0);
1336 setTimeout(function () {rect.remove();}, 0);
1339 Raphael = function () {
1340 return r._create.apply(r, arguments);
1342 return r._create.apply(r, args);
1346 })(arguments.callee, arguments);
1350 Raphael.type = (!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2) && !(window.CanvasRenderingContext2D)) ? "VML" : "SVG";
1351 Raphael.vml = !(Raphael.svg = (Raphael.type == "SVG"));
1352 if (!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2) && window.CanvasRenderingContext2D) {
1353 Raphael.type = "Canvas only";
1354 Raphael.vml = Raphael.svg = false;
1356 Raphael.toString = function () {
1357 return "You browser supports " + this.type;