chartkickm 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2266 @@
1
+ /*
2
+ * Chartkick.js
3
+ * Create beautiful charts with one line of JavaScript
4
+ * https://github.com/ankane/chartkick.js
5
+ * v3.0.2
6
+ * MIT License
7
+ */
8
+
9
+ (function (global, factory) {
10
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
11
+ typeof define === 'function' && define.amd ? define(factory) :
12
+ (global.Chartkick = factory());
13
+ }(this, (function () { 'use strict';
14
+
15
+ function isArray(variable) {
16
+ return Object.prototype.toString.call(variable) === "[object Array]";
17
+ }
18
+
19
+ function isFunction(variable) {
20
+ return variable instanceof Function;
21
+ }
22
+
23
+ function isPlainObject(variable) {
24
+ return !isFunction(variable) && variable instanceof Object;
25
+ }
26
+
27
+ // https://github.com/madrobby/zepto/blob/master/src/zepto.js
28
+ function extend(target, source) {
29
+ var key;
30
+ for (key in source) {
31
+ if (isPlainObject(source[key]) || isArray(source[key])) {
32
+ if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
33
+ target[key] = {};
34
+ }
35
+ if (isArray(source[key]) && !isArray(target[key])) {
36
+ target[key] = [];
37
+ }
38
+ extend(target[key], source[key]);
39
+ } else if (source[key] !== undefined) {
40
+ target[key] = source[key];
41
+ }
42
+ }
43
+ }
44
+
45
+ function merge(obj1, obj2) {
46
+ var target = {};
47
+ extend(target, obj1);
48
+ extend(target, obj2);
49
+ return target;
50
+ }
51
+
52
+ var DATE_PATTERN = /^(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)$/i;
53
+
54
+ // https://github.com/Do/iso8601.js
55
+ var ISO8601_PATTERN = /(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)?(:)?(\d\d)?([.,]\d+)?($|Z|([+-])(\d\d)(:)?(\d\d)?)/i;
56
+ var DECIMAL_SEPARATOR = String(1.5).charAt(1);
57
+
58
+ function parseISO8601(input) {
59
+ var day, hour, matches, milliseconds, minutes, month, offset, result, seconds, type, year;
60
+ type = Object.prototype.toString.call(input);
61
+ if (type === "[object Date]") {
62
+ return input;
63
+ }
64
+ if (type !== "[object String]") {
65
+ return;
66
+ }
67
+ matches = input.match(ISO8601_PATTERN);
68
+ if (matches) {
69
+ year = parseInt(matches[1], 10);
70
+ month = parseInt(matches[3], 10) - 1;
71
+ day = parseInt(matches[5], 10);
72
+ hour = parseInt(matches[7], 10);
73
+ minutes = matches[9] ? parseInt(matches[9], 10) : 0;
74
+ seconds = matches[11] ? parseInt(matches[11], 10) : 0;
75
+ milliseconds = matches[12] ? parseFloat(DECIMAL_SEPARATOR + matches[12].slice(1)) * 1000 : 0;
76
+ result = Date.UTC(year, month, day, hour, minutes, seconds, milliseconds);
77
+ if (matches[13] && matches[14]) {
78
+ offset = matches[15] * 60;
79
+ if (matches[17]) {
80
+ offset += parseInt(matches[17], 10);
81
+ }
82
+ offset *= matches[14] === "-" ? -1 : 1;
83
+ result -= offset * 60 * 1000;
84
+ }
85
+ return new Date(result);
86
+ }
87
+ }
88
+ // end iso8601.js
89
+
90
+ function negativeValues(series) {
91
+ var i, j, data;
92
+ for (i = 0; i < series.length; i++) {
93
+ data = series[i].data;
94
+ for (j = 0; j < data.length; j++) {
95
+ if (data[j][1] < 0) {
96
+ return true;
97
+ }
98
+ }
99
+ }
100
+ return false;
101
+ }
102
+
103
+ function toStr(n) {
104
+ return "" + n;
105
+ }
106
+
107
+ function toFloat(n) {
108
+ return parseFloat(n);
109
+ }
110
+
111
+ function toDate(n) {
112
+ var matches, year, month, day;
113
+ if (typeof n !== "object") {
114
+ if (typeof n === "number") {
115
+ n = new Date(n * 1000); // ms
116
+ } else {
117
+ n = toStr(n);
118
+ if ((matches = n.match(DATE_PATTERN))) {
119
+ year = parseInt(matches[1], 10);
120
+ month = parseInt(matches[3], 10) - 1;
121
+ day = parseInt(matches[5], 10);
122
+ return new Date(year, month, day);
123
+ } else { // str
124
+ // try our best to get the str into iso8601
125
+ // TODO be smarter about this
126
+ var str = n.replace(/ /, "T").replace(" ", "").replace("UTC", "Z");
127
+ n = parseISO8601(str) || new Date(n);
128
+ }
129
+ }
130
+ }
131
+ return n;
132
+ }
133
+
134
+ function toArr(n) {
135
+ if (!isArray(n)) {
136
+ var arr = [], i;
137
+ for (i in n) {
138
+ if (n.hasOwnProperty(i)) {
139
+ arr.push([i, n[i]]);
140
+ }
141
+ }
142
+ n = arr;
143
+ }
144
+ return n;
145
+ }
146
+
147
+ function jsOptionsFunc(defaultOptions, hideLegend, setTitle, setMin, setMax, setStacked, setXtitle, setYtitle) {
148
+ return function (chart, opts, chartOptions) {
149
+ var series = chart.data;
150
+ var options = merge({}, defaultOptions);
151
+ options = merge(options, chartOptions || {});
152
+
153
+ if (chart.hideLegend || "legend" in opts) {
154
+ hideLegend(options, opts.legend, chart.hideLegend);
155
+ }
156
+
157
+ if (opts.title) {
158
+ setTitle(options, opts.title);
159
+ }
160
+
161
+ // min
162
+ if ("min" in opts) {
163
+ setMin(options, opts.min);
164
+ } else if (!negativeValues(series)) {
165
+ setMin(options, 0);
166
+ }
167
+
168
+ // max
169
+ if (opts.max) {
170
+ setMax(options, opts.max);
171
+ }
172
+
173
+ if ("stacked" in opts) {
174
+ setStacked(options, opts.stacked);
175
+ }
176
+
177
+ if (opts.colors) {
178
+ options.colors = opts.colors;
179
+ }
180
+
181
+ if (opts.xtitle) {
182
+ setXtitle(options, opts.xtitle);
183
+ }
184
+
185
+ if (opts.ytitle) {
186
+ setYtitle(options, opts.ytitle);
187
+ }
188
+
189
+ // merge library last
190
+ options = merge(options, opts.library || {});
191
+
192
+ return options;
193
+ };
194
+ }
195
+
196
+ function sortByTime(a, b) {
197
+ return a[0].getTime() - b[0].getTime();
198
+ }
199
+
200
+ function sortByNumberSeries(a, b) {
201
+ return a[0] - b[0];
202
+ }
203
+
204
+ function sortByNumber(a, b) {
205
+ return a - b;
206
+ }
207
+
208
+ function isMinute(d) {
209
+ return d.getMilliseconds() === 0 && d.getSeconds() === 0;
210
+ }
211
+
212
+ function isHour(d) {
213
+ return isMinute(d) && d.getMinutes() === 0;
214
+ }
215
+
216
+ function isDay(d) {
217
+ return isHour(d) && d.getHours() === 0;
218
+ }
219
+
220
+ function isWeek(d, dayOfWeek) {
221
+ return isDay(d) && d.getDay() === dayOfWeek;
222
+ }
223
+
224
+ function isMonth(d) {
225
+ return isDay(d) && d.getDate() === 1;
226
+ }
227
+
228
+ function isYear(d) {
229
+ return isMonth(d) && d.getMonth() === 0;
230
+ }
231
+
232
+ function isDate(obj) {
233
+ return !isNaN(toDate(obj)) && toStr(obj).length >= 6;
234
+ }
235
+
236
+ function isNumber(obj) {
237
+ return typeof obj === "number";
238
+ }
239
+
240
+ function formatValue(pre, value, options) {
241
+ pre = pre || "";
242
+ if (options.prefix) {
243
+ if (value < 0) {
244
+ value = value * -1;
245
+ pre += "-";
246
+ }
247
+ pre += options.prefix;
248
+ }
249
+
250
+ if (options.thousands || options.decimal) {
251
+ value = toStr(value);
252
+ var parts = value.split(".");
253
+ value = parts[0];
254
+ if (options.thousands) {
255
+ value = value.replace(/\B(?=(\d{3})+(?!\d))/g, options.thousands);
256
+ }
257
+ if (parts.length > 1) {
258
+ value += (options.decimal || ".") + parts[1];
259
+ }
260
+ }
261
+
262
+ return pre + value + (options.suffix || "");
263
+ }
264
+
265
+ function seriesOption(chart, series, option) {
266
+ if (option in series) {
267
+ return series[option];
268
+ } else if (option in chart.options) {
269
+ return chart.options[option];
270
+ }
271
+ return null;
272
+ }
273
+
274
+ function allZeros(data) {
275
+ var i, j, d;
276
+ for (i = 0; i < data.length; i++) {
277
+ d = data[i].data;
278
+ for (j = 0; j < d.length; j++) {
279
+ if (d[j][1] != 0) {
280
+ return false;
281
+ }
282
+ }
283
+ }
284
+ return true;
285
+ }
286
+
287
+ var baseOptions = {
288
+ maintainAspectRatio: false,
289
+ animation: false,
290
+ tooltips: {
291
+ displayColors: false,
292
+ callbacks: {}
293
+ },
294
+ legend: {},
295
+ title: {fontSize: 20, fontColor: "#333"}
296
+ };
297
+
298
+ var defaultOptions = {
299
+ scales: {
300
+ yAxes: [
301
+ {
302
+ ticks: {
303
+ maxTicksLimit: 4
304
+ },
305
+ scaleLabel: {
306
+ fontSize: 16,
307
+ // fontStyle: "bold",
308
+ fontColor: "#333"
309
+ }
310
+ }
311
+ ],
312
+ xAxes: [
313
+ {
314
+ gridLines: {
315
+ drawOnChartArea: false
316
+ },
317
+ scaleLabel: {
318
+ fontSize: 16,
319
+ // fontStyle: "bold",
320
+ fontColor: "#333"
321
+ },
322
+ time: {},
323
+ ticks: {}
324
+ }
325
+ ]
326
+ }
327
+ };
328
+
329
+ // http://there4.io/2012/05/02/google-chart-color-list/
330
+ var defaultColors = [
331
+ "#3366CC", "#DC3912", "#FF9900", "#109618", "#990099", "#3B3EAC", "#0099C6",
332
+ "#DD4477", "#66AA00", "#B82E2E", "#316395", "#994499", "#22AA99", "#AAAA11",
333
+ "#6633CC", "#E67300", "#8B0707", "#329262", "#5574A6", "#651067"
334
+ ];
335
+
336
+ var hideLegend = function (options, legend, hideLegend) {
337
+ if (legend !== undefined) {
338
+ options.legend.display = !!legend;
339
+ if (legend && legend !== true) {
340
+ options.legend.position = legend;
341
+ }
342
+ } else if (hideLegend) {
343
+ options.legend.display = false;
344
+ }
345
+ };
346
+
347
+ var setTitle = function (options, title) {
348
+ options.title.display = true;
349
+ options.title.text = title;
350
+ };
351
+
352
+ var setMin = function (options, min) {
353
+ if (min !== null) {
354
+ options.scales.yAxes[0].ticks.min = toFloat(min);
355
+ }
356
+ };
357
+
358
+ var setMax = function (options, max) {
359
+ options.scales.yAxes[0].ticks.max = toFloat(max);
360
+ };
361
+
362
+ var setBarMin = function (options, min) {
363
+ if (min !== null) {
364
+ options.scales.xAxes[0].ticks.min = toFloat(min);
365
+ }
366
+ };
367
+
368
+ var setBarMax = function (options, max) {
369
+ options.scales.xAxes[0].ticks.max = toFloat(max);
370
+ };
371
+
372
+ var setStacked = function (options, stacked) {
373
+ options.scales.xAxes[0].stacked = !!stacked;
374
+ options.scales.yAxes[0].stacked = !!stacked;
375
+ };
376
+
377
+ var setXtitle = function (options, title) {
378
+ options.scales.xAxes[0].scaleLabel.display = true;
379
+ options.scales.xAxes[0].scaleLabel.labelString = title;
380
+ };
381
+
382
+ var setYtitle = function (options, title) {
383
+ options.scales.yAxes[0].scaleLabel.display = true;
384
+ options.scales.yAxes[0].scaleLabel.labelString = title;
385
+ };
386
+
387
+ // https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
388
+ var addOpacity = function(hex, opacity) {
389
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
390
+ return result ? "rgba(" + parseInt(result[1], 16) + ", " + parseInt(result[2], 16) + ", " + parseInt(result[3], 16) + ", " + opacity + ")" : hex;
391
+ };
392
+
393
+ var setLabelSize = function (chart, data, options) {
394
+ var maxLabelSize = Math.ceil(chart.element.offsetWidth / 4.0 / data.labels.length);
395
+ if (maxLabelSize > 25) {
396
+ maxLabelSize = 25;
397
+ } else if (maxLabelSize < 10) {
398
+ maxLabelSize = 10;
399
+ }
400
+ if (!options.scales.xAxes[0].ticks.callback) {
401
+ options.scales.xAxes[0].ticks.callback = function (value) {
402
+ value = toStr(value);
403
+ if (value.length > maxLabelSize) {
404
+ return value.substring(0, maxLabelSize - 2) + "...";
405
+ } else {
406
+ return value;
407
+ }
408
+ };
409
+ }
410
+ };
411
+
412
+ var setFormatOptions = function(chart, options, chartType) {
413
+ var formatOptions = {
414
+ prefix: chart.options.prefix,
415
+ suffix: chart.options.suffix,
416
+ thousands: chart.options.thousands,
417
+ decimal: chart.options.decimal
418
+ };
419
+
420
+ if (chartType !== "pie") {
421
+ var myAxes = options.scales.yAxes;
422
+ if (chartType === "bar") {
423
+ myAxes = options.scales.xAxes;
424
+ }
425
+
426
+ if (!myAxes[0].ticks.callback) {
427
+ myAxes[0].ticks.callback = function (value) {
428
+ return formatValue("", value, formatOptions);
429
+ };
430
+ }
431
+ }
432
+
433
+ if (!options.tooltips.callbacks.label) {
434
+ if (chartType === "scatter") {
435
+ options.tooltips.callbacks.label = function (item, data) {
436
+ var label = data.datasets[item.datasetIndex].label || '';
437
+ if (label) {
438
+ label += ': ';
439
+ }
440
+ return label + '(' + item.xLabel + ', ' + item.yLabel + ')';
441
+ };
442
+ } else if (chartType === "bubble") {
443
+ options.tooltips.callbacks.label = function (item, data) {
444
+ var label = data.datasets[item.datasetIndex].label || '';
445
+ if (label) {
446
+ label += ': ';
447
+ }
448
+ var dataPoint = data.datasets[item.datasetIndex].data[item.index];
449
+ return label + '(' + item.xLabel + ', ' + item.yLabel + ', ' + dataPoint.v + ')';
450
+ };
451
+ } else if (chartType === "pie") {
452
+ // need to use separate label for pie charts
453
+ options.tooltips.callbacks.label = function (tooltipItem, data) {
454
+ var dataLabel = data.labels[tooltipItem.index];
455
+ var value = ': ';
456
+
457
+ if (isArray(dataLabel)) {
458
+ // show value on first line of multiline label
459
+ // need to clone because we are changing the value
460
+ dataLabel = dataLabel.slice();
461
+ dataLabel[0] += value;
462
+ } else {
463
+ dataLabel += value;
464
+ }
465
+
466
+ return formatValue(dataLabel, data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index], formatOptions);
467
+ };
468
+ } else {
469
+ var valueLabel = chartType === "bar" ? "xLabel" : "yLabel";
470
+ options.tooltips.callbacks.label = function (tooltipItem, data) {
471
+ var label = data.datasets[tooltipItem.datasetIndex].label || '';
472
+ if (label) {
473
+ label += ': ';
474
+ }
475
+ return formatValue(label, tooltipItem[valueLabel], formatOptions);
476
+ };
477
+ }
478
+ }
479
+ };
480
+
481
+ var jsOptions = jsOptionsFunc(merge(baseOptions, defaultOptions), hideLegend, setTitle, setMin, setMax, setStacked, setXtitle, setYtitle);
482
+
483
+ var createDataTable = function (chart, options, chartType) {
484
+ var datasets = [];
485
+ var labels = [];
486
+
487
+ var colors = chart.options.colors || defaultColors;
488
+
489
+ var day = true;
490
+ var week = true;
491
+ var dayOfWeek;
492
+ var month = true;
493
+ var year = true;
494
+ var hour = true;
495
+ var minute = true;
496
+
497
+ var series = chart.data;
498
+
499
+ var max = 0;
500
+ if (chartType === "bubble") {
501
+ for (var i$1 = 0; i$1 < series.length; i$1++) {
502
+ var s$1 = series[i$1];
503
+ for (var j$1 = 0; j$1 < s$1.data.length; j$1++) {
504
+ if (s$1.data[j$1][2] > max) {
505
+ max = s$1.data[j$1][2];
506
+ }
507
+ }
508
+ }
509
+ }
510
+
511
+ var i, j, s, d, key, rows = [], rows2 = [];
512
+
513
+ if (chartType === "bar" || chartType === "column" || (chart.xtype !== "number" && chart.xtype !== "bubble")) {
514
+ var sortedLabels = [];
515
+
516
+ for (i = 0; i < series.length; i++) {
517
+ s = series[i];
518
+
519
+ for (j = 0; j < s.data.length; j++) {
520
+ d = s.data[j];
521
+ key = chart.xtype == "datetime" ? d[0].getTime() : d[0];
522
+ if (!rows[key]) {
523
+ rows[key] = new Array(series.length);
524
+ }
525
+ rows[key][i] = toFloat(d[1]);
526
+ if (sortedLabels.indexOf(key) === -1) {
527
+ sortedLabels.push(key);
528
+ }
529
+ }
530
+ }
531
+
532
+ if (chart.xtype === "datetime" || chart.xtype === "number") {
533
+ sortedLabels.sort(sortByNumber);
534
+ }
535
+
536
+ for (j = 0; j < series.length; j++) {
537
+ rows2.push([]);
538
+ }
539
+
540
+ var value;
541
+ var k;
542
+ for (k = 0; k < sortedLabels.length; k++) {
543
+ i = sortedLabels[k];
544
+ if (chart.xtype === "datetime") {
545
+ value = new Date(toFloat(i));
546
+ // TODO make this efficient
547
+ day = day && isDay(value);
548
+ if (!dayOfWeek) {
549
+ dayOfWeek = value.getDay();
550
+ }
551
+ week = week && isWeek(value, dayOfWeek);
552
+ month = month && isMonth(value);
553
+ year = year && isYear(value);
554
+ hour = hour && isHour(value);
555
+ minute = minute && isMinute(value);
556
+ } else {
557
+ value = i;
558
+ }
559
+ labels.push(value);
560
+ for (j = 0; j < series.length; j++) {
561
+ // Chart.js doesn't like undefined
562
+ rows2[j].push(rows[i][j] === undefined ? null : rows[i][j]);
563
+ }
564
+ }
565
+ } else {
566
+ for (var i$2 = 0; i$2 < series.length; i$2++) {
567
+ var s$2 = series[i$2];
568
+ var d$1 = [];
569
+ for (var j$2 = 0; j$2 < s$2.data.length; j$2++) {
570
+ var point = {
571
+ x: toFloat(s$2.data[j$2][0]),
572
+ y: toFloat(s$2.data[j$2][1])
573
+ };
574
+ if (chartType === "bubble") {
575
+ point.r = toFloat(s$2.data[j$2][2]) * 20 / max;
576
+ // custom attribute, for tooltip
577
+ point.v = s$2.data[j$2][2];
578
+ }
579
+ d$1.push(point);
580
+ }
581
+ rows2.push(d$1);
582
+ }
583
+ }
584
+
585
+ for (i = 0; i < series.length; i++) {
586
+ s = series[i];
587
+
588
+ var color = s.color || colors[i];
589
+ var backgroundColor = chartType !== "line" ? addOpacity(color, 0.5) : color;
590
+
591
+ var dataset = {
592
+ label: s.name || "",
593
+ data: rows2[i],
594
+ fill: chartType === "area",
595
+ borderColor: color,
596
+ backgroundColor: backgroundColor,
597
+ pointBackgroundColor: color,
598
+ borderWidth: 2,
599
+ pointHoverBackgroundColor: color
600
+ };
601
+
602
+ if (s.stack) {
603
+ dataset.stack = s.stack;
604
+ }
605
+
606
+ var curve = seriesOption(chart, s, "curve");
607
+ if (curve === false) {
608
+ dataset.lineTension = 0;
609
+ }
610
+
611
+ var points = seriesOption(chart, s, "points");
612
+ if (points === false) {
613
+ dataset.pointRadius = 0;
614
+ dataset.pointHitRadius = 5;
615
+ }
616
+
617
+ dataset = merge(dataset, chart.options.dataset || {});
618
+ dataset = merge(dataset, s.library || {});
619
+ dataset = merge(dataset, s.dataset || {});
620
+
621
+ datasets.push(dataset);
622
+ }
623
+
624
+ if (chart.xtype === "datetime" && labels.length > 0) {
625
+ var minTime = labels[0].getTime();
626
+ var maxTime = labels[0].getTime();
627
+ for (i = 1; i < labels.length; i++) {
628
+ var value$1 = labels[i].getTime();
629
+ if (value$1 < minTime) {
630
+ minTime = value$1;
631
+ }
632
+ if (value$1 > maxTime) {
633
+ maxTime = value$1;
634
+ }
635
+ }
636
+
637
+ var timeDiff = (maxTime - minTime) / (86400 * 1000.0);
638
+
639
+ if (!options.scales.xAxes[0].time.unit) {
640
+ var step;
641
+ if (year || timeDiff > 365 * 10) {
642
+ options.scales.xAxes[0].time.unit = "year";
643
+ step = 365;
644
+ } else if (month || timeDiff > 30 * 10) {
645
+ options.scales.xAxes[0].time.unit = "month";
646
+ step = 30;
647
+ } else if (day || timeDiff > 10) {
648
+ options.scales.xAxes[0].time.unit = "day";
649
+ step = 1;
650
+ } else if (hour || timeDiff > 0.5) {
651
+ options.scales.xAxes[0].time.displayFormats = {hour: "MMM D, h a"};
652
+ options.scales.xAxes[0].time.unit = "hour";
653
+ step = 1 / 24.0;
654
+ } else if (minute) {
655
+ options.scales.xAxes[0].time.displayFormats = {minute: "h:mm a"};
656
+ options.scales.xAxes[0].time.unit = "minute";
657
+ step = 1 / 24.0 / 60.0;
658
+ }
659
+
660
+ if (step && timeDiff > 0) {
661
+ var unitStepSize = Math.ceil(timeDiff / step / (chart.element.offsetWidth / 100.0));
662
+ if (week && step === 1) {
663
+ unitStepSize = Math.ceil(unitStepSize / 7.0) * 7;
664
+ }
665
+ options.scales.xAxes[0].time.unitStepSize = unitStepSize;
666
+ }
667
+ }
668
+
669
+ if (!options.scales.xAxes[0].time.tooltipFormat) {
670
+ if (day) {
671
+ options.scales.xAxes[0].time.tooltipFormat = "ll";
672
+ } else if (hour) {
673
+ options.scales.xAxes[0].time.tooltipFormat = "MMM D, h a";
674
+ } else if (minute) {
675
+ options.scales.xAxes[0].time.tooltipFormat = "h:mm a";
676
+ }
677
+ }
678
+ }
679
+
680
+ var data = {
681
+ labels: labels,
682
+ datasets: datasets
683
+ };
684
+
685
+ return data;
686
+ };
687
+
688
+ var defaultExport = function defaultExport(library) {
689
+ this.name = "chartjs";
690
+ this.library = library;
691
+ };
692
+
693
+ defaultExport.prototype.renderLineChart = function renderLineChart (chart, chartType) {
694
+ var chartOptions = {};
695
+ // fix for https://github.com/chartjs/Chart.js/issues/2441
696
+ if (!chart.options.max && allZeros(chart.data)) {
697
+ chartOptions.max = 1;
698
+ }
699
+
700
+ var options = jsOptions(chart, merge(chartOptions, chart.options));
701
+ setFormatOptions(chart, options, chartType);
702
+
703
+ var data = createDataTable(chart, options, chartType || "line");
704
+
705
+ if (chart.xtype === "number") {
706
+ options.scales.xAxes[0].type = "linear";
707
+ options.scales.xAxes[0].position = "bottom";
708
+ } else {
709
+ options.scales.xAxes[0].type = chart.xtype === "string" ? "category" : "time";
710
+ }
711
+
712
+ this.drawChart(chart, "line", data, options);
713
+ };
714
+
715
+ defaultExport.prototype.renderPieChart = function renderPieChart (chart) {
716
+ var options = merge({}, baseOptions);
717
+ if (chart.options.donut) {
718
+ options.cutoutPercentage = 50;
719
+ }
720
+
721
+ if ("legend" in chart.options) {
722
+ hideLegend(options, chart.options.legend);
723
+ }
724
+
725
+ if (chart.options.title) {
726
+ setTitle(options, chart.options.title);
727
+ }
728
+
729
+ options = merge(options, chart.options.library || {});
730
+ setFormatOptions(chart, options, "pie");
731
+
732
+ var labels = [];
733
+ var values = [];
734
+ for (var i = 0; i < chart.data.length; i++) {
735
+ var point = chart.data[i];
736
+ labels.push(point[0]);
737
+ values.push(point[1]);
738
+ }
739
+
740
+ var dataset = {
741
+ data: values,
742
+ backgroundColor: chart.options.colors || defaultColors
743
+ };
744
+ dataset = merge(dataset, chart.options.dataset || {});
745
+
746
+ var data = {
747
+ labels: labels,
748
+ datasets: [dataset]
749
+ };
750
+
751
+ this.drawChart(chart, "pie", data, options);
752
+ };
753
+
754
+ defaultExport.prototype.renderColumnChart = function renderColumnChart (chart, chartType) {
755
+ var options;
756
+ if (chartType === "bar") {
757
+ options = jsOptionsFunc(merge(baseOptions, defaultOptions), hideLegend, setTitle, setBarMin, setBarMax, setStacked, setXtitle, setYtitle)(chart, chart.options);
758
+ } else {
759
+ options = jsOptions(chart, chart.options);
760
+ }
761
+ setFormatOptions(chart, options, chartType);
762
+ var data = createDataTable(chart, options, "column");
763
+ if (chartType !== "bar") {
764
+ setLabelSize(chart, data, options);
765
+ }
766
+ this.drawChart(chart, (chartType === "bar" ? "horizontalBar" : "bar"), data, options);
767
+ };
768
+
769
+ defaultExport.prototype.renderAreaChart = function renderAreaChart (chart) {
770
+ this.renderLineChart(chart, "area");
771
+ };
772
+
773
+ defaultExport.prototype.renderBarChart = function renderBarChart (chart) {
774
+ this.renderColumnChart(chart, "bar");
775
+ };
776
+
777
+ defaultExport.prototype.renderScatterChart = function renderScatterChart (chart, chartType) {
778
+ chartType = chartType || "scatter";
779
+
780
+ var options = jsOptions(chart, chart.options);
781
+ setFormatOptions(chart, options, chartType);
782
+
783
+ if (!("showLines" in options)) {
784
+ options.showLines = false;
785
+ }
786
+
787
+ var data = createDataTable(chart, options, chartType);
788
+
789
+ options.scales.xAxes[0].type = "linear";
790
+ options.scales.xAxes[0].position = "bottom";
791
+
792
+ this.drawChart(chart, chartType, data, options);
793
+ };
794
+
795
+ defaultExport.prototype.renderBubbleChart = function renderBubbleChart (chart) {
796
+ this.renderScatterChart(chart, "bubble");
797
+ };
798
+
799
+ defaultExport.prototype.destroy = function destroy (chart) {
800
+ if (chart.chart) {
801
+ chart.chart.destroy();
802
+ }
803
+ };
804
+
805
+ defaultExport.prototype.drawChart = function drawChart (chart, type, data, options) {
806
+ this.destroy(chart);
807
+
808
+ var chartOptions = {
809
+ type: type,
810
+ data: data,
811
+ options: options
812
+ };
813
+
814
+ if (chart.options.code) {
815
+ window.console.log("new Chart(ctx, " + JSON.stringify(chartOptions) + ");");
816
+ }
817
+
818
+ chart.element.innerHTML = "<canvas></canvas>";
819
+ var ctx = chart.element.getElementsByTagName("CANVAS")[0];
820
+ chart.chart = new this.library(ctx, chartOptions);
821
+ };
822
+
823
+ var defaultOptions$1 = {
824
+ chart: {},
825
+ xAxis: {
826
+ title: {
827
+ text: null
828
+ },
829
+ labels: {
830
+ style: {
831
+ fontSize: "12px"
832
+ }
833
+ }
834
+ },
835
+ yAxis: {
836
+ title: {
837
+ text: null
838
+ },
839
+ labels: {
840
+ style: {
841
+ fontSize: "12px"
842
+ }
843
+ }
844
+ },
845
+ title: {
846
+ text: null
847
+ },
848
+ credits: {
849
+ enabled: false
850
+ },
851
+ legend: {
852
+ borderWidth: 0
853
+ },
854
+ tooltip: {
855
+ style: {
856
+ fontSize: "12px"
857
+ }
858
+ },
859
+ plotOptions: {
860
+ areaspline: {},
861
+ series: {
862
+ marker: {}
863
+ }
864
+ }
865
+ };
866
+
867
+ var hideLegend$1 = function (options, legend, hideLegend) {
868
+ if (legend !== undefined) {
869
+ options.legend.enabled = !!legend;
870
+ if (legend && legend !== true) {
871
+ if (legend === "top" || legend === "bottom") {
872
+ options.legend.verticalAlign = legend;
873
+ } else {
874
+ options.legend.layout = "vertical";
875
+ options.legend.verticalAlign = "middle";
876
+ options.legend.align = legend;
877
+ }
878
+ }
879
+ } else if (hideLegend) {
880
+ options.legend.enabled = false;
881
+ }
882
+ };
883
+
884
+ var setTitle$1 = function (options, title) {
885
+ options.title.text = title;
886
+ };
887
+
888
+ var setMin$1 = function (options, min) {
889
+ options.yAxis.min = min;
890
+ };
891
+
892
+ var setMax$1 = function (options, max) {
893
+ options.yAxis.max = max;
894
+ };
895
+
896
+ var setStacked$1 = function (options, stacked) {
897
+ options.plotOptions.series.stacking = stacked ? (stacked === true ? "normal" : stacked) : null;
898
+ };
899
+
900
+ var setXtitle$1 = function (options, title) {
901
+ options.xAxis.title.text = title;
902
+ };
903
+
904
+ var setYtitle$1 = function (options, title) {
905
+ options.yAxis.title.text = title;
906
+ };
907
+
908
+ var jsOptions$1 = jsOptionsFunc(defaultOptions$1, hideLegend$1, setTitle$1, setMin$1, setMax$1, setStacked$1, setXtitle$1, setYtitle$1);
909
+
910
+ var setFormatOptions$1 = function(chart, options, chartType) {
911
+ var formatOptions = {
912
+ prefix: chart.options.prefix,
913
+ suffix: chart.options.suffix,
914
+ thousands: chart.options.thousands,
915
+ decimal: chart.options.decimal
916
+ };
917
+
918
+ if (chartType !== "pie" && !options.yAxis.labels.formatter) {
919
+ options.yAxis.labels.formatter = function () {
920
+ return formatValue("", this.value, formatOptions);
921
+ };
922
+ }
923
+
924
+ if (!options.tooltip.pointFormatter) {
925
+ options.tooltip.pointFormatter = function () {
926
+ return '<span style="color:' + this.color + '>\u25CF</span> ' + formatValue(this.series.name + ': <b>', this.y, formatOptions) + '</b><br/>';
927
+ };
928
+ }
929
+ };
930
+
931
+ var defaultExport$1 = function defaultExport(library) {
932
+ this.name = "highcharts";
933
+ this.library = library;
934
+ };
935
+
936
+ defaultExport$1.prototype.renderLineChart = function renderLineChart (chart, chartType) {
937
+ chartType = chartType || "spline";
938
+ var chartOptions = {};
939
+ if (chartType === "areaspline") {
940
+ chartOptions = {
941
+ plotOptions: {
942
+ areaspline: {
943
+ stacking: "normal"
944
+ },
945
+ area: {
946
+ stacking: "normal"
947
+ },
948
+ series: {
949
+ marker: {
950
+ enabled: false
951
+ }
952
+ }
953
+ }
954
+ };
955
+ }
956
+
957
+ if (chart.options.curve === false) {
958
+ if (chartType === "areaspline") {
959
+ chartType = "area";
960
+ } else if (chartType === "spline") {
961
+ chartType = "line";
962
+ }
963
+ }
964
+
965
+ var options = jsOptions$1(chart, chart.options, chartOptions), data, i, j;
966
+ options.xAxis.type = chart.xtype === "string" ? "category" : (chart.xtype === "number" ? "linear" : "datetime");
967
+ if (!options.chart.type) {
968
+ options.chart.type = chartType;
969
+ }
970
+ setFormatOptions$1(chart, options, chartType);
971
+
972
+ var series = chart.data;
973
+ for (i = 0; i < series.length; i++) {
974
+ series[i].name = series[i].name || "Value";
975
+ data = series[i].data;
976
+ if (chart.xtype === "datetime") {
977
+ for (j = 0; j < data.length; j++) {
978
+ data[j][0] = data[j][0].getTime();
979
+ }
980
+ }
981
+ series[i].marker = {symbol: "circle"};
982
+ if (chart.options.points === false) {
983
+ series[i].marker.enabled = false;
984
+ }
985
+ }
986
+
987
+ this.drawChart(chart, series, options);
988
+ };
989
+
990
+ defaultExport$1.prototype.renderScatterChart = function renderScatterChart (chart) {
991
+ var options = jsOptions$1(chart, chart.options, {});
992
+ options.chart.type = "scatter";
993
+ this.drawChart(chart, chart.data, options);
994
+ };
995
+
996
+ defaultExport$1.prototype.renderPieChart = function renderPieChart (chart) {
997
+ var chartOptions = merge(defaultOptions$1, {});
998
+
999
+ if (chart.options.colors) {
1000
+ chartOptions.colors = chart.options.colors;
1001
+ }
1002
+ if (chart.options.donut) {
1003
+ chartOptions.plotOptions = {pie: {innerSize: "50%"}};
1004
+ }
1005
+
1006
+ if ("legend" in chart.options) {
1007
+ hideLegend$1(chartOptions, chart.options.legend);
1008
+ }
1009
+
1010
+ if (chart.options.title) {
1011
+ setTitle$1(chartOptions, chart.options.title);
1012
+ }
1013
+
1014
+ var options = merge(chartOptions, chart.options.library || {});
1015
+ setFormatOptions$1(chart, options, "pie");
1016
+ var series = [{
1017
+ type: "pie",
1018
+ name: chart.options.label || "Value",
1019
+ data: chart.data
1020
+ }];
1021
+
1022
+ this.drawChart(chart, series, options);
1023
+ };
1024
+
1025
+ defaultExport$1.prototype.renderColumnChart = function renderColumnChart (chart, chartType) {
1026
+ chartType = chartType || "column";
1027
+ var series = chart.data;
1028
+ var options = jsOptions$1(chart, chart.options), i, j, s, d, rows = [], categories = [];
1029
+ options.chart.type = chartType;
1030
+ setFormatOptions$1(chart, options, chartType);
1031
+
1032
+ for (i = 0; i < series.length; i++) {
1033
+ s = series[i];
1034
+
1035
+ for (j = 0; j < s.data.length; j++) {
1036
+ d = s.data[j];
1037
+ if (!rows[d[0]]) {
1038
+ rows[d[0]] = new Array(series.length);
1039
+ categories.push(d[0]);
1040
+ }
1041
+ rows[d[0]][i] = d[1];
1042
+ }
1043
+ }
1044
+
1045
+ if (chart.xtype === "number") {
1046
+ categories.sort(sortByNumber);
1047
+ }
1048
+
1049
+ options.xAxis.categories = categories;
1050
+
1051
+ var newSeries = [], d2;
1052
+ for (i = 0; i < series.length; i++) {
1053
+ d = [];
1054
+ for (j = 0; j < categories.length; j++) {
1055
+ d.push(rows[categories[j]][i] || 0);
1056
+ }
1057
+
1058
+ d2 = {
1059
+ name: series[i].name || "Value",
1060
+ data: d
1061
+ };
1062
+ if (series[i].stack) {
1063
+ d2.stack = series[i].stack;
1064
+ }
1065
+
1066
+ newSeries.push(d2);
1067
+ }
1068
+
1069
+ this.drawChart(chart, newSeries, options);
1070
+ };
1071
+
1072
+ defaultExport$1.prototype.renderBarChart = function renderBarChart (chart) {
1073
+ this.renderColumnChart(chart, "bar");
1074
+ };
1075
+
1076
+ defaultExport$1.prototype.renderAreaChart = function renderAreaChart (chart) {
1077
+ this.renderLineChart(chart, "areaspline");
1078
+ };
1079
+
1080
+ defaultExport$1.prototype.destroy = function destroy (chart) {
1081
+ if (chart.chart) {
1082
+ chart.chart.destroy();
1083
+ }
1084
+ };
1085
+
1086
+ defaultExport$1.prototype.drawChart = function drawChart (chart, data, options) {
1087
+ this.destroy(chart);
1088
+
1089
+ options.chart.renderTo = chart.element.id;
1090
+ options.series = data;
1091
+
1092
+ if (chart.options.code) {
1093
+ window.console.log("new Highcharts.Chart(" + JSON.stringify(options) + ");");
1094
+ }
1095
+
1096
+ chart.chart = new this.library.Chart(options);
1097
+ };
1098
+
1099
+ var loaded = {};
1100
+ var callbacks = [];
1101
+
1102
+ // Set chart options
1103
+ var defaultOptions$2 = {
1104
+ chartArea: {},
1105
+ fontName: "'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif",
1106
+ pointSize: 6,
1107
+ legend: {
1108
+ textStyle: {
1109
+ fontSize: 12,
1110
+ color: "#444"
1111
+ },
1112
+ alignment: "center",
1113
+ position: "right"
1114
+ },
1115
+ curveType: "function",
1116
+ hAxis: {
1117
+ textStyle: {
1118
+ color: "#666",
1119
+ fontSize: 12
1120
+ },
1121
+ titleTextStyle: {},
1122
+ gridlines: {
1123
+ color: "transparent"
1124
+ },
1125
+ baselineColor: "#ccc",
1126
+ viewWindow: {}
1127
+ },
1128
+ vAxis: {
1129
+ textStyle: {
1130
+ color: "#666",
1131
+ fontSize: 12
1132
+ },
1133
+ titleTextStyle: {},
1134
+ baselineColor: "#ccc",
1135
+ viewWindow: {}
1136
+ },
1137
+ tooltip: {
1138
+ textStyle: {
1139
+ color: "#666",
1140
+ fontSize: 12
1141
+ }
1142
+ }
1143
+ };
1144
+
1145
+ var hideLegend$2 = function (options, legend, hideLegend) {
1146
+ if (legend !== undefined) {
1147
+ var position;
1148
+ if (!legend) {
1149
+ position = "none";
1150
+ } else if (legend === true) {
1151
+ position = "right";
1152
+ } else {
1153
+ position = legend;
1154
+ }
1155
+ options.legend.position = position;
1156
+ } else if (hideLegend) {
1157
+ options.legend.position = "none";
1158
+ }
1159
+ };
1160
+
1161
+ var setTitle$2 = function (options, title) {
1162
+ options.title = title;
1163
+ options.titleTextStyle = {color: "#333", fontSize: "20px"};
1164
+ };
1165
+
1166
+ var setMin$2 = function (options, min) {
1167
+ options.vAxis.viewWindow.min = min;
1168
+ };
1169
+
1170
+ var setMax$2 = function (options, max) {
1171
+ options.vAxis.viewWindow.max = max;
1172
+ };
1173
+
1174
+ var setBarMin$1 = function (options, min) {
1175
+ options.hAxis.viewWindow.min = min;
1176
+ };
1177
+
1178
+ var setBarMax$1 = function (options, max) {
1179
+ options.hAxis.viewWindow.max = max;
1180
+ };
1181
+
1182
+ var setStacked$2 = function (options, stacked) {
1183
+ options.isStacked = stacked ? stacked : false;
1184
+ };
1185
+
1186
+ var setXtitle$2 = function (options, title) {
1187
+ options.hAxis.title = title;
1188
+ options.hAxis.titleTextStyle.italic = false;
1189
+ };
1190
+
1191
+ var setYtitle$2 = function (options, title) {
1192
+ options.vAxis.title = title;
1193
+ options.vAxis.titleTextStyle.italic = false;
1194
+ };
1195
+
1196
+ var jsOptions$2 = jsOptionsFunc(defaultOptions$2, hideLegend$2, setTitle$2, setMin$2, setMax$2, setStacked$2, setXtitle$2, setYtitle$2);
1197
+
1198
+ var resize = function (callback) {
1199
+ if (window.attachEvent) {
1200
+ window.attachEvent("onresize", callback);
1201
+ } else if (window.addEventListener) {
1202
+ window.addEventListener("resize", callback, true);
1203
+ }
1204
+ callback();
1205
+ };
1206
+
1207
+ var defaultExport$2 = function defaultExport(library) {
1208
+ this.name = "google";
1209
+ this.library = library;
1210
+ };
1211
+
1212
+ defaultExport$2.prototype.renderLineChart = function renderLineChart (chart) {
1213
+ var this$1 = this;
1214
+
1215
+ this.waitForLoaded(chart, function () {
1216
+ var chartOptions = {};
1217
+
1218
+ if (chart.options.curve === false) {
1219
+ chartOptions.curveType = "none";
1220
+ }
1221
+
1222
+ if (chart.options.points === false) {
1223
+ chartOptions.pointSize = 0;
1224
+ }
1225
+
1226
+ var options = jsOptions$2(chart, chart.options, chartOptions);
1227
+ var data = this$1.createDataTable(chart, chart.xtype);
1228
+
1229
+ this$1.drawChart(chart, "LineChart", data, options);
1230
+ });
1231
+ };
1232
+
1233
+ defaultExport$2.prototype.renderPieChart = function renderPieChart (chart) {
1234
+ var this$1 = this;
1235
+
1236
+ this.waitForLoaded(chart, function () {
1237
+ var chartOptions = {
1238
+ chartArea: {
1239
+ top: "10%",
1240
+ height: "80%"
1241
+ },
1242
+ legend: {}
1243
+ };
1244
+ if (chart.options.colors) {
1245
+ chartOptions.colors = chart.options.colors;
1246
+ }
1247
+ if (chart.options.donut) {
1248
+ chartOptions.pieHole = 0.5;
1249
+ }
1250
+ if ("legend" in chart.options) {
1251
+ hideLegend$2(chartOptions, chart.options.legend);
1252
+ }
1253
+ if (chart.options.title) {
1254
+ setTitle$2(chartOptions, chart.options.title);
1255
+ }
1256
+ var options = merge(merge(defaultOptions$2, chartOptions), chart.options.library || {});
1257
+
1258
+ var data = new this$1.library.visualization.DataTable();
1259
+ data.addColumn("string", "");
1260
+ data.addColumn("number", "Value");
1261
+ data.addRows(chart.data);
1262
+
1263
+ this$1.drawChart(chart, "PieChart", data, options);
1264
+ });
1265
+ };
1266
+
1267
+ defaultExport$2.prototype.renderColumnChart = function renderColumnChart (chart) {
1268
+ var this$1 = this;
1269
+
1270
+ this.waitForLoaded(chart, function () {
1271
+ var options = jsOptions$2(chart, chart.options);
1272
+ var data = this$1.createDataTable(chart, chart.xtype);
1273
+
1274
+ this$1.drawChart(chart, "ColumnChart", data, options);
1275
+ });
1276
+ };
1277
+
1278
+ defaultExport$2.prototype.renderBarChart = function renderBarChart (chart) {
1279
+ var this$1 = this;
1280
+
1281
+ this.waitForLoaded(chart, function () {
1282
+ var chartOptions = {
1283
+ hAxis: {
1284
+ gridlines: {
1285
+ color: "#ccc"
1286
+ }
1287
+ }
1288
+ };
1289
+ var options = jsOptionsFunc(defaultOptions$2, hideLegend$2, setTitle$2, setBarMin$1, setBarMax$1, setStacked$2, setXtitle$2, setYtitle$2)(chart, chart.options, chartOptions);
1290
+ var data = this$1.createDataTable(chart, chart.xtype);
1291
+
1292
+ this$1.drawChart(chart, "BarChart", data, options);
1293
+ });
1294
+ };
1295
+
1296
+ defaultExport$2.prototype.renderAreaChart = function renderAreaChart (chart) {
1297
+ var this$1 = this;
1298
+
1299
+ this.waitForLoaded(chart, function () {
1300
+ var chartOptions = {
1301
+ isStacked: true,
1302
+ pointSize: 0,
1303
+ areaOpacity: 0.5
1304
+ };
1305
+
1306
+ var options = jsOptions$2(chart, chart.options, chartOptions);
1307
+ var data = this$1.createDataTable(chart, chart.xtype);
1308
+
1309
+ this$1.drawChart(chart, "AreaChart", data, options);
1310
+ });
1311
+ };
1312
+
1313
+ defaultExport$2.prototype.renderGeoChart = function renderGeoChart (chart) {
1314
+ var this$1 = this;
1315
+
1316
+ this.waitForLoaded(chart, function () {
1317
+ var chartOptions = {
1318
+ legend: "none",
1319
+ colorAxis: {
1320
+ colors: chart.options.colors || ["#f6c7b6", "#ce502d"]
1321
+ }
1322
+ };
1323
+ var options = merge(merge(defaultOptions$2, chartOptions), chart.options.library || {});
1324
+
1325
+ var data = new this$1.library.visualization.DataTable();
1326
+ data.addColumn("string", "");
1327
+ data.addColumn("number", chart.options.label || "Value");
1328
+ data.addRows(chart.data);
1329
+
1330
+ this$1.drawChart(chart, "GeoChart", data, options);
1331
+ });
1332
+ };
1333
+
1334
+ defaultExport$2.prototype.renderScatterChart = function renderScatterChart (chart) {
1335
+ var this$1 = this;
1336
+
1337
+ this.waitForLoaded(chart, function () {
1338
+ var chartOptions = {};
1339
+ var options = jsOptions$2(chart, chart.options, chartOptions);
1340
+
1341
+ var series = chart.data, rows2 = [], i, j, data, d;
1342
+ for (i = 0; i < series.length; i++) {
1343
+ series[i].name = series[i].name || "Value";
1344
+ d = series[i].data;
1345
+ for (j = 0; j < d.length; j++) {
1346
+ var row = new Array(series.length + 1);
1347
+ row[0] = d[j][0];
1348
+ row[i + 1] = d[j][1];
1349
+ rows2.push(row);
1350
+ }
1351
+ }
1352
+
1353
+ data = new this$1.library.visualization.DataTable();
1354
+ data.addColumn("number", "");
1355
+ for (i = 0; i < series.length; i++) {
1356
+ data.addColumn("number", series[i].name);
1357
+ }
1358
+ data.addRows(rows2);
1359
+
1360
+ this$1.drawChart(chart, "ScatterChart", data, options);
1361
+ });
1362
+ };
1363
+
1364
+ defaultExport$2.prototype.renderTimeline = function renderTimeline (chart) {
1365
+ var this$1 = this;
1366
+
1367
+ this.waitForLoaded(chart, "timeline", function () {
1368
+ var chartOptions = {
1369
+ legend: "none"
1370
+ };
1371
+
1372
+ if (chart.options.colors) {
1373
+ chartOptions.colors = chart.options.colors;
1374
+ }
1375
+ var options = merge(merge(defaultOptions$2, chartOptions), chart.options.library || {});
1376
+
1377
+ var data = new this$1.library.visualization.DataTable();
1378
+ data.addColumn({type: "string", id: "Name"});
1379
+ data.addColumn({type: "date", id: "Start"});
1380
+ data.addColumn({type: "date", id: "End"});
1381
+ data.addRows(chart.data);
1382
+
1383
+ chart.element.style.lineHeight = "normal";
1384
+
1385
+ this$1.drawChart(chart, "Timeline", data, options);
1386
+ });
1387
+ };
1388
+
1389
+ defaultExport$2.prototype.destroy = function destroy (chart) {
1390
+ if (chart.chart) {
1391
+ chart.chart.clearChart();
1392
+ }
1393
+ };
1394
+
1395
+ defaultExport$2.prototype.drawChart = function drawChart (chart, type, data, options) {
1396
+ this.destroy(chart);
1397
+
1398
+ if (chart.options.code) {
1399
+ window.console.log("var data = new google.visualization.DataTable(" + data.toJSON() + ");\nvar chart = new google.visualization." + type + "(element);\nchart.draw(data, " + JSON.stringify(options) + ");");
1400
+ }
1401
+
1402
+ chart.chart = new this.library.visualization[type](chart.element);
1403
+ resize(function () {
1404
+ chart.chart.draw(data, options);
1405
+ });
1406
+ };
1407
+
1408
+ defaultExport$2.prototype.waitForLoaded = function waitForLoaded (chart, pack, callback) {
1409
+ var this$1 = this;
1410
+
1411
+ if (!callback) {
1412
+ callback = pack;
1413
+ pack = "corechart";
1414
+ }
1415
+
1416
+ callbacks.push({pack: pack, callback: callback});
1417
+
1418
+ if (loaded[pack]) {
1419
+ this.runCallbacks();
1420
+ } else {
1421
+ loaded[pack] = true;
1422
+
1423
+ // https://groups.google.com/forum/#!topic/google-visualization-api/fMKJcyA2yyI
1424
+ var loadOptions = {
1425
+ packages: [pack],
1426
+ callback: function () { this$1.runCallbacks(); }
1427
+ };
1428
+ var config = chart.__config();
1429
+ if (config.language) {
1430
+ loadOptions.language = config.language;
1431
+ }
1432
+ if (pack === "corechart" && config.mapsApiKey) {
1433
+ loadOptions.mapsApiKey = config.mapsApiKey;
1434
+ }
1435
+
1436
+ this.library.charts.load("current", loadOptions);
1437
+ }
1438
+ };
1439
+
1440
+ defaultExport$2.prototype.runCallbacks = function runCallbacks () {
1441
+ var cb, call;
1442
+ for (var i = 0; i < callbacks.length; i++) {
1443
+ cb = callbacks[i];
1444
+ call = this.library.visualization && ((cb.pack === "corechart" && this.library.visualization.LineChart) || (cb.pack === "timeline" && this.library.visualization.Timeline));
1445
+ if (call) {
1446
+ cb.callback();
1447
+ callbacks.splice(i, 1);
1448
+ i--;
1449
+ }
1450
+ }
1451
+ };
1452
+
1453
+ // cant use object as key
1454
+ defaultExport$2.prototype.createDataTable = function createDataTable (chart, columnType) {
1455
+ var i, j, s, d, key, rows = [], sortedLabels = [], series = chart.data;
1456
+ var withAnnotations = 'series' in chart.options.library
1457
+
1458
+ for (i = 0; i < series.length; i++) {
1459
+ s = series[i];
1460
+ series[i].name = series[i].name || "Value";
1461
+
1462
+ for (j = 0; j < s.data.length; j++) {
1463
+ d = s.data[j];
1464
+ key = (columnType === "datetime") ? d[0].getTime() : d[0];
1465
+ if (!rows[key]) {
1466
+ rows[key] = new Array(series.length);
1467
+ sortedLabels.push(key);
1468
+ }
1469
+
1470
+ if (withAnnotations) {
1471
+ d = chart.rawData[i].data[j];
1472
+ rows[key][i] = [toFloat(d[1]), d[2]];
1473
+ } else {
1474
+ rows[key][i] = toFloat(d[1]);
1475
+ }
1476
+ }
1477
+ }
1478
+
1479
+ var rows2 = [];
1480
+ var formated_row = [];
1481
+ var day = true;
1482
+ var value;
1483
+ for (j = 0; j < sortedLabels.length; j++) {
1484
+ i = sortedLabels[j];
1485
+ if (columnType === "datetime") {
1486
+ value = new Date(toFloat(i));
1487
+ day = day && isDay(value);
1488
+ } else if (columnType === "number") {
1489
+ value = toFloat(i);
1490
+ } else {
1491
+ value = i;
1492
+ }
1493
+
1494
+ formated_row = [value].concat(rows[i]).flat(1)
1495
+ rows2.push(formated_row);
1496
+ }
1497
+ if (columnType === "datetime") {
1498
+ rows2.sort(sortByTime);
1499
+ } else if (columnType === "number") {
1500
+ rows2.sort(sortByNumberSeries);
1501
+
1502
+ for (i = 0; i < rows2.length; i++) {
1503
+ rows2[i][0] = toStr(rows2[i][0]);
1504
+ }
1505
+
1506
+ columnType = "string";
1507
+ }
1508
+
1509
+ // create datatable
1510
+ var data = new this.library.visualization.DataTable();
1511
+ columnType = columnType === "datetime" && day ? "date" : columnType;
1512
+ data.addColumn(columnType, "");
1513
+ for (i = 0; i < series.length; i++) {
1514
+ data.addColumn("number", series[i].name);
1515
+ if (withAnnotations) data.addColumn(chart.options.library.series[i]);
1516
+ }
1517
+
1518
+ data.addRows(rows2);
1519
+ return data;
1520
+ };
1521
+
1522
+ var pendingRequests = [], runningRequests = 0, maxRequests = 4;
1523
+
1524
+ function pushRequest(url, success, error) {
1525
+ pendingRequests.push([url, success, error]);
1526
+ runNext();
1527
+ }
1528
+
1529
+ function runNext() {
1530
+ if (runningRequests < maxRequests) {
1531
+ var request = pendingRequests.shift();
1532
+ if (request) {
1533
+ runningRequests++;
1534
+ getJSON(request[0], request[1], request[2]);
1535
+ runNext();
1536
+ }
1537
+ }
1538
+ }
1539
+
1540
+ function requestComplete() {
1541
+ runningRequests--;
1542
+ runNext();
1543
+ }
1544
+
1545
+ function getJSON(url, success, error) {
1546
+ ajaxCall(url, success, function (jqXHR, textStatus, errorThrown) {
1547
+ var message = (typeof errorThrown === "string") ? errorThrown : errorThrown.message;
1548
+ error(message);
1549
+ });
1550
+ }
1551
+
1552
+ function ajaxCall(url, success, error) {
1553
+ var $ = window.jQuery || window.Zepto || window.$;
1554
+
1555
+ if ($) {
1556
+ $.ajax({
1557
+ dataType: "json",
1558
+ url: url,
1559
+ success: success,
1560
+ error: error,
1561
+ complete: requestComplete
1562
+ });
1563
+ } else {
1564
+ var xhr = new XMLHttpRequest();
1565
+ xhr.open("GET", url, true);
1566
+ xhr.setRequestHeader("Content-Type", "application/json");
1567
+ xhr.onload = function () {
1568
+ requestComplete();
1569
+ if (xhr.status === 200) {
1570
+ success(JSON.parse(xhr.responseText), xhr.statusText, xhr);
1571
+ } else {
1572
+ error(xhr, "error", xhr.statusText);
1573
+ }
1574
+ };
1575
+ xhr.send();
1576
+ }
1577
+ }
1578
+
1579
+ var config = {};
1580
+ var adapters = [];
1581
+
1582
+ // helpers
1583
+
1584
+ function setText(element, text) {
1585
+ if (document.body.innerText) {
1586
+ element.innerText = text;
1587
+ } else {
1588
+ element.textContent = text;
1589
+ }
1590
+ }
1591
+
1592
+ function chartError(element, message) {
1593
+ setText(element, "Error Loading Chart: " + message);
1594
+ element.style.color = "#ff0000";
1595
+ }
1596
+
1597
+ function errorCatcher(chart) {
1598
+ try {
1599
+ chart.__render();
1600
+ } catch (err) {
1601
+ chartError(chart.element, err.message);
1602
+ throw err;
1603
+ }
1604
+ }
1605
+
1606
+ function fetchDataSource(chart, dataSource) {
1607
+ if (typeof dataSource === "string") {
1608
+ pushRequest(dataSource, function (data) {
1609
+ chart.rawData = data;
1610
+ errorCatcher(chart);
1611
+ }, function (message) {
1612
+ chartError(chart.element, message);
1613
+ });
1614
+ } else {
1615
+ chart.rawData = dataSource;
1616
+ errorCatcher(chart);
1617
+ }
1618
+ }
1619
+
1620
+ function addDownloadButton(chart) {
1621
+ var element = chart.element;
1622
+ var link = document.createElement("a");
1623
+
1624
+ var download = chart.options.download;
1625
+ if (download === true) {
1626
+ download = {};
1627
+ } else if (typeof download === "string") {
1628
+ download = {filename: download};
1629
+ }
1630
+ link.download = download.filename || "chart.png"; // https://caniuse.com/download
1631
+
1632
+ link.style.position = "absolute";
1633
+ link.style.top = "20px";
1634
+ link.style.right = "20px";
1635
+ link.style.zIndex = 1000;
1636
+ link.style.lineHeight = "20px";
1637
+ link.target = "_blank"; // for safari
1638
+ var image = document.createElement("img");
1639
+ image.alt = "Download";
1640
+ image.style.border = "none";
1641
+ // icon from font-awesome
1642
+ // http://fa2png.io/
1643
+ image.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAMAAAC6V+0/AAABCFBMVEUAAADMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMywEsqxAAAAV3RSTlMAAQIDBggJCgsMDQ4PERQaHB0eISIjJCouLzE0OTo/QUJHSUpLTU5PUllhYmltcHh5foWLjI+SlaCio6atr7S1t7m6vsHHyM7R2tze5Obo7fHz9ff5+/1hlxK2AAAA30lEQVQYGUXBhVYCQQBA0TdYWAt2d3d3YWAHyur7/z9xgD16Lw0DW+XKx+1GgX+FRzM3HWQWrHl5N/oapW5RPe0PkBu+UYeICvozTWZVK23Ao04B79oJrOsJDOoxkZoQPWgX29pHpCZEk7rEvQYiNSFq1UMqvlCjJkRBS1R8hb00Vb/TajtBL7nTHE1X1vyMQF732dQhyF2o6SAwrzP06iUQzvwsArlnzcOdrgBhJyHa1QOgO9U1GsKuvjUTjavliZYQ8nNPapG6sap/3nrIdJ6bOWzmX/fy0XVpfzZP3S8OJT3g9EEiJwAAAABJRU5ErkJggg==";
1644
+ link.appendChild(image);
1645
+ element.style.position = "relative";
1646
+
1647
+ chart.__downloadAttached = true;
1648
+
1649
+ // mouseenter
1650
+ chart.__enterEvent = addEvent(element, "mouseover", function(e) {
1651
+ var related = e.relatedTarget;
1652
+ // check download option again to ensure it wasn't changed
1653
+ if ((!related || (related !== this && !childOf(this, related))) && chart.options.download) {
1654
+ link.href = chart.toImage(download);
1655
+ element.appendChild(link);
1656
+ }
1657
+ });
1658
+
1659
+ // mouseleave
1660
+ chart.__leaveEvent = addEvent(element, "mouseout", function(e) {
1661
+ var related = e.relatedTarget;
1662
+ if (!related || (related !== this && !childOf(this, related))) {
1663
+ if (link.parentNode) {
1664
+ link.parentNode.removeChild(link);
1665
+ }
1666
+ }
1667
+ });
1668
+ }
1669
+
1670
+ // https://stackoverflow.com/questions/10149963/adding-event-listener-cross-browser
1671
+ function addEvent(elem, event, fn) {
1672
+ if (elem.addEventListener) {
1673
+ elem.addEventListener(event, fn, false);
1674
+ return fn;
1675
+ } else {
1676
+ var fn2 = function() {
1677
+ // set the this pointer same as addEventListener when fn is called
1678
+ return(fn.call(elem, window.event));
1679
+ };
1680
+ elem.attachEvent("on" + event, fn2);
1681
+ return fn2;
1682
+ }
1683
+ }
1684
+
1685
+ function removeEvent(elem, event, fn) {
1686
+ if (elem.removeEventListener) {
1687
+ elem.removeEventListener(event, fn, false);
1688
+ } else {
1689
+ elem.detachEvent("on" + event, fn);
1690
+ }
1691
+ }
1692
+
1693
+ // https://gist.github.com/shawnbot/4166283
1694
+ function childOf(p, c) {
1695
+ if (p === c) { return false; }
1696
+ while (c && c !== p) { c = c.parentNode; }
1697
+ return c === p;
1698
+ }
1699
+
1700
+ function getAdapterType(library) {
1701
+ if (library) {
1702
+ if (library.product === "Highcharts") {
1703
+ return defaultExport$1;
1704
+ } else if (library.charts) {
1705
+ return defaultExport$2;
1706
+ } else if (isFunction(library)) {
1707
+ return defaultExport;
1708
+ }
1709
+ }
1710
+ throw new Error("Unknown adapter");
1711
+ }
1712
+
1713
+ function addAdapter(library) {
1714
+ var adapterType = getAdapterType(library);
1715
+ var adapter = new adapterType(library);
1716
+
1717
+ if (adapters.indexOf(adapter) === -1) {
1718
+ adapters.push(adapter);
1719
+ }
1720
+ }
1721
+
1722
+ function loadAdapters() {
1723
+ if ("Chart" in window) {
1724
+ addAdapter(window.Chart);
1725
+ }
1726
+
1727
+ if ("Highcharts" in window) {
1728
+ addAdapter(window.Highcharts);
1729
+ }
1730
+
1731
+ if (window.google && window.google.charts) {
1732
+ addAdapter(window.google);
1733
+ }
1734
+ }
1735
+
1736
+ function dataEmpty(data, chartType) {
1737
+ if (chartType === "PieChart" || chartType === "GeoChart" || chartType === "Timeline") {
1738
+ return data.length === 0;
1739
+ } else {
1740
+ for (var i = 0; i < data.length; i++) {
1741
+ if (data[i].data.length > 0) {
1742
+ return false;
1743
+ }
1744
+ }
1745
+ return true;
1746
+ }
1747
+ }
1748
+
1749
+ function renderChart(chartType, chart) {
1750
+ if (chart.options.messages && chart.options.messages.empty && dataEmpty(chart.data, chartType)) {
1751
+ setText(chart.element, chart.options.messages.empty);
1752
+ } else {
1753
+ callAdapter(chartType, chart);
1754
+ if (chart.options.download && !chart.__downloadAttached && chart.adapter === "chartjs") {
1755
+ addDownloadButton(chart);
1756
+ }
1757
+ }
1758
+ }
1759
+
1760
+ // TODO remove chartType if cross-browser way
1761
+ // to get the name of the chart class
1762
+ function callAdapter(chartType, chart) {
1763
+ var i, adapter, fnName, adapterName;
1764
+ fnName = "render" + chartType;
1765
+ adapterName = chart.options.adapter;
1766
+
1767
+ loadAdapters();
1768
+
1769
+ for (i = 0; i < adapters.length; i++) {
1770
+ adapter = adapters[i];
1771
+ if ((!adapterName || adapterName === adapter.name) && isFunction(adapter[fnName])) {
1772
+ chart.adapter = adapter.name;
1773
+ chart.__adapterObject = adapter;
1774
+ return adapter[fnName](chart);
1775
+ }
1776
+ }
1777
+
1778
+ if (adapters.length > 0) {
1779
+ throw new Error("No charting library found for " + chartType);
1780
+ } else {
1781
+ throw new Error("No charting libraries found - be sure to include one before your charts");
1782
+ }
1783
+ }
1784
+
1785
+ // process data
1786
+
1787
+ var toFormattedKey = function (key, keyType) {
1788
+ if (keyType === "number") {
1789
+ key = toFloat(key);
1790
+ } else if (keyType === "datetime") {
1791
+ key = toDate(key);
1792
+ } else {
1793
+ key = toStr(key);
1794
+ }
1795
+ return key;
1796
+ };
1797
+
1798
+ var formatSeriesData = function (data, keyType) {
1799
+ var r = [], key, j;
1800
+ for (j = 0; j < data.length; j++) {
1801
+ if (keyType === "bubble") {
1802
+ r.push([toFloat(data[j][0]), toFloat(data[j][1]), toFloat(data[j][2])]);
1803
+ } else {
1804
+ key = toFormattedKey(data[j][0], keyType);
1805
+ r.push([key, toFloat(data[j][1])]);
1806
+ }
1807
+ }
1808
+ if (keyType === "datetime") {
1809
+ r.sort(sortByTime);
1810
+ } else if (keyType === "number") {
1811
+ r.sort(sortByNumberSeries);
1812
+ }
1813
+ return r;
1814
+ };
1815
+
1816
+ function detectXType(series, noDatetime) {
1817
+ if (detectXTypeWithFunction(series, isNumber)) {
1818
+ return "number";
1819
+ } else if (!noDatetime && detectXTypeWithFunction(series, isDate)) {
1820
+ return "datetime";
1821
+ } else {
1822
+ return "string";
1823
+ }
1824
+ }
1825
+
1826
+ function detectXTypeWithFunction(series, func) {
1827
+ var i, j, data;
1828
+ for (i = 0; i < series.length; i++) {
1829
+ data = toArr(series[i].data);
1830
+ for (j = 0; j < data.length; j++) {
1831
+ if (!func(data[j][0])) {
1832
+ return false;
1833
+ }
1834
+ }
1835
+ }
1836
+ return true;
1837
+ }
1838
+
1839
+ // creates a shallow copy of each element of the array
1840
+ // elements are expected to be objects
1841
+ function copySeries(series) {
1842
+ var newSeries = [], i, j;
1843
+ for (i = 0; i < series.length; i++) {
1844
+ var copy = {};
1845
+ for (j in series[i]) {
1846
+ if (series[i].hasOwnProperty(j)) {
1847
+ copy[j] = series[i][j];
1848
+ }
1849
+ }
1850
+ newSeries.push(copy);
1851
+ }
1852
+ return newSeries;
1853
+ }
1854
+
1855
+ function processSeries(chart, keyType, noDatetime) {
1856
+ var i;
1857
+
1858
+ var opts = chart.options;
1859
+ var series = chart.rawData;
1860
+
1861
+ // see if one series or multiple
1862
+ if (!isArray(series) || typeof series[0] !== "object" || isArray(series[0])) {
1863
+ series = [{name: opts.label, data: series}];
1864
+ chart.hideLegend = true;
1865
+ } else {
1866
+ chart.hideLegend = false;
1867
+ }
1868
+
1869
+ chart.xtype = keyType ? keyType : (opts.discrete ? "string" : detectXType(series, noDatetime));
1870
+
1871
+ // right format
1872
+ series = copySeries(series);
1873
+ for (i = 0; i < series.length; i++) {
1874
+ series[i].data = formatSeriesData(toArr(series[i].data), chart.xtype);
1875
+ }
1876
+
1877
+ return series;
1878
+ }
1879
+
1880
+ function processSimple(chart) {
1881
+ var perfectData = toArr(chart.rawData), i;
1882
+ for (i = 0; i < perfectData.length; i++) {
1883
+ perfectData[i] = [toStr(perfectData[i][0]), toFloat(perfectData[i][1])];
1884
+ }
1885
+ return perfectData;
1886
+ }
1887
+
1888
+ // define classes
1889
+
1890
+ var Chart = function Chart(element, dataSource, options) {
1891
+ var elementId;
1892
+ if (typeof element === "string") {
1893
+ elementId = element;
1894
+ element = document.getElementById(element);
1895
+ if (!element) {
1896
+ throw new Error("No element with id " + elementId);
1897
+ }
1898
+ }
1899
+ this.element = element;
1900
+ this.options = merge(Chartkick.options, options || {});
1901
+ this.dataSource = dataSource;
1902
+
1903
+ Chartkick.charts[element.id] = this;
1904
+
1905
+ fetchDataSource(this, dataSource);
1906
+
1907
+ if (this.options.refresh) {
1908
+ this.startRefresh();
1909
+ }
1910
+ };
1911
+
1912
+ Chart.prototype.getElement = function getElement () {
1913
+ return this.element;
1914
+ };
1915
+
1916
+ Chart.prototype.getDataSource = function getDataSource () {
1917
+ return this.dataSource;
1918
+ };
1919
+
1920
+ Chart.prototype.getData = function getData () {
1921
+ return this.data;
1922
+ };
1923
+
1924
+ Chart.prototype.getOptions = function getOptions () {
1925
+ return this.options;
1926
+ };
1927
+
1928
+ Chart.prototype.getChartObject = function getChartObject () {
1929
+ return this.chart;
1930
+ };
1931
+
1932
+ Chart.prototype.getAdapter = function getAdapter () {
1933
+ return this.adapter;
1934
+ };
1935
+
1936
+ Chart.prototype.updateData = function updateData (dataSource, options) {
1937
+ this.dataSource = dataSource;
1938
+ if (options) {
1939
+ this.__updateOptions(options);
1940
+ }
1941
+ fetchDataSource(this, dataSource);
1942
+ };
1943
+
1944
+ Chart.prototype.setOptions = function setOptions (options) {
1945
+ this.__updateOptions(options);
1946
+ this.redraw();
1947
+ };
1948
+
1949
+ Chart.prototype.redraw = function redraw () {
1950
+ fetchDataSource(this, this.rawData);
1951
+ };
1952
+
1953
+ Chart.prototype.refreshData = function refreshData () {
1954
+ if (typeof this.dataSource === "string") {
1955
+ // prevent browser from caching
1956
+ var sep = this.dataSource.indexOf("?") === -1 ? "?" : "&";
1957
+ var url = this.dataSource + sep + "_=" + (new Date()).getTime();
1958
+ fetchDataSource(this, url);
1959
+ }
1960
+ };
1961
+
1962
+ Chart.prototype.startRefresh = function startRefresh () {
1963
+ var this$1 = this;
1964
+
1965
+ var refresh = this.options.refresh;
1966
+
1967
+ if (refresh && typeof this.dataSource !== "string") {
1968
+ throw new Error("Data source must be a URL for refresh");
1969
+ }
1970
+
1971
+ if (!this.intervalId) {
1972
+ if (refresh) {
1973
+ this.intervalId = setInterval( function () {
1974
+ this$1.refreshData();
1975
+ }, refresh * 1000);
1976
+ } else {
1977
+ throw new Error("No refresh interval");
1978
+ }
1979
+ }
1980
+ };
1981
+
1982
+ Chart.prototype.stopRefresh = function stopRefresh () {
1983
+ if (this.intervalId) {
1984
+ clearInterval(this.intervalId);
1985
+ this.intervalId = null;
1986
+ }
1987
+ };
1988
+
1989
+ Chart.prototype.toImage = function toImage (download) {
1990
+ if (this.adapter === "chartjs") {
1991
+ if (download && download.background && download.background !== "transparent") {
1992
+ // https://stackoverflow.com/questions/30464750/chartjs-line-chart-set-background-color
1993
+ var canvas = this.chart.chart.canvas;
1994
+ var ctx = this.chart.chart.ctx;
1995
+ var tmpCanvas = document.createElement("canvas");
1996
+ var tmpCtx = tmpCanvas.getContext("2d");
1997
+ tmpCanvas.width = ctx.canvas.width;
1998
+ tmpCanvas.height = ctx.canvas.height;
1999
+ tmpCtx.fillStyle = download.background;
2000
+ tmpCtx.fillRect(0, 0, tmpCanvas.width, tmpCanvas.height);
2001
+ tmpCtx.drawImage(canvas, 0, 0);
2002
+ return tmpCanvas.toDataURL("image/png");
2003
+ } else {
2004
+ return this.chart.toBase64Image();
2005
+ }
2006
+ } else {
2007
+ // TODO throw error in next major version
2008
+ // throw new Error("Feature only available for Chart.js");
2009
+ return null;
2010
+ }
2011
+ };
2012
+
2013
+ Chart.prototype.destroy = function destroy () {
2014
+ if (this.__adapterObject) {
2015
+ this.__adapterObject.destroy(this);
2016
+ }
2017
+
2018
+ if (this.__enterEvent) {
2019
+ removeEvent(this.element, "mouseover", this.__enterEvent);
2020
+ }
2021
+
2022
+ if (this.__leaveEvent) {
2023
+ removeEvent(this.element, "mouseout", this.__leaveEvent);
2024
+ }
2025
+ };
2026
+
2027
+ Chart.prototype.__updateOptions = function __updateOptions (options) {
2028
+ var updateRefresh = options.refresh && options.refresh !== this.options.refresh;
2029
+ this.options = merge(Chartkick.options, options);
2030
+ if (updateRefresh) {
2031
+ this.stopRefresh();
2032
+ this.startRefresh();
2033
+ }
2034
+ };
2035
+
2036
+ Chart.prototype.__render = function __render () {
2037
+ this.data = this.__processData();
2038
+ renderChart(this.__chartName(), this);
2039
+ };
2040
+
2041
+ Chart.prototype.__config = function __config () {
2042
+ return config;
2043
+ };
2044
+
2045
+ var LineChart = /*@__PURE__*/(function (Chart) {
2046
+ function LineChart () {
2047
+ Chart.apply(this, arguments);
2048
+ }
2049
+
2050
+ if ( Chart ) LineChart.__proto__ = Chart;
2051
+ LineChart.prototype = Object.create( Chart && Chart.prototype );
2052
+ LineChart.prototype.constructor = LineChart;
2053
+
2054
+ LineChart.prototype.__processData = function __processData () {
2055
+ return processSeries(this);
2056
+ };
2057
+
2058
+ LineChart.prototype.__chartName = function __chartName () {
2059
+ return "LineChart";
2060
+ };
2061
+
2062
+ return LineChart;
2063
+ }(Chart));
2064
+
2065
+ var PieChart = /*@__PURE__*/(function (Chart) {
2066
+ function PieChart () {
2067
+ Chart.apply(this, arguments);
2068
+ }
2069
+
2070
+ if ( Chart ) PieChart.__proto__ = Chart;
2071
+ PieChart.prototype = Object.create( Chart && Chart.prototype );
2072
+ PieChart.prototype.constructor = PieChart;
2073
+
2074
+ PieChart.prototype.__processData = function __processData () {
2075
+ return processSimple(this);
2076
+ };
2077
+
2078
+ PieChart.prototype.__chartName = function __chartName () {
2079
+ return "PieChart";
2080
+ };
2081
+
2082
+ return PieChart;
2083
+ }(Chart));
2084
+
2085
+ var ColumnChart = /*@__PURE__*/(function (Chart) {
2086
+ function ColumnChart () {
2087
+ Chart.apply(this, arguments);
2088
+ }
2089
+
2090
+ if ( Chart ) ColumnChart.__proto__ = Chart;
2091
+ ColumnChart.prototype = Object.create( Chart && Chart.prototype );
2092
+ ColumnChart.prototype.constructor = ColumnChart;
2093
+
2094
+ ColumnChart.prototype.__processData = function __processData () {
2095
+ return processSeries(this, null, true);
2096
+ };
2097
+
2098
+ ColumnChart.prototype.__chartName = function __chartName () {
2099
+ return "ColumnChart";
2100
+ };
2101
+
2102
+ return ColumnChart;
2103
+ }(Chart));
2104
+
2105
+ var BarChart = /*@__PURE__*/(function (Chart) {
2106
+ function BarChart () {
2107
+ Chart.apply(this, arguments);
2108
+ }
2109
+
2110
+ if ( Chart ) BarChart.__proto__ = Chart;
2111
+ BarChart.prototype = Object.create( Chart && Chart.prototype );
2112
+ BarChart.prototype.constructor = BarChart;
2113
+
2114
+ BarChart.prototype.__processData = function __processData () {
2115
+ return processSeries(this, null, true);
2116
+ };
2117
+
2118
+ BarChart.prototype.__chartName = function __chartName () {
2119
+ return "BarChart";
2120
+ };
2121
+
2122
+ return BarChart;
2123
+ }(Chart));
2124
+
2125
+ var AreaChart = /*@__PURE__*/(function (Chart) {
2126
+ function AreaChart () {
2127
+ Chart.apply(this, arguments);
2128
+ }
2129
+
2130
+ if ( Chart ) AreaChart.__proto__ = Chart;
2131
+ AreaChart.prototype = Object.create( Chart && Chart.prototype );
2132
+ AreaChart.prototype.constructor = AreaChart;
2133
+
2134
+ AreaChart.prototype.__processData = function __processData () {
2135
+ return processSeries(this);
2136
+ };
2137
+
2138
+ AreaChart.prototype.__chartName = function __chartName () {
2139
+ return "AreaChart";
2140
+ };
2141
+
2142
+ return AreaChart;
2143
+ }(Chart));
2144
+
2145
+ var GeoChart = /*@__PURE__*/(function (Chart) {
2146
+ function GeoChart () {
2147
+ Chart.apply(this, arguments);
2148
+ }
2149
+
2150
+ if ( Chart ) GeoChart.__proto__ = Chart;
2151
+ GeoChart.prototype = Object.create( Chart && Chart.prototype );
2152
+ GeoChart.prototype.constructor = GeoChart;
2153
+
2154
+ GeoChart.prototype.__processData = function __processData () {
2155
+ return processSimple(this);
2156
+ };
2157
+
2158
+ GeoChart.prototype.__chartName = function __chartName () {
2159
+ return "GeoChart";
2160
+ };
2161
+
2162
+ return GeoChart;
2163
+ }(Chart));
2164
+
2165
+ var ScatterChart = /*@__PURE__*/(function (Chart) {
2166
+ function ScatterChart () {
2167
+ Chart.apply(this, arguments);
2168
+ }
2169
+
2170
+ if ( Chart ) ScatterChart.__proto__ = Chart;
2171
+ ScatterChart.prototype = Object.create( Chart && Chart.prototype );
2172
+ ScatterChart.prototype.constructor = ScatterChart;
2173
+
2174
+ ScatterChart.prototype.__processData = function __processData () {
2175
+ return processSeries(this, "number");
2176
+ };
2177
+
2178
+ ScatterChart.prototype.__chartName = function __chartName () {
2179
+ return "ScatterChart";
2180
+ };
2181
+
2182
+ return ScatterChart;
2183
+ }(Chart));
2184
+
2185
+ var BubbleChart = /*@__PURE__*/(function (Chart) {
2186
+ function BubbleChart () {
2187
+ Chart.apply(this, arguments);
2188
+ }
2189
+
2190
+ if ( Chart ) BubbleChart.__proto__ = Chart;
2191
+ BubbleChart.prototype = Object.create( Chart && Chart.prototype );
2192
+ BubbleChart.prototype.constructor = BubbleChart;
2193
+
2194
+ BubbleChart.prototype.__processData = function __processData () {
2195
+ return processSeries(this, "bubble");
2196
+ };
2197
+
2198
+ BubbleChart.prototype.__chartName = function __chartName () {
2199
+ return "BubbleChart";
2200
+ };
2201
+
2202
+ return BubbleChart;
2203
+ }(Chart));
2204
+
2205
+ var Timeline = /*@__PURE__*/(function (Chart) {
2206
+ function Timeline () {
2207
+ Chart.apply(this, arguments);
2208
+ }
2209
+
2210
+ if ( Chart ) Timeline.__proto__ = Chart;
2211
+ Timeline.prototype = Object.create( Chart && Chart.prototype );
2212
+ Timeline.prototype.constructor = Timeline;
2213
+
2214
+ Timeline.prototype.__processData = function __processData () {
2215
+ var i, data = this.rawData;
2216
+ for (i = 0; i < data.length; i++) {
2217
+ data[i][1] = toDate(data[i][1]);
2218
+ data[i][2] = toDate(data[i][2]);
2219
+ }
2220
+ return data;
2221
+ };
2222
+
2223
+ Timeline.prototype.__chartName = function __chartName () {
2224
+ return "Timeline";
2225
+ };
2226
+
2227
+ return Timeline;
2228
+ }(Chart));
2229
+
2230
+ var Chartkick = {
2231
+ LineChart: LineChart,
2232
+ PieChart: PieChart,
2233
+ ColumnChart: ColumnChart,
2234
+ BarChart: BarChart,
2235
+ AreaChart: AreaChart,
2236
+ GeoChart: GeoChart,
2237
+ ScatterChart: ScatterChart,
2238
+ BubbleChart: BubbleChart,
2239
+ Timeline: Timeline,
2240
+ charts: {},
2241
+ configure: function (options) {
2242
+ for (var key in options) {
2243
+ if (options.hasOwnProperty(key)) {
2244
+ config[key] = options[key];
2245
+ }
2246
+ }
2247
+ },
2248
+ setDefaultOptions: function (opts) {
2249
+ Chartkick.options = opts;
2250
+ },
2251
+ eachChart: function (callback) {
2252
+ for (var chartId in Chartkick.charts) {
2253
+ if (Chartkick.charts.hasOwnProperty(chartId)) {
2254
+ callback(Chartkick.charts[chartId]);
2255
+ }
2256
+ }
2257
+ },
2258
+ config: config,
2259
+ options: {},
2260
+ adapters: adapters,
2261
+ addAdapter: addAdapter
2262
+ };
2263
+
2264
+ return Chartkick;
2265
+
2266
+ })));