1 // ┌─────────────────────────────────────────────────────────────────────┐ \\
2 // │ Raphaël 2.0 - 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.3.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.3.0",
18 has = "hasOwnProperty",
22 numsort = function (a, b) {
29 eve = function (name, scope) {
31 args = Array.prototype.slice.call(arguments, 2),
32 listeners = eve.listeners(name),
42 for (var i = 0, ii = listeners.length; i < ii; i++) if ("zIndex" in listeners[i]) {
43 indexed.push(listeners[i].zIndex);
44 if (listeners[i].zIndex < 0) {
45 queue[listeners[i].zIndex] = listeners[i];
48 indexed.sort(numsort);
49 while (indexed[z] < 0) {
50 l = queue[indexed[z++]];
51 out.push(l.apply(scope, args));
56 for (i = 0; i < ii; i++) {
59 if (l.zIndex == indexed[z]) {
60 out.push(l.apply(scope, args));
66 l = queue[indexed[z]];
67 l && out.push(l.apply(scope, args));
76 out.push(l.apply(scope, args));
82 return out.length ? out : null;
85 eve.listeners = function (name) {
86 var names = name.split(separator),
98 for (i = 0, ii = names.length; i < ii; i++) {
100 for (j = 0, jj = es.length; j < jj; j++) {
102 items = [e[names[i]], e[wildcard]];
108 out = out.concat(item.f || []);
118 eve.on = function (name, f) {
119 var names = name.split(separator),
121 for (var i = 0, ii = names.length; i < ii; i++) {
123 !e[names[i]] && (e[names[i]] = {n: {}});
127 for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) {
131 return function (zIndex) {
132 if (+zIndex == +zIndex) {
138 eve.stop = function () {
142 eve.nt = function (subname) {
144 return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(current_event);
146 return current_event;
149 eve.unbind = function (name, f) {
150 var names = name.split(separator),
155 for (var i = 0, ii = names.length; i < ii; i++) {
156 for (var j = 0; j < cur.length; j += splice.length - 2) {
159 if (names[i] != wildcard) {
161 splice.push(e[names[i]]);
164 for (key in e) if (e[has](key)) {
168 cur.splice.apply(cur, splice);
171 for (i = 0, ii = cur.length; i < ii; i++) {
176 for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) {
180 !e.f.length && delete e.f;
182 for (key in e.n) if (e.n[has](key) && e.n[key].f) {
183 var funcs = e.n[key].f;
184 for (i = 0, ii = funcs.length; i < ii; i++) if (funcs[i] == f) {
188 !funcs.length && delete e.n[key].f;
192 for (key in e.n) if (e.n[has](key) && e.n[key].f) {
201 eve.version = version;
202 eve.toString = function () {
203 return "You are running Eve " + version;
205 (typeof module != "undefined" && module.exports) ? (module.exports = eve) : (glob.eve = eve);
208 // ┌─────────────────────────────────────────────────────────────────────┐ \\
209 // │ "Raphaël 2.0" - JavaScript Vector Library │ \\
210 // ├─────────────────────────────────────────────────────────────────────┤ \\
211 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
212 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
213 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
214 // └─────────────────────────────────────────────────────────────────────┘ \\
218 if (R.is(first, "function")) {
219 return loaded ? first() : eve.on("DOMload", first);
220 } else if (R.is(first, array)) {
222 cnv = R._engine.create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
227 for (; i < ii; i++) {
229 elements[has](j.type) && res.push(cnv[j.type]().attr(j));
233 var args = Array.prototype.slice.call(arguments, 0);
234 if (R.is(args[args.length - 1], "function")) {
236 return loaded ? f.call(R._engine.create[apply](R, args)) : eve.on("DOMload", function () {
237 f.call(R._engine.create[apply](R, args));
240 return R._engine.create[apply](R, arguments);
248 elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
249 formatrg = /\{(\d+)\}/g,
251 has = "hasOwnProperty",
257 was: Object.prototype[has].call(g.win, "Raphael"),
260 Paper = function () {},
262 appendChild = "appendChild",
265 supportsTouch = "createTouch" in g.doc,
270 events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel".split(S),
272 mousedown: "touchstart",
273 mousemove: "touchmove",
276 lowerCase = Str.prototype.toLowerCase,
286 toString = "toString",
288 objectToString = Object.prototype.toString,
291 ISURL = R._ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
292 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,
293 isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
294 bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
296 setAttribute = "setAttribute",
297 toFloat = parseFloat,
299 ms = " progid:DXImageTransform.Microsoft",
300 upperCase = Str.prototype.toUpperCase,
301 availableAttrs = R._availableAttrs = {
303 "arrow-start": "none",
305 "clip-rect": "0 0 1e9 1e9",
311 font: '10px "Arial"',
312 "font-family": '"Arial"',
314 "font-style": "normal",
318 href: "http://raphaeljs.com/",
326 "stroke-dasharray": "",
327 "stroke-linecap": "butt",
328 "stroke-linejoin": "butt",
329 "stroke-miterlimit": 0,
333 "text-anchor": "middle",
340 availableAnimAttrs = R._availableAnimAttrs = {
355 "stroke-opacity": nu,
357 transform: "transform",
362 commaSpaces = /\s*,\s*/,
363 hsrg = {hs: 1, rg: 1},
364 p2s = /,?([achlmqrstvxz]),?/gi,
365 pathCommand = /([achlmrqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
366 tCommand = /([rstm])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
367 pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)\s*,?\s*/ig,
368 radial_gradient = R._radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/,
370 sortByKey = function (a, b) {
371 return a.key - b.key;
373 sortByNumber = function (a, b) {
376 fun = function () {},
377 pipe = function (x) {
380 rectPath = R._rectPath = function (x, y, w, h, r) {
382 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"]];
384 return [["M", x, y], ["l", w, 0], ["l", 0, h], ["l", -w, 0], ["z"]];
386 ellipsePath = function (x, y, rx, ry) {
390 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"]];
392 getPath = R._getPath = {
393 path: function (el) {
394 return el.attr("path");
396 circle: function (el) {
398 return ellipsePath(a.cx, a.cy, a.r);
400 ellipse: function (el) {
402 return ellipsePath(a.cx, a.cy, a.rx, a.ry);
404 rect: function (el) {
406 return rectPath(a.x, a.y, a.width, a.height, a.r);
408 image: function (el) {
410 return rectPath(a.x, a.y, a.width, a.height);
412 text: function (el) {
413 var bbox = el._getBBox();
414 return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
417 mapPath = function (path, matrix) {
421 var x, y, i, j, pathi;
422 path = path2curve(path);
423 for (i = 0, ii = path.length; i < ii; i++) {
425 for (j = 1, jj = pathi.length; j < jj; j += 2) {
426 x = matrix.x(pathi[j], pathi[j + 1]);
427 y = matrix.y(pathi[j], pathi[j + 1]);
437 R.type = (g.win.SVGAngle || g.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
438 if (R.type == "VML") {
439 var d = g.doc.createElement("div"),
441 d.innerHTML = '<v:shape adj="1"/>';
443 b.style.behavior = "url(#default#VML)";
444 if (!(b && typeof b.adj == "object")) {
451 R.svg = !(R.vml = R.type == "VML");
454 R.fn = paperproto = Paper.prototype = R.prototype;
456 paperproto.customAttributes = {};
460 R.is = function (o, type) {
461 type = lowerCase.call(type);
462 if (type == "finite") {
463 return !isnan[has](+o);
465 if (type == "array") {
466 return o instanceof Array;
468 return (type == "null" && o === null) ||
469 (type == typeof o) ||
470 (type == "object" && o === Object(o)) ||
471 (type == "array" && Array.isArray && Array.isArray(o)) ||
472 objectToString.call(o).slice(8, -1).toLowerCase() == type;
475 R.angle = function (x1, y1, x2, y2, x3, y3) {
482 return (180 + math.atan2(-y, -x) * 180 / PI + 360) % 360;
484 return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
488 R.rad = function (deg) {
489 return deg % 360 * PI / 180;
492 R.deg = function (rad) {
493 return rad * 180 / PI % 360;
496 R.snapTo = function (values, value, tolerance) {
497 tolerance = R.is(tolerance, "finite") ? tolerance : 10;
498 if (R.is(values, array)) {
499 var i = values.length;
500 while (i--) if (abs(values[i] - value) <= tolerance) {
505 var rem = value % values;
506 if (rem < tolerance) {
509 if (rem > values - tolerance) {
510 return value - rem + values;
516 var createUUID = R._createUUID = (function (uuidRegEx, uuidReplacer) {
518 return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase();
520 })(/[xy]/g, function (c) {
521 var r = math.random() * 16 | 0,
522 v = c == "x" ? r : (r & 3 | 8);
523 return v.toString(16);
527 R.setWindow = function (newwin) {
528 eve("setWindow", R, g.win, newwin);
530 g.doc = g.win.document;
535 var toHex = function (color) {
537 // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
538 var trim = /^\s+|\s+$/g;
541 var docum = new ActiveXObject("htmlfile");
542 docum.write("<body>");
546 bod = createPopup().document.body;
548 var range = bod.createTextRange();
549 toHex = cacher(function (color) {
551 bod.style.color = Str(color).replace(trim, E);
552 var value = range.queryCommandValue("ForeColor");
553 value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
554 return "#" + ("000000" + value.toString(16)).slice(-6);
560 var i = g.doc.createElement("i");
561 i.title = "Rapha\xebl Colour Picker";
562 i.style.display = "none";
563 g.doc.body.appendChild(i);
564 toHex = cacher(function (color) {
565 i.style.color = color;
566 return g.doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
571 hsbtoString = function () {
572 return "hsb(" + [this.h, this.s, this.b] + ")";
574 hsltoString = function () {
575 return "hsl(" + [this.h, this.s, this.l] + ")";
577 rgbtoString = function () {
580 prepareRGB = function (r, g, b) {
581 if (g == null && R.is(r, "object") && "r" in r && "g" in r && "b" in r) {
586 if (g == null && R.is(r, string)) {
587 var clr = R.getRGB(r);
592 if (r > 1 || g > 1 || b > 1) {
600 packageRGB = function (r, g, b, o) {
609 toString: rgbtoString
611 R.is(o, "finite") && (rgb.opacity = o);
616 R.color = function (clr) {
618 if (R.is(clr, "object") && "h" in clr && "s" in clr && "b" in clr) {
619 rgb = R.hsb2rgb(clr);
624 } else if (R.is(clr, "object") && "h" in clr && "s" in clr && "l" in clr) {
625 rgb = R.hsl2rgb(clr);
631 if (R.is(clr, "string")) {
634 if (R.is(clr, "object") && "r" in clr && "g" in clr && "b" in clr) {
635 rgb = R.rgb2hsl(clr);
639 rgb = R.rgb2hsb(clr);
643 crl.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1;
646 clr.toString = rgbtoString;
650 R.hsb2rgb = function (h, s, v, o) {
651 if (this.is(h, "object") && "h" in h && "s" in h && "b" in h) {
661 X = C * (1 - abs(h % 2 - 1));
665 R += [C, X, 0, 0, X, C][h];
666 G += [X, C, C, X, 0, 0][h];
667 B += [0, 0, X, C, C, X][h];
668 return packageRGB(R, G, B, o);
671 R.hsl2rgb = function (h, s, l, o) {
672 if (this.is(h, "object") && "h" in h && "s" in h && "l" in h) {
677 if (h > 1 || s > 1 || l > 1) {
685 C = 2 * s * (l < .5 ? l : 1 - l);
686 X = C * (1 - abs(h % 2 - 1));
687 R = G = B = l - C / 2;
690 R += [C, X, 0, 0, X, C][h];
691 G += [X, C, C, X, 0, 0][h];
692 B += [0, 0, X, C, C, X][h];
693 return packageRGB(R, G, B, o);
696 R.rgb2hsb = function (r, g, b) {
697 b = prepareRGB(r, g, b);
704 C = V - mmin(r, g, b);
706 V == r ? (g - b) / C :
707 V == g ? (b - r) / C + 2 :
710 H = ((H + 360) % 6) * 60 / 360;
711 S = C == 0 ? 0 : C / V;
712 return {h: H, s: S, b: V, toString: hsbtoString};
715 R.rgb2hsl = function (r, g, b) {
716 b = prepareRGB(r, g, b);
721 var H, S, L, M, m, C;
726 M == r ? (g - b) / C :
727 M == g ? (b - r) / C + 2 :
729 H = ((H + 360) % 6) * 60 / 360;
732 L < .5 ? C / (2 * L) :
734 return {h: H, s: S, l: L, toString: hsltoString};
736 R._path2string = function () {
737 return this.join(",").replace(p2s, "$1");
739 function repush(array, item) {
740 for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
741 return array.push(array.splice(i, 1)[0]);
744 function cacher(f, scope, postprocessor) {
746 var arg = Array.prototype.slice.call(arguments, 0),
747 args = arg.join("\u2400"),
748 cache = newf.cache = newf.cache || {},
749 count = newf.count = newf.count || [];
750 if (cache[has](args)) {
752 return postprocessor ? postprocessor(cache[args]) : cache[args];
754 count.length >= 1e3 && delete cache[count.shift()];
756 cache[args] = f[apply](scope, arg);
757 return postprocessor ? postprocessor(cache[args]) : cache[args];
762 var preload = R._preload = function (src, f) {
763 var img = g.doc.createElement("img");
764 img.style.cssText = "position:absolute;left:-9999em;top-9999em";
765 img.onload = function () {
768 g.doc.body.removeChild(this);
770 img.onerror = function () {
771 g.doc.body.removeChild(this);
773 g.doc.body.appendChild(img);
777 function clrToString() {
782 R.getRGB = cacher(function (colour) {
783 if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
784 return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
786 if (colour == "none") {
787 return {r: -1, g: -1, b: -1, hex: "none", toString: clrToString};
789 !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
797 rgb = colour.match(colourRegExp);
800 blue = toInt(rgb[2].substring(5), 16);
801 green = toInt(rgb[2].substring(3, 5), 16);
802 red = toInt(rgb[2].substring(1, 3), 16);
805 blue = toInt((t = rgb[3].charAt(3)) + t, 16);
806 green = toInt((t = rgb[3].charAt(2)) + t, 16);
807 red = toInt((t = rgb[3].charAt(1)) + t, 16);
810 values = rgb[4].split(commaSpaces);
811 red = toFloat(values[0]);
812 values[0].slice(-1) == "%" && (red *= 2.55);
813 green = toFloat(values[1]);
814 values[1].slice(-1) == "%" && (green *= 2.55);
815 blue = toFloat(values[2]);
816 values[2].slice(-1) == "%" && (blue *= 2.55);
817 rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3]));
818 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
821 values = rgb[5].split(commaSpaces);
822 red = toFloat(values[0]);
823 values[0].slice(-1) == "%" && (red *= 2.55);
824 green = toFloat(values[1]);
825 values[1].slice(-1) == "%" && (green *= 2.55);
826 blue = toFloat(values[2]);
827 values[2].slice(-1) == "%" && (blue *= 2.55);
828 (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
829 rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3]));
830 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
831 return R.hsb2rgb(red, green, blue, opacity);
834 values = rgb[6].split(commaSpaces);
835 red = toFloat(values[0]);
836 values[0].slice(-1) == "%" && (red *= 2.55);
837 green = toFloat(values[1]);
838 values[1].slice(-1) == "%" && (green *= 2.55);
839 blue = toFloat(values[2]);
840 values[2].slice(-1) == "%" && (blue *= 2.55);
841 (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
842 rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3]));
843 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
844 return R.hsl2rgb(red, green, blue, opacity);
846 rgb = {r: red, g: green, b: blue, toString: clrToString};
847 rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1);
848 R.is(opacity, "finite") && (rgb.opacity = opacity);
851 return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
854 R.hsb = cacher(function (h, s, b) {
855 return R.hsb2rgb(h, s, b).hex;
858 R.hsl = cacher(function (h, s, l) {
859 return R.hsl2rgb(h, s, l).hex;
862 R.rgb = cacher(function (r, g, b) {
863 return "#" + (16777216 | b | (g << 8) | (r << 16)).toString(16).slice(1);
866 R.getColor = function (value) {
867 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
868 rgb = this.hsb2rgb(start.h, start.s, start.b);
873 start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
878 R.getColor.reset = function () {
883 R.parsePathString = cacher(function (pathString) {
887 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
889 if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
890 data = pathClone(pathString);
893 Str(pathString).replace(pathCommand, function (a, b, c) {
895 name = lowerCase.call(b);
896 c.replace(pathValues, function (a, b) {
897 b && params.push(+b);
899 if (name == "m" && params.length > 2) {
900 data.push([b][concat](params.splice(0, 2)));
902 b = b == "m" ? "l" : "L";
904 while (params.length >= paramCounts[name]) {
905 data.push([b][concat](params.splice(0, paramCounts[name])));
906 if (!paramCounts[name]) {
912 data.toString = R._path2string;
916 R.parseTransformString = cacher(function (TString) {
920 var paramCounts = {r: 3, s: 4, t: 2, m: 6},
922 if (R.is(TString, array) && R.is(TString[0], array)) { // rough assumption
923 data = pathClone(TString);
926 Str(TString).replace(tCommand, function (a, b, c) {
928 name = lowerCase.call(b);
929 c.replace(pathValues, function (a, b) {
930 b && params.push(+b);
932 data.push([name][concat](params));
935 data.toString = R._path2string;
939 R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
945 x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
946 y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y,
947 mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x),
948 my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y),
949 nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x),
950 ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y),
951 ax = t1 * p1x + t * c1x,
952 ay = t1 * p1y + t * c1y,
953 cx = t1 * c2x + t * p2x,
954 cy = t1 * c2y + t * p2y,
955 alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
956 (mx > nx || my < ny) && (alpha += 180);
962 start: {x: ax, y: ay},
967 var pathDimensions = cacher(function (path) {
969 return {x: 0, y: 0, width: 0, height: 0};
971 path = path2curve(path);
977 for (var i = 0, ii = path.length; i < ii; i++) {
985 var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
986 X = X[concat](dim.min.x, dim.max.x);
987 Y = Y[concat](dim.min.y, dim.max.y);
992 var xmin = mmin[apply](0, X),
993 ymin = mmin[apply](0, Y);
997 width: mmax[apply](0, X) - xmin,
998 height: mmax[apply](0, Y) - ymin
1000 }, null, function (o) {
1008 pathClone = function (pathArray) {
1010 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
1011 pathArray = R.parsePathString(pathArray);
1013 for (var i = 0, ii = pathArray.length; i < ii; i++) {
1015 for (var j = 0, jj = pathArray[i].length; j < jj; j++) {
1016 res[i][j] = pathArray[i][j];
1019 res.toString = R._path2string;
1022 pathToRelative = R._pathToRelative = cacher(function (pathArray) {
1023 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
1024 pathArray = R.parsePathString(pathArray);
1032 if (pathArray[0][0] == "M") {
1033 x = pathArray[0][1];
1034 y = pathArray[0][2];
1038 res.push(["M", x, y]);
1040 for (var i = start, ii = pathArray.length; i < ii; i++) {
1041 var r = res[i] = [],
1043 if (pa[0] != lowerCase.call(pa[0])) {
1044 r[0] = lowerCase.call(pa[0]);
1052 r[6] = +(pa[6] - x).toFixed(3);
1053 r[7] = +(pa[7] - y).toFixed(3);
1056 r[1] = +(pa[1] - y).toFixed(3);
1062 for (var j = 1, jj = pa.length; j < jj; j++) {
1063 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
1072 for (var k = 0, kk = pa.length; k < kk; k++) {
1076 var len = res[i].length;
1077 switch (res[i][0]) {
1083 x += +res[i][len - 1];
1086 y += +res[i][len - 1];
1089 x += +res[i][len - 2];
1090 y += +res[i][len - 1];
1093 res.toString = R._path2string;
1096 pathToAbsolute = R._pathToAbsolute = cacher(function (pathArray) {
1097 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
1098 pathArray = R.parsePathString(pathArray);
1100 if (!pathArray || !pathArray.length) {
1101 return [["M", 0, 0]];
1109 if (pathArray[0][0] == "M") {
1110 x = +pathArray[0][1];
1111 y = +pathArray[0][2];
1115 res[0] = ["M", x, y];
1117 for (var i = start, ii = pathArray.length; i < ii; i++) {
1118 var r = res[i] = [],
1120 if (pa[0] != upperCase.call(pa[0])) {
1121 r[0] = upperCase.call(pa[0]);
1129 r[6] = +(pa[6] + x);
1130 r[7] = +(pa[7] + y);
1142 for (var j = 1, jj = pa.length; j < jj; j++) {
1143 r[j] = +pa[j] + ((j % 2) ? x : y);
1147 for (var k = 0, kk = pa.length; k < kk; k++) {
1163 mx = res[i][res[i].length - 2];
1164 my = res[i][res[i].length - 1];
1166 x = res[i][res[i].length - 2];
1167 y = res[i][res[i].length - 1];
1170 res.toString = R._path2string;
1172 }, null, pathClone),
1173 l2c = function (x1, y1, x2, y2) {
1174 return [x1, y1, x2, y2, x2, y2];
1176 q2c = function (x1, y1, ax, ay, x2, y2) {
1180 _13 * x1 + _23 * ax,
1181 _13 * y1 + _23 * ay,
1182 _13 * x2 + _23 * ax,
1183 _13 * y2 + _23 * ay,
1188 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
1189 // for more information of where this math came from visit:
1190 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1191 var _120 = PI * 120 / 180,
1192 rad = PI / 180 * (+angle || 0),
1195 rotate = cacher(function (x, y, rad) {
1196 var X = x * math.cos(rad) - y * math.sin(rad),
1197 Y = x * math.sin(rad) + y * math.cos(rad);
1198 return {x: X, y: Y};
1201 xy = rotate(x1, y1, -rad);
1204 xy = rotate(x2, y2, -rad);
1207 var cos = math.cos(PI / 180 * angle),
1208 sin = math.sin(PI / 180 * angle),
1211 var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
1219 k = (large_arc_flag == sweep_flag ? -1 : 1) *
1220 math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
1221 cx = k * rx * y / ry + (x1 + x2) / 2,
1222 cy = k * -ry * x / rx + (y1 + y2) / 2,
1223 f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
1224 f2 = math.asin(((y2 - cy) / ry).toFixed(9));
1226 f1 = x1 < cx ? PI - f1 : f1;
1227 f2 = x2 < cx ? PI - f2 : f2;
1228 f1 < 0 && (f1 = PI * 2 + f1);
1229 f2 < 0 && (f2 = PI * 2 + f2);
1230 if (sweep_flag && f1 > f2) {
1233 if (!sweep_flag && f2 > f1) {
1243 if (abs(df) > _120) {
1247 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
1248 x2 = cx + rx * math.cos(f2);
1249 y2 = cy + ry * math.sin(f2);
1250 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
1253 var c1 = math.cos(f1),
1257 t = math.tan(df / 4),
1258 hx = 4 / 3 * rx * t,
1259 hy = 4 / 3 * ry * t,
1261 m2 = [x1 + hx * s1, y1 - hy * c1],
1262 m3 = [x2 + hx * s2, y2 - hy * c2],
1264 m2[0] = 2 * m1[0] - m2[0];
1265 m2[1] = 2 * m1[1] - m2[1];
1267 return [m2, m3, m4][concat](res);
1269 res = [m2, m3, m4][concat](res).join().split(",");
1271 for (var i = 0, ii = res.length; i < ii; i++) {
1272 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
1277 findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
1280 x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
1281 y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
1284 curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
1285 var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
1286 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
1288 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
1289 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
1293 abs(t1) > "1e12" && (t1 = .5);
1294 abs(t2) > "1e12" && (t2 = .5);
1295 if (t1 > 0 && t1 < 1) {
1296 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
1300 if (t2 > 0 && t2 < 1) {
1301 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
1305 a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
1306 b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
1308 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
1309 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
1310 abs(t1) > "1e12" && (t1 = .5);
1311 abs(t2) > "1e12" && (t2 = .5);
1312 if (t1 > 0 && t1 < 1) {
1313 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
1317 if (t2 > 0 && t2 < 1) {
1318 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
1323 min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
1324 max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
1327 path2curve = R._path2curve = cacher(function (path, path2) {
1328 var p = pathToAbsolute(path),
1329 p2 = path2 && pathToAbsolute(path2),
1330 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
1331 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
1332 processPath = function (path, d) {
1335 return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
1337 !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
1344 path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
1347 nx = d.x + (d.x - (d.bx || d.x));
1348 ny = d.y + (d.y - (d.by || d.y));
1349 path = ["C", nx, ny][concat](path.slice(1));
1352 d.qx = d.x + (d.x - (d.qx || d.x));
1353 d.qy = d.y + (d.y - (d.qy || d.y));
1354 path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
1359 path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
1362 path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
1365 path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
1368 path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
1371 path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
1376 fixArc = function (pp, i) {
1377 if (pp[i].length > 7) {
1381 pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
1384 ii = mmax(p.length, p2 && p2.length || 0);
1387 fixM = function (path1, path2, a1, a2, i) {
1388 if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
1389 path2.splice(i, 0, ["M", a2.x, a2.y]);
1394 ii = mmax(p.length, p2 && p2.length || 0);
1397 for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
1398 p[i] = processPath(p[i], attrs);
1400 p2 && (p2[i] = processPath(p2[i], attrs2));
1401 p2 && fixArc(p2, i);
1402 fixM(p, p2, attrs, attrs2, i);
1403 fixM(p2, p, attrs2, attrs, i);
1406 seglen = seg.length,
1407 seg2len = p2 && seg2.length;
1408 attrs.x = seg[seglen - 2];
1409 attrs.y = seg[seglen - 1];
1410 attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
1411 attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
1412 attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
1413 attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
1414 attrs2.x = p2 && seg2[seg2len - 2];
1415 attrs2.y = p2 && seg2[seg2len - 1];
1417 return p2 ? [p, p2] : p;
1418 }, null, pathClone),
1419 parseDots = R._parseDots = cacher(function (gradient) {
1421 for (var i = 0, ii = gradient.length; i < ii; i++) {
1423 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
1424 dot.color = R.getRGB(par[1]);
1425 if (dot.color.error) {
1428 dot.color = dot.color.hex;
1429 par[2] && (dot.offset = par[2] + "%");
1432 for (i = 1, ii = dots.length - 1; i < ii; i++) {
1433 if (!dots[i].offset) {
1434 var start = toFloat(dots[i - 1].offset || 0),
1436 for (var j = i + 1; j < ii; j++) {
1437 if (dots[j].offset) {
1438 end = dots[j].offset;
1447 var d = (end - start) / (j - i + 1);
1448 for (; i < j; i++) {
1450 dots[i].offset = start + "%";
1456 tear = R._tear = function (el, paper) {
1457 el == paper.top && (paper.top = el.prev);
1458 el == paper.bottom && (paper.bottom = el.next);
1459 el.next && (el.next.prev = el.prev);
1460 el.prev && (el.prev.next = el.next);
1462 tofront = R._tofront = function (el, paper) {
1463 if (paper.top === el) {
1468 el.prev = paper.top;
1469 paper.top.next = el;
1472 toback = R._toback = function (el, paper) {
1473 if (paper.bottom === el) {
1477 el.next = paper.bottom;
1479 paper.bottom.prev = el;
1482 insertafter = R._insertafter = function (el, el2, paper) {
1484 el2 == paper.top && (paper.top = el);
1485 el2.next && (el2.next.prev = el);
1490 insertbefore = R._insertbefore = function (el, el2, paper) {
1492 el2 == paper.bottom && (paper.bottom = el);
1493 el2.prev && (el2.prev.next = el);
1498 removed = function (methodname) {
1499 return function () {
1500 throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
1503 extractTransform = R._extractTransform = function (el, tstr) {
1505 return el._.transform;
1507 tstr = Str(tstr).replace(/\.{3}|\u2026/g, el._.transform || E);
1508 var tdata = R.parseTransformString(tstr),
1516 _.transform = tdata || [];
1518 for (var i = 0, ii = tdata.length; i < ii; i++) {
1522 t[0] = Str(t[0]).toLowerCase();
1523 if (t[0] == "t" && tlen == 3) {
1524 m.translate(t[1], t[2]);
1525 } else if (t[0] == "r") {
1527 bb = bb || el.getBBox(1);
1528 m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
1530 } else if (tlen == 4) {
1531 m.rotate(t[1], t[2], t[3]);
1534 } else if (t[0] == "s") {
1535 if (tlen == 2 || tlen == 3) {
1536 bb = bb || el.getBBox(1);
1537 m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
1540 } else if (tlen == 5) {
1541 m.scale(t[1], t[2], t[3], t[4]);
1545 } else if (t[0] == "m" && tlen == 7) {
1546 m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
1561 if (sx == 1 && sy == 1 && !deg && _.bbox) {
1568 getEmpty = function (item) {
1570 case "t": return ["t", 0, 0];
1571 case "m": return ["m", 1, 0, 0, 1, 0, 0];
1572 case "r": if (item.length == 4) {
1573 return ["r", 0, item[2], item[3]];
1577 case "s": if (item.length == 5) {
1578 return ["s", 1, 1, item[3], item[4]];
1579 } else if (item.length == 3) {
1586 equaliseTransform = R._equaliseTransform = function (t1, t2) {
1587 t2 = Str(t2).replace(/\.{3}|\u2026/g, t1);
1588 t1 = R.parseTransformString(t1) || [];
1589 t2 = R.parseTransformString(t2) || [];
1590 var maxlength = mmax(t1.length, t2.length),
1595 for (; i < maxlength; i++) {
1596 tt1 = t1[i] || getEmpty(t2[i]);
1597 tt2 = t2[i] || getEmpty(tt1);
1598 if ((tt1[0] != tt2[0]) ||
1599 (tt1[0] == "r" && (tt1[2] != tt2[2] || tt1[3] != tt2[3])) ||
1600 (tt1[0] == "s" && (tt1[3] != tt2[3] || tt1[4] != tt2[4]))
1606 for (j = 0, jj = mmax(tt1.length, tt2.length); j < jj; j++) {
1607 j in tt1 && (from[i][j] = tt1[j]);
1608 j in tt2 && (to[i][j] = tt2[j]);
1616 R._getContainer = function (x, y, w, h) {
1618 container = h == null && !R.is(x, "object") ? g.doc.getElementById(x) : x;
1619 if (container == null) {
1622 if (container.tagName) {
1625 container: container,
1626 width: container.style.pixelWidth || container.offsetWidth,
1627 height: container.style.pixelHeight || container.offsetHeight
1631 container: container,
1646 R.pathToRelative = pathToRelative;
1649 R.path2curve = path2curve;
1651 R.matrix = function (a, b, c, d, e, f) {
1652 return new Matrix(a, b, c, d, e, f);
1654 function Matrix(a, b, c, d, e, f) {
1671 (function (matrixproto) {
1673 matrixproto.add = function (a, b, c, d, e, f) {
1674 var out = [[], [], []],
1675 m = [[this.a, this.c, this.e], [this.b, this.d, this.f], [0, 0, 1]],
1676 matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
1679 if (a && a instanceof Matrix) {
1680 matrix = [[a.a, a.c, a.e], [a.b, a.d, a.f], [0, 0, 1]];
1683 for (x = 0; x < 3; x++) {
1684 for (y = 0; y < 3; y++) {
1686 for (z = 0; z < 3; z++) {
1687 res += m[x][z] * matrix[z][y];
1700 matrixproto.invert = function () {
1702 x = me.a * me.d - me.b * me.c;
1703 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);
1706 matrixproto.clone = function () {
1707 return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
1710 matrixproto.translate = function (x, y) {
1711 this.add(1, 0, 0, 1, x, y);
1714 matrixproto.scale = function (x, y, cx, cy) {
1715 y == null && (y = x);
1716 (cx || cy) && this.add(1, 0, 0, 1, cx, cy);
1717 this.add(x, 0, 0, y, 0, 0);
1718 (cx || cy) && this.add(1, 0, 0, 1, -cx, -cy);
1721 matrixproto.rotate = function (a, x, y) {
1725 var cos = +math.cos(a).toFixed(9),
1726 sin = +math.sin(a).toFixed(9);
1727 this.add(cos, sin, -sin, cos, x, y);
1728 this.add(1, 0, 0, 1, -x, -y);
1731 matrixproto.x = function (x, y) {
1732 return x * this.a + y * this.c + this.e;
1735 matrixproto.y = function (x, y) {
1736 return x * this.b + y * this.d + this.f;
1738 matrixproto.get = function (i) {
1739 return +this[Str.fromCharCode(97 + i)].toFixed(4);
1741 matrixproto.toString = function () {
1743 "matrix(" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)].join() + ")" :
1744 [this.get(0), this.get(2), this.get(1), this.get(3), 0, 0].join();
1746 matrixproto.toFilter = function () {
1747 return "progid:DXImageTransform.Microsoft.Matrix(M11=" + this.get(0) +
1748 ", M12=" + this.get(2) + ", M21=" + this.get(1) + ", M22=" + this.get(3) +
1749 ", Dx=" + this.get(4) + ", Dy=" + this.get(5) + ", sizingmethod='auto expand')";
1751 matrixproto.offset = function () {
1752 return [this.e.toFixed(4), this.f.toFixed(4)];
1755 return a[0] * a[0] + a[1] * a[1];
1757 function normalize(a) {
1758 var mag = math.sqrt(norm(a));
1759 a[0] && (a[0] /= mag);
1760 a[1] && (a[1] /= mag);
1763 matrixproto.split = function () {
1770 var row = [[this.a, this.c], [this.b, this.d]];
1771 out.scalex = math.sqrt(norm(row[0]));
1774 out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1];
1775 row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear];
1777 out.scaley = math.sqrt(norm(row[1]));
1779 out.shear /= out.scaley;
1782 var sin = -row[0][1],
1785 out.rotate = R.deg(math.acos(cos));
1787 out.rotate = 360 - out.rotate;
1790 out.rotate = R.deg(math.asin(sin));
1793 out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate);
1794 out.isSuperSimple = !+out.shear.toFixed(9) && out.scalex.toFixed(9) == out.scaley.toFixed(9) && !out.rotate;
1795 out.noRotation = !+out.shear.toFixed(9) && !out.rotate;
1799 matrixproto.toTransformString = function () {
1800 var s = this.split();
1802 return "t" + [s.dx, s.dy] + "s" + [s.scalex, s.scaley, 0, 0] + "r" + [s.rotate, 0, 0];
1804 return "m" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)];
1807 })(Matrix.prototype);
1809 // WebKit rendering bug workaround method
1810 var version = navigator.userAgent.match(/Version\/(.*?)\s/) || navigator.userAgent.match(/Chrome\/(\d+)/);
1811 if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP") ||
1812 (navigator.vendor == "Google Inc." && version && version[1] < 8)) {
1814 paperproto.safari = function () {
1815 var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
1816 setTimeout(function () {rect.remove();});
1819 paperproto.safari = fun;
1822 var preventDefault = function () {
1823 this.returnValue = false;
1825 preventTouch = function () {
1826 return this.originalEvent.preventDefault();
1828 stopPropagation = function () {
1829 this.cancelBubble = true;
1831 stopTouch = function () {
1832 return this.originalEvent.stopPropagation();
1834 addEvent = (function () {
1835 if (g.doc.addEventListener) {
1836 return function (obj, type, fn, element) {
1837 var realName = supportsTouch && touchMap[type] ? touchMap[type] : type,
1839 var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
1840 scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
1841 x = e.clientX + scrollX,
1842 y = e.clientY + scrollY;
1843 if (supportsTouch && touchMap[has](type)) {
1844 for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
1845 if (e.targetTouches[i].target == obj) {
1847 e = e.targetTouches[i];
1848 e.originalEvent = olde;
1849 e.preventDefault = preventTouch;
1850 e.stopPropagation = stopTouch;
1855 return fn.call(element, e, x, y);
1857 obj.addEventListener(realName, f, false);
1858 return function () {
1859 obj.removeEventListener(realName, f, false);
1863 } else if (g.doc.attachEvent) {
1864 return function (obj, type, fn, element) {
1865 var f = function (e) {
1866 e = e || g.win.event;
1867 var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
1868 scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
1869 x = e.clientX + scrollX,
1870 y = e.clientY + scrollY;
1871 e.preventDefault = e.preventDefault || preventDefault;
1872 e.stopPropagation = e.stopPropagation || stopPropagation;
1873 return fn.call(element, e, x, y);
1875 obj.attachEvent("on" + type, f);
1876 var detacher = function () {
1877 obj.detachEvent("on" + type, f);
1885 dragMove = function (e) {
1888 scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
1889 scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
1894 if (supportsTouch) {
1895 var i = e.touches.length,
1898 touch = e.touches[i];
1899 if (touch.identifier == dragi.el._drag.id) {
1902 (e.originalEvent ? e.originalEvent : e).preventDefault();
1909 var node = dragi.el.node,
1911 next = node.nextSibling,
1912 parent = node.parentNode,
1913 display = node.style.display;
1914 g.win.opera && parent.removeChild(node);
1915 node.style.display = "none";
1916 o = dragi.el.paper.getElementByPoint(x, y);
1917 node.style.display = display;
1918 g.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node));
1919 o && eve("drag.over." + dragi.el.id, dragi.el, o);
1922 eve("drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e);
1925 dragUp = function (e) {
1926 R.unmousemove(dragMove).unmouseup(dragUp);
1927 var i = drag.length,
1931 dragi.el._drag = {};
1932 eve("drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e);
1937 elproto = R.el = {};
1970 for (var i = events.length; i--;) {
1971 (function (eventName) {
1972 R[eventName] = elproto[eventName] = function (fn, scope) {
1973 if (R.is(fn, "function")) {
1974 this.events = this.events || [];
1975 this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || g.doc, eventName, fn, scope || this)});
1979 R["un" + eventName] = elproto["un" + eventName] = function (fn) {
1980 var events = this.events,
1982 while (l--) if (events[l].name == eventName && events[l].f == fn) {
1984 events.splice(l, 1);
1985 !events.length && delete this.events;
1994 elproto.data = function (key, value) {
1995 var data = eldata[this.id] = eldata[this.id] || {};
1996 if (arguments.length == 1) {
1997 if (R.is(key, "object")) {
1998 for (var i in key) if (key[has](i)) {
1999 this.data(i, key[i]);
2003 eve("data.get." + this.id, this, data[key], key);
2007 eve("data.set." + this.id, this, value, key);
2011 elproto.removeData = function (key) {
2013 eldata[this.id] = {};
2015 eldata[this.id] && delete eldata[this.id][key];
2020 elproto.hover = function (f_in, f_out, scope_in, scope_out) {
2021 return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in);
2024 elproto.unhover = function (f_in, f_out) {
2025 return this.unmouseover(f_in).unmouseout(f_out);
2028 elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) {
2030 (e.originalEvent || e).preventDefault();
2031 var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
2032 scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
2033 this._drag.x = e.clientX + scrollX;
2034 this._drag.y = e.clientY + scrollY;
2035 this._drag.id = e.identifier;
2036 !drag.length && R.mousemove(dragMove).mouseup(dragUp);
2037 drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
2038 onstart && eve.on("drag.start." + this.id, onstart);
2039 onmove && eve.on("drag.move." + this.id, onmove);
2040 onend && eve.on("drag.end." + this.id, onend);
2041 eve("drag.start." + this.id, start_scope || move_scope || this, e.clientX + scrollX, e.clientY + scrollY, e);
2044 this.mousedown(start);
2048 elproto.onDragOver = function (f) {
2049 f ? eve.on("drag.over." + this.id, f) : eve.unbind("drag.over." + this.id);
2052 elproto.undrag = function () {
2053 var i = drag.length;
2054 while (i--) if (drag[i].el == this) {
2055 R.unmousedown(drag[i].start);
2056 drag.splice(i++, 1);
2057 eve.unbind("drag.*." + this.id);
2059 !drag.length && R.unmousemove(dragMove).unmouseup(dragUp);
2062 paperproto.circle = function (x, y, r) {
2063 var out = R._engine.circle(this, x || 0, y || 0, r || 0);
2064 this.__set__ && this.__set__.push(out);
2068 paperproto.rect = function (x, y, w, h, r) {
2069 var out = R._engine.rect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
2070 this.__set__ && this.__set__.push(out);
2074 paperproto.ellipse = function (x, y, rx, ry) {
2075 var out = R._engine.ellipse(this, x || 0, y || 0, rx || 0, ry || 0);
2076 this.__set__ && this.__set__.push(out);
2080 paperproto.path = function (pathString) {
2081 pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
2082 var out = R._engine.path(R.format[apply](R, arguments), this);
2083 this.__set__ && this.__set__.push(out);
2087 paperproto.image = function (src, x, y, w, h) {
2088 var out = R._engine.image(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
2089 this.__set__ && this.__set__.push(out);
2093 paperproto.text = function (x, y, text) {
2094 var out = R._engine.text(this, x || 0, y || 0, Str(text));
2095 this.__set__ && this.__set__.push(out);
2099 paperproto.set = function (itemsArray) {
2100 !R.is(itemsArray, "array") && (itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length));
2101 var out = new Set(itemsArray);
2102 this.__set__ && this.__set__.push(out);
2106 paperproto.setStart = function (set) {
2107 this.__set__ = set || this.set();
2110 paperproto.setFinish = function (set) {
2111 var out = this.__set__;
2112 delete this.__set__;
2116 paperproto.setSize = function (width, height) {
2117 return R._engine.setSize.call(this, width, height);
2120 paperproto.setViewBox = function (x, y, w, h, fit) {
2121 return R._engine.setViewBox.call(this, x, y, w, h, fit);
2125 paperproto.top = paperproto.bottom = null;
2127 paperproto.raphael = R;
2128 var getOffset = function (elem) {
2129 var box = elem.getBoundingClientRect(),
2130 doc = elem.ownerDocument,
2132 docElem = doc.documentElement,
2133 clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
2134 top = box.top + (g.win.pageYOffset || docElem.scrollTop || body.scrollTop ) - clientTop,
2135 left = box.left + (g.win.pageXOffset || docElem.scrollLeft || body.scrollLeft) - clientLeft;
2142 paperproto.getElementByPoint = function (x, y) {
2145 target = g.doc.elementFromPoint(x, y);
2146 if (g.win.opera && target.tagName == "svg") {
2147 var so = getOffset(svg),
2148 sr = svg.createSVGRect();
2151 sr.width = sr.height = 1;
2152 var hits = svg.getIntersectionList(sr, null);
2154 target = hits[hits.length - 1];
2160 while (target.parentNode && target != svg.parentNode && !target.raphael) {
2161 target = target.parentNode;
2163 target == paper.canvas.parentNode && (target = svg);
2164 target = target && target.raphael ? paper.getById(target.raphaelid) : null;
2168 paperproto.getById = function (id) {
2169 var bot = this.bottom;
2179 paperproto.forEach = function (callback, thisArg) {
2180 var bot = this.bottom;
2182 if (callback.call(thisArg, bot) === false) {
2190 return this.x + S + this.y;
2192 function x_y_w_h() {
2193 return this.x + S + this.y + S + this.width + " \xd7 " + this.height;
2196 elproto.getBBox = function (isWithoutTransform) {
2201 if (isWithoutTransform) {
2202 if (_.dirty || !_.bboxwt) {
2203 this.realPath = getPath[this.type](this);
2204 _.bboxwt = pathDimensions(this.realPath);
2205 _.bboxwt.toString = x_y_w_h;
2210 if (_.dirty || _.dirtyT || !_.bbox) {
2211 if (_.dirty || !this.realPath) {
2213 this.realPath = getPath[this.type](this);
2215 _.bbox = pathDimensions(mapPath(this.realPath, this.matrix));
2216 _.bbox.toString = x_y_w_h;
2217 _.dirty = _.dirtyT = 0;
2222 elproto.clone = function () {
2226 return this.paper[this.type]().attr(this.attr());
2229 elproto.glow = function (glow) {
2230 if (this.type == "text") {
2235 width: (glow.width || 10) + (+this.attr("stroke-width") || 1),
2236 fill: glow.fill || false,
2237 opacity: glow.opacity || .5,
2238 offsetx: glow.offsetx || 0,
2239 offsety: glow.offsety || 0,
2240 color: glow.color || "#000"
2245 path = this.realPath || getPath[this.type](this);
2246 path = this.matrix ? mapPath(path, this.matrix) : path;
2247 for (var i = 1; i < c + 1; i++) {
2248 out.push(r.path(path).attr({
2250 fill: s.fill ? s.color : "none",
2251 "stroke-linejoin": "round",
2252 "stroke-linecap": "round",
2253 "stroke-width": +(s.width / c * i).toFixed(3),
2254 opacity: +(s.opacity / c).toFixed(3)
2257 return out.insertBefore(this).translate(s.offsetx, s.offsety);
2259 var curveslengths = {},
2260 getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
2263 name = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y].join(),
2264 cache = curveslengths[name],
2266 !cache && (curveslengths[name] = cache = {data: []});
2267 cache.timer && clearTimeout(cache.timer);
2268 cache.timer = setTimeout(function () {delete curveslengths[name];}, 2e3);
2269 if (length != null && !cache.precision) {
2270 var total = getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
2271 cache.precision = ~~total * 10;
2274 precision = cache.precision || precision;
2275 for (var i = 0; i < precision + 1; i++) {
2276 if (cache.data[i * precision]) {
2277 dot = cache.data[i * precision];
2279 dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i / precision);
2280 cache.data[i * precision] = dot;
2282 i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
2283 if (length != null && len >= length) {
2288 if (length == null) {
2292 getLengthFactory = function (istotal, subpath) {
2293 return function (path, length, onlystart) {
2294 path = path2curve(path);
2295 var x, y, p, l, sp = "", subpaths = {}, point,
2297 for (var i = 0, ii = path.length; i < ii; i++) {
2303 l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
2304 if (len + l > length) {
2305 if (subpath && !subpaths.start) {
2306 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
2307 sp += ["C" + point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
2308 if (onlystart) {return sp;}
2309 subpaths.start = sp;
2310 sp = ["M" + point.x, point.y + "C" + point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]].join();
2316 if (!istotal && !subpath) {
2317 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
2318 return {x: point.x, y: point.y, alpha: point.alpha};
2325 sp += p.shift() + p;
2328 point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
2329 point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
2333 var getTotalLength = getLengthFactory(1),
2334 getPointAtLength = getLengthFactory(),
2335 getSubpathsAtLength = getLengthFactory(0, 1);
2337 R.getTotalLength = getTotalLength;
2339 R.getPointAtLength = getPointAtLength;
2341 R.getSubpath = function (path, from, to) {
2342 if (abs(this.getTotalLength(path) - to) < 1e-6) {
2343 return getSubpathsAtLength(path, from).end;
2345 var a = getSubpathsAtLength(path, to, 1);
2346 return from ? getSubpathsAtLength(a, from).end : a;
2349 elproto.getTotalLength = function () {
2350 if (this.type != "path") {return;}
2351 if (this.node.getTotalLength) {
2352 return this.node.getTotalLength();
2354 return getTotalLength(this.attrs.path);
2357 elproto.getPointAtLength = function (length) {
2358 if (this.type != "path") {return;}
2359 return getPointAtLength(this.attrs.path, length);
2362 elproto.getSubpath = function (from, to) {
2363 if (this.type != "path") {return;}
2364 return R.getSubpath(this.attrs.path, from, to);
2367 var ef = R.easing_formulas = {
2368 linear: function (n) {
2377 "<>": function (n) {
2378 var q = .48 - n / 1.04,
2379 Q = math.sqrt(.1734 + q * q),
2381 X = pow(abs(x), 1 / 3) * (x < 0 ? -1 : 1),
2383 Y = pow(abs(y), 1 / 3) * (y < 0 ? -1 : 1),
2385 return (1 - t) * 3 * t * t + t * t * t;
2387 backIn: function (n) {
2389 return n * n * ((s + 1) * n - s);
2391 backOut: function (n) {
2394 return n * n * ((s + 1) * n + s) + 1;
2396 elastic: function (n) {
2400 return pow(2, -10 * n) * math.sin((n - .075) * (2 * PI) / .3) + 1;
2402 bounce: function (n) {
2411 l = s * n * n + .75;
2413 if (n < (2.5 / p)) {
2415 l = s * n * n + .9375;
2418 l = s * n * n + .984375;
2425 ef.easeIn = ef["ease-in"] = ef["<"];
2426 ef.easeOut = ef["ease-out"] = ef[">"];
2427 ef.easeInOut = ef["ease-in-out"] = ef["<>"];
2428 ef["back-in"] = ef.backIn;
2429 ef["back-out"] = ef.backOut;
2431 var animationElements = [],
2432 requestAnimFrame = window.requestAnimationFrame ||
2433 window.webkitRequestAnimationFrame ||
2434 window.mozRequestAnimationFrame ||
2435 window.oRequestAnimationFrame ||
2436 window.msRequestAnimationFrame ||
2437 function (callback) {
2438 setTimeout(callback, 16);
2440 animation = function () {
2441 var Now = +new Date,
2443 for (; l < animationElements.length; l++) {
2444 var e = animationElements[l];
2445 if (e.el.removed || e.paused) {
2448 var time = Now - e.start,
2459 time = (e.initstatus * e.anim.top - e.prev) / (e.percent - e.prev) * ms;
2460 e.status = e.initstatus;
2461 delete e.initstatus;
2462 e.stop && animationElements.splice(l--, 1);
2464 e.status = (e.prev + (e.percent - e.prev) * (time / ms)) / e.anim.top;
2470 var pos = easing(time / ms);
2471 for (var attr in from) if (from[has](attr)) {
2472 switch (availableAnimAttrs[attr]) {
2474 now = +from[attr] + pos * ms * diff[attr];
2478 upto255(round(from[attr].r + pos * ms * diff[attr].r)),
2479 upto255(round(from[attr].g + pos * ms * diff[attr].g)),
2480 upto255(round(from[attr].b + pos * ms * diff[attr].b))
2485 for (var i = 0, ii = from[attr].length; i < ii; i++) {
2486 now[i] = [from[attr][i][0]];
2487 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2488 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
2490 now[i] = now[i].join(S);
2495 if (diff[attr].real) {
2497 for (i = 0, ii = from[attr].length; i < ii; i++) {
2498 now[i] = [from[attr][i][0]];
2499 for (j = 1, jj = from[attr][i].length; j < jj; j++) {
2500 now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
2504 var get = function (i) {
2505 return +from[attr][i] + pos * ms * diff[attr][i];
2507 // now = [["r", get(2), 0, 0], ["t", get(3), get(4)], ["s", get(0), get(1), 0, 0]];
2508 now = [["m", get(0), get(1), get(2), get(3), get(4), get(5)]];
2512 if (attr == "clip-rect") {
2516 now[i] = +from[attr][i] + pos * ms * diff[attr][i];
2521 var from2 = [].concat(from[attr]);
2523 i = that.paper.customAttributes[attr].length;
2525 now[i] = +from2[i] + pos * ms * diff[attr][i];
2532 (function (id, that, anim) {
2533 setTimeout(function () {
2534 eve("anim.frame." + id, that, anim);
2536 })(that.id, that, e.anim);
2538 (function(f, el, a) {
2539 setTimeout(function() {
2540 eve("anim.frame." + el.id, el, a);
2541 eve("anim.finish." + el.id, el, a);
2542 R.is(f, "function") && f.call(el);
2544 })(e.callback, that, e.anim);
2546 animationElements.splice(l--, 1);
2547 if (e.repeat > 1 && !e.next) {
2548 runAnimation(e.anim, e.el, e.anim.percents[0], null, e.totalOrigin, e.repeat - 1);
2550 if (e.next && !e.stop) {
2551 runAnimation(e.anim, e.el, e.next, null, e.totalOrigin, e.repeat);
2555 R.svg && that && that.paper && that.paper.safari();
2556 animationElements.length && requestAnimFrame(animation);
2558 upto255 = function (color) {
2559 return color > 255 ? 255 : color < 0 ? 0 : color;
2562 elproto.animateWith = function (element, anim, params, ms, easing, callback) {
2563 var a = params ? R.animation(params, ms, easing, callback) : anim;
2564 status = element.status(anim);
2565 return this.animate(a).status(a, status * anim.ms / a.ms);
2567 function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
2569 bx = 3 * (p2x - p1x) - cx,
2572 by = 3 * (p2y - p1y) - cy,
2574 function sampleCurveX(t) {
2575 return ((ax * t + bx) * t + cx) * t;
2577 function solve(x, epsilon) {
2578 var t = solveCurveX(x, epsilon);
2579 return ((ay * t + by) * t + cy) * t;
2581 function solveCurveX(x, epsilon) {
2582 var t0, t1, t2, x2, d2, i;
2583 for(t2 = x, i = 0; i < 8; i++) {
2584 x2 = sampleCurveX(t2) - x;
2585 if (abs(x2) < epsilon) {
2588 d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
2589 if (abs(d2) < 1e-6) {
2604 x2 = sampleCurveX(t2);
2605 if (abs(x2 - x) < epsilon) {
2613 t2 = (t1 - t0) / 2 + t0;
2617 return solve(t, 1 / (200 * duration));
2619 elproto.onAnimation = function (f) {
2620 f ? eve.on("anim.frame." + this.id, f) : eve.unbind("anim.frame." + this.id);
2623 function Animation(anim, ms) {
2629 for (var attr in this.anim) if (this.anim[has](attr)) {
2630 percents.push(+attr);
2632 percents.sort(sortByNumber);
2634 this.top = percents[percents.length - 1];
2635 this.percents = percents;
2638 Animation.prototype.delay = function (delay) {
2639 var a = new Animation(this.anim, this.ms);
2640 a.times = this.times;
2641 a.del = +delay || 0;
2645 Animation.prototype.repeat = function (times) {
2646 var a = new Animation(this.anim, this.ms);
2648 a.times = math.floor(mmax(times, 0)) || 1;
2651 function runAnimation(anim, element, percent, status, totalOrigin, times) {
2652 percent = toFloat(percent);
2665 for (i = 0, ii = animationElements.length; i < ii; i++) {
2666 var e = animationElements[i];
2667 if (e.el.id == element.id && e.anim == anim) {
2668 if (e.percent != percent) {
2669 animationElements.splice(i, 1);
2674 element.attr(e.totalOrigin);
2679 status = +to; // NaN
2681 for (var i = 0, ii = anim.percents.length; i < ii; i++) {
2682 if (anim.percents[i] == percent || anim.percents[i] > status * anim.top) {
2683 percent = anim.percents[i];
2684 prev = anim.percents[i - 1] || 0;
2685 ms = ms / anim.top * (percent - prev);
2686 next = anim.percents[i + 1];
2687 params = anim.anim[percent];
2689 } else if (status) {
2690 element.attr(anim.anim[anim.percents[i]]);
2697 for (attr in params) if (params[has](attr)) {
2698 if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
2699 from[attr] = element.attr(attr);
2700 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
2701 to[attr] = params[attr];
2702 switch (availableAnimAttrs[attr]) {
2704 diff[attr] = (to[attr] - from[attr]) / ms;
2707 from[attr] = R.getRGB(from[attr]);
2708 var toColour = R.getRGB(to[attr]);
2710 r: (toColour.r - from[attr].r) / ms,
2711 g: (toColour.g - from[attr].g) / ms,
2712 b: (toColour.b - from[attr].b) / ms
2716 var pathes = path2curve(from[attr], to[attr]),
2718 from[attr] = pathes[0];
2720 for (i = 0, ii = from[attr].length; i < ii; i++) {
2721 diff[attr][i] = [0];
2722 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
2723 diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
2729 eq = equaliseTransform(_[attr], to[attr]);
2731 from[attr] = eq.from;
2734 diff[attr].real = true;
2735 for (i = 0, ii = from[attr].length; i < ii; i++) {
2736 diff[attr][i] = [from[attr][i][0]];
2737 for (j = 1, jj = from[attr][i].length; j < jj; j++) {
2738 diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
2742 var m = (element.matrix || new Matrix),
2744 _: {transform: _.transform},
2745 getBBox: function () {
2746 return element.getBBox(1);
2757 extractTransform(to2, to[attr]);
2758 to[attr] = to2._.transform;
2760 (to2.matrix.a - m.a) / ms,
2761 (to2.matrix.b - m.b) / ms,
2762 (to2.matrix.c - m.c) / ms,
2763 (to2.matrix.d - m.d) / ms,
2764 (to2.matrix.e - m.e) / ms,
2765 (to2.matrix.e - m.f) / ms
2767 // from[attr] = [_.sx, _.sy, _.deg, _.dx, _.dy];
2768 // var to2 = {_:{}, getBBox: function () { return element.getBBox(); }};
2769 // extractTransform(to2, to[attr]);
2771 // (to2._.sx - _.sx) / ms,
2772 // (to2._.sy - _.sy) / ms,
2773 // (to2._.deg - _.deg) / ms,
2774 // (to2._.dx - _.dx) / ms,
2775 // (to2._.dy - _.dy) / ms
2780 var values = Str(params[attr]).split(separator),
2781 from2 = Str(from[attr]).split(separator);
2782 if (attr == "clip-rect") {
2787 diff[attr][i] = (values[i] - from[attr][i]) / ms;
2793 values = [].concat(params[attr]);
2794 from2 = [].concat(from[attr]);
2796 i = element.paper.customAttributes[attr].length;
2798 diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
2804 var easing = params.easing,
2805 easyeasy = R.easing_formulas[easing];
2807 easyeasy = Str(easing).match(bezierrg);
2808 if (easyeasy && easyeasy.length == 5) {
2809 var curve = easyeasy;
2810 easyeasy = function (t) {
2811 return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
2817 timestamp = params.start || anim.start || +new Date;
2821 timestamp: timestamp,
2822 start: timestamp + (anim.del || 0),
2824 initstatus: status || 0,
2832 callback: params.callback,
2835 repeat: times || anim.times,
2836 origin: element.attr(),
2837 totalOrigin: totalOrigin
2839 animationElements.push(e);
2840 if (status && !isInAnim && !isInAnimSet) {
2842 e.start = new Date - ms * status;
2843 if (animationElements.length == 1) {
2848 e.start = new Date - e.ms * status;
2850 animationElements.length == 1 && requestAnimFrame(animation);
2852 isInAnim.initstatus = status;
2853 isInAnim.start = new Date - isInAnim.ms * status;
2855 eve("anim.start." + element.id, element, anim);
2858 R.animation = function (params, ms, easing, callback) {
2859 if (params instanceof Animation) {
2862 if (R.is(easing, "function") || !easing) {
2863 callback = callback || easing || null;
2866 params = Object(params);
2871 for (attr in params) if (params[has](attr) && toFloat(attr) != attr) {
2873 p[attr] = params[attr];
2876 return new Animation(params, ms);
2878 easing && (p.easing = easing);
2879 callback && (p.callback = callback);
2880 return new Animation({100: p}, ms);
2884 elproto.animate = function (params, ms, easing, callback) {
2886 if (element.removed) {
2887 callback && callback.call(element);
2890 var anim = params instanceof Animation ? params : R.animation(params, ms, easing, callback);
2891 runAnimation(anim, element, anim.percents[0], null, element.attr());
2895 elproto.setTime = function (anim, value) {
2896 if (anim && value != null) {
2897 this.status(anim, mmin(value, anim.ms) / anim.ms);
2902 elproto.status = function (anim, value) {
2907 if (value != null) {
2908 runAnimation(anim, this, -1, mmin(value, 1));
2911 len = animationElements.length;
2912 for (; i < len; i++) {
2913 e = animationElements[i];
2914 if (e.el.id == this.id && (!anim || e.anim == anim)) {
2931 elproto.pause = function (anim) {
2932 for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
2933 if (eve("anim.pause." + this.id, this, animationElements[i].anim) !== false) {
2934 animationElements[i].paused = true;
2940 elproto.resume = function (anim) {
2941 for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
2942 var e = animationElements[i];
2943 if (eve("anim.resume." + this.id, this, e.anim) !== false) {
2945 this.status(e.anim, e.status);
2951 elproto.stop = function (anim) {
2952 for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
2953 if (eve("anim.stop." + this.id, this, animationElements[i].anim) !== false) {
2954 animationElements.splice(i--, 1);
2959 elproto.toString = function () {
2960 return "Rapha\xebl\u2019s object";
2964 var Set = function (items) {
2969 for (var i = 0, ii = items.length; i < ii; i++) {
2970 if (items[i] && (items[i].constructor == elproto.constructor || items[i].constructor == Set)) {
2971 this[this.items.length] = this.items[this.items.length] = items[i];
2977 setproto = Set.prototype;
2979 setproto.push = function () {
2982 for (var i = 0, ii = arguments.length; i < ii; i++) {
2983 item = arguments[i];
2984 if (item && (item.constructor == elproto.constructor || item.constructor == Set)) {
2985 len = this.items.length;
2986 this[len] = this.items[len] = item;
2993 setproto.pop = function () {
2994 this.length && delete this[this.length--];
2995 return this.items.pop();
2998 setproto.forEach = function (callback, thisArg) {
2999 for (var i = 0, ii = this.items.length; i < ii; i++) {
3000 if (callback.call(thisArg, this.items[i]) === false) {
3006 for (var method in elproto) if (elproto[has](method)) {
3007 setproto[method] = (function (methodname) {
3008 return function () {
3009 var arg = arguments;
3010 return this.forEach(function (el) {
3011 el[methodname][apply](el, arg);
3016 setproto.attr = function (name, value) {
3017 if (name && R.is(name, array) && R.is(name[0], "object")) {
3018 for (var j = 0, jj = name.length; j < jj; j++) {
3019 this.items[j].attr(name[j]);
3022 for (var i = 0, ii = this.items.length; i < ii; i++) {
3023 this.items[i].attr(name, value);
3029 setproto.clear = function () {
3030 while (this.length) {
3035 setproto.splice = function (index, count, insertion) {
3036 index = index < 0 ? mmax(this.length + index, 0) : index;
3037 count = mmax(0, mmin(this.length - index, count));
3042 for (i = 2; i < arguments.length; i++) {
3043 args.push(arguments[i]);
3045 for (i = 0; i < count; i++) {
3046 todel.push(this[index + i]);
3048 for (; i < this.length - index; i++) {
3049 tail.push(this[index + i]);
3051 var arglen = args.length;
3052 for (i = 0; i < arglen + tail.length; i++) {
3053 this.items[index + i] = this[index + i] = i < arglen ? args[i] : tail[i - arglen];
3055 i = this.items.length = this.length -= count - arglen;
3059 return new Set(todel);
3062 setproto.exclude = function (el) {
3063 for (var i = 0, ii = this.length, found; i < ii; i++) if (found || this[i] == el) {
3064 this[i] = this[i + 1];
3073 setproto.animate = function (params, ms, easing, callback) {
3074 (R.is(easing, "function") || !easing) && (callback = easing || null);
3075 var len = this.items.length,
3083 callback && (collector = function () {
3084 !--len && callback.call(set);
3086 easing = R.is(easing, string) ? easing : collector;
3087 var anim = R.animation(params, ms, easing, collector);
3088 item = this.items[--i].animate(anim);
3090 this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, anim);
3094 setproto.insertAfter = function (el) {
3095 var i = this.items.length;
3097 this.items[i].insertAfter(el);
3101 setproto.getBBox = function () {
3106 for (var i = this.items.length; i--;) if (!this.items[i].removed) {
3107 var box = this.items[i].getBBox();
3110 w.push(box.x + box.width);
3111 h.push(box.y + box.height);
3113 x = mmin[apply](0, x);
3114 y = mmin[apply](0, y);
3118 width: mmax[apply](0, w) - x,
3119 height: mmax[apply](0, h) - y
3122 setproto.clone = function (s) {
3124 for (var i = 0, ii = this.items.length; i < ii; i++) {
3125 s.push(this.items[i].clone());
3129 setproto.toString = function () {
3130 return "Rapha\xebl\u2018s set";
3134 R.registerFont = function (font) {
3138 this.fonts = this.fonts || {};
3144 family = font.face["font-family"];
3145 for (var prop in font.face) if (font.face[has](prop)) {
3146 fontcopy.face[prop] = font.face[prop];
3148 if (this.fonts[family]) {
3149 this.fonts[family].push(fontcopy);
3151 this.fonts[family] = [fontcopy];
3154 fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
3155 for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
3156 var path = font.glyphs[glyph];
3157 fontcopy.glyphs[glyph] = {
3160 d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
3161 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
3165 for (var k in path.k) if (path[has](k)) {
3166 fontcopy.glyphs[glyph].k[k] = path.k[k];
3174 paperproto.getFont = function (family, weight, style, stretch) {
3175 stretch = stretch || "normal";
3176 style = style || "normal";
3177 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
3181 var font = R.fonts[family];
3183 var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
3184 for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
3185 if (name.test(fontName)) {
3186 font = R.fonts[fontName];
3193 for (var i = 0, ii = font.length; i < ii; i++) {
3195 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
3203 paperproto.print = function (x, y, string, font, size, origin, letter_spacing) {
3204 origin = origin || "middle"; // baseline|middle
3205 letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
3206 var out = this.set(),
3207 letters = Str(string).split(E),
3211 R.is(font, string) && (font = this.getFont(font));
3213 scale = (size || 16) / font.face["units-per-em"];
3214 var bb = font.face.bbox.split(separator),
3216 height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
3217 for (var i = 0, ii = letters.length; i < ii; i++) {
3218 var prev = i && font.glyphs[letters[i - 1]] || {},
3219 curr = font.glyphs[letters[i]];
3220 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
3221 curr && curr.d && out.push(this.path(curr.d).attr({
3224 transform: [["t", shift * scale, 0]]
3227 out.transform(["...s", scale, scale, top, height, "t", (x - top) / scale, (y - height) / scale]);
3233 R.format = function (token, params) {
3234 var args = R.is(params, array) ? [0][concat](params) : arguments;
3235 token && R.is(token, string) && args.length - 1 && (token = token.replace(formatrg, function (str, i) {
3236 return args[++i] == null ? E : args[i];
3241 R.fullfill = (function () {
3242 var tokenRegex = /\{([^\}]+)\}/g,
3243 objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g, // matches .xxxxx or ["xxxxx"] to run over object properties
3244 replacer = function (all, key, obj) {
3246 key.replace(objNotationRegex, function (all, name, quote, quotedName, isFunc) {
3247 name = name || quotedName;
3252 typeof res == "function" && isFunc && (res = res());
3255 res = (res == null || res == obj ? all : res) + "";
3258 return function (str, obj) {
3259 return String(str).replace(tokenRegex, function (all, key) {
3260 return replacer(all, key, obj);
3265 R.ninja = function () {
3266 oldRaphael.was ? (g.win.Raphael = oldRaphael.is) : delete Raphael;
3271 // Firefox <3.6 fix: http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
3272 (function (doc, loaded, f) {
3273 if (doc.readyState == null && doc.addEventListener){
3274 doc.addEventListener(loaded, f = function () {
3275 doc.removeEventListener(loaded, f, false);
3276 doc.readyState = "complete";
3278 doc.readyState = "loading";
3280 function isLoaded() {
3281 (/in/).test(doc.readyState) ? setTimeout(isLoaded, 9) : R.eve("DOMload");
3284 })(document, "DOMContentLoaded");
3286 oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
3288 eve.on("DOMload", function () {
3293 // ┌─────────────────────────────────────────────────────────────────────┐ \\
3294 // │ Raphaël 2 - JavaScript Vector Library │ \\
3295 // ├─────────────────────────────────────────────────────────────────────┤ \\
3296 // │ SVG Module │ \\
3297 // ├─────────────────────────────────────────────────────────────────────┤ \\
3298 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
3299 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
3300 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
3301 // └─────────────────────────────────────────────────────────────────────┘ \\
3302 window.Raphael.svg && function (R) {
3303 var has = "hasOwnProperty",
3305 toFloat = parseFloat,
3311 separator = /[, ]+/,
3315 var xlink = "http://www.w3.org/1999/xlink",
3317 block: "M5,0 0,2.5 5,5z",
3318 classic: "M5,0 0,2.5 5,5 3.5,3 3.5,2z",
3319 diamond: "M2.5,0 5,2.5 2.5,5 0,2.5z",
3320 open: "M6,1 1,3.5 6,6",
3321 oval: "M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"
3324 R.toString = function () {
3325 return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
3327 var $ = function (el, attr) {
3329 if (typeof el == "string") {
3332 for (var key in attr) if (attr[has](key)) {
3333 if (key.substring(0, 6) == "xlink:") {
3334 el.setAttributeNS(xlink, key.substring(6), Str(attr[key]));
3336 el.setAttribute(key, Str(attr[key]));
3340 el = R._g.doc.createElementNS("http://www.w3.org/2000/svg", el);
3341 el.style && (el.style.webkitTapHighlightColor = "rgba(0,0,0,0)");
3346 rgGrad = /^url\(#(.*)\)$/,
3347 removeGradientFill = function (node, paper) {
3348 var oid = node.getAttribute("fill");
3349 oid = oid && oid.match(rgGrad);
3350 if (oid && !--gradients[oid[1]]) {
3351 delete gradients[oid[1]];
3352 paper.defs.removeChild(R._g.doc.getElementById(oid[1]));
3355 addGradientFill = function (element, gradient) {
3356 var type = "linear",
3357 id = element.id + gradient,
3360 SVG = element.paper,
3362 el = R._g.doc.getElementById(id);
3364 gradient = Str(gradient).replace(R._radial_gradient, function (all, _fx, _fy) {
3369 var dir = ((fy > .5) * 2 - 1);
3370 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
3371 (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
3373 (fy = fy.toFixed(5) - 1e-5 * dir);
3377 gradient = gradient.split(/\s*\-\s*/);
3378 if (type == "linear") {
3379 var angle = gradient.shift();
3380 angle = -toFloat(angle);
3384 var vector = [0, 0, math.cos(R.rad(angle)), math.sin(R.rad(angle))],
3385 max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
3388 if (vector[2] < 0) {
3389 vector[0] = -vector[2];
3392 if (vector[3] < 0) {
3393 vector[1] = -vector[3];
3397 var dots = R._parseDots(gradient);
3401 if (element.gradient) {
3402 SVG.defs.removeChild(element.gradient);
3403 delete element.gradient;
3406 id = id.replace(/[\(\)\s,\xb0#]/g, "-");
3407 el = $(type + "Gradient", {id: id});
3408 element.gradient = el;
3409 $(el, type == "radial" ? {
3417 gradientTransform: element.matrix.invert()
3419 SVG.defs.appendChild(el);
3420 for (var i = 0, ii = dots.length; i < ii; i++) {
3421 el.appendChild($("stop", {
3422 offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%",
3423 "stop-color": dots[i].color || "#fff"
3428 fill: "url(#" + id + ")",
3437 updatePosition = function (o) {
3438 var bbox = o.getBBox(1);
3439 $(o.pattern, {patternTransform: o.matrix.invert() + " translate(" + bbox.x + "," + bbox.y + ")"});
3441 addArrow = function (o, value, isEnd) {
3442 if (o.type == "path") {
3443 var values = Str(value).toLowerCase().split("-"),
3445 se = isEnd ? "end" : "start",
3448 stroke = attrs["stroke-width"],
3460 switch (values[i]) {
3469 case "wide": h = 5; break;
3470 case "narrow": h = 2; break;
3471 case "long": w = 5; break;
3472 case "short": w = 2; break;
3475 if (type == "open") {
3480 refX = isEnd ? 4 : 1;
3483 stroke: attrs.stroke
3494 o._.arrows.endPath && markerCounter[o._.arrows.endPath]--;
3495 o._.arrows.endMarker && markerCounter[o._.arrows.endMarker]--;
3497 o._.arrows.startPath && markerCounter[o._.arrows.startPath]--;
3498 o._.arrows.startMarker && markerCounter[o._.arrows.startMarker]--;
3503 if (type != "none") {
3504 var pathId = "raphael-marker-" + type,
3505 markerId = "raphael-marker-" + se + type + w + h;
3506 if (!R._g.doc.getElementById(pathId)) {
3507 p.defs.appendChild($($("path"), {
3508 "stroke-linecap": "round",
3512 markerCounter[pathId] = 1;
3514 markerCounter[pathId]++;
3516 var marker = R._g.doc.getElementById(markerId),
3519 marker = $($("marker"), {
3528 "xlink:href": "#" + pathId,
3529 transform: (isEnd ? " rotate(180 " + w / 2 + " " + h / 2 + ") " : S) + "scale(" + w / t + "," + h / t + ")",
3530 "stroke-width": 1 / ((w / t + h / t) / 2)
3532 marker.appendChild(use);
3533 p.defs.appendChild(marker);
3534 markerCounter[markerId] = 1;
3536 markerCounter[markerId]++;
3537 use = marker.getElementsByTagName("use")[0];
3540 var delta = dx * (type != "diamond" && type != "oval");
3542 from = o._.arrows.startdx * stroke || 0;
3543 to = R.getTotalLength(attrs.path) - delta * stroke;
3545 from = delta * stroke;
3546 to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
3549 attr["marker-" + se] = "url(#" + markerId + ")";
3551 attr.d = Raphael.getSubpath(attrs.path, from, to);
3554 o._.arrows[se + "Path"] = pathId;
3555 o._.arrows[se + "Marker"] = markerId;
3556 o._.arrows[se + "dx"] = delta;
3557 o._.arrows[se + "Type"] = type;
3558 o._.arrows[se + "String"] = value;
3561 from = o._.arrows.startdx * stroke || 0;
3562 to = R.getTotalLength(attrs.path) - from;
3565 to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
3567 o._.arrows[se + "Path"] && $(node, {d: Raphael.getSubpath(attrs.path, from, to)});
3568 delete o._.arrows[se + "Path"];
3569 delete o._.arrows[se + "Marker"];
3570 delete o._.arrows[se + "dx"];
3571 delete o._.arrows[se + "Type"];
3572 delete o._.arrows[se + "String"];
3574 for (attr in markerCounter) if (markerCounter[has](attr) && !markerCounter[attr]) {
3575 var item = R._g.doc.getElementById(attr);
3576 item && item.parentNode.removeChild(item);
3586 "-..": [3, 1, 1, 1, 1, 1],
3590 "- .": [4, 3, 1, 3],
3591 "--.": [8, 3, 1, 3],
3592 "--..": [8, 3, 1, 3, 1, 3]
3594 addDashes = function (o, value, params) {
3595 value = dasharray[Str(value).toLowerCase()];
3597 var width = o.attrs["stroke-width"] || "1",
3598 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
3602 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
3604 $(o.node, {"stroke-dasharray": dashes.join(",")});
3607 setFillAndStroke = function (o, params) {
3610 vis = node.style.visibility;
3611 node.style.visibility = "hidden";
3612 for (var att in params) {
3613 if (params[has](att)) {
3614 if (!R._availableAttrs[has](att)) {
3617 var value = params[att];
3626 var pn = node.parentNode;
3627 if (pn.tagName.toLowerCase() != "a") {
3629 pn.insertBefore(hl, node);
3630 hl.appendChild(node);
3633 if (att == "target" && value == "blank") {
3634 pn.setAttributeNS(xlink, "show", "new");
3636 pn.setAttributeNS(xlink, att, value);
3640 node.style.cursor = value;
3649 addArrow(o, value, 1);
3652 var rect = Str(value).split(separator);
3653 if (rect.length == 4) {
3654 o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
3655 var el = $("clipPath"),
3657 el.id = R._createUUID();
3665 o.paper.defs.appendChild(el);
3666 $(node, {"clip-path": "url(#" + el.id + ")"});
3670 var clip = R._g.doc.getElementById(node.getAttribute("clip-path").replace(/(^url\(#|\)$)/g, E));
3671 clip && clip.parentNode.removeChild(clip);
3672 $(node, {"clip-path": E});
3677 if (o.type == "path") {
3678 $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"});
3681 "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
3682 "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
3687 node.setAttribute(att, value);
3697 value = -attrs.x - (attrs.width || 0);
3700 if (att == "rx" && o.type == "rect") {
3704 node.setAttribute(att, value);
3705 o.pattern && updatePosition(o);
3709 node.setAttribute(att, value);
3719 value = -attrs.y - (attrs.height || 0);
3722 if (att == "ry" && o.type == "rect") {
3726 node.setAttribute(att, value);
3727 o.pattern && updatePosition(o);
3731 if (o.type == "rect") {
3732 $(node, {rx: value, ry: value});
3734 node.setAttribute(att, value);
3739 if (o.type == "image") {
3740 node.setAttributeNS(xlink, "href", value);
3743 case "stroke-width":
3744 if (o._.sx != 1 || o._.sy != 1) {
3745 value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
3747 if (o.paper._vbSize) {
3748 value *= o.paper._vbSize;
3750 node.setAttribute(att, value);
3751 if (attrs["stroke-dasharray"]) {
3752 addDashes(o, attrs["stroke-dasharray"], params);
3755 "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
3756 "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
3759 case "stroke-dasharray":
3760 addDashes(o, value, params);
3763 var isURL = Str(value).match(R._ISURL);
3766 var ig = $("image");
3767 el.id = R._createUUID();
3768 $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
3769 $(ig, {x: 0, y: 0, "xlink:href": isURL[1]});
3773 R._preload(isURL[1], function () {
3774 var w = this.offsetWidth,
3775 h = this.offsetHeight;
3776 $(el, {width: w, height: h});
3777 $(ig, {width: w, height: h});
3781 o.paper.defs.appendChild(el);
3782 node.style.fill = "url(#" + el.id + ")";
3783 $(node, {fill: "url(#" + el.id + ")"});
3785 o.pattern && updatePosition(o);
3788 var clr = R.getRGB(value);
3790 delete params.gradient;
3791 delete attrs.gradient;
3792 !R.is(attrs.opacity, "undefined") &&
3793 R.is(params.opacity, "undefined") &&
3794 $(node, {opacity: attrs.opacity});
3795 !R.is(attrs["fill-opacity"], "undefined") &&
3796 R.is(params["fill-opacity"], "undefined") &&
3797 $(node, {"fill-opacity": attrs["fill-opacity"]});
3798 } else if ((o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value)) {
3799 if ("opacity" in attrs || "fill-opacity" in attrs) {
3800 var gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
3802 var stops = gradient.getElementsByTagName("stop");
3803 $(stops[stops.length - 1], {"stop-opacity": ("opacity" in attrs ? attrs.opacity : 1) * ("fill-opacity" in attrs ? attrs["fill-opacity"] : 1)});
3806 attrs.gradient = value;
3807 attrs.fill = "none";
3810 clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
3812 clr = R.getRGB(value);
3813 node.setAttribute(att, clr.hex);
3814 att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
3815 if (att == "stroke" && o._.arrows) {
3816 "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
3817 "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
3821 (o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value);
3824 if (attrs.gradient && !attrs[has]("stroke-opacity")) {
3825 $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
3828 case "fill-opacity":
3829 if (attrs.gradient) {
3830 gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
3832 stops = gradient.getElementsByTagName("stop");
3833 $(stops[stops.length - 1], {"stop-opacity": value});
3838 att == "font-size" && (value = toInt(value, 10) + "px");
3839 var cssrule = att.replace(/(\-.)/g, function (w) {
3840 return w.substring(1).toUpperCase();
3842 node.style[cssrule] = value;
3844 node.setAttribute(att, value);
3850 tuneText(o, params);
3851 node.style.visibility = vis;
3854 tuneText = function (el, params) {
3855 if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
3860 fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
3862 if (params[has]("text")) {
3863 a.text = params.text;
3864 while (node.firstChild) {
3865 node.removeChild(node.firstChild);
3867 var texts = Str(params.text).split("\n"),
3870 for (var i = 0, ii = texts.length; i < ii; i++) {
3872 i && $(tspan, {dy: fontSize * leading, x: a.x});
3873 tspan.appendChild(R._g.doc.createTextNode(texts[i]));
3874 node.appendChild(tspan);
3878 tspans = node.getElementsByTagName("tspan");
3879 for (i = 0, ii = tspans.length; i < ii; i++) if (i) {
3880 $(tspans[i], {dy: fontSize * leading, x: a.x});
3882 $(tspans[0], {dy: 0});
3885 $(node, {x: a.x, y: a.y});
3887 var bb = el._getBBox(),
3888 dif = a.y - (bb.y + bb.height / 2);
3889 dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
3891 Element = function (node, svg) {
3895 this[0] = this.node = node;
3897 node.raphael = true;
3900 node.raphaelid = this.id;
3901 this.matrix = R.matrix();
3902 this.realPath = null;
3905 this.attrs = this.attrs || {};
3915 !svg.bottom && (svg.bottom = this);
3917 this.prev = svg.top;
3918 svg.top && (svg.top.next = this);
3925 Element.prototype = elproto;
3926 elproto.constructor = Element;
3928 R._engine.path = function (pathString, SVG) {
3930 SVG.canvas && SVG.canvas.appendChild(el);
3931 var p = new Element(el, SVG);
3933 setFillAndStroke(p, {
3941 elproto.rotate = function (deg, cx, cy) {
3945 deg = Str(deg).split(separator);
3946 if (deg.length - 1) {
3947 cx = toFloat(deg[1]);
3948 cy = toFloat(deg[2]);
3950 deg = toFloat(deg[0]);
3951 (cy == null) && (cx = cy);
3952 if (cx == null || cy == null) {
3953 var bbox = this.getBBox(1);
3954 cx = bbox.x + bbox.width / 2;
3955 cy = bbox.y + bbox.height / 2;
3957 this.transform(this._.transform.concat([["r", deg, cx, cy]]));
3961 elproto.scale = function (sx, sy, cx, cy) {
3965 sx = Str(sx).split(separator);
3966 if (sx.length - 1) {
3967 sy = toFloat(sx[1]);
3968 cx = toFloat(sx[2]);
3969 cy = toFloat(sx[3]);
3971 sx = toFloat(sx[0]);
3972 (sy == null) && (sy = sx);
3973 (cy == null) && (cx = cy);
3974 if (cx == null || cy == null) {
3975 var bbox = this.getBBox(1);
3977 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
3978 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
3979 this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
3983 elproto.translate = function (dx, dy) {
3987 dx = Str(dx).split(separator);
3988 if (dx.length - 1) {
3989 dy = toFloat(dx[1]);
3991 dx = toFloat(dx[0]) || 0;
3993 this.transform(this._.transform.concat([["t", dx, dy]]));
3997 elproto.transform = function (tstr) {
4002 R._extractTransform(this, tstr);
4004 this.clip && $(this.clip, {transform: this.matrix.invert()});
4005 this.pattern && updatePosition(this);
4006 this.node && $(this.node, {transform: this.matrix});
4008 if (_.sx != 1 || _.sy != 1) {
4009 var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
4010 this.attr({"stroke-width": sw});
4016 elproto.hide = function () {
4017 !this.removed && this.paper.safari(this.node.style.display = "none");
4021 elproto.show = function () {
4022 !this.removed && this.paper.safari(this.node.style.display = "");
4026 elproto.remove = function () {
4030 eve.unbind("*.*." + this.id);
4031 R._tear(this, this.paper);
4032 this.node.parentNode.removeChild(this.node);
4033 for (var i in this) {
4036 this.removed = true;
4038 elproto._getBBox = function () {
4039 if (this.node.style.display == "none") {
4045 bbox = this.node.getBBox();
4047 // Firefox 3.0.x plays badly here
4051 hide && this.hide();
4055 elproto.attr = function (name, value) {
4061 for (var a in this.attrs) if (this.attrs[has](a)) {
4062 res[a] = this.attrs[a];
4064 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
4065 res.transform = this._.transform;
4068 if (value == null && R.is(name, "string")) {
4069 if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
4070 return this.attrs.gradient;
4072 if (name == "transform") {
4073 return this._.transform;
4075 var names = name.split(separator),
4077 for (var i = 0, ii = names.length; i < ii; i++) {
4079 if (name in this.attrs) {
4080 out[name] = this.attrs[name];
4081 } else if (R.is(this.paper.customAttributes[name], "function")) {
4082 out[name] = this.paper.customAttributes[name].def;
4084 out[name] = R._availableAttrs[name];
4087 return ii - 1 ? out : out[names[0]];
4089 if (value == null && R.is(name, "array")) {
4091 for (i = 0, ii = name.length; i < ii; i++) {
4092 out[name[i]] = this.attr(name[i]);
4096 if (value != null) {
4098 params[name] = value;
4099 } else if (name != null && R.is(name, "object")) {
4102 for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
4103 var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
4104 this.attrs[key] = params[key];
4105 for (var subkey in par) if (par[has](subkey)) {
4106 params[subkey] = par[subkey];
4109 setFillAndStroke(this, params);
4113 elproto.toFront = function () {
4117 this.node.parentNode.appendChild(this.node);
4118 var svg = this.paper;
4119 svg.top != this && R._tofront(this, svg);
4123 elproto.toBack = function () {
4127 if (this.node.parentNode.firstChild != this.node) {
4128 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
4129 R._toback(this, this.paper);
4130 var svg = this.paper;
4135 elproto.insertAfter = function (element) {
4139 var node = element.node || element[element.length - 1].node;
4140 if (node.nextSibling) {
4141 node.parentNode.insertBefore(this.node, node.nextSibling);
4143 node.parentNode.appendChild(this.node);
4145 R._insertafter(this, element, this.paper);
4149 elproto.insertBefore = function (element) {
4153 var node = element.node || element[0].node;
4154 node.parentNode.insertBefore(this.node, node);
4155 R._insertbefore(this, element, this.paper);
4158 elproto.blur = function (size) {
4159 // Experimental. No Safari support. Use it on your own risk.
4162 var fltr = $("filter"),
4163 blur = $("feGaussianBlur");
4164 t.attrs.blur = size;
4165 fltr.id = R._createUUID();
4166 $(blur, {stdDeviation: +size || 1.5});
4167 fltr.appendChild(blur);
4168 t.paper.defs.appendChild(fltr);
4170 $(t.node, {filter: "url(#" + fltr.id + ")"});
4173 t._blur.parentNode.removeChild(t._blur);
4175 delete t.attrs.blur;
4177 t.node.removeAttribute("filter");
4180 R._engine.circle = function (svg, x, y, r) {
4181 var el = $("circle");
4182 svg.canvas && svg.canvas.appendChild(el);
4183 var res = new Element(el, svg);
4184 res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
4185 res.type = "circle";
4189 R._engine.rect = function (svg, x, y, w, h, r) {
4191 svg.canvas && svg.canvas.appendChild(el);
4192 var res = new Element(el, svg);
4193 res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
4198 R._engine.ellipse = function (svg, x, y, rx, ry) {
4199 var el = $("ellipse");
4200 svg.canvas && svg.canvas.appendChild(el);
4201 var res = new Element(el, svg);
4202 res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
4203 res.type = "ellipse";
4207 R._engine.image = function (svg, src, x, y, w, h) {
4208 var el = $("image");
4209 $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
4210 el.setAttributeNS(xlink, "href", src);
4211 svg.canvas && svg.canvas.appendChild(el);
4212 var res = new Element(el, svg);
4213 res.attrs = {x: x, y: y, width: w, height: h, src: src};
4217 R._engine.text = function (svg, x, y, text) {
4219 // $(el, {x: x, y: y, "text-anchor": "middle"});
4220 svg.canvas && svg.canvas.appendChild(el);
4221 var res = new Element(el, svg);
4225 "text-anchor": "middle",
4227 font: R._availableAttrs.font,
4232 setFillAndStroke(res, res.attrs);
4235 R._engine.setSize = function (width, height) {
4236 this.width = width || this.width;
4237 this.height = height || this.height;
4238 this.canvas.setAttribute("width", this.width);
4239 this.canvas.setAttribute("height", this.height);
4240 if (this._viewBox) {
4241 this.setViewBox.apply(this, this._viewBox);
4245 R._engine.create = function () {
4246 var con = R._getContainer.apply(0, arguments),
4247 container = con && con.container,
4251 height = con.height;
4253 throw new Error("SVG container not found.");
4255 var cnvs = $("svg"),
4256 css = "overflow:hidden;",
4260 width = width || 512;
4261 height = height || 342;
4266 xmlns: "http://www.w3.org/2000/svg"
4268 if (container == 1) {
4269 cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
4270 R._g.doc.body.appendChild(cnvs);
4273 cnvs.style.cssText = css + "position:relative";
4274 if (container.firstChild) {
4275 container.insertBefore(cnvs, container.firstChild);
4277 container.appendChild(cnvs);
4280 container = new R._Paper;
4281 container.width = width;
4282 container.height = height;
4283 container.canvas = cnvs;
4284 // plugins.call(container, container, R.fn);
4286 container._left = container._top = 0;
4287 isFloating && (container.renderfix = function () {});
4288 container.renderfix();
4291 R._engine.setViewBox = function (x, y, w, h, fit) {
4292 eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
4293 var size = mmax(w / this.width, h / this.height),
4295 aspectRatio = fit ? "meet" : "xMinYMin",
4302 delete this._vbSize;
4303 vb = "0 0 " + this.width + S + this.height;
4305 this._vbSize = size;
4306 vb = x + S + y + S + w + S + h;
4310 preserveAspectRatio: aspectRatio
4312 while (size && top) {
4313 sw = "stroke-width" in top.attrs ? top.attrs["stroke-width"] : 1;
4314 top.attr({"stroke-width": sw});
4319 this._viewBox = [x, y, w, h, !!fit];
4323 R.prototype.renderfix = function () {
4324 var cnvs = this.canvas,
4326 pos = cnvs.getScreenCTM(),
4331 this._left = (this._left + left) % 1;
4332 s.left = this._left + "px";
4335 this._top = (this._top + top) % 1;
4336 s.top = this._top + "px";
4341 R.prototype.clear = function () {
4342 R.eve("clear", this);
4343 var c = this.canvas;
4344 while (c.firstChild) {
4345 c.removeChild(c.firstChild);
4347 this.bottom = this.top = null;
4348 (this.desc = $("desc")).appendChild(R._g.doc.createTextNode("Created with Rapha\xebl " + R.version));
4349 c.appendChild(this.desc);
4350 c.appendChild(this.defs = $("defs"));
4353 R.prototype.remove = function () {
4354 eve("remove", this);
4355 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
4356 for (var i in this) {
4357 this[i] = removed(i);
4360 var setproto = R.st;
4361 for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
4362 setproto[method] = (function (methodname) {
4363 return function () {
4364 var arg = arguments;
4365 return this.forEach(function (el) {
4366 el[methodname].apply(el, arg);
4373 // ┌─────────────────────────────────────────────────────────────────────┐ \\
4374 // │ Raphaël 2 - JavaScript Vector Library │ \\
4375 // ├─────────────────────────────────────────────────────────────────────┤ \\
4376 // │ VML Module │ \\
4377 // ├─────────────────────────────────────────────────────────────────────┤ \\
4378 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
4379 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
4380 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
4381 // └─────────────────────────────────────────────────────────────────────┘ \\
4382 window.Raphael.vml && function (R) {
4383 var has = "hasOwnProperty",
4385 toFloat = parseFloat,
4391 fillString = "fill",
4392 separator = /[, ]+/,
4397 var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
4398 bites = /([clmz]),?([^clmz]*)/gi,
4399 blurregexp = / progid:\S+Blur\([^\)]+\)/g,
4400 val = /-?[^,\s-]+/g,
4401 cssDot = "position:absolute;left:0;top:0;width:1px;height:1px",
4403 pathTypes = {path: 1, rect: 1},
4404 ovalTypes = {circle: 1, ellipse: 1},
4405 path2vml = function (path) {
4406 var total = /[ahqstv]/ig,
4407 command = R._pathToAbsolute;
4408 Str(path).match(total) && (command = R._path2curve);
4410 if (command == R._pathToAbsolute && !Str(path).match(total)) {
4411 var res = Str(path).replace(bites, function (all, command, args) {
4413 isMove = command.toLowerCase() == "m",
4415 args.replace(val, function (value) {
4416 if (isMove && vals.length == 2) {
4417 res += vals + map[command == "m" ? "l" : "L"];
4420 vals.push(round(value * zoom));
4426 var pa = command(path), p, r;
4428 for (var i = 0, ii = pa.length; i < ii; i++) {
4430 r = pa[i][0].toLowerCase();
4431 r == "z" && (r = "x");
4432 for (var j = 1, jj = p.length; j < jj; j++) {
4433 r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
4439 compensation = function (deg, dx, dy) {
4441 m.rotate(-deg, .5, .5);
4447 setCoords = function (p, sx, sy, dx, dy, deg) {
4450 fillpos = _.fillpos,
4458 s.visibility = "hidden";
4462 o.coordsize = abs(kx) + S + abs(ky);
4463 s.rotation = deg * (sx * sy < 0 ? -1 : 1);
4465 var c = compensation(deg, dx, dy);
4469 sx < 0 && (flip += "x");
4470 sy < 0 && (flip += " y") && (y = -1);
4472 o.coordorigin = (dx * -kx) + S + (dy * -ky);
4473 if (fillpos || _.fillsize) {
4474 var fill = o.getElementsByTagName(fillString);
4475 fill = fill && fill[0];
4476 o.removeChild(fill);
4478 c = compensation(deg, m.x(fillpos[0], fillpos[1]), m.y(fillpos[0], fillpos[1]));
4479 fill.position = c.dx * y + S + c.dy * y;
4482 fill.size = _.fillsize[0] * abs(sx) + S + _.fillsize[1] * abs(sy);
4484 o.appendChild(fill);
4486 s.visibility = "visible";
4488 R.toString = function () {
4489 return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
4491 addArrow = function (o, value, isEnd) {
4492 var values = Str(value).toLowerCase().split("-"),
4493 se = isEnd ? "end" : "start",
4499 switch (values[i]) {
4509 case "narrow": h = values[i]; break;
4511 case "short": w = values[i]; break;
4514 var stroke = o.node.getElementsByTagName("stroke")[0];
4515 stroke[se + "arrow"] = type;
4516 stroke[se + "arrowlength"] = w;
4517 stroke[se + "arrowwidth"] = h;
4519 setFillAndStroke = function (o, params) {
4520 // o.paper.canvas.style.display = "none";
4521 o.attrs = o.attrs || {};
4526 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),
4527 isOval = ovalTypes[o.type] && (a.cx != params.cx || a.cy != params.cy || a.r != params.r || a.rx != params.rx || a.ry != params.ry),
4531 for (var par in params) if (params[has](par)) {
4532 a[par] = params[par];
4535 a.path = R._getPath[o.type](o);
4538 params.href && (node.href = params.href);
4539 params.title && (node.title = params.title);
4540 params.target && (node.target = params.target);
4541 params.cursor && (s.cursor = params.cursor);
4542 "blur" in params && o.blur(params.blur);
4543 "transform" in params && o.transform(params.transform);
4544 if (params.path && o.type == "path" || newpath) {
4545 node.path = path2vml(a.path);
4550 rx = +a.rx || +a.r || 0,
4551 ry = +a.ry || +a.r || 0;
4552 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));
4554 if ("clip-rect" in params) {
4555 var rect = Str(params["clip-rect"]).split(separator);
4556 if (rect.length == 4) {
4557 rect[2] = +rect[2] + (+rect[0]);
4558 rect[3] = +rect[3] + (+rect[1]);
4559 var div = node.clipRect || R._g.doc.createElement("div"),
4561 group = node.parentNode;
4562 dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
4563 if (!node.clipRect) {
4564 dstyle.position = "absolute";
4567 dstyle.width = o.paper.width + "px";
4568 dstyle.height = o.paper.height + "px";
4569 group.parentNode.insertBefore(div, group);
4570 div.appendChild(group);
4571 node.clipRect = div;
4574 if (!params["clip-rect"]) {
4575 node.clipRect && (node.clipRect.style.clip = E);
4579 var textpathStyle = o.textpath.style;
4580 params.font && (textpathStyle.font = params.font);
4581 params["font-family"] && (textpathStyle.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, E) + '"');
4582 params["font-size"] && (textpathStyle.fontSize = params["font-size"]);
4583 params["font-weight"] && (textpathStyle.fontWeight = params["font-weight"]);
4584 params["font-style"] && (textpathStyle.fontStyle = params["font-style"]);
4586 if ("arrow-start" in params) {
4587 addArrow(res, params["arrow-start"]);
4589 if ("arrow-end" in params) {
4590 addArrow(res, params["arrow-end"], 1);
4592 if (params.opacity != null ||
4593 params["stroke-width"] != null ||
4594 params.fill != null ||
4595 params.src != null ||
4596 params.stroke != null ||
4597 params["stroke-width"] != null ||
4598 params["stroke-opacity"] != null ||
4599 params["fill-opacity"] != null ||
4600 params["stroke-dasharray"] != null ||
4601 params["stroke-miterlimit"] != null ||
4602 params["stroke-linejoin"] != null ||
4603 params["stroke-linecap"] != null) {
4604 var fill = node.getElementsByTagName(fillString),
4606 fill = fill && fill[0];
4607 !fill && (newfill = fill = createNode(fillString));
4608 if (o.type == "image" && params.src) {
4609 fill.src = params.src;
4611 params.fill && (fill.on = true);
4612 if (fill.on == null || params.fill == "none" || params.fill === null) {
4615 if (fill.on && params.fill) {
4616 var isURL = Str(params.fill).match(R._ISURL);
4618 fill.parentNode == node && node.removeChild(fill);
4620 fill.src = isURL[1];
4622 var bbox = o.getBBox(1);
4623 fill.position = bbox.x + S + bbox.y;
4624 o._.fillpos = [bbox.x, bbox.y];
4626 R._preload(isURL[1], function () {
4627 o._.fillsize = [this.offsetWidth, this.offsetHeight];
4630 fill.color = R.getRGB(params.fill).hex;
4632 fill.type = "solid";
4633 if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill, fill)) {
4635 a.gradient = params.fill;
4636 fill.rotate = false;
4640 if ("fill-opacity" in params || "opacity" in params) {
4641 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
4642 opacity = mmin(mmax(opacity, 0), 1);
4643 fill.opacity = opacity;
4645 fill.color = "none";
4648 node.appendChild(fill);
4649 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
4651 !stroke && (newstroke = stroke = createNode("stroke"));
4652 if ((params.stroke && params.stroke != "none") ||
4653 params["stroke-width"] ||
4654 params["stroke-opacity"] != null ||
4655 params["stroke-dasharray"] ||
4656 params["stroke-miterlimit"] ||
4657 params["stroke-linejoin"] ||
4658 params["stroke-linecap"]) {
4661 (params.stroke == "none" || params.stroke === null || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
4662 var strokeColor = R.getRGB(params.stroke);
4663 stroke.on && params.stroke && (stroke.color = strokeColor.hex);
4664 opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
4665 var width = (toFloat(params["stroke-width"]) || 1) * .75;
4666 opacity = mmin(mmax(opacity, 0), 1);
4667 params["stroke-width"] == null && (width = a["stroke-width"]);
4668 params["stroke-width"] && (stroke.weight = width);
4669 width && width < 1 && (opacity *= width) && (stroke.weight = 1);
4670 stroke.opacity = opacity;
4672 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
4673 stroke.miterlimit = params["stroke-miterlimit"] || 8;
4674 params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
4675 if (params["stroke-dasharray"]) {
4679 "-.": "shortdashdot",
4680 "-..": "shortdashdotdot",
4685 "--.": "longdashdot",
4686 "--..": "longdashdotdot"
4688 stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
4690 newstroke && node.appendChild(stroke);
4692 if (res.type == "text") {
4693 res.paper.canvas.style.display = E;
4694 var span = res.paper.span,
4696 fontSize = a.font && a.font.match(/\d+(?:\.\d*)?(?=px)/);
4698 a.font && (s.font = a.font);
4699 a["font-family"] && (s.fontFamily = a["font-family"]);
4700 a["font-weight"] && (s.fontWeight = a["font-weight"]);
4701 a["font-style"] && (s.fontStyle = a["font-style"]);
4702 fontSize = toFloat(fontSize ? fontSize[0] : a["font-size"]);
4703 s.fontSize = fontSize * m + "px";
4704 res.textpath.string && (span.innerHTML = Str(res.textpath.string).replace(/</g, "<").replace(/&/g, "&").replace(/\n/g, "<br>"));
4705 var brect = span.getBoundingClientRect();
4706 res.W = a.w = (brect.right - brect.left) / m;
4707 res.H = a.h = (brect.bottom - brect.top) / m;
4708 // res.paper.canvas.style.display = "none";
4710 res.Y = a.y + res.H / 2;
4712 ("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));
4713 var dirtyattrs = ["x", "y", "text", "font", "font-family", "font-weight", "font-style", "font-size"];
4714 for (var d = 0, dd = dirtyattrs.length; d < dd; d++) if (dirtyattrs[d] in params) {
4719 // text-anchor emulation
4720 switch (a["text-anchor"]) {
4722 res.textpath.style["v-text-align"] = "left";
4723 res.bbx = res.W / 2;
4726 res.textpath.style["v-text-align"] = "right";
4727 res.bbx = -res.W / 2;
4730 res.textpath.style["v-text-align"] = "center";
4734 res.textpath.style["v-text-kern"] = true;
4736 // res.paper.canvas.style.display = E;
4738 addGradientFill = function (o, gradient, fill) {
4739 o.attrs = o.attrs || {};
4740 var attrs = o.attrs,
4745 o.attrs.gradient = gradient;
4746 gradient = Str(gradient).replace(R._radial_gradient, function (all, fx, fy) {
4751 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
4756 gradient = gradient.split(/\s*\-\s*/);
4757 if (type == "linear") {
4758 var angle = gradient.shift();
4759 angle = -toFloat(angle);
4764 var dots = R._parseDots(gradient);
4768 o = o.shape || o.node;
4770 o.removeChild(fill);
4772 fill.method = "none";
4773 fill.color = dots[0].color;
4774 fill.color2 = dots[dots.length - 1].color;
4776 for (var i = 0, ii = dots.length; i < ii; i++) {
4777 dots[i].offset && clrs.push(dots[i].offset + S + dots[i].color);
4779 fill.colors = clrs.length ? clrs.join() : "0% " + fill.color;
4780 if (type == "radial") {
4781 fill.type = "gradientTitle";
4782 fill.focus = "100%";
4783 fill.focussize = "0 0";
4784 fill.focusposition = fxfy;
4787 // fill.rotate= true;
4788 fill.type = "gradient";
4789 fill.angle = (270 - angle) % 360;
4791 o.appendChild(fill);
4795 Element = function (node, vml) {
4796 this[0] = this.node = node;
4797 node.raphael = true;
4799 node.raphaelid = this.id;
4804 this.matrix = R.matrix();
4815 !vml.bottom && (vml.bottom = this);
4816 this.prev = vml.top;
4817 vml.top && (vml.top.next = this);
4823 Element.prototype = elproto;
4824 elproto.constructor = Element;
4825 elproto.transform = function (tstr) {
4827 return this._.transform;
4829 var vbs = this.paper._viewBoxShift,
4830 vbt = vbs ? "s" + [vbs.scale, vbs.scale] + "-1-1t" + [vbs.dx, vbs.dy] : E,
4833 oldt = tstr = Str(tstr).replace(/\.{3}|\u2026/g, this._.transform || E);
4835 R._extractTransform(this, vbt + tstr);
4836 var matrix = this.matrix.clone(),
4840 isGrad = ~Str(this.attrs.fill).indexOf("-"),
4841 isPatt = !Str(this.attrs.fill).indexOf("url(");
4842 matrix.translate(-.5, -.5);
4843 if (isPatt || isGrad || this.type == "image") {
4844 skew.matrix = "1 0 0 1";
4845 skew.offset = "0 0";
4846 split = matrix.split();
4847 if ((isGrad && split.noRotation) || !split.isSimple) {
4848 o.style.filter = matrix.toFilter();
4849 var bb = this.getBBox(),
4850 bbt = this.getBBox(1),
4853 o.coordorigin = (dx * -zoom) + S + (dy * -zoom);
4854 setCoords(this, 1, 1, dx, dy, 0);
4857 setCoords(this, split.scalex, split.scaley, split.dx, split.dy, split.rotate);
4861 skew.matrix = Str(matrix);
4862 skew.offset = matrix.offset();
4864 oldt && (this._.transform = oldt);
4867 elproto.rotate = function (deg, cx, cy) {
4874 deg = Str(deg).split(separator);
4875 if (deg.length - 1) {
4876 cx = toFloat(deg[1]);
4877 cy = toFloat(deg[2]);
4879 deg = toFloat(deg[0]);
4880 (cy == null) && (cx = cy);
4881 if (cx == null || cy == null) {
4882 var bbox = this.getBBox(1);
4883 cx = bbox.x + bbox.width / 2;
4884 cy = bbox.y + bbox.height / 2;
4887 this.transform(this._.transform.concat([["r", deg, cx, cy]]));
4890 elproto.translate = function (dx, dy) {
4894 dx = Str(dx).split(separator);
4895 if (dx.length - 1) {
4896 dy = toFloat(dx[1]);
4898 dx = toFloat(dx[0]) || 0;
4901 this._.bbox.x += dx;
4902 this._.bbox.y += dy;
4904 this.transform(this._.transform.concat([["t", dx, dy]]));
4907 elproto.scale = function (sx, sy, cx, cy) {
4911 sx = Str(sx).split(separator);
4912 if (sx.length - 1) {
4913 sy = toFloat(sx[1]);
4914 cx = toFloat(sx[2]);
4915 cy = toFloat(sx[3]);
4916 isNaN(cx) && (cx = null);
4917 isNaN(cy) && (cy = null);
4919 sx = toFloat(sx[0]);
4920 (sy == null) && (sy = sx);
4921 (cy == null) && (cx = cy);
4922 if (cx == null || cy == null) {
4923 var bbox = this.getBBox(1);
4925 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
4926 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
4928 this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
4932 elproto.hide = function () {
4933 !this.removed && (this.node.style.display = "none");
4936 elproto.show = function () {
4937 !this.removed && (this.node.style.display = E);
4940 elproto._getBBox = function () {
4944 if (this.type == "text") {
4946 x: this.X + (this.bbx || 0) - this.W / 2,
4952 return pathDimensions(this.attrs.path);
4955 elproto.remove = function () {
4959 R.eve.unbind("*.*." + this.id);
4960 R._tear(this, this.paper);
4961 this.node.parentNode.removeChild(this.node);
4962 this.shape && this.shape.parentNode.removeChild(this.shape);
4963 for (var i in this) {
4966 this.removed = true;
4968 elproto.attr = function (name, value) {
4974 for (var a in this.attrs) if (this.attrs[has](a)) {
4975 res[a] = this.attrs[a];
4977 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
4978 res.transform = this._.transform;
4981 if (value == null && R.is(name, "string")) {
4982 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
4983 return this.attrs.gradient;
4985 var names = name.split(separator),
4987 for (var i = 0, ii = names.length; i < ii; i++) {
4989 if (name in this.attrs) {
4990 out[name] = this.attrs[name];
4991 } else if (R.is(this.paper.customAttributes[name], "function")) {
4992 out[name] = this.paper.customAttributes[name].def;
4994 out[name] = R._availableAttrs[name];
4997 return ii - 1 ? out : out[names[0]];
4999 if (this.attrs && value == null && R.is(name, "array")) {
5001 for (i = 0, ii = name.length; i < ii; i++) {
5002 out[name[i]] = this.attr(name[i]);
5007 if (value != null) {
5009 params[name] = value;
5011 value == null && R.is(name, "object") && (params = name);
5012 for (var key in params) {
5013 R.eve("attr." + key + "." + this.id, this, params[key]);
5016 for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
5017 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
5018 this.attrs[key] = params[key];
5019 for (var subkey in par) if (par[has](subkey)) {
5020 params[subkey] = par[subkey];
5023 // this.paper.canvas.style.display = "none";
5024 if (params.text && this.type == "text") {
5025 this.textpath.string = params.text;
5027 setFillAndStroke(this, params);
5028 // this.paper.canvas.style.display = E;
5032 elproto.toFront = function () {
5033 !this.removed && this.node.parentNode.appendChild(this.node);
5034 this.paper && this.paper.top != this && R._tofront(this, this.paper);
5037 elproto.toBack = function () {
5041 if (this.node.parentNode.firstChild != this.node) {
5042 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
5043 R._toback(this, this.paper);
5047 elproto.insertAfter = function (element) {
5051 if (element.constructor == R.st.constructor) {
5052 element = element[element.length - 1];
5054 if (element.node.nextSibling) {
5055 element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
5057 element.node.parentNode.appendChild(this.node);
5059 R._insertafter(this, element, this.paper);
5062 elproto.insertBefore = function (element) {
5066 if (element.constructor == R.st.constructor) {
5067 element = element[0];
5069 element.node.parentNode.insertBefore(this.node, element.node);
5070 R._insertbefore(this, element, this.paper);
5073 elproto.blur = function (size) {
5074 var s = this.node.runtimeStyle,
5076 f = f.replace(blurregexp, E);
5078 this.attrs.blur = size;
5079 s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
5080 s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
5084 delete this.attrs.blur;
5088 R._engine.path = function (pathString, vml) {
5089 var el = createNode("shape");
5090 el.style.cssText = cssDot;
5091 el.coordsize = zoom + S + zoom;
5092 el.coordorigin = vml.coordorigin;
5093 var p = new Element(el, vml),
5094 attr = {fill: "none", stroke: "#000"};
5095 pathString && (attr.path = pathString);
5099 setFillAndStroke(p, attr);
5100 vml.canvas.appendChild(el);
5101 var skew = createNode("skew");
5103 el.appendChild(skew);
5108 R._engine.rect = function (vml, x, y, w, h, r) {
5109 var path = R._rectPath(x, y, w, h, r),
5110 res = vml.path(path),
5114 res.W = a.width = w;
5115 res.H = a.height = h;
5121 R._engine.ellipse = function (vml, x, y, rx, ry) {
5122 var res = vml.path(),
5128 res.type = "ellipse";
5129 setFillAndStroke(res, {
5137 R._engine.circle = function (vml, x, y, r) {
5138 var res = vml.path(),
5142 res.W = res.H = r * 2;
5143 res.type = "circle";
5144 setFillAndStroke(res, {
5151 R._engine.image = function (vml, src, x, y, w, h) {
5152 var path = R._rectPath(x, y, w, h),
5153 res = vml.path(path).attr({stroke: "none"}),
5156 fill = node.getElementsByTagName(fillString)[0];
5160 res.W = a.width = w;
5161 res.H = a.height = h;
5164 fill.parentNode == node && node.removeChild(fill);
5168 res._.fillpos = [x, y];
5169 res._.fillsize = [w, h];
5170 node.appendChild(fill);
5171 setCoords(res, 1, 1, 0, 0, 0);
5174 R._engine.text = function (vml, x, y, text) {
5175 var el = createNode("shape"),
5176 path = createNode("path"),
5177 o = createNode("textpath");
5181 path.v = R.format("m{0},{1}l{2},{1}", round(x * zoom), round(y * zoom), round(x * zoom) + 1);
5182 path.textpathok = true;
5183 o.string = Str(text);
5185 el.style.cssText = "position:absolute;left:0;top:0;width:1px;height:1px";
5186 el.coordsize = zoom + S + zoom;
5187 el.coordorigin = "0 0";
5188 var p = new Element(el, vml),
5192 font: R._availableAttrs.font,
5199 p.attrs.text = Str(text);
5204 setFillAndStroke(p, attr);
5206 el.appendChild(path);
5207 vml.canvas.appendChild(el);
5208 var skew = createNode("skew");
5210 el.appendChild(skew);
5215 R._engine.setSize = function (width, height) {
5216 var cs = this.canvas.style;
5218 this.height = height;
5219 width == +width && (width += "px");
5220 height == +height && (height += "px");
5223 cs.clip = "rect(0 " + width + " " + height + " 0)";
5224 if (this._viewBox) {
5225 setViewBox.apply(this, this._viewBox);
5229 R._engine.setViewBox = function (x, y, w, h, fit) {
5230 R.eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
5231 var width = this.width,
5232 height = this.height,
5233 size = 1 / mmax(w / width, h / height),
5238 if (w * H < width) {
5239 x -= (width - w * H) / 2 / H;
5241 if (h * W < height) {
5242 y -= (height - h * W) / 2 / W;
5245 this._viewBox = [x, y, w, h, !!fit];
5246 this._viewBoxShift = {
5251 this.forEach(function (el) {
5252 el.transform("...");
5257 initWin = function (win) {
5258 var doc = win.document;
5259 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
5261 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
5262 createNode = function (tagName) {
5263 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
5266 createNode = function (tagName) {
5267 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
5272 R._engine.create = function () {
5273 var con = R._getContainer.apply(0, arguments),
5274 container = con.container,
5275 height = con.height,
5281 throw new Error("VML container not found.");
5283 var res = new R._Paper,
5284 c = res.canvas = R._g.doc.createElement("div"),
5288 width = width || 512;
5289 height = height || 342;
5291 res.height = height;
5292 width == +width && (width += "px");
5293 height == +height && (height += "px");
5294 res.coordsize = zoom * 1e3 + S + zoom * 1e3;
5295 res.coordorigin = "0 0";
5296 res.span = R._g.doc.createElement("span");
5297 res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;";
5298 c.appendChild(res.span);
5299 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);
5300 if (container == 1) {
5301 R._g.doc.body.appendChild(c);
5304 cs.position = "absolute";
5306 if (container.firstChild) {
5307 container.insertBefore(c, container.firstChild);
5309 container.appendChild(c);
5312 // plugins.call(res, res, R.fn);
5313 res.renderfix = function () {};
5316 R.prototype.clear = function () {
5317 R.eve("clear", this);
5318 this.canvas.innerHTML = E;
5319 this.span = R._g.doc.createElement("span");
5320 this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
5321 this.canvas.appendChild(this.span);
5322 this.bottom = this.top = null;
5324 R.prototype.remove = function () {
5325 R.eve("remove", this);
5326 this.canvas.parentNode.removeChild(this.canvas);
5327 for (var i in this) {
5328 this[i] = removed(i);