pghero 2.8.1 → 2.8.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

@@ -1,15 +1,15 @@
1
- /*
1
+ /*!
2
2
  * Chartkick.js
3
3
  * Create beautiful charts with one line of JavaScript
4
4
  * https://github.com/ankane/chartkick.js
5
- * v3.2.0
5
+ * v4.0.2
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 = global || self, global.Chartkick = factory());
12
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Chartkick = factory());
13
13
  }(this, (function () { 'use strict';
14
14
 
15
15
  function isArray(variable) {
@@ -55,42 +55,6 @@
55
55
 
56
56
  var DATE_PATTERN = /^(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)$/i;
57
57
 
58
- // https://github.com/Do/iso8601.js
59
- 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;
60
- var DECIMAL_SEPARATOR = String(1.5).charAt(1);
61
-
62
- function parseISO8601(input) {
63
- var day, hour, matches, milliseconds, minutes, month, offset, result, seconds, type, year;
64
- type = Object.prototype.toString.call(input);
65
- if (type === "[object Date]") {
66
- return input;
67
- }
68
- if (type !== "[object String]") {
69
- return;
70
- }
71
- matches = input.match(ISO8601_PATTERN);
72
- if (matches) {
73
- year = parseInt(matches[1], 10);
74
- month = parseInt(matches[3], 10) - 1;
75
- day = parseInt(matches[5], 10);
76
- hour = parseInt(matches[7], 10);
77
- minutes = matches[9] ? parseInt(matches[9], 10) : 0;
78
- seconds = matches[11] ? parseInt(matches[11], 10) : 0;
79
- milliseconds = matches[12] ? parseFloat(DECIMAL_SEPARATOR + matches[12].slice(1)) * 1000 : 0;
80
- result = Date.UTC(year, month, day, hour, minutes, seconds, milliseconds);
81
- if (matches[13] && matches[14]) {
82
- offset = matches[15] * 60;
83
- if (matches[17]) {
84
- offset += parseInt(matches[17], 10);
85
- }
86
- offset *= matches[14] === "-" ? -1 : 1;
87
- result -= offset * 60 * 1000;
88
- }
89
- return new Date(result);
90
- }
91
- }
92
- // end iso8601.js
93
-
94
58
  function negativeValues(series) {
95
59
  var i, j, data;
96
60
  for (i = 0; i < series.length; i++) {
@@ -120,15 +84,16 @@
120
84
  } else {
121
85
  n = toStr(n);
122
86
  if ((matches = n.match(DATE_PATTERN))) {
123
- year = parseInt(matches[1], 10);
124
- month = parseInt(matches[3], 10) - 1;
125
- day = parseInt(matches[5], 10);
126
- return new Date(year, month, day);
127
- } else { // str
87
+ year = parseInt(matches[1], 10);
88
+ month = parseInt(matches[3], 10) - 1;
89
+ day = parseInt(matches[5], 10);
90
+ return new Date(year, month, day);
91
+ } else {
128
92
  // try our best to get the str into iso8601
129
93
  // TODO be smarter about this
130
94
  var str = n.replace(/ /, "T").replace(" ", "").replace("UTC", "Z");
131
- n = parseISO8601(str) || new Date(n);
95
+ // Date.parse returns milliseconds if valid and NaN if invalid
96
+ n = new Date(Date.parse(str) || n);
132
97
  }
133
98
  }
134
99
  }
@@ -154,8 +119,8 @@
154
119
  var options = merge({}, defaultOptions);
155
120
  options = merge(options, chartOptions || {});
156
121
 
157
- if (chart.hideLegend || "legend" in opts) {
158
- hideLegend(options, opts.legend, chart.hideLegend);
122
+ if (chart.singleSeriesFormat || "legend" in opts) {
123
+ hideLegend(options, opts.legend, chart.singleSeriesFormat);
159
124
  }
160
125
 
161
126
  if (opts.title) {
@@ -361,42 +326,49 @@
361
326
  var baseOptions = {
362
327
  maintainAspectRatio: false,
363
328
  animation: false,
364
- tooltips: {
365
- displayColors: false,
366
- callbacks: {}
329
+ plugins: {
330
+ legend: {},
331
+ tooltip: {
332
+ displayColors: false,
333
+ callbacks: {}
334
+ },
335
+ title: {
336
+ font: {
337
+ size: 20
338
+ },
339
+ color: "#333"
340
+ }
367
341
  },
368
- legend: {},
369
- title: {fontSize: 20, fontColor: "#333"}
342
+ interaction: {}
370
343
  };
371
344
 
372
- var defaultOptions = {
345
+ var defaultOptions$2 = {
373
346
  scales: {
374
- yAxes: [
375
- {
376
- ticks: {
377
- maxTicksLimit: 4
378
- },
379
- scaleLabel: {
380
- fontSize: 16,
381
- // fontStyle: "bold",
382
- fontColor: "#333"
383
- }
384
- }
385
- ],
386
- xAxes: [
387
- {
388
- gridLines: {
389
- drawOnChartArea: false
347
+ y: {
348
+ ticks: {
349
+ maxTicksLimit: 4
350
+ },
351
+ title: {
352
+ font: {
353
+ size: 16
390
354
  },
391
- scaleLabel: {
392
- fontSize: 16,
393
- // fontStyle: "bold",
394
- fontColor: "#333"
355
+ color: "#333"
356
+ },
357
+ grid: {}
358
+ },
359
+ x: {
360
+ grid: {
361
+ drawOnChartArea: false
362
+ },
363
+ title: {
364
+ font: {
365
+ size: 16
395
366
  },
396
- time: {},
397
- ticks: {}
398
- }
399
- ]
367
+ color: "#333"
368
+ },
369
+ time: {},
370
+ ticks: {}
371
+ }
400
372
  }
401
373
  };
402
374
 
@@ -407,66 +379,66 @@
407
379
  "#6633CC", "#E67300", "#8B0707", "#329262", "#5574A6", "#651067"
408
380
  ];
409
381
 
410
- var hideLegend = function (options, legend, hideLegend) {
382
+ var hideLegend$2 = function (options, legend, hideLegend) {
411
383
  if (legend !== undefined) {
412
- options.legend.display = !!legend;
384
+ options.plugins.legend.display = !!legend;
413
385
  if (legend && legend !== true) {
414
- options.legend.position = legend;
386
+ options.plugins.legend.position = legend;
415
387
  }
416
388
  } else if (hideLegend) {
417
- options.legend.display = false;
389
+ options.plugins.legend.display = false;
418
390
  }
419
391
  };
420
392
 
421
- var setTitle = function (options, title) {
422
- options.title.display = true;
423
- options.title.text = title;
393
+ var setTitle$2 = function (options, title) {
394
+ options.plugins.title.display = true;
395
+ options.plugins.title.text = title;
424
396
  };
425
397
 
426
- var setMin = function (options, min) {
398
+ var setMin$2 = function (options, min) {
427
399
  if (min !== null) {
428
- options.scales.yAxes[0].ticks.min = toFloat(min);
400
+ options.scales.y.min = toFloat(min);
429
401
  }
430
402
  };
431
403
 
432
- var setMax = function (options, max) {
433
- options.scales.yAxes[0].ticks.max = toFloat(max);
404
+ var setMax$2 = function (options, max) {
405
+ options.scales.y.max = toFloat(max);
434
406
  };
435
407
 
436
- var setBarMin = function (options, min) {
408
+ var setBarMin$1 = function (options, min) {
437
409
  if (min !== null) {
438
- options.scales.xAxes[0].ticks.min = toFloat(min);
410
+ options.scales.x.min = toFloat(min);
439
411
  }
440
412
  };
441
413
 
442
- var setBarMax = function (options, max) {
443
- options.scales.xAxes[0].ticks.max = toFloat(max);
414
+ var setBarMax$1 = function (options, max) {
415
+ options.scales.x.max = toFloat(max);
444
416
  };
445
417
 
446
- var setStacked = function (options, stacked) {
447
- options.scales.xAxes[0].stacked = !!stacked;
448
- options.scales.yAxes[0].stacked = !!stacked;
418
+ var setStacked$2 = function (options, stacked) {
419
+ options.scales.x.stacked = !!stacked;
420
+ options.scales.y.stacked = !!stacked;
449
421
  };
450
422
 
451
- var setXtitle = function (options, title) {
452
- options.scales.xAxes[0].scaleLabel.display = true;
453
- options.scales.xAxes[0].scaleLabel.labelString = title;
423
+ var setXtitle$2 = function (options, title) {
424
+ options.scales.x.title.display = true;
425
+ options.scales.x.title.text = title;
454
426
  };
455
427
 
456
- var setYtitle = function (options, title) {
457
- options.scales.yAxes[0].scaleLabel.display = true;
458
- options.scales.yAxes[0].scaleLabel.labelString = title;
428
+ var setYtitle$2 = function (options, title) {
429
+ options.scales.y.title.display = true;
430
+ options.scales.y.title.text = title;
459
431
  };
460
432
 
461
433
  // https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
462
- var addOpacity = function(hex, opacity) {
434
+ var addOpacity = function (hex, opacity) {
463
435
  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
464
436
  return result ? "rgba(" + parseInt(result[1], 16) + ", " + parseInt(result[2], 16) + ", " + parseInt(result[3], 16) + ", " + opacity + ")" : hex;
465
437
  };
466
438
 
467
439
  // check if not null or undefined
468
440
  // https://stackoverflow.com/a/27757708/1177228
469
- var notnull = function(x) {
441
+ var notnull = function (x) {
470
442
  return x != null;
471
443
  };
472
444
 
@@ -477,9 +449,9 @@
477
449
  } else if (maxLabelSize < 10) {
478
450
  maxLabelSize = 10;
479
451
  }
480
- if (!options.scales.xAxes[0].ticks.callback) {
481
- options.scales.xAxes[0].ticks.callback = function (value) {
482
- value = toStr(value);
452
+ if (!options.scales.x.ticks.callback) {
453
+ options.scales.x.ticks.callback = function (value) {
454
+ value = toStr(this.getLabelForValue(value));
483
455
  if (value.length > maxLabelSize) {
484
456
  return value.substring(0, maxLabelSize - 2) + "...";
485
457
  } else {
@@ -489,7 +461,7 @@
489
461
  }
490
462
  };
491
463
 
492
- var setFormatOptions = function(chart, options, chartType) {
464
+ var setFormatOptions$1 = function (chart, options, chartType) {
493
465
  var formatOptions = {
494
466
  prefix: chart.options.prefix,
495
467
  suffix: chart.options.suffix,
@@ -529,49 +501,49 @@
529
501
  }
530
502
 
531
503
  if (chartType !== "pie") {
532
- var myAxes = options.scales.yAxes;
504
+ var axis = options.scales.y;
533
505
  if (chartType === "bar") {
534
- myAxes = options.scales.xAxes;
506
+ axis = options.scales.x;
535
507
  }
536
508
 
537
509
  if (formatOptions.byteScale) {
538
- if (!myAxes[0].ticks.stepSize) {
539
- myAxes[0].ticks.stepSize = formatOptions.byteScale / 2;
510
+ if (!axis.ticks.stepSize) {
511
+ axis.ticks.stepSize = formatOptions.byteScale / 2;
540
512
  }
541
- if (!myAxes[0].ticks.maxTicksLimit) {
542
- myAxes[0].ticks.maxTicksLimit = 4;
513
+ if (!axis.ticks.maxTicksLimit) {
514
+ axis.ticks.maxTicksLimit = 4;
543
515
  }
544
516
  }
545
517
 
546
- if (!myAxes[0].ticks.callback) {
547
- myAxes[0].ticks.callback = function (value) {
518
+ if (!axis.ticks.callback) {
519
+ axis.ticks.callback = function (value) {
548
520
  return formatValue("", value, formatOptions, true);
549
521
  };
550
522
  }
551
523
  }
552
524
 
553
- if (!options.tooltips.callbacks.label) {
525
+ if (!options.plugins.tooltip.callbacks.label) {
554
526
  if (chartType === "scatter") {
555
- options.tooltips.callbacks.label = function (item, data) {
556
- var label = data.datasets[item.datasetIndex].label || '';
527
+ options.plugins.tooltip.callbacks.label = function (context) {
528
+ var label = context.dataset.label || '';
557
529
  if (label) {
558
530
  label += ': ';
559
531
  }
560
- return label + '(' + item.xLabel + ', ' + item.yLabel + ')';
532
+ return label + '(' + context.label + ', ' + context.formattedValue + ')';
561
533
  };
562
534
  } else if (chartType === "bubble") {
563
- options.tooltips.callbacks.label = function (item, data) {
564
- var label = data.datasets[item.datasetIndex].label || '';
535
+ options.plugins.tooltip.callbacks.label = function (context) {
536
+ var label = context.dataset.label || '';
565
537
  if (label) {
566
538
  label += ': ';
567
539
  }
568
- var dataPoint = data.datasets[item.datasetIndex].data[item.index];
569
- return label + '(' + item.xLabel + ', ' + item.yLabel + ', ' + dataPoint.v + ')';
540
+ var dataPoint = context.raw;
541
+ return label + '(' + dataPoint.x + ', ' + dataPoint.y + ', ' + dataPoint.v + ')';
570
542
  };
571
543
  } else if (chartType === "pie") {
572
544
  // need to use separate label for pie charts
573
- options.tooltips.callbacks.label = function (tooltipItem, data) {
574
- var dataLabel = data.labels[tooltipItem.index];
545
+ options.plugins.tooltip.callbacks.label = function (context) {
546
+ var dataLabel = context.label;
575
547
  var value = ': ';
576
548
 
577
549
  if (isArray(dataLabel)) {
@@ -583,24 +555,24 @@
583
555
  dataLabel += value;
584
556
  }
585
557
 
586
- return formatValue(dataLabel, data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index], formatOptions);
558
+ return formatValue(dataLabel, context.parsed, formatOptions);
587
559
  };
588
560
  } else {
589
- var valueLabel = chartType === "bar" ? "xLabel" : "yLabel";
590
- options.tooltips.callbacks.label = function (tooltipItem, data) {
591
- var label = data.datasets[tooltipItem.datasetIndex].label || '';
561
+ var valueLabel = chartType === "bar" ? "x" : "y";
562
+ options.plugins.tooltip.callbacks.label = function (context) {
563
+ var label = context.dataset.label || '';
592
564
  if (label) {
593
565
  label += ': ';
594
566
  }
595
- return formatValue(label, tooltipItem[valueLabel], formatOptions);
567
+ return formatValue(label, context.parsed[valueLabel], formatOptions);
596
568
  };
597
569
  }
598
570
  }
599
571
  };
600
572
 
601
- var jsOptions = jsOptionsFunc(merge(baseOptions, defaultOptions), hideLegend, setTitle, setMin, setMax, setStacked, setXtitle, setYtitle);
573
+ var jsOptions$2 = jsOptionsFunc(merge(baseOptions, defaultOptions$2), hideLegend$2, setTitle$2, setMin$2, setMax$2, setStacked$2, setXtitle$2, setYtitle$2);
602
574
 
603
- var createDataTable = function (chart, options, chartType, library) {
575
+ var createDataTable = function (chart, options, chartType) {
604
576
  var datasets = [];
605
577
  var labels = [];
606
578
 
@@ -702,11 +674,23 @@
702
674
  }
703
675
  }
704
676
 
677
+ var color;
678
+ var backgroundColor;
679
+
705
680
  for (i = 0; i < series.length; i++) {
706
681
  s = series[i];
707
682
 
708
- var color = s.color || colors[i];
709
- var backgroundColor = chartType !== "line" ? addOpacity(color, 0.5) : color;
683
+ // use colors for each bar for single series format
684
+ if (chart.options.colors && chart.singleSeriesFormat && (chartType === "bar" || chartType === "column") && !s.color) {
685
+ color = colors;
686
+ backgroundColor = [];
687
+ for (var j$3 = 0; j$3 < colors.length; j$3++) {
688
+ backgroundColor[j$3] = addOpacity(color[j$3], 0.5);
689
+ }
690
+ } else {
691
+ color = s.color || colors[i];
692
+ backgroundColor = chartType !== "line" ? addOpacity(color, 0.5) : color;
693
+ }
710
694
 
711
695
  var dataset = {
712
696
  label: s.name || "",
@@ -714,24 +698,37 @@
714
698
  fill: chartType === "area",
715
699
  borderColor: color,
716
700
  backgroundColor: backgroundColor,
717
- pointBackgroundColor: color,
718
- borderWidth: 2,
719
- pointHoverBackgroundColor: color
701
+ borderWidth: 2
720
702
  };
721
703
 
704
+ var pointChart = chartType === "line" || chartType === "area" || chartType === "scatter" || chartType === "bubble";
705
+ if (pointChart) {
706
+ dataset.pointBackgroundColor = color;
707
+ dataset.pointHoverBackgroundColor = color;
708
+ dataset.pointHitRadius = 50;
709
+ }
710
+
711
+ if (chartType === "bubble") {
712
+ dataset.pointBackgroundColor = backgroundColor;
713
+ dataset.pointHoverBackgroundColor = backgroundColor;
714
+ dataset.pointHoverBorderWidth = 2;
715
+ }
716
+
722
717
  if (s.stack) {
723
718
  dataset.stack = s.stack;
724
719
  }
725
720
 
726
721
  var curve = seriesOption(chart, s, "curve");
727
722
  if (curve === false) {
728
- dataset.lineTension = 0;
723
+ dataset.tension = 0;
724
+ } else if (pointChart) {
725
+ dataset.tension = 0.4;
729
726
  }
730
727
 
731
728
  var points = seriesOption(chart, s, "points");
732
729
  if (points === false) {
733
730
  dataset.pointRadius = 0;
734
- dataset.pointHitRadius = 5;
731
+ dataset.pointHoverRadius = 0;
735
732
  }
736
733
 
737
734
  dataset = merge(dataset, chart.options.dataset || {});
@@ -745,23 +742,35 @@
745
742
  var xmax = chart.options.xmax;
746
743
 
747
744
  if (chart.xtype === "datetime") {
748
- // hacky check for Chart.js >= 2.9.0
749
- // https://github.com/chartjs/Chart.js/compare/v2.8.0...v2.9.0
750
- var gte29 = "math" in library.helpers;
751
- var ticksKey = gte29 ? "ticks" : "time";
752
745
  if (notnull(xmin)) {
753
- options.scales.xAxes[0][ticksKey].min = toDate(xmin).getTime();
746
+ options.scales.x.ticks.min = toDate(xmin).getTime();
754
747
  }
755
748
  if (notnull(xmax)) {
756
- options.scales.xAxes[0][ticksKey].max = toDate(xmax).getTime();
749
+ options.scales.x.ticks.max = toDate(xmax).getTime();
757
750
  }
758
751
  } else if (chart.xtype === "number") {
759
752
  if (notnull(xmin)) {
760
- options.scales.xAxes[0].ticks.min = xmin;
753
+ options.scales.x.ticks.min = xmin;
754
+ }
755
+ if (notnull(xmax)) {
756
+ options.scales.x.ticks.max = xmax;
757
+ }
758
+ }
759
+
760
+ // for empty datetime chart
761
+ if (chart.xtype === "datetime" && labels.length === 0) {
762
+ if (notnull(xmin)) {
763
+ labels.push(toDate(xmin));
761
764
  }
762
765
  if (notnull(xmax)) {
763
- options.scales.xAxes[0].ticks.max = xmax;
766
+ labels.push(toDate(xmax));
764
767
  }
768
+ day = false;
769
+ week = false;
770
+ month = false;
771
+ year = false;
772
+ hour = false;
773
+ minute = false;
765
774
  }
766
775
 
767
776
  if (chart.xtype === "datetime" && labels.length > 0) {
@@ -780,24 +789,24 @@
780
789
 
781
790
  var timeDiff = (maxTime - minTime) / (86400 * 1000.0);
782
791
 
783
- if (!options.scales.xAxes[0].time.unit) {
792
+ if (!options.scales.x.time.unit) {
784
793
  var step;
785
794
  if (year || timeDiff > 365 * 10) {
786
- options.scales.xAxes[0].time.unit = "year";
795
+ options.scales.x.time.unit = "year";
787
796
  step = 365;
788
797
  } else if (month || timeDiff > 30 * 10) {
789
- options.scales.xAxes[0].time.unit = "month";
798
+ options.scales.x.time.unit = "month";
790
799
  step = 30;
791
800
  } else if (day || timeDiff > 10) {
792
- options.scales.xAxes[0].time.unit = "day";
801
+ options.scales.x.time.unit = "day";
793
802
  step = 1;
794
803
  } else if (hour || timeDiff > 0.5) {
795
- options.scales.xAxes[0].time.displayFormats = {hour: "MMM D, h a"};
796
- options.scales.xAxes[0].time.unit = "hour";
804
+ options.scales.x.time.displayFormats = {hour: "MMM d, h a"};
805
+ options.scales.x.time.unit = "hour";
797
806
  step = 1 / 24.0;
798
807
  } else if (minute) {
799
- options.scales.xAxes[0].time.displayFormats = {minute: "h:mm a"};
800
- options.scales.xAxes[0].time.unit = "minute";
808
+ options.scales.x.time.displayFormats = {minute: "h:mm a"};
809
+ options.scales.x.time.unit = "minute";
801
810
  step = 1 / 24.0 / 60.0;
802
811
  }
803
812
 
@@ -806,17 +815,17 @@
806
815
  if (week && step === 1) {
807
816
  unitStepSize = Math.ceil(unitStepSize / 7.0) * 7;
808
817
  }
809
- options.scales.xAxes[0].time.unitStepSize = unitStepSize;
818
+ options.scales.x.time.stepSize = unitStepSize;
810
819
  }
811
820
  }
812
821
 
813
- if (!options.scales.xAxes[0].time.tooltipFormat) {
822
+ if (!options.scales.x.time.tooltipFormat) {
814
823
  if (day) {
815
- options.scales.xAxes[0].time.tooltipFormat = "ll";
824
+ options.scales.x.time.tooltipFormat = "PP";
816
825
  } else if (hour) {
817
- options.scales.xAxes[0].time.tooltipFormat = "MMM D, h a";
826
+ options.scales.x.time.tooltipFormat = "MMM d, h a";
818
827
  } else if (minute) {
819
- options.scales.xAxes[0].time.tooltipFormat = "h:mm a";
828
+ options.scales.x.time.tooltipFormat = "h:mm a";
820
829
  }
821
830
  }
822
831
  }
@@ -829,49 +838,49 @@
829
838
  return data;
830
839
  };
831
840
 
832
- var defaultExport = function defaultExport(library) {
841
+ var defaultExport$2 = function defaultExport(library) {
833
842
  this.name = "chartjs";
834
843
  this.library = library;
835
844
  };
836
845
 
837
- defaultExport.prototype.renderLineChart = function renderLineChart (chart, chartType) {
846
+ defaultExport$2.prototype.renderLineChart = function renderLineChart (chart, chartType) {
838
847
  var chartOptions = {};
839
848
  // fix for https://github.com/chartjs/Chart.js/issues/2441
840
849
  if (!chart.options.max && allZeros(chart.data)) {
841
850
  chartOptions.max = 1;
842
851
  }
843
852
 
844
- var options = jsOptions(chart, merge(chartOptions, chart.options));
845
- setFormatOptions(chart, options, chartType);
853
+ var options = jsOptions$2(chart, merge(chartOptions, chart.options));
854
+ setFormatOptions$1(chart, options, chartType);
846
855
 
847
- var data = createDataTable(chart, options, chartType || "line", this.library);
856
+ var data = createDataTable(chart, options, chartType || "line");
848
857
 
849
858
  if (chart.xtype === "number") {
850
- options.scales.xAxes[0].type = "linear";
851
- options.scales.xAxes[0].position = "bottom";
859
+ options.scales.x.type = "linear";
860
+ options.scales.x.position = "bottom";
852
861
  } else {
853
- options.scales.xAxes[0].type = chart.xtype === "string" ? "category" : "time";
862
+ options.scales.x.type = chart.xtype === "string" ? "category" : "time";
854
863
  }
855
864
 
856
865
  this.drawChart(chart, "line", data, options);
857
866
  };
858
867
 
859
- defaultExport.prototype.renderPieChart = function renderPieChart (chart) {
868
+ defaultExport$2.prototype.renderPieChart = function renderPieChart (chart) {
860
869
  var options = merge({}, baseOptions);
861
870
  if (chart.options.donut) {
862
- options.cutoutPercentage = 50;
871
+ options.cutout = "50%";
863
872
  }
864
873
 
865
874
  if ("legend" in chart.options) {
866
- hideLegend(options, chart.options.legend);
875
+ hideLegend$2(options, chart.options.legend);
867
876
  }
868
877
 
869
878
  if (chart.options.title) {
870
- setTitle(options, chart.options.title);
879
+ setTitle$2(options, chart.options.title);
871
880
  }
872
881
 
873
882
  options = merge(options, chart.options.library || {});
874
- setFormatOptions(chart, options, "pie");
883
+ setFormatOptions$1(chart, options, "pie");
875
884
 
876
885
  var labels = [];
877
886
  var values = [];
@@ -895,61 +904,73 @@
895
904
  this.drawChart(chart, "pie", data, options);
896
905
  };
897
906
 
898
- defaultExport.prototype.renderColumnChart = function renderColumnChart (chart, chartType) {
907
+ defaultExport$2.prototype.renderColumnChart = function renderColumnChart (chart, chartType) {
899
908
  var options;
900
909
  if (chartType === "bar") {
901
- var barOptions = merge(baseOptions, defaultOptions);
902
- delete barOptions.scales.yAxes[0].ticks.maxTicksLimit;
903
- options = jsOptionsFunc(barOptions, hideLegend, setTitle, setBarMin, setBarMax, setStacked, setXtitle, setYtitle)(chart, chart.options);
910
+ var barOptions = merge(baseOptions, defaultOptions$2);
911
+ barOptions.indexAxis = "y";
912
+
913
+ // ensure gridlines have proper orientation
914
+ barOptions.scales.x.grid.drawOnChartArea = true;
915
+ barOptions.scales.y.grid.drawOnChartArea = false;
916
+ delete barOptions.scales.y.ticks.maxTicksLimit;
917
+
918
+ options = jsOptionsFunc(barOptions, hideLegend$2, setTitle$2, setBarMin$1, setBarMax$1, setStacked$2, setXtitle$2, setYtitle$2)(chart, chart.options);
904
919
  } else {
905
- options = jsOptions(chart, chart.options);
920
+ options = jsOptions$2(chart, chart.options);
906
921
  }
907
- setFormatOptions(chart, options, chartType);
908
- var data = createDataTable(chart, options, "column", this.library);
922
+ setFormatOptions$1(chart, options, chartType);
923
+ var data = createDataTable(chart, options, "column");
909
924
  if (chartType !== "bar") {
910
925
  setLabelSize(chart, data, options);
911
926
  }
912
- this.drawChart(chart, (chartType === "bar" ? "horizontalBar" : "bar"), data, options);
927
+ this.drawChart(chart, "bar", data, options);
913
928
  };
914
929
 
915
- defaultExport.prototype.renderAreaChart = function renderAreaChart (chart) {
930
+ defaultExport$2.prototype.renderAreaChart = function renderAreaChart (chart) {
916
931
  this.renderLineChart(chart, "area");
917
932
  };
918
933
 
919
- defaultExport.prototype.renderBarChart = function renderBarChart (chart) {
934
+ defaultExport$2.prototype.renderBarChart = function renderBarChart (chart) {
920
935
  this.renderColumnChart(chart, "bar");
921
936
  };
922
937
 
923
- defaultExport.prototype.renderScatterChart = function renderScatterChart (chart, chartType) {
938
+ defaultExport$2.prototype.renderScatterChart = function renderScatterChart (chart, chartType) {
924
939
  chartType = chartType || "scatter";
925
940
 
926
- var options = jsOptions(chart, chart.options);
927
- setFormatOptions(chart, options, chartType);
941
+ var options = jsOptions$2(chart, chart.options);
942
+ setFormatOptions$1(chart, options, chartType);
928
943
 
929
- if (!("showLines" in options)) {
930
- options.showLines = false;
944
+ if (!("showLine" in options)) {
945
+ options.showLine = false;
931
946
  }
932
947
 
933
- var data = createDataTable(chart, options, chartType, this.library);
948
+ var data = createDataTable(chart, options, chartType);
934
949
 
935
- options.scales.xAxes[0].type = "linear";
936
- options.scales.xAxes[0].position = "bottom";
950
+ options.scales.x.type = "linear";
951
+ options.scales.x.position = "bottom";
952
+
953
+ // prevent grouping hover and tooltips
954
+ if (!("mode" in options.interaction)) {
955
+ options.interaction.mode = "nearest";
956
+ }
937
957
 
938
958
  this.drawChart(chart, chartType, data, options);
939
959
  };
940
960
 
941
- defaultExport.prototype.renderBubbleChart = function renderBubbleChart (chart) {
961
+ defaultExport$2.prototype.renderBubbleChart = function renderBubbleChart (chart) {
942
962
  this.renderScatterChart(chart, "bubble");
943
963
  };
944
964
 
945
- defaultExport.prototype.destroy = function destroy (chart) {
965
+ defaultExport$2.prototype.destroy = function destroy (chart) {
946
966
  if (chart.chart) {
947
967
  chart.chart.destroy();
948
968
  }
949
969
  };
950
970
 
951
- defaultExport.prototype.drawChart = function drawChart (chart, type, data, options) {
971
+ defaultExport$2.prototype.drawChart = function drawChart (chart, type, data, options) {
952
972
  this.destroy(chart);
973
+ if (chart.destroyed) { return; }
953
974
 
954
975
  var chartOptions = {
955
976
  type: type,
@@ -1008,6 +1029,9 @@
1008
1029
  series: {
1009
1030
  marker: {}
1010
1031
  }
1032
+ },
1033
+ time: {
1034
+ useUTC: false
1011
1035
  }
1012
1036
  };
1013
1037
 
@@ -1057,7 +1081,7 @@
1057
1081
 
1058
1082
  var jsOptions$1 = jsOptionsFunc(defaultOptions$1, hideLegend$1, setTitle$1, setMin$1, setMax$1, setStacked$1, setXtitle$1, setYtitle$1);
1059
1083
 
1060
- var setFormatOptions$1 = function(chart, options, chartType) {
1084
+ var setFormatOptions = function(chart, options, chartType) {
1061
1085
  var formatOptions = {
1062
1086
  prefix: chart.options.prefix,
1063
1087
  suffix: chart.options.suffix,
@@ -1120,7 +1144,7 @@
1120
1144
  if (!options.chart.type) {
1121
1145
  options.chart.type = chartType;
1122
1146
  }
1123
- setFormatOptions$1(chart, options, chartType);
1147
+ setFormatOptions(chart, options, chartType);
1124
1148
 
1125
1149
  var series = chart.data;
1126
1150
  for (i = 0; i < series.length; i++) {
@@ -1165,7 +1189,7 @@
1165
1189
  }
1166
1190
 
1167
1191
  var options = merge(chartOptions, chart.options.library || {});
1168
- setFormatOptions$1(chart, options, "pie");
1192
+ setFormatOptions(chart, options, "pie");
1169
1193
  var series = [{
1170
1194
  type: "pie",
1171
1195
  name: chart.options.label || "Value",
@@ -1180,7 +1204,7 @@
1180
1204
  var series = chart.data;
1181
1205
  var options = jsOptions$1(chart, chart.options), i, j, s, d, rows = [], categories = [];
1182
1206
  options.chart.type = chartType;
1183
- setFormatOptions$1(chart, options, chartType);
1207
+ setFormatOptions(chart, options, chartType);
1184
1208
 
1185
1209
  for (i = 0; i < series.length; i++) {
1186
1210
  s = series[i];
@@ -1238,6 +1262,7 @@
1238
1262
 
1239
1263
  defaultExport$1.prototype.drawChart = function drawChart (chart, data, options) {
1240
1264
  this.destroy(chart);
1265
+ if (chart.destroyed) { return; }
1241
1266
 
1242
1267
  options.chart.renderTo = chart.element.id;
1243
1268
  options.series = data;
@@ -1253,7 +1278,7 @@
1253
1278
  var callbacks = [];
1254
1279
 
1255
1280
  // Set chart options
1256
- var defaultOptions$2 = {
1281
+ var defaultOptions = {
1257
1282
  chartArea: {},
1258
1283
  fontName: "'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif",
1259
1284
  pointSize: 6,
@@ -1295,7 +1320,7 @@
1295
1320
  }
1296
1321
  };
1297
1322
 
1298
- var hideLegend$2 = function (options, legend, hideLegend) {
1323
+ var hideLegend = function (options, legend, hideLegend) {
1299
1324
  if (legend !== undefined) {
1300
1325
  var position;
1301
1326
  if (!legend) {
@@ -1311,42 +1336,42 @@
1311
1336
  }
1312
1337
  };
1313
1338
 
1314
- var setTitle$2 = function (options, title) {
1339
+ var setTitle = function (options, title) {
1315
1340
  options.title = title;
1316
1341
  options.titleTextStyle = {color: "#333", fontSize: "20px"};
1317
1342
  };
1318
1343
 
1319
- var setMin$2 = function (options, min) {
1344
+ var setMin = function (options, min) {
1320
1345
  options.vAxis.viewWindow.min = min;
1321
1346
  };
1322
1347
 
1323
- var setMax$2 = function (options, max) {
1348
+ var setMax = function (options, max) {
1324
1349
  options.vAxis.viewWindow.max = max;
1325
1350
  };
1326
1351
 
1327
- var setBarMin$1 = function (options, min) {
1352
+ var setBarMin = function (options, min) {
1328
1353
  options.hAxis.viewWindow.min = min;
1329
1354
  };
1330
1355
 
1331
- var setBarMax$1 = function (options, max) {
1356
+ var setBarMax = function (options, max) {
1332
1357
  options.hAxis.viewWindow.max = max;
1333
1358
  };
1334
1359
 
1335
- var setStacked$2 = function (options, stacked) {
1360
+ var setStacked = function (options, stacked) {
1336
1361
  options.isStacked = stacked ? stacked : false;
1337
1362
  };
1338
1363
 
1339
- var setXtitle$2 = function (options, title) {
1364
+ var setXtitle = function (options, title) {
1340
1365
  options.hAxis.title = title;
1341
1366
  options.hAxis.titleTextStyle.italic = false;
1342
1367
  };
1343
1368
 
1344
- var setYtitle$2 = function (options, title) {
1369
+ var setYtitle = function (options, title) {
1345
1370
  options.vAxis.title = title;
1346
1371
  options.vAxis.titleTextStyle.italic = false;
1347
1372
  };
1348
1373
 
1349
- var jsOptions$2 = jsOptionsFunc(defaultOptions$2, hideLegend$2, setTitle$2, setMin$2, setMax$2, setStacked$2, setXtitle$2, setYtitle$2);
1374
+ var jsOptions = jsOptionsFunc(defaultOptions, hideLegend, setTitle, setMin, setMax, setStacked, setXtitle, setYtitle);
1350
1375
 
1351
1376
  var resize = function (callback) {
1352
1377
  if (window.attachEvent) {
@@ -1357,12 +1382,12 @@
1357
1382
  callback();
1358
1383
  };
1359
1384
 
1360
- var defaultExport$2 = function defaultExport(library) {
1385
+ var defaultExport = function defaultExport(library) {
1361
1386
  this.name = "google";
1362
1387
  this.library = library;
1363
1388
  };
1364
1389
 
1365
- defaultExport$2.prototype.renderLineChart = function renderLineChart (chart) {
1390
+ defaultExport.prototype.renderLineChart = function renderLineChart (chart) {
1366
1391
  var this$1 = this;
1367
1392
 
1368
1393
  this.waitForLoaded(chart, function () {
@@ -1376,14 +1401,14 @@
1376
1401
  chartOptions.pointSize = 0;
1377
1402
  }
1378
1403
 
1379
- var options = jsOptions$2(chart, chart.options, chartOptions);
1404
+ var options = jsOptions(chart, chart.options, chartOptions);
1380
1405
  var data = this$1.createDataTable(chart.data, chart.xtype);
1381
1406
 
1382
1407
  this$1.drawChart(chart, "LineChart", data, options);
1383
1408
  });
1384
1409
  };
1385
1410
 
1386
- defaultExport$2.prototype.renderPieChart = function renderPieChart (chart) {
1411
+ defaultExport.prototype.renderPieChart = function renderPieChart (chart) {
1387
1412
  var this$1 = this;
1388
1413
 
1389
1414
  this.waitForLoaded(chart, function () {
@@ -1401,12 +1426,12 @@
1401
1426
  chartOptions.pieHole = 0.5;
1402
1427
  }
1403
1428
  if ("legend" in chart.options) {
1404
- hideLegend$2(chartOptions, chart.options.legend);
1429
+ hideLegend(chartOptions, chart.options.legend);
1405
1430
  }
1406
1431
  if (chart.options.title) {
1407
- setTitle$2(chartOptions, chart.options.title);
1432
+ setTitle(chartOptions, chart.options.title);
1408
1433
  }
1409
- var options = merge(merge(defaultOptions$2, chartOptions), chart.options.library || {});
1434
+ var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {});
1410
1435
 
1411
1436
  var data = new this$1.library.visualization.DataTable();
1412
1437
  data.addColumn("string", "");
@@ -1417,18 +1442,18 @@
1417
1442
  });
1418
1443
  };
1419
1444
 
1420
- defaultExport$2.prototype.renderColumnChart = function renderColumnChart (chart) {
1445
+ defaultExport.prototype.renderColumnChart = function renderColumnChart (chart) {
1421
1446
  var this$1 = this;
1422
1447
 
1423
1448
  this.waitForLoaded(chart, function () {
1424
- var options = jsOptions$2(chart, chart.options);
1449
+ var options = jsOptions(chart, chart.options);
1425
1450
  var data = this$1.createDataTable(chart.data, chart.xtype);
1426
1451
 
1427
1452
  this$1.drawChart(chart, "ColumnChart", data, options);
1428
1453
  });
1429
1454
  };
1430
1455
 
1431
- defaultExport$2.prototype.renderBarChart = function renderBarChart (chart) {
1456
+ defaultExport.prototype.renderBarChart = function renderBarChart (chart) {
1432
1457
  var this$1 = this;
1433
1458
 
1434
1459
  this.waitForLoaded(chart, function () {
@@ -1439,14 +1464,14 @@
1439
1464
  }
1440
1465
  }
1441
1466
  };
1442
- var options = jsOptionsFunc(defaultOptions$2, hideLegend$2, setTitle$2, setBarMin$1, setBarMax$1, setStacked$2, setXtitle$2, setYtitle$2)(chart, chart.options, chartOptions);
1467
+ var options = jsOptionsFunc(defaultOptions, hideLegend, setTitle, setBarMin, setBarMax, setStacked, setXtitle, setYtitle)(chart, chart.options, chartOptions);
1443
1468
  var data = this$1.createDataTable(chart.data, chart.xtype);
1444
1469
 
1445
1470
  this$1.drawChart(chart, "BarChart", data, options);
1446
1471
  });
1447
1472
  };
1448
1473
 
1449
- defaultExport$2.prototype.renderAreaChart = function renderAreaChart (chart) {
1474
+ defaultExport.prototype.renderAreaChart = function renderAreaChart (chart) {
1450
1475
  var this$1 = this;
1451
1476
 
1452
1477
  this.waitForLoaded(chart, function () {
@@ -1456,24 +1481,24 @@
1456
1481
  areaOpacity: 0.5
1457
1482
  };
1458
1483
 
1459
- var options = jsOptions$2(chart, chart.options, chartOptions);
1484
+ var options = jsOptions(chart, chart.options, chartOptions);
1460
1485
  var data = this$1.createDataTable(chart.data, chart.xtype);
1461
1486
 
1462
1487
  this$1.drawChart(chart, "AreaChart", data, options);
1463
1488
  });
1464
1489
  };
1465
1490
 
1466
- defaultExport$2.prototype.renderGeoChart = function renderGeoChart (chart) {
1491
+ defaultExport.prototype.renderGeoChart = function renderGeoChart (chart) {
1467
1492
  var this$1 = this;
1468
1493
 
1469
- this.waitForLoaded(chart, function () {
1494
+ this.waitForLoaded(chart, "geochart", function () {
1470
1495
  var chartOptions = {
1471
1496
  legend: "none",
1472
1497
  colorAxis: {
1473
1498
  colors: chart.options.colors || ["#f6c7b6", "#ce502d"]
1474
1499
  }
1475
1500
  };
1476
- var options = merge(merge(defaultOptions$2, chartOptions), chart.options.library || {});
1501
+ var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {});
1477
1502
 
1478
1503
  var data = new this$1.library.visualization.DataTable();
1479
1504
  data.addColumn("string", "");
@@ -1484,12 +1509,12 @@
1484
1509
  });
1485
1510
  };
1486
1511
 
1487
- defaultExport$2.prototype.renderScatterChart = function renderScatterChart (chart) {
1512
+ defaultExport.prototype.renderScatterChart = function renderScatterChart (chart) {
1488
1513
  var this$1 = this;
1489
1514
 
1490
1515
  this.waitForLoaded(chart, function () {
1491
1516
  var chartOptions = {};
1492
- var options = jsOptions$2(chart, chart.options, chartOptions);
1517
+ var options = jsOptions(chart, chart.options, chartOptions);
1493
1518
 
1494
1519
  var series = chart.data, rows2 = [], i, j, data, d;
1495
1520
  for (i = 0; i < series.length; i++) {
@@ -1514,7 +1539,7 @@
1514
1539
  });
1515
1540
  };
1516
1541
 
1517
- defaultExport$2.prototype.renderTimeline = function renderTimeline (chart) {
1542
+ defaultExport.prototype.renderTimeline = function renderTimeline (chart) {
1518
1543
  var this$1 = this;
1519
1544
 
1520
1545
  this.waitForLoaded(chart, "timeline", function () {
@@ -1525,7 +1550,7 @@
1525
1550
  if (chart.options.colors) {
1526
1551
  chartOptions.colors = chart.options.colors;
1527
1552
  }
1528
- var options = merge(merge(defaultOptions$2, chartOptions), chart.options.library || {});
1553
+ var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {});
1529
1554
 
1530
1555
  var data = new this$1.library.visualization.DataTable();
1531
1556
  data.addColumn({type: "string", id: "Name"});
@@ -1539,14 +1564,16 @@
1539
1564
  });
1540
1565
  };
1541
1566
 
1542
- defaultExport$2.prototype.destroy = function destroy (chart) {
1567
+ // TODO remove resize events
1568
+ defaultExport.prototype.destroy = function destroy (chart) {
1543
1569
  if (chart.chart) {
1544
1570
  chart.chart.clearChart();
1545
1571
  }
1546
1572
  };
1547
1573
 
1548
- defaultExport$2.prototype.drawChart = function drawChart (chart, type, data, options) {
1574
+ defaultExport.prototype.drawChart = function drawChart (chart, type, data, options) {
1549
1575
  this.destroy(chart);
1576
+ if (chart.destroyed) { return; }
1550
1577
 
1551
1578
  if (chart.options.code) {
1552
1579
  window.console.log("var data = new google.visualization.DataTable(" + data.toJSON() + ");\nvar chart = new google.visualization." + type + "(element);\nchart.draw(data, " + JSON.stringify(options) + ");");
@@ -1558,7 +1585,7 @@
1558
1585
  });
1559
1586
  };
1560
1587
 
1561
- defaultExport$2.prototype.waitForLoaded = function waitForLoaded (chart, pack, callback) {
1588
+ defaultExport.prototype.waitForLoaded = function waitForLoaded (chart, pack, callback) {
1562
1589
  var this$1 = this;
1563
1590
 
1564
1591
  if (!callback) {
@@ -1582,7 +1609,7 @@
1582
1609
  if (config.language) {
1583
1610
  loadOptions.language = config.language;
1584
1611
  }
1585
- if (pack === "corechart" && config.mapsApiKey) {
1612
+ if (pack === "geochart" && config.mapsApiKey) {
1586
1613
  loadOptions.mapsApiKey = config.mapsApiKey;
1587
1614
  }
1588
1615
 
@@ -1590,11 +1617,11 @@
1590
1617
  }
1591
1618
  };
1592
1619
 
1593
- defaultExport$2.prototype.runCallbacks = function runCallbacks () {
1620
+ defaultExport.prototype.runCallbacks = function runCallbacks () {
1594
1621
  var cb, call;
1595
1622
  for (var i = 0; i < callbacks.length; i++) {
1596
1623
  cb = callbacks[i];
1597
- call = this.library.visualization && ((cb.pack === "corechart" && this.library.visualization.LineChart) || (cb.pack === "timeline" && this.library.visualization.Timeline));
1624
+ call = this.library.visualization && ((cb.pack === "corechart" && this.library.visualization.LineChart) || (cb.pack === "timeline" && this.library.visualization.Timeline) || (cb.pack === "geochart" && this.library.visualization.GeoChart));
1598
1625
  if (call) {
1599
1626
  cb.callback();
1600
1627
  callbacks.splice(i, 1);
@@ -1604,7 +1631,7 @@
1604
1631
  };
1605
1632
 
1606
1633
  // cant use object as key
1607
- defaultExport$2.prototype.createDataTable = function createDataTable (series, columnType) {
1634
+ defaultExport.prototype.createDataTable = function createDataTable (series, columnType) {
1608
1635
  var i, j, s, d, key, rows = [], sortedLabels = [];
1609
1636
  for (i = 0; i < series.length; i++) {
1610
1637
  s = series[i];
@@ -1748,7 +1775,12 @@
1748
1775
  }
1749
1776
  }
1750
1777
 
1751
- function fetchDataSource(chart, dataSource) {
1778
+ function fetchDataSource(chart, dataSource, showLoading) {
1779
+ // only show loading message for urls and callbacks
1780
+ if (showLoading && chart.options.loading && (typeof dataSource === "string" || typeof dataSource === "function")) {
1781
+ setText(chart.element, chart.options.loading);
1782
+ }
1783
+
1752
1784
  if (typeof dataSource === "string") {
1753
1785
  pushRequest(dataSource, function (data) {
1754
1786
  chart.rawData = data;
@@ -1858,9 +1890,9 @@
1858
1890
  if (library.product === "Highcharts") {
1859
1891
  return defaultExport$1;
1860
1892
  } else if (library.charts) {
1861
- return defaultExport$2;
1862
- } else if (isFunction(library)) {
1863
1893
  return defaultExport;
1894
+ } else if (isFunction(library)) {
1895
+ return defaultExport$2;
1864
1896
  }
1865
1897
  }
1866
1898
  throw new Error("Unknown adapter");
@@ -1903,8 +1935,9 @@
1903
1935
  }
1904
1936
 
1905
1937
  function renderChart(chartType, chart) {
1906
- if (chart.options.messages && chart.options.messages.empty && dataEmpty(chart.data, chartType)) {
1907
- setText(chart.element, chart.options.messages.empty);
1938
+ if (dataEmpty(chart.data, chartType)) {
1939
+ var message = chart.options.empty || (chart.options.messages && chart.options.messages.empty) || "No data";
1940
+ setText(chart.element, message);
1908
1941
  } else {
1909
1942
  callAdapter(chartType, chart);
1910
1943
  if (chart.options.download && !chart.__downloadAttached && chart.adapter === "chartjs") {
@@ -1969,8 +2002,14 @@
1969
2002
  return r;
1970
2003
  };
1971
2004
 
1972
- function detectXType(series, noDatetime) {
1973
- if (detectXTypeWithFunction(series, isNumber)) {
2005
+ function detectXType(series, noDatetime, options) {
2006
+ if (dataEmpty(series)) {
2007
+ if ((options.xmin || options.xmax) && (!options.xmin || isDate(options.xmin)) && (!options.xmax || isDate(options.xmax))) {
2008
+ return "datetime";
2009
+ } else {
2010
+ return "number";
2011
+ }
2012
+ } else if (detectXTypeWithFunction(series, isNumber)) {
1974
2013
  return "number";
1975
2014
  } else if (!noDatetime && detectXTypeWithFunction(series, isDate)) {
1976
2015
  return "datetime";
@@ -2017,17 +2056,23 @@
2017
2056
  // see if one series or multiple
2018
2057
  if (!isArray(series) || typeof series[0] !== "object" || isArray(series[0])) {
2019
2058
  series = [{name: opts.label, data: series}];
2020
- chart.hideLegend = true;
2059
+ chart.singleSeriesFormat = true;
2021
2060
  } else {
2022
- chart.hideLegend = false;
2061
+ chart.singleSeriesFormat = false;
2023
2062
  }
2024
2063
 
2025
- chart.xtype = keyType ? keyType : (opts.discrete ? "string" : detectXType(series, noDatetime));
2064
+ // convert to array
2065
+ // must come before dataEmpty check
2066
+ series = copySeries(series);
2067
+ for (i = 0; i < series.length; i++) {
2068
+ series[i].data = toArr(series[i].data);
2069
+ }
2070
+
2071
+ chart.xtype = keyType ? keyType : (opts.discrete ? "string" : detectXType(series, noDatetime, opts));
2026
2072
 
2027
2073
  // right format
2028
- series = copySeries(series);
2029
2074
  for (i = 0; i < series.length; i++) {
2030
- series[i].data = formatSeriesData(toArr(series[i].data), chart.xtype);
2075
+ series[i].data = formatSeriesData(series[i].data, chart.xtype);
2031
2076
  }
2032
2077
 
2033
2078
  return series;
@@ -2058,7 +2103,7 @@
2058
2103
 
2059
2104
  Chartkick.charts[element.id] = this;
2060
2105
 
2061
- fetchDataSource(this, dataSource);
2106
+ fetchDataSource(this, dataSource, true);
2062
2107
 
2063
2108
  if (this.options.refresh) {
2064
2109
  this.startRefresh();
@@ -2094,7 +2139,7 @@
2094
2139
  if (options) {
2095
2140
  this.__updateOptions(options);
2096
2141
  }
2097
- fetchDataSource(this, dataSource);
2142
+ fetchDataSource(this, dataSource, true);
2098
2143
  };
2099
2144
 
2100
2145
  Chart.prototype.setOptions = function setOptions (options) {
@@ -2162,13 +2207,14 @@
2162
2207
  return this.chart.toBase64Image();
2163
2208
  }
2164
2209
  } else {
2165
- // TODO throw error in next major version
2166
- // throw new Error("Feature only available for Chart.js");
2167
- return null;
2210
+ throw new Error("Feature only available for Chart.js");
2168
2211
  }
2169
2212
  };
2170
2213
 
2171
2214
  Chart.prototype.destroy = function destroy () {
2215
+ this.destroyed = true;
2216
+ this.stopRefresh();
2217
+
2172
2218
  if (this.__adapterObject) {
2173
2219
  this.__adapterObject.destroy(this);
2174
2220
  }
@@ -2413,6 +2459,14 @@
2413
2459
  }
2414
2460
  }
2415
2461
  },
2462
+ destroyAll: function() {
2463
+ for (var chartId in Chartkick.charts) {
2464
+ if (Chartkick.charts.hasOwnProperty(chartId)) {
2465
+ Chartkick.charts[chartId].destroy();
2466
+ delete Chartkick.charts[chartId];
2467
+ }
2468
+ }
2469
+ },
2416
2470
  config: config,
2417
2471
  options: {},
2418
2472
  adapters: adapters,
@@ -2426,6 +2480,16 @@
2426
2480
  // not ideal, but allows for simpler integration
2427
2481
  if (typeof window !== "undefined" && !window.Chartkick) {
2428
2482
  window.Chartkick = Chartkick;
2483
+
2484
+ // clean up previous charts before Turbolinks loads new page
2485
+ document.addEventListener("turbolinks:before-render", function() {
2486
+ Chartkick.destroyAll();
2487
+ });
2488
+
2489
+ // use setTimeout so charting library can come later in same JS file
2490
+ setTimeout(function() {
2491
+ window.dispatchEvent(new Event("chartkick:load"));
2492
+ }, 0);
2429
2493
  }
2430
2494
 
2431
2495
  // backwards compatibility for esm require