1 // ┌─────────────────────────────────────────────────────────────────────┐ \\
2 // │ Raphaël 2.0.1 - JavaScript Vector Library │ \\
3 // ├─────────────────────────────────────────────────────────────────────┤ \\
4 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
5 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
6 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
7 // └─────────────────────────────────────────────────────────────────────┘ \\
9 // ┌──────────────────────────────────────────────────────────────────────────────────────┐ \\
10 // │ Eve 0.4.0 - JavaScript Events Library │ \\
11 // ├──────────────────────────────────────────────────────────────────────────────────────┤ \\
12 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\
13 // │ Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. │ \\
14 // └──────────────────────────────────────────────────────────────────────────────────────┘ \\
17 var version = "0.4.0",
18 has = "hasOwnProperty",
22 numsort = function (a, b) {
29 eve = function (name, scope) {
32 args = Array.prototype.slice.call(arguments, 2),
33 listeners = eve.listeners(name),
43 for (var i = 0, ii = listeners.length; i < ii; i++) if ("zIndex" in listeners[i]) {
44 indexed.push(listeners[i].zIndex);
45 if (listeners[i].zIndex < 0) {
46 queue[listeners[i].zIndex] = listeners[i];
49 indexed.sort(numsort);
50 while (indexed[z] < 0) {
51 l = queue[indexed[z++]];
52 out.push(l.apply(scope, args));
58 for (i = 0; i < ii; i++) {
61 if (l.zIndex == indexed[z]) {
62 out.push(l.apply(scope, args));
69 l = queue[indexed[z]];
70 l && out.push(l.apply(scope, args));
80 out.push(l.apply(scope, args));
88 return out.length ? out : null;
91 eve.listeners = function (name) {
92 var names = name.split(separator),
104 for (i = 0, ii = names.length; i < ii; i++) {
106 for (j = 0, jj = es.length; j < jj; j++) {
108 items = [e[names[i]], e[wildcard]];
114 out = out.concat(item.f || []);
124 eve.on = function (name, f) {
125 var names = name.split(separator),
127 for (var i = 0, ii = names.length; i < ii; i++) {
129 !e[names[i]] && (e[names[i]] = {n: {}});
133 for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) {
137 return function (zIndex) {
138 if (+zIndex == +zIndex) {
144 eve.stop = function () {
148 eve.nt = function (subname) {
150 return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(current_event);
152 return current_event;
155 eve.unbind = function (name, f) {
156 var names = name.split(separator),
162 for (i = 0, ii = names.length; i < ii; i++) {
163 for (j = 0; j < cur.length; j += splice.length - 2) {
166 if (names[i] != wildcard) {
168 splice.push(e[names[i]]);
171 for (key in e) if (e[has](key)) {
175 cur.splice.apply(cur, splice);
178 for (i = 0, ii = cur.length; i < ii; i++) {
183 for (j = 0, jj = e.f.length; j < jj; j++) if (e.f[j] == f) {
187 !e.f.length && delete e.f;
189 for (key in e.n) if (e.n[has](key) && e.n[key].f) {
190 var funcs = e.n[key].f;
191 for (j = 0, jj = funcs.length; j < jj; j++) if (funcs[j] == f) {
195 !funcs.length && delete e.n[key].f;
199 for (key in e.n) if (e.n[has](key) && e.n[key].f) {
208 eve.once = function (name, f) {
209 var f2 = function () {
210 f.apply(this, arguments);
211 eve.unbind(name, f2);
213 return eve.on(name, f2);
216 eve.version = version;
217 eve.toString = function () {
218 return "You are running Eve " + version;
220 (typeof module != "undefined" && module.exports) ? (module.exports = eve) : (glob.eve = eve);
223 // ┌─────────────────────────────────────────────────────────────────────┐ \\
224 // │ "Raphaël 2.0.1" - JavaScript Vector Library │ \\
225 // ├─────────────────────────────────────────────────────────────────────┤ \\
226 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
227 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
228 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
229 // └─────────────────────────────────────────────────────────────────────┘ \\
234 if (R.is(first, "function")) {
235 return loaded ? first() : eve.on("DOMload", first);
236 } else if (R.is(first, array)) {
237 return R._engine.create[apply](R, first.splice(0, 3 + R.is(first[0], nu))).add(first);
239 var args = Array.prototype.slice.call(arguments, 0);
240 if (R.is(args[args.length - 1], "function")) {
242 return loaded ? f.call(R._engine.create[apply](R, args)) : eve.on("DOMload", function () {
243 f.call(R._engine.create[apply](R, args));
246 return R._engine.create[apply](R, arguments);
254 elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
255 formatrg = /\{(\d+)\}/g,
257 has = "hasOwnProperty",
263 was: Object.prototype[has].call(g.win, "Raphael"),
266 Paper = function () {
269 this.ca = this.customAttributes = {};
272 appendChild = "appendChild",
275 supportsTouch = "createTouch" in g.doc,
280 events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[split](S),
282 mousedown: "touchstart",
283 mousemove: "touchmove",
286 lowerCase = Str.prototype.toLowerCase,
296 toString = "toString",
298 objectToString = Object.prototype.toString,
301 ISURL = R._ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
302 colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i,
303 isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
304 bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
306 setAttribute = "setAttribute",
307 toFloat = parseFloat,
309 upperCase = Str.prototype.toUpperCase,
310 availableAttrs = R._availableAttrs = {
312 "arrow-start": "none",
314 "clip-rect": "0 0 1e9 1e9",
320 font: '10px "Arial"',
321 "font-family": '"Arial"',
323 "font-style": "normal",
327 href: "http://raphaeljs.com/",
336 "stroke-dasharray": "",
337 "stroke-linecap": "butt",
338 "stroke-linejoin": "butt",
339 "stroke-miterlimit": 0,
343 "text-anchor": "middle",
350 availableAnimAttrs = R._availableAnimAttrs = {
365 "stroke-opacity": nu,
367 transform: "transform",
372 commaSpaces = /\s*,\s*/,
373 hsrg = {hs: 1, rg: 1},
374 p2s = /,?([achlmqrstvxz]),?/gi,
375 pathCommand = /([achlmrqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
376 tCommand = /([rstm])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
377 pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)\s*,?\s*/ig,
378 radial_gradient = R._radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/,
380 sortByKey = function (a, b) {
381 return a.key - b.key;
383 sortByNumber = function (a, b) {
384 return toFloat(a) - toFloat(b);
386 fun = function () {},
387 pipe = function (x) {
390 rectPath = R._rectPath = function (x, y, w, h, r) {
392 return [["M", x + r, y], ["l", w - r * 2, 0], ["a", r, r, 0, 0, 1, r, r], ["l", 0, h - r * 2], ["a", r, r, 0, 0, 1, -r, r], ["l", r * 2 - w, 0], ["a", r, r, 0, 0, 1, -r, -r], ["l", 0, r * 2 - h], ["a", r, r, 0, 0, 1, r, -r], ["z"]];
394 return [["M", x, y], ["l", w, 0], ["l", 0, h], ["l", -w, 0], ["z"]];
396 ellipsePath = function (x, y, rx, ry) {
400 return [["M", x, y], ["m", 0, -ry], ["a", rx, ry, 0, 1, 1, 0, 2 * ry], ["a", rx, ry, 0, 1, 1, 0, -2 * ry], ["z"]];
402 getPath = R._getPath = {
403 path: function (el) {
404 return el.attr("path");
406 circle: function (el) {
408 return ellipsePath(a.cx, a.cy, a.r);
410 ellipse: function (el) {
412 return ellipsePath(a.cx, a.cy, a.rx, a.ry);
414 rect: function (el) {
416 return rectPath(a.x, a.y, a.width, a.height, a.r);
418 image: function (el) {
420 return rectPath(a.x, a.y, a.width, a.height);
422 text: function (el) {
423 var bbox = el._getBBox();
424 return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
427 mapPath = R.mapPath = function (path, matrix) {
431 var x, y, i, j, ii, jj, pathi;
432 path = path2curve(path);
433 for (i = 0, ii = path.length; i < ii; i++) {
435 for (j = 1, jj = pathi.length; j < jj; j += 2) {
436 x = matrix.x(pathi[j], pathi[j + 1]);
437 y = matrix.y(pathi[j], pathi[j + 1]);
447 R.type = (g.win.SVGAngle || g.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
448 if (R.type == "VML") {
449 var d = g.doc.createElement("div"),
451 d.innerHTML = '<v:shape adj="1"/>';
453 b.style.behavior = "url(#default#VML)";
454 if (!(b && typeof b.adj == "object")) {
461 R.svg = !(R.vml = R.type == "VML");
464 R.fn = paperproto = Paper.prototype = R.prototype;
468 R.is = function (o, type) {
469 type = lowerCase.call(type);
470 if (type == "finite") {
471 return !isnan[has](+o);
473 if (type == "array") {
474 return o instanceof Array;
476 return (type == "null" && o === null) ||
477 (type == typeof o && o !== null) ||
478 (type == "object" && o === Object(o)) ||
479 (type == "array" && Array.isArray && Array.isArray(o)) ||
480 objectToString.call(o).slice(8, -1).toLowerCase() == type;
483 R.angle = function (x1, y1, x2, y2, x3, y3) {
490 return (180 + math.atan2(-y, -x) * 180 / PI + 360) % 360;
492 return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
496 R.rad = function (deg) {
497 return deg % 360 * PI / 180;
500 R.deg = function (rad) {
501 return rad * 180 / PI % 360;
504 R.snapTo = function (values, value, tolerance) {
505 tolerance = R.is(tolerance, "finite") ? tolerance : 10;
506 if (R.is(values, array)) {
507 var i = values.length;
508 while (i--) if (abs(values[i] - value) <= tolerance) {
513 var rem = value % values;
514 if (rem < tolerance) {
517 if (rem > values - tolerance) {
518 return value - rem + values;
525 var createUUID = R.createUUID = (function (uuidRegEx, uuidReplacer) {
527 return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase();
529 })(/[xy]/g, function (c) {
530 var r = math.random() * 16 | 0,
531 v = c == "x" ? r : (r & 3 | 8);
532 return v.toString(16);
536 R.setWindow = function (newwin) {
537 eve("setWindow", R, g.win, newwin);
539 g.doc = g.win.document;
540 if (R._engine.initWin) {
541 R._engine.initWin(g.win);
544 var toHex = function (color) {
546 // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
547 var trim = /^\s+|\s+$/g;
550 var docum = new ActiveXObject("htmlfile");
551 docum.write("<body>");
555 bod = createPopup().document.body;
557 var range = bod.createTextRange();
558 toHex = cacher(function (color) {
560 bod.style.color = Str(color).replace(trim, E);
561 var value = range.queryCommandValue("ForeColor");
562 value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
563 return "#" + ("000000" + value.toString(16)).slice(-6);
569 var i = g.doc.createElement("i");
570 i.title = "Rapha\xebl Colour Picker";
571 i.style.display = "none";
572 g.doc.body.appendChild(i);
573 toHex = cacher(function (color) {
574 i.style.color = color;
575 return g.doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
580 hsbtoString = function () {
581 return "hsb(" + [this.h, this.s, this.b] + ")";
583 hsltoString = function () {
584 return "hsl(" + [this.h, this.s, this.l] + ")";
586 rgbtoString = function () {
589 prepareRGB = function (r, g, b) {
590 if (g == null && R.is(r, "object") && "r" in r && "g" in r && "b" in r) {
595 if (g == null && R.is(r, string)) {
596 var clr = R.getRGB(r);
601 if (r > 1 || g > 1 || b > 1) {
609 packageRGB = function (r, g, b, o) {
618 toString: rgbtoString
620 R.is(o, "finite") && (rgb.opacity = o);
625 R.color = function (clr) {
627 if (R.is(clr, "object") && "h" in clr && "s" in clr && "b" in clr) {
628 rgb = R.hsb2rgb(clr);
633 } else if (R.is(clr, "object") && "h" in clr && "s" in clr && "l" in clr) {
634 rgb = R.hsl2rgb(clr);
640 if (R.is(clr, "string")) {
643 if (R.is(clr, "object") && "r" in clr && "g" in clr && "b" in clr) {
644 rgb = R.rgb2hsl(clr);
648 rgb = R.rgb2hsb(clr);
652 clr.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1;
655 clr.toString = rgbtoString;
659 R.hsb2rgb = function (h, s, v, o) {
660 if (this.is(h, "object") && "h" in h && "s" in h && "b" in h) {
670 X = C * (1 - abs(h % 2 - 1));
674 R += [C, X, 0, 0, X, C][h];
675 G += [X, C, C, X, 0, 0][h];
676 B += [0, 0, X, C, C, X][h];
677 return packageRGB(R, G, B, o);
680 R.hsl2rgb = function (h, s, l, o) {
681 if (this.is(h, "object") && "h" in h && "s" in h && "l" in h) {
686 if (h > 1 || s > 1 || l > 1) {
694 C = 2 * s * (l < .5 ? l : 1 - l);
695 X = C * (1 - abs(h % 2 - 1));
696 R = G = B = l - C / 2;
699 R += [C, X, 0, 0, X, C][h];
700 G += [X, C, C, X, 0, 0][h];
701 B += [0, 0, X, C, C, X][h];
702 return packageRGB(R, G, B, o);
705 R.rgb2hsb = function (r, g, b) {
706 b = prepareRGB(r, g, b);
713 C = V - mmin(r, g, b);
715 V == r ? (g - b) / C :
716 V == g ? (b - r) / C + 2 :
719 H = ((H + 360) % 6) * 60 / 360;
720 S = C == 0 ? 0 : C / V;
721 return {h: H, s: S, b: V, toString: hsbtoString};
724 R.rgb2hsl = function (r, g, b) {
725 b = prepareRGB(r, g, b);
730 var H, S, L, M, m, C;
735 M == r ? (g - b) / C :
736 M == g ? (b - r) / C + 2 :
738 H = ((H + 360) % 6) * 60 / 360;
741 L < .5 ? C / (2 * L) :
743 return {h: H, s: S, l: L, toString: hsltoString};
745 R._path2string = function () {
746 return this.join(",").replace(p2s, "$1");
748 function repush(array, item) {
749 for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
750 return array.push(array.splice(i, 1)[0]);
753 function cacher(f, scope, postprocessor) {
755 var arg = Array.prototype.slice.call(arguments, 0),
756 args = arg.join("\u2400"),
757 cache = newf.cache = newf.cache || {},
758 count = newf.count = newf.count || [];
759 if (cache[has](args)) {
761 return postprocessor ? postprocessor(cache[args]) : cache[args];
763 count.length >= 1e3 && delete cache[count.shift()];
765 cache[args] = f[apply](scope, arg);
766 return postprocessor ? postprocessor(cache[args]) : cache[args];
771 var preload = R._preload = function (src, f) {
772 var img = g.doc.createElement("img");
773 img.style.cssText = "position:absolute;left:-9999em;top:-9999em";
774 img.onload = function () {
777 g.doc.body.removeChild(this);
779 img.onerror = function () {
780 g.doc.body.removeChild(this);
782 g.doc.body.appendChild(img);
786 function clrToString() {
791 R.getRGB = cacher(function (colour) {
792 if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
793 return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
795 if (colour == "none") {
796 return {r: -1, g: -1, b: -1, hex: "none", toString: clrToString};
798 !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
806 rgb = colour.match(colourRegExp);
809 blue = toInt(rgb[2].substring(5), 16);
810 green = toInt(rgb[2].substring(3, 5), 16);
811 red = toInt(rgb[2].substring(1, 3), 16);
814 blue = toInt((t = rgb[3].charAt(3)) + t, 16);
815 green = toInt((t = rgb[3].charAt(2)) + t, 16);
816 red = toInt((t = rgb[3].charAt(1)) + t, 16);
819 values = rgb[4][split](commaSpaces);
820 red = toFloat(values[0]);
821 values[0].slice(-1) == "%" && (red *= 2.55);
822 green = toFloat(values[1]);
823 values[1].slice(-1) == "%" && (green *= 2.55);
824 blue = toFloat(values[2]);
825 values[2].slice(-1) == "%" && (blue *= 2.55);
826 rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3]));
827 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
830 values = rgb[5][split](commaSpaces);
831 red = toFloat(values[0]);
832 values[0].slice(-1) == "%" && (red *= 2.55);
833 green = toFloat(values[1]);
834 values[1].slice(-1) == "%" && (green *= 2.55);
835 blue = toFloat(values[2]);
836 values[2].slice(-1) == "%" && (blue *= 2.55);
837 (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
838 rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3]));
839 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
840 return R.hsb2rgb(red, green, blue, opacity);
843 values = rgb[6][split](commaSpaces);
844 red = toFloat(values[0]);
845 values[0].slice(-1) == "%" && (red *= 2.55);
846 green = toFloat(values[1]);
847 values[1].slice(-1) == "%" && (green *= 2.55);
848 blue = toFloat(values[2]);
849 values[2].slice(-1) == "%" && (blue *= 2.55);
850 (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
851 rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3]));
852 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
853 return R.hsl2rgb(red, green, blue, opacity);
855 rgb = {r: red, g: green, b: blue, toString: clrToString};
856 rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1);
857 R.is(opacity, "finite") && (rgb.opacity = opacity);
860 return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
863 R.hsb = cacher(function (h, s, b) {
864 return R.hsb2rgb(h, s, b).hex;
867 R.hsl = cacher(function (h, s, l) {
868 return R.hsl2rgb(h, s, l).hex;
871 R.rgb = cacher(function (r, g, b) {
872 return "#" + (16777216 | b | (g << 8) | (r << 16)).toString(16).slice(1);
875 R.getColor = function (value) {
876 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
877 rgb = this.hsb2rgb(start.h, start.s, start.b);
882 start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
887 R.getColor.reset = function () {
891 // http://schepers.cc/getting-to-the-point
892 function catmullRom2bezier(crp) {
894 for (var i = 0, iLen = crp.length; iLen - 2 > i; i += 2) {
895 var p = [{x: +crp[i], y: +crp[i + 1]},
896 {x: +crp[i], y: +crp[i + 1]},
897 {x: +crp[i + 2], y: +crp[i + 3]},
898 {x: +crp[i + 4], y: +crp[i + 5]}];
900 p[0] = {x: +crp[i - 2], y: +crp[i - 1]};
903 p[0] = {x: +crp[i - 2], y: +crp[i - 1]};
906 (-p[0].x + 6 * p[1].x + p[2].x) / 6,
907 (-p[0].y + 6 * p[1].y + p[2].y) / 6,
908 (p[1].x + 6 * p[2].x - p[3].x) / 6,
909 (p[1].y + 6*p[2].y - p[3].y) / 6,
918 R.parsePathString = cacher(function (pathString) {
922 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
924 if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
925 data = pathClone(pathString);
928 Str(pathString).replace(pathCommand, function (a, b, c) {
930 name = b.toLowerCase();
931 c.replace(pathValues, function (a, b) {
932 b && params.push(+b);
934 if (name == "m" && params.length > 2) {
935 data.push([b][concat](params.splice(0, 2)));
937 b = b == "m" ? "l" : "L";
940 data.push([b][concat](params));
941 } else while (params.length >= paramCounts[name]) {
942 data.push([b][concat](params.splice(0, paramCounts[name])));
943 if (!paramCounts[name]) {
949 data.toString = R._path2string;
953 R.parseTransformString = cacher(function (TString) {
957 var paramCounts = {r: 3, s: 4, t: 2, m: 6},
959 if (R.is(TString, array) && R.is(TString[0], array)) { // rough assumption
960 data = pathClone(TString);
963 Str(TString).replace(tCommand, function (a, b, c) {
965 name = lowerCase.call(b);
966 c.replace(pathValues, function (a, b) {
967 b && params.push(+b);
969 data.push([b][concat](params));
972 data.toString = R._path2string;
976 R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
982 x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
983 y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y,
984 mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x),
985 my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y),
986 nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x),
987 ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y),
988 ax = t1 * p1x + t * c1x,
989 ay = t1 * p1y + t * c1y,
990 cx = t1 * c2x + t * p2x,
991 cy = t1 * c2y + t * p2y,
992 alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
993 (mx > nx || my < ny) && (alpha += 180);
999 start: {x: ax, y: ay},
1000 end: {x: cx, y: cy},
1004 R._removedFactory = function (methodname) {
1005 return function () {
1006 throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
1009 var pathDimensions = cacher(function (path) {
1011 return {x: 0, y: 0, width: 0, height: 0};
1013 path = path2curve(path);
1019 for (var i = 0, ii = path.length; i < ii; i++) {
1027 var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
1028 X = X[concat](dim.min.x, dim.max.x);
1029 Y = Y[concat](dim.min.y, dim.max.y);
1034 var xmin = mmin[apply](0, X),
1035 ymin = mmin[apply](0, Y);
1039 width: mmax[apply](0, X) - xmin,
1040 height: mmax[apply](0, Y) - ymin
1042 }, null, function (o) {
1050 pathClone = function (pathArray) {
1052 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
1053 pathArray = R.parsePathString(pathArray);
1055 for (var i = 0, ii = pathArray.length; i < ii; i++) {
1057 for (var j = 0, jj = pathArray[i].length; j < jj; j++) {
1058 res[i][j] = pathArray[i][j];
1061 res.toString = R._path2string;
1064 pathToRelative = R._pathToRelative = cacher(function (pathArray) {
1065 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
1066 pathArray = R.parsePathString(pathArray);
1074 if (pathArray[0][0] == "M") {
1075 x = pathArray[0][1];
1076 y = pathArray[0][2];
1080 res.push(["M", x, y]);
1082 for (var i = start, ii = pathArray.length; i < ii; i++) {
1083 var r = res[i] = [],
1085 if (pa[0] != lowerCase.call(pa[0])) {
1086 r[0] = lowerCase.call(pa[0]);
1094 r[6] = +(pa[6] - x).toFixed(3);
1095 r[7] = +(pa[7] - y).toFixed(3);
1098 r[1] = +(pa[1] - y).toFixed(3);
1104 for (var j = 1, jj = pa.length; j < jj; j++) {
1105 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
1114 for (var k = 0, kk = pa.length; k < kk; k++) {
1118 var len = res[i].length;
1119 switch (res[i][0]) {
1125 x += +res[i][len - 1];
1128 y += +res[i][len - 1];
1131 x += +res[i][len - 2];
1132 y += +res[i][len - 1];
1135 res.toString = R._path2string;
1138 pathToAbsolute = R._pathToAbsolute = cacher(function (pathArray) {
1139 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
1140 pathArray = R.parsePathString(pathArray);
1142 if (!pathArray || !pathArray.length) {
1143 return [["M", 0, 0]];
1151 if (pathArray[0][0] == "M") {
1152 x = +pathArray[0][1];
1153 y = +pathArray[0][2];
1157 res[0] = ["M", x, y];
1159 for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
1162 if (pa[0] != upperCase.call(pa[0])) {
1163 r[0] = upperCase.call(pa[0]);
1171 r[6] = +(pa[6] + x);
1172 r[7] = +(pa[7] + y);
1181 var dots = [x, y][concat](pa.slice(1));
1182 for (var j = 2, jj = dots.length; j < jj; j++) {
1183 dots[j] = +dots[j] + x;
1184 dots[++j] = +dots[j] + y;
1187 res = res[concat](catmullRom2bezier(dots));
1193 for (j = 1, jj = pa.length; j < jj; j++) {
1194 r[j] = +pa[j] + ((j % 2) ? x : y);
1197 } else if (pa[0] == "R") {
1198 dots = [x, y][concat](pa.slice(1));
1200 res = res[concat](catmullRom2bezier(dots));
1201 r = ["R"][concat](pa.slice(-2));
1203 for (var k = 0, kk = pa.length; k < kk; k++) {
1219 mx = r[r.length - 2];
1220 my = r[r.length - 1];
1222 x = r[r.length - 2];
1223 y = r[r.length - 1];
1226 res.toString = R._path2string;
1228 }, null, pathClone),
1229 l2c = function (x1, y1, x2, y2) {
1230 return [x1, y1, x2, y2, x2, y2];
1232 q2c = function (x1, y1, ax, ay, x2, y2) {
1236 _13 * x1 + _23 * ax,
1237 _13 * y1 + _23 * ay,
1238 _13 * x2 + _23 * ax,
1239 _13 * y2 + _23 * ay,
1244 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
1245 // for more information of where this math came from visit:
1246 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1247 var _120 = PI * 120 / 180,
1248 rad = PI / 180 * (+angle || 0),
1251 rotate = cacher(function (x, y, rad) {
1252 var X = x * math.cos(rad) - y * math.sin(rad),
1253 Y = x * math.sin(rad) + y * math.cos(rad);
1254 return {x: X, y: Y};
1257 xy = rotate(x1, y1, -rad);
1260 xy = rotate(x2, y2, -rad);
1263 var cos = math.cos(PI / 180 * angle),
1264 sin = math.sin(PI / 180 * angle),
1267 var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
1275 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1276 math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
1277 cx = k * rx * y / ry + (x1 + x2) / 2,
1278 cy = k * -ry * x / rx + (y1 + y2) / 2,
1279 f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
1280 f2 = math.asin(((y2 - cy) / ry).toFixed(9));
1282 f1 = x1 < cx ? PI - f1 : f1;
1283 f2 = x2 < cx ? PI - f2 : f2;
1284 f1 < 0 && (f1 = PI * 2 + f1);
1285 f2 < 0 && (f2 = PI * 2 + f2);
1286 if (sweep_flag && f1 > f2) {
1289 if (!sweep_flag && f2 > f1) {
1299 if (abs(df) > _120) {
1303 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
1304 x2 = cx + rx * math.cos(f2);
1305 y2 = cy + ry * math.sin(f2);
1306 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
1309 var c1 = math.cos(f1),
1313 t = math.tan(df / 4),
1314 hx = 4 / 3 * rx * t,
1315 hy = 4 / 3 * ry * t,
1317 m2 = [x1 + hx * s1, y1 - hy * c1],
1318 m3 = [x2 + hx * s2, y2 - hy * c2],
1320 m2[0] = 2 * m1[0] - m2[0];
1321 m2[1] = 2 * m1[1] - m2[1];
1323 return [m2, m3, m4][concat](res);
1325 res = [m2, m3, m4][concat](res).join()[split](",");
1327 for (var i = 0, ii = res.length; i < ii; i++) {
1328 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
1333 findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
1336 x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
1337 y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
1340 curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
1341 var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
1342 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
1344 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
1345 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
1349 abs(t1) > "1e12" && (t1 = .5);
1350 abs(t2) > "1e12" && (t2 = .5);
1351 if (t1 > 0 && t1 < 1) {
1352 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
1356 if (t2 > 0 && t2 < 1) {
1357 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
1361 a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
1362 b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
1364 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
1365 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
1366 abs(t1) > "1e12" && (t1 = .5);
1367 abs(t2) > "1e12" && (t2 = .5);
1368 if (t1 > 0 && t1 < 1) {
1369 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
1373 if (t2 > 0 && t2 < 1) {
1374 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
1379 min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
1380 max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
1383 path2curve = R._path2curve = cacher(function (path, path2) {
1384 var p = pathToAbsolute(path),
1385 p2 = path2 && pathToAbsolute(path2),
1386 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
1387 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
1388 processPath = function (path, d) {
1391 return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
1393 !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
1400 path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
1403 nx = d.x + (d.x - (d.bx || d.x));
1404 ny = d.y + (d.y - (d.by || d.y));
1405 path = ["C", nx, ny][concat](path.slice(1));
1408 d.qx = d.x + (d.x - (d.qx || d.x));
1409 d.qy = d.y + (d.y - (d.qy || d.y));
1410 path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
1415 path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
1418 path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
1421 path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
1424 path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
1427 path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
1432 fixArc = function (pp, i) {
1433 if (pp[i].length > 7) {
1437 pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
1440 ii = mmax(p.length, p2 && p2.length || 0);
1443 fixM = function (path1, path2, a1, a2, i) {
1444 if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
1445 path2.splice(i, 0, ["M", a2.x, a2.y]);
1450 ii = mmax(p.length, p2 && p2.length || 0);
1453 for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
1454 p[i] = processPath(p[i], attrs);
1456 p2 && (p2[i] = processPath(p2[i], attrs2));
1457 p2 && fixArc(p2, i);
1458 fixM(p, p2, attrs, attrs2, i);
1459 fixM(p2, p, attrs2, attrs, i);
1462 seglen = seg.length,
1463 seg2len = p2 && seg2.length;
1464 attrs.x = seg[seglen - 2];
1465 attrs.y = seg[seglen - 1];
1466 attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
1467 attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
1468 attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
1469 attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
1470 attrs2.x = p2 && seg2[seg2len - 2];
1471 attrs2.y = p2 && seg2[seg2len - 1];
1473 return p2 ? [p, p2] : p;
1474 }, null, pathClone),
1475 parseDots = R._parseDots = cacher(function (gradient) {
1477 for (var i = 0, ii = gradient.length; i < ii; i++) {
1479 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
1480 dot.color = R.getRGB(par[1]);
1481 if (dot.color.error) {
1484 dot.color = dot.color.hex;
1485 par[2] && (dot.offset = par[2] + "%");
1488 for (i = 1, ii = dots.length - 1; i < ii; i++) {
1489 if (!dots[i].offset) {
1490 var start = toFloat(dots[i - 1].offset || 0),
1492 for (var j = i + 1; j < ii; j++) {
1493 if (dots[j].offset) {
1494 end = dots[j].offset;
1503 var d = (end - start) / (j - i + 1);
1504 for (; i < j; i++) {
1506 dots[i].offset = start + "%";
1512 tear = R._tear = function (el, paper) {
1513 el == paper.top && (paper.top = el.prev);
1514 el == paper.bottom && (paper.bottom = el.next);
1515 el.next && (el.next.prev = el.prev);
1516 el.prev && (el.prev.next = el.next);
1518 tofront = R._tofront = function (el, paper) {
1519 if (paper.top === el) {
1524 el.prev = paper.top;
1525 paper.top.next = el;
1528 toback = R._toback = function (el, paper) {
1529 if (paper.bottom === el) {
1533 el.next = paper.bottom;
1535 paper.bottom.prev = el;
1538 insertafter = R._insertafter = function (el, el2, paper) {
1540 el2 == paper.top && (paper.top = el);
1541 el2.next && (el2.next.prev = el);
1546 insertbefore = R._insertbefore = function (el, el2, paper) {
1548 el2 == paper.bottom && (paper.bottom = el);
1549 el2.prev && (el2.prev.next = el);
1554 extractTransform = R._extractTransform = function (el, tstr) {
1556 return el._.transform;
1558 tstr = Str(tstr).replace(/\.{3}|\u2026/g, el._.transform || E);
1559 var tdata = R.parseTransformString(tstr),
1567 _.transform = tdata || [];
1569 for (var i = 0, ii = tdata.length; i < ii; i++) {
1572 command = Str(t[0]).toLowerCase(),
1573 absolute = t[0] != command,
1574 inver = absolute ? m.invert() : 0,
1580 if (command == "t" && tlen == 3) {
1584 x2 = inver.x(t[1], t[2]);
1585 y2 = inver.y(t[1], t[2]);
1586 m.translate(x2 - x1, y2 - y1);
1588 m.translate(t[1], t[2]);
1590 } else if (command == "r") {
1592 bb = bb || el.getBBox(1);
1593 m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
1595 } else if (tlen == 4) {
1597 x2 = inver.x(t[2], t[3]);
1598 y2 = inver.y(t[2], t[3]);
1599 m.rotate(t[1], x2, y2);
1601 m.rotate(t[1], t[2], t[3]);
1605 } else if (command == "s") {
1606 if (tlen == 2 || tlen == 3) {
1607 bb = bb || el.getBBox(1);
1608 m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
1611 } else if (tlen == 5) {
1613 x2 = inver.x(t[3], t[4]);
1614 y2 = inver.y(t[3], t[4]);
1615 m.scale(t[1], t[2], x2, y2);
1617 m.scale(t[1], t[2], t[3], t[4]);
1622 } else if (command == "m" && tlen == 7) {
1623 m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
1638 if (sx == 1 && sy == 1 && !deg && _.bbox) {
1645 getEmpty = function (item) {
1647 switch (l.toLowerCase()) {
1648 case "t": return [l, 0, 0];
1649 case "m": return [l, 1, 0, 0, 1, 0, 0];
1650 case "r": if (item.length == 4) {
1651 return [l, 0, item[2], item[3]];
1655 case "s": if (item.length == 5) {
1656 return [l, 1, 1, item[3], item[4]];
1657 } else if (item.length == 3) {
1664 equaliseTransform = R._equaliseTransform = function (t1, t2) {
1665 t2 = Str(t2).replace(/\.{3}|\u2026/g, t1);
1666 t1 = R.parseTransformString(t1) || [];
1667 t2 = R.parseTransformString(t2) || [];
1668 var maxlength = mmax(t1.length, t2.length),
1673 for (; i < maxlength; i++) {
1674 tt1 = t1[i] || getEmpty(t2[i]);
1675 tt2 = t2[i] || getEmpty(tt1);
1676 if ((tt1[0] != tt2[0]) ||
1677 (tt1[0].toLowerCase() == "r" && (tt1[2] != tt2[2] || tt1[3] != tt2[3])) ||
1678 (tt1[0].toLowerCase() == "s" && (tt1[3] != tt2[3] || tt1[4] != tt2[4]))
1684 for (j = 0, jj = mmax(tt1.length, tt2.length); j < jj; j++) {
1685 j in tt1 && (from[i][j] = tt1[j]);
1686 j in tt2 && (to[i][j] = tt2[j]);
1694 R._getContainer = function (x, y, w, h) {
1696 container = h == null && !R.is(x, "object") ? g.doc.getElementById(x) : x;
1697 if (container == null) {
1700 if (container.tagName) {
1703 container: container,
1704 width: container.style.pixelWidth || container.offsetWidth,
1705 height: container.style.pixelHeight || container.offsetHeight
1709 container: container,
1724 R.pathToRelative = pathToRelative;
1727 R.path2curve = path2curve;
1729 R.matrix = function (a, b, c, d, e, f) {
1730 return new Matrix(a, b, c, d, e, f);
1732 function Matrix(a, b, c, d, e, f) {
1749 (function (matrixproto) {
1751 matrixproto.add = function (a, b, c, d, e, f) {
1752 var out = [[], [], []],
1753 m = [[this.a, this.c, this.e], [this.b, this.d, this.f], [0, 0, 1]],
1754 matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
1757 if (a && a instanceof Matrix) {
1758 matrix = [[a.a, a.c, a.e], [a.b, a.d, a.f], [0, 0, 1]];
1761 for (x = 0; x < 3; x++) {
1762 for (y = 0; y < 3; y++) {
1764 for (z = 0; z < 3; z++) {
1765 res += m[x][z] * matrix[z][y];
1778 matrixproto.invert = function () {
1780 x = me.a * me.d - me.b * me.c;
1781 return new Matrix(me.d / x, -me.b / x, -me.c / x, me.a / x, (me.c * me.f - me.d * me.e) / x, (me.b * me.e - me.a * me.f) / x);
1784 matrixproto.clone = function () {
1785 return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
1788 matrixproto.translate = function (x, y) {
1789 this.add(1, 0, 0, 1, x, y);
1792 matrixproto.scale = function (x, y, cx, cy) {
1793 y == null && (y = x);
1794 (cx || cy) && this.add(1, 0, 0, 1, cx, cy);
1795 this.add(x, 0, 0, y, 0, 0);
1796 (cx || cy) && this.add(1, 0, 0, 1, -cx, -cy);
1799 matrixproto.rotate = function (a, x, y) {
1803 var cos = +math.cos(a).toFixed(9),
1804 sin = +math.sin(a).toFixed(9);
1805 this.add(cos, sin, -sin, cos, x, y);
1806 this.add(1, 0, 0, 1, -x, -y);
1809 matrixproto.x = function (x, y) {
1810 return x * this.a + y * this.c + this.e;
1813 matrixproto.y = function (x, y) {
1814 return x * this.b + y * this.d + this.f;
1816 matrixproto.get = function (i) {
1817 return +this[Str.fromCharCode(97 + i)].toFixed(4);
1819 matrixproto.toString = function () {
1821 "matrix(" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)].join() + ")" :
1822 [this.get(0), this.get(2), this.get(1), this.get(3), 0, 0].join();
1824 matrixproto.toFilter = function () {
1825 return "progid:DXImageTransform.Microsoft.Matrix(M11=" + this.get(0) +
1826 ", M12=" + this.get(2) + ", M21=" + this.get(1) + ", M22=" + this.get(3) +
1827 ", Dx=" + this.get(4) + ", Dy=" + this.get(5) + ", sizingmethod='auto expand')";
1829 matrixproto.offset = function () {
1830 return [this.e.toFixed(4), this.f.toFixed(4)];
1833 return a[0] * a[0] + a[1] * a[1];
1835 function normalize(a) {
1836 var mag = math.sqrt(norm(a));
1837 a[0] && (a[0] /= mag);
1838 a[1] && (a[1] /= mag);
1841 matrixproto.split = function () {
1848 var row = [[this.a, this.c], [this.b, this.d]];
1849 out.scalex = math.sqrt(norm(row[0]));
1852 out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1];
1853 row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear];
1855 out.scaley = math.sqrt(norm(row[1]));
1857 out.shear /= out.scaley;
1860 var sin = -row[0][1],
1863 out.rotate = R.deg(math.acos(cos));
1865 out.rotate = 360 - out.rotate;
1868 out.rotate = R.deg(math.asin(sin));
1871 out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate);
1872 out.isSuperSimple = !+out.shear.toFixed(9) && out.scalex.toFixed(9) == out.scaley.toFixed(9) && !out.rotate;
1873 out.noRotation = !+out.shear.toFixed(9) && !out.rotate;
1877 matrixproto.toTransformString = function (shorter) {
1878 var s = shorter || this[split]();
1880 s.scalex = +s.scalex.toFixed(4);
1881 s.scaley = +s.scaley.toFixed(4);
1882 s.rotate = +s.rotate.toFixed(4);
1883 return (s.dx && s.dy ? "t" + [s.dx, s.dy] : E) +
1884 (s.scalex != 1 || s.scaley != 1 ? "s" + [s.scalex, s.scaley, 0, 0] : E) +
1885 (s.rotate ? "r" + [s.rotate, 0, 0] : E);
1887 return "m" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)];
1890 })(Matrix.prototype);
1892 // WebKit rendering bug workaround method
1893 var version = navigator.userAgent.match(/Version\/(.*?)\s/) || navigator.userAgent.match(/Chrome\/(\d+)/);
1894 if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP") ||
1895 (navigator.vendor == "Google Inc." && version && version[1] < 8)) {
1897 paperproto.safari = function () {
1898 var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
1899 setTimeout(function () {rect.remove();});
1902 paperproto.safari = fun;
1905 var preventDefault = function () {
1906 this.returnValue = false;
1908 preventTouch = function () {
1909 return this.originalEvent.preventDefault();
1911 stopPropagation = function () {
1912 this.cancelBubble = true;
1914 stopTouch = function () {
1915 return this.originalEvent.stopPropagation();
1917 addEvent = (function () {
1918 if (g.doc.addEventListener) {
1919 return function (obj, type, fn, element) {
1920 var realName = supportsTouch && touchMap[type] ? touchMap[type] : type,
1922 var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
1923 scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
1924 x = e.clientX + scrollX,
1925 y = e.clientY + scrollY;
1926 if (supportsTouch && touchMap[has](type)) {
1927 for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
1928 if (e.targetTouches[i].target == obj) {
1930 e = e.targetTouches[i];
1931 e.originalEvent = olde;
1932 e.preventDefault = preventTouch;
1933 e.stopPropagation = stopTouch;
1938 return fn.call(element, e, x, y);
1940 obj.addEventListener(realName, f, false);
1941 return function () {
1942 obj.removeEventListener(realName, f, false);
1946 } else if (g.doc.attachEvent) {
1947 return function (obj, type, fn, element) {
1948 var f = function (e) {
1949 e = e || g.win.event;
1950 var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
1951 scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
1952 x = e.clientX + scrollX,
1953 y = e.clientY + scrollY;
1954 e.preventDefault = e.preventDefault || preventDefault;
1955 e.stopPropagation = e.stopPropagation || stopPropagation;
1956 return fn.call(element, e, x, y);
1958 obj.attachEvent("on" + type, f);
1959 var detacher = function () {
1960 obj.detachEvent("on" + type, f);
1968 dragMove = function (e) {
1971 scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
1972 scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
1977 if (supportsTouch) {
1978 var i = e.touches.length,
1981 touch = e.touches[i];
1982 if (touch.identifier == dragi.el._drag.id) {
1985 (e.originalEvent ? e.originalEvent : e).preventDefault();
1992 var node = dragi.el.node,
1994 next = node.nextSibling,
1995 parent = node.parentNode,
1996 display = node.style.display;
1997 g.win.opera && parent.removeChild(node);
1998 node.style.display = "none";
1999 o = dragi.el.paper.getElementByPoint(x, y);
2000 node.style.display = display;
2001 g.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node));
2002 o && eve("drag.over." + dragi.el.id, dragi.el, o);
2005 eve("drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e);
2008 dragUp = function (e) {
2009 R.unmousemove(dragMove).unmouseup(dragUp);
2010 var i = drag.length,
2014 dragi.el._drag = {};
2015 eve("drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e);
2020 elproto = R.el = {};
2023 for (var i = events.length; i--;) {
2024 (function (eventName) {
2025 R[eventName] = elproto[eventName] = function (fn, scope) {
2026 if (R.is(fn, "function")) {
2027 this.events = this.events || [];
2028 this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || g.doc, eventName, fn, scope || this)});
2032 R["un" + eventName] = elproto["un" + eventName] = function (fn) {
2033 var events = this.events,
2035 while (l--) if (events[l].name == eventName && events[l].f == fn) {
2037 events.splice(l, 1);
2038 !events.length && delete this.events;
2047 elproto.data = function (key, value) {
2048 var data = eldata[this.id] = eldata[this.id] || {};
2049 if (arguments.length == 1) {
2050 if (R.is(key, "object")) {
2051 for (var i in key) if (key[has](i)) {
2052 this.data(i, key[i]);
2056 eve("data.get." + this.id, this, data[key], key);
2060 eve("data.set." + this.id, this, value, key);
2064 elproto.removeData = function (key) {
2066 eldata[this.id] = {};
2068 eldata[this.id] && delete eldata[this.id][key];
2073 elproto.hover = function (f_in, f_out, scope_in, scope_out) {
2074 return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in);
2077 elproto.unhover = function (f_in, f_out) {
2078 return this.unmouseover(f_in).unmouseout(f_out);
2082 elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) {
2084 (e.originalEvent || e).preventDefault();
2085 var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
2086 scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
2087 this._drag.x = e.clientX + scrollX;
2088 this._drag.y = e.clientY + scrollY;
2089 this._drag.id = e.identifier;
2090 !drag.length && R.mousemove(dragMove).mouseup(dragUp);
2091 drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
2092 onstart && eve.on("drag.start." + this.id, onstart);
2093 onmove && eve.on("drag.move." + this.id, onmove);
2094 onend && eve.on("drag.end." + this.id, onend);
2095 eve("drag.start." + this.id, start_scope || move_scope || this, e.clientX + scrollX, e.clientY + scrollY, e);
2098 draggable.push({el: this, start: start});
2099 this.mousedown(start);
2103 elproto.onDragOver = function (f) {
2104 f ? eve.on("drag.over." + this.id, f) : eve.unbind("drag.over." + this.id);
2107 elproto.undrag = function () {
2108 var i = draggable.length;
2109 while (i--) if (draggable[i].el == this) {
2110 this.unmousedown(draggable[i].start);
2111 draggable.splice(i, 1);
2112 eve.unbind("drag.*." + this.id);
2114 !draggable.length && R.unmousemove(dragMove).unmouseup(dragUp);
2117 paperproto.circle = function (x, y, r) {
2118 var out = R._engine.circle(this, x || 0, y || 0, r || 0);
2119 this.__set__ && this.__set__.push(out);
2123 paperproto.rect = function (x, y, w, h, r) {
2124 var out = R._engine.rect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
2125 this.__set__ && this.__set__.push(out);
2129 paperproto.ellipse = function (x, y, rx, ry) {
2130 var out = R._engine.ellipse(this, x || 0, y || 0, rx || 0, ry || 0);
2131 this.__set__ && this.__set__.push(out);
2135 paperproto.path = function (pathString) {
2136 pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
2137 var out = R._engine.path(R.format[apply](R, arguments), this);
2138 this.__set__ && this.__set__.push(out);
2142 paperproto.image = function (src, x, y, w, h) {
2143 var out = R._engine.image(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
2144 this.__set__ && this.__set__.push(out);
2148 paperproto.text = function (x, y, text) {
2149 var out = R._engine.text(this, x || 0, y || 0, Str(text));
2150 this.__set__ && this.__set__.push(out);
2154 paperproto.set = function (itemsArray) {
2155 !R.is(itemsArray, "array") && (itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length));
2156 var out = new Set(itemsArray);
2157 this.__set__ && this.__set__.push(out);
2161 paperproto.setStart = function (set) {
2162 this.__set__ = set || this.set();
2165 paperproto.setFinish = function (set) {
2166 var out = this.__set__;
2167 delete this.__set__;
2171 paperproto.setSize = function (width, height) {
2172 return R._engine.setSize.call(this, width, height);
2175 paperproto.setViewBox = function (x, y, w, h, fit) {
2176 return R._engine.setViewBox.call(this, x, y, w, h, fit);
2180 paperproto.top = paperproto.bottom = null;
2182 paperproto.raphael = R;
2183 var getOffset = function (elem) {
2184 var box = elem.getBoundingClientRect(),
2185 doc = elem.ownerDocument,
2187 docElem = doc.documentElement,
2188 clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
2189 top = box.top + (g.win.pageYOffset || docElem.scrollTop || body.scrollTop ) - clientTop,
2190 left = box.left + (g.win.pageXOffset || docElem.scrollLeft || body.scrollLeft) - clientLeft;
2197 paperproto.getElementByPoint = function (x, y) {
2200 target = g.doc.elementFromPoint(x, y);
2201 if (g.win.opera && target.tagName == "svg") {
2202 var so = getOffset(svg),
2203 sr = svg.createSVGRect();
2206 sr.width = sr.height = 1;
2207 var hits = svg.getIntersectionList(sr, null);
2209 target = hits[hits.length - 1];
2215 while (target.parentNode && target != svg.parentNode && !target.raphael) {
2216 target = target.parentNode;
2218 target == paper.canvas.parentNode && (target = svg);
2219 target = target && target.raphael ? paper.getById(target.raphaelid) : null;
2223 paperproto.getById = function (id) {
2224 var bot = this.bottom;
2234 paperproto.forEach = function (callback, thisArg) {
2235 var bot = this.bottom;
2237 if (callback.call(thisArg, bot) === false) {
2245 return this.x + S + this.y;
2247 function x_y_w_h() {
2248 return this.x + S + this.y + S + this.width + " \xd7 " + this.height;
2251 elproto.getBBox = function (isWithoutTransform) {
2256 if (isWithoutTransform) {
2257 if (_.dirty || !_.bboxwt) {
2258 this.realPath = getPath[this.type](this);
2259 _.bboxwt = pathDimensions(this.realPath);
2260 _.bboxwt.toString = x_y_w_h;
2265 if (_.dirty || _.dirtyT || !_.bbox) {
2266 if (_.dirty || !this.realPath) {
2268 this.realPath = getPath[this.type](this);
2270 _.bbox = pathDimensions(mapPath(this.realPath, this.matrix));
2271 _.bbox.toString = x_y_w_h;
2272 _.dirty = _.dirtyT = 0;
2277 elproto.clone = function () {
2281 var out = this.paper[this.type]().attr(this.attr());
2282 this.__set__ && this.__set__.push(out);
2286 elproto.glow = function (glow) {
2287 if (this.type == "text") {
2292 width: (glow.width || 10) + (+this.attr("stroke-width") || 1),
2293 fill: glow.fill || false,
2294 opacity: glow.opacity || .5,
2295 offsetx: glow.offsetx || 0,
2296 offsety: glow.offsety || 0,
2297 color: glow.color || "#000"
2302 path = this.realPath || getPath[this.type](this);
2303 path = this.matrix ? mapPath(path, this.matrix) : path;
2304 for (var i = 1; i < c + 1; i++) {
2305 out.push(r.path(path).attr({
2307 fill: s.fill ? s.color : "none",
2308 "stroke-linejoin": "round",
2309 "stroke-linecap": "round",
2310 "stroke-width": +(s.width / c * i).toFixed(3),
2311 opacity: +(s.opacity / c).toFixed(3)
2314 return out.insertBefore(this).translate(s.offsetx, s.offsety);
2316 var curveslengths = {},
2317 getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
2320 name = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y].join(),
2321 cache = curveslengths[name],
2323 !cache && (curveslengths[name] = cache = {data: []});
2324 cache.timer && clearTimeout(cache.timer);
2325 cache.timer = setTimeout(function () {delete curveslengths[name];}, 2e3);
2326 if (length != null && !cache.precision) {
2327 var total = getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
2328 cache.precision = ~~total * 10;
2331 precision = cache.precision || precision;
2332 for (var i = 0; i < precision + 1; i++) {
2333 if (cache.data[i * precision]) {
2334 dot = cache.data[i * precision];
2336 dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i / precision);
2337 cache.data[i * precision] = dot;
2339 i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
2340 if (length != null && len >= length) {
2345 if (length == null) {
2349 getLengthFactory = function (istotal, subpath) {
2350 return function (path, length, onlystart) {
2351 path = path2curve(path);
2352 var x, y, p, l, sp = "", subpaths = {}, point,
2354 for (var i = 0, ii = path.length; i < ii; i++) {
2360 l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
2361 if (len + l > length) {
2362 if (subpath && !subpaths.start) {
2363 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
2364 sp += ["C" + point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
2365 if (onlystart) {return sp;}
2366 subpaths.start = sp;
2367 sp = ["M" + point.x, point.y + "C" + point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]].join();
2373 if (!istotal && !subpath) {
2374 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
2375 return {x: point.x, y: point.y, alpha: point.alpha};
2382 sp += p.shift() + p;
2385 point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1);
2386 point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
2390 var getTotalLength = getLengthFactory(1),
2391 getPointAtLength = getLengthFactory(),
2392 getSubpathsAtLength = getLengthFactory(0, 1);
2394 R.getTotalLength = getTotalLength;
2396 R.getPointAtLength = getPointAtLength;
2398 R.getSubpath = function (path, from, to) {
2399 if (this.getTotalLength(path) - to < 1e-6) {
2400 return getSubpathsAtLength(path, from).end;
2402 var a = getSubpathsAtLength(path, to, 1);
2403 return from ? getSubpathsAtLength(a, from).end : a;
2406 elproto.getTotalLength = function () {
2407 if (this.type != "path") {return;}
2408 if (this.node.getTotalLength) {
2409 return this.node.getTotalLength();
2411 return getTotalLength(this.attrs.path);
2414 elproto.getPointAtLength = function (length) {
2415 if (this.type != "path") {return;}
2416 return getPointAtLength(this.attrs.path, length);
2419 elproto.getSubpath = function (from, to) {
2420 if (this.type != "path") {return;}
2421 return R.getSubpath(this.attrs.path, from, to);
2424 var ef = R.easing_formulas = {
2425 linear: function (n) {
2434 "<>": function (n) {
2435 var q = .48 - n / 1.04,
2436 Q = math.sqrt(.1734 + q * q),
2438 X = pow(abs(x), 1 / 3) * (x < 0 ? -1 : 1),
2440 Y = pow(abs(y), 1 / 3) * (y < 0 ? -1 : 1),
2442 return (1 - t) * 3 * t * t + t * t * t;
2444 backIn: function (n) {
2446 return n * n * ((s + 1) * n - s);
2448 backOut: function (n) {
2451 return n * n * ((s + 1) * n + s) + 1;
2453 elastic: function (n) {
2457 return pow(2, -10 * n) * math.sin((n - .075) * (2 * PI) / .3) + 1;
2459 bounce: function (n) {
2468 l = s * n * n + .75;
2470 if (n < (2.5 / p)) {
2472 l = s * n * n + .9375;
2475 l = s * n * n + .984375;
2482 ef.easeIn = ef["ease-in"] = ef["<"];
2483 ef.easeOut = ef["ease-out"] = ef[">"];
2484 ef.easeInOut = ef["ease-in-out"] = ef["<>"];
2485 ef["back-in"] = ef.backIn;
2486 ef["back-out"] = ef.backOut;
2488 var animationElements = [],
2489 requestAnimFrame = window.requestAnimationFrame ||
2490 window.webkitRequestAnimationFrame ||
2491 window.mozRequestAnimationFrame ||
2492 window.oRequestAnimationFrame ||
2493 window.msRequestAnimationFrame ||
2494 function (callback) {
2495 setTimeout(callback, 16);
2497 animation = function () {
2498 var Now = +new Date,
2500 for (; l < animationElements.length; l++) {
2501 var e = animationElements[l];
2502 if (e.el.removed || e.paused) {
2505 var time = Now - e.start,
2518 time = (e.initstatus * e.anim.top - e.prev) / (e.percent - e.prev) * ms;
2519 e.status = e.initstatus;
2520 delete e.initstatus;
2521 e.stop && animationElements.splice(l--, 1);
2523 e.status = (e.prev + (e.percent - e.prev) * (time / ms)) / e.anim.top;
2529 var pos = easing(time / ms);
2530 for (var attr in from) if (from[has](attr)) {
2531 switch (availableAnimAttrs[attr]) {
2533 now = +from[attr] + pos * ms * diff[attr];
2537 upto255(round(from[attr].r + pos * ms * diff[attr].r)),
2538 upto255(round(from[attr].g + pos * ms * diff[attr].g)),
2539 upto255(round(from[attr].b + pos * ms * diff[attr].b))
2544 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2545 now[i] = [from[attr][i][0]];
2546 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2547 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
2549 now[i] = now[i].join(S);
2554 if (diff[attr].real) {
2556 for (i = 0, ii = from[attr].length; i < ii; i++) {
2557 now[i] = [from[attr][i][0]];
2558 for (j = 1, jj = from[attr][i].length; j < jj; j++) {
2559 now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
2563 var get = function (i) {
2564 return +from[attr][i] + pos * ms * diff[attr][i];
2566 // now = [["r", get(2), 0, 0], ["t", get(3), get(4)], ["s", get(0), get(1), 0, 0]];
2567 now = [["m", get(0), get(1), get(2), get(3), get(4), get(5)]];
2571 if (attr == "clip-rect") {
2575 now[i] = +from[attr][i] + pos * ms * diff[attr][i];
2580 var from2 = [][concat](from[attr]);
2582 i = that.paper.customAttributes[attr].length;
2584 now[i] = +from2[i] + pos * ms * diff[attr][i];
2591 (function (id, that, anim) {
2592 setTimeout(function () {
2593 eve("anim.frame." + id, that, anim);
2595 })(that.id, that, e.anim);
2597 (function(f, el, a) {
2598 setTimeout(function() {
2599 eve("anim.frame." + el.id, el, a);
2600 eve("anim.finish." + el.id, el, a);
2601 R.is(f, "function") && f.call(el);
2603 })(e.callback, that, e.anim);
2605 animationElements.splice(l--, 1);
2606 if (e.repeat > 1 && !e.next) {
2607 for (key in to) if (to[has](key)) {
2608 init[key] = e.totalOrigin[key];
2611 runAnimation(e.anim, e.el, e.anim.percents[0], null, e.totalOrigin, e.repeat - 1);
2613 if (e.next && !e.stop) {
2614 runAnimation(e.anim, e.el, e.next, null, e.totalOrigin, e.repeat);
2618 R.svg && that && that.paper && that.paper.safari();
2619 animationElements.length && requestAnimFrame(animation);
2621 upto255 = function (color) {
2622 return color > 255 ? 255 : color < 0 ? 0 : color;
2625 elproto.animateWith = function (element, anim, params, ms, easing, callback) {
2626 var a = params ? R.animation(params, ms, easing, callback) : anim,
2627 status = element.status(anim);
2628 return this.animate(a).status(a, status * anim.ms / a.ms);
2630 function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
2632 bx = 3 * (p2x - p1x) - cx,
2635 by = 3 * (p2y - p1y) - cy,
2637 function sampleCurveX(t) {
2638 return ((ax * t + bx) * t + cx) * t;
2640 function solve(x, epsilon) {
2641 var t = solveCurveX(x, epsilon);
2642 return ((ay * t + by) * t + cy) * t;
2644 function solveCurveX(x, epsilon) {
2645 var t0, t1, t2, x2, d2, i;
2646 for(t2 = x, i = 0; i < 8; i++) {
2647 x2 = sampleCurveX(t2) - x;
2648 if (abs(x2) < epsilon) {
2651 d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
2652 if (abs(d2) < 1e-6) {
2667 x2 = sampleCurveX(t2);
2668 if (abs(x2 - x) < epsilon) {
2676 t2 = (t1 - t0) / 2 + t0;
2680 return solve(t, 1 / (200 * duration));
2682 elproto.onAnimation = function (f) {
2683 f ? eve.on("anim.frame." + this.id, f) : eve.unbind("anim.frame." + this.id);
2686 function Animation(anim, ms) {
2692 for (var attr in anim) if (anim[has](attr)) {
2693 newAnim[toFloat(attr)] = anim[attr];
2694 percents.push(toFloat(attr));
2696 percents.sort(sortByNumber);
2698 this.anim = newAnim;
2699 this.top = percents[percents.length - 1];
2700 this.percents = percents;
2703 Animation.prototype.delay = function (delay) {
2704 var a = new Animation(this.anim, this.ms);
2705 a.times = this.times;
2706 a.del = +delay || 0;
2710 Animation.prototype.repeat = function (times) {
2711 var a = new Animation(this.anim, this.ms);
2713 a.times = math.floor(mmax(times, 0)) || 1;
2716 function runAnimation(anim, element, percent, status, totalOrigin, times) {
2717 percent = toFloat(percent);
2730 for (i = 0, ii = animationElements.length; i < ii; i++) {
2731 var e = animationElements[i];
2732 if (e.el.id == element.id && e.anim == anim) {
2733 if (e.percent != percent) {
2734 animationElements.splice(i, 1);
2739 element.attr(e.totalOrigin);
2744 status = +to; // NaN
2746 for (var i = 0, ii = anim.percents.length; i < ii; i++) {
2747 if (anim.percents[i] == percent || anim.percents[i] > status * anim.top) {
2748 percent = anim.percents[i];
2749 prev = anim.percents[i - 1] || 0;
2750 ms = ms / anim.top * (percent - prev);
2751 next = anim.percents[i + 1];
2752 params = anim.anim[percent];
2754 } else if (status) {
2755 element.attr(anim.anim[anim.percents[i]]);
2762 for (var attr in params) if (params[has](attr)) {
2763 if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
2764 from[attr] = element.attr(attr);
2765 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
2766 to[attr] = params[attr];
2767 switch (availableAnimAttrs[attr]) {
2769 diff[attr] = (to[attr] - from[attr]) / ms;
2772 from[attr] = R.getRGB(from[attr]);
2773 var toColour = R.getRGB(to[attr]);
2775 r: (toColour.r - from[attr].r) / ms,
2776 g: (toColour.g - from[attr].g) / ms,
2777 b: (toColour.b - from[attr].b) / ms
2781 var pathes = path2curve(from[attr], to[attr]),
2783 from[attr] = pathes[0];
2785 for (i = 0, ii = from[attr].length; i < ii; i++) {
2786 diff[attr][i] = [0];
2787 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2788 diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
2794 eq = equaliseTransform(_[attr], to[attr]);
2796 from[attr] = eq.from;
2799 diff[attr].real = true;
2800 for (i = 0, ii = from[attr].length; i < ii; i++) {
2801 diff[attr][i] = [from[attr][i][0]];
2802 for (j = 1, jj = from[attr][i].length; j < jj; j++) {
2803 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2807 var m = (element.matrix || new Matrix),
2809 _: {transform: _.transform},
2810 getBBox: function () {
2811 return element.getBBox(1);
2822 extractTransform(to2, to[attr]);
2823 to[attr] = to2._.transform;
2825 (to2.matrix.a - m.a) / ms,
2826 (to2.matrix.b - m.b) / ms,
2827 (to2.matrix.c - m.c) / ms,
2828 (to2.matrix.d - m.d) / ms,
2829 (to2.matrix.e - m.e) / ms,
2830 (to2.matrix.e - m.f) / ms
2832 // from[attr] = [_.sx, _.sy, _.deg, _.dx, _.dy];
2833 // var to2 = {_:{}, getBBox: function () { return element.getBBox(); }};
2834 // extractTransform(to2, to[attr]);
2836 // (to2._.sx - _.sx) / ms,
2837 // (to2._.sy - _.sy) / ms,
2838 // (to2._.deg - _.deg) / ms,
2839 // (to2._.dx - _.dx) / ms,
2840 // (to2._.dy - _.dy) / ms
2845 var values = Str(params[attr])[split](separator),
2846 from2 = Str(from[attr])[split](separator);
2847 if (attr == "clip-rect") {
2852 diff[attr][i] = (values[i] - from[attr][i]) / ms;
2858 values = [][concat](params[attr]);
2859 from2 = [][concat](from[attr]);
2861 i = element.paper.customAttributes[attr].length;
2863 diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
2869 var easing = params.easing,
2870 easyeasy = R.easing_formulas[easing];
2872 easyeasy = Str(easing).match(bezierrg);
2873 if (easyeasy && easyeasy.length == 5) {
2874 var curve = easyeasy;
2875 easyeasy = function (t) {
2876 return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
2882 timestamp = params.start || anim.start || +new Date;
2886 timestamp: timestamp,
2887 start: timestamp + (anim.del || 0),
2889 initstatus: status || 0,
2897 callback: params.callback,
2900 repeat: times || anim.times,
2901 origin: element.attr(),
2902 totalOrigin: totalOrigin
2904 animationElements.push(e);
2905 if (status && !isInAnim && !isInAnimSet) {
2907 e.start = new Date - ms * status;
2908 if (animationElements.length == 1) {
2913 e.start = new Date - e.ms * status;
2915 animationElements.length == 1 && requestAnimFrame(animation);
2917 isInAnim.initstatus = status;
2918 isInAnim.start = new Date - isInAnim.ms * status;
2920 eve("anim.start." + element.id, element, anim);
2923 R.animation = function (params, ms, easing, callback) {
2924 if (params instanceof Animation) {
2927 if (R.is(easing, "function") || !easing) {
2928 callback = callback || easing || null;
2931 params = Object(params);
2936 for (attr in params) if (params[has](attr) && toFloat(attr) != attr && toFloat(attr) + "%" != attr) {
2938 p[attr] = params[attr];
2941 return new Animation(params, ms);
2943 easing && (p.easing = easing);
2944 callback && (p.callback = callback);
2945 return new Animation({100: p}, ms);
2949 elproto.animate = function (params, ms, easing, callback) {
2951 if (element.removed) {
2952 callback && callback.call(element);
2955 var anim = params instanceof Animation ? params : R.animation(params, ms, easing, callback);
2956 runAnimation(anim, element, anim.percents[0], null, element.attr());
2960 elproto.setTime = function (anim, value) {
2961 if (anim && value != null) {
2962 this.status(anim, mmin(value, anim.ms) / anim.ms);
2967 elproto.status = function (anim, value) {
2972 if (value != null) {
2973 runAnimation(anim, this, -1, mmin(value, 1));
2976 len = animationElements.length;
2977 for (; i < len; i++) {
2978 e = animationElements[i];
2979 if (e.el.id == this.id && (!anim || e.anim == anim)) {
2996 elproto.pause = function (anim) {
2997 for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
2998 if (eve("anim.pause." + this.id, this, animationElements[i].anim) !== false) {
2999 animationElements[i].paused = true;
3005 elproto.resume = function (anim) {
3006 for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
3007 var e = animationElements[i];
3008 if (eve("anim.resume." + this.id, this, e.anim) !== false) {
3010 this.status(e.anim, e.status);
3016 elproto.stop = function (anim) {
3017 for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
3018 if (eve("anim.stop." + this.id, this, animationElements[i].anim) !== false) {
3019 animationElements.splice(i--, 1);
3024 elproto.toString = function () {
3025 return "Rapha\xebl\u2019s object";
3029 var Set = function (items) {
3034 for (var i = 0, ii = items.length; i < ii; i++) {
3035 if (items[i] && (items[i].constructor == elproto.constructor || items[i].constructor == Set)) {
3036 this[this.items.length] = this.items[this.items.length] = items[i];
3042 setproto = Set.prototype;
3044 setproto.push = function () {
3047 for (var i = 0, ii = arguments.length; i < ii; i++) {
3048 item = arguments[i];
3049 if (item && (item.constructor == elproto.constructor || item.constructor == Set)) {
3050 len = this.items.length;
3051 this[len] = this.items[len] = item;
3058 setproto.pop = function () {
3059 this.length && delete this[this.length--];
3060 return this.items.pop();
3063 setproto.forEach = function (callback, thisArg) {
3064 for (var i = 0, ii = this.items.length; i < ii; i++) {
3065 if (callback.call(thisArg, this.items[i], i) === false) {
3071 for (var method in elproto) if (elproto[has](method)) {
3072 setproto[method] = (function (methodname) {
3073 return function () {
3074 var arg = arguments;
3075 return this.forEach(function (el) {
3076 el[methodname][apply](el, arg);
3081 setproto.attr = function (name, value) {
3082 if (name && R.is(name, array) && R.is(name[0], "object")) {
3083 for (var j = 0, jj = name.length; j < jj; j++) {
3084 this.items[j].attr(name[j]);
3087 for (var i = 0, ii = this.items.length; i < ii; i++) {
3088 this.items[i].attr(name, value);
3094 setproto.clear = function () {
3095 while (this.length) {
3100 setproto.splice = function (index, count, insertion) {
3101 index = index < 0 ? mmax(this.length + index, 0) : index;
3102 count = mmax(0, mmin(this.length - index, count));
3107 for (i = 2; i < arguments.length; i++) {
3108 args.push(arguments[i]);
3110 for (i = 0; i < count; i++) {
3111 todel.push(this[index + i]);
3113 for (; i < this.length - index; i++) {
3114 tail.push(this[index + i]);
3116 var arglen = args.length;
3117 for (i = 0; i < arglen + tail.length; i++) {
3118 this.items[index + i] = this[index + i] = i < arglen ? args[i] : tail[i - arglen];
3120 i = this.items.length = this.length -= count - arglen;
3124 return new Set(todel);
3127 setproto.exclude = function (el) {
3128 for (var i = 0, ii = this.length; i < ii; i++) if (this[i] == el) {
3133 setproto.animate = function (params, ms, easing, callback) {
3134 (R.is(easing, "function") || !easing) && (callback = easing || null);
3135 var len = this.items.length,
3143 callback && (collector = function () {
3144 !--len && callback.call(set);
3146 easing = R.is(easing, string) ? easing : collector;
3147 var anim = R.animation(params, ms, easing, collector);
3148 item = this.items[--i].animate(anim);
3150 this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, anim);
3154 setproto.insertAfter = function (el) {
3155 var i = this.items.length;
3157 this.items[i].insertAfter(el);
3161 setproto.getBBox = function () {
3166 for (var i = this.items.length; i--;) if (!this.items[i].removed) {
3167 var box = this.items[i].getBBox();
3170 w.push(box.x + box.width);
3171 h.push(box.y + box.height);
3173 x = mmin[apply](0, x);
3174 y = mmin[apply](0, y);
3178 width: mmax[apply](0, w) - x,
3179 height: mmax[apply](0, h) - y
3182 setproto.clone = function (s) {
3184 for (var i = 0, ii = this.items.length; i < ii; i++) {
3185 s.push(this.items[i].clone());
3189 setproto.toString = function () {
3190 return "Rapha\xebl\u2018s set";
3194 R.registerFont = function (font) {
3198 this.fonts = this.fonts || {};
3204 family = font.face["font-family"];
3205 for (var prop in font.face) if (font.face[has](prop)) {
3206 fontcopy.face[prop] = font.face[prop];
3208 if (this.fonts[family]) {
3209 this.fonts[family].push(fontcopy);
3211 this.fonts[family] = [fontcopy];
3214 fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
3215 for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
3216 var path = font.glyphs[glyph];
3217 fontcopy.glyphs[glyph] = {
3220 d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
3221 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
3225 for (var k in path.k) if (path[has](k)) {
3226 fontcopy.glyphs[glyph].k[k] = path.k[k];
3234 paperproto.getFont = function (family, weight, style, stretch) {
3235 stretch = stretch || "normal";
3236 style = style || "normal";
3237 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
3241 var font = R.fonts[family];
3243 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
3244 for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
3245 if (name.test(fontName)) {
3246 font = R.fonts[fontName];
3253 for (var i = 0, ii = font.length; i < ii; i++) {
3255 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
3263 paperproto.print = function (x, y, string, font, size, origin, letter_spacing) {
3264 origin = origin || "middle"; // baseline|middle
3265 letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
3266 var out = this.set(),
3267 letters = Str(string)[split](E),
3271 R.is(font, string) && (font = this.getFont(font));
3273 scale = (size || 16) / font.face["units-per-em"];
3274 var bb = font.face.bbox[split](separator),
3276 height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
3277 for (var i = 0, ii = letters.length; i < ii; i++) {
3278 var prev = i && font.glyphs[letters[i - 1]] || {},
3279 curr = font.glyphs[letters[i]];
3280 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
3281 curr && curr.d && out.push(this.path(curr.d).attr({
3284 transform: [["t", shift * scale, 0]]
3287 out.transform(["...s", scale, scale, top, height, "t", (x - top) / scale, (y - height) / scale]);
3293 paperproto.add = function (json) {
3294 if (R.is(json, "array")) {
3295 var res = this.set(),
3299 for (; i < ii; i++) {
3301 elements[has](j.type) && res.push(this[j.type]().attr(j));
3308 R.format = function (token, params) {
3309 var args = R.is(params, array) ? [0][concat](params) : arguments;
3310 token && R.is(token, string) && args.length - 1 && (token = token.replace(formatrg, function (str, i) {
3311 return args[++i] == null ? E : args[i];
3316 R.fullfill = (function () {
3317 var tokenRegex = /\{([^\}]+)\}/g,
3318 objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g, // matches .xxxxx or ["xxxxx"] to run over object properties
3319 replacer = function (all, key, obj) {
3321 key.replace(objNotationRegex, function (all, name, quote, quotedName, isFunc) {
3322 name = name || quotedName;
3327 typeof res == "function" && isFunc && (res = res());
3330 res = (res == null || res == obj ? all : res) + "";
3333 return function (str, obj) {
3334 return String(str).replace(tokenRegex, function (all, key) {
3335 return replacer(all, key, obj);
3340 R.ninja = function () {
3341 oldRaphael.was ? (g.win.Raphael = oldRaphael.is) : delete Raphael;
3346 // Firefox <3.6 fix: http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
3347 (function (doc, loaded, f) {
3348 if (doc.readyState == null && doc.addEventListener){
3349 doc.addEventListener(loaded, f = function () {
3350 doc.removeEventListener(loaded, f, false);
3351 doc.readyState = "complete";
3353 doc.readyState = "loading";
3355 function isLoaded() {
3356 (/in/).test(doc.readyState) ? setTimeout(isLoaded, 9) : R.eve("DOMload");
3359 })(document, "DOMContentLoaded");
3361 oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
3363 eve.on("DOMload", function () {
3369 // ┌─────────────────────────────────────────────────────────────────────┐ \\
3370 // │ Raphaël - JavaScript Vector Library │ \\
3371 // ├─────────────────────────────────────────────────────────────────────┤ \\
3372 // │ SVG Module │ \\
3373 // ├─────────────────────────────────────────────────────────────────────┤ \\
3374 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
3375 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
3376 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
3377 // └─────────────────────────────────────────────────────────────────────┘ \\
3378 window.Raphael.svg && function (R) {
3379 var has = "hasOwnProperty",
3381 toFloat = parseFloat,
3387 separator = /[, ]+/,
3391 var xlink = "http://www.w3.org/1999/xlink",
3393 block: "M5,0 0,2.5 5,5z",
3394 classic: "M5,0 0,2.5 5,5 3.5,3 3.5,2z",
3395 diamond: "M2.5,0 5,2.5 2.5,5 0,2.5z",
3396 open: "M6,1 1,3.5 6,6",
3397 oval: "M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"
3400 R.toString = function () {
3401 return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
3403 var $ = function (el, attr) {
3405 if (typeof el == "string") {
3408 for (var key in attr) if (attr[has](key)) {
3409 if (key.substring(0, 6) == "xlink:") {
3410 el.setAttributeNS(xlink, key.substring(6), Str(attr[key]));
3412 el.setAttribute(key, Str(attr[key]));
3416 el = R._g.doc.createElementNS("http://www.w3.org/2000/svg", el);
3417 el.style && (el.style.webkitTapHighlightColor = "rgba(0,0,0,0)");
3421 addGradientFill = function (element, gradient) {
3422 var type = "linear",
3423 id = element.id + gradient,
3426 SVG = element.paper,
3428 el = R._g.doc.getElementById(id);
3430 gradient = Str(gradient).replace(R._radial_gradient, function (all, _fx, _fy) {
3435 var dir = ((fy > .5) * 2 - 1);
3436 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
3437 (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
3439 (fy = fy.toFixed(5) - 1e-5 * dir);
3443 gradient = gradient.split(/\s*\-\s*/);
3444 if (type == "linear") {
3445 var angle = gradient.shift();
3446 angle = -toFloat(angle);
3450 var vector = [0, 0, math.cos(R.rad(angle)), math.sin(R.rad(angle))],
3451 max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
3454 if (vector[2] < 0) {
3455 vector[0] = -vector[2];
3458 if (vector[3] < 0) {
3459 vector[1] = -vector[3];
3463 var dots = R._parseDots(gradient);
3467 id = id.replace(/[\(\)\s,\xb0#]/g, "_");
3469 if (element.gradient && id != element.gradient.id) {
3470 SVG.defs.removeChild(element.gradient);
3471 delete element.gradient;
3474 if (!element.gradient) {
3475 el = $(type + "Gradient", {id: id});
3476 element.gradient = el;
3477 $(el, type == "radial" ? {
3485 gradientTransform: element.matrix.invert()
3487 SVG.defs.appendChild(el);
3488 for (var i = 0, ii = dots.length; i < ii; i++) {
3489 el.appendChild($("stop", {
3490 offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%",
3491 "stop-color": dots[i].color || "#fff"
3497 fill: "url(#" + id + ")",
3506 updatePosition = function (o) {
3507 var bbox = o.getBBox(1);
3508 $(o.pattern, {patternTransform: o.matrix.invert() + " translate(" + bbox.x + "," + bbox.y + ")"});
3510 addArrow = function (o, value, isEnd) {
3511 if (o.type == "path") {
3512 var values = Str(value).toLowerCase().split("-"),
3514 se = isEnd ? "end" : "start",
3517 stroke = attrs["stroke-width"],
3529 switch (values[i]) {
3538 case "wide": h = 5; break;
3539 case "narrow": h = 2; break;
3540 case "long": w = 5; break;
3541 case "short": w = 2; break;
3544 if (type == "open") {
3549 refX = isEnd ? 4 : 1;
3552 stroke: attrs.stroke
3563 o._.arrows.endPath && markerCounter[o._.arrows.endPath]--;
3564 o._.arrows.endMarker && markerCounter[o._.arrows.endMarker]--;
3566 o._.arrows.startPath && markerCounter[o._.arrows.startPath]--;
3567 o._.arrows.startMarker && markerCounter[o._.arrows.startMarker]--;
3572 if (type != "none") {
3573 var pathId = "raphael-marker-" + type,
3574 markerId = "raphael-marker-" + se + type + w + h;
3575 if (!R._g.doc.getElementById(pathId)) {
3576 p.defs.appendChild($($("path"), {
3577 "stroke-linecap": "round",
3581 markerCounter[pathId] = 1;
3583 markerCounter[pathId]++;
3585 var marker = R._g.doc.getElementById(markerId),
3588 marker = $($("marker"), {
3597 "xlink:href": "#" + pathId,
3598 transform: (isEnd ? " rotate(180 " + w / 2 + " " + h / 2 + ") " : S) + "scale(" + w / t + "," + h / t + ")",
3599 "stroke-width": 1 / ((w / t + h / t) / 2)
3601 marker.appendChild(use);
3602 p.defs.appendChild(marker);
3603 markerCounter[markerId] = 1;
3605 markerCounter[markerId]++;
3606 use = marker.getElementsByTagName("use")[0];
3609 var delta = dx * (type != "diamond" && type != "oval");
3611 from = o._.arrows.startdx * stroke || 0;
3612 to = R.getTotalLength(attrs.path) - delta * stroke;
3614 from = delta * stroke;
3615 to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
3618 attr["marker-" + se] = "url(#" + markerId + ")";
3620 attr.d = Raphael.getSubpath(attrs.path, from, to);
3623 o._.arrows[se + "Path"] = pathId;
3624 o._.arrows[se + "Marker"] = markerId;
3625 o._.arrows[se + "dx"] = delta;
3626 o._.arrows[se + "Type"] = type;
3627 o._.arrows[se + "String"] = value;
3630 from = o._.arrows.startdx * stroke || 0;
3631 to = R.getTotalLength(attrs.path) - from;
3634 to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
3636 o._.arrows[se + "Path"] && $(node, {d: Raphael.getSubpath(attrs.path, from, to)});
3637 delete o._.arrows[se + "Path"];
3638 delete o._.arrows[se + "Marker"];
3639 delete o._.arrows[se + "dx"];
3640 delete o._.arrows[se + "Type"];
3641 delete o._.arrows[se + "String"];
3643 for (attr in markerCounter) if (markerCounter[has](attr) && !markerCounter[attr]) {
3644 var item = R._g.doc.getElementById(attr);
3645 item && item.parentNode.removeChild(item);
3655 "-..": [3, 1, 1, 1, 1, 1],
3659 "- .": [4, 3, 1, 3],
3660 "--.": [8, 3, 1, 3],
3661 "--..": [8, 3, 1, 3, 1, 3]
3663 addDashes = function (o, value, params) {
3664 value = dasharray[Str(value).toLowerCase()];
3666 var width = o.attrs["stroke-width"] || "1",
3667 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
3671 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
3673 $(o.node, {"stroke-dasharray": dashes.join(",")});
3676 setFillAndStroke = function (o, params) {
3679 vis = node.style.visibility;
3680 node.style.visibility = "hidden";
3681 for (var att in params) {
3682 if (params[has](att)) {
3683 if (!R._availableAttrs[has](att)) {
3686 var value = params[att];
3695 var pn = node.parentNode;
3696 if (pn.tagName.toLowerCase() != "a") {
3698 pn.insertBefore(hl, node);
3699 hl.appendChild(node);
3702 if (att == "target" && value == "blank") {
3703 pn.setAttributeNS(xlink, "show", "new");
3705 pn.setAttributeNS(xlink, att, value);
3709 node.style.cursor = value;
3718 addArrow(o, value, 1);
3721 var rect = Str(value).split(separator);
3722 if (rect.length == 4) {
3723 o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
3724 var el = $("clipPath"),
3726 el.id = R.createUUID();
3734 o.paper.defs.appendChild(el);
3735 $(node, {"clip-path": "url(#" + el.id + ")"});
3739 var path = node.getAttribute("clip-path");
3741 var clip = R._g.doc.getElementById(path.replace(/(^url\(#|\)$)/g, E));
3742 clip && clip.parentNode.removeChild(clip);
3743 $(node, {"clip-path": E});
3749 if (o.type == "path") {
3750 $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"});
3753 "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
3754 "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
3759 node.setAttribute(att, value);
3769 value = -attrs.x - (attrs.width || 0);
3772 if (att == "rx" && o.type == "rect") {
3776 node.setAttribute(att, value);
3777 o.pattern && updatePosition(o);
3781 node.setAttribute(att, value);
3791 value = -attrs.y - (attrs.height || 0);
3794 if (att == "ry" && o.type == "rect") {
3798 node.setAttribute(att, value);
3799 o.pattern && updatePosition(o);
3803 if (o.type == "rect") {
3804 $(node, {rx: value, ry: value});
3806 node.setAttribute(att, value);
3811 if (o.type == "image") {
3812 node.setAttributeNS(xlink, "href", value);
3815 case "stroke-width":
3816 if (o._.sx != 1 || o._.sy != 1) {
3817 value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
3819 if (o.paper._vbSize) {
3820 value *= o.paper._vbSize;
3822 node.setAttribute(att, value);
3823 if (attrs["stroke-dasharray"]) {
3824 addDashes(o, attrs["stroke-dasharray"], params);
3827 "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
3828 "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
3831 case "stroke-dasharray":
3832 addDashes(o, value, params);
3835 var isURL = Str(value).match(R._ISURL);
3838 var ig = $("image");
3839 el.id = R.createUUID();
3840 $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
3841 $(ig, {x: 0, y: 0, "xlink:href": isURL[1]});
3845 R._preload(isURL[1], function () {
3846 var w = this.offsetWidth,
3847 h = this.offsetHeight;
3848 $(el, {width: w, height: h});
3849 $(ig, {width: w, height: h});
3853 o.paper.defs.appendChild(el);
3854 node.style.fill = "url(#" + el.id + ")";
3855 $(node, {fill: "url(#" + el.id + ")"});
3857 o.pattern && updatePosition(o);
3860 var clr = R.getRGB(value);
3862 delete params.gradient;
3863 delete attrs.gradient;
3864 !R.is(attrs.opacity, "undefined") &&
3865 R.is(params.opacity, "undefined") &&
3866 $(node, {opacity: attrs.opacity});
3867 !R.is(attrs["fill-opacity"], "undefined") &&
3868 R.is(params["fill-opacity"], "undefined") &&
3869 $(node, {"fill-opacity": attrs["fill-opacity"]});
3870 } else if ((o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value)) {
3871 if ("opacity" in attrs || "fill-opacity" in attrs) {
3872 var gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
3874 var stops = gradient.getElementsByTagName("stop");
3875 $(stops[stops.length - 1], {"stop-opacity": ("opacity" in attrs ? attrs.opacity : 1) * ("fill-opacity" in attrs ? attrs["fill-opacity"] : 1)});
3878 attrs.gradient = value;
3879 attrs.fill = "none";
3882 clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
3884 clr = R.getRGB(value);
3885 node.setAttribute(att, clr.hex);
3886 att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
3887 if (att == "stroke" && o._.arrows) {
3888 "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
3889 "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
3893 (o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value);
3896 if (attrs.gradient && !attrs[has]("stroke-opacity")) {
3897 $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
3900 case "fill-opacity":
3901 if (attrs.gradient) {
3902 gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
3904 stops = gradient.getElementsByTagName("stop");
3905 $(stops[stops.length - 1], {"stop-opacity": value});
3910 att == "font-size" && (value = toInt(value, 10) + "px");
3911 var cssrule = att.replace(/(\-.)/g, function (w) {
3912 return w.substring(1).toUpperCase();
3914 node.style[cssrule] = value;
3916 node.setAttribute(att, value);
3922 tuneText(o, params);
3923 node.style.visibility = vis;
3926 tuneText = function (el, params) {
3927 if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
3932 fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
3934 if (params[has]("text")) {
3935 a.text = params.text;
3936 while (node.firstChild) {
3937 node.removeChild(node.firstChild);
3939 var texts = Str(params.text).split("\n"),
3942 for (var i = 0, ii = texts.length; i < ii; i++) {
3944 i && $(tspan, {dy: fontSize * leading, x: a.x});
3945 tspan.appendChild(R._g.doc.createTextNode(texts[i]));
3946 node.appendChild(tspan);
3950 tspans = node.getElementsByTagName("tspan");
3951 for (i = 0, ii = tspans.length; i < ii; i++) if (i) {
3952 $(tspans[i], {dy: fontSize * leading, x: a.x});
3954 $(tspans[0], {dy: 0});
3957 $(node, {x: a.x, y: a.y});
3959 var bb = el._getBBox(),
3960 dif = a.y - (bb.y + bb.height / 2);
3961 dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
3963 Element = function (node, svg) {
3967 this[0] = this.node = node;
3969 node.raphael = true;
3972 node.raphaelid = this.id;
3973 this.matrix = R.matrix();
3974 this.realPath = null;
3977 this.attrs = this.attrs || {};
3987 !svg.bottom && (svg.bottom = this);
3989 this.prev = svg.top;
3990 svg.top && (svg.top.next = this);
3997 Element.prototype = elproto;
3998 elproto.constructor = Element;
4000 R._engine.path = function (pathString, SVG) {
4002 SVG.canvas && SVG.canvas.appendChild(el);
4003 var p = new Element(el, SVG);
4005 setFillAndStroke(p, {
4013 elproto.rotate = function (deg, cx, cy) {
4017 deg = Str(deg).split(separator);
4018 if (deg.length - 1) {
4019 cx = toFloat(deg[1]);
4020 cy = toFloat(deg[2]);
4022 deg = toFloat(deg[0]);
4023 (cy == null) && (cx = cy);
4024 if (cx == null || cy == null) {
4025 var bbox = this.getBBox(1);
4026 cx = bbox.x + bbox.width / 2;
4027 cy = bbox.y + bbox.height / 2;
4029 this.transform(this._.transform.concat([["r", deg, cx, cy]]));
4033 elproto.scale = function (sx, sy, cx, cy) {
4037 sx = Str(sx).split(separator);
4038 if (sx.length - 1) {
4039 sy = toFloat(sx[1]);
4040 cx = toFloat(sx[2]);
4041 cy = toFloat(sx[3]);
4043 sx = toFloat(sx[0]);
4044 (sy == null) && (sy = sx);
4045 (cy == null) && (cx = cy);
4046 if (cx == null || cy == null) {
4047 var bbox = this.getBBox(1);
4049 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
4050 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
4051 this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
4055 elproto.translate = function (dx, dy) {
4059 dx = Str(dx).split(separator);
4060 if (dx.length - 1) {
4061 dy = toFloat(dx[1]);
4063 dx = toFloat(dx[0]) || 0;
4065 this.transform(this._.transform.concat([["t", dx, dy]]));
4069 elproto.transform = function (tstr) {
4074 R._extractTransform(this, tstr);
4076 this.clip && $(this.clip, {transform: this.matrix.invert()});
4077 this.pattern && updatePosition(this);
4078 this.node && $(this.node, {transform: this.matrix});
4080 if (_.sx != 1 || _.sy != 1) {
4081 var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
4082 this.attr({"stroke-width": sw});
4088 elproto.hide = function () {
4089 !this.removed && this.paper.safari(this.node.style.display = "none");
4093 elproto.show = function () {
4094 !this.removed && this.paper.safari(this.node.style.display = "");
4098 elproto.remove = function () {
4102 var paper = this.paper;
4103 paper.__set__ && paper.__set__.exclude(this);
4104 eve.unbind("*.*." + this.id);
4105 if (this.gradient) {
4106 paper.defs.removeChild(this.gradient);
4108 R._tear(this, paper);
4109 this.node.parentNode.removeChild(this.node);
4110 for (var i in this) {
4111 this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
4113 this.removed = true;
4115 elproto._getBBox = function () {
4116 if (this.node.style.display == "none") {
4122 bbox = this.node.getBBox();
4124 // Firefox 3.0.x plays badly here
4128 hide && this.hide();
4132 elproto.attr = function (name, value) {
4138 for (var a in this.attrs) if (this.attrs[has](a)) {
4139 res[a] = this.attrs[a];
4141 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
4142 res.transform = this._.transform;
4145 if (value == null && R.is(name, "string")) {
4146 if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
4147 return this.attrs.gradient;
4149 if (name == "transform") {
4150 return this._.transform;
4152 var names = name.split(separator),
4154 for (var i = 0, ii = names.length; i < ii; i++) {
4156 if (name in this.attrs) {
4157 out[name] = this.attrs[name];
4158 } else if (R.is(this.paper.customAttributes[name], "function")) {
4159 out[name] = this.paper.customAttributes[name].def;
4161 out[name] = R._availableAttrs[name];
4164 return ii - 1 ? out : out[names[0]];
4166 if (value == null && R.is(name, "array")) {
4168 for (i = 0, ii = name.length; i < ii; i++) {
4169 out[name[i]] = this.attr(name[i]);
4173 if (value != null) {
4175 params[name] = value;
4176 } else if (name != null && R.is(name, "object")) {
4179 for (var key in params) {
4180 eve("attr." + key + "." + this.id, this, params[key]);
4182 for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
4183 var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
4184 this.attrs[key] = params[key];
4185 for (var subkey in par) if (par[has](subkey)) {
4186 params[subkey] = par[subkey];
4189 setFillAndStroke(this, params);
4193 elproto.toFront = function () {
4197 if (this.node.parentNode.tagName.toLowerCase() == "a") {
4198 this.node.parentNode.parentNode.appendChild(this.node.parentNode);
4200 this.node.parentNode.appendChild(this.node);
4202 var svg = this.paper;
4203 svg.top != this && R._tofront(this, svg);
4207 elproto.toBack = function () {
4211 var parent = this.node.parentNode;
4212 if (parent.tagName.toLowerCase() == "a") {
4213 parent.parentNode.insertBefore(this.node.parentNode, this.node.parentNode.parentNode.firstChild);
4214 } else if (parent.firstChild != this.node) {
4215 parent.insertBefore(this.node, this.node.parentNode.firstChild);
4217 R._toback(this, this.paper);
4218 var svg = this.paper;
4222 elproto.insertAfter = function (element) {
4226 var node = element.node || element[element.length - 1].node;
4227 if (node.nextSibling) {
4228 node.parentNode.insertBefore(this.node, node.nextSibling);
4230 node.parentNode.appendChild(this.node);
4232 R._insertafter(this, element, this.paper);
4236 elproto.insertBefore = function (element) {
4240 var node = element.node || element[0].node;
4241 node.parentNode.insertBefore(this.node, node);
4242 R._insertbefore(this, element, this.paper);
4245 elproto.blur = function (size) {
4246 // Experimental. No Safari support. Use it on your own risk.
4249 var fltr = $("filter"),
4250 blur = $("feGaussianBlur");
4251 t.attrs.blur = size;
4252 fltr.id = R.createUUID();
4253 $(blur, {stdDeviation: +size || 1.5});
4254 fltr.appendChild(blur);
4255 t.paper.defs.appendChild(fltr);
4257 $(t.node, {filter: "url(#" + fltr.id + ")"});
4260 t._blur.parentNode.removeChild(t._blur);
4262 delete t.attrs.blur;
4264 t.node.removeAttribute("filter");
4267 R._engine.circle = function (svg, x, y, r) {
4268 var el = $("circle");
4269 svg.canvas && svg.canvas.appendChild(el);
4270 var res = new Element(el, svg);
4271 res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
4272 res.type = "circle";
4276 R._engine.rect = function (svg, x, y, w, h, r) {
4278 svg.canvas && svg.canvas.appendChild(el);
4279 var res = new Element(el, svg);
4280 res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
4285 R._engine.ellipse = function (svg, x, y, rx, ry) {
4286 var el = $("ellipse");
4287 svg.canvas && svg.canvas.appendChild(el);
4288 var res = new Element(el, svg);
4289 res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
4290 res.type = "ellipse";
4294 R._engine.image = function (svg, src, x, y, w, h) {
4295 var el = $("image");
4296 $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
4297 el.setAttributeNS(xlink, "href", src);
4298 svg.canvas && svg.canvas.appendChild(el);
4299 var res = new Element(el, svg);
4300 res.attrs = {x: x, y: y, width: w, height: h, src: src};
4304 R._engine.text = function (svg, x, y, text) {
4306 // $(el, {x: x, y: y, "text-anchor": "middle"});
4307 svg.canvas && svg.canvas.appendChild(el);
4308 var res = new Element(el, svg);
4312 "text-anchor": "middle",
4314 font: R._availableAttrs.font,
4319 setFillAndStroke(res, res.attrs);
4322 R._engine.setSize = function (width, height) {
4323 this.width = width || this.width;
4324 this.height = height || this.height;
4325 this.canvas.setAttribute("width", this.width);
4326 this.canvas.setAttribute("height", this.height);
4327 if (this._viewBox) {
4328 this.setViewBox.apply(this, this._viewBox);
4332 R._engine.create = function () {
4333 var con = R._getContainer.apply(0, arguments),
4334 container = con && con.container,
4338 height = con.height;
4340 throw new Error("SVG container not found.");
4342 var cnvs = $("svg"),
4343 css = "overflow:hidden;",
4347 width = width || 512;
4348 height = height || 342;
4353 xmlns: "http://www.w3.org/2000/svg"
4355 if (container == 1) {
4356 cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
4357 R._g.doc.body.appendChild(cnvs);
4360 cnvs.style.cssText = css + "position:relative";
4361 if (container.firstChild) {
4362 container.insertBefore(cnvs, container.firstChild);
4364 container.appendChild(cnvs);
4367 container = new R._Paper;
4368 container.width = width;
4369 container.height = height;
4370 container.canvas = cnvs;
4371 // plugins.call(container, container, R.fn);
4373 container._left = container._top = 0;
4374 isFloating && (container.renderfix = function () {});
4375 container.renderfix();
4378 R._engine.setViewBox = function (x, y, w, h, fit) {
4379 eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
4380 var size = mmax(w / this.width, h / this.height),
4382 aspectRatio = fit ? "meet" : "xMinYMin",
4389 delete this._vbSize;
4390 vb = "0 0 " + this.width + S + this.height;
4392 this._vbSize = size;
4393 vb = x + S + y + S + w + S + h;
4397 preserveAspectRatio: aspectRatio
4399 while (size && top) {
4400 sw = "stroke-width" in top.attrs ? top.attrs["stroke-width"] : 1;
4401 top.attr({"stroke-width": sw});
4406 this._viewBox = [x, y, w, h, !!fit];
4410 R.prototype.renderfix = function () {
4411 var cnvs = this.canvas,
4413 pos = cnvs.getScreenCTM() || cnvs.createSVGMatrix(),
4418 this._left = (this._left + left) % 1;
4419 s.left = this._left + "px";
4422 this._top = (this._top + top) % 1;
4423 s.top = this._top + "px";
4428 R.prototype.clear = function () {
4429 R.eve("clear", this);
4430 var c = this.canvas;
4431 while (c.firstChild) {
4432 c.removeChild(c.firstChild);
4434 this.bottom = this.top = null;
4435 (this.desc = $("desc")).appendChild(R._g.doc.createTextNode("Created with Rapha\xebl " + R.version));
4436 c.appendChild(this.desc);
4437 c.appendChild(this.defs = $("defs"));
4440 R.prototype.remove = function () {
4441 eve("remove", this);
4442 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
4443 for (var i in this) {
4444 this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
4447 var setproto = R.st;
4448 for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
4449 setproto[method] = (function (methodname) {
4450 return function () {
4451 var arg = arguments;
4452 return this.forEach(function (el) {
4453 el[methodname].apply(el, arg);
4460 // ┌─────────────────────────────────────────────────────────────────────┐ \\
4461 // │ Raphaël - JavaScript Vector Library │ \\
4462 // ├─────────────────────────────────────────────────────────────────────┤ \\
4463 // │ VML Module │ \\
4464 // ├─────────────────────────────────────────────────────────────────────┤ \\
4465 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
4466 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
4467 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
4468 // └─────────────────────────────────────────────────────────────────────┘ \\
4471 window.Raphael.vml && function (R) {
4472 var has = "hasOwnProperty",
4474 toFloat = parseFloat,
4480 fillString = "fill",
4481 separator = /[, ]+/,
4483 ms = " progid:DXImageTransform.Microsoft",
4486 map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
4487 bites = /([clmz]),?([^clmz]*)/gi,
4488 blurregexp = / progid:\S+Blur\([^\)]+\)/g,
4489 val = /-?[^,\s-]+/g,
4490 cssDot = "position:absolute;left:0;top:0;width:1px;height:1px",
4492 pathTypes = {path: 1, rect: 1, image: 1},
4493 ovalTypes = {circle: 1, ellipse: 1},
4494 path2vml = function (path) {
4495 var total = /[ahqstv]/ig,
4496 command = R._pathToAbsolute;
4497 Str(path).match(total) && (command = R._path2curve);
4499 if (command == R._pathToAbsolute && !Str(path).match(total)) {
4500 var res = Str(path).replace(bites, function (all, command, args) {
4502 isMove = command.toLowerCase() == "m",
4504 args.replace(val, function (value) {
4505 if (isMove && vals.length == 2) {
4506 res += vals + map[command == "m" ? "l" : "L"];
4509 vals.push(round(value * zoom));
4515 var pa = command(path), p, r;
4517 for (var i = 0, ii = pa.length; i < ii; i++) {
4519 r = pa[i][0].toLowerCase();
4520 r == "z" && (r = "x");
4521 for (var j = 1, jj = p.length; j < jj; j++) {
4522 r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
4528 compensation = function (deg, dx, dy) {
4530 m.rotate(-deg, .5, .5);
4536 setCoords = function (p, sx, sy, dx, dy, deg) {
4539 fillpos = _.fillpos,
4547 s.visibility = "hidden";
4551 o.coordsize = abs(kx) + S + abs(ky);
4552 s.rotation = deg * (sx * sy < 0 ? -1 : 1);
4554 var c = compensation(deg, dx, dy);
4558 sx < 0 && (flip += "x");
4559 sy < 0 && (flip += " y") && (y = -1);
4561 o.coordorigin = (dx * -kx) + S + (dy * -ky);
4562 if (fillpos || _.fillsize) {
4563 var fill = o.getElementsByTagName(fillString);
4564 fill = fill && fill[0];
4565 o.removeChild(fill);
4567 c = compensation(deg, m.x(fillpos[0], fillpos[1]), m.y(fillpos[0], fillpos[1]));
4568 fill.position = c.dx * y + S + c.dy * y;
4571 fill.size = _.fillsize[0] * abs(sx) + S + _.fillsize[1] * abs(sy);
4573 o.appendChild(fill);
4575 s.visibility = "visible";
4577 R.toString = function () {
4578 return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
4580 var addArrow = function (o, value, isEnd) {
4581 var values = Str(value).toLowerCase().split("-"),
4582 se = isEnd ? "end" : "start",
4588 switch (values[i]) {
4598 case "narrow": h = values[i]; break;
4600 case "short": w = values[i]; break;
4603 var stroke = o.node.getElementsByTagName("stroke")[0];
4604 stroke[se + "arrow"] = type;
4605 stroke[se + "arrowlength"] = w;
4606 stroke[se + "arrowwidth"] = h;
4608 setFillAndStroke = function (o, params) {
4609 // o.paper.canvas.style.display = "none";
4610 o.attrs = o.attrs || {};
4615 newpath = pathTypes[o.type] && (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.cx != a.cx || params.cy != a.cy || params.rx != a.rx || params.ry != a.ry || params.r != a.r),
4616 isOval = ovalTypes[o.type] && (a.cx != params.cx || a.cy != params.cy || a.r != params.r || a.rx != params.rx || a.ry != params.ry),
4620 for (var par in params) if (params[has](par)) {
4621 a[par] = params[par];
4624 a.path = R._getPath[o.type](o);
4627 params.href && (node.href = params.href);
4628 params.title && (node.title = params.title);
4629 params.target && (node.target = params.target);
4630 params.cursor && (s.cursor = params.cursor);
4631 "blur" in params && o.blur(params.blur);
4632 if (params.path && o.type == "path" || newpath) {
4633 node.path = path2vml(~Str(a.path).toLowerCase().indexOf("r") ? R._pathToAbsolute(a.path) : a.path);
4634 if (o.type == "image") {
4635 o._.fillpos = [a.x, a.y];
4636 o._.fillsize = [a.width, a.height];
4637 setCoords(o, 1, 1, 0, 0, 0);
4640 "transform" in params && o.transform(params.transform);
4644 rx = +a.rx || +a.r || 0,
4645 ry = +a.ry || +a.r || 0;
4646 node.path = R.format("ar{0},{1},{2},{3},{4},{1},{4},{1}x", round((cx - rx) * zoom), round((cy - ry) * zoom), round((cx + rx) * zoom), round((cy + ry) * zoom), round(cx * zoom));
4648 if ("clip-rect" in params) {
4649 var rect = Str(params["clip-rect"]).split(separator);
4650 if (rect.length == 4) {
4651 rect[2] = +rect[2] + (+rect[0]);
4652 rect[3] = +rect[3] + (+rect[1]);
4653 var div = node.clipRect || R._g.doc.createElement("div"),
4655 dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
4656 if (!node.clipRect) {
4657 dstyle.position = "absolute";
4660 dstyle.width = o.paper.width + "px";
4661 dstyle.height = o.paper.height + "px";
4662 node.parentNode.insertBefore(div, node);
4663 div.appendChild(node);
4664 node.clipRect = div;
4667 if (!params["clip-rect"]) {
4668 node.clipRect && (node.clipRect.style.clip = "auto");
4672 var textpathStyle = o.textpath.style;
4673 params.font && (textpathStyle.font = params.font);
4674 params["font-family"] && (textpathStyle.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, E) + '"');
4675 params["font-size"] && (textpathStyle.fontSize = params["font-size"]);
4676 params["font-weight"] && (textpathStyle.fontWeight = params["font-weight"]);
4677 params["font-style"] && (textpathStyle.fontStyle = params["font-style"]);
4679 if ("arrow-start" in params) {
4680 addArrow(res, params["arrow-start"]);
4682 if ("arrow-end" in params) {
4683 addArrow(res, params["arrow-end"], 1);
4685 if (params.opacity != null ||
4686 params["stroke-width"] != null ||
4687 params.fill != null ||
4688 params.src != null ||
4689 params.stroke != null ||
4690 params["stroke-width"] != null ||
4691 params["stroke-opacity"] != null ||
4692 params["fill-opacity"] != null ||
4693 params["stroke-dasharray"] != null ||
4694 params["stroke-miterlimit"] != null ||
4695 params["stroke-linejoin"] != null ||
4696 params["stroke-linecap"] != null) {
4697 var fill = node.getElementsByTagName(fillString),
4699 fill = fill && fill[0];
4700 !fill && (newfill = fill = createNode(fillString));
4701 if (o.type == "image" && params.src) {
4702 fill.src = params.src;
4704 params.fill && (fill.on = true);
4705 if (fill.on == null || params.fill == "none" || params.fill === null) {
4708 if (fill.on && params.fill) {
4709 var isURL = Str(params.fill).match(R._ISURL);
4711 fill.parentNode == node && node.removeChild(fill);
4713 fill.src = isURL[1];
4715 var bbox = o.getBBox(1);
4716 fill.position = bbox.x + S + bbox.y;
4717 o._.fillpos = [bbox.x, bbox.y];
4719 R._preload(isURL[1], function () {
4720 o._.fillsize = [this.offsetWidth, this.offsetHeight];
4723 fill.color = R.getRGB(params.fill).hex;
4725 fill.type = "solid";
4726 if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill, fill)) {
4728 a.gradient = params.fill;
4729 fill.rotate = false;
4733 if ("fill-opacity" in params || "opacity" in params) {
4734 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
4735 opacity = mmin(mmax(opacity, 0), 1);
4736 fill.opacity = opacity;
4738 fill.color = "none";
4741 node.appendChild(fill);
4742 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
4744 !stroke && (newstroke = stroke = createNode("stroke"));
4745 if ((params.stroke && params.stroke != "none") ||
4746 params["stroke-width"] ||
4747 params["stroke-opacity"] != null ||
4748 params["stroke-dasharray"] ||
4749 params["stroke-miterlimit"] ||
4750 params["stroke-linejoin"] ||
4751 params["stroke-linecap"]) {
4754 (params.stroke == "none" || params.stroke === null || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
4755 var strokeColor = R.getRGB(params.stroke);
4756 stroke.on && params.stroke && (stroke.color = strokeColor.hex);
4757 opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
4758 var width = (toFloat(params["stroke-width"]) || 1) * .75;
4759 opacity = mmin(mmax(opacity, 0), 1);
4760 params["stroke-width"] == null && (width = a["stroke-width"]);
4761 params["stroke-width"] && (stroke.weight = width);
4762 width && width < 1 && (opacity *= width) && (stroke.weight = 1);
4763 stroke.opacity = opacity;
4765 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
4766 stroke.miterlimit = params["stroke-miterlimit"] || 8;
4767 params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
4768 if (params["stroke-dasharray"]) {
4772 "-.": "shortdashdot",
4773 "-..": "shortdashdotdot",
4778 "--.": "longdashdot",
4779 "--..": "longdashdotdot"
4781 stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
4783 newstroke && node.appendChild(stroke);
4785 if (res.type == "text") {
4786 res.paper.canvas.style.display = E;
4787 var span = res.paper.span,
4789 fontSize = a.font && a.font.match(/\d+(?:\.\d*)?(?=px)/);
4791 a.font && (s.font = a.font);
4792 a["font-family"] && (s.fontFamily = a["font-family"]);
4793 a["font-weight"] && (s.fontWeight = a["font-weight"]);
4794 a["font-style"] && (s.fontStyle = a["font-style"]);
4795 fontSize = toFloat(a["font-size"] || fontSize && fontSize[0]) || 10;
4796 s.fontSize = fontSize * m + "px";
4797 res.textpath.string && (span.innerHTML = Str(res.textpath.string).replace(/</g, "<").replace(/&/g, "&").replace(/\n/g, "<br>"));
4798 var brect = span.getBoundingClientRect();
4799 res.W = a.w = (brect.right - brect.left) / m;
4800 res.H = a.h = (brect.bottom - brect.top) / m;
4801 // res.paper.canvas.style.display = "none";
4803 res.Y = a.y + res.H / 2;
4805 ("x" in params || "y" in params) && (res.path.v = R.format("m{0},{1}l{2},{1}", round(a.x * zoom), round(a.y * zoom), round(a.x * zoom) + 1));
4806 var dirtyattrs = ["x", "y", "text", "font", "font-family", "font-weight", "font-style", "font-size"];
4807 for (var d = 0, dd = dirtyattrs.length; d < dd; d++) if (dirtyattrs[d] in params) {
4812 // text-anchor emulation
4813 switch (a["text-anchor"]) {
4815 res.textpath.style["v-text-align"] = "left";
4816 res.bbx = res.W / 2;
4819 res.textpath.style["v-text-align"] = "right";
4820 res.bbx = -res.W / 2;
4823 res.textpath.style["v-text-align"] = "center";
4827 res.textpath.style["v-text-kern"] = true;
4829 // res.paper.canvas.style.display = E;
4831 addGradientFill = function (o, gradient, fill) {
4832 o.attrs = o.attrs || {};
4833 var attrs = o.attrs,
4839 o.attrs.gradient = gradient;
4840 gradient = Str(gradient).replace(R._radial_gradient, function (all, fx, fy) {
4845 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
4850 gradient = gradient.split(/\s*\-\s*/);
4851 if (type == "linear") {
4852 var angle = gradient.shift();
4853 angle = -toFloat(angle);
4858 var dots = R._parseDots(gradient);
4862 o = o.shape || o.node;
4864 o.removeChild(fill);
4866 fill.method = "none";
4867 fill.color = dots[0].color;
4868 fill.color2 = dots[dots.length - 1].color;
4870 for (var i = 0, ii = dots.length; i < ii; i++) {
4871 dots[i].offset && clrs.push(dots[i].offset + S + dots[i].color);
4873 fill.colors = clrs.length ? clrs.join() : "0% " + fill.color;
4874 if (type == "radial") {
4875 fill.type = "gradientTitle";
4876 fill.focus = "100%";
4877 fill.focussize = "0 0";
4878 fill.focusposition = fxfy;
4881 // fill.rotate= true;
4882 fill.type = "gradient";
4883 fill.angle = (270 - angle) % 360;
4885 o.appendChild(fill);
4889 Element = function (node, vml) {
4890 this[0] = this.node = node;
4891 node.raphael = true;
4893 node.raphaelid = this.id;
4898 this.matrix = R.matrix();
4909 !vml.bottom && (vml.bottom = this);
4910 this.prev = vml.top;
4911 vml.top && (vml.top.next = this);
4917 Element.prototype = elproto;
4918 elproto.constructor = Element;
4919 elproto.transform = function (tstr) {
4921 return this._.transform;
4923 var vbs = this.paper._viewBoxShift,
4924 vbt = vbs ? "s" + [vbs.scale, vbs.scale] + "-1-1t" + [vbs.dx, vbs.dy] : E,
4927 oldt = tstr = Str(tstr).replace(/\.{3}|\u2026/g, this._.transform || E);
4929 R._extractTransform(this, vbt + tstr);
4930 var matrix = this.matrix.clone(),
4934 isGrad = ~Str(this.attrs.fill).indexOf("-"),
4935 isPatt = !Str(this.attrs.fill).indexOf("url(");
4936 matrix.translate(-.5, -.5);
4937 if (isPatt || isGrad || this.type == "image") {
4938 skew.matrix = "1 0 0 1";
4939 skew.offset = "0 0";
4940 split = matrix.split();
4941 if ((isGrad && split.noRotation) || !split.isSimple) {
4942 o.style.filter = matrix.toFilter();
4943 var bb = this.getBBox(),
4944 bbt = this.getBBox(1),
4947 o.coordorigin = (dx * -zoom) + S + (dy * -zoom);
4948 setCoords(this, 1, 1, dx, dy, 0);
4951 setCoords(this, split.scalex, split.scaley, split.dx, split.dy, split.rotate);
4955 skew.matrix = Str(matrix);
4956 skew.offset = matrix.offset();
4958 oldt && (this._.transform = oldt);
4961 elproto.rotate = function (deg, cx, cy) {
4968 deg = Str(deg).split(separator);
4969 if (deg.length - 1) {
4970 cx = toFloat(deg[1]);
4971 cy = toFloat(deg[2]);
4973 deg = toFloat(deg[0]);
4974 (cy == null) && (cx = cy);
4975 if (cx == null || cy == null) {
4976 var bbox = this.getBBox(1);
4977 cx = bbox.x + bbox.width / 2;
4978 cy = bbox.y + bbox.height / 2;
4981 this.transform(this._.transform.concat([["r", deg, cx, cy]]));
4984 elproto.translate = function (dx, dy) {
4988 dx = Str(dx).split(separator);
4989 if (dx.length - 1) {
4990 dy = toFloat(dx[1]);
4992 dx = toFloat(dx[0]) || 0;
4995 this._.bbox.x += dx;
4996 this._.bbox.y += dy;
4998 this.transform(this._.transform.concat([["t", dx, dy]]));
5001 elproto.scale = function (sx, sy, cx, cy) {
5005 sx = Str(sx).split(separator);
5006 if (sx.length - 1) {
5007 sy = toFloat(sx[1]);
5008 cx = toFloat(sx[2]);
5009 cy = toFloat(sx[3]);
5010 isNaN(cx) && (cx = null);
5011 isNaN(cy) && (cy = null);
5013 sx = toFloat(sx[0]);
5014 (sy == null) && (sy = sx);
5015 (cy == null) && (cx = cy);
5016 if (cx == null || cy == null) {
5017 var bbox = this.getBBox(1);
5019 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
5020 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
5022 this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
5026 elproto.hide = function () {
5027 !this.removed && (this.node.style.display = "none");
5030 elproto.show = function () {
5031 !this.removed && (this.node.style.display = E);
5034 elproto._getBBox = function () {
5039 x: this.X + (this.bbx || 0) - this.W / 2,
5045 elproto.remove = function () {
5049 this.paper.__set__ && this.paper.__set__.exclude(this);
5050 R.eve.unbind("*.*." + this.id);
5051 R._tear(this, this.paper);
5052 this.node.parentNode.removeChild(this.node);
5053 this.shape && this.shape.parentNode.removeChild(this.shape);
5054 for (var i in this) {
5055 this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
5057 this.removed = true;
5059 elproto.attr = function (name, value) {
5065 for (var a in this.attrs) if (this.attrs[has](a)) {
5066 res[a] = this.attrs[a];
5068 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
5069 res.transform = this._.transform;
5072 if (value == null && R.is(name, "string")) {
5073 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
5074 return this.attrs.gradient;
5076 var names = name.split(separator),
5078 for (var i = 0, ii = names.length; i < ii; i++) {
5080 if (name in this.attrs) {
5081 out[name] = this.attrs[name];
5082 } else if (R.is(this.paper.customAttributes[name], "function")) {
5083 out[name] = this.paper.customAttributes[name].def;
5085 out[name] = R._availableAttrs[name];
5088 return ii - 1 ? out : out[names[0]];
5090 if (this.attrs && value == null && R.is(name, "array")) {
5092 for (i = 0, ii = name.length; i < ii; i++) {
5093 out[name[i]] = this.attr(name[i]);
5098 if (value != null) {
5100 params[name] = value;
5102 value == null && R.is(name, "object") && (params = name);
5103 for (var key in params) {
5104 eve("attr." + key + "." + this.id, this, params[key]);
5107 for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
5108 var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
5109 this.attrs[key] = params[key];
5110 for (var subkey in par) if (par[has](subkey)) {
5111 params[subkey] = par[subkey];
5114 // this.paper.canvas.style.display = "none";
5115 if (params.text && this.type == "text") {
5116 this.textpath.string = params.text;
5118 setFillAndStroke(this, params);
5119 // this.paper.canvas.style.display = E;
5123 elproto.toFront = function () {
5124 !this.removed && this.node.parentNode.appendChild(this.node);
5125 this.paper && this.paper.top != this && R._tofront(this, this.paper);
5128 elproto.toBack = function () {
5132 if (this.node.parentNode.firstChild != this.node) {
5133 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
5134 R._toback(this, this.paper);
5138 elproto.insertAfter = function (element) {
5142 if (element.constructor == R.st.constructor) {
5143 element = element[element.length - 1];
5145 if (element.node.nextSibling) {
5146 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
5148 element.node.parentNode.appendChild(this.node);
5150 R._insertafter(this, element, this.paper);
5153 elproto.insertBefore = function (element) {
5157 if (element.constructor == R.st.constructor) {
5158 element = element[0];
5160 element.node.parentNode.insertBefore(this.node, element.node);
5161 R._insertbefore(this, element, this.paper);
5164 elproto.blur = function (size) {
5165 var s = this.node.runtimeStyle,
5167 f = f.replace(blurregexp, E);
5169 this.attrs.blur = size;
5170 s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
5171 s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
5175 delete this.attrs.blur;
5179 R._engine.path = function (pathString, vml) {
5180 var el = createNode("shape");
5181 el.style.cssText = cssDot;
5182 el.coordsize = zoom + S + zoom;
5183 el.coordorigin = vml.coordorigin;
5184 var p = new Element(el, vml),
5185 attr = {fill: "none", stroke: "#000"};
5186 pathString && (attr.path = pathString);
5190 setFillAndStroke(p, attr);
5191 vml.canvas.appendChild(el);
5192 var skew = createNode("skew");
5194 el.appendChild(skew);
5199 R._engine.rect = function (vml, x, y, w, h, r) {
5200 var path = R._rectPath(x, y, w, h, r),
5201 res = vml.path(path),
5205 res.W = a.width = w;
5206 res.H = a.height = h;
5212 R._engine.ellipse = function (vml, x, y, rx, ry) {
5213 var res = vml.path(),
5219 res.type = "ellipse";
5220 setFillAndStroke(res, {
5228 R._engine.circle = function (vml, x, y, r) {
5229 var res = vml.path(),
5233 res.W = res.H = r * 2;
5234 res.type = "circle";
5235 setFillAndStroke(res, {
5242 R._engine.image = function (vml, src, x, y, w, h) {
5243 var path = R._rectPath(x, y, w, h),
5244 res = vml.path(path).attr({stroke: "none"}),
5247 fill = node.getElementsByTagName(fillString)[0];
5251 res.W = a.width = w;
5252 res.H = a.height = h;
5255 fill.parentNode == node && node.removeChild(fill);
5259 res._.fillpos = [x, y];
5260 res._.fillsize = [w, h];
5261 node.appendChild(fill);
5262 setCoords(res, 1, 1, 0, 0, 0);
5265 R._engine.text = function (vml, x, y, text) {
5266 var el = createNode("shape"),
5267 path = createNode("path"),
5268 o = createNode("textpath");
5272 path.v = R.format("m{0},{1}l{2},{1}", round(x * zoom), round(y * zoom), round(x * zoom) + 1);
5273 path.textpathok = true;
5274 o.string = Str(text);
5276 el.style.cssText = cssDot;
5277 el.coordsize = zoom + S + zoom;
5278 el.coordorigin = "0 0";
5279 var p = new Element(el, vml),
5283 font: R._availableAttrs.font,
5290 p.attrs.text = Str(text);
5295 setFillAndStroke(p, attr);
5297 el.appendChild(path);
5298 vml.canvas.appendChild(el);
5299 var skew = createNode("skew");
5301 el.appendChild(skew);
5306 R._engine.setSize = function (width, height) {
5307 var cs = this.canvas.style;
5309 this.height = height;
5310 width == +width && (width += "px");
5311 height == +height && (height += "px");
5314 cs.clip = "rect(0 " + width + " " + height + " 0)";
5315 if (this._viewBox) {
5316 R._engine.setViewBox.apply(this, this._viewBox);
5320 R._engine.setViewBox = function (x, y, w, h, fit) {
5321 R.eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
5322 var width = this.width,
5323 height = this.height,
5324 size = 1 / mmax(w / width, h / height),
5329 if (w * H < width) {
5330 x -= (width - w * H) / 2 / H;
5332 if (h * W < height) {
5333 y -= (height - h * W) / 2 / W;
5336 this._viewBox = [x, y, w, h, !!fit];
5337 this._viewBoxShift = {
5342 this.forEach(function (el) {
5343 el.transform("...");
5348 R._engine.initWin = function (win) {
5349 var doc = win.document;
5350 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
5352 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
5353 createNode = function (tagName) {
5354 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
5357 createNode = function (tagName) {
5358 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
5362 R._engine.initWin(R._g.win);
5363 R._engine.create = function () {
5364 var con = R._getContainer.apply(0, arguments),
5365 container = con.container,
5366 height = con.height,
5372 throw new Error("VML container not found.");
5374 var res = new R._Paper,
5375 c = res.canvas = R._g.doc.createElement("div"),
5379 width = width || 512;
5380 height = height || 342;
5382 res.height = height;
5383 width == +width && (width += "px");
5384 height == +height && (height += "px");
5385 res.coordsize = zoom * 1e3 + S + zoom * 1e3;
5386 res.coordorigin = "0 0";
5387 res.span = R._g.doc.createElement("span");
5388 res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;";
5389 c.appendChild(res.span);
5390 cs.cssText = R.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden", width, height);
5391 if (container == 1) {
5392 R._g.doc.body.appendChild(c);
5395 cs.position = "absolute";
5397 if (container.firstChild) {
5398 container.insertBefore(c, container.firstChild);
5400 container.appendChild(c);
5403 // plugins.call(res, res, R.fn);
5404 res.renderfix = function () {};
5407 R.prototype.clear = function () {
5408 R.eve("clear", this);
5409 this.canvas.innerHTML = E;
5410 this.span = R._g.doc.createElement("span");
5411 this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
5412 this.canvas.appendChild(this.span);
5413 this.bottom = this.top = null;
5415 R.prototype.remove = function () {
5416 R.eve("remove", this);
5417 this.canvas.parentNode.removeChild(this.canvas);
5418 for (var i in this) {
5419 this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
5424 var setproto = R.st;
5425 for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
5426 setproto[method] = (function (methodname) {
5427 return function () {
5428 var arg = arguments;
5429 return this.forEach(function (el) {
5430 el[methodname].apply(el, arg);