· 7 years ago · Nov 30, 2018, 11:30 AM
1/*!
2 * Chart.js
3 * http://chartjs.org/
4 * Version: 2.7.3
5 *
6 * Copyright 2018 Chart.js Contributors
7 * Released under the MIT license
8 * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md
9 */
10(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Chart = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
11
12},{}],2:[function(require,module,exports){
13/* MIT license */
14var colorNames = require(6);
15
16module.exports = {
17 getRgba: getRgba,
18 getHsla: getHsla,
19 getRgb: getRgb,
20 getHsl: getHsl,
21 getHwb: getHwb,
22 getAlpha: getAlpha,
23
24 hexString: hexString,
25 rgbString: rgbString,
26 rgbaString: rgbaString,
27 percentString: percentString,
28 percentaString: percentaString,
29 hslString: hslString,
30 hslaString: hslaString,
31 hwbString: hwbString,
32 keyword: keyword
33}
34
35function getRgba(string) {
36 if (!string) {
37 return;
38 }
39 var abbr = /^#([a-fA-F0-9]{3})$/i,
40 hex = /^#([a-fA-F0-9]{6})$/i,
41 rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
42 per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
43 keyword = /(\w+)/;
44
45 var rgb = [0, 0, 0],
46 a = 1,
47 match = string.match(abbr);
48 if (match) {
49 match = match[1];
50 for (var i = 0; i < rgb.length; i++) {
51 rgb[i] = parseInt(match[i] + match[i], 16);
52 }
53 }
54 else if (match = string.match(hex)) {
55 match = match[1];
56 for (var i = 0; i < rgb.length; i++) {
57 rgb[i] = parseInt(match.slice(i * 2, i * 2 + 2), 16);
58 }
59 }
60 else if (match = string.match(rgba)) {
61 for (var i = 0; i < rgb.length; i++) {
62 rgb[i] = parseInt(match[i + 1]);
63 }
64 a = parseFloat(match[4]);
65 }
66 else if (match = string.match(per)) {
67 for (var i = 0; i < rgb.length; i++) {
68 rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
69 }
70 a = parseFloat(match[4]);
71 }
72 else if (match = string.match(keyword)) {
73 if (match[1] == "transparent") {
74 return [0, 0, 0, 0];
75 }
76 rgb = colorNames[match[1]];
77 if (!rgb) {
78 return;
79 }
80 }
81
82 for (var i = 0; i < rgb.length; i++) {
83 rgb[i] = scale(rgb[i], 0, 255);
84 }
85 if (!a && a != 0) {
86 a = 1;
87 }
88 else {
89 a = scale(a, 0, 1);
90 }
91 rgb[3] = a;
92 return rgb;
93}
94
95function getHsla(string) {
96 if (!string) {
97 return;
98 }
99 var hsl = /^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
100 var match = string.match(hsl);
101 if (match) {
102 var alpha = parseFloat(match[4]);
103 var h = scale(parseInt(match[1]), 0, 360),
104 s = scale(parseFloat(match[2]), 0, 100),
105 l = scale(parseFloat(match[3]), 0, 100),
106 a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
107 return [h, s, l, a];
108 }
109}
110
111function getHwb(string) {
112 if (!string) {
113 return;
114 }
115 var hwb = /^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
116 var match = string.match(hwb);
117 if (match) {
118 var alpha = parseFloat(match[4]);
119 var h = scale(parseInt(match[1]), 0, 360),
120 w = scale(parseFloat(match[2]), 0, 100),
121 b = scale(parseFloat(match[3]), 0, 100),
122 a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
123 return [h, w, b, a];
124 }
125}
126
127function getRgb(string) {
128 var rgba = getRgba(string);
129 return rgba && rgba.slice(0, 3);
130}
131
132function getHsl(string) {
133 var hsla = getHsla(string);
134 return hsla && hsla.slice(0, 3);
135}
136
137function getAlpha(string) {
138 var vals = getRgba(string);
139 if (vals) {
140 return vals[3];
141 }
142 else if (vals = getHsla(string)) {
143 return vals[3];
144 }
145 else if (vals = getHwb(string)) {
146 return vals[3];
147 }
148}
149
150// generators
151function hexString(rgb) {
152 return "#" + hexDouble(rgb[0]) + hexDouble(rgb[1])
153 + hexDouble(rgb[2]);
154}
155
156function rgbString(rgba, alpha) {
157 if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
158 return rgbaString(rgba, alpha);
159 }
160 return "rgb(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ")";
161}
162
163function rgbaString(rgba, alpha) {
164 if (alpha === undefined) {
165 alpha = (rgba[3] !== undefined ? rgba[3] : 1);
166 }
167 return "rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2]
168 + ", " + alpha + ")";
169}
170
171function percentString(rgba, alpha) {
172 if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
173 return percentaString(rgba, alpha);
174 }
175 var r = Math.round(rgba[0]/255 * 100),
176 g = Math.round(rgba[1]/255 * 100),
177 b = Math.round(rgba[2]/255 * 100);
178
179 return "rgb(" + r + "%, " + g + "%, " + b + "%)";
180}
181
182function percentaString(rgba, alpha) {
183 var r = Math.round(rgba[0]/255 * 100),
184 g = Math.round(rgba[1]/255 * 100),
185 b = Math.round(rgba[2]/255 * 100);
186 return "rgba(" + r + "%, " + g + "%, " + b + "%, " + (alpha || rgba[3] || 1) + ")";
187}
188
189function hslString(hsla, alpha) {
190 if (alpha < 1 || (hsla[3] && hsla[3] < 1)) {
191 return hslaString(hsla, alpha);
192 }
193 return "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)";
194}
195
196function hslaString(hsla, alpha) {
197 if (alpha === undefined) {
198 alpha = (hsla[3] !== undefined ? hsla[3] : 1);
199 }
200 return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, "
201 + alpha + ")";
202}
203
204// hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
205// (hwb have alpha optional & 1 is default value)
206function hwbString(hwb, alpha) {
207 if (alpha === undefined) {
208 alpha = (hwb[3] !== undefined ? hwb[3] : 1);
209 }
210 return "hwb(" + hwb[0] + ", " + hwb[1] + "%, " + hwb[2] + "%"
211 + (alpha !== undefined && alpha !== 1 ? ", " + alpha : "") + ")";
212}
213
214function keyword(rgb) {
215 return reverseNames[rgb.slice(0, 3)];
216}
217
218// helpers
219function scale(num, min, max) {
220 return Math.min(Math.max(min, num), max);
221}
222
223function hexDouble(num) {
224 var str = num.toString(16).toUpperCase();
225 return (str.length < 2) ? "0" + str : str;
226}
227
228
229//create a list of reverse color names
230var reverseNames = {};
231for (var name in colorNames) {
232 reverseNames[colorNames[name]] = name;
233}
234
235},{"6":6}],3:[function(require,module,exports){
236/* MIT license */
237var convert = require(5);
238var string = require(2);
239
240var Color = function (obj) {
241 if (obj instanceof Color) {
242 return obj;
243 }
244 if (!(this instanceof Color)) {
245 return new Color(obj);
246 }
247
248 this.valid = false;
249 this.values = {
250 rgb: [0, 0, 0],
251 hsl: [0, 0, 0],
252 hsv: [0, 0, 0],
253 hwb: [0, 0, 0],
254 cmyk: [0, 0, 0, 0],
255 alpha: 1
256 };
257
258 // parse Color() argument
259 var vals;
260 if (typeof obj === 'string') {
261 vals = string.getRgba(obj);
262 if (vals) {
263 this.setValues('rgb', vals);
264 } else if (vals = string.getHsla(obj)) {
265 this.setValues('hsl', vals);
266 } else if (vals = string.getHwb(obj)) {
267 this.setValues('hwb', vals);
268 }
269 } else if (typeof obj === 'object') {
270 vals = obj;
271 if (vals.r !== undefined || vals.red !== undefined) {
272 this.setValues('rgb', vals);
273 } else if (vals.l !== undefined || vals.lightness !== undefined) {
274 this.setValues('hsl', vals);
275 } else if (vals.v !== undefined || vals.value !== undefined) {
276 this.setValues('hsv', vals);
277 } else if (vals.w !== undefined || vals.whiteness !== undefined) {
278 this.setValues('hwb', vals);
279 } else if (vals.c !== undefined || vals.cyan !== undefined) {
280 this.setValues('cmyk', vals);
281 }
282 }
283};
284
285Color.prototype = {
286 isValid: function () {
287 return this.valid;
288 },
289 rgb: function () {
290 return this.setSpace('rgb', arguments);
291 },
292 hsl: function () {
293 return this.setSpace('hsl', arguments);
294 },
295 hsv: function () {
296 return this.setSpace('hsv', arguments);
297 },
298 hwb: function () {
299 return this.setSpace('hwb', arguments);
300 },
301 cmyk: function () {
302 return this.setSpace('cmyk', arguments);
303 },
304
305 rgbArray: function () {
306 return this.values.rgb;
307 },
308 hslArray: function () {
309 return this.values.hsl;
310 },
311 hsvArray: function () {
312 return this.values.hsv;
313 },
314 hwbArray: function () {
315 var values = this.values;
316 if (values.alpha !== 1) {
317 return values.hwb.concat([values.alpha]);
318 }
319 return values.hwb;
320 },
321 cmykArray: function () {
322 return this.values.cmyk;
323 },
324 rgbaArray: function () {
325 var values = this.values;
326 return values.rgb.concat([values.alpha]);
327 },
328 hslaArray: function () {
329 var values = this.values;
330 return values.hsl.concat([values.alpha]);
331 },
332 alpha: function (val) {
333 if (val === undefined) {
334 return this.values.alpha;
335 }
336 this.setValues('alpha', val);
337 return this;
338 },
339
340 red: function (val) {
341 return this.setChannel('rgb', 0, val);
342 },
343 green: function (val) {
344 return this.setChannel('rgb', 1, val);
345 },
346 blue: function (val) {
347 return this.setChannel('rgb', 2, val);
348 },
349 hue: function (val) {
350 if (val) {
351 val %= 360;
352 val = val < 0 ? 360 + val : val;
353 }
354 return this.setChannel('hsl', 0, val);
355 },
356 saturation: function (val) {
357 return this.setChannel('hsl', 1, val);
358 },
359 lightness: function (val) {
360 return this.setChannel('hsl', 2, val);
361 },
362 saturationv: function (val) {
363 return this.setChannel('hsv', 1, val);
364 },
365 whiteness: function (val) {
366 return this.setChannel('hwb', 1, val);
367 },
368 blackness: function (val) {
369 return this.setChannel('hwb', 2, val);
370 },
371 value: function (val) {
372 return this.setChannel('hsv', 2, val);
373 },
374 cyan: function (val) {
375 return this.setChannel('cmyk', 0, val);
376 },
377 magenta: function (val) {
378 return this.setChannel('cmyk', 1, val);
379 },
380 yellow: function (val) {
381 return this.setChannel('cmyk', 2, val);
382 },
383 black: function (val) {
384 return this.setChannel('cmyk', 3, val);
385 },
386
387 hexString: function () {
388 return string.hexString(this.values.rgb);
389 },
390 rgbString: function () {
391 return string.rgbString(this.values.rgb, this.values.alpha);
392 },
393 rgbaString: function () {
394 return string.rgbaString(this.values.rgb, this.values.alpha);
395 },
396 percentString: function () {
397 return string.percentString(this.values.rgb, this.values.alpha);
398 },
399 hslString: function () {
400 return string.hslString(this.values.hsl, this.values.alpha);
401 },
402 hslaString: function () {
403 return string.hslaString(this.values.hsl, this.values.alpha);
404 },
405 hwbString: function () {
406 return string.hwbString(this.values.hwb, this.values.alpha);
407 },
408 keyword: function () {
409 return string.keyword(this.values.rgb, this.values.alpha);
410 },
411
412 rgbNumber: function () {
413 var rgb = this.values.rgb;
414 return (rgb[0] << 16) | (rgb[1] << 8) | rgb[2];
415 },
416
417 luminosity: function () {
418 // http://www.w3.org/TR/WCAG20/#relativeluminancedef
419 var rgb = this.values.rgb;
420 var lum = [];
421 for (var i = 0; i < rgb.length; i++) {
422 var chan = rgb[i] / 255;
423 lum[i] = (chan <= 0.03928) ? chan / 12.92 : Math.pow(((chan + 0.055) / 1.055), 2.4);
424 }
425 return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
426 },
427
428 contrast: function (color2) {
429 // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
430 var lum1 = this.luminosity();
431 var lum2 = color2.luminosity();
432 if (lum1 > lum2) {
433 return (lum1 + 0.05) / (lum2 + 0.05);
434 }
435 return (lum2 + 0.05) / (lum1 + 0.05);
436 },
437
438 level: function (color2) {
439 var contrastRatio = this.contrast(color2);
440 if (contrastRatio >= 7.1) {
441 return 'AAA';
442 }
443
444 return (contrastRatio >= 4.5) ? 'AA' : '';
445 },
446
447 dark: function () {
448 // YIQ equation from http://24ways.org/2010/calculating-color-contrast
449 var rgb = this.values.rgb;
450 var yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
451 return yiq < 128;
452 },
453
454 light: function () {
455 return !this.dark();
456 },
457
458 negate: function () {
459 var rgb = [];
460 for (var i = 0; i < 3; i++) {
461 rgb[i] = 255 - this.values.rgb[i];
462 }
463 this.setValues('rgb', rgb);
464 return this;
465 },
466
467 lighten: function (ratio) {
468 var hsl = this.values.hsl;
469 hsl[2] += hsl[2] * ratio;
470 this.setValues('hsl', hsl);
471 return this;
472 },
473
474 darken: function (ratio) {
475 var hsl = this.values.hsl;
476 hsl[2] -= hsl[2] * ratio;
477 this.setValues('hsl', hsl);
478 return this;
479 },
480
481 saturate: function (ratio) {
482 var hsl = this.values.hsl;
483 hsl[1] += hsl[1] * ratio;
484 this.setValues('hsl', hsl);
485 return this;
486 },
487
488 desaturate: function (ratio) {
489 var hsl = this.values.hsl;
490 hsl[1] -= hsl[1] * ratio;
491 this.setValues('hsl', hsl);
492 return this;
493 },
494
495 whiten: function (ratio) {
496 var hwb = this.values.hwb;
497 hwb[1] += hwb[1] * ratio;
498 this.setValues('hwb', hwb);
499 return this;
500 },
501
502 blacken: function (ratio) {
503 var hwb = this.values.hwb;
504 hwb[2] += hwb[2] * ratio;
505 this.setValues('hwb', hwb);
506 return this;
507 },
508
509 greyscale: function () {
510 var rgb = this.values.rgb;
511 // http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
512 var val = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
513 this.setValues('rgb', [val, val, val]);
514 return this;
515 },
516
517 clearer: function (ratio) {
518 var alpha = this.values.alpha;
519 this.setValues('alpha', alpha - (alpha * ratio));
520 return this;
521 },
522
523 opaquer: function (ratio) {
524 var alpha = this.values.alpha;
525 this.setValues('alpha', alpha + (alpha * ratio));
526 return this;
527 },
528
529 rotate: function (degrees) {
530 var hsl = this.values.hsl;
531 var hue = (hsl[0] + degrees) % 360;
532 hsl[0] = hue < 0 ? 360 + hue : hue;
533 this.setValues('hsl', hsl);
534 return this;
535 },
536
537 /**
538 * Ported from sass implementation in C
539 * https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209
540 */
541 mix: function (mixinColor, weight) {
542 var color1 = this;
543 var color2 = mixinColor;
544 var p = weight === undefined ? 0.5 : weight;
545
546 var w = 2 * p - 1;
547 var a = color1.alpha() - color2.alpha();
548
549 var w1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
550 var w2 = 1 - w1;
551
552 return this
553 .rgb(
554 w1 * color1.red() + w2 * color2.red(),
555 w1 * color1.green() + w2 * color2.green(),
556 w1 * color1.blue() + w2 * color2.blue()
557 )
558 .alpha(color1.alpha() * p + color2.alpha() * (1 - p));
559 },
560
561 toJSON: function () {
562 return this.rgb();
563 },
564
565 clone: function () {
566 // NOTE(SB): using node-clone creates a dependency to Buffer when using browserify,
567 // making the final build way to big to embed in Chart.js. So let's do it manually,
568 // assuming that values to clone are 1 dimension arrays containing only numbers,
569 // except 'alpha' which is a number.
570 var result = new Color();
571 var source = this.values;
572 var target = result.values;
573 var value, type;
574
575 for (var prop in source) {
576 if (source.hasOwnProperty(prop)) {
577 value = source[prop];
578 type = ({}).toString.call(value);
579 if (type === '[object Array]') {
580 target[prop] = value.slice(0);
581 } else if (type === '[object Number]') {
582 target[prop] = value;
583 } else {
584 console.error('unexpected color value:', value);
585 }
586 }
587 }
588
589 return result;
590 }
591};
592
593Color.prototype.spaces = {
594 rgb: ['red', 'green', 'blue'],
595 hsl: ['hue', 'saturation', 'lightness'],
596 hsv: ['hue', 'saturation', 'value'],
597 hwb: ['hue', 'whiteness', 'blackness'],
598 cmyk: ['cyan', 'magenta', 'yellow', 'black']
599};
600
601Color.prototype.maxes = {
602 rgb: [255, 255, 255],
603 hsl: [360, 100, 100],
604 hsv: [360, 100, 100],
605 hwb: [360, 100, 100],
606 cmyk: [100, 100, 100, 100]
607};
608
609Color.prototype.getValues = function (space) {
610 var values = this.values;
611 var vals = {};
612
613 for (var i = 0; i < space.length; i++) {
614 vals[space.charAt(i)] = values[space][i];
615 }
616
617 if (values.alpha !== 1) {
618 vals.a = values.alpha;
619 }
620
621 // {r: 255, g: 255, b: 255, a: 0.4}
622 return vals;
623};
624
625Color.prototype.setValues = function (space, vals) {
626 var values = this.values;
627 var spaces = this.spaces;
628 var maxes = this.maxes;
629 var alpha = 1;
630 var i;
631
632 this.valid = true;
633
634 if (space === 'alpha') {
635 alpha = vals;
636 } else if (vals.length) {
637 // [10, 10, 10]
638 values[space] = vals.slice(0, space.length);
639 alpha = vals[space.length];
640 } else if (vals[space.charAt(0)] !== undefined) {
641 // {r: 10, g: 10, b: 10}
642 for (i = 0; i < space.length; i++) {
643 values[space][i] = vals[space.charAt(i)];
644 }
645
646 alpha = vals.a;
647 } else if (vals[spaces[space][0]] !== undefined) {
648 // {red: 10, green: 10, blue: 10}
649 var chans = spaces[space];
650
651 for (i = 0; i < space.length; i++) {
652 values[space][i] = vals[chans[i]];
653 }
654
655 alpha = vals.alpha;
656 }
657
658 values.alpha = Math.max(0, Math.min(1, (alpha === undefined ? values.alpha : alpha)));
659
660 if (space === 'alpha') {
661 return false;
662 }
663
664 var capped;
665
666 // cap values of the space prior converting all values
667 for (i = 0; i < space.length; i++) {
668 capped = Math.max(0, Math.min(maxes[space][i], values[space][i]));
669 values[space][i] = Math.round(capped);
670 }
671
672 // convert to all the other color spaces
673 for (var sname in spaces) {
674 if (sname !== space) {
675 values[sname] = convert[space][sname](values[space]);
676 }
677 }
678
679 return true;
680};
681
682Color.prototype.setSpace = function (space, args) {
683 var vals = args[0];
684
685 if (vals === undefined) {
686 // color.rgb()
687 return this.getValues(space);
688 }
689
690 // color.rgb(10, 10, 10)
691 if (typeof vals === 'number') {
692 vals = Array.prototype.slice.call(args);
693 }
694
695 this.setValues(space, vals);
696 return this;
697};
698
699Color.prototype.setChannel = function (space, index, val) {
700 var svalues = this.values[space];
701 if (val === undefined) {
702 // color.red()
703 return svalues[index];
704 } else if (val === svalues[index]) {
705 // color.red(color.red())
706 return this;
707 }
708
709 // color.red(100)
710 svalues[index] = val;
711 this.setValues(space, svalues);
712
713 return this;
714};
715
716if (typeof window !== 'undefined') {
717 window.Color = Color;
718}
719
720module.exports = Color;
721
722},{"2":2,"5":5}],4:[function(require,module,exports){
723/* MIT license */
724
725module.exports = {
726 rgb2hsl: rgb2hsl,
727 rgb2hsv: rgb2hsv,
728 rgb2hwb: rgb2hwb,
729 rgb2cmyk: rgb2cmyk,
730 rgb2keyword: rgb2keyword,
731 rgb2xyz: rgb2xyz,
732 rgb2lab: rgb2lab,
733 rgb2lch: rgb2lch,
734
735 hsl2rgb: hsl2rgb,
736 hsl2hsv: hsl2hsv,
737 hsl2hwb: hsl2hwb,
738 hsl2cmyk: hsl2cmyk,
739 hsl2keyword: hsl2keyword,
740
741 hsv2rgb: hsv2rgb,
742 hsv2hsl: hsv2hsl,
743 hsv2hwb: hsv2hwb,
744 hsv2cmyk: hsv2cmyk,
745 hsv2keyword: hsv2keyword,
746
747 hwb2rgb: hwb2rgb,
748 hwb2hsl: hwb2hsl,
749 hwb2hsv: hwb2hsv,
750 hwb2cmyk: hwb2cmyk,
751 hwb2keyword: hwb2keyword,
752
753 cmyk2rgb: cmyk2rgb,
754 cmyk2hsl: cmyk2hsl,
755 cmyk2hsv: cmyk2hsv,
756 cmyk2hwb: cmyk2hwb,
757 cmyk2keyword: cmyk2keyword,
758
759 keyword2rgb: keyword2rgb,
760 keyword2hsl: keyword2hsl,
761 keyword2hsv: keyword2hsv,
762 keyword2hwb: keyword2hwb,
763 keyword2cmyk: keyword2cmyk,
764 keyword2lab: keyword2lab,
765 keyword2xyz: keyword2xyz,
766
767 xyz2rgb: xyz2rgb,
768 xyz2lab: xyz2lab,
769 xyz2lch: xyz2lch,
770
771 lab2xyz: lab2xyz,
772 lab2rgb: lab2rgb,
773 lab2lch: lab2lch,
774
775 lch2lab: lch2lab,
776 lch2xyz: lch2xyz,
777 lch2rgb: lch2rgb
778}
779
780
781function rgb2hsl(rgb) {
782 var r = rgb[0]/255,
783 g = rgb[1]/255,
784 b = rgb[2]/255,
785 min = Math.min(r, g, b),
786 max = Math.max(r, g, b),
787 delta = max - min,
788 h, s, l;
789
790 if (max == min)
791 h = 0;
792 else if (r == max)
793 h = (g - b) / delta;
794 else if (g == max)
795 h = 2 + (b - r) / delta;
796 else if (b == max)
797 h = 4 + (r - g)/ delta;
798
799 h = Math.min(h * 60, 360);
800
801 if (h < 0)
802 h += 360;
803
804 l = (min + max) / 2;
805
806 if (max == min)
807 s = 0;
808 else if (l <= 0.5)
809 s = delta / (max + min);
810 else
811 s = delta / (2 - max - min);
812
813 return [h, s * 100, l * 100];
814}
815
816function rgb2hsv(rgb) {
817 var r = rgb[0],
818 g = rgb[1],
819 b = rgb[2],
820 min = Math.min(r, g, b),
821 max = Math.max(r, g, b),
822 delta = max - min,
823 h, s, v;
824
825 if (max == 0)
826 s = 0;
827 else
828 s = (delta/max * 1000)/10;
829
830 if (max == min)
831 h = 0;
832 else if (r == max)
833 h = (g - b) / delta;
834 else if (g == max)
835 h = 2 + (b - r) / delta;
836 else if (b == max)
837 h = 4 + (r - g) / delta;
838
839 h = Math.min(h * 60, 360);
840
841 if (h < 0)
842 h += 360;
843
844 v = ((max / 255) * 1000) / 10;
845
846 return [h, s, v];
847}
848
849function rgb2hwb(rgb) {
850 var r = rgb[0],
851 g = rgb[1],
852 b = rgb[2],
853 h = rgb2hsl(rgb)[0],
854 w = 1/255 * Math.min(r, Math.min(g, b)),
855 b = 1 - 1/255 * Math.max(r, Math.max(g, b));
856
857 return [h, w * 100, b * 100];
858}
859
860function rgb2cmyk(rgb) {
861 var r = rgb[0] / 255,
862 g = rgb[1] / 255,
863 b = rgb[2] / 255,
864 c, m, y, k;
865
866 k = Math.min(1 - r, 1 - g, 1 - b);
867 c = (1 - r - k) / (1 - k) || 0;
868 m = (1 - g - k) / (1 - k) || 0;
869 y = (1 - b - k) / (1 - k) || 0;
870 return [c * 100, m * 100, y * 100, k * 100];
871}
872
873function rgb2keyword(rgb) {
874 return reverseKeywords[JSON.stringify(rgb)];
875}
876
877function rgb2xyz(rgb) {
878 var r = rgb[0] / 255,
879 g = rgb[1] / 255,
880 b = rgb[2] / 255;
881
882 // assume sRGB
883 r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
884 g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
885 b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
886
887 var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
888 var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
889 var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
890
891 return [x * 100, y *100, z * 100];
892}
893
894function rgb2lab(rgb) {
895 var xyz = rgb2xyz(rgb),
896 x = xyz[0],
897 y = xyz[1],
898 z = xyz[2],
899 l, a, b;
900
901 x /= 95.047;
902 y /= 100;
903 z /= 108.883;
904
905 x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
906 y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
907 z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
908
909 l = (116 * y) - 16;
910 a = 500 * (x - y);
911 b = 200 * (y - z);
912
913 return [l, a, b];
914}
915
916function rgb2lch(args) {
917 return lab2lch(rgb2lab(args));
918}
919
920function hsl2rgb(hsl) {
921 var h = hsl[0] / 360,
922 s = hsl[1] / 100,
923 l = hsl[2] / 100,
924 t1, t2, t3, rgb, val;
925
926 if (s == 0) {
927 val = l * 255;
928 return [val, val, val];
929 }
930
931 if (l < 0.5)
932 t2 = l * (1 + s);
933 else
934 t2 = l + s - l * s;
935 t1 = 2 * l - t2;
936
937 rgb = [0, 0, 0];
938 for (var i = 0; i < 3; i++) {
939 t3 = h + 1 / 3 * - (i - 1);
940 t3 < 0 && t3++;
941 t3 > 1 && t3--;
942
943 if (6 * t3 < 1)
944 val = t1 + (t2 - t1) * 6 * t3;
945 else if (2 * t3 < 1)
946 val = t2;
947 else if (3 * t3 < 2)
948 val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
949 else
950 val = t1;
951
952 rgb[i] = val * 255;
953 }
954
955 return rgb;
956}
957
958function hsl2hsv(hsl) {
959 var h = hsl[0],
960 s = hsl[1] / 100,
961 l = hsl[2] / 100,
962 sv, v;
963
964 if(l === 0) {
965 // no need to do calc on black
966 // also avoids divide by 0 error
967 return [0, 0, 0];
968 }
969
970 l *= 2;
971 s *= (l <= 1) ? l : 2 - l;
972 v = (l + s) / 2;
973 sv = (2 * s) / (l + s);
974 return [h, sv * 100, v * 100];
975}
976
977function hsl2hwb(args) {
978 return rgb2hwb(hsl2rgb(args));
979}
980
981function hsl2cmyk(args) {
982 return rgb2cmyk(hsl2rgb(args));
983}
984
985function hsl2keyword(args) {
986 return rgb2keyword(hsl2rgb(args));
987}
988
989
990function hsv2rgb(hsv) {
991 var h = hsv[0] / 60,
992 s = hsv[1] / 100,
993 v = hsv[2] / 100,
994 hi = Math.floor(h) % 6;
995
996 var f = h - Math.floor(h),
997 p = 255 * v * (1 - s),
998 q = 255 * v * (1 - (s * f)),
999 t = 255 * v * (1 - (s * (1 - f))),
1000 v = 255 * v;
1001
1002 switch(hi) {
1003 case 0:
1004 return [v, t, p];
1005 case 1:
1006 return [q, v, p];
1007 case 2:
1008 return [p, v, t];
1009 case 3:
1010 return [p, q, v];
1011 case 4:
1012 return [t, p, v];
1013 case 5:
1014 return [v, p, q];
1015 }
1016}
1017
1018function hsv2hsl(hsv) {
1019 var h = hsv[0],
1020 s = hsv[1] / 100,
1021 v = hsv[2] / 100,
1022 sl, l;
1023
1024 l = (2 - s) * v;
1025 sl = s * v;
1026 sl /= (l <= 1) ? l : 2 - l;
1027 sl = sl || 0;
1028 l /= 2;
1029 return [h, sl * 100, l * 100];
1030}
1031
1032function hsv2hwb(args) {
1033 return rgb2hwb(hsv2rgb(args))
1034}
1035
1036function hsv2cmyk(args) {
1037 return rgb2cmyk(hsv2rgb(args));
1038}
1039
1040function hsv2keyword(args) {
1041 return rgb2keyword(hsv2rgb(args));
1042}
1043
1044// http://dev.w3.org/csswg/css-color/#hwb-to-rgb
1045function hwb2rgb(hwb) {
1046 var h = hwb[0] / 360,
1047 wh = hwb[1] / 100,
1048 bl = hwb[2] / 100,
1049 ratio = wh + bl,
1050 i, v, f, n;
1051
1052 // wh + bl cant be > 1
1053 if (ratio > 1) {
1054 wh /= ratio;
1055 bl /= ratio;
1056 }
1057
1058 i = Math.floor(6 * h);
1059 v = 1 - bl;
1060 f = 6 * h - i;
1061 if ((i & 0x01) != 0) {
1062 f = 1 - f;
1063 }
1064 n = wh + f * (v - wh); // linear interpolation
1065
1066 switch (i) {
1067 default:
1068 case 6:
1069 case 0: r = v; g = n; b = wh; break;
1070 case 1: r = n; g = v; b = wh; break;
1071 case 2: r = wh; g = v; b = n; break;
1072 case 3: r = wh; g = n; b = v; break;
1073 case 4: r = n; g = wh; b = v; break;
1074 case 5: r = v; g = wh; b = n; break;
1075 }
1076
1077 return [r * 255, g * 255, b * 255];
1078}
1079
1080function hwb2hsl(args) {
1081 return rgb2hsl(hwb2rgb(args));
1082}
1083
1084function hwb2hsv(args) {
1085 return rgb2hsv(hwb2rgb(args));
1086}
1087
1088function hwb2cmyk(args) {
1089 return rgb2cmyk(hwb2rgb(args));
1090}
1091
1092function hwb2keyword(args) {
1093 return rgb2keyword(hwb2rgb(args));
1094}
1095
1096function cmyk2rgb(cmyk) {
1097 var c = cmyk[0] / 100,
1098 m = cmyk[1] / 100,
1099 y = cmyk[2] / 100,
1100 k = cmyk[3] / 100,
1101 r, g, b;
1102
1103 r = 1 - Math.min(1, c * (1 - k) + k);
1104 g = 1 - Math.min(1, m * (1 - k) + k);
1105 b = 1 - Math.min(1, y * (1 - k) + k);
1106 return [r * 255, g * 255, b * 255];
1107}
1108
1109function cmyk2hsl(args) {
1110 return rgb2hsl(cmyk2rgb(args));
1111}
1112
1113function cmyk2hsv(args) {
1114 return rgb2hsv(cmyk2rgb(args));
1115}
1116
1117function cmyk2hwb(args) {
1118 return rgb2hwb(cmyk2rgb(args));
1119}
1120
1121function cmyk2keyword(args) {
1122 return rgb2keyword(cmyk2rgb(args));
1123}
1124
1125
1126function xyz2rgb(xyz) {
1127 var x = xyz[0] / 100,
1128 y = xyz[1] / 100,
1129 z = xyz[2] / 100,
1130 r, g, b;
1131
1132 r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
1133 g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
1134 b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
1135
1136 // assume sRGB
1137 r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
1138 : r = (r * 12.92);
1139
1140 g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
1141 : g = (g * 12.92);
1142
1143 b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
1144 : b = (b * 12.92);
1145
1146 r = Math.min(Math.max(0, r), 1);
1147 g = Math.min(Math.max(0, g), 1);
1148 b = Math.min(Math.max(0, b), 1);
1149
1150 return [r * 255, g * 255, b * 255];
1151}
1152
1153function xyz2lab(xyz) {
1154 var x = xyz[0],
1155 y = xyz[1],
1156 z = xyz[2],
1157 l, a, b;
1158
1159 x /= 95.047;
1160 y /= 100;
1161 z /= 108.883;
1162
1163 x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
1164 y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
1165 z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
1166
1167 l = (116 * y) - 16;
1168 a = 500 * (x - y);
1169 b = 200 * (y - z);
1170
1171 return [l, a, b];
1172}
1173
1174function xyz2lch(args) {
1175 return lab2lch(xyz2lab(args));
1176}
1177
1178function lab2xyz(lab) {
1179 var l = lab[0],
1180 a = lab[1],
1181 b = lab[2],
1182 x, y, z, y2;
1183
1184 if (l <= 8) {
1185 y = (l * 100) / 903.3;
1186 y2 = (7.787 * (y / 100)) + (16 / 116);
1187 } else {
1188 y = 100 * Math.pow((l + 16) / 116, 3);
1189 y2 = Math.pow(y / 100, 1/3);
1190 }
1191
1192 x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
1193
1194 z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
1195
1196 return [x, y, z];
1197}
1198
1199function lab2lch(lab) {
1200 var l = lab[0],
1201 a = lab[1],
1202 b = lab[2],
1203 hr, h, c;
1204
1205 hr = Math.atan2(b, a);
1206 h = hr * 360 / 2 / Math.PI;
1207 if (h < 0) {
1208 h += 360;
1209 }
1210 c = Math.sqrt(a * a + b * b);
1211 return [l, c, h];
1212}
1213
1214function lab2rgb(args) {
1215 return xyz2rgb(lab2xyz(args));
1216}
1217
1218function lch2lab(lch) {
1219 var l = lch[0],
1220 c = lch[1],
1221 h = lch[2],
1222 a, b, hr;
1223
1224 hr = h / 360 * 2 * Math.PI;
1225 a = c * Math.cos(hr);
1226 b = c * Math.sin(hr);
1227 return [l, a, b];
1228}
1229
1230function lch2xyz(args) {
1231 return lab2xyz(lch2lab(args));
1232}
1233
1234function lch2rgb(args) {
1235 return lab2rgb(lch2lab(args));
1236}
1237
1238function keyword2rgb(keyword) {
1239 return cssKeywords[keyword];
1240}
1241
1242function keyword2hsl(args) {
1243 return rgb2hsl(keyword2rgb(args));
1244}
1245
1246function keyword2hsv(args) {
1247 return rgb2hsv(keyword2rgb(args));
1248}
1249
1250function keyword2hwb(args) {
1251 return rgb2hwb(keyword2rgb(args));
1252}
1253
1254function keyword2cmyk(args) {
1255 return rgb2cmyk(keyword2rgb(args));
1256}
1257
1258function keyword2lab(args) {
1259 return rgb2lab(keyword2rgb(args));
1260}
1261
1262function keyword2xyz(args) {
1263 return rgb2xyz(keyword2rgb(args));
1264}
1265
1266var cssKeywords = {
1267 aliceblue: [240,248,255],
1268 antiquewhite: [250,235,215],
1269 aqua: [0,255,255],
1270 aquamarine: [127,255,212],
1271 azure: [240,255,255],
1272 beige: [245,245,220],
1273 bisque: [255,228,196],
1274 black: [0,0,0],
1275 blanchedalmond: [255,235,205],
1276 blue: [0,0,255],
1277 blueviolet: [138,43,226],
1278 brown: [165,42,42],
1279 burlywood: [222,184,135],
1280 cadetblue: [95,158,160],
1281 chartreuse: [127,255,0],
1282 chocolate: [210,105,30],
1283 coral: [255,127,80],
1284 cornflowerblue: [100,149,237],
1285 cornsilk: [255,248,220],
1286 crimson: [220,20,60],
1287 cyan: [0,255,255],
1288 darkblue: [0,0,139],
1289 darkcyan: [0,139,139],
1290 darkgoldenrod: [184,134,11],
1291 darkgray: [169,169,169],
1292 darkgreen: [0,100,0],
1293 darkgrey: [169,169,169],
1294 darkkhaki: [189,183,107],
1295 darkmagenta: [139,0,139],
1296 darkolivegreen: [85,107,47],
1297 darkorange: [255,140,0],
1298 darkorchid: [153,50,204],
1299 darkred: [139,0,0],
1300 darksalmon: [233,150,122],
1301 darkseagreen: [143,188,143],
1302 darkslateblue: [72,61,139],
1303 darkslategray: [47,79,79],
1304 darkslategrey: [47,79,79],
1305 darkturquoise: [0,206,209],
1306 darkviolet: [148,0,211],
1307 deeppink: [255,20,147],
1308 deepskyblue: [0,191,255],
1309 dimgray: [105,105,105],
1310 dimgrey: [105,105,105],
1311 dodgerblue: [30,144,255],
1312 firebrick: [178,34,34],
1313 floralwhite: [255,250,240],
1314 forestgreen: [34,139,34],
1315 fuchsia: [255,0,255],
1316 gainsboro: [220,220,220],
1317 ghostwhite: [248,248,255],
1318 gold: [255,215,0],
1319 goldenrod: [218,165,32],
1320 gray: [128,128,128],
1321 green: [0,128,0],
1322 greenyellow: [173,255,47],
1323 grey: [128,128,128],
1324 honeydew: [240,255,240],
1325 hotpink: [255,105,180],
1326 indianred: [205,92,92],
1327 indigo: [75,0,130],
1328 ivory: [255,255,240],
1329 khaki: [240,230,140],
1330 lavender: [230,230,250],
1331 lavenderblush: [255,240,245],
1332 lawngreen: [124,252,0],
1333 lemonchiffon: [255,250,205],
1334 lightblue: [173,216,230],
1335 lightcoral: [240,128,128],
1336 lightcyan: [224,255,255],
1337 lightgoldenrodyellow: [250,250,210],
1338 lightgray: [211,211,211],
1339 lightgreen: [144,238,144],
1340 lightgrey: [211,211,211],
1341 lightpink: [255,182,193],
1342 lightsalmon: [255,160,122],
1343 lightseagreen: [32,178,170],
1344 lightskyblue: [135,206,250],
1345 lightslategray: [119,136,153],
1346 lightslategrey: [119,136,153],
1347 lightsteelblue: [176,196,222],
1348 lightyellow: [255,255,224],
1349 lime: [0,255,0],
1350 limegreen: [50,205,50],
1351 linen: [250,240,230],
1352 magenta: [255,0,255],
1353 maroon: [128,0,0],
1354 mediumaquamarine: [102,205,170],
1355 mediumblue: [0,0,205],
1356 mediumorchid: [186,85,211],
1357 mediumpurple: [147,112,219],
1358 mediumseagreen: [60,179,113],
1359 mediumslateblue: [123,104,238],
1360 mediumspringgreen: [0,250,154],
1361 mediumturquoise: [72,209,204],
1362 mediumvioletred: [199,21,133],
1363 midnightblue: [25,25,112],
1364 mintcream: [245,255,250],
1365 mistyrose: [255,228,225],
1366 moccasin: [255,228,181],
1367 navajowhite: [255,222,173],
1368 navy: [0,0,128],
1369 oldlace: [253,245,230],
1370 olive: [128,128,0],
1371 olivedrab: [107,142,35],
1372 orange: [255,165,0],
1373 orangered: [255,69,0],
1374 orchid: [218,112,214],
1375 palegoldenrod: [238,232,170],
1376 palegreen: [152,251,152],
1377 paleturquoise: [175,238,238],
1378 palevioletred: [219,112,147],
1379 papayawhip: [255,239,213],
1380 peachpuff: [255,218,185],
1381 peru: [205,133,63],
1382 pink: [255,192,203],
1383 plum: [221,160,221],
1384 powderblue: [176,224,230],
1385 purple: [128,0,128],
1386 rebeccapurple: [102, 51, 153],
1387 red: [255,0,0],
1388 rosybrown: [188,143,143],
1389 royalblue: [65,105,225],
1390 saddlebrown: [139,69,19],
1391 salmon: [250,128,114],
1392 sandybrown: [244,164,96],
1393 seagreen: [46,139,87],
1394 seashell: [255,245,238],
1395 sienna: [160,82,45],
1396 silver: [192,192,192],
1397 skyblue: [135,206,235],
1398 slateblue: [106,90,205],
1399 slategray: [112,128,144],
1400 slategrey: [112,128,144],
1401 snow: [255,250,250],
1402 springgreen: [0,255,127],
1403 steelblue: [70,130,180],
1404 tan: [210,180,140],
1405 teal: [0,128,128],
1406 thistle: [216,191,216],
1407 tomato: [255,99,71],
1408 turquoise: [64,224,208],
1409 violet: [238,130,238],
1410 wheat: [245,222,179],
1411 white: [255,255,255],
1412 whitesmoke: [245,245,245],
1413 yellow: [255,255,0],
1414 yellowgreen: [154,205,50]
1415};
1416
1417var reverseKeywords = {};
1418for (var key in cssKeywords) {
1419 reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
1420}
1421
1422},{}],5:[function(require,module,exports){
1423var conversions = require(4);
1424
1425var convert = function() {
1426 return new Converter();
1427}
1428
1429for (var func in conversions) {
1430 // export Raw versions
1431 convert[func + "Raw"] = (function(func) {
1432 // accept array or plain args
1433 return function(arg) {
1434 if (typeof arg == "number")
1435 arg = Array.prototype.slice.call(arguments);
1436 return conversions[func](arg);
1437 }
1438 })(func);
1439
1440 var pair = /(\w+)2(\w+)/.exec(func),
1441 from = pair[1],
1442 to = pair[2];
1443
1444 // export rgb2hsl and ["rgb"]["hsl"]
1445 convert[from] = convert[from] || {};
1446
1447 convert[from][to] = convert[func] = (function(func) {
1448 return function(arg) {
1449 if (typeof arg == "number")
1450 arg = Array.prototype.slice.call(arguments);
1451
1452 var val = conversions[func](arg);
1453 if (typeof val == "string" || val === undefined)
1454 return val; // keyword
1455
1456 for (var i = 0; i < val.length; i++)
1457 val[i] = Math.round(val[i]);
1458 return val;
1459 }
1460 })(func);
1461}
1462
1463
1464/* Converter does lazy conversion and caching */
1465var Converter = function() {
1466 this.convs = {};
1467};
1468
1469/* Either get the values for a space or
1470 set the values for a space, depending on args */
1471Converter.prototype.routeSpace = function(space, args) {
1472 var values = args[0];
1473 if (values === undefined) {
1474 // color.rgb()
1475 return this.getValues(space);
1476 }
1477 // color.rgb(10, 10, 10)
1478 if (typeof values == "number") {
1479 values = Array.prototype.slice.call(args);
1480 }
1481
1482 return this.setValues(space, values);
1483};
1484
1485/* Set the values for a space, invalidating cache */
1486Converter.prototype.setValues = function(space, values) {
1487 this.space = space;
1488 this.convs = {};
1489 this.convs[space] = values;
1490 return this;
1491};
1492
1493/* Get the values for a space. If there's already
1494 a conversion for the space, fetch it, otherwise
1495 compute it */
1496Converter.prototype.getValues = function(space) {
1497 var vals = this.convs[space];
1498 if (!vals) {
1499 var fspace = this.space,
1500 from = this.convs[fspace];
1501 vals = convert[fspace][space](from);
1502
1503 this.convs[space] = vals;
1504 }
1505 return vals;
1506};
1507
1508["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function(space) {
1509 Converter.prototype[space] = function(vals) {
1510 return this.routeSpace(space, arguments);
1511 }
1512});
1513
1514module.exports = convert;
1515},{"4":4}],6:[function(require,module,exports){
1516'use strict'
1517
1518module.exports = {
1519 "aliceblue": [240, 248, 255],
1520 "antiquewhite": [250, 235, 215],
1521 "aqua": [0, 255, 255],
1522 "aquamarine": [127, 255, 212],
1523 "azure": [240, 255, 255],
1524 "beige": [245, 245, 220],
1525 "bisque": [255, 228, 196],
1526 "black": [0, 0, 0],
1527 "blanchedalmond": [255, 235, 205],
1528 "blue": [0, 0, 255],
1529 "blueviolet": [138, 43, 226],
1530 "brown": [165, 42, 42],
1531 "burlywood": [222, 184, 135],
1532 "cadetblue": [95, 158, 160],
1533 "chartreuse": [127, 255, 0],
1534 "chocolate": [210, 105, 30],
1535 "coral": [255, 127, 80],
1536 "cornflowerblue": [100, 149, 237],
1537 "cornsilk": [255, 248, 220],
1538 "crimson": [220, 20, 60],
1539 "cyan": [0, 255, 255],
1540 "darkblue": [0, 0, 139],
1541 "darkcyan": [0, 139, 139],
1542 "darkgoldenrod": [184, 134, 11],
1543 "darkgray": [169, 169, 169],
1544 "darkgreen": [0, 100, 0],
1545 "darkgrey": [169, 169, 169],
1546 "darkkhaki": [189, 183, 107],
1547 "darkmagenta": [139, 0, 139],
1548 "darkolivegreen": [85, 107, 47],
1549 "darkorange": [255, 140, 0],
1550 "darkorchid": [153, 50, 204],
1551 "darkred": [139, 0, 0],
1552 "darksalmon": [233, 150, 122],
1553 "darkseagreen": [143, 188, 143],
1554 "darkslateblue": [72, 61, 139],
1555 "darkslategray": [47, 79, 79],
1556 "darkslategrey": [47, 79, 79],
1557 "darkturquoise": [0, 206, 209],
1558 "darkviolet": [148, 0, 211],
1559 "deeppink": [255, 20, 147],
1560 "deepskyblue": [0, 191, 255],
1561 "dimgray": [105, 105, 105],
1562 "dimgrey": [105, 105, 105],
1563 "dodgerblue": [30, 144, 255],
1564 "firebrick": [178, 34, 34],
1565 "floralwhite": [255, 250, 240],
1566 "forestgreen": [34, 139, 34],
1567 "fuchsia": [255, 0, 255],
1568 "gainsboro": [220, 220, 220],
1569 "ghostwhite": [248, 248, 255],
1570 "gold": [255, 215, 0],
1571 "goldenrod": [218, 165, 32],
1572 "gray": [128, 128, 128],
1573 "green": [0, 128, 0],
1574 "greenyellow": [173, 255, 47],
1575 "grey": [128, 128, 128],
1576 "honeydew": [240, 255, 240],
1577 "hotpink": [255, 105, 180],
1578 "indianred": [205, 92, 92],
1579 "indigo": [75, 0, 130],
1580 "ivory": [255, 255, 240],
1581 "khaki": [240, 230, 140],
1582 "lavender": [230, 230, 250],
1583 "lavenderblush": [255, 240, 245],
1584 "lawngreen": [124, 252, 0],
1585 "lemonchiffon": [255, 250, 205],
1586 "lightblue": [173, 216, 230],
1587 "lightcoral": [240, 128, 128],
1588 "lightcyan": [224, 255, 255],
1589 "lightgoldenrodyellow": [250, 250, 210],
1590 "lightgray": [211, 211, 211],
1591 "lightgreen": [144, 238, 144],
1592 "lightgrey": [211, 211, 211],
1593 "lightpink": [255, 182, 193],
1594 "lightsalmon": [255, 160, 122],
1595 "lightseagreen": [32, 178, 170],
1596 "lightskyblue": [135, 206, 250],
1597 "lightslategray": [119, 136, 153],
1598 "lightslategrey": [119, 136, 153],
1599 "lightsteelblue": [176, 196, 222],
1600 "lightyellow": [255, 255, 224],
1601 "lime": [0, 255, 0],
1602 "limegreen": [50, 205, 50],
1603 "linen": [250, 240, 230],
1604 "magenta": [255, 0, 255],
1605 "maroon": [128, 0, 0],
1606 "mediumaquamarine": [102, 205, 170],
1607 "mediumblue": [0, 0, 205],
1608 "mediumorchid": [186, 85, 211],
1609 "mediumpurple": [147, 112, 219],
1610 "mediumseagreen": [60, 179, 113],
1611 "mediumslateblue": [123, 104, 238],
1612 "mediumspringgreen": [0, 250, 154],
1613 "mediumturquoise": [72, 209, 204],
1614 "mediumvioletred": [199, 21, 133],
1615 "midnightblue": [25, 25, 112],
1616 "mintcream": [245, 255, 250],
1617 "mistyrose": [255, 228, 225],
1618 "moccasin": [255, 228, 181],
1619 "navajowhite": [255, 222, 173],
1620 "navy": [0, 0, 128],
1621 "oldlace": [253, 245, 230],
1622 "olive": [128, 128, 0],
1623 "olivedrab": [107, 142, 35],
1624 "orange": [255, 165, 0],
1625 "orangered": [255, 69, 0],
1626 "orchid": [218, 112, 214],
1627 "palegoldenrod": [238, 232, 170],
1628 "palegreen": [152, 251, 152],
1629 "paleturquoise": [175, 238, 238],
1630 "palevioletred": [219, 112, 147],
1631 "papayawhip": [255, 239, 213],
1632 "peachpuff": [255, 218, 185],
1633 "peru": [205, 133, 63],
1634 "pink": [255, 192, 203],
1635 "plum": [221, 160, 221],
1636 "powderblue": [176, 224, 230],
1637 "purple": [128, 0, 128],
1638 "rebeccapurple": [102, 51, 153],
1639 "red": [255, 0, 0],
1640 "rosybrown": [188, 143, 143],
1641 "royalblue": [65, 105, 225],
1642 "saddlebrown": [139, 69, 19],
1643 "salmon": [250, 128, 114],
1644 "sandybrown": [244, 164, 96],
1645 "seagreen": [46, 139, 87],
1646 "seashell": [255, 245, 238],
1647 "sienna": [160, 82, 45],
1648 "silver": [192, 192, 192],
1649 "skyblue": [135, 206, 235],
1650 "slateblue": [106, 90, 205],
1651 "slategray": [112, 128, 144],
1652 "slategrey": [112, 128, 144],
1653 "snow": [255, 250, 250],
1654 "springgreen": [0, 255, 127],
1655 "steelblue": [70, 130, 180],
1656 "tan": [210, 180, 140],
1657 "teal": [0, 128, 128],
1658 "thistle": [216, 191, 216],
1659 "tomato": [255, 99, 71],
1660 "turquoise": [64, 224, 208],
1661 "violet": [238, 130, 238],
1662 "wheat": [245, 222, 179],
1663 "white": [255, 255, 255],
1664 "whitesmoke": [245, 245, 245],
1665 "yellow": [255, 255, 0],
1666 "yellowgreen": [154, 205, 50]
1667};
1668
1669},{}],7:[function(require,module,exports){
1670/**
1671 * @namespace Chart
1672 */
1673var Chart = require(26)();
1674
1675Chart.helpers = require(42);
1676
1677// @todo dispatch these helpers into appropriated helpers/helpers.* file and write unit tests!
1678require(24)(Chart);
1679
1680Chart.Animation = require(18);
1681Chart.animationService = require(19);
1682Chart.controllers = require(17);
1683Chart.DatasetController = require(21);
1684Chart.defaults = require(22);
1685Chart.Element = require(23);
1686Chart.elements = require(37);
1687Chart.Interaction = require(25);
1688Chart.layouts = require(27);
1689Chart.platform = require(45);
1690Chart.plugins = require(28);
1691Chart.Scale = require(29);
1692Chart.scaleService = require(30);
1693Chart.Ticks = require(31);
1694Chart.Tooltip = require(32);
1695
1696require(20)(Chart);
1697
1698require(52)(Chart);
1699require(50)(Chart);
1700require(51)(Chart);
1701require(53)(Chart);
1702require(54)(Chart);
1703require(55)(Chart);
1704
1705// Loading built-in plugins
1706var plugins = require(46);
1707for (var k in plugins) {
1708 if (plugins.hasOwnProperty(k)) {
1709 Chart.plugins.register(plugins[k]);
1710 }
1711}
1712
1713Chart.platform.initialize();
1714
1715module.exports = Chart;
1716if (typeof window !== 'undefined') {
1717 window.Chart = Chart;
1718}
1719
1720// DEPRECATIONS
1721
1722/**
1723 * Provided for backward compatibility, not available anymore
1724 * @namespace Chart.Legend
1725 * @deprecated since version 2.1.5
1726 * @todo remove at version 3
1727 * @private
1728 */
1729Chart.Legend = plugins.legend._element;
1730
1731/**
1732 * Provided for backward compatibility, not available anymore
1733 * @namespace Chart.Title
1734 * @deprecated since version 2.1.5
1735 * @todo remove at version 3
1736 * @private
1737 */
1738Chart.Title = plugins.title._element;
1739
1740/**
1741 * Provided for backward compatibility, use Chart.plugins instead
1742 * @namespace Chart.pluginService
1743 * @deprecated since version 2.1.5
1744 * @todo remove at version 3
1745 * @private
1746 */
1747Chart.pluginService = Chart.plugins;
1748
1749/**
1750 * Provided for backward compatibility, inheriting from Chart.PlugingBase has no
1751 * effect, instead simply create/register plugins via plain JavaScript objects.
1752 * @interface Chart.PluginBase
1753 * @deprecated since version 2.5.0
1754 * @todo remove at version 3
1755 * @private
1756 */
1757Chart.PluginBase = Chart.Element.extend({});
1758
1759/**
1760 * Provided for backward compatibility, use Chart.helpers.canvas instead.
1761 * @namespace Chart.canvasHelpers
1762 * @deprecated since version 2.6.0
1763 * @todo remove at version 3
1764 * @private
1765 */
1766Chart.canvasHelpers = Chart.helpers.canvas;
1767
1768/**
1769 * Provided for backward compatibility, use Chart.layouts instead.
1770 * @namespace Chart.layoutService
1771 * @deprecated since version 2.7.3
1772 * @todo remove at version 3
1773 * @private
1774 */
1775Chart.layoutService = Chart.layouts;
1776
1777/**
1778 * Provided for backward compatibility, instead we should create a new Chart
1779 * by setting the type in the config (`new Chart(id, {type: '{chart-type}'}`).
1780 * @deprecated since version 2.8.0
1781 * @todo remove at version 3
1782 */
1783Chart.helpers.each(
1784 [
1785 'Bar',
1786 'Bubble',
1787 'Doughnut',
1788 'Line',
1789 'PolarArea',
1790 'Radar',
1791 'Scatter'
1792 ],
1793 function(klass) {
1794 Chart[klass] = function(ctx, cfg) {
1795 return new Chart(ctx, Chart.helpers.merge(cfg || {}, {
1796 type: klass.charAt(0).toLowerCase() + klass.slice(1)
1797 }));
1798 };
1799 }
1800);
1801
1802},{"17":17,"18":18,"19":19,"20":20,"21":21,"22":22,"23":23,"24":24,"25":25,"26":26,"27":27,"28":28,"29":29,"30":30,"31":31,"32":32,"37":37,"42":42,"45":45,"46":46,"50":50,"51":51,"52":52,"53":53,"54":54,"55":55}],8:[function(require,module,exports){
1803'use strict';
1804
1805var DatasetController = require(21);
1806var defaults = require(22);
1807var elements = require(37);
1808var helpers = require(42);
1809
1810defaults._set('bar', {
1811 hover: {
1812 mode: 'label'
1813 },
1814
1815 scales: {
1816 xAxes: [{
1817 type: 'category',
1818 categoryPercentage: 0.8,
1819 barPercentage: 0.9,
1820 offset: true,
1821 gridLines: {
1822 offsetGridLines: true
1823 }
1824 }],
1825
1826 yAxes: [{
1827 type: 'linear'
1828 }]
1829 }
1830});
1831
1832/**
1833 * Computes the "optimal" sample size to maintain bars equally sized while preventing overlap.
1834 * @private
1835 */
1836function computeMinSampleSize(scale, pixels) {
1837 var min = scale.isHorizontal() ? scale.width : scale.height;
1838 var ticks = scale.getTicks();
1839 var prev, curr, i, ilen;
1840
1841 for (i = 1, ilen = pixels.length; i < ilen; ++i) {
1842 min = Math.min(min, pixels[i] - pixels[i - 1]);
1843 }
1844
1845 for (i = 0, ilen = ticks.length; i < ilen; ++i) {
1846 curr = scale.getPixelForTick(i);
1847 min = i > 0 ? Math.min(min, curr - prev) : min;
1848 prev = curr;
1849 }
1850
1851 return min;
1852}
1853
1854/**
1855 * Computes an "ideal" category based on the absolute bar thickness or, if undefined or null,
1856 * uses the smallest interval (see computeMinSampleSize) that prevents bar overlapping. This
1857 * mode currently always generates bars equally sized (until we introduce scriptable options?).
1858 * @private
1859 */
1860function computeFitCategoryTraits(index, ruler, options) {
1861 var thickness = options.barThickness;
1862 var count = ruler.stackCount;
1863 var curr = ruler.pixels[index];
1864 var size, ratio;
1865
1866 if (helpers.isNullOrUndef(thickness)) {
1867 size = ruler.min * options.categoryPercentage;
1868 ratio = options.barPercentage;
1869 } else {
1870 // When bar thickness is enforced, category and bar percentages are ignored.
1871 // Note(SB): we could add support for relative bar thickness (e.g. barThickness: '50%')
1872 // and deprecate barPercentage since this value is ignored when thickness is absolute.
1873 size = thickness * count;
1874 ratio = 1;
1875 }
1876
1877 return {
1878 chunk: size / count,
1879 ratio: ratio,
1880 start: curr - (size / 2)
1881 };
1882}
1883
1884/**
1885 * Computes an "optimal" category that globally arranges bars side by side (no gap when
1886 * percentage options are 1), based on the previous and following categories. This mode
1887 * generates bars with different widths when data are not evenly spaced.
1888 * @private
1889 */
1890function computeFlexCategoryTraits(index, ruler, options) {
1891 var pixels = ruler.pixels;
1892 var curr = pixels[index];
1893 var prev = index > 0 ? pixels[index - 1] : null;
1894 var next = index < pixels.length - 1 ? pixels[index + 1] : null;
1895 var percent = options.categoryPercentage;
1896 var start, size;
1897
1898 if (prev === null) {
1899 // first data: its size is double based on the next point or,
1900 // if it's also the last data, we use the scale end extremity.
1901 prev = curr - (next === null ? ruler.end - curr : next - curr);
1902 }
1903
1904 if (next === null) {
1905 // last data: its size is also double based on the previous point.
1906 next = curr + curr - prev;
1907 }
1908
1909 start = curr - ((curr - prev) / 2) * percent;
1910 size = ((next - prev) / 2) * percent;
1911
1912 return {
1913 chunk: size / ruler.stackCount,
1914 ratio: options.barPercentage,
1915 start: start
1916 };
1917}
1918
1919module.exports = DatasetController.extend({
1920
1921 dataElementType: elements.Rectangle,
1922
1923 initialize: function() {
1924 var me = this;
1925 var meta;
1926
1927 DatasetController.prototype.initialize.apply(me, arguments);
1928
1929 meta = me.getMeta();
1930 meta.stack = me.getDataset().stack;
1931 meta.bar = true;
1932 },
1933
1934 update: function(reset) {
1935 var me = this;
1936 var rects = me.getMeta().data;
1937 var i, ilen;
1938
1939 me._ruler = me.getRuler();
1940
1941 for (i = 0, ilen = rects.length; i < ilen; ++i) {
1942 me.updateElement(rects[i], i, reset);
1943 }
1944 },
1945
1946 updateElement: function(rectangle, index, reset) {
1947 var me = this;
1948 var meta = me.getMeta();
1949 var dataset = me.getDataset();
1950 var options = me._resolveElementOptions(rectangle, index);
1951
1952 rectangle._xScale = me.getScaleForId(meta.xAxisID);
1953 rectangle._yScale = me.getScaleForId(meta.yAxisID);
1954 rectangle._datasetIndex = me.index;
1955 rectangle._index = index;
1956 rectangle._model = {
1957 backgroundColor: options.backgroundColor,
1958 borderColor: options.borderColor,
1959 borderSkipped: options.borderSkipped,
1960 borderWidth: options.borderWidth,
1961 datasetLabel: dataset.label,
1962 label: me.chart.data.labels[index]
1963 };
1964
1965 me._updateElementGeometry(rectangle, index, reset);
1966
1967 rectangle.pivot();
1968 },
1969
1970 /**
1971 * @private
1972 */
1973 _updateElementGeometry: function(rectangle, index, reset) {
1974 var me = this;
1975 var model = rectangle._model;
1976 var vscale = me.getValueScale();
1977 var base = vscale.getBasePixel();
1978 var horizontal = vscale.isHorizontal();
1979 var ruler = me._ruler || me.getRuler();
1980 var vpixels = me.calculateBarValuePixels(me.index, index);
1981 var ipixels = me.calculateBarIndexPixels(me.index, index, ruler);
1982
1983 model.horizontal = horizontal;
1984 model.base = reset ? base : vpixels.base;
1985 model.x = horizontal ? reset ? base : vpixels.head : ipixels.center;
1986 model.y = horizontal ? ipixels.center : reset ? base : vpixels.head;
1987 model.height = horizontal ? ipixels.size : undefined;
1988 model.width = horizontal ? undefined : ipixels.size;
1989 },
1990
1991 /**
1992 * @private
1993 */
1994 getValueScaleId: function() {
1995 return this.getMeta().yAxisID;
1996 },
1997
1998 /**
1999 * @private
2000 */
2001 getIndexScaleId: function() {
2002 return this.getMeta().xAxisID;
2003 },
2004
2005 /**
2006 * @private
2007 */
2008 getValueScale: function() {
2009 return this.getScaleForId(this.getValueScaleId());
2010 },
2011
2012 /**
2013 * @private
2014 */
2015 getIndexScale: function() {
2016 return this.getScaleForId(this.getIndexScaleId());
2017 },
2018
2019 /**
2020 * Returns the stacks based on groups and bar visibility.
2021 * @param {Number} [last] - The dataset index
2022 * @returns {Array} The stack list
2023 * @private
2024 */
2025 _getStacks: function(last) {
2026 var me = this;
2027 var chart = me.chart;
2028 var scale = me.getIndexScale();
2029 var stacked = scale.options.stacked;
2030 var ilen = last === undefined ? chart.data.datasets.length : last + 1;
2031 var stacks = [];
2032 var i, meta;
2033
2034 for (i = 0; i < ilen; ++i) {
2035 meta = chart.getDatasetMeta(i);
2036 if (meta.bar && chart.isDatasetVisible(i) &&
2037 (stacked === false ||
2038 (stacked === true && stacks.indexOf(meta.stack) === -1) ||
2039 (stacked === undefined && (meta.stack === undefined || stacks.indexOf(meta.stack) === -1)))) {
2040 stacks.push(meta.stack);
2041 }
2042 }
2043
2044 return stacks;
2045 },
2046
2047 /**
2048 * Returns the effective number of stacks based on groups and bar visibility.
2049 * @private
2050 */
2051 getStackCount: function() {
2052 return this._getStacks().length;
2053 },
2054
2055 /**
2056 * Returns the stack index for the given dataset based on groups and bar visibility.
2057 * @param {Number} [datasetIndex] - The dataset index
2058 * @param {String} [name] - The stack name to find
2059 * @returns {Number} The stack index
2060 * @private
2061 */
2062 getStackIndex: function(datasetIndex, name) {
2063 var stacks = this._getStacks(datasetIndex);
2064 var index = (name !== undefined)
2065 ? stacks.indexOf(name)
2066 : -1; // indexOf returns -1 if element is not present
2067
2068 return (index === -1)
2069 ? stacks.length - 1
2070 : index;
2071 },
2072
2073 /**
2074 * @private
2075 */
2076 getRuler: function() {
2077 var me = this;
2078 var scale = me.getIndexScale();
2079 var stackCount = me.getStackCount();
2080 var datasetIndex = me.index;
2081 var isHorizontal = scale.isHorizontal();
2082 var start = isHorizontal ? scale.left : scale.top;
2083 var end = start + (isHorizontal ? scale.width : scale.height);
2084 var pixels = [];
2085 var i, ilen, min;
2086
2087 for (i = 0, ilen = me.getMeta().data.length; i < ilen; ++i) {
2088 pixels.push(scale.getPixelForValue(null, i, datasetIndex));
2089 }
2090
2091 min = helpers.isNullOrUndef(scale.options.barThickness)
2092 ? computeMinSampleSize(scale, pixels)
2093 : -1;
2094
2095 return {
2096 min: min,
2097 pixels: pixels,
2098 start: start,
2099 end: end,
2100 stackCount: stackCount,
2101 scale: scale
2102 };
2103 },
2104
2105 /**
2106 * Note: pixel values are not clamped to the scale area.
2107 * @private
2108 */
2109 calculateBarValuePixels: function(datasetIndex, index) {
2110 var me = this;
2111 var chart = me.chart;
2112 var meta = me.getMeta();
2113 var scale = me.getValueScale();
2114 var isHorizontal = scale.isHorizontal();
2115 var datasets = chart.data.datasets;
2116 var value = scale.getRightValue(datasets[datasetIndex].data[index]);
2117 var minBarLength = scale.options.minBarLength;
2118 var stacked = scale.options.stacked;
2119 var stack = meta.stack;
2120 var start = 0;
2121 var i, imeta, ivalue, base, head, size;
2122
2123 if (stacked || (stacked === undefined && stack !== undefined)) {
2124 for (i = 0; i < datasetIndex; ++i) {
2125 imeta = chart.getDatasetMeta(i);
2126
2127 if (imeta.bar &&
2128 imeta.stack === stack &&
2129 imeta.controller.getValueScaleId() === scale.id &&
2130 chart.isDatasetVisible(i)) {
2131
2132 ivalue = scale.getRightValue(datasets[i].data[index]);
2133 if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) {
2134 start += ivalue;
2135 }
2136 }
2137 }
2138 }
2139
2140 base = scale.getPixelForValue(start);
2141 head = scale.getPixelForValue(start + value);
2142 size = (head - base) / 2;
2143
2144 if (minBarLength !== undefined && Math.abs(size) < minBarLength) {
2145 size = minBarLength;
2146 if (value >= 0 && !isHorizontal || value < 0 && isHorizontal) {
2147 head = base - minBarLength;
2148 } else {
2149 head = base + minBarLength;
2150 }
2151 }
2152
2153 return {
2154 size: size,
2155 base: base,
2156 head: head,
2157 center: head + size / 2
2158 };
2159 },
2160
2161 /**
2162 * @private
2163 */
2164 calculateBarIndexPixels: function(datasetIndex, index, ruler) {
2165 var me = this;
2166 var options = ruler.scale.options;
2167 var range = options.barThickness === 'flex'
2168 ? computeFlexCategoryTraits(index, ruler, options)
2169 : computeFitCategoryTraits(index, ruler, options);
2170
2171 var stackIndex = me.getStackIndex(datasetIndex, me.getMeta().stack);
2172 var center = range.start + (range.chunk * stackIndex) + (range.chunk / 2);
2173 var size = Math.min(
2174 helpers.valueOrDefault(options.maxBarThickness, Infinity),
2175 range.chunk * range.ratio);
2176
2177 return {
2178 base: center - size / 2,
2179 head: center + size / 2,
2180 center: center,
2181 size: size
2182 };
2183 },
2184
2185 draw: function() {
2186 var me = this;
2187 var chart = me.chart;
2188 var scale = me.getValueScale();
2189 var rects = me.getMeta().data;
2190 var dataset = me.getDataset();
2191 var ilen = rects.length;
2192 var i = 0;
2193
2194 helpers.canvas.clipArea(chart.ctx, chart.chartArea);
2195
2196 for (; i < ilen; ++i) {
2197 if (!isNaN(scale.getRightValue(dataset.data[i]))) {
2198 rects[i].draw();
2199 }
2200 }
2201
2202 helpers.canvas.unclipArea(chart.ctx);
2203 },
2204
2205 /**
2206 * @private
2207 */
2208 _resolveElementOptions: function(rectangle, index) {
2209 var me = this;
2210 var chart = me.chart;
2211 var datasets = chart.data.datasets;
2212 var dataset = datasets[me.index];
2213 var custom = rectangle.custom || {};
2214 var options = chart.options.elements.rectangle;
2215 var resolve = helpers.options.resolve;
2216 var values = {};
2217 var i, ilen, key;
2218
2219 // Scriptable options
2220 var context = {
2221 chart: chart,
2222 dataIndex: index,
2223 dataset: dataset,
2224 datasetIndex: me.index
2225 };
2226
2227 var keys = [
2228 'backgroundColor',
2229 'borderColor',
2230 'borderSkipped',
2231 'borderWidth'
2232 ];
2233
2234 for (i = 0, ilen = keys.length; i < ilen; ++i) {
2235 key = keys[i];
2236 values[key] = resolve([
2237 custom[key],
2238 dataset[key],
2239 options[key]
2240 ], context, index);
2241 }
2242
2243 return values;
2244 }
2245});
2246
2247},{"21":21,"22":22,"37":37,"42":42}],9:[function(require,module,exports){
2248'use strict';
2249
2250var DatasetController = require(21);
2251var defaults = require(22);
2252var elements = require(37);
2253var helpers = require(42);
2254
2255defaults._set('bubble', {
2256 hover: {
2257 mode: 'single'
2258 },
2259
2260 scales: {
2261 xAxes: [{
2262 type: 'linear', // bubble should probably use a linear scale by default
2263 position: 'bottom',
2264 id: 'x-axis-0' // need an ID so datasets can reference the scale
2265 }],
2266 yAxes: [{
2267 type: 'linear',
2268 position: 'left',
2269 id: 'y-axis-0'
2270 }]
2271 },
2272
2273 tooltips: {
2274 callbacks: {
2275 title: function() {
2276 // Title doesn't make sense for scatter since we format the data as a point
2277 return '';
2278 },
2279 label: function(item, data) {
2280 var datasetLabel = data.datasets[item.datasetIndex].label || '';
2281 var dataPoint = data.datasets[item.datasetIndex].data[item.index];
2282 return datasetLabel + ': (' + item.xLabel + ', ' + item.yLabel + ', ' + dataPoint.r + ')';
2283 }
2284 }
2285 }
2286});
2287
2288module.exports = DatasetController.extend({
2289 /**
2290 * @protected
2291 */
2292 dataElementType: elements.Point,
2293
2294 /**
2295 * @protected
2296 */
2297 update: function(reset) {
2298 var me = this;
2299 var meta = me.getMeta();
2300 var points = meta.data;
2301
2302 // Update Points
2303 helpers.each(points, function(point, index) {
2304 me.updateElement(point, index, reset);
2305 });
2306 },
2307
2308 /**
2309 * @protected
2310 */
2311 updateElement: function(point, index, reset) {
2312 var me = this;
2313 var meta = me.getMeta();
2314 var custom = point.custom || {};
2315 var xScale = me.getScaleForId(meta.xAxisID);
2316 var yScale = me.getScaleForId(meta.yAxisID);
2317 var options = me._resolveElementOptions(point, index);
2318 var data = me.getDataset().data[index];
2319 var dsIndex = me.index;
2320
2321 var x = reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(typeof data === 'object' ? data : NaN, index, dsIndex);
2322 var y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(data, index, dsIndex);
2323
2324 point._xScale = xScale;
2325 point._yScale = yScale;
2326 point._options = options;
2327 point._datasetIndex = dsIndex;
2328 point._index = index;
2329 point._model = {
2330 backgroundColor: options.backgroundColor,
2331 borderColor: options.borderColor,
2332 borderWidth: options.borderWidth,
2333 hitRadius: options.hitRadius,
2334 pointStyle: options.pointStyle,
2335 rotation: options.rotation,
2336 radius: reset ? 0 : options.radius,
2337 skip: custom.skip || isNaN(x) || isNaN(y),
2338 x: x,
2339 y: y,
2340 };
2341
2342 point.pivot();
2343 },
2344
2345 /**
2346 * @protected
2347 */
2348 setHoverStyle: function(point) {
2349 var model = point._model;
2350 var options = point._options;
2351
2352 point.$previousStyle = {
2353 backgroundColor: model.backgroundColor,
2354 borderColor: model.borderColor,
2355 borderWidth: model.borderWidth,
2356 radius: model.radius
2357 };
2358
2359 model.backgroundColor = helpers.valueOrDefault(options.hoverBackgroundColor, helpers.getHoverColor(options.backgroundColor));
2360 model.borderColor = helpers.valueOrDefault(options.hoverBorderColor, helpers.getHoverColor(options.borderColor));
2361 model.borderWidth = helpers.valueOrDefault(options.hoverBorderWidth, options.borderWidth);
2362 model.radius = options.radius + options.hoverRadius;
2363 },
2364
2365 /**
2366 * @private
2367 */
2368 _resolveElementOptions: function(point, index) {
2369 var me = this;
2370 var chart = me.chart;
2371 var datasets = chart.data.datasets;
2372 var dataset = datasets[me.index];
2373 var custom = point.custom || {};
2374 var options = chart.options.elements.point;
2375 var resolve = helpers.options.resolve;
2376 var data = dataset.data[index];
2377 var values = {};
2378 var i, ilen, key;
2379
2380 // Scriptable options
2381 var context = {
2382 chart: chart,
2383 dataIndex: index,
2384 dataset: dataset,
2385 datasetIndex: me.index
2386 };
2387
2388 var keys = [
2389 'backgroundColor',
2390 'borderColor',
2391 'borderWidth',
2392 'hoverBackgroundColor',
2393 'hoverBorderColor',
2394 'hoverBorderWidth',
2395 'hoverRadius',
2396 'hitRadius',
2397 'pointStyle',
2398 'rotation'
2399 ];
2400
2401 for (i = 0, ilen = keys.length; i < ilen; ++i) {
2402 key = keys[i];
2403 values[key] = resolve([
2404 custom[key],
2405 dataset[key],
2406 options[key]
2407 ], context, index);
2408 }
2409
2410 // Custom radius resolution
2411 values.radius = resolve([
2412 custom.radius,
2413 data ? data.r : undefined,
2414 dataset.radius,
2415 options.radius
2416 ], context, index);
2417
2418 return values;
2419 }
2420});
2421
2422},{"21":21,"22":22,"37":37,"42":42}],10:[function(require,module,exports){
2423'use strict';
2424
2425var DatasetController = require(21);
2426var defaults = require(22);
2427var elements = require(37);
2428var helpers = require(42);
2429
2430defaults._set('doughnut', {
2431 animation: {
2432 // Boolean - Whether we animate the rotation of the Doughnut
2433 animateRotate: true,
2434 // Boolean - Whether we animate scaling the Doughnut from the centre
2435 animateScale: false
2436 },
2437 hover: {
2438 mode: 'single'
2439 },
2440 legendCallback: function(chart) {
2441 var text = [];
2442 text.push('<ul class="' + chart.id + '-legend">');
2443
2444 var data = chart.data;
2445 var datasets = data.datasets;
2446 var labels = data.labels;
2447
2448 if (datasets.length) {
2449 for (var i = 0; i < datasets[0].data.length; ++i) {
2450 text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
2451 if (labels[i]) {
2452 text.push(labels[i]);
2453 }
2454 text.push('</li>');
2455 }
2456 }
2457
2458 text.push('</ul>');
2459 return text.join('');
2460 },
2461 legend: {
2462 labels: {
2463 generateLabels: function(chart) {
2464 var data = chart.data;
2465 if (data.labels.length && data.datasets.length) {
2466 return data.labels.map(function(label, i) {
2467 var meta = chart.getDatasetMeta(0);
2468 var ds = data.datasets[0];
2469 var arc = meta.data[i];
2470 var custom = arc && arc.custom || {};
2471 var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
2472 var arcOpts = chart.options.elements.arc;
2473 var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
2474 var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
2475 var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
2476
2477 return {
2478 text: label,
2479 fillStyle: fill,
2480 strokeStyle: stroke,
2481 lineWidth: bw,
2482 hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
2483
2484 // Extra data used for toggling the correct item
2485 index: i
2486 };
2487 });
2488 }
2489 return [];
2490 }
2491 },
2492
2493 onClick: function(e, legendItem) {
2494 var index = legendItem.index;
2495 var chart = this.chart;
2496 var i, ilen, meta;
2497
2498 for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
2499 meta = chart.getDatasetMeta(i);
2500 // toggle visibility of index if exists
2501 if (meta.data[index]) {
2502 meta.data[index].hidden = !meta.data[index].hidden;
2503 }
2504 }
2505
2506 chart.update();
2507 }
2508 },
2509
2510 // The percentage of the chart that we cut out of the middle.
2511 cutoutPercentage: 50,
2512
2513 // The rotation of the chart, where the first data arc begins.
2514 rotation: Math.PI * -0.5,
2515
2516 // The total circumference of the chart.
2517 circumference: Math.PI * 2.0,
2518
2519 // Need to override these to give a nice default
2520 tooltips: {
2521 callbacks: {
2522 title: function() {
2523 return '';
2524 },
2525 label: function(tooltipItem, data) {
2526 var dataLabel = data.labels[tooltipItem.index];
2527 var value = ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
2528
2529 if (helpers.isArray(dataLabel)) {
2530 // show value on first line of multiline label
2531 // need to clone because we are changing the value
2532 dataLabel = dataLabel.slice();
2533 dataLabel[0] += value;
2534 } else {
2535 dataLabel += value;
2536 }
2537
2538 return dataLabel;
2539 }
2540 }
2541 }
2542});
2543
2544module.exports = DatasetController.extend({
2545
2546 dataElementType: elements.Arc,
2547
2548 linkScales: helpers.noop,
2549
2550 // Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
2551 getRingIndex: function(datasetIndex) {
2552 var ringIndex = 0;
2553
2554 for (var j = 0; j < datasetIndex; ++j) {
2555 if (this.chart.isDatasetVisible(j)) {
2556 ++ringIndex;
2557 }
2558 }
2559
2560 return ringIndex;
2561 },
2562
2563 update: function(reset) {
2564 var me = this;
2565 var chart = me.chart;
2566 var chartArea = chart.chartArea;
2567 var opts = chart.options;
2568 var arcOpts = opts.elements.arc;
2569 var availableWidth = chartArea.right - chartArea.left - arcOpts.borderWidth;
2570 var availableHeight = chartArea.bottom - chartArea.top - arcOpts.borderWidth;
2571 var minSize = Math.min(availableWidth, availableHeight);
2572 var offset = {x: 0, y: 0};
2573 var meta = me.getMeta();
2574 var cutoutPercentage = opts.cutoutPercentage;
2575 var circumference = opts.circumference;
2576
2577 // If the chart's circumference isn't a full circle, calculate minSize as a ratio of the width/height of the arc
2578 if (circumference < Math.PI * 2.0) {
2579 var startAngle = opts.rotation % (Math.PI * 2.0);
2580 startAngle += Math.PI * 2.0 * (startAngle >= Math.PI ? -1 : startAngle < -Math.PI ? 1 : 0);
2581 var endAngle = startAngle + circumference;
2582 var start = {x: Math.cos(startAngle), y: Math.sin(startAngle)};
2583 var end = {x: Math.cos(endAngle), y: Math.sin(endAngle)};
2584 var contains0 = (startAngle <= 0 && endAngle >= 0) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
2585 var contains90 = (startAngle <= Math.PI * 0.5 && Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 2.5 && Math.PI * 2.5 <= endAngle);
2586 var contains180 = (startAngle <= -Math.PI && -Math.PI <= endAngle) || (startAngle <= Math.PI && Math.PI <= endAngle);
2587 var contains270 = (startAngle <= -Math.PI * 0.5 && -Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 1.5 && Math.PI * 1.5 <= endAngle);
2588 var cutout = cutoutPercentage / 100.0;
2589 var min = {x: contains180 ? -1 : Math.min(start.x * (start.x < 0 ? 1 : cutout), end.x * (end.x < 0 ? 1 : cutout)), y: contains270 ? -1 : Math.min(start.y * (start.y < 0 ? 1 : cutout), end.y * (end.y < 0 ? 1 : cutout))};
2590 var max = {x: contains0 ? 1 : Math.max(start.x * (start.x > 0 ? 1 : cutout), end.x * (end.x > 0 ? 1 : cutout)), y: contains90 ? 1 : Math.max(start.y * (start.y > 0 ? 1 : cutout), end.y * (end.y > 0 ? 1 : cutout))};
2591 var size = {width: (max.x - min.x) * 0.5, height: (max.y - min.y) * 0.5};
2592 minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
2593 offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
2594 }
2595
2596 chart.borderWidth = me.getMaxBorderWidth(meta.data);
2597 chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0);
2598 chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 0, 0);
2599 chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
2600 chart.offsetX = offset.x * chart.outerRadius;
2601 chart.offsetY = offset.y * chart.outerRadius;
2602
2603 meta.total = me.calculateTotal();
2604
2605 me.outerRadius = chart.outerRadius - (chart.radiusLength * me.getRingIndex(me.index));
2606 me.innerRadius = Math.max(me.outerRadius - chart.radiusLength, 0);
2607
2608 helpers.each(meta.data, function(arc, index) {
2609 me.updateElement(arc, index, reset);
2610 });
2611 },
2612
2613 updateElement: function(arc, index, reset) {
2614 var me = this;
2615 var chart = me.chart;
2616 var chartArea = chart.chartArea;
2617 var opts = chart.options;
2618 var animationOpts = opts.animation;
2619 var centerX = (chartArea.left + chartArea.right) / 2;
2620 var centerY = (chartArea.top + chartArea.bottom) / 2;
2621 var startAngle = opts.rotation; // non reset case handled later
2622 var endAngle = opts.rotation; // non reset case handled later
2623 var dataset = me.getDataset();
2624 var circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(dataset.data[index]) * (opts.circumference / (2.0 * Math.PI));
2625 var innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius;
2626 var outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius;
2627 var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
2628
2629 helpers.extend(arc, {
2630 // Utility
2631 _datasetIndex: me.index,
2632 _index: index,
2633
2634 // Desired view properties
2635 _model: {
2636 x: centerX + chart.offsetX,
2637 y: centerY + chart.offsetY,
2638 startAngle: startAngle,
2639 endAngle: endAngle,
2640 circumference: circumference,
2641 outerRadius: outerRadius,
2642 innerRadius: innerRadius,
2643 label: valueAtIndexOrDefault(dataset.label, index, chart.data.labels[index])
2644 }
2645 });
2646
2647 var model = arc._model;
2648
2649 // Resets the visual styles
2650 var custom = arc.custom || {};
2651 var valueOrDefault = helpers.valueAtIndexOrDefault;
2652 var elementOpts = this.chart.options.elements.arc;
2653 model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
2654 model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
2655 model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
2656
2657 // Set correct angles if not resetting
2658 if (!reset || !animationOpts.animateRotate) {
2659 if (index === 0) {
2660 model.startAngle = opts.rotation;
2661 } else {
2662 model.startAngle = me.getMeta().data[index - 1]._model.endAngle;
2663 }
2664
2665 model.endAngle = model.startAngle + model.circumference;
2666 }
2667
2668 arc.pivot();
2669 },
2670
2671 calculateTotal: function() {
2672 var dataset = this.getDataset();
2673 var meta = this.getMeta();
2674 var total = 0;
2675 var value;
2676
2677 helpers.each(meta.data, function(element, index) {
2678 value = dataset.data[index];
2679 if (!isNaN(value) && !element.hidden) {
2680 total += Math.abs(value);
2681 }
2682 });
2683
2684 /* if (total === 0) {
2685 total = NaN;
2686 }*/
2687
2688 return total;
2689 },
2690
2691 calculateCircumference: function(value) {
2692 var total = this.getMeta().total;
2693 if (total > 0 && !isNaN(value)) {
2694 return (Math.PI * 2.0) * (Math.abs(value) / total);
2695 }
2696 return 0;
2697 },
2698
2699 // gets the max border or hover width to properly scale pie charts
2700 getMaxBorderWidth: function(arcs) {
2701 var max = 0;
2702 var index = this.index;
2703 var length = arcs.length;
2704 var borderWidth;
2705 var hoverWidth;
2706
2707 for (var i = 0; i < length; i++) {
2708 borderWidth = arcs[i]._model ? arcs[i]._model.borderWidth : 0;
2709 hoverWidth = arcs[i]._chart ? arcs[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
2710
2711 max = borderWidth > max ? borderWidth : max;
2712 max = hoverWidth > max ? hoverWidth : max;
2713 }
2714 return max;
2715 }
2716});
2717
2718},{"21":21,"22":22,"37":37,"42":42}],11:[function(require,module,exports){
2719
2720'use strict';
2721
2722var BarController = require(8);
2723var defaults = require(22);
2724
2725defaults._set('horizontalBar', {
2726 hover: {
2727 mode: 'index',
2728 axis: 'y'
2729 },
2730
2731 scales: {
2732 xAxes: [{
2733 type: 'linear',
2734 position: 'bottom'
2735 }],
2736
2737 yAxes: [{
2738 type: 'category',
2739 position: 'left',
2740 categoryPercentage: 0.8,
2741 barPercentage: 0.9,
2742 offset: true,
2743 gridLines: {
2744 offsetGridLines: true
2745 }
2746 }]
2747 },
2748
2749 elements: {
2750 rectangle: {
2751 borderSkipped: 'left'
2752 }
2753 },
2754
2755 tooltips: {
2756 callbacks: {
2757 title: function(item, data) {
2758 // Pick first xLabel for now
2759 var title = '';
2760
2761 if (item.length > 0) {
2762 if (item[0].yLabel) {
2763 title = item[0].yLabel;
2764 } else if (data.labels.length > 0 && item[0].index < data.labels.length) {
2765 title = data.labels[item[0].index];
2766 }
2767 }
2768
2769 return title;
2770 },
2771
2772 label: function(item, data) {
2773 var datasetLabel = data.datasets[item.datasetIndex].label || '';
2774 return datasetLabel + ': ' + item.xLabel;
2775 }
2776 },
2777 mode: 'index',
2778 axis: 'y'
2779 }
2780});
2781
2782module.exports = BarController.extend({
2783 /**
2784 * @private
2785 */
2786 getValueScaleId: function() {
2787 return this.getMeta().xAxisID;
2788 },
2789
2790 /**
2791 * @private
2792 */
2793 getIndexScaleId: function() {
2794 return this.getMeta().yAxisID;
2795 }
2796});
2797
2798
2799},{"22":22,"8":8}],12:[function(require,module,exports){
2800'use strict';
2801
2802var DatasetController = require(21);
2803var defaults = require(22);
2804var elements = require(37);
2805var helpers = require(42);
2806
2807defaults._set('line', {
2808 showLines: true,
2809 spanGaps: false,
2810
2811 hover: {
2812 mode: 'label'
2813 },
2814
2815 scales: {
2816 xAxes: [{
2817 type: 'category',
2818 id: 'x-axis-0'
2819 }],
2820 yAxes: [{
2821 type: 'linear',
2822 id: 'y-axis-0'
2823 }]
2824 }
2825});
2826
2827function lineEnabled(dataset, options) {
2828 return helpers.valueOrDefault(dataset.showLine, options.showLines);
2829}
2830
2831module.exports = DatasetController.extend({
2832
2833 datasetElementType: elements.Line,
2834
2835 dataElementType: elements.Point,
2836
2837 update: function(reset) {
2838 var me = this;
2839 var meta = me.getMeta();
2840 var line = meta.dataset;
2841 var points = meta.data || [];
2842 var options = me.chart.options;
2843 var lineElementOptions = options.elements.line;
2844 var scale = me.getScaleForId(meta.yAxisID);
2845 var i, ilen, custom;
2846 var dataset = me.getDataset();
2847 var showLine = lineEnabled(dataset, options);
2848
2849 // Update Line
2850 if (showLine) {
2851 custom = line.custom || {};
2852
2853 // Compatibility: If the properties are defined with only the old name, use those values
2854 if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
2855 dataset.lineTension = dataset.tension;
2856 }
2857
2858 // Utility
2859 line._scale = scale;
2860 line._datasetIndex = me.index;
2861 // Data
2862 line._children = points;
2863 // Model
2864 line._model = {
2865 // Appearance
2866 // The default behavior of lines is to break at null values, according
2867 // to https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158
2868 // This option gives lines the ability to span gaps
2869 spanGaps: dataset.spanGaps ? dataset.spanGaps : options.spanGaps,
2870 tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
2871 backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
2872 borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
2873 borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
2874 borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
2875 borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
2876 borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
2877 borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
2878 fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
2879 steppedLine: custom.steppedLine ? custom.steppedLine : helpers.valueOrDefault(dataset.steppedLine, lineElementOptions.stepped),
2880 cubicInterpolationMode: custom.cubicInterpolationMode ? custom.cubicInterpolationMode : helpers.valueOrDefault(dataset.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode),
2881 };
2882
2883 line.pivot();
2884 }
2885
2886 // Update Points
2887 for (i = 0, ilen = points.length; i < ilen; ++i) {
2888 me.updateElement(points[i], i, reset);
2889 }
2890
2891 if (showLine && line._model.tension !== 0) {
2892 me.updateBezierControlPoints();
2893 }
2894
2895 // Now pivot the point for animation
2896 for (i = 0, ilen = points.length; i < ilen; ++i) {
2897 points[i].pivot();
2898 }
2899 },
2900
2901 getPointBackgroundColor: function(point, index) {
2902 var backgroundColor = this.chart.options.elements.point.backgroundColor;
2903 var dataset = this.getDataset();
2904 var custom = point.custom || {};
2905
2906 if (custom.backgroundColor) {
2907 backgroundColor = custom.backgroundColor;
2908 } else if (dataset.pointBackgroundColor) {
2909 backgroundColor = helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
2910 } else if (dataset.backgroundColor) {
2911 backgroundColor = dataset.backgroundColor;
2912 }
2913
2914 return backgroundColor;
2915 },
2916
2917 getPointBorderColor: function(point, index) {
2918 var borderColor = this.chart.options.elements.point.borderColor;
2919 var dataset = this.getDataset();
2920 var custom = point.custom || {};
2921
2922 if (custom.borderColor) {
2923 borderColor = custom.borderColor;
2924 } else if (dataset.pointBorderColor) {
2925 borderColor = helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, borderColor);
2926 } else if (dataset.borderColor) {
2927 borderColor = dataset.borderColor;
2928 }
2929
2930 return borderColor;
2931 },
2932
2933 getPointBorderWidth: function(point, index) {
2934 var borderWidth = this.chart.options.elements.point.borderWidth;
2935 var dataset = this.getDataset();
2936 var custom = point.custom || {};
2937
2938 if (!isNaN(custom.borderWidth)) {
2939 borderWidth = custom.borderWidth;
2940 } else if (!isNaN(dataset.pointBorderWidth) || helpers.isArray(dataset.pointBorderWidth)) {
2941 borderWidth = helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
2942 } else if (!isNaN(dataset.borderWidth)) {
2943 borderWidth = dataset.borderWidth;
2944 }
2945
2946 return borderWidth;
2947 },
2948
2949 getPointRotation: function(point, index) {
2950 var pointRotation = this.chart.options.elements.point.rotation;
2951 var dataset = this.getDataset();
2952 var custom = point.custom || {};
2953
2954 if (!isNaN(custom.rotation)) {
2955 pointRotation = custom.rotation;
2956 } else if (!isNaN(dataset.pointRotation) || helpers.isArray(dataset.pointRotation)) {
2957 pointRotation = helpers.valueAtIndexOrDefault(dataset.pointRotation, index, pointRotation);
2958 }
2959 return pointRotation;
2960 },
2961
2962 updateElement: function(point, index, reset) {
2963 var me = this;
2964 var meta = me.getMeta();
2965 var custom = point.custom || {};
2966 var dataset = me.getDataset();
2967 var datasetIndex = me.index;
2968 var value = dataset.data[index];
2969 var yScale = me.getScaleForId(meta.yAxisID);
2970 var xScale = me.getScaleForId(meta.xAxisID);
2971 var pointOptions = me.chart.options.elements.point;
2972 var x, y;
2973
2974 // Compatibility: If the properties are defined with only the old name, use those values
2975 if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
2976 dataset.pointRadius = dataset.radius;
2977 }
2978 if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
2979 dataset.pointHitRadius = dataset.hitRadius;
2980 }
2981
2982 x = xScale.getPixelForValue(typeof value === 'object' ? value : NaN, index, datasetIndex);
2983 y = reset ? yScale.getBasePixel() : me.calculatePointY(value, index, datasetIndex);
2984
2985 // Utility
2986 point._xScale = xScale;
2987 point._yScale = yScale;
2988 point._datasetIndex = datasetIndex;
2989 point._index = index;
2990
2991 // Desired view properties
2992 point._model = {
2993 x: x,
2994 y: y,
2995 skip: custom.skip || isNaN(x) || isNaN(y),
2996 // Appearance
2997 radius: custom.radius || helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointOptions.radius),
2998 pointStyle: custom.pointStyle || helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointOptions.pointStyle),
2999 rotation: me.getPointRotation(point, index),
3000 backgroundColor: me.getPointBackgroundColor(point, index),
3001 borderColor: me.getPointBorderColor(point, index),
3002 borderWidth: me.getPointBorderWidth(point, index),
3003 tension: meta.dataset._model ? meta.dataset._model.tension : 0,
3004 steppedLine: meta.dataset._model ? meta.dataset._model.steppedLine : false,
3005 // Tooltip
3006 hitRadius: custom.hitRadius || helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointOptions.hitRadius)
3007 };
3008 },
3009
3010 calculatePointY: function(value, index, datasetIndex) {
3011 var me = this;
3012 var chart = me.chart;
3013 var meta = me.getMeta();
3014 var yScale = me.getScaleForId(meta.yAxisID);
3015 var sumPos = 0;
3016 var sumNeg = 0;
3017 var i, ds, dsMeta;
3018
3019 if (yScale.options.stacked) {
3020 for (i = 0; i < datasetIndex; i++) {
3021 ds = chart.data.datasets[i];
3022 dsMeta = chart.getDatasetMeta(i);
3023 if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
3024 var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
3025 if (stackedRightValue < 0) {
3026 sumNeg += stackedRightValue || 0;
3027 } else {
3028 sumPos += stackedRightValue || 0;
3029 }
3030 }
3031 }
3032
3033 var rightValue = Number(yScale.getRightValue(value));
3034 if (rightValue < 0) {
3035 return yScale.getPixelForValue(sumNeg + rightValue);
3036 }
3037 return yScale.getPixelForValue(sumPos + rightValue);
3038 }
3039
3040 return yScale.getPixelForValue(value);
3041 },
3042
3043 updateBezierControlPoints: function() {
3044 var me = this;
3045 var meta = me.getMeta();
3046 var area = me.chart.chartArea;
3047 var points = (meta.data || []);
3048 var i, ilen, point, model, controlPoints;
3049
3050 // Only consider points that are drawn in case the spanGaps option is used
3051 if (meta.dataset._model.spanGaps) {
3052 points = points.filter(function(pt) {
3053 return !pt._model.skip;
3054 });
3055 }
3056
3057 function capControlPoint(pt, min, max) {
3058 return Math.max(Math.min(pt, max), min);
3059 }
3060
3061 if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
3062 helpers.splineCurveMonotone(points);
3063 } else {
3064 for (i = 0, ilen = points.length; i < ilen; ++i) {
3065 point = points[i];
3066 model = point._model;
3067 controlPoints = helpers.splineCurve(
3068 helpers.previousItem(points, i)._model,
3069 model,
3070 helpers.nextItem(points, i)._model,
3071 meta.dataset._model.tension
3072 );
3073 model.controlPointPreviousX = controlPoints.previous.x;
3074 model.controlPointPreviousY = controlPoints.previous.y;
3075 model.controlPointNextX = controlPoints.next.x;
3076 model.controlPointNextY = controlPoints.next.y;
3077 }
3078 }
3079
3080 if (me.chart.options.elements.line.capBezierPoints) {
3081 for (i = 0, ilen = points.length; i < ilen; ++i) {
3082 model = points[i]._model;
3083 model.controlPointPreviousX = capControlPoint(model.controlPointPreviousX, area.left, area.right);
3084 model.controlPointPreviousY = capControlPoint(model.controlPointPreviousY, area.top, area.bottom);
3085 model.controlPointNextX = capControlPoint(model.controlPointNextX, area.left, area.right);
3086 model.controlPointNextY = capControlPoint(model.controlPointNextY, area.top, area.bottom);
3087 }
3088 }
3089 },
3090
3091 draw: function() {
3092 var me = this;
3093 var chart = me.chart;
3094 var meta = me.getMeta();
3095 var points = meta.data || [];
3096 var area = chart.chartArea;
3097 var ilen = points.length;
3098 var halfBorderWidth;
3099 var i = 0;
3100
3101 if (lineEnabled(me.getDataset(), chart.options)) {
3102 halfBorderWidth = (meta.dataset._model.borderWidth || 0) / 2;
3103
3104 helpers.canvas.clipArea(chart.ctx, {
3105 left: area.left,
3106 right: area.right,
3107 top: area.top - halfBorderWidth,
3108 bottom: area.bottom + halfBorderWidth
3109 });
3110
3111 meta.dataset.draw();
3112
3113 helpers.canvas.unclipArea(chart.ctx);
3114 }
3115
3116 // Draw the points
3117 for (; i < ilen; ++i) {
3118 points[i].draw(area);
3119 }
3120 },
3121
3122 setHoverStyle: function(element) {
3123 // Point
3124 var dataset = this.chart.data.datasets[element._datasetIndex];
3125 var index = element._index;
3126 var custom = element.custom || {};
3127 var model = element._model;
3128
3129 element.$previousStyle = {
3130 backgroundColor: model.backgroundColor,
3131 borderColor: model.borderColor,
3132 borderWidth: model.borderWidth,
3133 radius: model.radius
3134 };
3135
3136 model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
3137 model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
3138 model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
3139 model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
3140 }
3141});
3142
3143},{"21":21,"22":22,"37":37,"42":42}],13:[function(require,module,exports){
3144'use strict';
3145
3146var DoughnutController = require(10);
3147var defaults = require(22);
3148var helpers = require(42);
3149
3150defaults._set('pie', helpers.clone(defaults.doughnut));
3151defaults._set('pie', {
3152 cutoutPercentage: 0
3153});
3154
3155// Pie charts are Doughnut chart with different defaults
3156module.exports = DoughnutController;
3157
3158},{"10":10,"22":22,"42":42}],14:[function(require,module,exports){
3159'use strict';
3160
3161var DatasetController = require(21);
3162var defaults = require(22);
3163var elements = require(37);
3164var helpers = require(42);
3165
3166defaults._set('polarArea', {
3167 scale: {
3168 type: 'radialLinear',
3169 angleLines: {
3170 display: false
3171 },
3172 gridLines: {
3173 circular: true
3174 },
3175 pointLabels: {
3176 display: false
3177 },
3178 ticks: {
3179 beginAtZero: true
3180 }
3181 },
3182
3183 // Boolean - Whether to animate the rotation of the chart
3184 animation: {
3185 animateRotate: true,
3186 animateScale: true
3187 },
3188
3189 startAngle: -0.5 * Math.PI,
3190 legendCallback: function(chart) {
3191 var text = [];
3192 text.push('<ul class="' + chart.id + '-legend">');
3193
3194 var data = chart.data;
3195 var datasets = data.datasets;
3196 var labels = data.labels;
3197
3198 if (datasets.length) {
3199 for (var i = 0; i < datasets[0].data.length; ++i) {
3200 text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
3201 if (labels[i]) {
3202 text.push(labels[i]);
3203 }
3204 text.push('</li>');
3205 }
3206 }
3207
3208 text.push('</ul>');
3209 return text.join('');
3210 },
3211 legend: {
3212 labels: {
3213 generateLabels: function(chart) {
3214 var data = chart.data;
3215 if (data.labels.length && data.datasets.length) {
3216 return data.labels.map(function(label, i) {
3217 var meta = chart.getDatasetMeta(0);
3218 var ds = data.datasets[0];
3219 var arc = meta.data[i];
3220 var custom = arc.custom || {};
3221 var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
3222 var arcOpts = chart.options.elements.arc;
3223 var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
3224 var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
3225 var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
3226
3227 return {
3228 text: label,
3229 fillStyle: fill,
3230 strokeStyle: stroke,
3231 lineWidth: bw,
3232 hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
3233
3234 // Extra data used for toggling the correct item
3235 index: i
3236 };
3237 });
3238 }
3239 return [];
3240 }
3241 },
3242
3243 onClick: function(e, legendItem) {
3244 var index = legendItem.index;
3245 var chart = this.chart;
3246 var i, ilen, meta;
3247
3248 for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
3249 meta = chart.getDatasetMeta(i);
3250 meta.data[index].hidden = !meta.data[index].hidden;
3251 }
3252
3253 chart.update();
3254 }
3255 },
3256
3257 // Need to override these to give a nice default
3258 tooltips: {
3259 callbacks: {
3260 title: function() {
3261 return '';
3262 },
3263 label: function(item, data) {
3264 return data.labels[item.index] + ': ' + item.yLabel;
3265 }
3266 }
3267 }
3268});
3269
3270module.exports = DatasetController.extend({
3271
3272 dataElementType: elements.Arc,
3273
3274 linkScales: helpers.noop,
3275
3276 update: function(reset) {
3277 var me = this;
3278 var dataset = me.getDataset();
3279 var meta = me.getMeta();
3280 var start = me.chart.options.startAngle || 0;
3281 var starts = me._starts = [];
3282 var angles = me._angles = [];
3283 var i, ilen, angle;
3284
3285 me._updateRadius();
3286
3287 meta.count = me.countVisibleElements();
3288
3289 for (i = 0, ilen = dataset.data.length; i < ilen; i++) {
3290 starts[i] = start;
3291 angle = me._computeAngle(i);
3292 angles[i] = angle;
3293 start += angle;
3294 }
3295
3296 helpers.each(meta.data, function(arc, index) {
3297 me.updateElement(arc, index, reset);
3298 });
3299 },
3300
3301 /**
3302 * @private
3303 */
3304 _updateRadius: function() {
3305 var me = this;
3306 var chart = me.chart;
3307 var chartArea = chart.chartArea;
3308 var opts = chart.options;
3309 var arcOpts = opts.elements.arc;
3310 var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
3311
3312 chart.outerRadius = Math.max((minSize - arcOpts.borderWidth / 2) / 2, 0);
3313 chart.innerRadius = Math.max(opts.cutoutPercentage ? (chart.outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
3314 chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
3315
3316 me.outerRadius = chart.outerRadius - (chart.radiusLength * me.index);
3317 me.innerRadius = me.outerRadius - chart.radiusLength;
3318 },
3319
3320 updateElement: function(arc, index, reset) {
3321 var me = this;
3322 var chart = me.chart;
3323 var dataset = me.getDataset();
3324 var opts = chart.options;
3325 var animationOpts = opts.animation;
3326 var scale = chart.scale;
3327 var labels = chart.data.labels;
3328
3329 var centerX = scale.xCenter;
3330 var centerY = scale.yCenter;
3331
3332 // var negHalfPI = -0.5 * Math.PI;
3333 var datasetStartAngle = opts.startAngle;
3334 var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
3335 var startAngle = me._starts[index];
3336 var endAngle = startAngle + (arc.hidden ? 0 : me._angles[index]);
3337
3338 var resetRadius = animationOpts.animateScale ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
3339
3340 helpers.extend(arc, {
3341 // Utility
3342 _datasetIndex: me.index,
3343 _index: index,
3344 _scale: scale,
3345
3346 // Desired view properties
3347 _model: {
3348 x: centerX,
3349 y: centerY,
3350 innerRadius: 0,
3351 outerRadius: reset ? resetRadius : distance,
3352 startAngle: reset && animationOpts.animateRotate ? datasetStartAngle : startAngle,
3353 endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle,
3354 label: helpers.valueAtIndexOrDefault(labels, index, labels[index])
3355 }
3356 });
3357
3358 // Apply border and fill style
3359 var elementOpts = this.chart.options.elements.arc;
3360 var custom = arc.custom || {};
3361 var valueOrDefault = helpers.valueAtIndexOrDefault;
3362 var model = arc._model;
3363
3364 model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
3365 model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
3366 model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
3367
3368 arc.pivot();
3369 },
3370
3371 countVisibleElements: function() {
3372 var dataset = this.getDataset();
3373 var meta = this.getMeta();
3374 var count = 0;
3375
3376 helpers.each(meta.data, function(element, index) {
3377 if (!isNaN(dataset.data[index]) && !element.hidden) {
3378 count++;
3379 }
3380 });
3381
3382 return count;
3383 },
3384
3385 /**
3386 * @private
3387 */
3388 _computeAngle: function(index) {
3389 var me = this;
3390 var count = this.getMeta().count;
3391 var dataset = me.getDataset();
3392 var meta = me.getMeta();
3393
3394 if (isNaN(dataset.data[index]) || meta.data[index].hidden) {
3395 return 0;
3396 }
3397
3398 // Scriptable options
3399 var context = {
3400 chart: me.chart,
3401 dataIndex: index,
3402 dataset: dataset,
3403 datasetIndex: me.index
3404 };
3405
3406 return helpers.options.resolve([
3407 me.chart.options.elements.arc.angle,
3408 (2 * Math.PI) / count
3409 ], context, index);
3410 }
3411});
3412
3413},{"21":21,"22":22,"37":37,"42":42}],15:[function(require,module,exports){
3414'use strict';
3415
3416var DatasetController = require(21);
3417var defaults = require(22);
3418var elements = require(37);
3419var helpers = require(42);
3420
3421defaults._set('radar', {
3422 scale: {
3423 type: 'radialLinear'
3424 },
3425 elements: {
3426 line: {
3427 tension: 0 // no bezier in radar
3428 }
3429 }
3430});
3431
3432module.exports = DatasetController.extend({
3433
3434 datasetElementType: elements.Line,
3435
3436 dataElementType: elements.Point,
3437
3438 linkScales: helpers.noop,
3439
3440 update: function(reset) {
3441 var me = this;
3442 var meta = me.getMeta();
3443 var line = meta.dataset;
3444 var points = meta.data || [];
3445 var custom = line.custom || {};
3446 var dataset = me.getDataset();
3447 var lineElementOptions = me.chart.options.elements.line;
3448 var scale = me.chart.scale;
3449 var i, ilen;
3450
3451 // Compatibility: If the properties are defined with only the old name, use those values
3452 if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
3453 dataset.lineTension = dataset.tension;
3454 }
3455
3456 helpers.extend(meta.dataset, {
3457 // Utility
3458 _datasetIndex: me.index,
3459 _scale: scale,
3460 // Data
3461 _children: points,
3462 _loop: true,
3463 // Model
3464 _model: {
3465 // Appearance
3466 tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
3467 backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
3468 borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
3469 borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
3470 fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
3471 borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
3472 borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
3473 borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
3474 borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
3475 }
3476 });
3477
3478 meta.dataset.pivot();
3479
3480 // Update Points
3481 for (i = 0, ilen = points.length; i < ilen; i++) {
3482 me.updateElement(points[i], i, reset);
3483 }
3484
3485 // Update bezier control points
3486 me.updateBezierControlPoints();
3487
3488 // Now pivot the point for animation
3489 for (i = 0, ilen = points.length; i < ilen; i++) {
3490 points[i].pivot();
3491 }
3492 },
3493
3494 updateElement: function(point, index, reset) {
3495 var me = this;
3496 var custom = point.custom || {};
3497 var dataset = me.getDataset();
3498 var scale = me.chart.scale;
3499 var pointElementOptions = me.chart.options.elements.point;
3500 var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
3501
3502 // Compatibility: If the properties are defined with only the old name, use those values
3503 if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
3504 dataset.pointRadius = dataset.radius;
3505 }
3506 if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
3507 dataset.pointHitRadius = dataset.hitRadius;
3508 }
3509
3510 helpers.extend(point, {
3511 // Utility
3512 _datasetIndex: me.index,
3513 _index: index,
3514 _scale: scale,
3515
3516 // Desired view properties
3517 _model: {
3518 x: reset ? scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
3519 y: reset ? scale.yCenter : pointPosition.y,
3520
3521 // Appearance
3522 tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, me.chart.options.elements.line.tension),
3523 radius: custom.radius ? custom.radius : helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius),
3524 backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor),
3525 borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor),
3526 borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth),
3527 pointStyle: custom.pointStyle ? custom.pointStyle : helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle),
3528 rotation: custom.rotation ? custom.rotation : helpers.valueAtIndexOrDefault(dataset.pointRotation, index, pointElementOptions.rotation),
3529
3530 // Tooltip
3531 hitRadius: custom.hitRadius ? custom.hitRadius : helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointElementOptions.hitRadius)
3532 }
3533 });
3534
3535 point._model.skip = custom.skip ? custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
3536 },
3537
3538 updateBezierControlPoints: function() {
3539 var me = this;
3540 var meta = me.getMeta();
3541 var area = me.chart.chartArea;
3542 var points = meta.data || [];
3543 var i, ilen, model, controlPoints;
3544
3545 function capControlPoint(pt, min, max) {
3546 return Math.max(Math.min(pt, max), min);
3547 }
3548
3549 for (i = 0, ilen = points.length; i < ilen; i++) {
3550 model = points[i]._model;
3551 controlPoints = helpers.splineCurve(
3552 helpers.previousItem(points, i, true)._model,
3553 model,
3554 helpers.nextItem(points, i, true)._model,
3555 model.tension
3556 );
3557
3558 // Prevent the bezier going outside of the bounds of the graph
3559 model.controlPointPreviousX = capControlPoint(controlPoints.previous.x, area.left, area.right);
3560 model.controlPointPreviousY = capControlPoint(controlPoints.previous.y, area.top, area.bottom);
3561 model.controlPointNextX = capControlPoint(controlPoints.next.x, area.left, area.right);
3562 model.controlPointNextY = capControlPoint(controlPoints.next.y, area.top, area.bottom);
3563 }
3564 },
3565
3566 setHoverStyle: function(point) {
3567 // Point
3568 var dataset = this.chart.data.datasets[point._datasetIndex];
3569 var custom = point.custom || {};
3570 var index = point._index;
3571 var model = point._model;
3572
3573 point.$previousStyle = {
3574 backgroundColor: model.backgroundColor,
3575 borderColor: model.borderColor,
3576 borderWidth: model.borderWidth,
3577 radius: model.radius
3578 };
3579
3580 model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
3581 model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
3582 model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
3583 model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
3584 }
3585});
3586
3587},{"21":21,"22":22,"37":37,"42":42}],16:[function(require,module,exports){
3588'use strict';
3589
3590var LineController = require(12);
3591var defaults = require(22);
3592
3593defaults._set('scatter', {
3594 hover: {
3595 mode: 'single'
3596 },
3597
3598 scales: {
3599 xAxes: [{
3600 id: 'x-axis-1', // need an ID so datasets can reference the scale
3601 type: 'linear', // scatter should not use a category axis
3602 position: 'bottom'
3603 }],
3604 yAxes: [{
3605 id: 'y-axis-1',
3606 type: 'linear',
3607 position: 'left'
3608 }]
3609 },
3610
3611 showLines: false,
3612
3613 tooltips: {
3614 callbacks: {
3615 title: function() {
3616 return ''; // doesn't make sense for scatter since data are formatted as a point
3617 },
3618 label: function(item) {
3619 return '(' + item.xLabel + ', ' + item.yLabel + ')';
3620 }
3621 }
3622 }
3623});
3624
3625// Scatter charts use line controllers
3626module.exports = LineController;
3627
3628},{"12":12,"22":22}],17:[function(require,module,exports){
3629'use strict';
3630
3631// NOTE export a map in which the key represents the controller type, not
3632// the class, and so must be CamelCase in order to be correctly retrieved
3633// by the controller in core.controller.js (`controllers[meta.type]`).
3634
3635/* eslint-disable global-require */
3636module.exports = {
3637 bar: require(8),
3638 bubble: require(9),
3639 doughnut: require(10),
3640 horizontalBar: require(11),
3641 line: require(12),
3642 polarArea: require(14),
3643 pie: require(13),
3644 radar: require(15),
3645 scatter: require(16)
3646};
3647
3648},{"10":10,"11":11,"12":12,"13":13,"14":14,"15":15,"16":16,"8":8,"9":9}],18:[function(require,module,exports){
3649'use strict';
3650
3651var Element = require(23);
3652
3653var exports = module.exports = Element.extend({
3654 chart: null, // the animation associated chart instance
3655 currentStep: 0, // the current animation step
3656 numSteps: 60, // default number of steps
3657 easing: '', // the easing to use for this animation
3658 render: null, // render function used by the animation service
3659
3660 onAnimationProgress: null, // user specified callback to fire on each step of the animation
3661 onAnimationComplete: null, // user specified callback to fire when the animation finishes
3662});
3663
3664// DEPRECATIONS
3665
3666/**
3667 * Provided for backward compatibility, use Chart.Animation instead
3668 * @prop Chart.Animation#animationObject
3669 * @deprecated since version 2.6.0
3670 * @todo remove at version 3
3671 */
3672Object.defineProperty(exports.prototype, 'animationObject', {
3673 get: function() {
3674 return this;
3675 }
3676});
3677
3678/**
3679 * Provided for backward compatibility, use Chart.Animation#chart instead
3680 * @prop Chart.Animation#chartInstance
3681 * @deprecated since version 2.6.0
3682 * @todo remove at version 3
3683 */
3684Object.defineProperty(exports.prototype, 'chartInstance', {
3685 get: function() {
3686 return this.chart;
3687 },
3688 set: function(value) {
3689 this.chart = value;
3690 }
3691});
3692
3693},{"23":23}],19:[function(require,module,exports){
3694/* global window: false */
3695'use strict';
3696
3697var defaults = require(22);
3698var helpers = require(42);
3699
3700defaults._set('global', {
3701 animation: {
3702 duration: 1000,
3703 easing: 'easeOutQuart',
3704 onProgress: helpers.noop,
3705 onComplete: helpers.noop
3706 }
3707});
3708
3709module.exports = {
3710 frameDuration: 17,
3711 animations: [],
3712 dropFrames: 0,
3713 request: null,
3714
3715 /**
3716 * @param {Chart} chart - The chart to animate.
3717 * @param {Chart.Animation} animation - The animation that we will animate.
3718 * @param {Number} duration - The animation duration in ms.
3719 * @param {Boolean} lazy - if true, the chart is not marked as animating to enable more responsive interactions
3720 */
3721 addAnimation: function(chart, animation, duration, lazy) {
3722 var animations = this.animations;
3723 var i, ilen;
3724
3725 animation.chart = chart;
3726
3727 if (!lazy) {
3728 chart.animating = true;
3729 }
3730
3731 for (i = 0, ilen = animations.length; i < ilen; ++i) {
3732 if (animations[i].chart === chart) {
3733 animations[i] = animation;
3734 return;
3735 }
3736 }
3737
3738 animations.push(animation);
3739
3740 // If there are no animations queued, manually kickstart a digest, for lack of a better word
3741 if (animations.length === 1) {
3742 this.requestAnimationFrame();
3743 }
3744 },
3745
3746 cancelAnimation: function(chart) {
3747 var index = helpers.findIndex(this.animations, function(animation) {
3748 return animation.chart === chart;
3749 });
3750
3751 if (index !== -1) {
3752 this.animations.splice(index, 1);
3753 chart.animating = false;
3754 }
3755 },
3756
3757 requestAnimationFrame: function() {
3758 var me = this;
3759 if (me.request === null) {
3760 // Skip animation frame requests until the active one is executed.
3761 // This can happen when processing mouse events, e.g. 'mousemove'
3762 // and 'mouseout' events will trigger multiple renders.
3763 me.request = helpers.requestAnimFrame.call(window, function() {
3764 me.request = null;
3765 me.startDigest();
3766 });
3767 }
3768 },
3769
3770 /**
3771 * @private
3772 */
3773 startDigest: function() {
3774 var me = this;
3775 var startTime = Date.now();
3776 var framesToDrop = 0;
3777
3778 if (me.dropFrames > 1) {
3779 framesToDrop = Math.floor(me.dropFrames);
3780 me.dropFrames = me.dropFrames % 1;
3781 }
3782
3783 me.advance(1 + framesToDrop);
3784
3785 var endTime = Date.now();
3786
3787 me.dropFrames += (endTime - startTime) / me.frameDuration;
3788
3789 // Do we have more stuff to animate?
3790 if (me.animations.length > 0) {
3791 me.requestAnimationFrame();
3792 }
3793 },
3794
3795 /**
3796 * @private
3797 */
3798 advance: function(count) {
3799 var animations = this.animations;
3800 var animation, chart;
3801 var i = 0;
3802
3803 while (i < animations.length) {
3804 animation = animations[i];
3805 chart = animation.chart;
3806
3807 animation.currentStep = (animation.currentStep || 0) + count;
3808 animation.currentStep = Math.min(animation.currentStep, animation.numSteps);
3809
3810 helpers.callback(animation.render, [chart, animation], chart);
3811 helpers.callback(animation.onAnimationProgress, [animation], chart);
3812
3813 if (animation.currentStep >= animation.numSteps) {
3814 helpers.callback(animation.onAnimationComplete, [animation], chart);
3815 chart.animating = false;
3816 animations.splice(i, 1);
3817 } else {
3818 ++i;
3819 }
3820 }
3821 }
3822};
3823
3824},{"22":22,"42":42}],20:[function(require,module,exports){
3825'use strict';
3826
3827var Animation = require(18);
3828var animations = require(19);
3829var controllers = require(17);
3830var defaults = require(22);
3831var helpers = require(42);
3832var Interaction = require(25);
3833var layouts = require(27);
3834var platform = require(45);
3835var plugins = require(28);
3836var scaleService = require(30);
3837var Tooltip = require(32);
3838
3839module.exports = function(Chart) {
3840
3841 // Create a dictionary of chart types, to allow for extension of existing types
3842 Chart.types = {};
3843
3844 // Store a reference to each instance - allowing us to globally resize chart instances on window resize.
3845 // Destroy method on the chart will remove the instance of the chart from this reference.
3846 Chart.instances = {};
3847
3848 /**
3849 * Initializes the given config with global and chart default values.
3850 */
3851 function initConfig(config) {
3852 config = config || {};
3853
3854 // Do NOT use configMerge() for the data object because this method merges arrays
3855 // and so would change references to labels and datasets, preventing data updates.
3856 var data = config.data = config.data || {};
3857 data.datasets = data.datasets || [];
3858 data.labels = data.labels || [];
3859
3860 config.options = helpers.configMerge(
3861 defaults.global,
3862 defaults[config.type],
3863 config.options || {});
3864
3865 return config;
3866 }
3867
3868 /**
3869 * Updates the config of the chart
3870 * @param chart {Chart} chart to update the options for
3871 */
3872 function updateConfig(chart) {
3873 var newOptions = chart.options;
3874
3875 helpers.each(chart.scales, function(scale) {
3876 layouts.removeBox(chart, scale);
3877 });
3878
3879 newOptions = helpers.configMerge(
3880 Chart.defaults.global,
3881 Chart.defaults[chart.config.type],
3882 newOptions);
3883
3884 chart.options = chart.config.options = newOptions;
3885 chart.ensureScalesHaveIDs();
3886 chart.buildOrUpdateScales();
3887 // Tooltip
3888 chart.tooltip._options = newOptions.tooltips;
3889 chart.tooltip.initialize();
3890 }
3891
3892 function positionIsHorizontal(position) {
3893 return position === 'top' || position === 'bottom';
3894 }
3895
3896 helpers.extend(Chart.prototype, /** @lends Chart */ {
3897 /**
3898 * @private
3899 */
3900 construct: function(item, config) {
3901 var me = this;
3902
3903 config = initConfig(config);
3904
3905 var context = platform.acquireContext(item, config);
3906 var canvas = context && context.canvas;
3907 var height = canvas && canvas.height;
3908 var width = canvas && canvas.width;
3909
3910 me.id = helpers.uid();
3911 me.ctx = context;
3912 me.canvas = canvas;
3913 me.config = config;
3914 me.width = width;
3915 me.height = height;
3916 me.aspectRatio = height ? width / height : null;
3917 me.options = config.options;
3918 me._bufferedRender = false;
3919
3920 /**
3921 * Provided for backward compatibility, Chart and Chart.Controller have been merged,
3922 * the "instance" still need to be defined since it might be called from plugins.
3923 * @prop Chart#chart
3924 * @deprecated since version 2.6.0
3925 * @todo remove at version 3
3926 * @private
3927 */
3928 me.chart = me;
3929 me.controller = me; // chart.chart.controller #inception
3930
3931 // Add the chart instance to the global namespace
3932 Chart.instances[me.id] = me;
3933
3934 // Define alias to the config data: `chart.data === chart.config.data`
3935 Object.defineProperty(me, 'data', {
3936 get: function() {
3937 return me.config.data;
3938 },
3939 set: function(value) {
3940 me.config.data = value;
3941 }
3942 });
3943
3944 if (!context || !canvas) {
3945 // The given item is not a compatible context2d element, let's return before finalizing
3946 // the chart initialization but after setting basic chart / controller properties that
3947 // can help to figure out that the chart is not valid (e.g chart.canvas !== null);
3948 // https://github.com/chartjs/Chart.js/issues/2807
3949 console.error("Failed to create chart: can't acquire context from the given item");
3950 return;
3951 }
3952
3953 me.initialize();
3954 me.update();
3955 },
3956
3957 /**
3958 * @private
3959 */
3960 initialize: function() {
3961 var me = this;
3962
3963 // Before init plugin notification
3964 plugins.notify(me, 'beforeInit');
3965
3966 helpers.retinaScale(me, me.options.devicePixelRatio);
3967
3968 me.bindEvents();
3969
3970 if (me.options.responsive) {
3971 // Initial resize before chart draws (must be silent to preserve initial animations).
3972 me.resize(true);
3973 }
3974
3975 // Make sure scales have IDs and are built before we build any controllers.
3976 me.ensureScalesHaveIDs();
3977 me.buildOrUpdateScales();
3978 me.initToolTip();
3979
3980 // After init plugin notification
3981 plugins.notify(me, 'afterInit');
3982
3983 return me;
3984 },
3985
3986 clear: function() {
3987 helpers.canvas.clear(this);
3988 return this;
3989 },
3990
3991 stop: function() {
3992 // Stops any current animation loop occurring
3993 animations.cancelAnimation(this);
3994 return this;
3995 },
3996
3997 resize: function(silent) {
3998 var me = this;
3999 var options = me.options;
4000 var canvas = me.canvas;
4001 var aspectRatio = (options.maintainAspectRatio && me.aspectRatio) || null;
4002
4003 // the canvas render width and height will be casted to integers so make sure that
4004 // the canvas display style uses the same integer values to avoid blurring effect.
4005
4006 // Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collapsed
4007 var newWidth = Math.max(0, Math.floor(helpers.getMaximumWidth(canvas)));
4008 var newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas)));
4009
4010 if (me.width === newWidth && me.height === newHeight) {
4011 return;
4012 }
4013
4014 canvas.width = me.width = newWidth;
4015 canvas.height = me.height = newHeight;
4016 canvas.style.width = newWidth + 'px';
4017 canvas.style.height = newHeight + 'px';
4018
4019 helpers.retinaScale(me, options.devicePixelRatio);
4020
4021 if (!silent) {
4022 // Notify any plugins about the resize
4023 var newSize = {width: newWidth, height: newHeight};
4024 plugins.notify(me, 'resize', [newSize]);
4025
4026 // Notify of resize
4027 if (me.options.onResize) {
4028 me.options.onResize(me, newSize);
4029 }
4030
4031 me.stop();
4032 me.update({
4033 duration: me.options.responsiveAnimationDuration
4034 });
4035 }
4036 },
4037
4038 ensureScalesHaveIDs: function() {
4039 var options = this.options;
4040 var scalesOptions = options.scales || {};
4041 var scaleOptions = options.scale;
4042
4043 helpers.each(scalesOptions.xAxes, function(xAxisOptions, index) {
4044 xAxisOptions.id = xAxisOptions.id || ('x-axis-' + index);
4045 });
4046
4047 helpers.each(scalesOptions.yAxes, function(yAxisOptions, index) {
4048 yAxisOptions.id = yAxisOptions.id || ('y-axis-' + index);
4049 });
4050
4051 if (scaleOptions) {
4052 scaleOptions.id = scaleOptions.id || 'scale';
4053 }
4054 },
4055
4056 /**
4057 * Builds a map of scale ID to scale object for future lookup.
4058 */
4059 buildOrUpdateScales: function() {
4060 var me = this;
4061 var options = me.options;
4062 var scales = me.scales || {};
4063 var items = [];
4064 var updated = Object.keys(scales).reduce(function(obj, id) {
4065 obj[id] = false;
4066 return obj;
4067 }, {});
4068
4069 if (options.scales) {
4070 items = items.concat(
4071 (options.scales.xAxes || []).map(function(xAxisOptions) {
4072 return {options: xAxisOptions, dtype: 'category', dposition: 'bottom'};
4073 }),
4074 (options.scales.yAxes || []).map(function(yAxisOptions) {
4075 return {options: yAxisOptions, dtype: 'linear', dposition: 'left'};
4076 })
4077 );
4078 }
4079
4080 if (options.scale) {
4081 items.push({
4082 options: options.scale,
4083 dtype: 'radialLinear',
4084 isDefault: true,
4085 dposition: 'chartArea'
4086 });
4087 }
4088
4089 helpers.each(items, function(item) {
4090 var scaleOptions = item.options;
4091 var id = scaleOptions.id;
4092 var scaleType = helpers.valueOrDefault(scaleOptions.type, item.dtype);
4093
4094 if (positionIsHorizontal(scaleOptions.position) !== positionIsHorizontal(item.dposition)) {
4095 scaleOptions.position = item.dposition;
4096 }
4097
4098 updated[id] = true;
4099 var scale = null;
4100 if (id in scales && scales[id].type === scaleType) {
4101 scale = scales[id];
4102 scale.options = scaleOptions;
4103 scale.ctx = me.ctx;
4104 scale.chart = me;
4105 } else {
4106 var scaleClass = scaleService.getScaleConstructor(scaleType);
4107 if (!scaleClass) {
4108 return;
4109 }
4110 scale = new scaleClass({
4111 id: id,
4112 type: scaleType,
4113 options: scaleOptions,
4114 ctx: me.ctx,
4115 chart: me
4116 });
4117 scales[scale.id] = scale;
4118 }
4119
4120 scale.mergeTicksOptions();
4121
4122 // TODO(SB): I think we should be able to remove this custom case (options.scale)
4123 // and consider it as a regular scale part of the "scales"" map only! This would
4124 // make the logic easier and remove some useless? custom code.
4125 if (item.isDefault) {
4126 me.scale = scale;
4127 }
4128 });
4129 // clear up discarded scales
4130 helpers.each(updated, function(hasUpdated, id) {
4131 if (!hasUpdated) {
4132 delete scales[id];
4133 }
4134 });
4135
4136 me.scales = scales;
4137
4138 scaleService.addScalesToLayout(this);
4139 },
4140
4141 buildOrUpdateControllers: function() {
4142 var me = this;
4143 var types = [];
4144 var newControllers = [];
4145
4146 helpers.each(me.data.datasets, function(dataset, datasetIndex) {
4147 var meta = me.getDatasetMeta(datasetIndex);
4148 var type = dataset.type || me.config.type;
4149
4150 if (meta.type && meta.type !== type) {
4151 me.destroyDatasetMeta(datasetIndex);
4152 meta = me.getDatasetMeta(datasetIndex);
4153 }
4154 meta.type = type;
4155
4156 types.push(meta.type);
4157
4158 if (meta.controller) {
4159 meta.controller.updateIndex(datasetIndex);
4160 meta.controller.linkScales();
4161 } else {
4162 var ControllerClass = controllers[meta.type];
4163 if (ControllerClass === undefined) {
4164 throw new Error('"' + meta.type + '" is not a chart type.');
4165 }
4166
4167 meta.controller = new ControllerClass(me, datasetIndex);
4168 newControllers.push(meta.controller);
4169 }
4170 }, me);
4171
4172 return newControllers;
4173 },
4174
4175 /**
4176 * Reset the elements of all datasets
4177 * @private
4178 */
4179 resetElements: function() {
4180 var me = this;
4181 helpers.each(me.data.datasets, function(dataset, datasetIndex) {
4182 me.getDatasetMeta(datasetIndex).controller.reset();
4183 }, me);
4184 },
4185
4186 /**
4187 * Resets the chart back to it's state before the initial animation
4188 */
4189 reset: function() {
4190 this.resetElements();
4191 this.tooltip.initialize();
4192 },
4193
4194 update: function(config) {
4195 var me = this;
4196
4197 if (!config || typeof config !== 'object') {
4198 // backwards compatibility
4199 config = {
4200 duration: config,
4201 lazy: arguments[1]
4202 };
4203 }
4204
4205 updateConfig(me);
4206
4207 // plugins options references might have change, let's invalidate the cache
4208 // https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
4209 plugins._invalidate(me);
4210
4211 if (plugins.notify(me, 'beforeUpdate') === false) {
4212 return;
4213 }
4214
4215 // In case the entire data object changed
4216 me.tooltip._data = me.data;
4217
4218 // Make sure dataset controllers are updated and new controllers are reset
4219 var newControllers = me.buildOrUpdateControllers();
4220
4221 // Make sure all dataset controllers have correct meta data counts
4222 helpers.each(me.data.datasets, function(dataset, datasetIndex) {
4223 me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
4224 }, me);
4225
4226 me.updateLayout();
4227
4228 // Can only reset the new controllers after the scales have been updated
4229 if (me.options.animation && me.options.animation.duration) {
4230 helpers.each(newControllers, function(controller) {
4231 controller.reset();
4232 });
4233 }
4234
4235 me.updateDatasets();
4236
4237 // Need to reset tooltip in case it is displayed with elements that are removed
4238 // after update.
4239 me.tooltip.initialize();
4240
4241 // Last active contains items that were previously in the tooltip.
4242 // When we reset the tooltip, we need to clear it
4243 me.lastActive = [];
4244
4245 // Do this before render so that any plugins that need final scale updates can use it
4246 plugins.notify(me, 'afterUpdate');
4247
4248 if (me._bufferedRender) {
4249 me._bufferedRequest = {
4250 duration: config.duration,
4251 easing: config.easing,
4252 lazy: config.lazy
4253 };
4254 } else {
4255 me.render(config);
4256 }
4257 },
4258
4259 /**
4260 * Updates the chart layout unless a plugin returns `false` to the `beforeLayout`
4261 * hook, in which case, plugins will not be called on `afterLayout`.
4262 * @private
4263 */
4264 updateLayout: function() {
4265 var me = this;
4266
4267 if (plugins.notify(me, 'beforeLayout') === false) {
4268 return;
4269 }
4270
4271 layouts.update(this, this.width, this.height);
4272
4273 /**
4274 * Provided for backward compatibility, use `afterLayout` instead.
4275 * @method IPlugin#afterScaleUpdate
4276 * @deprecated since version 2.5.0
4277 * @todo remove at version 3
4278 * @private
4279 */
4280 plugins.notify(me, 'afterScaleUpdate');
4281 plugins.notify(me, 'afterLayout');
4282 },
4283
4284 /**
4285 * Updates all datasets unless a plugin returns `false` to the `beforeDatasetsUpdate`
4286 * hook, in which case, plugins will not be called on `afterDatasetsUpdate`.
4287 * @private
4288 */
4289 updateDatasets: function() {
4290 var me = this;
4291
4292 if (plugins.notify(me, 'beforeDatasetsUpdate') === false) {
4293 return;
4294 }
4295
4296 for (var i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
4297 me.updateDataset(i);
4298 }
4299
4300 plugins.notify(me, 'afterDatasetsUpdate');
4301 },
4302
4303 /**
4304 * Updates dataset at index unless a plugin returns `false` to the `beforeDatasetUpdate`
4305 * hook, in which case, plugins will not be called on `afterDatasetUpdate`.
4306 * @private
4307 */
4308 updateDataset: function(index) {
4309 var me = this;
4310 var meta = me.getDatasetMeta(index);
4311 var args = {
4312 meta: meta,
4313 index: index
4314 };
4315
4316 if (plugins.notify(me, 'beforeDatasetUpdate', [args]) === false) {
4317 return;
4318 }
4319
4320 meta.controller.update();
4321
4322 plugins.notify(me, 'afterDatasetUpdate', [args]);
4323 },
4324
4325 render: function(config) {
4326 var me = this;
4327
4328 if (!config || typeof config !== 'object') {
4329 // backwards compatibility
4330 config = {
4331 duration: config,
4332 lazy: arguments[1]
4333 };
4334 }
4335
4336 var duration = config.duration;
4337 var lazy = config.lazy;
4338
4339 if (plugins.notify(me, 'beforeRender') === false) {
4340 return;
4341 }
4342
4343 var animationOptions = me.options.animation;
4344 var onComplete = function(animation) {
4345 plugins.notify(me, 'afterRender');
4346 helpers.callback(animationOptions && animationOptions.onComplete, [animation], me);
4347 };
4348
4349 if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
4350 var animation = new Animation({
4351 numSteps: (duration || animationOptions.duration) / 16.66, // 60 fps
4352 easing: config.easing || animationOptions.easing,
4353
4354 render: function(chart, animationObject) {
4355 var easingFunction = helpers.easing.effects[animationObject.easing];
4356 var currentStep = animationObject.currentStep;
4357 var stepDecimal = currentStep / animationObject.numSteps;
4358
4359 chart.draw(easingFunction(stepDecimal), stepDecimal, currentStep);
4360 },
4361
4362 onAnimationProgress: animationOptions.onProgress,
4363 onAnimationComplete: onComplete
4364 });
4365
4366 animations.addAnimation(me, animation, duration, lazy);
4367 } else {
4368 me.draw();
4369
4370 // See https://github.com/chartjs/Chart.js/issues/3781
4371 onComplete(new Animation({numSteps: 0, chart: me}));
4372 }
4373
4374 return me;
4375 },
4376
4377 draw: function(easingValue) {
4378 var me = this;
4379
4380 me.clear();
4381
4382 if (helpers.isNullOrUndef(easingValue)) {
4383 easingValue = 1;
4384 }
4385
4386 me.transition(easingValue);
4387
4388 if (me.width <= 0 || me.height <= 0) {
4389 return;
4390 }
4391
4392 if (plugins.notify(me, 'beforeDraw', [easingValue]) === false) {
4393 return;
4394 }
4395
4396 // Draw all the scales
4397 helpers.each(me.boxes, function(box) {
4398 box.draw(me.chartArea);
4399 }, me);
4400
4401 if (me.scale) {
4402 me.scale.draw();
4403 }
4404
4405 me.drawDatasets(easingValue);
4406 me._drawTooltip(easingValue);
4407
4408 plugins.notify(me, 'afterDraw', [easingValue]);
4409 },
4410
4411 /**
4412 * @private
4413 */
4414 transition: function(easingValue) {
4415 var me = this;
4416
4417 for (var i = 0, ilen = (me.data.datasets || []).length; i < ilen; ++i) {
4418 if (me.isDatasetVisible(i)) {
4419 me.getDatasetMeta(i).controller.transition(easingValue);
4420 }
4421 }
4422
4423 me.tooltip.transition(easingValue);
4424 },
4425
4426 /**
4427 * Draws all datasets unless a plugin returns `false` to the `beforeDatasetsDraw`
4428 * hook, in which case, plugins will not be called on `afterDatasetsDraw`.
4429 * @private
4430 */
4431 drawDatasets: function(easingValue) {
4432 var me = this;
4433
4434 if (plugins.notify(me, 'beforeDatasetsDraw', [easingValue]) === false) {
4435 return;
4436 }
4437
4438 // Draw datasets reversed to support proper line stacking
4439 for (var i = (me.data.datasets || []).length - 1; i >= 0; --i) {
4440 if (me.isDatasetVisible(i)) {
4441 me.drawDataset(i, easingValue);
4442 }
4443 }
4444
4445 plugins.notify(me, 'afterDatasetsDraw', [easingValue]);
4446 },
4447
4448 /**
4449 * Draws dataset at index unless a plugin returns `false` to the `beforeDatasetDraw`
4450 * hook, in which case, plugins will not be called on `afterDatasetDraw`.
4451 * @private
4452 */
4453 drawDataset: function(index, easingValue) {
4454 var me = this;
4455 var meta = me.getDatasetMeta(index);
4456 var args = {
4457 meta: meta,
4458 index: index,
4459 easingValue: easingValue
4460 };
4461
4462 if (plugins.notify(me, 'beforeDatasetDraw', [args]) === false) {
4463 return;
4464 }
4465
4466 meta.controller.draw(easingValue);
4467
4468 plugins.notify(me, 'afterDatasetDraw', [args]);
4469 },
4470
4471 /**
4472 * Draws tooltip unless a plugin returns `false` to the `beforeTooltipDraw`
4473 * hook, in which case, plugins will not be called on `afterTooltipDraw`.
4474 * @private
4475 */
4476 _drawTooltip: function(easingValue) {
4477 var me = this;
4478 var tooltip = me.tooltip;
4479 var args = {
4480 tooltip: tooltip,
4481 easingValue: easingValue
4482 };
4483
4484 if (plugins.notify(me, 'beforeTooltipDraw', [args]) === false) {
4485 return;
4486 }
4487
4488 tooltip.draw();
4489
4490 plugins.notify(me, 'afterTooltipDraw', [args]);
4491 },
4492
4493 // Get the single element that was clicked on
4494 // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
4495 getElementAtEvent: function(e) {
4496 return Interaction.modes.single(this, e);
4497 },
4498
4499 getElementsAtEvent: function(e) {
4500 return Interaction.modes.label(this, e, {intersect: true});
4501 },
4502
4503 getElementsAtXAxis: function(e) {
4504 return Interaction.modes['x-axis'](this, e, {intersect: true});
4505 },
4506
4507 getElementsAtEventForMode: function(e, mode, options) {
4508 var method = Interaction.modes[mode];
4509 if (typeof method === 'function') {
4510 return method(this, e, options);
4511 }
4512
4513 return [];
4514 },
4515
4516 getDatasetAtEvent: function(e) {
4517 return Interaction.modes.dataset(this, e, {intersect: true});
4518 },
4519
4520 getDatasetMeta: function(datasetIndex) {
4521 var me = this;
4522 var dataset = me.data.datasets[datasetIndex];
4523 if (!dataset._meta) {
4524 dataset._meta = {};
4525 }
4526
4527 var meta = dataset._meta[me.id];
4528 if (!meta) {
4529 meta = dataset._meta[me.id] = {
4530 type: null,
4531 data: [],
4532 dataset: null,
4533 controller: null,
4534 hidden: null, // See isDatasetVisible() comment
4535 xAxisID: null,
4536 yAxisID: null
4537 };
4538 }
4539
4540 return meta;
4541 },
4542
4543 getVisibleDatasetCount: function() {
4544 var count = 0;
4545 for (var i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
4546 if (this.isDatasetVisible(i)) {
4547 count++;
4548 }
4549 }
4550 return count;
4551 },
4552
4553 isDatasetVisible: function(datasetIndex) {
4554 var meta = this.getDatasetMeta(datasetIndex);
4555
4556 // meta.hidden is a per chart dataset hidden flag override with 3 states: if true or false,
4557 // the dataset.hidden value is ignored, else if null, the dataset hidden state is returned.
4558 return typeof meta.hidden === 'boolean' ? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
4559 },
4560
4561 generateLegend: function() {
4562 return this.options.legendCallback(this);
4563 },
4564
4565 /**
4566 * @private
4567 */
4568 destroyDatasetMeta: function(datasetIndex) {
4569 var id = this.id;
4570 var dataset = this.data.datasets[datasetIndex];
4571 var meta = dataset._meta && dataset._meta[id];
4572
4573 if (meta) {
4574 meta.controller.destroy();
4575 delete dataset._meta[id];
4576 }
4577 },
4578
4579 destroy: function() {
4580 var me = this;
4581 var canvas = me.canvas;
4582 var i, ilen;
4583
4584 me.stop();
4585
4586 // dataset controllers need to cleanup associated data
4587 for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
4588 me.destroyDatasetMeta(i);
4589 }
4590
4591 if (canvas) {
4592 me.unbindEvents();
4593 helpers.canvas.clear(me);
4594 platform.releaseContext(me.ctx);
4595 me.canvas = null;
4596 me.ctx = null;
4597 }
4598
4599 plugins.notify(me, 'destroy');
4600
4601 delete Chart.instances[me.id];
4602 },
4603
4604 toBase64Image: function() {
4605 return this.canvas.toDataURL.apply(this.canvas, arguments);
4606 },
4607
4608 initToolTip: function() {
4609 var me = this;
4610 me.tooltip = new Tooltip({
4611 _chart: me,
4612 _chartInstance: me, // deprecated, backward compatibility
4613 _data: me.data,
4614 _options: me.options.tooltips
4615 }, me);
4616 },
4617
4618 /**
4619 * @private
4620 */
4621 bindEvents: function() {
4622 var me = this;
4623 var listeners = me._listeners = {};
4624 var listener = function() {
4625 me.eventHandler.apply(me, arguments);
4626 };
4627
4628 helpers.each(me.options.events, function(type) {
4629 platform.addEventListener(me, type, listener);
4630 listeners[type] = listener;
4631 });
4632
4633 // Elements used to detect size change should not be injected for non responsive charts.
4634 // See https://github.com/chartjs/Chart.js/issues/2210
4635 if (me.options.responsive) {
4636 listener = function() {
4637 me.resize();
4638 };
4639
4640 platform.addEventListener(me, 'resize', listener);
4641 listeners.resize = listener;
4642 }
4643 },
4644
4645 /**
4646 * @private
4647 */
4648 unbindEvents: function() {
4649 var me = this;
4650 var listeners = me._listeners;
4651 if (!listeners) {
4652 return;
4653 }
4654
4655 delete me._listeners;
4656 helpers.each(listeners, function(listener, type) {
4657 platform.removeEventListener(me, type, listener);
4658 });
4659 },
4660
4661 updateHoverStyle: function(elements, mode, enabled) {
4662 var method = enabled ? 'setHoverStyle' : 'removeHoverStyle';
4663 var element, i, ilen;
4664
4665 for (i = 0, ilen = elements.length; i < ilen; ++i) {
4666 element = elements[i];
4667 if (element) {
4668 this.getDatasetMeta(element._datasetIndex).controller[method](element);
4669 }
4670 }
4671 },
4672
4673 /**
4674 * @private
4675 */
4676 eventHandler: function(e) {
4677 var me = this;
4678 var tooltip = me.tooltip;
4679
4680 if (plugins.notify(me, 'beforeEvent', [e]) === false) {
4681 return;
4682 }
4683
4684 // Buffer any update calls so that renders do not occur
4685 me._bufferedRender = true;
4686 me._bufferedRequest = null;
4687
4688 var changed = me.handleEvent(e);
4689 // for smooth tooltip animations issue #4989
4690 // the tooltip should be the source of change
4691 // Animation check workaround:
4692 // tooltip._start will be null when tooltip isn't animating
4693 if (tooltip) {
4694 changed = tooltip._start
4695 ? tooltip.handleEvent(e)
4696 : changed | tooltip.handleEvent(e);
4697 }
4698
4699 plugins.notify(me, 'afterEvent', [e]);
4700
4701 var bufferedRequest = me._bufferedRequest;
4702 if (bufferedRequest) {
4703 // If we have an update that was triggered, we need to do a normal render
4704 me.render(bufferedRequest);
4705 } else if (changed && !me.animating) {
4706 // If entering, leaving, or changing elements, animate the change via pivot
4707 me.stop();
4708
4709 // We only need to render at this point. Updating will cause scales to be
4710 // recomputed generating flicker & using more memory than necessary.
4711 me.render({
4712 duration: me.options.hover.animationDuration,
4713 lazy: true
4714 });
4715 }
4716
4717 me._bufferedRender = false;
4718 me._bufferedRequest = null;
4719
4720 return me;
4721 },
4722
4723 /**
4724 * Handle an event
4725 * @private
4726 * @param {IEvent} event the event to handle
4727 * @return {Boolean} true if the chart needs to re-render
4728 */
4729 handleEvent: function(e) {
4730 var me = this;
4731 var options = me.options || {};
4732 var hoverOptions = options.hover;
4733 var changed = false;
4734
4735 me.lastActive = me.lastActive || [];
4736
4737 // Find Active Elements for hover and tooltips
4738 if (e.type === 'mouseout') {
4739 me.active = [];
4740 } else {
4741 me.active = me.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions);
4742 }
4743
4744 // Invoke onHover hook
4745 // Need to call with native event here to not break backwards compatibility
4746 helpers.callback(options.onHover || options.hover.onHover, [e.native, me.active], me);
4747
4748 if (e.type === 'mouseup' || e.type === 'click') {
4749 if (options.onClick) {
4750 // Use e.native here for backwards compatibility
4751 options.onClick.call(me, e.native, me.active);
4752 }
4753 }
4754
4755 // Remove styling for last active (even if it may still be active)
4756 if (me.lastActive.length) {
4757 me.updateHoverStyle(me.lastActive, hoverOptions.mode, false);
4758 }
4759
4760 // Built in hover styling
4761 if (me.active.length && hoverOptions.mode) {
4762 me.updateHoverStyle(me.active, hoverOptions.mode, true);
4763 }
4764
4765 changed = !helpers.arrayEquals(me.active, me.lastActive);
4766
4767 // Remember Last Actives
4768 me.lastActive = me.active;
4769
4770 return changed;
4771 }
4772 });
4773
4774 /**
4775 * Provided for backward compatibility, use Chart instead.
4776 * @class Chart.Controller
4777 * @deprecated since version 2.6.0
4778 * @todo remove at version 3
4779 * @private
4780 */
4781 Chart.Controller = Chart;
4782};
4783
4784},{"17":17,"18":18,"19":19,"22":22,"25":25,"27":27,"28":28,"30":30,"32":32,"42":42,"45":45}],21:[function(require,module,exports){
4785'use strict';
4786
4787var helpers = require(42);
4788
4789var arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift'];
4790
4791/**
4792 * Hooks the array methods that add or remove values ('push', pop', 'shift', 'splice',
4793 * 'unshift') and notify the listener AFTER the array has been altered. Listeners are
4794 * called on the 'onData*' callbacks (e.g. onDataPush, etc.) with same arguments.
4795 */
4796function listenArrayEvents(array, listener) {
4797 if (array._chartjs) {
4798 array._chartjs.listeners.push(listener);
4799 return;
4800 }
4801
4802 Object.defineProperty(array, '_chartjs', {
4803 configurable: true,
4804 enumerable: false,
4805 value: {
4806 listeners: [listener]
4807 }
4808 });
4809
4810 arrayEvents.forEach(function(key) {
4811 var method = 'onData' + key.charAt(0).toUpperCase() + key.slice(1);
4812 var base = array[key];
4813
4814 Object.defineProperty(array, key, {
4815 configurable: true,
4816 enumerable: false,
4817 value: function() {
4818 var args = Array.prototype.slice.call(arguments);
4819 var res = base.apply(this, args);
4820
4821 helpers.each(array._chartjs.listeners, function(object) {
4822 if (typeof object[method] === 'function') {
4823 object[method].apply(object, args);
4824 }
4825 });
4826
4827 return res;
4828 }
4829 });
4830 });
4831}
4832
4833/**
4834 * Removes the given array event listener and cleanup extra attached properties (such as
4835 * the _chartjs stub and overridden methods) if array doesn't have any more listeners.
4836 */
4837function unlistenArrayEvents(array, listener) {
4838 var stub = array._chartjs;
4839 if (!stub) {
4840 return;
4841 }
4842
4843 var listeners = stub.listeners;
4844 var index = listeners.indexOf(listener);
4845 if (index !== -1) {
4846 listeners.splice(index, 1);
4847 }
4848
4849 if (listeners.length > 0) {
4850 return;
4851 }
4852
4853 arrayEvents.forEach(function(key) {
4854 delete array[key];
4855 });
4856
4857 delete array._chartjs;
4858}
4859
4860// Base class for all dataset controllers (line, bar, etc)
4861var DatasetController = module.exports = function(chart, datasetIndex) {
4862 this.initialize(chart, datasetIndex);
4863};
4864
4865helpers.extend(DatasetController.prototype, {
4866
4867 /**
4868 * Element type used to generate a meta dataset (e.g. Chart.element.Line).
4869 * @type {Chart.core.element}
4870 */
4871 datasetElementType: null,
4872
4873 /**
4874 * Element type used to generate a meta data (e.g. Chart.element.Point).
4875 * @type {Chart.core.element}
4876 */
4877 dataElementType: null,
4878
4879 initialize: function(chart, datasetIndex) {
4880 var me = this;
4881 me.chart = chart;
4882 me.index = datasetIndex;
4883 me.linkScales();
4884 me.addElements();
4885 },
4886
4887 updateIndex: function(datasetIndex) {
4888 this.index = datasetIndex;
4889 },
4890
4891 linkScales: function() {
4892 var me = this;
4893 var meta = me.getMeta();
4894 var dataset = me.getDataset();
4895
4896 if (meta.xAxisID === null || !(meta.xAxisID in me.chart.scales)) {
4897 meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
4898 }
4899 if (meta.yAxisID === null || !(meta.yAxisID in me.chart.scales)) {
4900 meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
4901 }
4902 },
4903
4904 getDataset: function() {
4905 return this.chart.data.datasets[this.index];
4906 },
4907
4908 getMeta: function() {
4909 return this.chart.getDatasetMeta(this.index);
4910 },
4911
4912 getScaleForId: function(scaleID) {
4913 return this.chart.scales[scaleID];
4914 },
4915
4916 reset: function() {
4917 this.update(true);
4918 },
4919
4920 /**
4921 * @private
4922 */
4923 destroy: function() {
4924 if (this._data) {
4925 unlistenArrayEvents(this._data, this);
4926 }
4927 },
4928
4929 createMetaDataset: function() {
4930 var me = this;
4931 var type = me.datasetElementType;
4932 return type && new type({
4933 _chart: me.chart,
4934 _datasetIndex: me.index
4935 });
4936 },
4937
4938 createMetaData: function(index) {
4939 var me = this;
4940 var type = me.dataElementType;
4941 return type && new type({
4942 _chart: me.chart,
4943 _datasetIndex: me.index,
4944 _index: index
4945 });
4946 },
4947
4948 addElements: function() {
4949 var me = this;
4950 var meta = me.getMeta();
4951 var data = me.getDataset().data || [];
4952 var metaData = meta.data;
4953 var i, ilen;
4954
4955 for (i = 0, ilen = data.length; i < ilen; ++i) {
4956 metaData[i] = metaData[i] || me.createMetaData(i);
4957 }
4958
4959 meta.dataset = meta.dataset || me.createMetaDataset();
4960 },
4961
4962 addElementAndReset: function(index) {
4963 var element = this.createMetaData(index);
4964 this.getMeta().data.splice(index, 0, element);
4965 this.updateElement(element, index, true);
4966 },
4967
4968 buildOrUpdateElements: function() {
4969 var me = this;
4970 var dataset = me.getDataset();
4971 var data = dataset.data || (dataset.data = []);
4972
4973 // In order to correctly handle data addition/deletion animation (an thus simulate
4974 // real-time charts), we need to monitor these data modifications and synchronize
4975 // the internal meta data accordingly.
4976 if (me._data !== data) {
4977 if (me._data) {
4978 // This case happens when the user replaced the data array instance.
4979 unlistenArrayEvents(me._data, me);
4980 }
4981
4982 listenArrayEvents(data, me);
4983 me._data = data;
4984 }
4985
4986 // Re-sync meta data in case the user replaced the data array or if we missed
4987 // any updates and so make sure that we handle number of datapoints changing.
4988 me.resyncElements();
4989 },
4990
4991 update: helpers.noop,
4992
4993 transition: function(easingValue) {
4994 var meta = this.getMeta();
4995 var elements = meta.data || [];
4996 var ilen = elements.length;
4997 var i = 0;
4998
4999 for (; i < ilen; ++i) {
5000 elements[i].transition(easingValue);
5001 }
5002
5003 if (meta.dataset) {
5004 meta.dataset.transition(easingValue);
5005 }
5006 },
5007
5008 draw: function() {
5009 var meta = this.getMeta();
5010 var elements = meta.data || [];
5011 var ilen = elements.length;
5012 var i = 0;
5013
5014 if (meta.dataset) {
5015 meta.dataset.draw();
5016 }
5017
5018 for (; i < ilen; ++i) {
5019 elements[i].draw();
5020 }
5021 },
5022
5023 removeHoverStyle: function(element) {
5024 helpers.merge(element._model, element.$previousStyle || {});
5025 delete element.$previousStyle;
5026 },
5027
5028 setHoverStyle: function(element) {
5029 var dataset = this.chart.data.datasets[element._datasetIndex];
5030 var index = element._index;
5031 var custom = element.custom || {};
5032 var valueOrDefault = helpers.valueAtIndexOrDefault;
5033 var getHoverColor = helpers.getHoverColor;
5034 var model = element._model;
5035
5036 element.$previousStyle = {
5037 backgroundColor: model.backgroundColor,
5038 borderColor: model.borderColor,
5039 borderWidth: model.borderWidth
5040 };
5041
5042 model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor));
5043 model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
5044 model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
5045 },
5046
5047 /**
5048 * @private
5049 */
5050 resyncElements: function() {
5051 var me = this;
5052 var meta = me.getMeta();
5053 var data = me.getDataset().data;
5054 var numMeta = meta.data.length;
5055 var numData = data.length;
5056
5057 if (numData < numMeta) {
5058 meta.data.splice(numData, numMeta - numData);
5059 } else if (numData > numMeta) {
5060 me.insertElements(numMeta, numData - numMeta);
5061 }
5062 },
5063
5064 /**
5065 * @private
5066 */
5067 insertElements: function(start, count) {
5068 for (var i = 0; i < count; ++i) {
5069 this.addElementAndReset(start + i);
5070 }
5071 },
5072
5073 /**
5074 * @private
5075 */
5076 onDataPush: function() {
5077 this.insertElements(this.getDataset().data.length - 1, arguments.length);
5078 },
5079
5080 /**
5081 * @private
5082 */
5083 onDataPop: function() {
5084 this.getMeta().data.pop();
5085 },
5086
5087 /**
5088 * @private
5089 */
5090 onDataShift: function() {
5091 this.getMeta().data.shift();
5092 },
5093
5094 /**
5095 * @private
5096 */
5097 onDataSplice: function(start, count) {
5098 this.getMeta().data.splice(start, count);
5099 this.insertElements(start, arguments.length - 2);
5100 },
5101
5102 /**
5103 * @private
5104 */
5105 onDataUnshift: function() {
5106 this.insertElements(0, arguments.length);
5107 }
5108});
5109
5110DatasetController.extend = helpers.inherits;
5111
5112},{"42":42}],22:[function(require,module,exports){
5113'use strict';
5114
5115var helpers = require(42);
5116
5117module.exports = {
5118 /**
5119 * @private
5120 */
5121 _set: function(scope, values) {
5122 return helpers.merge(this[scope] || (this[scope] = {}), values);
5123 }
5124};
5125
5126},{"42":42}],23:[function(require,module,exports){
5127'use strict';
5128
5129var color = require(3);
5130var helpers = require(42);
5131
5132function interpolate(start, view, model, ease) {
5133 var keys = Object.keys(model);
5134 var i, ilen, key, actual, origin, target, type, c0, c1;
5135
5136 for (i = 0, ilen = keys.length; i < ilen; ++i) {
5137 key = keys[i];
5138
5139 target = model[key];
5140
5141 // if a value is added to the model after pivot() has been called, the view
5142 // doesn't contain it, so let's initialize the view to the target value.
5143 if (!view.hasOwnProperty(key)) {
5144 view[key] = target;
5145 }
5146
5147 actual = view[key];
5148
5149 if (actual === target || key[0] === '_') {
5150 continue;
5151 }
5152
5153 if (!start.hasOwnProperty(key)) {
5154 start[key] = actual;
5155 }
5156
5157 origin = start[key];
5158
5159 type = typeof target;
5160
5161 if (type === typeof origin) {
5162 if (type === 'string') {
5163 c0 = color(origin);
5164 if (c0.valid) {
5165 c1 = color(target);
5166 if (c1.valid) {
5167 view[key] = c1.mix(c0, ease).rgbString();
5168 continue;
5169 }
5170 }
5171 } else if (helpers.isFinite(origin) && helpers.isFinite(target)) {
5172 view[key] = origin + (target - origin) * ease;
5173 continue;
5174 }
5175 }
5176
5177 view[key] = target;
5178 }
5179}
5180
5181var Element = function(configuration) {
5182 helpers.extend(this, configuration);
5183 this.initialize.apply(this, arguments);
5184};
5185
5186helpers.extend(Element.prototype, {
5187
5188 initialize: function() {
5189 this.hidden = false;
5190 },
5191
5192 pivot: function() {
5193 var me = this;
5194 if (!me._view) {
5195 me._view = helpers.clone(me._model);
5196 }
5197 me._start = {};
5198 return me;
5199 },
5200
5201 transition: function(ease) {
5202 var me = this;
5203 var model = me._model;
5204 var start = me._start;
5205 var view = me._view;
5206
5207 // No animation -> No Transition
5208 if (!model || ease === 1) {
5209 me._view = model;
5210 me._start = null;
5211 return me;
5212 }
5213
5214 if (!view) {
5215 view = me._view = {};
5216 }
5217
5218 if (!start) {
5219 start = me._start = {};
5220 }
5221
5222 interpolate(start, view, model, ease);
5223
5224 return me;
5225 },
5226
5227 tooltipPosition: function() {
5228 return {
5229 x: this._model.x,
5230 y: this._model.y
5231 };
5232 },
5233
5234 hasValue: function() {
5235 return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
5236 }
5237});
5238
5239Element.extend = helpers.inherits;
5240
5241module.exports = Element;
5242
5243},{"3":3,"42":42}],24:[function(require,module,exports){
5244/* global window: false */
5245/* global document: false */
5246'use strict';
5247
5248var color = require(3);
5249var defaults = require(22);
5250var helpers = require(42);
5251var scaleService = require(30);
5252
5253module.exports = function() {
5254
5255 // -- Basic js utility methods
5256
5257 helpers.configMerge = function(/* objects ... */) {
5258 return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
5259 merger: function(key, target, source, options) {
5260 var tval = target[key] || {};
5261 var sval = source[key];
5262
5263 if (key === 'scales') {
5264 // scale config merging is complex. Add our own function here for that
5265 target[key] = helpers.scaleMerge(tval, sval);
5266 } else if (key === 'scale') {
5267 // used in polar area & radar charts since there is only one scale
5268 target[key] = helpers.merge(tval, [scaleService.getScaleDefaults(sval.type), sval]);
5269 } else {
5270 helpers._merger(key, target, source, options);
5271 }
5272 }
5273 });
5274 };
5275
5276 helpers.scaleMerge = function(/* objects ... */) {
5277 return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
5278 merger: function(key, target, source, options) {
5279 if (key === 'xAxes' || key === 'yAxes') {
5280 var slen = source[key].length;
5281 var i, type, scale;
5282
5283 if (!target[key]) {
5284 target[key] = [];
5285 }
5286
5287 for (i = 0; i < slen; ++i) {
5288 scale = source[key][i];
5289 type = helpers.valueOrDefault(scale.type, key === 'xAxes' ? 'category' : 'linear');
5290
5291 if (i >= target[key].length) {
5292 target[key].push({});
5293 }
5294
5295 if (!target[key][i].type || (scale.type && scale.type !== target[key][i].type)) {
5296 // new/untyped scale or type changed: let's apply the new defaults
5297 // then merge source scale to correctly overwrite the defaults.
5298 helpers.merge(target[key][i], [scaleService.getScaleDefaults(type), scale]);
5299 } else {
5300 // scales type are the same
5301 helpers.merge(target[key][i], scale);
5302 }
5303 }
5304 } else {
5305 helpers._merger(key, target, source, options);
5306 }
5307 }
5308 });
5309 };
5310
5311 helpers.where = function(collection, filterCallback) {
5312 if (helpers.isArray(collection) && Array.prototype.filter) {
5313 return collection.filter(filterCallback);
5314 }
5315 var filtered = [];
5316
5317 helpers.each(collection, function(item) {
5318 if (filterCallback(item)) {
5319 filtered.push(item);
5320 }
5321 });
5322
5323 return filtered;
5324 };
5325 helpers.findIndex = Array.prototype.findIndex ?
5326 function(array, callback, scope) {
5327 return array.findIndex(callback, scope);
5328 } :
5329 function(array, callback, scope) {
5330 scope = scope === undefined ? array : scope;
5331 for (var i = 0, ilen = array.length; i < ilen; ++i) {
5332 if (callback.call(scope, array[i], i, array)) {
5333 return i;
5334 }
5335 }
5336 return -1;
5337 };
5338 helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
5339 // Default to start of the array
5340 if (helpers.isNullOrUndef(startIndex)) {
5341 startIndex = -1;
5342 }
5343 for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
5344 var currentItem = arrayToSearch[i];
5345 if (filterCallback(currentItem)) {
5346 return currentItem;
5347 }
5348 }
5349 };
5350 helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex) {
5351 // Default to end of the array
5352 if (helpers.isNullOrUndef(startIndex)) {
5353 startIndex = arrayToSearch.length;
5354 }
5355 for (var i = startIndex - 1; i >= 0; i--) {
5356 var currentItem = arrayToSearch[i];
5357 if (filterCallback(currentItem)) {
5358 return currentItem;
5359 }
5360 }
5361 };
5362
5363 // -- Math methods
5364 helpers.isNumber = function(n) {
5365 return !isNaN(parseFloat(n)) && isFinite(n);
5366 };
5367 helpers.almostEquals = function(x, y, epsilon) {
5368 return Math.abs(x - y) < epsilon;
5369 };
5370 helpers.almostWhole = function(x, epsilon) {
5371 var rounded = Math.round(x);
5372 return (((rounded - epsilon) < x) && ((rounded + epsilon) > x));
5373 };
5374 helpers.max = function(array) {
5375 return array.reduce(function(max, value) {
5376 if (!isNaN(value)) {
5377 return Math.max(max, value);
5378 }
5379 return max;
5380 }, Number.NEGATIVE_INFINITY);
5381 };
5382 helpers.min = function(array) {
5383 return array.reduce(function(min, value) {
5384 if (!isNaN(value)) {
5385 return Math.min(min, value);
5386 }
5387 return min;
5388 }, Number.POSITIVE_INFINITY);
5389 };
5390 helpers.sign = Math.sign ?
5391 function(x) {
5392 return Math.sign(x);
5393 } :
5394 function(x) {
5395 x = +x; // convert to a number
5396 if (x === 0 || isNaN(x)) {
5397 return x;
5398 }
5399 return x > 0 ? 1 : -1;
5400 };
5401 helpers.log10 = Math.log10 ?
5402 function(x) {
5403 return Math.log10(x);
5404 } :
5405 function(x) {
5406 var exponent = Math.log(x) * Math.LOG10E; // Math.LOG10E = 1 / Math.LN10.
5407 // Check for whole powers of 10,
5408 // which due to floating point rounding error should be corrected.
5409 var powerOf10 = Math.round(exponent);
5410 var isPowerOf10 = x === Math.pow(10, powerOf10);
5411
5412 return isPowerOf10 ? powerOf10 : exponent;
5413 };
5414 helpers.toRadians = function(degrees) {
5415 return degrees * (Math.PI / 180);
5416 };
5417 helpers.toDegrees = function(radians) {
5418 return radians * (180 / Math.PI);
5419 };
5420
5421 /**
5422 * Returns the number of decimal places
5423 * i.e. the number of digits after the decimal point, of the value of this Number.
5424 * @param {Number} x - A number.
5425 * @returns {Number} The number of decimal places.
5426 */
5427 helpers.decimalPlaces = function(x) {
5428 if (!helpers.isFinite(x)) {
5429 return;
5430 }
5431 var e = 1;
5432 var p = 0;
5433 while (Math.round(x * e) / e !== x) {
5434 e *= 10;
5435 p++;
5436 }
5437 return p;
5438 };
5439
5440 // Gets the angle from vertical upright to the point about a centre.
5441 helpers.getAngleFromPoint = function(centrePoint, anglePoint) {
5442 var distanceFromXCenter = anglePoint.x - centrePoint.x;
5443 var distanceFromYCenter = anglePoint.y - centrePoint.y;
5444 var radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
5445
5446 var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
5447
5448 if (angle < (-0.5 * Math.PI)) {
5449 angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
5450 }
5451
5452 return {
5453 angle: angle,
5454 distance: radialDistanceFromCenter
5455 };
5456 };
5457 helpers.distanceBetweenPoints = function(pt1, pt2) {
5458 return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
5459 };
5460 helpers.aliasPixel = function(pixelWidth) {
5461 return (pixelWidth % 2 === 0) ? 0 : 0.5;
5462 };
5463 helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
5464 // Props to Rob Spencer at scaled innovation for his post on splining between points
5465 // http://scaledinnovation.com/analytics/splines/aboutSplines.html
5466
5467 // This function must also respect "skipped" points
5468
5469 var previous = firstPoint.skip ? middlePoint : firstPoint;
5470 var current = middlePoint;
5471 var next = afterPoint.skip ? middlePoint : afterPoint;
5472
5473 var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
5474 var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
5475
5476 var s01 = d01 / (d01 + d12);
5477 var s12 = d12 / (d01 + d12);
5478
5479 // If all points are the same, s01 & s02 will be inf
5480 s01 = isNaN(s01) ? 0 : s01;
5481 s12 = isNaN(s12) ? 0 : s12;
5482
5483 var fa = t * s01; // scaling factor for triangle Ta
5484 var fb = t * s12;
5485
5486 return {
5487 previous: {
5488 x: current.x - fa * (next.x - previous.x),
5489 y: current.y - fa * (next.y - previous.y)
5490 },
5491 next: {
5492 x: current.x + fb * (next.x - previous.x),
5493 y: current.y + fb * (next.y - previous.y)
5494 }
5495 };
5496 };
5497 helpers.EPSILON = Number.EPSILON || 1e-14;
5498 helpers.splineCurveMonotone = function(points) {
5499 // This function calculates Bézier control points in a similar way than |splineCurve|,
5500 // but preserves monotonicity of the provided data and ensures no local extremums are added
5501 // between the dataset discrete points due to the interpolation.
5502 // See : https://en.wikipedia.org/wiki/Monotone_cubic_interpolation
5503
5504 var pointsWithTangents = (points || []).map(function(point) {
5505 return {
5506 model: point._model,
5507 deltaK: 0,
5508 mK: 0
5509 };
5510 });
5511
5512 // Calculate slopes (deltaK) and initialize tangents (mK)
5513 var pointsLen = pointsWithTangents.length;
5514 var i, pointBefore, pointCurrent, pointAfter;
5515 for (i = 0; i < pointsLen; ++i) {
5516 pointCurrent = pointsWithTangents[i];
5517 if (pointCurrent.model.skip) {
5518 continue;
5519 }
5520
5521 pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
5522 pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
5523 if (pointAfter && !pointAfter.model.skip) {
5524 var slopeDeltaX = (pointAfter.model.x - pointCurrent.model.x);
5525
5526 // In the case of two points that appear at the same x pixel, slopeDeltaX is 0
5527 pointCurrent.deltaK = slopeDeltaX !== 0 ? (pointAfter.model.y - pointCurrent.model.y) / slopeDeltaX : 0;
5528 }
5529
5530 if (!pointBefore || pointBefore.model.skip) {
5531 pointCurrent.mK = pointCurrent.deltaK;
5532 } else if (!pointAfter || pointAfter.model.skip) {
5533 pointCurrent.mK = pointBefore.deltaK;
5534 } else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) {
5535 pointCurrent.mK = 0;
5536 } else {
5537 pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
5538 }
5539 }
5540
5541 // Adjust tangents to ensure monotonic properties
5542 var alphaK, betaK, tauK, squaredMagnitude;
5543 for (i = 0; i < pointsLen - 1; ++i) {
5544 pointCurrent = pointsWithTangents[i];
5545 pointAfter = pointsWithTangents[i + 1];
5546 if (pointCurrent.model.skip || pointAfter.model.skip) {
5547 continue;
5548 }
5549
5550 if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
5551 pointCurrent.mK = pointAfter.mK = 0;
5552 continue;
5553 }
5554
5555 alphaK = pointCurrent.mK / pointCurrent.deltaK;
5556 betaK = pointAfter.mK / pointCurrent.deltaK;
5557 squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2);
5558 if (squaredMagnitude <= 9) {
5559 continue;
5560 }
5561
5562 tauK = 3 / Math.sqrt(squaredMagnitude);
5563 pointCurrent.mK = alphaK * tauK * pointCurrent.deltaK;
5564 pointAfter.mK = betaK * tauK * pointCurrent.deltaK;
5565 }
5566
5567 // Compute control points
5568 var deltaX;
5569 for (i = 0; i < pointsLen; ++i) {
5570 pointCurrent = pointsWithTangents[i];
5571 if (pointCurrent.model.skip) {
5572 continue;
5573 }
5574
5575 pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
5576 pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
5577 if (pointBefore && !pointBefore.model.skip) {
5578 deltaX = (pointCurrent.model.x - pointBefore.model.x) / 3;
5579 pointCurrent.model.controlPointPreviousX = pointCurrent.model.x - deltaX;
5580 pointCurrent.model.controlPointPreviousY = pointCurrent.model.y - deltaX * pointCurrent.mK;
5581 }
5582 if (pointAfter && !pointAfter.model.skip) {
5583 deltaX = (pointAfter.model.x - pointCurrent.model.x) / 3;
5584 pointCurrent.model.controlPointNextX = pointCurrent.model.x + deltaX;
5585 pointCurrent.model.controlPointNextY = pointCurrent.model.y + deltaX * pointCurrent.mK;
5586 }
5587 }
5588 };
5589 helpers.nextItem = function(collection, index, loop) {
5590 if (loop) {
5591 return index >= collection.length - 1 ? collection[0] : collection[index + 1];
5592 }
5593 return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
5594 };
5595 helpers.previousItem = function(collection, index, loop) {
5596 if (loop) {
5597 return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
5598 }
5599 return index <= 0 ? collection[0] : collection[index - 1];
5600 };
5601 // Implementation of the nice number algorithm used in determining where axis labels will go
5602 helpers.niceNum = function(range, round) {
5603 var exponent = Math.floor(helpers.log10(range));
5604 var fraction = range / Math.pow(10, exponent);
5605 var niceFraction;
5606
5607 if (round) {
5608 if (fraction < 1.5) {
5609 niceFraction = 1;
5610 } else if (fraction < 3) {
5611 niceFraction = 2;
5612 } else if (fraction < 7) {
5613 niceFraction = 5;
5614 } else {
5615 niceFraction = 10;
5616 }
5617 } else if (fraction <= 1.0) {
5618 niceFraction = 1;
5619 } else if (fraction <= 2) {
5620 niceFraction = 2;
5621 } else if (fraction <= 5) {
5622 niceFraction = 5;
5623 } else {
5624 niceFraction = 10;
5625 }
5626
5627 return niceFraction * Math.pow(10, exponent);
5628 };
5629 // Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
5630 helpers.requestAnimFrame = (function() {
5631 if (typeof window === 'undefined') {
5632 return function(callback) {
5633 callback();
5634 };
5635 }
5636 return window.requestAnimationFrame ||
5637 window.webkitRequestAnimationFrame ||
5638 window.mozRequestAnimationFrame ||
5639 window.oRequestAnimationFrame ||
5640 window.msRequestAnimationFrame ||
5641 function(callback) {
5642 return window.setTimeout(callback, 1000 / 60);
5643 };
5644 }());
5645 // -- DOM methods
5646 helpers.getRelativePosition = function(evt, chart) {
5647 var mouseX, mouseY;
5648 var e = evt.originalEvent || evt;
5649 var canvas = evt.target || evt.srcElement;
5650 var boundingRect = canvas.getBoundingClientRect();
5651
5652 var touches = e.touches;
5653 if (touches && touches.length > 0) {
5654 mouseX = touches[0].clientX;
5655 mouseY = touches[0].clientY;
5656
5657 } else {
5658 mouseX = e.clientX;
5659 mouseY = e.clientY;
5660 }
5661
5662 // Scale mouse coordinates into canvas coordinates
5663 // by following the pattern laid out by 'jerryj' in the comments of
5664 // http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
5665 var paddingLeft = parseFloat(helpers.getStyle(canvas, 'padding-left'));
5666 var paddingTop = parseFloat(helpers.getStyle(canvas, 'padding-top'));
5667 var paddingRight = parseFloat(helpers.getStyle(canvas, 'padding-right'));
5668 var paddingBottom = parseFloat(helpers.getStyle(canvas, 'padding-bottom'));
5669 var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight;
5670 var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;
5671
5672 // We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
5673 // the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
5674 mouseX = Math.round((mouseX - boundingRect.left - paddingLeft) / (width) * canvas.width / chart.currentDevicePixelRatio);
5675 mouseY = Math.round((mouseY - boundingRect.top - paddingTop) / (height) * canvas.height / chart.currentDevicePixelRatio);
5676
5677 return {
5678 x: mouseX,
5679 y: mouseY
5680 };
5681
5682 };
5683
5684 // Private helper function to convert max-width/max-height values that may be percentages into a number
5685 function parseMaxStyle(styleValue, node, parentProperty) {
5686 var valueInPixels;
5687 if (typeof styleValue === 'string') {
5688 valueInPixels = parseInt(styleValue, 10);
5689
5690 if (styleValue.indexOf('%') !== -1) {
5691 // percentage * size in dimension
5692 valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
5693 }
5694 } else {
5695 valueInPixels = styleValue;
5696 }
5697
5698 return valueInPixels;
5699 }
5700
5701 /**
5702 * Returns if the given value contains an effective constraint.
5703 * @private
5704 */
5705 function isConstrainedValue(value) {
5706 return value !== undefined && value !== null && value !== 'none';
5707 }
5708
5709 // Private helper to get a constraint dimension
5710 // @param domNode : the node to check the constraint on
5711 // @param maxStyle : the style that defines the maximum for the direction we are using (maxWidth / maxHeight)
5712 // @param percentageProperty : property of parent to use when calculating width as a percentage
5713 // @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
5714 function getConstraintDimension(domNode, maxStyle, percentageProperty) {
5715 var view = document.defaultView;
5716 var parentNode = helpers._getParentNode(domNode);
5717 var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
5718 var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
5719 var hasCNode = isConstrainedValue(constrainedNode);
5720 var hasCContainer = isConstrainedValue(constrainedContainer);
5721 var infinity = Number.POSITIVE_INFINITY;
5722
5723 if (hasCNode || hasCContainer) {
5724 return Math.min(
5725 hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
5726 hasCContainer ? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
5727 }
5728
5729 return 'none';
5730 }
5731 // returns Number or undefined if no constraint
5732 helpers.getConstraintWidth = function(domNode) {
5733 return getConstraintDimension(domNode, 'max-width', 'clientWidth');
5734 };
5735 // returns Number or undefined if no constraint
5736 helpers.getConstraintHeight = function(domNode) {
5737 return getConstraintDimension(domNode, 'max-height', 'clientHeight');
5738 };
5739 /**
5740 * @private
5741 */
5742 helpers._calculatePadding = function(container, padding, parentDimension) {
5743 padding = helpers.getStyle(container, padding);
5744
5745 return padding.indexOf('%') > -1 ? parentDimension * parseInt(padding, 10) / 100 : parseInt(padding, 10);
5746 };
5747 /**
5748 * @private
5749 */
5750 helpers._getParentNode = function(domNode) {
5751 var parent = domNode.parentNode;
5752 if (parent && parent.toString() === '[object ShadowRoot]') {
5753 parent = parent.host;
5754 }
5755 return parent;
5756 };
5757 helpers.getMaximumWidth = function(domNode) {
5758 var container = helpers._getParentNode(domNode);
5759 if (!container) {
5760 return domNode.clientWidth;
5761 }
5762
5763 var clientWidth = container.clientWidth;
5764 var paddingLeft = helpers._calculatePadding(container, 'padding-left', clientWidth);
5765 var paddingRight = helpers._calculatePadding(container, 'padding-right', clientWidth);
5766
5767 var w = clientWidth - paddingLeft - paddingRight;
5768 var cw = helpers.getConstraintWidth(domNode);
5769 return isNaN(cw) ? w : Math.min(w, cw);
5770 };
5771 helpers.getMaximumHeight = function(domNode) {
5772 var container = helpers._getParentNode(domNode);
5773 if (!container) {
5774 return domNode.clientHeight;
5775 }
5776
5777 var clientHeight = container.clientHeight;
5778 var paddingTop = helpers._calculatePadding(container, 'padding-top', clientHeight);
5779 var paddingBottom = helpers._calculatePadding(container, 'padding-bottom', clientHeight);
5780
5781 var h = clientHeight - paddingTop - paddingBottom;
5782 var ch = helpers.getConstraintHeight(domNode);
5783 return isNaN(ch) ? h : Math.min(h, ch);
5784 };
5785 helpers.getStyle = function(el, property) {
5786 return el.currentStyle ?
5787 el.currentStyle[property] :
5788 document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
5789 };
5790 helpers.retinaScale = function(chart, forceRatio) {
5791 var pixelRatio = chart.currentDevicePixelRatio = forceRatio || (typeof window !== 'undefined' && window.devicePixelRatio) || 1;
5792 if (pixelRatio === 1) {
5793 return;
5794 }
5795
5796 var canvas = chart.canvas;
5797 var height = chart.height;
5798 var width = chart.width;
5799
5800 canvas.height = height * pixelRatio;
5801 canvas.width = width * pixelRatio;
5802 chart.ctx.scale(pixelRatio, pixelRatio);
5803
5804 // If no style has been set on the canvas, the render size is used as display size,
5805 // making the chart visually bigger, so let's enforce it to the "correct" values.
5806 // See https://github.com/chartjs/Chart.js/issues/3575
5807 if (!canvas.style.height && !canvas.style.width) {
5808 canvas.style.height = height + 'px';
5809 canvas.style.width = width + 'px';
5810 }
5811 };
5812 // -- Canvas methods
5813 helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
5814 return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
5815 };
5816 helpers.longestText = function(ctx, font, arrayOfThings, cache) {
5817 cache = cache || {};
5818 var data = cache.data = cache.data || {};
5819 var gc = cache.garbageCollect = cache.garbageCollect || [];
5820
5821 if (cache.font !== font) {
5822 data = cache.data = {};
5823 gc = cache.garbageCollect = [];
5824 cache.font = font;
5825 }
5826
5827 ctx.font = font;
5828 var longest = 0;
5829 helpers.each(arrayOfThings, function(thing) {
5830 // Undefined strings and arrays should not be measured
5831 if (thing !== undefined && thing !== null && helpers.isArray(thing) !== true) {
5832 longest = helpers.measureText(ctx, data, gc, longest, thing);
5833 } else if (helpers.isArray(thing)) {
5834 // if it is an array lets measure each element
5835 // to do maybe simplify this function a bit so we can do this more recursively?
5836 helpers.each(thing, function(nestedThing) {
5837 // Undefined strings and arrays should not be measured
5838 if (nestedThing !== undefined && nestedThing !== null && !helpers.isArray(nestedThing)) {
5839 longest = helpers.measureText(ctx, data, gc, longest, nestedThing);
5840 }
5841 });
5842 }
5843 });
5844
5845 var gcLen = gc.length / 2;
5846 if (gcLen > arrayOfThings.length) {
5847 for (var i = 0; i < gcLen; i++) {
5848 delete data[gc[i]];
5849 }
5850 gc.splice(0, gcLen);
5851 }
5852 return longest;
5853 };
5854 helpers.measureText = function(ctx, data, gc, longest, string) {
5855 var textWidth = data[string];
5856 if (!textWidth) {
5857 textWidth = data[string] = ctx.measureText(string).width;
5858 gc.push(string);
5859 }
5860 if (textWidth > longest) {
5861 longest = textWidth;
5862 }
5863 return longest;
5864 };
5865 helpers.numberOfLabelLines = function(arrayOfThings) {
5866 var numberOfLines = 1;
5867 helpers.each(arrayOfThings, function(thing) {
5868 if (helpers.isArray(thing)) {
5869 if (thing.length > numberOfLines) {
5870 numberOfLines = thing.length;
5871 }
5872 }
5873 });
5874 return numberOfLines;
5875 };
5876
5877 helpers.color = !color ?
5878 function(value) {
5879 console.error('Color.js not found!');
5880 return value;
5881 } :
5882 function(value) {
5883 /* global CanvasGradient */
5884 if (value instanceof CanvasGradient) {
5885 value = defaults.global.defaultColor;
5886 }
5887
5888 return color(value);
5889 };
5890
5891 helpers.getHoverColor = function(colorValue) {
5892 /* global CanvasPattern */
5893 return (colorValue instanceof CanvasPattern || colorValue instanceof CanvasGradient) ?
5894 colorValue :
5895 helpers.color(colorValue).saturate(0.5).darken(0.1).rgbString();
5896 };
5897};
5898
5899},{"22":22,"3":3,"30":30,"42":42}],25:[function(require,module,exports){
5900'use strict';
5901
5902var helpers = require(42);
5903
5904/**
5905 * Helper function to get relative position for an event
5906 * @param {Event|IEvent} event - The event to get the position for
5907 * @param {Chart} chart - The chart
5908 * @returns {Point} the event position
5909 */
5910function getRelativePosition(e, chart) {
5911 if (e.native) {
5912 return {
5913 x: e.x,
5914 y: e.y
5915 };
5916 }
5917
5918 return helpers.getRelativePosition(e, chart);
5919}
5920
5921/**
5922 * Helper function to traverse all of the visible elements in the chart
5923 * @param chart {chart} the chart
5924 * @param handler {Function} the callback to execute for each visible item
5925 */
5926function parseVisibleItems(chart, handler) {
5927 var datasets = chart.data.datasets;
5928 var meta, i, j, ilen, jlen;
5929
5930 for (i = 0, ilen = datasets.length; i < ilen; ++i) {
5931 if (!chart.isDatasetVisible(i)) {
5932 continue;
5933 }
5934
5935 meta = chart.getDatasetMeta(i);
5936 for (j = 0, jlen = meta.data.length; j < jlen; ++j) {
5937 var element = meta.data[j];
5938 if (!element._view.skip) {
5939 handler(element);
5940 }
5941 }
5942 }
5943}
5944
5945/**
5946 * Helper function to get the items that intersect the event position
5947 * @param items {ChartElement[]} elements to filter
5948 * @param position {Point} the point to be nearest to
5949 * @return {ChartElement[]} the nearest items
5950 */
5951function getIntersectItems(chart, position) {
5952 var elements = [];
5953
5954 parseVisibleItems(chart, function(element) {
5955 if (element.inRange(position.x, position.y)) {
5956 elements.push(element);
5957 }
5958 });
5959
5960 return elements;
5961}
5962
5963/**
5964 * Helper function to get the items nearest to the event position considering all visible items in teh chart
5965 * @param chart {Chart} the chart to look at elements from
5966 * @param position {Point} the point to be nearest to
5967 * @param intersect {Boolean} if true, only consider items that intersect the position
5968 * @param distanceMetric {Function} function to provide the distance between points
5969 * @return {ChartElement[]} the nearest items
5970 */
5971function getNearestItems(chart, position, intersect, distanceMetric) {
5972 var minDistance = Number.POSITIVE_INFINITY;
5973 var nearestItems = [];
5974
5975 parseVisibleItems(chart, function(element) {
5976 if (intersect && !element.inRange(position.x, position.y)) {
5977 return;
5978 }
5979
5980 var center = element.getCenterPoint();
5981 var distance = distanceMetric(position, center);
5982
5983 if (distance < minDistance) {
5984 nearestItems = [element];
5985 minDistance = distance;
5986 } else if (distance === minDistance) {
5987 // Can have multiple items at the same distance in which case we sort by size
5988 nearestItems.push(element);
5989 }
5990 });
5991
5992 return nearestItems;
5993}
5994
5995/**
5996 * Get a distance metric function for two points based on the
5997 * axis mode setting
5998 * @param {String} axis the axis mode. x|y|xy
5999 */
6000function getDistanceMetricForAxis(axis) {
6001 var useX = axis.indexOf('x') !== -1;
6002 var useY = axis.indexOf('y') !== -1;
6003
6004 return function(pt1, pt2) {
6005 var deltaX = useX ? Math.abs(pt1.x - pt2.x) : 0;
6006 var deltaY = useY ? Math.abs(pt1.y - pt2.y) : 0;
6007 return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
6008 };
6009}
6010
6011function indexMode(chart, e, options) {
6012 var position = getRelativePosition(e, chart);
6013 // Default axis for index mode is 'x' to match old behaviour
6014 options.axis = options.axis || 'x';
6015 var distanceMetric = getDistanceMetricForAxis(options.axis);
6016 var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
6017 var elements = [];
6018
6019 if (!items.length) {
6020 return [];
6021 }
6022
6023 chart.data.datasets.forEach(function(dataset, datasetIndex) {
6024 if (chart.isDatasetVisible(datasetIndex)) {
6025 var meta = chart.getDatasetMeta(datasetIndex);
6026 var element = meta.data[items[0]._index];
6027
6028 // don't count items that are skipped (null data)
6029 if (element && !element._view.skip) {
6030 elements.push(element);
6031 }
6032 }
6033 });
6034
6035 return elements;
6036}
6037
6038/**
6039 * @interface IInteractionOptions
6040 */
6041/**
6042 * If true, only consider items that intersect the point
6043 * @name IInterfaceOptions#boolean
6044 * @type Boolean
6045 */
6046
6047/**
6048 * Contains interaction related functions
6049 * @namespace Chart.Interaction
6050 */
6051module.exports = {
6052 // Helper function for different modes
6053 modes: {
6054 single: function(chart, e) {
6055 var position = getRelativePosition(e, chart);
6056 var elements = [];
6057
6058 parseVisibleItems(chart, function(element) {
6059 if (element.inRange(position.x, position.y)) {
6060 elements.push(element);
6061 return elements;
6062 }
6063 });
6064
6065 return elements.slice(0, 1);
6066 },
6067
6068 /**
6069 * @function Chart.Interaction.modes.label
6070 * @deprecated since version 2.4.0
6071 * @todo remove at version 3
6072 * @private
6073 */
6074 label: indexMode,
6075
6076 /**
6077 * Returns items at the same index. If the options.intersect parameter is true, we only return items if we intersect something
6078 * If the options.intersect mode is false, we find the nearest item and return the items at the same index as that item
6079 * @function Chart.Interaction.modes.index
6080 * @since v2.4.0
6081 * @param chart {chart} the chart we are returning items from
6082 * @param e {Event} the event we are find things at
6083 * @param options {IInteractionOptions} options to use during interaction
6084 * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
6085 */
6086 index: indexMode,
6087
6088 /**
6089 * Returns items in the same dataset. If the options.intersect parameter is true, we only return items if we intersect something
6090 * If the options.intersect is false, we find the nearest item and return the items in that dataset
6091 * @function Chart.Interaction.modes.dataset
6092 * @param chart {chart} the chart we are returning items from
6093 * @param e {Event} the event we are find things at
6094 * @param options {IInteractionOptions} options to use during interaction
6095 * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
6096 */
6097 dataset: function(chart, e, options) {
6098 var position = getRelativePosition(e, chart);
6099 options.axis = options.axis || 'xy';
6100 var distanceMetric = getDistanceMetricForAxis(options.axis);
6101 var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
6102
6103 if (items.length > 0) {
6104 items = chart.getDatasetMeta(items[0]._datasetIndex).data;
6105 }
6106
6107 return items;
6108 },
6109
6110 /**
6111 * @function Chart.Interaction.modes.x-axis
6112 * @deprecated since version 2.4.0. Use index mode and intersect == true
6113 * @todo remove at version 3
6114 * @private
6115 */
6116 'x-axis': function(chart, e) {
6117 return indexMode(chart, e, {intersect: false});
6118 },
6119
6120 /**
6121 * Point mode returns all elements that hit test based on the event position
6122 * of the event
6123 * @function Chart.Interaction.modes.intersect
6124 * @param chart {chart} the chart we are returning items from
6125 * @param e {Event} the event we are find things at
6126 * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
6127 */
6128 point: function(chart, e) {
6129 var position = getRelativePosition(e, chart);
6130 return getIntersectItems(chart, position);
6131 },
6132
6133 /**
6134 * nearest mode returns the element closest to the point
6135 * @function Chart.Interaction.modes.intersect
6136 * @param chart {chart} the chart we are returning items from
6137 * @param e {Event} the event we are find things at
6138 * @param options {IInteractionOptions} options to use
6139 * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
6140 */
6141 nearest: function(chart, e, options) {
6142 var position = getRelativePosition(e, chart);
6143 options.axis = options.axis || 'xy';
6144 var distanceMetric = getDistanceMetricForAxis(options.axis);
6145 return getNearestItems(chart, position, options.intersect, distanceMetric);
6146 },
6147
6148 /**
6149 * x mode returns the elements that hit-test at the current x coordinate
6150 * @function Chart.Interaction.modes.x
6151 * @param chart {chart} the chart we are returning items from
6152 * @param e {Event} the event we are find things at
6153 * @param options {IInteractionOptions} options to use
6154 * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
6155 */
6156 x: function(chart, e, options) {
6157 var position = getRelativePosition(e, chart);
6158 var items = [];
6159 var intersectsItem = false;
6160
6161 parseVisibleItems(chart, function(element) {
6162 if (element.inXRange(position.x)) {
6163 items.push(element);
6164 }
6165
6166 if (element.inRange(position.x, position.y)) {
6167 intersectsItem = true;
6168 }
6169 });
6170
6171 // If we want to trigger on an intersect and we don't have any items
6172 // that intersect the position, return nothing
6173 if (options.intersect && !intersectsItem) {
6174 items = [];
6175 }
6176 return items;
6177 },
6178
6179 /**
6180 * y mode returns the elements that hit-test at the current y coordinate
6181 * @function Chart.Interaction.modes.y
6182 * @param chart {chart} the chart we are returning items from
6183 * @param e {Event} the event we are find things at
6184 * @param options {IInteractionOptions} options to use
6185 * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
6186 */
6187 y: function(chart, e, options) {
6188 var position = getRelativePosition(e, chart);
6189 var items = [];
6190 var intersectsItem = false;
6191
6192 parseVisibleItems(chart, function(element) {
6193 if (element.inYRange(position.y)) {
6194 items.push(element);
6195 }
6196
6197 if (element.inRange(position.x, position.y)) {
6198 intersectsItem = true;
6199 }
6200 });
6201
6202 // If we want to trigger on an intersect and we don't have any items
6203 // that intersect the position, return nothing
6204 if (options.intersect && !intersectsItem) {
6205 items = [];
6206 }
6207 return items;
6208 }
6209 }
6210};
6211
6212},{"42":42}],26:[function(require,module,exports){
6213'use strict';
6214
6215var defaults = require(22);
6216
6217defaults._set('global', {
6218 responsive: true,
6219 responsiveAnimationDuration: 0,
6220 maintainAspectRatio: true,
6221 events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],
6222 hover: {
6223 onHover: null,
6224 mode: 'nearest',
6225 intersect: true,
6226 animationDuration: 400
6227 },
6228 onClick: null,
6229 defaultColor: 'rgba(0,0,0,0.1)',
6230 defaultFontColor: '#666',
6231 defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
6232 defaultFontSize: 12,
6233 defaultFontStyle: 'normal',
6234 showLines: true,
6235
6236 // Element defaults defined in element extensions
6237 elements: {},
6238
6239 // Layout options such as padding
6240 layout: {
6241 padding: {
6242 top: 0,
6243 right: 0,
6244 bottom: 0,
6245 left: 0
6246 }
6247 }
6248});
6249
6250module.exports = function() {
6251
6252 // Occupy the global variable of Chart, and create a simple base class
6253 var Chart = function(item, config) {
6254 this.construct(item, config);
6255 return this;
6256 };
6257
6258 Chart.Chart = Chart;
6259
6260 return Chart;
6261};
6262
6263},{"22":22}],27:[function(require,module,exports){
6264'use strict';
6265
6266var helpers = require(42);
6267
6268function filterByPosition(array, position) {
6269 return helpers.where(array, function(v) {
6270 return v.position === position;
6271 });
6272}
6273
6274function sortByWeight(array, reverse) {
6275 array.forEach(function(v, i) {
6276 v._tmpIndex_ = i;
6277 return v;
6278 });
6279 array.sort(function(a, b) {
6280 var v0 = reverse ? b : a;
6281 var v1 = reverse ? a : b;
6282 return v0.weight === v1.weight ?
6283 v0._tmpIndex_ - v1._tmpIndex_ :
6284 v0.weight - v1.weight;
6285 });
6286 array.forEach(function(v) {
6287 delete v._tmpIndex_;
6288 });
6289}
6290
6291/**
6292 * @interface ILayoutItem
6293 * @prop {String} position - The position of the item in the chart layout. Possible values are
6294 * 'left', 'top', 'right', 'bottom', and 'chartArea'
6295 * @prop {Number} weight - The weight used to sort the item. Higher weights are further away from the chart area
6296 * @prop {Boolean} fullWidth - if true, and the item is horizontal, then push vertical boxes down
6297 * @prop {Function} isHorizontal - returns true if the layout item is horizontal (ie. top or bottom)
6298 * @prop {Function} update - Takes two parameters: width and height. Returns size of item
6299 * @prop {Function} getPadding - Returns an object with padding on the edges
6300 * @prop {Number} width - Width of item. Must be valid after update()
6301 * @prop {Number} height - Height of item. Must be valid after update()
6302 * @prop {Number} left - Left edge of the item. Set by layout system and cannot be used in update
6303 * @prop {Number} top - Top edge of the item. Set by layout system and cannot be used in update
6304 * @prop {Number} right - Right edge of the item. Set by layout system and cannot be used in update
6305 * @prop {Number} bottom - Bottom edge of the item. Set by layout system and cannot be used in update
6306 */
6307
6308// The layout service is very self explanatory. It's responsible for the layout within a chart.
6309// Scales, Legends and Plugins all rely on the layout service and can easily register to be placed anywhere they need
6310// It is this service's responsibility of carrying out that layout.
6311module.exports = {
6312 defaults: {},
6313
6314 /**
6315 * Register a box to a chart.
6316 * A box is simply a reference to an object that requires layout. eg. Scales, Legend, Title.
6317 * @param {Chart} chart - the chart to use
6318 * @param {ILayoutItem} item - the item to add to be layed out
6319 */
6320 addBox: function(chart, item) {
6321 if (!chart.boxes) {
6322 chart.boxes = [];
6323 }
6324
6325 // initialize item with default values
6326 item.fullWidth = item.fullWidth || false;
6327 item.position = item.position || 'top';
6328 item.weight = item.weight || 0;
6329
6330 chart.boxes.push(item);
6331 },
6332
6333 /**
6334 * Remove a layoutItem from a chart
6335 * @param {Chart} chart - the chart to remove the box from
6336 * @param {Object} layoutItem - the item to remove from the layout
6337 */
6338 removeBox: function(chart, layoutItem) {
6339 var index = chart.boxes ? chart.boxes.indexOf(layoutItem) : -1;
6340 if (index !== -1) {
6341 chart.boxes.splice(index, 1);
6342 }
6343 },
6344
6345 /**
6346 * Sets (or updates) options on the given `item`.
6347 * @param {Chart} chart - the chart in which the item lives (or will be added to)
6348 * @param {Object} item - the item to configure with the given options
6349 * @param {Object} options - the new item options.
6350 */
6351 configure: function(chart, item, options) {
6352 var props = ['fullWidth', 'position', 'weight'];
6353 var ilen = props.length;
6354 var i = 0;
6355 var prop;
6356
6357 for (; i < ilen; ++i) {
6358 prop = props[i];
6359 if (options.hasOwnProperty(prop)) {
6360 item[prop] = options[prop];
6361 }
6362 }
6363 },
6364
6365 /**
6366 * Fits boxes of the given chart into the given size by having each box measure itself
6367 * then running a fitting algorithm
6368 * @param {Chart} chart - the chart
6369 * @param {Number} width - the width to fit into
6370 * @param {Number} height - the height to fit into
6371 */
6372 update: function(chart, width, height) {
6373 if (!chart) {
6374 return;
6375 }
6376
6377 var layoutOptions = chart.options.layout || {};
6378 var padding = helpers.options.toPadding(layoutOptions.padding);
6379 var leftPadding = padding.left;
6380 var rightPadding = padding.right;
6381 var topPadding = padding.top;
6382 var bottomPadding = padding.bottom;
6383
6384 var leftBoxes = filterByPosition(chart.boxes, 'left');
6385 var rightBoxes = filterByPosition(chart.boxes, 'right');
6386 var topBoxes = filterByPosition(chart.boxes, 'top');
6387 var bottomBoxes = filterByPosition(chart.boxes, 'bottom');
6388 var chartAreaBoxes = filterByPosition(chart.boxes, 'chartArea');
6389
6390 // Sort boxes by weight. A higher weight is further away from the chart area
6391 sortByWeight(leftBoxes, true);
6392 sortByWeight(rightBoxes, false);
6393 sortByWeight(topBoxes, true);
6394 sortByWeight(bottomBoxes, false);
6395
6396 // Essentially we now have any number of boxes on each of the 4 sides.
6397 // Our canvas looks like the following.
6398 // The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
6399 // B1 is the bottom axis
6400 // There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
6401 // These locations are single-box locations only, when trying to register a chartArea location that is already taken,
6402 // an error will be thrown.
6403 //
6404 // |----------------------------------------------------|
6405 // | T1 (Full Width) |
6406 // |----------------------------------------------------|
6407 // | | | T2 | |
6408 // | |----|-------------------------------------|----|
6409 // | | | C1 | | C2 | |
6410 // | | |----| |----| |
6411 // | | | | |
6412 // | L1 | L2 | ChartArea (C0) | R1 |
6413 // | | | | |
6414 // | | |----| |----| |
6415 // | | | C3 | | C4 | |
6416 // | |----|-------------------------------------|----|
6417 // | | | B1 | |
6418 // |----------------------------------------------------|
6419 // | B2 (Full Width) |
6420 // |----------------------------------------------------|
6421 //
6422 // What we do to find the best sizing, we do the following
6423 // 1. Determine the minimum size of the chart area.
6424 // 2. Split the remaining width equally between each vertical axis
6425 // 3. Split the remaining height equally between each horizontal axis
6426 // 4. Give each layout the maximum size it can be. The layout will return it's minimum size
6427 // 5. Adjust the sizes of each axis based on it's minimum reported size.
6428 // 6. Refit each axis
6429 // 7. Position each axis in the final location
6430 // 8. Tell the chart the final location of the chart area
6431 // 9. Tell any axes that overlay the chart area the positions of the chart area
6432
6433 // Step 1
6434 var chartWidth = width - leftPadding - rightPadding;
6435 var chartHeight = height - topPadding - bottomPadding;
6436 var chartAreaWidth = chartWidth / 2; // min 50%
6437 var chartAreaHeight = chartHeight / 2; // min 50%
6438
6439 // Step 2
6440 var verticalBoxWidth = (width - chartAreaWidth) / (leftBoxes.length + rightBoxes.length);
6441
6442 // Step 3
6443 var horizontalBoxHeight = (height - chartAreaHeight) / (topBoxes.length + bottomBoxes.length);
6444
6445 // Step 4
6446 var maxChartAreaWidth = chartWidth;
6447 var maxChartAreaHeight = chartHeight;
6448 var minBoxSizes = [];
6449
6450 function getMinimumBoxSize(box) {
6451 var minSize;
6452 var isHorizontal = box.isHorizontal();
6453
6454 if (isHorizontal) {
6455 minSize = box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
6456 maxChartAreaHeight -= minSize.height;
6457 } else {
6458 minSize = box.update(verticalBoxWidth, maxChartAreaHeight);
6459 maxChartAreaWidth -= minSize.width;
6460 }
6461
6462 minBoxSizes.push({
6463 horizontal: isHorizontal,
6464 minSize: minSize,
6465 box: box,
6466 });
6467 }
6468
6469 helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
6470
6471 // If a horizontal box has padding, we move the left boxes over to avoid ugly charts (see issue #2478)
6472 var maxHorizontalLeftPadding = 0;
6473 var maxHorizontalRightPadding = 0;
6474 var maxVerticalTopPadding = 0;
6475 var maxVerticalBottomPadding = 0;
6476
6477 helpers.each(topBoxes.concat(bottomBoxes), function(horizontalBox) {
6478 if (horizontalBox.getPadding) {
6479 var boxPadding = horizontalBox.getPadding();
6480 maxHorizontalLeftPadding = Math.max(maxHorizontalLeftPadding, boxPadding.left);
6481 maxHorizontalRightPadding = Math.max(maxHorizontalRightPadding, boxPadding.right);
6482 }
6483 });
6484
6485 helpers.each(leftBoxes.concat(rightBoxes), function(verticalBox) {
6486 if (verticalBox.getPadding) {
6487 var boxPadding = verticalBox.getPadding();
6488 maxVerticalTopPadding = Math.max(maxVerticalTopPadding, boxPadding.top);
6489 maxVerticalBottomPadding = Math.max(maxVerticalBottomPadding, boxPadding.bottom);
6490 }
6491 });
6492
6493 // At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
6494 // be if the axes are drawn at their minimum sizes.
6495 // Steps 5 & 6
6496 var totalLeftBoxesWidth = leftPadding;
6497 var totalRightBoxesWidth = rightPadding;
6498 var totalTopBoxesHeight = topPadding;
6499 var totalBottomBoxesHeight = bottomPadding;
6500
6501 // Function to fit a box
6502 function fitBox(box) {
6503 var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBox) {
6504 return minBox.box === box;
6505 });
6506
6507 if (minBoxSize) {
6508 if (box.isHorizontal()) {
6509 var scaleMargin = {
6510 left: Math.max(totalLeftBoxesWidth, maxHorizontalLeftPadding),
6511 right: Math.max(totalRightBoxesWidth, maxHorizontalRightPadding),
6512 top: 0,
6513 bottom: 0
6514 };
6515
6516 // Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
6517 // on the margin. Sometimes they need to increase in size slightly
6518 box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
6519 } else {
6520 box.update(minBoxSize.minSize.width, maxChartAreaHeight);
6521 }
6522 }
6523 }
6524
6525 // Update, and calculate the left and right margins for the horizontal boxes
6526 helpers.each(leftBoxes.concat(rightBoxes), fitBox);
6527
6528 helpers.each(leftBoxes, function(box) {
6529 totalLeftBoxesWidth += box.width;
6530 });
6531
6532 helpers.each(rightBoxes, function(box) {
6533 totalRightBoxesWidth += box.width;
6534 });
6535
6536 // Set the Left and Right margins for the horizontal boxes
6537 helpers.each(topBoxes.concat(bottomBoxes), fitBox);
6538
6539 // Figure out how much margin is on the top and bottom of the vertical boxes
6540 helpers.each(topBoxes, function(box) {
6541 totalTopBoxesHeight += box.height;
6542 });
6543
6544 helpers.each(bottomBoxes, function(box) {
6545 totalBottomBoxesHeight += box.height;
6546 });
6547
6548 function finalFitVerticalBox(box) {
6549 var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minSize) {
6550 return minSize.box === box;
6551 });
6552
6553 var scaleMargin = {
6554 left: 0,
6555 right: 0,
6556 top: totalTopBoxesHeight,
6557 bottom: totalBottomBoxesHeight
6558 };
6559
6560 if (minBoxSize) {
6561 box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
6562 }
6563 }
6564
6565 // Let the left layout know the final margin
6566 helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
6567
6568 // Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance)
6569 totalLeftBoxesWidth = leftPadding;
6570 totalRightBoxesWidth = rightPadding;
6571 totalTopBoxesHeight = topPadding;
6572 totalBottomBoxesHeight = bottomPadding;
6573
6574 helpers.each(leftBoxes, function(box) {
6575 totalLeftBoxesWidth += box.width;
6576 });
6577
6578 helpers.each(rightBoxes, function(box) {
6579 totalRightBoxesWidth += box.width;
6580 });
6581
6582 helpers.each(topBoxes, function(box) {
6583 totalTopBoxesHeight += box.height;
6584 });
6585 helpers.each(bottomBoxes, function(box) {
6586 totalBottomBoxesHeight += box.height;
6587 });
6588
6589 // We may be adding some padding to account for rotated x axis labels
6590 var leftPaddingAddition = Math.max(maxHorizontalLeftPadding - totalLeftBoxesWidth, 0);
6591 totalLeftBoxesWidth += leftPaddingAddition;
6592 totalRightBoxesWidth += Math.max(maxHorizontalRightPadding - totalRightBoxesWidth, 0);
6593
6594 var topPaddingAddition = Math.max(maxVerticalTopPadding - totalTopBoxesHeight, 0);
6595 totalTopBoxesHeight += topPaddingAddition;
6596 totalBottomBoxesHeight += Math.max(maxVerticalBottomPadding - totalBottomBoxesHeight, 0);
6597
6598 // Figure out if our chart area changed. This would occur if the dataset layout label rotation
6599 // changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
6600 // without calling `fit` again
6601 var newMaxChartAreaHeight = height - totalTopBoxesHeight - totalBottomBoxesHeight;
6602 var newMaxChartAreaWidth = width - totalLeftBoxesWidth - totalRightBoxesWidth;
6603
6604 if (newMaxChartAreaWidth !== maxChartAreaWidth || newMaxChartAreaHeight !== maxChartAreaHeight) {
6605 helpers.each(leftBoxes, function(box) {
6606 box.height = newMaxChartAreaHeight;
6607 });
6608
6609 helpers.each(rightBoxes, function(box) {
6610 box.height = newMaxChartAreaHeight;
6611 });
6612
6613 helpers.each(topBoxes, function(box) {
6614 if (!box.fullWidth) {
6615 box.width = newMaxChartAreaWidth;
6616 }
6617 });
6618
6619 helpers.each(bottomBoxes, function(box) {
6620 if (!box.fullWidth) {
6621 box.width = newMaxChartAreaWidth;
6622 }
6623 });
6624
6625 maxChartAreaHeight = newMaxChartAreaHeight;
6626 maxChartAreaWidth = newMaxChartAreaWidth;
6627 }
6628
6629 // Step 7 - Position the boxes
6630 var left = leftPadding + leftPaddingAddition;
6631 var top = topPadding + topPaddingAddition;
6632
6633 function placeBox(box) {
6634 if (box.isHorizontal()) {
6635 box.left = box.fullWidth ? leftPadding : totalLeftBoxesWidth;
6636 box.right = box.fullWidth ? width - rightPadding : totalLeftBoxesWidth + maxChartAreaWidth;
6637 box.top = top;
6638 box.bottom = top + box.height;
6639
6640 // Move to next point
6641 top = box.bottom;
6642
6643 } else {
6644
6645 box.left = left;
6646 box.right = left + box.width;
6647 box.top = totalTopBoxesHeight;
6648 box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
6649
6650 // Move to next point
6651 left = box.right;
6652 }
6653 }
6654
6655 helpers.each(leftBoxes.concat(topBoxes), placeBox);
6656
6657 // Account for chart width and height
6658 left += maxChartAreaWidth;
6659 top += maxChartAreaHeight;
6660
6661 helpers.each(rightBoxes, placeBox);
6662 helpers.each(bottomBoxes, placeBox);
6663
6664 // Step 8
6665 chart.chartArea = {
6666 left: totalLeftBoxesWidth,
6667 top: totalTopBoxesHeight,
6668 right: totalLeftBoxesWidth + maxChartAreaWidth,
6669 bottom: totalTopBoxesHeight + maxChartAreaHeight
6670 };
6671
6672 // Step 9
6673 helpers.each(chartAreaBoxes, function(box) {
6674 box.left = chart.chartArea.left;
6675 box.top = chart.chartArea.top;
6676 box.right = chart.chartArea.right;
6677 box.bottom = chart.chartArea.bottom;
6678
6679 box.update(maxChartAreaWidth, maxChartAreaHeight);
6680 });
6681 }
6682};
6683
6684},{"42":42}],28:[function(require,module,exports){
6685'use strict';
6686
6687var defaults = require(22);
6688var helpers = require(42);
6689
6690defaults._set('global', {
6691 plugins: {}
6692});
6693
6694/**
6695 * The plugin service singleton
6696 * @namespace Chart.plugins
6697 * @since 2.1.0
6698 */
6699module.exports = {
6700 /**
6701 * Globally registered plugins.
6702 * @private
6703 */
6704 _plugins: [],
6705
6706 /**
6707 * This identifier is used to invalidate the descriptors cache attached to each chart
6708 * when a global plugin is registered or unregistered. In this case, the cache ID is
6709 * incremented and descriptors are regenerated during following API calls.
6710 * @private
6711 */
6712 _cacheId: 0,
6713
6714 /**
6715 * Registers the given plugin(s) if not already registered.
6716 * @param {Array|Object} plugins plugin instance(s).
6717 */
6718 register: function(plugins) {
6719 var p = this._plugins;
6720 ([]).concat(plugins).forEach(function(plugin) {
6721 if (p.indexOf(plugin) === -1) {
6722 p.push(plugin);
6723 }
6724 });
6725
6726 this._cacheId++;
6727 },
6728
6729 /**
6730 * Unregisters the given plugin(s) only if registered.
6731 * @param {Array|Object} plugins plugin instance(s).
6732 */
6733 unregister: function(plugins) {
6734 var p = this._plugins;
6735 ([]).concat(plugins).forEach(function(plugin) {
6736 var idx = p.indexOf(plugin);
6737 if (idx !== -1) {
6738 p.splice(idx, 1);
6739 }
6740 });
6741
6742 this._cacheId++;
6743 },
6744
6745 /**
6746 * Remove all registered plugins.
6747 * @since 2.1.5
6748 */
6749 clear: function() {
6750 this._plugins = [];
6751 this._cacheId++;
6752 },
6753
6754 /**
6755 * Returns the number of registered plugins?
6756 * @returns {Number}
6757 * @since 2.1.5
6758 */
6759 count: function() {
6760 return this._plugins.length;
6761 },
6762
6763 /**
6764 * Returns all registered plugin instances.
6765 * @returns {Array} array of plugin objects.
6766 * @since 2.1.5
6767 */
6768 getAll: function() {
6769 return this._plugins;
6770 },
6771
6772 /**
6773 * Calls enabled plugins for `chart` on the specified hook and with the given args.
6774 * This method immediately returns as soon as a plugin explicitly returns false. The
6775 * returned value can be used, for instance, to interrupt the current action.
6776 * @param {Object} chart - The chart instance for which plugins should be called.
6777 * @param {String} hook - The name of the plugin method to call (e.g. 'beforeUpdate').
6778 * @param {Array} [args] - Extra arguments to apply to the hook call.
6779 * @returns {Boolean} false if any of the plugins return false, else returns true.
6780 */
6781 notify: function(chart, hook, args) {
6782 var descriptors = this.descriptors(chart);
6783 var ilen = descriptors.length;
6784 var i, descriptor, plugin, params, method;
6785
6786 for (i = 0; i < ilen; ++i) {
6787 descriptor = descriptors[i];
6788 plugin = descriptor.plugin;
6789 method = plugin[hook];
6790 if (typeof method === 'function') {
6791 params = [chart].concat(args || []);
6792 params.push(descriptor.options);
6793 if (method.apply(plugin, params) === false) {
6794 return false;
6795 }
6796 }
6797 }
6798
6799 return true;
6800 },
6801
6802 /**
6803 * Returns descriptors of enabled plugins for the given chart.
6804 * @returns {Array} [{ plugin, options }]
6805 * @private
6806 */
6807 descriptors: function(chart) {
6808 var cache = chart.$plugins || (chart.$plugins = {});
6809 if (cache.id === this._cacheId) {
6810 return cache.descriptors;
6811 }
6812
6813 var plugins = [];
6814 var descriptors = [];
6815 var config = (chart && chart.config) || {};
6816 var options = (config.options && config.options.plugins) || {};
6817
6818 this._plugins.concat(config.plugins || []).forEach(function(plugin) {
6819 var idx = plugins.indexOf(plugin);
6820 if (idx !== -1) {
6821 return;
6822 }
6823
6824 var id = plugin.id;
6825 var opts = options[id];
6826 if (opts === false) {
6827 return;
6828 }
6829
6830 if (opts === true) {
6831 opts = helpers.clone(defaults.global.plugins[id]);
6832 }
6833
6834 plugins.push(plugin);
6835 descriptors.push({
6836 plugin: plugin,
6837 options: opts || {}
6838 });
6839 });
6840
6841 cache.descriptors = descriptors;
6842 cache.id = this._cacheId;
6843 return descriptors;
6844 },
6845
6846 /**
6847 * Invalidates cache for the given chart: descriptors hold a reference on plugin option,
6848 * but in some cases, this reference can be changed by the user when updating options.
6849 * https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
6850 * @private
6851 */
6852 _invalidate: function(chart) {
6853 delete chart.$plugins;
6854 }
6855};
6856
6857/**
6858 * Plugin extension hooks.
6859 * @interface IPlugin
6860 * @since 2.1.0
6861 */
6862/**
6863 * @method IPlugin#beforeInit
6864 * @desc Called before initializing `chart`.
6865 * @param {Chart.Controller} chart - The chart instance.
6866 * @param {Object} options - The plugin options.
6867 */
6868/**
6869 * @method IPlugin#afterInit
6870 * @desc Called after `chart` has been initialized and before the first update.
6871 * @param {Chart.Controller} chart - The chart instance.
6872 * @param {Object} options - The plugin options.
6873 */
6874/**
6875 * @method IPlugin#beforeUpdate
6876 * @desc Called before updating `chart`. If any plugin returns `false`, the update
6877 * is cancelled (and thus subsequent render(s)) until another `update` is triggered.
6878 * @param {Chart.Controller} chart - The chart instance.
6879 * @param {Object} options - The plugin options.
6880 * @returns {Boolean} `false` to cancel the chart update.
6881 */
6882/**
6883 * @method IPlugin#afterUpdate
6884 * @desc Called after `chart` has been updated and before rendering. Note that this
6885 * hook will not be called if the chart update has been previously cancelled.
6886 * @param {Chart.Controller} chart - The chart instance.
6887 * @param {Object} options - The plugin options.
6888 */
6889/**
6890 * @method IPlugin#beforeDatasetsUpdate
6891 * @desc Called before updating the `chart` datasets. If any plugin returns `false`,
6892 * the datasets update is cancelled until another `update` is triggered.
6893 * @param {Chart.Controller} chart - The chart instance.
6894 * @param {Object} options - The plugin options.
6895 * @returns {Boolean} false to cancel the datasets update.
6896 * @since version 2.1.5
6897*/
6898/**
6899 * @method IPlugin#afterDatasetsUpdate
6900 * @desc Called after the `chart` datasets have been updated. Note that this hook
6901 * will not be called if the datasets update has been previously cancelled.
6902 * @param {Chart.Controller} chart - The chart instance.
6903 * @param {Object} options - The plugin options.
6904 * @since version 2.1.5
6905 */
6906/**
6907 * @method IPlugin#beforeDatasetUpdate
6908 * @desc Called before updating the `chart` dataset at the given `args.index`. If any plugin
6909 * returns `false`, the datasets update is cancelled until another `update` is triggered.
6910 * @param {Chart} chart - The chart instance.
6911 * @param {Object} args - The call arguments.
6912 * @param {Number} args.index - The dataset index.
6913 * @param {Object} args.meta - The dataset metadata.
6914 * @param {Object} options - The plugin options.
6915 * @returns {Boolean} `false` to cancel the chart datasets drawing.
6916 */
6917/**
6918 * @method IPlugin#afterDatasetUpdate
6919 * @desc Called after the `chart` datasets at the given `args.index` has been updated. Note
6920 * that this hook will not be called if the datasets update has been previously cancelled.
6921 * @param {Chart} chart - The chart instance.
6922 * @param {Object} args - The call arguments.
6923 * @param {Number} args.index - The dataset index.
6924 * @param {Object} args.meta - The dataset metadata.
6925 * @param {Object} options - The plugin options.
6926 */
6927/**
6928 * @method IPlugin#beforeLayout
6929 * @desc Called before laying out `chart`. If any plugin returns `false`,
6930 * the layout update is cancelled until another `update` is triggered.
6931 * @param {Chart.Controller} chart - The chart instance.
6932 * @param {Object} options - The plugin options.
6933 * @returns {Boolean} `false` to cancel the chart layout.
6934 */
6935/**
6936 * @method IPlugin#afterLayout
6937 * @desc Called after the `chart` has been layed out. Note that this hook will not
6938 * be called if the layout update has been previously cancelled.
6939 * @param {Chart.Controller} chart - The chart instance.
6940 * @param {Object} options - The plugin options.
6941 */
6942/**
6943 * @method IPlugin#beforeRender
6944 * @desc Called before rendering `chart`. If any plugin returns `false`,
6945 * the rendering is cancelled until another `render` is triggered.
6946 * @param {Chart.Controller} chart - The chart instance.
6947 * @param {Object} options - The plugin options.
6948 * @returns {Boolean} `false` to cancel the chart rendering.
6949 */
6950/**
6951 * @method IPlugin#afterRender
6952 * @desc Called after the `chart` has been fully rendered (and animation completed). Note
6953 * that this hook will not be called if the rendering has been previously cancelled.
6954 * @param {Chart.Controller} chart - The chart instance.
6955 * @param {Object} options - The plugin options.
6956 */
6957/**
6958 * @method IPlugin#beforeDraw
6959 * @desc Called before drawing `chart` at every animation frame specified by the given
6960 * easing value. If any plugin returns `false`, the frame drawing is cancelled until
6961 * another `render` is triggered.
6962 * @param {Chart.Controller} chart - The chart instance.
6963 * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
6964 * @param {Object} options - The plugin options.
6965 * @returns {Boolean} `false` to cancel the chart drawing.
6966 */
6967/**
6968 * @method IPlugin#afterDraw
6969 * @desc Called after the `chart` has been drawn for the specific easing value. Note
6970 * that this hook will not be called if the drawing has been previously cancelled.
6971 * @param {Chart.Controller} chart - The chart instance.
6972 * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
6973 * @param {Object} options - The plugin options.
6974 */
6975/**
6976 * @method IPlugin#beforeDatasetsDraw
6977 * @desc Called before drawing the `chart` datasets. If any plugin returns `false`,
6978 * the datasets drawing is cancelled until another `render` is triggered.
6979 * @param {Chart.Controller} chart - The chart instance.
6980 * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
6981 * @param {Object} options - The plugin options.
6982 * @returns {Boolean} `false` to cancel the chart datasets drawing.
6983 */
6984/**
6985 * @method IPlugin#afterDatasetsDraw
6986 * @desc Called after the `chart` datasets have been drawn. Note that this hook
6987 * will not be called if the datasets drawing has been previously cancelled.
6988 * @param {Chart.Controller} chart - The chart instance.
6989 * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
6990 * @param {Object} options - The plugin options.
6991 */
6992/**
6993 * @method IPlugin#beforeDatasetDraw
6994 * @desc Called before drawing the `chart` dataset at the given `args.index` (datasets
6995 * are drawn in the reverse order). If any plugin returns `false`, the datasets drawing
6996 * is cancelled until another `render` is triggered.
6997 * @param {Chart} chart - The chart instance.
6998 * @param {Object} args - The call arguments.
6999 * @param {Number} args.index - The dataset index.
7000 * @param {Object} args.meta - The dataset metadata.
7001 * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
7002 * @param {Object} options - The plugin options.
7003 * @returns {Boolean} `false` to cancel the chart datasets drawing.
7004 */
7005/**
7006 * @method IPlugin#afterDatasetDraw
7007 * @desc Called after the `chart` datasets at the given `args.index` have been drawn
7008 * (datasets are drawn in the reverse order). Note that this hook will not be called
7009 * if the datasets drawing has been previously cancelled.
7010 * @param {Chart} chart - The chart instance.
7011 * @param {Object} args - The call arguments.
7012 * @param {Number} args.index - The dataset index.
7013 * @param {Object} args.meta - The dataset metadata.
7014 * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
7015 * @param {Object} options - The plugin options.
7016 */
7017/**
7018 * @method IPlugin#beforeTooltipDraw
7019 * @desc Called before drawing the `tooltip`. If any plugin returns `false`,
7020 * the tooltip drawing is cancelled until another `render` is triggered.
7021 * @param {Chart} chart - The chart instance.
7022 * @param {Object} args - The call arguments.
7023 * @param {Object} args.tooltip - The tooltip.
7024 * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
7025 * @param {Object} options - The plugin options.
7026 * @returns {Boolean} `false` to cancel the chart tooltip drawing.
7027 */
7028/**
7029 * @method IPlugin#afterTooltipDraw
7030 * @desc Called after drawing the `tooltip`. Note that this hook will not
7031 * be called if the tooltip drawing has been previously cancelled.
7032 * @param {Chart} chart - The chart instance.
7033 * @param {Object} args - The call arguments.
7034 * @param {Object} args.tooltip - The tooltip.
7035 * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
7036 * @param {Object} options - The plugin options.
7037 */
7038/**
7039 * @method IPlugin#beforeEvent
7040 * @desc Called before processing the specified `event`. If any plugin returns `false`,
7041 * the event will be discarded.
7042 * @param {Chart.Controller} chart - The chart instance.
7043 * @param {IEvent} event - The event object.
7044 * @param {Object} options - The plugin options.
7045 */
7046/**
7047 * @method IPlugin#afterEvent
7048 * @desc Called after the `event` has been consumed. Note that this hook
7049 * will not be called if the `event` has been previously discarded.
7050 * @param {Chart.Controller} chart - The chart instance.
7051 * @param {IEvent} event - The event object.
7052 * @param {Object} options - The plugin options.
7053 */
7054/**
7055 * @method IPlugin#resize
7056 * @desc Called after the chart as been resized.
7057 * @param {Chart.Controller} chart - The chart instance.
7058 * @param {Number} size - The new canvas display size (eq. canvas.style width & height).
7059 * @param {Object} options - The plugin options.
7060 */
7061/**
7062 * @method IPlugin#destroy
7063 * @desc Called after the chart as been destroyed.
7064 * @param {Chart.Controller} chart - The chart instance.
7065 * @param {Object} options - The plugin options.
7066 */
7067
7068},{"22":22,"42":42}],29:[function(require,module,exports){
7069'use strict';
7070
7071var defaults = require(22);
7072var Element = require(23);
7073var helpers = require(42);
7074var Ticks = require(31);
7075
7076defaults._set('scale', {
7077 display: true,
7078 position: 'left',
7079 offset: false,
7080
7081 // grid line settings
7082 gridLines: {
7083 display: true,
7084 color: 'rgba(0, 0, 0, 0.1)',
7085 lineWidth: 1,
7086 drawBorder: true,
7087 drawOnChartArea: true,
7088 drawTicks: true,
7089 tickMarkLength: 10,
7090 zeroLineWidth: 1,
7091 zeroLineColor: 'rgba(0,0,0,0.25)',
7092 zeroLineBorderDash: [],
7093 zeroLineBorderDashOffset: 0.0,
7094 offsetGridLines: false,
7095 borderDash: [],
7096 borderDashOffset: 0.0
7097 },
7098
7099 // scale label
7100 scaleLabel: {
7101 // display property
7102 display: false,
7103
7104 // actual label
7105 labelString: '',
7106
7107 // line height
7108 lineHeight: 1.2,
7109
7110 // top/bottom padding
7111 padding: {
7112 top: 4,
7113 bottom: 4
7114 }
7115 },
7116
7117 // label settings
7118 ticks: {
7119 beginAtZero: false,
7120 minRotation: 0,
7121 maxRotation: 50,
7122 mirror: false,
7123 padding: 0,
7124 reverse: false,
7125 display: true,
7126 autoSkip: true,
7127 autoSkipPadding: 0,
7128 labelOffset: 0,
7129 // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
7130 callback: Ticks.formatters.values,
7131 minor: {},
7132 major: {}
7133 }
7134});
7135
7136function labelsFromTicks(ticks) {
7137 var labels = [];
7138 var i, ilen;
7139
7140 for (i = 0, ilen = ticks.length; i < ilen; ++i) {
7141 labels.push(ticks[i].label);
7142 }
7143
7144 return labels;
7145}
7146
7147function getPixelForGridLine(scale, index, offsetGridLines) {
7148 var lineValue = scale.getPixelForTick(index);
7149
7150 if (offsetGridLines) {
7151 if (scale.getTicks().length === 1) {
7152 lineValue -= scale.isHorizontal() ?
7153 Math.max(lineValue - scale.left, scale.right - lineValue) :
7154 Math.max(lineValue - scale.top, scale.bottom - lineValue);
7155 } else if (index === 0) {
7156 lineValue -= (scale.getPixelForTick(1) - lineValue) / 2;
7157 } else {
7158 lineValue -= (lineValue - scale.getPixelForTick(index - 1)) / 2;
7159 }
7160 }
7161 return lineValue;
7162}
7163
7164function computeTextSize(context, tick, font) {
7165 return helpers.isArray(tick) ?
7166 helpers.longestText(context, font, tick) :
7167 context.measureText(tick).width;
7168}
7169
7170function parseFontOptions(options) {
7171 var valueOrDefault = helpers.valueOrDefault;
7172 var globalDefaults = defaults.global;
7173 var size = valueOrDefault(options.fontSize, globalDefaults.defaultFontSize);
7174 var style = valueOrDefault(options.fontStyle, globalDefaults.defaultFontStyle);
7175 var family = valueOrDefault(options.fontFamily, globalDefaults.defaultFontFamily);
7176
7177 return {
7178 size: size,
7179 style: style,
7180 family: family,
7181 font: helpers.fontString(size, style, family)
7182 };
7183}
7184
7185function parseLineHeight(options) {
7186 return helpers.options.toLineHeight(
7187 helpers.valueOrDefault(options.lineHeight, 1.2),
7188 helpers.valueOrDefault(options.fontSize, defaults.global.defaultFontSize));
7189}
7190
7191module.exports = Element.extend({
7192 /**
7193 * Get the padding needed for the scale
7194 * @method getPadding
7195 * @private
7196 * @returns {Padding} the necessary padding
7197 */
7198 getPadding: function() {
7199 var me = this;
7200 return {
7201 left: me.paddingLeft || 0,
7202 top: me.paddingTop || 0,
7203 right: me.paddingRight || 0,
7204 bottom: me.paddingBottom || 0
7205 };
7206 },
7207
7208 /**
7209 * Returns the scale tick objects ({label, major})
7210 * @since 2.7
7211 */
7212 getTicks: function() {
7213 return this._ticks;
7214 },
7215
7216 // These methods are ordered by lifecyle. Utilities then follow.
7217 // Any function defined here is inherited by all scale types.
7218 // Any function can be extended by the scale type
7219
7220 mergeTicksOptions: function() {
7221 var ticks = this.options.ticks;
7222 if (ticks.minor === false) {
7223 ticks.minor = {
7224 display: false
7225 };
7226 }
7227 if (ticks.major === false) {
7228 ticks.major = {
7229 display: false
7230 };
7231 }
7232 for (var key in ticks) {
7233 if (key !== 'major' && key !== 'minor') {
7234 if (typeof ticks.minor[key] === 'undefined') {
7235 ticks.minor[key] = ticks[key];
7236 }
7237 if (typeof ticks.major[key] === 'undefined') {
7238 ticks.major[key] = ticks[key];
7239 }
7240 }
7241 }
7242 },
7243 beforeUpdate: function() {
7244 helpers.callback(this.options.beforeUpdate, [this]);
7245 },
7246
7247 update: function(maxWidth, maxHeight, margins) {
7248 var me = this;
7249 var i, ilen, labels, label, ticks, tick;
7250
7251 // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
7252 me.beforeUpdate();
7253
7254 // Absorb the master measurements
7255 me.maxWidth = maxWidth;
7256 me.maxHeight = maxHeight;
7257 me.margins = helpers.extend({
7258 left: 0,
7259 right: 0,
7260 top: 0,
7261 bottom: 0
7262 }, margins);
7263 me.longestTextCache = me.longestTextCache || {};
7264
7265 // Dimensions
7266 me.beforeSetDimensions();
7267 me.setDimensions();
7268 me.afterSetDimensions();
7269
7270 // Data min/max
7271 me.beforeDataLimits();
7272 me.determineDataLimits();
7273 me.afterDataLimits();
7274
7275 // Ticks - `this.ticks` is now DEPRECATED!
7276 // Internal ticks are now stored as objects in the PRIVATE `this._ticks` member
7277 // and must not be accessed directly from outside this class. `this.ticks` being
7278 // around for long time and not marked as private, we can't change its structure
7279 // without unexpected breaking changes. If you need to access the scale ticks,
7280 // use scale.getTicks() instead.
7281
7282 me.beforeBuildTicks();
7283
7284 // New implementations should return an array of objects but for BACKWARD COMPAT,
7285 // we still support no return (`this.ticks` internally set by calling this method).
7286 ticks = me.buildTicks() || [];
7287
7288 me.afterBuildTicks();
7289
7290 me.beforeTickToLabelConversion();
7291
7292 // New implementations should return the formatted tick labels but for BACKWARD
7293 // COMPAT, we still support no return (`this.ticks` internally changed by calling
7294 // this method and supposed to contain only string values).
7295 labels = me.convertTicksToLabels(ticks) || me.ticks;
7296
7297 me.afterTickToLabelConversion();
7298
7299 me.ticks = labels; // BACKWARD COMPATIBILITY
7300
7301 // IMPORTANT: from this point, we consider that `this.ticks` will NEVER change!
7302
7303 // BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`)
7304 for (i = 0, ilen = labels.length; i < ilen; ++i) {
7305 label = labels[i];
7306 tick = ticks[i];
7307 if (!tick) {
7308 ticks.push(tick = {
7309 label: label,
7310 major: false
7311 });
7312 } else {
7313 tick.label = label;
7314 }
7315 }
7316
7317 me._ticks = ticks;
7318
7319 // Tick Rotation
7320 me.beforeCalculateTickRotation();
7321 me.calculateTickRotation();
7322 me.afterCalculateTickRotation();
7323 // Fit
7324 me.beforeFit();
7325 me.fit();
7326 me.afterFit();
7327 //
7328 me.afterUpdate();
7329
7330 return me.minSize;
7331
7332 },
7333 afterUpdate: function() {
7334 helpers.callback(this.options.afterUpdate, [this]);
7335 },
7336
7337 //
7338
7339 beforeSetDimensions: function() {
7340 helpers.callback(this.options.beforeSetDimensions, [this]);
7341 },
7342 setDimensions: function() {
7343 var me = this;
7344 // Set the unconstrained dimension before label rotation
7345 if (me.isHorizontal()) {
7346 // Reset position before calculating rotation
7347 me.width = me.maxWidth;
7348 me.left = 0;
7349 me.right = me.width;
7350 } else {
7351 me.height = me.maxHeight;
7352
7353 // Reset position before calculating rotation
7354 me.top = 0;
7355 me.bottom = me.height;
7356 }
7357
7358 // Reset padding
7359 me.paddingLeft = 0;
7360 me.paddingTop = 0;
7361 me.paddingRight = 0;
7362 me.paddingBottom = 0;
7363 },
7364 afterSetDimensions: function() {
7365 helpers.callback(this.options.afterSetDimensions, [this]);
7366 },
7367
7368 // Data limits
7369 beforeDataLimits: function() {
7370 helpers.callback(this.options.beforeDataLimits, [this]);
7371 },
7372 determineDataLimits: helpers.noop,
7373 afterDataLimits: function() {
7374 helpers.callback(this.options.afterDataLimits, [this]);
7375 },
7376
7377 //
7378 beforeBuildTicks: function() {
7379 helpers.callback(this.options.beforeBuildTicks, [this]);
7380 },
7381 buildTicks: helpers.noop,
7382 afterBuildTicks: function() {
7383 helpers.callback(this.options.afterBuildTicks, [this]);
7384 },
7385
7386 beforeTickToLabelConversion: function() {
7387 helpers.callback(this.options.beforeTickToLabelConversion, [this]);
7388 },
7389 convertTicksToLabels: function() {
7390 var me = this;
7391 // Convert ticks to strings
7392 var tickOpts = me.options.ticks;
7393 me.ticks = me.ticks.map(tickOpts.userCallback || tickOpts.callback, this);
7394 },
7395 afterTickToLabelConversion: function() {
7396 helpers.callback(this.options.afterTickToLabelConversion, [this]);
7397 },
7398
7399 //
7400
7401 beforeCalculateTickRotation: function() {
7402 helpers.callback(this.options.beforeCalculateTickRotation, [this]);
7403 },
7404 calculateTickRotation: function() {
7405 var me = this;
7406 var context = me.ctx;
7407 var tickOpts = me.options.ticks;
7408 var labels = labelsFromTicks(me._ticks);
7409
7410 // Get the width of each grid by calculating the difference
7411 // between x offsets between 0 and 1.
7412 var tickFont = parseFontOptions(tickOpts);
7413 context.font = tickFont.font;
7414
7415 var labelRotation = tickOpts.minRotation || 0;
7416
7417 if (labels.length && me.options.display && me.isHorizontal()) {
7418 var originalLabelWidth = helpers.longestText(context, tickFont.font, labels, me.longestTextCache);
7419 var labelWidth = originalLabelWidth;
7420 var cosRotation, sinRotation;
7421
7422 // Allow 3 pixels x2 padding either side for label readability
7423 var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
7424
7425 // Max label rotation can be set or default to 90 - also act as a loop counter
7426 while (labelWidth > tickWidth && labelRotation < tickOpts.maxRotation) {
7427 var angleRadians = helpers.toRadians(labelRotation);
7428 cosRotation = Math.cos(angleRadians);
7429 sinRotation = Math.sin(angleRadians);
7430
7431 if (sinRotation * originalLabelWidth > me.maxHeight) {
7432 // go back one step
7433 labelRotation--;
7434 break;
7435 }
7436
7437 labelRotation++;
7438 labelWidth = cosRotation * originalLabelWidth;
7439 }
7440 }
7441
7442 me.labelRotation = labelRotation;
7443 },
7444 afterCalculateTickRotation: function() {
7445 helpers.callback(this.options.afterCalculateTickRotation, [this]);
7446 },
7447
7448 //
7449
7450 beforeFit: function() {
7451 helpers.callback(this.options.beforeFit, [this]);
7452 },
7453 fit: function() {
7454 var me = this;
7455 // Reset
7456 var minSize = me.minSize = {
7457 width: 0,
7458 height: 0
7459 };
7460
7461 var labels = labelsFromTicks(me._ticks);
7462
7463 var opts = me.options;
7464 var tickOpts = opts.ticks;
7465 var scaleLabelOpts = opts.scaleLabel;
7466 var gridLineOpts = opts.gridLines;
7467 var display = opts.display;
7468 var isHorizontal = me.isHorizontal();
7469
7470 var tickFont = parseFontOptions(tickOpts);
7471 var tickMarkLength = opts.gridLines.tickMarkLength;
7472
7473 // Width
7474 if (isHorizontal) {
7475 // subtract the margins to line up with the chartArea if we are a full width scale
7476 minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
7477 } else {
7478 minSize.width = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
7479 }
7480
7481 // height
7482 if (isHorizontal) {
7483 minSize.height = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
7484 } else {
7485 minSize.height = me.maxHeight; // fill all the height
7486 }
7487
7488 // Are we showing a title for the scale?
7489 if (scaleLabelOpts.display && display) {
7490 var scaleLabelLineHeight = parseLineHeight(scaleLabelOpts);
7491 var scaleLabelPadding = helpers.options.toPadding(scaleLabelOpts.padding);
7492 var deltaHeight = scaleLabelLineHeight + scaleLabelPadding.height;
7493
7494 if (isHorizontal) {
7495 minSize.height += deltaHeight;
7496 } else {
7497 minSize.width += deltaHeight;
7498 }
7499 }
7500
7501 // Don't bother fitting the ticks if we are not showing them
7502 if (tickOpts.display && display) {
7503 var largestTextWidth = helpers.longestText(me.ctx, tickFont.font, labels, me.longestTextCache);
7504 var tallestLabelHeightInLines = helpers.numberOfLabelLines(labels);
7505 var lineSpace = tickFont.size * 0.5;
7506 var tickPadding = me.options.ticks.padding;
7507
7508 if (isHorizontal) {
7509 // A horizontal axis is more constrained by the height.
7510 me.longestLabelWidth = largestTextWidth;
7511
7512 var angleRadians = helpers.toRadians(me.labelRotation);
7513 var cosRotation = Math.cos(angleRadians);
7514 var sinRotation = Math.sin(angleRadians);
7515
7516 // TODO - improve this calculation
7517 var labelHeight = (sinRotation * largestTextWidth)
7518 + (tickFont.size * tallestLabelHeightInLines)
7519 + (lineSpace * (tallestLabelHeightInLines - 1))
7520 + lineSpace; // padding
7521
7522 minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight + tickPadding);
7523
7524 me.ctx.font = tickFont.font;
7525 var firstLabelWidth = computeTextSize(me.ctx, labels[0], tickFont.font);
7526 var lastLabelWidth = computeTextSize(me.ctx, labels[labels.length - 1], tickFont.font);
7527
7528 // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned
7529 // which means that the right padding is dominated by the font height
7530 if (me.labelRotation !== 0) {
7531 me.paddingLeft = opts.position === 'bottom' ? (cosRotation * firstLabelWidth) + 3 : (cosRotation * lineSpace) + 3; // add 3 px to move away from canvas edges
7532 me.paddingRight = opts.position === 'bottom' ? (cosRotation * lineSpace) + 3 : (cosRotation * lastLabelWidth) + 3;
7533 } else {
7534 me.paddingLeft = firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
7535 me.paddingRight = lastLabelWidth / 2 + 3;
7536 }
7537 } else {
7538 // A vertical axis is more constrained by the width. Labels are the
7539 // dominant factor here, so get that length first and account for padding
7540 if (tickOpts.mirror) {
7541 largestTextWidth = 0;
7542 } else {
7543 // use lineSpace for consistency with horizontal axis
7544 // tickPadding is not implemented for horizontal
7545 largestTextWidth += tickPadding + lineSpace;
7546 }
7547
7548 minSize.width = Math.min(me.maxWidth, minSize.width + largestTextWidth);
7549
7550 me.paddingTop = tickFont.size / 2;
7551 me.paddingBottom = tickFont.size / 2;
7552 }
7553 }
7554
7555 me.handleMargins();
7556
7557 me.width = minSize.width;
7558 me.height = minSize.height;
7559 },
7560
7561 /**
7562 * Handle margins and padding interactions
7563 * @private
7564 */
7565 handleMargins: function() {
7566 var me = this;
7567 if (me.margins) {
7568 me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
7569 me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
7570 me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
7571 me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
7572 }
7573 },
7574
7575 afterFit: function() {
7576 helpers.callback(this.options.afterFit, [this]);
7577 },
7578
7579 // Shared Methods
7580 isHorizontal: function() {
7581 return this.options.position === 'top' || this.options.position === 'bottom';
7582 },
7583 isFullWidth: function() {
7584 return (this.options.fullWidth);
7585 },
7586
7587 // Get the correct value. NaN bad inputs, If the value type is object get the x or y based on whether we are horizontal or not
7588 getRightValue: function(rawValue) {
7589 // Null and undefined values first
7590 if (helpers.isNullOrUndef(rawValue)) {
7591 return NaN;
7592 }
7593 // isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values
7594 if ((typeof rawValue === 'number' || rawValue instanceof Number) && !isFinite(rawValue)) {
7595 return NaN;
7596 }
7597 // If it is in fact an object, dive in one more level
7598 if (rawValue) {
7599 if (this.isHorizontal()) {
7600 if (rawValue.x !== undefined) {
7601 return this.getRightValue(rawValue.x);
7602 }
7603 } else if (rawValue.y !== undefined) {
7604 return this.getRightValue(rawValue.y);
7605 }
7606 }
7607
7608 // Value is good, return it
7609 return rawValue;
7610 },
7611
7612 /**
7613 * Used to get the value to display in the tooltip for the data at the given index
7614 * @param index
7615 * @param datasetIndex
7616 */
7617 getLabelForIndex: helpers.noop,
7618
7619 /**
7620 * Returns the location of the given data point. Value can either be an index or a numerical value
7621 * The coordinate (0, 0) is at the upper-left corner of the canvas
7622 * @param value
7623 * @param index
7624 * @param datasetIndex
7625 */
7626 getPixelForValue: helpers.noop,
7627
7628 /**
7629 * Used to get the data value from a given pixel. This is the inverse of getPixelForValue
7630 * The coordinate (0, 0) is at the upper-left corner of the canvas
7631 * @param pixel
7632 */
7633 getValueForPixel: helpers.noop,
7634
7635 /**
7636 * Returns the location of the tick at the given index
7637 * The coordinate (0, 0) is at the upper-left corner of the canvas
7638 */
7639 getPixelForTick: function(index) {
7640 var me = this;
7641 var offset = me.options.offset;
7642 if (me.isHorizontal()) {
7643 var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
7644 var tickWidth = innerWidth / Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
7645 var pixel = (tickWidth * index) + me.paddingLeft;
7646
7647 if (offset) {
7648 pixel += tickWidth / 2;
7649 }
7650
7651 var finalVal = me.left + Math.round(pixel);
7652 finalVal += me.isFullWidth() ? me.margins.left : 0;
7653 return finalVal;
7654 }
7655 var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
7656 return me.top + (index * (innerHeight / (me._ticks.length - 1)));
7657 },
7658
7659 /**
7660 * Utility for getting the pixel location of a percentage of scale
7661 * The coordinate (0, 0) is at the upper-left corner of the canvas
7662 */
7663 getPixelForDecimal: function(decimal) {
7664 var me = this;
7665 if (me.isHorizontal()) {
7666 var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
7667 var valueOffset = (innerWidth * decimal) + me.paddingLeft;
7668
7669 var finalVal = me.left + Math.round(valueOffset);
7670 finalVal += me.isFullWidth() ? me.margins.left : 0;
7671 return finalVal;
7672 }
7673 return me.top + (decimal * me.height);
7674 },
7675
7676 /**
7677 * Returns the pixel for the minimum chart value
7678 * The coordinate (0, 0) is at the upper-left corner of the canvas
7679 */
7680 getBasePixel: function() {
7681 return this.getPixelForValue(this.getBaseValue());
7682 },
7683
7684 getBaseValue: function() {
7685 var me = this;
7686 var min = me.min;
7687 var max = me.max;
7688
7689 return me.beginAtZero ? 0 :
7690 min < 0 && max < 0 ? max :
7691 min > 0 && max > 0 ? min :
7692 0;
7693 },
7694
7695 /**
7696 * Returns a subset of ticks to be plotted to avoid overlapping labels.
7697 * @private
7698 */
7699 _autoSkip: function(ticks) {
7700 var skipRatio;
7701 var me = this;
7702 var isHorizontal = me.isHorizontal();
7703 var optionTicks = me.options.ticks.minor;
7704 var tickCount = ticks.length;
7705 var labelRotationRadians = helpers.toRadians(me.labelRotation);
7706 var cosRotation = Math.cos(labelRotationRadians);
7707 var longestRotatedLabel = me.longestLabelWidth * cosRotation;
7708 var result = [];
7709 var i, tick, shouldSkip;
7710
7711 // figure out the maximum number of gridlines to show
7712 var maxTicks;
7713 if (optionTicks.maxTicksLimit) {
7714 maxTicks = optionTicks.maxTicksLimit;
7715 }
7716
7717 if (isHorizontal) {
7718 skipRatio = false;
7719
7720 if ((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount > (me.width - (me.paddingLeft + me.paddingRight))) {
7721 skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount) / (me.width - (me.paddingLeft + me.paddingRight)));
7722 }
7723
7724 // if they defined a max number of optionTicks,
7725 // increase skipRatio until that number is met
7726 if (maxTicks && tickCount > maxTicks) {
7727 skipRatio = Math.max(skipRatio, Math.floor(tickCount / maxTicks));
7728 }
7729 }
7730
7731 for (i = 0; i < tickCount; i++) {
7732 tick = ticks[i];
7733
7734 // Since we always show the last tick,we need may need to hide the last shown one before
7735 shouldSkip = (skipRatio > 1 && i % skipRatio > 0) || (i % skipRatio === 0 && i + skipRatio >= tickCount);
7736 if (shouldSkip && i !== tickCount - 1) {
7737 // leave tick in place but make sure it's not displayed (#4635)
7738 delete tick.label;
7739 }
7740 result.push(tick);
7741 }
7742 return result;
7743 },
7744
7745 // Actually draw the scale on the canvas
7746 // @param {rectangle} chartArea : the area of the chart to draw full grid lines on
7747 draw: function(chartArea) {
7748 var me = this;
7749 var options = me.options;
7750 if (!options.display) {
7751 return;
7752 }
7753
7754 var context = me.ctx;
7755 var globalDefaults = defaults.global;
7756 var optionTicks = options.ticks.minor;
7757 var optionMajorTicks = options.ticks.major || optionTicks;
7758 var gridLines = options.gridLines;
7759 var scaleLabel = options.scaleLabel;
7760
7761 var isRotated = me.labelRotation !== 0;
7762 var isHorizontal = me.isHorizontal();
7763
7764 var ticks = optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks();
7765 var tickFontColor = helpers.valueOrDefault(optionTicks.fontColor, globalDefaults.defaultFontColor);
7766 var tickFont = parseFontOptions(optionTicks);
7767 var majorTickFontColor = helpers.valueOrDefault(optionMajorTicks.fontColor, globalDefaults.defaultFontColor);
7768 var majorTickFont = parseFontOptions(optionMajorTicks);
7769
7770 var tl = gridLines.drawTicks ? gridLines.tickMarkLength : 0;
7771
7772 var scaleLabelFontColor = helpers.valueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
7773 var scaleLabelFont = parseFontOptions(scaleLabel);
7774 var scaleLabelPadding = helpers.options.toPadding(scaleLabel.padding);
7775 var labelRotationRadians = helpers.toRadians(me.labelRotation);
7776
7777 var itemsToDraw = [];
7778
7779 var axisWidth = helpers.valueAtIndexOrDefault(me.options.gridLines.lineWidth, 0);
7780 var xTickStart = options.position === 'right' ? me.left : me.right - axisWidth - tl;
7781 var xTickEnd = options.position === 'right' ? me.left + tl : me.right;
7782 var yTickStart = options.position === 'bottom' ? me.top + axisWidth : me.bottom - tl - axisWidth;
7783 var yTickEnd = options.position === 'bottom' ? me.top + axisWidth + tl : me.bottom + axisWidth;
7784
7785 var epsilon = 0.0000001; // 0.0000001 is margin in pixels for Accumulated error.
7786
7787 helpers.each(ticks, function(tick, index) {
7788 // autoskipper skipped this tick (#4635)
7789 if (helpers.isNullOrUndef(tick.label)) {
7790 return;
7791 }
7792
7793 var label = tick.label;
7794 var lineWidth, lineColor, borderDash, borderDashOffset;
7795 if (index === me.zeroLineIndex && options.offset === gridLines.offsetGridLines) {
7796 // Draw the first index specially
7797 lineWidth = gridLines.zeroLineWidth;
7798 lineColor = gridLines.zeroLineColor;
7799 borderDash = gridLines.zeroLineBorderDash || [];
7800 borderDashOffset = gridLines.zeroLineBorderDashOffset || 0.0;
7801 } else {
7802 lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, index);
7803 lineColor = helpers.valueAtIndexOrDefault(gridLines.color, index);
7804 borderDash = gridLines.borderDash || [];
7805 borderDashOffset = gridLines.borderDashOffset || 0.0;
7806 }
7807
7808 // Common properties
7809 var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
7810 var textAlign = 'middle';
7811 var textBaseline = 'middle';
7812 var tickPadding = optionTicks.padding;
7813
7814 if (isHorizontal) {
7815 var labelYOffset = tl + tickPadding;
7816
7817 if (options.position === 'bottom') {
7818 // bottom
7819 textBaseline = !isRotated ? 'top' : 'middle';
7820 textAlign = !isRotated ? 'center' : 'right';
7821 labelY = me.top + labelYOffset;
7822 } else {
7823 // top
7824 textBaseline = !isRotated ? 'bottom' : 'middle';
7825 textAlign = !isRotated ? 'center' : 'left';
7826 labelY = me.bottom - labelYOffset;
7827 }
7828
7829 var xLineValue = getPixelForGridLine(me, index, gridLines.offsetGridLines);
7830 if (xLineValue < me.left - epsilon) {
7831 lineColor = 'rgba(0,0,0,0)';
7832 }
7833 xLineValue += helpers.aliasPixel(lineWidth);
7834
7835 labelX = me.getPixelForTick(index) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
7836
7837 tx1 = tx2 = x1 = x2 = xLineValue;
7838 ty1 = yTickStart;
7839 ty2 = yTickEnd;
7840 y1 = chartArea.top;
7841 y2 = chartArea.bottom + axisWidth;
7842 } else {
7843 var isLeft = options.position === 'left';
7844 var labelXOffset;
7845
7846 if (optionTicks.mirror) {
7847 textAlign = isLeft ? 'left' : 'right';
7848 labelXOffset = tickPadding;
7849 } else {
7850 textAlign = isLeft ? 'right' : 'left';
7851 labelXOffset = tl + tickPadding;
7852 }
7853
7854 labelX = isLeft ? me.right - labelXOffset : me.left + labelXOffset;
7855
7856 var yLineValue = getPixelForGridLine(me, index, gridLines.offsetGridLines);
7857 if (yLineValue < me.top - epsilon) {
7858 lineColor = 'rgba(0,0,0,0)';
7859 }
7860 yLineValue += helpers.aliasPixel(lineWidth);
7861
7862 labelY = me.getPixelForTick(index) + optionTicks.labelOffset;
7863
7864 tx1 = xTickStart;
7865 tx2 = xTickEnd;
7866 x1 = chartArea.left;
7867 x2 = chartArea.right + axisWidth;
7868 ty1 = ty2 = y1 = y2 = yLineValue;
7869 }
7870
7871 itemsToDraw.push({
7872 tx1: tx1,
7873 ty1: ty1,
7874 tx2: tx2,
7875 ty2: ty2,
7876 x1: x1,
7877 y1: y1,
7878 x2: x2,
7879 y2: y2,
7880 labelX: labelX,
7881 labelY: labelY,
7882 glWidth: lineWidth,
7883 glColor: lineColor,
7884 glBorderDash: borderDash,
7885 glBorderDashOffset: borderDashOffset,
7886 rotation: -1 * labelRotationRadians,
7887 label: label,
7888 major: tick.major,
7889 textBaseline: textBaseline,
7890 textAlign: textAlign
7891 });
7892 });
7893
7894 // Draw all of the tick labels, tick marks, and grid lines at the correct places
7895 helpers.each(itemsToDraw, function(itemToDraw) {
7896 var glWidth = itemToDraw.glWidth;
7897 var glColor = itemToDraw.glColor;
7898
7899 if (gridLines.display && glWidth && glColor) {
7900 context.save();
7901 context.lineWidth = glWidth;
7902 context.strokeStyle = glColor;
7903 if (context.setLineDash) {
7904 context.setLineDash(itemToDraw.glBorderDash);
7905 context.lineDashOffset = itemToDraw.glBorderDashOffset;
7906 }
7907
7908 context.beginPath();
7909
7910 if (gridLines.drawTicks) {
7911 context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
7912 context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
7913 }
7914
7915 if (gridLines.drawOnChartArea) {
7916 context.moveTo(itemToDraw.x1, itemToDraw.y1);
7917 context.lineTo(itemToDraw.x2, itemToDraw.y2);
7918 }
7919
7920 context.stroke();
7921 context.restore();
7922 }
7923
7924 if (optionTicks.display) {
7925 // Make sure we draw text in the correct color and font
7926 context.save();
7927 context.translate(itemToDraw.labelX, itemToDraw.labelY);
7928 context.rotate(itemToDraw.rotation);
7929 context.font = itemToDraw.major ? majorTickFont.font : tickFont.font;
7930 context.fillStyle = itemToDraw.major ? majorTickFontColor : tickFontColor;
7931 context.textBaseline = itemToDraw.textBaseline;
7932 context.textAlign = itemToDraw.textAlign;
7933
7934 var label = itemToDraw.label;
7935 if (helpers.isArray(label)) {
7936 var lineCount = label.length;
7937 var lineHeight = tickFont.size * 1.5;
7938 var y = me.isHorizontal() ? 0 : -lineHeight * (lineCount - 1) / 2;
7939
7940 for (var i = 0; i < lineCount; ++i) {
7941 // We just make sure the multiline element is a string here..
7942 context.fillText('' + label[i], 0, y);
7943 // apply same lineSpacing as calculated @ L#320
7944 y += lineHeight;
7945 }
7946 } else {
7947 context.fillText(label, 0, 0);
7948 }
7949 context.restore();
7950 }
7951 });
7952
7953 if (scaleLabel.display) {
7954 // Draw the scale label
7955 var scaleLabelX;
7956 var scaleLabelY;
7957 var rotation = 0;
7958 var halfLineHeight = parseLineHeight(scaleLabel) / 2;
7959
7960 if (isHorizontal) {
7961 scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
7962 scaleLabelY = options.position === 'bottom'
7963 ? me.bottom - halfLineHeight - scaleLabelPadding.bottom
7964 : me.top + halfLineHeight + scaleLabelPadding.top;
7965 } else {
7966 var isLeft = options.position === 'left';
7967 scaleLabelX = isLeft
7968 ? me.left + halfLineHeight + scaleLabelPadding.top
7969 : me.right - halfLineHeight - scaleLabelPadding.top;
7970 scaleLabelY = me.top + ((me.bottom - me.top) / 2);
7971 rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
7972 }
7973
7974 context.save();
7975 context.translate(scaleLabelX, scaleLabelY);
7976 context.rotate(rotation);
7977 context.textAlign = 'center';
7978 context.textBaseline = 'middle';
7979 context.fillStyle = scaleLabelFontColor; // render in correct colour
7980 context.font = scaleLabelFont.font;
7981 context.fillText(scaleLabel.labelString, 0, 0);
7982 context.restore();
7983 }
7984
7985 if (gridLines.drawBorder) {
7986 // Draw the line at the edge of the axis
7987 context.lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, 0);
7988 context.strokeStyle = helpers.valueAtIndexOrDefault(gridLines.color, 0);
7989 var x1 = me.left;
7990 var x2 = me.right + axisWidth;
7991 var y1 = me.top;
7992 var y2 = me.bottom + axisWidth;
7993
7994 var aliasPixel = helpers.aliasPixel(context.lineWidth);
7995 if (isHorizontal) {
7996 y1 = y2 = options.position === 'top' ? me.bottom : me.top;
7997 y1 += aliasPixel;
7998 y2 += aliasPixel;
7999 } else {
8000 x1 = x2 = options.position === 'left' ? me.right : me.left;
8001 x1 += aliasPixel;
8002 x2 += aliasPixel;
8003 }
8004
8005 context.beginPath();
8006 context.moveTo(x1, y1);
8007 context.lineTo(x2, y2);
8008 context.stroke();
8009 }
8010 }
8011});
8012
8013},{"22":22,"23":23,"31":31,"42":42}],30:[function(require,module,exports){
8014'use strict';
8015
8016var defaults = require(22);
8017var helpers = require(42);
8018var layouts = require(27);
8019
8020module.exports = {
8021 // Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
8022 // use the new chart options to grab the correct scale
8023 constructors: {},
8024 // Use a registration function so that we can move to an ES6 map when we no longer need to support
8025 // old browsers
8026
8027 // Scale config defaults
8028 defaults: {},
8029 registerScaleType: function(type, scaleConstructor, scaleDefaults) {
8030 this.constructors[type] = scaleConstructor;
8031 this.defaults[type] = helpers.clone(scaleDefaults);
8032 },
8033 getScaleConstructor: function(type) {
8034 return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
8035 },
8036 getScaleDefaults: function(type) {
8037 // Return the scale defaults merged with the global settings so that we always use the latest ones
8038 return this.defaults.hasOwnProperty(type) ? helpers.merge({}, [defaults.scale, this.defaults[type]]) : {};
8039 },
8040 updateScaleDefaults: function(type, additions) {
8041 var me = this;
8042 if (me.defaults.hasOwnProperty(type)) {
8043 me.defaults[type] = helpers.extend(me.defaults[type], additions);
8044 }
8045 },
8046 addScalesToLayout: function(chart) {
8047 // Adds each scale to the chart.boxes array to be sized accordingly
8048 helpers.each(chart.scales, function(scale) {
8049 // Set ILayoutItem parameters for backwards compatibility
8050 scale.fullWidth = scale.options.fullWidth;
8051 scale.position = scale.options.position;
8052 scale.weight = scale.options.weight;
8053 layouts.addBox(chart, scale);
8054 });
8055 }
8056};
8057
8058},{"22":22,"27":27,"42":42}],31:[function(require,module,exports){
8059'use strict';
8060
8061var helpers = require(42);
8062
8063/**
8064 * Namespace to hold static tick generation functions
8065 * @namespace Chart.Ticks
8066 */
8067module.exports = {
8068 /**
8069 * Namespace to hold formatters for different types of ticks
8070 * @namespace Chart.Ticks.formatters
8071 */
8072 formatters: {
8073 /**
8074 * Formatter for value labels
8075 * @method Chart.Ticks.formatters.values
8076 * @param value the value to display
8077 * @return {String|Array} the label to display
8078 */
8079 values: function(value) {
8080 return helpers.isArray(value) ? value : '' + value;
8081 },
8082
8083 /**
8084 * Formatter for linear numeric ticks
8085 * @method Chart.Ticks.formatters.linear
8086 * @param tickValue {Number} the value to be formatted
8087 * @param index {Number} the position of the tickValue parameter in the ticks array
8088 * @param ticks {Array<Number>} the list of ticks being converted
8089 * @return {String} string representation of the tickValue parameter
8090 */
8091 linear: function(tickValue, index, ticks) {
8092 // If we have lots of ticks, don't use the ones
8093 var delta = ticks.length > 3 ? ticks[2] - ticks[1] : ticks[1] - ticks[0];
8094
8095 // If we have a number like 2.5 as the delta, figure out how many decimal places we need
8096 if (Math.abs(delta) > 1) {
8097 if (tickValue !== Math.floor(tickValue)) {
8098 // not an integer
8099 delta = tickValue - Math.floor(tickValue);
8100 }
8101 }
8102
8103 var logDelta = helpers.log10(Math.abs(delta));
8104 var tickString = '';
8105
8106 if (tickValue !== 0) {
8107 var maxTick = Math.max(Math.abs(ticks[0]), Math.abs(ticks[ticks.length - 1]));
8108 if (maxTick < 1e-4) { // all ticks are small numbers; use scientific notation
8109 var logTick = helpers.log10(Math.abs(tickValue));
8110 tickString = tickValue.toExponential(Math.floor(logTick) - Math.floor(logDelta));
8111 } else {
8112 var numDecimal = -1 * Math.floor(logDelta);
8113 numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
8114 tickString = tickValue.toFixed(numDecimal);
8115 }
8116 } else {
8117 tickString = '0'; // never show decimal places for 0
8118 }
8119
8120 return tickString;
8121 },
8122
8123 logarithmic: function(tickValue, index, ticks) {
8124 var remain = tickValue / (Math.pow(10, Math.floor(helpers.log10(tickValue))));
8125
8126 if (tickValue === 0) {
8127 return '0';
8128 } else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === ticks.length - 1) {
8129 return tickValue.toExponential();
8130 }
8131 return '';
8132 }
8133 }
8134};
8135
8136},{"42":42}],32:[function(require,module,exports){
8137'use strict';
8138
8139var defaults = require(22);
8140var Element = require(23);
8141var helpers = require(42);
8142
8143defaults._set('global', {
8144 tooltips: {
8145 enabled: true,
8146 custom: null,
8147 mode: 'nearest',
8148 position: 'average',
8149 intersect: true,
8150 backgroundColor: 'rgba(0,0,0,0.8)',
8151 titleFontStyle: 'bold',
8152 titleSpacing: 2,
8153 titleMarginBottom: 6,
8154 titleFontColor: '#fff',
8155 titleAlign: 'left',
8156 bodySpacing: 2,
8157 bodyFontColor: '#fff',
8158 bodyAlign: 'left',
8159 footerFontStyle: 'bold',
8160 footerSpacing: 2,
8161 footerMarginTop: 6,
8162 footerFontColor: '#fff',
8163 footerAlign: 'left',
8164 yPadding: 6,
8165 xPadding: 6,
8166 caretPadding: 2,
8167 caretSize: 5,
8168 cornerRadius: 6,
8169 multiKeyBackground: '#fff',
8170 displayColors: true,
8171 borderColor: 'rgba(0,0,0,0)',
8172 borderWidth: 0,
8173 callbacks: {
8174 // Args are: (tooltipItems, data)
8175 beforeTitle: helpers.noop,
8176 title: function(tooltipItems, data) {
8177 // Pick first xLabel for now
8178 var title = '';
8179 var labels = data.labels;
8180 var labelCount = labels ? labels.length : 0;
8181
8182 if (tooltipItems.length > 0) {
8183 var item = tooltipItems[0];
8184
8185 if (item.xLabel) {
8186 title = item.xLabel;
8187 } else if (labelCount > 0 && item.index < labelCount) {
8188 title = labels[item.index];
8189 }
8190 }
8191
8192 return title;
8193 },
8194 afterTitle: helpers.noop,
8195
8196 // Args are: (tooltipItems, data)
8197 beforeBody: helpers.noop,
8198
8199 // Args are: (tooltipItem, data)
8200 beforeLabel: helpers.noop,
8201 label: function(tooltipItem, data) {
8202 var label = data.datasets[tooltipItem.datasetIndex].label || '';
8203
8204 if (label) {
8205 label += ': ';
8206 }
8207 label += tooltipItem.yLabel;
8208 return label;
8209 },
8210 labelColor: function(tooltipItem, chart) {
8211 var meta = chart.getDatasetMeta(tooltipItem.datasetIndex);
8212 var activeElement = meta.data[tooltipItem.index];
8213 var view = activeElement._view;
8214 return {
8215 borderColor: view.borderColor,
8216 backgroundColor: view.backgroundColor
8217 };
8218 },
8219 labelTextColor: function() {
8220 return this._options.bodyFontColor;
8221 },
8222 afterLabel: helpers.noop,
8223
8224 // Args are: (tooltipItems, data)
8225 afterBody: helpers.noop,
8226
8227 // Args are: (tooltipItems, data)
8228 beforeFooter: helpers.noop,
8229 footer: helpers.noop,
8230 afterFooter: helpers.noop
8231 }
8232 }
8233});
8234
8235var positioners = {
8236 /**
8237 * Average mode places the tooltip at the average position of the elements shown
8238 * @function Chart.Tooltip.positioners.average
8239 * @param elements {ChartElement[]} the elements being displayed in the tooltip
8240 * @returns {Point} tooltip position
8241 */
8242 average: function(elements) {
8243 if (!elements.length) {
8244 return false;
8245 }
8246
8247 var i, len;
8248 var x = 0;
8249 var y = 0;
8250 var count = 0;
8251
8252 for (i = 0, len = elements.length; i < len; ++i) {
8253 var el = elements[i];
8254 if (el && el.hasValue()) {
8255 var pos = el.tooltipPosition();
8256 x += pos.x;
8257 y += pos.y;
8258 ++count;
8259 }
8260 }
8261
8262 return {
8263 x: Math.round(x / count),
8264 y: Math.round(y / count)
8265 };
8266 },
8267
8268 /**
8269 * Gets the tooltip position nearest of the item nearest to the event position
8270 * @function Chart.Tooltip.positioners.nearest
8271 * @param elements {Chart.Element[]} the tooltip elements
8272 * @param eventPosition {Point} the position of the event in canvas coordinates
8273 * @returns {Point} the tooltip position
8274 */
8275 nearest: function(elements, eventPosition) {
8276 var x = eventPosition.x;
8277 var y = eventPosition.y;
8278 var minDistance = Number.POSITIVE_INFINITY;
8279 var i, len, nearestElement;
8280
8281 for (i = 0, len = elements.length; i < len; ++i) {
8282 var el = elements[i];
8283 if (el && el.hasValue()) {
8284 var center = el.getCenterPoint();
8285 var d = helpers.distanceBetweenPoints(eventPosition, center);
8286
8287 if (d < minDistance) {
8288 minDistance = d;
8289 nearestElement = el;
8290 }
8291 }
8292 }
8293
8294 if (nearestElement) {
8295 var tp = nearestElement.tooltipPosition();
8296 x = tp.x;
8297 y = tp.y;
8298 }
8299
8300 return {
8301 x: x,
8302 y: y
8303 };
8304 }
8305};
8306
8307// Helper to push or concat based on if the 2nd parameter is an array or not
8308function pushOrConcat(base, toPush) {
8309 if (toPush) {
8310 if (helpers.isArray(toPush)) {
8311 // base = base.concat(toPush);
8312 Array.prototype.push.apply(base, toPush);
8313 } else {
8314 base.push(toPush);
8315 }
8316 }
8317
8318 return base;
8319}
8320
8321/**
8322 * Returns array of strings split by newline
8323 * @param {String} value - The value to split by newline.
8324 * @returns {Array} value if newline present - Returned from String split() method
8325 * @function
8326 */
8327function splitNewlines(str) {
8328 if ((typeof str === 'string' || str instanceof String) && str.indexOf('\n') > -1) {
8329 return str.split('\n');
8330 }
8331 return str;
8332}
8333
8334
8335// Private helper to create a tooltip item model
8336// @param element : the chart element (point, arc, bar) to create the tooltip item for
8337// @return : new tooltip item
8338function createTooltipItem(element) {
8339 var xScale = element._xScale;
8340 var yScale = element._yScale || element._scale; // handle radar || polarArea charts
8341 var index = element._index;
8342 var datasetIndex = element._datasetIndex;
8343
8344 return {
8345 xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '',
8346 yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '',
8347 index: index,
8348 datasetIndex: datasetIndex,
8349 x: element._model.x,
8350 y: element._model.y
8351 };
8352}
8353
8354/**
8355 * Helper to get the reset model for the tooltip
8356 * @param tooltipOpts {Object} the tooltip options
8357 */
8358function getBaseModel(tooltipOpts) {
8359 var globalDefaults = defaults.global;
8360 var valueOrDefault = helpers.valueOrDefault;
8361
8362 return {
8363 // Positioning
8364 xPadding: tooltipOpts.xPadding,
8365 yPadding: tooltipOpts.yPadding,
8366 xAlign: tooltipOpts.xAlign,
8367 yAlign: tooltipOpts.yAlign,
8368
8369 // Body
8370 bodyFontColor: tooltipOpts.bodyFontColor,
8371 _bodyFontFamily: valueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily),
8372 _bodyFontStyle: valueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle),
8373 _bodyAlign: tooltipOpts.bodyAlign,
8374 bodyFontSize: valueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize),
8375 bodySpacing: tooltipOpts.bodySpacing,
8376
8377 // Title
8378 titleFontColor: tooltipOpts.titleFontColor,
8379 _titleFontFamily: valueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily),
8380 _titleFontStyle: valueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle),
8381 titleFontSize: valueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize),
8382 _titleAlign: tooltipOpts.titleAlign,
8383 titleSpacing: tooltipOpts.titleSpacing,
8384 titleMarginBottom: tooltipOpts.titleMarginBottom,
8385
8386 // Footer
8387 footerFontColor: tooltipOpts.footerFontColor,
8388 _footerFontFamily: valueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily),
8389 _footerFontStyle: valueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle),
8390 footerFontSize: valueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize),
8391 _footerAlign: tooltipOpts.footerAlign,
8392 footerSpacing: tooltipOpts.footerSpacing,
8393 footerMarginTop: tooltipOpts.footerMarginTop,
8394
8395 // Appearance
8396 caretSize: tooltipOpts.caretSize,
8397 cornerRadius: tooltipOpts.cornerRadius,
8398 backgroundColor: tooltipOpts.backgroundColor,
8399 opacity: 0,
8400 legendColorBackground: tooltipOpts.multiKeyBackground,
8401 displayColors: tooltipOpts.displayColors,
8402 borderColor: tooltipOpts.borderColor,
8403 borderWidth: tooltipOpts.borderWidth
8404 };
8405}
8406
8407/**
8408 * Get the size of the tooltip
8409 */
8410function getTooltipSize(tooltip, model) {
8411 var ctx = tooltip._chart.ctx;
8412
8413 var height = model.yPadding * 2; // Tooltip Padding
8414 var width = 0;
8415
8416 // Count of all lines in the body
8417 var body = model.body;
8418 var combinedBodyLength = body.reduce(function(count, bodyItem) {
8419 return count + bodyItem.before.length + bodyItem.lines.length + bodyItem.after.length;
8420 }, 0);
8421 combinedBodyLength += model.beforeBody.length + model.afterBody.length;
8422
8423 var titleLineCount = model.title.length;
8424 var footerLineCount = model.footer.length;
8425 var titleFontSize = model.titleFontSize;
8426 var bodyFontSize = model.bodyFontSize;
8427 var footerFontSize = model.footerFontSize;
8428
8429 height += titleLineCount * titleFontSize; // Title Lines
8430 height += titleLineCount ? (titleLineCount - 1) * model.titleSpacing : 0; // Title Line Spacing
8431 height += titleLineCount ? model.titleMarginBottom : 0; // Title's bottom Margin
8432 height += combinedBodyLength * bodyFontSize; // Body Lines
8433 height += combinedBodyLength ? (combinedBodyLength - 1) * model.bodySpacing : 0; // Body Line Spacing
8434 height += footerLineCount ? model.footerMarginTop : 0; // Footer Margin
8435 height += footerLineCount * (footerFontSize); // Footer Lines
8436 height += footerLineCount ? (footerLineCount - 1) * model.footerSpacing : 0; // Footer Line Spacing
8437
8438 // Title width
8439 var widthPadding = 0;
8440 var maxLineWidth = function(line) {
8441 width = Math.max(width, ctx.measureText(line).width + widthPadding);
8442 };
8443
8444 ctx.font = helpers.fontString(titleFontSize, model._titleFontStyle, model._titleFontFamily);
8445 helpers.each(model.title, maxLineWidth);
8446
8447 // Body width
8448 ctx.font = helpers.fontString(bodyFontSize, model._bodyFontStyle, model._bodyFontFamily);
8449 helpers.each(model.beforeBody.concat(model.afterBody), maxLineWidth);
8450
8451 // Body lines may include some extra width due to the color box
8452 widthPadding = model.displayColors ? (bodyFontSize + 2) : 0;
8453 helpers.each(body, function(bodyItem) {
8454 helpers.each(bodyItem.before, maxLineWidth);
8455 helpers.each(bodyItem.lines, maxLineWidth);
8456 helpers.each(bodyItem.after, maxLineWidth);
8457 });
8458
8459 // Reset back to 0
8460 widthPadding = 0;
8461
8462 // Footer width
8463 ctx.font = helpers.fontString(footerFontSize, model._footerFontStyle, model._footerFontFamily);
8464 helpers.each(model.footer, maxLineWidth);
8465
8466 // Add padding
8467 width += 2 * model.xPadding;
8468
8469 return {
8470 width: width,
8471 height: height
8472 };
8473}
8474
8475/**
8476 * Helper to get the alignment of a tooltip given the size
8477 */
8478function determineAlignment(tooltip, size) {
8479 var model = tooltip._model;
8480 var chart = tooltip._chart;
8481 var chartArea = tooltip._chart.chartArea;
8482 var xAlign = 'center';
8483 var yAlign = 'center';
8484
8485 if (model.y < size.height) {
8486 yAlign = 'top';
8487 } else if (model.y > (chart.height - size.height)) {
8488 yAlign = 'bottom';
8489 }
8490
8491 var lf, rf; // functions to determine left, right alignment
8492 var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
8493 var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
8494 var midX = (chartArea.left + chartArea.right) / 2;
8495 var midY = (chartArea.top + chartArea.bottom) / 2;
8496
8497 if (yAlign === 'center') {
8498 lf = function(x) {
8499 return x <= midX;
8500 };
8501 rf = function(x) {
8502 return x > midX;
8503 };
8504 } else {
8505 lf = function(x) {
8506 return x <= (size.width / 2);
8507 };
8508 rf = function(x) {
8509 return x >= (chart.width - (size.width / 2));
8510 };
8511 }
8512
8513 olf = function(x) {
8514 return x + size.width + model.caretSize + model.caretPadding > chart.width;
8515 };
8516 orf = function(x) {
8517 return x - size.width - model.caretSize - model.caretPadding < 0;
8518 };
8519 yf = function(y) {
8520 return y <= midY ? 'top' : 'bottom';
8521 };
8522
8523 if (lf(model.x)) {
8524 xAlign = 'left';
8525
8526 // Is tooltip too wide and goes over the right side of the chart.?
8527 if (olf(model.x)) {
8528 xAlign = 'center';
8529 yAlign = yf(model.y);
8530 }
8531 } else if (rf(model.x)) {
8532 xAlign = 'right';
8533
8534 // Is tooltip too wide and goes outside left edge of canvas?
8535 if (orf(model.x)) {
8536 xAlign = 'center';
8537 yAlign = yf(model.y);
8538 }
8539 }
8540
8541 var opts = tooltip._options;
8542 return {
8543 xAlign: opts.xAlign ? opts.xAlign : xAlign,
8544 yAlign: opts.yAlign ? opts.yAlign : yAlign
8545 };
8546}
8547
8548/**
8549 * Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
8550 */
8551function getBackgroundPoint(vm, size, alignment, chart) {
8552 // Background Position
8553 var x = vm.x;
8554 var y = vm.y;
8555
8556 var caretSize = vm.caretSize;
8557 var caretPadding = vm.caretPadding;
8558 var cornerRadius = vm.cornerRadius;
8559 var xAlign = alignment.xAlign;
8560 var yAlign = alignment.yAlign;
8561 var paddingAndSize = caretSize + caretPadding;
8562 var radiusAndPadding = cornerRadius + caretPadding;
8563
8564 if (xAlign === 'right') {
8565 x -= size.width;
8566 } else if (xAlign === 'center') {
8567 x -= (size.width / 2);
8568 if (x + size.width > chart.width) {
8569 x = chart.width - size.width;
8570 }
8571 if (x < 0) {
8572 x = 0;
8573 }
8574 }
8575
8576 if (yAlign === 'top') {
8577 y += paddingAndSize;
8578 } else if (yAlign === 'bottom') {
8579 y -= size.height + paddingAndSize;
8580 } else {
8581 y -= (size.height / 2);
8582 }
8583
8584 if (yAlign === 'center') {
8585 if (xAlign === 'left') {
8586 x += paddingAndSize;
8587 } else if (xAlign === 'right') {
8588 x -= paddingAndSize;
8589 }
8590 } else if (xAlign === 'left') {
8591 x -= radiusAndPadding;
8592 } else if (xAlign === 'right') {
8593 x += radiusAndPadding;
8594 }
8595
8596 return {
8597 x: x,
8598 y: y
8599 };
8600}
8601
8602/**
8603 * Helper to build before and after body lines
8604 */
8605function getBeforeAfterBodyLines(callback) {
8606 return pushOrConcat([], splitNewlines(callback));
8607}
8608
8609var exports = module.exports = Element.extend({
8610 initialize: function() {
8611 this._model = getBaseModel(this._options);
8612 this._lastActive = [];
8613 },
8614
8615 // Get the title
8616 // Args are: (tooltipItem, data)
8617 getTitle: function() {
8618 var me = this;
8619 var opts = me._options;
8620 var callbacks = opts.callbacks;
8621
8622 var beforeTitle = callbacks.beforeTitle.apply(me, arguments);
8623 var title = callbacks.title.apply(me, arguments);
8624 var afterTitle = callbacks.afterTitle.apply(me, arguments);
8625
8626 var lines = [];
8627 lines = pushOrConcat(lines, splitNewlines(beforeTitle));
8628 lines = pushOrConcat(lines, splitNewlines(title));
8629 lines = pushOrConcat(lines, splitNewlines(afterTitle));
8630
8631 return lines;
8632 },
8633
8634 // Args are: (tooltipItem, data)
8635 getBeforeBody: function() {
8636 return getBeforeAfterBodyLines(this._options.callbacks.beforeBody.apply(this, arguments));
8637 },
8638
8639 // Args are: (tooltipItem, data)
8640 getBody: function(tooltipItems, data) {
8641 var me = this;
8642 var callbacks = me._options.callbacks;
8643 var bodyItems = [];
8644
8645 helpers.each(tooltipItems, function(tooltipItem) {
8646 var bodyItem = {
8647 before: [],
8648 lines: [],
8649 after: []
8650 };
8651 pushOrConcat(bodyItem.before, splitNewlines(callbacks.beforeLabel.call(me, tooltipItem, data)));
8652 pushOrConcat(bodyItem.lines, callbacks.label.call(me, tooltipItem, data));
8653 pushOrConcat(bodyItem.after, splitNewlines(callbacks.afterLabel.call(me, tooltipItem, data)));
8654
8655 bodyItems.push(bodyItem);
8656 });
8657
8658 return bodyItems;
8659 },
8660
8661 // Args are: (tooltipItem, data)
8662 getAfterBody: function() {
8663 return getBeforeAfterBodyLines(this._options.callbacks.afterBody.apply(this, arguments));
8664 },
8665
8666 // Get the footer and beforeFooter and afterFooter lines
8667 // Args are: (tooltipItem, data)
8668 getFooter: function() {
8669 var me = this;
8670 var callbacks = me._options.callbacks;
8671
8672 var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
8673 var footer = callbacks.footer.apply(me, arguments);
8674 var afterFooter = callbacks.afterFooter.apply(me, arguments);
8675
8676 var lines = [];
8677 lines = pushOrConcat(lines, splitNewlines(beforeFooter));
8678 lines = pushOrConcat(lines, splitNewlines(footer));
8679 lines = pushOrConcat(lines, splitNewlines(afterFooter));
8680
8681 return lines;
8682 },
8683
8684 update: function(changed) {
8685 var me = this;
8686 var opts = me._options;
8687
8688 // Need to regenerate the model because its faster than using extend and it is necessary due to the optimization in Chart.Element.transition
8689 // that does _view = _model if ease === 1. This causes the 2nd tooltip update to set properties in both the view and model at the same time
8690 // which breaks any animations.
8691 var existingModel = me._model;
8692 var model = me._model = getBaseModel(opts);
8693 var active = me._active;
8694
8695 var data = me._data;
8696
8697 // In the case where active.length === 0 we need to keep these at existing values for good animations
8698 var alignment = {
8699 xAlign: existingModel.xAlign,
8700 yAlign: existingModel.yAlign
8701 };
8702 var backgroundPoint = {
8703 x: existingModel.x,
8704 y: existingModel.y
8705 };
8706 var tooltipSize = {
8707 width: existingModel.width,
8708 height: existingModel.height
8709 };
8710 var tooltipPosition = {
8711 x: existingModel.caretX,
8712 y: existingModel.caretY
8713 };
8714
8715 var i, len;
8716
8717 if (active.length) {
8718 model.opacity = 1;
8719
8720 var labelColors = [];
8721 var labelTextColors = [];
8722 tooltipPosition = positioners[opts.position].call(me, active, me._eventPosition);
8723
8724 var tooltipItems = [];
8725 for (i = 0, len = active.length; i < len; ++i) {
8726 tooltipItems.push(createTooltipItem(active[i]));
8727 }
8728
8729 // If the user provided a filter function, use it to modify the tooltip items
8730 if (opts.filter) {
8731 tooltipItems = tooltipItems.filter(function(a) {
8732 return opts.filter(a, data);
8733 });
8734 }
8735
8736 // If the user provided a sorting function, use it to modify the tooltip items
8737 if (opts.itemSort) {
8738 tooltipItems = tooltipItems.sort(function(a, b) {
8739 return opts.itemSort(a, b, data);
8740 });
8741 }
8742
8743 // Determine colors for boxes
8744 helpers.each(tooltipItems, function(tooltipItem) {
8745 labelColors.push(opts.callbacks.labelColor.call(me, tooltipItem, me._chart));
8746 labelTextColors.push(opts.callbacks.labelTextColor.call(me, tooltipItem, me._chart));
8747 });
8748
8749
8750 // Build the Text Lines
8751 model.title = me.getTitle(tooltipItems, data);
8752 model.beforeBody = me.getBeforeBody(tooltipItems, data);
8753 model.body = me.getBody(tooltipItems, data);
8754 model.afterBody = me.getAfterBody(tooltipItems, data);
8755 model.footer = me.getFooter(tooltipItems, data);
8756
8757 // Initial positioning and colors
8758 model.x = Math.round(tooltipPosition.x);
8759 model.y = Math.round(tooltipPosition.y);
8760 model.caretPadding = opts.caretPadding;
8761 model.labelColors = labelColors;
8762 model.labelTextColors = labelTextColors;
8763
8764 // data points
8765 model.dataPoints = tooltipItems;
8766
8767 // We need to determine alignment of the tooltip
8768 tooltipSize = getTooltipSize(this, model);
8769 alignment = determineAlignment(this, tooltipSize);
8770 // Final Size and Position
8771 backgroundPoint = getBackgroundPoint(model, tooltipSize, alignment, me._chart);
8772 } else {
8773 model.opacity = 0;
8774 }
8775
8776 model.xAlign = alignment.xAlign;
8777 model.yAlign = alignment.yAlign;
8778 model.x = backgroundPoint.x;
8779 model.y = backgroundPoint.y;
8780 model.width = tooltipSize.width;
8781 model.height = tooltipSize.height;
8782
8783 // Point where the caret on the tooltip points to
8784 model.caretX = tooltipPosition.x;
8785 model.caretY = tooltipPosition.y;
8786
8787 me._model = model;
8788
8789 if (changed && opts.custom) {
8790 opts.custom.call(me, model);
8791 }
8792
8793 return me;
8794 },
8795
8796 drawCaret: function(tooltipPoint, size) {
8797 var ctx = this._chart.ctx;
8798 var vm = this._view;
8799 var caretPosition = this.getCaretPosition(tooltipPoint, size, vm);
8800
8801 ctx.lineTo(caretPosition.x1, caretPosition.y1);
8802 ctx.lineTo(caretPosition.x2, caretPosition.y2);
8803 ctx.lineTo(caretPosition.x3, caretPosition.y3);
8804 },
8805 getCaretPosition: function(tooltipPoint, size, vm) {
8806 var x1, x2, x3, y1, y2, y3;
8807 var caretSize = vm.caretSize;
8808 var cornerRadius = vm.cornerRadius;
8809 var xAlign = vm.xAlign;
8810 var yAlign = vm.yAlign;
8811 var ptX = tooltipPoint.x;
8812 var ptY = tooltipPoint.y;
8813 var width = size.width;
8814 var height = size.height;
8815
8816 if (yAlign === 'center') {
8817 y2 = ptY + (height / 2);
8818
8819 if (xAlign === 'left') {
8820 x1 = ptX;
8821 x2 = x1 - caretSize;
8822 x3 = x1;
8823
8824 y1 = y2 + caretSize;
8825 y3 = y2 - caretSize;
8826 } else {
8827 x1 = ptX + width;
8828 x2 = x1 + caretSize;
8829 x3 = x1;
8830
8831 y1 = y2 - caretSize;
8832 y3 = y2 + caretSize;
8833 }
8834 } else {
8835 if (xAlign === 'left') {
8836 x2 = ptX + cornerRadius + (caretSize);
8837 x1 = x2 - caretSize;
8838 x3 = x2 + caretSize;
8839 } else if (xAlign === 'right') {
8840 x2 = ptX + width - cornerRadius - caretSize;
8841 x1 = x2 - caretSize;
8842 x3 = x2 + caretSize;
8843 } else {
8844 x2 = vm.caretX;
8845 x1 = x2 - caretSize;
8846 x3 = x2 + caretSize;
8847 }
8848 if (yAlign === 'top') {
8849 y1 = ptY;
8850 y2 = y1 - caretSize;
8851 y3 = y1;
8852 } else {
8853 y1 = ptY + height;
8854 y2 = y1 + caretSize;
8855 y3 = y1;
8856 // invert drawing order
8857 var tmp = x3;
8858 x3 = x1;
8859 x1 = tmp;
8860 }
8861 }
8862 return {x1: x1, x2: x2, x3: x3, y1: y1, y2: y2, y3: y3};
8863 },
8864
8865 drawTitle: function(pt, vm, ctx) {
8866 var title = vm.title;
8867
8868 if (title.length) {
8869 ctx.textAlign = vm._titleAlign;
8870 ctx.textBaseline = 'top';
8871
8872 var titleFontSize = vm.titleFontSize;
8873 var titleSpacing = vm.titleSpacing;
8874
8875 ctx.fillStyle = vm.titleFontColor;
8876 ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
8877
8878 var i, len;
8879 for (i = 0, len = title.length; i < len; ++i) {
8880 ctx.fillText(title[i], pt.x, pt.y);
8881 pt.y += titleFontSize + titleSpacing; // Line Height and spacing
8882
8883 if (i + 1 === title.length) {
8884 pt.y += vm.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
8885 }
8886 }
8887 }
8888 },
8889
8890 drawBody: function(pt, vm, ctx) {
8891 var bodyFontSize = vm.bodyFontSize;
8892 var bodySpacing = vm.bodySpacing;
8893 var body = vm.body;
8894
8895 ctx.textAlign = vm._bodyAlign;
8896 ctx.textBaseline = 'top';
8897 ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
8898
8899 // Before Body
8900 var xLinePadding = 0;
8901 var fillLineOfText = function(line) {
8902 ctx.fillText(line, pt.x + xLinePadding, pt.y);
8903 pt.y += bodyFontSize + bodySpacing;
8904 };
8905
8906 // Before body lines
8907 ctx.fillStyle = vm.bodyFontColor;
8908 helpers.each(vm.beforeBody, fillLineOfText);
8909
8910 var drawColorBoxes = vm.displayColors;
8911 xLinePadding = drawColorBoxes ? (bodyFontSize + 2) : 0;
8912
8913 // Draw body lines now
8914 helpers.each(body, function(bodyItem, i) {
8915 var textColor = vm.labelTextColors[i];
8916 ctx.fillStyle = textColor;
8917 helpers.each(bodyItem.before, fillLineOfText);
8918
8919 helpers.each(bodyItem.lines, function(line) {
8920 // Draw Legend-like boxes if needed
8921 if (drawColorBoxes) {
8922 // Fill a white rect so that colours merge nicely if the opacity is < 1
8923 ctx.fillStyle = vm.legendColorBackground;
8924 ctx.fillRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
8925
8926 // Border
8927 ctx.lineWidth = 1;
8928 ctx.strokeStyle = vm.labelColors[i].borderColor;
8929 ctx.strokeRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
8930
8931 // Inner square
8932 ctx.fillStyle = vm.labelColors[i].backgroundColor;
8933 ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
8934 ctx.fillStyle = textColor;
8935 }
8936
8937 fillLineOfText(line);
8938 });
8939
8940 helpers.each(bodyItem.after, fillLineOfText);
8941 });
8942
8943 // Reset back to 0 for after body
8944 xLinePadding = 0;
8945
8946 // After body lines
8947 helpers.each(vm.afterBody, fillLineOfText);
8948 pt.y -= bodySpacing; // Remove last body spacing
8949 },
8950
8951 drawFooter: function(pt, vm, ctx) {
8952 var footer = vm.footer;
8953
8954 if (footer.length) {
8955 pt.y += vm.footerMarginTop;
8956
8957 ctx.textAlign = vm._footerAlign;
8958 ctx.textBaseline = 'top';
8959
8960 ctx.fillStyle = vm.footerFontColor;
8961 ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
8962
8963 helpers.each(footer, function(line) {
8964 ctx.fillText(line, pt.x, pt.y);
8965 pt.y += vm.footerFontSize + vm.footerSpacing;
8966 });
8967 }
8968 },
8969
8970 drawBackground: function(pt, vm, ctx, tooltipSize) {
8971 ctx.fillStyle = vm.backgroundColor;
8972 ctx.strokeStyle = vm.borderColor;
8973 ctx.lineWidth = vm.borderWidth;
8974 var xAlign = vm.xAlign;
8975 var yAlign = vm.yAlign;
8976 var x = pt.x;
8977 var y = pt.y;
8978 var width = tooltipSize.width;
8979 var height = tooltipSize.height;
8980 var radius = vm.cornerRadius;
8981
8982 ctx.beginPath();
8983 ctx.moveTo(x + radius, y);
8984 if (yAlign === 'top') {
8985 this.drawCaret(pt, tooltipSize);
8986 }
8987 ctx.lineTo(x + width - radius, y);
8988 ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
8989 if (yAlign === 'center' && xAlign === 'right') {
8990 this.drawCaret(pt, tooltipSize);
8991 }
8992 ctx.lineTo(x + width, y + height - radius);
8993 ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
8994 if (yAlign === 'bottom') {
8995 this.drawCaret(pt, tooltipSize);
8996 }
8997 ctx.lineTo(x + radius, y + height);
8998 ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
8999 if (yAlign === 'center' && xAlign === 'left') {
9000 this.drawCaret(pt, tooltipSize);
9001 }
9002 ctx.lineTo(x, y + radius);
9003 ctx.quadraticCurveTo(x, y, x + radius, y);
9004 ctx.closePath();
9005
9006 ctx.fill();
9007
9008 if (vm.borderWidth > 0) {
9009 ctx.stroke();
9010 }
9011 },
9012
9013 draw: function() {
9014 var ctx = this._chart.ctx;
9015 var vm = this._view;
9016
9017 if (vm.opacity === 0) {
9018 return;
9019 }
9020
9021 var tooltipSize = {
9022 width: vm.width,
9023 height: vm.height
9024 };
9025 var pt = {
9026 x: vm.x,
9027 y: vm.y
9028 };
9029
9030 // IE11/Edge does not like very small opacities, so snap to 0
9031 var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
9032
9033 // Truthy/falsey value for empty tooltip
9034 var hasTooltipContent = vm.title.length || vm.beforeBody.length || vm.body.length || vm.afterBody.length || vm.footer.length;
9035
9036 if (this._options.enabled && hasTooltipContent) {
9037 ctx.save();
9038 ctx.globalAlpha = opacity;
9039
9040 // Draw Background
9041 this.drawBackground(pt, vm, ctx, tooltipSize);
9042
9043 // Draw Title, Body, and Footer
9044 pt.x += vm.xPadding;
9045 pt.y += vm.yPadding;
9046
9047 // Titles
9048 this.drawTitle(pt, vm, ctx);
9049
9050 // Body
9051 this.drawBody(pt, vm, ctx);
9052
9053 // Footer
9054 this.drawFooter(pt, vm, ctx);
9055
9056 ctx.restore();
9057 }
9058 },
9059
9060 /**
9061 * Handle an event
9062 * @private
9063 * @param {IEvent} event - The event to handle
9064 * @returns {Boolean} true if the tooltip changed
9065 */
9066 handleEvent: function(e) {
9067 var me = this;
9068 var options = me._options;
9069 var changed = false;
9070
9071 me._lastActive = me._lastActive || [];
9072
9073 // Find Active Elements for tooltips
9074 if (e.type === 'mouseout') {
9075 me._active = [];
9076 } else {
9077 me._active = me._chart.getElementsAtEventForMode(e, options.mode, options);
9078 }
9079
9080 // Remember Last Actives
9081 changed = !helpers.arrayEquals(me._active, me._lastActive);
9082
9083 // Only handle target event on tooltip change
9084 if (changed) {
9085 me._lastActive = me._active;
9086
9087 if (options.enabled || options.custom) {
9088 me._eventPosition = {
9089 x: e.x,
9090 y: e.y
9091 };
9092
9093 me.update(true);
9094 me.pivot();
9095 }
9096 }
9097
9098 return changed;
9099 }
9100});
9101
9102/**
9103 * @namespace Chart.Tooltip.positioners
9104 */
9105exports.positioners = positioners;
9106
9107
9108},{"22":22,"23":23,"42":42}],33:[function(require,module,exports){
9109'use strict';
9110
9111var defaults = require(22);
9112var Element = require(23);
9113var helpers = require(42);
9114
9115defaults._set('global', {
9116 elements: {
9117 arc: {
9118 backgroundColor: defaults.global.defaultColor,
9119 borderColor: '#fff',
9120 borderWidth: 2
9121 }
9122 }
9123});
9124
9125module.exports = Element.extend({
9126 inLabelRange: function(mouseX) {
9127 var vm = this._view;
9128
9129 if (vm) {
9130 return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
9131 }
9132 return false;
9133 },
9134
9135 inRange: function(chartX, chartY) {
9136 var vm = this._view;
9137
9138 if (vm) {
9139 var pointRelativePosition = helpers.getAngleFromPoint(vm, {x: chartX, y: chartY});
9140 var angle = pointRelativePosition.angle;
9141 var distance = pointRelativePosition.distance;
9142
9143 // Sanitise angle range
9144 var startAngle = vm.startAngle;
9145 var endAngle = vm.endAngle;
9146 while (endAngle < startAngle) {
9147 endAngle += 2.0 * Math.PI;
9148 }
9149 while (angle > endAngle) {
9150 angle -= 2.0 * Math.PI;
9151 }
9152 while (angle < startAngle) {
9153 angle += 2.0 * Math.PI;
9154 }
9155
9156 // Check if within the range of the open/close angle
9157 var betweenAngles = (angle >= startAngle && angle <= endAngle);
9158 var withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
9159
9160 return (betweenAngles && withinRadius);
9161 }
9162 return false;
9163 },
9164
9165 getCenterPoint: function() {
9166 var vm = this._view;
9167 var halfAngle = (vm.startAngle + vm.endAngle) / 2;
9168 var halfRadius = (vm.innerRadius + vm.outerRadius) / 2;
9169 return {
9170 x: vm.x + Math.cos(halfAngle) * halfRadius,
9171 y: vm.y + Math.sin(halfAngle) * halfRadius
9172 };
9173 },
9174
9175 getArea: function() {
9176 var vm = this._view;
9177 return Math.PI * ((vm.endAngle - vm.startAngle) / (2 * Math.PI)) * (Math.pow(vm.outerRadius, 2) - Math.pow(vm.innerRadius, 2));
9178 },
9179
9180 tooltipPosition: function() {
9181 var vm = this._view;
9182 var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2);
9183 var rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
9184
9185 return {
9186 x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
9187 y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
9188 };
9189 },
9190
9191 draw: function() {
9192 var ctx = this._chart.ctx;
9193 var vm = this._view;
9194 var sA = vm.startAngle;
9195 var eA = vm.endAngle;
9196
9197 ctx.beginPath();
9198
9199 ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
9200 ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
9201
9202 ctx.closePath();
9203 ctx.strokeStyle = vm.borderColor;
9204 ctx.lineWidth = vm.borderWidth;
9205
9206 ctx.fillStyle = vm.backgroundColor;
9207
9208 ctx.fill();
9209 ctx.lineJoin = 'bevel';
9210
9211 if (vm.borderWidth) {
9212 ctx.stroke();
9213 }
9214 }
9215});
9216
9217},{"22":22,"23":23,"42":42}],34:[function(require,module,exports){
9218'use strict';
9219
9220var defaults = require(22);
9221var Element = require(23);
9222var helpers = require(42);
9223
9224var globalDefaults = defaults.global;
9225
9226defaults._set('global', {
9227 elements: {
9228 line: {
9229 tension: 0.4,
9230 backgroundColor: globalDefaults.defaultColor,
9231 borderWidth: 3,
9232 borderColor: globalDefaults.defaultColor,
9233 borderCapStyle: 'butt',
9234 borderDash: [],
9235 borderDashOffset: 0.0,
9236 borderJoinStyle: 'miter',
9237 capBezierPoints: true,
9238 fill: true, // do we fill in the area between the line and its base axis
9239 }
9240 }
9241});
9242
9243module.exports = Element.extend({
9244 draw: function() {
9245 var me = this;
9246 var vm = me._view;
9247 var ctx = me._chart.ctx;
9248 var spanGaps = vm.spanGaps;
9249 var points = me._children.slice(); // clone array
9250 var globalOptionLineElements = globalDefaults.elements.line;
9251 var lastDrawnIndex = -1;
9252 var index, current, previous, currentVM;
9253
9254 // If we are looping, adding the first point again
9255 if (me._loop && points.length) {
9256 points.push(points[0]);
9257 }
9258
9259 ctx.save();
9260
9261 // Stroke Line Options
9262 ctx.lineCap = vm.borderCapStyle || globalOptionLineElements.borderCapStyle;
9263
9264 // IE 9 and 10 do not support line dash
9265 if (ctx.setLineDash) {
9266 ctx.setLineDash(vm.borderDash || globalOptionLineElements.borderDash);
9267 }
9268
9269 ctx.lineDashOffset = vm.borderDashOffset || globalOptionLineElements.borderDashOffset;
9270 ctx.lineJoin = vm.borderJoinStyle || globalOptionLineElements.borderJoinStyle;
9271 ctx.lineWidth = vm.borderWidth || globalOptionLineElements.borderWidth;
9272 ctx.strokeStyle = vm.borderColor || globalDefaults.defaultColor;
9273
9274 // Stroke Line
9275 ctx.beginPath();
9276 lastDrawnIndex = -1;
9277
9278 for (index = 0; index < points.length; ++index) {
9279 current = points[index];
9280 previous = helpers.previousItem(points, index);
9281 currentVM = current._view;
9282
9283 // First point moves to it's starting position no matter what
9284 if (index === 0) {
9285 if (!currentVM.skip) {
9286 ctx.moveTo(currentVM.x, currentVM.y);
9287 lastDrawnIndex = index;
9288 }
9289 } else {
9290 previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
9291
9292 if (!currentVM.skip) {
9293 if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
9294 // There was a gap and this is the first point after the gap
9295 ctx.moveTo(currentVM.x, currentVM.y);
9296 } else {
9297 // Line to next point
9298 helpers.canvas.lineTo(ctx, previous._view, current._view);
9299 }
9300 lastDrawnIndex = index;
9301 }
9302 }
9303 }
9304
9305 ctx.stroke();
9306 ctx.restore();
9307 }
9308});
9309
9310},{"22":22,"23":23,"42":42}],35:[function(require,module,exports){
9311'use strict';
9312
9313var defaults = require(22);
9314var Element = require(23);
9315var helpers = require(42);
9316
9317var defaultColor = defaults.global.defaultColor;
9318
9319defaults._set('global', {
9320 elements: {
9321 point: {
9322 radius: 3,
9323 pointStyle: 'circle',
9324 backgroundColor: defaultColor,
9325 borderColor: defaultColor,
9326 borderWidth: 1,
9327 // Hover
9328 hitRadius: 1,
9329 hoverRadius: 4,
9330 hoverBorderWidth: 1
9331 }
9332 }
9333});
9334
9335function xRange(mouseX) {
9336 var vm = this._view;
9337 return vm ? (Math.abs(mouseX - vm.x) < vm.radius + vm.hitRadius) : false;
9338}
9339
9340function yRange(mouseY) {
9341 var vm = this._view;
9342 return vm ? (Math.abs(mouseY - vm.y) < vm.radius + vm.hitRadius) : false;
9343}
9344
9345module.exports = Element.extend({
9346 inRange: function(mouseX, mouseY) {
9347 var vm = this._view;
9348 return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
9349 },
9350
9351 inLabelRange: xRange,
9352 inXRange: xRange,
9353 inYRange: yRange,
9354
9355 getCenterPoint: function() {
9356 var vm = this._view;
9357 return {
9358 x: vm.x,
9359 y: vm.y
9360 };
9361 },
9362
9363 getArea: function() {
9364 return Math.PI * Math.pow(this._view.radius, 2);
9365 },
9366
9367 tooltipPosition: function() {
9368 var vm = this._view;
9369 return {
9370 x: vm.x,
9371 y: vm.y,
9372 padding: vm.radius + vm.borderWidth
9373 };
9374 },
9375
9376 draw: function(chartArea) {
9377 var vm = this._view;
9378 var model = this._model;
9379 var ctx = this._chart.ctx;
9380 var pointStyle = vm.pointStyle;
9381 var rotation = vm.rotation;
9382 var radius = vm.radius;
9383 var x = vm.x;
9384 var y = vm.y;
9385 var epsilon = 0.0000001; // 0.0000001 is margin in pixels for Accumulated error.
9386
9387 if (vm.skip) {
9388 return;
9389 }
9390
9391 // Clipping for Points.
9392 if (chartArea === undefined || (model.x > chartArea.left - epsilon && chartArea.right + epsilon > model.x && model.y > chartArea.top - epsilon && chartArea.bottom + epsilon > model.y)) {
9393 ctx.strokeStyle = vm.borderColor || defaultColor;
9394 ctx.lineWidth = helpers.valueOrDefault(vm.borderWidth, defaults.global.elements.point.borderWidth);
9395 ctx.fillStyle = vm.backgroundColor || defaultColor;
9396 helpers.canvas.drawPoint(ctx, pointStyle, radius, x, y, rotation);
9397 }
9398 }
9399});
9400
9401},{"22":22,"23":23,"42":42}],36:[function(require,module,exports){
9402'use strict';
9403
9404var defaults = require(22);
9405var Element = require(23);
9406
9407defaults._set('global', {
9408 elements: {
9409 rectangle: {
9410 backgroundColor: defaults.global.defaultColor,
9411 borderColor: defaults.global.defaultColor,
9412 borderSkipped: 'bottom',
9413 borderWidth: 0
9414 }
9415 }
9416});
9417
9418function isVertical(bar) {
9419 return bar._view.width !== undefined;
9420}
9421
9422/**
9423 * Helper function to get the bounds of the bar regardless of the orientation
9424 * @param bar {Chart.Element.Rectangle} the bar
9425 * @return {Bounds} bounds of the bar
9426 * @private
9427 */
9428function getBarBounds(bar) {
9429 var vm = bar._view;
9430 var x1, x2, y1, y2;
9431
9432 if (isVertical(bar)) {
9433 // vertical
9434 var halfWidth = vm.width / 2;
9435 x1 = vm.x - halfWidth;
9436 x2 = vm.x + halfWidth;
9437 y1 = Math.min(vm.y, vm.base);
9438 y2 = Math.max(vm.y, vm.base);
9439 } else {
9440 // horizontal bar
9441 var halfHeight = vm.height / 2;
9442 x1 = Math.min(vm.x, vm.base);
9443 x2 = Math.max(vm.x, vm.base);
9444 y1 = vm.y - halfHeight;
9445 y2 = vm.y + halfHeight;
9446 }
9447
9448 return {
9449 left: x1,
9450 top: y1,
9451 right: x2,
9452 bottom: y2
9453 };
9454}
9455
9456module.exports = Element.extend({
9457 draw: function() {
9458 var ctx = this._chart.ctx;
9459 var vm = this._view;
9460 var left, right, top, bottom, signX, signY, borderSkipped;
9461 var borderWidth = vm.borderWidth;
9462
9463 if (!vm.horizontal) {
9464 // bar
9465 left = vm.x - vm.width / 2;
9466 right = vm.x + vm.width / 2;
9467 top = vm.y;
9468 bottom = vm.base;
9469 signX = 1;
9470 signY = bottom > top ? 1 : -1;
9471 borderSkipped = vm.borderSkipped || 'bottom';
9472 } else {
9473 // horizontal bar
9474 left = vm.base;
9475 right = vm.x;
9476 top = vm.y - vm.height / 2;
9477 bottom = vm.y + vm.height / 2;
9478 signX = right > left ? 1 : -1;
9479 signY = 1;
9480 borderSkipped = vm.borderSkipped || 'left';
9481 }
9482
9483 // Canvas doesn't allow us to stroke inside the width so we can
9484 // adjust the sizes to fit if we're setting a stroke on the line
9485 if (borderWidth) {
9486 // borderWidth shold be less than bar width and bar height.
9487 var barSize = Math.min(Math.abs(left - right), Math.abs(top - bottom));
9488 borderWidth = borderWidth > barSize ? barSize : borderWidth;
9489 var halfStroke = borderWidth / 2;
9490 // Adjust borderWidth when bar top position is near vm.base(zero).
9491 var borderLeft = left + (borderSkipped !== 'left' ? halfStroke * signX : 0);
9492 var borderRight = right + (borderSkipped !== 'right' ? -halfStroke * signX : 0);
9493 var borderTop = top + (borderSkipped !== 'top' ? halfStroke * signY : 0);
9494 var borderBottom = bottom + (borderSkipped !== 'bottom' ? -halfStroke * signY : 0);
9495 // not become a vertical line?
9496 if (borderLeft !== borderRight) {
9497 top = borderTop;
9498 bottom = borderBottom;
9499 }
9500 // not become a horizontal line?
9501 if (borderTop !== borderBottom) {
9502 left = borderLeft;
9503 right = borderRight;
9504 }
9505 }
9506
9507 ctx.beginPath();
9508 ctx.fillStyle = vm.backgroundColor;
9509 ctx.strokeStyle = vm.borderColor;
9510 ctx.lineWidth = borderWidth;
9511
9512 // Corner points, from bottom-left to bottom-right clockwise
9513 // | 1 2 |
9514 // | 0 3 |
9515 var corners = [
9516 [left, bottom],
9517 [left, top],
9518 [right, top],
9519 [right, bottom]
9520 ];
9521
9522 // Find first (starting) corner with fallback to 'bottom'
9523 var borders = ['bottom', 'left', 'top', 'right'];
9524 var startCorner = borders.indexOf(borderSkipped, 0);
9525 if (startCorner === -1) {
9526 startCorner = 0;
9527 }
9528
9529 function cornerAt(index) {
9530 return corners[(startCorner + index) % 4];
9531 }
9532
9533 // Draw rectangle from 'startCorner'
9534 var corner = cornerAt(0);
9535 ctx.moveTo(corner[0], corner[1]);
9536
9537 for (var i = 1; i < 4; i++) {
9538 corner = cornerAt(i);
9539 ctx.lineTo(corner[0], corner[1]);
9540 }
9541
9542 ctx.fill();
9543 if (borderWidth) {
9544 ctx.stroke();
9545 }
9546 },
9547
9548 height: function() {
9549 var vm = this._view;
9550 return vm.base - vm.y;
9551 },
9552
9553 inRange: function(mouseX, mouseY) {
9554 var inRange = false;
9555
9556 if (this._view) {
9557 var bounds = getBarBounds(this);
9558 inRange = mouseX >= bounds.left && mouseX <= bounds.right && mouseY >= bounds.top && mouseY <= bounds.bottom;
9559 }
9560
9561 return inRange;
9562 },
9563
9564 inLabelRange: function(mouseX, mouseY) {
9565 var me = this;
9566 if (!me._view) {
9567 return false;
9568 }
9569
9570 var inRange = false;
9571 var bounds = getBarBounds(me);
9572
9573 if (isVertical(me)) {
9574 inRange = mouseX >= bounds.left && mouseX <= bounds.right;
9575 } else {
9576 inRange = mouseY >= bounds.top && mouseY <= bounds.bottom;
9577 }
9578
9579 return inRange;
9580 },
9581
9582 inXRange: function(mouseX) {
9583 var bounds = getBarBounds(this);
9584 return mouseX >= bounds.left && mouseX <= bounds.right;
9585 },
9586
9587 inYRange: function(mouseY) {
9588 var bounds = getBarBounds(this);
9589 return mouseY >= bounds.top && mouseY <= bounds.bottom;
9590 },
9591
9592 getCenterPoint: function() {
9593 var vm = this._view;
9594 var x, y;
9595 if (isVertical(this)) {
9596 x = vm.x;
9597 y = (vm.y + vm.base) / 2;
9598 } else {
9599 x = (vm.x + vm.base) / 2;
9600 y = vm.y;
9601 }
9602
9603 return {x: x, y: y};
9604 },
9605
9606 getArea: function() {
9607 var vm = this._view;
9608 return vm.width * Math.abs(vm.y - vm.base);
9609 },
9610
9611 tooltipPosition: function() {
9612 var vm = this._view;
9613 return {
9614 x: vm.x,
9615 y: vm.y
9616 };
9617 }
9618});
9619
9620},{"22":22,"23":23}],37:[function(require,module,exports){
9621'use strict';
9622
9623module.exports = {};
9624module.exports.Arc = require(33);
9625module.exports.Line = require(34);
9626module.exports.Point = require(35);
9627module.exports.Rectangle = require(36);
9628
9629},{"33":33,"34":34,"35":35,"36":36}],38:[function(require,module,exports){
9630'use strict';
9631
9632var helpers = require(39);
9633
9634var PI = Math.PI;
9635var RAD_PER_DEG = PI / 180;
9636var DOUBLE_PI = PI * 2;
9637var HALF_PI = PI / 2;
9638var QUARTER_PI = PI / 4;
9639var TWO_THIRDS_PI = PI * 2 / 3;
9640
9641/**
9642 * @namespace Chart.helpers.canvas
9643 */
9644var exports = module.exports = {
9645 /**
9646 * Clears the entire canvas associated to the given `chart`.
9647 * @param {Chart} chart - The chart for which to clear the canvas.
9648 */
9649 clear: function(chart) {
9650 chart.ctx.clearRect(0, 0, chart.width, chart.height);
9651 },
9652
9653 /**
9654 * Creates a "path" for a rectangle with rounded corners at position (x, y) with a
9655 * given size (width, height) and the same `radius` for all corners.
9656 * @param {CanvasRenderingContext2D} ctx - The canvas 2D Context.
9657 * @param {Number} x - The x axis of the coordinate for the rectangle starting point.
9658 * @param {Number} y - The y axis of the coordinate for the rectangle starting point.
9659 * @param {Number} width - The rectangle's width.
9660 * @param {Number} height - The rectangle's height.
9661 * @param {Number} radius - The rounded amount (in pixels) for the four corners.
9662 * @todo handle `radius` as top-left, top-right, bottom-right, bottom-left array/object?
9663 */
9664 roundedRect: function(ctx, x, y, width, height, radius) {
9665 if (radius) {
9666 var r = Math.min(radius, height / 2, width / 2);
9667 var left = x + r;
9668 var top = y + r;
9669 var right = x + width - r;
9670 var bottom = y + height - r;
9671
9672 ctx.moveTo(x, top);
9673 if (left < right && top < bottom) {
9674 ctx.arc(left, top, r, -PI, -HALF_PI);
9675 ctx.arc(right, top, r, -HALF_PI, 0);
9676 ctx.arc(right, bottom, r, 0, HALF_PI);
9677 ctx.arc(left, bottom, r, HALF_PI, PI);
9678 } else if (left < right) {
9679 ctx.moveTo(left, y);
9680 ctx.arc(right, top, r, -HALF_PI, HALF_PI);
9681 ctx.arc(left, top, r, HALF_PI, PI + HALF_PI);
9682 } else if (top < bottom) {
9683 ctx.arc(left, top, r, -PI, 0);
9684 ctx.arc(left, bottom, r, 0, PI);
9685 } else {
9686 ctx.arc(left, top, r, -PI, PI);
9687 }
9688 ctx.closePath();
9689 ctx.moveTo(x, y);
9690 } else {
9691 ctx.rect(x, y, width, height);
9692 }
9693 },
9694
9695 drawPoint: function(ctx, style, radius, x, y, rotation) {
9696 var type, xOffset, yOffset, size, cornerRadius;
9697 var rad = (rotation || 0) * RAD_PER_DEG;
9698
9699 if (style && typeof style === 'object') {
9700 type = style.toString();
9701 if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
9702 ctx.drawImage(style, x - style.width / 2, y - style.height / 2, style.width, style.height);
9703 return;
9704 }
9705 }
9706
9707 if (isNaN(radius) || radius <= 0) {
9708 return;
9709 }
9710
9711 ctx.beginPath();
9712
9713 switch (style) {
9714 // Default includes circle
9715 default:
9716 ctx.arc(x, y, radius, 0, DOUBLE_PI);
9717 ctx.closePath();
9718 break;
9719 case 'triangle':
9720 ctx.moveTo(x + Math.sin(rad) * radius, y - Math.cos(rad) * radius);
9721 rad += TWO_THIRDS_PI;
9722 ctx.lineTo(x + Math.sin(rad) * radius, y - Math.cos(rad) * radius);
9723 rad += TWO_THIRDS_PI;
9724 ctx.lineTo(x + Math.sin(rad) * radius, y - Math.cos(rad) * radius);
9725 ctx.closePath();
9726 break;
9727 case 'rectRounded':
9728 // NOTE: the rounded rect implementation changed to use `arc` instead of
9729 // `quadraticCurveTo` since it generates better results when rect is
9730 // almost a circle. 0.516 (instead of 0.5) produces results with visually
9731 // closer proportion to the previous impl and it is inscribed in the
9732 // circle with `radius`. For more details, see the following PRs:
9733 // https://github.com/chartjs/Chart.js/issues/5597
9734 // https://github.com/chartjs/Chart.js/issues/5858
9735 cornerRadius = radius * 0.516;
9736 size = radius - cornerRadius;
9737 xOffset = Math.cos(rad + QUARTER_PI) * size;
9738 yOffset = Math.sin(rad + QUARTER_PI) * size;
9739 ctx.arc(x - xOffset, y - yOffset, cornerRadius, rad - PI, rad - HALF_PI);
9740 ctx.arc(x + yOffset, y - xOffset, cornerRadius, rad - HALF_PI, rad);
9741 ctx.arc(x + xOffset, y + yOffset, cornerRadius, rad, rad + HALF_PI);
9742 ctx.arc(x - yOffset, y + xOffset, cornerRadius, rad + HALF_PI, rad + PI);
9743 ctx.closePath();
9744 break;
9745 case 'rect':
9746 if (!rotation) {
9747 size = Math.SQRT1_2 * radius;
9748 ctx.rect(x - size, y - size, 2 * size, 2 * size);
9749 break;
9750 }
9751 rad += QUARTER_PI;
9752 /* falls through */
9753 case 'rectRot':
9754 xOffset = Math.cos(rad) * radius;
9755 yOffset = Math.sin(rad) * radius;
9756 ctx.moveTo(x - xOffset, y - yOffset);
9757 ctx.lineTo(x + yOffset, y - xOffset);
9758 ctx.lineTo(x + xOffset, y + yOffset);
9759 ctx.lineTo(x - yOffset, y + xOffset);
9760 ctx.closePath();
9761 break;
9762 case 'crossRot':
9763 rad += QUARTER_PI;
9764 /* falls through */
9765 case 'cross':
9766 xOffset = Math.cos(rad) * radius;
9767 yOffset = Math.sin(rad) * radius;
9768 ctx.moveTo(x - xOffset, y - yOffset);
9769 ctx.lineTo(x + xOffset, y + yOffset);
9770 ctx.moveTo(x + yOffset, y - xOffset);
9771 ctx.lineTo(x - yOffset, y + xOffset);
9772 break;
9773 case 'star':
9774 xOffset = Math.cos(rad) * radius;
9775 yOffset = Math.sin(rad) * radius;
9776 ctx.moveTo(x - xOffset, y - yOffset);
9777 ctx.lineTo(x + xOffset, y + yOffset);
9778 ctx.moveTo(x + yOffset, y - xOffset);
9779 ctx.lineTo(x - yOffset, y + xOffset);
9780 rad += QUARTER_PI;
9781 xOffset = Math.cos(rad) * radius;
9782 yOffset = Math.sin(rad) * radius;
9783 ctx.moveTo(x - xOffset, y - yOffset);
9784 ctx.lineTo(x + xOffset, y + yOffset);
9785 ctx.moveTo(x + yOffset, y - xOffset);
9786 ctx.lineTo(x - yOffset, y + xOffset);
9787 break;
9788 case 'line':
9789 xOffset = Math.cos(rad) * radius;
9790 yOffset = Math.sin(rad) * radius;
9791 ctx.moveTo(x - xOffset, y - yOffset);
9792 ctx.lineTo(x + xOffset, y + yOffset);
9793 break;
9794 case 'dash':
9795 ctx.moveTo(x, y);
9796 ctx.lineTo(x + Math.cos(rad) * radius, y + Math.sin(rad) * radius);
9797 break;
9798 }
9799
9800 ctx.fill();
9801 ctx.stroke();
9802 },
9803
9804 clipArea: function(ctx, area) {
9805 ctx.save();
9806 ctx.beginPath();
9807 ctx.rect(area.left, area.top, area.right - area.left, area.bottom - area.top);
9808 ctx.clip();
9809 },
9810
9811 unclipArea: function(ctx) {
9812 ctx.restore();
9813 },
9814
9815 lineTo: function(ctx, previous, target, flip) {
9816 if (target.steppedLine) {
9817 if ((target.steppedLine === 'after' && !flip) || (target.steppedLine !== 'after' && flip)) {
9818 ctx.lineTo(previous.x, target.y);
9819 } else {
9820 ctx.lineTo(target.x, previous.y);
9821 }
9822 ctx.lineTo(target.x, target.y);
9823 return;
9824 }
9825
9826 if (!target.tension) {
9827 ctx.lineTo(target.x, target.y);
9828 return;
9829 }
9830
9831 ctx.bezierCurveTo(
9832 flip ? previous.controlPointPreviousX : previous.controlPointNextX,
9833 flip ? previous.controlPointPreviousY : previous.controlPointNextY,
9834 flip ? target.controlPointNextX : target.controlPointPreviousX,
9835 flip ? target.controlPointNextY : target.controlPointPreviousY,
9836 target.x,
9837 target.y);
9838 }
9839};
9840
9841// DEPRECATIONS
9842
9843/**
9844 * Provided for backward compatibility, use Chart.helpers.canvas.clear instead.
9845 * @namespace Chart.helpers.clear
9846 * @deprecated since version 2.7.0
9847 * @todo remove at version 3
9848 * @private
9849 */
9850helpers.clear = exports.clear;
9851
9852/**
9853 * Provided for backward compatibility, use Chart.helpers.canvas.roundedRect instead.
9854 * @namespace Chart.helpers.drawRoundedRectangle
9855 * @deprecated since version 2.7.0
9856 * @todo remove at version 3
9857 * @private
9858 */
9859helpers.drawRoundedRectangle = function(ctx) {
9860 ctx.beginPath();
9861 exports.roundedRect.apply(exports, arguments);
9862};
9863
9864},{"39":39}],39:[function(require,module,exports){
9865'use strict';
9866
9867/**
9868 * @namespace Chart.helpers
9869 */
9870var helpers = {
9871 /**
9872 * An empty function that can be used, for example, for optional callback.
9873 */
9874 noop: function() {},
9875
9876 /**
9877 * Returns a unique id, sequentially generated from a global variable.
9878 * @returns {Number}
9879 * @function
9880 */
9881 uid: (function() {
9882 var id = 0;
9883 return function() {
9884 return id++;
9885 };
9886 }()),
9887
9888 /**
9889 * Returns true if `value` is neither null nor undefined, else returns false.
9890 * @param {*} value - The value to test.
9891 * @returns {Boolean}
9892 * @since 2.7.0
9893 */
9894 isNullOrUndef: function(value) {
9895 return value === null || typeof value === 'undefined';
9896 },
9897
9898 /**
9899 * Returns true if `value` is an array, else returns false.
9900 * @param {*} value - The value to test.
9901 * @returns {Boolean}
9902 * @function
9903 */
9904 isArray: Array.isArray ? Array.isArray : function(value) {
9905 return Object.prototype.toString.call(value) === '[object Array]';
9906 },
9907
9908 /**
9909 * Returns true if `value` is an object (excluding null), else returns false.
9910 * @param {*} value - The value to test.
9911 * @returns {Boolean}
9912 * @since 2.7.0
9913 */
9914 isObject: function(value) {
9915 return value !== null && Object.prototype.toString.call(value) === '[object Object]';
9916 },
9917
9918 /**
9919 * Returns true if `value` is a finite number, else returns false
9920 * @param {*} value - The value to test.
9921 * @returns {Boolean}
9922 */
9923 isFinite: function(value) {
9924 return (typeof value === 'number' || value instanceof Number) && isFinite(value);
9925 },
9926
9927 /**
9928 * Returns `value` if defined, else returns `defaultValue`.
9929 * @param {*} value - The value to return if defined.
9930 * @param {*} defaultValue - The value to return if `value` is undefined.
9931 * @returns {*}
9932 */
9933 valueOrDefault: function(value, defaultValue) {
9934 return typeof value === 'undefined' ? defaultValue : value;
9935 },
9936
9937 /**
9938 * Returns value at the given `index` in array if defined, else returns `defaultValue`.
9939 * @param {Array} value - The array to lookup for value at `index`.
9940 * @param {Number} index - The index in `value` to lookup for value.
9941 * @param {*} defaultValue - The value to return if `value[index]` is undefined.
9942 * @returns {*}
9943 */
9944 valueAtIndexOrDefault: function(value, index, defaultValue) {
9945 return helpers.valueOrDefault(helpers.isArray(value) ? value[index] : value, defaultValue);
9946 },
9947
9948 /**
9949 * Calls `fn` with the given `args` in the scope defined by `thisArg` and returns the
9950 * value returned by `fn`. If `fn` is not a function, this method returns undefined.
9951 * @param {Function} fn - The function to call.
9952 * @param {Array|undefined|null} args - The arguments with which `fn` should be called.
9953 * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
9954 * @returns {*}
9955 */
9956 callback: function(fn, args, thisArg) {
9957 if (fn && typeof fn.call === 'function') {
9958 return fn.apply(thisArg, args);
9959 }
9960 },
9961
9962 /**
9963 * Note(SB) for performance sake, this method should only be used when loopable type
9964 * is unknown or in none intensive code (not called often and small loopable). Else
9965 * it's preferable to use a regular for() loop and save extra function calls.
9966 * @param {Object|Array} loopable - The object or array to be iterated.
9967 * @param {Function} fn - The function to call for each item.
9968 * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
9969 * @param {Boolean} [reverse] - If true, iterates backward on the loopable.
9970 */
9971 each: function(loopable, fn, thisArg, reverse) {
9972 var i, len, keys;
9973 if (helpers.isArray(loopable)) {
9974 len = loopable.length;
9975 if (reverse) {
9976 for (i = len - 1; i >= 0; i--) {
9977 fn.call(thisArg, loopable[i], i);
9978 }
9979 } else {
9980 for (i = 0; i < len; i++) {
9981 fn.call(thisArg, loopable[i], i);
9982 }
9983 }
9984 } else if (helpers.isObject(loopable)) {
9985 keys = Object.keys(loopable);
9986 len = keys.length;
9987 for (i = 0; i < len; i++) {
9988 fn.call(thisArg, loopable[keys[i]], keys[i]);
9989 }
9990 }
9991 },
9992
9993 /**
9994 * Returns true if the `a0` and `a1` arrays have the same content, else returns false.
9995 * @see http://stackoverflow.com/a/14853974
9996 * @param {Array} a0 - The array to compare
9997 * @param {Array} a1 - The array to compare
9998 * @returns {Boolean}
9999 */
10000 arrayEquals: function(a0, a1) {
10001 var i, ilen, v0, v1;
10002
10003 if (!a0 || !a1 || a0.length !== a1.length) {
10004 return false;
10005 }
10006
10007 for (i = 0, ilen = a0.length; i < ilen; ++i) {
10008 v0 = a0[i];
10009 v1 = a1[i];
10010
10011 if (v0 instanceof Array && v1 instanceof Array) {
10012 if (!helpers.arrayEquals(v0, v1)) {
10013 return false;
10014 }
10015 } else if (v0 !== v1) {
10016 // NOTE: two different object instances will never be equal: {x:20} != {x:20}
10017 return false;
10018 }
10019 }
10020
10021 return true;
10022 },
10023
10024 /**
10025 * Returns a deep copy of `source` without keeping references on objects and arrays.
10026 * @param {*} source - The value to clone.
10027 * @returns {*}
10028 */
10029 clone: function(source) {
10030 if (helpers.isArray(source)) {
10031 return source.map(helpers.clone);
10032 }
10033
10034 if (helpers.isObject(source)) {
10035 var target = {};
10036 var keys = Object.keys(source);
10037 var klen = keys.length;
10038 var k = 0;
10039
10040 for (; k < klen; ++k) {
10041 target[keys[k]] = helpers.clone(source[keys[k]]);
10042 }
10043
10044 return target;
10045 }
10046
10047 return source;
10048 },
10049
10050 /**
10051 * The default merger when Chart.helpers.merge is called without merger option.
10052 * Note(SB): this method is also used by configMerge and scaleMerge as fallback.
10053 * @private
10054 */
10055 _merger: function(key, target, source, options) {
10056 var tval = target[key];
10057 var sval = source[key];
10058
10059 if (helpers.isObject(tval) && helpers.isObject(sval)) {
10060 helpers.merge(tval, sval, options);
10061 } else {
10062 target[key] = helpers.clone(sval);
10063 }
10064 },
10065
10066 /**
10067 * Merges source[key] in target[key] only if target[key] is undefined.
10068 * @private
10069 */
10070 _mergerIf: function(key, target, source) {
10071 var tval = target[key];
10072 var sval = source[key];
10073
10074 if (helpers.isObject(tval) && helpers.isObject(sval)) {
10075 helpers.mergeIf(tval, sval);
10076 } else if (!target.hasOwnProperty(key)) {
10077 target[key] = helpers.clone(sval);
10078 }
10079 },
10080
10081 /**
10082 * Recursively deep copies `source` properties into `target` with the given `options`.
10083 * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
10084 * @param {Object} target - The target object in which all sources are merged into.
10085 * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
10086 * @param {Object} [options] - Merging options:
10087 * @param {Function} [options.merger] - The merge method (key, target, source, options)
10088 * @returns {Object} The `target` object.
10089 */
10090 merge: function(target, source, options) {
10091 var sources = helpers.isArray(source) ? source : [source];
10092 var ilen = sources.length;
10093 var merge, i, keys, klen, k;
10094
10095 if (!helpers.isObject(target)) {
10096 return target;
10097 }
10098
10099 options = options || {};
10100 merge = options.merger || helpers._merger;
10101
10102 for (i = 0; i < ilen; ++i) {
10103 source = sources[i];
10104 if (!helpers.isObject(source)) {
10105 continue;
10106 }
10107
10108 keys = Object.keys(source);
10109 for (k = 0, klen = keys.length; k < klen; ++k) {
10110 merge(keys[k], target, source, options);
10111 }
10112 }
10113
10114 return target;
10115 },
10116
10117 /**
10118 * Recursively deep copies `source` properties into `target` *only* if not defined in target.
10119 * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
10120 * @param {Object} target - The target object in which all sources are merged into.
10121 * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
10122 * @returns {Object} The `target` object.
10123 */
10124 mergeIf: function(target, source) {
10125 return helpers.merge(target, source, {merger: helpers._mergerIf});
10126 },
10127
10128 /**
10129 * Applies the contents of two or more objects together into the first object.
10130 * @param {Object} target - The target object in which all objects are merged into.
10131 * @param {Object} arg1 - Object containing additional properties to merge in target.
10132 * @param {Object} argN - Additional objects containing properties to merge in target.
10133 * @returns {Object} The `target` object.
10134 */
10135 extend: function(target) {
10136 var setFn = function(value, key) {
10137 target[key] = value;
10138 };
10139 for (var i = 1, ilen = arguments.length; i < ilen; ++i) {
10140 helpers.each(arguments[i], setFn);
10141 }
10142 return target;
10143 },
10144
10145 /**
10146 * Basic javascript inheritance based on the model created in Backbone.js
10147 */
10148 inherits: function(extensions) {
10149 var me = this;
10150 var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() {
10151 return me.apply(this, arguments);
10152 };
10153
10154 var Surrogate = function() {
10155 this.constructor = ChartElement;
10156 };
10157
10158 Surrogate.prototype = me.prototype;
10159 ChartElement.prototype = new Surrogate();
10160 ChartElement.extend = helpers.inherits;
10161
10162 if (extensions) {
10163 helpers.extend(ChartElement.prototype, extensions);
10164 }
10165
10166 ChartElement.__super__ = me.prototype;
10167 return ChartElement;
10168 }
10169};
10170
10171module.exports = helpers;
10172
10173// DEPRECATIONS
10174
10175/**
10176 * Provided for backward compatibility, use Chart.helpers.callback instead.
10177 * @function Chart.helpers.callCallback
10178 * @deprecated since version 2.6.0
10179 * @todo remove at version 3
10180 * @private
10181 */
10182helpers.callCallback = helpers.callback;
10183
10184/**
10185 * Provided for backward compatibility, use Array.prototype.indexOf instead.
10186 * Array.prototype.indexOf compatibility: Chrome, Opera, Safari, FF1.5+, IE9+
10187 * @function Chart.helpers.indexOf
10188 * @deprecated since version 2.7.0
10189 * @todo remove at version 3
10190 * @private
10191 */
10192helpers.indexOf = function(array, item, fromIndex) {
10193 return Array.prototype.indexOf.call(array, item, fromIndex);
10194};
10195
10196/**
10197 * Provided for backward compatibility, use Chart.helpers.valueOrDefault instead.
10198 * @function Chart.helpers.getValueOrDefault
10199 * @deprecated since version 2.7.0
10200 * @todo remove at version 3
10201 * @private
10202 */
10203helpers.getValueOrDefault = helpers.valueOrDefault;
10204
10205/**
10206 * Provided for backward compatibility, use Chart.helpers.valueAtIndexOrDefault instead.
10207 * @function Chart.helpers.getValueAtIndexOrDefault
10208 * @deprecated since version 2.7.0
10209 * @todo remove at version 3
10210 * @private
10211 */
10212helpers.getValueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
10213
10214},{}],40:[function(require,module,exports){
10215'use strict';
10216
10217var helpers = require(39);
10218
10219/**
10220 * Easing functions adapted from Robert Penner's easing equations.
10221 * @namespace Chart.helpers.easingEffects
10222 * @see http://www.robertpenner.com/easing/
10223 */
10224var effects = {
10225 linear: function(t) {
10226 return t;
10227 },
10228
10229 easeInQuad: function(t) {
10230 return t * t;
10231 },
10232
10233 easeOutQuad: function(t) {
10234 return -t * (t - 2);
10235 },
10236
10237 easeInOutQuad: function(t) {
10238 if ((t /= 0.5) < 1) {
10239 return 0.5 * t * t;
10240 }
10241 return -0.5 * ((--t) * (t - 2) - 1);
10242 },
10243
10244 easeInCubic: function(t) {
10245 return t * t * t;
10246 },
10247
10248 easeOutCubic: function(t) {
10249 return (t = t - 1) * t * t + 1;
10250 },
10251
10252 easeInOutCubic: function(t) {
10253 if ((t /= 0.5) < 1) {
10254 return 0.5 * t * t * t;
10255 }
10256 return 0.5 * ((t -= 2) * t * t + 2);
10257 },
10258
10259 easeInQuart: function(t) {
10260 return t * t * t * t;
10261 },
10262
10263 easeOutQuart: function(t) {
10264 return -((t = t - 1) * t * t * t - 1);
10265 },
10266
10267 easeInOutQuart: function(t) {
10268 if ((t /= 0.5) < 1) {
10269 return 0.5 * t * t * t * t;
10270 }
10271 return -0.5 * ((t -= 2) * t * t * t - 2);
10272 },
10273
10274 easeInQuint: function(t) {
10275 return t * t * t * t * t;
10276 },
10277
10278 easeOutQuint: function(t) {
10279 return (t = t - 1) * t * t * t * t + 1;
10280 },
10281
10282 easeInOutQuint: function(t) {
10283 if ((t /= 0.5) < 1) {
10284 return 0.5 * t * t * t * t * t;
10285 }
10286 return 0.5 * ((t -= 2) * t * t * t * t + 2);
10287 },
10288
10289 easeInSine: function(t) {
10290 return -Math.cos(t * (Math.PI / 2)) + 1;
10291 },
10292
10293 easeOutSine: function(t) {
10294 return Math.sin(t * (Math.PI / 2));
10295 },
10296
10297 easeInOutSine: function(t) {
10298 return -0.5 * (Math.cos(Math.PI * t) - 1);
10299 },
10300
10301 easeInExpo: function(t) {
10302 return (t === 0) ? 0 : Math.pow(2, 10 * (t - 1));
10303 },
10304
10305 easeOutExpo: function(t) {
10306 return (t === 1) ? 1 : -Math.pow(2, -10 * t) + 1;
10307 },
10308
10309 easeInOutExpo: function(t) {
10310 if (t === 0) {
10311 return 0;
10312 }
10313 if (t === 1) {
10314 return 1;
10315 }
10316 if ((t /= 0.5) < 1) {
10317 return 0.5 * Math.pow(2, 10 * (t - 1));
10318 }
10319 return 0.5 * (-Math.pow(2, -10 * --t) + 2);
10320 },
10321
10322 easeInCirc: function(t) {
10323 if (t >= 1) {
10324 return t;
10325 }
10326 return -(Math.sqrt(1 - t * t) - 1);
10327 },
10328
10329 easeOutCirc: function(t) {
10330 return Math.sqrt(1 - (t = t - 1) * t);
10331 },
10332
10333 easeInOutCirc: function(t) {
10334 if ((t /= 0.5) < 1) {
10335 return -0.5 * (Math.sqrt(1 - t * t) - 1);
10336 }
10337 return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
10338 },
10339
10340 easeInElastic: function(t) {
10341 var s = 1.70158;
10342 var p = 0;
10343 var a = 1;
10344 if (t === 0) {
10345 return 0;
10346 }
10347 if (t === 1) {
10348 return 1;
10349 }
10350 if (!p) {
10351 p = 0.3;
10352 }
10353 if (a < 1) {
10354 a = 1;
10355 s = p / 4;
10356 } else {
10357 s = p / (2 * Math.PI) * Math.asin(1 / a);
10358 }
10359 return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
10360 },
10361
10362 easeOutElastic: function(t) {
10363 var s = 1.70158;
10364 var p = 0;
10365 var a = 1;
10366 if (t === 0) {
10367 return 0;
10368 }
10369 if (t === 1) {
10370 return 1;
10371 }
10372 if (!p) {
10373 p = 0.3;
10374 }
10375 if (a < 1) {
10376 a = 1;
10377 s = p / 4;
10378 } else {
10379 s = p / (2 * Math.PI) * Math.asin(1 / a);
10380 }
10381 return a * Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1;
10382 },
10383
10384 easeInOutElastic: function(t) {
10385 var s = 1.70158;
10386 var p = 0;
10387 var a = 1;
10388 if (t === 0) {
10389 return 0;
10390 }
10391 if ((t /= 0.5) === 2) {
10392 return 1;
10393 }
10394 if (!p) {
10395 p = 0.45;
10396 }
10397 if (a < 1) {
10398 a = 1;
10399 s = p / 4;
10400 } else {
10401 s = p / (2 * Math.PI) * Math.asin(1 / a);
10402 }
10403 if (t < 1) {
10404 return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
10405 }
10406 return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p) * 0.5 + 1;
10407 },
10408 easeInBack: function(t) {
10409 var s = 1.70158;
10410 return t * t * ((s + 1) * t - s);
10411 },
10412
10413 easeOutBack: function(t) {
10414 var s = 1.70158;
10415 return (t = t - 1) * t * ((s + 1) * t + s) + 1;
10416 },
10417
10418 easeInOutBack: function(t) {
10419 var s = 1.70158;
10420 if ((t /= 0.5) < 1) {
10421 return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s));
10422 }
10423 return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
10424 },
10425
10426 easeInBounce: function(t) {
10427 return 1 - effects.easeOutBounce(1 - t);
10428 },
10429
10430 easeOutBounce: function(t) {
10431 if (t < (1 / 2.75)) {
10432 return 7.5625 * t * t;
10433 }
10434 if (t < (2 / 2.75)) {
10435 return 7.5625 * (t -= (1.5 / 2.75)) * t + 0.75;
10436 }
10437 if (t < (2.5 / 2.75)) {
10438 return 7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375;
10439 }
10440 return 7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375;
10441 },
10442
10443 easeInOutBounce: function(t) {
10444 if (t < 0.5) {
10445 return effects.easeInBounce(t * 2) * 0.5;
10446 }
10447 return effects.easeOutBounce(t * 2 - 1) * 0.5 + 0.5;
10448 }
10449};
10450
10451module.exports = {
10452 effects: effects
10453};
10454
10455// DEPRECATIONS
10456
10457/**
10458 * Provided for backward compatibility, use Chart.helpers.easing.effects instead.
10459 * @function Chart.helpers.easingEffects
10460 * @deprecated since version 2.7.0
10461 * @todo remove at version 3
10462 * @private
10463 */
10464helpers.easingEffects = effects;
10465
10466},{"39":39}],41:[function(require,module,exports){
10467'use strict';
10468
10469var helpers = require(39);
10470
10471/**
10472 * @alias Chart.helpers.options
10473 * @namespace
10474 */
10475module.exports = {
10476 /**
10477 * Converts the given line height `value` in pixels for a specific font `size`.
10478 * @param {Number|String} value - The lineHeight to parse (eg. 1.6, '14px', '75%', '1.6em').
10479 * @param {Number} size - The font size (in pixels) used to resolve relative `value`.
10480 * @returns {Number} The effective line height in pixels (size * 1.2 if value is invalid).
10481 * @see https://developer.mozilla.org/en-US/docs/Web/CSS/line-height
10482 * @since 2.7.0
10483 */
10484 toLineHeight: function(value, size) {
10485 var matches = ('' + value).match(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/);
10486 if (!matches || matches[1] === 'normal') {
10487 return size * 1.2;
10488 }
10489
10490 value = +matches[2];
10491
10492 switch (matches[3]) {
10493 case 'px':
10494 return value;
10495 case '%':
10496 value /= 100;
10497 break;
10498 default:
10499 break;
10500 }
10501
10502 return size * value;
10503 },
10504
10505 /**
10506 * Converts the given value into a padding object with pre-computed width/height.
10507 * @param {Number|Object} value - If a number, set the value to all TRBL component,
10508 * else, if and object, use defined properties and sets undefined ones to 0.
10509 * @returns {Object} The padding values (top, right, bottom, left, width, height)
10510 * @since 2.7.0
10511 */
10512 toPadding: function(value) {
10513 var t, r, b, l;
10514
10515 if (helpers.isObject(value)) {
10516 t = +value.top || 0;
10517 r = +value.right || 0;
10518 b = +value.bottom || 0;
10519 l = +value.left || 0;
10520 } else {
10521 t = r = b = l = +value || 0;
10522 }
10523
10524 return {
10525 top: t,
10526 right: r,
10527 bottom: b,
10528 left: l,
10529 height: t + b,
10530 width: l + r
10531 };
10532 },
10533
10534 /**
10535 * Evaluates the given `inputs` sequentially and returns the first defined value.
10536 * @param {Array[]} inputs - An array of values, falling back to the last value.
10537 * @param {Object} [context] - If defined and the current value is a function, the value
10538 * is called with `context` as first argument and the result becomes the new input.
10539 * @param {Number} [index] - If defined and the current value is an array, the value
10540 * at `index` become the new input.
10541 * @since 2.7.0
10542 */
10543 resolve: function(inputs, context, index) {
10544 var i, ilen, value;
10545
10546 for (i = 0, ilen = inputs.length; i < ilen; ++i) {
10547 value = inputs[i];
10548 if (value === undefined) {
10549 continue;
10550 }
10551 if (context !== undefined && typeof value === 'function') {
10552 value = value(context);
10553 }
10554 if (index !== undefined && helpers.isArray(value)) {
10555 value = value[index];
10556 }
10557 if (value !== undefined) {
10558 return value;
10559 }
10560 }
10561 }
10562};
10563
10564},{"39":39}],42:[function(require,module,exports){
10565'use strict';
10566
10567module.exports = require(39);
10568module.exports.easing = require(40);
10569module.exports.canvas = require(38);
10570module.exports.options = require(41);
10571
10572},{"38":38,"39":39,"40":40,"41":41}],43:[function(require,module,exports){
10573/**
10574 * Platform fallback implementation (minimal).
10575 * @see https://github.com/chartjs/Chart.js/pull/4591#issuecomment-319575939
10576 */
10577
10578module.exports = {
10579 acquireContext: function(item) {
10580 if (item && item.canvas) {
10581 // Support for any object associated to a canvas (including a context2d)
10582 item = item.canvas;
10583 }
10584
10585 return item && item.getContext('2d') || null;
10586 }
10587};
10588
10589},{}],44:[function(require,module,exports){
10590/**
10591 * Chart.Platform implementation for targeting a web browser
10592 */
10593
10594'use strict';
10595
10596var helpers = require(42);
10597
10598var EXPANDO_KEY = '$chartjs';
10599var CSS_PREFIX = 'chartjs-';
10600var CSS_RENDER_MONITOR = CSS_PREFIX + 'render-monitor';
10601var CSS_RENDER_ANIMATION = CSS_PREFIX + 'render-animation';
10602var ANIMATION_START_EVENTS = ['animationstart', 'webkitAnimationStart'];
10603
10604/**
10605 * DOM event types -> Chart.js event types.
10606 * Note: only events with different types are mapped.
10607 * @see https://developer.mozilla.org/en-US/docs/Web/Events
10608 */
10609var EVENT_TYPES = {
10610 touchstart: 'mousedown',
10611 touchmove: 'mousemove',
10612 touchend: 'mouseup',
10613 pointerenter: 'mouseenter',
10614 pointerdown: 'mousedown',
10615 pointermove: 'mousemove',
10616 pointerup: 'mouseup',
10617 pointerleave: 'mouseout',
10618 pointerout: 'mouseout'
10619};
10620
10621/**
10622 * The "used" size is the final value of a dimension property after all calculations have
10623 * been performed. This method uses the computed style of `element` but returns undefined
10624 * if the computed style is not expressed in pixels. That can happen in some cases where
10625 * `element` has a size relative to its parent and this last one is not yet displayed,
10626 * for example because of `display: none` on a parent node.
10627 * @see https://developer.mozilla.org/en-US/docs/Web/CSS/used_value
10628 * @returns {Number} Size in pixels or undefined if unknown.
10629 */
10630function readUsedSize(element, property) {
10631 var value = helpers.getStyle(element, property);
10632 var matches = value && value.match(/^(\d+)(\.\d+)?px$/);
10633 return matches ? Number(matches[1]) : undefined;
10634}
10635
10636/**
10637 * Initializes the canvas style and render size without modifying the canvas display size,
10638 * since responsiveness is handled by the controller.resize() method. The config is used
10639 * to determine the aspect ratio to apply in case no explicit height has been specified.
10640 */
10641function initCanvas(canvas, config) {
10642 var style = canvas.style;
10643
10644 // NOTE(SB) canvas.getAttribute('width') !== canvas.width: in the first case it
10645 // returns null or '' if no explicit value has been set to the canvas attribute.
10646 var renderHeight = canvas.getAttribute('height');
10647 var renderWidth = canvas.getAttribute('width');
10648
10649 // Chart.js modifies some canvas values that we want to restore on destroy
10650 canvas[EXPANDO_KEY] = {
10651 initial: {
10652 height: renderHeight,
10653 width: renderWidth,
10654 style: {
10655 display: style.display,
10656 height: style.height,
10657 width: style.width
10658 }
10659 }
10660 };
10661
10662 // Force canvas to display as block to avoid extra space caused by inline
10663 // elements, which would interfere with the responsive resize process.
10664 // https://github.com/chartjs/Chart.js/issues/2538
10665 style.display = style.display || 'block';
10666
10667 if (renderWidth === null || renderWidth === '') {
10668 var displayWidth = readUsedSize(canvas, 'width');
10669 if (displayWidth !== undefined) {
10670 canvas.width = displayWidth;
10671 }
10672 }
10673
10674 if (renderHeight === null || renderHeight === '') {
10675 if (canvas.style.height === '') {
10676 // If no explicit render height and style height, let's apply the aspect ratio,
10677 // which one can be specified by the user but also by charts as default option
10678 // (i.e. options.aspectRatio). If not specified, use canvas aspect ratio of 2.
10679 canvas.height = canvas.width / (config.options.aspectRatio || 2);
10680 } else {
10681 var displayHeight = readUsedSize(canvas, 'height');
10682 if (displayWidth !== undefined) {
10683 canvas.height = displayHeight;
10684 }
10685 }
10686 }
10687
10688 return canvas;
10689}
10690
10691/**
10692 * Detects support for options object argument in addEventListener.
10693 * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
10694 * @private
10695 */
10696var supportsEventListenerOptions = (function() {
10697 var supports = false;
10698 try {
10699 var options = Object.defineProperty({}, 'passive', {
10700 // eslint-disable-next-line getter-return
10701 get: function() {
10702 supports = true;
10703 }
10704 });
10705 window.addEventListener('e', null, options);
10706 } catch (e) {
10707 // continue regardless of error
10708 }
10709 return supports;
10710}());
10711
10712// Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
10713// https://github.com/chartjs/Chart.js/issues/4287
10714var eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false;
10715
10716function addEventListener(node, type, listener) {
10717 node.addEventListener(type, listener, eventListenerOptions);
10718}
10719
10720function removeEventListener(node, type, listener) {
10721 node.removeEventListener(type, listener, eventListenerOptions);
10722}
10723
10724function createEvent(type, chart, x, y, nativeEvent) {
10725 return {
10726 type: type,
10727 chart: chart,
10728 native: nativeEvent || null,
10729 x: x !== undefined ? x : null,
10730 y: y !== undefined ? y : null,
10731 };
10732}
10733
10734function fromNativeEvent(event, chart) {
10735 var type = EVENT_TYPES[event.type] || event.type;
10736 var pos = helpers.getRelativePosition(event, chart);
10737 return createEvent(type, chart, pos.x, pos.y, event);
10738}
10739
10740function throttled(fn, thisArg) {
10741 var ticking = false;
10742 var args = [];
10743
10744 return function() {
10745 args = Array.prototype.slice.call(arguments);
10746 thisArg = thisArg || this;
10747
10748 if (!ticking) {
10749 ticking = true;
10750 helpers.requestAnimFrame.call(window, function() {
10751 ticking = false;
10752 fn.apply(thisArg, args);
10753 });
10754 }
10755 };
10756}
10757
10758// Implementation based on https://github.com/marcj/css-element-queries
10759function createResizer(handler) {
10760 var resizer = document.createElement('div');
10761 var cls = CSS_PREFIX + 'size-monitor';
10762 var maxSize = 1000000;
10763 var style =
10764 'position:absolute;' +
10765 'left:0;' +
10766 'top:0;' +
10767 'right:0;' +
10768 'bottom:0;' +
10769 'overflow:hidden;' +
10770 'pointer-events:none;' +
10771 'visibility:hidden;' +
10772 'z-index:-1;';
10773
10774 resizer.style.cssText = style;
10775 resizer.className = cls;
10776 resizer.innerHTML =
10777 '<div class="' + cls + '-expand" style="' + style + '">' +
10778 '<div style="' +
10779 'position:absolute;' +
10780 'width:' + maxSize + 'px;' +
10781 'height:' + maxSize + 'px;' +
10782 'left:0;' +
10783 'top:0">' +
10784 '</div>' +
10785 '</div>' +
10786 '<div class="' + cls + '-shrink" style="' + style + '">' +
10787 '<div style="' +
10788 'position:absolute;' +
10789 'width:200%;' +
10790 'height:200%;' +
10791 'left:0; ' +
10792 'top:0">' +
10793 '</div>' +
10794 '</div>';
10795
10796 var expand = resizer.childNodes[0];
10797 var shrink = resizer.childNodes[1];
10798
10799 resizer._reset = function() {
10800 expand.scrollLeft = maxSize;
10801 expand.scrollTop = maxSize;
10802 shrink.scrollLeft = maxSize;
10803 shrink.scrollTop = maxSize;
10804 };
10805 var onScroll = function() {
10806 resizer._reset();
10807 handler();
10808 };
10809
10810 addEventListener(expand, 'scroll', onScroll.bind(expand, 'expand'));
10811 addEventListener(shrink, 'scroll', onScroll.bind(shrink, 'shrink'));
10812
10813 return resizer;
10814}
10815
10816// https://davidwalsh.name/detect-node-insertion
10817function watchForRender(node, handler) {
10818 var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
10819 var proxy = expando.renderProxy = function(e) {
10820 if (e.animationName === CSS_RENDER_ANIMATION) {
10821 handler();
10822 }
10823 };
10824
10825 helpers.each(ANIMATION_START_EVENTS, function(type) {
10826 addEventListener(node, type, proxy);
10827 });
10828
10829 // #4737: Chrome might skip the CSS animation when the CSS_RENDER_MONITOR class
10830 // is removed then added back immediately (same animation frame?). Accessing the
10831 // `offsetParent` property will force a reflow and re-evaluate the CSS animation.
10832 // https://gist.github.com/paulirish/5d52fb081b3570c81e3a#box-metrics
10833 // https://github.com/chartjs/Chart.js/issues/4737
10834 expando.reflow = !!node.offsetParent;
10835
10836 node.classList.add(CSS_RENDER_MONITOR);
10837}
10838
10839function unwatchForRender(node) {
10840 var expando = node[EXPANDO_KEY] || {};
10841 var proxy = expando.renderProxy;
10842
10843 if (proxy) {
10844 helpers.each(ANIMATION_START_EVENTS, function(type) {
10845 removeEventListener(node, type, proxy);
10846 });
10847
10848 delete expando.renderProxy;
10849 }
10850
10851 node.classList.remove(CSS_RENDER_MONITOR);
10852}
10853
10854function addResizeListener(node, listener, chart) {
10855 var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
10856
10857 // Let's keep track of this added resizer and thus avoid DOM query when removing it.
10858 var resizer = expando.resizer = createResizer(throttled(function() {
10859 if (expando.resizer) {
10860 return listener(createEvent('resize', chart));
10861 }
10862 }));
10863
10864 // The resizer needs to be attached to the node parent, so we first need to be
10865 // sure that `node` is attached to the DOM before injecting the resizer element.
10866 watchForRender(node, function() {
10867 if (expando.resizer) {
10868 var container = node.parentNode;
10869 if (container && container !== resizer.parentNode) {
10870 container.insertBefore(resizer, container.firstChild);
10871 }
10872
10873 // The container size might have changed, let's reset the resizer state.
10874 resizer._reset();
10875 }
10876 });
10877}
10878
10879function removeResizeListener(node) {
10880 var expando = node[EXPANDO_KEY] || {};
10881 var resizer = expando.resizer;
10882
10883 delete expando.resizer;
10884 unwatchForRender(node);
10885
10886 if (resizer && resizer.parentNode) {
10887 resizer.parentNode.removeChild(resizer);
10888 }
10889}
10890
10891function injectCSS(platform, css) {
10892 // http://stackoverflow.com/q/3922139
10893 var style = platform._style || document.createElement('style');
10894 if (!platform._style) {
10895 platform._style = style;
10896 css = '/* Chart.js */\n' + css;
10897 style.setAttribute('type', 'text/css');
10898 document.getElementsByTagName('head')[0].appendChild(style);
10899 }
10900
10901 style.appendChild(document.createTextNode(css));
10902}
10903
10904module.exports = {
10905 /**
10906 * This property holds whether this platform is enabled for the current environment.
10907 * Currently used by platform.js to select the proper implementation.
10908 * @private
10909 */
10910 _enabled: typeof window !== 'undefined' && typeof document !== 'undefined',
10911
10912 initialize: function() {
10913 var keyframes = 'from{opacity:0.99}to{opacity:1}';
10914
10915 injectCSS(this,
10916 // DOM rendering detection
10917 // https://davidwalsh.name/detect-node-insertion
10918 '@-webkit-keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
10919 '@keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
10920 '.' + CSS_RENDER_MONITOR + '{' +
10921 '-webkit-animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
10922 'animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
10923 '}'
10924 );
10925 },
10926
10927 acquireContext: function(item, config) {
10928 if (typeof item === 'string') {
10929 item = document.getElementById(item);
10930 } else if (item.length) {
10931 // Support for array based queries (such as jQuery)
10932 item = item[0];
10933 }
10934
10935 if (item && item.canvas) {
10936 // Support for any object associated to a canvas (including a context2d)
10937 item = item.canvas;
10938 }
10939
10940 // To prevent canvas fingerprinting, some add-ons undefine the getContext
10941 // method, for example: https://github.com/kkapsner/CanvasBlocker
10942 // https://github.com/chartjs/Chart.js/issues/2807
10943 var context = item && item.getContext && item.getContext('2d');
10944
10945 // `instanceof HTMLCanvasElement/CanvasRenderingContext2D` fails when the item is
10946 // inside an iframe or when running in a protected environment. We could guess the
10947 // types from their toString() value but let's keep things flexible and assume it's
10948 // a sufficient condition if the item has a context2D which has item as `canvas`.
10949 // https://github.com/chartjs/Chart.js/issues/3887
10950 // https://github.com/chartjs/Chart.js/issues/4102
10951 // https://github.com/chartjs/Chart.js/issues/4152
10952 if (context && context.canvas === item) {
10953 initCanvas(item, config);
10954 return context;
10955 }
10956
10957 return null;
10958 },
10959
10960 releaseContext: function(context) {
10961 var canvas = context.canvas;
10962 if (!canvas[EXPANDO_KEY]) {
10963 return;
10964 }
10965
10966 var initial = canvas[EXPANDO_KEY].initial;
10967 ['height', 'width'].forEach(function(prop) {
10968 var value = initial[prop];
10969 if (helpers.isNullOrUndef(value)) {
10970 canvas.removeAttribute(prop);
10971 } else {
10972 canvas.setAttribute(prop, value);
10973 }
10974 });
10975
10976 helpers.each(initial.style || {}, function(value, key) {
10977 canvas.style[key] = value;
10978 });
10979
10980 // The canvas render size might have been changed (and thus the state stack discarded),
10981 // we can't use save() and restore() to restore the initial state. So make sure that at
10982 // least the canvas context is reset to the default state by setting the canvas width.
10983 // https://www.w3.org/TR/2011/WD-html5-20110525/the-canvas-element.html
10984 // eslint-disable-next-line no-self-assign
10985 canvas.width = canvas.width;
10986
10987 delete canvas[EXPANDO_KEY];
10988 },
10989
10990 addEventListener: function(chart, type, listener) {
10991 var canvas = chart.canvas;
10992 if (type === 'resize') {
10993 // Note: the resize event is not supported on all browsers.
10994 addResizeListener(canvas, listener, chart);
10995 return;
10996 }
10997
10998 var expando = listener[EXPANDO_KEY] || (listener[EXPANDO_KEY] = {});
10999 var proxies = expando.proxies || (expando.proxies = {});
11000 var proxy = proxies[chart.id + '_' + type] = function(event) {
11001 listener(fromNativeEvent(event, chart));
11002 };
11003
11004 addEventListener(canvas, type, proxy);
11005 },
11006
11007 removeEventListener: function(chart, type, listener) {
11008 var canvas = chart.canvas;
11009 if (type === 'resize') {
11010 // Note: the resize event is not supported on all browsers.
11011 removeResizeListener(canvas, listener);
11012 return;
11013 }
11014
11015 var expando = listener[EXPANDO_KEY] || {};
11016 var proxies = expando.proxies || {};
11017 var proxy = proxies[chart.id + '_' + type];
11018 if (!proxy) {
11019 return;
11020 }
11021
11022 removeEventListener(canvas, type, proxy);
11023 }
11024};
11025
11026// DEPRECATIONS
11027
11028/**
11029 * Provided for backward compatibility, use EventTarget.addEventListener instead.
11030 * EventTarget.addEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
11031 * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
11032 * @function Chart.helpers.addEvent
11033 * @deprecated since version 2.7.0
11034 * @todo remove at version 3
11035 * @private
11036 */
11037helpers.addEvent = addEventListener;
11038
11039/**
11040 * Provided for backward compatibility, use EventTarget.removeEventListener instead.
11041 * EventTarget.removeEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
11042 * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener
11043 * @function Chart.helpers.removeEvent
11044 * @deprecated since version 2.7.0
11045 * @todo remove at version 3
11046 * @private
11047 */
11048helpers.removeEvent = removeEventListener;
11049
11050},{"42":42}],45:[function(require,module,exports){
11051'use strict';
11052
11053var helpers = require(42);
11054var basic = require(43);
11055var dom = require(44);
11056
11057// @TODO Make possible to select another platform at build time.
11058var implementation = dom._enabled ? dom : basic;
11059
11060/**
11061 * @namespace Chart.platform
11062 * @see https://chartjs.gitbooks.io/proposals/content/Platform.html
11063 * @since 2.4.0
11064 */
11065module.exports = helpers.extend({
11066 /**
11067 * @since 2.7.0
11068 */
11069 initialize: function() {},
11070
11071 /**
11072 * Called at chart construction time, returns a context2d instance implementing
11073 * the [W3C Canvas 2D Context API standard]{@link https://www.w3.org/TR/2dcontext/}.
11074 * @param {*} item - The native item from which to acquire context (platform specific)
11075 * @param {Object} options - The chart options
11076 * @returns {CanvasRenderingContext2D} context2d instance
11077 */
11078 acquireContext: function() {},
11079
11080 /**
11081 * Called at chart destruction time, releases any resources associated to the context
11082 * previously returned by the acquireContext() method.
11083 * @param {CanvasRenderingContext2D} context - The context2d instance
11084 * @returns {Boolean} true if the method succeeded, else false
11085 */
11086 releaseContext: function() {},
11087
11088 /**
11089 * Registers the specified listener on the given chart.
11090 * @param {Chart} chart - Chart from which to listen for event
11091 * @param {String} type - The ({@link IEvent}) type to listen for
11092 * @param {Function} listener - Receives a notification (an object that implements
11093 * the {@link IEvent} interface) when an event of the specified type occurs.
11094 */
11095 addEventListener: function() {},
11096
11097 /**
11098 * Removes the specified listener previously registered with addEventListener.
11099 * @param {Chart} chart -Chart from which to remove the listener
11100 * @param {String} type - The ({@link IEvent}) type to remove
11101 * @param {Function} listener - The listener function to remove from the event target.
11102 */
11103 removeEventListener: function() {}
11104
11105}, implementation);
11106
11107/**
11108 * @interface IPlatform
11109 * Allows abstracting platform dependencies away from the chart
11110 * @borrows Chart.platform.acquireContext as acquireContext
11111 * @borrows Chart.platform.releaseContext as releaseContext
11112 * @borrows Chart.platform.addEventListener as addEventListener
11113 * @borrows Chart.platform.removeEventListener as removeEventListener
11114 */
11115
11116/**
11117 * @interface IEvent
11118 * @prop {String} type - The event type name, possible values are:
11119 * 'contextmenu', 'mouseenter', 'mousedown', 'mousemove', 'mouseup', 'mouseout',
11120 * 'click', 'dblclick', 'keydown', 'keypress', 'keyup' and 'resize'
11121 * @prop {*} native - The original native event (null for emulated events, e.g. 'resize')
11122 * @prop {Number} x - The mouse x position, relative to the canvas (null for incompatible events)
11123 * @prop {Number} y - The mouse y position, relative to the canvas (null for incompatible events)
11124 */
11125
11126},{"42":42,"43":43,"44":44}],46:[function(require,module,exports){
11127'use strict';
11128
11129module.exports = {};
11130module.exports.filler = require(47);
11131module.exports.legend = require(48);
11132module.exports.title = require(49);
11133
11134},{"47":47,"48":48,"49":49}],47:[function(require,module,exports){
11135/**
11136 * Plugin based on discussion from the following Chart.js issues:
11137 * @see https://github.com/chartjs/Chart.js/issues/2380#issuecomment-279961569
11138 * @see https://github.com/chartjs/Chart.js/issues/2440#issuecomment-256461897
11139 */
11140
11141'use strict';
11142
11143var defaults = require(22);
11144var elements = require(37);
11145var helpers = require(42);
11146
11147defaults._set('global', {
11148 plugins: {
11149 filler: {
11150 propagate: true
11151 }
11152 }
11153});
11154
11155var mappers = {
11156 dataset: function(source) {
11157 var index = source.fill;
11158 var chart = source.chart;
11159 var meta = chart.getDatasetMeta(index);
11160 var visible = meta && chart.isDatasetVisible(index);
11161 var points = (visible && meta.dataset._children) || [];
11162 var length = points.length || 0;
11163
11164 return !length ? null : function(point, i) {
11165 return (i < length && points[i]._view) || null;
11166 };
11167 },
11168
11169 boundary: function(source) {
11170 var boundary = source.boundary;
11171 var x = boundary ? boundary.x : null;
11172 var y = boundary ? boundary.y : null;
11173
11174 return function(point) {
11175 return {
11176 x: x === null ? point.x : x,
11177 y: y === null ? point.y : y,
11178 };
11179 };
11180 }
11181};
11182
11183// @todo if (fill[0] === '#')
11184function decodeFill(el, index, count) {
11185 var model = el._model || {};
11186 var fill = model.fill;
11187 var target;
11188
11189 if (fill === undefined) {
11190 fill = !!model.backgroundColor;
11191 }
11192
11193 if (fill === false || fill === null) {
11194 return false;
11195 }
11196
11197 if (fill === true) {
11198 return 'origin';
11199 }
11200
11201 target = parseFloat(fill, 10);
11202 if (isFinite(target) && Math.floor(target) === target) {
11203 if (fill[0] === '-' || fill[0] === '+') {
11204 target = index + target;
11205 }
11206
11207 if (target === index || target < 0 || target >= count) {
11208 return false;
11209 }
11210
11211 return target;
11212 }
11213
11214 switch (fill) {
11215 // compatibility
11216 case 'bottom':
11217 return 'start';
11218 case 'top':
11219 return 'end';
11220 case 'zero':
11221 return 'origin';
11222 // supported boundaries
11223 case 'origin':
11224 case 'start':
11225 case 'end':
11226 return fill;
11227 // invalid fill values
11228 default:
11229 return false;
11230 }
11231}
11232
11233function computeBoundary(source) {
11234 var model = source.el._model || {};
11235 var scale = source.el._scale || {};
11236 var fill = source.fill;
11237 var target = null;
11238 var horizontal;
11239
11240 if (isFinite(fill)) {
11241 return null;
11242 }
11243
11244 // Backward compatibility: until v3, we still need to support boundary values set on
11245 // the model (scaleTop, scaleBottom and scaleZero) because some external plugins and
11246 // controllers might still use it (e.g. the Smith chart).
11247
11248 if (fill === 'start') {
11249 target = model.scaleBottom === undefined ? scale.bottom : model.scaleBottom;
11250 } else if (fill === 'end') {
11251 target = model.scaleTop === undefined ? scale.top : model.scaleTop;
11252 } else if (model.scaleZero !== undefined) {
11253 target = model.scaleZero;
11254 } else if (scale.getBasePosition) {
11255 target = scale.getBasePosition();
11256 } else if (scale.getBasePixel) {
11257 target = scale.getBasePixel();
11258 }
11259
11260 if (target !== undefined && target !== null) {
11261 if (target.x !== undefined && target.y !== undefined) {
11262 return target;
11263 }
11264
11265 if (helpers.isFinite(target)) {
11266 horizontal = scale.isHorizontal();
11267 return {
11268 x: horizontal ? target : null,
11269 y: horizontal ? null : target
11270 };
11271 }
11272 }
11273
11274 return null;
11275}
11276
11277function resolveTarget(sources, index, propagate) {
11278 var source = sources[index];
11279 var fill = source.fill;
11280 var visited = [index];
11281 var target;
11282
11283 if (!propagate) {
11284 return fill;
11285 }
11286
11287 while (fill !== false && visited.indexOf(fill) === -1) {
11288 if (!isFinite(fill)) {
11289 return fill;
11290 }
11291
11292 target = sources[fill];
11293 if (!target) {
11294 return false;
11295 }
11296
11297 if (target.visible) {
11298 return fill;
11299 }
11300
11301 visited.push(fill);
11302 fill = target.fill;
11303 }
11304
11305 return false;
11306}
11307
11308function createMapper(source) {
11309 var fill = source.fill;
11310 var type = 'dataset';
11311
11312 if (fill === false) {
11313 return null;
11314 }
11315
11316 if (!isFinite(fill)) {
11317 type = 'boundary';
11318 }
11319
11320 return mappers[type](source);
11321}
11322
11323function isDrawable(point) {
11324 return point && !point.skip;
11325}
11326
11327function drawArea(ctx, curve0, curve1, len0, len1) {
11328 var i;
11329
11330 if (!len0 || !len1) {
11331 return;
11332 }
11333
11334 // building first area curve (normal)
11335 ctx.moveTo(curve0[0].x, curve0[0].y);
11336 for (i = 1; i < len0; ++i) {
11337 helpers.canvas.lineTo(ctx, curve0[i - 1], curve0[i]);
11338 }
11339
11340 // joining the two area curves
11341 ctx.lineTo(curve1[len1 - 1].x, curve1[len1 - 1].y);
11342
11343 // building opposite area curve (reverse)
11344 for (i = len1 - 1; i > 0; --i) {
11345 helpers.canvas.lineTo(ctx, curve1[i], curve1[i - 1], true);
11346 }
11347}
11348
11349function doFill(ctx, points, mapper, view, color, loop) {
11350 var count = points.length;
11351 var span = view.spanGaps;
11352 var curve0 = [];
11353 var curve1 = [];
11354 var len0 = 0;
11355 var len1 = 0;
11356 var i, ilen, index, p0, p1, d0, d1;
11357
11358 ctx.beginPath();
11359
11360 for (i = 0, ilen = (count + !!loop); i < ilen; ++i) {
11361 index = i % count;
11362 p0 = points[index]._view;
11363 p1 = mapper(p0, index, view);
11364 d0 = isDrawable(p0);
11365 d1 = isDrawable(p1);
11366
11367 if (d0 && d1) {
11368 len0 = curve0.push(p0);
11369 len1 = curve1.push(p1);
11370 } else if (len0 && len1) {
11371 if (!span) {
11372 drawArea(ctx, curve0, curve1, len0, len1);
11373 len0 = len1 = 0;
11374 curve0 = [];
11375 curve1 = [];
11376 } else {
11377 if (d0) {
11378 curve0.push(p0);
11379 }
11380 if (d1) {
11381 curve1.push(p1);
11382 }
11383 }
11384 }
11385 }
11386
11387 drawArea(ctx, curve0, curve1, len0, len1);
11388
11389 ctx.closePath();
11390 ctx.fillStyle = color;
11391 ctx.fill();
11392}
11393
11394module.exports = {
11395 id: 'filler',
11396
11397 afterDatasetsUpdate: function(chart, options) {
11398 var count = (chart.data.datasets || []).length;
11399 var propagate = options.propagate;
11400 var sources = [];
11401 var meta, i, el, source;
11402
11403 for (i = 0; i < count; ++i) {
11404 meta = chart.getDatasetMeta(i);
11405 el = meta.dataset;
11406 source = null;
11407
11408 if (el && el._model && el instanceof elements.Line) {
11409 source = {
11410 visible: chart.isDatasetVisible(i),
11411 fill: decodeFill(el, i, count),
11412 chart: chart,
11413 el: el
11414 };
11415 }
11416
11417 meta.$filler = source;
11418 sources.push(source);
11419 }
11420
11421 for (i = 0; i < count; ++i) {
11422 source = sources[i];
11423 if (!source) {
11424 continue;
11425 }
11426
11427 source.fill = resolveTarget(sources, i, propagate);
11428 source.boundary = computeBoundary(source);
11429 source.mapper = createMapper(source);
11430 }
11431 },
11432
11433 beforeDatasetDraw: function(chart, args) {
11434 var meta = args.meta.$filler;
11435 if (!meta) {
11436 return;
11437 }
11438
11439 var ctx = chart.ctx;
11440 var el = meta.el;
11441 var view = el._view;
11442 var points = el._children || [];
11443 var mapper = meta.mapper;
11444 var color = view.backgroundColor || defaults.global.defaultColor;
11445
11446 if (mapper && color && points.length) {
11447 helpers.canvas.clipArea(ctx, chart.chartArea);
11448 doFill(ctx, points, mapper, view, color, el._loop);
11449 helpers.canvas.unclipArea(ctx);
11450 }
11451 }
11452};
11453
11454},{"22":22,"37":37,"42":42}],48:[function(require,module,exports){
11455'use strict';
11456
11457var defaults = require(22);
11458var Element = require(23);
11459var helpers = require(42);
11460var layouts = require(27);
11461
11462var noop = helpers.noop;
11463
11464defaults._set('global', {
11465 legend: {
11466 display: true,
11467 position: 'top',
11468 fullWidth: true,
11469 reverse: false,
11470 weight: 1000,
11471
11472 // a callback that will handle
11473 onClick: function(e, legendItem) {
11474 var index = legendItem.datasetIndex;
11475 var ci = this.chart;
11476 var meta = ci.getDatasetMeta(index);
11477
11478 // See controller.isDatasetVisible comment
11479 meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;
11480
11481 // We hid a dataset ... rerender the chart
11482 ci.update();
11483 },
11484
11485 onHover: null,
11486
11487 labels: {
11488 boxWidth: 40,
11489 padding: 10,
11490 // Generates labels shown in the legend
11491 // Valid properties to return:
11492 // text : text to display
11493 // fillStyle : fill of coloured box
11494 // strokeStyle: stroke of coloured box
11495 // hidden : if this legend item refers to a hidden item
11496 // lineCap : cap style for line
11497 // lineDash
11498 // lineDashOffset :
11499 // lineJoin :
11500 // lineWidth :
11501 generateLabels: function(chart) {
11502 var data = chart.data;
11503 return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
11504 return {
11505 text: dataset.label,
11506 fillStyle: (!helpers.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0]),
11507 hidden: !chart.isDatasetVisible(i),
11508 lineCap: dataset.borderCapStyle,
11509 lineDash: dataset.borderDash,
11510 lineDashOffset: dataset.borderDashOffset,
11511 lineJoin: dataset.borderJoinStyle,
11512 lineWidth: dataset.borderWidth,
11513 strokeStyle: dataset.borderColor,
11514 pointStyle: dataset.pointStyle,
11515
11516 // Below is extra data used for toggling the datasets
11517 datasetIndex: i
11518 };
11519 }, this) : [];
11520 }
11521 }
11522 },
11523
11524 legendCallback: function(chart) {
11525 var text = [];
11526 text.push('<ul class="' + chart.id + '-legend">');
11527 for (var i = 0; i < chart.data.datasets.length; i++) {
11528 text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '"></span>');
11529 if (chart.data.datasets[i].label) {
11530 text.push(chart.data.datasets[i].label);
11531 }
11532 text.push('</li>');
11533 }
11534 text.push('</ul>');
11535 return text.join('');
11536 }
11537});
11538
11539/**
11540 * Helper function to get the box width based on the usePointStyle option
11541 * @param labelopts {Object} the label options on the legend
11542 * @param fontSize {Number} the label font size
11543 * @return {Number} width of the color box area
11544 */
11545function getBoxWidth(labelOpts, fontSize) {
11546 return labelOpts.usePointStyle ?
11547 fontSize * Math.SQRT2 :
11548 labelOpts.boxWidth;
11549}
11550
11551/**
11552 * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
11553 */
11554var Legend = Element.extend({
11555
11556 initialize: function(config) {
11557 helpers.extend(this, config);
11558
11559 // Contains hit boxes for each dataset (in dataset order)
11560 this.legendHitBoxes = [];
11561
11562 // Are we in doughnut mode which has a different data type
11563 this.doughnutMode = false;
11564 },
11565
11566 // These methods are ordered by lifecycle. Utilities then follow.
11567 // Any function defined here is inherited by all legend types.
11568 // Any function can be extended by the legend type
11569
11570 beforeUpdate: noop,
11571 update: function(maxWidth, maxHeight, margins) {
11572 var me = this;
11573
11574 // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
11575 me.beforeUpdate();
11576
11577 // Absorb the master measurements
11578 me.maxWidth = maxWidth;
11579 me.maxHeight = maxHeight;
11580 me.margins = margins;
11581
11582 // Dimensions
11583 me.beforeSetDimensions();
11584 me.setDimensions();
11585 me.afterSetDimensions();
11586 // Labels
11587 me.beforeBuildLabels();
11588 me.buildLabels();
11589 me.afterBuildLabels();
11590
11591 // Fit
11592 me.beforeFit();
11593 me.fit();
11594 me.afterFit();
11595 //
11596 me.afterUpdate();
11597
11598 return me.minSize;
11599 },
11600 afterUpdate: noop,
11601
11602 //
11603
11604 beforeSetDimensions: noop,
11605 setDimensions: function() {
11606 var me = this;
11607 // Set the unconstrained dimension before label rotation
11608 if (me.isHorizontal()) {
11609 // Reset position before calculating rotation
11610 me.width = me.maxWidth;
11611 me.left = 0;
11612 me.right = me.width;
11613 } else {
11614 me.height = me.maxHeight;
11615
11616 // Reset position before calculating rotation
11617 me.top = 0;
11618 me.bottom = me.height;
11619 }
11620
11621 // Reset padding
11622 me.paddingLeft = 0;
11623 me.paddingTop = 0;
11624 me.paddingRight = 0;
11625 me.paddingBottom = 0;
11626
11627 // Reset minSize
11628 me.minSize = {
11629 width: 0,
11630 height: 0
11631 };
11632 },
11633 afterSetDimensions: noop,
11634
11635 //
11636
11637 beforeBuildLabels: noop,
11638 buildLabels: function() {
11639 var me = this;
11640 var labelOpts = me.options.labels || {};
11641 var legendItems = helpers.callback(labelOpts.generateLabels, [me.chart], me) || [];
11642
11643 if (labelOpts.filter) {
11644 legendItems = legendItems.filter(function(item) {
11645 return labelOpts.filter(item, me.chart.data);
11646 });
11647 }
11648
11649 if (me.options.reverse) {
11650 legendItems.reverse();
11651 }
11652
11653 me.legendItems = legendItems;
11654 },
11655 afterBuildLabels: noop,
11656
11657 //
11658
11659 beforeFit: noop,
11660 fit: function() {
11661 var me = this;
11662 var opts = me.options;
11663 var labelOpts = opts.labels;
11664 var display = opts.display;
11665
11666 var ctx = me.ctx;
11667
11668 var globalDefault = defaults.global;
11669 var valueOrDefault = helpers.valueOrDefault;
11670 var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
11671 var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
11672 var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
11673 var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
11674
11675 // Reset hit boxes
11676 var hitboxes = me.legendHitBoxes = [];
11677
11678 var minSize = me.minSize;
11679 var isHorizontal = me.isHorizontal();
11680
11681 if (isHorizontal) {
11682 minSize.width = me.maxWidth; // fill all the width
11683 minSize.height = display ? 10 : 0;
11684 } else {
11685 minSize.width = display ? 10 : 0;
11686 minSize.height = me.maxHeight; // fill all the height
11687 }
11688
11689 // Increase sizes here
11690 if (display) {
11691 ctx.font = labelFont;
11692
11693 if (isHorizontal) {
11694 // Labels
11695
11696 // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
11697 var lineWidths = me.lineWidths = [0];
11698 var totalHeight = 0;
11699
11700 ctx.textAlign = 'left';
11701 ctx.textBaseline = 'top';
11702
11703 helpers.each(me.legendItems, function(legendItem, i) {
11704 var boxWidth = getBoxWidth(labelOpts, fontSize);
11705 var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
11706
11707 if (i === 0 || lineWidths[lineWidths.length - 1] + width + labelOpts.padding > minSize.width) {
11708 totalHeight += fontSize + labelOpts.padding;
11709 lineWidths[lineWidths.length - (i > 0 ? 0 : 1)] = labelOpts.padding;
11710 }
11711
11712 // Store the hitbox width and height here. Final position will be updated in `draw`
11713 hitboxes[i] = {
11714 left: 0,
11715 top: 0,
11716 width: width,
11717 height: fontSize
11718 };
11719
11720 lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
11721 });
11722
11723 minSize.height += totalHeight;
11724
11725 } else {
11726 var vPadding = labelOpts.padding;
11727 var columnWidths = me.columnWidths = [];
11728 var totalWidth = labelOpts.padding;
11729 var currentColWidth = 0;
11730 var currentColHeight = 0;
11731 var itemHeight = fontSize + vPadding;
11732
11733 helpers.each(me.legendItems, function(legendItem, i) {
11734 var boxWidth = getBoxWidth(labelOpts, fontSize);
11735 var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
11736
11737 // If too tall, go to new column
11738 if (i > 0 && currentColHeight + itemHeight > minSize.height - vPadding) {
11739 totalWidth += currentColWidth + labelOpts.padding;
11740 columnWidths.push(currentColWidth); // previous column width
11741
11742 currentColWidth = 0;
11743 currentColHeight = 0;
11744 }
11745
11746 // Get max width
11747 currentColWidth = Math.max(currentColWidth, itemWidth);
11748 currentColHeight += itemHeight;
11749
11750 // Store the hitbox width and height here. Final position will be updated in `draw`
11751 hitboxes[i] = {
11752 left: 0,
11753 top: 0,
11754 width: itemWidth,
11755 height: fontSize
11756 };
11757 });
11758
11759 totalWidth += currentColWidth;
11760 columnWidths.push(currentColWidth);
11761 minSize.width += totalWidth;
11762 }
11763 }
11764
11765 me.width = minSize.width;
11766 me.height = minSize.height;
11767 },
11768 afterFit: noop,
11769
11770 // Shared Methods
11771 isHorizontal: function() {
11772 return this.options.position === 'top' || this.options.position === 'bottom';
11773 },
11774
11775 // Actually draw the legend on the canvas
11776 draw: function() {
11777 var me = this;
11778 var opts = me.options;
11779 var labelOpts = opts.labels;
11780 var globalDefault = defaults.global;
11781 var lineDefault = globalDefault.elements.line;
11782 var legendWidth = me.width;
11783 var lineWidths = me.lineWidths;
11784
11785 if (opts.display) {
11786 var ctx = me.ctx;
11787 var valueOrDefault = helpers.valueOrDefault;
11788 var fontColor = valueOrDefault(labelOpts.fontColor, globalDefault.defaultFontColor);
11789 var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
11790 var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
11791 var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
11792 var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
11793 var cursor;
11794
11795 // Canvas setup
11796 ctx.textAlign = 'left';
11797 ctx.textBaseline = 'middle';
11798 ctx.lineWidth = 0.5;
11799 ctx.strokeStyle = fontColor; // for strikethrough effect
11800 ctx.fillStyle = fontColor; // render in correct colour
11801 ctx.font = labelFont;
11802
11803 var boxWidth = getBoxWidth(labelOpts, fontSize);
11804 var hitboxes = me.legendHitBoxes;
11805
11806 // current position
11807 var drawLegendBox = function(x, y, legendItem) {
11808 if (isNaN(boxWidth) || boxWidth <= 0) {
11809 return;
11810 }
11811
11812 // Set the ctx for the box
11813 ctx.save();
11814
11815 ctx.fillStyle = valueOrDefault(legendItem.fillStyle, globalDefault.defaultColor);
11816 ctx.lineCap = valueOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
11817 ctx.lineDashOffset = valueOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
11818 ctx.lineJoin = valueOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
11819 ctx.lineWidth = valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
11820 ctx.strokeStyle = valueOrDefault(legendItem.strokeStyle, globalDefault.defaultColor);
11821 var isLineWidthZero = (valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth) === 0);
11822
11823 if (ctx.setLineDash) {
11824 // IE 9 and 10 do not support line dash
11825 ctx.setLineDash(valueOrDefault(legendItem.lineDash, lineDefault.borderDash));
11826 }
11827
11828 if (opts.labels && opts.labels.usePointStyle) {
11829 // Recalculate x and y for drawPoint() because its expecting
11830 // x and y to be center of figure (instead of top left)
11831 var radius = fontSize * Math.SQRT2 / 2;
11832 var offSet = radius / Math.SQRT2;
11833 var centerX = x + offSet;
11834 var centerY = y + offSet;
11835
11836 // Draw pointStyle as legend symbol
11837 helpers.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
11838 } else {
11839 // Draw box as legend symbol
11840 if (!isLineWidthZero) {
11841 ctx.strokeRect(x, y, boxWidth, fontSize);
11842 }
11843 ctx.fillRect(x, y, boxWidth, fontSize);
11844 }
11845
11846 ctx.restore();
11847 };
11848 var fillText = function(x, y, legendItem, textWidth) {
11849 var halfFontSize = fontSize / 2;
11850 var xLeft = boxWidth + halfFontSize + x;
11851 var yMiddle = y + halfFontSize;
11852
11853 ctx.fillText(legendItem.text, xLeft, yMiddle);
11854
11855 if (legendItem.hidden) {
11856 // Strikethrough the text if hidden
11857 ctx.beginPath();
11858 ctx.lineWidth = 2;
11859 ctx.moveTo(xLeft, yMiddle);
11860 ctx.lineTo(xLeft + textWidth, yMiddle);
11861 ctx.stroke();
11862 }
11863 };
11864
11865 // Horizontal
11866 var isHorizontal = me.isHorizontal();
11867 if (isHorizontal) {
11868 cursor = {
11869 x: me.left + ((legendWidth - lineWidths[0]) / 2) + labelOpts.padding,
11870 y: me.top + labelOpts.padding,
11871 line: 0
11872 };
11873 } else {
11874 cursor = {
11875 x: me.left + labelOpts.padding,
11876 y: me.top + labelOpts.padding,
11877 line: 0
11878 };
11879 }
11880
11881 var itemHeight = fontSize + labelOpts.padding;
11882 helpers.each(me.legendItems, function(legendItem, i) {
11883 var textWidth = ctx.measureText(legendItem.text).width;
11884 var width = boxWidth + (fontSize / 2) + textWidth;
11885 var x = cursor.x;
11886 var y = cursor.y;
11887
11888 // Use (me.left + me.minSize.width) and (me.top + me.minSize.height)
11889 // instead of me.right and me.bottom because me.width and me.height
11890 // may have been changed since me.minSize was calculated
11891 if (isHorizontal) {
11892 if (i > 0 && x + width + labelOpts.padding > me.left + me.minSize.width) {
11893 y = cursor.y += itemHeight;
11894 cursor.line++;
11895 x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2) + labelOpts.padding;
11896 }
11897 } else if (i > 0 && y + itemHeight > me.top + me.minSize.height) {
11898 x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
11899 y = cursor.y = me.top + labelOpts.padding;
11900 cursor.line++;
11901 }
11902
11903 drawLegendBox(x, y, legendItem);
11904
11905 hitboxes[i].left = x;
11906 hitboxes[i].top = y;
11907
11908 // Fill the actual label
11909 fillText(x, y, legendItem, textWidth);
11910
11911 if (isHorizontal) {
11912 cursor.x += width + labelOpts.padding;
11913 } else {
11914 cursor.y += itemHeight;
11915 }
11916
11917 });
11918 }
11919 },
11920
11921 /**
11922 * Handle an event
11923 * @private
11924 * @param {IEvent} event - The event to handle
11925 * @return {Boolean} true if a change occured
11926 */
11927 handleEvent: function(e) {
11928 var me = this;
11929 var opts = me.options;
11930 var type = e.type === 'mouseup' ? 'click' : e.type;
11931 var changed = false;
11932
11933 if (type === 'mousemove') {
11934 if (!opts.onHover) {
11935 return;
11936 }
11937 } else if (type === 'click') {
11938 if (!opts.onClick) {
11939 return;
11940 }
11941 } else {
11942 return;
11943 }
11944
11945 // Chart event already has relative position in it
11946 var x = e.x;
11947 var y = e.y;
11948
11949 if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) {
11950 // See if we are touching one of the dataset boxes
11951 var lh = me.legendHitBoxes;
11952 for (var i = 0; i < lh.length; ++i) {
11953 var hitBox = lh[i];
11954
11955 if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
11956 // Touching an element
11957 if (type === 'click') {
11958 // use e.native for backwards compatibility
11959 opts.onClick.call(me, e.native, me.legendItems[i]);
11960 changed = true;
11961 break;
11962 } else if (type === 'mousemove') {
11963 // use e.native for backwards compatibility
11964 opts.onHover.call(me, e.native, me.legendItems[i]);
11965 changed = true;
11966 break;
11967 }
11968 }
11969 }
11970 }
11971
11972 return changed;
11973 }
11974});
11975
11976function createNewLegendAndAttach(chart, legendOpts) {
11977 var legend = new Legend({
11978 ctx: chart.ctx,
11979 options: legendOpts,
11980 chart: chart
11981 });
11982
11983 layouts.configure(chart, legend, legendOpts);
11984 layouts.addBox(chart, legend);
11985 chart.legend = legend;
11986}
11987
11988module.exports = {
11989 id: 'legend',
11990
11991 /**
11992 * Backward compatibility: since 2.1.5, the legend is registered as a plugin, making
11993 * Chart.Legend obsolete. To avoid a breaking change, we export the Legend as part of
11994 * the plugin, which one will be re-exposed in the chart.js file.
11995 * https://github.com/chartjs/Chart.js/pull/2640
11996 * @private
11997 */
11998 _element: Legend,
11999
12000 beforeInit: function(chart) {
12001 var legendOpts = chart.options.legend;
12002
12003 if (legendOpts) {
12004 createNewLegendAndAttach(chart, legendOpts);
12005 }
12006 },
12007
12008 beforeUpdate: function(chart) {
12009 var legendOpts = chart.options.legend;
12010 var legend = chart.legend;
12011
12012 if (legendOpts) {
12013 helpers.mergeIf(legendOpts, defaults.global.legend);
12014
12015 if (legend) {
12016 layouts.configure(chart, legend, legendOpts);
12017 legend.options = legendOpts;
12018 } else {
12019 createNewLegendAndAttach(chart, legendOpts);
12020 }
12021 } else if (legend) {
12022 layouts.removeBox(chart, legend);
12023 delete chart.legend;
12024 }
12025 },
12026
12027 afterEvent: function(chart, e) {
12028 var legend = chart.legend;
12029 if (legend) {
12030 legend.handleEvent(e);
12031 }
12032 }
12033};
12034
12035},{"22":22,"23":23,"27":27,"42":42}],49:[function(require,module,exports){
12036'use strict';
12037
12038var defaults = require(22);
12039var Element = require(23);
12040var helpers = require(42);
12041var layouts = require(27);
12042
12043var noop = helpers.noop;
12044
12045defaults._set('global', {
12046 title: {
12047 display: false,
12048 fontStyle: 'bold',
12049 fullWidth: true,
12050 lineHeight: 1.2,
12051 padding: 10,
12052 position: 'top',
12053 text: '',
12054 weight: 2000 // by default greater than legend (1000) to be above
12055 }
12056});
12057
12058/**
12059 * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
12060 */
12061var Title = Element.extend({
12062 initialize: function(config) {
12063 var me = this;
12064 helpers.extend(me, config);
12065
12066 // Contains hit boxes for each dataset (in dataset order)
12067 me.legendHitBoxes = [];
12068 },
12069
12070 // These methods are ordered by lifecycle. Utilities then follow.
12071
12072 beforeUpdate: noop,
12073 update: function(maxWidth, maxHeight, margins) {
12074 var me = this;
12075
12076 // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
12077 me.beforeUpdate();
12078
12079 // Absorb the master measurements
12080 me.maxWidth = maxWidth;
12081 me.maxHeight = maxHeight;
12082 me.margins = margins;
12083
12084 // Dimensions
12085 me.beforeSetDimensions();
12086 me.setDimensions();
12087 me.afterSetDimensions();
12088 // Labels
12089 me.beforeBuildLabels();
12090 me.buildLabels();
12091 me.afterBuildLabels();
12092
12093 // Fit
12094 me.beforeFit();
12095 me.fit();
12096 me.afterFit();
12097 //
12098 me.afterUpdate();
12099
12100 return me.minSize;
12101
12102 },
12103 afterUpdate: noop,
12104
12105 //
12106
12107 beforeSetDimensions: noop,
12108 setDimensions: function() {
12109 var me = this;
12110 // Set the unconstrained dimension before label rotation
12111 if (me.isHorizontal()) {
12112 // Reset position before calculating rotation
12113 me.width = me.maxWidth;
12114 me.left = 0;
12115 me.right = me.width;
12116 } else {
12117 me.height = me.maxHeight;
12118
12119 // Reset position before calculating rotation
12120 me.top = 0;
12121 me.bottom = me.height;
12122 }
12123
12124 // Reset padding
12125 me.paddingLeft = 0;
12126 me.paddingTop = 0;
12127 me.paddingRight = 0;
12128 me.paddingBottom = 0;
12129
12130 // Reset minSize
12131 me.minSize = {
12132 width: 0,
12133 height: 0
12134 };
12135 },
12136 afterSetDimensions: noop,
12137
12138 //
12139
12140 beforeBuildLabels: noop,
12141 buildLabels: noop,
12142 afterBuildLabels: noop,
12143
12144 //
12145
12146 beforeFit: noop,
12147 fit: function() {
12148 var me = this;
12149 var valueOrDefault = helpers.valueOrDefault;
12150 var opts = me.options;
12151 var display = opts.display;
12152 var fontSize = valueOrDefault(opts.fontSize, defaults.global.defaultFontSize);
12153 var minSize = me.minSize;
12154 var lineCount = helpers.isArray(opts.text) ? opts.text.length : 1;
12155 var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
12156 var textSize = display ? (lineCount * lineHeight) + (opts.padding * 2) : 0;
12157
12158 if (me.isHorizontal()) {
12159 minSize.width = me.maxWidth; // fill all the width
12160 minSize.height = textSize;
12161 } else {
12162 minSize.width = textSize;
12163 minSize.height = me.maxHeight; // fill all the height
12164 }
12165
12166 me.width = minSize.width;
12167 me.height = minSize.height;
12168
12169 },
12170 afterFit: noop,
12171
12172 // Shared Methods
12173 isHorizontal: function() {
12174 var pos = this.options.position;
12175 return pos === 'top' || pos === 'bottom';
12176 },
12177
12178 // Actually draw the title block on the canvas
12179 draw: function() {
12180 var me = this;
12181 var ctx = me.ctx;
12182 var valueOrDefault = helpers.valueOrDefault;
12183 var opts = me.options;
12184 var globalDefaults = defaults.global;
12185
12186 if (opts.display) {
12187 var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize);
12188 var fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle);
12189 var fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily);
12190 var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily);
12191 var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
12192 var offset = lineHeight / 2 + opts.padding;
12193 var rotation = 0;
12194 var top = me.top;
12195 var left = me.left;
12196 var bottom = me.bottom;
12197 var right = me.right;
12198 var maxWidth, titleX, titleY;
12199
12200 ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
12201 ctx.font = titleFont;
12202
12203 // Horizontal
12204 if (me.isHorizontal()) {
12205 titleX = left + ((right - left) / 2); // midpoint of the width
12206 titleY = top + offset;
12207 maxWidth = right - left;
12208 } else {
12209 titleX = opts.position === 'left' ? left + offset : right - offset;
12210 titleY = top + ((bottom - top) / 2);
12211 maxWidth = bottom - top;
12212 rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
12213 }
12214
12215 ctx.save();
12216 ctx.translate(titleX, titleY);
12217 ctx.rotate(rotation);
12218 ctx.textAlign = 'center';
12219 ctx.textBaseline = 'middle';
12220
12221 var text = opts.text;
12222 if (helpers.isArray(text)) {
12223 var y = 0;
12224 for (var i = 0; i < text.length; ++i) {
12225 ctx.fillText(text[i], 0, y, maxWidth);
12226 y += lineHeight;
12227 }
12228 } else {
12229 ctx.fillText(text, 0, 0, maxWidth);
12230 }
12231
12232 ctx.restore();
12233 }
12234 }
12235});
12236
12237function createNewTitleBlockAndAttach(chart, titleOpts) {
12238 var title = new Title({
12239 ctx: chart.ctx,
12240 options: titleOpts,
12241 chart: chart
12242 });
12243
12244 layouts.configure(chart, title, titleOpts);
12245 layouts.addBox(chart, title);
12246 chart.titleBlock = title;
12247}
12248
12249module.exports = {
12250 id: 'title',
12251
12252 /**
12253 * Backward compatibility: since 2.1.5, the title is registered as a plugin, making
12254 * Chart.Title obsolete. To avoid a breaking change, we export the Title as part of
12255 * the plugin, which one will be re-exposed in the chart.js file.
12256 * https://github.com/chartjs/Chart.js/pull/2640
12257 * @private
12258 */
12259 _element: Title,
12260
12261 beforeInit: function(chart) {
12262 var titleOpts = chart.options.title;
12263
12264 if (titleOpts) {
12265 createNewTitleBlockAndAttach(chart, titleOpts);
12266 }
12267 },
12268
12269 beforeUpdate: function(chart) {
12270 var titleOpts = chart.options.title;
12271 var titleBlock = chart.titleBlock;
12272
12273 if (titleOpts) {
12274 helpers.mergeIf(titleOpts, defaults.global.title);
12275
12276 if (titleBlock) {
12277 layouts.configure(chart, titleBlock, titleOpts);
12278 titleBlock.options = titleOpts;
12279 } else {
12280 createNewTitleBlockAndAttach(chart, titleOpts);
12281 }
12282 } else if (titleBlock) {
12283 layouts.removeBox(chart, titleBlock);
12284 delete chart.titleBlock;
12285 }
12286 }
12287};
12288
12289},{"22":22,"23":23,"27":27,"42":42}],50:[function(require,module,exports){
12290'use strict';
12291
12292var Scale = require(29);
12293var scaleService = require(30);
12294
12295module.exports = function() {
12296
12297 // Default config for a category scale
12298 var defaultConfig = {
12299 position: 'bottom'
12300 };
12301
12302 var DatasetScale = Scale.extend({
12303 /**
12304 * Internal function to get the correct labels. If data.xLabels or data.yLabels are defined, use those
12305 * else fall back to data.labels
12306 * @private
12307 */
12308 getLabels: function() {
12309 var data = this.chart.data;
12310 return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels;
12311 },
12312
12313 determineDataLimits: function() {
12314 var me = this;
12315 var labels = me.getLabels();
12316 me.minIndex = 0;
12317 me.maxIndex = labels.length - 1;
12318 var findIndex;
12319
12320 if (me.options.ticks.min !== undefined) {
12321 // user specified min value
12322 findIndex = labels.indexOf(me.options.ticks.min);
12323 me.minIndex = findIndex !== -1 ? findIndex : me.minIndex;
12324 }
12325
12326 if (me.options.ticks.max !== undefined) {
12327 // user specified max value
12328 findIndex = labels.indexOf(me.options.ticks.max);
12329 me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex;
12330 }
12331
12332 me.min = labels[me.minIndex];
12333 me.max = labels[me.maxIndex];
12334 },
12335
12336 buildTicks: function() {
12337 var me = this;
12338 var labels = me.getLabels();
12339 // If we are viewing some subset of labels, slice the original array
12340 me.ticks = (me.minIndex === 0 && me.maxIndex === labels.length - 1) ? labels : labels.slice(me.minIndex, me.maxIndex + 1);
12341 },
12342
12343 getLabelForIndex: function(index, datasetIndex) {
12344 var me = this;
12345 var data = me.chart.data;
12346 var isHorizontal = me.isHorizontal();
12347
12348 if (data.yLabels && !isHorizontal) {
12349 return me.getRightValue(data.datasets[datasetIndex].data[index]);
12350 }
12351 return me.ticks[index - me.minIndex];
12352 },
12353
12354 // Used to get data value locations. Value can either be an index or a numerical value
12355 getPixelForValue: function(value, index) {
12356 var me = this;
12357 var offset = me.options.offset;
12358 // 1 is added because we need the length but we have the indexes
12359 var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - (offset ? 0 : 1)), 1);
12360
12361 // If value is a data object, then index is the index in the data array,
12362 // not the index of the scale. We need to change that.
12363 var valueCategory;
12364 if (value !== undefined && value !== null) {
12365 valueCategory = me.isHorizontal() ? value.x : value.y;
12366 }
12367 if (valueCategory !== undefined || (value !== undefined && isNaN(index))) {
12368 var labels = me.getLabels();
12369 value = valueCategory || value;
12370 var idx = labels.indexOf(value);
12371 index = idx !== -1 ? idx : index;
12372 }
12373
12374 if (me.isHorizontal()) {
12375 var valueWidth = me.width / offsetAmt;
12376 var widthOffset = (valueWidth * (index - me.minIndex));
12377
12378 if (offset) {
12379 widthOffset += (valueWidth / 2);
12380 }
12381
12382 return me.left + Math.round(widthOffset);
12383 }
12384 var valueHeight = me.height / offsetAmt;
12385 var heightOffset = (valueHeight * (index - me.minIndex));
12386
12387 if (offset) {
12388 heightOffset += (valueHeight / 2);
12389 }
12390
12391 return me.top + Math.round(heightOffset);
12392 },
12393 getPixelForTick: function(index) {
12394 return this.getPixelForValue(this.ticks[index], index + this.minIndex, null);
12395 },
12396 getValueForPixel: function(pixel) {
12397 var me = this;
12398 var offset = me.options.offset;
12399 var value;
12400 var offsetAmt = Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
12401 var horz = me.isHorizontal();
12402 var valueDimension = (horz ? me.width : me.height) / offsetAmt;
12403
12404 pixel -= horz ? me.left : me.top;
12405
12406 if (offset) {
12407 pixel -= (valueDimension / 2);
12408 }
12409
12410 if (pixel <= 0) {
12411 value = 0;
12412 } else {
12413 value = Math.round(pixel / valueDimension);
12414 }
12415
12416 return value + me.minIndex;
12417 },
12418 getBasePixel: function() {
12419 return this.bottom;
12420 }
12421 });
12422
12423 scaleService.registerScaleType('category', DatasetScale, defaultConfig);
12424};
12425
12426},{"29":29,"30":30}],51:[function(require,module,exports){
12427'use strict';
12428
12429var defaults = require(22);
12430var helpers = require(42);
12431var scaleService = require(30);
12432var Ticks = require(31);
12433
12434module.exports = function(Chart) {
12435
12436 var defaultConfig = {
12437 position: 'left',
12438 ticks: {
12439 callback: Ticks.formatters.linear
12440 }
12441 };
12442
12443 var LinearScale = Chart.LinearScaleBase.extend({
12444
12445 determineDataLimits: function() {
12446 var me = this;
12447 var opts = me.options;
12448 var chart = me.chart;
12449 var data = chart.data;
12450 var datasets = data.datasets;
12451 var isHorizontal = me.isHorizontal();
12452 var DEFAULT_MIN = 0;
12453 var DEFAULT_MAX = 1;
12454
12455 function IDMatches(meta) {
12456 return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
12457 }
12458
12459 // First Calculate the range
12460 me.min = null;
12461 me.max = null;
12462
12463 var hasStacks = opts.stacked;
12464 if (hasStacks === undefined) {
12465 helpers.each(datasets, function(dataset, datasetIndex) {
12466 if (hasStacks) {
12467 return;
12468 }
12469
12470 var meta = chart.getDatasetMeta(datasetIndex);
12471 if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
12472 meta.stack !== undefined) {
12473 hasStacks = true;
12474 }
12475 });
12476 }
12477
12478 if (opts.stacked || hasStacks) {
12479 var valuesPerStack = {};
12480
12481 helpers.each(datasets, function(dataset, datasetIndex) {
12482 var meta = chart.getDatasetMeta(datasetIndex);
12483 var key = [
12484 meta.type,
12485 // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
12486 ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
12487 meta.stack
12488 ].join('.');
12489
12490 if (valuesPerStack[key] === undefined) {
12491 valuesPerStack[key] = {
12492 positiveValues: [],
12493 negativeValues: []
12494 };
12495 }
12496
12497 // Store these per type
12498 var positiveValues = valuesPerStack[key].positiveValues;
12499 var negativeValues = valuesPerStack[key].negativeValues;
12500
12501 if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
12502 helpers.each(dataset.data, function(rawValue, index) {
12503 var value = +me.getRightValue(rawValue);
12504 if (isNaN(value) || meta.data[index].hidden) {
12505 return;
12506 }
12507
12508 positiveValues[index] = positiveValues[index] || 0;
12509 negativeValues[index] = negativeValues[index] || 0;
12510
12511 if (opts.relativePoints) {
12512 positiveValues[index] = 100;
12513 } else if (value < 0) {
12514 negativeValues[index] += value;
12515 } else {
12516 positiveValues[index] += value;
12517 }
12518 });
12519 }
12520 });
12521
12522 helpers.each(valuesPerStack, function(valuesForType) {
12523 var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
12524 var minVal = helpers.min(values);
12525 var maxVal = helpers.max(values);
12526 me.min = me.min === null ? minVal : Math.min(me.min, minVal);
12527 me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
12528 });
12529
12530 } else {
12531 helpers.each(datasets, function(dataset, datasetIndex) {
12532 var meta = chart.getDatasetMeta(datasetIndex);
12533 if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
12534 helpers.each(dataset.data, function(rawValue, index) {
12535 var value = +me.getRightValue(rawValue);
12536 if (isNaN(value) || meta.data[index].hidden) {
12537 return;
12538 }
12539
12540 if (me.min === null) {
12541 me.min = value;
12542 } else if (value < me.min) {
12543 me.min = value;
12544 }
12545
12546 if (me.max === null) {
12547 me.max = value;
12548 } else if (value > me.max) {
12549 me.max = value;
12550 }
12551 });
12552 }
12553 });
12554 }
12555
12556 me.min = isFinite(me.min) && !isNaN(me.min) ? me.min : DEFAULT_MIN;
12557 me.max = isFinite(me.max) && !isNaN(me.max) ? me.max : DEFAULT_MAX;
12558
12559 // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
12560 this.handleTickRangeOptions();
12561 },
12562 getTickLimit: function() {
12563 var maxTicks;
12564 var me = this;
12565 var tickOpts = me.options.ticks;
12566
12567 if (me.isHorizontal()) {
12568 maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.width / 50));
12569 } else {
12570 // The factor of 2 used to scale the font size has been experimentally determined.
12571 var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, defaults.global.defaultFontSize);
12572 maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.height / (2 * tickFontSize)));
12573 }
12574
12575 return maxTicks;
12576 },
12577 // Called after the ticks are built. We need
12578 handleDirectionalChanges: function() {
12579 if (!this.isHorizontal()) {
12580 // We are in a vertical orientation. The top value is the highest. So reverse the array
12581 this.ticks.reverse();
12582 }
12583 },
12584 getLabelForIndex: function(index, datasetIndex) {
12585 return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
12586 },
12587 // Utils
12588 getPixelForValue: function(value) {
12589 // This must be called after fit has been run so that
12590 // this.left, this.top, this.right, and this.bottom have been defined
12591 var me = this;
12592 var start = me.start;
12593
12594 var rightValue = +me.getRightValue(value);
12595 var pixel;
12596 var range = me.end - start;
12597
12598 if (me.isHorizontal()) {
12599 pixel = me.left + (me.width / range * (rightValue - start));
12600 } else {
12601 pixel = me.bottom - (me.height / range * (rightValue - start));
12602 }
12603 return pixel;
12604 },
12605 getValueForPixel: function(pixel) {
12606 var me = this;
12607 var isHorizontal = me.isHorizontal();
12608 var innerDimension = isHorizontal ? me.width : me.height;
12609 var offset = (isHorizontal ? pixel - me.left : me.bottom - pixel) / innerDimension;
12610 return me.start + ((me.end - me.start) * offset);
12611 },
12612 getPixelForTick: function(index) {
12613 return this.getPixelForValue(this.ticksAsNumbers[index]);
12614 }
12615 });
12616
12617 scaleService.registerScaleType('linear', LinearScale, defaultConfig);
12618};
12619
12620},{"22":22,"30":30,"31":31,"42":42}],52:[function(require,module,exports){
12621'use strict';
12622
12623var helpers = require(42);
12624var Scale = require(29);
12625
12626/**
12627 * Generate a set of linear ticks
12628 * @param generationOptions the options used to generate the ticks
12629 * @param dataRange the range of the data
12630 * @returns {Array<Number>} array of tick values
12631 */
12632function generateTicks(generationOptions, dataRange) {
12633 var ticks = [];
12634 // To get a "nice" value for the tick spacing, we will use the appropriately named
12635 // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
12636 // for details.
12637
12638 var stepSize = generationOptions.stepSize;
12639 var min = generationOptions.min;
12640 var max = generationOptions.max;
12641 var spacing, precision, factor, niceRange, niceMin, niceMax, numSpaces;
12642
12643 if (stepSize && stepSize > 0) {
12644 spacing = stepSize;
12645 } else {
12646 niceRange = helpers.niceNum(dataRange.max - dataRange.min, false);
12647 spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true);
12648
12649 precision = generationOptions.precision;
12650 if (!helpers.isNullOrUndef(precision)) {
12651 // If the user specified a precision, round to that number of decimal places
12652 factor = Math.pow(10, precision);
12653 spacing = Math.ceil(spacing * factor) / factor;
12654 }
12655 }
12656 // If a precision is not specified, calculate factor based on spacing
12657 if (!factor) {
12658 factor = Math.pow(10, helpers.decimalPlaces(spacing));
12659 }
12660 niceMin = Math.floor(dataRange.min / spacing) * spacing;
12661 niceMax = Math.ceil(dataRange.max / spacing) * spacing;
12662
12663 // If min, max and stepSize is set and they make an evenly spaced scale use it.
12664 if (!helpers.isNullOrUndef(min) && !helpers.isNullOrUndef(max) && stepSize) {
12665 // If very close to our whole number, use it.
12666 if (helpers.almostWhole((max - min) / stepSize, spacing / 1000)) {
12667 niceMin = min;
12668 niceMax = max;
12669 }
12670 }
12671
12672 numSpaces = (niceMax - niceMin) / spacing;
12673 // If very close to our rounded value, use it.
12674 if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
12675 numSpaces = Math.round(numSpaces);
12676 } else {
12677 numSpaces = Math.ceil(numSpaces);
12678 }
12679
12680 niceMin = Math.round(niceMin * factor) / factor;
12681 niceMax = Math.round(niceMax * factor) / factor;
12682 ticks.push(helpers.isNullOrUndef(min) ? niceMin : min);
12683 for (var j = 1; j < numSpaces; ++j) {
12684 ticks.push(Math.round((niceMin + j * spacing) * factor) / factor);
12685 }
12686 ticks.push(helpers.isNullOrUndef(max) ? niceMax : max);
12687
12688 return ticks;
12689}
12690
12691module.exports = function(Chart) {
12692
12693 var noop = helpers.noop;
12694
12695 Chart.LinearScaleBase = Scale.extend({
12696 getRightValue: function(value) {
12697 if (typeof value === 'string') {
12698 return +value;
12699 }
12700 return Scale.prototype.getRightValue.call(this, value);
12701 },
12702
12703 handleTickRangeOptions: function() {
12704 var me = this;
12705 var opts = me.options;
12706 var tickOpts = opts.ticks;
12707
12708 // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
12709 // do nothing since that would make the chart weird. If the user really wants a weird chart
12710 // axis, they can manually override it
12711 if (tickOpts.beginAtZero) {
12712 var minSign = helpers.sign(me.min);
12713 var maxSign = helpers.sign(me.max);
12714
12715 if (minSign < 0 && maxSign < 0) {
12716 // move the top up to 0
12717 me.max = 0;
12718 } else if (minSign > 0 && maxSign > 0) {
12719 // move the bottom down to 0
12720 me.min = 0;
12721 }
12722 }
12723
12724 var setMin = tickOpts.min !== undefined || tickOpts.suggestedMin !== undefined;
12725 var setMax = tickOpts.max !== undefined || tickOpts.suggestedMax !== undefined;
12726
12727 if (tickOpts.min !== undefined) {
12728 me.min = tickOpts.min;
12729 } else if (tickOpts.suggestedMin !== undefined) {
12730 if (me.min === null) {
12731 me.min = tickOpts.suggestedMin;
12732 } else {
12733 me.min = Math.min(me.min, tickOpts.suggestedMin);
12734 }
12735 }
12736
12737 if (tickOpts.max !== undefined) {
12738 me.max = tickOpts.max;
12739 } else if (tickOpts.suggestedMax !== undefined) {
12740 if (me.max === null) {
12741 me.max = tickOpts.suggestedMax;
12742 } else {
12743 me.max = Math.max(me.max, tickOpts.suggestedMax);
12744 }
12745 }
12746
12747 if (setMin !== setMax) {
12748 // We set the min or the max but not both.
12749 // So ensure that our range is good
12750 // Inverted or 0 length range can happen when
12751 // ticks.min is set, and no datasets are visible
12752 if (me.min >= me.max) {
12753 if (setMin) {
12754 me.max = me.min + 1;
12755 } else {
12756 me.min = me.max - 1;
12757 }
12758 }
12759 }
12760
12761 if (me.min === me.max) {
12762 me.max++;
12763
12764 if (!tickOpts.beginAtZero) {
12765 me.min--;
12766 }
12767 }
12768 },
12769 getTickLimit: noop,
12770 handleDirectionalChanges: noop,
12771
12772 buildTicks: function() {
12773 var me = this;
12774 var opts = me.options;
12775 var tickOpts = opts.ticks;
12776
12777 // Figure out what the max number of ticks we can support it is based on the size of
12778 // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
12779 // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
12780 // the graph. Make sure we always have at least 2 ticks
12781 var maxTicks = me.getTickLimit();
12782 maxTicks = Math.max(2, maxTicks);
12783
12784 var numericGeneratorOptions = {
12785 maxTicks: maxTicks,
12786 min: tickOpts.min,
12787 max: tickOpts.max,
12788 precision: tickOpts.precision,
12789 stepSize: helpers.valueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize)
12790 };
12791 var ticks = me.ticks = generateTicks(numericGeneratorOptions, me);
12792
12793 me.handleDirectionalChanges();
12794
12795 // At this point, we need to update our max and min given the tick values since we have expanded the
12796 // range of the scale
12797 me.max = helpers.max(ticks);
12798 me.min = helpers.min(ticks);
12799
12800 if (tickOpts.reverse) {
12801 ticks.reverse();
12802
12803 me.start = me.max;
12804 me.end = me.min;
12805 } else {
12806 me.start = me.min;
12807 me.end = me.max;
12808 }
12809 },
12810 convertTicksToLabels: function() {
12811 var me = this;
12812 me.ticksAsNumbers = me.ticks.slice();
12813 me.zeroLineIndex = me.ticks.indexOf(0);
12814
12815 Scale.prototype.convertTicksToLabels.call(me);
12816 }
12817 });
12818};
12819
12820},{"29":29,"42":42}],53:[function(require,module,exports){
12821'use strict';
12822
12823var helpers = require(42);
12824var Scale = require(29);
12825var scaleService = require(30);
12826var Ticks = require(31);
12827
12828/**
12829 * Generate a set of logarithmic ticks
12830 * @param generationOptions the options used to generate the ticks
12831 * @param dataRange the range of the data
12832 * @returns {Array<Number>} array of tick values
12833 */
12834function generateTicks(generationOptions, dataRange) {
12835 var ticks = [];
12836 var valueOrDefault = helpers.valueOrDefault;
12837
12838 // Figure out what the max number of ticks we can support it is based on the size of
12839 // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
12840 // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
12841 // the graph
12842 var tickVal = valueOrDefault(generationOptions.min, Math.pow(10, Math.floor(helpers.log10(dataRange.min))));
12843
12844 var endExp = Math.floor(helpers.log10(dataRange.max));
12845 var endSignificand = Math.ceil(dataRange.max / Math.pow(10, endExp));
12846 var exp, significand;
12847
12848 if (tickVal === 0) {
12849 exp = Math.floor(helpers.log10(dataRange.minNotZero));
12850 significand = Math.floor(dataRange.minNotZero / Math.pow(10, exp));
12851
12852 ticks.push(tickVal);
12853 tickVal = significand * Math.pow(10, exp);
12854 } else {
12855 exp = Math.floor(helpers.log10(tickVal));
12856 significand = Math.floor(tickVal / Math.pow(10, exp));
12857 }
12858 var precision = exp < 0 ? Math.pow(10, Math.abs(exp)) : 1;
12859
12860 do {
12861 ticks.push(tickVal);
12862
12863 ++significand;
12864 if (significand === 10) {
12865 significand = 1;
12866 ++exp;
12867 precision = exp >= 0 ? 1 : precision;
12868 }
12869
12870 tickVal = Math.round(significand * Math.pow(10, exp) * precision) / precision;
12871 } while (exp < endExp || (exp === endExp && significand < endSignificand));
12872
12873 var lastTick = valueOrDefault(generationOptions.max, tickVal);
12874 ticks.push(lastTick);
12875
12876 return ticks;
12877}
12878
12879
12880module.exports = function(Chart) {
12881
12882 var defaultConfig = {
12883 position: 'left',
12884
12885 // label settings
12886 ticks: {
12887 callback: Ticks.formatters.logarithmic
12888 }
12889 };
12890
12891 var LogarithmicScale = Scale.extend({
12892 determineDataLimits: function() {
12893 var me = this;
12894 var opts = me.options;
12895 var chart = me.chart;
12896 var data = chart.data;
12897 var datasets = data.datasets;
12898 var isHorizontal = me.isHorizontal();
12899 function IDMatches(meta) {
12900 return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
12901 }
12902
12903 // Calculate Range
12904 me.min = null;
12905 me.max = null;
12906 me.minNotZero = null;
12907
12908 var hasStacks = opts.stacked;
12909 if (hasStacks === undefined) {
12910 helpers.each(datasets, function(dataset, datasetIndex) {
12911 if (hasStacks) {
12912 return;
12913 }
12914
12915 var meta = chart.getDatasetMeta(datasetIndex);
12916 if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
12917 meta.stack !== undefined) {
12918 hasStacks = true;
12919 }
12920 });
12921 }
12922
12923 if (opts.stacked || hasStacks) {
12924 var valuesPerStack = {};
12925
12926 helpers.each(datasets, function(dataset, datasetIndex) {
12927 var meta = chart.getDatasetMeta(datasetIndex);
12928 var key = [
12929 meta.type,
12930 // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
12931 ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
12932 meta.stack
12933 ].join('.');
12934
12935 if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
12936 if (valuesPerStack[key] === undefined) {
12937 valuesPerStack[key] = [];
12938 }
12939
12940 helpers.each(dataset.data, function(rawValue, index) {
12941 var values = valuesPerStack[key];
12942 var value = +me.getRightValue(rawValue);
12943 // invalid, hidden and negative values are ignored
12944 if (isNaN(value) || meta.data[index].hidden || value < 0) {
12945 return;
12946 }
12947 values[index] = values[index] || 0;
12948 values[index] += value;
12949 });
12950 }
12951 });
12952
12953 helpers.each(valuesPerStack, function(valuesForType) {
12954 if (valuesForType.length > 0) {
12955 var minVal = helpers.min(valuesForType);
12956 var maxVal = helpers.max(valuesForType);
12957 me.min = me.min === null ? minVal : Math.min(me.min, minVal);
12958 me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
12959 }
12960 });
12961
12962 } else {
12963 helpers.each(datasets, function(dataset, datasetIndex) {
12964 var meta = chart.getDatasetMeta(datasetIndex);
12965 if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
12966 helpers.each(dataset.data, function(rawValue, index) {
12967 var value = +me.getRightValue(rawValue);
12968 // invalid, hidden and negative values are ignored
12969 if (isNaN(value) || meta.data[index].hidden || value < 0) {
12970 return;
12971 }
12972
12973 if (me.min === null) {
12974 me.min = value;
12975 } else if (value < me.min) {
12976 me.min = value;
12977 }
12978
12979 if (me.max === null) {
12980 me.max = value;
12981 } else if (value > me.max) {
12982 me.max = value;
12983 }
12984
12985 if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
12986 me.minNotZero = value;
12987 }
12988 });
12989 }
12990 });
12991 }
12992
12993 // Common base implementation to handle ticks.min, ticks.max
12994 this.handleTickRangeOptions();
12995 },
12996 handleTickRangeOptions: function() {
12997 var me = this;
12998 var opts = me.options;
12999 var tickOpts = opts.ticks;
13000 var valueOrDefault = helpers.valueOrDefault;
13001 var DEFAULT_MIN = 1;
13002 var DEFAULT_MAX = 10;
13003
13004 me.min = valueOrDefault(tickOpts.min, me.min);
13005 me.max = valueOrDefault(tickOpts.max, me.max);
13006
13007 if (me.min === me.max) {
13008 if (me.min !== 0 && me.min !== null) {
13009 me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
13010 me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
13011 } else {
13012 me.min = DEFAULT_MIN;
13013 me.max = DEFAULT_MAX;
13014 }
13015 }
13016 if (me.min === null) {
13017 me.min = Math.pow(10, Math.floor(helpers.log10(me.max)) - 1);
13018 }
13019 if (me.max === null) {
13020 me.max = me.min !== 0
13021 ? Math.pow(10, Math.floor(helpers.log10(me.min)) + 1)
13022 : DEFAULT_MAX;
13023 }
13024 if (me.minNotZero === null) {
13025 if (me.min > 0) {
13026 me.minNotZero = me.min;
13027 } else if (me.max < 1) {
13028 me.minNotZero = Math.pow(10, Math.floor(helpers.log10(me.max)));
13029 } else {
13030 me.minNotZero = DEFAULT_MIN;
13031 }
13032 }
13033 },
13034 buildTicks: function() {
13035 var me = this;
13036 var opts = me.options;
13037 var tickOpts = opts.ticks;
13038 var reverse = !me.isHorizontal();
13039
13040 var generationOptions = {
13041 min: tickOpts.min,
13042 max: tickOpts.max
13043 };
13044 var ticks = me.ticks = generateTicks(generationOptions, me);
13045
13046 // At this point, we need to update our max and min given the tick values since we have expanded the
13047 // range of the scale
13048 me.max = helpers.max(ticks);
13049 me.min = helpers.min(ticks);
13050
13051 if (tickOpts.reverse) {
13052 reverse = !reverse;
13053 me.start = me.max;
13054 me.end = me.min;
13055 } else {
13056 me.start = me.min;
13057 me.end = me.max;
13058 }
13059 if (reverse) {
13060 ticks.reverse();
13061 }
13062 },
13063 convertTicksToLabels: function() {
13064 this.tickValues = this.ticks.slice();
13065
13066 Scale.prototype.convertTicksToLabels.call(this);
13067 },
13068 // Get the correct tooltip label
13069 getLabelForIndex: function(index, datasetIndex) {
13070 return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
13071 },
13072 getPixelForTick: function(index) {
13073 return this.getPixelForValue(this.tickValues[index]);
13074 },
13075 /**
13076 * Returns the value of the first tick.
13077 * @param {Number} value - The minimum not zero value.
13078 * @return {Number} The first tick value.
13079 * @private
13080 */
13081 _getFirstTickValue: function(value) {
13082 var exp = Math.floor(helpers.log10(value));
13083 var significand = Math.floor(value / Math.pow(10, exp));
13084
13085 return significand * Math.pow(10, exp);
13086 },
13087 getPixelForValue: function(value) {
13088 var me = this;
13089 var reverse = me.options.ticks.reverse;
13090 var log10 = helpers.log10;
13091 var firstTickValue = me._getFirstTickValue(me.minNotZero);
13092 var offset = 0;
13093 var innerDimension, pixel, start, end, sign;
13094
13095 value = +me.getRightValue(value);
13096 if (reverse) {
13097 start = me.end;
13098 end = me.start;
13099 sign = -1;
13100 } else {
13101 start = me.start;
13102 end = me.end;
13103 sign = 1;
13104 }
13105 if (me.isHorizontal()) {
13106 innerDimension = me.width;
13107 pixel = reverse ? me.right : me.left;
13108 } else {
13109 innerDimension = me.height;
13110 sign *= -1; // invert, since the upper-left corner of the canvas is at pixel (0, 0)
13111 pixel = reverse ? me.top : me.bottom;
13112 }
13113 if (value !== start) {
13114 if (start === 0) { // include zero tick
13115 offset = helpers.getValueOrDefault(
13116 me.options.ticks.fontSize,
13117 Chart.defaults.global.defaultFontSize
13118 );
13119 innerDimension -= offset;
13120 start = firstTickValue;
13121 }
13122 if (value !== 0) {
13123 offset += innerDimension / (log10(end) - log10(start)) * (log10(value) - log10(start));
13124 }
13125 pixel += sign * offset;
13126 }
13127 return pixel;
13128 },
13129 getValueForPixel: function(pixel) {
13130 var me = this;
13131 var reverse = me.options.ticks.reverse;
13132 var log10 = helpers.log10;
13133 var firstTickValue = me._getFirstTickValue(me.minNotZero);
13134 var innerDimension, start, end, value;
13135
13136 if (reverse) {
13137 start = me.end;
13138 end = me.start;
13139 } else {
13140 start = me.start;
13141 end = me.end;
13142 }
13143 if (me.isHorizontal()) {
13144 innerDimension = me.width;
13145 value = reverse ? me.right - pixel : pixel - me.left;
13146 } else {
13147 innerDimension = me.height;
13148 value = reverse ? pixel - me.top : me.bottom - pixel;
13149 }
13150 if (value !== start) {
13151 if (start === 0) { // include zero tick
13152 var offset = helpers.getValueOrDefault(
13153 me.options.ticks.fontSize,
13154 Chart.defaults.global.defaultFontSize
13155 );
13156 value -= offset;
13157 innerDimension -= offset;
13158 start = firstTickValue;
13159 }
13160 value *= log10(end) - log10(start);
13161 value /= innerDimension;
13162 value = Math.pow(10, log10(start) + value);
13163 }
13164 return value;
13165 }
13166 });
13167
13168 scaleService.registerScaleType('logarithmic', LogarithmicScale, defaultConfig);
13169};
13170
13171},{"29":29,"30":30,"31":31,"42":42}],54:[function(require,module,exports){
13172'use strict';
13173
13174var defaults = require(22);
13175var helpers = require(42);
13176var scaleService = require(30);
13177var Ticks = require(31);
13178
13179module.exports = function(Chart) {
13180
13181 var globalDefaults = defaults.global;
13182
13183 var defaultConfig = {
13184 display: true,
13185
13186 // Boolean - Whether to animate scaling the chart from the centre
13187 animate: true,
13188 position: 'chartArea',
13189
13190 angleLines: {
13191 display: true,
13192 color: 'rgba(0, 0, 0, 0.1)',
13193 lineWidth: 1,
13194 borderDash: [],
13195 borderDashOffset: 0.0
13196 },
13197
13198 gridLines: {
13199 circular: false
13200 },
13201
13202 // label settings
13203 ticks: {
13204 // Boolean - Show a backdrop to the scale label
13205 showLabelBackdrop: true,
13206
13207 // String - The colour of the label backdrop
13208 backdropColor: 'rgba(255,255,255,0.75)',
13209
13210 // Number - The backdrop padding above & below the label in pixels
13211 backdropPaddingY: 2,
13212
13213 // Number - The backdrop padding to the side of the label in pixels
13214 backdropPaddingX: 2,
13215
13216 callback: Ticks.formatters.linear
13217 },
13218
13219 pointLabels: {
13220 // Boolean - if true, show point labels
13221 display: true,
13222
13223 // Number - Point label font size in pixels
13224 fontSize: 10,
13225
13226 // Function - Used to convert point labels
13227 callback: function(label) {
13228 return label;
13229 }
13230 }
13231 };
13232
13233 function getValueCount(scale) {
13234 var opts = scale.options;
13235 return opts.angleLines.display || opts.pointLabels.display ? scale.chart.data.labels.length : 0;
13236 }
13237
13238 function getPointLabelFontOptions(scale) {
13239 var pointLabelOptions = scale.options.pointLabels;
13240 var fontSize = helpers.valueOrDefault(pointLabelOptions.fontSize, globalDefaults.defaultFontSize);
13241 var fontStyle = helpers.valueOrDefault(pointLabelOptions.fontStyle, globalDefaults.defaultFontStyle);
13242 var fontFamily = helpers.valueOrDefault(pointLabelOptions.fontFamily, globalDefaults.defaultFontFamily);
13243 var font = helpers.fontString(fontSize, fontStyle, fontFamily);
13244
13245 return {
13246 size: fontSize,
13247 style: fontStyle,
13248 family: fontFamily,
13249 font: font
13250 };
13251 }
13252
13253 function getTickFontSize(scale) {
13254 var opts = scale.options;
13255 var tickOpts = opts.ticks;
13256
13257 if (tickOpts.display && opts.display) {
13258 return helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
13259 }
13260 return 0;
13261 }
13262
13263 function measureLabelSize(ctx, fontSize, label) {
13264 if (helpers.isArray(label)) {
13265 return {
13266 w: helpers.longestText(ctx, ctx.font, label),
13267 h: (label.length * fontSize) + ((label.length - 1) * 1.5 * fontSize)
13268 };
13269 }
13270
13271 return {
13272 w: ctx.measureText(label).width,
13273 h: fontSize
13274 };
13275 }
13276
13277 function determineLimits(angle, pos, size, min, max) {
13278 if (angle === min || angle === max) {
13279 return {
13280 start: pos - (size / 2),
13281 end: pos + (size / 2)
13282 };
13283 } else if (angle < min || angle > max) {
13284 return {
13285 start: pos - size - 5,
13286 end: pos
13287 };
13288 }
13289
13290 return {
13291 start: pos,
13292 end: pos + size + 5
13293 };
13294 }
13295
13296 /**
13297 * Helper function to fit a radial linear scale with point labels
13298 */
13299 function fitWithPointLabels(scale) {
13300 /*
13301 * Right, this is really confusing and there is a lot of maths going on here
13302 * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
13303 *
13304 * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
13305 *
13306 * Solution:
13307 *
13308 * We assume the radius of the polygon is half the size of the canvas at first
13309 * at each index we check if the text overlaps.
13310 *
13311 * Where it does, we store that angle and that index.
13312 *
13313 * After finding the largest index and angle we calculate how much we need to remove
13314 * from the shape radius to move the point inwards by that x.
13315 *
13316 * We average the left and right distances to get the maximum shape radius that can fit in the box
13317 * along with labels.
13318 *
13319 * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
13320 * on each side, removing that from the size, halving it and adding the left x protrusion width.
13321 *
13322 * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
13323 * and position it in the most space efficient manner
13324 *
13325 * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
13326 */
13327
13328 var plFont = getPointLabelFontOptions(scale);
13329 var paddingTop = getTickFontSize(scale) / 2;
13330
13331 // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
13332 // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
13333 var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
13334 var furthestLimits = {
13335 r: scale.width,
13336 l: 0,
13337 t: scale.height,
13338 b: 0
13339 };
13340 var furthestAngles = {};
13341 var i, textSize, pointPosition;
13342
13343 scale.ctx.font = plFont.font;
13344 scale._pointLabelSizes = [];
13345
13346 var valueCount = getValueCount(scale);
13347 for (i = 0; i < valueCount; i++) {
13348 pointPosition = scale.getPointPosition(i, largestPossibleRadius);
13349 textSize = measureLabelSize(scale.ctx, plFont.size, scale.pointLabels[i] || '');
13350 scale._pointLabelSizes[i] = textSize;
13351
13352 // Add quarter circle to make degree 0 mean top of circle
13353 var angleRadians = scale.getIndexAngle(i);
13354 var angle = helpers.toDegrees(angleRadians) % 360;
13355 var hLimits = determineLimits(angle, pointPosition.x, textSize.w, 0, 180);
13356 var vLimits = determineLimits(angle, pointPosition.y, textSize.h, 90, 270);
13357
13358 if (hLimits.start < furthestLimits.l) {
13359 furthestLimits.l = hLimits.start;
13360 furthestAngles.l = angleRadians;
13361 }
13362
13363 if (hLimits.end > furthestLimits.r) {
13364 furthestLimits.r = hLimits.end;
13365 furthestAngles.r = angleRadians;
13366 }
13367
13368 if (vLimits.start < furthestLimits.t) {
13369 furthestLimits.t = vLimits.start;
13370 furthestAngles.t = angleRadians;
13371 }
13372
13373 if (vLimits.end > furthestLimits.b) {
13374 furthestLimits.b = vLimits.end;
13375 furthestAngles.b = angleRadians;
13376 }
13377 }
13378
13379 if (paddingTop && -paddingTop < furthestLimits.t) {
13380 furthestLimits.t = -paddingTop;
13381 furthestAngles.t = 0;
13382 }
13383
13384 scale.setReductions(largestPossibleRadius, furthestLimits, furthestAngles);
13385 }
13386
13387 /**
13388 * Helper function to fit a radial linear scale with no point labels
13389 */
13390 function fit(scale) {
13391 var paddingTop = getTickFontSize(scale) / 2;
13392 var largestPossibleRadius = Math.min((scale.height - paddingTop) / 2, scale.width / 2);
13393 scale.drawingArea = Math.floor(largestPossibleRadius);
13394 scale.setCenterPoint(0, 0, paddingTop, 0);
13395 }
13396
13397 function getTextAlignForAngle(angle) {
13398 if (angle === 0 || angle === 180) {
13399 return 'center';
13400 } else if (angle < 180) {
13401 return 'left';
13402 }
13403
13404 return 'right';
13405 }
13406
13407 function fillText(ctx, text, position, fontSize) {
13408 if (helpers.isArray(text)) {
13409 var y = position.y;
13410 var spacing = 1.5 * fontSize;
13411
13412 for (var i = 0; i < text.length; ++i) {
13413 ctx.fillText(text[i], position.x, y);
13414 y += spacing;
13415 }
13416 } else {
13417 ctx.fillText(text, position.x, position.y);
13418 }
13419 }
13420
13421 function adjustPointPositionForLabelHeight(angle, textSize, position) {
13422 if (angle === 90 || angle === 270) {
13423 position.y -= (textSize.h / 2);
13424 } else if (angle > 270 || angle < 90) {
13425 position.y -= textSize.h;
13426 }
13427 }
13428
13429 function drawPointLabels(scale) {
13430 var ctx = scale.ctx;
13431 var opts = scale.options;
13432 var angleLineOpts = opts.angleLines;
13433 var gridLineOpts = opts.gridLines;
13434 var pointLabelOpts = opts.pointLabels;
13435 var lineWidth = helpers.valueOrDefault(angleLineOpts.lineWidth, gridLineOpts.lineWidth);
13436 var lineColor = helpers.valueOrDefault(angleLineOpts.color, gridLineOpts.color);
13437
13438 ctx.save();
13439 ctx.lineWidth = lineWidth;
13440 ctx.strokeStyle = lineColor;
13441 if (ctx.setLineDash) {
13442 ctx.setLineDash(helpers.valueOrDefault(angleLineOpts.borderDash, gridLineOpts.borderDash) || []);
13443 ctx.lineDashOffset = helpers.valueOrDefault(angleLineOpts.borderDashOffset, gridLineOpts.borderDashOffset) || 0.0;
13444 }
13445
13446 var outerDistance = scale.getDistanceFromCenterForValue(opts.ticks.reverse ? scale.min : scale.max);
13447
13448 // Point Label Font
13449 var plFont = getPointLabelFontOptions(scale);
13450
13451 ctx.font = plFont.font;
13452 ctx.textBaseline = 'top';
13453
13454 for (var i = getValueCount(scale) - 1; i >= 0; i--) {
13455 if (angleLineOpts.display && lineWidth && lineColor) {
13456 var outerPosition = scale.getPointPosition(i, outerDistance);
13457 ctx.beginPath();
13458 ctx.moveTo(scale.xCenter, scale.yCenter);
13459 ctx.lineTo(outerPosition.x, outerPosition.y);
13460 ctx.stroke();
13461 }
13462
13463 if (pointLabelOpts.display) {
13464 // Extra 3px out for some label spacing
13465 var pointLabelPosition = scale.getPointPosition(i, outerDistance + 5);
13466
13467 // Keep this in loop since we may support array properties here
13468 var pointLabelFontColor = helpers.valueAtIndexOrDefault(pointLabelOpts.fontColor, i, globalDefaults.defaultFontColor);
13469 ctx.fillStyle = pointLabelFontColor;
13470
13471 var angleRadians = scale.getIndexAngle(i);
13472 var angle = helpers.toDegrees(angleRadians);
13473 ctx.textAlign = getTextAlignForAngle(angle);
13474 adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
13475 fillText(ctx, scale.pointLabels[i] || '', pointLabelPosition, plFont.size);
13476 }
13477 }
13478 ctx.restore();
13479 }
13480
13481 function drawRadiusLine(scale, gridLineOpts, radius, index) {
13482 var ctx = scale.ctx;
13483 var circular = gridLineOpts.circular;
13484 var valueCount = getValueCount(scale);
13485 var lineColor = helpers.valueAtIndexOrDefault(gridLineOpts.color, index - 1);
13486 var lineWidth = helpers.valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
13487 var pointPosition;
13488
13489 if ((!circular && !valueCount) || !lineColor || !lineWidth) {
13490 return;
13491 }
13492
13493 ctx.save();
13494 ctx.strokeStyle = lineColor;
13495 ctx.lineWidth = lineWidth;
13496 if (ctx.setLineDash) {
13497 ctx.setLineDash(gridLineOpts.borderDash || []);
13498 ctx.lineDashOffset = gridLineOpts.borderDashOffset || 0.0;
13499 }
13500
13501 ctx.beginPath();
13502 if (circular) {
13503 // Draw circular arcs between the points
13504 ctx.arc(scale.xCenter, scale.yCenter, radius, 0, Math.PI * 2);
13505 } else {
13506 // Draw straight lines connecting each index
13507 pointPosition = scale.getPointPosition(0, radius);
13508 ctx.moveTo(pointPosition.x, pointPosition.y);
13509
13510 for (var i = 1; i < valueCount; i++) {
13511 pointPosition = scale.getPointPosition(i, radius);
13512 ctx.lineTo(pointPosition.x, pointPosition.y);
13513 }
13514 }
13515 ctx.closePath();
13516 ctx.stroke();
13517 ctx.restore();
13518 }
13519
13520 function numberOrZero(param) {
13521 return helpers.isNumber(param) ? param : 0;
13522 }
13523
13524 var LinearRadialScale = Chart.LinearScaleBase.extend({
13525 setDimensions: function() {
13526 var me = this;
13527 var opts = me.options;
13528 var tickOpts = opts.ticks;
13529 // Set the unconstrained dimension before label rotation
13530 me.width = me.maxWidth;
13531 me.height = me.maxHeight;
13532 me.xCenter = Math.floor(me.width / 2);
13533 me.yCenter = Math.floor(me.height / 2);
13534
13535 var minSize = helpers.min([me.height, me.width]);
13536 var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
13537 me.drawingArea = opts.display ? (minSize / 2) - (tickFontSize / 2 + tickOpts.backdropPaddingY) : (minSize / 2);
13538 },
13539 determineDataLimits: function() {
13540 var me = this;
13541 var chart = me.chart;
13542 var min = Number.POSITIVE_INFINITY;
13543 var max = Number.NEGATIVE_INFINITY;
13544
13545 helpers.each(chart.data.datasets, function(dataset, datasetIndex) {
13546 if (chart.isDatasetVisible(datasetIndex)) {
13547 var meta = chart.getDatasetMeta(datasetIndex);
13548
13549 helpers.each(dataset.data, function(rawValue, index) {
13550 var value = +me.getRightValue(rawValue);
13551 if (isNaN(value) || meta.data[index].hidden) {
13552 return;
13553 }
13554
13555 min = Math.min(value, min);
13556 max = Math.max(value, max);
13557 });
13558 }
13559 });
13560
13561 me.min = (min === Number.POSITIVE_INFINITY ? 0 : min);
13562 me.max = (max === Number.NEGATIVE_INFINITY ? 0 : max);
13563
13564 // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
13565 me.handleTickRangeOptions();
13566 },
13567 getTickLimit: function() {
13568 var tickOpts = this.options.ticks;
13569 var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
13570 return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
13571 },
13572 convertTicksToLabels: function() {
13573 var me = this;
13574
13575 Chart.LinearScaleBase.prototype.convertTicksToLabels.call(me);
13576
13577 // Point labels
13578 me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
13579 },
13580 getLabelForIndex: function(index, datasetIndex) {
13581 return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
13582 },
13583 fit: function() {
13584 if (this.options.pointLabels.display) {
13585 fitWithPointLabels(this);
13586 } else {
13587 fit(this);
13588 }
13589 },
13590 /**
13591 * Set radius reductions and determine new radius and center point
13592 * @private
13593 */
13594 setReductions: function(largestPossibleRadius, furthestLimits, furthestAngles) {
13595 var me = this;
13596 var radiusReductionLeft = furthestLimits.l / Math.sin(furthestAngles.l);
13597 var radiusReductionRight = Math.max(furthestLimits.r - me.width, 0) / Math.sin(furthestAngles.r);
13598 var radiusReductionTop = -furthestLimits.t / Math.cos(furthestAngles.t);
13599 var radiusReductionBottom = -Math.max(furthestLimits.b - me.height, 0) / Math.cos(furthestAngles.b);
13600
13601 radiusReductionLeft = numberOrZero(radiusReductionLeft);
13602 radiusReductionRight = numberOrZero(radiusReductionRight);
13603 radiusReductionTop = numberOrZero(radiusReductionTop);
13604 radiusReductionBottom = numberOrZero(radiusReductionBottom);
13605
13606 me.drawingArea = Math.min(
13607 Math.floor(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2),
13608 Math.floor(largestPossibleRadius - (radiusReductionTop + radiusReductionBottom) / 2));
13609 me.setCenterPoint(radiusReductionLeft, radiusReductionRight, radiusReductionTop, radiusReductionBottom);
13610 },
13611 setCenterPoint: function(leftMovement, rightMovement, topMovement, bottomMovement) {
13612 var me = this;
13613 var maxRight = me.width - rightMovement - me.drawingArea;
13614 var maxLeft = leftMovement + me.drawingArea;
13615 var maxTop = topMovement + me.drawingArea;
13616 var maxBottom = me.height - bottomMovement - me.drawingArea;
13617
13618 me.xCenter = Math.floor(((maxLeft + maxRight) / 2) + me.left);
13619 me.yCenter = Math.floor(((maxTop + maxBottom) / 2) + me.top);
13620 },
13621
13622 getIndexAngle: function(index) {
13623 var angleMultiplier = (Math.PI * 2) / getValueCount(this);
13624 var startAngle = this.chart.options && this.chart.options.startAngle ?
13625 this.chart.options.startAngle :
13626 0;
13627
13628 var startAngleRadians = startAngle * Math.PI * 2 / 360;
13629
13630 // Start from the top instead of right, so remove a quarter of the circle
13631 return index * angleMultiplier + startAngleRadians;
13632 },
13633 getDistanceFromCenterForValue: function(value) {
13634 var me = this;
13635
13636 if (value === null) {
13637 return 0; // null always in center
13638 }
13639
13640 // Take into account half font size + the yPadding of the top value
13641 var scalingFactor = me.drawingArea / (me.max - me.min);
13642 if (me.options.ticks.reverse) {
13643 return (me.max - value) * scalingFactor;
13644 }
13645 return (value - me.min) * scalingFactor;
13646 },
13647 getPointPosition: function(index, distanceFromCenter) {
13648 var me = this;
13649 var thisAngle = me.getIndexAngle(index) - (Math.PI / 2);
13650 return {
13651 x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + me.xCenter,
13652 y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + me.yCenter
13653 };
13654 },
13655 getPointPositionForValue: function(index, value) {
13656 return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
13657 },
13658
13659 getBasePosition: function() {
13660 var me = this;
13661 var min = me.min;
13662 var max = me.max;
13663
13664 return me.getPointPositionForValue(0,
13665 me.beginAtZero ? 0 :
13666 min < 0 && max < 0 ? max :
13667 min > 0 && max > 0 ? min :
13668 0);
13669 },
13670
13671 draw: function() {
13672 var me = this;
13673 var opts = me.options;
13674 var gridLineOpts = opts.gridLines;
13675 var tickOpts = opts.ticks;
13676 var valueOrDefault = helpers.valueOrDefault;
13677
13678 if (opts.display) {
13679 var ctx = me.ctx;
13680 var startAngle = this.getIndexAngle(0);
13681
13682 // Tick Font
13683 var tickFontSize = valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
13684 var tickFontStyle = valueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
13685 var tickFontFamily = valueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
13686 var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
13687
13688 if (opts.angleLines.display || opts.pointLabels.display) {
13689 drawPointLabels(me);
13690 }
13691
13692 helpers.each(me.ticks, function(label, index) {
13693 // Don't draw a centre value (if it is minimum)
13694 if (index > 0 || tickOpts.reverse) {
13695 var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
13696
13697 // Draw circular lines around the scale
13698 if (gridLineOpts.display && index !== 0) {
13699 drawRadiusLine(me, gridLineOpts, yCenterOffset, index);
13700 }
13701
13702 if (tickOpts.display) {
13703 var tickFontColor = valueOrDefault(tickOpts.fontColor, globalDefaults.defaultFontColor);
13704 ctx.font = tickLabelFont;
13705
13706 ctx.save();
13707 ctx.translate(me.xCenter, me.yCenter);
13708 ctx.rotate(startAngle);
13709
13710 if (tickOpts.showLabelBackdrop) {
13711 var labelWidth = ctx.measureText(label).width;
13712 ctx.fillStyle = tickOpts.backdropColor;
13713 ctx.fillRect(
13714 -labelWidth / 2 - tickOpts.backdropPaddingX,
13715 -yCenterOffset - tickFontSize / 2 - tickOpts.backdropPaddingY,
13716 labelWidth + tickOpts.backdropPaddingX * 2,
13717 tickFontSize + tickOpts.backdropPaddingY * 2
13718 );
13719 }
13720
13721 ctx.textAlign = 'center';
13722 ctx.textBaseline = 'middle';
13723 ctx.fillStyle = tickFontColor;
13724 ctx.fillText(label, 0, -yCenterOffset);
13725 ctx.restore();
13726 }
13727 }
13728 });
13729 }
13730 }
13731 });
13732
13733 scaleService.registerScaleType('radialLinear', LinearRadialScale, defaultConfig);
13734};
13735
13736},{"22":22,"30":30,"31":31,"42":42}],55:[function(require,module,exports){
13737/* global window: false */
13738'use strict';
13739
13740var moment = require(1);
13741moment = typeof moment === 'function' ? moment : window.moment;
13742
13743var defaults = require(22);
13744var helpers = require(42);
13745var Scale = require(29);
13746var scaleService = require(30);
13747
13748// Integer constants are from the ES6 spec.
13749var MIN_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
13750var MAX_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
13751
13752var INTERVALS = {
13753 millisecond: {
13754 common: true,
13755 size: 1,
13756 steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
13757 },
13758 second: {
13759 common: true,
13760 size: 1000,
13761 steps: [1, 2, 5, 10, 15, 30]
13762 },
13763 minute: {
13764 common: true,
13765 size: 60000,
13766 steps: [1, 2, 5, 10, 15, 30]
13767 },
13768 hour: {
13769 common: true,
13770 size: 3600000,
13771 steps: [1, 2, 3, 6, 12]
13772 },
13773 day: {
13774 common: true,
13775 size: 86400000,
13776 steps: [1, 2, 5]
13777 },
13778 week: {
13779 common: false,
13780 size: 604800000,
13781 steps: [1, 2, 3, 4]
13782 },
13783 month: {
13784 common: true,
13785 size: 2.628e9,
13786 steps: [1, 2, 3]
13787 },
13788 quarter: {
13789 common: false,
13790 size: 7.884e9,
13791 steps: [1, 2, 3, 4]
13792 },
13793 year: {
13794 common: true,
13795 size: 3.154e10
13796 }
13797};
13798
13799var UNITS = Object.keys(INTERVALS);
13800
13801function sorter(a, b) {
13802 return a - b;
13803}
13804
13805function arrayUnique(items) {
13806 var hash = {};
13807 var out = [];
13808 var i, ilen, item;
13809
13810 for (i = 0, ilen = items.length; i < ilen; ++i) {
13811 item = items[i];
13812 if (!hash[item]) {
13813 hash[item] = true;
13814 out.push(item);
13815 }
13816 }
13817
13818 return out;
13819}
13820
13821/**
13822 * Returns an array of {time, pos} objects used to interpolate a specific `time` or position
13823 * (`pos`) on the scale, by searching entries before and after the requested value. `pos` is
13824 * a decimal between 0 and 1: 0 being the start of the scale (left or top) and 1 the other
13825 * extremity (left + width or top + height). Note that it would be more optimized to directly
13826 * store pre-computed pixels, but the scale dimensions are not guaranteed at the time we need
13827 * to create the lookup table. The table ALWAYS contains at least two items: min and max.
13828 *
13829 * @param {Number[]} timestamps - timestamps sorted from lowest to highest.
13830 * @param {String} distribution - If 'linear', timestamps will be spread linearly along the min
13831 * and max range, so basically, the table will contains only two items: {min, 0} and {max, 1}.
13832 * If 'series', timestamps will be positioned at the same distance from each other. In this
13833 * case, only timestamps that break the time linearity are registered, meaning that in the
13834 * best case, all timestamps are linear, the table contains only min and max.
13835 */
13836function buildLookupTable(timestamps, min, max, distribution) {
13837 if (distribution === 'linear' || !timestamps.length) {
13838 return [
13839 {time: min, pos: 0},
13840 {time: max, pos: 1}
13841 ];
13842 }
13843
13844 var table = [];
13845 var items = [min];
13846 var i, ilen, prev, curr, next;
13847
13848 for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
13849 curr = timestamps[i];
13850 if (curr > min && curr < max) {
13851 items.push(curr);
13852 }
13853 }
13854
13855 items.push(max);
13856
13857 for (i = 0, ilen = items.length; i < ilen; ++i) {
13858 next = items[i + 1];
13859 prev = items[i - 1];
13860 curr = items[i];
13861
13862 // only add points that breaks the scale linearity
13863 if (prev === undefined || next === undefined || Math.round((next + prev) / 2) !== curr) {
13864 table.push({time: curr, pos: i / (ilen - 1)});
13865 }
13866 }
13867
13868 return table;
13869}
13870
13871// @see adapted from http://www.anujgakhar.com/2014/03/01/binary-search-in-javascript/
13872function lookup(table, key, value) {
13873 var lo = 0;
13874 var hi = table.length - 1;
13875 var mid, i0, i1;
13876
13877 while (lo >= 0 && lo <= hi) {
13878 mid = (lo + hi) >> 1;
13879 i0 = table[mid - 1] || null;
13880 i1 = table[mid];
13881
13882 if (!i0) {
13883 // given value is outside table (before first item)
13884 return {lo: null, hi: i1};
13885 } else if (i1[key] < value) {
13886 lo = mid + 1;
13887 } else if (i0[key] > value) {
13888 hi = mid - 1;
13889 } else {
13890 return {lo: i0, hi: i1};
13891 }
13892 }
13893
13894 // given value is outside table (after last item)
13895 return {lo: i1, hi: null};
13896}
13897
13898/**
13899 * Linearly interpolates the given source `value` using the table items `skey` values and
13900 * returns the associated `tkey` value. For example, interpolate(table, 'time', 42, 'pos')
13901 * returns the position for a timestamp equal to 42. If value is out of bounds, values at
13902 * index [0, 1] or [n - 1, n] are used for the interpolation.
13903 */
13904function interpolate(table, skey, sval, tkey) {
13905 var range = lookup(table, skey, sval);
13906
13907 // Note: the lookup table ALWAYS contains at least 2 items (min and max)
13908 var prev = !range.lo ? table[0] : !range.hi ? table[table.length - 2] : range.lo;
13909 var next = !range.lo ? table[1] : !range.hi ? table[table.length - 1] : range.hi;
13910
13911 var span = next[skey] - prev[skey];
13912 var ratio = span ? (sval - prev[skey]) / span : 0;
13913 var offset = (next[tkey] - prev[tkey]) * ratio;
13914
13915 return prev[tkey] + offset;
13916}
13917
13918/**
13919 * Convert the given value to a moment object using the given time options.
13920 * @see http://momentjs.com/docs/#/parsing/
13921 */
13922function momentify(value, options) {
13923 var parser = options.parser;
13924 var format = options.parser || options.format;
13925
13926 if (typeof parser === 'function') {
13927 return parser(value);
13928 }
13929
13930 if (typeof value === 'string' && typeof format === 'string') {
13931 return moment(value, format);
13932 }
13933
13934 if (!(value instanceof moment)) {
13935 value = moment(value);
13936 }
13937
13938 if (value.isValid()) {
13939 return value;
13940 }
13941
13942 // Labels are in an incompatible moment format and no `parser` has been provided.
13943 // The user might still use the deprecated `format` option to convert his inputs.
13944 if (typeof format === 'function') {
13945 return format(value);
13946 }
13947
13948 return value;
13949}
13950
13951function parse(input, scale) {
13952 if (helpers.isNullOrUndef(input)) {
13953 return null;
13954 }
13955
13956 var options = scale.options.time;
13957 var value = momentify(scale.getRightValue(input), options);
13958 if (!value.isValid()) {
13959 return null;
13960 }
13961
13962 if (options.round) {
13963 value.startOf(options.round);
13964 }
13965
13966 return value.valueOf();
13967}
13968
13969/**
13970 * Returns the number of unit to skip to be able to display up to `capacity` number of ticks
13971 * in `unit` for the given `min` / `max` range and respecting the interval steps constraints.
13972 */
13973function determineStepSize(min, max, unit, capacity) {
13974 var range = max - min;
13975 var interval = INTERVALS[unit];
13976 var milliseconds = interval.size;
13977 var steps = interval.steps;
13978 var i, ilen, factor;
13979
13980 if (!steps) {
13981 return Math.ceil(range / (capacity * milliseconds));
13982 }
13983
13984 for (i = 0, ilen = steps.length; i < ilen; ++i) {
13985 factor = steps[i];
13986 if (Math.ceil(range / (milliseconds * factor)) <= capacity) {
13987 break;
13988 }
13989 }
13990
13991 return factor;
13992}
13993
13994/**
13995 * Figures out what unit results in an appropriate number of auto-generated ticks
13996 */
13997function determineUnitForAutoTicks(minUnit, min, max, capacity) {
13998 var ilen = UNITS.length;
13999 var i, interval, factor;
14000
14001 for (i = UNITS.indexOf(minUnit); i < ilen - 1; ++i) {
14002 interval = INTERVALS[UNITS[i]];
14003 factor = interval.steps ? interval.steps[interval.steps.length - 1] : MAX_INTEGER;
14004
14005 if (interval.common && Math.ceil((max - min) / (factor * interval.size)) <= capacity) {
14006 return UNITS[i];
14007 }
14008 }
14009
14010 return UNITS[ilen - 1];
14011}
14012
14013/**
14014 * Figures out what unit to format a set of ticks with
14015 */
14016function determineUnitForFormatting(ticks, minUnit, min, max) {
14017 var duration = moment.duration(moment(max).diff(moment(min)));
14018 var ilen = UNITS.length;
14019 var i, unit;
14020
14021 for (i = ilen - 1; i >= UNITS.indexOf(minUnit); i--) {
14022 unit = UNITS[i];
14023 if (INTERVALS[unit].common && duration.as(unit) >= ticks.length) {
14024 return unit;
14025 }
14026 }
14027
14028 return UNITS[minUnit ? UNITS.indexOf(minUnit) : 0];
14029}
14030
14031function determineMajorUnit(unit) {
14032 for (var i = UNITS.indexOf(unit) + 1, ilen = UNITS.length; i < ilen; ++i) {
14033 if (INTERVALS[UNITS[i]].common) {
14034 return UNITS[i];
14035 }
14036 }
14037}
14038
14039/**
14040 * Generates a maximum of `capacity` timestamps between min and max, rounded to the
14041 * `minor` unit, aligned on the `major` unit and using the given scale time `options`.
14042 * Important: this method can return ticks outside the min and max range, it's the
14043 * responsibility of the calling code to clamp values if needed.
14044 */
14045function generate(min, max, capacity, options) {
14046 var timeOpts = options.time;
14047 var minor = timeOpts.unit || determineUnitForAutoTicks(timeOpts.minUnit, min, max, capacity);
14048 var major = determineMajorUnit(minor);
14049 var stepSize = helpers.valueOrDefault(timeOpts.stepSize, timeOpts.unitStepSize);
14050 var weekday = minor === 'week' ? timeOpts.isoWeekday : false;
14051 var majorTicksEnabled = options.ticks.major.enabled;
14052 var interval = INTERVALS[minor];
14053 var first = moment(min);
14054 var last = moment(max);
14055 var ticks = [];
14056 var time;
14057
14058 if (!stepSize) {
14059 stepSize = determineStepSize(min, max, minor, capacity);
14060 }
14061
14062 // For 'week' unit, handle the first day of week option
14063 if (weekday) {
14064 first = first.isoWeekday(weekday);
14065 last = last.isoWeekday(weekday);
14066 }
14067
14068 // Align first/last ticks on unit
14069 first = first.startOf(weekday ? 'day' : minor);
14070 last = last.startOf(weekday ? 'day' : minor);
14071
14072 // Make sure that the last tick include max
14073 if (last < max) {
14074 last.add(1, minor);
14075 }
14076
14077 time = moment(first);
14078
14079 if (majorTicksEnabled && major && !weekday && !timeOpts.round) {
14080 // Align the first tick on the previous `minor` unit aligned on the `major` unit:
14081 // we first aligned time on the previous `major` unit then add the number of full
14082 // stepSize there is between first and the previous major time.
14083 time.startOf(major);
14084 time.add(~~((first - time) / (interval.size * stepSize)) * stepSize, minor);
14085 }
14086
14087 for (; time < last; time.add(stepSize, minor)) {
14088 ticks.push(+time);
14089 }
14090
14091 ticks.push(+time);
14092
14093 return ticks;
14094}
14095
14096/**
14097 * Returns the right and left offsets from edges in the form of {left, right}.
14098 * Offsets are added when the `offset` option is true.
14099 */
14100function computeOffsets(table, ticks, min, max, options) {
14101 var left = 0;
14102 var right = 0;
14103 var upper, lower;
14104
14105 if (options.offset && ticks.length) {
14106 if (!options.time.min) {
14107 upper = ticks.length > 1 ? ticks[1] : max;
14108 lower = ticks[0];
14109 left = (
14110 interpolate(table, 'time', upper, 'pos') -
14111 interpolate(table, 'time', lower, 'pos')
14112 ) / 2;
14113 }
14114 if (!options.time.max) {
14115 upper = ticks[ticks.length - 1];
14116 lower = ticks.length > 1 ? ticks[ticks.length - 2] : min;
14117 right = (
14118 interpolate(table, 'time', upper, 'pos') -
14119 interpolate(table, 'time', lower, 'pos')
14120 ) / 2;
14121 }
14122 }
14123
14124 return {left: left, right: right};
14125}
14126
14127function ticksFromTimestamps(values, majorUnit) {
14128 var ticks = [];
14129 var i, ilen, value, major;
14130
14131 for (i = 0, ilen = values.length; i < ilen; ++i) {
14132 value = values[i];
14133 major = majorUnit ? value === +moment(value).startOf(majorUnit) : false;
14134
14135 ticks.push({
14136 value: value,
14137 major: major
14138 });
14139 }
14140
14141 return ticks;
14142}
14143
14144function determineLabelFormat(data, timeOpts) {
14145 var i, momentDate, hasTime;
14146 var ilen = data.length;
14147
14148 // find the label with the most parts (milliseconds, minutes, etc.)
14149 // format all labels with the same level of detail as the most specific label
14150 for (i = 0; i < ilen; i++) {
14151 momentDate = momentify(data[i], timeOpts);
14152 if (momentDate.millisecond() !== 0) {
14153 return 'MMM D, YYYY h:mm:ss.SSS a';
14154 }
14155 if (momentDate.second() !== 0 || momentDate.minute() !== 0 || momentDate.hour() !== 0) {
14156 hasTime = true;
14157 }
14158 }
14159 if (hasTime) {
14160 return 'MMM D, YYYY h:mm:ss a';
14161 }
14162 return 'MMM D, YYYY';
14163}
14164
14165module.exports = function() {
14166
14167 var defaultConfig = {
14168 position: 'bottom',
14169
14170 /**
14171 * Data distribution along the scale:
14172 * - 'linear': data are spread according to their time (distances can vary),
14173 * - 'series': data are spread at the same distance from each other.
14174 * @see https://github.com/chartjs/Chart.js/pull/4507
14175 * @since 2.7.0
14176 */
14177 distribution: 'linear',
14178
14179 /**
14180 * Scale boundary strategy (bypassed by min/max time options)
14181 * - `data`: make sure data are fully visible, ticks outside are removed
14182 * - `ticks`: make sure ticks are fully visible, data outside are truncated
14183 * @see https://github.com/chartjs/Chart.js/pull/4556
14184 * @since 2.7.0
14185 */
14186 bounds: 'data',
14187
14188 time: {
14189 parser: false, // false == a pattern string from http://momentjs.com/docs/#/parsing/string-format/ or a custom callback that converts its argument to a moment
14190 format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
14191 unit: false, // false == automatic or override with week, month, year, etc.
14192 round: false, // none, or override with week, month, year, etc.
14193 displayFormat: false, // DEPRECATED
14194 isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
14195 minUnit: 'millisecond',
14196
14197 // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
14198 displayFormats: {
14199 millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM,
14200 second: 'h:mm:ss a', // 11:20:01 AM
14201 minute: 'h:mm a', // 11:20 AM
14202 hour: 'hA', // 5PM
14203 day: 'MMM D', // Sep 4
14204 week: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
14205 month: 'MMM YYYY', // Sept 2015
14206 quarter: '[Q]Q - YYYY', // Q3
14207 year: 'YYYY' // 2015
14208 },
14209 },
14210 ticks: {
14211 autoSkip: false,
14212
14213 /**
14214 * Ticks generation input values:
14215 * - 'auto': generates "optimal" ticks based on scale size and time options.
14216 * - 'data': generates ticks from data (including labels from data {t|x|y} objects).
14217 * - 'labels': generates ticks from user given `data.labels` values ONLY.
14218 * @see https://github.com/chartjs/Chart.js/pull/4507
14219 * @since 2.7.0
14220 */
14221 source: 'auto',
14222
14223 major: {
14224 enabled: false
14225 }
14226 }
14227 };
14228
14229 var TimeScale = Scale.extend({
14230 initialize: function() {
14231 if (!moment) {
14232 throw new Error('Chart.js - Moment.js could not be found! You must include it before Chart.js to use the time scale. Download at https://momentjs.com');
14233 }
14234
14235 this.mergeTicksOptions();
14236
14237 Scale.prototype.initialize.call(this);
14238 },
14239
14240 update: function() {
14241 var me = this;
14242 var options = me.options;
14243
14244 // DEPRECATIONS: output a message only one time per update
14245 if (options.time && options.time.format) {
14246 console.warn('options.time.format is deprecated and replaced by options.time.parser.');
14247 }
14248
14249 return Scale.prototype.update.apply(me, arguments);
14250 },
14251
14252 /**
14253 * Allows data to be referenced via 't' attribute
14254 */
14255 getRightValue: function(rawValue) {
14256 if (rawValue && rawValue.t !== undefined) {
14257 rawValue = rawValue.t;
14258 }
14259 return Scale.prototype.getRightValue.call(this, rawValue);
14260 },
14261
14262 determineDataLimits: function() {
14263 var me = this;
14264 var chart = me.chart;
14265 var timeOpts = me.options.time;
14266 var unit = timeOpts.unit || 'day';
14267 var min = MAX_INTEGER;
14268 var max = MIN_INTEGER;
14269 var timestamps = [];
14270 var datasets = [];
14271 var labels = [];
14272 var i, j, ilen, jlen, data, timestamp;
14273 var dataLabels = chart.data.labels || [];
14274
14275 // Convert labels to timestamps
14276 for (i = 0, ilen = dataLabels.length; i < ilen; ++i) {
14277 labels.push(parse(dataLabels[i], me));
14278 }
14279
14280 // Convert data to timestamps
14281 for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
14282 if (chart.isDatasetVisible(i)) {
14283 data = chart.data.datasets[i].data;
14284
14285 // Let's consider that all data have the same format.
14286 if (helpers.isObject(data[0])) {
14287 datasets[i] = [];
14288
14289 for (j = 0, jlen = data.length; j < jlen; ++j) {
14290 timestamp = parse(data[j], me);
14291 timestamps.push(timestamp);
14292 datasets[i][j] = timestamp;
14293 }
14294 } else {
14295 timestamps.push.apply(timestamps, labels);
14296 datasets[i] = labels.slice(0);
14297 }
14298 } else {
14299 datasets[i] = [];
14300 }
14301 }
14302
14303 if (labels.length) {
14304 // Sort labels **after** data have been converted
14305 labels = arrayUnique(labels).sort(sorter);
14306 min = Math.min(min, labels[0]);
14307 max = Math.max(max, labels[labels.length - 1]);
14308 }
14309
14310 if (timestamps.length) {
14311 timestamps = arrayUnique(timestamps).sort(sorter);
14312 min = Math.min(min, timestamps[0]);
14313 max = Math.max(max, timestamps[timestamps.length - 1]);
14314 }
14315
14316 min = parse(timeOpts.min, me) || min;
14317 max = parse(timeOpts.max, me) || max;
14318
14319 // In case there is no valid min/max, set limits based on unit time option
14320 min = min === MAX_INTEGER ? +moment().startOf(unit) : min;
14321 max = max === MIN_INTEGER ? +moment().endOf(unit) + 1 : max;
14322
14323 // Make sure that max is strictly higher than min (required by the lookup table)
14324 me.min = Math.min(min, max);
14325 me.max = Math.max(min + 1, max);
14326
14327 // PRIVATE
14328 me._horizontal = me.isHorizontal();
14329 me._table = [];
14330 me._timestamps = {
14331 data: timestamps,
14332 datasets: datasets,
14333 labels: labels
14334 };
14335 },
14336
14337 buildTicks: function() {
14338 var me = this;
14339 var min = me.min;
14340 var max = me.max;
14341 var options = me.options;
14342 var timeOpts = options.time;
14343 var timestamps = [];
14344 var ticks = [];
14345 var i, ilen, timestamp;
14346
14347 switch (options.ticks.source) {
14348 case 'data':
14349 timestamps = me._timestamps.data;
14350 break;
14351 case 'labels':
14352 timestamps = me._timestamps.labels;
14353 break;
14354 case 'auto':
14355 default:
14356 timestamps = generate(min, max, me.getLabelCapacity(min), options);
14357 }
14358
14359 if (options.bounds === 'ticks' && timestamps.length) {
14360 min = timestamps[0];
14361 max = timestamps[timestamps.length - 1];
14362 }
14363
14364 // Enforce limits with user min/max options
14365 min = parse(timeOpts.min, me) || min;
14366 max = parse(timeOpts.max, me) || max;
14367
14368 // Remove ticks outside the min/max range
14369 for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
14370 timestamp = timestamps[i];
14371 if (timestamp >= min && timestamp <= max) {
14372 ticks.push(timestamp);
14373 }
14374 }
14375
14376 me.min = min;
14377 me.max = max;
14378
14379 // PRIVATE
14380 me._unit = timeOpts.unit || determineUnitForFormatting(ticks, timeOpts.minUnit, me.min, me.max);
14381 me._majorUnit = determineMajorUnit(me._unit);
14382 me._table = buildLookupTable(me._timestamps.data, min, max, options.distribution);
14383 me._offsets = computeOffsets(me._table, ticks, min, max, options);
14384 me._labelFormat = determineLabelFormat(me._timestamps.data, timeOpts);
14385
14386 return ticksFromTimestamps(ticks, me._majorUnit);
14387 },
14388
14389 getLabelForIndex: function(index, datasetIndex) {
14390 var me = this;
14391 var data = me.chart.data;
14392 var timeOpts = me.options.time;
14393 var label = data.labels && index < data.labels.length ? data.labels[index] : '';
14394 var value = data.datasets[datasetIndex].data[index];
14395
14396 if (helpers.isObject(value)) {
14397 label = me.getRightValue(value);
14398 }
14399 if (timeOpts.tooltipFormat) {
14400 return momentify(label, timeOpts).format(timeOpts.tooltipFormat);
14401 }
14402 if (typeof label === 'string') {
14403 return label;
14404 }
14405
14406 return momentify(label, timeOpts).format(me._labelFormat);
14407 },
14408
14409 /**
14410 * Function to format an individual tick mark
14411 * @private
14412 */
14413 tickFormatFunction: function(tick, index, ticks, formatOverride) {
14414 var me = this;
14415 var options = me.options;
14416 var time = tick.valueOf();
14417 var formats = options.time.displayFormats;
14418 var minorFormat = formats[me._unit];
14419 var majorUnit = me._majorUnit;
14420 var majorFormat = formats[majorUnit];
14421 var majorTime = tick.clone().startOf(majorUnit).valueOf();
14422 var majorTickOpts = options.ticks.major;
14423 var major = majorTickOpts.enabled && majorUnit && majorFormat && time === majorTime;
14424 var label = tick.format(formatOverride ? formatOverride : major ? majorFormat : minorFormat);
14425 var tickOpts = major ? majorTickOpts : options.ticks.minor;
14426 var formatter = helpers.valueOrDefault(tickOpts.callback, tickOpts.userCallback);
14427
14428 return formatter ? formatter(label, index, ticks) : label;
14429 },
14430
14431 convertTicksToLabels: function(ticks) {
14432 var labels = [];
14433 var i, ilen;
14434
14435 for (i = 0, ilen = ticks.length; i < ilen; ++i) {
14436 labels.push(this.tickFormatFunction(moment(ticks[i].value), i, ticks));
14437 }
14438
14439 return labels;
14440 },
14441
14442 /**
14443 * @private
14444 */
14445 getPixelForOffset: function(time) {
14446 var me = this;
14447 var size = me._horizontal ? me.width : me.height;
14448 var start = me._horizontal ? me.left : me.top;
14449 var pos = interpolate(me._table, 'time', time, 'pos');
14450
14451 return start + size * (me._offsets.left + pos) / (me._offsets.left + 1 + me._offsets.right);
14452 },
14453
14454 getPixelForValue: function(value, index, datasetIndex) {
14455 var me = this;
14456 var time = null;
14457
14458 if (index !== undefined && datasetIndex !== undefined) {
14459 time = me._timestamps.datasets[datasetIndex][index];
14460 }
14461
14462 if (time === null) {
14463 time = parse(value, me);
14464 }
14465
14466 if (time !== null) {
14467 return me.getPixelForOffset(time);
14468 }
14469 },
14470
14471 getPixelForTick: function(index) {
14472 var ticks = this.getTicks();
14473 return index >= 0 && index < ticks.length ?
14474 this.getPixelForOffset(ticks[index].value) :
14475 null;
14476 },
14477
14478 getValueForPixel: function(pixel) {
14479 var me = this;
14480 var size = me._horizontal ? me.width : me.height;
14481 var start = me._horizontal ? me.left : me.top;
14482 var pos = (size ? (pixel - start) / size : 0) * (me._offsets.left + 1 + me._offsets.left) - me._offsets.right;
14483 var time = interpolate(me._table, 'pos', pos, 'time');
14484
14485 return moment(time);
14486 },
14487
14488 /**
14489 * Crude approximation of what the label width might be
14490 * @private
14491 */
14492 getLabelWidth: function(label) {
14493 var me = this;
14494 var ticksOpts = me.options.ticks;
14495 var tickLabelWidth = me.ctx.measureText(label).width;
14496 var angle = helpers.toRadians(ticksOpts.maxRotation);
14497 var cosRotation = Math.cos(angle);
14498 var sinRotation = Math.sin(angle);
14499 var tickFontSize = helpers.valueOrDefault(ticksOpts.fontSize, defaults.global.defaultFontSize);
14500
14501 return (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
14502 },
14503
14504 /**
14505 * @private
14506 */
14507 getLabelCapacity: function(exampleTime) {
14508 var me = this;
14509
14510 var formatOverride = me.options.time.displayFormats.millisecond; // Pick the longest format for guestimation
14511
14512 var exampleLabel = me.tickFormatFunction(moment(exampleTime), 0, [], formatOverride);
14513 var tickLabelWidth = me.getLabelWidth(exampleLabel);
14514 var innerWidth = me.isHorizontal() ? me.width : me.height;
14515
14516 var capacity = Math.floor(innerWidth / tickLabelWidth);
14517 return capacity > 0 ? capacity : 1;
14518 }
14519 });
14520
14521 scaleService.registerScaleType('time', TimeScale, defaultConfig);
14522};
14523
14524},{"1":1,"22":22,"29":29,"30":30,"42":42}]},{},[7])(7)
14525});