2 * Raphael 1.2.7dev - 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 window.Raphael = (function () {
10 var separator = /[, ]+/,
11 elements = /^(circle|rect|path|ellipse|text|image)$/,
15 was: "Raphael" in win,
19 if (R.is(arguments[0], "array")) {
21 cnv = create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
23 for (var i = 0, ii = a[length]; i < ii; i++) {
25 elements.test(j.type) && res[push](cnv[j.type]().attr(j));
29 return create[apply](R, arguments);
31 appendChild = "appendChild",
36 events = "click dblclick mousedown mousemove mouseout mouseover mouseup".split(S),
37 has = "hasOwnProperty",
38 isit = /^\[object\s+|\]$/gi,
42 lowerCase = String[proto].toLowerCase,
47 toString = "toString",
48 objectToString = Object[proto][toString],
53 ISURL = /^url\(['"]?([^\)]+)['"]?\)$/i,
55 setAttribute = "setAttribute",
59 upperCase = String[proto].toUpperCase,
60 availableAttrs = {"clip-rect": "0 0 10e9 10e9", cursor: "default", cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0},
61 availableAnimAttrs = {"clip-rect": "csv", cx: nu, cy: nu, fill: "colour", "fill-opacity": nu, "font-size": nu, height: nu, opacity: nu, path: "path", r: nu, rotation: "csv", rx: nu, ry: nu, scale: "csv", stroke: "colour", "stroke-opacity": nu, "stroke-width": nu, translation: "csv", width: nu, x: nu, y: nu},
63 R.version = "1.2.7dev";
64 R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
65 R.svg = !(R.vml = R.type == "VML");
69 R.is = function (o, type) {
70 type = lowerCase.call(type);
71 return ((type == "object" || type == "undefined") && typeof o == type) || (o == null && type == "null") || lowerCase.call(objectToString.call(o)[rp](isit, E)) == type;
73 R.setWindow = function (newwin) {
78 var toHex = function (color) {
80 // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
81 var trim = /^\s+|\s+$/g;
82 toHex = cacher(function (color) {
84 color = (color + E).replace(trim, E);
86 var document = new ActiveXObject("htmlfile");
87 document.write("<body>");
91 bod = createPopup().document.body;
93 var range = bod.createTextRange();
95 bod.style.color = color;
96 var value = range.queryCommandValue("ForeColor");
97 value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
98 return "#" + ("000000" + value[toString](16)).slice(-6);
104 var i = doc.createElement("i");
105 i.className = "Rapha\xebl Colour Picker";
106 i.style.cssText = "display:none";
107 doc.body[appendChild](i);
108 toHex = cacher(function (color) {
109 i.style.color = color;
110 return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
115 R.hsb2rgb = cacher(function (hue, saturation, brightness) {
116 if (R.is(hue, "object") && "h" in hue && "s" in hue && "b" in hue) {
124 if (brightness == 0) {
125 return {r: 0, g: 0, b: 0, hex: "#000"};
127 if (hue > 1 || saturation > 1 || brightness > 1) {
134 p = brightness * (1 - saturation),
135 q = brightness * (1 - (saturation * f)),
136 t = brightness * (1 - (saturation * (1 - f)));
137 red = [brightness, q, p, p, t, brightness, brightness][i];
138 green = [t, brightness, brightness, q, p, p, t][i];
139 blue = [p, p, t, brightness, brightness, q, p][i];
143 var rgb = {r: red, g: green, b: blue},
144 r = (~~red)[toString](16),
145 g = (~~green)[toString](16),
146 b = (~~blue)[toString](16);
150 rgb.hex = "#" + r + g + b;
153 R.rgb2hsb = cacher(function (red, green, blue) {
154 if (R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
159 if (R.is(red, "string")) {
160 var clr = R.getRGB(red);
165 if (red > 1 || green > 1 || blue > 1) {
170 var max = mmax(red, green, blue),
171 min = mmin(red, green, blue),
176 return {h: 0, s: 0, b: max};
178 var delta = (max - min);
179 saturation = delta / max;
181 hue = (green - blue) / delta;
182 } else if (green == max) {
183 hue = 2 + ((blue - red) / delta);
185 hue = 4 + ((red - green) / delta);
191 return {h: hue, s: saturation, b: brightness};
193 var p2s = /,?([achlmqrstvxz]),?/gi;
194 R._path2string = function () {
195 return this.join(",")[rp](p2s, "$1");
197 function cacher(f, scope, postprocessor) {
199 var arg = Array[proto].slice.call(arguments, 0),
200 args = arg[join]("\u25ba"),
201 cache = newf.cache = newf.cache || {},
202 count = newf.count = newf.count || [];
203 if (cache[has](args)) {
204 return postprocessor ? postprocessor(cache[args]) : cache[args];
206 count[length] >= 1e3 && delete cache[count.shift()];
208 cache[args] = f[apply](scope, arg);
209 return postprocessor ? postprocessor(cache[args]) : cache[args];
214 R.getRGB = cacher(function (colour) {
215 if (!colour || !!((colour + E).indexOf("-") + 1)) {
216 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
219 if (colour == "none") {
220 return {r: -1, g: -1, b: -1, hex: "none"};
222 !({hs: 1, rg: 1})[has](colour.substring(0, 2)) && (colour = toHex(colour));
227 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*\)|hs[bl]\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hs[bl]\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i);
230 blue = toInt(rgb[2].substring(5), 16);
231 green = toInt(rgb[2].substring(3, 5), 16);
232 red = toInt(rgb[2].substring(1, 3), 16);
235 blue = toInt(rgb[3].substring(3) + rgb[3].substring(3), 16);
236 green = toInt(rgb[3].substring(2, 3) + rgb[3].substring(2, 3), 16);
237 red = toInt(rgb[3].substring(1, 2) + rgb[3].substring(1, 2), 16);
240 rgb = rgb[4][split](/\s*,\s*/);
241 red = toFloat(rgb[0]);
242 green = toFloat(rgb[1]);
243 blue = toFloat(rgb[2]);
246 rgb = rgb[5][split](/\s*,\s*/);
247 red = toFloat(rgb[0]) * 2.55;
248 green = toFloat(rgb[1]) * 2.55;
249 blue = toFloat(rgb[2]) * 2.55;
252 rgb = rgb[6][split](/\s*,\s*/);
253 red = toFloat(rgb[0]);
254 green = toFloat(rgb[1]);
255 blue = toFloat(rgb[2]);
256 return R.hsb2rgb(red, green, blue);
259 rgb = rgb[7][split](/\s*,\s*/);
260 red = toFloat(rgb[0]) * 2.55;
261 green = toFloat(rgb[1]) * 2.55;
262 blue = toFloat(rgb[2]) * 2.55;
263 return R.hsb2rgb(red, green, blue);
265 rgb = {r: red, g: green, b: blue};
266 var r = (~~red)[toString](16),
267 g = (~~green)[toString](16),
268 b = (~~blue)[toString](16);
272 rgb.hex = "#" + r + g + b;
275 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
277 R.getColor = function (value) {
278 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
279 rgb = this.hsb2rgb(start.h, start.s, start.b);
284 start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
288 R.getColor.reset = function () {
292 R.parsePathString = cacher(function (pathString) {
296 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
298 if (R.is(pathString, "array") && R.is(pathString[0], "array")) { // rough assumption
299 data = pathClone(pathString);
302 (pathString + E)[rp](/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, function (a, b, c) {
304 name = lowerCase.call(b);
305 c[rp](/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig, function (a, b) {
306 b && params[push](+b);
308 while (params[length] >= paramCounts[name]) {
309 data[push]([b][concat](params.splice(0, paramCounts[name])));
310 if (!paramCounts[name]) {
316 data[toString] = R._path2string;
319 var pathDimensions = cacher(function (path) {
321 return {x: 0, y: 0, width: 0, height: 0};
323 path = path2curve(path);
329 for (var i = 0, ii = path[length]; i < ii; i++) {
337 var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
338 X = X[concat](dim.min.x, dim.max.x);
339 Y = Y[concat](dim.min.y, dim.max.y);
344 var xmin = mmin[apply](0, X),
345 ymin = mmin[apply](0, Y);
349 width: mmax[apply](0, X) - xmin,
350 height: mmax[apply](0, Y) - ymin
353 pathClone = function (pathArray) {
355 if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption
356 pathArray = R.parsePathString(pathArray);
358 for (var i = 0, ii = pathArray[length]; i < ii; i++) {
360 for (var j = 0, jj = pathArray[i][length]; j < jj; j++) {
361 res[i][j] = pathArray[i][j];
364 res[toString] = R._path2string;
367 pathToRelative = cacher(function (pathArray) {
368 if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption
369 pathArray = R.parsePathString(pathArray);
377 if (pathArray[0][0] == "M") {
383 res[push](["M", x, y]);
385 for (var i = start, ii = pathArray[length]; i < ii; i++) {
388 if (pa[0] != lowerCase.call(pa[0])) {
389 r[0] = lowerCase.call(pa[0]);
397 r[6] = +(pa[6] - x).toFixed(3);
398 r[7] = +(pa[7] - y).toFixed(3);
401 r[1] = +(pa[1] - y).toFixed(3);
407 for (var j = 1, jj = pa[length]; j < jj; j++) {
408 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
417 for (var k = 0, kk = pa[length]; k < kk; k++) {
421 var len = res[i][length];
428 x += +res[i][len - 1];
431 y += +res[i][len - 1];
434 x += +res[i][len - 2];
435 y += +res[i][len - 1];
438 res[toString] = R._path2string;
441 pathToAbsolute = cacher(function (pathArray) {
442 if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption
443 pathArray = R.parsePathString(pathArray);
451 if (pathArray[0][0] == "M") {
452 x = +pathArray[0][1];
453 y = +pathArray[0][2];
457 res[0] = ["M", x, y];
459 for (var i = start, ii = pathArray[length]; i < ii; i++) {
462 if (pa[0] != upperCase.call(pa[0])) {
463 r[0] = upperCase.call(pa[0]);
484 for (var j = 1, jj = pa[length]; j < jj; j++) {
485 r[j] = +pa[j] + ((j % 2) ? x : y);
489 for (var k = 0, kk = pa[length]; k < kk; k++) {
505 x = res[i][res[i][length] - 2];
506 y = res[i][res[i][length] - 1];
509 res[toString] = R._path2string;
512 l2c = function (x1, y1, x2, y2) {
513 return [x1, y1, x2, y2, x2, y2];
515 q2c = function (x1, y1, ax, ay, x2, y2) {
527 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
528 // for more information of where this math came from visit:
529 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
531 _120 = PI * 120 / 180,
532 rad = PI / 180 * (+angle || 0),
535 rotate = cacher(function (x, y, rad) {
536 var X = x * math.cos(rad) - y * math.sin(rad),
537 Y = x * math.sin(rad) + y * math.cos(rad);
541 xy = rotate(x1, y1, -rad);
544 xy = rotate(x2, y2, -rad);
547 var cos = math.cos(PI / 180 * angle),
548 sin = math.sin(PI / 180 * angle),
551 rx = mmax(rx, math.abs(x));
552 ry = mmax(ry, math.abs(y));
555 k = (large_arc_flag == sweep_flag ? -1 : 1) *
556 math.sqrt(math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
557 cx = k * rx * y / ry + (x1 + x2) / 2,
558 cy = k * -ry * x / rx + (y1 + y2) / 2,
559 f1 = math.asin((y1 - cy) / ry),
560 f2 = math.asin((y2 - cy) / ry);
562 f1 = x1 < cx ? PI - f1 : f1;
563 f2 = x2 < cx ? PI - f2 : f2;
564 f1 < 0 && (f1 = PI * 2 + f1);
565 f2 < 0 && (f2 = PI * 2 + f2);
566 if (sweep_flag && f1 > f2) {
569 if (!sweep_flag && f2 > f1) {
579 if (math.abs(df) > _120) {
583 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
584 x2 = cx + rx * math.cos(f2);
585 y2 = cy + ry * math.sin(f2);
586 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
589 var c1 = math.cos(f1),
593 t = math.tan(df / 4),
597 m2 = [x1 + hx * s1, y1 - hy * c1],
598 m3 = [x2 + hx * s2, y2 - hy * c2],
600 m2[0] = 2 * m1[0] - m2[0];
601 m2[1] = 2 * m1[1] - m2[1];
603 return [m2, m3, m4][concat](res);
605 res = [m2, m3, m4][concat](res)[join](",")[split](",");
607 for (var i = 0, ii = res[length]; i < ii; i++) {
608 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
613 findDotAtSegment = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
616 x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
617 y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
620 findDotsAtSegment = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
622 x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
623 y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y,
624 mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
625 my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
626 nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
627 ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
628 ax = (1 - t) * p1x + t * c1x,
629 ay = (1 - t) * p1y + t * c1y,
630 cx = (1 - t) * c2x + t * p2x,
631 cy = (1 - t) * c2y + t * p2y;
632 return {x: x, y: y, m: {x: mx, y: my}, n: {x: nx, y: ny}, start: {x: ax, y: ay}, end: {x: cx, y: cy}};
634 curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
635 var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
636 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
638 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
639 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
643 math.abs(t1) > 1e12 && (t1 = .5);
644 math.abs(t2) > 1e12 && (t2 = .5);
645 if (t1 > 0 && t1 < 1) {
646 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
650 if (t2 > 0 && t2 < 1) {
651 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
655 a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
656 b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
658 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
659 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
660 math.abs(t1) > 1e12 && (t1 = .5);
661 math.abs(t2) > 1e12 && (t2 = .5);
662 if (t1 > 0 && t1 < 1) {
663 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
667 if (t2 > 0 && t2 < 1) {
668 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
673 min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
674 max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
677 path2curve = cacher(function (path, path2) {
678 var p = pathToAbsolute(path),
679 p2 = path2 && pathToAbsolute(path2),
680 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
681 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
682 processPath = function (path, d) {
685 return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
687 !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
694 path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
697 nx = d.x + (d.x - (d.bx || d.x));
698 ny = d.y + (d.y - (d.by || d.y));
699 path = ["C", nx, ny][concat](path.slice(1));
702 d.qx = d.x + (d.x - (d.qx || d.x));
703 d.qy = d.y + (d.y - (d.qy || d.y));
704 path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
709 path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
712 path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
715 path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
718 path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
721 path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
726 fixArc = function (pp, i) {
727 if (pp[i][length] > 7) {
731 pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
734 ii = mmax(p[length], p2 && p2[length] || 0);
737 fixM = function (path1, path2, a1, a2, i) {
738 if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
739 path2.splice(i, 0, ["M", a2.x, a2.y]);
744 ii = mmax(p[length], p2 && p2[length] || 0);
747 for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) {
748 p[i] = processPath(p[i], attrs);
750 p2 && (p2[i] = processPath(p2[i], attrs2));
752 fixM(p, p2, attrs, attrs2, i);
753 fixM(p2, p, attrs2, attrs, i);
756 seglen = seg[length],
757 seg2len = p2 && seg2[length];
758 attrs.x = seg[seglen - 2];
759 attrs.y = seg[seglen - 1];
760 attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
761 attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
762 attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
763 attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
764 attrs2.x = p2 && seg2[seg2len - 2];
765 attrs2.y = p2 && seg2[seg2len - 1];
767 return p2 ? [p, p2] : p;
769 parseDots = cacher(function (gradient) {
771 for (var i = 0, ii = gradient[length]; i < ii; i++) {
773 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
774 dot.color = R.getRGB(par[1]);
775 if (dot.color.error) {
778 dot.color = dot.color.hex;
779 par[2] && (dot.offset = par[2] + "%");
782 for (var i = 1, ii = dots[length] - 1; i < ii; i++) {
783 if (!dots[i].offset) {
784 var start = toFloat(dots[i - 1].offset || 0),
786 for (var j = i + 1; j < ii; j++) {
787 if (dots[j].offset) {
788 end = dots[j].offset;
797 var d = (end - start) / (j - i + 1);
800 dots[i].offset = start + "%";
806 getContainer = function () {
812 if (R.is(arguments[0], "string") || R.is(arguments[0], "object")) {
813 if (R.is(arguments[0], "string")) {
814 container = doc.getElementById(arguments[0]);
816 container = arguments[0];
818 if (container.tagName) {
819 if (arguments[1] == null) {
821 container: container,
822 width: container.style.pixelWidth || container.offsetWidth,
823 height: container.style.pixelHeight || container.offsetHeight
826 return {container: container, width: arguments[1], height: arguments[2]};
829 } else if (R.is(arguments[0], nu) && arguments[length] > 3) {
830 return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]};
833 plugins = function (con, add) {
835 for (var prop in add) if (add[has](prop) && !(prop in con)) {
836 switch (typeof add[prop]) {
839 con[prop] = con === that ? f : function () { return f[apply](that, arguments); };
843 con[prop] = con[prop] || {};
844 plugins.call(this, con[prop], add[prop]);
847 con[prop] = add[prop];
852 tear = function (el, paper) {
853 el == paper.top && (paper.top = el.prev);
854 el == paper.bottom && (paper.bottom = el.next);
855 el.next && (el.next.prev = el.prev);
856 el.prev && (el.prev.next = el.next);
858 tofront = function (el, paper) {
859 if (paper.top === el) {
868 toback = function (el, paper) {
869 if (paper.bottom === el) {
873 el.next = paper.bottom;
875 paper.bottom.prev = el;
878 insertafter = function (el, el2, paper) {
880 el2 == paper.top && (paper.top = el);
881 el2.next && (el2.next.prev = el);
886 insertbefore = function (el, el2, paper) {
888 el2 == paper.bottom && (paper.bottom = el);
889 el2.prev && (el2.prev.next = el);
894 radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/;
898 paper.svgns = "http://www.w3.org/2000/svg";
899 paper.xlink = "http://www.w3.org/1999/xlink";
900 var round = function (num) {
901 return +num + (~~num === num) * .5;
903 roundPath = function (path) {
904 for (var i = 0, ii = path[length]; i < ii; i++) {
905 if (lowerCase.call(path[i][0]) != "a") {
906 for (var j = 1, jj = path[i][length]; j < jj; j++) {
907 path[i][j] = round(path[i][j]);
910 path[i][6] = round(path[i][6]);
911 path[i][7] = round(path[i][7]);
916 $ = function (el, attr) {
918 for (var key in attr) if (attr[has](key)) {
919 el[setAttribute](key, attr[key]);
922 return doc.createElementNS(paper.svgns, el);
925 R[toString] = function () {
926 return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
928 var thePath = function (pathString, SVG) {
930 SVG.canvas && SVG.canvas[appendChild](el);
931 var p = new Element(el, SVG);
933 setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
936 var addGradientFill = function (o, gradient, SVG) {
940 gradient = (gradient + E)[rp](radial_gradient, function (all, _fx, _fy) {
945 var dir = ((fy > .5) * 2 - 1);
946 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
947 (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
949 (fy = fy.toFixed(5) - 1e-5 * dir);
953 gradient = gradient[split](/\s*\-\s*/);
954 if (type == "linear") {
955 var angle = gradient.shift();
956 angle = -toFloat(angle);
960 var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)],
961 max = 1 / (mmax(math.abs(vector[2]), math.abs(vector[3])) || 1);
965 vector[0] = -vector[2];
969 vector[1] = -vector[3];
973 var dots = parseDots(gradient);
977 var el = $(type + "Gradient");
978 el.id = "r" + (R._id++)[toString](36);
979 $(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]});
980 SVG.defs[appendChild](el);
981 for (var i = 0, ii = dots[length]; i < ii; i++) {
982 var stop = $("stop");
984 offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%",
985 "stop-color": dots[i].color || "#fff"
987 el[appendChild](stop);
990 fill: "url(#" + el.id + ")",
999 var updatePosition = function (o) {
1000 var bbox = o.getBBox();
1001 $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
1003 var setFillAndStroke = function (o, params) {
1010 "-..": [3, 1, 1, 1, 1, 1],
1014 "- .": [4, 3, 1, 3],
1015 "--.": [8, 3, 1, 3],
1016 "--..": [8, 3, 1, 3, 1, 3]
1021 addDashes = function (o, value) {
1022 value = dasharray[lowerCase.call(value)];
1024 var width = o.attrs["stroke-width"] || "1",
1025 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
1027 var i = value[length];
1029 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
1031 $(node, {"stroke-dasharray": dashes[join](",")});
1034 params[has]("rotation") && (rot = params.rotation);
1035 var rotxy = (rot + E)[split](separator);
1036 if (!(rotxy.length - 1)) {
1039 rotxy[1] = +rotxy[1];
1040 rotxy[2] = +rotxy[2];
1042 toFloat(rot) && o.rotate(0, true);
1043 for (var att in params) if (params[has](att)) {
1044 if (!availableAttrs[has](att)) {
1047 var value = params[att];
1051 o.rotate(value, true);
1057 var pn = node.parentNode;
1058 if (lowerCase.call(pn.tagName) != "a") {
1060 pn.insertBefore(hl, node);
1061 hl[appendChild](node);
1064 pn.setAttributeNS(o.paper.xlink, att, value);
1067 node.style.cursor = value;
1070 var rect = (value + E)[split](separator);
1071 if (rect[length] == 4) {
1072 o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
1073 var el = $("clipPath"),
1075 el.id = "r" + (R._id++)[toString](36);
1082 el[appendChild](rc);
1083 o.paper.defs[appendChild](el);
1084 $(node, {"clip-path": "url(#" + el.id + ")"});
1088 var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E));
1089 clip && clip.parentNode.removeChild(clip);
1090 $(node, {"clip-path": E});
1095 if (value && o.type == "path") {
1096 attrs.path = roundPath(pathToAbsolute(value));
1097 $(node, {d: attrs.path});
1101 node[setAttribute](att, value);
1110 value = -attrs.x - (attrs.width || 0);
1113 if (att == "rx" && o.type == "rect") {
1117 rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]);
1118 node[setAttribute](att, round(value));
1119 o.pattern && updatePosition(o);
1122 node[setAttribute](att, value);
1131 value = -attrs.y - (attrs.height || 0);
1134 if (att == "ry" && o.type == "rect") {
1138 rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]);
1139 node[setAttribute](att, round(value));
1140 o.pattern && updatePosition(o);
1143 if (o.type == "rect") {
1144 $(node, {rx: value, ry: value});
1146 node[setAttribute](att, value);
1150 if (o.type == "image") {
1151 node.setAttributeNS(o.paper.xlink, "href", value);
1154 case "stroke-width":
1155 node.style.strokeWidth = value;
1156 // Need following line for Firefox
1157 node[setAttribute](att, value);
1158 if (attrs["stroke-dasharray"]) {
1159 addDashes(o, attrs["stroke-dasharray"]);
1162 case "stroke-dasharray":
1163 addDashes(o, value);
1166 var xy = (value + E)[split](separator);
1167 xy[0] = +xy[0] || 0;
1168 xy[1] = +xy[1] || 0;
1173 translate.call(o, xy[0], xy[1]);
1176 var xy = (value + E)[split](separator);
1177 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1180 var isURL = (value + E).match(ISURL);
1182 var el = $("pattern"),
1184 el.id = "r" + (R._id++)[toString](36);
1185 $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
1186 $(ig, {x: 0, y: 0});
1187 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1188 el[appendChild](ig);
1190 var img = doc.createElement("img");
1191 img.style.cssText = "position:absolute;left:-9999em;top-9999em";
1192 img.onload = function () {
1193 $(el, {width: this.offsetWidth, height: this.offsetHeight});
1194 $(ig, {width: this.offsetWidth, height: this.offsetHeight});
1195 doc.body.removeChild(this);
1198 doc.body[appendChild](img);
1200 o.paper.defs[appendChild](el);
1201 node.style.fill = "url(#" + el.id + ")";
1202 $(node, {fill: "url(#" + el.id + ")"});
1204 o.pattern && updatePosition(o);
1207 if (!R.getRGB(value).error) {
1208 delete params.gradient;
1209 delete attrs.gradient;
1210 !R.is(attrs.opacity, "undefined") &&
1211 R.is(params.opacity, "undefined") &&
1212 $(node, {opacity: attrs.opacity});
1213 !R.is(attrs["fill-opacity"], "undefined") &&
1214 R.is(params["fill-opacity"], "undefined") &&
1215 $(node, {"fill-opacity": attrs["fill-opacity"]});
1216 } else if ((({circle: 1, ellipse: 1})[has](o.type) || (value + E).charAt() != "r") && addGradientFill(node, value, o.paper)) {
1217 attrs.gradient = value;
1218 attrs.fill = "none";
1222 node[setAttribute](att, R.getRGB(value).hex);
1225 (({circle: 1, ellipse: 1})[has](o.type) || (value + E).charAt() != "r") && addGradientFill(node, value, o.paper);
1228 case "fill-opacity":
1229 if (attrs.gradient) {
1230 var gradient = doc.getElementById(node.getAttribute("fill")[rp](/^url\(#|\)$/g, E));
1232 var stops = gradient.getElementsByTagName("stop");
1233 stops[stops[length] - 1][setAttribute]("stop-opacity", value);
1238 att == "font-size" && (value = toInt(value, 10) + "px");
1239 var cssrule = att[rp](/(\-.)/g, function (w) {
1240 return upperCase.call(w.substring(1));
1242 node.style[cssrule] = value;
1243 // Need following line for Firefox
1244 node[setAttribute](att, value);
1249 tuneText(o, params);
1251 o.rotate(rotxy.join(S));
1253 toFloat(rot) && o.rotate(rot, true);
1257 var tuneText = function (el, params) {
1258 if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
1263 fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
1265 if (params[has]("text")) {
1266 a.text = params.text;
1267 while (node.firstChild) {
1268 node.removeChild(node.firstChild);
1270 var texts = (params.text + E)[split]("\n");
1271 for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) {
1272 var tspan = $("tspan");
1273 i && $(tspan, {dy: fontSize * leading, x: a.x});
1274 tspan[appendChild](doc.createTextNode(texts[i]));
1275 node[appendChild](tspan);
1278 var texts = node.getElementsByTagName("tspan");
1279 for (var i = 0, ii = texts[length]; i < ii; i++) {
1280 i && $(texts[i], {dy: fontSize * leading, x: a.x});
1284 var bb = el.getBBox(),
1285 dif = a.y - (bb.y + bb.height / 2);
1286 dif && isFinite(dif) && $(node, {y: a.y + dif});
1288 var Element = function (node, svg) {
1294 node.raphael = this;
1296 this.attrs = this.attrs || {};
1297 this.transformations = []; // rotate, translate, scale
1301 rt: {deg: 0, cx: 0, cy: 0},
1305 !svg.bottom && (svg.bottom = this);
1306 this.prev = svg.top;
1307 svg.top && (svg.top.next = this);
1311 Element[proto].rotate = function (deg, cx, cy) {
1317 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
1319 return this._.rt.deg;
1321 var bbox = this.getBBox();
1322 deg = (deg + E)[split](separator);
1323 if (deg[length] - 1) {
1324 cx = toFloat(deg[1]);
1325 cy = toFloat(deg[2]);
1327 deg = toFloat(deg[0]);
1329 this._.rt.deg = deg;
1331 this._.rt.deg += deg;
1333 (cy == null) && (cx = null);
1336 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1337 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1338 if (this._.rt.deg) {
1339 this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
1340 this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
1342 this.transformations[0] = E;
1343 this.clip && $(this.clip, {transform: E});
1345 $(this.node, {transform: this.transformations[join](S)});
1348 Element[proto].hide = function () {
1349 !this.removed && (this.node.style.display = "none");
1352 Element[proto].show = function () {
1353 !this.removed && (this.node.style.display = "");
1356 Element[proto].remove = function () {
1360 tear(this, this.paper);
1361 this.node.parentNode.removeChild(this.node);
1362 for (var i in this) {
1365 this.removed = true;
1367 Element[proto].getBBox = function () {
1371 if (this.type == "path") {
1372 return pathDimensions(this.attrs.path);
1374 if (this.node.style.display == "none") {
1380 bbox = this.node.getBBox();
1382 // Firefox 3.0.x plays badly here
1386 if (this.type == "text") {
1387 bbox = {x: bbox.x, y: Infinity, width: 0, height: 0};
1388 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1389 var bb = this.node.getExtentOfChar(i);
1390 (bb.y < bbox.y) && (bbox.y = bb.y);
1391 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1392 (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x);
1395 hide && this.hide();
1398 Element[proto].attr = function () {
1402 if (arguments[length] == 0) {
1404 for (var i in this.attrs) if (this.attrs[has](i)) {
1405 res[i] = this.attrs[i];
1407 this._.rt.deg && (res.rotation = this.rotate());
1408 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
1409 delete res.translation;
1410 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
1413 if (arguments[length] == 1 && R.is(arguments[0], "string")) {
1414 if (arguments[0] == "translation") {
1415 return translate.call(this);
1417 if (arguments[0] == "rotation") {
1418 return this.rotate();
1420 if (arguments[0] == "scale") {
1421 return this.scale();
1423 if (arguments[0] == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
1424 return this.attrs.gradient;
1426 return this.attrs[arguments[0]];
1428 if (arguments[length] == 1 && R.is(arguments[0], "array")) {
1430 for (var j in arguments[0]) if (arguments[0][has](j)) {
1431 values[arguments[0][j]] = this.attrs[arguments[0][j]];
1435 if (arguments[length] == 2) {
1437 params[arguments[0]] = arguments[1];
1438 setFillAndStroke(this, params);
1439 } else if (arguments[length] == 1 && R.is(arguments[0], "object")) {
1440 setFillAndStroke(this, arguments[0]);
1444 Element[proto].toFront = function () {
1448 this.node.parentNode[appendChild](this.node);
1449 var svg = this.paper;
1450 svg.top != this && tofront(this, svg);
1453 Element[proto].toBack = function () {
1457 if (this.node.parentNode.firstChild != this.node) {
1458 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1459 toback(this, this.paper);
1460 var svg = this.paper;
1464 Element[proto].insertAfter = function (element) {
1468 var svg = this.paper,
1469 node = element.node;
1470 if (node.nextSibling) {
1471 node.parentNode.insertBefore(this.node, node.nextSibling);
1473 node.parentNode[appendChild](this.node);
1475 insertafter(this, element, this.paper);
1478 Element[proto].insertBefore = function (element) {
1482 var node = element.node;
1483 node.parentNode.insertBefore(this.node, node);
1484 insertbefore(this, element, this.paper);
1488 var theCircle = function (svg, x, y, r) {
1491 var el = $("circle");
1492 svg.canvas && svg.canvas[appendChild](el);
1493 var res = new Element(el, svg);
1494 res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1495 res.type = "circle";
1499 var theRect = function (svg, x, y, w, h, r) {
1503 svg.canvas && svg.canvas[appendChild](el);
1504 var res = new Element(el, svg);
1505 res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1510 var theEllipse = function (svg, x, y, rx, ry) {
1513 var el = $("ellipse");
1514 svg.canvas && svg.canvas[appendChild](el);
1515 var res = new Element(el, svg);
1516 res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1517 res.type = "ellipse";
1521 var theImage = function (svg, src, x, y, w, h) {
1522 var el = $("image");
1523 $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1524 el.setAttributeNS(svg.xlink, "href", src);
1525 svg.canvas && svg.canvas[appendChild](el);
1526 var res = new Element(el, svg);
1527 res.attrs = {x: x, y: y, width: w, height: h, src: src};
1531 var theText = function (svg, x, y, text) {
1533 $(el, {x: x, y: y, "text-anchor": "middle"});
1534 svg.canvas && svg.canvas[appendChild](el);
1535 var res = new Element(el, svg);
1536 res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
1538 setFillAndStroke(res, res.attrs);
1541 var setSize = function (width, height) {
1542 this.width = width || this.width;
1543 this.height = height || this.height;
1544 this.canvas[setAttribute]("width", this.width);
1545 this.canvas[setAttribute]("height", this.height);
1548 var create = function () {
1549 var con = getContainer[apply](null, arguments),
1550 container = con && con.container,
1554 height = con.height;
1556 throw new Error("SVG container not found.");
1558 paper.canvas = $("svg");
1559 var cnvs = paper.canvas;
1560 paper.width = width || 512;
1561 paper.height = height || 342;
1563 xmlns: "http://www.w3.org/2000/svg",
1566 height: paper.height
1568 if (container == 1) {
1569 cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
1570 doc.body[appendChild](cnvs);
1572 if (container.firstChild) {
1573 container.insertBefore(cnvs, container.firstChild);
1575 container[appendChild](cnvs);
1578 container = { canvas: cnvs };
1579 for (var prop in paper) if (paper[has](prop)) {
1580 container[prop] = paper[prop];
1582 container.bottom = container.top = null;
1583 plugins.call(container, container, R.fn);
1585 container.raphael = R;
1588 paper.clear = function () {
1589 var c = this.canvas;
1590 while (c.firstChild) {
1591 c.removeChild(c.firstChild);
1593 this.bottom = this.top = null;
1594 (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl"));
1595 c[appendChild](this.desc);
1596 c[appendChild](this.defs = $("defs"));
1598 paper.remove = function () {
1599 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1600 for (var i in this) {
1608 var path2vml = function (path) {
1609 var total = /[ahqtv]/ig,
1610 command = pathToAbsolute;
1611 (path + E).match(total) && (command = path2curve);
1613 if (command == pathToAbsolute && !(path + E).match(total)) {
1614 var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
1615 bites = /([clmz]),?([^clmz]*)/gi,
1616 val = /-?[^,\s-]+/g;
1617 var res = (path + E)[rp](bites, function (all, command, args) {
1619 args[rp](val, function (value) {
1620 vals[push](round(value));
1622 return map[command] + vals;
1626 var pa = command(path), p, res = [], r;
1627 for (var i = 0, ii = pa[length]; i < ii; i++) {
1629 r = lowerCase.call(pa[i][0]);
1630 r == "z" && (r = "x");
1631 for (var j = 1, jj = p[length]; j < jj; j++) {
1632 r += round(p[j]) + (j != jj - 1 ? "," : E);
1636 return res[join](S);
1639 R[toString] = function () {
1640 return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
1642 var thePath = function (pathString, VML) {
1643 var g = createNode("group");
1644 g.style.cssText = "position:absolute;left:0;top:0;width:" + VML.width + "px;height:" + VML.height + "px";
1645 g.coordsize = VML.coordsize;
1646 g.coordorigin = VML.coordorigin;
1647 var el = createNode("shape"), ol = el.style;
1648 ol.width = VML.width + "px";
1649 ol.height = VML.height + "px";
1650 el.coordsize = this.coordsize;
1651 el.coordorigin = this.coordorigin;
1653 var p = new Element(el, g, VML);
1654 p.isAbsolute = true;
1658 pathString && setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
1659 VML.canvas[appendChild](g);
1662 var setFillAndStroke = function (o, params) {
1663 o.attrs = o.attrs || {};
1669 for (var par in params) if (params[has](par)) {
1670 a[par] = params[par];
1672 params.href && (node.href = params.href);
1673 params.title && (node.title = params.title);
1674 params.target && (node.target = params.target);
1675 params.cursor && (s.cursor = params.cursor);
1676 if (params.path && o.type == "path") {
1677 a.path = params.path;
1678 node.path = path2vml(a.path);
1680 if (params.rotation != null) {
1681 o.rotate(params.rotation, true);
1683 if (params.translation) {
1684 xy = (params.translation + E)[split](separator);
1685 translate.call(o, xy[0], xy[1]);
1686 if (o._.rt.cx != null) {
1687 o._.rt.cx +=+ xy[0];
1688 o._.rt.cy +=+ xy[1];
1689 o.setBox(o.attrs, xy[0], xy[1]);
1693 xy = (params.scale + E)[split](separator);
1694 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1696 if ("clip-rect" in params) {
1697 var rect = (params["clip-rect"] + E)[split](separator);
1698 if (rect[length] == 4) {
1699 rect[2] = +rect[2] + (+rect[0]);
1700 rect[3] = +rect[3] + (+rect[1]);
1701 var div = node.clipRect || doc.createElement("div"),
1703 group = node.parentNode;
1704 dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
1705 if (!node.clipRect) {
1706 dstyle.position = "absolute";
1709 dstyle.width = o.paper.width + "px";
1710 dstyle.height = o.paper.height + "px";
1711 group.parentNode.insertBefore(div, group);
1712 div[appendChild](group);
1713 node.clipRect = div;
1716 if (!params["clip-rect"]) {
1717 node.clipRect && (node.clipRect.style.clip = E);
1720 if (o.type == "image" && params.src) {
1721 node.src = params.src;
1723 if (o.type == "image" && params.opacity) {
1724 node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")";
1725 s.filter = (node.filterMatrix || E) + (node.filterOpacity || E);
1727 params.font && (s.font = params.font);
1728 params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"');
1729 params["font-size"] && (s.fontSize = params["font-size"]);
1730 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1731 params["font-style"] && (s.fontStyle = params["font-style"]);
1732 if (params.opacity != null ||
1733 params["stroke-width"] != null ||
1734 params.fill != null ||
1735 params.stroke != null ||
1736 params["stroke-width"] != null ||
1737 params["stroke-opacity"] != null ||
1738 params["fill-opacity"] != null ||
1739 params["stroke-dasharray"] != null ||
1740 params["stroke-miterlimit"] != null ||
1741 params["stroke-linejoin"] != null ||
1742 params["stroke-linecap"] != null) {
1743 node = o.shape || node;
1744 var fill = (node.getElementsByTagName("fill") && node.getElementsByTagName("fill")[0]),
1746 !fill && (newfill = fill = createNode("fill"));
1747 if ("fill-opacity" in params || "opacity" in params) {
1748 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1);
1749 opacity < 0 && (opacity = 0);
1750 opacity > 1 && (opacity = 1);
1751 fill.opacity = opacity;
1753 params.fill && (fill.on = true);
1754 if (fill.on == null || params.fill == "none") {
1757 if (fill.on && params.fill) {
1758 var isURL = params.fill.match(ISURL);
1760 fill.src = isURL[1];
1763 fill.color = R.getRGB(params.fill).hex;
1765 fill.type = "solid";
1766 if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || (params.fill + E).charAt() != "r") && addGradientFill(res, params.fill)) {
1768 a.gradient = params.fill;
1772 newfill && node[appendChild](fill);
1773 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
1775 !stroke && (newstroke = stroke = createNode("stroke"));
1776 if ((params.stroke && params.stroke != "none") ||
1777 params["stroke-width"] ||
1778 params["stroke-opacity"] != null ||
1779 params["stroke-dasharray"] ||
1780 params["stroke-miterlimit"] ||
1781 params["stroke-linejoin"] ||
1782 params["stroke-linecap"]) {
1785 (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
1786 stroke.on && params.stroke && (stroke.color = R.getRGB(params.stroke).hex);
1787 var opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1),
1788 width = (toFloat(params["stroke-width"]) || 1) * .75;
1789 opacity < 0 && (opacity = 0);
1790 opacity > 1 && (opacity = 1);
1791 params["stroke-width"] == null && (width = a["stroke-width"]);
1792 params["stroke-width"] && (stroke.weight = width);
1793 width && width < 1 && (opacity *= width) && (stroke.weight = 1);
1794 stroke.opacity = opacity;
1796 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1797 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1798 params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
1799 if (params["stroke-dasharray"]) {
1803 "-.": "shortdashdot",
1804 "-..": "shortdashdotdot",
1809 "--.": "longdashdot",
1810 "--..": "longdashdotdot"
1812 stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
1814 newstroke && node[appendChild](stroke);
1816 if (res.type == "text") {
1817 var s = res.paper.span.style;
1818 a.font && (s.font = a.font);
1819 a["font-family"] && (s.fontFamily = a["font-family"]);
1820 a["font-size"] && (s.fontSize = a["font-size"]);
1821 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1822 a["font-style"] && (s.fontStyle = a["font-style"]);
1823 res.node.string && (res.paper.span.innerHTML = (res.node.string + E)[rp](/</g, "<")[rp](/&/g, "&")[rp](/\n/g, "<br>"));
1824 res.W = a.w = res.paper.span.offsetWidth;
1825 res.H = a.h = res.paper.span.offsetHeight;
1827 res.Y = a.y + round(res.H / 2);
1829 // text-anchor emulationm
1830 switch (a["text-anchor"]) {
1832 res.node.style["v-text-align"] = "left";
1833 res.bbx = round(res.W / 2);
1836 res.node.style["v-text-align"] = "right";
1837 res.bbx = -round(res.W / 2);
1840 res.node.style["v-text-align"] = "center";
1845 var addGradientFill = function (o, gradient) {
1846 o.attrs = o.attrs || {};
1847 var attrs = o.attrs,
1848 fill = o.node.getElementsByTagName("fill"),
1851 o.attrs.gradient = gradient;
1852 gradient = (gradient + E)[rp](radial_gradient, function (all, fx, fy) {
1857 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
1862 gradient = gradient[split](/\s*\-\s*/);
1863 if (type == "linear") {
1864 var angle = gradient.shift();
1865 angle = -toFloat(angle);
1870 var dots = parseDots(gradient);
1874 o = o.shape || o.node;
1875 fill = fill[0] || createNode("fill");
1878 fill.method = "none";
1879 fill.type = (type == "radial") ? "gradientradial" : "gradient";
1880 fill.color = dots[0].color;
1881 fill.color2 = dots[dots[length] - 1].color;
1883 for (var i = 0, ii = dots[length]; i < ii; i++) {
1884 dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color);
1886 fill.colors && (fill.colors.value = clrs[length] ? clrs[join](",") : "0% " + fill.color);
1887 if (type == "radial") {
1888 fill.focus = "100%";
1889 fill.focussize = fxfy;
1890 fill.focusposition = fxfy;
1892 fill.angle = (270 - angle) % 360;
1897 var Element = function (node, group, vml) {
1905 node.raphael = this;
1918 !vml.bottom && (vml.bottom = this);
1919 this.prev = vml.top;
1920 vml.top && (vml.top.next = this);
1924 Element[proto].rotate = function (deg, cx, cy) {
1930 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
1932 return this._.rt.deg;
1934 deg = (deg + E)[split](separator);
1935 if (deg[length] - 1) {
1936 cx = toFloat(deg[1]);
1937 cy = toFloat(deg[2]);
1939 deg = toFloat(deg[0]);
1941 this._.rt.deg = deg;
1943 this._.rt.deg += deg;
1945 cy == null && (cx = null);
1948 this.setBox(this.attrs, cx, cy);
1949 this.Group.style.rotation = this._.rt.deg;
1950 // gradient fix for rotation. TODO
1951 // var fill = (this.shape || this.node).getElementsByTagName("fill");
1952 // fill = fill[0] || {};
1953 // var b = ((360 - this._.rt.deg) - 270) % 360;
1954 // !R.is(fill.angle, "undefined") && (fill.angle = b);
1957 Element[proto].setBox = function (params, cx, cy) {
1961 var gs = this.Group.style,
1962 os = (this.shape && this.shape.style) || this.node.style;
1963 params = params || {};
1964 for (var i in params) if (params[has](i)) {
1965 this.attrs[i] = params[i];
1967 cx = cx || this._.rt.cx;
1968 cy = cy || this._.rt.cy;
1969 var attr = this.attrs,
1974 switch (this.type) {
1976 x = attr.cx - attr.r;
1977 y = attr.cy - attr.r;
1981 x = attr.cx - attr.rx;
1982 y = attr.cy - attr.ry;
1990 w = attr.width || 0;
1991 h = attr.height || 0;
1994 this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
1995 x = attr.x - round(this.W / 2);
1996 y = attr.y - this.H / 2;
2001 if (!this.attrs.path) {
2004 w = this.paper.width;
2005 h = this.paper.height;
2007 var dim = pathDimensions(this.attrs.path);
2017 w = this.paper.width;
2018 h = this.paper.height;
2021 cx = (cx == null) ? x + w / 2 : cx;
2022 cy = (cy == null) ? y + h / 2 : cy;
2023 var left = cx - this.paper.width / 2,
2024 top = cy - this.paper.height / 2;
2025 if (this.type == "path" || this.type == "text") {
2026 (gs.left != left + "px") && (gs.left = left + "px");
2027 (gs.top != top + "px") && (gs.top = top + "px");
2028 this.X = this.type == "text" ? x : -left;
2029 this.Y = this.type == "text" ? y : -top;
2032 (os.left != -left + "px") && (os.left = -left + "px");
2033 (os.top != -top + "px") && (os.top = -top + "px");
2035 (gs.left != left + "px") && (gs.left = left + "px");
2036 (gs.top != top + "px") && (gs.top = top + "px");
2041 (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px");
2042 (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px");
2043 (os.left != x - left + "px") && (os.left = x - left + "px");
2044 (os.top != y - top + "px") && (os.top = y - top + "px");
2045 (os.width != w + "px") && (os.width = w + "px");
2046 (os.height != h + "px") && (os.height = h + "px");
2047 var arcsize = (+params.r || 0) / mmin(w, h);
2048 if (this.type == "rect" && this.arcsize.toFixed(4) != arcsize.toFixed(4) && (arcsize || this.arcsize)) {
2049 // We should replace element with the new one
2050 var o = createNode("roundrect"),
2053 ii = this.events && this.events[length];
2054 o.arcsize = arcsize;
2056 this.Group[appendChild](o);
2057 this.Group.removeChild(this.node);
2058 this[0] = this.node = o;
2059 this.arcsize = arcsize;
2060 for (var i in attr) {
2065 if (this.events) for (; i < ii; i++) {
2066 this.events[i].unbind = addEvent(this.node, this.events[i].name, this.events[i].f, this);
2071 Element[proto].hide = function () {
2072 !this.removed && (this.Group.style.display = "none");
2075 Element[proto].show = function () {
2076 !this.removed && (this.Group.style.display = "block");
2079 Element[proto].getBBox = function () {
2083 if (this.type == "path") {
2084 return pathDimensions(this.attrs.path);
2087 x: this.X + (this.bbx || 0),
2093 Element[proto].remove = function () {
2097 tear(this, this.paper);
2098 this.node.parentNode.removeChild(this.node);
2099 this.Group.parentNode.removeChild(this.Group);
2100 this.shape && this.shape.parentNode.removeChild(this.shape);
2101 for (var i in this) {
2104 this.removed = true;
2106 Element[proto].attr = function () {
2110 if (arguments[length] == 0) {
2112 for (var i in this.attrs) if (this.attrs[has](i)) {
2113 res[i] = this.attrs[i];
2115 this._.rt.deg && (res.rotation = this.rotate());
2116 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
2117 delete res.translation;
2118 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
2121 if (arguments[length] == 1 && R.is(arguments[0], "string")) {
2122 if (arguments[0] == "translation") {
2123 return translate.call(this);
2125 if (arguments[0] == "rotation") {
2126 return this.rotate();
2128 if (arguments[0] == "scale") {
2129 return this.scale();
2131 if (arguments[0] == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
2132 return this.attrs.gradient;
2134 return this.attrs[arguments[0]];
2136 if (this.attrs && arguments[length] == 1 && R.is(arguments[0], "array")) {
2138 for (var i = 0, ii = arguments[0][length]; i < ii; i++) {
2139 values[arguments[0][i]] = this.attrs[arguments[0][i]];
2144 if (arguments[length] == 2) {
2146 params[arguments[0]] = arguments[1];
2148 arguments[length] == 1 && R.is(arguments[0], "object") && (params = arguments[0]);
2150 if (params.text && this.type == "text") {
2151 this.node.string = params.text;
2153 setFillAndStroke(this, params);
2154 if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || (params.gradient + E).charAt() != "r")) {
2155 addGradientFill(this, params.gradient);
2157 (this.type != "path" || this._.rt.deg) && this.setBox(this.attrs);
2161 Element[proto].toFront = function () {
2162 !this.removed && this.Group.parentNode[appendChild](this.Group);
2163 this.paper.top != this && tofront(this, this.paper);
2166 Element[proto].toBack = function () {
2170 if (this.Group.parentNode.firstChild != this.Group) {
2171 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2172 toback(this, this.paper);
2176 Element[proto].insertAfter = function (element) {
2180 if (element.Group.nextSibling) {
2181 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2183 element.Group.parentNode[appendChild](this.Group);
2185 insertafter(this, element, this.paper);
2188 Element[proto].insertBefore = function (element) {
2192 element.Group.parentNode.insertBefore(this.Group, element.Group);
2193 insertbefore(this, element, this.paper);
2197 var theCircle = function (vml, x, y, r) {
2198 var g = createNode("group"),
2199 o = createNode("oval"),
2201 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2202 g.coordsize = vml.coordsize;
2203 g.coordorigin = vml.coordorigin;
2205 var res = new Element(o, g, vml);
2206 res.type = "circle";
2207 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2211 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2212 vml.canvas[appendChild](g);
2215 var theRect = function (vml, x, y, w, h, r) {
2216 var g = createNode("group"),
2217 o = createNode("roundrect"),
2218 arcsize = (+r || 0) / (mmin(w, h));
2219 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2220 g.coordsize = vml.coordsize;
2221 g.coordorigin = vml.coordorigin;
2223 o.arcsize = arcsize;
2224 var res = new Element(o, g, vml);
2226 setFillAndStroke(res, {stroke: "#000"});
2227 res.arcsize = arcsize;
2228 res.setBox({x: x, y: y, width: w, height: h, r: r});
2229 vml.canvas[appendChild](g);
2232 var theEllipse = function (vml, x, y, rx, ry) {
2233 var g = createNode("group"),
2234 o = createNode("oval"),
2236 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2237 g.coordsize = vml.coordsize;
2238 g.coordorigin = vml.coordorigin;
2240 var res = new Element(o, g, vml);
2241 res.type = "ellipse";
2242 setFillAndStroke(res, {stroke: "#000"});
2247 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2248 vml.canvas[appendChild](g);
2251 var theImage = function (vml, src, x, y, w, h) {
2252 var g = createNode("group"),
2253 o = createNode("image"),
2255 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2256 g.coordsize = vml.coordsize;
2257 g.coordorigin = vml.coordorigin;
2260 var res = new Element(o, g, vml);
2262 res.attrs.src = src;
2267 res.setBox({x: x, y: y, width: w, height: h});
2268 vml.canvas[appendChild](g);
2271 var theText = function (vml, x, y, text) {
2272 var g = createNode("group"),
2273 el = createNode("shape"),
2275 path = createNode("path"),
2277 o = createNode("textpath");
2278 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2279 g.coordsize = vml.coordsize;
2280 g.coordorigin = vml.coordorigin;
2281 path.v = R.format("m{0},{1}l{2},{1}", round(x), round(y), round(x) + 1);
2282 path.textpathok = true;
2283 ol.width = vml.width;
2284 ol.height = vml.height;
2285 o.string = text + E;
2288 el[appendChild](path);
2290 var res = new Element(o, g, vml);
2292 res.textpath = path;
2294 res.attrs.text = text;
2299 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2301 vml.canvas[appendChild](g);
2304 var setSize = function (width, height) {
2305 var cs = this.canvas.style;
2306 width == +width && (width += "px");
2307 height == +height && (height += "px");
2310 cs.clip = "rect(0 " + width + " " + height + " 0)";
2313 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2315 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2316 var createNode = function (tagName) {
2317 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2320 var createNode = function (tagName) {
2321 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2324 var create = function () {
2325 var con = getContainer[apply](null, arguments),
2326 container = con.container,
2327 height = con.height,
2333 throw new Error("VML container not found.");
2336 c = res.canvas = doc.createElement("div"),
2338 width = width || 512;
2339 height = height || 342;
2340 width == +width && (width += "px");
2341 height == +height && (height += "px");
2344 res.coordsize = "1000 1000";
2345 res.coordorigin = "0 0";
2346 res.span = doc.createElement("span");
2347 res.span.style.cssText = "position:absolute;left:-9999px;top:-9999px;padding:0;margin:0;line-height:1;display:inline;";
2348 c[appendChild](res.span);
2349 cs.cssText = R.format("width:{0};height:{1};position:absolute;clip:rect(0 {0} {1} 0);overflow:hidden", width, height);
2350 if (container == 1) {
2351 doc.body[appendChild](c);
2361 container.style.width = width;
2362 container.style.height = height;
2363 if (container.firstChild) {
2364 container.insertBefore(c, container.firstChild);
2366 container[appendChild](c);
2369 for (var prop in paper) if (paper[has](prop)) {
2370 res[prop] = paper[prop];
2372 plugins.call(res, res, R.fn);
2373 res.top = res.bottom = null;
2377 paper.clear = function () {
2378 this.canvas.innerHTML = E;
2379 this.bottom = this.top = null;
2381 paper.remove = function () {
2382 this.canvas.parentNode.removeChild(this.canvas);
2383 for (var i in this) {
2390 // Safari or Chrome (WebKit) rendering bug workaround method
2391 if ((/^Apple|^Google/).test(navigator.vendor) && !(navigator.userAgent.indexOf("Version/4.0") + 1)) {
2392 paper.safari = function () {
2393 var rect = this.rect(-99, -99, this.width + 99, this.height + 99);
2394 setTimeout(function () {rect.remove();});
2397 paper.safari = function () {};
2401 var addEvent = (function () {
2402 if (doc.addEventListener) {
2403 return function (obj, type, fn, element) {
2404 var f = function (e) {
2405 return fn.call(element, e);
2407 obj.addEventListener(type, f, false);
2408 return function () {
2409 obj.removeEventListener(type, f, false);
2413 } else if (doc.attachEvent) {
2414 return function (obj, type, fn, element) {
2415 var f = function (e) {
2416 return fn.call(element, e || win.event);
2418 obj.attachEvent("on" + type, f);
2419 var detacher = function () {
2420 obj.detachEvent("on" + type, f);
2427 for (var i = events[length]; i--;) {
2428 (function (eventName) {
2429 Element[proto][eventName] = function (fn) {
2430 if (R.is(fn, "function")) {
2431 this.events = this.events || [];
2432 this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node, eventName, fn, this)});
2436 Element[proto]["un" + eventName] = function (fn) {
2437 var events = this.events,
2439 while (l--) if (events[l].name == eventName && events[l].f == fn) {
2441 events.splice(l, 1);
2442 !events.length && delete this.events;
2449 Element[proto].hover = function (f_in, f_out) {
2450 return this.mouseover(f_in).mouseout(f_out);
2452 Element[proto].unhover = function (f_in, f_out) {
2453 return this.unmouseover(f_in).unmouseout(f_out);
2455 paper.circle = function (x, y, r) {
2456 return theCircle(this, x || 0, y || 0, r || 0);
2458 paper.rect = function (x, y, w, h, r) {
2459 return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
2461 paper.ellipse = function (x, y, rx, ry) {
2462 return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0);
2464 paper.path = function (pathString) {
2465 pathString && !R.is(pathString, "string") && !R.is(pathString[0], "array") && (pathString += E);
2466 return thePath(R.format[apply](R, arguments), this);
2468 paper.image = function (src, x, y, w, h) {
2469 return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
2471 paper.text = function (x, y, text) {
2472 return theText(this, x || 0, y || 0, text || E);
2474 paper.set = function (itemsArray) {
2475 arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length]));
2476 return new Set(itemsArray);
2478 paper.setSize = setSize;
2480 return this.x + S + this.y;
2482 Element[proto].scale = function (x, y, cx, cy) {
2483 if (x == null && y == null) {
2498 var bb = this.getBBox(),
2499 rcx = bb.x + bb.width / 2,
2500 rcy = bb.y + bb.height / 2,
2503 cx = (+cx || cx == 0) ? cx : rcx;
2504 cy = (+cy || cy == 0) ? cy : rcy;
2505 var dirx = ~~(x / math.abs(x)),
2506 diry = ~~(y / math.abs(y)),
2507 s = this.node.style,
2508 ncx = cx + (rcx - cx) * kx,
2509 ncy = cy + (rcy - cy) * ky;
2510 switch (this.type) {
2513 var neww = a.width * dirx * kx,
2514 newh = a.height * diry * ky,
2515 newr = a.r * mmin(kx, ky),
2516 newx = ncx - neww / 2,
2517 newy = ncy - newh / 2;
2529 rx: a.rx * dirx * kx,
2530 ry: a.ry * diry * ky,
2531 r: a.r * mmin(dirx * kx, diry * ky),
2537 var path = pathToRelative(a.path),
2539 for (var i = 0, ii = path[length]; i < ii; i++) {
2542 P0 = upperCase.call(p[0]);
2543 if (P0 == "M" && skip) {
2549 p[path[i][length] - 2] *= kx;
2550 p[path[i][length] - 1] *= ky;
2553 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2554 } else if (P0 == "H") {
2555 for (j = 1, jj = p[length]; j < jj; j++) {
2558 } else if (P0 == "V") {
2559 for (j = 1, jj = p[length]; j < jj; j++) {
2563 for (j = 1, jj = p[length]; j < jj; j++) {
2564 p[j] *= (j % 2) ? kx : ky;
2568 var dim2 = pathDimensions(path),
2569 dx = ncx - dim2.x - dim2.width / 2,
2570 dy = ncy - dim2.y - dim2.height / 2;
2574 this.attr({path: path});
2577 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2578 if (this.transformations) {
2579 this.transformations[2] = "scale("[concat](dirx, ",", diry, ")");
2580 this.node[setAttribute]("transform", this.transformations[join](S));
2581 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2582 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2583 this.attr({x: dx, y: dy});
2587 this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11="[concat](dirx,
2588 ", M12=0, M21=0, M22=", diry,
2589 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2590 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2593 if (this.transformations) {
2594 this.transformations[2] = E;
2595 this.node[setAttribute]("transform", this.transformations[join](S));
2599 this.node.filterMatrix = E;
2600 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2603 a.scale = [x, y, cx, cy][join](S);
2609 Element[proto].clone = function () {
2610 return this.paper[this.type]().attr(this.attr());
2613 // animation easing formulas
2614 R.easing_formulas = {
2615 linear: function (n) {
2622 return pow(n - 1, 3) + 1;
2624 "<>": function (n) {
2627 return pow(n, 3) / 2;
2630 return (pow(n, 3) + 2) / 2;
2632 backIn: function (n) {
2634 return n * n * ((s + 1) * n - s);
2636 backOut: function (n) {
2639 return n * n * ((s + 1) * n + s) + 1;
2641 elastic: function (n) {
2642 if (n == 0 || n == 1) {
2647 return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1;
2649 bounce: function (n) {
2658 l = s * n * n + .75;
2660 if (n < (2.5 / p)) {
2662 l = s * n * n + .9375;
2665 l = s * n * n + .984375;
2673 var animationElements = {length : 0},
2674 animation = function () {
2675 var Now = +new Date;
2676 for (var l in animationElements) if (l != "length" && animationElements[has](l)) {
2677 var e = animationElements[l];
2679 delete animationElements[l];
2680 animationElements[length]--;
2683 var time = Now - e.start,
2692 callback = e.callback,
2696 var pos = R.easing_formulas[easing] ? R.easing_formulas[easing](time / ms) : time / ms;
2697 for (var attr in from) if (from[has](attr)) {
2698 switch (availableAnimAttrs[attr]) {
2700 now = +from[attr] + pos * ms * diff[attr];
2704 upto255(round(from[attr].r + pos * ms * diff[attr].r)),
2705 upto255(round(from[attr].g + pos * ms * diff[attr].g)),
2706 upto255(round(from[attr].b + pos * ms * diff[attr].b))
2711 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
2712 now[i] = [from[attr][i][0]];
2713 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
2714 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
2716 now[i] = now[i][join](S);
2723 var x = diff[attr][0] * (time - prev),
2724 y = diff[attr][1] * (time - prev);
2730 now = +from[attr][0] + pos * ms * diff[attr][0];
2731 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
2734 now = [+from[attr][0] + pos * ms * diff[attr][0], +from[attr][1] + pos * ms * diff[attr][1], (2 in to[attr] ? to[attr][2] : E), (3 in to[attr] ? to[attr][3] : E)][join](S);
2740 now[i] = +from[attr][i] + pos * ms * diff[attr][i];
2749 that._run && that._run.call(that);
2751 (t.x || t.y) && that.translate(-t.x, -t.y);
2752 to.scale && (to.scale = to.scale + E);
2754 delete animationElements[l];
2755 animationElements[length]--;
2756 that.in_animation = null;
2757 R.is(callback, "function") && callback.call(that);
2761 R.svg && paper.safari();
2762 animationElements[length] && setTimeout(animation);
2764 upto255 = function (color) {
2765 return color > 255 ? 255 : (color < 0 ? 0 : color);
2767 translate = function (x, y) {
2769 return {x: this._.tx, y: this._.ty, toString: x_y};
2773 switch (this.type) {
2776 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
2781 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
2784 var path = pathToRelative(this.attrs.path);
2787 this.attr({path: path});
2792 Element[proto].animateWith = function (element, params, ms, easing, callback) {
2793 animationElements[element.id] && (params.start = animationElements[element.id].start);
2794 return this.animate(params, ms, easing, callback);
2796 Element[proto].onAnimation = function (f) {
2797 this._run = f || null;
2800 Element[proto].animate = function (params, ms, easing, callback) {
2801 if (R.is(easing, "function") || !easing) {
2802 callback = easing || null;
2807 for (var attr in params) if (params[has](attr)) {
2808 if (availableAnimAttrs[has](attr)) {
2809 from[attr] = this.attr(attr);
2810 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
2811 to[attr] = params[attr];
2812 switch (availableAnimAttrs[attr]) {
2814 diff[attr] = (to[attr] - from[attr]) / ms;
2817 from[attr] = R.getRGB(from[attr]);
2818 var toColour = R.getRGB(to[attr]);
2820 r: (toColour.r - from[attr].r) / ms,
2821 g: (toColour.g - from[attr].g) / ms,
2822 b: (toColour.b - from[attr].b) / ms
2826 var pathes = path2curve(from[attr], to[attr]);
2827 from[attr] = pathes[0];
2828 to[attr] = pathes[1];
2830 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
2831 diff[attr][i] = [0];
2832 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
2833 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2838 var values = (params[attr] + E)[split](separator),
2839 from2 = (from[attr] + E)[split](separator);
2842 from[attr] = [0, 0];
2843 diff[attr] = [values[0] / ms, values[1] / ms];
2846 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
2847 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
2850 params[attr] = values;
2851 from[attr] = (from[attr] + E)[split](separator);
2852 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
2855 from[attr] = (from[attr] + E)[split](separator);
2859 diff[attr][i] = (values[i] - from[attr][i]) / ms;
2868 this.in_animation = 1;
2869 animationElements[this.id] = {
2870 start: params.start || +new Date,
2880 ++animationElements[length] == 1 && animation();
2883 Element[proto].stop = function () {
2884 animationElements[this.id] && animationElements[length]--;
2885 delete animationElements[this.id];
2888 Element[proto].translate = function (x, y) {
2889 return this.attr({translation: x + " " + y});
2891 Element[proto][toString] = function () {
2892 return "Rapha\xebl\u2019s object";
2894 R.ae = animationElements;
2897 var Set = function (items) {
2901 for (var i = 0, ii = items[length]; i < ii; i++) {
2902 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
2903 this[this.items[length]] = this.items[this.items[length]] = items[i];
2909 Set[proto][push] = function () {
2912 for (var i = 0, ii = arguments[length]; i < ii; i++) {
2913 item = arguments[i];
2914 if (item && (item.constructor == Element || item.constructor == Set)) {
2915 len = this.items[length];
2916 this[len] = this.items[len] = item;
2922 Set[proto].pop = function () {
2923 delete this[this[length]--];
2924 return this.items.pop();
2926 for (var method in Element[proto]) if (Element[proto][has](method)) {
2927 Set[proto][method] = (function (methodname) {
2928 return function () {
2929 for (var i = 0, ii = this.items[length]; i < ii; i++) {
2930 this.items[i][methodname][apply](this.items[i], arguments);
2936 Set[proto].attr = function (name, value) {
2937 if (name && R.is(name, "array") && R.is(name[0], "object")) {
2938 for (var j = 0, jj = name[length]; j < jj; j++) {
2939 this.items[j].attr(name[j]);
2942 for (var i = 0, ii = this.items[length]; i < ii; i++) {
2943 this.items[i].attr[apply](this.items[i], arguments);
2948 Set[proto].animate = function (params, ms, easing, callback) {
2949 (R.is(easing, "function") || !easing) && (callback = easing || null);
2950 var len = this.items[length],
2954 callback && (collector = function () {
2955 !--len && callback.call(set);
2957 this.items[--i].animate(params, ms, easing || collector, collector);
2959 this.items[i].animateWith(this.items[len - 1], params, ms, easing || collector, collector);
2963 Set[proto].insertAfter = function (el) {
2964 var i = this.items[length];
2966 this.items[i].insertAfter(el);
2970 Set[proto].getBBox = function () {
2975 for (var i = this.items[length]; i--;) {
2976 var box = this.items[i].getBBox();
2979 w[push](box.x + box.width);
2980 h[push](box.y + box.height);
2982 x = mmin[apply](0, x);
2983 y = mmin[apply](0, y);
2987 width: mmax[apply](0, w) - x,
2988 height: mmax[apply](0, h) - y
2992 R.registerFont = function (font) {
2996 this.fonts = this.fonts || {};
3002 family = font.face["font-family"];
3003 for (var prop in font.face) if (font.face[has](prop)) {
3004 fontcopy.face[prop] = font.face[prop];
3006 if (this.fonts[family]) {
3007 this.fonts[family][push](fontcopy);
3009 this.fonts[family] = [fontcopy];
3012 fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
3013 for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
3014 var path = font.glyphs[glyph];
3015 fontcopy.glyphs[glyph] = {
3018 d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) {
3019 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
3023 for (var k in path.k) if (path[has](k)) {
3024 fontcopy.glyphs[glyph].k[k] = path.k[k];
3031 paper.getFont = function (family, weight, style, stretch) {
3032 stretch = stretch || "normal";
3033 style = style || "normal";
3034 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
3035 var font = R.fonts[family];
3037 var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
3038 for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
3039 if (name.test(fontName)) {
3040 font = R.fonts[fontName];
3047 for (var i = 0, ii = font[length]; i < ii; i++) {
3049 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
3056 paper.print = function (x, y, string, font, size, origin) {
3057 origin = origin || "middle"; // baseline|middle
3058 var out = this.set(),
3059 letters = (string + E)[split](E),
3063 R.is(font, "string") && (font = this.getFont(font));
3065 scale = (size || 16) / font.face["units-per-em"];
3066 var bb = font.face.bbox.split(separator),
3068 height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
3069 for (var i = 0, ii = letters[length]; i < ii; i++) {
3070 var prev = i && font.glyphs[letters[i - 1]] || {},
3071 curr = font.glyphs[letters[i]];
3072 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
3073 curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
3075 out.scale(scale, scale, top, height).translate(x - top, y - height);
3080 R.format = function (token) {
3081 var args = R.is(arguments[1], "array") ? [0][concat](arguments[1]) : arguments,
3083 token && R.is(token, "string") && args[length] - 1 && (token = token[rp](rg, function (str, i) {
3084 return args[++i] == null ? E : args[i];
3088 R.ninja = function () {
3089 var r = win.Raphael, u;
3090 if (oldRaphael.was) {
3091 win.Raphael = oldRaphael.is;
3101 R.el = Element[proto];