2 * Raphael 0.7.dev - 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.
9 var Raphael = (function () {
10 var separator = /[, ]+/,
13 return create.apply(R, arguments);
15 R.version = "0.7.dev";
16 R.type = (window.SVGAngle ? "SVG" : "VML");
17 R.svg = !(R.vml = R.type == "VML");
21 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},
22 availableAnimAttrs = {cx: "number", cy: "number", fill: "colour", "fill-opacity": "number", "font-size": "number", height: "number", opacity: "number", path: "path", r: "number", rotation: "csv", rx: "number", ry: "number", scale: "csv", stroke: "colour", "stroke-opacity": "number", "stroke-width": "number", translation: "csv", width: "number", x: "number", y: "number"};
24 R.toString = function () {
25 return "Your browser " + (this.vml ? "doesn't ": "") + "support" + (this.svg ? "s": "") +
26 " SVG.\nYou are running " + unescape("Rapha%EBl%20") + this.version;
29 var hsb2rgb = function (hue, saturation, brightness) {
30 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
38 if (brightness == 0) {
39 return {r: 0, g: 0, b: 0, hex: "#000"};
41 if (hue > 1 || saturation > 1 || brightness > 1) {
46 var i = Math.floor(hue * 6),
48 p = brightness * (1 - saturation),
49 q = brightness * (1 - (saturation * f)),
50 t = brightness * (1 - (saturation * (1 - f)));
51 red = [brightness, q, p, p, t, brightness, brightness][i];
52 green = [t, brightness, brightness, q, p, p, t][i];
53 blue = [p, p, t, brightness, brightness, q, p][i];
57 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 var getRGB = function (colour) {
74 var htmlcolors = {aliceblue: "#f0f8ff", amethyst: "#96c", antiquewhite: "#faebd7", aqua: "#0ff", aquamarine: "#7fffd4", azure: "#f0ffff", beige: "#f5f5dc", bisque: "#ffe4c4", black: "#000", blanchedalmond: "#ffebcd", blue: "#00f", blueviolet: "#8a2be2", brown: "#a52a2a", burlywood: "#deb887", cadetblue: "#5f9ea0", chartreuse: "#7fff00", chocolate: "#d2691e", coral: "#ff7f50", cornflowerblue: "#6495ed", cornsilk: "#fff8dc", crimson: "#dc143c", cyan: "#0ff", darkblue: "#00008b", darkcyan: "#008b8b", darkgoldenrod: "#b8860b", darkgray: "#a9a9a9", darkgreen: "#006400", darkkhaki: "#bdb76b", darkmagenta: "#8b008b", darkolivegreen: "#556b2f", darkorange: "#ff8c00", darkorchid: "#9932cc", darkred: "#8b0000", darksalmon: "#e9967a", darkseagreen: "#8fbc8f", darkslateblue: "#483d8b", darkslategray: "#2f4f4f", darkturquoise: "#00ced1", darkviolet: "#9400d3", deeppink: "#ff1493", deepskyblue: "#00bfff", dimgray: "#696969", dodgerblue: "#1e90ff", firebrick: "#b22222", floralwhite: "#fffaf0", forestgreen: "#228b22", fuchsia: "#f0f", gainsboro: "#dcdcdc", ghostwhite: "#f8f8ff", gold: "#ffd700", goldenrod: "#daa520", gray: "#808080", green: "#008000", greenyellow: "#adff2f", honeydew: "#f0fff0", hotpink: "#ff69b4", indianred: "#cd5c5c", indigo: "#4b0082", ivory: "#fffff0", khaki: "#f0e68c", lavender: "#e6e6fa", lavenderblush: "#fff0f5", lawngreen: "#7cfc00", lemonchiffon: "#fffacd", lightblue: "#add8e6", lightcoral: "#f08080", lightcyan: "#e0ffff", lightgoldenrodyellow: "#fafad2", lightgreen: "#90ee90", lightgrey: "#d3d3d3", lightpink: "#ffb6c1", lightsalmon: "#ffa07a", lightsalmon: "#ffa07a", lightseagreen: "#20b2aa", lightskyblue: "#87cefa", lightslategray: "#789", lightsteelblue: "#b0c4de", lightyellow: "#ffffe0", lime: "#0f0", limegreen: "#32cd32", linen: "#faf0e6", magenta: "#f0f", maroon: "#800000", mediumaquamarine: "#66cdaa", mediumblue: "#0000cd", mediumorchid: "#ba55d3", mediumpurple: "#9370db", mediumseagreen: "#3cb371", mediumslateblue: "#7b68ee", mediumslateblue: "#7b68ee", mediumspringgreen: "#00fa9a", mediumturquoise: "#48d1cc", mediumvioletred: "#c71585", midnightblue: "#191970", mintcream: "#f5fffa", mistyrose: "#ffe4e1", moccasin: "#ffe4b5", navajowhite: "#ffdead", navy: "#000080", oldlace: "#fdf5e6", olive: "#808000", olivedrab: "#6b8e23", orange: "#ffa500", orangered: "#ff4500", orchid: "#da70d6", palegoldenrod: "#eee8aa", palegreen: "#98fb98", paleturquoise: "#afeeee", palevioletred: "#db7093", papayawhip: "#ffefd5", peachpuff: "#ffdab9", peru: "#cd853f", pink: "#ffc0cb", plum: "#dda0dd", powderblue: "#b0e0e6", purple: "#800080", red: "#f00", rosybrown: "#bc8f8f", royalblue: "#4169e1", saddlebrown: "#8b4513", salmon: "#fa8072", sandybrown: "#f4a460", seagreen: "#2e8b57", seashell: "#fff5ee", sienna: "#a0522d", silver: "#c0c0c0", skyblue: "#87ceeb", slateblue: "#6a5acd", slategray: "#708090", snow: "#fffafa", springgreen: "#00ff7f", steelblue: "#4682b4", tan: "#d2b48c", teal: "#008080", thistle: "#d8bfd8", tomato: "#ff6347", turquoise: "#40e0d0", violet: "#ee82ee", wheat: "#f5deb3", white: "#fff", whitesmoke: "#f5f5f5", yellow: "#ff0", yellowgreen: "#9acd32"};
75 if (colour.toString().toLowerCase() in htmlcolors) {
76 colour = htmlcolors[colour.toString().toLowerCase()];
79 return {r: 0, g: 0, b: 0, hex: "#000"};
81 if (colour == "none") {
82 return {r: -1, g: -1, b: -1, hex: "none"};
85 rgb = colour.match(/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|rgb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hsb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i);
88 blue = parseInt(rgb[2].substring(5), 16);
89 green = parseInt(rgb[2].substring(3, 5), 16);
90 red = parseInt(rgb[2].substring(1, 3), 16);
93 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
94 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
95 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
98 rgb = rgb[4].split(/\s*,\s*/);
99 red = parseFloat(rgb[0], 10);
100 green = parseFloat(rgb[1], 10);
101 blue = parseFloat(rgb[2], 10);
104 rgb = rgb[5].split(/\s*,\s*/);
105 red = parseFloat(rgb[0], 10) * 2.55;
106 green = parseFloat(rgb[1], 10) * 2.55;
107 blue = parseFloat(rgb[2], 10) * 2.55;
110 rgb = rgb[6].split(/\s*,\s*/);
111 red = parseFloat(rgb[0], 10);
112 green = parseFloat(rgb[1], 10);
113 blue = parseFloat(rgb[2], 10);
114 return hsb2rgb(red, green, blue);
117 rgb = rgb[7].split(/\s*,\s*/);
118 red = parseFloat(rgb[0], 10) * 2.55;
119 green = parseFloat(rgb[1], 10) * 2.55;
120 blue = parseFloat(rgb[2], 10) * 2.55;
121 return hsb2rgb(red, green, blue);
123 var rgb = {r: red, g: green, b: blue};
124 var r = Math.round(red).toString(16);
125 (r.length == 1) && (r = "0" + r);
126 var g = Math.round(green).toString(16);
127 (g.length == 1) && (g = "0" + g);
128 var b = Math.round(blue).toString(16);
129 (b.length == 1) && (b = "0" + b);
130 rgb.hex = "#" + r + g + b;
133 return {r: -1, g: -1, b: -1, hex: "none"};
136 R.getColor = function (value) {
137 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
138 var rgb = hsb2rgb(start.h, start.s, start.b);
144 arguments.callee.start = {h: 0, s: 1, b: start.b};
149 R.getColor.reset = function () {
150 this.start = undefined;
153 R.parsePathString = function (pathString) {
154 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
156 toString = function () {
158 for (var i = 0, ii = this.length; i < ii; i++) {
159 res += this[i][0] + this[i].join(",").substring(2);
163 if (pathString.toString.toString() == toString.toString()) {
166 pathString.replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*\s*,?\s*)+)/ig, function (a, b, c) {
167 var params = [], name = b.toLowerCase();
168 c.replace(/(-?\d*\.?\d*)\s*,?\s*/ig, function (a, b) {
169 b && params.push(+b);
171 while (params.length >= paramCounts[name]) {
172 data.push([b].concat(params.splice(0, paramCounts[name])));
173 if (!paramCounts[name]) {
178 data.toString = toString;
181 var pathDimensions = function (path) {
182 var pathArray = path;
183 if (typeof path == "string") {
184 pathArray = Raphael.parsePathString(path);
186 pathArray = pathToAbsolute(pathArray);
187 var x = [], y = [], length = 0;
188 for (var i = 0, ii = pathArray.length; i < ii; i++) {
189 switch (pathArray[i][0]) {
193 x.push(pathArray[i][pathArray[i].length - 2]);
194 y.push(pathArray[i][pathArray[i].length - 1]);
197 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
199 x.push(pathArray[i][j]);
201 y.push(pathArray[i][j]);
206 var minx = Math.min.apply(Math, x),
207 miny = Math.min.apply(Math, y);
211 width: Math.max.apply(Math, x) - minx,
212 height: Math.max.apply(Math, y) - miny,
217 var pathToRelative = function (pathArray) {
219 if (typeof pathArray == "string") {
220 pathArray = R.parsePathString(pathArray);
222 var x = 0, y = 0, start = 0;
223 if (pathArray[0][0] == "M") {
227 res.push(pathArray[0]);
229 for (var i = start, ii = pathArray.length; i < ii; i++) {
231 if (pathArray[i][0] != pathArray[i][0].toLowerCase()) {
232 res[i][0] = pathArray[i][0].toLowerCase();
235 res[i][1] = pathArray[i][1];
236 res[i][2] = pathArray[i][2];
238 res[i][4] = pathArray[i][4];
239 res[i][5] = pathArray[i][5];
240 res[i][6] = +(pathArray[i][6] - x).toFixed(3);
241 res[i][7] = +(pathArray[i][7] - y).toFixed(3);
244 res[i][1] = +(pathArray[i][1] - y).toFixed(3);
247 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
248 res[i][j] = +(pathArray[i][j] - ((j % 2) ? x : y)).toFixed(3);
252 res[i] = pathArray[i];
258 x += res[i][res[i].length - 1];
261 y += res[i][res[i].length - 1];
264 x += res[i][res[i].length - 2];
265 y += res[i][res[i].length - 1];
268 res.toString = pathArray.toString;
271 var pathToAbsolute = function (pathArray) {
273 if (typeof pathArray == "string") {
274 pathArray = R.parsePathString(pathArray);
276 var x = 0, y = 0, start = 0;
277 if (pathArray[0][0] == "M") {
278 x = +pathArray[0][1];
279 y = +pathArray[0][2];
281 res[0] = pathArray[0];
283 for (var i = start, ii = pathArray.length; i < ii; i++) {
285 if (pathArray[i][0] != pathArray[i][0].toUpperCase()) {
286 res[i][0] = pathArray[i][0].toUpperCase();
289 res[i][1] = pathArray[i][1];
290 res[i][2] = pathArray[i][2];
292 res[i][4] = pathArray[i][4];
293 res[i][5] = pathArray[i][5];
294 res[i][6] = +(pathArray[i][6] + x).toFixed(3);
295 res[i][7] = +(pathArray[i][7] + y).toFixed(3);
298 res[i][1] = +pathArray[i][1] + y;
301 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
302 res[i][j] = +pathArray[i][j] + ((j % 2) ? x : y);
306 res[i] = pathArray[i];
318 x = res[i][res[i].length - 2];
319 y = res[i][res[i].length - 1];
322 res.toString = pathArray.toString;
325 var pathEqualiser = function (path1, path2) {
326 var data = [pathToAbsolute(Raphael.parsePathString(path1)), pathToAbsolute(Raphael.parsePathString(path2))],
327 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}],
328 processPath = function (path, d) {
338 var nx = d.x + (d.x - (d.bx || d.x));
339 var ny = d.y + (d.y - (d.by || d.y));
340 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
343 var nx = d.x + (d.x - (d.bx || d.x));
344 var ny = d.y + (d.y - (d.by || d.y));
345 path = ["Q", nx, ny, path[1], path[2]];
348 path = ["L", path[1], d.y];
351 path = ["L", d.x, path[1]];
354 path = ["L", d.X, d.Y];
359 edgeCases = function (a, b, i) {
360 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
361 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
362 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
363 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
364 attrs[a].x = data[a][i][data[a][i].length - 2];
365 attrs[a].y = data[a][i][data[a][i].length - 1];
367 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
368 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]];
369 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
370 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
371 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
372 var x = data[b][i][data[b][i].length - 2];
373 var y = data[b][i][data[b][i].length - 1];
374 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
375 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
377 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
378 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
379 attrs[b].x = data[b][i][data[b][i].length - 2];
380 attrs[b].y = data[b][i][data[b][i].length - 1];
382 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
383 var x = data[b][i][data[b][i].length - 2];
384 var y = data[b][i][data[b][i].length - 1];
385 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
386 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
388 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
389 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
390 attrs[b].x = data[b][i][data[b][i].length - 2];
391 attrs[b].y = data[b][i][data[b][i].length - 1];
393 } else if (data[a][i][0] == "U") {
394 data[a][i][0] = data[b][i][0];
395 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
396 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
401 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
402 data[0][i] = processPath(data[0][i], attrs[0]);
403 data[1][i] = processPath(data[1][i], attrs[1]);
404 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
407 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
408 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
409 attrs[0].x = data[0][i][data[0][i].length - 2];
410 attrs[0].y = data[0][i][data[0][i].length - 1];
411 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
412 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
413 attrs[1].x = data[1][i][data[1][i].length - 2];
414 attrs[1].y = data[1][i][data[1][i].length - 1];
421 var thePath = function (params, pathString, SVG) {
422 var el = document.createElementNS(SVG.svgns, "path");
423 el.setAttribute("fill", "none");
425 SVG.canvas.appendChild(el);
427 var p = new Element(el, SVG);
430 p.last = {x: 0, y: 0, bx: 0, by: 0};
431 p.absolutely = function () {
432 this.isAbsolute = true;
435 p.relatively = function () {
436 this.isAbsolute = false;
439 p.moveTo = function (x, y) {
440 var d = this.isAbsolute?"M":"m";
441 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
442 var oldD = this[0].getAttribute("d") || "";
443 (oldD == "M0,0") && (oldD = "");
444 this[0].setAttribute("d", oldD + d);
445 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
446 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
447 this.attrs.path = oldD + d;
450 p.lineTo = function (x, y) {
451 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
452 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
453 var d = this.isAbsolute?"L":"l";
454 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
455 var oldD = this[0].getAttribute("d") || "";
456 this[0].setAttribute("d", oldD + d);
457 this.attrs.path = oldD + d;
460 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
461 var d = this.isAbsolute ? "A" : "a";
462 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(" ");
463 var oldD = this[0].getAttribute("d") || "";
464 this[0].setAttribute("d", oldD + d);
465 this.last.x = parseFloat(x, 10);
466 this.last.y = parseFloat(y, 10);
467 this.attrs.path = oldD + d;
470 p.cplineTo = function (x1, y1, w1) {
472 return this.lineTo(x1, y1);
475 var x = parseFloat(x1, 10);
476 var y = parseFloat(y1, 10);
477 var w = parseFloat(w1, 10);
478 var d = this.isAbsolute?"C":"c";
479 var attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
480 for (var i = 0, ii = attr.length; i < ii; i++) {
481 d += attr[i].toFixed(3) + " ";
483 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
484 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
485 this.last.bx = attr[2];
486 this.last.by = attr[3];
487 var oldD = this[0].getAttribute("d") || "";
488 this[0].setAttribute("d", oldD + d);
489 this.attrs.path = oldD + d;
493 p.curveTo = function () {
495 command = [0, 1, 2, 3, "s", 5, "c"];
497 var d = command[arguments.length];
498 if (this.isAbsolute) {
501 for (var i = 0, ii = arguments.length; i < ii; i++) {
502 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
504 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
505 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
506 this.last.bx = parseFloat(arguments[arguments.length - 4], 10);
507 this.last.by = parseFloat(arguments[arguments.length - 3], 10);
508 var oldD = this.node.getAttribute("d") || "";
509 this.node.setAttribute("d", oldD + d);
510 this.attrs.path = oldD + d;
513 p.qcurveTo = function () {
515 command = [0, 1, "t", 3, "q"];
517 var d = command[arguments.length];
518 if (this.isAbsolute) {
521 for (var i = 0, ii = arguments.length; i < ii; i++) {
522 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
524 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
525 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
526 if (arguments.length != 2) {
527 this.last.qx = parseFloat(arguments[arguments.length - 4], 10);
528 this.last.qy = parseFloat(arguments[arguments.length - 3], 10);
530 var oldD = this.node.getAttribute("d") || "";
531 this.node.setAttribute("d", oldD + d);
532 this.attrs.path = oldD + d;
535 p.addRoundedCorner = function (r, dir) {
536 var R = .5522 * r, rollback = this.isAbsolute, o = this;
539 rollback = function () {
543 rollback = function () {};
549 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
552 o.curveTo(-R, 0, -r, r - R, -r, r);
559 o.curveTo(R, 0, r, -(r - R), r, -r);
562 o.curveTo(R, 0, r, r - R, r, r);
569 o.curveTo(0, -R, -(R - r), -r, r, -r);
572 o.curveTo(0, -R, R - r, -r, -r, -r);
579 o.curveTo(0, R, -(R - r), r, r, r);
582 o.curveTo(0, R, R - r, r, -r, r);
587 actions[dir[0]]()[dir[1]]();
591 p.andClose = function () {
592 var oldD = this[0].getAttribute("d") || "";
593 this[0].setAttribute("d", oldD + "Z ");
594 this.attrs.path = oldD + "Z ";
598 p.attrs.path = "" + pathString;
600 paper.pathfinder(p, p.attrs.path);
603 setFillAndStroke(p, params);
607 var addGrdientFill = function (o, gradient, SVG) {
608 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
609 el.id = "raphael-gradient-" + Raphael.idGenerator++;
610 if (gradient.vector && gradient.vector.length) {
611 el.setAttribute("x1", gradient.vector[0]);
612 el.setAttribute("y1", gradient.vector[1]);
613 el.setAttribute("x2", gradient.vector[2]);
614 el.setAttribute("y2", gradient.vector[3]);
616 SVG.defs.appendChild(el);
617 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
618 var stop = document.createElementNS(SVG.svgns, "stop");
619 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
620 stop.setAttribute("stop-color", getRGB(gradient.dots[i].color).hex || "#fff");
621 if (typeof gradient.dots[i].opacity != "undefined") {
622 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
624 el.appendChild(stop);
626 o.setAttribute("fill", "url(#" + el.id + ")");
628 var updatePosition = function (o) {
630 var bbox = o.node.getBBox();
631 o.pattern.setAttribute("patternTransform", "translate(" + [bbox.x, bbox.y].join(",") + ")");
634 var setFillAndStroke = function (o, params) {
639 "-..": [3, 1, 1, 1, 1, 1],
645 "--..": [8, 3, 1, 3, 1, 3]
647 addDashes = function (o, value) {
648 value = dasharray[value.toString().toLowerCase()];
650 var width = o.attrs["stroke-width"] || "1",
651 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
653 for (var i = 0, ii = value.length; i < ii; i++) {
654 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
656 value = dashes.join(",");
657 o.node.setAttribute("stroke-dasharray", value);
660 for (var att in params) {
661 var value = params[att];
662 o.attrs[att] = value;
665 if (o.type == "path") {
666 o.node.setAttribute("d", "M0,0");
667 paper.pathfinder(o, value);
672 o.node.setAttribute(att, value);
678 o.node.setAttribute(att, value);
682 o.node.setAttribute(att, value);
685 o.node.setAttribute(att, value);
688 addGrdientFill(o.node, value, o.svg);
691 o.node.style.strokeWidth = value;
692 // Need following line for Firefox
693 o.node.setAttribute(att, value);
694 if (o.attrs["stroke-dasharray"]) {
695 addDashes(o, o.attrs["stroke-dasharray"]);
698 case "stroke-dasharray":
702 if (o.type == "text") {
703 o.node.childNodes.length && o.node.removeChild(o.node.firstChild);
704 o.node.appendChild(document.createTextNode(value));
708 o.rotate(value, true);
711 var xy = value.split(separator);
712 o.translate(xy[0], xy[1]);
715 var xy = value.split(separator);
716 o.scale(xy[0], xy[1]);
719 var isURL = value.match(/^url\(([^\)]+)\)$/i);
721 var el = document.createElementNS(o.svg.svgns, "pattern");
722 var ig = document.createElementNS(o.svg.svgns, "image");
723 el.id = "raphael-pattern-" + Raphael.idGenerator++;
724 el.setAttribute("x", 0);
725 el.setAttribute("y", 0);
726 el.setAttribute("patternUnits", "userSpaceOnUse");
727 ig.setAttribute("x", 0);
728 ig.setAttribute("y", 0);
729 ig.setAttributeNS(o.svg.xlink, "href", isURL[1]);
732 var img = document.createElement("img");
733 img.style.position = "absolute";
734 img.style.top = "-9999em";
735 img.style.left = "-9999em";
736 img.onload = function () {
737 el.setAttribute("width", this.offsetWidth);
738 el.setAttribute("height", this.offsetHeight);
739 ig.setAttribute("width", this.offsetWidth);
740 ig.setAttribute("height", this.offsetHeight);
741 document.body.removeChild(this);
744 document.body.appendChild(img);
746 o.svg.defs.appendChild(el);
747 o.node.style.fill = "url(#" + el.id + ")";
748 o.node.setAttribute("fill", "url(#" + el.id + ")");
754 o.node.style[att] = getRGB(value).hex;
755 // Need following line for Firefox
756 o.node.setAttribute(att, getRGB(value).hex);
759 var cssrule = att.replace(/(\-.)/g, function (w) {
760 return w.substring(1).toUpperCase();
762 o.node.style[cssrule] = value;
763 // Need following line for Firefox
764 o.node.setAttribute(att, value);
769 var Element = function (node, svg) {
775 this.attrs = this.attrs || {};
776 this.transformations = []; // rotate, translate, scale
780 rt: {deg: 0, x: 0, y: 0},
785 Element.prototype.translate = function (x, y) {
786 if (x == undefined && y == undefined) {
787 return {x: this._.tx, y: this._.ty};
794 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
799 this.attr({x: this.attrs.x + x, y: this.attrs.y + y});
802 var path = pathToRelative(this.attrs.path);
805 this.attr({path: path.join(" ")});
810 Element.prototype.rotate = function (deg, cx, cy) {
812 return this._.rt.deg;
814 var bbox = this.getBBox();
815 deg = deg.toString().split(separator);
816 if (deg.length - 1) {
817 cx = parseFloat(deg[1], 10);
818 cy = parseFloat(deg[2], 10);
820 deg = parseFloat(deg[0], 10);
824 this._.rt.deg += deg;
829 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
830 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
832 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
834 this.transformations[0] = "";
836 this.node.setAttribute("transform", this.transformations.join(" "));
839 Element.prototype.hide = function () {
840 this.node.style.display = "none";
843 Element.prototype.show = function () {
844 this.node.style.display = "block";
847 Element.prototype.remove = function () {
848 this.node.parentNode.removeChild(this.node);
850 Element.prototype.getBBox = function () {
851 return this.node.getBBox();
853 Element.prototype.attr = function () {
854 if (arguments.length == 1 && typeof arguments[0] == "string") {
855 if (arguments[0] == "translation") {
856 return this.translate();
858 return this.attrs[arguments[0]];
860 if (arguments.length == 1 && arguments[0] instanceof Array) {
862 for (var j in arguments[0]) {
863 values[arguments[0][j]] = this.attrs[arguments[0][j]];
867 if (arguments.length == 2) {
869 params[arguments[0]] = arguments[1];
870 setFillAndStroke(this, params);
871 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
872 setFillAndStroke(this, arguments[0]);
876 Element.prototype.toFront = function () {
877 this.node.parentNode.appendChild(this.node);
880 Element.prototype.toBack = function () {
881 if (this.node.parentNode.firstChild != this.node) {
882 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
886 Element.prototype.insertAfter = function (element) {
887 if (element.node.nextSibling) {
888 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
890 element.node.parentNode.appendChild(this.node);
894 Element.prototype.insertBefore = function (element) {
895 element.node.parentNode.insertBefore(this.node, element.node);
898 var theCircle = function (svg, x, y, r) {
899 var el = document.createElementNS(svg.svgns, "circle");
900 el.setAttribute("cx", x);
901 el.setAttribute("cy", y);
902 el.setAttribute("r", r);
903 el.setAttribute("fill", "none");
904 el.setAttribute("stroke", "#000");
906 svg.canvas.appendChild(el);
908 var res = new Element(el, svg);
909 res.attrs = res.attrs || {};
913 res.attrs.stroke = "#000";
917 var theRect = function (svg, x, y, w, h, r) {
918 var el = document.createElementNS(svg.svgns, "rect");
919 el.setAttribute("x", x);
920 el.setAttribute("y", y);
921 el.setAttribute("width", w);
922 el.setAttribute("height", h);
924 el.setAttribute("rx", r);
925 el.setAttribute("ry", r);
927 el.setAttribute("fill", "none");
928 el.setAttribute("stroke", "#000");
930 svg.canvas.appendChild(el);
932 var res = new Element(el, svg);
933 res.attrs = res.attrs || {};
937 res.attrs.height = h;
938 res.attrs.stroke = "#000";
940 res.attrs.rx = res.attrs.ry = r;
945 var theEllipse = function (svg, x, y, rx, ry) {
946 var el = document.createElementNS(svg.svgns, "ellipse");
947 el.setAttribute("cx", x);
948 el.setAttribute("cy", y);
949 el.setAttribute("rx", rx);
950 el.setAttribute("ry", ry);
951 el.setAttribute("fill", "none");
952 el.setAttribute("stroke", "#000");
954 svg.canvas.appendChild(el);
956 var res = new Element(el, svg);
957 res.attrs = res.attrs || {};
962 res.attrs.stroke = "#000";
963 res.type = "ellipse";
966 var theImage = function (svg, src, x, y, w, h) {
967 var el = document.createElementNS(svg.svgns, "image");
968 el.setAttribute("x", x);
969 el.setAttribute("y", y);
970 el.setAttribute("width", w);
971 el.setAttribute("height", h);
972 el.setAttribute("preserveAspectRatio", "none");
973 el.setAttributeNS(svg.xlink, "href", src);
975 svg.canvas.appendChild(el);
977 var res = new Element(el, svg);
978 res.attrs = res.attrs || {};
982 res.attrs.height = h;
986 var theText = function (svg, x, y, text) {
987 var el = document.createElementNS(svg.svgns, "text");
988 el.setAttribute("x", x);
989 el.setAttribute("y", y);
990 el.setAttribute("text-anchor", "middle");
992 el.appendChild(document.createTextNode(text));
995 svg.canvas.appendChild(el);
997 var res = new Element(el, svg);
998 res.attrs = res.attrs || {};
1002 setFillAndStroke(res, {font: '10px "Arial"', stroke: "none", fill: "#000"});
1005 var theGroup = function (svg) {
1006 var el = document.createElementNS(svg.svgns, "g");
1008 svg.canvas.appendChild(el);
1010 var i = new Element(el, svg);
1011 for (var f in svg) {
1012 if (f[0] != "_" && typeof svg[f] == "function") {
1013 i[f] = (function (f) {
1014 return function () {
1015 var e = svg[f].apply(svg, arguments);
1016 el.appendChild(e[0]);
1025 create = function () {
1026 // container, width, height
1027 // x, y, width, height
1028 if (typeof arguments[0] == "string") {
1029 var container = document.getElementById(arguments[0]);
1030 var width = arguments[1];
1031 var height = arguments[2];
1033 if (typeof arguments[0] == "object") {
1034 var container = arguments[0];
1035 var width = arguments[1];
1036 var height = arguments[2];
1038 if (typeof arguments[0] == "number") {
1042 width = arguments[2],
1043 height = arguments[3];
1046 throw new Error("SVG container not found.");
1048 paper.canvas = document.createElementNS(paper.svgns, "svg");
1049 paper.canvas.setAttribute("width", width || 320);
1050 paper.width = width || 320;
1051 paper.canvas.setAttribute("height", height || 200);
1052 paper.height = height || 200;
1053 if (container == 1) {
1054 document.body.appendChild(paper.canvas);
1055 paper.canvas.style.position = "absolute";
1056 paper.canvas.style.left = x + "px";
1057 paper.canvas.style.top = y + "px";
1059 if (container.firstChild) {
1060 container.insertBefore(paper.canvas, container.firstChild);
1062 container.appendChild(paper.canvas);
1066 canvas: paper.canvas,
1067 clear: function () {
1068 while (this.canvas.firstChild) {
1069 this.canvas.removeChild(this.canvas.firstChild);
1071 this.defs = document.createElementNS(paper.svgns, "defs");
1072 this.canvas.appendChild(this.defs);
1075 for (var prop in paper) {
1076 if (prop != "create") {
1077 container[prop] = paper[prop];
1080 for (var prop in R.fn) {
1081 if (!container[prop]) {
1082 container[prop] = R.fn[prop];
1088 paper.remove = function () {
1089 this.canvas.parentNode.removeChild(this.canvas);
1091 paper.svgns = "http://www.w3.org/2000/svg";
1092 paper.xlink = "http://www.w3.org/1999/xlink";
1093 paper.safari = function () {
1094 if (navigator.vendor == "Apple Computer, Inc.") {
1095 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1096 setTimeout(function () {rect.remove();}, 0);
1103 thePath = function (params, pathString, VML) {
1104 var g = document.createElement("rvml:group"), gl = g.style;
1105 gl.position = "absolute";
1108 gl.width = VML.width + "px";
1109 gl.height = VML.height + "px";
1110 var el = document.createElement("rvml:shape"), ol = el.style;
1111 ol.width = VML.width + "px";
1112 ol.height = VML.height + "px";
1114 if (params["class"]) {
1115 el.className = params["class"];
1117 el.coordsize = this.coordsize;
1118 el.coordorigin = this.coordorigin;
1120 VML.canvas.appendChild(g);
1121 var p = new Element(el, g, VML);
1122 p.isAbsolute = true;
1125 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1127 p.absolutely = function () {
1128 this.isAbsolute = true;
1131 p.relatively = function () {
1132 this.isAbsolute = false;
1135 p.moveTo = function (x, y) {
1136 var d = this.isAbsolute?"m":"t";
1137 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
1138 this.node.path = this.Path += d;
1139 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
1140 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
1141 this.last.isAbsolute = this.isAbsolute;
1142 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1145 p.lineTo = function (x, y) {
1146 var d = this.isAbsolute?"l":"r";
1147 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
1148 this[0].path = this.Path += d;
1149 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
1150 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
1151 this.last.isAbsolute = this.isAbsolute;
1152 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1155 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1156 // for more information of where this math came from visit:
1157 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1158 x2 = (this.isAbsolute ? 0 : this.last.x) + x2;
1159 y2 = (this.isAbsolute ? 0 : this.last.y) + y2;
1160 var x1 = this.last.x,
1164 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1165 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1166 cx = k * rx * y / ry + (x1 + x2) / 2,
1167 cy = k * -ry * x / rx + (y1 + y2) / 2,
1168 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1169 left = Math.round(cx - rx),
1170 top = Math.round(cy - ry);
1171 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(", ");
1172 this.node.path = this.Path += d;
1173 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2, 10);
1174 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2, 10);
1175 this.last.isAbsolute = this.isAbsolute;
1176 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1179 p.cplineTo = function (x1, y1, w1) {
1181 return this.lineTo(x1, y1);
1183 var x = Math.round(Math.round(parseFloat(x1, 10) * 100) / 100),
1184 y = Math.round(Math.round(parseFloat(y1, 10) * 100) / 100),
1185 w = Math.round(Math.round(parseFloat(w1, 10) * 100) / 100),
1186 d = this.isAbsolute ? "c" : "v",
1187 attr = [Math.round(this.last.x) + w, Math.round(this.last.y), x - w, y, x, y],
1188 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1189 d += attr.join(" ") + " ";
1190 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1191 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1192 this.last.bx = attr[2];
1193 this.last.by = attr[3];
1194 this.node.path = this.Path += d;
1195 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1199 p.curveTo = function () {
1200 var d = this.isAbsolute ? "c" : "v";
1201 if (arguments.length == 6) {
1202 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1203 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1204 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4], 10);
1205 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5], 10);
1206 d += [Math.round(parseFloat(arguments[0], 10)),
1207 Math.round(parseFloat(arguments[1], 10)),
1208 Math.round(parseFloat(arguments[2], 10)),
1209 Math.round(parseFloat(arguments[3], 10)),
1210 Math.round(parseFloat(arguments[4], 10)),
1211 Math.round(parseFloat(arguments[5], 10))].join(" ") + " ";
1212 this.last.isAbsolute = this.isAbsolute;
1213 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1215 if (arguments.length == 4) {
1216 var bx = this.last.x * 2 - this.last.bx;
1217 var by = this.last.y * 2 - this.last.by;
1218 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
1219 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
1220 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1221 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1222 d += [Math.round(bx), Math.round(by),
1223 Math.round(parseFloat(arguments[0], 10)),
1224 Math.round(parseFloat(arguments[1], 10)),
1225 Math.round(parseFloat(arguments[2], 10)),
1226 Math.round(parseFloat(arguments[3], 10))].join(" ") + " ";
1227 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1229 this.node.path = this.Path += d;
1232 p.qcurveTo = function () {
1234 if (arguments.length == 4) {
1235 this.last.qx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
1236 this.last.qy = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
1237 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1238 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1239 d += [Math.round(this.last.qx),
1240 Math.round(this.last.qy),
1241 Math.round(this.last.x),
1242 Math.round(this.last.y)].join(" ") + " ";
1243 this.last.isAbsolute = this.isAbsolute;
1244 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1246 if (arguments.length == 2) {
1247 this.last.qx = this.last.x * 2 - this.last.qx;
1248 this.last.qy = this.last.y * 2 - this.last.qy;
1249 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1250 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1251 d += [Math.round(this.last.qx),
1252 Math.round(this.last.qy),
1253 Math.round(this.last.x),
1254 Math.round(this.last.y)].join(" ") + " ";
1255 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1257 this.node.path = this.Path += d;
1258 this.path.push({type: "qcurve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
1261 p.addRoundedCorner = function (r, dir) {
1262 var R = .5522 * r, rollback = this.isAbsolute, o = this;
1265 rollback = function () {
1269 rollback = function () {};
1275 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
1278 o.curveTo(-R, 0, -r, r - R, -r, r);
1285 o.curveTo(R, 0, r, -(r - R), r, -r);
1288 o.curveTo(R, 0, r, r - R, r, r);
1295 o.curveTo(0, -R, -(R - r), -r, r, -r);
1298 o.curveTo(0, -R, R - r, -r, -r, -r);
1305 o.curveTo(0, R, -(R - r), r, r, r);
1308 o.curveTo(0, R, R - r, r, -r, r);
1313 actions[dir.charAt(0)]()[dir.charAt(1)]();
1317 p.andClose = function () {
1318 this.node.path = (this.Path += "x e");
1319 this.attrs.path += "z";
1325 paper.pathfinder(p, "" + pathString);
1328 setFillAndStroke(p, params);
1329 if (params.gradient) {
1330 addGrdientFill(p, params.gradient);
1334 var setFillAndStroke = function (o, params) {
1335 var s = o.node.style,
1337 o.attrs = o.attrs || {};
1338 for (var par in params) {
1339 o.attrs[par] = params[par];
1341 if (params.path && o.type == "path") {
1344 paper.pathfinder(o, params.path);
1346 if (params.rotation != null) {
1347 o.rotate(params.rotation, true);
1349 if (params.translation) {
1350 var xy = params.translation.split(separator);
1351 o.translate(xy[0], xy[1]);
1354 var xy = params.scale.split(separator);
1355 o.scale(xy[0], xy[1]);
1357 if (o.type == "image" && params.opacity) {
1358 o.node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1359 o.node.style.filter = (o.node.filterMatrix || "") + (o.node.filterOpacity || "");
1361 params.font && (s.font = params.font);
1362 params["font-family"] && (s.fontFamily = params["font-family"]);
1363 params["font-size"] && (s.fontSize = params["font-size"]);
1364 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1365 params["font-style"] && (s.fontStyle = params["font-style"]);
1366 if (typeof params.opacity != "undefined" || typeof params["stroke-width"] != "undefined" || typeof params.fill != "undefined" || typeof params.stroke != "undefined") {
1367 o = o.shape || o.node;
1368 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || document.createElement("rvml:fill");
1369 if ("fill-opacity" in params || "opacity" in params) {
1370 fill.opacity = ((params["fill-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
1375 if (fill.on == undefined || params.fill == "none") {
1378 if (fill.on && params.fill) {
1379 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1381 fill.src = isURL[1];
1384 fill.color = getRGB(params.fill).hex;
1386 fill.type = "solid";
1389 o.appendChild(fill);
1390 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || document.createElement("rvml:stroke");
1391 if ((params.stroke && params.stroke != "none") || params["stroke-width"] || params["stroke-opacity"] || params["stroke-dasharray"]) {
1394 if (params.stroke == "none" || typeof stroke.on == "undefined") {
1397 if (stroke.on && params.stroke) {
1398 stroke.color = getRGB(params.stroke).hex;
1400 stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
1401 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1402 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1403 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1404 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"], 10) || 1) * 12 / 16);
1405 if (params["stroke-dasharray"]) {
1409 "-.": "shortdashdot",
1410 "-..": "shortdashdotdot",
1415 "--.": "longdashdot",
1416 "--..": "longdashdotdot"
1418 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1420 o.appendChild(stroke);
1422 if (res.type == "text") {
1423 var span = document.createElement("span"),
1425 res.attrs.font && (s.font = res.attrs.font);
1426 res.attrs["font-family"] && (s.fontFamily = res.attrs["font-family"]);
1427 res.attrs["font-size"] && (s.fontSize = res.attrs["font-size"]);
1428 res.attrs["font-weight"] && (s.fontWeight = res.attrs["font-weight"]);
1429 res.attrs["font-style"] && (s.fontStyle = res.attrs["font-style"]);
1430 res.node.parentNode.appendChild(span);
1431 span.innerText = res.node.string;
1432 res.W = res.attrs.w = span.offsetWidth;
1433 res.H = res.attrs.h = span.offsetHeight;
1434 res.X = res.attrs.x - Math.round(res.W / 2);
1435 res.Y = res.attrs.y - Math.round(res.H / 2);
1436 res.node.parentNode.removeChild(span);
1439 var getAngle = function (a, b, c, d) {
1440 var angle = Math.round(Math.atan((parseFloat(c, 10) - parseFloat(a, 10)) / (parseFloat(d, 10) - parseFloat(b, 10))) * 57.29) || 0;
1441 if (!angle && parseFloat(a, 10) < parseFloat(b, 10)) {
1450 var addGrdientFill = function (o, gradient) {
1451 o.attrs = o.attrs || {};
1452 o.attrs.gradient = gradient;
1453 o = o.shape || o[0];
1454 var fill = o.getElementsByTagName("fill");
1458 fill = document.createElement("rvml:fill");
1460 if (gradient.dots.length) {
1462 fill.method = "none";
1463 fill.type = (gradient.type.toLowerCase() == "linear") ? "gradient" : "gradientTitle";
1464 if (typeof gradient.dots[0].color != "undefined") {
1465 fill.color = getRGB(gradient.dots[0].color).hex;
1467 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1468 fill.color2 = getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1471 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1472 if (gradient.dots[i].offset) {
1473 colors.push(gradient.dots[i].offset + " " + getRGB(gradient.dots[i].color).hex);
1476 var fillOpacity = typeof gradient.dots[0].opacity == "undefined" ? 1 : gradient.dots[0].opacity;
1477 var fillOpacity2 = typeof gradient.dots[gradient.dots.length - 1].opacity == "undefined" ? 1 : gradient.dots[gradient.dots.length - 1].opacity;
1479 fill.colors.value = colors.join(",");
1480 fillOpacity2 += fillOpacity;
1481 fillOpacity = fillOpacity2 - fillOpacity;
1482 fillOpacity2 -= fillOpacity;
1484 fill.setAttribute("opacity", fillOpacity);
1485 fill.setAttribute("opacity2", fillOpacity2);
1486 if (gradient.vector) {
1487 fill.angle = getAngle.apply(null, gradient.vector);
1489 if (gradient.type.toLowerCase() == "radial") {
1490 fill.focus = "100%";
1491 fill.focusposition = "0.5 0.5";
1495 var Element = function (node, group, vml) {
1515 Element.prototype.rotate = function (deg, cx, cy) {
1517 return this._.rt.deg;
1519 deg = deg.toString().split(separator);
1520 if (deg.length - 1) {
1521 cx = parseFloat(deg[1], 10);
1522 cy = parseFloat(deg[2], 10);
1524 deg = parseFloat(deg[0], 10);
1529 this._.rt.deg = deg;
1531 this._.rt.deg += deg;
1535 this.setBox(null, cx, cy);
1536 this.Group.style.rotation = this._.rt.deg;
1539 Element.prototype.setBox = function (params, cx, cy) {
1540 var gs = this.Group.style,
1541 os = (this.shape && this.shape.style) || this.node.style;
1542 for (var i in params) {
1543 this.attrs[i] = params[i];
1545 cx = cx || this._.rt.cx;
1546 cy = cy || this._.rt.cy;
1547 var attr = this.attrs, x, y, w, h;
1548 switch (this.type) {
1550 x = attr.cx - attr.r;
1551 y = attr.cy - attr.r;
1555 x = attr.cx - attr.rx;
1556 y = attr.cy - attr.ry;
1564 w = attr.width || 0;
1565 h = attr.height || 0;
1568 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("");
1569 x = attr.x - Math.round(this.W / 2);
1570 y = attr.y - this.H / 2;
1575 if (!this.attrs.path) {
1579 h = this.vml.height;
1581 var dim = pathDimensions(this.attrs.path),
1592 h = this.vml.height;
1595 cx = (cx == null) ? x + w / 2 : cx;
1596 cy = (cy == null) ? y + h / 2 : cy;
1597 var left = cx - this.vml.width / 2,
1598 top = cy - this.vml.height / 2;
1599 if (this.type == "path" || this.type == "text") {
1600 gs.left = left + "px";
1601 gs.top = top + "px";
1602 this.X = this.type == "text" ? x : -left;
1603 this.Y = this.type == "text" ? y : -top;
1606 os.left = -left + "px";
1607 os.top = -top + "px";
1609 gs.left = left + "px";
1610 gs.top = top + "px";
1615 gs.width = this.vml.width + "px";
1616 gs.height = this.vml.height + "px";
1617 os.left = x - left + "px";
1618 os.top = y - top + "px";
1619 os.width = w + "px";
1620 os.height = h + "px";
1623 Element.prototype.hide = function () {
1624 this.Group.style.display = "none";
1627 Element.prototype.show = function () {
1628 this.Group.style.display = "block";
1631 Element.prototype.translate = function (x, y) {
1632 if (x == undefined && y == undefined) {
1633 return {x: this._.tx, y: this._.ty};
1637 if (this.type == "path") {
1638 var path = this.attrs.path;
1639 path = pathToRelative(path);
1642 this.attr({path: path.join(" ")});
1644 this.setBox({x: this._.tx, y: this._.ty});
1647 Element.prototype.getBBox = function () {
1655 Element.prototype.remove = function () {
1656 this[0].parentNode.removeChild(this[0]);
1657 this.Group.parentNode.removeChild(this.Group);
1658 this.shape && this.shape.parentNode.removeChild(this.shape);
1660 Element.prototype.attr = function () {
1661 if (arguments.length == 1 && typeof arguments[0] == "string") {
1662 if (arguments[0] == "translation") {
1663 return this.translate();
1665 return this.attrs[arguments[0]];
1667 if (this.attrs && arguments.length == 1 && arguments[0] instanceof Array) {
1669 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1670 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1675 if (arguments.length == 2) {
1677 params[arguments[0]] = arguments[1];
1679 if (arguments.length == 1 && typeof arguments[0] == "object") {
1680 params = arguments[0];
1683 if (params.gradient) {
1684 addGrdientFill(this, params.gradient);
1686 if (params.text && this.type == "text") {
1687 this.node.string = params.text;
1690 this.node.id = params.id;
1692 setFillAndStroke(this, params);
1693 this.setBox(params);
1697 Element.prototype.toFront = function () {
1698 this.Group.parentNode.appendChild(this.Group);
1701 Element.prototype.toBack = function () {
1702 if (this.Group.parentNode.firstChild != this.Group) {
1703 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
1707 Element.prototype.insertAfter = function (element) {
1708 if (element.Group.nextSibling) {
1709 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
1711 element.Group.parentNode.appendChild(this.Group);
1715 Element.prototype.insertBefore = function (element) {
1716 element.Group.parentNode.insertBefore(this.Group, element.Group);
1719 var theCircle = function (vml, x, y, r) {
1720 var g = document.createElement("rvml:group");
1721 var o = document.createElement("rvml:oval");
1723 vml.canvas.appendChild(g);
1724 var res = new Element(o, g, vml);
1725 res.type = "circle";
1726 setFillAndStroke(res, {stroke: "#000", fill: "none"});
1730 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
1733 var theRect = function (vml, x, y, w, h, r) {
1734 var g = document.createElement("rvml:group");
1735 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect");
1737 o.arcsize = r / (Math.min(w, h));
1740 vml.canvas.appendChild(g);
1741 var res = new Element(o, g, vml);
1743 setFillAndStroke(res, {stroke: "#000"});
1749 res.setBox({x: x, y: y, width: w, height: h});
1752 var theEllipse = function (vml, x, y, rx, ry) {
1753 var g = document.createElement("rvml:group");
1754 var o = document.createElement("rvml:oval");
1756 vml.canvas.appendChild(g);
1757 var res = new Element(o, g, vml);
1758 res.type = "ellipse";
1759 setFillAndStroke(res, {stroke: "#000"});
1764 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
1767 var theImage = function (vml, src, x, y, w, h) {
1768 var g = document.createElement("rvml:group");
1769 var o = document.createElement("rvml:image");
1772 vml.canvas.appendChild(g);
1773 var res = new Element(o, g, vml);
1779 res.setBox({x: x, y: y, width: w, height: h});
1782 var theText = function (vml, x, y, text) {
1783 var g = document.createElement("rvml:group"), gs = g.style;
1784 var el = document.createElement("rvml:shape"), ol = el.style;
1785 var path = document.createElement("rvml:path"), ps = path.style;
1786 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
1787 path.textpathok = true;
1788 ol.width = vml.width;
1789 ol.height = vml.height;
1790 gs.position = "absolute";
1793 gs.width = vml.width;
1794 gs.height = vml.height;
1795 var o = document.createElement("rvml:textpath");
1798 o.coordsize = vml.coordsize;
1799 o.coordorigin = vml.coordorigin;
1801 el.appendChild(path);
1803 vml.canvas.appendChild(g);
1804 var res = new Element(o, g, vml);
1806 res.textpath = path;
1812 setFillAndStroke(res, {font: '10px "Arial"', stroke: "none", fill: "#000"});
1815 create = function () {
1816 // container, width, height
1817 // x, y, width, height
1818 var container, width, height;
1819 if (typeof arguments[0] == "string") {
1820 container = document.getElementById(arguments[0]);
1821 width = arguments[1];
1822 height = arguments[2];
1824 if (typeof arguments[0] == "object") {
1825 container = arguments[0];
1826 width = arguments[1];
1827 height = arguments[2];
1829 if (typeof arguments[0] == "number") {
1833 width = arguments[2];
1834 height = arguments[3];
1837 throw new Error("VML container not found.");
1839 if (!document.namespaces["rvml"]) {
1840 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
1841 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
1843 var c = document.createElement("div"),
1844 d = document.createElement("div"),
1845 r = paper.canvas = document.createElement("rvml:group"),
1846 cs = c.style, rs = r.style;
1847 paper.width = width;
1848 paper.height = height;
1849 width = width || "320px";
1850 height = height || "200px";
1851 cs.clip = "rect(0 " + width + " " + height + " 0)";
1854 cs.position = "absolute";
1855 rs.position = "absolute";
1856 d.style.position = "relative";
1859 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
1860 r.coordorigin = "0 0";
1862 var b = document.createElement("rvml:rect"), bs = b.style;
1863 bs.left = bs.top = 0;
1864 bs.width = rs.width;
1865 bs.height = rs.height;
1866 b.filled = b.stroked = "f";
1871 if (container == 1) {
1872 document.body.appendChild(d);
1873 cs.position = "absolute";
1885 cs.width = container.style.width = width;
1886 cs.height = container.style.height = height;
1887 if (container.firstChild) {
1888 container.insertBefore(d, container.firstChild);
1890 container.appendChild(d);
1893 for (var prop in paper) {
1894 container[prop] = paper[prop];
1896 for (var prop in R.fn) {
1897 if (!container[prop]) {
1898 container[prop] = R.fn[prop];
1901 container.clear = function () {
1903 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
1904 if (r.childNodes[i] != b) {
1905 todel.push(r.childNodes[i]);
1908 for (i = 0, ii = todel.length; i < ii; i++) {
1909 r.removeChild(todel[i]);
1914 paper.remove = function () {
1915 this.canvas.parentNode.parentNode.parentNode.removeChild(this.canvas.parentNode.parentNode);
1917 paper.safari = function () {};
1923 var addEvent = (function () {
1924 if (document.addEventListener) {
1925 return function (obj, type, fn, element) {
1926 obj.addEventListener(type, function (e) {
1927 return fn.call(element, e);
1930 } else if (document.attachEvent) {
1931 return function (obj, type, fn, element) {
1932 obj.attachEvent("on" + type, function (e) {
1933 return fn.call(element, e || window.event);
1938 var events = ["click", "dblclick", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup"];
1939 for (var i = events.length; i--;) {
1940 (function (eventName) {
1941 Element.prototype[eventName] = function (fn) {
1942 addEvent(this.node, eventName, fn, this);
1947 paper.circle = function (x, y, r) {
1948 return theCircle(this, x, y, r);
1950 paper.rect = function (x, y, w, h, r) {
1951 return theRect(this, x, y, w, h, r);
1953 paper.ellipse = function (x, y, rx, ry) {
1954 return theEllipse(this, x, y, rx, ry);
1956 paper.path = function (params, pathString) {
1957 return thePath(params, pathString, this);
1959 paper.image = function (src, x, y, w, h) {
1960 return theImage(this, src, x, y, w, h);
1962 paper.text = function (x, y, text) {
1963 return theText(this, x, y, text);
1965 paper.group = function () {
1968 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
1969 color = color || "#000";
1970 var p = this.path({stroke: color, "stroke-width": 1})
1971 .moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).lineTo(x, y),
1973 columnWidth = w / wv;
1974 for (var i = 1; i < hv; i++) {
1975 p.moveTo(x, y + i * rowHeight).lineTo(x + w, y + i * rowHeight);
1977 for (var i = 1; i < wv; i++) {
1978 p.moveTo(x + i * columnWidth, y).lineTo(x + i * columnWidth, y + h);
1982 paper.pathfinder = function (p, path) {
1984 M: function (x, y) {
1987 C: function (x1, y1, x2, y2, x3, y3) {
1988 this.curveTo(x1, y1, x2, y2, x3, y3);
1990 Q: function (x1, y1, x2, y2) {
1991 this.qcurveTo(x1, y1, x2, y2);
1993 T: function (x, y) {
1994 this.qcurveTo(x, y);
1996 S: function (x1, y1, x2, y2) {
1997 p.curveTo(x1, y1, x2, y2);
1999 L: function (x, y) {
2003 this.lineTo(x, this.last.y);
2006 this.lineTo(this.last.x, y);
2008 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2009 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2016 path = pathToAbsolute(path);
2017 for (var i = 0, ii = path.length; i < ii; i++) {
2018 var b = path[i].shift();
2019 commands[b].apply(p, path[i]);
2022 paper.set = function (itemsArray) {
2023 return new Set(itemsArray);
2025 Element.prototype.stop = function () {
2026 clearTimeout(this.animation_in_progress);
2028 Element.prototype.scale = function (x, y) {
2029 if (x == undefined && y == undefined) {
2030 return {x: this._.sx, y: this._.sy};
2034 if (x != 0 && !(x == 1 && y == 1)) {
2035 var dirx = Math.round(x / Math.abs(x)),
2036 diry = Math.round(y / Math.abs(y)),
2037 s = this.node.style;
2038 dx = this.attr("x");
2039 dy = this.attr("y");
2040 cx = this.attr("cx");
2041 cy = this.attr("cy");
2042 if (dirx != 1 || diry != 1) {
2043 if (this.transformations) {
2044 this.transformations[2] = "scale(" + [dirx, diry] + ")";
2045 this.node.setAttribute("transform", this.transformations.join(" "));
2046 dx = (dirx < 0) ? -this.attr("x") - this.attrs.width * x * dirx / this._.sx : this.attr("x");
2047 dy = (diry < 0) ? -this.attr("y") - this.attrs.height * y * diry / this._.sy : this.attr("y");
2048 cx = this.attr("cx") * dirx;
2049 cy = this.attr("cy") * diry;
2051 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=" + dirx +
2052 ", M12=0, M21=0, M22=" + diry +
2053 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')";
2054 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2057 if (this.transformations) {
2058 this.transformations[2] = "";
2059 this.node.setAttribute("transform", this.transformations.join(" "));
2061 this.node.filterMatrix = "";
2062 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2065 switch (this.type) {
2069 width: this.attrs.width * x * dirx / this._.sx,
2070 height: this.attrs.height * y * diry / this._.sy,
2078 rx: this.attrs.rx * x * dirx / this._.sx,
2079 ry: this.attrs.ry * y * diry / this._.sy,
2080 r: this.attrs.r * x * diry / this._.sx,
2086 var path = pathToRelative(Raphael.parsePathString(this.attr("path"))),
2088 dim = pathDimensions(this.attrs.path),
2089 dx = -dim.width * (x - 1) / 2,
2090 dy = -dim.height * (y - 1) / 2;
2091 for (var i = 0, ii = path.length; i < ii; i++) {
2092 if (path[i][0].toUpperCase() == "M" && skip) {
2097 if (path[i][0].toUpperCase() == "A") {
2098 path[i][path[i].length - 2] *= x * dirx;
2099 path[i][path[i].length - 1] *= y * diry;
2101 for (var j = 1, jj = path[i].length; j < jj; j++) {
2102 path[i][j] *= (j % 2) ? x * dirx / this._.sx : y * diry / this._.sy;
2106 var dim2 = pathDimensions(path),
2107 dx = dim.x + dim.width / 2 - dim2.x - dim2.width / 2,
2108 dy = dim.y + dim.height / 2 - dim2.y - dim2.height / 2;
2109 path = pathToRelative(path);
2113 this.attr({path: path.join(" ")});
2120 Element.prototype.animate = function (params, ms, callback) {
2121 clearTimeout(this.animation_in_progress);
2126 for (var attr in params) {
2127 if (attr in availableAnimAttrs) {
2128 from[attr] = this.attr(attr);
2129 if (typeof from[attr] == "undefined") {
2130 from[attr] = availableAttrs[attr];
2132 to[attr] = params[attr];
2133 switch (availableAnimAttrs[attr]) {
2135 diff[attr] = (to[attr] - from[attr]) / ms;
2138 from[attr] = getRGB(from[attr]);
2139 var toColour = getRGB(to[attr]);
2141 r: (toColour.r - from[attr].r) / ms,
2142 g: (toColour.g - from[attr].g) / ms,
2143 b: (toColour.b - from[attr].b) / ms
2147 var pathes = pathEqualiser(from[attr], to[attr]);
2148 from[attr] = pathes[0];
2149 to[attr] = pathes[1];
2151 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2152 diff[attr][i] = [0];
2153 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2154 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2159 var values = params[attr].toString().split(separator),
2160 from2 = from[attr].toString().split(separator);
2161 if (attr == "translation") {
2162 from[attr] = [0, 0];
2163 diff[attr] = [values[0] / ms, values[1] / ms];
2164 } else if (attr == "rotation") {
2165 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2166 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2168 from[attr] = from[attr].split(separator);
2169 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][0]) / ms];
2175 var start = new Date(),
2179 var time = (new Date()).getTime() - start.getTime(),
2183 for (var attr in from) {
2184 switch (availableAnimAttrs[attr]) {
2186 now = +from[attr] + time * diff[attr];
2190 Math.round(from[attr].r + time * diff[attr].r),
2191 Math.round(from[attr].g + time * diff[attr].g),
2192 Math.round(from[attr].b + time * diff[attr].b)
2197 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2198 now[i] = [from[attr][i][0]];
2199 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2200 now[i][j] = from[attr][i][j] + time * diff[attr][i][j];
2202 now[i] = now[i].join(" ");
2204 now = now.join(" ");
2207 if (attr == "translation") {
2208 var x = diff[attr][0] * (time - prev),
2209 y = diff[attr][1] * (time - prev);
2212 now = [x, y].join(" ");
2213 } else if (attr == "rotation") {
2214 now = +from[attr][0] + time * diff[attr][0];
2215 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2217 now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1]].join(" ");
2221 if (attr == "font-size") {
2222 set[attr] = now + "px";
2228 that.animation_in_progress = setTimeout(arguments.callee, 0);
2231 (t.x || t.y) && that.translate(-t.x, -t.y);
2233 clearTimeout(that.animation_in_progress);
2235 (typeof callback == "function") && callback.call(that);
2243 var Set = function (itemsArray) {
2245 if (itemsArray && itemsArray.constructor == Array) {
2246 for (var i = itemsArray.length; i--;) {
2247 if (itemsArray[i].constructor == Element) {
2248 this.items[this.items.length] = itemsArray[i];
2253 Set.prototype.push = function (item) {
2254 if (item && item.constructor == Element) {
2255 var len = this.items.length;
2256 this.items[len] = item;
2261 Set.prototype.pull = function (id) {
2262 var res = this.items.splice(id, 1)[0];
2263 for (var j = id, jj = this.items.length; j < jj; j++) {
2264 this[j] = this[j + 1];
2266 delete this[jj + 1];
2269 for (var method in Element.prototype) {
2270 Set.prototype[method] = (function (methodname) {
2271 return function () {
2272 for (var i = this.items.length; i--;) {
2273 this.items[i][methodname].apply(this.items[i], arguments);
2279 Set.prototype.getBBox = function () {
2280 var x = [], y = [], w = [], h = [];
2281 for (var i = this.items.length; i--;) {
2282 var box = this.items[i].getBBox();
2285 w.push(box.x + box.width);
2286 h.push(box.y + box.height);
2288 x = Math.min.apply(Math, x);
2289 y = Math.min.apply(Math, y);
2293 width: Math.max.apply(Math, w) - x,
2294 height: Math.max.apply(Math, h) - y