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.rotate = function (deg) {
367 this.Group.style.rotation = Rotation;
370 this.translate = function (x, y) {
373 this.Group.style.left = this.X + "px";
374 this.Group.style.top = this.Y + "px";
378 this.matrix = function (xx, xy, yx, yy, dx, dy) {
379 tMatrix = new Matrix(xx, xy, yx, yy, dx, dy);
380 this.Group.style.filter = tMatrix;
383 this.scale = function (x, y) {
385 if (x != 0 && !(x == 1 && y == 1)) {
386 var dirx = Math.round(x / Math.abs(x)),
387 diry = Math.round(y / Math.abs(y));
388 if (dirx != 1 || diry != 1) {
389 this[0].style.filter = new Matrix(dirx, 0, 0, diry, 0, 0);
391 var width = parseInt(this[0].style.width, 10) * x * dirx;
392 var height = parseInt(this[0].style.height, 10) * y * diry;
393 var left = parseInt(this[0].style.left, 10);
394 var top = parseInt(this[0].style.top, 10);
395 this[0].style.left = this.X = left + this.W / 2 - width / 2;
396 this[0].style.top = this.Y = top + this.H / 2 - height / 2;
397 this[0].style.width = this.W = width;
398 this[0].style.height = this.H = height;
402 this.getBBox = function () {
404 x: this.Group.offsetLeft,
405 y: this.Group.offsetTop,
406 width: this.Group.offsetWidth,
407 height: this.Group.offsetHeight
410 this.remove = function () {
411 this[0].parentNode.removeChild(this[0]);
412 this.Group.parentNode.removeChild(this.Group);
413 this.shape && this.shape.parentNode.removeChild(this.shape);
415 this.attr = function () {
416 if (arguments.length == 1 && typeof arguments[0] == "string") {
417 return this[0].attrs[arguments[0]];
419 if (this[0].attrs && arguments.length == 1 && arguments[0] instanceof Array) {
421 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
422 values[arguments[0][i]] = this[0].attrs[arguments[0][i]];
426 if (this[0].tagName.toLowerCase() == "group") {
427 var children = this[0].childNodes;
428 this[0].attrs = this[0].attrs || {};
429 if (arguments.length == 2) {
430 this[0].attrs[arguments[0]] = arguments[1];
431 } else if (arguments.length = 1 || typeof arguments[0] == "object") {
432 for (var j in arguments[0]) {
433 this[0].attrs[j] = arguments[0][j];
436 for (var i = 0, ii = children.length; i < ii; i++) {
437 this.attr.apply(new item(children[i], this[0], vml), arguments);
440 if (arguments.length == 2) {
441 var att = arguments[0],
442 value = arguments[1];
445 this[0].style.width = this[0].style.height = value * 2 + "px";
446 this[0].style.left = vml._getX(this.cx) - value + "px";
447 this[0].style.top = vml._getY(this.cy) - value + "px";
451 this[0].style.width = value * 2 + "px";
452 this[0].style.left = vml._getX(this.cx) - value + "px";
456 this[0].style.height = value * 2 + "px";
457 this[0].style.top = vml._getY(this.cy) - value + "px";
461 if (this.r || this.rx) {
462 this[0].style.left = vml._getX(value) - (this.r || vml._getW(this.rx)) + "px";
467 this[0].style.left = vml._getX(value) + "px";
470 if (this.r || this.ry) {
471 this[0].style.top = vml._getY(value) - (this.r || vml._getH(this.ry)) + "px";
476 this[0].style.top = vml._getY(value) + "px";
483 case "stroke-dasharray":
484 case "stroke-opacity":
488 setFillAndStroke(this, params);
496 this[0].style[att] = value;
502 addGrdientFill(this, value);
505 if (arguments.length == 1 && typeof arguments[0] == "object") {
506 var params = arguments[0];
507 setFillAndStroke(this, params);
508 if (params.gradient) {
509 addGrdientFill(this, params.gradient);
512 this[0].id = params.id;
518 this.toFront = function () {
519 this.Group.parentNode.appendChild(this.Group);
521 this.toBack = function () {
522 if (this.Group.parentNode.firstChild != this.Group) {
523 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
527 var theCircle = function (vml, x, y, r) {
528 var g = document.createElement("rvml:group");
529 var o = document.createElement("rvml:oval");
531 vml.canvas.appendChild(g);
532 var res = new Element(o, g, vml);
533 setFillAndStroke(res, {stroke: "#000"});
534 setTheBox(vml, res, x - r, y - r, r * 2, r * 2);
541 var theRect = function (vml, x, y, w, h, r) {
542 var g = document.createElement("rvml:group");
543 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect");
545 o.arcsize = r / (Math.min(w, h));
548 vml.canvas.appendChild(g);
549 var res = new Element(o, g, vml);
550 setFillAndStroke(res, {stroke: "#000"});
551 setTheBox(vml, res, x, y, w, h);
560 var theEllipse = function (vml, x, y, rx, ry) {
561 var g = document.createElement("rvml:group");
562 var o = document.createElement("rvml:oval");
564 vml.canvas.appendChild(g);
565 var res = new Element(o, g, vml);
566 setFillAndStroke(res, {stroke: "#000"});
567 setTheBox(vml, res, x - rx, y - ry, rx * 2, ry * 2);
572 res.type = "ellipse";
575 var theImage = function (vml, src, x, y, w, h) {
576 var g = document.createElement("rvml:group");
577 var o = document.createElement("rvml:image");
580 vml.canvas.appendChild(g);
581 var res = new Element(o, g, vml);
582 setTheBox(vml, res, x, y, w, h);
586 var theText = function (vml, x, y, text) {
588 var g = document.createElement("rvml:group"), gs = g.style;
589 var el = document.createElement("rvml:shape"), ol = el.style;
590 var path = document.createElement("rvml:path"), ps = path.style;
591 path.v = ["m", x, ", ", y, "l", x + 1, ", ", y].join("");
592 path.textpathok = true;
593 ps.position = "absolute";
596 ol.width = vml.width + "px";
597 ol.height = vml.height + "px";
598 gs.position = "absolute";
601 gs.width = vml.width;
602 gs.height = vml.height;
603 g.coordsize = vml.coordsize;
604 g.coordorigin = vml.coordorigin;
605 var o = document.createElement("rvml:textpath");
608 o.coordsize = vml.coordsize;
609 o.coordorigin = vml.coordorigin;
611 el.appendChild(path);
613 vml.canvas.appendChild(g);
614 var res = new Element(o, g, vml);
619 var theGroup = function (vml) {
620 var el = document.createElement("rvml:group"), els = el.style;
621 els.position = "absolute";
624 els.width = vml.width;
625 els.height = vml.height;
627 vml.canvas.appendChild(el);
629 var res = new Element(el, el, vml);
631 if (f.charAt(0) != "_" && typeof vml[f] == "function") {
632 res[f] = (function (f) {
634 var e = vml[f].apply(vml, arguments);
635 el.appendChild(e[0].parentNode);
644 r._create = function () {
645 // container, width, height
646 // x, y, width, height
647 if (typeof arguments[0] == "string") {
648 var container = document.getElementById(arguments[0]);
649 var width = arguments[1];
650 var height = arguments[2];
652 if (typeof arguments[0] == "object") {
653 var container = arguments[0];
654 var width = arguments[1];
655 var height = arguments[2];
657 if (typeof arguments[0] == "number") {
661 width = arguments[2],
662 height = arguments[3];
665 throw new Error("VML container not found.");
667 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
668 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
669 var c = document.createElement("div"),
670 r = C.canvas = document.createElement("rvml:group"),
671 cs = c.style, rs = r.style;
674 width = width || "320px";
675 height = height || "200px";
676 cs.clip = "rect(0 " + width + " " + height + " 0)";
677 cs.position = "absolute";
680 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
681 r.coordorigin = "0 0";
683 var b = document.createElement("rvml:rect"), bs = b.style;
684 bs.left = bs.top = 0;
686 bs.height = rs.height;
687 b.filled = b.stroked = "f";
691 if (container == 1) {
692 document.body.appendChild(c);
693 cs.position = "absolute";
705 cs.width = container.style.width = width;
706 cs.height = container.style.height = height;
707 if (container.firstChild) {
708 container.insertBefore(c, container.firstChild);
710 container.appendChild(c);
713 for (var prop in C) {
714 container[prop] = C[prop];
716 container.clear = function () {
718 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
719 if (r.childNodes[i] != b) {
720 todel.push(r.childNodes[i]);
723 for (i = 0, ii = todel.length; i < ii; i++) {
724 r.removeChild(todel[i]);
731 Matrix.prototype.toString = function () {
732 return "matrix(" + this.m[0][0] +
733 ", " + this.m[1][0] + ", " + this.m[0][1] + ", " + this.m[1][1] +
734 ", " + this.m[2][0] + ", " + this.m[2][1] + ")";
736 var thePath = function (params, pathString, SVG) {
737 var el = document.createElementNS(SVG.svgns, "path");
738 el.setAttribute("fill", "none");
740 for (var attr in params) {
741 if (params.gradient) {
742 addGrdientFill(el, params.gradient, SVG);
744 el.setAttribute(attr, params[attr]);
749 SVG.canvas.appendChild(el);
751 var p = new Element(el, SVG);
754 p.last = {x: 0, y: 0, bx: 0, by: 0};
755 p.absolutely = function () {
756 this.isAbsolute = true;
759 p.relatively = function () {
760 this.isAbsolute = false;
763 p.redraw = function () {
764 this[0].setAttribute("d", "M0 0");
765 var oldPath = this.path;
767 for (var i = 0, ii = oldPath.length; i < ii; i++) {
768 if (oldPath[i].type != "end") {
769 this[oldPath[i].type + "To"].apply(this, oldPath[i].arg);
775 p.moveTo = function (x, y) {
776 var d = this.isAbsolute?"M":"m";
777 var _getX = this.isAbsolute ? SVG._getX : SVG._getW;
778 var _getY = this.isAbsolute ? SVG._getY : SVG._getH;
779 d += _getX(parseFloat(x, 10)) + " " + _getY(parseFloat(y, 10)) + " ";
780 var oldD = this[0].getAttribute("d") || "";
781 this[0].setAttribute("d", oldD + d);
782 this.last.x = SVG._getX(parseFloat(x, 10));
783 this.last.y = SVG._getY(parseFloat(y, 10));
784 this.path.push({type: "move", arg: arguments, pos: this.isAbsolute});
787 p.lineTo = function (x, y) {
788 var d = this.isAbsolute?"L":"l";
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: "line", arg: arguments, pos: this.isAbsolute});
799 p.cplineTo = function (x1, y1, w1) {
801 return this.lineTo(x1, y1);
804 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
805 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
806 var x = p._getX(Math.round(parseFloat(x1, 10) * 100) / 100);
807 var y = p._getY(Math.round(parseFloat(y1, 10) * 100) / 100);
808 var w = SVG._getW(Math.round(parseFloat(w1, 10) * 100) / 100);
809 var d = this.isAbsolute?"C":"c";
810 var attr = [this.last.x + w, this.last.y, x - w, y, x, y];
811 for (var i = 0, ii = attr.length; i < ii; i++) {
814 this.last.x = attr[4];
815 this.last.y = attr[5];
816 this.last.bx = attr[2];
817 this.last.by = attr[3];
818 var oldD = this[0].getAttribute("d") || "";
819 this[0].setAttribute("d", oldD + d);
820 this.path.push({type: "cpline", arg: arguments, pos: this.isAbsolute});
824 p.curveTo = function () {
826 p._getX = this.isAbsolute ? SVG._getX : SVG._getW;
827 p._getY = this.isAbsolute ? SVG._getY : SVG._getH;
828 if (arguments.length == 6) {
829 var d = this.isAbsolute?"C":"c";
830 for (var i = 0, ii = arguments.length; i < ii; i++) {
831 d += p[(i % 2 == 0) ? "_getX" : "_getY"](Math.round(parseFloat(arguments[i], 10) * 100) / 100) + " ";
833 this.last.x = p._getX((parseFloat(arguments[4], 10) * 100) / 100);
834 this.last.y = p._getY((parseFloat(arguments[5], 10) * 100) / 100);
835 this.last.bx = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
836 this.last.by = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
838 if (arguments.length == 4) {
839 var d = this.isAbsolute?"S":"s";
840 for (var i = 0, ii = arguments.length; i < ii; i++) {
841 d += p[i % 2 == 0 ? "_getX" : "_getY"]((parseFloat(arguments[i], 10) * 100) / 100) + " ";
844 this.last.x = p._getX((parseFloat(arguments[2], 10) * 100) / 100);
845 this.last.y = p._getY((parseFloat(arguments[3], 10) * 100) / 100);
846 this.last.bx = p._getX((parseFloat(arguments[0], 10) * 100) / 100);
847 this.last.by = p._getY((parseFloat(arguments[1], 10) * 100) / 100);
849 var oldD = this[0].getAttribute("d") || "";
850 this[0].setAttribute("d", oldD + d);
851 this.path.push({type: "curve", arg: arguments, pos: this.isAbsolute});
854 p.addRoundedCorner = function (r, dir) {
855 var R = .5522 * r, rollback = this.isAbsolute, o = this;
858 rollback = function () {
862 rollback = function () {};
868 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
871 o.curveTo(-R, 0, -r, r - R, -r, r);
878 o.curveTo(R, 0, r, -(r - R), r, -r);
881 o.curveTo(R, 0, r, r - R, r, r);
888 o.curveTo(0, -R, -(R - r), -r, r, -r);
891 o.curveTo(0, -R, R - r, -r, -r, -r);
898 o.curveTo(0, R, -(R - r), r, r, r);
901 o.curveTo(0, R, R - r, r, -r, r);
906 actions[dir[0]]()[dir[1]]();
910 p.andClose = function () {
911 var oldD = this[0].getAttribute("d") || "";
912 this[0].setAttribute("d", oldD + "Z ");
913 this.path.push({type: "end"});
916 if (typeof pathString == "string") {
917 pathString = pathString.replace(/([mzlhvcsqta])/ig, ",$1,").replace(/([^,])\-/ig, "$1,-");
918 path = pathString.split(",");
919 var i = 1, ii = path.length;
923 p.absolutely().moveTo(path[++i], path[++i]);
926 p.relatively().moveTo(path[++i], path[++i]);
929 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
932 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i], path[++i], path[++i]);
935 p.relatively().curveTo(path[++i], path[++i], path[++i], path[++i]);
938 p.absolutely().curveTo(path[++i], path[++i], path[++i], path[++i]);
941 p.absolutely().lineTo(path[++i], path[++i]);
944 p.relatively().lineTo(path[++i], path[++i]);
947 p.absolutely().lineTo(path[++i], 0);
950 p.relatively().lineTo(path[++i], 0);
953 p.absolutely().lineTo(0, path[++i]);
956 p.relatively().lineTo(0, path[++i]);
967 var addGrdientFill = function (o, gradient, SVG) {
968 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
969 el.id = "raphael-gradient-" + SVG.gradients++;
970 if (gradient.vector && gradient.vector.length) {
971 el.setAttribute("x1", gradient.vector[0]);
972 el.setAttribute("y1", gradient.vector[1]);
973 el.setAttribute("x2", gradient.vector[2]);
974 el.setAttribute("y2", gradient.vector[3]);
976 SVG.defs.appendChild(el);
977 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
978 var stop = document.createElementNS(SVG.svgns, "stop");
979 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
980 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
981 if (typeof gradient.dots[i].opacity != "undefined") {
982 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
984 el.appendChild(stop);
986 o.setAttribute("fill", "url(#" + el.id + ")");
988 var Element = function (node, svg) {
991 Rotation = {deg: 0, x: 0, y: 0},
995 this[0].attrs = this[0].attrs || {};
996 this.transformations = [];
997 this.rotate = function (deg) {
998 var bbox = this.getBBox();
999 this.transformations.push("rotate(" + deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
1000 this[0].setAttribute("transform", this.transformations.join(" "));
1003 this.translate = function (x, y) {
1004 this.transformations.push("translate(" + x + "," + y + ")");
1005 this[0].setAttribute("transform", this.transformations.join(" "));
1008 this.scale = function (x, y) {
1010 if (x != 0 && !(x == 1 && y == 1)) {
1011 var bbox = this.getBBox(),
1012 dx = bbox.x * (1 - x) + (bbox.width / 2 - bbox.width * x / 2),
1013 dy = bbox.y * (1 - y) + (bbox.height / 2 - bbox.height * y / 2);
1014 this.transformations.push(new Matrix(x, 0, 0, y, dx, dy));
1015 this[0].setAttribute("transform", this.transformations.join(" "));
1019 this.matrix = function (xx, xy, yx, yy, dx, dy) {
1020 this.transformations.push(new Matrix(xx, xy, yx, yy, dx, dy));
1021 this[0].setAttribute("transform", this.transformations.join(" "));
1024 this.remove = function () {
1025 this[0].parentNode.removeChild(this[0]);
1027 this.getBBox = function () {
1028 return this[0].getBBox();
1030 this.attr = function () {
1031 if (arguments.length == 1 && typeof arguments[0] == "string") {
1032 return this[0].attrs[arguments[0]];
1034 if (arguments.length == 1 && arguments[0] instanceof Array) {
1036 for (var j in arguments[0]) {
1037 values[arguments[0][j]] = this[0].attrs[arguments[0][j]];
1041 if (arguments.length == 2) {
1042 var att = arguments[0],
1043 value = arguments[1];
1045 this[0].attrs[att] = value;
1050 this[0].setAttribute(att, svg._getX(value));
1055 this[0].setAttribute(att, svg._getY(value));
1058 this[0].setAttribute(att, svg._getW(value));
1061 this[0].setAttribute(att, svg._getH(value));
1064 addGrdientFill(this[0], params.gradient, svg);
1066 case "stroke-dasharray":
1067 this[0].setAttribute(att, value.replace(" ", ","));
1070 var cssrule = att.replace(/(\-.)/g, function (w) {
1071 return w.substring(1).toUpperCase();
1073 this[0].style[cssrule] = value;
1074 // Need following line for Firefox
1075 this[0].setAttribute(att, value);
1077 } else if (arguments.length = 1 && typeof arguments[0] == "object") {
1078 var params = arguments[0];
1080 for (var attr in params) {
1081 this[0].attrs[attr] = params[attr];
1082 if (attr == "stroke-dasharray") {
1083 this[0].setAttribute(attr, params[attr].replace(" ", ","));
1085 var cssrule = attr.replace(/(\-.)/g, function (w) {
1086 return w.substring(1).toUpperCase();
1088 this[0].style[cssrule] = params[attr];
1089 // Need following line for Firefox
1090 this[0].setAttribute(attr, params[attr]);
1094 if (params.gradient) {
1095 this[0].attrs.gradient = params.gradient;
1096 addGrdientFill(this[0], params.gradient, svg);
1101 this.toFront = function () {
1102 this[0].parentNode.appendChild(this[0]);
1105 var theCircle = function (svg, x, y, r) {
1106 var el = document.createElementNS(svg.svgns, "circle");
1107 el.setAttribute("cx", svg._getX(x));
1108 el.setAttribute("cy", svg._getY(y));
1109 el.setAttribute("r", r);
1110 el.setAttribute("fill", "none");
1111 el.setAttribute("stroke", "#000");
1112 el.attrs = el.attrs || {};
1116 el.attrs.stroke = "#000";
1118 svg.canvas.appendChild(el);
1120 var res = new Element(el, svg);
1121 res.type = "circle";
1124 var theRect = function (svg, x, y, w, h, r) {
1125 var el = document.createElementNS(svg.svgns, "rect");
1126 el.setAttribute("x", svg._getX(x));
1127 el.setAttribute("y", svg._getY(y));
1128 el.setAttribute("width", svg._getW(w));
1129 el.setAttribute("height", svg._getH(h));
1130 el.attrs = el.attrs || {};
1134 el.attrs.height = h;
1136 el.setAttribute("rx", r);
1137 el.setAttribute("ry", r);
1138 el.attrs.rx = el.attrs.ry = r;
1140 el.setAttribute("fill", "none");
1141 el.setAttribute("stroke", "#000");
1142 el.attrs.stroke = "#000";
1144 svg.canvas.appendChild(el);
1146 var res = new Element(el, svg);
1150 var theEllipse = function (svg, x, y, rx, ry) {
1151 var el = document.createElementNS(svg.svgns, "ellipse");
1152 el.setAttribute("cx", svg._getX(x));
1153 el.setAttribute("cy", svg._getY(y));
1154 el.setAttribute("rx", svg._getW(rx));
1155 el.setAttribute("ry", svg._getH(ry));
1156 el.setAttribute("fill", "none");
1157 el.setAttribute("stroke", "#000");
1158 el.attrs = el.attrs || {};
1163 el.attrs.stroke = "#000";
1165 svg.canvas.appendChild(el);
1167 var res = new Element(el, svg);
1168 res.type = "ellipse";
1171 var theImage = function (svg, src, x, y, w, h) {
1172 var el = document.createElementNS(svg.svgns, "image");
1173 el.setAttribute("x", svg._getX(x));
1174 el.setAttribute("y", svg._getY(y));
1175 el.setAttribute("width", svg._getW(w));
1176 el.setAttribute("height", svg._getH(h));
1177 el.setAttributeNS(svg.xlink, "href", src);
1179 svg.canvas.appendChild(el);
1181 var res = new Element(el, svg);
1185 var theText = function (svg, x, y, text) {
1186 var el = document.createElementNS(svg.svgns, "text");
1187 el.setAttribute("x", x);
1188 el.setAttribute("y", y);
1189 el.setAttribute("text-anchor", "middle");
1190 el.setAttribute("fill", "#000");
1191 el.attrs = el.attrs || {};
1194 el.attrs.fill = "#000";
1196 el.appendChild(document.createTextNode(text));
1199 svg.canvas.appendChild(el);
1201 var res = new Element(el, svg);
1205 var theGroup = function (svg) {
1206 var el = document.createElementNS(svg.svgns, "g");
1208 svg.canvas.appendChild(el);
1210 var i = new Element(el, svg);
1211 for (var f in svg) {
1212 if (f[0] != "_" && typeof svg[f] == "function") {
1213 i[f] = (function (f) {
1214 return function () {
1215 var e = svg[f].apply(svg, arguments);
1216 el.appendChild(e[0]);
1225 r._create = function () {
1226 // container, width, height
1227 // x, y, width, height
1228 if (typeof arguments[0] == "string") {
1229 var container = document.getElementById(arguments[0]);
1230 var width = arguments[1];
1231 var height = arguments[2];
1233 if (typeof arguments[0] == "object") {
1234 var container = arguments[0];
1235 var width = arguments[1];
1236 var height = arguments[2];
1238 if (typeof arguments[0] == "number") {
1242 width = arguments[2],
1243 height = arguments[3];
1246 throw new Error("SVG container not found.");
1248 C.canvas = document.createElementNS(C.svgns, "svg");
1249 C.canvas.setAttribute("width", width || 320);
1250 C.width = width || 320;
1251 C.canvas.setAttribute("height", height || 200);
1252 C.height = height || 200;
1253 if (container == 1) {
1254 document.body.appendChild(C.canvas);
1255 C.canvas.style.position = "absolute";
1256 C.canvas.style.left = x + "px";
1257 C.canvas.style.top = y + "px";
1259 if (container.firstChild) {
1260 container.insertBefore(C.canvas, container.firstChild);
1262 container.appendChild(C.canvas);
1267 clear: function () {
1268 while (this.canvas.firstChild) {
1269 this.canvas.removeChild(this.canvas.firstChild);
1271 this.defs = document.createElementNS(C.svgns, "defs");
1273 this.canvas.appendChild(this.defs);
1276 for (var prop in C) {
1277 if (prop != "create") {
1278 container[prop] = C[prop];
1284 C.svgns = "http://www.w3.org/2000/svg";
1285 C.xlink = "http://www.w3.org/1999/xlink";
1287 if (r.vml || r.svg) {
1288 C.circle = function (x, y, r) {
1289 return theCircle(this, x, y, r);
1291 C.rect = function (x, y, w, h, r) {
1292 return theRect(this, x, y, w, h, r);
1294 C.ellipse = function (x, y, rx, ry) {
1295 return theEllipse(this, x, y, rx, ry);
1297 C.path = function (params, pathString) {
1298 return thePath(params, pathString, this);
1300 C.image = function (src, x, y, w, h) {
1301 return theImage(this, src, x, y, w, h);
1303 C.text = function (x, y, text) {
1304 return theText(this, x, y, text);
1306 C.group = function () {
1307 return theGroup(this);
1309 C.linerect = function (x, y, w, h, r) {
1310 if (r && parseInt(r, 10)) {
1311 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();
1313 return this.path({stroke: "#000"}).moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).andClose();
1315 C.drawGrid = function (x, y, w, h, wv, hv, color) {
1316 color = color || "#000";
1317 var res = this.group();
1318 var params = {stroke: color, "stroke-width": "1px", "stroke-opacity": .3};
1319 res.rect(x, y, w, h).attr(params);
1320 for (var i = 1; i < hv; i++) {
1321 var p = res.path(params);
1322 p.moveTo(x, y + i * Math.round(h / hv)).lineTo(x + w, y + i * Math.round(h / hv));
1324 for (var i = 1; i < wv; i++) {
1325 res.path(params).moveTo(x + i * Math.round(w / wv), y).lineTo(x + i * Math.round(w / wv), y + h);
1329 C.setGrid = function (xmin, ymin, xmax, ymax, w, h) {
1330 var xc = (xmax - xmin) / w;
1331 var yc = (ymax - ymin) / h;
1332 this._getX = function (x) {
1333 return xmin + x * xc;
1335 this._getY = function (y) {
1336 return ymin + y * yc;
1338 this._getW = function (w) {
1341 this._getH = function (h) {
1345 C.clearGrid = function () {
1346 this._getX = this._getY = this._getW = this._getH = function (x) { return x; };
1348 C.safari = function () {
1349 if (this.type == "SVG") {
1350 var rect = C.rect(0, 0, C.width, C.height).attr("stroke-width", 0);
1351 setTimeout(function () {rect.remove();}, 0);
1354 Raphael = function () {
1355 return r._create.apply(r, arguments);
1357 return r._create.apply(r, args);
1361 })(arguments.callee, arguments);
1365 Raphael.type = (!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2) && !(window.CanvasRenderingContext2D)) ? "VML" : "SVG";
1366 Raphael.vml = !(Raphael.svg = (Raphael.type == "SVG"));
1367 if (!(window.SVGPreserveAspectRatio && window.SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN == 2) && window.CanvasRenderingContext2D) {
1368 Raphael.type = "Canvas only";
1369 Raphael.vml = Raphael.svg = false;
1371 Raphael.toString = function () {
1372 return "You browser supports " + this.type;