2 * g.Raphael 0.5 - Charting library, based on Raphaƫl
4 * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com)
5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
9 * Tooltips on Element prototype
15 * Puts the context Element in a 'popup' tooltip. Can also be used on sets.
19 - dir (string) location of Element relative to the tail: `'down'`, `'left'`, `'up'` [default], or `'right'`.
20 - size (number) amount of bevel/padding around the Element, as well as half the width and height of the tail [default: `5`]
21 - x (number) x coordinate of the popup's tail [default: Element's `x` or `cx`]
22 - y (number) y coordinate of the popup's tail [default: Element's `y` or `cy`]
24 = (object) path element of the popup
26 | paper.circle(50, 50, 5).attr({
28 | fill: "0-#c9de96-#8ab66b:44-#398235"
31 Raphael.el.popup = function (dir, size, x, y) {
32 var paper = this.paper || this[0].paper,
33 bb, xy, center, cw, ch;
40 case 'ellipse': center = true; break;
41 default: center = false;
44 dir = dir == null ? 'up' : dir;
48 x = typeof x == 'number' ? x : (center ? bb.x + bb.width / 2 : bb.x);
49 y = typeof y == 'number' ? y : (center ? bb.y + bb.height / 2 : bb.y);
50 cw = Math.max(bb.width / 2 - size, 0);
51 ch = Math.max(bb.height / 2 - size, 0);
53 this.translate(x - bb.x - (center ? bb.width / 2 : 0), y - bb.y - (center ? bb.height / 2 : 0));
59 'l', -size, -size, -cw, 0,
60 'a', size, size, 0, 0, 1, -size, -size,
62 'a', size, size, 0, 0, 1, size, -size,
63 'l', size * 2 + cw * 2, 0,
64 'a', size, size, 0, 0, 1, size, size,
66 'a', size, size, 0, 0, 1, -size, size,
72 'l', size, size, cw, 0,
73 'a', size, size, 0, 0, 1, size, size,
75 'a', size, size, 0, 0, 1, -size, size,
76 'l', -(size * 2 + cw * 2), 0,
77 'a', size, size, 0, 0, 1, -size, -size,
79 'a', size, size, 0, 0, 1, size, -size,
85 'l', -size, size, 0, ch,
86 'a', size, size, 0, 0, 1, -size, size,
88 'a', size, size, 0, 0, 1, -size, -size,
89 'l', 0, -(size * 2 + ch * 2),
90 'a', size, size, 0, 0, 1, size, -size,
92 'a', size, size, 0, 0, 1, size, size,
98 'l', size, -size, 0, -ch,
99 'a', size, size, 0, 0, 1, size, -size,
101 'a', size, size, 0, 0, 1, size, size,
102 'l', 0, size * 2 + ch * 2,
103 'a', size, size, 0, 0, 1, -size, size,
105 'a', size, size, 0, 0, 1, -size, -size,
112 up: { x: -!center * (bb.width / 2), y: -size * 2 - (center ? bb.height / 2 : bb.height) },
113 down: { x: -!center * (bb.width / 2), y: size * 2 + (center ? bb.height / 2 : bb.height) },
114 left: { x: -size * 2 - (center ? bb.width / 2 : bb.width), y: -!center * (bb.height / 2) },
115 right: { x: size * 2 + (center ? bb.width / 2 : bb.width), y: -!center * (bb.height / 2) }
118 this.translate(xy.x, xy.y);
119 return paper.path(paths[dir]).attr({ fill: "#000", stroke: "none" }).insertBefore(this.node ? this : this[0]);
126 * Puts the context Element in a 'tag' tooltip. Can also be used on sets.
130 - angle (number) angle of orientation in degrees [default: `0`]
131 - r (number) radius of the loop [default: `5`]
132 - x (number) x coordinate of the center of the tag loop [default: Element's `x` or `cx`]
133 - y (number) y coordinate of the center of the tag loop [default: Element's `x` or `cx`]
135 = (object) path element of the tag
137 | paper.circle(50, 50, 15).attr({
139 | fill: "0-#c9de96-#8ab66b:44-#398235"
142 Raphael.el.tag = function (angle, r, x, y) {
144 paper = this.paper || this[0].paper;
148 var p = paper.path().attr({ fill: '#000', stroke: '#000' }),
155 case 'ellipse': center = true; break;
156 default: center = false;
160 x = typeof x == 'number' ? x : (center ? bb.x + bb.width / 2 : bb.x);
161 y = typeof y == 'number' ? y : (center ? bb.y + bb.height / 2 : bb.y);
162 r = r == null ? 5 : r;
165 if (bb.height >= r * 2) {
169 "a", r, r, 0, 1, 1, 0, -r * 2, r, r, 0, 1, 1, 0, r * 2,
171 "a", r + d, r + d, 0, 1, 0, 0, (r + d) * 2,
172 "L", x + r + d, y + bb.height / 2 + d,
173 "l", bb.width + 2 * d, 0, 0, -bb.height - 2 * d, -bb.width - 2 * d, 0,
178 dx = Math.sqrt(Math.pow(r + d, 2) - Math.pow(bb.height / 2 + d, 2));
182 "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,
183 "M", x + dx, y - bb.height / 2 - d,
184 "a", r + d, r + d, 0, 1, 0, 0, bb.height + 2 * d,
185 "l", r + d - dx + bb.width + 2 * d, 0, 0, -bb.height - 2 * d,
186 "L", x + dx, y - bb.height / 2 - d
192 p.rotate(angle, x, y);
196 this.attr(this.attrs.x ? 'x' : 'cx', x + r + d + (!center ? this.type == 'text' ? bb.width : 0 : bb.width / 2)).attr('y', center ? y : y - bb.height / 2);
197 this.rotate(angle, x, y);
198 angle > 90 && angle < 270 && this.attr(this.attrs.x ? 'x' : 'cx', x - r - d - (!center ? bb.width : bb.width / 2)).rotate(180, x, y);
201 if (angle > 90 && angle < 270) {
202 this.translate(x - bb.x - bb.width - r - d, y - bb.y - bb.height / 2);
203 this.rotate(angle - 180, bb.x + bb.width + r + d, bb.y + bb.height / 2);
205 this.translate(x - bb.x + r + d, y - bb.y - bb.height / 2);
206 this.rotate(angle, bb.x - r - d, bb.y + bb.height / 2);
210 return p.insertBefore(this.node ? this : this[0]);
217 * Puts the context Element in a 'drop' tooltip. Can also be used on sets.
221 - angle (number) angle of orientation in degrees [default: `0`]
222 - x (number) x coordinate of the drop's point [default: Element's `x` or `cx`]
223 - y (number) y coordinate of the drop's point [default: Element's `x` or `cx`]
225 = (object) path element of the drop
227 | paper.circle(50, 50, 8).attr({
229 | fill: "0-#c9de96-#8ab66b:44-#398235"
232 Raphael.el.drop = function (angle, x, y) {
233 var bb = this.getBBox(),
234 paper = this.paper || this[0].paper,
235 center, size, p, dx, dy;
242 case 'ellipse': center = true; break;
243 default: center = false;
248 x = typeof x == 'number' ? x : (center ? bb.x + bb.width / 2 : bb.x);
249 y = typeof y == 'number' ? y : (center ? bb.y + bb.height / 2 : bb.y);
250 size = Math.max(bb.width, bb.height) + Math.min(bb.width, bb.height);
254 "A", size * .4, size * .4, 0, 1, 0, x + size * .7, y - size * .7,
256 ]).attr({fill: "#000", stroke: "none"}).rotate(22.5 - angle, x, y);
258 angle = (angle + 90) * Math.PI / 180;
259 dx = (x + size * Math.sin(angle)) - (center ? 0 : bb.width / 2);
260 dy = (y + size * Math.cos(angle)) - (center ? 0 : bb.height / 2);
263 this.attr(this.attrs.x ? 'x' : 'cx', dx).attr(this.attrs.y ? 'y' : 'cy', dy) :
264 this.translate(dx - bb.x, dy - bb.y);
266 return p.insertBefore(this.node ? this : this[0]);
273 * Puts the context Element in a 'flag' tooltip. Can also be used on sets.
277 - angle (number) angle of orientation in degrees [default: `0`]
278 - x (number) x coordinate of the flag's point [default: Element's `x` or `cx`]
279 - y (number) y coordinate of the flag's point [default: Element's `x` or `cx`]
281 = (object) path element of the flag
283 | paper.circle(50, 50, 10).attr({
285 | fill: "0-#c9de96-#8ab66b:44-#398235"
288 Raphael.el.flag = function (angle, x, y) {
290 paper = this.paper || this[0].paper;
294 var p = paper.path().attr({ fill: '#000', stroke: '#000' }),
302 case 'ellipse': center = true; break;
303 default: center = false;
307 x = typeof x == 'number' ? x : (center ? bb.x + bb.width / 2 : bb.x);
308 y = typeof y == 'number' ? y : (center ? bb.y + bb.height / 2: bb.y);
313 "l", h + d, -h - d, bb.width + 2 * d, 0, 0, bb.height + 2 * d, -bb.width - 2 * d, 0,
319 p.rotate(angle, x, y);
323 this.attr(this.attrs.x ? 'x' : 'cx', x + h + d + (!center ? this.type == 'text' ? bb.width : 0 : bb.width / 2)).attr('y', center ? y : y - bb.height / 2);
324 this.rotate(angle, x, y);
325 angle > 90 && angle < 270 && this.attr(this.attrs.x ? 'x' : 'cx', x - h - d - (!center ? bb.width : bb.width / 2)).rotate(180, x, y);
328 if (angle > 90 && angle < 270) {
329 this.translate(x - bb.x - bb.width - h - d, y - bb.y - bb.height / 2);
330 this.rotate(angle - 180, bb.x + bb.width + h + d, bb.y + bb.height / 2);
332 this.translate(x - bb.x + h + d, y - bb.y - bb.height / 2);
333 this.rotate(angle, bb.x - h - d, bb.y + bb.height / 2);
337 return p.insertBefore(this.node ? this : this[0]);
344 * Puts the context Element in a 'label' tooltip. Can also be used on sets.
346 = (object) path element of the label.
348 | paper.circle(50, 50, 10).attr({
350 | fill: "0-#c9de96-#8ab66b:44-#398235"
353 Raphael.el.label = function () {
354 var bb = this.getBBox(),
355 paper = this.paper || this[0].paper,
356 r = Math.min(20, bb.width + 10, bb.height + 10) / 2;
360 return paper.rect(bb.x - r / 2, bb.y - r / 2, bb.width + r, bb.height + r, r).attr({ stroke: 'none', fill: '#000' }).insertBefore(this.node ? this : this[0]);
367 * Puts the context Element in a 'blob' tooltip. Can also be used on sets.
371 - angle (number) angle of orientation in degrees [default: `0`]
372 - x (number) x coordinate of the blob's tail [default: Element's `x` or `cx`]
373 - y (number) y coordinate of the blob's tail [default: Element's `x` or `cx`]
375 = (object) path element of the blob
377 | paper.circle(50, 50, 8).attr({
379 | fill: "0-#c9de96-#8ab66b:44-#398235"
382 Raphael.el.blob = function (angle, x, y) {
383 var bb = this.getBBox(),
385 paper = this.paper || this[0].paper,
393 case 'ellipse': center = true; break;
394 default: center = false;
397 p = paper.path().attr({ fill: "#000", stroke: "none" });
398 angle = (+angle + 1 ? angle : 45) + 90;
399 size = Math.min(bb.height, bb.width);
400 x = typeof x == 'number' ? x : (center ? bb.x + bb.width / 2 : bb.x);
401 y = typeof y == 'number' ? y : (center ? bb.y + bb.height / 2 : bb.y);
403 var w = Math.max(bb.width + size, size * 25 / 12),
404 h = Math.max(bb.height + size, size * 25 / 12),
405 x2 = x + size * Math.sin((angle - 22.5) * rad),
406 y2 = y + size * Math.cos((angle - 22.5) * rad),
407 x1 = x + size * Math.sin((angle + 22.5) * rad),
408 y1 = y + size * Math.cos((angle + 22.5) * rad),
413 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)),
414 cx = k * rx * dy / ry + (x1 + x2) / 2,
415 cy = k * -ry * dx / rx + (y1 + y2) / 2;
423 "A", rx, ry, 0, 1, 1, x2, y2,
428 this.translate(cx - bb.x - bb.width / 2, cy - bb.y - bb.height / 2);
430 return p.insertBefore(this.node ? this : this[0]);
434 * Tooltips on Paper prototype
440 * Puts the given `text` into a 'label' tooltip. The text is given a default style according to @g.txtattr. See @Element.label
444 - x (number) x coordinate of the center of the label
445 - y (number) y coordinate of the center of the label
446 - text (string) text to place inside the label
448 = (object) set containing the label path and the text element
450 | paper.label(50, 50, "$9.99");
452 Raphael.fn.label = function (x, y, text) {
453 var set = this.set();
455 text = this.text(x, y, text).attr(Raphael.g.txtattr);
456 return set.push(text.label(), text);
463 * Puts the given `text` into a 'popup' tooltip. The text is given a default style according to @g.txtattr. See @Element.popup
465 * Note: The `dir` parameter has changed from g.Raphael 0.4.1 to 0.5. The options `0`, `1`, `2`, and `3` has been changed to `'down'`, `'left'`, `'up'`, and `'right'` respectively.
469 - x (number) x coordinate of the popup's tail
470 - y (number) y coordinate of the popup's tail
471 - text (string) text to place inside the popup
472 - dir (string) location of the text relative to the tail: `'down'`, `'left'`, `'up'` [default], or `'right'`.
473 - size (number) amount of padding around the Element [default: `5`]
475 = (object) set containing the popup path and the text element
477 | paper.popup(50, 50, "$9.99", 'down');
479 Raphael.fn.popup = function (x, y, text, dir, size) {
480 var set = this.set();
482 text = this.text(x, y, text).attr(Raphael.g.txtattr);
483 return set.push(text.popup(dir, size), text);
490 * Puts the given text into a 'tag' tooltip. The text is given a default style according to @g.txtattr. See @Element.tag
494 - x (number) x coordinate of the center of the tag loop
495 - y (number) y coordinate of the center of the tag loop
496 - text (string) text to place inside the tag
497 - angle (number) angle of orientation in degrees [default: `0`]
498 - r (number) radius of the loop [default: `5`]
500 = (object) set containing the tag path and the text element
502 | paper.tag(50, 50, "$9.99", 60);
504 Raphael.fn.tag = function (x, y, text, angle, r) {
505 var set = this.set();
507 text = this.text(x, y, text).attr(Raphael.g.txtattr);
508 return set.push(text.tag(angle, r), text);
515 * Puts the given `text` into a 'flag' tooltip. The text is given a default style according to @g.txtattr. See @Element.flag
519 - x (number) x coordinate of the flag's point
520 - y (number) y coordinate of the flag's point
521 - text (string) text to place inside the flag
522 - angle (number) angle of orientation in degrees [default: `0`]
524 = (object) set containing the flag path and the text element
526 | paper.flag(50, 50, "$9.99", 60);
528 Raphael.fn.flag = function (x, y, text, angle) {
529 var set = this.set();
531 text = this.text(x, y, text).attr(Raphael.g.txtattr);
532 return set.push(text.flag(angle), text);
539 * Puts the given text into a 'drop' tooltip. The text is given a default style according to @g.txtattr. See @Element.drop
543 - x (number) x coordinate of the drop's point
544 - y (number) y coordinate of the drop's point
545 - text (string) text to place inside the drop
546 - angle (number) angle of orientation in degrees [default: `0`]
548 = (object) set containing the drop path and the text element
550 | paper.drop(50, 50, "$9.99", 60);
552 Raphael.fn.drop = function (x, y, text, angle) {
553 var set = this.set();
555 text = this.text(x, y, text).attr(Raphael.g.txtattr);
556 return set.push(text.drop(angle), text);
563 * Puts the given text into a 'blob' tooltip. The text is given a default style according to @g.txtattr. See @Element.blob
567 - x (number) x coordinate of the blob's tail
568 - y (number) y coordinate of the blob's tail
569 - text (string) text to place inside the blob
570 - angle (number) angle of orientation in degrees [default: `0`]
572 = (object) set containing the blob path and the text element
574 | paper.blob(50, 50, "$9.99", 60);
576 Raphael.fn.blob = function (x, y, text, angle) {
577 var set = this.set();
579 text = this.text(x, y, text).attr(Raphael.g.txtattr);
580 return set.push(text.blob(angle), text);
584 * Brightness functions on the Element prototype
590 * Makes the context element lighter by increasing the brightness and reducing the saturation by a given factor. Can be called on Sets.
594 - times (number) adjustment factor [default: `2`]
598 | paper.circle(50, 50, 20).attr({
604 Raphael.el.lighter = function (times) {
607 var fs = [this.attrs.fill, this.attrs.stroke];
609 this.fs = this.fs || [fs[0], fs[1]];
611 fs[0] = Raphael.rgb2hsb(Raphael.getRGB(fs[0]).hex);
612 fs[1] = Raphael.rgb2hsb(Raphael.getRGB(fs[1]).hex);
613 fs[0].b = Math.min(fs[0].b * times, 1);
614 fs[0].s = fs[0].s / times;
615 fs[1].b = Math.min(fs[1].b * times, 1);
616 fs[1].s = fs[1].s / times;
618 this.attr({fill: "hsb(" + [fs[0].h, fs[0].s, fs[0].b] + ")", stroke: "hsb(" + [fs[1].h, fs[1].s, fs[1].b] + ")"});
626 * Makes the context element darker by decreasing the brightness and increasing the saturation by a given factor. Can be called on Sets.
630 - times (number) adjustment factor [default: `2`]
634 | paper.circle(50, 50, 20).attr({
640 Raphael.el.darker = function (times) {
643 var fs = [this.attrs.fill, this.attrs.stroke];
645 this.fs = this.fs || [fs[0], fs[1]];
647 fs[0] = Raphael.rgb2hsb(Raphael.getRGB(fs[0]).hex);
648 fs[1] = Raphael.rgb2hsb(Raphael.getRGB(fs[1]).hex);
649 fs[0].s = Math.min(fs[0].s * times, 1);
650 fs[0].b = fs[0].b / times;
651 fs[1].s = Math.min(fs[1].s * times, 1);
652 fs[1].b = fs[1].b / times;
654 this.attr({fill: "hsb(" + [fs[0].h, fs[0].s, fs[0].b] + ")", stroke: "hsb(" + [fs[1].h, fs[1].s, fs[1].b] + ")"});
659 * Element.resetBrightness
662 * Resets brightness and saturation levels to their original values. See @Element.lighter and @Element.darker. Can be called on Sets.
666 | paper.circle(50, 50, 20).attr({
670 | }).lighter(6).resetBrightness();
672 Raphael.el.resetBrightness = function () {
674 this.attr({ fill: this.fs[0], stroke: this.fs[1] });
680 //alias to set prototype
682 var brightness = ['lighter', 'darker', 'resetBrightness'],
683 tooltips = ['popup', 'tag', 'flag', 'label', 'drop', 'blob'];
685 for (var f in tooltips) (function (name) {
686 Raphael.st[name] = function () {
687 return Raphael.el[name].apply(this, arguments);
691 for (var f in brightness) (function (name) {
692 Raphael.st[name] = function () {
693 for (var i = 0; i < this.length; i++) {
694 this[i][name].apply(this[i], arguments);
702 //chart prototype for storing common functions
708 * An attribute object that charts will set on all generated shims (shims being the invisible objects that mouse events are bound to)
711 | { stroke: 'none', fill: '#000', 'fill-opacity': 0 }
713 shim: { stroke: 'none', fill: '#000', 'fill-opacity': 0 },
719 * An attribute object that charts and tooltips will set on any generated text
722 | { font: '12px Arial, sans-serif', fill: '#fff' }
724 txtattr: { font: '12px Arial, sans-serif', fill: '#fff' },
730 * An array of color values that charts will iterate through when drawing chart data values.
733 colors: (function () {
734 var hues = [.6, .2, .05, .1333, .75, 0],
737 for (var i = 0; i < 10; i++) {
738 if (i < hues.length) {
739 colors.push('hsb(' + hues[i] + ',.75, .75)');
741 colors.push('hsb(' + hues[i - hues.length] + ', 1, .5)');
748 snapEnds: function(from, to, steps)
756 if (f == t || steps == 0) {
757 return {from: f, to: t, power: 0};
760 if (Math.abs(f) == Infinity || Math.abs(t) == Infinity) {
761 return {from: f, to: t, power: 0};
765 return Math.abs(a - .5) < .25 ? ~~(a) + .5 : Math.round(a);
768 var d = (t - f) / steps,
776 R = ~~(d * Math.pow(10, i)) / Math.pow(10, i);
783 r = ~~(d * Math.pow(10, i)) / Math.pow(10, i);
790 t = round(to * Math.pow(10, i)) / Math.pow(10, i);
793 t = round((to + .5) * Math.pow(10, i)) / Math.pow(10, i);
796 f = round((from - (i > 0 ? 0 : .5)) * Math.pow(10, i)) / Math.pow(10, i);
797 return { from: f, to: t, power: i };
800 axis: function (x, y, length, from, to, steps, orientation, labels, type, dashsize, paper)
802 dashsize = dashsize == null ? 2 : dashsize;
805 paper = arguments[arguments.length-1] //paper is always last argument
807 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],
808 ends = this.snapEnds(from, to, steps),
813 txtattr = { font: "11px Arial, sans-serif" },
823 // Orientation- "top2 right3 bottom0 left1". If
825 if (+orientation == 1 || +orientation == 3) {
827 addon = (orientation - 1 ? 1 : -1) * (dashsize + 3 + !!(orientation - 1));
829 while (Y >= y - length) {
830 type != "-" && type != " " && (path = path.concat(["M", x - (type == "+" || type == "|" ? dashsize : !(orientation - 1) * dashsize * 2), Y + .5, "l", dashsize * 2 + 1, 0]));
836 (labels && labels[j++]) || (
837 Math.round(label) == label ? Roo.util.Format.number(label,0) : Roo.util.Format.number(label,rnd)
839 ).attr(txtattr).attr({
840 "text-anchor": orientation - 1 ? "start" : "end"
846 if (Math.round(Y + dx - (y - length))) {
847 type != "-" && type != " " && (path = path.concat(["M", x - (type == "+" || type == "|" ? dashsize : !(orientation - 1) * dashsize * 2), y - length + .5, "l", dashsize * 2 + 1, 0]));
848 text.push(paper.text(x + addon, y - length, (labels && labels[j]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(txtattr).attr({ "text-anchor": orientation - 1 ? "start" : "end" }));
854 addon = (orientation ? -1 : 1) * (dashsize + 9 + !orientation);
861 //Roo.log([X,x,length, dx]); return;
862 while (X <= x + length) {
863 type != "-" && type != " " && (path = path.concat(["M", X + .5, y - (type == "+" ? dashsize : !!orientation * dashsize * 2), "l", 0, dashsize * 2 + 1]));
864 text.push(txt = paper.text(X, y + addon, (labels && labels[j++]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(txtattr));
866 var bb = txt.getBBox();
868 if (prev >= bb.x - 5) {
869 text.pop(text.length - 1).remove();
871 prev = bb.x + bb.width;
878 if (Math.round(X - dx - x - length)) {
879 type != "-" && type != " " && (path = path.concat(["M", x + length + .5, y - (type == "+" ? dashsize : !!orientation * dashsize * 2), "l", 0, dashsize * 2 + 1]));
880 text.push(paper.text(x + length, y + addon, (labels && labels[j]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(txtattr));
884 var res = paper.path(path);
887 res.all = paper.set([res, text]);
888 res.remove = function () {
890 this.constructor.prototype.remove.call(this);
896 labelise: function(label, val, total) {
898 return (label + "").replace(/(##+(?:\.#+)?)|(%%+(?:\.%+)?)/g, function (all, value, percent) {
900 return (+val).toFixed(value.replace(/^#+\.?/g, "").length);
903 return (val * 100 / total).toFixed(percent.replace(/^%+\.?/g, "").length) + "%";
907 return (+val).toFixed(0);