2 * Raphael 0.7 - JavaScript Vector Library
4 * Copyright (c) 2008 – 2009 Dmitry Baranovskiy (http://raphaeljs.com)
5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
8 return Raphael._create.apply(Raphael, arguments);
14 R.type = (window.SVGAngle ? "SVG" : "VML");
15 R.svg = !(R.vml = R.type == "VML");
19 var availableAttrs = {cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '16px "Arial"', "font-family": '"Arial"', "font-size": "16", gradient: 0, height: 0, opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, translation: "0 0", width: 0, x: 0, y: 0},
20 availableAnimAttrs = {cx: "number", cy: "number", fill: "colour", "fill-opacity": "number", "font-size": "number", height: "number", opacity: "number", path: "path", r: "number", rotation: "number", rx: "number", ry: "number", scale: "csv", stroke: "colour", "stroke-opacity": "number", "stroke-width": "number", translation: "csv", width: "number", x: "number", y: "number"};
22 R.toString = function () {
23 return "Your browser " + (this.vml ? "doesn't ": "") + "support" + (this.svg ? "s": "") +
24 " SVG.\nYou are running " + unescape("Rapha%EBl%20") + this.version;
27 R.hsb2rgb = function (hue, saturation, brightness) {
28 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
36 if (brightness == 0) {
37 return {r: 0, g: 0, b: 0, hex: "#000"};
39 var i = Math.floor(hue * 6),
41 p = brightness * (1 - saturation),
42 q = brightness * (1 - (saturation * f)),
43 t = brightness * (1 - (saturation * (1 - f)));
45 function () {red = brightness; green = t; blue = p;},
46 function () {red = q; green = brightness; blue = p;},
47 function () {red = p; green = brightness; blue = t;},
48 function () {red = p; green = q; blue = brightness;},
49 function () {red = t; green = p; blue = brightness;},
50 function () {red = brightness; green = p; blue = q;},
51 function () {red = brightness; green = t; blue = p;}
54 var rgb = {r: red, g: green, b: blue};
58 var r = Math.round(red).toString(16);
62 var g = Math.round(green).toString(16);
66 var b = Math.round(blue).toString(16);
70 rgb.hex = "#" + r + g + b;
73 R.rgb2hsb = function (red, green, blue) {
74 if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
79 if (typeof red == "string" && red.charAt(0) == "#") {
80 if (red.length == 4) {
81 blue = parseInt(red.substring(3), 16);
82 green = parseInt(red.substring(2, 3), 16);
83 red = parseInt(red.substring(1, 2), 16);
85 blue = parseInt(red.substring(5), 16);
86 green = parseInt(red.substring(3, 5), 16);
87 red = parseInt(red.substring(1, 3), 16);
90 if (red > 1 || green > 1 || blue > 1) {
95 var max = Math.max(red, green, blue),
96 min = Math.min(red, green, blue),
101 return {h: 0, s: 0, b: max};
103 var delta = (max - min);
104 saturation = delta / max;
106 hue = (green - blue) / delta;
107 } else if (green == max) {
108 hue = 2 + ((blue - red) / delta);
110 hue = 4 + ((red - green) / delta);
120 return {h: hue, s: saturation, b: brightness};
122 R.getRGB = function (colour) {
123 var red, green, blue,
124 rgb = colour.match(/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*(\d+,\s*\d+,\s*\d+)\s*\)|rgb\(\s*(\d+%,\s*\d+%,\s*\d+%)\s*\)|hsb\(\s*(\d+,\s*\d+,\s*\d+)\s*\)|hsb\(\s*(\d+%,\s*\d+%,\s*\d+%)\s*\))\s*$/i);
127 blue = parseInt(rgb[2].substring(5), 16);
128 green = parseInt(rgb[2].substring(3, 5), 16);
129 red = parseInt(rgb[2].substring(1, 3), 16);
132 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
133 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
134 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
137 rgb = rgb[4].split(/\s*,\s*/);
138 red = parseInt(rgb[0], 10);
139 green = parseInt(rgb[1], 10);
140 blue = parseInt(rgb[2], 10);
143 rgb = rgb[5].split(/\s*,\s*/);
144 red = parseInt(rgb[0], 10) * 2.55;
145 green = parseInt(rgb[1], 10) * 2.55;
146 blue = parseInt(rgb[2], 10) * 2.55;
149 rgb = rgb[6].split(/\s*,\s*/);
150 red = parseInt(rgb[0], 10);
151 green = parseInt(rgb[1], 10);
152 blue = parseInt(rgb[2], 10);
153 return this.hsb2rgb(red, green, blue);
156 rgb = rgb[7].split(/\s*,\s*/);
157 red = parseInt(rgb[0], 10) * 2.55;
158 green = parseInt(rgb[1], 10) * 2.55;
159 blue = parseInt(rgb[2], 10) * 2.55;
160 return this.hsb2rgb(red, green, blue);
162 var rgb = {r: red, g: green, b: blue};
163 var r = Math.round(red).toString(16);
164 (r.length == 1) && (r = "0" + r);
165 var g = Math.round(green).toString(16);
166 (g.length == 1) && (g = "0" + g);
167 var b = Math.round(blue).toString(16);
168 (b.length == 1) && (b = "0" + b);
169 rgb.hex = "#" + r + g + b;
173 R.getColor = function (value) {
174 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
175 var rgb = this.hsb2rgb(start.h, start.s, start.b);
181 arguments.callee.start = {h: 0, s: 1, b: start.b};
186 R.getColor.reset = function () {
187 this.start = undefined;
189 R.parsePathString = function (pathString) {
190 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
192 toString = function () {
194 for (var i = 0, ii = this.length; i < ii; i++) {
195 res += this[i][0] + this[i].join(",").substring(2);
199 if (pathString.toString.toString() == toString.toString()) {
202 pathString.replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*\s*,?\s*)+)/ig, function (a, b, c) {
203 var params = [], name = b.toLowerCase();
204 c.replace(/(-?\d*\.?\d*)\s*,?\s*/ig, function (a, b) {
205 b && params.push(+b);
207 while (params.length >= paramCounts[name]) {
208 data.push([b].concat(params.splice(0, paramCounts[name])));
209 if (!paramCounts[name]) {
214 data.toString = toString;
217 R.pathDimensions = function (path) {
218 var pathArray = path;
219 if (typeof path == "string") {
220 pathArray = this.parsePathString(path);
222 pathArray = this.pathToAbsolute(pathArray);
223 var x = [], y = [], length = 0;
224 for (var i = 0, ii = pathArray.length; i < ii; i++) {
225 switch (pathArray[i][0]) {
229 x.push(pathArray[i][pathArray[i].length - 2]);
230 y.push(pathArray[i][pathArray[i].length - 1]);
233 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
235 x.push(pathArray[i][j]);
237 y.push(pathArray[i][j]);
242 var minx = Math.min.apply(Math, x),
243 miny = Math.min.apply(Math, y);
247 width: Math.max.apply(Math, x) - minx,
248 height: Math.max.apply(Math, y) - miny,
253 R.pathToRelative = function (pathArray) {
255 if (typeof pathArray == "string") {
256 pathArray = this.parsePathString(pathArray);
258 var x = 0, y = 0, start = 0;
259 if (pathArray[0][0] == "M") {
263 res.push(pathArray[0]);
265 for (var i = start, ii = pathArray.length; i < ii; i++) {
267 if (pathArray[i][0] != pathArray[i][0].toLowerCase()) {
268 res[i][0] = pathArray[i][0].toLowerCase();
271 res[i][1] = pathArray[i][1];
272 res[i][2] = pathArray[i][2];
274 res[i][4] = pathArray[i][4];
275 res[i][5] = pathArray[i][5];
276 res[i][6] = +(pathArray[i][6] - x).toFixed(3);
277 res[i][7] = +(pathArray[i][7] - y).toFixed(3);
280 res[i][1] = +(pathArray[i][1] - y).toFixed(3);
283 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
284 res[i][j] = +(pathArray[i][j] - ((j % 2) ? x : y)).toFixed(3);
288 res[i] = pathArray[i];
294 x += res[i][res[i].length - 1];
297 y += res[i][res[i].length - 1];
300 x += res[i][res[i].length - 2];
301 y += res[i][res[i].length - 1];
304 res.toString = pathArray.toString;
307 R.pathToAbsolute = function (pathArray) {
309 if (typeof pathArray == "string") {
310 pathArray = this.parsePathString(pathArray);
312 var x = 0, y = 0, start = 0;
313 if (pathArray[0][0] == "M") {
314 x = +pathArray[0][1];
315 y = +pathArray[0][2];
317 res[0] = pathArray[0];
319 for (var i = start, ii = pathArray.length; i < ii; i++) {
321 if (pathArray[i][0] != pathArray[i][0].toUpperCase()) {
322 res[i][0] = pathArray[i][0].toUpperCase();
325 res[i][1] = pathArray[i][1];
326 res[i][2] = pathArray[i][2];
328 res[i][4] = pathArray[i][4];
329 res[i][5] = pathArray[i][5];
330 res[i][6] = +(pathArray[i][6] + x).toFixed(3);
331 res[i][7] = +(pathArray[i][7] + y).toFixed(3);
334 res[i][1] = +pathArray[i][1] + y;
337 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
338 res[i][j] = +pathArray[i][j] + ((j % 2) ? x : y);
342 res[i] = pathArray[i];
354 x = res[i][res[i].length - 2];
355 y = res[i][res[i].length - 1];
358 res.toString = pathArray.toString;
361 R.pathEqualiser = function (path1, path2) {
362 var data = [this.pathToAbsolute(this.parsePathString(path1)), this.pathToAbsolute(this.parsePathString(path2))],
363 attrs = [{x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0}, {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0}],
364 processPath = function (path, d) {
374 var nx = d.x + (d.x - (d.bx || d.x));
375 var ny = d.y + (d.y - (d.by || d.y));
376 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
379 var nx = d.x + (d.x - (d.bx || d.x));
380 var ny = d.y + (d.y - (d.by || d.y));
381 path = ["Q", nx, ny, path[1], path[2]];
384 path = ["L", path[1], d.y];
387 path = ["L", d.x, path[1]];
390 path = ["L", d.X, d.Y];
395 edgeCases = function (a, b, i) {
396 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
397 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
398 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
399 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
400 attrs[a].x = data[a][i][data[a][i].length - 2];
401 attrs[a].y = data[a][i][data[a][i].length - 1];
403 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
404 data[a][i] = ["C", attrs[a].x, attrs[a].y, data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
405 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
406 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
407 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
408 var x = data[b][i][data[b][i].length - 2];
409 var y = data[b][i][data[b][i].length - 1];
410 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
411 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
413 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
414 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
415 attrs[b].x = data[b][i][data[b][i].length - 2];
416 attrs[b].y = data[b][i][data[b][i].length - 1];
418 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
419 var x = data[b][i][data[b][i].length - 2];
420 var y = data[b][i][data[b][i].length - 1];
421 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
422 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
424 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
425 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
426 attrs[b].x = data[b][i][data[b][i].length - 2];
427 attrs[b].y = data[b][i][data[b][i].length - 1];
429 } else if (data[a][i][0] == "U") {
430 data[a][i][0] = data[b][i][0];
431 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
432 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
437 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
438 data[0][i] = processPath(data[0][i], attrs[0]);
439 data[1][i] = processPath(data[1][i], attrs[1]);
440 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
443 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
444 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
445 attrs[0].x = data[0][i][data[0][i].length - 2];
446 attrs[0].y = data[0][i][data[0][i].length - 1];
447 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
448 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
449 attrs[1].x = data[1][i][data[1][i].length - 2];
450 attrs[1].y = data[1][i][data[1][i].length - 1];
457 var thePath = function (params, pathString, SVG) {
458 var el = document.createElementNS(SVG.svgns, "path");
459 el.setAttribute("fill", "none");
461 SVG.canvas.appendChild(el);
463 var p = new Element(el, SVG);
466 p.last = {x: 0, y: 0, bx: 0, by: 0};
467 p.absolutely = function () {
468 this.isAbsolute = true;
471 p.relatively = function () {
472 this.isAbsolute = false;
475 p.moveTo = function (x, y) {
476 var d = this.isAbsolute?"M":"m";
477 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
478 var oldD = this[0].getAttribute("d") || "";
479 (oldD == "M0,0") && (oldD = "");
480 this[0].setAttribute("d", oldD + d);
481 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
482 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
483 this.attrs.path = oldD + d;
486 p.lineTo = function (x, y) {
487 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
488 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
489 var d = this.isAbsolute?"L":"l";
490 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
491 var oldD = this[0].getAttribute("d") || "";
492 this[0].setAttribute("d", oldD + d);
493 this.attrs.path = oldD + d;
496 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
497 var d = this.isAbsolute ? "A" : "a";
498 d += [parseFloat(rx, 10).toFixed(3), parseFloat(ry, 10).toFixed(3), 0, large_arc_flag, sweep_flag, parseFloat(x, 10).toFixed(3), parseFloat(y, 10).toFixed(3)].join(" ");
499 var oldD = this[0].getAttribute("d") || "";
500 this[0].setAttribute("d", oldD + d);
501 this.last.x = parseFloat(x, 10);
502 this.last.y = parseFloat(y, 10);
503 this.attrs.path = oldD + d;
506 p.cplineTo = function (x1, y1, w1) {
508 return this.lineTo(x1, y1);
511 var x = parseFloat(x1, 10);
512 var y = parseFloat(y1, 10);
513 var w = parseFloat(w1, 10);
514 var d = this.isAbsolute?"C":"c";
515 var attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
516 for (var i = 0, ii = attr.length; i < ii; i++) {
517 d += attr[i].toFixed(3) + " ";
519 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
520 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
521 this.last.bx = attr[2];
522 this.last.by = attr[3];
523 var oldD = this[0].getAttribute("d") || "";
524 this[0].setAttribute("d", oldD + d);
525 this.attrs.path = oldD + d;
529 p.curveTo = function () {
531 command = [0, 1, 2, 3, "s", 5, "c"];
533 var d = command[arguments.length];
534 if (this.isAbsolute) {
537 for (var i = 0, ii = arguments.length; i < ii; i++) {
538 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
540 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
541 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
542 this.last.bx = parseFloat(arguments[arguments.length - 4], 10);
543 this.last.by = parseFloat(arguments[arguments.length - 3], 10);
544 var oldD = this.node.getAttribute("d") || "";
545 this.node.setAttribute("d", oldD + d);
546 this.attrs.path = oldD + d;
549 p.qcurveTo = function () {
551 command = [0, 1, "t", 3, "q"];
553 var d = command[arguments.length];
554 if (this.isAbsolute) {
557 for (var i = 0, ii = arguments.length; i < ii; i++) {
558 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
560 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
561 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
562 if (arguments.length != 2) {
563 this.last.qx = parseFloat(arguments[arguments.length - 4], 10);
564 this.last.qy = parseFloat(arguments[arguments.length - 3], 10);
566 var oldD = this.node.getAttribute("d") || "";
567 this.node.setAttribute("d", oldD + d);
568 this.attrs.path = oldD + d;
571 p.addRoundedCorner = function (r, dir) {
572 var R = .5522 * r, rollback = this.isAbsolute, o = this;
575 rollback = function () {
579 rollback = function () {};
585 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
588 o.curveTo(-R, 0, -r, r - R, -r, r);
595 o.curveTo(R, 0, r, -(r - R), r, -r);
598 o.curveTo(R, 0, r, r - R, r, r);
605 o.curveTo(0, -R, -(R - r), -r, r, -r);
608 o.curveTo(0, -R, R - r, -r, -r, -r);
615 o.curveTo(0, R, -(R - r), r, r, r);
618 o.curveTo(0, R, R - r, r, -r, r);
623 actions[dir[0]]()[dir[1]]();
627 p.andClose = function () {
628 var oldD = this[0].getAttribute("d") || "";
629 this[0].setAttribute("d", oldD + "Z ");
630 this.attrs.path = oldD + "Z ";
634 p.attrs.path = "" + pathString;
636 paper.pathfinder(p, p.attrs.path);
639 setFillAndStroke(p, params);
643 var addGrdientFill = function (o, gradient, SVG) {
644 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
645 el.id = "raphael-gradient-" + Raphael.idGenerator++;
646 if (gradient.vector && gradient.vector.length) {
647 el.setAttribute("x1", gradient.vector[0]);
648 el.setAttribute("y1", gradient.vector[1]);
649 el.setAttribute("x2", gradient.vector[2]);
650 el.setAttribute("y2", gradient.vector[3]);
652 SVG.defs.appendChild(el);
653 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
654 var stop = document.createElementNS(SVG.svgns, "stop");
655 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
656 stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
657 if (typeof gradient.dots[i].opacity != "undefined") {
658 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
660 el.appendChild(stop);
662 o.setAttribute("fill", "url(#" + el.id + ")");
664 var updatePosition = function (o) {
666 var bbox = o.node.getBBox();
667 o.pattern.setAttribute("patternTransform", "translate(" + [bbox.x, bbox.y].join(",") + ")");
670 var setFillAndStroke = function (o, params) {
675 "-..": [3, 1, 1, 1, 1, 1],
681 "--..": [8, 3, 1, 3, 1, 3]
683 addDashes = function (o, value) {
684 value = dasharray[value.toString().toLowerCase()];
686 var width = o.attrs["stroke-width"] || "1",
687 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
689 for (var i = 0, ii = value.length; i < ii; i++) {
690 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
692 value = dashes.join(",");
693 o.node.setAttribute("stroke-dasharray", value);
696 for (var att in params) {
697 var value = params[att];
698 o.attrs[att] = value;
701 if (o.type == "path") {
702 o.node.setAttribute("d", "M0,0");
703 paper.pathfinder(o, value);
708 o.node.setAttribute(att, value);
714 o.node.setAttribute(att, value);
718 o.node.setAttribute(att, value);
721 o.node.setAttribute(att, value);
724 addGrdientFill(o.node, value, o.svg);
727 o.node.style.strokeWidth = value;
728 // Need following line for Firefox
729 o.node.setAttribute(att, value);
730 if (o.attrs["stroke-dasharray"]) {
731 addDashes(o, o.attrs["stroke-dasharray"]);
734 case "stroke-dasharray":
738 if (o.type == "text") {
739 o.node.childNodes.length && o.node.removeChild(o.node.firstChild);
740 o.node.appendChild(document.createTextNode(value));
744 o.rotate(value, true);
747 var xy = value.split(/[, ]+/);
748 o.translate(xy[0], xy[1]);
751 var xy = value.split(/[, ]+/);
752 o.scale(xy[0], xy[1]);
755 var isURL = value.match(/^url\(([^\)]+)\)$/i);
757 var el = document.createElementNS(o.svg.svgns, "pattern");
758 var ig = document.createElementNS(o.svg.svgns, "image");
759 el.id = "raphael-pattern-" + Raphael.idGenerator++;
760 el.setAttribute("x", 0);
761 el.setAttribute("y", 0);
762 el.setAttribute("patternUnits", "userSpaceOnUse");
763 ig.setAttribute("x", 0);
764 ig.setAttribute("y", 0);
765 ig.setAttributeNS(o.svg.xlink, "href", isURL[1]);
768 var img = document.createElement("img");
769 img.style.position = "absolute";
770 img.style.top = "-9999em";
771 img.style.left = "-9999em";
772 img.onload = function () {
773 el.setAttribute("width", this.offsetWidth);
774 el.setAttribute("height", this.offsetHeight);
775 ig.setAttribute("width", this.offsetWidth);
776 ig.setAttribute("height", this.offsetHeight);
777 document.body.removeChild(this);
780 document.body.appendChild(img);
782 o.svg.defs.appendChild(el);
783 o.node.style.fill = "url(#" + el.id + ")";
784 o.node.setAttribute("fill", "url(#" + el.id + ")");
790 var cssrule = att.replace(/(\-.)/g, function (w) {
791 return w.substring(1).toUpperCase();
793 o.node.style[cssrule] = value;
794 // Need following line for Firefox
795 o.node.setAttribute(att, value);
800 var Element = function (node, svg) {
806 this.attrs = this.attrs || {};
807 this.transformations = []; // rotate, translate, scale
811 rt: {deg: 0, x: 0, y: 0},
816 Element.prototype.translate = function (x, y) {
817 if (x == undefined && y == undefined) {
818 return {x: this._.tx, y: this._.ty};
825 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
830 this.attr({x: this.attrs.x + x, y: this.attrs.y + y});
833 var path = Raphael.pathToRelative(this.attrs.path);
836 this.attr({path: path.join(" ")});
841 Element.prototype.rotate = function (deg, isAbsolute) {
842 if (deg == undefined) {
843 return this._.rt.deg;
845 var bbox = this.getBBox();
849 this._.rt.deg += deg;
853 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
855 this.transformations[0] = "";
857 this.node.setAttribute("transform", this.transformations.join(" "));
860 Element.prototype.hide = function () {
861 this.node.style.display = "none";
864 Element.prototype.show = function () {
865 this.node.style.display = "block";
868 Element.prototype.remove = function () {
869 this.node.parentNode.removeChild(this.node);
871 Element.prototype.getBBox = function () {
872 return this.node.getBBox();
874 Element.prototype.attr = function () {
875 if (arguments.length == 1 && typeof arguments[0] == "string") {
876 if (arguments[0] == "translation") {
877 return this.translate();
879 return this.attrs[arguments[0]];
881 if (arguments.length == 1 && arguments[0] instanceof Array) {
883 for (var j in arguments[0]) {
884 values[arguments[0][j]] = this.attrs[arguments[0][j]];
888 if (arguments.length == 2) {
890 params[arguments[0]] = arguments[1];
891 setFillAndStroke(this, params);
892 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
893 setFillAndStroke(this, arguments[0]);
897 Element.prototype.toFront = function () {
898 this.node.parentNode.appendChild(this.node);
901 Element.prototype.toBack = function () {
902 if (this.node.parentNode.firstChild != this.node) {
903 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
907 Element.prototype.insertAfter = function (element) {
908 if (element.node.nextSibling) {
909 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
911 element.node.parentNode.appendChild(this.node);
915 Element.prototype.insertBefore = function (element) {
916 element.node.parentNode.insertBefore(this.node, element.node);
919 var theCircle = function (svg, x, y, r) {
920 var el = document.createElementNS(svg.svgns, "circle");
921 el.setAttribute("cx", x);
922 el.setAttribute("cy", y);
923 el.setAttribute("r", r);
924 el.setAttribute("fill", "none");
925 el.setAttribute("stroke", "#000");
927 svg.canvas.appendChild(el);
929 var res = new Element(el, svg);
930 res.attrs = res.attrs || {};
934 res.attrs.stroke = "#000";
938 var theRect = function (svg, x, y, w, h, r) {
939 var el = document.createElementNS(svg.svgns, "rect");
940 el.setAttribute("x", x);
941 el.setAttribute("y", y);
942 el.setAttribute("width", w);
943 el.setAttribute("height", h);
945 el.setAttribute("rx", r);
946 el.setAttribute("ry", r);
948 el.setAttribute("fill", "none");
949 el.setAttribute("stroke", "#000");
951 svg.canvas.appendChild(el);
953 var res = new Element(el, svg);
954 res.attrs = res.attrs || {};
958 res.attrs.height = h;
959 res.attrs.stroke = "#000";
961 res.attrs.rx = res.attrs.ry = r;
966 var theEllipse = function (svg, x, y, rx, ry) {
967 var el = document.createElementNS(svg.svgns, "ellipse");
968 el.setAttribute("cx", x);
969 el.setAttribute("cy", y);
970 el.setAttribute("rx", rx);
971 el.setAttribute("ry", ry);
972 el.setAttribute("fill", "none");
973 el.setAttribute("stroke", "#000");
975 svg.canvas.appendChild(el);
977 var res = new Element(el, svg);
978 res.attrs = res.attrs || {};
983 res.attrs.stroke = "#000";
984 res.type = "ellipse";
987 var theImage = function (svg, src, x, y, w, h) {
988 var el = document.createElementNS(svg.svgns, "image");
989 el.setAttribute("x", x);
990 el.setAttribute("y", y);
991 el.setAttribute("width", w);
992 el.setAttribute("height", h);
993 el.setAttribute("preserveAspectRatio", "none");
994 el.setAttributeNS(svg.xlink, "href", src);
996 svg.canvas.appendChild(el);
998 var res = new Element(el, svg);
999 res.attrs = res.attrs || {};
1002 res.attrs.width = w;
1003 res.attrs.height = h;
1007 var theText = function (svg, x, y, text) {
1008 var el = document.createElementNS(svg.svgns, "text");
1009 el.setAttribute("x", x);
1010 el.setAttribute("y", y);
1011 el.setAttribute("text-anchor", "middle");
1013 el.appendChild(document.createTextNode(text));
1016 svg.canvas.appendChild(el);
1018 var res = new Element(el, svg);
1019 res.attrs = res.attrs || {};
1023 setFillAndStroke(res, {font: '10px "Arial"', stroke: "none", fill: "#000"});
1026 var theGroup = function (svg) {
1027 var el = document.createElementNS(svg.svgns, "g");
1029 svg.canvas.appendChild(el);
1031 var i = new Element(el, svg);
1032 for (var f in svg) {
1033 if (f[0] != "_" && typeof svg[f] == "function") {
1034 i[f] = (function (f) {
1035 return function () {
1036 var e = svg[f].apply(svg, arguments);
1037 el.appendChild(e[0]);
1046 R._create = function () {
1047 // container, width, height
1048 // x, y, width, height
1049 if (typeof arguments[0] == "string") {
1050 var container = document.getElementById(arguments[0]);
1051 var width = arguments[1];
1052 var height = arguments[2];
1054 if (typeof arguments[0] == "object") {
1055 var container = arguments[0];
1056 var width = arguments[1];
1057 var height = arguments[2];
1059 if (typeof arguments[0] == "number") {
1063 width = arguments[2],
1064 height = arguments[3];
1067 throw new Error("SVG container not found.");
1069 paper.canvas = document.createElementNS(paper.svgns, "svg");
1070 paper.canvas.setAttribute("width", width || 320);
1071 paper.width = width || 320;
1072 paper.canvas.setAttribute("height", height || 200);
1073 paper.height = height || 200;
1074 if (container == 1) {
1075 document.body.appendChild(paper.canvas);
1076 paper.canvas.style.position = "absolute";
1077 paper.canvas.style.left = x + "px";
1078 paper.canvas.style.top = y + "px";
1080 if (container.firstChild) {
1081 container.insertBefore(paper.canvas, container.firstChild);
1083 container.appendChild(paper.canvas);
1087 canvas: paper.canvas,
1088 clear: function () {
1089 while (this.canvas.firstChild) {
1090 this.canvas.removeChild(this.canvas.firstChild);
1092 this.defs = document.createElementNS(paper.svgns, "defs");
1093 this.canvas.appendChild(this.defs);
1096 for (var prop in paper) {
1097 if (prop != "create") {
1098 container[prop] = paper[prop];
1101 for (var prop in R.fn) {
1102 if (!container[prop]) {
1103 container[prop] = R.fn[prop];
1109 paper.remove = function () {
1110 this.canvas.parentNode.removeChild(this.canvas);
1112 paper.svgns = "http://www.w3.org/2000/svg";
1113 paper.xlink = "http://www.w3.org/1999/xlink";
1114 paper.safari = function () {
1115 if (navigator.vendor == "Apple Computer, Inc.") {
1116 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1117 setTimeout(function () {rect.remove();}, 0);
1124 thePath = function (params, pathString, VML) {
1125 var g = document.createElement("rvml:group"), gl = g.style;
1126 gl.position = "absolute";
1129 gl.width = VML.width + "px";
1130 gl.height = VML.height + "px";
1131 var el = document.createElement("rvml:shape"), ol = el.style;
1132 ol.width = VML.width + "px";
1133 ol.height = VML.height + "px";
1135 if (params["class"]) {
1136 el.className = params["class"];
1138 el.coordsize = this.coordsize;
1139 el.coordorigin = this.coordorigin;
1141 VML.canvas.appendChild(g);
1142 var p = new Element(el, g, VML);
1143 p.isAbsolute = true;
1146 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1148 p.absolutely = function () {
1149 this.isAbsolute = true;
1152 p.relatively = function () {
1153 this.isAbsolute = false;
1156 p.moveTo = function (x, y) {
1157 var d = this.isAbsolute?"m":"t";
1158 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
1159 this.node.path = this.Path += d;
1160 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
1161 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
1162 this.last.isAbsolute = this.isAbsolute;
1163 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1166 p.lineTo = function (x, y) {
1167 var d = this.isAbsolute?"l":"r";
1168 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
1169 this[0].path = this.Path += d;
1170 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
1171 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
1172 this.last.isAbsolute = this.isAbsolute;
1173 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1176 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1177 // for more information of where this math came from visit:
1178 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1179 x2 = (this.isAbsolute ? 0 : this.last.x) + x2;
1180 y2 = (this.isAbsolute ? 0 : this.last.y) + y2;
1181 var x1 = this.last.x,
1185 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1186 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1187 cx = k * rx * y / ry + (x1 + x2) / 2,
1188 cy = k * -ry * x / rx + (y1 + y2) / 2,
1189 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1190 left = Math.round(cx - rx),
1191 top = Math.round(cy - ry);
1192 d += [left, top, Math.round(left + rx * 2), Math.round(top + ry * 2), Math.round(x1), Math.round(y1), Math.round(parseFloat(x2, 10)), Math.round(parseFloat(y2, 10))].join(", ");
1193 this.node.path = this.Path += d;
1194 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2, 10);
1195 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2, 10);
1196 this.last.isAbsolute = this.isAbsolute;
1197 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1200 p.cplineTo = function (x1, y1, w1) {
1202 return this.lineTo(x1, y1);
1204 var x = Math.round(Math.round(parseFloat(x1, 10) * 100) / 100),
1205 y = Math.round(Math.round(parseFloat(y1, 10) * 100) / 100),
1206 w = Math.round(Math.round(parseFloat(w1, 10) * 100) / 100),
1207 d = this.isAbsolute ? "c" : "v",
1208 attr = [Math.round(this.last.x) + w, Math.round(this.last.y), x - w, y, x, y],
1209 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1210 d += attr.join(" ") + " ";
1211 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1212 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1213 this.last.bx = attr[2];
1214 this.last.by = attr[3];
1215 this.node.path = this.Path += d;
1216 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1220 p.curveTo = function () {
1221 var d = this.isAbsolute ? "c" : "v";
1222 if (arguments.length == 6) {
1223 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1224 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1225 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4], 10);
1226 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5], 10);
1227 d += [Math.round(parseFloat(arguments[0], 10)),
1228 Math.round(parseFloat(arguments[1], 10)),
1229 Math.round(parseFloat(arguments[2], 10)),
1230 Math.round(parseFloat(arguments[3], 10)),
1231 Math.round(parseFloat(arguments[4], 10)),
1232 Math.round(parseFloat(arguments[5], 10))].join(" ") + " ";
1233 this.last.isAbsolute = this.isAbsolute;
1234 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1236 if (arguments.length == 4) {
1237 var bx = this.last.x * 2 - this.last.bx;
1238 var by = this.last.y * 2 - this.last.by;
1239 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
1240 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
1241 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1242 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1243 d += [Math.round(bx), Math.round(by),
1244 Math.round(parseFloat(arguments[0], 10)),
1245 Math.round(parseFloat(arguments[1], 10)),
1246 Math.round(parseFloat(arguments[2], 10)),
1247 Math.round(parseFloat(arguments[3], 10))].join(" ") + " ";
1248 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1250 this.node.path = this.Path += d;
1253 p.qcurveTo = function () {
1255 if (arguments.length == 4) {
1256 this.last.qx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
1257 this.last.qy = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
1258 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1259 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1260 d += [Math.round(this.last.qx),
1261 Math.round(this.last.qy),
1262 Math.round(this.last.x),
1263 Math.round(this.last.y)].join(" ") + " ";
1264 this.last.isAbsolute = this.isAbsolute;
1265 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1267 if (arguments.length == 2) {
1268 this.last.qx = this.last.x * 2 - this.last.qx;
1269 this.last.qy = this.last.y * 2 - this.last.qy;
1270 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1271 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1272 d += [Math.round(this.last.qx),
1273 Math.round(this.last.qy),
1274 Math.round(this.last.x),
1275 Math.round(this.last.y)].join(" ") + " ";
1276 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1278 this.node.path = this.Path += d;
1279 this.path.push({type: "qcurve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
1282 p.addRoundedCorner = function (r, dir) {
1283 var R = .5522 * r, rollback = this.isAbsolute, o = this;
1286 rollback = function () {
1290 rollback = function () {};
1296 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
1299 o.curveTo(-R, 0, -r, r - R, -r, r);
1306 o.curveTo(R, 0, r, -(r - R), r, -r);
1309 o.curveTo(R, 0, r, r - R, r, r);
1316 o.curveTo(0, -R, -(R - r), -r, r, -r);
1319 o.curveTo(0, -R, R - r, -r, -r, -r);
1326 o.curveTo(0, R, -(R - r), r, r, r);
1329 o.curveTo(0, R, R - r, r, -r, r);
1334 actions[dir.charAt(0)]()[dir.charAt(1)]();
1338 p.andClose = function () {
1339 this.node.path = (this.Path += "x e");
1340 this.attrs.path += "z";
1346 paper.pathfinder(p, "" + pathString);
1349 setFillAndStroke(p, params);
1350 if (params.gradient) {
1351 addGrdientFill(p, params.gradient);
1355 var setFillAndStroke = function (o, params) {
1356 var s = o.node.style,
1358 o.attrs = o.attrs || {};
1359 for (var par in params) {
1360 o.attrs[par] = params[par];
1362 if (params.path && o.type == "path") {
1365 paper.pathfinder(o, params.path);
1367 if (params.rotation != null) {
1368 o.Group.style.rotation = params.rotation;
1370 if (params.translation) {
1371 var xy = params.translation.split(/[, ]+/);
1372 o.translate(xy[0], xy[1]);
1375 var xy = params.scale.split(/[, ]+/);
1376 o.scale(xy[0], xy[1]);
1378 if (o.type == "image" && params.opacity) {
1379 o.node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1380 o.node.style.filter = (o.node.filterMatrix || "") + (o.node.filterOpacity || "");
1382 params.font && (s.font = params.font);
1383 params["font-family"] && (s.fontFamily = params["font-family"]);
1384 params["font-size"] && (s.fontSize = params["font-size"]);
1385 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1386 params["font-style"] && (s.fontStyle = params["font-style"]);
1387 if (typeof params.opacity != "undefined" || typeof params["stroke-width"] != "undefined" || typeof params.fill != "undefined" || typeof params.stroke != "undefined") {
1388 o = o.shape || o.node;
1389 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || document.createElement("rvml:fill");
1390 if ("fill-opacity" in params || "opacity" in params) {
1391 fill.opacity = ((params["fill-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
1396 if (fill.on == undefined || params.fill == "none") {
1399 if (fill.on && params.fill) {
1400 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1402 fill.src = isURL[1];
1405 fill.color = params.fill;
1407 fill.type = "solid";
1410 o.appendChild(fill);
1411 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || document.createElement("rvml:stroke");
1412 if ((params.stroke && params.stroke != "none") || params["stroke-width"] || params["stroke-opacity"] || params["stroke-dasharray"]) {
1415 if (params.stroke == "none" || typeof stroke.on == "undefined") {
1418 if (stroke.on && params.stroke) {
1419 stroke.color = params.stroke;
1421 stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
1422 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1423 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1424 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1425 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"], 10) || 1) * 12 / 16);
1426 if (params["stroke-dasharray"]) {
1430 "-.": "shortdashdot",
1431 "-..": "shortdashdotdot",
1436 "--.": "longdashdot",
1437 "--..": "longdashdotdot"
1439 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1441 o.appendChild(stroke);
1443 if (res.type == "text") {
1444 var span = document.createElement("span"),
1446 res.attrs.font && (s.font = res.attrs.font);
1447 res.attrs["font-family"] && (s.fontFamily = res.attrs["font-family"]);
1448 res.attrs["font-size"] && (s.fontSize = res.attrs["font-size"]);
1449 res.attrs["font-weight"] && (s.fontWeight = res.attrs["font-weight"]);
1450 res.attrs["font-style"] && (s.fontStyle = res.attrs["font-style"]);
1451 res.node.parentNode.appendChild(span);
1452 span.innerText = res.node.string;
1453 res.W = res.attrs.w = span.offsetWidth;
1454 res.H = res.attrs.h = span.offsetHeight;
1455 res.X = res.attrs.x - Math.round(res.W / 2);
1456 res.Y = res.attrs.y - Math.round(res.H / 2);
1457 res.node.parentNode.removeChild(span);
1460 var getAngle = function (a, b, c, d) {
1461 var angle = Math.round(Math.atan((parseFloat(c, 10) - parseFloat(a, 10)) / (parseFloat(d, 10) - parseFloat(b, 10))) * 57.29) || 0;
1462 if (!angle && parseFloat(a, 10) < parseFloat(b, 10)) {
1471 var addGrdientFill = function (o, gradient) {
1472 o.attrs = o.attrs || {};
1473 o.attrs.gradient = gradient;
1474 o = o.shape || o[0];
1475 var fill = o.getElementsByTagName("fill");
1479 fill = document.createElement("rvml:fill");
1481 if (gradient.dots.length) {
1483 fill.method = "none";
1484 fill.type = (gradient.type.toLowerCase() == "linear") ? "gradient" : "gradientTitle";
1485 if (typeof gradient.dots[0].color != "undefined") {
1486 fill.color = gradient.dots[0].color || "#000";
1488 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1489 fill.color2 = gradient.dots[gradient.dots.length - 1].color || "#000";
1492 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1493 if (gradient.dots[i].offset) {
1494 colors.push(gradient.dots[i].offset + " " + gradient.dots[i].color);
1497 var fillOpacity = typeof gradient.dots[0].opacity == "undefined" ? 1 : gradient.dots[0].opacity;
1498 var fillOpacity2 = typeof gradient.dots[gradient.dots.length - 1].opacity == "undefined" ? 1 : gradient.dots[gradient.dots.length - 1].opacity;
1500 fill.colors.value = colors.join(",");
1501 fillOpacity2 += fillOpacity;
1502 fillOpacity = fillOpacity2 - fillOpacity;
1503 fillOpacity2 -= fillOpacity;
1505 fill.setAttribute("opacity", fillOpacity);
1506 fill.setAttribute("opacity2", fillOpacity2);
1507 if (gradient.vector) {
1508 fill.angle = getAngle.apply(null, gradient.vector);
1510 if (gradient.type.toLowerCase() == "radial") {
1511 fill.focus = "100%";
1512 fill.focusposition = "0.5 0.5";
1516 var Element = function (node, group, vml) {
1536 Element.prototype.rotate = function (deg, isAbsolute) {
1537 if (deg == undefined) {
1545 this.Group.style.rotation = this._.rt;
1548 Element.prototype.setBox = function (params) {
1549 var gs = this.Group.style,
1550 os = (this.shape && this.shape.style) || this.node.style;
1551 for (var i in params) {
1552 this.attrs[i] = params[i];
1554 var attr = this.attrs, x, y, w, h;
1555 switch (this.type) {
1557 x = attr.cx - attr.r;
1558 y = attr.cy - attr.r;
1562 x = attr.cx - attr.rx;
1563 y = attr.cy - attr.ry;
1571 w = attr.width || 0;
1572 h = attr.height || 0;
1575 this.textpath.v = ["m", Math.round(attr.x), ", ", Math.round(attr.y - 2), "l", Math.round(attr.x) + 1, ", ", Math.round(attr.y - 2)].join("");
1576 x = attr.x - Math.round(this.W / 2);
1577 y = attr.y - this.H / 2;
1582 if (!this.attrs.path) {
1586 h = this.vml.height;
1588 var dim = Raphael.pathDimensions(this.attrs.path),
1599 h = this.vml.height;
1602 if (this.type == "path" || this.type == "text") {
1603 var left = Math.round(this.vml.width / 2 - w / 2 - x),
1604 top = Math.round(this.vml.height / 2 - h / 2 - y);
1605 gs.left = - left + "px";
1606 gs.top = - top + "px";
1607 this.X = this.type == "text" ? x : left;
1608 this.Y = this.type == "text" ? y : top;
1611 os.top = top + "px";
1612 os.left = left + "px";
1614 var left = this.vml.width / 2 - w / 2,
1615 top = this.vml.height / 2 - h / 2;
1616 gs.position = "absolute";
1617 gs.left = x - left + "px";
1618 gs.top = y - top + "px";
1623 gs.width = this.vml.width + "px";
1624 gs.height = this.vml.height + "px";
1625 os.position = "absolute";
1626 os.top = top + "px";
1627 os.left = left + "px";
1628 os.width = w + "px";
1629 os.height = h + "px";
1632 Element.prototype.hide = function () {
1633 this.Group.style.display = "none";
1636 Element.prototype.show = function () {
1637 this.Group.style.display = "block";
1640 Element.prototype.translate = function (x, y) {
1641 if (x == undefined && y == undefined) {
1642 return {x: this._.tx, y: this._.ty};
1646 if (this.type == "path") {
1647 var path = this.attrs.path;
1648 path = Raphael.pathToRelative(path);
1651 this.attr({path: path.join(" ")});
1653 this.setBox({x: this._.tx, y: this._.ty});
1656 Element.prototype.getBBox = function () {
1664 Element.prototype.remove = function () {
1665 this[0].parentNode.removeChild(this[0]);
1666 this.Group.parentNode.removeChild(this.Group);
1667 this.shape && this.shape.parentNode.removeChild(this.shape);
1669 Element.prototype.attr = function () {
1670 if (arguments.length == 1 && typeof arguments[0] == "string") {
1671 if (arguments[0] == "translation") {
1672 return this.translate();
1674 return this.attrs[arguments[0]];
1676 if (this.attrs && arguments.length == 1 && arguments[0] instanceof Array) {
1678 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1679 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1683 if (this.node.tagName.toLowerCase() == "group") {
1684 var children = this[0].childNodes;
1685 this.attrs = this.attrs || {};
1686 if (arguments.length == 2) {
1687 this.attrs[arguments[0]] = arguments[1];
1688 } else if (arguments.length == 1 || typeof arguments[0] == "object") {
1689 for (var j in arguments[0]) {
1690 this.attrs[j] = arguments[0][j];
1693 for (var i = 0, ii = children.length; i < ii; i++) {
1694 this.attr.apply(new item(children[i], this[0], this.vml), arguments);
1698 if (arguments.length == 2) {
1700 params[arguments[0]] = arguments[1];
1702 if (arguments.length == 1 && typeof arguments[0] == "object") {
1703 params = arguments[0];
1706 if (params.gradient) {
1707 addGrdientFill(this, params.gradient);
1709 if (params.text && this.type == "text") {
1710 this.node.string = params.text;
1713 this.node.id = params.id;
1715 setFillAndStroke(this, params);
1716 this.setBox(params);
1721 Element.prototype.toFront = function () {
1722 this.Group.parentNode.appendChild(this.Group);
1725 Element.prototype.toBack = function () {
1726 if (this.Group.parentNode.firstChild != this.Group) {
1727 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
1731 Element.prototype.insertAfter = function (element) {
1732 if (element.Group.nextSibling) {
1733 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
1735 element.Group.parentNode.appendChild(this.Group);
1739 Element.prototype.insertBefore = function (element) {
1740 element.Group.parentNode.insertBefore(this.Group, element.Group);
1743 var theCircle = function (vml, x, y, r) {
1744 var g = document.createElement("rvml:group");
1745 var o = document.createElement("rvml:oval");
1747 vml.canvas.appendChild(g);
1748 var res = new Element(o, g, vml);
1749 res.type = "circle";
1750 setFillAndStroke(res, {stroke: "#000", fill: "none"});
1751 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
1757 var theRect = function (vml, x, y, w, h, r) {
1758 var g = document.createElement("rvml:group");
1759 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect");
1761 o.arcsize = r / (Math.min(w, h));
1764 vml.canvas.appendChild(g);
1765 var res = new Element(o, g, vml);
1767 setFillAndStroke(res, {stroke: "#000"});
1768 res.setBox({x: x, y: y, width: w, height: h});
1776 var theEllipse = function (vml, x, y, rx, ry) {
1777 var g = document.createElement("rvml:group");
1778 var o = document.createElement("rvml:oval");
1780 vml.canvas.appendChild(g);
1781 var res = new Element(o, g, vml);
1782 res.type = "ellipse";
1783 setFillAndStroke(res, {stroke: "#000"});
1784 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
1791 var theImage = function (vml, src, x, y, w, h) {
1792 var g = document.createElement("rvml:group");
1793 var o = document.createElement("rvml:image");
1796 vml.canvas.appendChild(g);
1797 var res = new Element(o, g, vml);
1799 res.setBox({x: x, y: y, width: w, height: h});
1806 var theText = function (vml, x, y, text) {
1807 var g = document.createElement("rvml:group"), gs = g.style;
1808 var el = document.createElement("rvml:shape"), ol = el.style;
1809 var path = document.createElement("rvml:path"), ps = path.style;
1810 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
1811 path.textpathok = true;
1812 ol.width = vml.width;
1813 ol.height = vml.height;
1814 gs.position = "absolute";
1817 gs.width = vml.width;
1818 gs.height = vml.height;
1819 var o = document.createElement("rvml:textpath");
1822 o.coordsize = vml.coordsize;
1823 o.coordorigin = vml.coordorigin;
1825 el.appendChild(path);
1827 vml.canvas.appendChild(g);
1828 var res = new Element(o, g, vml);
1830 res.textpath = path;
1836 setFillAndStroke(res, {font: '10px "Arial"', stroke: "none", fill: "#000"});
1839 var theGroup = function (vml) {
1842 R._create = function () {
1843 // container, width, height
1844 // x, y, width, height
1845 var container, width, height;
1846 if (typeof arguments[0] == "string") {
1847 container = document.getElementById(arguments[0]);
1848 width = arguments[1];
1849 height = arguments[2];
1851 if (typeof arguments[0] == "object") {
1852 container = arguments[0];
1853 width = arguments[1];
1854 height = arguments[2];
1856 if (typeof arguments[0] == "number") {
1860 width = arguments[2];
1861 height = arguments[3];
1864 throw new Error("VML container not found.");
1866 if (!document.namespaces["rvml"]) {
1867 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
1868 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
1870 var c = document.createElement("div"),
1871 d = document.createElement("div"),
1872 r = paper.canvas = document.createElement("rvml:group"),
1873 cs = c.style, rs = r.style;
1874 paper.width = width;
1875 paper.height = height;
1876 width = width || "320px";
1877 height = height || "200px";
1878 cs.clip = "rect(0 " + width + " " + height + " 0)";
1881 cs.position = "absolute";
1882 rs.position = "absolute";
1883 d.style.position = "relative";
1886 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
1887 r.coordorigin = "0 0";
1889 var b = document.createElement("rvml:rect"), bs = b.style;
1890 bs.left = bs.top = 0;
1891 bs.width = rs.width;
1892 bs.height = rs.height;
1893 b.filled = b.stroked = "f";
1898 if (container == 1) {
1899 document.body.appendChild(d);
1900 cs.position = "absolute";
1912 cs.width = container.style.width = width;
1913 cs.height = container.style.height = height;
1914 if (container.firstChild) {
1915 container.insertBefore(d, container.firstChild);
1917 container.appendChild(d);
1920 for (var prop in paper) {
1921 container[prop] = paper[prop];
1923 for (var prop in R.fn) {
1924 if (!container[prop]) {
1925 container[prop] = R.fn[prop];
1928 container.clear = function () {
1930 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
1931 if (r.childNodes[i] != b) {
1932 todel.push(r.childNodes[i]);
1935 for (i = 0, ii = todel.length; i < ii; i++) {
1936 r.removeChild(todel[i]);
1941 paper.remove = function () {
1942 this.canvas.parentNode.parentNode.parentNode.removeChild(this.canvas.parentNode.parentNode);
1944 paper.safari = function () {};
1950 var addEvent = (function () {
1951 if (document.addEventListener) {
1952 return function (obj, type, fn) {
1953 obj.addEventListener(type, fn, false);
1955 } else if (document.attachEvent) {
1956 return function (obj, type, fn) {
1957 var f = function (e) {
1958 fn.call(this, e || window.event);
1960 obj.attachEvent("on" + type, f);
1964 var events = ["click", "dblclick", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup"];
1965 for (var i = events.length; i--;) {
1966 (function (eventName) {
1967 Element.prototype[eventName] = function (fn) {
1968 addEvent(this.node, eventName, fn);
1975 var Set = function (itemsArray) {
1977 if (itemsArray && itemsArray.constructor == Array) {
1978 for (var i = itemsArray.length; i--;) {
1979 if (itemsArray[i].constructor == Element) {
1980 this.items[this.items.length] = itemsArray[i];
1985 Set.prototype.add = function (item) {
1986 if (item && item.constructor == Element) {
1987 this.items[this.items.length] = item;
1991 Set.prototype.remove = function (item) {
1992 if (item && item.constructor == Element) {
1993 for (var i = this.items.length; i--;) {
1994 if (this.items[i] == item) {
1995 this.items.splice(i, 1);
2002 for (var method in Element.prototype) {
2003 Set.prototype[method] = (function (methodname) {
2004 return function () {
2005 for (var i = this.items.length; i--;) {
2006 this.items[i][methodname].apply(this.items[i], arguments);
2012 Set.prototype.getBBox = function () {
2013 var x = [], y = [], w = [], h = [];
2014 for (var i = this.items.length; i--;) {
2015 var box = this.items[i].getBBox();
2018 w.push(box.x + box.width);
2019 h.push(box.y + box.height);
2031 paper.circle = function (x, y, r) {
2032 return theCircle(this, x, y, r);
2034 paper.rect = function (x, y, w, h, r) {
2035 return theRect(this, x, y, w, h, r);
2037 paper.ellipse = function (x, y, rx, ry) {
2038 return theEllipse(this, x, y, rx, ry);
2040 paper.path = function (params, pathString) {
2041 return thePath(params, pathString, this);
2043 paper.image = function (src, x, y, w, h) {
2044 return theImage(this, src, x, y, w, h);
2046 paper.text = function (x, y, text) {
2047 return theText(this, x, y, text);
2049 paper.group = function () {
2052 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
2053 color = color || "#000";
2054 var p = this.path({stroke: color, "stroke-width": 1})
2055 .moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).lineTo(x, y),
2057 columnWidth = w / wv;
2058 for (var i = 1; i < hv; i++) {
2059 p.moveTo(x, y + i * rowHeight).lineTo(x + w, y + i * rowHeight);
2061 for (var i = 1; i < wv; i++) {
2062 p.moveTo(x + i * columnWidth, y).lineTo(x + i * columnWidth, y + h);
2066 paper.pathfinder = function (p, path) {
2068 M: function (x, y) {
2071 C: function (x1, y1, x2, y2, x3, y3) {
2072 this.curveTo(x1, y1, x2, y2, x3, y3);
2074 Q: function (x1, y1, x2, y2) {
2075 this.qcurveTo(x1, y1, x2, y2);
2077 T: function (x, y) {
2078 this.qcurveTo(x, y);
2080 S: function (x1, y1, x2, y2) {
2081 p.curveTo(x1, y1, x2, y2);
2083 L: function (x, y) {
2087 this.lineTo(x, this.last.y);
2090 this.lineTo(this.last.x, y);
2092 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2093 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2100 path = Raphael.pathToAbsolute(path);
2101 for (var i = 0, ii = path.length; i < ii; i++) {
2102 var b = path[i].shift();
2103 commands[b].apply(p, path[i]);
2106 paper.set = function (itemsArray) {
2107 return new Set(itemsArray);
2109 Element.prototype.stop = function () {
2110 clearTimeout(this.animation_in_progress);
2112 Element.prototype.scale = function (x, y) {
2113 if (x == undefined && y == undefined) {
2114 return {x: this._.sx, y: this._.sy};
2118 if (x != 0 && !(x == 1 && y == 1)) {
2119 var dirx = Math.round(x / Math.abs(x)),
2120 diry = Math.round(y / Math.abs(y)),
2121 s = this.node.style;
2122 dx = this.attr("x");
2123 dy = this.attr("y");
2124 cx = this.attr("cx");
2125 cy = this.attr("cy");
2126 if (dirx != 1 || diry != 1) {
2127 if (this.transformations) {
2128 this.transformations[2] = "scale(" + [dirx, diry] + ")";
2129 this.node.setAttribute("transform", this.transformations.join(" "));
2130 dx = (dirx < 0) ? -this.attr("x") - this.attrs.width * x * dirx / this._.sx : this.attr("x");
2131 dy = (diry < 0) ? -this.attr("y") - this.attrs.height * y * diry / this._.sy : this.attr("y");
2132 cx = this.attr("cx") * dirx;
2133 cy = this.attr("cy") * diry;
2135 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=" + dirx +
2136 ", M12=0, M21=0, M22=" + diry +
2137 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')";
2138 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2141 if (this.transformations) {
2142 this.transformations[2] = "";
2143 this.node.setAttribute("transform", this.transformations.join(" "));
2145 this.node.filterMatrix = "";
2146 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2149 switch (this.type) {
2153 width: this.attrs.width * x * dirx / this._.sx,
2154 height: this.attrs.height * y * diry / this._.sy,
2162 rx: this.attrs.rx * x * dirx / this._.sx,
2163 ry: this.attrs.ry * y * diry / this._.sy,
2164 r: this.attrs.r * x * diry / this._.sx,
2170 var path = Raphael.pathToRelative(Raphael.parsePathString(this.attr("path"))),
2172 dim = Raphael.pathDimensions(this.attrs.path),
2173 dx = -dim.width * (x - 1) / 2,
2174 dy = -dim.height * (y - 1) / 2;
2175 for (var i = 0, ii = path.length; i < ii; i++) {
2176 if (path[i][0].toUpperCase() == "M" && skip) {
2181 if (path[i][0].toUpperCase() == "A") {
2182 path[i][path[i].length - 2] *= x * dirx;
2183 path[i][path[i].length - 1] *= y * diry;
2185 for (var j = 1, jj = path[i].length; j < jj; j++) {
2186 path[i][j] *= (j % 2) ? x * dirx / this._.sx : y * diry / this._.sy;
2190 var dim2 = Raphael.pathDimensions(path),
2191 dx = dim.x + dim.width / 2 - dim2.x - dim2.width / 2,
2192 dy = dim.y + dim.height / 2 - dim2.y - dim2.height / 2;
2193 path = Raphael.pathToRelative(path);
2197 this.attr({path: path.join(" ")});
2204 Element.prototype.animate = function (params, ms, callback) {
2205 clearTimeout(this.animation_in_progress);
2206 var from = {}, to = {}, diff = {}, t = {x: 0, y: 0};
2207 for (var attr in params) {
2208 if (attr in availableAnimAttrs) {
2209 from[attr] = this.attr(attr);
2210 if (typeof from[attr] == "undefined") {
2211 from[attr] = availableAttrs[attr];
2213 to[attr] = params[attr];
2214 switch (availableAnimAttrs[attr]) {
2216 diff[attr] = (to[attr] - from[attr]) / ms;
2219 from[attr] = Raphael.getRGB(from[attr]);
2220 var toColour = Raphael.getRGB(to[attr]);
2222 r: (toColour.r - from[attr].r) / ms,
2223 g: (toColour.g - from[attr].g) / ms,
2224 b: (toColour.b - from[attr].b) / ms
2228 var pathes = Raphael.pathEqualiser(from[attr], to[attr]);
2229 from[attr] = pathes[0];
2230 to[attr] = pathes[1];
2232 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2233 diff[attr][i] = [0];
2234 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2235 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2240 var values = params[attr].split(/[, ]+/);
2241 if (attr == "translation") {
2242 from[attr] = [0, 0];
2243 diff[attr] = [values[0] / ms, values[1] / ms];
2245 from[attr] = from[attr].split(/[, ]+/);
2246 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][0]) / ms];
2252 var start = new Date(),
2256 var time = (new Date()).getTime() - start.getTime(),
2260 for (var attr in from) {
2261 switch (availableAnimAttrs[attr]) {
2263 now = +from[attr] + time * diff[attr];
2267 Math.round(from[attr].r + time * diff[attr].r),
2268 Math.round(from[attr].g + time * diff[attr].g),
2269 Math.round(from[attr].b + time * diff[attr].b)
2274 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2275 now[i] = [from[attr][i][0]];
2276 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2277 now[i][j] = from[attr][i][j] + time * diff[attr][i][j];
2279 now[i] = now[i].join(" ");
2281 now = now.join(" ");
2284 if (attr == "translation") {
2285 var x = diff[attr][0] * (time - prev),
2286 y = diff[attr][1] * (time - prev);
2289 now = [x, y].join(" ");
2291 now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1]].join(" ");
2295 if (attr == "font-size") {
2296 set[attr] = now + "px";
2302 that.animation_in_progress = setTimeout(arguments.callee, 0);
2306 that.translate(-t.x, -t.y);
2309 clearTimeout(that.animation_in_progress);
2311 (typeof callback == "function") && callback.call(that);