2 * Raphael 1.5.2 - JavaScript Vector Library
4 * Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com)
5 * Licensed under the MIT (http://raphaeljs.com/license.html) license.
6 * from fork at git@github.com:mobz/g.raphael.git
10 if (R.is(arguments[0], array)) {
12 cnv = create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
14 for (var i = 0, ii = a[length]; i < ii; i++) {
16 elements[has](j.type) && res[push](cnv[j.type]().attr(j));
20 return create[apply](R, arguments);
23 var separator = /[, ]+/,
24 elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
25 formatrg = /\{(\d+)\}/g,
27 has = "hasOwnProperty",
31 was: Object[proto][has].call(win, "Raphael"),
35 this.customAttributes = {};
38 appendChild = "appendChild",
41 supportsTouch = "createTouch" in doc,
46 events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend orientationchange touchcancel gesturestart gesturechange gestureend"[split](S),
48 mousedown: "touchstart",
49 mousemove: "touchmove",
54 lowerCase = Str[proto].toLowerCase,
64 toString = "toString",
66 objectToString = Object[proto][toString],
69 ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
70 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,
71 isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
72 bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
74 setAttribute = "setAttribute",
77 ms = " progid:DXImageTransform.Microsoft",
78 upperCase = Str[proto].toUpperCase,
79 availableAttrs = {blur: 0, "clip-rect": "0 0 1e9 1e9", cursor: "default", cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0},
80 availableAnimAttrs = {along: "along", blur: nu, "clip-rect": "csv", cx: nu, cy: nu, fill: "colour", "fill-opacity": nu, "font-size": nu, height: nu, opacity: nu, path: "path", r: nu, rotation: "csv", rx: nu, ry: nu, scale: "csv", stroke: "colour", "stroke-opacity": nu, "stroke-width": nu, translation: "csv", width: nu, x: nu, y: nu},
82 animKeyFrames= /^(from|to|\d+%?)$/,
83 commaSpaces = /\s*,\s*/,
84 hsrg = {hs: 1, rg: 1},
85 p2s = /,?([achlmqrstvxz]),?/gi,
86 pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
87 pathValues = /(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig,
88 radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/,
89 sortByKey = function (a, b) {
93 R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
94 if (R.type == "VML") {
95 var d = doc.createElement("div"),
97 d.innerHTML = '<v:shape adj="1"/>';
99 b.style.behavior = "url(#default#VML)";
100 if (!(b && typeof b.adj == "object")) {
101 return R.type = null;
105 R.svg = !(R.vml = R.type == "VML");
106 Paper[proto] = R[proto];
107 paperproto = Paper[proto];
111 R.is = function (o, type) {
112 type = lowerCase.call(type);
113 if (type == "finite") {
114 return !isnan[has](+o);
116 return (type == "null" && o === null) ||
117 (type == typeof o) ||
118 (type == "object" && o === Object(o)) ||
119 (type == "array" && Array.isArray && Array.isArray(o)) ||
120 objectToString.call(o).slice(8, -1).toLowerCase() == type;
122 R.angle = function (x1, y1, x2, y2, x3, y3) {
129 return ((x < 0) * 180 + math.atan(-y / -x) * 180 / PI + 360) % 360;
131 return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
134 R.rad = function (deg) {
135 return deg % 360 * PI / 180;
137 R.deg = function (rad) {
138 return rad * 180 / PI % 360;
140 R.snapTo = function (values, value, tolerance) {
141 tolerance = R.is(tolerance, "finite") ? tolerance : 10;
142 if (R.is(values, array)) {
143 var i = values.length;
144 while (i--) if (abs(values[i] - value) <= tolerance) {
149 var rem = value % values;
150 if (rem < tolerance) {
153 if (rem > values - tolerance) {
154 return value - rem + values;
159 function createUUID() {
160 // http://www.ietf.org/rfc/rfc4122.txt
163 for (; i < 32; i++) {
164 s[i] = (~~(math.random() * 16))[toString](16);
166 s[12] = 4; // bits 12-15 of the time_hi_and_version field to 0010
167 s[16] = ((s[16] & 3) | 8)[toString](16); // bits 6-7 of the clock_seq_hi_and_reserved to 01
168 return "r-" + s[join]("");
171 R.setWindow = function (newwin) {
176 var toHex = function (color) {
178 // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
179 var trim = /^\s+|\s+$/g;
182 var docum = new ActiveXObject("htmlfile");
183 docum.write("<body>");
187 bod = createPopup().document.body;
189 var range = bod.createTextRange();
190 toHex = cacher(function (color) {
192 bod.style.color = Str(color)[rp](trim, E);
193 var value = range.queryCommandValue("ForeColor");
194 value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
195 return "#" + ("000000" + value[toString](16)).slice(-6);
201 var i = doc.createElement("i");
202 i.title = "Rapha\xebl Colour Picker";
203 i.style.display = "none";
204 doc.body[appendChild](i);
205 toHex = cacher(function (color) {
206 i.style.color = color;
207 return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
212 hsbtoString = function () {
213 return "hsb(" + [this.h, this.s, this.b] + ")";
215 hsltoString = function () {
216 return "hsl(" + [this.h, this.s, this.l] + ")";
218 rgbtoString = function () {
221 R.hsb2rgb = function (h, s, b, o) {
222 if (R.is(h, "object") && "h" in h && "s" in h && "b" in h) {
228 return R.hsl2rgb(h, s, b / 2, o);
230 R.hsl2rgb = function (h, s, l, o) {
231 if (R.is(h, "object") && "h" in h && "s" in h && "l" in h) {
236 if (h > 1 || s > 1 || l > 1) {
242 channels = ["r", "g", "b"],
257 for (var i = 0; i < 3; i++) {
258 t3 = h + 1 / 3 * -(i - 1);
262 rgb[channels[i]] = t1 + (t2 - t1) * 6 * t3;
263 } else if (t3 * 2 < 1) {
264 rgb[channels[i]] = t2;
265 } else if (t3 * 3 < 2) {
266 rgb[channels[i]] = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
268 rgb[channels[i]] = t1;
275 rgb.hex = "#" + (16777216 | rgb.b | (rgb.g << 8) | (rgb.r << 16)).toString(16).slice(1);
276 R.is(o, "finite") && (rgb.opacity = o);
277 rgb.toString = rgbtoString;
280 R.rgb2hsb = function (red, green, blue) {
281 if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
286 if (green == null && R.is(red, string)) {
287 var clr = R.getRGB(red);
292 if (red > 1 || green > 1 || blue > 1) {
297 var max = mmax(red, green, blue),
298 min = mmin(red, green, blue),
303 return {h: 0, s: 0, b: max, toString: hsbtoString};
305 var delta = (max - min);
306 saturation = delta / max;
308 hue = (green - blue) / delta;
309 } else if (green == max) {
310 hue = 2 + ((blue - red) / delta);
312 hue = 4 + ((red - green) / delta);
318 return {h: hue, s: saturation, b: brightness, toString: hsbtoString};
320 R.rgb2hsl = function (red, green, blue) {
321 if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
326 if (green == null && R.is(red, string)) {
327 var clr = R.getRGB(red);
332 if (red > 1 || green > 1 || blue > 1) {
337 var max = mmax(red, green, blue),
338 min = mmin(red, green, blue),
344 hsl = {h: 0, s: 0, l: l};
346 var delta = max - min;
347 s = l < .5 ? delta / (max + min) : delta / (2 - max - min);
349 h = (green - blue) / delta;
350 } else if (green == max) {
351 h = 2 + (blue - red) / delta;
353 h = 4 + (red - green) / delta;
358 hsl = {h: h, s: s, l: l};
360 hsl.toString = hsltoString;
363 R._path2string = function () {
364 return this.join(",")[rp](p2s, "$1");
366 function cacher(f, scope, postprocessor) {
368 var arg = Array[proto].slice.call(arguments, 0),
369 args = arg[join]("\u25ba"),
370 cache = newf.cache = newf.cache || {},
371 count = newf.count = newf.count || [];
372 if (cache[has](args)) {
373 return postprocessor ? postprocessor(cache[args]) : cache[args];
375 count[length] >= 1e3 && delete cache[count.shift()];
377 cache[args] = f[apply](scope, arg);
378 return postprocessor ? postprocessor(cache[args]) : cache[args];
383 R.getRGB = cacher(function (colour) {
384 if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
385 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
387 if (colour == "none") {
388 return {r: -1, g: -1, b: -1, hex: "none"};
390 !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
398 rgb = colour.match(colourRegExp);
401 blue = toInt(rgb[2].substring(5), 16);
402 green = toInt(rgb[2].substring(3, 5), 16);
403 red = toInt(rgb[2].substring(1, 3), 16);
406 blue = toInt((t = rgb[3].charAt(3)) + t, 16);
407 green = toInt((t = rgb[3].charAt(2)) + t, 16);
408 red = toInt((t = rgb[3].charAt(1)) + t, 16);
411 values = rgb[4][split](commaSpaces);
412 red = toFloat(values[0]);
413 values[0].slice(-1) == "%" && (red *= 2.55);
414 green = toFloat(values[1]);
415 values[1].slice(-1) == "%" && (green *= 2.55);
416 blue = toFloat(values[2]);
417 values[2].slice(-1) == "%" && (blue *= 2.55);
418 rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3]));
419 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
422 values = rgb[5][split](commaSpaces);
423 red = toFloat(values[0]);
424 values[0].slice(-1) == "%" && (red *= 2.55);
425 green = toFloat(values[1]);
426 values[1].slice(-1) == "%" && (green *= 2.55);
427 blue = toFloat(values[2]);
428 values[2].slice(-1) == "%" && (blue *= 2.55);
429 (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
430 rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3]));
431 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
432 return R.hsb2rgb(red, green, blue, opacity);
435 values = rgb[6][split](commaSpaces);
436 red = toFloat(values[0]);
437 values[0].slice(-1) == "%" && (red *= 2.55);
438 green = toFloat(values[1]);
439 values[1].slice(-1) == "%" && (green *= 2.55);
440 blue = toFloat(values[2]);
441 values[2].slice(-1) == "%" && (blue *= 2.55);
442 (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
443 rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3]));
444 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
445 return R.hsl2rgb(red, green, blue, opacity);
447 rgb = {r: red, g: green, b: blue};
448 rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1);
449 R.is(opacity, "finite") && (rgb.opacity = opacity);
452 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
454 R.getColor = function (value) {
455 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
456 rgb = this.hsb2rgb(start.h, start.s, start.b);
461 start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
465 R.getColor.reset = function () {
469 R.parsePathString = cacher(function (pathString) {
473 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
475 if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
476 data = pathClone(pathString);
479 Str(pathString)[rp](pathCommand, function (a, b, c) {
481 name = lowerCase.call(b);
482 c[rp](pathValues, function (a, b) {
483 b && params[push](+b);
485 if (name == "m" && params[length] > 2) {
486 data[push]([b][concat](params.splice(0, 2)));
488 b = b == "m" ? "l" : "L";
490 while (params[length] >= paramCounts[name]) {
491 data[push]([b][concat](params.splice(0, paramCounts[name])));
492 if (!paramCounts[name]) {
498 data[toString] = R._path2string;
501 R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
503 x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
504 y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y,
505 mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
506 my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
507 nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
508 ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
509 ax = (1 - t) * p1x + t * c1x,
510 ay = (1 - t) * p1y + t * c1y,
511 cx = (1 - t) * c2x + t * p2x,
512 cy = (1 - t) * c2y + t * p2y,
513 alpha = (90 - math.atan((mx - nx) / (my - ny)) * 180 / PI);
514 (mx > nx || my < ny) && (alpha += 180);
515 return {x: x, y: y, m: {x: mx, y: my}, n: {x: nx, y: ny}, start: {x: ax, y: ay}, end: {x: cx, y: cy}, alpha: alpha};
517 var pathDimensions = cacher(function (path) {
519 return {x: 0, y: 0, width: 0, height: 0};
521 path = path2curve(path);
527 for (var i = 0, ii = path[length]; i < ii; i++) {
535 var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
536 X = X[concat](dim.min.x, dim.max.x);
537 Y = Y[concat](dim.min.y, dim.max.y);
542 var xmin = mmin[apply](0, X),
543 ymin = mmin[apply](0, Y);
547 width: mmax[apply](0, X) - xmin,
548 height: mmax[apply](0, Y) - ymin
551 pathClone = function (pathArray) {
553 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
554 pathArray = R.parsePathString(pathArray);
556 for (var i = 0, ii = pathArray[length]; i < ii; i++) {
558 for (var j = 0, jj = pathArray[i][length]; j < jj; j++) {
559 res[i][j] = pathArray[i][j];
562 res[toString] = R._path2string;
565 pathToRelative = cacher(function (pathArray) {
566 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
567 pathArray = R.parsePathString(pathArray);
575 if (pathArray[0][0] == "M") {
581 res[push](["M", x, y]);
583 for (var i = start, ii = pathArray[length]; i < ii; i++) {
586 if (pa[0] != lowerCase.call(pa[0])) {
587 r[0] = lowerCase.call(pa[0]);
595 r[6] = +(pa[6] - x).toFixed(3);
596 r[7] = +(pa[7] - y).toFixed(3);
599 r[1] = +(pa[1] - y).toFixed(3);
605 for (var j = 1, jj = pa[length]; j < jj; j++) {
606 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
615 for (var k = 0, kk = pa[length]; k < kk; k++) {
619 var len = res[i][length];
626 x += +res[i][len - 1];
629 y += +res[i][len - 1];
632 x += +res[i][len - 2];
633 y += +res[i][len - 1];
636 res[toString] = R._path2string;
639 pathToAbsolute = cacher(function (pathArray) {
640 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
641 pathArray = R.parsePathString(pathArray);
649 if (pathArray[0][0] == "M") {
650 x = +pathArray[0][1];
651 y = +pathArray[0][2];
655 res[0] = ["M", x, y];
657 for (var i = start, ii = pathArray[length]; i < ii; i++) {
660 if (pa[0] != upperCase.call(pa[0])) {
661 r[0] = upperCase.call(pa[0]);
682 for (var j = 1, jj = pa[length]; j < jj; j++) {
683 r[j] = +pa[j] + ((j % 2) ? x : y);
687 for (var k = 0, kk = pa[length]; k < kk; k++) {
703 mx = res[i][res[i][length] - 2];
704 my = res[i][res[i][length] - 1];
706 x = res[i][res[i][length] - 2];
707 y = res[i][res[i][length] - 1];
710 res[toString] = R._path2string;
713 l2c = function (x1, y1, x2, y2) {
714 return [x1, y1, x2, y2, x2, y2];
716 q2c = function (x1, y1, ax, ay, x2, y2) {
728 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
729 // for more information of where this math came from visit:
730 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
731 var _120 = PI * 120 / 180,
732 rad = PI / 180 * (+angle || 0),
735 rotate = cacher(function (x, y, rad) {
736 var X = x * math.cos(rad) - y * math.sin(rad),
737 Y = x * math.sin(rad) + y * math.cos(rad);
741 xy = rotate(x1, y1, -rad);
744 xy = rotate(x2, y2, -rad);
747 var cos = math.cos(PI / 180 * angle),
748 sin = math.sin(PI / 180 * angle),
751 var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
759 k = (large_arc_flag == sweep_flag ? -1 : 1) *
760 math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
761 cx = k * rx * y / ry + (x1 + x2) / 2,
762 cy = k * -ry * x / rx + (y1 + y2) / 2,
763 f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
764 f2 = math.asin(((y2 - cy) / ry).toFixed(9));
766 f1 = x1 < cx ? PI - f1 : f1;
767 f2 = x2 < cx ? PI - f2 : f2;
768 f1 < 0 && (f1 = PI * 2 + f1);
769 f2 < 0 && (f2 = PI * 2 + f2);
770 if (sweep_flag && f1 > f2) {
773 if (!sweep_flag && f2 > f1) {
783 if (abs(df) > _120) {
787 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
788 x2 = cx + rx * math.cos(f2);
789 y2 = cy + ry * math.sin(f2);
790 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
793 var c1 = math.cos(f1),
797 t = math.tan(df / 4),
801 m2 = [x1 + hx * s1, y1 - hy * c1],
802 m3 = [x2 + hx * s2, y2 - hy * c2],
804 m2[0] = 2 * m1[0] - m2[0];
805 m2[1] = 2 * m1[1] - m2[1];
807 return [m2, m3, m4][concat](res);
809 res = [m2, m3, m4][concat](res)[join]()[split](",");
811 for (var i = 0, ii = res[length]; i < ii; i++) {
812 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
817 findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
820 x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
821 y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
824 curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
825 var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
826 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
828 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
829 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
833 abs(t1) > "1e12" && (t1 = .5);
834 abs(t2) > "1e12" && (t2 = .5);
835 if (t1 > 0 && t1 < 1) {
836 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
840 if (t2 > 0 && t2 < 1) {
841 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
845 a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
846 b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
848 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
849 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
850 abs(t1) > "1e12" && (t1 = .5);
851 abs(t2) > "1e12" && (t2 = .5);
852 if (t1 > 0 && t1 < 1) {
853 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
857 if (t2 > 0 && t2 < 1) {
858 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
863 min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
864 max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
867 path2curve = cacher(function (path, path2) {
868 var p = pathToAbsolute(path),
869 p2 = path2 && pathToAbsolute(path2),
870 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
871 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
872 processPath = function (path, d) {
875 return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
877 !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
884 path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
887 nx = d.x + (d.x - (d.bx || d.x));
888 ny = d.y + (d.y - (d.by || d.y));
889 path = ["C", nx, ny][concat](path.slice(1));
892 d.qx = d.x + (d.x - (d.qx || d.x));
893 d.qy = d.y + (d.y - (d.qy || d.y));
894 path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
899 path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
902 path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
905 path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
908 path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
911 path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
916 fixArc = function (pp, i) {
917 if (pp[i][length] > 7) {
921 pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
924 ii = mmax(p[length], p2 && p2[length] || 0);
927 fixM = function (path1, path2, a1, a2, i) {
928 if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
929 path2.splice(i, 0, ["M", a2.x, a2.y]);
934 ii = mmax(p[length], p2 && p2[length] || 0);
937 for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) {
938 p[i] = processPath(p[i], attrs);
940 p2 && (p2[i] = processPath(p2[i], attrs2));
942 fixM(p, p2, attrs, attrs2, i);
943 fixM(p2, p, attrs2, attrs, i);
946 seglen = seg[length],
947 seg2len = p2 && seg2[length];
948 attrs.x = seg[seglen - 2];
949 attrs.y = seg[seglen - 1];
950 attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
951 attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
952 attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
953 attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
954 attrs2.x = p2 && seg2[seg2len - 2];
955 attrs2.y = p2 && seg2[seg2len - 1];
957 return p2 ? [p, p2] : p;
959 parseDots = cacher(function (gradient) {
961 for (var i = 0, ii = gradient[length]; i < ii; i++) {
963 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
964 dot.color = R.getRGB(par[1]);
965 if (dot.color.error) {
968 dot.color = dot.color.hex;
969 par[2] && (dot.offset = par[2] + "%");
972 for (i = 1, ii = dots[length] - 1; i < ii; i++) {
973 if (!dots[i].offset) {
974 var start = toFloat(dots[i - 1].offset || 0),
976 for (var j = i + 1; j < ii; j++) {
977 if (dots[j].offset) {
978 end = dots[j].offset;
987 var d = (end - start) / (j - i + 1);
990 dots[i].offset = start + "%";
996 getContainer = function (x, y, w, h) {
998 if (R.is(x, string) || R.is(x, "object")) {
999 container = R.is(x, string) ? doc.getElementById(x) : x;
1000 if (container.tagName) {
1003 container: container,
1004 width: container.style.pixelWidth || container.offsetWidth,
1005 height: container.style.pixelHeight || container.offsetHeight
1008 return {container: container, width: y, height: w};
1012 return {container: 1, x: x, y: y, width: w, height: h};
1015 plugins = function (con, add) {
1017 for (var prop in add) {
1018 if (add[has](prop) && !(prop in con)) {
1019 switch (typeof add[prop]) {
1022 con[prop] = con === that ? f : function () { return f[apply](that, arguments); };
1026 con[prop] = con[prop] || {};
1027 plugins.call(this, con[prop], add[prop]);
1030 con[prop] = add[prop];
1036 tear = function (el, paper) {
1037 el == paper.top && (paper.top = el.prev);
1038 el == paper.bottom && (paper.bottom = el.next);
1039 el.next && (el.next.prev = el.prev);
1040 el.prev && (el.prev.next = el.next);
1042 tofront = function (el, paper) {
1043 if (paper.top === el) {
1048 el.prev = paper.top;
1049 paper.top.next = el;
1052 toback = function (el, paper) {
1053 if (paper.bottom === el) {
1057 el.next = paper.bottom;
1059 paper.bottom.prev = el;
1062 insertafter = function (el, el2, paper) {
1064 el2 == paper.top && (paper.top = el);
1065 el2.next && (el2.next.prev = el);
1070 insertbefore = function (el, el2, paper) {
1072 el2 == paper.bottom && (paper.bottom = el);
1073 el2.prev && (el2.prev.next = el);
1078 removed = function (methodname) {
1079 return function () {
1080 throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
1083 R.pathToRelative = pathToRelative;
1086 paperproto.svgns = "http://www.w3.org/2000/svg";
1087 paperproto.xlink = "http://www.w3.org/1999/xlink";
1088 round = function (num) {
1089 return +num + (~~num === num) * .5;
1091 var $ = function (el, attr) {
1093 for (var key in attr) {
1094 if (attr[has](key)) {
1095 el[setAttribute](key, Str(attr[key]));
1099 el = doc.createElementNS(paperproto.svgns, el);
1100 el.style.webkitTapHighlightColor = "rgba(0,0,0,0)";
1104 R[toString] = function () {
1105 return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
1107 var thePath = function (pathString, SVG) {
1109 SVG.canvas && SVG.canvas[appendChild](el);
1110 var p = new Element(el, SVG);
1112 setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
1115 var addGradientFill = function (o, gradient, SVG) {
1116 var type = "linear",
1119 gradient = Str(gradient)[rp](radial_gradient, function (all, _fx, _fy) {
1124 var dir = ((fy > .5) * 2 - 1);
1125 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
1126 (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
1128 (fy = fy.toFixed(5) - 1e-5 * dir);
1132 gradient = gradient[split](/\s*\-\s*/);
1133 if (type == "linear") {
1134 var angle = gradient.shift();
1135 angle = -toFloat(angle);
1139 var vector = [0, 0, math.cos(angle * PI / 180), math.sin(angle * PI / 180)],
1140 max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
1143 if (vector[2] < 0) {
1144 vector[0] = -vector[2];
1147 if (vector[3] < 0) {
1148 vector[1] = -vector[3];
1152 var dots = parseDots(gradient);
1156 var id = o.getAttribute(fillString);
1157 id = id.match(/^url\(#(.*)\)$/);
1158 id && SVG.defs.removeChild(doc.getElementById(id[1]));
1160 var el = $(type + "Gradient");
1161 el.id = createUUID();
1162 $(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]});
1163 SVG.defs[appendChild](el);
1164 for (var i = 0, ii = dots[length]; i < ii; i++) {
1165 var stop = $("stop");
1167 offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%",
1168 "stop-color": dots[i].color || "#fff"
1170 el[appendChild](stop);
1173 fill: "url(#" + el.id + ")",
1182 var updatePosition = function (o) {
1183 var bbox = o.getBBox();
1184 $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
1186 var setFillAndStroke = function (o, params) {
1193 "-..": [3, 1, 1, 1, 1, 1],
1197 "- .": [4, 3, 1, 3],
1198 "--.": [8, 3, 1, 3],
1199 "--..": [8, 3, 1, 3, 1, 3]
1204 addDashes = function (o, value) {
1205 value = dasharray[lowerCase.call(value)];
1207 var width = o.attrs["stroke-width"] || "1",
1208 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
1210 var i = value[length];
1212 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
1214 $(node, {"stroke-dasharray": dashes[join](",")});
1217 params[has]("rotation") && (rot = params.rotation);
1218 var rotxy = Str(rot)[split](separator);
1219 if (!(rotxy.length - 1)) {
1222 rotxy[1] = +rotxy[1];
1223 rotxy[2] = +rotxy[2];
1225 toFloat(rot) && o.rotate(0, true);
1226 for (var att in params) {
1227 if (params[has](att)) {
1228 if (!availableAttrs[has](att)) {
1231 var value = params[att];
1238 o.rotate(value, true);
1243 var pn = node.parentNode;
1244 if (lowerCase.call(pn.tagName) != "a") {
1246 pn.insertBefore(hl, node);
1247 hl[appendChild](node);
1250 if (att == "target" && value == "blank") {
1251 pn.setAttributeNS(o.paper.xlink, "show", "new");
1253 pn.setAttributeNS(o.paper.xlink, att, value);
1257 node.style.cursor = value;
1260 var rect = Str(value)[split](separator);
1261 if (rect[length] == 4) {
1262 o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
1263 var el = $("clipPath"),
1265 el.id = createUUID();
1272 el[appendChild](rc);
1273 o.paper.defs[appendChild](el);
1274 $(node, {"clip-path": "url(#" + el.id + ")"});
1278 var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E));
1279 clip && clip.parentNode.removeChild(clip);
1280 $(node, {"clip-path": E});
1285 if (o.type == "path") {
1286 $(node, {d: value ? attrs.path = pathToAbsolute(value) : "M0,0"});
1290 node[setAttribute](att, value);
1299 value = -attrs.x - (attrs.width || 0);
1302 if (att == "rx" && o.type == "rect") {
1306 rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]);
1307 node[setAttribute](att, value);
1308 o.pattern && updatePosition(o);
1311 node[setAttribute](att, value);
1320 value = -attrs.y - (attrs.height || 0);
1323 if (att == "ry" && o.type == "rect") {
1327 rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]);
1328 node[setAttribute](att, value);
1329 o.pattern && updatePosition(o);
1332 if (o.type == "rect") {
1333 $(node, {rx: value, ry: value});
1335 node[setAttribute](att, value);
1339 if (o.type == "image") {
1340 node.setAttributeNS(o.paper.xlink, "href", value);
1343 case "stroke-width":
1344 node.style.strokeWidth = value;
1345 // Need following line for Firefox
1346 node[setAttribute](att, value);
1347 if (attrs["stroke-dasharray"]) {
1348 addDashes(o, attrs["stroke-dasharray"]);
1351 case "stroke-dasharray":
1352 addDashes(o, value);
1355 var xy = Str(value)[split](separator);
1356 xy[0] = +xy[0] || 0;
1357 xy[1] = +xy[1] || 0;
1362 translate.call(o, xy[0], xy[1]);
1365 xy = Str(value)[split](separator);
1366 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, isNaN(toFloat(xy[2])) ? null : +xy[2], isNaN(toFloat(xy[3])) ? null : +xy[3]);
1369 var isURL = Str(value).match(ISURL);
1372 var ig = $("image");
1373 el.id = createUUID();
1374 $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
1375 $(ig, {x: 0, y: 0});
1376 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1377 el[appendChild](ig);
1379 var img = doc.createElement("img");
1380 img.style.cssText = "position:absolute;left:-9999em;top-9999em";
1381 img.onload = function () {
1382 $(el, {width: this.offsetWidth, height: this.offsetHeight});
1383 $(ig, {width: this.offsetWidth, height: this.offsetHeight});
1384 doc.body.removeChild(this);
1387 doc.body[appendChild](img);
1389 o.paper.defs[appendChild](el);
1390 node.style.fill = "url(#" + el.id + ")";
1391 $(node, {fill: "url(#" + el.id + ")"});
1393 o.pattern && updatePosition(o);
1396 var clr = R.getRGB(value);
1398 delete params.gradient;
1399 delete attrs.gradient;
1400 !R.is(attrs.opacity, "undefined") &&
1401 R.is(params.opacity, "undefined") &&
1402 $(node, {opacity: attrs.opacity});
1403 !R.is(attrs["fill-opacity"], "undefined") &&
1404 R.is(params["fill-opacity"], "undefined") &&
1405 $(node, {"fill-opacity": attrs["fill-opacity"]});
1406 } else if ((({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper)) {
1407 attrs.gradient = value;
1408 attrs.fill = "none";
1411 clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
1413 clr = R.getRGB(value);
1414 node[setAttribute](att, clr.hex);
1415 att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
1418 (({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper);
1421 if (attrs.gradient && !attrs[has]("stroke-opacity")) {
1422 $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
1425 case "fill-opacity":
1426 if (attrs.gradient) {
1427 var gradient = doc.getElementById(node.getAttribute(fillString)[rp](/^url\(#|\)$/g, E));
1429 var stops = gradient.getElementsByTagName("stop");
1430 stops[stops[length] - 1][setAttribute]("stop-opacity", value);
1435 att == "font-size" && (value = toInt(value, 10) + "px");
1436 var cssrule = att[rp](/(\-.)/g, function (w) {
1437 return upperCase.call(w.substring(1));
1439 node.style[cssrule] = value;
1440 // Need following line for Firefox
1441 node[setAttribute](att, value);
1447 tuneText(o, params);
1449 o.rotate(rotxy.join(S));
1451 toFloat(rot) && o.rotate(rot, true);
1455 tuneText = function (el, params) {
1456 if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
1461 fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
1463 if (params[has]("text")) {
1464 a.text = params.text;
1465 while (node.firstChild) {
1466 node.removeChild(node.firstChild);
1468 var texts = Str(params.text)[split]("\n");
1469 for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) {
1470 var tspan = $("tspan");
1471 i && $(tspan, {dy: fontSize * leading, x: a.x});
1472 tspan[appendChild](doc.createTextNode(texts[i]));
1473 node[appendChild](tspan);
1476 texts = node.getElementsByTagName("tspan");
1477 for (i = 0, ii = texts[length]; i < ii; i++) {
1478 i && $(texts[i], {dy: fontSize * leading, x: a.x});
1482 var bb = el.getBBox(),
1483 dif = a.y - (bb.y + bb.height / 2);
1484 dif && R.is(dif, "finite") && $(node, {y: a.y + dif});
1486 Element = function (node, svg) {
1492 node.raphael = this;
1494 this.attrs = this.attrs || {};
1495 this.transformations = []; // rotate, translate, scale
1499 rt: {deg: 0, cx: 0, cy: 0},
1503 !svg.bottom && (svg.bottom = this);
1504 this.prev = svg.top;
1505 svg.top && (svg.top.next = this);
1509 var elproto = Element[proto];
1510 Element[proto].rotate = function (deg, cx, cy) {
1516 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
1518 return this._.rt.deg;
1520 var bbox = this.getBBox();
1521 deg = Str(deg)[split](separator);
1522 if (deg[length] - 1) {
1523 cx = toFloat(deg[1]);
1524 cy = toFloat(deg[2]);
1526 deg = toFloat(deg[0]);
1527 if (cx != null && cx !== false) {
1528 this._.rt.deg = deg;
1530 this._.rt.deg += deg;
1532 (cy == null) && (cx = null);
1535 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1536 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1537 if (this._.rt.deg) {
1538 this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
1539 this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
1541 this.transformations[0] = E;
1542 this.clip && $(this.clip, {transform: E});
1544 $(this.node, {transform: this.transformations[join](S)});
1547 Element[proto].hide = function () {
1548 !this.removed && (this.node.style.display = "none");
1551 Element[proto].show = function () {
1552 !this.removed && (this.node.style.display = "");
1555 Element[proto].remove = function () {
1559 tear(this, this.paper);
1560 this.node.parentNode.removeChild(this.node);
1561 for (var i in this) {
1564 this.removed = true;
1566 Element[proto].getBBox = function () {
1570 if (this.type == "path") {
1571 return pathDimensions(this.attrs.path);
1573 if (this.node.style.display == "none") {
1579 bbox = this.node.getBBox();
1581 // Firefox 3.0.x plays badly here
1585 if (this.type == "text") {
1586 bbox = {x: bbox.x, y: Infinity, width: 0, height: 0};
1587 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1588 var bb = this.node.getExtentOfChar(i);
1589 (bb.y < bbox.y) && (bbox.y = bb.y);
1590 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1591 (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x);
1594 hide && this.hide();
1597 Element[proto].attr = function (name, value) {
1603 for (var i in this.attrs) if (this.attrs[has](i)) {
1604 res[i] = this.attrs[i];
1606 this._.rt.deg && (res.rotation = this.rotate());
1607 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
1608 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
1611 if (value == null && R.is(name, string)) {
1612 if (name == "translation") {
1613 return translate.call(this);
1615 if (name == "rotation") {
1616 return this.rotate();
1618 if (name == "scale") {
1619 return this.scale();
1621 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
1622 return this.attrs.gradient;
1624 return this.attrs[name];
1626 if (value == null && R.is(name, array)) {
1628 for (var j = 0, jj = name.length; j < jj; j++) {
1629 values[name[j]] = this.attr(name[j]);
1633 if (value != null) {
1635 params[name] = value;
1636 } else if (name != null && R.is(name, "object")) {
1639 for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
1640 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
1641 this.attrs[key] = params[key];
1642 for (var subkey in par) if (par[has](subkey)) {
1643 params[subkey] = par[subkey];
1646 setFillAndStroke(this, params);
1649 Element[proto].toFront = function () {
1653 this.node.parentNode[appendChild](this.node);
1654 var svg = this.paper;
1655 svg.top != this && tofront(this, svg);
1658 Element[proto].toBack = function () {
1662 if (this.node.parentNode.firstChild != this.node) {
1663 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1664 toback(this, this.paper);
1665 var svg = this.paper;
1669 Element[proto].insertAfter = function (element) {
1673 var node = element.node || element[element.length - 1].node;
1674 if (node.nextSibling) {
1675 node.parentNode.insertBefore(this.node, node.nextSibling);
1677 node.parentNode[appendChild](this.node);
1679 insertafter(this, element, this.paper);
1682 Element[proto].insertBefore = function (element) {
1686 var node = element.node || element[0].node;
1687 node.parentNode.insertBefore(this.node, node);
1688 insertbefore(this, element, this.paper);
1691 Element[proto].blur = function (size) {
1692 // Experimental. No Safari support. Use it on your own risk.
1695 var fltr = $("filter"),
1696 blur = $("feGaussianBlur");
1697 t.attrs.blur = size;
1698 fltr.id = createUUID();
1699 $(blur, {stdDeviation: +size || 1.5});
1700 fltr.appendChild(blur);
1701 t.paper.defs.appendChild(fltr);
1703 $(t.node, {filter: "url(#" + fltr.id + ")"});
1706 t._blur.parentNode.removeChild(t._blur);
1708 delete t.attrs.blur;
1710 t.node.removeAttribute("filter");
1713 var theCircle = function (svg, x, y, r) {
1714 var el = $("circle");
1715 svg.canvas && svg.canvas[appendChild](el);
1716 var res = new Element(el, svg);
1717 res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1718 res.type = "circle";
1722 theRect = function (svg, x, y, w, h, r) {
1724 svg.canvas && svg.canvas[appendChild](el);
1725 var res = new Element(el, svg);
1726 res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1731 theEllipse = function (svg, x, y, rx, ry) {
1732 var el = $("ellipse");
1733 svg.canvas && svg.canvas[appendChild](el);
1734 var res = new Element(el, svg);
1735 res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1736 res.type = "ellipse";
1740 theImage = function (svg, src, x, y, w, h) {
1741 var el = $("image");
1742 $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1743 el.setAttributeNS(svg.xlink, "href", src);
1744 svg.canvas && svg.canvas[appendChild](el);
1745 var res = new Element(el, svg);
1746 res.attrs = {x: x, y: y, width: w, height: h, src: src};
1750 theText = function (svg, x, y, text) {
1752 $(el, {x: x, y: y, "text-anchor": "middle"});
1753 svg.canvas && svg.canvas[appendChild](el);
1754 var res = new Element(el, svg);
1755 res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
1757 setFillAndStroke(res, res.attrs);
1760 setSize = function (width, height) {
1761 this.width = width || this.width;
1762 this.height = height || this.height;
1763 this.canvas[setAttribute]("width", this.width);
1764 this.canvas[setAttribute]("height", this.height);
1767 create = function () {
1768 var con = getContainer[apply](0, arguments),
1769 container = con && con.container,
1773 height = con.height;
1775 throw new Error("SVG container not found.");
1777 var cnvs = $("svg");
1780 width = width || 512;
1781 height = height || 342;
1783 xmlns: "http://www.w3.org/2000/svg",
1788 if (container == 1) {
1789 cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
1790 doc.body[appendChild](cnvs);
1792 if (container.firstChild) {
1793 container.insertBefore(cnvs, container.firstChild);
1795 container[appendChild](cnvs);
1798 container = new Paper;
1799 container.width = width;
1800 container.height = height;
1801 container.canvas = cnvs;
1802 plugins.call(container, container, R.fn);
1806 paperproto.clear = function () {
1807 var c = this.canvas;
1808 while (c.firstChild) {
1809 c.removeChild(c.firstChild);
1811 this.bottom = this.top = null;
1812 (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl"));
1813 c[appendChild](this.desc);
1814 c[appendChild](this.defs = $("defs"));
1816 paperproto.remove = function () {
1817 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1818 for (var i in this) {
1819 this[i] = removed(i);
1826 var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
1827 bites = /([clmz]),?([^clmz]*)/gi,
1828 blurregexp = / progid:\S+Blur\([^\)]+\)/g,
1829 val = /-?[^,\s-]+/g,
1830 coordsize = 1e3 + S + 1e3,
1832 pathlike = {path: 1, rect: 1},
1833 path2vml = function (path) {
1834 var total = /[ahqstv]/ig,
1835 command = pathToAbsolute;
1836 Str(path).match(total) && (command = path2curve);
1838 if (command == pathToAbsolute && !Str(path).match(total)) {
1839 var res = Str(path)[rp](bites, function (all, command, args) {
1841 isMove = lowerCase.call(command) == "m",
1843 args[rp](val, function (value) {
1844 if (isMove && vals[length] == 2) {
1845 res += vals + map[command == "m" ? "l" : "L"];
1848 vals[push](round(value * zoom));
1854 var pa = command(path), p, r;
1856 for (var i = 0, ii = pa[length]; i < ii; i++) {
1858 r = lowerCase.call(pa[i][0]);
1859 r == "z" && (r = "x");
1860 for (var j = 1, jj = p[length]; j < jj; j++) {
1861 r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
1865 return res[join](S);
1868 R[toString] = function () {
1869 return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
1871 thePath = function (pathString, vml) {
1872 var g = createNode("group");
1873 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
1874 g.coordsize = vml.coordsize;
1875 g.coordorigin = vml.coordorigin;
1876 var el = createNode("shape"), ol = el.style;
1877 ol.width = vml.width + "px";
1878 ol.height = vml.height + "px";
1879 el.coordsize = coordsize;
1880 el.coordorigin = vml.coordorigin;
1882 var p = new Element(el, g, vml),
1883 attr = {fill: "none", stroke: "#000"};
1884 pathString && (attr.path = pathString);
1888 setFillAndStroke(p, attr);
1889 vml.canvas[appendChild](g);
1892 setFillAndStroke = function (o, params) {
1893 o.attrs = o.attrs || {};
1898 newpath = (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.r != a.r) && o.type == "rect",
1901 for (var par in params) if (params[has](par)) {
1902 a[par] = params[par];
1905 a.path = rectPath(a.x, a.y, a.width, a.height, a.r);
1911 params.href && (node.href = params.href);
1912 params.title && (node.title = params.title);
1913 params.target && (node.target = params.target);
1914 params.cursor && (s.cursor = params.cursor);
1915 "blur" in params && o.blur(params.blur);
1916 if (params.path && o.type == "path" || newpath) {
1917 node.path = path2vml(a.path);
1919 if (params.rotation != null) {
1920 o.rotate(params.rotation, true);
1922 if (params.translation) {
1923 xy = Str(params.translation)[split](separator);
1924 translate.call(o, xy[0], xy[1]);
1925 if (o._.rt.cx != null) {
1926 o._.rt.cx +=+ xy[0];
1927 o._.rt.cy +=+ xy[1];
1928 o.setBox(o.attrs, xy[0], xy[1]);
1932 xy = Str(params.scale)[split](separator);
1933 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1935 if ("clip-rect" in params) {
1936 var rect = Str(params["clip-rect"])[split](separator);
1937 if (rect[length] == 4) {
1938 rect[2] = +rect[2] + (+rect[0]);
1939 rect[3] = +rect[3] + (+rect[1]);
1940 var div = node.clipRect || doc.createElement("div"),
1942 group = node.parentNode;
1943 dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
1944 if (!node.clipRect) {
1945 dstyle.position = "absolute";
1948 dstyle.width = o.paper.width + "px";
1949 dstyle.height = o.paper.height + "px";
1950 group.parentNode.insertBefore(div, group);
1951 div[appendChild](group);
1952 node.clipRect = div;
1955 if (!params["clip-rect"]) {
1956 node.clipRect && (node.clipRect.style.clip = E);
1959 if (o.type == "image" && params.src) {
1960 node.src = params.src;
1962 if (o.type == "image" && params.opacity) {
1963 node.filterOpacity = ms + ".Alpha(opacity=" + (params.opacity * 100) + ")";
1964 s.filter = (node.filterMatrix || E) + (node.filterOpacity || E);
1966 params.font && (s.font = params.font);
1967 params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"');
1968 params["font-size"] && (s.fontSize = params["font-size"]);
1969 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1970 params["font-style"] && (s.fontStyle = params["font-style"]);
1971 if (params.opacity != null ||
1972 params["stroke-width"] != null ||
1973 params.fill != null ||
1974 params.stroke != null ||
1975 params["stroke-width"] != null ||
1976 params["stroke-opacity"] != null ||
1977 params["fill-opacity"] != null ||
1978 params["stroke-dasharray"] != null ||
1979 params["stroke-miterlimit"] != null ||
1980 params["stroke-linejoin"] != null ||
1981 params["stroke-linecap"] != null) {
1982 node = o.shape || node;
1983 var fill = (node.getElementsByTagName(fillString) && node.getElementsByTagName(fillString)[0]),
1985 !fill && (newfill = fill = createNode(fillString));
1986 if ("fill-opacity" in params || "opacity" in params) {
1987 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
1988 opacity = mmin(mmax(opacity, 0), 1);
1989 fill.opacity = opacity;
1991 params.fill && (fill.on = true);
1992 if (fill.on == null || params.fill == "none") {
1995 if (fill.on && params.fill) {
1996 var isURL = params.fill.match(ISURL);
1998 fill.src = isURL[1];
2001 fill.color = R.getRGB(params.fill).hex;
2003 fill.type = "solid";
2004 if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill)) {
2006 a.gradient = params.fill;
2010 newfill && node[appendChild](fill);
2011 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
2013 !stroke && (newstroke = stroke = createNode("stroke"));
2014 if ((params.stroke && params.stroke != "none") ||
2015 params["stroke-width"] ||
2016 params["stroke-opacity"] != null ||
2017 params["stroke-dasharray"] ||
2018 params["stroke-miterlimit"] ||
2019 params["stroke-linejoin"] ||
2020 params["stroke-linecap"]) {
2023 (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
2024 var strokeColor = R.getRGB(params.stroke);
2025 stroke.on && params.stroke && (stroke.color = strokeColor.hex);
2026 opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
2027 var width = (toFloat(params["stroke-width"]) || 1) * .75;
2028 opacity = mmin(mmax(opacity, 0), 1);
2029 params["stroke-width"] == null && (width = a["stroke-width"]);
2030 params["stroke-width"] && (stroke.weight = width);
2031 width && width < 1 && (opacity *= width) && (stroke.weight = 1);
2032 stroke.opacity = opacity;
2034 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
2035 stroke.miterlimit = params["stroke-miterlimit"] || 8;
2036 params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
2037 if (params["stroke-dasharray"]) {
2041 "-.": "shortdashdot",
2042 "-..": "shortdashdotdot",
2047 "--.": "longdashdot",
2048 "--..": "longdashdotdot"
2050 stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
2052 newstroke && node[appendChild](stroke);
2054 if (res.type == "text") {
2055 s = res.paper.span.style;
2056 a.font && (s.font = a.font);
2057 a["font-family"] && (s.fontFamily = a["font-family"]);
2058 a["font-size"] && (s.fontSize = a["font-size"]);
2059 a["font-weight"] && (s.fontWeight = a["font-weight"]);
2060 a["font-style"] && (s.fontStyle = a["font-style"]);
2061 res.node.string && (res.paper.span.innerHTML = Str(res.node.string)[rp](/</g, "<")[rp](/&/g, "&")[rp](/\n/g, "<br>"));
2062 res.W = a.w = res.paper.span.offsetWidth;
2063 res.H = a.h = res.paper.span.offsetHeight;
2065 res.Y = a.y + round(res.H / 2);
2067 // text-anchor emulationm
2068 switch (a["text-anchor"]) {
2070 res.node.style["v-text-align"] = "left";
2071 res.bbx = round(res.W / 2);
2074 res.node.style["v-text-align"] = "right";
2075 res.bbx = -round(res.W / 2);
2078 res.node.style["v-text-align"] = "center";
2083 addGradientFill = function (o, gradient) {
2084 o.attrs = o.attrs || {};
2085 var attrs = o.attrs,
2089 o.attrs.gradient = gradient;
2090 gradient = Str(gradient)[rp](radial_gradient, function (all, fx, fy) {
2095 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
2100 gradient = gradient[split](/\s*\-\s*/);
2101 if (type == "linear") {
2102 var angle = gradient.shift();
2103 angle = -toFloat(angle);
2108 var dots = parseDots(gradient);
2112 o = o.shape || o.node;
2113 fill = o.getElementsByTagName(fillString)[0] || createNode(fillString);
2114 !fill.parentNode && o.appendChild(fill);
2117 fill.method = "none";
2118 fill.color = dots[0].color;
2119 fill.color2 = dots[dots[length] - 1].color;
2121 for (var i = 0, ii = dots[length]; i < ii; i++) {
2122 dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color);
2124 fill.colors && (fill.colors.value = clrs[length] ? clrs[join]() : "0% " + fill.color);
2125 if (type == "radial") {
2126 fill.type = "gradientradial";
2127 fill.focus = "100%";
2128 fill.focussize = fxfy;
2129 fill.focusposition = fxfy;
2131 fill.type = "gradient";
2132 fill.angle = (270 - angle) % 360;
2137 Element = function (node, group, vml) {
2145 node.raphael = this;
2158 !vml.bottom && (vml.bottom = this);
2159 this.prev = vml.top;
2160 vml.top && (vml.top.next = this);
2164 elproto = Element[proto];
2165 elproto.rotate = function (deg, cx, cy) {
2171 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
2173 return this._.rt.deg;
2175 deg = Str(deg)[split](separator);
2176 if (deg[length] - 1) {
2177 cx = toFloat(deg[1]);
2178 cy = toFloat(deg[2]);
2180 deg = toFloat(deg[0]);
2182 this._.rt.deg = deg;
2184 this._.rt.deg += deg;
2186 cy == null && (cx = null);
2189 this.setBox(this.attrs, cx, cy);
2190 this.Group.style.rotation = this._.rt.deg;
2191 // gradient fix for rotation. TODO
2192 // var fill = (this.shape || this.node).getElementsByTagName(fillString);
2193 // fill = fill[0] || {};
2194 // var b = ((360 - this._.rt.deg) - 270) % 360;
2195 // !R.is(fill.angle, "undefined") && (fill.angle = b);
2198 elproto.setBox = function (params, cx, cy) {
2202 var gs = this.Group.style,
2203 os = (this.shape && this.shape.style) || this.node.style;
2204 params = params || {};
2205 for (var i in params) if (params[has](i)) {
2206 this.attrs[i] = params[i];
2208 cx = cx || this._.rt.cx;
2209 cy = cy || this._.rt.cy;
2210 var attr = this.attrs,
2215 switch (this.type) {
2217 x = attr.cx - attr.r;
2218 y = attr.cy - attr.r;
2222 x = attr.cx - attr.rx;
2223 y = attr.cy - attr.ry;
2230 w = attr.width || 0;
2231 h = attr.height || 0;
2234 this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
2235 x = attr.x - round(this.W / 2);
2236 y = attr.y - this.H / 2;
2242 if (!this.attrs.path) {
2245 w = this.paper.width;
2246 h = this.paper.height;
2248 var dim = pathDimensions(this.attrs.path);
2258 w = this.paper.width;
2259 h = this.paper.height;
2262 cx = (cx == null) ? x + w / 2 : cx;
2263 cy = (cy == null) ? y + h / 2 : cy;
2264 var left = cx - this.paper.width / 2,
2265 top = cy - this.paper.height / 2, t;
2266 gs.left != (t = left + "px") && (gs.left = t);
2267 gs.top != (t = top + "px") && (gs.top = t);
2268 this.X = pathlike[has](this.type) ? -left : x;
2269 this.Y = pathlike[has](this.type) ? -top : y;
2272 if (pathlike[has](this.type)) {
2273 os.left != (t = -left * zoom + "px") && (os.left = t);
2274 os.top != (t = -top * zoom + "px") && (os.top = t);
2275 } else if (this.type == "text") {
2276 os.left != (t = -left + "px") && (os.left = t);
2277 os.top != (t = -top + "px") && (os.top = t);
2279 gs.width != (t = this.paper.width + "px") && (gs.width = t);
2280 gs.height != (t = this.paper.height + "px") && (gs.height = t);
2281 os.left != (t = x - left + "px") && (os.left = t);
2282 os.top != (t = y - top + "px") && (os.top = t);
2283 os.width != (t = w + "px") && (os.width = t);
2284 os.height != (t = h + "px") && (os.height = t);
2287 elproto.hide = function () {
2288 !this.removed && (this.Group.style.display = "none");
2291 elproto.show = function () {
2292 !this.removed && (this.Group.style.display = "block");
2295 elproto.getBBox = function () {
2299 if (pathlike[has](this.type)) {
2300 return pathDimensions(this.attrs.path);
2303 x: this.X + (this.bbx || 0),
2309 elproto.remove = function () {
2313 tear(this, this.paper);
2314 this.node.parentNode.removeChild(this.node);
2315 this.Group.parentNode.removeChild(this.Group);
2316 this.shape && this.shape.parentNode.removeChild(this.shape);
2317 for (var i in this) {
2320 this.removed = true;
2322 elproto.attr = function (name, value) {
2328 for (var i in this.attrs) if (this.attrs[has](i)) {
2329 res[i] = this.attrs[i];
2331 this._.rt.deg && (res.rotation = this.rotate());
2332 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
2333 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
2336 if (value == null && R.is(name, "string")) {
2337 if (name == "translation") {
2338 return translate.call(this);
2340 if (name == "rotation") {
2341 return this.rotate();
2343 if (name == "scale") {
2344 return this.scale();
2346 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
2347 return this.attrs.gradient;
2349 return this.attrs[name];
2351 if (this.attrs && value == null && R.is(name, array)) {
2352 var ii, values = {};
2353 for (i = 0, ii = name[length]; i < ii; i++) {
2354 values[name[i]] = this.attr(name[i]);
2359 if (value != null) {
2361 params[name] = value;
2363 value == null && R.is(name, "object") && (params = name);
2365 for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
2366 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
2367 this.attrs[key] = params[key];
2368 for (var subkey in par) if (par[has](subkey)) {
2369 params[subkey] = par[subkey];
2372 if (params.text && this.type == "text") {
2373 this.node.string = params.text;
2375 setFillAndStroke(this, params);
2376 if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || Str(params.gradient).charAt() != "r")) {
2377 addGradientFill(this, params.gradient);
2379 (!pathlike[has](this.type) || this._.rt.deg) && this.setBox(this.attrs);
2383 elproto.toFront = function () {
2384 !this.removed && this.Group.parentNode[appendChild](this.Group);
2385 this.paper.top != this && tofront(this, this.paper);
2388 elproto.toBack = function () {
2392 if (this.Group.parentNode.firstChild != this.Group) {
2393 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2394 toback(this, this.paper);
2398 elproto.insertAfter = function (element) {
2402 if (element.constructor == Set) {
2403 element = element[element.length - 1];
2405 if (element.Group.nextSibling) {
2406 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2408 element.Group.parentNode[appendChild](this.Group);
2410 insertafter(this, element, this.paper);
2413 elproto.insertBefore = function (element) {
2417 if (element.constructor == Set) {
2418 element = element[0];
2420 element.Group.parentNode.insertBefore(this.Group, element.Group);
2421 insertbefore(this, element, this.paper);
2424 elproto.blur = function (size) {
2425 var s = this.node.runtimeStyle,
2427 f = f.replace(blurregexp, E);
2429 this.attrs.blur = size;
2430 s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
2431 s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
2435 delete this.attrs.blur;
2439 theCircle = function (vml, x, y, r) {
2440 var g = createNode("group"),
2441 o = createNode("oval"),
2443 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2444 g.coordsize = coordsize;
2445 g.coordorigin = vml.coordorigin;
2447 var res = new Element(o, g, vml);
2448 res.type = "circle";
2449 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2453 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2454 vml.canvas[appendChild](g);
2457 function rectPath(x, y, w, h, r) {
2459 return R.format("M{0},{1}l{2},0a{3},{3},0,0,1,{3},{3}l0,{5}a{3},{3},0,0,1,{4},{3}l{6},0a{3},{3},0,0,1,{4},{4}l0,{7}a{3},{3},0,0,1,{3},{4}z", x + r, y, w - r * 2, r, -r, h - r * 2, r * 2 - w, r * 2 - h);
2461 return R.format("M{0},{1}l{2},0,0,{3},{4},0z", x, y, w, h, -w);
2464 theRect = function (vml, x, y, w, h, r) {
2465 var path = rectPath(x, y, w, h, r),
2466 res = vml.path(path),
2470 res.W = a.width = w;
2471 res.H = a.height = h;
2477 theEllipse = function (vml, x, y, rx, ry) {
2478 var g = createNode("group"),
2479 o = createNode("oval"),
2481 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2482 g.coordsize = coordsize;
2483 g.coordorigin = vml.coordorigin;
2485 var res = new Element(o, g, vml);
2486 res.type = "ellipse";
2487 setFillAndStroke(res, {stroke: "#000"});
2492 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2493 vml.canvas[appendChild](g);
2496 theImage = function (vml, src, x, y, w, h) {
2497 var g = createNode("group"),
2498 o = createNode("image");
2499 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2500 g.coordsize = coordsize;
2501 g.coordorigin = vml.coordorigin;
2504 var res = new Element(o, g, vml);
2506 res.attrs.src = src;
2511 res.setBox({x: x, y: y, width: w, height: h});
2512 vml.canvas[appendChild](g);
2515 theText = function (vml, x, y, text) {
2516 var g = createNode("group"),
2517 el = createNode("shape"),
2519 path = createNode("path"),
2521 o = createNode("textpath");
2522 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2523 g.coordsize = coordsize;
2524 g.coordorigin = vml.coordorigin;
2525 path.v = R.format("m{0},{1}l{2},{1}", round(x * 10), round(y * 10), round(x * 10) + 1);
2526 path.textpathok = true;
2527 ol.width = vml.width;
2528 ol.height = vml.height;
2529 o.string = Str(text);
2532 el[appendChild](path);
2534 var res = new Element(o, g, vml);
2536 res.textpath = path;
2538 res.attrs.text = text;
2543 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2545 vml.canvas[appendChild](g);
2548 setSize = function (width, height) {
2549 var cs = this.canvas.style;
2550 width == +width && (width += "px");
2551 height == +height && (height += "px");
2554 cs.clip = "rect(0 " + width + " " + height + " 0)";
2558 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2560 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2561 createNode = function (tagName) {
2562 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2565 createNode = function (tagName) {
2566 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2569 create = function () {
2570 var con = getContainer[apply](0, arguments),
2571 container = con.container,
2572 height = con.height,
2578 throw new Error("VML container not found.");
2580 var res = new Paper,
2581 c = res.canvas = doc.createElement("div"),
2585 width = width || 512;
2586 height = height || 342;
2587 width == +width && (width += "px");
2588 height == +height && (height += "px");
2591 res.coordsize = zoom * 1e3 + S + zoom * 1e3;
2592 res.coordorigin = "0 0";
2593 res.span = doc.createElement("span");
2594 res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2595 c[appendChild](res.span);
2596 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);
2597 if (container == 1) {
2598 doc.body[appendChild](c);
2601 cs.position = "absolute";
2603 if (container.firstChild) {
2604 container.insertBefore(c, container.firstChild);
2606 container[appendChild](c);
2609 plugins.call(res, res, R.fn);
2612 paperproto.clear = function () {
2613 this.canvas.innerHTML = E;
2614 this.span = doc.createElement("span");
2615 this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2616 this.canvas[appendChild](this.span);
2617 this.bottom = this.top = null;
2619 paperproto.remove = function () {
2620 this.canvas.parentNode.removeChild(this.canvas);
2621 for (var i in this) {
2622 this[i] = removed(i);
2629 // WebKit rendering bug workaround method
2630 var version = navigator.userAgent.match(/Version\/(.*?)\s/);
2631 if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP")) {
2632 paperproto.safari = function () {
2633 var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
2634 win.setTimeout(function () {rect.remove();});
2637 paperproto.safari = function () {};
2641 var preventDefault = function () {
2642 this.returnValue = false;
2644 preventTouch = function () {
2645 return this.originalEvent.preventDefault();
2647 stopPropagation = function () {
2648 this.cancelBubble = true;
2650 stopTouch = function () {
2651 return this.originalEvent.stopPropagation();
2653 addEvent = (function () {
2654 if (doc.addEventListener) {
2655 return function (obj, type, fn, element) {
2656 var realName = supportsTouch && touchMap[type] ? touchMap[type] : type;
2657 var f = function (e) {
2658 if (supportsTouch && touchMap[has](type)) {
2659 for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
2660 if (e.targetTouches[i].target == obj) {
2662 e = e.targetTouches[i];
2663 e.originalEvent = olde;
2664 e.preventDefault = preventTouch;
2665 e.stopPropagation = stopTouch;
2670 return fn.call(element, e);
2672 obj.addEventListener(realName, f, false);
2673 return function () {
2674 obj.removeEventListener(realName, f, false);
2678 } else if (doc.attachEvent) {
2679 return function (obj, type, fn, element) {
2680 var f = function (e) {
2682 e.preventDefault = e.preventDefault || preventDefault;
2683 e.stopPropagation = e.stopPropagation || stopPropagation;
2684 return fn.call(element, e);
2686 obj.attachEvent("on" + type, f);
2687 var detacher = function () {
2688 obj.detachEvent("on" + type, f);
2696 dragMove = function (e) {
2699 scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2700 scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft,
2705 if (supportsTouch) {
2706 var i = e.touches.length,
2709 touch = e.touches[i];
2710 if (touch.identifier == dragi.el._drag.id) {
2713 (e.originalEvent ? e.originalEvent : e).preventDefault();
2722 dragi.move && dragi.move.call(dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e);
2725 dragUp = function (e) {
2726 R.unmousemove(dragMove).unmouseup(dragUp);
2727 var i = drag.length,
2731 dragi.el._drag = {};
2732 dragi.end && dragi.end.call(dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e);
2736 for (var i = events[length]; i--;) {
2737 (function (eventName) {
2738 R[eventName] = Element[proto][eventName] = function (fn, scope) {
2739 if (R.is(fn, "function")) {
2740 this.events = this.events || [];
2741 this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || doc, eventName, fn, scope || this)});
2745 R["un" + eventName] = Element[proto]["un" + eventName] = function (fn) {
2746 var events = this.events,
2748 while (l--) if (events[l].name == eventName && events[l].f == fn) {
2750 events.splice(l, 1);
2751 !events.length && delete this.events;
2758 elproto.hover = function (f_in, f_out, scope_in, scope_out) {
2759 return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in);
2761 elproto.unhover = function (f_in, f_out) {
2762 return this.unmouseover(f_in).unmouseout(f_out);
2764 elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) {
2766 this.mousedown(function (e) {
2767 (e.originalEvent || e).preventDefault();
2768 var scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2769 scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft;
2770 this._drag.x = e.clientX + scrollX;
2771 this._drag.y = e.clientY + scrollY;
2772 this._drag.id = e.identifier;
2773 onstart && onstart.call(start_scope || move_scope || this, e.clientX + scrollX, e.clientY + scrollY, e);
2774 !drag.length && R.mousemove(dragMove).mouseup(dragUp);
2775 drag.push({el: this, move: onmove, end: onend, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
2779 elproto.undrag = function (onmove, onstart, onend) {
2780 var i = drag.length;
2782 drag[i].el == this && (drag[i].move == onmove && drag[i].end == onend) && drag.splice(i++, 1);
2784 !drag.length && R.unmousemove(dragMove).unmouseup(dragUp);
2786 paperproto.circle = function (x, y, r) {
2787 return theCircle(this, x || 0, y || 0, r || 0);
2789 paperproto.rect = function (x, y, w, h, r) {
2790 return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
2792 paperproto.ellipse = function (x, y, rx, ry) {
2793 return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0);
2795 paperproto.path = function (pathString) {
2796 pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
2797 return thePath(R.format[apply](R, arguments), this);
2799 paperproto.image = function (src, x, y, w, h) {
2800 return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
2802 paperproto.text = function (x, y, text) {
2803 return theText(this, x || 0, y || 0, Str(text));
2805 paperproto.set = function (itemsArray) {
2806 arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length]));
2807 return new Set(itemsArray);
2809 paperproto.setSize = setSize;
2810 paperproto.top = paperproto.bottom = null;
2811 paperproto.raphael = R;
2813 return this.x + S + this.y;
2815 elproto.resetScale = function () {
2821 this.attrs.scale = "1 1";
2823 elproto.scale = function (x, y, cx, cy) {
2827 if (x == null && y == null) {
2842 var bb = this.getBBox(),
2843 rcx = bb.x + bb.width / 2,
2844 rcy = bb.y + bb.height / 2,
2845 kx = abs(x / this._.sx),
2846 ky = abs(y / this._.sy);
2847 cx = (+cx || cx == 0) ? cx : rcx;
2848 cy = (+cy || cy == 0) ? cy : rcy;
2849 var posx = this._.sx > 0,
2850 posy = this._.sy > 0,
2851 dirx = ~~(x / abs(x)),
2852 diry = ~~(y / abs(y)),
2855 s = this.node.style,
2856 ncx = cx + abs(rcx - cx) * dkx * (rcx > cx == posx ? 1 : -1),
2857 ncy = cy + abs(rcy - cy) * dky * (rcy > cy == posy ? 1 : -1),
2858 fr = (x * dirx > y * diry ? ky : kx);
2859 switch (this.type) {
2862 var neww = a.width * kx,
2863 newh = a.height * ky;
2889 var path = pathToRelative(a.path),
2891 fx = posx ? dkx : kx,
2892 fy = posy ? dky : ky;
2893 for (var i = 0, ii = path[length]; i < ii; i++) {
2895 P0 = upperCase.call(p[0]);
2896 if (P0 == "M" && skip) {
2902 p[path[i][length] - 2] *= fx;
2903 p[path[i][length] - 1] *= fy;
2906 p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
2907 } else if (P0 == "H") {
2908 for (var j = 1, jj = p[length]; j < jj; j++) {
2911 } else if (P0 == "V") {
2912 for (j = 1, jj = p[length]; j < jj; j++) {
2916 for (j = 1, jj = p[length]; j < jj; j++) {
2917 p[j] *= (j % 2) ? fx : fy;
2921 var dim2 = pathDimensions(path);
2922 dx = ncx - dim2.x - dim2.width / 2;
2923 dy = ncy - dim2.y - dim2.height / 2;
2926 this.attr({path: path});
2929 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2930 if (this.transformations) {
2931 this.transformations[2] = "scale("[concat](dirx, ",", diry, ")");
2932 this.node[setAttribute]("transform", this.transformations[join](S));
2933 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2934 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2935 this.attr({x: dx, y: dy});
2939 this.node.filterMatrix = ms + ".Matrix(M11="[concat](dirx,
2940 ", M12=0, M21=0, M22=", diry,
2941 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2942 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2945 if (this.transformations) {
2946 this.transformations[2] = E;
2947 this.node[setAttribute]("transform", this.transformations[join](S));
2951 this.node.filterMatrix = E;
2952 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2955 a.scale = [x, y, cx, cy][join](S);
2961 elproto.clone = function () {
2965 var attr = this.attr();
2967 delete attr.translation;
2968 return this.paper[this.type]().attr(attr);
2970 var curveslengths = {},
2971 getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
2974 name = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y].join(),
2975 cache = curveslengths[name],
2977 !cache && (curveslengths[name] = cache = {data: []});
2978 cache.timer && clearTimeout(cache.timer);
2979 cache.timer = setTimeout(function () {delete curveslengths[name];}, 2000);
2980 if (length != null) {
2981 var total = getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
2982 precision = ~~total * 10;
2984 for (var i = 0; i < precision + 1; i++) {
2985 if (cache.data[length] > i) {
2986 dot = cache.data[i * precision];
2988 dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i / precision);
2989 cache.data[i] = dot;
2991 i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
2992 if (length != null && len >= length) {
2997 if (length == null) {
3001 getLengthFactory = function (istotal, subpath) {
3002 return function (path, length, onlystart) {
3003 path = path2curve(path);
3004 var x, y, p, l, sp = "", subpaths = {}, point,
3006 for (var i = 0, ii = path.length; i < ii; i++) {
3012 l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
3013 if (len + l > length) {
3014 if (subpath && !subpaths.start) {
3015 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
3016 sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
3017 if (onlystart) {return sp;}
3018 subpaths.start = sp;
3019 sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join]();
3025 if (!istotal && !subpath) {
3026 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
3027 return {x: point.x, y: point.y, alpha: point.alpha};
3037 point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
3038 point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
3042 var getTotalLength = getLengthFactory(1),
3043 getPointAtLength = getLengthFactory(),
3044 getSubpathsAtLength = getLengthFactory(0, 1);
3045 elproto.getTotalLength = function () {
3046 if (this.type != "path") {return;}
3047 if (this.node.getTotalLength) {
3048 return this.node.getTotalLength();
3050 return getTotalLength(this.attrs.path);
3052 elproto.getPointAtLength = function (length) {
3053 if (this.type != "path") {return;}
3054 return getPointAtLength(this.attrs.path, length);
3056 elproto.getSubpath = function (from, to) {
3057 if (this.type != "path") {return;}
3058 if (abs(this.getTotalLength() - to) < "1e-6") {
3059 return getSubpathsAtLength(this.attrs.path, from).end;
3061 var a = getSubpathsAtLength(this.attrs.path, to, 1);
3062 return from ? getSubpathsAtLength(a, from).end : a;
3065 // animation easing formulas
3066 R.easing_formulas = {
3067 linear: function (n) {
3074 return pow(n - 1, 3) + 1;
3076 "<>": function (n) {
3079 return pow(n, 3) / 2;
3082 return (pow(n, 3) + 2) / 2;
3084 backIn: function (n) {
3086 return n * n * ((s + 1) * n - s);
3088 backOut: function (n) {
3091 return n * n * ((s + 1) * n + s) + 1;
3093 elastic: function (n) {
3094 if (n == 0 || n == 1) {
3099 return pow(2, -10 * n) * math.sin((n - s) * (2 * PI) / p) + 1;
3101 bounce: function (n) {
3110 l = s * n * n + .75;
3112 if (n < (2.5 / p)) {
3114 l = s * n * n + .9375;
3117 l = s * n * n + .984375;
3125 var animationElements = [],
3126 animation = function () {
3127 var Now = +new Date;
3128 for (var l = 0; l < animationElements[length]; l++) {
3129 var e = animationElements[l];
3130 if (e.stop || e.el.removed) {
3133 var time = Now - e.start,
3144 var pos = easing(time / ms);
3145 for (var attr in from) if (from[has](attr)) {
3146 switch (availableAnimAttrs[attr]) {
3148 now = pos * ms * diff[attr];
3149 to.back && (now = to.len - now);
3150 var point = getPointAtLength(to[attr], now);
3151 that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0);
3154 that.translate(point.x - diff.sx, point.y - diff.sy);
3155 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3158 now = +from[attr] + pos * ms * diff[attr];
3162 upto255(round(from[attr].r + pos * ms * diff[attr].r)),
3163 upto255(round(from[attr].g + pos * ms * diff[attr].g)),
3164 upto255(round(from[attr].b + pos * ms * diff[attr].b))
3169 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3170 now[i] = [from[attr][i][0]];
3171 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3172 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
3174 now[i] = now[i][join](S);
3181 var x = pos * ms * diff[attr][0] - t.x,
3182 y = pos * ms * diff[attr][1] - t.y;
3188 now = +from[attr][0] + pos * ms * diff[attr][0];
3189 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
3192 now = [+from[attr][0] + pos * ms * diff[attr][0], +from[attr][1] + pos * ms * diff[attr][1], (2 in to[attr] ? to[attr][2] : E), (3 in to[attr] ? to[attr][3] : E)][join](S);
3198 now[i] = +from[attr][i] + pos * ms * diff[attr][i];
3204 var from2 = [].concat(from[attr]);
3206 i = that.paper.customAttributes[attr].length;
3208 now[i] = +from2[i] + pos * ms * diff[attr][i];
3215 that._run && that._run.call(that);
3218 point = getPointAtLength(to.along, to.len * !to.back);
3219 that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy);
3220 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3222 (t.x || t.y) && that.translate(-t.x, -t.y);
3223 to.scale && (to.scale += E);
3225 animationElements.splice(l--, 1);
3228 R.svg && that && that.paper && that.paper.safari();
3229 animationElements[length] && setTimeout(animation);
3231 keyframesRun = function (attr, element, time, prev, prevcallback) {
3232 var dif = time - prev;
3233 element.timeouts.push(setTimeout(function () {
3234 R.is(prevcallback, "function") && prevcallback.call(element);
3235 element.animate(attr, dif, attr.easing);
3238 upto255 = function (color) {
3239 return mmax(mmin(color, 255), 0);
3241 translate = function (x, y) {
3243 return {x: this._.tx, y: this._.ty, toString: x_y};
3247 switch (this.type) {
3250 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
3255 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
3258 var path = pathToRelative(this.attrs.path);
3261 this.attr({path: path});
3266 elproto.animateWith = function (element, params, ms, easing, callback) {
3267 for (var i = 0, ii = animationElements.length; i < ii; i++) {
3268 if (animationElements[i].el.id == element.id) {
3269 params.start = animationElements[i].start;
3272 return this.animate(params, ms, easing, callback);
3274 elproto.animateAlong = along();
3275 elproto.animateAlongBack = along(1);
3276 function along(isBack) {
3277 return function (path, ms, rotate, callback) {
3278 var params = {back: isBack};
3279 R.is(rotate, "function") ? (callback = rotate) : (params.rot = rotate);
3280 path && path.constructor == Element && (path = path.attrs.path);
3281 path && (params.along = path);
3282 return this.animate(params, ms, callback);
3285 function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
3287 bx = 3 * (p2x - p1x) - cx,
3290 by = 3 * (p2y - p1y) - cy,
3292 function sampleCurveX(t) {
3293 return ((ax * t + bx) * t + cx) * t;
3295 function solve(x, epsilon) {
3296 var t = solveCurveX(x, epsilon);
3297 return ((ay * t + by) * t + cy) * t;
3299 function solveCurveX(x, epsilon) {
3300 var t0, t1, t2, x2, d2, i;
3301 for(t2 = x, i = 0; i < 8; i++) {
3302 x2 = sampleCurveX(t2) - x;
3303 if (abs(x2) < epsilon) {
3306 d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
3307 if (abs(d2) < 1e-6) {
3322 x2 = sampleCurveX(t2);
3323 if (abs(x2 - x) < epsilon) {
3331 t2 = (t1 - t0) / 2 + t0;
3335 return solve(t, 1 / (200 * duration));
3337 elproto.onAnimation = function (f) {
3341 elproto.animate = function (params, ms, easing, callback) {
3343 element.timeouts = element.timeouts || [];
3344 if (R.is(easing, "function") || !easing) {
3345 callback = easing || null;
3347 if (element.removed) {
3348 callback && callback.call(element);
3353 animateable = false,
3355 for (var attr in params) if (params[has](attr)) {
3356 if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
3358 from[attr] = element.attr(attr);
3359 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
3360 to[attr] = params[attr];
3361 switch (availableAnimAttrs[attr]) {
3363 var len = getTotalLength(params[attr]);
3364 var point = getPointAtLength(params[attr], len * !!params.back);
3365 var bb = element.getBBox();
3366 diff[attr] = len / ms;
3371 to.rot = params.rot;
3372 to.back = params.back;
3374 params.rot && (diff.r = toFloat(element.rotate()) || 0);
3377 diff[attr] = (to[attr] - from[attr]) / ms;
3380 from[attr] = R.getRGB(from[attr]);
3381 var toColour = R.getRGB(to[attr]);
3383 r: (toColour.r - from[attr].r) / ms,
3384 g: (toColour.g - from[attr].g) / ms,
3385 b: (toColour.b - from[attr].b) / ms
3389 var pathes = path2curve(from[attr], to[attr]);
3390 from[attr] = pathes[0];
3391 var toPath = pathes[1];
3393 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3394 diff[attr][i] = [0];
3395 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3396 diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
3401 var values = Str(params[attr])[split](separator),
3402 from2 = Str(from[attr])[split](separator);
3405 from[attr] = [0, 0];
3406 diff[attr] = [values[0] / ms, values[1] / ms];
3409 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
3410 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
3413 params[attr] = values;
3414 from[attr] = Str(from[attr])[split](separator);
3415 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
3418 from[attr] = Str(from[attr])[split](separator);
3422 diff[attr][i] = (values[i] - from[attr][i]) / ms;
3429 values = [].concat(params[attr]);
3430 from2 = [].concat(from[attr]);
3432 i = element.paper.customAttributes[attr][length];
3434 diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
3443 for (var key in params) if (params[has](key) && animKeyFrames.test(key)) {
3444 attr = {value: params[key]};
3445 key == "from" && (key = 0);
3446 key == "to" && (key = 100);
3447 attr.key = toInt(key, 10);
3450 attrs.sort(sortByKey);
3452 attrs.unshift({key: 0, value: element.attrs});
3454 for (i = 0, ii = attrs[length]; i < ii; i++) {
3455 keyframesRun(attrs[i].value, element, ms / 100 * attrs[i].key, ms / 100 * (attrs[i - 1] && attrs[i - 1].key || 0), attrs[i - 1] && attrs[i - 1].value.callback);
3457 lastcall = attrs[attrs[length] - 1].value.callback;
3459 element.timeouts.push(setTimeout(function () {lastcall.call(element);}, ms));
3462 var easyeasy = R.easing_formulas[easing];
3464 easyeasy = Str(easing).match(bezierrg);
3465 if (easyeasy && easyeasy[length] == 5) {
3466 var curve = easyeasy;
3467 easyeasy = function (t) {
3468 return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
3471 easyeasy = function (t) {
3476 animationElements.push({
3477 start: params.start || +new Date,
3486 R.is(callback, "function") && (element._ac = setTimeout(function () {
3487 callback.call(element);
3489 animationElements[length] == 1 && setTimeout(animation);
3493 elproto.stop = function () {
3494 for (var i = 0; i < animationElements.length; i++) {
3495 animationElements[i].el.id == this.id && animationElements.splice(i--, 1);
3497 for (i = 0, ii = this.timeouts && this.timeouts.length; i < ii; i++) {
3498 clearTimeout(this.timeouts[i]);
3501 clearTimeout(this._ac);
3505 elproto.translate = function (x, y) {
3506 return this.attr({translation: x + " " + y});
3508 elproto[toString] = function () {
3509 return "Rapha\xebl\u2019s object";
3511 R.ae = animationElements;
3514 var Set = function (items) {
3519 for (var i = 0, ii = items[length]; i < ii; i++) {
3520 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
3521 this[this.items[length]] = this.items[this.items[length]] = items[i];
3527 Set[proto][push] = function () {
3530 for (var i = 0, ii = arguments[length]; i < ii; i++) {
3531 item = arguments[i];
3532 if (item && (item.constructor == Element || item.constructor == Set)) {
3533 len = this.items[length];
3534 this[len] = this.items[len] = item;
3540 Set[proto].pop = function () {
3541 delete this[this[length]--];
3542 return this.items.pop();
3544 for (var method in elproto) if (elproto[has](method)) {
3545 Set[proto][method] = (function (methodname) {
3546 return function () {
3547 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3548 this.items[i][methodname][apply](this.items[i], arguments);
3554 Set[proto].attr = function (name, value) {
3555 if (name && R.is(name, array) && R.is(name[0], "object")) {
3556 for (var j = 0, jj = name[length]; j < jj; j++) {
3557 this.items[j].attr(name[j]);
3560 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3561 this.items[i].attr(name, value);
3566 Set[proto].animate = function (params, ms, easing, callback) {
3567 (R.is(easing, "function") || !easing) && (callback = easing || null);
3568 var len = this.items[length],
3573 callback && (collector = function () {
3574 !--len && callback.call(set);
3576 easing = R.is(easing, string) ? easing : collector;
3577 item = this.items[--i].animate(params, ms, easing, collector);
3579 this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, params, ms, easing, collector);
3583 Set[proto].insertAfter = function (el) {
3584 var i = this.items[length];
3586 this.items[i].insertAfter(el);
3590 Set[proto].getBBox = function () {
3595 for (var i = this.items[length]; i--;) {
3596 var box = this.items[i].getBBox();
3599 w[push](box.x + box.width);
3600 h[push](box.y + box.height);
3602 x = mmin[apply](0, x);
3603 y = mmin[apply](0, y);
3607 width: mmax[apply](0, w) - x,
3608 height: mmax[apply](0, h) - y
3611 Set[proto].clone = function (s) {
3613 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3614 s[push](this.items[i].clone());
3619 R.registerFont = function (font) {
3623 this.fonts = this.fonts || {};
3629 family = font.face["font-family"];
3630 for (var prop in font.face) if (font.face[has](prop)) {
3631 fontcopy.face[prop] = font.face[prop];
3633 if (this.fonts[family]) {
3634 this.fonts[family][push](fontcopy);
3636 this.fonts[family] = [fontcopy];
3639 fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
3640 for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
3641 var path = font.glyphs[glyph];
3642 fontcopy.glyphs[glyph] = {
3645 d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) {
3646 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
3650 for (var k in path.k) if (path[has](k)) {
3651 fontcopy.glyphs[glyph].k[k] = path.k[k];
3658 paperproto.getFont = function (family, weight, style, stretch) {
3659 stretch = stretch || "normal";
3660 style = style || "normal";
3661 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
3665 var font = R.fonts[family];
3667 var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
3668 for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
3669 if (name.test(fontName)) {
3670 font = R.fonts[fontName];
3677 for (var i = 0, ii = font[length]; i < ii; i++) {
3679 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
3686 paperproto.print = function (x, y, string, font, size, origin, letter_spacing) {
3687 origin = origin || "middle"; // baseline|middle
3688 letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
3689 var out = this.set(),
3690 letters = Str(string)[split](E),
3694 R.is(font, string) && (font = this.getFont(font));
3696 scale = (size || 16) / font.face["units-per-em"];
3697 var bb = font.face.bbox.split(separator),
3699 height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
3700 for (var i = 0, ii = letters[length]; i < ii; i++) {
3701 var prev = i && font.glyphs[letters[i - 1]] || {},
3702 curr = font.glyphs[letters[i]];
3703 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
3704 curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
3706 out.scale(scale, scale, top, height).translate(x - top, y - height);
3711 R.format = function (token, params) {
3712 var args = R.is(params, array) ? [0][concat](params) : arguments;
3713 token && R.is(token, string) && args[length] - 1 && (token = token[rp](formatrg, function (str, i) {
3714 return args[++i] == null ? E : args[i];
3718 R.ninja = function () {
3719 oldRaphael.was ? (win.Raphael = oldRaphael.is) : delete Raphael;
3725 oldRaphael.was ? (win.Raphael = R) : (Raphael = R);
3727 * g.Raphael 0.4.1 - Charting library, based on Raphaël
3729 * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com)
3730 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
3735 var mmax = Math.max,
3737 Raphael.fn.g = Raphael.fn.g || {};
3738 Raphael.fn.g.markers = {
3747 triangle: "triangle",
3758 Raphael.fn.g.shim = {stroke: "none", fill: "#000", "fill-opacity": 0};
3759 Raphael.fn.g.txtattr = {font: "12px Arial, sans-serif"};
3760 Raphael.fn.g.colors = [];
3761 var hues = [.6, .2, .05, .1333, .75, 0];
3762 for (var i = 0; i < 10; i++) {
3763 if (i < hues.length) {
3764 Raphael.fn.g.colors.push("hsb(" + hues[i] + ", .75, .75)");
3766 Raphael.fn.g.colors.push("hsb(" + hues[i - hues.length] + ", 1, .5)");
3769 Raphael.fn.g.text = function (x, y, text) {
3770 return this.text(x, y, text).attr(this.g.txtattr);
3772 Raphael.fn.g.labelise = function (label, val, total) {
3774 return (label + "").replace(/(##+(?:\.#+)?)|(%%+(?:\.%+)?)/g, function (all, value, percent) {
3776 return (+val).toFixed(value.replace(/^#+\.?/g, "").length);
3779 return (val * 100 / total).toFixed(percent.replace(/^%+\.?/g, "").length) + "%";
3783 return (+val).toFixed(0);
3787 Raphael.fn.g.finger = function (x, y, width, height, dir, ending, isPath) {
3788 // dir 0 for horisontal and 1 for vertical
3789 if ((dir && !height) || (!dir && !width)) {
3790 return isPath ? "" : this.path();
3792 ending = {square: "square", sharp: "sharp", soft: "soft"}[ending] || "round";
3794 height = Math.round(height);
3795 width = Math.round(width);
3801 var r = ~~(height / 2);
3804 path = ["M", x + .5, y + .5 - ~~(height / 2), "l", 0, 0, "a", r, ~~(height / 2), 0, 0, 1, 0, height, "l", 0, 0, "z"];
3806 path = ["M", x + .5, y + .5 - r, "l", width - r, 0, "a", r, r, 0, 1, 1, 0, height, "l", r - width, 0, "z"];
3812 path = ["M", x - ~~(width / 2), y, "l", 0, 0, "a", ~~(width / 2), r, 0, 0, 1, width, 0, "l", 0, 0, "z"];
3814 path = ["M", x - r, y, "l", 0, r - height, "a", r, r, 0, 1, 1, width, 0, "l", 0, height - r, "z"];
3820 var half = ~~(height / 2);
3821 path = ["M", x, y + half, "l", 0, -height, mmax(width - half, 0), 0, mmin(half, width), half, -mmin(half, width), half + (half * 2 < height), "z"];
3823 half = ~~(width / 2);
3824 path = ["M", x + half, y, "l", -width, 0, 0, -mmax(height - half, 0), half, -mmin(half, height), half, mmin(half, height), half, "z"];
3829 path = ["M", x, y + ~~(height / 2), "l", 0, -height, width, 0, 0, height, "z"];
3831 path = ["M", x + ~~(width / 2), y, "l", 1 - width, 0, 0, -height, width - 1, 0, "z"];
3836 r = mmin(width, Math.round(height / 5));
3837 path = ["M", x + .5, y + .5 - ~~(height / 2), "l", width - r, 0, "a", r, r, 0, 0, 1, r, r, "l", 0, height - r * 2, "a", r, r, 0, 0, 1, -r, r, "l", r - width, 0, "z"];
3839 r = mmin(Math.round(width / 5), height);
3840 path = ["M", x - ~~(width / 2), y, "l", 0, r - height, "a", r, r, 0, 0, 1, r, -r, "l", width - 2 * r, 0, "a", r, r, 0, 0, 1, r, r, "l", 0, height - r, "z"];
3844 return path.join(",");
3846 return this.path(path);
3851 Raphael.fn.g.disc = function (cx, cy, r) {
3852 return this.circle(cx, cy, r);
3854 Raphael.fn.g.line = function (cx, cy, r) {
3855 return this.rect(cx - r, cy - r / 5, 2 * r, 2 * r / 5);
3857 Raphael.fn.g.square = function (cx, cy, r) {
3859 return this.rect(cx - r, cy - r, 2 * r, 2 * r);
3861 Raphael.fn.g.triangle = function (cx, cy, r) {
3863 return this.path("M".concat(cx, ",", cy, "m0-", r * .58, "l", r * .5, ",", r * .87, "-", r, ",0z"));
3865 Raphael.fn.g.diamond = function (cx, cy, r) {
3866 return this.path(["M", cx, cy - r, "l", r, r, -r, r, -r, -r, r, -r, "z"]);
3868 Raphael.fn.g.flower = function (cx, cy, r, n) {
3872 n = +n < 3 || !n ? 5 : n;
3873 var points = ["M", cx, cy + rin, "Q"],
3875 for (var i = 1; i < n * 2 + 1; i++) {
3876 R = i % 2 ? rout : rin;
3877 points = points.concat([+(cx + R * Math.sin(i * Math.PI / n)).toFixed(3), +(cy + R * Math.cos(i * Math.PI / n)).toFixed(3)]);
3880 return this.path(points.join(","));
3882 Raphael.fn.g.star = function (cx, cy, r, r2, rays) {
3883 r2 = r2 || r * .382;
3885 var points = ["M", cx, cy + r2, "L"],
3887 for (var i = 1; i < rays * 2; i++) {
3889 points = points.concat([(cx + R * Math.sin(i * Math.PI / rays)), (cy + R * Math.cos(i * Math.PI / rays))]);
3892 return this.path(points.join(","));
3894 Raphael.fn.g.cross = function (cx, cy, r) {
3896 return this.path("M".concat(cx - r, ",", cy, "l", [-r, -r, r, -r, r, r, r, -r, r, r, -r, r, r, r, -r, r, -r, -r, -r, r, -r, -r, "z"]));
3898 Raphael.fn.g.plus = function (cx, cy, r) {
3900 return this.path("M".concat(cx - r / 2, ",", cy - r / 2, "l", [0, -r, r, 0, 0, r, r, 0, 0, r, -r, 0, 0, r, -r, 0, 0, -r, -r, 0, 0, -r, "z"]));
3902 Raphael.fn.g.arrow = function (cx, cy, r) {
3903 return this.path("M".concat(cx - r * .7, ",", cy - r * .4, "l", [r * .6, 0, 0, -r * .4, r, r * .8, -r, r * .8, 0, -r * .4, -r * .6, 0], "z"));
3907 Raphael.fn.g.tag = function (x, y, text, angle, r) {
3909 r = r == null ? 5 : r;
3910 text = text == null ? "$9.99" : text;
3914 res.push(this.path().attr({fill: "#000", stroke: "#000"}));
3915 res.push(this.text(x, y, text).attr(this.g.txtattr).attr({fill: "#fff", "font-family": "Helvetica, Arial"}));
3916 res.update = function () {
3917 this.rotate(0, x, y);
3918 var bb = this[1].getBBox();
3919 if (bb.height >= r * 2) {
3920 this[0].attr({path: ["M", x, y + r, "a", r, r, 0, 1, 1, 0, -r * 2, r, r, 0, 1, 1, 0, r * 2, "m", 0, -r * 2 -d, "a", r + d, r + d, 0, 1, 0, 0, (r + d) * 2, "L", x + r + d, y + bb.height / 2 + d, "l", bb.width + 2 * d, 0, 0, -bb.height - 2 * d, -bb.width - 2 * d, 0, "L", x, y - r - d].join(",")});
3922 var dx = Math.sqrt(Math.pow(r + d, 2) - Math.pow(bb.height / 2 + d, 2));
3923 this[0].attr({path: ["M", x, y + r, "c", -R, 0, -r, R - r, -r, -r, 0, -R, r - R, -r, r, -r, R, 0, r, r - R, r, r, 0, R, R - r, r, -r, r, "M", x + dx, y - bb.height / 2 - d, "a", r + d, r + d, 0, 1, 0, 0, bb.height + 2 * d, "l", r + d - dx + bb.width + 2 * d, 0, 0, -bb.height - 2 * d, "L", x + dx, y - bb.height / 2 - d].join(",")});
3925 this[1].attr({x: x + r + d + bb.width / 2, y: y});
3926 angle = (360 - angle) % 360;
3927 this.rotate(angle, x, y);
3928 angle > 90 && angle < 270 && this[1].attr({x: x - r - d - bb.width / 2, y: y, rotation: [180 + angle, x, y]});
3934 Raphael.fn.g.popupit = function (x, y, set, dir, size) {
3935 dir = dir == null ? 2 : dir;
3939 var bb = set.getBBox(),
3940 w = Math.round(bb.width / 2),
3941 h = Math.round(bb.height / 2),
3942 dx = [0, w + size * 2, 0, -w - size * 2],
3943 dy = [-h * 2 - size * 3, -h - size, 0, -h - size],
3944 p = ["M", x - dx[dir], y - dy[dir], "l", -size, (dir == 2) * -size, -mmax(w - size, 0), 0, "a", size, size, 0, 0, 1, -size, -size,
3945 "l", 0, -mmax(h - size, 0), (dir == 3) * -size, -size, (dir == 3) * size, -size, 0, -mmax(h - size, 0), "a", size, size, 0, 0, 1, size, -size,
3946 "l", mmax(w - size, 0), 0, size, !dir * -size, size, !dir * size, mmax(w - size, 0), 0, "a", size, size, 0, 0, 1, size, size,
3947 "l", 0, mmax(h - size, 0), (dir == 1) * size, size, (dir == 1) * -size, size, 0, mmax(h - size, 0), "a", size, size, 0, 0, 1, -size, size,
3948 "l", -mmax(w - size, 0), 0, "z"].join(","),
3949 xy = [{x: x, y: y + size * 2 + h}, {x: x - size * 2 - w, y: y}, {x: x, y: y - size * 2 - h}, {x: x + size * 2 + w, y: y}][dir];
3950 set.translate(xy.x - w - bb.x, xy.y - h - bb.y);
3951 return this.path(p).attr({fill: "#000", stroke: "none"}).insertBefore(set.node ? set : set[0]);
3953 Raphael.fn.g.popup = function (x, y, text, dir, size) {
3954 dir = dir == null ? 2 : dir > 3 ? 3 : dir;
3956 text = text || "$9.99";
3957 var res = this.set(),
3959 res.push(this.path().attr({fill: "#000", stroke: "#000"}));
3960 res.push(this.text(x, y, text).attr(this.g.txtattr).attr({fill: "#fff", "font-family": "Helvetica, Arial"}));
3961 res.update = function (X, Y, withAnimation) {
3964 var bb = this[1].getBBox(),
3967 dx = [0, w + size * 2, 0, -w - size * 2],
3968 dy = [-h * 2 - size * 3, -h - size, 0, -h - size],
3969 p = ["M", X - dx[dir], Y - dy[dir], "l", -size, (dir == 2) * -size, -mmax(w - size, 0), 0, "a", size, size, 0, 0, 1, -size, -size,
3970 "l", 0, -mmax(h - size, 0), (dir == 3) * -size, -size, (dir == 3) * size, -size, 0, -mmax(h - size, 0), "a", size, size, 0, 0, 1, size, -size,
3971 "l", mmax(w - size, 0), 0, size, !dir * -size, size, !dir * size, mmax(w - size, 0), 0, "a", size, size, 0, 0, 1, size, size,
3972 "l", 0, mmax(h - size, 0), (dir == 1) * size, size, (dir == 1) * -size, size, 0, mmax(h - size, 0), "a", size, size, 0, 0, 1, -size, size,
3973 "l", -mmax(w - size, 0), 0, "z"].join(","),
3974 xy = [{x: X, y: Y + size * 2 + h}, {x: X - size * 2 - w, y: Y}, {x: X, y: Y - size * 2 - h}, {x: X + size * 2 + w, y: Y}][dir];
3976 if (withAnimation) {
3977 this.animate(xy, 500, ">");
3983 return res.update(x, y);
3985 Raphael.fn.g.flag = function (x, y, text, angle) {
3987 text = text || "$9.99";
3988 var res = this.set(),
3990 res.push(this.path().attr({fill: "#000", stroke: "#000"}));
3991 res.push(this.text(x, y, text).attr(this.g.txtattr).attr({fill: "#fff", "font-family": "Helvetica, Arial"}));
3992 res.update = function (x, y) {
3993 this.rotate(0, x, y);
3994 var bb = this[1].getBBox(),
3996 this[0].attr({path: ["M", x, y, "l", h + d, -h - d, bb.width + 2 * d, 0, 0, bb.height + 2 * d, -bb.width - 2 * d, 0, "z"].join(",")});
3997 this[1].attr({x: x + h + d + bb.width / 2, y: y});
3998 angle = 360 - angle;
3999 this.rotate(angle, x, y);
4000 angle > 90 && angle < 270 && this[1].attr({x: x - r - d - bb.width / 2, y: y, rotation: [180 + angle, x, y]});
4003 return res.update(x, y);
4005 Raphael.fn.g.label = function (x, y, text) {
4006 var res = this.set();
4007 res.push(this.rect(x, y, 10, 10).attr({stroke: "none", fill: "#000"}));
4008 res.push(this.text(x, y, text).attr(this.g.txtattr).attr({fill: "#fff"}));
4009 res.update = function () {
4010 var bb = this[1].getBBox(),
4011 r = mmin(bb.width + 10, bb.height + 10) / 2;
4012 this[0].attr({x: bb.x - r / 2, y: bb.y - r / 2, width: bb.width + r, height: bb.height + r, r: r});
4017 Raphael.fn.g.labelit = function (set) {
4018 var bb = set.getBBox(),
4019 r = mmin(20, bb.width + 10, bb.height + 10) / 2;
4020 return this.rect(bb.x - r / 2, bb.y - r / 2, bb.width + r, bb.height + r, r).attr({stroke: "none", fill: "#000"}).insertBefore(set.node ? set : set[0]);
4022 Raphael.fn.g.drop = function (x, y, text, size, angle) {
4025 var res = this.set();
4026 res.push(this.path(["M", x, y, "l", size, 0, "A", size * .4, size * .4, 0, 1, 0, x + size * .7, y - size * .7, "z"]).attr({fill: "#000", stroke: "none", rotation: [22.5 - angle, x, y]}));
4027 angle = (angle + 90) * Math.PI / 180;
4028 res.push(this.text(x + size * Math.sin(angle), y + size * Math.cos(angle), text).attr(this.g.txtattr).attr({"font-size": size * 12 / 30, fill: "#fff"}));
4033 Raphael.fn.g.blob = function (x, y, text, angle, size) {
4034 angle = (+angle + 1 ? angle : 45) + 90;
4036 var rad = Math.PI / 180,
4037 fontSize = size * 12 / 12;
4038 var res = this.set();
4039 res.push(this.path().attr({fill: "#000", stroke: "none"}));
4040 res.push(this.text(x + size * Math.sin((angle) * rad), y + size * Math.cos((angle) * rad) - fontSize / 2, text).attr(this.g.txtattr).attr({"font-size": fontSize, fill: "#fff"}));
4041 res.update = function (X, Y, withAnimation) {
4044 var bb = this[1].getBBox(),
4045 w = mmax(bb.width + fontSize, size * 25 / 12),
4046 h = mmax(bb.height + fontSize, size * 25 / 12),
4047 x2 = X + size * Math.sin((angle - 22.5) * rad),
4048 y2 = Y + size * Math.cos((angle - 22.5) * rad),
4049 x1 = X + size * Math.sin((angle + 22.5) * rad),
4050 y1 = Y + size * Math.cos((angle + 22.5) * rad),
4055 k = -Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * dy * dy - ry * ry * dx * dx) / (rx * rx * dy * dy + ry * ry * dx * dx)),
4056 cx = k * rx * dy / ry + (x1 + x2) / 2,
4057 cy = k * -ry * dx / rx + (y1 + y2) / 2;
4058 if (withAnimation) {
4059 this.animate({x: cx, y: cy, path: ["M", x, y, "L", x1, y1, "A", rx, ry, 0, 1, 1, x2, y2, "z"].join(",")}, 500, ">");
4061 this.attr({x: cx, y: cy, path: ["M", x, y, "L", x1, y1, "A", rx, ry, 0, 1, 1, x2, y2, "z"].join(",")});
4069 Raphael.fn.g.colorValue = function (value, total, s, b) {
4070 return "hsb(" + [mmin((1 - value / total) * .4, 1), s || .75, b || .75] + ")";
4073 Raphael.fn.g.snapEnds = function (from, to, steps) {
4077 return {from: f, to: t, power: 0};
4080 return Math.abs(a - .5) < .25 ? ~~(a) + .5 : Math.round(a);
4082 var d = (t - f) / steps,
4089 R = ~~(d * Math.pow(10, i)) / Math.pow(10, i);
4095 r = ~~(d * Math.pow(10, i)) / Math.pow(10, i);
4100 t = round(to * Math.pow(10, i)) / Math.pow(10, i);
4102 t = round((to + .5) * Math.pow(10, i)) / Math.pow(10, i);
4104 f = round((from - (i > 0 ? 0 : .5)) * Math.pow(10, i)) / Math.pow(10, i);
4105 return {from: f, to: t, power: i};
4107 Raphael.fn.g.axis = function (x, y, length, from, to, steps, orientation, labels, type, dashsize) {
4108 dashsize = dashsize == null ? 2 : dashsize;
4110 steps = steps || 10;
4111 var path = type == "|" || type == " " ? ["M", x + .5, y, "l", 0, .001] : orientation == 1 || orientation == 3 ? ["M", x + .5, y, "l", 0, -length] : ["M", x, y + .5, "l", length, 0],
4112 ends = this.g.snapEnds(from, to, steps),
4118 d = (t - f) / steps;
4120 rnd = i > 0 ? i : 0;
4121 dx = length / steps;
4122 if (+orientation == 1 || +orientation == 3) {
4124 addon = (orientation - 1 ? 1 : -1) * (dashsize + 3 + !!(orientation - 1));
4125 while (Y >= y - length) {
4126 type != "-" && type != " " && (path = path.concat(["M", x - (type == "+" || type == "|" ? dashsize : !(orientation - 1) * dashsize * 2), Y + .5, "l", dashsize * 2 + 1, 0]));
4127 text.push(this.text(x + addon, Y, (labels && labels[j++]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(this.g.txtattr).attr({"text-anchor": orientation - 1 ? "start" : "end"}));
4131 if (Math.round(Y + dx - (y - length))) {
4132 type != "-" && type != " " && (path = path.concat(["M", x - (type == "+" || type == "|" ? dashsize : !(orientation - 1) * dashsize * 2), y - length + .5, "l", dashsize * 2 + 1, 0]));
4133 text.push(this.text(x + addon, y - length, (labels && labels[j]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(this.g.txtattr).attr({"text-anchor": orientation - 1 ? "start" : "end"}));
4138 addon = (orientation ? -1 : 1) * (dashsize + 9 + !orientation);
4140 dx = length / steps,
4143 while (X <= x + length) {
4144 type != "-" && type != " " && (path = path.concat(["M", X + .5, y - (type == "+" ? dashsize : !!orientation * dashsize * 2), "l", 0, dashsize * 2 + 1]));
4145 text.push(txt = this.text(X, y + addon, (labels && labels[j++]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(this.g.txtattr));
4146 var bb = txt.getBBox();
4147 if (prev >= bb.x - 5) {
4148 text.pop(text.length - 1).remove();
4150 prev = bb.x + bb.width;
4155 if (Math.round(X - dx - x - length)) {
4156 type != "-" && type != " " && (path = path.concat(["M", x + length + .5, y - (type == "+" ? dashsize : !!orientation * dashsize * 2), "l", 0, dashsize * 2 + 1]));
4157 text.push(this.text(x + length, y + addon, (labels && labels[j]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(this.g.txtattr));
4160 var res = this.path(path);
4162 res.all = this.set([res, text]);
4163 res.remove = function () {
4165 this.constructor.prototype.remove.call(this);
4170 Raphael.el.lighter = function (times) {
4172 var fs = [this.attrs.fill, this.attrs.stroke];
4173 this.fs = this.fs || [fs[0], fs[1]];
4174 fs[0] = Raphael.rgb2hsb(Raphael.getRGB(fs[0]).hex);
4175 fs[1] = Raphael.rgb2hsb(Raphael.getRGB(fs[1]).hex);
4176 fs[0].b = mmin(fs[0].b * times, 1);
4177 fs[0].s = fs[0].s / times;
4178 fs[1].b = mmin(fs[1].b * times, 1);
4179 fs[1].s = fs[1].s / times;
4180 this.attr({fill: "hsb(" + [fs[0].h, fs[0].s, fs[0].b] + ")", stroke: "hsb(" + [fs[1].h, fs[1].s, fs[1].b] + ")"});
4182 Raphael.el.darker = function (times) {
4184 var fs = [this.attrs.fill, this.attrs.stroke];
4185 this.fs = this.fs || [fs[0], fs[1]];
4186 fs[0] = Raphael.rgb2hsb(Raphael.getRGB(fs[0]).hex);
4187 fs[1] = Raphael.rgb2hsb(Raphael.getRGB(fs[1]).hex);
4188 fs[0].s = mmin(fs[0].s * times, 1);
4189 fs[0].b = fs[0].b / times;
4190 fs[1].s = mmin(fs[1].s * times, 1);
4191 fs[1].b = fs[1].b / times;
4192 this.attr({fill: "hsb(" + [fs[0].h, fs[0].s, fs[0].b] + ")", stroke: "hsb(" + [fs[1].h, fs[1].s, fs[1].b] + ")"});
4194 Raphael.el.original = function () {
4196 this.attr({fill: this.fs[0], stroke: this.fs[1]});
4201 * g.Raphael 0.4.1 - Charting library, based on Raphaël
4203 * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com)
4204 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
4206 Raphael.fn.g.barchart = function (x, y, width, height, values, opts) {
4208 var type = {round: "round", sharp: "sharp", soft: "soft"}[opts.type] || "square",
4209 gutter = parseFloat(opts.gutter || "20%"),
4212 covers = this.set(),
4213 covers2 = this.set(),
4214 total = Math.max.apply(Math, values),
4218 colors = opts.colors || this.g.colors,
4219 len = values.length;
4220 if (this.raphael.is(values[0], "array")) {
4224 for (var i = values.length; i--;) {
4225 bars.push(this.set());
4226 total.push(Math.max.apply(Math, values[i]));
4227 len = Math.max(len, values[i].length);
4230 for (var i = len; i--;) {
4232 for (var j = values.length; j--;) {
4233 tot +=+ values[j][i] || 0;
4235 stacktotal.push(tot);
4238 for (var i = values.length; i--;) {
4239 if (values[i].length < len) {
4240 for (var j = len; j--;) {
4245 total = Math.max.apply(Math, opts.stacked ? stacktotal : total);
4248 total = (opts.to) || total;
4249 var barwidth = width / (len * (100 + gutter) + gutter) * 100,
4250 barhgutter = barwidth * gutter / 100,
4251 barvgutter = opts.vgutter == null ? 20 : opts.vgutter,
4254 Y = (height - 2 * barvgutter) / total;
4255 if (!opts.stretch) {
4256 barhgutter = Math.round(barhgutter);
4257 barwidth = Math.floor(barwidth);
4259 !opts.stacked && (barwidth /= multi || 1);
4260 for (var i = 0; i < len; i++) {
4262 for (var j = 0; j < (multi || 1); j++) {
4263 var h = Math.round((multi ? values[j][i] : values[i]) * Y),
4264 top = y + height - barvgutter - h,
4265 bar = this.g.finger(Math.round(X + barwidth / 2), top + h, barwidth, h, true, type).attr({stroke: "none", fill: colors[multi ? j : i]});
4272 bar.x = Math.round(X + barwidth / 2);
4276 bar.value = multi ? values[j][i] : values[i];
4277 if (!opts.stacked) {
4285 covers2.push(cvr = this.rect(stack[0].x - stack[0].w / 2, y, barwidth, height).attr(this.g.shim));
4286 cvr.bars = this.set();
4288 for (var s = stack.length; s--;) {
4291 for (var s = 0, ss = stack.length; s < ss; s++) {
4294 h = (size + bar.value) * Y,
4295 path = this.g.finger(bar.x, y + height - barvgutter - !!size * .5, barwidth, h, true, type, 1);
4297 size && bar.attr({path: path});
4299 bar.y = y + height - barvgutter - !!size * .5 - h;
4300 covers.push(cover = this.rect(bar.x - bar.w / 2, bar.y, barwidth, bar.value * Y).attr(this.g.shim));
4302 cover.value = bar.value;
4311 if (!opts.stacked) {
4312 for (var i = 0; i < len; i++) {
4313 for (var j = 0; j < (multi || 1); j++) {
4315 covers.push(cover = this.rect(Math.round(X), y + barvgutter, barwidth, height - barvgutter).attr(this.g.shim));
4316 cover.bar = multi ? bars[j][i] : bars[i];
4317 cover.value = cover.bar.value;
4323 chart.label = function (labels, isBottom, rotate) {
4324 labels = labels || [];
4325 isBottom = isBottom == undefined ? true : isBottom;
4326 rotate = rotate == undefined ? false : rotate;
4327 this.labels = paper.set();
4328 var L, l = -Infinity;
4330 for (var i = 0; i < len; i++) {
4332 for (var j = 0; j < (multi || 1); j++) {
4333 tot += multi ? values[j][i] : values[i];
4335 var label = paper.g.labelise(labels[j][i], tot, total);
4336 L = paper.g.text(bars[j][i].x, isBottom ? y + height - barvgutter / 2 : bars[j][i].y - 10, label);
4340 var bb = L.getBBox();
4344 this.labels.push(L);
4345 l = bb.x + (rotate ? bb.height : bb.width);
4351 for (var i = 0; i < len; i++) {
4352 for (var j = 0; j < (multi || 1); j++) {
4353 // did not remove the loop because don't yet know whether to accept multi array input for arrays
4354 var label = paper.g.labelise(multi ? labels[0] && labels[0][i] : labels[i], multi ? values[0][i] : values[i], total);
4355 L = paper.g.text(bars[0][i].x, isBottom ? y + 5 + height - barvgutter / 2 : bars[0][i].y - 10, label);
4358 // If we rotated it, we need to move it as well. Still have to use the width
4359 // to get the "length" of the label, divided it in two and shift down.
4360 L.translate(0, (L.getBBox().width / 2));
4362 var bb = L.getBBox();
4363 // if (bb.x - 7 < l) {
4364 if (bb.x - (this.getBBox().width) < l) {
4367 this.labels.push(L);
4368 l = bb.x + (rotate ? bb.height : bb.width);
4375 chart.hover = function (fin, fout) {
4378 covers.mouseover(fin).mouseout(fout);
4381 chart.hoverColumn = function (fin, fout) {
4384 fout = fout || function () {};
4385 covers2.mouseover(fin).mouseout(fout);
4388 chart.click = function (f) {
4394 chart.each = function (f) {
4395 if (!Raphael.is(f, "function")) {
4398 for (var i = covers.length; i--;) {
4403 chart.eachColumn = function (f) {
4404 if (!Raphael.is(f, "function")) {
4407 for (var i = covers2.length; i--;) {
4412 chart.clickColumn = function (f) {
4418 chart.push(bars, covers, covers2);
4420 chart.covers = covers;
4423 Raphael.fn.g.hbarchart = function (x, y, width, height, values, opts) {
4425 var type = {round: "round", sharp: "sharp", soft: "soft"}[opts.type] || "square",
4426 gutter = parseFloat(opts.gutter || "20%"),
4429 covers = this.set(),
4430 covers2 = this.set(),
4431 total = Math.max.apply(Math, values),
4435 colors = opts.colors || this.g.colors,
4436 len = values.length;
4437 if (this.raphael.is(values[0], "array")) {
4441 for (var i = values.length; i--;) {
4442 bars.push(this.set());
4443 total.push(Math.max.apply(Math, values[i]));
4444 len = Math.max(len, values[i].length);
4447 for (var i = len; i--;) {
4449 for (var j = values.length; j--;) {
4450 tot +=+ values[j][i] || 0;
4452 stacktotal.push(tot);
4455 for (var i = values.length; i--;) {
4456 if (values[i].length < len) {
4457 for (var j = len; j--;) {
4462 total = Math.max.apply(Math, opts.stacked ? stacktotal : total);
4465 total = (opts.to) || total;
4466 var barheight = Math.floor(height / (len * (100 + gutter) + gutter) * 100),
4467 bargutter = Math.floor(barheight * gutter / 100),
4470 X = (width - 1) / total;
4471 !opts.stacked && (barheight /= multi || 1);
4472 for (var i = 0; i < len; i++) {
4474 for (var j = 0; j < (multi || 1); j++) {
4475 var val = multi ? values[j][i] : values[i],
4476 bar = this.g.finger(x, Y + barheight / 2, Math.round(val * X), barheight - 1, false, type).attr({stroke: "none", fill: colors[multi ? j : i]});
4482 bar.x = x + Math.round(val * X);
4483 bar.y = Y + barheight / 2;
4484 bar.w = Math.round(val * X);
4487 if (!opts.stacked) {
4494 var cvr = this.rect(x, stack[0].y - stack[0].h / 2, width, barheight).attr(this.g.shim);
4496 cvr.bars = this.set();
4498 for (var s = stack.length; s--;) {
4501 for (var s = 0, ss = stack.length; s < ss; s++) {
4504 val = Math.round((size + bar.value) * X),
4505 path = this.g.finger(x, bar.y, val, barheight - 1, false, type, 1);
4507 size && bar.attr({path: path});
4510 covers.push(cover = this.rect(x + size * X, bar.y - bar.h / 2, bar.value * X, barheight).attr(this.g.shim));
4520 if (!opts.stacked) {
4521 for (var i = 0; i < len; i++) {
4522 for (var j = 0; j < (multi || 1); j++) {
4523 var cover = this.rect(x, Y, width, barheight).attr(this.g.shim);
4525 cover.bar = multi ? bars[j][i] : bars[i];
4526 cover.value = cover.bar.value;
4532 chart.label = function (labels, isRight) {
4533 labels = labels || [];
4534 this.labels = paper.set();
4535 for (var i = 0; i < len; i++) {
4536 for (var j = 0; j < multi; j++) {
4537 var label = paper.g.labelise(multi ? labels[j] && labels[j][i] : labels[i], multi ? values[j][i] : values[i], total);
4538 var X = isRight ? bars[i * (multi || 1) + j].x - barheight / 2 + 3 : x + 5,
4539 A = isRight ? "end" : "start",
4541 this.labels.push(L = paper.g.text(X, bars[i * (multi || 1) + j].y, label).attr({"text-anchor": A}).insertBefore(covers[0]));
4542 if (L.getBBox().x < x + 5) {
4543 L.attr({x: x + 5, "text-anchor": "start"});
4545 bars[i * (multi || 1) + j].label = L;
4551 chart.hover = function (fin, fout) {
4554 fout = fout || function () {};
4555 covers.mouseover(fin).mouseout(fout);
4558 chart.hoverColumn = function (fin, fout) {
4561 fout = fout || function () {};
4562 covers2.mouseover(fin).mouseout(fout);
4565 chart.each = function (f) {
4566 if (!Raphael.is(f, "function")) {
4569 for (var i = covers.length; i--;) {
4574 chart.eachColumn = function (f) {
4575 if (!Raphael.is(f, "function")) {
4578 for (var i = covers2.length; i--;) {
4583 chart.click = function (f) {
4589 chart.clickColumn = function (f) {
4595 chart.push(bars, covers, covers2);
4597 chart.covers = covers;
4601 * g.Raphael 0.4.1 - Charting library, based on Raphaël
4603 * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com)
4604 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
4606 Raphael.fn.g.dotchart = function (x, y, width, height, valuesx, valuesy, size, opts) {
4607 function drawAxis(ax) {
4608 +ax[0] && (ax[0] = paper.g.axis(x + gutter, y + gutter, width - 2 * gutter, minx, maxx, opts.axisxstep || Math.floor((width - 2 * gutter) / 20), 2, opts.axisxlabels || null, opts.axisxtype || "t"));
4609 +ax[1] && (ax[1] = paper.g.axis(x + width - gutter, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 3, opts.axisylabels || null, opts.axisytype || "t"));
4610 +ax[2] && (ax[2] = paper.g.axis(x + gutter, y + height - gutter + maxR, width - 2 * gutter, minx, maxx, opts.axisxstep || Math.floor((width - 2 * gutter) / 20), 0, opts.axisxlabels || null, opts.axisxtype || "t"));
4611 +ax[3] && (ax[3] = paper.g.axis(x + gutter - maxR, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 1, opts.axisylabels || null, opts.axisytype || "t"));
4614 var xdim = this.g.snapEnds(Math.min.apply(Math, valuesx), Math.max.apply(Math, valuesx), valuesx.length - 1),
4617 gutter = opts.gutter || 10,
4618 ydim = this.g.snapEnds(Math.min.apply(Math, valuesy), Math.max.apply(Math, valuesy), valuesy.length - 1),
4621 len = Math.max(valuesx.length, valuesy.length, size.length),
4622 symbol = this.g.markers[opts.symbol] || "disc",
4624 series = this.set(),
4625 max = opts.max || 100,
4626 top = Math.max.apply(Math, size),
4629 k = Math.sqrt(top / Math.PI) * 2 / max;
4631 for (var i = 0; i < len; i++) {
4632 R[i] = Math.min(Math.sqrt(size[i] / Math.PI) * 2 / k, max);
4634 gutter = Math.max.apply(Math, R.concat(gutter));
4635 var axis = this.set(),
4636 maxR = Math.max.apply(Math, R);
4638 var ax = (opts.axis + "").split(/[,\s]+/);
4641 for (var i = 0, ii = ax.length; i < ii; i++) {
4642 var bb = ax[i].all ? ax[i].all.getBBox()[["height", "width"][i % 2]] : 0;
4646 gutter = Math.max.apply(Math, g.concat(gutter));
4647 for (var i = 0, ii = ax.length; i < ii; i++) if (ax[i].all) {
4652 for (var i = 0, ii = ax.length; i < ii; i++) if (ax[i].all) {
4653 axis.push(ax[i].all);
4657 var kx = (width - gutter * 2) / ((maxx - minx) || 1),
4658 ky = (height - gutter * 2) / ((maxy - miny) || 1);
4659 for (var i = 0, ii = valuesy.length; i < ii; i++) {
4660 var sym = this.raphael.is(symbol, "array") ? symbol[i] : symbol,
4661 X = x + gutter + (valuesx[i] - minx) * kx,
4662 Y = y + height - gutter - (valuesy[i] - miny) * ky;
4663 sym && R[i] && series.push(this.g[sym](X, Y, R[i]).attr({fill: opts.heat ? this.g.colorValue(R[i], maxR) : Raphael.fn.g.colors[0], "fill-opacity": opts.opacity ? R[i] / max : 1, stroke: "none"}));
4665 var covers = this.set();
4666 for (var i = 0, ii = valuesy.length; i < ii; i++) {
4667 var X = x + gutter + (valuesx[i] - minx) * kx,
4668 Y = y + height - gutter - (valuesy[i] - miny) * ky;
4669 covers.push(this.circle(X, Y, maxR).attr(this.g.shim));
4670 opts.href && opts.href[i] && covers[i].attr({href: opts.href[i]});
4671 covers[i].r = +R[i].toFixed(3);
4672 covers[i].x = +X.toFixed(3);
4673 covers[i].y = +Y.toFixed(3);
4674 covers[i].X = valuesx[i];
4675 covers[i].Y = valuesy[i];
4676 covers[i].value = size[i] || 0;
4677 covers[i].dot = series[i];
4679 res.covers = covers;
4680 res.series = series;
4681 res.push(series, axis, covers);
4682 res.hover = function (fin, fout) {
4683 covers.mouseover(fin).mouseout(fout);
4686 res.click = function (f) {
4690 res.each = function (f) {
4691 if (!Raphael.is(f, "function")) {
4694 for (var i = covers.length; i--;) {
4699 res.href = function (map) {
4701 for (var i = covers.length; i--;) {
4703 if (cover.X == map.x && cover.Y == map.y && cover.value == map.value) {
4704 cover.attr({href: map.href});
4711 * g.Raphael 0.4.2 - Charting library, based on Raphaël
4713 * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com)
4714 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
4716 Raphael.fn.g.linechart = function (x, y, width, height, valuesx, valuesy, opts) {
4717 function shrink(values, dim) {
4718 var k = values.length / dim,
4723 while (j < values.length) {
4726 sum += values[j] * (1 + l);
4728 sum = values[j++] * -l;
4736 function getAnchors(p1x, p1y, p2x, p2y, p3x, p3y) {
4737 var l1 = (p2x - p1x) / 2,
4738 l2 = (p3x - p2x) / 2,
4739 a = Math.atan((p2x - p1x) / Math.abs(p2y - p1y)),
4740 b = Math.atan((p3x - p2x) / Math.abs(p2y - p3y));
4741 a = p1y < p2y ? Math.PI - a : a;
4742 b = p3y < p2y ? Math.PI - b : b;
4743 var alpha = Math.PI / 2 - ((a + b) % (Math.PI * 2)) / 2,
4744 dx1 = l1 * Math.sin(alpha + a),
4745 dy1 = l1 * Math.cos(alpha + a),
4746 dx2 = l2 * Math.sin(alpha + b),
4747 dy2 = l2 * Math.cos(alpha + b);
4756 if (!this.raphael.is(valuesx[0], "array")) {
4757 valuesx = [valuesx];
4759 if (!this.raphael.is(valuesy[0], "array")) {
4760 valuesy = [valuesy];
4762 var gutter = opts.gutter || 10,
4763 len = Math.max(valuesx[0].length, valuesy[0].length),
4764 symbol = opts.symbol || "",
4765 colors = opts.colors || Raphael.fn.g.colors,
4772 for (var i = 0, ii = valuesy.length; i < ii; i++) {
4773 len = Math.max(len, valuesy[i].length);
4775 var shades = this.set();
4776 for (i = 0, ii = valuesy.length; i < ii; i++) {
4778 shades.push(this.path().attr({stroke: "none", fill: colors[i], opacity: opts.nostroke ? 1 : .3}));
4780 if (valuesy[i].length > width - 2 * gutter) {
4781 valuesy[i] = shrink(valuesy[i], width - 2 * gutter);
4782 len = width - 2 * gutter;
4784 if (valuesx[i] && valuesx[i].length > width - 2 * gutter) {
4785 valuesx[i] = shrink(valuesx[i], width - 2 * gutter);
4788 var allx = Array.prototype.concat.apply([], valuesx),
4789 ally = Array.prototype.concat.apply([], valuesy),
4790 xdim = this.g.snapEnds(Math.min.apply(Math, allx), Math.max.apply(Math, allx), valuesx[0].length - 1);
4792 var minx = opts.minx || xdim.from,
4793 maxx = opts.maxx || xdim.to,
4794 ydim = this.g.snapEnds(Math.min.apply(Math, ally), Math.max.apply(Math, ally), valuesy[0].length - 1),
4795 miny = opts.miny || ydim.from,
4796 maxy = opts.maxy || ydim.to;
4798 var minx = opts.minx && Math.min(opts.minx, xdim.from) || xdim.from,
4799 maxx = opts.maxx && Math.max(opts.maxx, xdimt.to) || xdim.to,
4800 ydim = this.g.snapEnds(Math.min.apply(Math, ally), Math.max.apply(Math, ally), valuesy[0].length - 1),
4801 miny = opts.miny && Math.min(opts.miny, ydim.from) || ydim.from,
4802 maxy = opts.maxy && Math.max(opts.maxy, ydim.to) || ydim.to;
4804 kx = (width - gutter * 2) / ((maxx - minx) || 1),
4805 ky = (height - gutter * 2) / ((maxy - miny) || 1);
4807 var lines = this.set(),
4808 symbols = this.set(),
4810 for (i = 0, ii = valuesy.length; i < ii; i++) {
4811 if (!opts.nostroke) {
4812 lines.push(line = this.path().attr({
4814 "stroke-width": opts.width || 2,
4815 "stroke-linejoin": "round",
4816 "stroke-linecap": "round",
4817 "stroke-dasharray": opts.dash || ""
4820 var sym = this.raphael.is(symbol, "array") ? symbol[i] : symbol,
4821 symset = this.set();
4823 for (var j = 0, jj = valuesy[i].length; j < jj; j++) {
4824 var X = x + gutter + ((valuesx[i] || valuesx[0])[j] - minx) * kx,
4825 Y = y + height - gutter - (valuesy[i][j] - miny) * ky;
4826 (Raphael.is(sym, "array") ? sym[j] : sym) && symset.push(this.g[Raphael.fn.g.markers[this.raphael.is(sym, "array") ? sym[j] : sym]](X, Y, (opts.width || 2) * 3).attr({fill: colors[i], stroke: "none"}));
4828 if (j && j != jj - 1) {
4829 var X0 = x + gutter + ((valuesx[i] || valuesx[0])[j - 1] - minx) * kx,
4830 Y0 = y + height - gutter - (valuesy[i][j - 1] - miny) * ky,
4831 X2 = x + gutter + ((valuesx[i] || valuesx[0])[j + 1] - minx) * kx,
4832 Y2 = y + height - gutter - (valuesy[i][j + 1] - miny) * ky;
4833 var a = getAnchors(X0, Y0, X, Y, X2, Y2);
4834 path = path.concat([a.x1, a.y1, X, Y, a.x2, a.y2]);
4837 path = ["M", X, Y, "C", X, Y];
4840 path = path.concat([j ? "L" : "M", X, Y]);
4844 path = path.concat([X, Y, X, Y]);
4846 symbols.push(symset);
4848 shades[i].attr({path: path.concat(["L", X, y + height - gutter, "L", x + gutter + ((valuesx[i] || valuesx[0])[0] - minx) * kx, y + height - gutter, "z"]).join(",")});
4850 !opts.nostroke && line.attr({path: path.join(","), 'clip-rect': [x + gutter, y + gutter, width - 2 * gutter, height - 2 * gutter].join(",")});
4853 function createColumns(f) {
4854 // unite Xs together
4856 for (var i = 0, ii = valuesx.length; i < ii; i++) {
4857 Xs = Xs.concat(valuesx[i]);
4859 Xs.sort(function(a,b) { return a - b; });
4860 // remove duplicates
4863 for (i = 0, ii = Xs.length; i < ii; i++) {
4864 Xs[i] != Xs[i - 1] && Xs2.push(Xs[i]) && xs.push(x + gutter + (Xs[i] - minx) * kx);
4868 var cvrs = f || that.set();
4869 for (i = 0; i < ii; i++) {
4870 var X = xs[i] - (xs[i] - (xs[i - 1] || x)) / 2,
4871 w = ((xs[i + 1] || x + width) - xs[i]) / 2 + (xs[i] - (xs[i - 1] || x)) / 2,
4873 f ? (C = {}) : cvrs.push(C = that.rect(X - 1, y, Math.max(w + 1, 1), height).attr({stroke: "none", fill: "#000", opacity: 0}));
4875 C.symbols = that.set();
4879 for (var j = 0, jj = valuesy.length; j < jj; j++) {
4880 Xs2 = valuesx[j] || valuesx[0];
4881 for (var k = 0, kk = Xs2.length; k < kk; k++) {
4882 if (Xs2[k] == Xs[i]) {
4883 C.values.push(valuesy[j][k]);
4884 C.y.push(y + height - gutter - (valuesy[j][k] - miny) * ky);
4885 C.symbols.push(chart.symbols[j][k]);
4891 !f && (columns = cvrs);
4893 function createDots(f) {
4894 var cvrs = f || that.set(),
4896 for (var i = 0, ii = valuesy.length; i < ii; i++) {
4897 for (var j = 0, jj = valuesy[i].length; j < jj; j++) {
4898 var X = x + gutter + ((valuesx[i] || valuesx[0])[j] - minx) * kx,
4899 nearX = x + gutter + ((valuesx[i] || valuesx[0])[j ? j - 1 : 1] - minx) * kx,
4900 Y = y + height - gutter - (valuesy[i][j] - miny) * ky;
4901 f ? (C = {}) : cvrs.push(C = that.circle(X, Y, Math.abs(nearX - X) / 2).attr({stroke: "none", fill: "#000", opacity: 0}));
4904 C.value = valuesy[i][j];
4905 C.line = chart.lines[i];
4906 C.shade = chart.shades[i];
4907 C.symbol = chart.symbols[i][j];
4908 C.symbols = chart.symbols[i];
4909 C.axis = (valuesx[i] || valuesx[0])[j];
4913 !f && (dots = cvrs);
4916 var axis = this.set();
4918 var ax = (opts.axis + "").split(/[,\s]+/);
4919 +ax[0] && axis.push(this.g.axis(x + gutter, y + gutter, width - 2 * gutter, minx, maxx, opts.axisxstep || Math.floor((width - 2 * gutter) / 20), 2, opts.axisxlabels || null, opts.axisxtype || "t"));
4920 +ax[1] && axis.push(this.g.axis(x + width - gutter, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 3, opts.axisylabels || null, opts.axisytype || "t"));
4921 +ax[2] && axis.push(this.g.axis(x + gutter, y + height - gutter, width - 2 * gutter, minx, maxx, opts.axisxstep || Math.floor((width - 2 * gutter) / 20), 0, opts.axisxlabels || null, opts.axisxtype || "t"));
4922 +ax[3] && axis.push(this.g.axis(x + gutter, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 1, opts.axisylabels || null, opts.axisytype || "t"));
4925 chart.push(lines, shades, symbols, axis, columns, dots);
4926 chart.lines = lines;
4927 chart.shades = shades;
4928 chart.symbols = symbols;
4930 chart.hoverColumn = function (fin, fout) {
4931 !columns && createColumns();
4932 columns.mouseover(fin).mouseout(fout);
4935 chart.clickColumn = function (f) {
4936 !columns && createColumns();
4940 chart.hrefColumn = function (cols) {
4941 var hrefs = that.raphael.is(arguments[0], "array") ? arguments[0] : arguments;
4942 if (!(arguments.length - 1) && typeof cols == "object") {
4943 for (var x in cols) {
4944 for (var i = 0, ii = columns.length; i < ii; i++) if (columns[i].axis == x) {
4945 columns[i].attr("href", cols[x]);
4949 !columns && createColumns();
4950 for (i = 0, ii = hrefs.length; i < ii; i++) {
4951 columns[i] && columns[i].attr("href", hrefs[i]);
4955 chart.hover = function (fin, fout) {
4956 !dots && createDots();
4957 dots.mouseover(fin).mouseout(fout);
4960 chart.click = function (f) {
4961 !dots && createDots();
4965 chart.each = function (f) {
4969 chart.eachColumn = function (f) {
4976 * g.Raphael 0.4.1 - Charting library, based on Raphaël
4978 * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com)
4979 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
4981 Raphael.fn.g.piechart = function (cx, cy, r, values, opts) {
4985 covers = this.set(),
4987 series = this.set(),
4989 len = values.length,
4997 for (var i = 0; i < len; i++)
5000 var single_index = -1;
5001 for (var i = 0; i < len; i++)
5002 if (sum == values[i]) {
5007 if (len == 1 || single == true) {
5008 for(var i = 0; i < len; i++) {
5010 if (i == single_index) {
5013 series.push(this.circle(cx, cy, radius).attr({fill: opts.colors && opts.colors[i] || this.g.colors[i], stroke: opts.stroke || "#fff", "stroke-width": opts.strokewidth == null ? 1 : opts.strokewidth}));
5014 covers.push(this.circle(cx, cy, radius).attr({href: opts.href ? opts.href[i] : null}).attr(this.g.shim));
5015 values[i] = {value: values[i], order: i, valueOf: function () { return this.value; }};
5016 series[i].middle = {x: cx, y: cy};
5017 series[i].mangle = 180;
5019 total = values[single_index];
5021 function sector(cx, cy, r, startAngle, endAngle, fill) {
5022 var rad = Math.PI / 180,
5023 x1 = cx + r * Math.cos(-startAngle * rad),
5024 x2 = cx + r * Math.cos(-endAngle * rad),
5025 xm = cx + r / 2 * Math.cos(-(startAngle + (endAngle - startAngle) / 2) * rad),
5026 y1 = cy + r * Math.sin(-startAngle * rad),
5027 y2 = cy + r * Math.sin(-endAngle * rad),
5028 ym = cy + r / 2 * Math.sin(-(startAngle + (endAngle - startAngle) / 2) * rad),
5029 res = ["M", cx, cy, "L", x1, y1, "A", r, r, 0, +(Math.abs(endAngle - startAngle) > 180), 1, x2, y2, "z"];
5030 res.middle = {x: xm, y: ym};
5033 for (var i = 0; i < len; i++) {
5035 values[i] = {value: values[i], order: i, valueOf: function () { return this.value; }};
5037 values.sort(function (a, b) {
5038 return b.value - a.value;
5040 for (i = 0; i < len; i++) {
5041 if (defcut && values[i] * 360 / total <= 1.5) {
5047 values[cut].value += values[i];
5048 values[cut].others = true;
5049 others = values[cut].value;
5052 len = Math.min(cut + 1, values.length);
5053 others && values.splice(len) && (values[cut].others = true);
5054 for (i = 0; i < len; i++) {
5055 var valueOrder = values[i].order;
5056 var mangle = angle - 360 * values[i] / total / 2;
5058 angle = 90 - mangle;
5059 mangle = angle - 360 * values[i] / total / 2;
5062 var ipath = sector(cx, cy, 1, angle, angle - 360 * values[i] / total).join(",");
5064 var path = sector(cx, cy, r, angle, angle -= 360 * values[i] / total);
5065 var p = this.path(opts.init ? ipath : path).attr({fill: opts.colors && opts.colors[valueOrder] || this.g.colors[valueOrder] || "#666", stroke: opts.stroke || "#fff", "stroke-width": (opts.strokewidth == null ? 1 : opts.strokewidth), "stroke-linejoin": "round"});
5066 p.value = values[i];
5067 p.middle = path.middle;
5071 opts.init && p.animate({path: path.join(",")}, (+opts.init - 1) || 1000, ">");
5073 for (i = 0; i < len; i++) {
5074 p = paper.path(sectors[i].attr("path")).attr(this.g.shim);
5075 var valueOrder = values[i].order;
5076 opts.href && opts.href[valueOrder] && p.attr({href: opts.href[valueOrder]});
5077 //p.attr = function () {}; // this breaks translate!
5082 chart.hover = function (fin, fout) {
5083 fout = fout || function () {};
5085 for (var i = 0; i < len; i++) {
5086 (function (sector, cover, j) {
5092 mx: sector.middle.x,
5093 my: sector.middle.y,
5094 mangle: sector.mangle,
5098 label: that.labels && that.labels[j]
5100 cover.mouseover(function () {
5102 }).mouseout(function () {
5105 })(series[i], covers[i], i);
5109 // x: where label could be put
5110 // y: where label could be put
5111 // value: value to show
5112 // total: total number to count %
5113 chart.each = function (f) {
5115 for (var i = 0; i < len; i++) {
5116 (function (sector, cover, j) {
5124 mangle: sector.mangle,
5128 label: that.labels && that.labels[j]
5131 })(series[i], covers[i], i);
5135 chart.click = function (f) {
5137 for (var i = 0; i < len; i++) {
5138 (function (sector, cover, j) {
5144 mx: sector.middle.x,
5145 my: sector.middle.y,
5146 mangle: sector.mangle,
5150 label: that.labels && that.labels[j]
5152 cover.click(function () { f.call(o); });
5153 })(series[i], covers[i], i);
5157 chart.inject = function (element) {
5158 element.insertBefore(covers[0]);
5160 var legend = function (labels, otherslabel, mark, dir) {
5161 var x = cx + r + r / 5,
5164 labels = labels || [];
5165 dir = (dir && dir.toLowerCase && dir.toLowerCase()) || "east";
5166 mark = paper.g.markers[mark && mark.toLowerCase()] || "disc";
5167 chart.labels = paper.set();
5168 for (var i = 0; i < len; i++) {
5169 var clr = series[i].attr("fill"),
5170 j = values[i].order,
5172 values[i].others && (labels[j] = otherslabel || "Others");
5173 labels[j] = paper.g.labelise(labels[j], values[i], total);
5174 chart.labels.push(paper.set());
5175 chart.labels[i].push(paper.g[mark](x + 5, h, 5).attr({fill: clr, stroke: "none"}));
5176 chart.labels[i].push(txt = paper.text(x + 20, h, labels[j] || values[j]).attr(paper.g.txtattr).attr({fill: opts.legendcolor || "#000", "text-anchor": "start"}));
5177 covers[i].label = chart.labels[i];
5178 h += txt.getBBox().height * 1.2;
5180 var bb = chart.labels.getBBox(),
5182 east: [0, -bb.height / 2],
5183 west: [-bb.width - 2 * r - 20, -bb.height / 2],
5184 north: [-r - bb.width / 2, -r - bb.height - 10],
5185 south: [-r - bb.width / 2, r + 10]
5187 chart.labels.translate.apply(chart.labels, tr);
5188 chart.push(chart.labels);
5191 legend(opts.legend, opts.legendothers, opts.legendmark, opts.legendpos);
5193 chart.push(series, covers);
5194 chart.series = series;
5195 chart.covers = covers;
5197 var w = paper.width,
5199 bb = chart.getBBox(),
5200 tr = [(w - bb.width)/2 - bb.x, (h - bb.height)/2 - bb.y];
5203 chart.translate.apply(chart, tr);