chartkick 2.3.5 → 3.3.0

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.

Potentially problematic release.


This version of chartkick might be problematic. Click here for more details.

@@ -2,14 +2,14 @@
2
2
  * Chartkick.js
3
3
  * Create beautiful charts with one line of JavaScript
4
4
  * https://github.com/ankane/chartkick.js
5
- * v2.3.6
5
+ * v3.2.0
6
6
  * MIT License
7
7
  */
8
8
 
9
9
  (function (global, factory) {
10
10
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
11
11
  typeof define === 'function' && define.amd ? define(factory) :
12
- (global.Chartkick = factory());
12
+ (global = global || self, global.Chartkick = factory());
13
13
  }(this, (function () { 'use strict';
14
14
 
15
15
  function isArray(variable) {
@@ -21,13 +21,17 @@
21
21
  }
22
22
 
23
23
  function isPlainObject(variable) {
24
- return !isFunction(variable) && variable instanceof Object;
24
+ // protect against prototype pollution, defense 2
25
+ return Object.prototype.toString.call(variable) === "[object Object]" && !isFunction(variable) && variable instanceof Object;
25
26
  }
26
27
 
27
28
  // https://github.com/madrobby/zepto/blob/master/src/zepto.js
28
29
  function extend(target, source) {
29
30
  var key;
30
31
  for (key in source) {
32
+ // protect against prototype pollution, defense 1
33
+ if (key === "__proto__") { continue; }
34
+
31
35
  if (isPlainObject(source[key]) || isArray(source[key])) {
32
36
  if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
33
37
  target[key] = {};
@@ -233,7 +237,11 @@
233
237
  return !isNaN(toDate(obj)) && toStr(obj).length >= 6;
234
238
  }
235
239
 
236
- function formatValue(pre, value, options) {
240
+ function isNumber(obj) {
241
+ return typeof obj === "number";
242
+ }
243
+
244
+ function formatValue(pre, value, options, axis) {
237
245
  pre = pre || "";
238
246
  if (options.prefix) {
239
247
  if (value < 0) {
@@ -243,6 +251,58 @@
243
251
  pre += options.prefix;
244
252
  }
245
253
 
254
+ var suffix = options.suffix || "";
255
+ var precision = options.precision;
256
+ var round = options.round;
257
+
258
+ if (options.byteScale) {
259
+ var baseValue = axis ? options.byteScale : value;
260
+ if (baseValue >= 1099511627776) {
261
+ value /= 1099511627776;
262
+ suffix = " TB";
263
+ } else if (baseValue >= 1073741824) {
264
+ value /= 1073741824;
265
+ suffix = " GB";
266
+ } else if (baseValue >= 1048576) {
267
+ value /= 1048576;
268
+ suffix = " MB";
269
+ } else if (baseValue >= 1024) {
270
+ value /= 1024;
271
+ suffix = " KB";
272
+ } else {
273
+ suffix = " bytes";
274
+ }
275
+
276
+ if (precision === undefined && round === undefined) {
277
+ precision = 3;
278
+ }
279
+ }
280
+
281
+ if (precision !== undefined && round !== undefined) {
282
+ throw Error("Use either round or precision, not both");
283
+ }
284
+
285
+ if (!axis) {
286
+ if (precision !== undefined) {
287
+ value = value.toPrecision(precision);
288
+ if (!options.zeros) {
289
+ value = parseFloat(value);
290
+ }
291
+ }
292
+
293
+ if (round !== undefined) {
294
+ if (round < 0) {
295
+ var num = Math.pow(10, -1 * round);
296
+ value = parseInt((1.0 * value / num).toFixed(0)) * num;
297
+ } else {
298
+ value = value.toFixed(round);
299
+ if (!options.zeros) {
300
+ value = parseFloat(value);
301
+ }
302
+ }
303
+ }
304
+ }
305
+
246
306
  if (options.thousands || options.decimal) {
247
307
  value = toStr(value);
248
308
  var parts = value.split(".");
@@ -255,7 +315,16 @@
255
315
  }
256
316
  }
257
317
 
258
- return pre + value + (options.suffix || "");
318
+ return pre + value + suffix;
319
+ }
320
+
321
+ function seriesOption(chart, series, option) {
322
+ if (option in series) {
323
+ return series[option];
324
+ } else if (option in chart.options) {
325
+ return chart.options[option];
326
+ }
327
+ return null;
259
328
  }
260
329
 
261
330
  function allZeros(data) {
@@ -371,25 +440,35 @@
371
440
  options.scales.yAxes[0].scaleLabel.labelString = title;
372
441
  };
373
442
 
374
- // http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
443
+ // https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
375
444
  var addOpacity = function(hex, opacity) {
376
445
  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
377
446
  return result ? "rgba(" + parseInt(result[1], 16) + ", " + parseInt(result[2], 16) + ", " + parseInt(result[3], 16) + ", " + opacity + ")" : hex;
378
447
  };
379
448
 
449
+ // check if not null or undefined
450
+ // https://stackoverflow.com/a/27757708/1177228
451
+ var notnull = function(x) {
452
+ return x != null;
453
+ };
454
+
380
455
  var setLabelSize = function (chart, data, options) {
381
456
  var maxLabelSize = Math.ceil(chart.element.offsetWidth / 4.0 / data.labels.length);
382
457
  if (maxLabelSize > 25) {
383
458
  maxLabelSize = 25;
459
+ } else if (maxLabelSize < 10) {
460
+ maxLabelSize = 10;
461
+ }
462
+ if (!options.scales.xAxes[0].ticks.callback) {
463
+ options.scales.xAxes[0].ticks.callback = function (value) {
464
+ value = toStr(value);
465
+ if (value.length > maxLabelSize) {
466
+ return value.substring(0, maxLabelSize - 2) + "...";
467
+ } else {
468
+ return value;
469
+ }
470
+ };
384
471
  }
385
- options.scales.xAxes[0].ticks.callback = function (value) {
386
- value = toStr(value);
387
- if (value.length > maxLabelSize) {
388
- return value.substring(0, maxLabelSize - 2) + "...";
389
- } else {
390
- return value;
391
- }
392
- };
393
472
  };
394
473
 
395
474
  var setFormatOptions = function(chart, options, chartType) {
@@ -397,58 +476,113 @@
397
476
  prefix: chart.options.prefix,
398
477
  suffix: chart.options.suffix,
399
478
  thousands: chart.options.thousands,
400
- decimal: chart.options.decimal
479
+ decimal: chart.options.decimal,
480
+ precision: chart.options.precision,
481
+ round: chart.options.round,
482
+ zeros: chart.options.zeros
401
483
  };
402
484
 
403
- if (formatOptions.prefix || formatOptions.suffix || formatOptions.thousands || formatOptions.decimal) {
404
- if (chartType !== "pie") {
405
- var myAxes = options.scales.yAxes;
406
- if (chartType === "bar") {
407
- myAxes = options.scales.xAxes;
408
- }
485
+ if (chart.options.bytes) {
486
+ var series = chart.data;
487
+ if (chartType === "pie") {
488
+ series = [{data: series}];
489
+ }
409
490
 
410
- if (!myAxes[0].ticks.callback) {
411
- myAxes[0].ticks.callback = function (value) {
412
- return formatValue("", value, formatOptions);
413
- };
491
+ // calculate max
492
+ var max = 0;
493
+ for (var i = 0; i < series.length; i++) {
494
+ var s = series[i];
495
+ for (var j = 0; j < s.data.length; j++) {
496
+ if (s.data[j][1] > max) {
497
+ max = s.data[j][1];
498
+ }
414
499
  }
415
500
  }
416
501
 
417
- if (!options.tooltips.callbacks.label) {
418
- if (chartType !== "pie") {
419
- var valueLabel = chartType === "bar" ? "xLabel" : "yLabel";
420
- options.tooltips.callbacks.label = function (tooltipItem, data) {
421
- var label = data.datasets[tooltipItem.datasetIndex].label || '';
422
- if (label) {
423
- label += ': ';
424
- }
425
- return formatValue(label, tooltipItem[valueLabel], formatOptions);
426
- };
427
- } else {
428
- // need to use separate label for pie charts
429
- options.tooltips.callbacks.label = function (tooltipItem, data) {
430
- var dataLabel = data.labels[tooltipItem.index];
431
- var value = ': ';
432
-
433
- if (isArray(dataLabel)) {
434
- // show value on first line of multiline label
435
- // need to clone because we are changing the value
436
- dataLabel = dataLabel.slice();
437
- dataLabel[0] += value;
438
- } else {
439
- dataLabel += value;
440
- }
502
+ // calculate scale
503
+ var scale = 1;
504
+ while (max >= 1024) {
505
+ scale *= 1024;
506
+ max /= 1024;
507
+ }
441
508
 
442
- return formatValue(dataLabel, data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index], formatOptions);
443
- };
509
+ // set step size
510
+ formatOptions.byteScale = scale;
511
+ }
512
+
513
+ if (chartType !== "pie") {
514
+ var myAxes = options.scales.yAxes;
515
+ if (chartType === "bar") {
516
+ myAxes = options.scales.xAxes;
517
+ }
518
+
519
+ if (formatOptions.byteScale) {
520
+ if (!myAxes[0].ticks.stepSize) {
521
+ myAxes[0].ticks.stepSize = formatOptions.byteScale / 2;
522
+ }
523
+ if (!myAxes[0].ticks.maxTicksLimit) {
524
+ myAxes[0].ticks.maxTicksLimit = 4;
444
525
  }
445
526
  }
527
+
528
+ if (!myAxes[0].ticks.callback) {
529
+ myAxes[0].ticks.callback = function (value) {
530
+ return formatValue("", value, formatOptions, true);
531
+ };
532
+ }
533
+ }
534
+
535
+ if (!options.tooltips.callbacks.label) {
536
+ if (chartType === "scatter") {
537
+ options.tooltips.callbacks.label = function (item, data) {
538
+ var label = data.datasets[item.datasetIndex].label || '';
539
+ if (label) {
540
+ label += ': ';
541
+ }
542
+ return label + '(' + item.xLabel + ', ' + item.yLabel + ')';
543
+ };
544
+ } else if (chartType === "bubble") {
545
+ options.tooltips.callbacks.label = function (item, data) {
546
+ var label = data.datasets[item.datasetIndex].label || '';
547
+ if (label) {
548
+ label += ': ';
549
+ }
550
+ var dataPoint = data.datasets[item.datasetIndex].data[item.index];
551
+ return label + '(' + item.xLabel + ', ' + item.yLabel + ', ' + dataPoint.v + ')';
552
+ };
553
+ } else if (chartType === "pie") {
554
+ // need to use separate label for pie charts
555
+ options.tooltips.callbacks.label = function (tooltipItem, data) {
556
+ var dataLabel = data.labels[tooltipItem.index];
557
+ var value = ': ';
558
+
559
+ if (isArray(dataLabel)) {
560
+ // show value on first line of multiline label
561
+ // need to clone because we are changing the value
562
+ dataLabel = dataLabel.slice();
563
+ dataLabel[0] += value;
564
+ } else {
565
+ dataLabel += value;
566
+ }
567
+
568
+ return formatValue(dataLabel, data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index], formatOptions);
569
+ };
570
+ } else {
571
+ var valueLabel = chartType === "bar" ? "xLabel" : "yLabel";
572
+ options.tooltips.callbacks.label = function (tooltipItem, data) {
573
+ var label = data.datasets[tooltipItem.datasetIndex].label || '';
574
+ if (label) {
575
+ label += ': ';
576
+ }
577
+ return formatValue(label, tooltipItem[valueLabel], formatOptions);
578
+ };
579
+ }
446
580
  }
447
581
  };
448
582
 
449
583
  var jsOptions = jsOptionsFunc(merge(baseOptions, defaultOptions), hideLegend, setTitle, setMin, setMax, setStacked, setXtitle, setYtitle);
450
584
 
451
- var createDataTable = function (chart, options, chartType) {
585
+ var createDataTable = function (chart, options, chartType, library) {
452
586
  var datasets = [];
453
587
  var labels = [];
454
588
 
@@ -461,61 +595,92 @@
461
595
  var year = true;
462
596
  var hour = true;
463
597
  var minute = true;
464
- var detectType = (chartType === "line" || chartType === "area") && !chart.discrete;
465
598
 
466
599
  var series = chart.data;
467
600
 
468
- var sortedLabels = [];
469
-
470
- var i, j, s, d, key, rows = [];
471
- for (i = 0; i < series.length; i++) {
472
- s = series[i];
473
-
474
- for (j = 0; j < s.data.length; j++) {
475
- d = s.data[j];
476
- key = detectType ? d[0].getTime() : d[0];
477
- if (!rows[key]) {
478
- rows[key] = new Array(series.length);
479
- }
480
- rows[key][i] = toFloat(d[1]);
481
- if (sortedLabels.indexOf(key) === -1) {
482
- sortedLabels.push(key);
601
+ var max = 0;
602
+ if (chartType === "bubble") {
603
+ for (var i$1 = 0; i$1 < series.length; i$1++) {
604
+ var s$1 = series[i$1];
605
+ for (var j$1 = 0; j$1 < s$1.data.length; j$1++) {
606
+ if (s$1.data[j$1][2] > max) {
607
+ max = s$1.data[j$1][2];
608
+ }
483
609
  }
484
610
  }
485
611
  }
486
612
 
487
- if (detectType || chart.options.xtype === "number") {
488
- sortedLabels.sort(sortByNumber);
489
- }
613
+ var i, j, s, d, key, rows = [], rows2 = [];
490
614
 
491
- var rows2 = [];
492
- for (j = 0; j < series.length; j++) {
493
- rows2.push([]);
494
- }
615
+ if (chartType === "bar" || chartType === "column" || (chart.xtype !== "number" && chart.xtype !== "bubble")) {
616
+ var sortedLabels = [];
495
617
 
496
- var value;
497
- var k;
498
- for (k = 0; k < sortedLabels.length; k++) {
499
- i = sortedLabels[k];
500
- if (detectType) {
501
- value = new Date(toFloat(i));
502
- // TODO make this efficient
503
- day = day && isDay(value);
504
- if (!dayOfWeek) {
505
- dayOfWeek = value.getDay();
618
+ for (i = 0; i < series.length; i++) {
619
+ s = series[i];
620
+
621
+ for (j = 0; j < s.data.length; j++) {
622
+ d = s.data[j];
623
+ key = chart.xtype == "datetime" ? d[0].getTime() : d[0];
624
+ if (!rows[key]) {
625
+ rows[key] = new Array(series.length);
626
+ }
627
+ rows[key][i] = toFloat(d[1]);
628
+ if (sortedLabels.indexOf(key) === -1) {
629
+ sortedLabels.push(key);
630
+ }
506
631
  }
507
- week = week && isWeek(value, dayOfWeek);
508
- month = month && isMonth(value);
509
- year = year && isYear(value);
510
- hour = hour && isHour(value);
511
- minute = minute && isMinute(value);
512
- } else {
513
- value = i;
514
632
  }
515
- labels.push(value);
633
+
634
+ if (chart.xtype === "datetime" || chart.xtype === "number") {
635
+ sortedLabels.sort(sortByNumber);
636
+ }
637
+
516
638
  for (j = 0; j < series.length; j++) {
517
- // Chart.js doesn't like undefined
518
- rows2[j].push(rows[i][j] === undefined ? null : rows[i][j]);
639
+ rows2.push([]);
640
+ }
641
+
642
+ var value;
643
+ var k;
644
+ for (k = 0; k < sortedLabels.length; k++) {
645
+ i = sortedLabels[k];
646
+ if (chart.xtype === "datetime") {
647
+ value = new Date(toFloat(i));
648
+ // TODO make this efficient
649
+ day = day && isDay(value);
650
+ if (!dayOfWeek) {
651
+ dayOfWeek = value.getDay();
652
+ }
653
+ week = week && isWeek(value, dayOfWeek);
654
+ month = month && isMonth(value);
655
+ year = year && isYear(value);
656
+ hour = hour && isHour(value);
657
+ minute = minute && isMinute(value);
658
+ } else {
659
+ value = i;
660
+ }
661
+ labels.push(value);
662
+ for (j = 0; j < series.length; j++) {
663
+ // Chart.js doesn't like undefined
664
+ rows2[j].push(rows[i][j] === undefined ? null : rows[i][j]);
665
+ }
666
+ }
667
+ } else {
668
+ for (var i$2 = 0; i$2 < series.length; i$2++) {
669
+ var s$2 = series[i$2];
670
+ var d$1 = [];
671
+ for (var j$2 = 0; j$2 < s$2.data.length; j$2++) {
672
+ var point = {
673
+ x: toFloat(s$2.data[j$2][0]),
674
+ y: toFloat(s$2.data[j$2][1])
675
+ };
676
+ if (chartType === "bubble") {
677
+ point.r = toFloat(s$2.data[j$2][2]) * 20 / max;
678
+ // custom attribute, for tooltip
679
+ point.v = s$2.data[j$2][2];
680
+ }
681
+ d$1.push(point);
682
+ }
683
+ rows2.push(d$1);
519
684
  }
520
685
  }
521
686
 
@@ -526,25 +691,27 @@
526
691
  var backgroundColor = chartType !== "line" ? addOpacity(color, 0.5) : color;
527
692
 
528
693
  var dataset = {
529
- label: s.name,
694
+ label: s.name || "",
530
695
  data: rows2[i],
531
696
  fill: chartType === "area",
532
697
  borderColor: color,
533
698
  backgroundColor: backgroundColor,
534
699
  pointBackgroundColor: color,
535
- pointHoverBackgroundColor: color,
536
- borderWidth: 2
700
+ borderWidth: 2,
701
+ pointHoverBackgroundColor: color
537
702
  };
538
703
 
539
704
  if (s.stack) {
540
705
  dataset.stack = s.stack;
541
706
  }
542
707
 
543
- if (chart.options.curve === false) {
708
+ var curve = seriesOption(chart, s, "curve");
709
+ if (curve === false) {
544
710
  dataset.lineTension = 0;
545
711
  }
546
712
 
547
- if (chart.options.points === false) {
713
+ var points = seriesOption(chart, s, "points");
714
+ if (points === false) {
548
715
  dataset.pointRadius = 0;
549
716
  dataset.pointHitRadius = 5;
550
717
  }
@@ -556,16 +723,40 @@
556
723
  datasets.push(dataset);
557
724
  }
558
725
 
559
- if (detectType && labels.length > 0) {
560
- var minTime = labels[0].getTime();
561
- var maxTime = labels[0].getTime();
726
+ var xmin = chart.options.xmin;
727
+ var xmax = chart.options.xmax;
728
+
729
+ if (chart.xtype === "datetime") {
730
+ // hacky check for Chart.js >= 2.9.0
731
+ // https://github.com/chartjs/Chart.js/compare/v2.8.0...v2.9.0
732
+ var gte29 = "math" in library.helpers;
733
+ var ticksKey = gte29 ? "ticks" : "time";
734
+ if (notnull(xmin)) {
735
+ options.scales.xAxes[0][ticksKey].min = toDate(xmin).getTime();
736
+ }
737
+ if (notnull(xmax)) {
738
+ options.scales.xAxes[0][ticksKey].max = toDate(xmax).getTime();
739
+ }
740
+ } else if (chart.xtype === "number") {
741
+ if (notnull(xmin)) {
742
+ options.scales.xAxes[0].ticks.min = xmin;
743
+ }
744
+ if (notnull(xmax)) {
745
+ options.scales.xAxes[0].ticks.max = xmax;
746
+ }
747
+ }
748
+
749
+ if (chart.xtype === "datetime" && labels.length > 0) {
750
+ var minTime = (notnull(xmin) ? toDate(xmin) : labels[0]).getTime();
751
+ var maxTime = (notnull(xmax) ? toDate(xmax) : labels[0]).getTime();
752
+
562
753
  for (i = 1; i < labels.length; i++) {
563
- value = labels[i].getTime();
564
- if (value < minTime) {
565
- minTime = value;
754
+ var value$1 = labels[i].getTime();
755
+ if (value$1 < minTime) {
756
+ minTime = value$1;
566
757
  }
567
- if (value > maxTime) {
568
- maxTime = value;
758
+ if (value$1 > maxTime) {
759
+ maxTime = value$1;
569
760
  }
570
761
  }
571
762
 
@@ -626,10 +817,6 @@
626
817
  };
627
818
 
628
819
  defaultExport.prototype.renderLineChart = function renderLineChart (chart, chartType) {
629
- if (chart.options.xtype === "number") {
630
- return this.renderScatterChart(chart, chartType, true);
631
- }
632
-
633
820
  var chartOptions = {};
634
821
  // fix for https://github.com/chartjs/Chart.js/issues/2441
635
822
  if (!chart.options.max && allZeros(chart.data)) {
@@ -639,9 +826,14 @@
639
826
  var options = jsOptions(chart, merge(chartOptions, chart.options));
640
827
  setFormatOptions(chart, options, chartType);
641
828
 
642
- var data = createDataTable(chart, options, chartType || "line");
829
+ var data = createDataTable(chart, options, chartType || "line", this.library);
643
830
 
644
- options.scales.xAxes[0].type = chart.discrete ? "category" : "time";
831
+ if (chart.xtype === "number") {
832
+ options.scales.xAxes[0].type = "linear";
833
+ options.scales.xAxes[0].position = "bottom";
834
+ } else {
835
+ options.scales.xAxes[0].type = chart.xtype === "string" ? "category" : "time";
836
+ }
645
837
 
646
838
  this.drawChart(chart, "line", data, options);
647
839
  };
@@ -688,12 +880,14 @@
688
880
  defaultExport.prototype.renderColumnChart = function renderColumnChart (chart, chartType) {
689
881
  var options;
690
882
  if (chartType === "bar") {
691
- options = jsOptionsFunc(merge(baseOptions, defaultOptions), hideLegend, setTitle, setBarMin, setBarMax, setStacked, setXtitle, setYtitle)(chart, chart.options);
883
+ var barOptions = merge(baseOptions, defaultOptions);
884
+ delete barOptions.scales.yAxes[0].ticks.maxTicksLimit;
885
+ options = jsOptionsFunc(barOptions, hideLegend, setTitle, setBarMin, setBarMax, setStacked, setXtitle, setYtitle)(chart, chart.options);
692
886
  } else {
693
887
  options = jsOptions(chart, chart.options);
694
888
  }
695
889
  setFormatOptions(chart, options, chartType);
696
- var data = createDataTable(chart, options, "column");
890
+ var data = createDataTable(chart, options, "column", this.library);
697
891
  if (chartType !== "bar") {
698
892
  setLabelSize(chart, data, options);
699
893
  }
@@ -708,51 +902,17 @@
708
902
  this.renderColumnChart(chart, "bar");
709
903
  };
710
904
 
711
- defaultExport.prototype.renderScatterChart = function renderScatterChart (chart, chartType, lineChart) {
712
- chartType = chartType || "line";
905
+ defaultExport.prototype.renderScatterChart = function renderScatterChart (chart, chartType) {
906
+ chartType = chartType || "scatter";
713
907
 
714
908
  var options = jsOptions(chart, chart.options);
715
- if (!lineChart) {
716
- setFormatOptions(chart, options, chartType);
717
- }
718
-
719
- var colors = chart.options.colors || defaultColors;
720
-
721
- var datasets = [];
722
- var series = chart.data;
723
- for (var i = 0; i < series.length; i++) {
724
- var s = series[i];
725
- var d = [];
726
- for (var j = 0; j < s.data.length; j++) {
727
- var point = {
728
- x: toFloat(s.data[j][0]),
729
- y: toFloat(s.data[j][1])
730
- };
731
- if (chartType === "bubble") {
732
- point.r = toFloat(s.data[j][2]);
733
- }
734
- d.push(point);
735
- }
736
-
737
- var color = s.color || colors[i];
738
- var backgroundColor = chartType === "area" ? addOpacity(color, 0.5) : color;
739
-
740
- datasets.push({
741
- label: s.name,
742
- showLine: lineChart || false,
743
- data: d,
744
- borderColor: color,
745
- backgroundColor: backgroundColor,
746
- pointBackgroundColor: color,
747
- fill: chartType === "area"
748
- });
749
- }
909
+ setFormatOptions(chart, options, chartType);
750
910
 
751
- if (chartType === "area") {
752
- chartType = "line";
911
+ if (!("showLines" in options)) {
912
+ options.showLines = false;
753
913
  }
754
914
 
755
- var data = {datasets: datasets};
915
+ var data = createDataTable(chart, options, chartType, this.library);
756
916
 
757
917
  options.scales.xAxes[0].type = "linear";
758
918
  options.scales.xAxes[0].position = "bottom";
@@ -773,13 +933,19 @@
773
933
  defaultExport.prototype.drawChart = function drawChart (chart, type, data, options) {
774
934
  this.destroy(chart);
775
935
 
776
- chart.element.innerHTML = "<canvas></canvas>";
777
- var ctx = chart.element.getElementsByTagName("CANVAS")[0];
778
- chart.chart = new this.library(ctx, {
936
+ var chartOptions = {
779
937
  type: type,
780
938
  data: data,
781
939
  options: options
782
- });
940
+ };
941
+
942
+ if (chart.options.code) {
943
+ window.console.log("new Chart(ctx, " + JSON.stringify(chartOptions) + ");");
944
+ }
945
+
946
+ chart.element.innerHTML = "<canvas></canvas>";
947
+ var ctx = chart.element.getElementsByTagName("CANVAS")[0];
948
+ chart.chart = new this.library(ctx, chartOptions);
783
949
  };
784
950
 
785
951
  var defaultOptions$1 = {
@@ -820,6 +986,7 @@
820
986
  },
821
987
  plotOptions: {
822
988
  areaspline: {},
989
+ area: {},
823
990
  series: {
824
991
  marker: {}
825
992
  }
@@ -856,7 +1023,10 @@
856
1023
  };
857
1024
 
858
1025
  var setStacked$1 = function (options, stacked) {
859
- options.plotOptions.series.stacking = stacked ? (stacked === true ? "normal" : stacked) : null;
1026
+ var stackedValue = stacked ? (stacked === true ? "normal" : stacked) : null;
1027
+ options.plotOptions.series.stacking = stackedValue;
1028
+ options.plotOptions.area.stacking = stackedValue;
1029
+ options.plotOptions.areaspline.stacking = stackedValue;
860
1030
  };
861
1031
 
862
1032
  var setXtitle$1 = function (options, title) {
@@ -874,21 +1044,22 @@
874
1044
  prefix: chart.options.prefix,
875
1045
  suffix: chart.options.suffix,
876
1046
  thousands: chart.options.thousands,
877
- decimal: chart.options.decimal
1047
+ decimal: chart.options.decimal,
1048
+ precision: chart.options.precision,
1049
+ round: chart.options.round,
1050
+ zeros: chart.options.zeros
878
1051
  };
879
1052
 
880
- if (formatOptions.prefix || formatOptions.suffix || formatOptions.thousands || formatOptions.decimal) {
881
- if (chartType !== "pie" && !options.yAxis.labels.formatter) {
882
- options.yAxis.labels.formatter = function () {
883
- return formatValue("", this.value, formatOptions);
884
- };
885
- }
1053
+ if (chartType !== "pie" && !options.yAxis.labels.formatter) {
1054
+ options.yAxis.labels.formatter = function () {
1055
+ return formatValue("", this.value, formatOptions);
1056
+ };
1057
+ }
886
1058
 
887
- if (!options.tooltip.pointFormatter) {
888
- options.tooltip.pointFormatter = function () {
889
- return '<span style="color:' + this.color + '>\u25CF</span> ' + formatValue(this.series.name + ': <b>', this.y, formatOptions) + '</b><br/>';
890
- };
891
- }
1059
+ if (!options.tooltip.pointFormatter) {
1060
+ options.tooltip.pointFormatter = function () {
1061
+ return '<span style="color:' + this.color + '">\u25CF</span> ' + formatValue(this.series.name + ': <b>', this.y, formatOptions) + '</b><br/>';
1062
+ };
892
1063
  }
893
1064
  };
894
1065
 
@@ -927,7 +1098,7 @@
927
1098
  }
928
1099
 
929
1100
  var options = jsOptions$1(chart, chart.options, chartOptions), data, i, j;
930
- options.xAxis.type = chart.discrete ? "category" : "datetime";
1101
+ options.xAxis.type = chart.xtype === "string" ? "category" : (chart.xtype === "number" ? "linear" : "datetime");
931
1102
  if (!options.chart.type) {
932
1103
  options.chart.type = chartType;
933
1104
  }
@@ -935,8 +1106,9 @@
935
1106
 
936
1107
  var series = chart.data;
937
1108
  for (i = 0; i < series.length; i++) {
1109
+ series[i].name = series[i].name || "Value";
938
1110
  data = series[i].data;
939
- if (!chart.discrete) {
1111
+ if (chart.xtype === "datetime") {
940
1112
  for (j = 0; j < data.length; j++) {
941
1113
  data[j][0] = data[j][0].getTime();
942
1114
  }
@@ -1005,7 +1177,7 @@
1005
1177
  }
1006
1178
  }
1007
1179
 
1008
- if (chart.options.xtype === "number") {
1180
+ if (chart.xtype === "number") {
1009
1181
  categories.sort(sortByNumber);
1010
1182
  }
1011
1183
 
@@ -1019,7 +1191,7 @@
1019
1191
  }
1020
1192
 
1021
1193
  d2 = {
1022
- name: series[i].name,
1194
+ name: series[i].name || "Value",
1023
1195
  data: d
1024
1196
  };
1025
1197
  if (series[i].stack) {
@@ -1051,6 +1223,11 @@
1051
1223
 
1052
1224
  options.chart.renderTo = chart.element.id;
1053
1225
  options.series = data;
1226
+
1227
+ if (chart.options.code) {
1228
+ window.console.log("new Highcharts.Chart(" + JSON.stringify(options) + ");");
1229
+ }
1230
+
1054
1231
  chart.chart = new this.library.Chart(options);
1055
1232
  };
1056
1233
 
@@ -1182,13 +1359,9 @@
1182
1359
  }
1183
1360
 
1184
1361
  var options = jsOptions$2(chart, chart.options, chartOptions);
1185
- var columnType = chart.discrete ? "string" : "datetime";
1186
- if (chart.options.xtype === "number") {
1187
- columnType = "number";
1188
- }
1189
- var data = this$1.createDataTable(chart.data, columnType);
1362
+ var data = this$1.createDataTable(chart.data, chart.xtype);
1190
1363
 
1191
- this$1.drawChart(chart, this$1.library.visualization.LineChart, data, options);
1364
+ this$1.drawChart(chart, "LineChart", data, options);
1192
1365
  });
1193
1366
  };
1194
1367
 
@@ -1222,7 +1395,7 @@
1222
1395
  data.addColumn("number", "Value");
1223
1396
  data.addRows(chart.data);
1224
1397
 
1225
- this$1.drawChart(chart, this$1.library.visualization.PieChart, data, options);
1398
+ this$1.drawChart(chart, "PieChart", data, options);
1226
1399
  });
1227
1400
  };
1228
1401
 
@@ -1231,9 +1404,9 @@
1231
1404
 
1232
1405
  this.waitForLoaded(chart, function () {
1233
1406
  var options = jsOptions$2(chart, chart.options);
1234
- var data = this$1.createDataTable(chart.data, "string", chart.options.xtype);
1407
+ var data = this$1.createDataTable(chart.data, chart.xtype);
1235
1408
 
1236
- this$1.drawChart(chart, this$1.library.visualization.ColumnChart, data, options);
1409
+ this$1.drawChart(chart, "ColumnChart", data, options);
1237
1410
  });
1238
1411
  };
1239
1412
 
@@ -1249,9 +1422,9 @@
1249
1422
  }
1250
1423
  };
1251
1424
  var options = jsOptionsFunc(defaultOptions$2, hideLegend$2, setTitle$2, setBarMin$1, setBarMax$1, setStacked$2, setXtitle$2, setYtitle$2)(chart, chart.options, chartOptions);
1252
- var data = this$1.createDataTable(chart.data, "string", chart.options.xtype);
1425
+ var data = this$1.createDataTable(chart.data, chart.xtype);
1253
1426
 
1254
- this$1.drawChart(chart, this$1.library.visualization.BarChart, data, options);
1427
+ this$1.drawChart(chart, "BarChart", data, options);
1255
1428
  });
1256
1429
  };
1257
1430
 
@@ -1266,13 +1439,9 @@
1266
1439
  };
1267
1440
 
1268
1441
  var options = jsOptions$2(chart, chart.options, chartOptions);
1269
- var columnType = chart.discrete ? "string" : "datetime";
1270
- if (chart.options.xtype === "number") {
1271
- columnType = "number";
1272
- }
1273
- var data = this$1.createDataTable(chart.data, columnType);
1442
+ var data = this$1.createDataTable(chart.data, chart.xtype);
1274
1443
 
1275
- this$1.drawChart(chart, this$1.library.visualization.AreaChart, data, options);
1444
+ this$1.drawChart(chart, "AreaChart", data, options);
1276
1445
  });
1277
1446
  };
1278
1447
 
@@ -1293,7 +1462,7 @@
1293
1462
  data.addColumn("number", chart.options.label || "Value");
1294
1463
  data.addRows(chart.data);
1295
1464
 
1296
- this$1.drawChart(chart, this$1.library.visualization.GeoChart, data, options);
1465
+ this$1.drawChart(chart, "GeoChart", data, options);
1297
1466
  });
1298
1467
  };
1299
1468
 
@@ -1306,6 +1475,7 @@
1306
1475
 
1307
1476
  var series = chart.data, rows2 = [], i, j, data, d;
1308
1477
  for (i = 0; i < series.length; i++) {
1478
+ series[i].name = series[i].name || "Value";
1309
1479
  d = series[i].data;
1310
1480
  for (j = 0; j < d.length; j++) {
1311
1481
  var row = new Array(series.length + 1);
@@ -1322,7 +1492,7 @@
1322
1492
  }
1323
1493
  data.addRows(rows2);
1324
1494
 
1325
- this$1.drawChart(chart, this$1.library.visualization.ScatterChart, data, options);
1495
+ this$1.drawChart(chart, "ScatterChart", data, options);
1326
1496
  });
1327
1497
  };
1328
1498
 
@@ -1347,7 +1517,7 @@
1347
1517
 
1348
1518
  chart.element.style.lineHeight = "normal";
1349
1519
 
1350
- this$1.drawChart(chart, this$1.library.visualization.Timeline, data, options);
1520
+ this$1.drawChart(chart, "Timeline", data, options);
1351
1521
  });
1352
1522
  };
1353
1523
 
@@ -1360,7 +1530,11 @@
1360
1530
  defaultExport$2.prototype.drawChart = function drawChart (chart, type, data, options) {
1361
1531
  this.destroy(chart);
1362
1532
 
1363
- chart.chart = new type(chart.element);
1533
+ if (chart.options.code) {
1534
+ window.console.log("var data = new google.visualization.DataTable(" + data.toJSON() + ");\nvar chart = new google.visualization." + type + "(element);\nchart.draw(data, " + JSON.stringify(options) + ");");
1535
+ }
1536
+
1537
+ chart.chart = new this.library.visualization[type](chart.element);
1364
1538
  resize(function () {
1365
1539
  chart.chart.draw(data, options);
1366
1540
  });
@@ -1394,21 +1568,15 @@
1394
1568
  loadOptions.mapsApiKey = config.mapsApiKey;
1395
1569
  }
1396
1570
 
1397
- if (this.library.setOnLoadCallback) {
1398
- this.library.load("visualization", "1", loadOptions);
1399
- } else {
1400
- this.library.charts.load("current", loadOptions);
1401
- }
1571
+ this.library.charts.load("current", loadOptions);
1402
1572
  }
1403
1573
  };
1404
1574
 
1405
1575
  defaultExport$2.prototype.runCallbacks = function runCallbacks () {
1406
- var this$1 = this;
1407
-
1408
1576
  var cb, call;
1409
1577
  for (var i = 0; i < callbacks.length; i++) {
1410
1578
  cb = callbacks[i];
1411
- call = this$1.library.visualization && ((cb.pack === "corechart" && this$1.library.visualization.LineChart) || (cb.pack === "timeline" && this$1.library.visualization.Timeline));
1579
+ call = this.library.visualization && ((cb.pack === "corechart" && this.library.visualization.LineChart) || (cb.pack === "timeline" && this.library.visualization.Timeline));
1412
1580
  if (call) {
1413
1581
  cb.callback();
1414
1582
  callbacks.splice(i, 1);
@@ -1418,10 +1586,11 @@
1418
1586
  };
1419
1587
 
1420
1588
  // cant use object as key
1421
- defaultExport$2.prototype.createDataTable = function createDataTable (series, columnType, xtype) {
1589
+ defaultExport$2.prototype.createDataTable = function createDataTable (series, columnType) {
1422
1590
  var i, j, s, d, key, rows = [], sortedLabels = [];
1423
1591
  for (i = 0; i < series.length; i++) {
1424
1592
  s = series[i];
1593
+ series[i].name = series[i].name || "Value";
1425
1594
 
1426
1595
  for (j = 0; j < s.data.length; j++) {
1427
1596
  d = s.data[j];
@@ -1453,14 +1622,12 @@
1453
1622
  rows2.sort(sortByTime);
1454
1623
  } else if (columnType === "number") {
1455
1624
  rows2.sort(sortByNumberSeries);
1456
- }
1457
-
1458
- if (xtype === "number") {
1459
- rows2.sort(sortByNumberSeries);
1460
1625
 
1461
1626
  for (i = 0; i < rows2.length; i++) {
1462
1627
  rows2[i][0] = toStr(rows2[i][0]);
1463
1628
  }
1629
+
1630
+ columnType = "string";
1464
1631
  }
1465
1632
 
1466
1633
  // create datatable
@@ -1508,7 +1675,7 @@
1508
1675
  function ajaxCall(url, success, error) {
1509
1676
  var $ = window.jQuery || window.Zepto || window.$;
1510
1677
 
1511
- if ($) {
1678
+ if ($ && $.ajax) {
1512
1679
  $.ajax({
1513
1680
  dataType: "json",
1514
1681
  url: url,
@@ -1532,7 +1699,7 @@
1532
1699
  }
1533
1700
  }
1534
1701
 
1535
- var config = (typeof window !== "undefined" && window.Chartkick) || {};
1702
+ var config = {};
1536
1703
  var adapters = [];
1537
1704
 
1538
1705
  // helpers
@@ -1545,8 +1712,12 @@
1545
1712
  }
1546
1713
  }
1547
1714
 
1548
- function chartError(element, message) {
1549
- setText(element, "Error Loading Chart: " + message);
1715
+ // TODO remove prefix for all messages
1716
+ function chartError(element, message, noPrefix) {
1717
+ if (!noPrefix) {
1718
+ message = "Error Loading Chart: " + message;
1719
+ }
1720
+ setText(element, message);
1550
1721
  element.style.color = "#ff0000";
1551
1722
  }
1552
1723
 
@@ -1567,6 +1738,17 @@
1567
1738
  }, function (message) {
1568
1739
  chartError(chart.element, message);
1569
1740
  });
1741
+ } else if (typeof dataSource === "function") {
1742
+ try {
1743
+ dataSource(function (data) {
1744
+ chart.rawData = data;
1745
+ errorCatcher(chart);
1746
+ }, function (message) {
1747
+ chartError(chart.element, message, true);
1748
+ });
1749
+ } catch (err) {
1750
+ chartError(chart.element, err, true);
1751
+ }
1570
1752
  } else {
1571
1753
  chart.rawData = dataSource;
1572
1754
  errorCatcher(chart);
@@ -1576,7 +1758,15 @@
1576
1758
  function addDownloadButton(chart) {
1577
1759
  var element = chart.element;
1578
1760
  var link = document.createElement("a");
1579
- link.download = chart.options.download === true ? "chart.png" : chart.options.download; // http://caniuse.com/download
1761
+
1762
+ var download = chart.options.download;
1763
+ if (download === true) {
1764
+ download = {};
1765
+ } else if (typeof download === "string") {
1766
+ download = {filename: download};
1767
+ }
1768
+ link.download = download.filename || "chart.png"; // https://caniuse.com/download
1769
+
1580
1770
  link.style.position = "absolute";
1581
1771
  link.style.top = "20px";
1582
1772
  link.style.right = "20px";
@@ -1599,7 +1789,7 @@
1599
1789
  var related = e.relatedTarget;
1600
1790
  // check download option again to ensure it wasn't changed
1601
1791
  if ((!related || (related !== this && !childOf(this, related))) && chart.options.download) {
1602
- link.href = chart.toImage();
1792
+ link.href = chart.toImage(download);
1603
1793
  element.appendChild(link);
1604
1794
  }
1605
1795
  });
@@ -1615,7 +1805,7 @@
1615
1805
  });
1616
1806
  }
1617
1807
 
1618
- // http://stackoverflow.com/questions/10149963/adding-event-listener-cross-browser
1808
+ // https://stackoverflow.com/questions/10149963/adding-event-listener-cross-browser
1619
1809
  function addEvent(elem, event, fn) {
1620
1810
  if (elem.addEventListener) {
1621
1811
  elem.addEventListener(event, fn, false);
@@ -1649,7 +1839,7 @@
1649
1839
  if (library) {
1650
1840
  if (library.product === "Highcharts") {
1651
1841
  return defaultExport$1;
1652
- } else if (library.setOnLoadCallback || library.charts) {
1842
+ } else if (library.charts) {
1653
1843
  return defaultExport$2;
1654
1844
  } else if (isFunction(library)) {
1655
1845
  return defaultExport;
@@ -1676,7 +1866,7 @@
1676
1866
  addAdapter(window.Highcharts);
1677
1867
  }
1678
1868
 
1679
- if (window.google && (window.google.setOnLoadCallback || window.google.charts)) {
1869
+ if (window.google && window.google.charts) {
1680
1870
  addAdapter(window.google);
1681
1871
  }
1682
1872
  }
@@ -1761,17 +1951,27 @@
1761
1951
  return r;
1762
1952
  };
1763
1953
 
1764
- function detectDiscrete(series) {
1954
+ function detectXType(series, noDatetime) {
1955
+ if (detectXTypeWithFunction(series, isNumber)) {
1956
+ return "number";
1957
+ } else if (!noDatetime && detectXTypeWithFunction(series, isDate)) {
1958
+ return "datetime";
1959
+ } else {
1960
+ return "string";
1961
+ }
1962
+ }
1963
+
1964
+ function detectXTypeWithFunction(series, func) {
1765
1965
  var i, j, data;
1766
1966
  for (i = 0; i < series.length; i++) {
1767
1967
  data = toArr(series[i].data);
1768
1968
  for (j = 0; j < data.length; j++) {
1769
- if (!isDate(data[j][0])) {
1770
- return true;
1969
+ if (!func(data[j][0])) {
1970
+ return false;
1771
1971
  }
1772
1972
  }
1773
1973
  }
1774
- return false;
1974
+ return true;
1775
1975
  }
1776
1976
 
1777
1977
  // creates a shallow copy of each element of the array
@@ -1790,7 +1990,7 @@
1790
1990
  return newSeries;
1791
1991
  }
1792
1992
 
1793
- function processSeries(chart, keyType) {
1993
+ function processSeries(chart, keyType, noDatetime) {
1794
1994
  var i;
1795
1995
 
1796
1996
  var opts = chart.options;
@@ -1798,27 +1998,18 @@
1798
1998
 
1799
1999
  // see if one series or multiple
1800
2000
  if (!isArray(series) || typeof series[0] !== "object" || isArray(series[0])) {
1801
- series = [{name: opts.label || "Value", data: series}];
2001
+ series = [{name: opts.label, data: series}];
1802
2002
  chart.hideLegend = true;
1803
2003
  } else {
1804
2004
  chart.hideLegend = false;
1805
2005
  }
1806
- if ((opts.discrete === null || opts.discrete === undefined) && keyType !== "bubble" && keyType !== "number") {
1807
- chart.discrete = detectDiscrete(series);
1808
- } else {
1809
- chart.discrete = opts.discrete;
1810
- }
1811
- if (chart.discrete) {
1812
- keyType = "string";
1813
- }
1814
- if (chart.options.xtype) {
1815
- keyType = chart.options.xtype;
1816
- }
2006
+
2007
+ chart.xtype = keyType ? keyType : (opts.discrete ? "string" : detectXType(series, noDatetime));
1817
2008
 
1818
2009
  // right format
1819
2010
  series = copySeries(series);
1820
2011
  for (i = 0; i < series.length; i++) {
1821
- series[i].data = formatSeriesData(toArr(series[i].data), keyType);
2012
+ series[i].data = formatSeriesData(toArr(series[i].data), chart.xtype);
1822
2013
  }
1823
2014
 
1824
2015
  return series;
@@ -1903,6 +2094,8 @@
1903
2094
  var sep = this.dataSource.indexOf("?") === -1 ? "?" : "&";
1904
2095
  var url = this.dataSource + sep + "_=" + (new Date()).getTime();
1905
2096
  fetchDataSource(this, url);
2097
+ } else if (typeof this.dataSource === "function") {
2098
+ fetchDataSource(this, this.dataSource);
1906
2099
  }
1907
2100
  };
1908
2101
 
@@ -1911,6 +2104,10 @@
1911
2104
 
1912
2105
  var refresh = this.options.refresh;
1913
2106
 
2107
+ if (refresh && typeof this.dataSource !== "string" && typeof this.dataSource !== "function") {
2108
+ throw new Error("Data source must be a URL or callback for refresh");
2109
+ }
2110
+
1914
2111
  if (!this.intervalId) {
1915
2112
  if (refresh) {
1916
2113
  this.intervalId = setInterval( function () {
@@ -1929,10 +2126,26 @@
1929
2126
  }
1930
2127
  };
1931
2128
 
1932
- Chart.prototype.toImage = function toImage () {
2129
+ Chart.prototype.toImage = function toImage (download) {
1933
2130
  if (this.adapter === "chartjs") {
1934
- return this.chart.toBase64Image();
2131
+ if (download && download.background && download.background !== "transparent") {
2132
+ // https://stackoverflow.com/questions/30464750/chartjs-line-chart-set-background-color
2133
+ var canvas = this.chart.chart.canvas;
2134
+ var ctx = this.chart.chart.ctx;
2135
+ var tmpCanvas = document.createElement("canvas");
2136
+ var tmpCtx = tmpCanvas.getContext("2d");
2137
+ tmpCanvas.width = ctx.canvas.width;
2138
+ tmpCanvas.height = ctx.canvas.height;
2139
+ tmpCtx.fillStyle = download.background;
2140
+ tmpCtx.fillRect(0, 0, tmpCanvas.width, tmpCanvas.height);
2141
+ tmpCtx.drawImage(canvas, 0, 0);
2142
+ return tmpCanvas.toDataURL("image/png");
2143
+ } else {
2144
+ return this.chart.toBase64Image();
2145
+ }
1935
2146
  } else {
2147
+ // TODO throw error in next major version
2148
+ // throw new Error("Feature only available for Chart.js");
1936
2149
  return null;
1937
2150
  }
1938
2151
  };
@@ -1969,7 +2182,7 @@
1969
2182
  return config;
1970
2183
  };
1971
2184
 
1972
- var LineChart = (function (Chart) {
2185
+ var LineChart = /*@__PURE__*/(function (Chart) {
1973
2186
  function LineChart () {
1974
2187
  Chart.apply(this, arguments);
1975
2188
  }
@@ -1979,7 +2192,7 @@
1979
2192
  LineChart.prototype.constructor = LineChart;
1980
2193
 
1981
2194
  LineChart.prototype.__processData = function __processData () {
1982
- return processSeries(this, "datetime");
2195
+ return processSeries(this);
1983
2196
  };
1984
2197
 
1985
2198
  LineChart.prototype.__chartName = function __chartName () {
@@ -1989,7 +2202,7 @@
1989
2202
  return LineChart;
1990
2203
  }(Chart));
1991
2204
 
1992
- var PieChart = (function (Chart) {
2205
+ var PieChart = /*@__PURE__*/(function (Chart) {
1993
2206
  function PieChart () {
1994
2207
  Chart.apply(this, arguments);
1995
2208
  }
@@ -2009,7 +2222,7 @@
2009
2222
  return PieChart;
2010
2223
  }(Chart));
2011
2224
 
2012
- var ColumnChart = (function (Chart) {
2225
+ var ColumnChart = /*@__PURE__*/(function (Chart) {
2013
2226
  function ColumnChart () {
2014
2227
  Chart.apply(this, arguments);
2015
2228
  }
@@ -2019,7 +2232,7 @@
2019
2232
  ColumnChart.prototype.constructor = ColumnChart;
2020
2233
 
2021
2234
  ColumnChart.prototype.__processData = function __processData () {
2022
- return processSeries(this, "string");
2235
+ return processSeries(this, null, true);
2023
2236
  };
2024
2237
 
2025
2238
  ColumnChart.prototype.__chartName = function __chartName () {
@@ -2029,7 +2242,7 @@
2029
2242
  return ColumnChart;
2030
2243
  }(Chart));
2031
2244
 
2032
- var BarChart = (function (Chart) {
2245
+ var BarChart = /*@__PURE__*/(function (Chart) {
2033
2246
  function BarChart () {
2034
2247
  Chart.apply(this, arguments);
2035
2248
  }
@@ -2039,7 +2252,7 @@
2039
2252
  BarChart.prototype.constructor = BarChart;
2040
2253
 
2041
2254
  BarChart.prototype.__processData = function __processData () {
2042
- return processSeries(this, "string");
2255
+ return processSeries(this, null, true);
2043
2256
  };
2044
2257
 
2045
2258
  BarChart.prototype.__chartName = function __chartName () {
@@ -2049,7 +2262,7 @@
2049
2262
  return BarChart;
2050
2263
  }(Chart));
2051
2264
 
2052
- var AreaChart = (function (Chart) {
2265
+ var AreaChart = /*@__PURE__*/(function (Chart) {
2053
2266
  function AreaChart () {
2054
2267
  Chart.apply(this, arguments);
2055
2268
  }
@@ -2059,7 +2272,7 @@
2059
2272
  AreaChart.prototype.constructor = AreaChart;
2060
2273
 
2061
2274
  AreaChart.prototype.__processData = function __processData () {
2062
- return processSeries(this, "datetime");
2275
+ return processSeries(this);
2063
2276
  };
2064
2277
 
2065
2278
  AreaChart.prototype.__chartName = function __chartName () {
@@ -2069,7 +2282,7 @@
2069
2282
  return AreaChart;
2070
2283
  }(Chart));
2071
2284
 
2072
- var GeoChart = (function (Chart) {
2285
+ var GeoChart = /*@__PURE__*/(function (Chart) {
2073
2286
  function GeoChart () {
2074
2287
  Chart.apply(this, arguments);
2075
2288
  }
@@ -2089,7 +2302,7 @@
2089
2302
  return GeoChart;
2090
2303
  }(Chart));
2091
2304
 
2092
- var ScatterChart = (function (Chart) {
2305
+ var ScatterChart = /*@__PURE__*/(function (Chart) {
2093
2306
  function ScatterChart () {
2094
2307
  Chart.apply(this, arguments);
2095
2308
  }
@@ -2109,7 +2322,7 @@
2109
2322
  return ScatterChart;
2110
2323
  }(Chart));
2111
2324
 
2112
- var BubbleChart = (function (Chart) {
2325
+ var BubbleChart = /*@__PURE__*/(function (Chart) {
2113
2326
  function BubbleChart () {
2114
2327
  Chart.apply(this, arguments);
2115
2328
  }
@@ -2129,7 +2342,7 @@
2129
2342
  return BubbleChart;
2130
2343
  }(Chart));
2131
2344
 
2132
- var Timeline = (function (Chart) {
2345
+ var Timeline = /*@__PURE__*/(function (Chart) {
2133
2346
  function Timeline () {
2134
2347
  Chart.apply(this, arguments);
2135
2348
  }
@@ -2172,6 +2385,9 @@
2172
2385
  }
2173
2386
  }
2174
2387
  },
2388
+ setDefaultOptions: function (opts) {
2389
+ Chartkick.options = opts;
2390
+ },
2175
2391
  eachChart: function (callback) {
2176
2392
  for (var chartId in Chartkick.charts) {
2177
2393
  if (Chartkick.charts.hasOwnProperty(chartId)) {
@@ -2182,9 +2398,21 @@
2182
2398
  config: config,
2183
2399
  options: {},
2184
2400
  adapters: adapters,
2185
- addAdapter: addAdapter
2401
+ addAdapter: addAdapter,
2402
+ use: function(adapter) {
2403
+ addAdapter(adapter);
2404
+ return Chartkick;
2405
+ }
2186
2406
  };
2187
2407
 
2408
+ // not ideal, but allows for simpler integration
2409
+ if (typeof window !== "undefined" && !window.Chartkick) {
2410
+ window.Chartkick = Chartkick;
2411
+ }
2412
+
2413
+ // backwards compatibility for esm require
2414
+ Chartkick.default = Chartkick;
2415
+
2188
2416
  return Chartkick;
2189
2417
 
2190
2418
  })));