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[0].style.display = "none";
368 this.show = function () {
369 this[0].style.display = "block";
371 this.rotate = function (deg) {
373 this.Group.style.rotation = Rotation;
376 this.translate = function (x, y) {
379 this.Group.style.left = this.X + "px";
380 this.Group.style.top = this.Y + "px";
384 this.matrix = function (xx, xy, yx, yy, dx, dy) {
385 tMatrix = new Matrix(xx, xy, yx, yy, dx, dy);
386 this.Group.style.filter = tMatrix;
389 this.scale = function (x, y) {
391 if (x != 0 && !(x == 1 && y == 1)) {
392 var dirx = Math.round(x / Math.abs(x)),
393 diry = Math.round(y / Math.abs(y));
394 if (dirx != 1 || diry != 1) {
395 this[0].style.filter = new Matrix(dirx, 0, 0, diry, 0, 0);
397 var width = parseInt(this[0].style.width, 10) * x * dirx;
398 var height = parseInt(this[0].style.height, 10) * y * diry;
399 var left = parseInt(this[0].style.left, 10);
400 var top = parseInt(this[0].style.top, 10);
401 this[0].style.left = this.X = left + this.W / 2 - width / 2;
402 this[0].style.top = this.Y = top + this.H / 2 - height / 2;
403 this[0].style.width = this.W = width;
404 this[0].style.height = this.H = height;
408 this.getBBox = function () {
410 x: this.Group.offsetLeft,
411 y: this.Group.offsetTop,
412 width: this.Group.offsetWidth,
413 height: this.Group.offsetHeight
416 this.remove = function () {
417 this[0].parentNode.removeChild(this[0]);
418 this.Group.parentNode.removeChild(this.Group);
419 this.shape && this.shape.parentNode.removeChild(this.shape);
421 this.attr = function () {
422 if (arguments.length == 1 && typeof arguments[0] == "string") {
423 return this[0].attrs[arguments[0]];
425 if (this[0].attrs && arguments.length == 1 && arguments[0] instanceof Array) {
427 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
428 values[arguments[0][i]] = this[0].attrs[arguments[0][i]];
432 if (this[0].tagName.toLowerCase() == "group") {
433 var children = this[0].childNodes;
434 this[0].attrs = this[0].attrs || {};
435 if (arguments.length == 2) {
436 this[0].attrs[arguments[0]] = arguments[1];
437 } else if (arguments.length = 1 || typeof arguments[0] == "object") {
438 for (var j in arguments[0]) {
439 this[0].attrs[j] = arguments[0][j];
442 for (var i = 0, ii = children.length; i < ii; i++) {
443 this.attr.apply(new item(children[i], this[0], vml), arguments);
446 if (arguments.length == 2) {
447 var att = arguments[0],
448 value = arguments[1];
451 this[0].style.width = this[0].style.height = value * 2 + "px";
452 this[0].style.left = vml._getX(this.cx) - value + "px";
453 this[0].style.top = vml._getY(this.cy) - value + "px";
457 this[0].style.width = value * 2 + "px";
458 this[0].style.left = vml._getX(this.cx) - value + "px";
462 this[0].style.height = value * 2 + "px";
463 this[0].style.top = vml._getY(this.cy) - value + "px";
467 if (this.r || this.rx) {
468 this[0].style.left = vml._getX(value) - (this.r || vml._getW(this.rx)) + "px";
473 this[0].style.left = vml._getX(value) + "px";
476 if (this.r || this.ry) {
477 this[0].style.top = vml._getY(value) - (this.r || vml._getH(this.ry)) + "px";
482 this[0].style.top = vml._getY(value) + "px";
489 case "stroke-dasharray":
490 case "stroke-opacity":
494 setFillAndStroke(this, params);
502 this[0].style[att] = value;
508 if (this.type == "text") {
509 this[0].string = value;
513 addGrdientFill(this, value);
516 if (arguments.length == 1 && typeof arguments[0] == "object") {
517 var params = arguments[0];
518 setFillAndStroke(this, params);
519 if (params.gradient) {
520 addGrdientFill(this, params.gradient);
522 if (params.text && this.type == "text") {
523 this[0].string = params.text;
526 this[0].id = params.id;
532 this.toFront = function () {
533 this.Group.parentNode.appendChild(this.Group);
535 this.toBack = function () {
536 if (this.Group.parentNode.firstChild != this.Group) {
537 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
541 var theCircle = function (vml, x, y, r) {
542 var g = document.createElement("rvml:group");
543 var o = document.createElement("rvml:oval");
545 vml.canvas.appendChild(g);
546 var res = new Element(o, g, vml);
547 setFillAndStroke(res, {stroke: "#000"});
548 setTheBox(vml, res, x - r, y - r, r * 2, r * 2);
555 var theRect = function (vml, x, y, w, h, r) {
556 var g = document.createElement("rvml:group");
557 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect");
559 o.arcsize = r / (Math.min(w, h));
562 vml.canvas.appendChild(g);
563 var res = new Element(o, g, vml);
564 setFillAndStroke(res, {stroke: "#000"});
565 setTheBox(vml, res, x, y, w, h);
574 var theEllipse = function (vml, x, y, rx, ry) {
575 var g = document.createElement("rvml:group");
576 var o = document.createElement("rvml:oval");
578 vml.canvas.appendChild(g);
579 var res = new Element(o, g, vml);
580 setFillAndStroke(res, {stroke: "#000"});
581 setTheBox(vml, res, x - rx, y - ry, rx * 2, ry * 2);
586 res.type = "ellipse";
589 var theImage = function (vml, src, x, y, w, h) {
590 var g = document.createElement("rvml:group");
591 var o = document.createElement("rvml:image");
594 vml.canvas.appendChild(g);
595 var res = new Element(o, g, vml);
596 setTheBox(vml, res, x, y, w, h);
600 var theText = function (vml, x, y, text) {
602 var g = document.createElement("rvml:group"), gs = g.style;
603 var el = document.createElement("rvml:shape"), ol = el.style;
604 var path = document.createElement("rvml:path"), ps = path.style;
605 path.v = ["m", Math.round(x), ", ", Math.round(y), "l", Math.round(x) + 1, ", ", Math.round(y)].join("");
606 path.textpathok = true;
607 ol.width = vml.width;
608 ol.height = vml.height;
609 gs.position = "absolute";
612 gs.width = vml.width;
613 gs.height = vml.height;
614 var o = document.createElement("rvml:textpath");
617 o.coordsize = vml.coordsize;
618 o.coordorigin = vml.coordorigin;
620 el.appendChild(path);
621 // g.appendChild(el);
622 vml.canvas.appendChild(el);
623 var res = new Element(o, el, vml);
628 var theGroup = function (vml) {
629 var el = document.createElement("rvml:group"), els = el.style;
630 els.position = "absolute";
633 els.width = vml.width;
634 els.height = vml.height;
636 vml.canvas.appendChild(el);
638 var res = new Element(el, el, vml);
640 if (f.charAt(0) != "_" && typeof vml[f] == "function") {
641 res[f] = (function (f) {
643 var e = vml[f].apply(vml, arguments);
644 el.appendChild(e[0].parentNode);
653 r._create = function () {
654 // container, width, height
655 // x, y, width, height
656 if (typeof arguments[0] == "string") {
657 var container = document.getElementById(arguments[0]);
658 var width = arguments[1];
659 var height = arguments[2];
661 if (typeof arguments[0] == "object") {
662 var container = arguments[0];
663 var width = arguments[1];
664 var height = arguments[2];
666 if (typeof arguments[0] == "number") {
670 width = arguments[2],
671 height = arguments[3];
674 throw new Error("VML container not found.");
676 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
677 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
678 var c = document.createElement("div"),
679 r = C.canvas = document.createElement("rvml:group"),
680 cs = c.style, rs = r.style;
683 width = width || "320px";
684 height = height || "200px";
685 cs.clip = "rect(0 " + width + " " + height + " 0)";
686 cs.position = "absolute";
689 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
690 r.coordorigin = "0 0";
692 var b = document.createElement("rvml:rect"), bs = b.style;
693 bs.left = bs.top = 0;
695 bs.height = rs.height;
696 b.filled = b.stroked = "f";
700 if (container == 1) {
701 document.body.appendChild(c);
702 cs.position = "absolute";
714 cs.width = container.style.width = width;
715 cs.height = container.style.height = height;
716 if (container.firstChild) {
717 container.insertBefore(c, container.firstChild);
719 container.appendChild(c);
722 for (var prop in C) {
723 container[prop] = C[prop];
725 container.clear = function () {
727 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
728 if (r.childNodes[i] != b) {
729 todel.push(r.childNodes[i]);
732 for (i = 0, ii = todel.length; i < ii; i++) {
733 r.removeChild(todel[i]);
740 Matrix.prototype.toString = function () {
741 return "matrix(" + this.m[0][0] +
742 ", " + this.m[1][0] + ", " + this.m[0][1] + ", " + this.m[1][1] +
743 ", " + this.m[2][0] + ", " + this.m[2][1] + ")";
745 var thePath = function (params, pathString, SVG) {
746 var el = document.createElementNS(SVG.svgns, "path");
747 el.setAttribute("fill", "none");
749 for (var attr in params) {
750 if (params.gradient) {
751 addGrdientFill(el, params.gradient, SVG);
753 el.setAttribute(attr, params[attr]);
758 SVG.canvas.appendChild(el);
760 var p = new Element(el, SVG);
761 for (var attr in params) {
762 p.attrs[attr] = params[attr];
766 p.last = {x: 0, y: 0, bx: 0, by: 0};
767 p.absolutely = function () {
768 this.isAbsolute = true;
771 p.relatively = function () {
772 this.isAbsolute = false;
775 p.redraw = function () {
776 this[0].setAttribute("d", "M0 0");
777 var oldPath = this.path;
779 for (var i = 0, ii = oldPath.length; i < ii; i++) {
780 if (oldPath[i].type != "end") {
781 this[oldPath[i].type + "To"].apply(this, oldPath[i].arg);
787 p.moveTo = function (x, y) {
788 var d = this.isAbsolute?"M":"m";
789 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
790 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
791 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
792 var oldD = this[0].getAttribute("d") || "";
793 this[0].setAttribute("d", oldD + d);
794 this.last.x = SVG._getX(parseFloat(x, 10));
795 this.last.y = SVG._getY(parseFloat(y, 10));
796 this.path.push({type: "move", arg: arguments, pos: this.isAbsolute});
799 p.lineTo = function (x, y) {
800 var d = this.isAbsolute?"L":"l";
801 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
802 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
803 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
804 var oldD = this[0].getAttribute("d") || "";
805 this[0].setAttribute("d", oldD + d);
806 this.last.x = SVG._getX(parseFloat(x, 10));
807 this.last.y = SVG._getY(parseFloat(y, 10));
808 this.path.push({type: "line", arg: arguments, pos: this.isAbsolute});
811 p.cplineTo = function (x1, y1, w1) {
813 return this.lineTo(x1, y1);
816 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
817 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
818 var x = p._getX(Math.round(parseFloat(x1, 10) * 100) / 100);
819 var y = p._getY(Math.round(parseFloat(y1, 10) * 100) / 100);
820 var w = SVG._getW(Math.round(parseFloat(w1, 10) * 100) / 100);
821 var d = this.isAbsolute?"C":"c";
822 var attr = [this.last.x + w, this.last.y, x - w, y, x, y];
823 for (var i = 0, ii = attr.length; i < ii; i++) {
826 this.last.x = attr[4];
827 this.last.y = attr[5];
828 this.last.bx = attr[2];
829 this.last.by = attr[3];
830 var oldD = this[0].getAttribute("d") || "";
831 this[0].setAttribute("d", oldD + d);
832 this.path.push({type: "cpline", arg: arguments, pos: this.isAbsolute});
836 p.curveTo = function () {
838 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
839 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
840 if (arguments.length == 6) {
841 var d = this.isAbsolute?"C":"c";
842 for (var i = 0, ii = arguments.length; i < ii; i++) {
843 d += p[(i % 2 == 0) ? "_getX" : "_getY"](Math.round(parseFloat(arguments[i], 10) * 100) / 100) + " ";
845 this.last.x = p._getX((parseFloat(arguments[4], 10) * 100) / 100);
846 this.last.y = p._getY((parseFloat(arguments[5], 10) * 100) / 100);
847 this.last.bx = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
848 this.last.by = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
850 if (arguments.length == 4) {
851 var d = this.isAbsolute?"S":"s";
852 for (var i = 0, ii = arguments.length; i < ii; i++) {
853 d += p[i % 2 == 0 ? "_getX" : "_getY"]((parseFloat(arguments[i], 10) * 100) / 100) + " ";
856 this.last.x = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
857 this.last.y = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
858 this.last.bx = p._getX((parseFloat(arguments[0], 10) * 100) / 100);
859 this.last.by = p._getY((parseFloat(arguments[1], 10) * 100) / 100);
861 var oldD = this[0].getAttribute("d") || "";
862 this[0].setAttribute("d", oldD + d);
863 this.path.push({type: "curve", arg: arguments, pos: this.isAbsolute});
866 p.addRoundedCorner = function (r, dir) {
867 var R = .5522 * r, rollback = this.isAbsolute, o = this;
870 rollback = function () {
874 rollback = function () {};
880 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
883 o.curveTo(-R, 0, -r, r - R, -r, r);
890 o.curveTo(R, 0, r, -(r - R), r, -r);
893 o.curveTo(R, 0, r, r - R, r, r);
900 o.curveTo(0, -R, -(R - r), -r, r, -r);
903 o.curveTo(0, -R, R - r, -r, -r, -r);
910 o.curveTo(0, R, -(R - r), r, r, r);
913 o.curveTo(0, R, R - r, r, -r, r);
918 actions[dir[0]]()[dir[1]]();
922 p.andClose = function () {
923 var oldD = this[0].getAttribute("d") || "";
924 this[0].setAttribute("d", oldD + "Z ");
925 this.path.push({type: "end"});
928 if (typeof pathString == "string") {
929 pathString = pathString.replace(/([mzlhvcsqta])/ig, ",$1,").replace(/([^,])\-/ig, "$1,-");
930 path = pathString.split(",");
931 var i = 1, ii = path.length;
935 p.absolutely().moveTo(path[++i], path[++i]);
938 p.relatively().moveTo(path[++i], path[++i]);
941 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
944 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
947 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i]);
950 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i]);
953 p.absolutely().lineTo(path[++i], path[++i]);
956 p.relatively().lineTo(path[++i], path[++i]);
959 p.absolutely().lineTo(path[++i], 0);
962 p.relatively().lineTo(path[++i], 0);
965 p.absolutely().lineTo(0, path[++i]);
968 p.relatively().lineTo(0, path[++i]);
979 var addGrdientFill = function (o, gradient, SVG) {
980 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
981 el.id = "raphael-gradient-" + SVG.gradients++;
982 if (gradient.vector && gradient.vector.length) {
983 el.setAttribute("x1", gradient.vector[0]);
984 el.setAttribute("y1", gradient.vector[1]);
985 el.setAttribute("x2", gradient.vector[2]);
986 el.setAttribute("y2", gradient.vector[3]);
988 SVG.defs.appendChild(el);
989 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
990 var stop = document.createElementNS(SVG.svgns, "stop");
991 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
992 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
993 if (typeof gradient.dots[i].opacity != "undefined") {
994 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
996 el.appendChild(stop);
998 o.setAttribute("fill", "url(#" + el.id + ")");
1000 var Element = function (node, svg) {
1003 Rotation = {deg: 0, x: 0, y: 0},
1007 this.attrs = this.attrs || {};
1008 this.transformations = [];
1009 this.hide = function () {
1010 this[0].style.display = "none";
1012 this.show = function () {
1013 this[0].style.display = "block";
1015 this.rotate = function (deg) {
1016 var bbox = this.getBBox();
1017 this.transformations.push("rotate(" + deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
1018 this[0].setAttribute("transform", this.transformations.join(" "));
1021 this.translate = function (x, y) {
1022 this.transformations.push("translate(" + x + "," + y + ")");
1023 this[0].setAttribute("transform", this.transformations.join(" "));
1026 this.scale = function (x, y) {
1028 if (x != 0 && !(x == 1 && y == 1)) {
1029 var bbox = this.getBBox(),
1030 dx = bbox.x * (1 - x) + (bbox.width / 2 - bbox.width * x / 2),
1031 dy = bbox.y * (1 - y) + (bbox.height / 2 - bbox.height * y / 2);
1032 this.transformations.push(new Matrix(x, 0, 0, y, dx, dy));
1033 this[0].setAttribute("transform", this.transformations.join(" "));
1037 this.matrix = function (xx, xy, yx, yy, dx, dy) {
1038 this.transformations.push(new Matrix(xx, xy, yx, yy, dx, dy));
1039 this[0].setAttribute("transform", this.transformations.join(" "));
1042 this.remove = function () {
1043 this[0].parentNode.removeChild(this[0]);
1045 this.getBBox = function () {
1046 return this[0].getBBox();
1048 this.attr = function () {
1049 if (arguments.length == 1 && typeof arguments[0] == "string") {
1050 return this.attrs[arguments[0]];
1052 if (arguments.length == 1 && arguments[0] instanceof Array) {
1054 for (var j in arguments[0]) {
1055 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1059 if (arguments.length == 2) {
1060 var att = arguments[0],
1061 value = arguments[1];
1063 this.attrs[att] = value;
1068 this[0].setAttribute(att, svg._getX(value));
1073 this[0].setAttribute(att, svg._getY(value));
1076 this[0].setAttribute(att, svg._getW(value));
1079 this[0].setAttribute(att, svg._getH(value));
1082 addGrdientFill(this[0], params.gradient, svg);
1084 case "stroke-dasharray":
1085 this[0].setAttribute(att, value.replace(" ", ","));
1088 if (this.type == "text") {
1089 this[0].removeChild(this[0].firstChild);
1090 this[0].appendChild(document.createTextNode(value));
1094 var cssrule = att.replace(/(\-.)/g, function (w) {
1095 return w.substring(1).toUpperCase();
1097 this[0].style[cssrule] = value;
1098 // Need following line for Firefox
1099 this[0].setAttribute(att, value);
1101 } else if (arguments.length = 1 && typeof arguments[0] == "object") {
1102 var params = arguments[0];
1103 for (var attr in params) {
1104 this.attrs[attr] = params[attr];
1105 if (attr == "stroke-dasharray") {
1106 this[0].setAttribute(attr, params[attr].replace(" ", ","));
1107 } else if (attr == "text" && this.type == "text") {
1108 this[0].removeChild(this[0].firstChild);
1109 this[0].appendChild(document.createTextNode(params[attr]));
1111 var cssrule = attr.replace(/(\-.)/g, function (w) {
1112 return w.substring(1).toUpperCase();
1114 this[0].style[cssrule] = params[attr];
1115 // Need following line for Firefox
1116 this[0].setAttribute(attr, params[attr]);
1119 if (params.gradient) {
1120 this[0].attrs.gradient = params.gradient;
1121 addGrdientFill(this[0], params.gradient, svg);
1126 this.toFront = function () {
1127 this[0].parentNode.appendChild(this[0]);
1129 this.toBack = function () {
1130 if (this[0].parentNode.firstChild != this[0]) {
1131 this[0].parentNode.insertBefore(this[0], this[0].parentNode.firstChild);
1135 var theCircle = function (svg, x, y, r) {
1136 var el = document.createElementNS(svg.svgns, "circle");
1137 el.setAttribute("cx", svg._getX(x));
1138 el.setAttribute("cy", svg._getY(y));
1139 el.setAttribute("r", r);
1140 el.setAttribute("fill", "none");
1141 el.setAttribute("stroke", "#000");
1142 el.attrs = el.attrs || {};
1146 el.attrs.stroke = "#000";
1148 svg.canvas.appendChild(el);
1150 var res = new Element(el, svg);
1151 res.type = "circle";
1154 var theRect = function (svg, x, y, w, h, r) {
1155 var el = document.createElementNS(svg.svgns, "rect");
1156 el.setAttribute("x", svg._getX(x));
1157 el.setAttribute("y", svg._getY(y));
1158 el.setAttribute("width", svg._getW(w));
1159 el.setAttribute("height", svg._getH(h));
1160 el.attrs = el.attrs || {};
1164 el.attrs.height = h;
1166 el.setAttribute("rx", r);
1167 el.setAttribute("ry", r);
1168 el.attrs.rx = el.attrs.ry = r;
1170 el.setAttribute("fill", "none");
1171 el.setAttribute("stroke", "#000");
1172 el.attrs.stroke = "#000";
1174 svg.canvas.appendChild(el);
1176 var res = new Element(el, svg);
1180 var theEllipse = function (svg, x, y, rx, ry) {
1181 var el = document.createElementNS(svg.svgns, "ellipse");
1182 el.setAttribute("cx", svg._getX(x));
1183 el.setAttribute("cy", svg._getY(y));
1184 el.setAttribute("rx", svg._getW(rx));
1185 el.setAttribute("ry", svg._getH(ry));
1186 el.setAttribute("fill", "none");
1187 el.setAttribute("stroke", "#000");
1188 el.attrs = el.attrs || {};
1193 el.attrs.stroke = "#000";
1195 svg.canvas.appendChild(el);
1197 var res = new Element(el, svg);
1198 res.type = "ellipse";
1201 var theImage = function (svg, src, x, y, w, h) {
1202 var el = document.createElementNS(svg.svgns, "image");
1203 el.setAttribute("x", svg._getX(x));
1204 el.setAttribute("y", svg._getY(y));
1205 el.setAttribute("width", svg._getW(w));
1206 el.setAttribute("height", svg._getH(h));
1207 el.setAttributeNS(svg.xlink, "href", src);
1209 svg.canvas.appendChild(el);
1211 var res = new Element(el, svg);
1215 var theText = function (svg, x, y, text) {
1216 var el = document.createElementNS(svg.svgns, "text");
1217 el.setAttribute("x", x);
1218 el.setAttribute("y", y);
1219 el.setAttribute("text-anchor", "middle");
1220 el.setAttribute("fill", "#000");
1221 el.attrs = el.attrs || {};
1224 el.attrs.fill = "#000";
1226 el.appendChild(document.createTextNode(text));
1229 svg.canvas.appendChild(el);
1231 var res = new Element(el, svg);
1235 var theGroup = function (svg) {
1236 var el = document.createElementNS(svg.svgns, "g");
1238 svg.canvas.appendChild(el);
1240 var i = new Element(el, svg);
1241 for (var f in svg) {
1242 if (f[0] != "_" && typeof svg[f] == "function") {
1243 i[f] = (function (f) {
1244 return function () {
1245 var e = svg[f].apply(svg, arguments);
1246 el.appendChild(e[0]);
1255 r._create = function () {
1256 // container, width, height
1257 // x, y, width, height
1258 if (typeof arguments[0] == "string") {
1259 var container = document.getElementById(arguments[0]);
1260 var width = arguments[1];
1261 var height = arguments[2];
1263 if (typeof arguments[0] == "object") {
1264 var container = arguments[0];
1265 var width = arguments[1];
1266 var height = arguments[2];
1268 if (typeof arguments[0] == "number") {
1272 width = arguments[2],
1273 height = arguments[3];
1276 throw new Error("SVG container not found.");
1278 C.canvas = document.createElementNS(C.svgns, "svg");
1279 C.canvas.setAttribute("width", width || 320);
1280 C.width = width || 320;
1281 C.canvas.setAttribute("height", height || 200);
1282 C.height = height || 200;
1283 if (container == 1) {
1284 document.body.appendChild(C.canvas);
1285 C.canvas.style.position = "absolute";
1286 C.canvas.style.left = x + "px";
1287 C.canvas.style.top = y + "px";
1289 if (container.firstChild) {
1290 container.insertBefore(C.canvas, container.firstChild);
1292 container.appendChild(C.canvas);
1297 clear: function () {
1298 while (this.canvas.firstChild) {
1299 this.canvas.removeChild(this.canvas.firstChild);
1301 this.defs = document.createElementNS(C.svgns, "defs");
1303 this.canvas.appendChild(this.defs);
1306 for (var prop in C) {
1307 if (prop != "create") {
1308 container[prop] = C[prop];
1314 C.svgns = "http://www.w3.org/2000/svg";
1315 C.xlink = "http://www.w3.org/1999/xlink";
1317 if (r.vml || r.svg) {
1318 C.circle = function (x, y, r) {
1319 return theCircle(this, x, y, r);
1321 C.rect = function (x, y, w, h, r) {
1322 return theRect(this, x, y, w, h, r);
1324 C.ellipse = function (x, y, rx, ry) {
1325 return theEllipse(this, x, y, rx, ry);
1327 C.path = function (params, pathString) {
1328 return thePath(params, pathString, this);
1330 C.image = function (src, x, y, w, h) {
1331 return theImage(this, src, x, y, w, h);
1333 C.text = function (x, y, text) {
1334 return theText(this, x, y, text);
1336 C.group = function () {
1337 return theGroup(this);
1339 C.linerect = function (x, y, w, h, r) {
1340 if (r && parseInt(r, 10)) {
1341 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();
1343 return this.path({stroke: "#000"}).moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).andClose();
1345 C.drawGrid = function (x, y, w, h, wv, hv, color) {
1346 color = color || "#000";
1347 var res = this.group();
1348 var params = {stroke: color, "stroke-width": "1px", "stroke-opacity": .3};
1349 res.rect(x, y, w, h).attr(params);
1350 for (var i = 1; i < hv; i++) {
1351 var p = res.path(params);
1352 p.moveTo(x, y + i * Math.round(h / hv)).lineTo(x + w, y + i * Math.round(h / hv));
1354 for (var i = 1; i < wv; i++) {
1355 res.path(params).moveTo(x + i * Math.round(w / wv), y).lineTo(x + i * Math.round(w / wv), y + h);
1359 C.setGrid = function (xmin, ymin, xmax, ymax, w, h) {
1360 var xc = (xmax - xmin) / w;
1361 var yc = (ymax - ymin) / h;
1362 this._getX = function (x) {
1363 return xmin + x * xc;
1365 this._getY = function (y) {
1366 return ymin + y * yc;
1368 this._getW = function (w) {
1371 this._getH = function (h) {
1375 C.clearGrid = function () {
1376 this._getX = this._getY = this._getW = this._getH = function (x) { return x; };
1378 C.safari = function () {
1379 if (this.type == "SVG") {
1380 var rect = C.rect(0, 0, C.width, C.height).attr("stroke-width", 0);
1381 setTimeout(function () {rect.remove();}, 0);
1384 Raphael = function () {
1385 return r._create.apply(r, arguments);
1387 return r._create.apply(r, args);
1391 })(arguments.callee, arguments);
1395 Raphael.type = (!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2) && !(window.CanvasRenderingContext2D)) ? "VML" : "SVG";
1396 Raphael.vml = !(Raphael.svg = (Raphael.type == "SVG"));
1397 if (!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2) && window.CanvasRenderingContext2D) {
1398 Raphael.type = "Canvas only";
1399 Raphael.vml = Raphael.svg = false;
1401 Raphael.toString = function () {
1402 return "You browser supports " + this.type;