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 () {
12 return create.apply(R, arguments);
14 R.version = "0.7.dev";
15 R.type = (window.SVGAngle ? "SVG" : "VML");
16 R.svg = !(R.vml = R.type == "VML");
20 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},
21 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"};
23 R.toString = function () {
24 return "Your browser " + (this.vml ? "doesn't ": "") + "support" + (this.svg ? "s": "") +
25 " SVG.\nYou are running " + unescape("Rapha%EBl%20") + this.version;
28 var hsb2rgb = function (hue, saturation, brightness) {
29 if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
37 if (brightness == 0) {
38 return {r: 0, g: 0, b: 0, hex: "#000"};
40 if (hue > 1 || saturation > 1 || brightness > 1) {
45 var i = Math.floor(hue * 6),
47 p = brightness * (1 - saturation),
48 q = brightness * (1 - (saturation * f)),
49 t = brightness * (1 - (saturation * (1 - f)));
50 red = [brightness, q, p, p, t, brightness, brightness][i];
51 green = [t, brightness, brightness, q, p, p, t][i];
52 blue = [p, p, t, brightness, brightness, q, p][i];
53 var rgb = {r: red, g: green, b: blue};
57 var r = Math.round(red).toString(16);
61 var g = Math.round(green).toString(16);
65 var b = Math.round(blue).toString(16);
69 rgb.hex = "#" + r + g + b;
72 var getRGB = function (colour) {
73 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"};
74 if (colour.toString().toLowerCase() in htmlcolors) {
75 colour = htmlcolors[colour.toString().toLowerCase()];
78 return {r: 0, g: 0, b: 0, hex: "#000"};
80 if (colour == "none") {
81 return {r: -1, g: -1, b: -1, hex: "none"};
84 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);
87 blue = parseInt(rgb[2].substring(5), 16);
88 green = parseInt(rgb[2].substring(3, 5), 16);
89 red = parseInt(rgb[2].substring(1, 3), 16);
92 blue = parseInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
93 green = parseInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
94 red = parseInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
97 rgb = rgb[4].split(/\s*,\s*/);
98 red = parseFloat(rgb[0], 10);
99 green = parseFloat(rgb[1], 10);
100 blue = parseFloat(rgb[2], 10);
103 rgb = rgb[5].split(/\s*,\s*/);
104 red = parseFloat(rgb[0], 10) * 2.55;
105 green = parseFloat(rgb[1], 10) * 2.55;
106 blue = parseFloat(rgb[2], 10) * 2.55;
109 rgb = rgb[6].split(/\s*,\s*/);
110 red = parseFloat(rgb[0], 10);
111 green = parseFloat(rgb[1], 10);
112 blue = parseFloat(rgb[2], 10);
113 return hsb2rgb(red, green, blue);
116 rgb = rgb[7].split(/\s*,\s*/);
117 red = parseFloat(rgb[0], 10) * 2.55;
118 green = parseFloat(rgb[1], 10) * 2.55;
119 blue = parseFloat(rgb[2], 10) * 2.55;
120 return hsb2rgb(red, green, blue);
122 var rgb = {r: red, g: green, b: blue};
123 var r = Math.round(red).toString(16);
124 (r.length == 1) && (r = "0" + r);
125 var g = Math.round(green).toString(16);
126 (g.length == 1) && (g = "0" + g);
127 var b = Math.round(blue).toString(16);
128 (b.length == 1) && (b = "0" + b);
129 rgb.hex = "#" + r + g + b;
132 return {r: -1, g: -1, b: -1, hex: "none"};
135 R.getColor = function (value) {
136 var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
137 var rgb = hsb2rgb(start.h, start.s, start.b);
143 arguments.callee.start = {h: 0, s: 1, b: start.b};
148 R.getColor.reset = function () {
149 this.start = undefined;
152 R.parsePathString = function (pathString) {
153 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
155 toString = function () {
157 for (var i = 0, ii = this.length; i < ii; i++) {
158 res += this[i][0] + this[i].join(",").substring(2);
162 if (pathString.toString.toString() == toString.toString()) {
165 pathString.replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*\s*,?\s*)+)/ig, function (a, b, c) {
166 var params = [], name = b.toLowerCase();
167 c.replace(/(-?\d*\.?\d*)\s*,?\s*/ig, function (a, b) {
168 b && params.push(+b);
170 while (params.length >= paramCounts[name]) {
171 data.push([b].concat(params.splice(0, paramCounts[name])));
172 if (!paramCounts[name]) {
177 data.toString = toString;
180 var pathDimensions = function (path) {
181 var pathArray = path;
182 if (typeof path == "string") {
183 pathArray = Raphael.parsePathString(path);
185 pathArray = pathToAbsolute(pathArray);
186 var x = [], y = [], length = 0;
187 for (var i = 0, ii = pathArray.length; i < ii; i++) {
188 switch (pathArray[i][0]) {
192 x.push(pathArray[i][pathArray[i].length - 2]);
193 y.push(pathArray[i][pathArray[i].length - 1]);
196 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
198 x.push(pathArray[i][j]);
200 y.push(pathArray[i][j]);
205 var minx = Math.min.apply(Math, x),
206 miny = Math.min.apply(Math, y);
210 width: Math.max.apply(Math, x) - minx,
211 height: Math.max.apply(Math, y) - miny,
216 var pathToRelative = function (pathArray) {
218 if (typeof pathArray == "string") {
219 pathArray = R.parsePathString(pathArray);
221 var x = 0, y = 0, start = 0;
222 if (pathArray[0][0] == "M") {
226 res.push(pathArray[0]);
228 for (var i = start, ii = pathArray.length; i < ii; i++) {
230 if (pathArray[i][0] != pathArray[i][0].toLowerCase()) {
231 res[i][0] = pathArray[i][0].toLowerCase();
234 res[i][1] = pathArray[i][1];
235 res[i][2] = pathArray[i][2];
237 res[i][4] = pathArray[i][4];
238 res[i][5] = pathArray[i][5];
239 res[i][6] = +(pathArray[i][6] - x).toFixed(3);
240 res[i][7] = +(pathArray[i][7] - y).toFixed(3);
243 res[i][1] = +(pathArray[i][1] - y).toFixed(3);
246 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
247 res[i][j] = +(pathArray[i][j] - ((j % 2) ? x : y)).toFixed(3);
251 res[i] = pathArray[i];
257 x += res[i][res[i].length - 1];
260 y += res[i][res[i].length - 1];
263 x += res[i][res[i].length - 2];
264 y += res[i][res[i].length - 1];
267 res.toString = pathArray.toString;
270 var pathToAbsolute = function (pathArray) {
272 if (typeof pathArray == "string") {
273 pathArray = R.parsePathString(pathArray);
275 var x = 0, y = 0, start = 0;
276 if (pathArray[0][0] == "M") {
277 x = +pathArray[0][1];
278 y = +pathArray[0][2];
280 res[0] = pathArray[0];
282 for (var i = start, ii = pathArray.length; i < ii; i++) {
284 if (pathArray[i][0] != pathArray[i][0].toUpperCase()) {
285 res[i][0] = pathArray[i][0].toUpperCase();
288 res[i][1] = pathArray[i][1];
289 res[i][2] = pathArray[i][2];
291 res[i][4] = pathArray[i][4];
292 res[i][5] = pathArray[i][5];
293 res[i][6] = +(pathArray[i][6] + x).toFixed(3);
294 res[i][7] = +(pathArray[i][7] + y).toFixed(3);
297 res[i][1] = +pathArray[i][1] + y;
300 for (var j = 1, jj = pathArray[i].length; j < jj; j++) {
301 res[i][j] = +pathArray[i][j] + ((j % 2) ? x : y);
305 res[i] = pathArray[i];
317 x = res[i][res[i].length - 2];
318 y = res[i][res[i].length - 1];
321 res.toString = pathArray.toString;
324 var pathEqualiser = function (path1, path2) {
325 var data = [pathToAbsolute(R.parsePathString(path1)), pathToAbsolute(R.parsePathString(path2))],
326 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}],
327 processPath = function (path, d) {
337 var nx = d.x + (d.x - (d.bx || d.x));
338 var ny = d.y + (d.y - (d.by || d.y));
339 path = ["C", nx, ny, path[1], path[2], path[3], path[4]];
342 var nx = d.x + (d.x - (d.bx || d.x));
343 var ny = d.y + (d.y - (d.by || d.y));
344 path = ["Q", nx, ny, path[1], path[2]];
347 path = ["L", path[1], d.y];
350 path = ["L", d.x, path[1]];
353 path = ["L", d.X, d.Y];
358 edgeCases = function (a, b, i) {
359 if (data[a][i][0] == "M" && data[b][i][0] != "M") {
360 data[b].splice(i, 0, ["M", attrs[b].x, attrs[b].y]);
361 attrs[a].bx = data[a][i][data[a][i].length - 4] || 0;
362 attrs[a].by = data[a][i][data[a][i].length - 3] || 0;
363 attrs[a].x = data[a][i][data[a][i].length - 2];
364 attrs[a].y = data[a][i][data[a][i].length - 1];
366 } else if (data[a][i][0] == "L" && data[b][i][0] == "C") {
367 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]];
368 } else if (data[a][i][0] == "L" && data[b][i][0] == "Q") {
369 data[a][i] = ["Q", data[a][i][1], data[a][i][2], data[a][i][1], data[a][i][2]];
370 } else if (data[a][i][0] == "Q" && data[b][i][0] == "C") {
371 var x = data[b][i][data[b][i].length - 2];
372 var y = data[b][i][data[b][i].length - 1];
373 data[b].splice(i + 1, 0, ["Q", x, y, x, y]);
374 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
376 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
377 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
378 attrs[b].x = data[b][i][data[b][i].length - 2];
379 attrs[b].y = data[b][i][data[b][i].length - 1];
381 } else if (data[a][i][0] == "A" && data[b][i][0] == "C") {
382 var x = data[b][i][data[b][i].length - 2];
383 var y = data[b][i][data[b][i].length - 1];
384 data[b].splice(i + 1, 0, ["A", 0, 0, data[a][i][3], data[a][i][4], data[a][i][5], x, y]);
385 data[a].splice(i, 0, ["C", attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y, attrs[a].x, attrs[a].y]);
387 attrs[b].bx = data[b][i][data[b][i].length - 4] || 0;
388 attrs[b].by = data[b][i][data[b][i].length - 3] || 0;
389 attrs[b].x = data[b][i][data[b][i].length - 2];
390 attrs[b].y = data[b][i][data[b][i].length - 1];
392 } else if (data[a][i][0] == "U") {
393 data[a][i][0] = data[b][i][0];
394 for (var j = 1, jj = data[b][i].length; j < jj; j++) {
395 data[a][i][j] = (j % 2) ? attrs[a].x : attrs[a].y;
400 for (var i = 0; i < Math.max(data[0].length, data[1].length); i++) {
401 data[0][i] = processPath(data[0][i], attrs[0]);
402 data[1][i] = processPath(data[1][i], attrs[1]);
403 if (data[0][i][0] != data[1][i][0] && (edgeCases(0, 1, i) || edgeCases(1, 0, i))) {
406 attrs[0].bx = data[0][i][data[0][i].length - 4] || 0;
407 attrs[0].by = data[0][i][data[0][i].length - 3] || 0;
408 attrs[0].x = data[0][i][data[0][i].length - 2];
409 attrs[0].y = data[0][i][data[0][i].length - 1];
410 attrs[1].bx = data[1][i][data[1][i].length - 4] || 0;
411 attrs[1].by = data[1][i][data[1][i].length - 3] || 0;
412 attrs[1].x = data[1][i][data[1][i].length - 2];
413 attrs[1].y = data[1][i][data[1][i].length - 1];
420 var thePath = function (params, pathString, SVG) {
421 var el = document.createElementNS(SVG.svgns, "path");
422 el.setAttribute("fill", "none");
424 SVG.canvas.appendChild(el);
426 var p = new Element(el, SVG);
429 p.last = {x: 0, y: 0, bx: 0, by: 0};
430 p.absolutely = function () {
431 this.isAbsolute = true;
434 p.relatively = function () {
435 this.isAbsolute = false;
438 p.moveTo = function (x, y) {
439 var d = this.isAbsolute?"M":"m";
440 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
441 var oldD = this[0].getAttribute("d") || "";
442 (oldD == "M0,0") && (oldD = "");
443 this[0].setAttribute("d", oldD + d);
444 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
445 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
446 this.attrs.path = oldD + d;
449 p.lineTo = function (x, y) {
450 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
451 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
452 var d = this.isAbsolute?"L":"l";
453 d += parseFloat(x, 10).toFixed(3) + " " + parseFloat(y, 10).toFixed(3) + " ";
454 var oldD = this[0].getAttribute("d") || "";
455 this[0].setAttribute("d", oldD + d);
456 this.attrs.path = oldD + d;
459 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
460 var d = this.isAbsolute ? "A" : "a";
461 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(" ");
462 var oldD = this[0].getAttribute("d") || "";
463 this[0].setAttribute("d", oldD + d);
464 this.last.x = parseFloat(x, 10);
465 this.last.y = parseFloat(y, 10);
466 this.attrs.path = oldD + d;
469 p.cplineTo = function (x1, y1, w1) {
471 return this.lineTo(x1, y1);
474 var x = parseFloat(x1, 10);
475 var y = parseFloat(y1, 10);
476 var w = parseFloat(w1, 10);
477 var d = this.isAbsolute?"C":"c";
478 var attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
479 for (var i = 0, ii = attr.length; i < ii; i++) {
480 d += attr[i].toFixed(3) + " ";
482 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
483 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
484 this.last.bx = attr[2];
485 this.last.by = attr[3];
486 var oldD = this[0].getAttribute("d") || "";
487 this[0].setAttribute("d", oldD + d);
488 this.attrs.path = oldD + d;
492 p.curveTo = function () {
494 command = [0, 1, 2, 3, "s", 5, "c"];
496 var d = command[arguments.length];
497 if (this.isAbsolute) {
500 for (var i = 0, ii = arguments.length; i < ii; i++) {
501 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
503 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
504 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
505 this.last.bx = parseFloat(arguments[arguments.length - 4], 10);
506 this.last.by = parseFloat(arguments[arguments.length - 3], 10);
507 var oldD = this.node.getAttribute("d") || "";
508 this.node.setAttribute("d", oldD + d);
509 this.attrs.path = oldD + d;
512 p.qcurveTo = function () {
514 command = [0, 1, "t", 3, "q"];
516 var d = command[arguments.length];
517 if (this.isAbsolute) {
520 for (var i = 0, ii = arguments.length; i < ii; i++) {
521 d += parseFloat(arguments[i], 10).toFixed(3) + " ";
523 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2], 10);
524 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1], 10);
525 if (arguments.length != 2) {
526 this.last.qx = parseFloat(arguments[arguments.length - 4], 10);
527 this.last.qy = parseFloat(arguments[arguments.length - 3], 10);
529 var oldD = this.node.getAttribute("d") || "";
530 this.node.setAttribute("d", oldD + d);
531 this.attrs.path = oldD + d;
534 p.addRoundedCorner = function (r, dir) {
535 var R = .5522 * r, rollback = this.isAbsolute, o = this;
538 rollback = function () {
542 rollback = function () {};
548 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
551 o.curveTo(-R, 0, -r, r - R, -r, r);
558 o.curveTo(R, 0, r, -(r - R), r, -r);
561 o.curveTo(R, 0, r, r - R, r, r);
568 o.curveTo(0, -R, -(R - r), -r, r, -r);
571 o.curveTo(0, -R, R - r, -r, -r, -r);
578 o.curveTo(0, R, -(R - r), r, r, r);
581 o.curveTo(0, R, R - r, r, -r, r);
586 actions[dir[0]]()[dir[1]]();
590 p.andClose = function () {
591 var oldD = this[0].getAttribute("d") || "";
592 this[0].setAttribute("d", oldD + "Z ");
593 this.attrs.path = oldD + "Z ";
597 p.attrs.path = "" + pathString;
599 paper.pathfinder(p, p.attrs.path);
602 setFillAndStroke(p, params);
606 var addGrdientFill = function (o, gradient, SVG) {
607 var el = document.createElementNS(SVG.svgns, gradient.type + "Gradient");
608 el.id = "raphael-gradient-" + Raphael.idGenerator++;
609 if (gradient.vector && gradient.vector.length) {
610 el.setAttribute("x1", gradient.vector[0]);
611 el.setAttribute("y1", gradient.vector[1]);
612 el.setAttribute("x2", gradient.vector[2]);
613 el.setAttribute("y2", gradient.vector[3]);
615 SVG.defs.appendChild(el);
616 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
617 var stop = document.createElementNS(SVG.svgns, "stop");
618 stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
619 stop.setAttribute("stop-color", getRGB(gradient.dots[i].color).hex || "#fff");
620 if (typeof gradient.dots[i].opacity != "undefined") {
621 stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
623 el.appendChild(stop);
625 o.setAttribute("fill", "url(#" + el.id + ")");
627 var updatePosition = function (o) {
629 var bbox = o.node.getBBox();
630 o.pattern.setAttribute("patternTransform", "translate(" + [bbox.x, bbox.y].join(",") + ")");
633 var setFillAndStroke = function (o, params) {
638 "-..": [3, 1, 1, 1, 1, 1],
644 "--..": [8, 3, 1, 3, 1, 3]
646 addDashes = function (o, value) {
647 value = dasharray[value.toString().toLowerCase()];
649 var width = o.attrs["stroke-width"] || "1",
650 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
652 for (var i = 0, ii = value.length; i < ii; i++) {
653 dashes.push(value[i] * width + ((i % 2) ? 1 : -1) * butt);
655 value = dashes.join(",");
656 o.node.setAttribute("stroke-dasharray", value);
659 for (var att in params) {
660 var value = params[att];
661 o.attrs[att] = value;
664 if (o.type == "path") {
665 o.node.setAttribute("d", "M0,0");
666 paper.pathfinder(o, value);
671 o.node.setAttribute(att, value);
677 o.node.setAttribute(att, value);
681 o.node.setAttribute(att, value);
684 o.node.setAttribute(att, value);
687 addGrdientFill(o.node, value, o.svg);
690 o.node.style.strokeWidth = value;
691 // Need following line for Firefox
692 o.node.setAttribute(att, value);
693 if (o.attrs["stroke-dasharray"]) {
694 addDashes(o, o.attrs["stroke-dasharray"]);
697 case "stroke-dasharray":
701 if (o.type == "text") {
702 o.node.childNodes.length && o.node.removeChild(o.node.firstChild);
703 o.node.appendChild(document.createTextNode(value));
707 o.rotate(value, true);
710 var xy = value.split(/[, ]+/);
711 o.translate(xy[0], xy[1]);
714 var xy = value.split(/[, ]+/);
715 o.scale(xy[0], xy[1]);
718 var isURL = value.match(/^url\(([^\)]+)\)$/i);
720 var el = document.createElementNS(o.svg.svgns, "pattern");
721 var ig = document.createElementNS(o.svg.svgns, "image");
722 el.id = "raphael-pattern-" + Raphael.idGenerator++;
723 el.setAttribute("x", 0);
724 el.setAttribute("y", 0);
725 el.setAttribute("patternUnits", "userSpaceOnUse");
726 ig.setAttribute("x", 0);
727 ig.setAttribute("y", 0);
728 ig.setAttributeNS(o.svg.xlink, "href", isURL[1]);
731 var img = document.createElement("img");
732 img.style.position = "absolute";
733 img.style.top = "-9999em";
734 img.style.left = "-9999em";
735 img.onload = function () {
736 el.setAttribute("width", this.offsetWidth);
737 el.setAttribute("height", this.offsetHeight);
738 ig.setAttribute("width", this.offsetWidth);
739 ig.setAttribute("height", this.offsetHeight);
740 document.body.removeChild(this);
743 document.body.appendChild(img);
745 o.svg.defs.appendChild(el);
746 o.node.style.fill = "url(#" + el.id + ")";
747 o.node.setAttribute("fill", "url(#" + el.id + ")");
753 o.node.style[att] = getRGB(value).hex;
754 // Need following line for Firefox
755 o.node.setAttribute(att, getRGB(value).hex);
758 var cssrule = att.replace(/(\-.)/g, function (w) {
759 return w.substring(1).toUpperCase();
761 o.node.style[cssrule] = value;
762 // Need following line for Firefox
763 o.node.setAttribute(att, value);
768 var Element = function (node, svg) {
774 this.attrs = this.attrs || {};
775 this.transformations = []; // rotate, translate, scale
779 rt: {deg: 0, x: 0, y: 0},
784 Element.prototype.translate = function (x, y) {
785 if (x == undefined && y == undefined) {
786 return {x: this._.tx, y: this._.ty};
793 this.attr({cx: this.attrs.cx + x, cy: this.attrs.cy + y});
798 this.attr({x: this.attrs.x + x, y: this.attrs.y + y});
801 var path = pathToRelative(this.attrs.path);
804 this.attr({path: path.join(" ")});
809 Element.prototype.rotate = function (deg, cx, cy) {
810 if (deg == undefined) {
811 return this._.rt.deg;
813 var bbox = this.getBBox();
814 deg = deg.toString().split(/[, ]+/);
815 if (deg.length - 1) {
816 cx = parseFloat(deg[1], 10);
817 cy = parseFloat(deg[2], 10);
819 deg = parseFloat(deg[0], 10);
823 this._.rt.deg += deg;
828 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
829 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
831 this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
833 this.transformations[0] = "";
835 this.node.setAttribute("transform", this.transformations.join(" "));
838 Element.prototype.hide = function () {
839 this.node.style.display = "none";
842 Element.prototype.show = function () {
843 this.node.style.display = "block";
846 Element.prototype.remove = function () {
847 this.node.parentNode.removeChild(this.node);
849 Element.prototype.getBBox = function () {
850 return this.node.getBBox();
852 Element.prototype.attr = function () {
853 if (arguments.length == 1 && typeof arguments[0] == "string") {
854 if (arguments[0] == "translation") {
855 return this.translate();
857 return this.attrs[arguments[0]];
859 if (arguments.length == 1 && arguments[0] instanceof Array) {
861 for (var j in arguments[0]) {
862 values[arguments[0][j]] = this.attrs[arguments[0][j]];
866 if (arguments.length == 2) {
868 params[arguments[0]] = arguments[1];
869 setFillAndStroke(this, params);
870 } else if (arguments.length == 1 && typeof arguments[0] == "object") {
871 setFillAndStroke(this, arguments[0]);
875 Element.prototype.toFront = function () {
876 this.node.parentNode.appendChild(this.node);
879 Element.prototype.toBack = function () {
880 if (this.node.parentNode.firstChild != this.node) {
881 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
885 Element.prototype.insertAfter = function (element) {
886 if (element.node.nextSibling) {
887 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
889 element.node.parentNode.appendChild(this.node);
893 Element.prototype.insertBefore = function (element) {
894 element.node.parentNode.insertBefore(this.node, element.node);
897 var theCircle = function (svg, x, y, r) {
898 var el = document.createElementNS(svg.svgns, "circle");
899 el.setAttribute("cx", x);
900 el.setAttribute("cy", y);
901 el.setAttribute("r", r);
902 el.setAttribute("fill", "none");
903 el.setAttribute("stroke", "#000");
905 svg.canvas.appendChild(el);
907 var res = new Element(el, svg);
908 res.attrs = res.attrs || {};
912 res.attrs.stroke = "#000";
916 var theRect = function (svg, x, y, w, h, r) {
917 var el = document.createElementNS(svg.svgns, "rect");
918 el.setAttribute("x", x);
919 el.setAttribute("y", y);
920 el.setAttribute("width", w);
921 el.setAttribute("height", h);
923 el.setAttribute("rx", r);
924 el.setAttribute("ry", r);
926 el.setAttribute("fill", "none");
927 el.setAttribute("stroke", "#000");
929 svg.canvas.appendChild(el);
931 var res = new Element(el, svg);
932 res.attrs = res.attrs || {};
936 res.attrs.height = h;
937 res.attrs.stroke = "#000";
939 res.attrs.rx = res.attrs.ry = r;
944 var theEllipse = function (svg, x, y, rx, ry) {
945 var el = document.createElementNS(svg.svgns, "ellipse");
946 el.setAttribute("cx", x);
947 el.setAttribute("cy", y);
948 el.setAttribute("rx", rx);
949 el.setAttribute("ry", ry);
950 el.setAttribute("fill", "none");
951 el.setAttribute("stroke", "#000");
953 svg.canvas.appendChild(el);
955 var res = new Element(el, svg);
956 res.attrs = res.attrs || {};
961 res.attrs.stroke = "#000";
962 res.type = "ellipse";
965 var theImage = function (svg, src, x, y, w, h) {
966 var el = document.createElementNS(svg.svgns, "image");
967 el.setAttribute("x", x);
968 el.setAttribute("y", y);
969 el.setAttribute("width", w);
970 el.setAttribute("height", h);
971 el.setAttribute("preserveAspectRatio", "none");
972 el.setAttributeNS(svg.xlink, "href", src);
974 svg.canvas.appendChild(el);
976 var res = new Element(el, svg);
977 res.attrs = res.attrs || {};
981 res.attrs.height = h;
985 var theText = function (svg, x, y, text) {
986 var el = document.createElementNS(svg.svgns, "text");
987 el.setAttribute("x", x);
988 el.setAttribute("y", y);
989 el.setAttribute("text-anchor", "middle");
991 el.appendChild(document.createTextNode(text));
994 svg.canvas.appendChild(el);
996 var res = new Element(el, svg);
997 res.attrs = res.attrs || {};
1001 setFillAndStroke(res, {font: '10px "Arial"', stroke: "none", fill: "#000"});
1004 var theGroup = function (svg) {
1005 var el = document.createElementNS(svg.svgns, "g");
1007 svg.canvas.appendChild(el);
1009 var i = new Element(el, svg);
1010 for (var f in svg) {
1011 if (f[0] != "_" && typeof svg[f] == "function") {
1012 i[f] = (function (f) {
1013 return function () {
1014 var e = svg[f].apply(svg, arguments);
1015 el.appendChild(e[0]);
1024 create = function () {
1025 // container, width, height
1026 // x, y, width, height
1027 if (typeof arguments[0] == "string") {
1028 var container = document.getElementById(arguments[0]);
1029 var width = arguments[1];
1030 var height = arguments[2];
1032 if (typeof arguments[0] == "object") {
1033 var container = arguments[0];
1034 var width = arguments[1];
1035 var height = arguments[2];
1037 if (typeof arguments[0] == "number") {
1041 width = arguments[2],
1042 height = arguments[3];
1045 throw new Error("SVG container not found.");
1047 paper.canvas = document.createElementNS(paper.svgns, "svg");
1048 paper.canvas.setAttribute("width", width || 320);
1049 paper.width = width || 320;
1050 paper.canvas.setAttribute("height", height || 200);
1051 paper.height = height || 200;
1052 if (container == 1) {
1053 document.body.appendChild(paper.canvas);
1054 paper.canvas.style.position = "absolute";
1055 paper.canvas.style.left = x + "px";
1056 paper.canvas.style.top = y + "px";
1058 if (container.firstChild) {
1059 container.insertBefore(paper.canvas, container.firstChild);
1061 container.appendChild(paper.canvas);
1065 canvas: paper.canvas,
1066 clear: function () {
1067 while (this.canvas.firstChild) {
1068 this.canvas.removeChild(this.canvas.firstChild);
1070 this.defs = document.createElementNS(paper.svgns, "defs");
1071 this.canvas.appendChild(this.defs);
1074 for (var prop in paper) {
1075 if (prop != "create") {
1076 container[prop] = paper[prop];
1079 for (var prop in R.fn) {
1080 if (!container[prop]) {
1081 container[prop] = R.fn[prop];
1087 paper.remove = function () {
1088 this.canvas.parentNode.removeChild(this.canvas);
1090 paper.svgns = "http://www.w3.org/2000/svg";
1091 paper.xlink = "http://www.w3.org/1999/xlink";
1092 paper.safari = function () {
1093 if (navigator.vendor == "Apple Computer, Inc.") {
1094 var rect = this.rect(-this.width, -this.height, this.width * 3, this.height * 3).attr({stroke: "none"});
1095 setTimeout(function () {rect.remove();}, 0);
1102 thePath = function (params, pathString, VML) {
1103 var g = document.createElement("rvml:group"), gl = g.style;
1104 gl.position = "absolute";
1107 gl.width = VML.width + "px";
1108 gl.height = VML.height + "px";
1109 var el = document.createElement("rvml:shape"), ol = el.style;
1110 ol.width = VML.width + "px";
1111 ol.height = VML.height + "px";
1113 if (params["class"]) {
1114 el.className = params["class"];
1116 el.coordsize = this.coordsize;
1117 el.coordorigin = this.coordorigin;
1119 VML.canvas.appendChild(g);
1120 var p = new Element(el, g, VML);
1121 p.isAbsolute = true;
1124 p.last = {x: 0, y: 0, bx: 0, by: 0, isAbsolute: true};
1126 p.absolutely = function () {
1127 this.isAbsolute = true;
1130 p.relatively = function () {
1131 this.isAbsolute = false;
1134 p.moveTo = function (x, y) {
1135 var d = this.isAbsolute?"m":"t";
1136 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
1137 this.node.path = this.Path += d;
1138 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
1139 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
1140 this.last.isAbsolute = this.isAbsolute;
1141 this.attrs.path += (this.isAbsolute ? "M" : "m") + [x, y];
1144 p.lineTo = function (x, y) {
1145 var d = this.isAbsolute?"l":"r";
1146 d += Math.round(parseFloat(x, 10)) + " " + Math.round(parseFloat(y, 10));
1147 this[0].path = this.Path += d;
1148 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x, 10);
1149 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y, 10);
1150 this.last.isAbsolute = this.isAbsolute;
1151 this.attrs.path += (this.isAbsolute ? "L" : "l") + [x, y];
1154 p.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x2, y2) {
1155 // for more information of where this math came from visit:
1156 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1157 x2 = (this.isAbsolute ? 0 : this.last.x) + x2;
1158 y2 = (this.isAbsolute ? 0 : this.last.y) + y2;
1159 var x1 = this.last.x,
1163 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1164 Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * y * y - ry * ry * x * x) / (rx * rx * y * y + ry * ry * x * x)),
1165 cx = k * rx * y / ry + (x1 + x2) / 2,
1166 cy = k * -ry * x / rx + (y1 + y2) / 2,
1167 d = sweep_flag ? (this.isAbsolute ? "wa" : "wr") : (this.isAbsolute ? "at" : "ar"),
1168 left = Math.round(cx - rx),
1169 top = Math.round(cy - ry);
1170 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(", ");
1171 this.node.path = this.Path += d;
1172 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x2, 10);
1173 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y2, 10);
1174 this.last.isAbsolute = this.isAbsolute;
1175 this.attrs.path += (this.isAbsolute ? "A" : "a") + [rx, ry, 0, large_arc_flag, sweep_flag, x2, y2];
1178 p.cplineTo = function (x1, y1, w1) {
1180 return this.lineTo(x1, y1);
1182 var x = Math.round(Math.round(parseFloat(x1, 10) * 100) / 100),
1183 y = Math.round(Math.round(parseFloat(y1, 10) * 100) / 100),
1184 w = Math.round(Math.round(parseFloat(w1, 10) * 100) / 100),
1185 d = this.isAbsolute ? "c" : "v",
1186 attr = [Math.round(this.last.x) + w, Math.round(this.last.y), x - w, y, x, y],
1187 svgattr = [this.last.x + w1, this.last.y, x1 - w1, y1, x1, y1];
1188 d += attr.join(" ") + " ";
1189 this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
1190 this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
1191 this.last.bx = attr[2];
1192 this.last.by = attr[3];
1193 this.node.path = this.Path += d;
1194 this.attrs.path += (this.isAbsolute ? "C" : "c") + svgattr;
1198 p.curveTo = function () {
1199 var d = this.isAbsolute ? "c" : "v";
1200 if (arguments.length == 6) {
1201 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1202 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1203 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[4], 10);
1204 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[5], 10);
1205 d += [Math.round(parseFloat(arguments[0], 10)),
1206 Math.round(parseFloat(arguments[1], 10)),
1207 Math.round(parseFloat(arguments[2], 10)),
1208 Math.round(parseFloat(arguments[3], 10)),
1209 Math.round(parseFloat(arguments[4], 10)),
1210 Math.round(parseFloat(arguments[5], 10))].join(" ") + " ";
1211 this.last.isAbsolute = this.isAbsolute;
1212 this.attrs.path += (this.isAbsolute ? "C" : "c") + Array.prototype.splice.call(arguments, 0, arguments.length);
1214 if (arguments.length == 4) {
1215 var bx = this.last.x * 2 - this.last.bx;
1216 var by = this.last.y * 2 - this.last.by;
1217 this.last.bx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
1218 this.last.by = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
1219 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1220 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1221 d += [Math.round(bx), Math.round(by),
1222 Math.round(parseFloat(arguments[0], 10)),
1223 Math.round(parseFloat(arguments[1], 10)),
1224 Math.round(parseFloat(arguments[2], 10)),
1225 Math.round(parseFloat(arguments[3], 10))].join(" ") + " ";
1226 this.attrs.path += (this.isAbsolute ? "S" : "s") + Array.prototype.splice.call(arguments, 0, arguments.length);
1228 this.node.path = this.Path += d;
1231 p.qcurveTo = function () {
1233 if (arguments.length == 4) {
1234 this.last.qx = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[0], 10);
1235 this.last.qy = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[1], 10);
1236 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1237 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1238 d += [Math.round(this.last.qx),
1239 Math.round(this.last.qy),
1240 Math.round(this.last.x),
1241 Math.round(this.last.y)].join(" ") + " ";
1242 this.last.isAbsolute = this.isAbsolute;
1243 this.attrs.path += (this.isAbsolute ? "Q" : "q") + Array.prototype.splice.call(arguments, 0, arguments.length);
1245 if (arguments.length == 2) {
1246 this.last.qx = this.last.x * 2 - this.last.qx;
1247 this.last.qy = this.last.y * 2 - this.last.qy;
1248 this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[2], 10);
1249 this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[3], 10);
1250 d += [Math.round(this.last.qx),
1251 Math.round(this.last.qy),
1252 Math.round(this.last.x),
1253 Math.round(this.last.y)].join(" ") + " ";
1254 this.attrs.path += (this.isAbsolute ? "T" : "t") + Array.prototype.splice.call(arguments, 0, arguments.length);
1256 this.node.path = this.Path += d;
1257 this.path.push({type: "qcurve", arg: [].slice.call(arguments, 0), pos: this.isAbsolute});
1260 p.addRoundedCorner = function (r, dir) {
1261 var R = .5522 * r, rollback = this.isAbsolute, o = this;
1264 rollback = function () {
1268 rollback = function () {};
1274 o.curveTo(-R, 0, -r, -(r - R), -r, -r);
1277 o.curveTo(-R, 0, -r, r - R, -r, r);
1284 o.curveTo(R, 0, r, -(r - R), r, -r);
1287 o.curveTo(R, 0, r, r - R, r, r);
1294 o.curveTo(0, -R, -(R - r), -r, r, -r);
1297 o.curveTo(0, -R, R - r, -r, -r, -r);
1304 o.curveTo(0, R, -(R - r), r, r, r);
1307 o.curveTo(0, R, R - r, r, -r, r);
1312 actions[dir.charAt(0)]()[dir.charAt(1)]();
1316 p.andClose = function () {
1317 this.node.path = (this.Path += "x e");
1318 this.attrs.path += "z";
1324 paper.pathfinder(p, "" + pathString);
1327 setFillAndStroke(p, params);
1328 if (params.gradient) {
1329 addGrdientFill(p, params.gradient);
1333 var setFillAndStroke = function (o, params) {
1334 var s = o.node.style,
1336 o.attrs = o.attrs || {};
1337 for (var par in params) {
1338 o.attrs[par] = params[par];
1340 if (params.path && o.type == "path") {
1343 paper.pathfinder(o, params.path);
1345 if (params.rotation != null) {
1346 o.rotate(params.rotation, true);
1348 if (params.translation) {
1349 var xy = params.translation.split(/[, ]+/);
1350 o.translate(xy[0], xy[1]);
1353 var xy = params.scale.split(/[, ]+/);
1354 o.scale(xy[0], xy[1]);
1356 if (o.type == "image" && params.opacity) {
1357 o.node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1358 o.node.style.filter = (o.node.filterMatrix || "") + (o.node.filterOpacity || "");
1360 params.font && (s.font = params.font);
1361 params["font-family"] && (s.fontFamily = params["font-family"]);
1362 params["font-size"] && (s.fontSize = params["font-size"]);
1363 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1364 params["font-style"] && (s.fontStyle = params["font-style"]);
1365 if (typeof params.opacity != "undefined" || typeof params["stroke-width"] != "undefined" || typeof params.fill != "undefined" || typeof params.stroke != "undefined") {
1366 o = o.shape || o.node;
1367 var fill = (o.getElementsByTagName("fill") && o.getElementsByTagName("fill")[0]) || document.createElement("rvml:fill");
1368 if ("fill-opacity" in params || "opacity" in params) {
1369 fill.opacity = ((params["fill-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
1374 if (fill.on == undefined || params.fill == "none") {
1377 if (fill.on && params.fill) {
1378 var isURL = params.fill.match(/^url\(([^\)]+)\)$/i);
1380 fill.src = isURL[1];
1383 fill.color = getRGB(params.fill).hex;
1385 fill.type = "solid";
1388 o.appendChild(fill);
1389 var stroke = (o.getElementsByTagName("stroke") && o.getElementsByTagName("stroke")[0]) || document.createElement("rvml:stroke");
1390 if ((params.stroke && params.stroke != "none") || params["stroke-width"] || params["stroke-opacity"] || params["stroke-dasharray"]) {
1393 if (params.stroke == "none" || typeof stroke.on == "undefined") {
1396 if (stroke.on && params.stroke) {
1397 stroke.color = getRGB(params.stroke).hex;
1399 stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
1400 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1401 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1402 params["stroke-linecap"] && (stroke.endcap = {butt: "flat", square: "square", round: "round"}[params["stroke-linecap"]] || "miter");
1403 params["stroke-width"] && (stroke.weight = (parseFloat(params["stroke-width"], 10) || 1) * 12 / 16);
1404 if (params["stroke-dasharray"]) {
1408 "-.": "shortdashdot",
1409 "-..": "shortdashdotdot",
1414 "--.": "longdashdot",
1415 "--..": "longdashdotdot"
1417 stroke.dashstyle = dasharray[params["stroke-dasharray"]] || "";
1419 o.appendChild(stroke);
1421 if (res.type == "text") {
1422 var span = document.createElement("span"),
1424 res.attrs.font && (s.font = res.attrs.font);
1425 res.attrs["font-family"] && (s.fontFamily = res.attrs["font-family"]);
1426 res.attrs["font-size"] && (s.fontSize = res.attrs["font-size"]);
1427 res.attrs["font-weight"] && (s.fontWeight = res.attrs["font-weight"]);
1428 res.attrs["font-style"] && (s.fontStyle = res.attrs["font-style"]);
1429 res.node.parentNode.appendChild(span);
1430 span.innerText = res.node.string;
1431 res.W = res.attrs.w = span.offsetWidth;
1432 res.H = res.attrs.h = span.offsetHeight;
1433 res.X = res.attrs.x - Math.round(res.W / 2);
1434 res.Y = res.attrs.y - Math.round(res.H / 2);
1435 res.node.parentNode.removeChild(span);
1438 var getAngle = function (a, b, c, d) {
1439 var angle = Math.round(Math.atan((parseFloat(c, 10) - parseFloat(a, 10)) / (parseFloat(d, 10) - parseFloat(b, 10))) * 57.29) || 0;
1440 if (!angle && parseFloat(a, 10) < parseFloat(b, 10)) {
1449 var addGrdientFill = function (o, gradient) {
1450 o.attrs = o.attrs || {};
1451 o.attrs.gradient = gradient;
1452 o = o.shape || o[0];
1453 var fill = o.getElementsByTagName("fill");
1457 fill = document.createElement("rvml:fill");
1459 if (gradient.dots.length) {
1461 fill.method = "none";
1462 fill.type = (gradient.type.toLowerCase() == "linear") ? "gradient" : "gradientTitle";
1463 if (typeof gradient.dots[0].color != "undefined") {
1464 fill.color = getRGB(gradient.dots[0].color).hex;
1466 if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
1467 fill.color2 = getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
1470 for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
1471 if (gradient.dots[i].offset) {
1472 colors.push(gradient.dots[i].offset + " " + getRGB(gradient.dots[i].color).hex);
1475 var fillOpacity = typeof gradient.dots[0].opacity == "undefined" ? 1 : gradient.dots[0].opacity;
1476 var fillOpacity2 = typeof gradient.dots[gradient.dots.length - 1].opacity == "undefined" ? 1 : gradient.dots[gradient.dots.length - 1].opacity;
1478 fill.colors.value = colors.join(",");
1479 fillOpacity2 += fillOpacity;
1480 fillOpacity = fillOpacity2 - fillOpacity;
1481 fillOpacity2 -= fillOpacity;
1483 fill.setAttribute("opacity", fillOpacity);
1484 fill.setAttribute("opacity2", fillOpacity2);
1485 if (gradient.vector) {
1486 fill.angle = getAngle.apply(null, gradient.vector);
1488 if (gradient.type.toLowerCase() == "radial") {
1489 fill.focus = "100%";
1490 fill.focusposition = "0.5 0.5";
1494 var Element = function (node, group, vml) {
1514 Element.prototype.rotate = function (deg, cx, cy) {
1518 deg = deg.toString().split(/[, ]+/);
1519 if (deg.length - 1) {
1520 cx = parseFloat(deg[1], 10);
1521 cy = parseFloat(deg[2], 10);
1523 deg = parseFloat(deg[0], 10);
1532 this.setBox(null, cx, cy);
1533 this.Group.style.rotation = this._.rt;
1536 Element.prototype.setBox = function (params, cx, cy) {
1537 var gs = this.Group.style,
1538 os = (this.shape && this.shape.style) || this.node.style;
1539 for (var i in params) {
1540 this.attrs[i] = params[i];
1542 var attr = this.attrs, x, y, w, h;
1543 switch (this.type) {
1545 x = attr.cx - attr.r;
1546 y = attr.cy - attr.r;
1550 x = attr.cx - attr.rx;
1551 y = attr.cy - attr.ry;
1559 w = attr.width || 0;
1560 h = attr.height || 0;
1563 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("");
1564 x = attr.x - Math.round(this.W / 2);
1565 y = attr.y - this.H / 2;
1570 if (!this.attrs.path) {
1574 h = this.vml.height;
1576 var dim = pathDimensions(this.attrs.path),
1587 h = this.vml.height;
1590 cx = (cx == null) ? x + w / 2 : cx;
1591 cy = (cy == null) ? y + h / 2 : cy;
1592 var left = cx - this.vml.width / 2,
1593 top = cy - this.vml.height / 2;
1594 if (this.type == "path" || this.type == "text") {
1595 gs.left = left + "px";
1596 gs.top = top + "px";
1597 this.X = this.type == "text" ? x : -left;
1598 this.Y = this.type == "text" ? y : -top;
1601 os.left = -left + "px";
1602 os.top = -top + "px";
1604 gs.left = left + "px";
1605 gs.top = top + "px";
1610 gs.width = this.vml.width + "px";
1611 gs.height = this.vml.height + "px";
1612 os.left = x - left + "px";
1613 os.top = y - top + "px";
1614 os.width = w + "px";
1615 os.height = h + "px";
1618 Element.prototype.hide = function () {
1619 this.Group.style.display = "none";
1622 Element.prototype.show = function () {
1623 this.Group.style.display = "block";
1626 Element.prototype.translate = function (x, y) {
1627 if (x == undefined && y == undefined) {
1628 return {x: this._.tx, y: this._.ty};
1632 if (this.type == "path") {
1633 var path = this.attrs.path;
1634 path = pathToRelative(path);
1637 this.attr({path: path.join(" ")});
1639 this.setBox({x: this._.tx, y: this._.ty});
1642 Element.prototype.getBBox = function () {
1650 Element.prototype.remove = function () {
1651 this[0].parentNode.removeChild(this[0]);
1652 this.Group.parentNode.removeChild(this.Group);
1653 this.shape && this.shape.parentNode.removeChild(this.shape);
1655 Element.prototype.attr = function () {
1656 if (arguments.length == 1 && typeof arguments[0] == "string") {
1657 if (arguments[0] == "translation") {
1658 return this.translate();
1660 return this.attrs[arguments[0]];
1662 if (this.attrs && arguments.length == 1 && arguments[0] instanceof Array) {
1664 for (var i = 0, ii = arguments[0].length; i < ii; i++) {
1665 values[arguments[0][i]] = this.attrs[arguments[0][i]];
1670 if (arguments.length == 2) {
1672 params[arguments[0]] = arguments[1];
1674 if (arguments.length == 1 && typeof arguments[0] == "object") {
1675 params = arguments[0];
1678 if (params.gradient) {
1679 addGrdientFill(this, params.gradient);
1681 if (params.text && this.type == "text") {
1682 this.node.string = params.text;
1685 this.node.id = params.id;
1687 setFillAndStroke(this, params);
1688 this.setBox(params);
1692 Element.prototype.toFront = function () {
1693 this.Group.parentNode.appendChild(this.Group);
1696 Element.prototype.toBack = function () {
1697 if (this.Group.parentNode.firstChild != this.Group) {
1698 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
1702 Element.prototype.insertAfter = function (element) {
1703 if (element.Group.nextSibling) {
1704 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
1706 element.Group.parentNode.appendChild(this.Group);
1710 Element.prototype.insertBefore = function (element) {
1711 element.Group.parentNode.insertBefore(this.Group, element.Group);
1714 var theCircle = function (vml, x, y, r) {
1715 var g = document.createElement("rvml:group");
1716 var o = document.createElement("rvml:oval");
1718 vml.canvas.appendChild(g);
1719 var res = new Element(o, g, vml);
1720 res.type = "circle";
1721 setFillAndStroke(res, {stroke: "#000", fill: "none"});
1725 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
1728 var theRect = function (vml, x, y, w, h, r) {
1729 var g = document.createElement("rvml:group");
1730 var o = document.createElement(r ? "rvml:roundrect" : "rvml:rect");
1732 o.arcsize = r / (Math.min(w, h));
1735 vml.canvas.appendChild(g);
1736 var res = new Element(o, g, vml);
1738 setFillAndStroke(res, {stroke: "#000"});
1744 res.setBox({x: x, y: y, width: w, height: h});
1747 var theEllipse = function (vml, x, y, rx, ry) {
1748 var g = document.createElement("rvml:group");
1749 var o = document.createElement("rvml:oval");
1751 vml.canvas.appendChild(g);
1752 var res = new Element(o, g, vml);
1753 res.type = "ellipse";
1754 setFillAndStroke(res, {stroke: "#000"});
1759 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
1762 var theImage = function (vml, src, x, y, w, h) {
1763 var g = document.createElement("rvml:group");
1764 var o = document.createElement("rvml:image");
1767 vml.canvas.appendChild(g);
1768 var res = new Element(o, g, vml);
1774 res.setBox({x: x, y: y, width: w, height: h});
1777 var theText = function (vml, x, y, text) {
1778 var g = document.createElement("rvml:group"), gs = g.style;
1779 var el = document.createElement("rvml:shape"), ol = el.style;
1780 var path = document.createElement("rvml:path"), ps = path.style;
1781 path.v = ["m", Math.round(x), ", ", Math.round(y - 2), "l", Math.round(x) + 1, ", ", Math.round(y - 2)].join("");
1782 path.textpathok = true;
1783 ol.width = vml.width;
1784 ol.height = vml.height;
1785 gs.position = "absolute";
1788 gs.width = vml.width;
1789 gs.height = vml.height;
1790 var o = document.createElement("rvml:textpath");
1793 o.coordsize = vml.coordsize;
1794 o.coordorigin = vml.coordorigin;
1796 el.appendChild(path);
1798 vml.canvas.appendChild(g);
1799 var res = new Element(o, g, vml);
1801 res.textpath = path;
1807 setFillAndStroke(res, {font: '10px "Arial"', stroke: "none", fill: "#000"});
1810 create = function () {
1811 // container, width, height
1812 // x, y, width, height
1813 var container, width, height;
1814 if (typeof arguments[0] == "string") {
1815 container = document.getElementById(arguments[0]);
1816 width = arguments[1];
1817 height = arguments[2];
1819 if (typeof arguments[0] == "object") {
1820 container = arguments[0];
1821 width = arguments[1];
1822 height = arguments[2];
1824 if (typeof arguments[0] == "number") {
1828 width = arguments[2];
1829 height = arguments[3];
1832 throw new Error("VML container not found.");
1834 if (!document.namespaces["rvml"]) {
1835 document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
1836 document.createStyleSheet().addRule("rvml\\:*", "behavior:url(#default#VML)");
1838 var c = document.createElement("div"),
1839 d = document.createElement("div"),
1840 r = paper.canvas = document.createElement("rvml:group"),
1841 cs = c.style, rs = r.style;
1842 paper.width = width;
1843 paper.height = height;
1844 width = width || "320px";
1845 height = height || "200px";
1846 cs.clip = "rect(0 " + width + " " + height + " 0)";
1849 cs.position = "absolute";
1850 rs.position = "absolute";
1851 d.style.position = "relative";
1854 r.coordsize = (width == "100%" ? width : parseFloat(width)) + " " + (height == "100%" ? height : parseFloat(height));
1855 r.coordorigin = "0 0";
1857 var b = document.createElement("rvml:rect"), bs = b.style;
1858 bs.left = bs.top = 0;
1859 bs.width = rs.width;
1860 bs.height = rs.height;
1861 b.filled = b.stroked = "f";
1866 if (container == 1) {
1867 document.body.appendChild(d);
1868 cs.position = "absolute";
1880 cs.width = container.style.width = width;
1881 cs.height = container.style.height = height;
1882 if (container.firstChild) {
1883 container.insertBefore(d, container.firstChild);
1885 container.appendChild(d);
1888 for (var prop in paper) {
1889 container[prop] = paper[prop];
1891 for (var prop in R.fn) {
1892 if (!container[prop]) {
1893 container[prop] = R.fn[prop];
1896 container.clear = function () {
1898 for (var i = 0, ii = r.childNodes.length; i < ii; i++) {
1899 if (r.childNodes[i] != b) {
1900 todel.push(r.childNodes[i]);
1903 for (i = 0, ii = todel.length; i < ii; i++) {
1904 r.removeChild(todel[i]);
1909 paper.remove = function () {
1910 this.canvas.parentNode.parentNode.parentNode.removeChild(this.canvas.parentNode.parentNode);
1912 paper.safari = function () {};
1918 var addEvent = (function () {
1919 if (document.addEventListener) {
1920 return function (obj, type, fn) {
1921 obj.addEventListener(type, fn, false);
1923 } else if (document.attachEvent) {
1924 return function (obj, type, fn) {
1925 var f = function (e) {
1926 fn.call(this, e || window.event);
1928 obj.attachEvent("on" + type, f);
1932 var events = ["click", "dblclick", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup"];
1933 for (var i = events.length; i--;) {
1934 (function (eventName) {
1935 Element.prototype[eventName] = function (fn) {
1936 addEvent(this.node, eventName, fn);
1941 paper.circle = function (x, y, r) {
1942 return theCircle(this, x, y, r);
1944 paper.rect = function (x, y, w, h, r) {
1945 return theRect(this, x, y, w, h, r);
1947 paper.ellipse = function (x, y, rx, ry) {
1948 return theEllipse(this, x, y, rx, ry);
1950 paper.path = function (params, pathString) {
1951 return thePath(params, pathString, this);
1953 paper.image = function (src, x, y, w, h) {
1954 return theImage(this, src, x, y, w, h);
1956 paper.text = function (x, y, text) {
1957 return theText(this, x, y, text);
1959 paper.group = function () {
1962 paper.drawGrid = function (x, y, w, h, wv, hv, color) {
1963 color = color || "#000";
1964 var p = this.path({stroke: color, "stroke-width": 1})
1965 .moveTo(x, y).lineTo(x + w, y).lineTo(x + w, y + h).lineTo(x, y + h).lineTo(x, y),
1967 columnWidth = w / wv;
1968 for (var i = 1; i < hv; i++) {
1969 p.moveTo(x, y + i * rowHeight).lineTo(x + w, y + i * rowHeight);
1971 for (var i = 1; i < wv; i++) {
1972 p.moveTo(x + i * columnWidth, y).lineTo(x + i * columnWidth, y + h);
1976 paper.pathfinder = function (p, path) {
1978 M: function (x, y) {
1981 C: function (x1, y1, x2, y2, x3, y3) {
1982 this.curveTo(x1, y1, x2, y2, x3, y3);
1984 Q: function (x1, y1, x2, y2) {
1985 this.qcurveTo(x1, y1, x2, y2);
1987 T: function (x, y) {
1988 this.qcurveTo(x, y);
1990 S: function (x1, y1, x2, y2) {
1991 p.curveTo(x1, y1, x2, y2);
1993 L: function (x, y) {
1997 this.lineTo(x, this.last.y);
2000 this.lineTo(this.last.x, y);
2002 A: function (rx, ry, xaxisrotation, largearcflag, sweepflag, x, y) {
2003 this.arcTo(rx, ry, largearcflag, sweepflag, x, y);
2010 path = pathToAbsolute(path);
2011 for (var i = 0, ii = path.length; i < ii; i++) {
2012 var b = path[i].shift();
2013 commands[b].apply(p, path[i]);
2016 paper.set = function (itemsArray) {
2017 return new Set(itemsArray);
2019 Element.prototype.stop = function () {
2020 clearTimeout(this.animation_in_progress);
2022 Element.prototype.scale = function (x, y) {
2023 if (x == undefined && y == undefined) {
2024 return {x: this._.sx, y: this._.sy};
2028 if (x != 0 && !(x == 1 && y == 1)) {
2029 var dirx = Math.round(x / Math.abs(x)),
2030 diry = Math.round(y / Math.abs(y)),
2031 s = this.node.style;
2032 dx = this.attr("x");
2033 dy = this.attr("y");
2034 cx = this.attr("cx");
2035 cy = this.attr("cy");
2036 if (dirx != 1 || diry != 1) {
2037 if (this.transformations) {
2038 this.transformations[2] = "scale(" + [dirx, diry] + ")";
2039 this.node.setAttribute("transform", this.transformations.join(" "));
2040 dx = (dirx < 0) ? -this.attr("x") - this.attrs.width * x * dirx / this._.sx : this.attr("x");
2041 dy = (diry < 0) ? -this.attr("y") - this.attrs.height * y * diry / this._.sy : this.attr("y");
2042 cx = this.attr("cx") * dirx;
2043 cy = this.attr("cy") * diry;
2045 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11=" + dirx +
2046 ", M12=0, M21=0, M22=" + diry +
2047 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')";
2048 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2051 if (this.transformations) {
2052 this.transformations[2] = "";
2053 this.node.setAttribute("transform", this.transformations.join(" "));
2055 this.node.filterMatrix = "";
2056 s.filter = (this.node.filterMatrix || "") + (this.node.filterOpacity || "");
2059 switch (this.type) {
2063 width: this.attrs.width * x * dirx / this._.sx,
2064 height: this.attrs.height * y * diry / this._.sy,
2072 rx: this.attrs.rx * x * dirx / this._.sx,
2073 ry: this.attrs.ry * y * diry / this._.sy,
2074 r: this.attrs.r * x * diry / this._.sx,
2080 var path = pathToRelative(Raphael.parsePathString(this.attr("path"))),
2082 dim = pathDimensions(this.attrs.path),
2083 dx = -dim.width * (x - 1) / 2,
2084 dy = -dim.height * (y - 1) / 2;
2085 for (var i = 0, ii = path.length; i < ii; i++) {
2086 if (path[i][0].toUpperCase() == "M" && skip) {
2091 if (path[i][0].toUpperCase() == "A") {
2092 path[i][path[i].length - 2] *= x * dirx;
2093 path[i][path[i].length - 1] *= y * diry;
2095 for (var j = 1, jj = path[i].length; j < jj; j++) {
2096 path[i][j] *= (j % 2) ? x * dirx / this._.sx : y * diry / this._.sy;
2100 var dim2 = pathDimensions(path),
2101 dx = dim.x + dim.width / 2 - dim2.x - dim2.width / 2,
2102 dy = dim.y + dim.height / 2 - dim2.y - dim2.height / 2;
2103 path = pathToRelative(path);
2107 this.attr({path: path.join(" ")});
2114 Element.prototype.animate = function (params, ms, callback) {
2115 clearTimeout(this.animation_in_progress);
2120 for (var attr in params) {
2121 if (attr in availableAnimAttrs) {
2122 from[attr] = this.attr(attr);
2123 if (typeof from[attr] == "undefined") {
2124 from[attr] = availableAttrs[attr];
2126 to[attr] = params[attr];
2127 switch (availableAnimAttrs[attr]) {
2129 diff[attr] = (to[attr] - from[attr]) / ms;
2132 from[attr] = getRGB(from[attr]);
2133 var toColour = getRGB(to[attr]);
2135 r: (toColour.r - from[attr].r) / ms,
2136 g: (toColour.g - from[attr].g) / ms,
2137 b: (toColour.b - from[attr].b) / ms
2141 var pathes = pathEqualiser(from[attr], to[attr]);
2142 from[attr] = pathes[0];
2143 to[attr] = pathes[1];
2145 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2146 diff[attr][i] = [0];
2147 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2148 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2153 var values = params[attr].toString().split(/[, ]+/);
2154 if (attr == "translation") {
2155 from[attr] = [0, 0];
2156 diff[attr] = [values[0] / ms, values[1] / ms];
2157 } else if (attr == "rotation") {
2158 from[attr] = [0, values[1], values[2]];
2159 diff[attr] = [values[0] / ms, 0, 0];
2161 from[attr] = from[attr].split(/[, ]+/);
2162 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][0]) / ms];
2168 var start = new Date(),
2172 var time = (new Date()).getTime() - start.getTime(),
2176 for (var attr in from) {
2177 switch (availableAnimAttrs[attr]) {
2179 now = +from[attr] + time * diff[attr];
2183 Math.round(from[attr].r + time * diff[attr].r),
2184 Math.round(from[attr].g + time * diff[attr].g),
2185 Math.round(from[attr].b + time * diff[attr].b)
2190 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2191 now[i] = [from[attr][i][0]];
2192 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2193 now[i][j] = from[attr][i][j] + time * diff[attr][i][j];
2195 now[i] = now[i].join(" ");
2197 now = now.join(" ");
2200 if (attr == "translation") {
2201 var x = diff[attr][0] * (time - prev),
2202 y = diff[attr][1] * (time - prev);
2205 now = [x, y].join(" ");
2206 } else if (attr == "rotation") {
2207 now = +from[attr][0] + time * diff[attr][0];
2208 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2210 now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1]].join(" ");
2214 if (attr == "font-size") {
2215 set[attr] = now + "px";
2221 that.animation_in_progress = setTimeout(arguments.callee, 0);
2224 (t.x || t.y) && that.translate(-t.x, -t.y);
2226 clearTimeout(that.animation_in_progress);
2228 (typeof callback == "function") && callback.call(that);
2236 var Set = function (itemsArray) {
2238 if (itemsArray && itemsArray.constructor == Array) {
2239 for (var i = itemsArray.length; i--;) {
2240 if (itemsArray[i].constructor == Element) {
2241 this.items[this.items.length] = itemsArray[i];
2246 Set.prototype.push = function (item) {
2247 if (item && item.constructor == Element) {
2248 this.items[this.items.length] = item;
2249 this[this.items.length] = item;
2253 Set.prototype.pull = function (id) {
2254 var res = this.items.splice(id, 1)[0];
2255 for (var j = id, jj = this.items.length; j < jj; j++) {
2256 this[j] = this[j + 1];
2258 delete this[jj + 1];
2261 for (var method in Element.prototype) {
2262 Set.prototype[method] = (function (methodname) {
2263 return function () {
2264 for (var i = this.items.length; i--;) {
2265 this.items[i][methodname].apply(this.items[i], arguments);
2271 Set.prototype.getBBox = function () {
2272 var x = [], y = [], w = [], h = [];
2273 for (var i = this.items.length; i--;) {
2274 var box = this.items[i].getBBox();
2277 w.push(box.x + box.width);
2278 h.push(box.y + box.height);
2280 x = Math.min.apply(Math, x);
2281 y = Math.min.apply(Math, y);
2285 width: Math.max.apply(Math, w) - x,
2286 height: Math.max.apply(Math, h) - y