chartkick 3.4.2 → 4.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/LICENSE.txt +1 -1
- data/README.md +42 -28
- data/lib/chartkick/helper.rb +39 -40
- data/lib/chartkick/version.rb +1 -1
- data/licenses/LICENSE-chart.js.txt +1 -1
- data/licenses/LICENSE-chartjs-adapter-date-fns.txt +9 -0
- data/licenses/LICENSE-chartkick.js.txt +1 -1
- data/licenses/LICENSE-date-fns.txt +20 -0
- data/vendor/assets/javascripts/Chart.bundle.js +2 -20776
- data/vendor/assets/javascripts/chart.js +12486 -0
- data/vendor/assets/javascripts/chartjs-adapter-date-fns.bundle.js +6313 -0
- data/vendor/assets/javascripts/chartkick.js +279 -242
- metadata +13 -52
- data/licenses/LICENSE-moment.txt +0 -22
|
@@ -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
|
-
*
|
|
5
|
+
* v4.0.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 = 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,15 @@
|
|
|
120
84
|
} else {
|
|
121
85
|
n = toStr(n);
|
|
122
86
|
if ((matches = n.match(DATE_PATTERN))) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
} else {
|
|
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 =
|
|
95
|
+
n = new Date(str) || new Date(n);
|
|
132
96
|
}
|
|
133
97
|
}
|
|
134
98
|
}
|
|
@@ -154,8 +118,8 @@
|
|
|
154
118
|
var options = merge({}, defaultOptions);
|
|
155
119
|
options = merge(options, chartOptions || {});
|
|
156
120
|
|
|
157
|
-
if (chart.
|
|
158
|
-
hideLegend(options, opts.legend, chart.
|
|
121
|
+
if (chart.singleSeriesFormat || "legend" in opts) {
|
|
122
|
+
hideLegend(options, opts.legend, chart.singleSeriesFormat);
|
|
159
123
|
}
|
|
160
124
|
|
|
161
125
|
if (opts.title) {
|
|
@@ -361,42 +325,49 @@
|
|
|
361
325
|
var baseOptions = {
|
|
362
326
|
maintainAspectRatio: false,
|
|
363
327
|
animation: false,
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
328
|
+
plugins: {
|
|
329
|
+
legend: {},
|
|
330
|
+
tooltip: {
|
|
331
|
+
displayColors: false,
|
|
332
|
+
callbacks: {}
|
|
333
|
+
},
|
|
334
|
+
title: {
|
|
335
|
+
font: {
|
|
336
|
+
size: 20
|
|
337
|
+
},
|
|
338
|
+
color: "#333"
|
|
339
|
+
}
|
|
367
340
|
},
|
|
368
|
-
|
|
369
|
-
title: {fontSize: 20, fontColor: "#333"}
|
|
341
|
+
interaction: {}
|
|
370
342
|
};
|
|
371
343
|
|
|
372
|
-
var defaultOptions = {
|
|
344
|
+
var defaultOptions$2 = {
|
|
373
345
|
scales: {
|
|
374
|
-
|
|
375
|
-
{
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
// fontStyle: "bold",
|
|
382
|
-
fontColor: "#333"
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
],
|
|
386
|
-
xAxes: [
|
|
387
|
-
{
|
|
388
|
-
gridLines: {
|
|
389
|
-
drawOnChartArea: false
|
|
346
|
+
y: {
|
|
347
|
+
ticks: {
|
|
348
|
+
maxTicksLimit: 4
|
|
349
|
+
},
|
|
350
|
+
title: {
|
|
351
|
+
font: {
|
|
352
|
+
size: 16
|
|
390
353
|
},
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
354
|
+
color: "#333"
|
|
355
|
+
},
|
|
356
|
+
grid: {}
|
|
357
|
+
},
|
|
358
|
+
x: {
|
|
359
|
+
grid: {
|
|
360
|
+
drawOnChartArea: false
|
|
361
|
+
},
|
|
362
|
+
title: {
|
|
363
|
+
font: {
|
|
364
|
+
size: 16
|
|
395
365
|
},
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
|
|
366
|
+
color: "#333"
|
|
367
|
+
},
|
|
368
|
+
time: {},
|
|
369
|
+
ticks: {}
|
|
370
|
+
}
|
|
400
371
|
}
|
|
401
372
|
};
|
|
402
373
|
|
|
@@ -407,66 +378,66 @@
|
|
|
407
378
|
"#6633CC", "#E67300", "#8B0707", "#329262", "#5574A6", "#651067"
|
|
408
379
|
];
|
|
409
380
|
|
|
410
|
-
var hideLegend = function (options, legend, hideLegend) {
|
|
381
|
+
var hideLegend$2 = function (options, legend, hideLegend) {
|
|
411
382
|
if (legend !== undefined) {
|
|
412
|
-
options.legend.display = !!legend;
|
|
383
|
+
options.plugins.legend.display = !!legend;
|
|
413
384
|
if (legend && legend !== true) {
|
|
414
|
-
options.legend.position = legend;
|
|
385
|
+
options.plugins.legend.position = legend;
|
|
415
386
|
}
|
|
416
387
|
} else if (hideLegend) {
|
|
417
|
-
options.legend.display = false;
|
|
388
|
+
options.plugins.legend.display = false;
|
|
418
389
|
}
|
|
419
390
|
};
|
|
420
391
|
|
|
421
|
-
var setTitle = function (options, title) {
|
|
422
|
-
options.title.display = true;
|
|
423
|
-
options.title.text = title;
|
|
392
|
+
var setTitle$2 = function (options, title) {
|
|
393
|
+
options.plugins.title.display = true;
|
|
394
|
+
options.plugins.title.text = title;
|
|
424
395
|
};
|
|
425
396
|
|
|
426
|
-
var setMin = function (options, min) {
|
|
397
|
+
var setMin$2 = function (options, min) {
|
|
427
398
|
if (min !== null) {
|
|
428
|
-
options.scales.
|
|
399
|
+
options.scales.y.min = toFloat(min);
|
|
429
400
|
}
|
|
430
401
|
};
|
|
431
402
|
|
|
432
|
-
var setMax = function (options, max) {
|
|
433
|
-
options.scales.
|
|
403
|
+
var setMax$2 = function (options, max) {
|
|
404
|
+
options.scales.y.max = toFloat(max);
|
|
434
405
|
};
|
|
435
406
|
|
|
436
|
-
var setBarMin = function (options, min) {
|
|
407
|
+
var setBarMin$1 = function (options, min) {
|
|
437
408
|
if (min !== null) {
|
|
438
|
-
options.scales.
|
|
409
|
+
options.scales.x.min = toFloat(min);
|
|
439
410
|
}
|
|
440
411
|
};
|
|
441
412
|
|
|
442
|
-
var setBarMax = function (options, max) {
|
|
443
|
-
options.scales.
|
|
413
|
+
var setBarMax$1 = function (options, max) {
|
|
414
|
+
options.scales.x.max = toFloat(max);
|
|
444
415
|
};
|
|
445
416
|
|
|
446
|
-
var setStacked = function (options, stacked) {
|
|
447
|
-
options.scales.
|
|
448
|
-
options.scales.
|
|
417
|
+
var setStacked$2 = function (options, stacked) {
|
|
418
|
+
options.scales.x.stacked = !!stacked;
|
|
419
|
+
options.scales.y.stacked = !!stacked;
|
|
449
420
|
};
|
|
450
421
|
|
|
451
|
-
var setXtitle = function (options, title) {
|
|
452
|
-
options.scales.
|
|
453
|
-
options.scales.
|
|
422
|
+
var setXtitle$2 = function (options, title) {
|
|
423
|
+
options.scales.x.title.display = true;
|
|
424
|
+
options.scales.x.title.text = title;
|
|
454
425
|
};
|
|
455
426
|
|
|
456
|
-
var setYtitle = function (options, title) {
|
|
457
|
-
options.scales.
|
|
458
|
-
options.scales.
|
|
427
|
+
var setYtitle$2 = function (options, title) {
|
|
428
|
+
options.scales.y.title.display = true;
|
|
429
|
+
options.scales.y.title.text = title;
|
|
459
430
|
};
|
|
460
431
|
|
|
461
432
|
// https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
|
|
462
|
-
var addOpacity = function(hex, opacity) {
|
|
433
|
+
var addOpacity = function (hex, opacity) {
|
|
463
434
|
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
464
435
|
return result ? "rgba(" + parseInt(result[1], 16) + ", " + parseInt(result[2], 16) + ", " + parseInt(result[3], 16) + ", " + opacity + ")" : hex;
|
|
465
436
|
};
|
|
466
437
|
|
|
467
438
|
// check if not null or undefined
|
|
468
439
|
// https://stackoverflow.com/a/27757708/1177228
|
|
469
|
-
var notnull = function(x) {
|
|
440
|
+
var notnull = function (x) {
|
|
470
441
|
return x != null;
|
|
471
442
|
};
|
|
472
443
|
|
|
@@ -477,9 +448,9 @@
|
|
|
477
448
|
} else if (maxLabelSize < 10) {
|
|
478
449
|
maxLabelSize = 10;
|
|
479
450
|
}
|
|
480
|
-
if (!options.scales.
|
|
481
|
-
options.scales.
|
|
482
|
-
value = toStr(value);
|
|
451
|
+
if (!options.scales.x.ticks.callback) {
|
|
452
|
+
options.scales.x.ticks.callback = function (value) {
|
|
453
|
+
value = toStr(this.getLabelForValue(value));
|
|
483
454
|
if (value.length > maxLabelSize) {
|
|
484
455
|
return value.substring(0, maxLabelSize - 2) + "...";
|
|
485
456
|
} else {
|
|
@@ -489,7 +460,7 @@
|
|
|
489
460
|
}
|
|
490
461
|
};
|
|
491
462
|
|
|
492
|
-
var setFormatOptions = function(chart, options, chartType) {
|
|
463
|
+
var setFormatOptions$1 = function (chart, options, chartType) {
|
|
493
464
|
var formatOptions = {
|
|
494
465
|
prefix: chart.options.prefix,
|
|
495
466
|
suffix: chart.options.suffix,
|
|
@@ -529,49 +500,49 @@
|
|
|
529
500
|
}
|
|
530
501
|
|
|
531
502
|
if (chartType !== "pie") {
|
|
532
|
-
var
|
|
503
|
+
var axis = options.scales.y;
|
|
533
504
|
if (chartType === "bar") {
|
|
534
|
-
|
|
505
|
+
axis = options.scales.x;
|
|
535
506
|
}
|
|
536
507
|
|
|
537
508
|
if (formatOptions.byteScale) {
|
|
538
|
-
if (!
|
|
539
|
-
|
|
509
|
+
if (!axis.ticks.stepSize) {
|
|
510
|
+
axis.ticks.stepSize = formatOptions.byteScale / 2;
|
|
540
511
|
}
|
|
541
|
-
if (!
|
|
542
|
-
|
|
512
|
+
if (!axis.ticks.maxTicksLimit) {
|
|
513
|
+
axis.ticks.maxTicksLimit = 4;
|
|
543
514
|
}
|
|
544
515
|
}
|
|
545
516
|
|
|
546
|
-
if (!
|
|
547
|
-
|
|
517
|
+
if (!axis.ticks.callback) {
|
|
518
|
+
axis.ticks.callback = function (value) {
|
|
548
519
|
return formatValue("", value, formatOptions, true);
|
|
549
520
|
};
|
|
550
521
|
}
|
|
551
522
|
}
|
|
552
523
|
|
|
553
|
-
if (!options.
|
|
524
|
+
if (!options.plugins.tooltip.callbacks.label) {
|
|
554
525
|
if (chartType === "scatter") {
|
|
555
|
-
options.
|
|
556
|
-
var label =
|
|
526
|
+
options.plugins.tooltip.callbacks.label = function (context) {
|
|
527
|
+
var label = context.dataset.label || '';
|
|
557
528
|
if (label) {
|
|
558
529
|
label += ': ';
|
|
559
530
|
}
|
|
560
|
-
return label + '(' +
|
|
531
|
+
return label + '(' + context.label + ', ' + context.formattedValue + ')';
|
|
561
532
|
};
|
|
562
533
|
} else if (chartType === "bubble") {
|
|
563
|
-
options.
|
|
564
|
-
var label =
|
|
534
|
+
options.plugins.tooltip.callbacks.label = function (context) {
|
|
535
|
+
var label = context.dataset.label || '';
|
|
565
536
|
if (label) {
|
|
566
537
|
label += ': ';
|
|
567
538
|
}
|
|
568
|
-
var dataPoint =
|
|
569
|
-
return label + '(' +
|
|
539
|
+
var dataPoint = context.raw;
|
|
540
|
+
return label + '(' + dataPoint.x + ', ' + dataPoint.y + ', ' + dataPoint.v + ')';
|
|
570
541
|
};
|
|
571
542
|
} else if (chartType === "pie") {
|
|
572
543
|
// need to use separate label for pie charts
|
|
573
|
-
options.
|
|
574
|
-
var dataLabel =
|
|
544
|
+
options.plugins.tooltip.callbacks.label = function (context) {
|
|
545
|
+
var dataLabel = context.label;
|
|
575
546
|
var value = ': ';
|
|
576
547
|
|
|
577
548
|
if (isArray(dataLabel)) {
|
|
@@ -583,24 +554,24 @@
|
|
|
583
554
|
dataLabel += value;
|
|
584
555
|
}
|
|
585
556
|
|
|
586
|
-
return formatValue(dataLabel,
|
|
557
|
+
return formatValue(dataLabel, context.parsed, formatOptions);
|
|
587
558
|
};
|
|
588
559
|
} else {
|
|
589
|
-
var valueLabel = chartType === "bar" ? "
|
|
590
|
-
options.
|
|
591
|
-
var label =
|
|
560
|
+
var valueLabel = chartType === "bar" ? "x" : "y";
|
|
561
|
+
options.plugins.tooltip.callbacks.label = function (context) {
|
|
562
|
+
var label = context.dataset.label || '';
|
|
592
563
|
if (label) {
|
|
593
564
|
label += ': ';
|
|
594
565
|
}
|
|
595
|
-
return formatValue(label,
|
|
566
|
+
return formatValue(label, context.parsed[valueLabel], formatOptions);
|
|
596
567
|
};
|
|
597
568
|
}
|
|
598
569
|
}
|
|
599
570
|
};
|
|
600
571
|
|
|
601
|
-
var jsOptions = jsOptionsFunc(merge(baseOptions, defaultOptions), hideLegend, setTitle, setMin, setMax, setStacked, setXtitle, setYtitle);
|
|
572
|
+
var jsOptions$2 = jsOptionsFunc(merge(baseOptions, defaultOptions$2), hideLegend$2, setTitle$2, setMin$2, setMax$2, setStacked$2, setXtitle$2, setYtitle$2);
|
|
602
573
|
|
|
603
|
-
var createDataTable = function (chart, options, chartType
|
|
574
|
+
var createDataTable = function (chart, options, chartType) {
|
|
604
575
|
var datasets = [];
|
|
605
576
|
var labels = [];
|
|
606
577
|
|
|
@@ -702,11 +673,23 @@
|
|
|
702
673
|
}
|
|
703
674
|
}
|
|
704
675
|
|
|
676
|
+
var color;
|
|
677
|
+
var backgroundColor;
|
|
678
|
+
|
|
705
679
|
for (i = 0; i < series.length; i++) {
|
|
706
680
|
s = series[i];
|
|
707
681
|
|
|
708
|
-
|
|
709
|
-
|
|
682
|
+
// use colors for each bar for single series format
|
|
683
|
+
if (chart.options.colors && chart.singleSeriesFormat && (chartType === "bar" || chartType === "column") && !s.color) {
|
|
684
|
+
color = colors;
|
|
685
|
+
backgroundColor = [];
|
|
686
|
+
for (var j$3 = 0; j$3 < colors.length; j$3++) {
|
|
687
|
+
backgroundColor[j$3] = addOpacity(color[j$3], 0.5);
|
|
688
|
+
}
|
|
689
|
+
} else {
|
|
690
|
+
color = s.color || colors[i];
|
|
691
|
+
backgroundColor = chartType !== "line" ? addOpacity(color, 0.5) : color;
|
|
692
|
+
}
|
|
710
693
|
|
|
711
694
|
var dataset = {
|
|
712
695
|
label: s.name || "",
|
|
@@ -714,24 +697,37 @@
|
|
|
714
697
|
fill: chartType === "area",
|
|
715
698
|
borderColor: color,
|
|
716
699
|
backgroundColor: backgroundColor,
|
|
717
|
-
|
|
718
|
-
borderWidth: 2,
|
|
719
|
-
pointHoverBackgroundColor: color
|
|
700
|
+
borderWidth: 2
|
|
720
701
|
};
|
|
721
702
|
|
|
703
|
+
var pointChart = chartType === "line" || chartType === "area" || chartType === "scatter" || chartType === "bubble";
|
|
704
|
+
if (pointChart) {
|
|
705
|
+
dataset.pointBackgroundColor = color;
|
|
706
|
+
dataset.pointHoverBackgroundColor = color;
|
|
707
|
+
dataset.pointHitRadius = 50;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
if (chartType === "bubble") {
|
|
711
|
+
dataset.pointBackgroundColor = backgroundColor;
|
|
712
|
+
dataset.pointHoverBackgroundColor = backgroundColor;
|
|
713
|
+
dataset.pointHoverBorderWidth = 2;
|
|
714
|
+
}
|
|
715
|
+
|
|
722
716
|
if (s.stack) {
|
|
723
717
|
dataset.stack = s.stack;
|
|
724
718
|
}
|
|
725
719
|
|
|
726
720
|
var curve = seriesOption(chart, s, "curve");
|
|
727
721
|
if (curve === false) {
|
|
728
|
-
dataset.
|
|
722
|
+
dataset.tension = 0;
|
|
723
|
+
} else if (pointChart) {
|
|
724
|
+
dataset.tension = 0.4;
|
|
729
725
|
}
|
|
730
726
|
|
|
731
727
|
var points = seriesOption(chart, s, "points");
|
|
732
728
|
if (points === false) {
|
|
733
729
|
dataset.pointRadius = 0;
|
|
734
|
-
dataset.
|
|
730
|
+
dataset.pointHoverRadius = 0;
|
|
735
731
|
}
|
|
736
732
|
|
|
737
733
|
dataset = merge(dataset, chart.options.dataset || {});
|
|
@@ -745,22 +741,18 @@
|
|
|
745
741
|
var xmax = chart.options.xmax;
|
|
746
742
|
|
|
747
743
|
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
744
|
if (notnull(xmin)) {
|
|
753
|
-
options.scales.
|
|
745
|
+
options.scales.x.ticks.min = toDate(xmin).getTime();
|
|
754
746
|
}
|
|
755
747
|
if (notnull(xmax)) {
|
|
756
|
-
options.scales.
|
|
748
|
+
options.scales.x.ticks.max = toDate(xmax).getTime();
|
|
757
749
|
}
|
|
758
750
|
} else if (chart.xtype === "number") {
|
|
759
751
|
if (notnull(xmin)) {
|
|
760
|
-
options.scales.
|
|
752
|
+
options.scales.x.ticks.min = xmin;
|
|
761
753
|
}
|
|
762
754
|
if (notnull(xmax)) {
|
|
763
|
-
options.scales.
|
|
755
|
+
options.scales.x.ticks.max = xmax;
|
|
764
756
|
}
|
|
765
757
|
}
|
|
766
758
|
|
|
@@ -796,24 +788,24 @@
|
|
|
796
788
|
|
|
797
789
|
var timeDiff = (maxTime - minTime) / (86400 * 1000.0);
|
|
798
790
|
|
|
799
|
-
if (!options.scales.
|
|
791
|
+
if (!options.scales.x.time.unit) {
|
|
800
792
|
var step;
|
|
801
793
|
if (year || timeDiff > 365 * 10) {
|
|
802
|
-
options.scales.
|
|
794
|
+
options.scales.x.time.unit = "year";
|
|
803
795
|
step = 365;
|
|
804
796
|
} else if (month || timeDiff > 30 * 10) {
|
|
805
|
-
options.scales.
|
|
797
|
+
options.scales.x.time.unit = "month";
|
|
806
798
|
step = 30;
|
|
807
799
|
} else if (day || timeDiff > 10) {
|
|
808
|
-
options.scales.
|
|
800
|
+
options.scales.x.time.unit = "day";
|
|
809
801
|
step = 1;
|
|
810
802
|
} else if (hour || timeDiff > 0.5) {
|
|
811
|
-
options.scales.
|
|
812
|
-
options.scales.
|
|
803
|
+
options.scales.x.time.displayFormats = {hour: "MMM d, h a"};
|
|
804
|
+
options.scales.x.time.unit = "hour";
|
|
813
805
|
step = 1 / 24.0;
|
|
814
806
|
} else if (minute) {
|
|
815
|
-
options.scales.
|
|
816
|
-
options.scales.
|
|
807
|
+
options.scales.x.time.displayFormats = {minute: "h:mm a"};
|
|
808
|
+
options.scales.x.time.unit = "minute";
|
|
817
809
|
step = 1 / 24.0 / 60.0;
|
|
818
810
|
}
|
|
819
811
|
|
|
@@ -822,17 +814,17 @@
|
|
|
822
814
|
if (week && step === 1) {
|
|
823
815
|
unitStepSize = Math.ceil(unitStepSize / 7.0) * 7;
|
|
824
816
|
}
|
|
825
|
-
options.scales.
|
|
817
|
+
options.scales.x.time.stepSize = unitStepSize;
|
|
826
818
|
}
|
|
827
819
|
}
|
|
828
820
|
|
|
829
|
-
if (!options.scales.
|
|
821
|
+
if (!options.scales.x.time.tooltipFormat) {
|
|
830
822
|
if (day) {
|
|
831
|
-
options.scales.
|
|
823
|
+
options.scales.x.time.tooltipFormat = "PP";
|
|
832
824
|
} else if (hour) {
|
|
833
|
-
options.scales.
|
|
825
|
+
options.scales.x.time.tooltipFormat = "MMM d, h a";
|
|
834
826
|
} else if (minute) {
|
|
835
|
-
options.scales.
|
|
827
|
+
options.scales.x.time.tooltipFormat = "h:mm a";
|
|
836
828
|
}
|
|
837
829
|
}
|
|
838
830
|
}
|
|
@@ -845,49 +837,49 @@
|
|
|
845
837
|
return data;
|
|
846
838
|
};
|
|
847
839
|
|
|
848
|
-
var defaultExport = function defaultExport(library) {
|
|
840
|
+
var defaultExport$2 = function defaultExport(library) {
|
|
849
841
|
this.name = "chartjs";
|
|
850
842
|
this.library = library;
|
|
851
843
|
};
|
|
852
844
|
|
|
853
|
-
defaultExport.prototype.renderLineChart = function renderLineChart (chart, chartType) {
|
|
845
|
+
defaultExport$2.prototype.renderLineChart = function renderLineChart (chart, chartType) {
|
|
854
846
|
var chartOptions = {};
|
|
855
847
|
// fix for https://github.com/chartjs/Chart.js/issues/2441
|
|
856
848
|
if (!chart.options.max && allZeros(chart.data)) {
|
|
857
849
|
chartOptions.max = 1;
|
|
858
850
|
}
|
|
859
851
|
|
|
860
|
-
var options = jsOptions(chart, merge(chartOptions, chart.options));
|
|
861
|
-
setFormatOptions(chart, options, chartType);
|
|
852
|
+
var options = jsOptions$2(chart, merge(chartOptions, chart.options));
|
|
853
|
+
setFormatOptions$1(chart, options, chartType);
|
|
862
854
|
|
|
863
|
-
var data = createDataTable(chart, options, chartType || "line"
|
|
855
|
+
var data = createDataTable(chart, options, chartType || "line");
|
|
864
856
|
|
|
865
857
|
if (chart.xtype === "number") {
|
|
866
|
-
options.scales.
|
|
867
|
-
options.scales.
|
|
858
|
+
options.scales.x.type = "linear";
|
|
859
|
+
options.scales.x.position = "bottom";
|
|
868
860
|
} else {
|
|
869
|
-
options.scales.
|
|
861
|
+
options.scales.x.type = chart.xtype === "string" ? "category" : "time";
|
|
870
862
|
}
|
|
871
863
|
|
|
872
864
|
this.drawChart(chart, "line", data, options);
|
|
873
865
|
};
|
|
874
866
|
|
|
875
|
-
defaultExport.prototype.renderPieChart = function renderPieChart (chart) {
|
|
867
|
+
defaultExport$2.prototype.renderPieChart = function renderPieChart (chart) {
|
|
876
868
|
var options = merge({}, baseOptions);
|
|
877
869
|
if (chart.options.donut) {
|
|
878
|
-
options.
|
|
870
|
+
options.cutout = "50%";
|
|
879
871
|
}
|
|
880
872
|
|
|
881
873
|
if ("legend" in chart.options) {
|
|
882
|
-
hideLegend(options, chart.options.legend);
|
|
874
|
+
hideLegend$2(options, chart.options.legend);
|
|
883
875
|
}
|
|
884
876
|
|
|
885
877
|
if (chart.options.title) {
|
|
886
|
-
setTitle(options, chart.options.title);
|
|
878
|
+
setTitle$2(options, chart.options.title);
|
|
887
879
|
}
|
|
888
880
|
|
|
889
881
|
options = merge(options, chart.options.library || {});
|
|
890
|
-
setFormatOptions(chart, options, "pie");
|
|
882
|
+
setFormatOptions$1(chart, options, "pie");
|
|
891
883
|
|
|
892
884
|
var labels = [];
|
|
893
885
|
var values = [];
|
|
@@ -911,61 +903,73 @@
|
|
|
911
903
|
this.drawChart(chart, "pie", data, options);
|
|
912
904
|
};
|
|
913
905
|
|
|
914
|
-
defaultExport.prototype.renderColumnChart = function renderColumnChart (chart, chartType) {
|
|
906
|
+
defaultExport$2.prototype.renderColumnChart = function renderColumnChart (chart, chartType) {
|
|
915
907
|
var options;
|
|
916
908
|
if (chartType === "bar") {
|
|
917
|
-
var barOptions = merge(baseOptions, defaultOptions);
|
|
918
|
-
|
|
919
|
-
|
|
909
|
+
var barOptions = merge(baseOptions, defaultOptions$2);
|
|
910
|
+
barOptions.indexAxis = "y";
|
|
911
|
+
|
|
912
|
+
// ensure gridlines have proper orientation
|
|
913
|
+
barOptions.scales.x.grid.drawOnChartArea = true;
|
|
914
|
+
barOptions.scales.y.grid.drawOnChartArea = false;
|
|
915
|
+
delete barOptions.scales.y.ticks.maxTicksLimit;
|
|
916
|
+
|
|
917
|
+
options = jsOptionsFunc(barOptions, hideLegend$2, setTitle$2, setBarMin$1, setBarMax$1, setStacked$2, setXtitle$2, setYtitle$2)(chart, chart.options);
|
|
920
918
|
} else {
|
|
921
|
-
options = jsOptions(chart, chart.options);
|
|
919
|
+
options = jsOptions$2(chart, chart.options);
|
|
922
920
|
}
|
|
923
|
-
setFormatOptions(chart, options, chartType);
|
|
924
|
-
var data = createDataTable(chart, options, "column"
|
|
921
|
+
setFormatOptions$1(chart, options, chartType);
|
|
922
|
+
var data = createDataTable(chart, options, "column");
|
|
925
923
|
if (chartType !== "bar") {
|
|
926
924
|
setLabelSize(chart, data, options);
|
|
927
925
|
}
|
|
928
|
-
this.drawChart(chart,
|
|
926
|
+
this.drawChart(chart, "bar", data, options);
|
|
929
927
|
};
|
|
930
928
|
|
|
931
|
-
defaultExport.prototype.renderAreaChart = function renderAreaChart (chart) {
|
|
929
|
+
defaultExport$2.prototype.renderAreaChart = function renderAreaChart (chart) {
|
|
932
930
|
this.renderLineChart(chart, "area");
|
|
933
931
|
};
|
|
934
932
|
|
|
935
|
-
defaultExport.prototype.renderBarChart = function renderBarChart (chart) {
|
|
933
|
+
defaultExport$2.prototype.renderBarChart = function renderBarChart (chart) {
|
|
936
934
|
this.renderColumnChart(chart, "bar");
|
|
937
935
|
};
|
|
938
936
|
|
|
939
|
-
defaultExport.prototype.renderScatterChart = function renderScatterChart (chart, chartType) {
|
|
937
|
+
defaultExport$2.prototype.renderScatterChart = function renderScatterChart (chart, chartType) {
|
|
940
938
|
chartType = chartType || "scatter";
|
|
941
939
|
|
|
942
|
-
var options = jsOptions(chart, chart.options);
|
|
943
|
-
setFormatOptions(chart, options, chartType);
|
|
940
|
+
var options = jsOptions$2(chart, chart.options);
|
|
941
|
+
setFormatOptions$1(chart, options, chartType);
|
|
944
942
|
|
|
945
|
-
if (!("
|
|
946
|
-
options.
|
|
943
|
+
if (!("showLine" in options)) {
|
|
944
|
+
options.showLine = false;
|
|
947
945
|
}
|
|
948
946
|
|
|
949
|
-
var data = createDataTable(chart, options, chartType
|
|
947
|
+
var data = createDataTable(chart, options, chartType);
|
|
948
|
+
|
|
949
|
+
options.scales.x.type = "linear";
|
|
950
|
+
options.scales.x.position = "bottom";
|
|
950
951
|
|
|
951
|
-
|
|
952
|
-
options.
|
|
952
|
+
// prevent grouping hover and tooltips
|
|
953
|
+
if (!("mode" in options.interaction)) {
|
|
954
|
+
options.interaction.mode = "nearest";
|
|
955
|
+
}
|
|
953
956
|
|
|
954
957
|
this.drawChart(chart, chartType, data, options);
|
|
955
958
|
};
|
|
956
959
|
|
|
957
|
-
defaultExport.prototype.renderBubbleChart = function renderBubbleChart (chart) {
|
|
960
|
+
defaultExport$2.prototype.renderBubbleChart = function renderBubbleChart (chart) {
|
|
958
961
|
this.renderScatterChart(chart, "bubble");
|
|
959
962
|
};
|
|
960
963
|
|
|
961
|
-
defaultExport.prototype.destroy = function destroy (chart) {
|
|
964
|
+
defaultExport$2.prototype.destroy = function destroy (chart) {
|
|
962
965
|
if (chart.chart) {
|
|
963
966
|
chart.chart.destroy();
|
|
964
967
|
}
|
|
965
968
|
};
|
|
966
969
|
|
|
967
|
-
defaultExport.prototype.drawChart = function drawChart (chart, type, data, options) {
|
|
970
|
+
defaultExport$2.prototype.drawChart = function drawChart (chart, type, data, options) {
|
|
968
971
|
this.destroy(chart);
|
|
972
|
+
if (chart.destroyed) { return; }
|
|
969
973
|
|
|
970
974
|
var chartOptions = {
|
|
971
975
|
type: type,
|
|
@@ -1024,6 +1028,9 @@
|
|
|
1024
1028
|
series: {
|
|
1025
1029
|
marker: {}
|
|
1026
1030
|
}
|
|
1031
|
+
},
|
|
1032
|
+
time: {
|
|
1033
|
+
useUTC: false
|
|
1027
1034
|
}
|
|
1028
1035
|
};
|
|
1029
1036
|
|
|
@@ -1073,7 +1080,7 @@
|
|
|
1073
1080
|
|
|
1074
1081
|
var jsOptions$1 = jsOptionsFunc(defaultOptions$1, hideLegend$1, setTitle$1, setMin$1, setMax$1, setStacked$1, setXtitle$1, setYtitle$1);
|
|
1075
1082
|
|
|
1076
|
-
var setFormatOptions
|
|
1083
|
+
var setFormatOptions = function(chart, options, chartType) {
|
|
1077
1084
|
var formatOptions = {
|
|
1078
1085
|
prefix: chart.options.prefix,
|
|
1079
1086
|
suffix: chart.options.suffix,
|
|
@@ -1136,7 +1143,7 @@
|
|
|
1136
1143
|
if (!options.chart.type) {
|
|
1137
1144
|
options.chart.type = chartType;
|
|
1138
1145
|
}
|
|
1139
|
-
setFormatOptions
|
|
1146
|
+
setFormatOptions(chart, options, chartType);
|
|
1140
1147
|
|
|
1141
1148
|
var series = chart.data;
|
|
1142
1149
|
for (i = 0; i < series.length; i++) {
|
|
@@ -1181,7 +1188,7 @@
|
|
|
1181
1188
|
}
|
|
1182
1189
|
|
|
1183
1190
|
var options = merge(chartOptions, chart.options.library || {});
|
|
1184
|
-
setFormatOptions
|
|
1191
|
+
setFormatOptions(chart, options, "pie");
|
|
1185
1192
|
var series = [{
|
|
1186
1193
|
type: "pie",
|
|
1187
1194
|
name: chart.options.label || "Value",
|
|
@@ -1196,7 +1203,7 @@
|
|
|
1196
1203
|
var series = chart.data;
|
|
1197
1204
|
var options = jsOptions$1(chart, chart.options), i, j, s, d, rows = [], categories = [];
|
|
1198
1205
|
options.chart.type = chartType;
|
|
1199
|
-
setFormatOptions
|
|
1206
|
+
setFormatOptions(chart, options, chartType);
|
|
1200
1207
|
|
|
1201
1208
|
for (i = 0; i < series.length; i++) {
|
|
1202
1209
|
s = series[i];
|
|
@@ -1254,6 +1261,7 @@
|
|
|
1254
1261
|
|
|
1255
1262
|
defaultExport$1.prototype.drawChart = function drawChart (chart, data, options) {
|
|
1256
1263
|
this.destroy(chart);
|
|
1264
|
+
if (chart.destroyed) { return; }
|
|
1257
1265
|
|
|
1258
1266
|
options.chart.renderTo = chart.element.id;
|
|
1259
1267
|
options.series = data;
|
|
@@ -1269,7 +1277,7 @@
|
|
|
1269
1277
|
var callbacks = [];
|
|
1270
1278
|
|
|
1271
1279
|
// Set chart options
|
|
1272
|
-
var defaultOptions
|
|
1280
|
+
var defaultOptions = {
|
|
1273
1281
|
chartArea: {},
|
|
1274
1282
|
fontName: "'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif",
|
|
1275
1283
|
pointSize: 6,
|
|
@@ -1311,7 +1319,7 @@
|
|
|
1311
1319
|
}
|
|
1312
1320
|
};
|
|
1313
1321
|
|
|
1314
|
-
var hideLegend
|
|
1322
|
+
var hideLegend = function (options, legend, hideLegend) {
|
|
1315
1323
|
if (legend !== undefined) {
|
|
1316
1324
|
var position;
|
|
1317
1325
|
if (!legend) {
|
|
@@ -1327,42 +1335,42 @@
|
|
|
1327
1335
|
}
|
|
1328
1336
|
};
|
|
1329
1337
|
|
|
1330
|
-
var setTitle
|
|
1338
|
+
var setTitle = function (options, title) {
|
|
1331
1339
|
options.title = title;
|
|
1332
1340
|
options.titleTextStyle = {color: "#333", fontSize: "20px"};
|
|
1333
1341
|
};
|
|
1334
1342
|
|
|
1335
|
-
var setMin
|
|
1343
|
+
var setMin = function (options, min) {
|
|
1336
1344
|
options.vAxis.viewWindow.min = min;
|
|
1337
1345
|
};
|
|
1338
1346
|
|
|
1339
|
-
var setMax
|
|
1347
|
+
var setMax = function (options, max) {
|
|
1340
1348
|
options.vAxis.viewWindow.max = max;
|
|
1341
1349
|
};
|
|
1342
1350
|
|
|
1343
|
-
var setBarMin
|
|
1351
|
+
var setBarMin = function (options, min) {
|
|
1344
1352
|
options.hAxis.viewWindow.min = min;
|
|
1345
1353
|
};
|
|
1346
1354
|
|
|
1347
|
-
var setBarMax
|
|
1355
|
+
var setBarMax = function (options, max) {
|
|
1348
1356
|
options.hAxis.viewWindow.max = max;
|
|
1349
1357
|
};
|
|
1350
1358
|
|
|
1351
|
-
var setStacked
|
|
1359
|
+
var setStacked = function (options, stacked) {
|
|
1352
1360
|
options.isStacked = stacked ? stacked : false;
|
|
1353
1361
|
};
|
|
1354
1362
|
|
|
1355
|
-
var setXtitle
|
|
1363
|
+
var setXtitle = function (options, title) {
|
|
1356
1364
|
options.hAxis.title = title;
|
|
1357
1365
|
options.hAxis.titleTextStyle.italic = false;
|
|
1358
1366
|
};
|
|
1359
1367
|
|
|
1360
|
-
var setYtitle
|
|
1368
|
+
var setYtitle = function (options, title) {
|
|
1361
1369
|
options.vAxis.title = title;
|
|
1362
1370
|
options.vAxis.titleTextStyle.italic = false;
|
|
1363
1371
|
};
|
|
1364
1372
|
|
|
1365
|
-
var jsOptions
|
|
1373
|
+
var jsOptions = jsOptionsFunc(defaultOptions, hideLegend, setTitle, setMin, setMax, setStacked, setXtitle, setYtitle);
|
|
1366
1374
|
|
|
1367
1375
|
var resize = function (callback) {
|
|
1368
1376
|
if (window.attachEvent) {
|
|
@@ -1373,12 +1381,12 @@
|
|
|
1373
1381
|
callback();
|
|
1374
1382
|
};
|
|
1375
1383
|
|
|
1376
|
-
var defaultExport
|
|
1384
|
+
var defaultExport = function defaultExport(library) {
|
|
1377
1385
|
this.name = "google";
|
|
1378
1386
|
this.library = library;
|
|
1379
1387
|
};
|
|
1380
1388
|
|
|
1381
|
-
defaultExport
|
|
1389
|
+
defaultExport.prototype.renderLineChart = function renderLineChart (chart) {
|
|
1382
1390
|
var this$1 = this;
|
|
1383
1391
|
|
|
1384
1392
|
this.waitForLoaded(chart, function () {
|
|
@@ -1392,14 +1400,14 @@
|
|
|
1392
1400
|
chartOptions.pointSize = 0;
|
|
1393
1401
|
}
|
|
1394
1402
|
|
|
1395
|
-
var options = jsOptions
|
|
1403
|
+
var options = jsOptions(chart, chart.options, chartOptions);
|
|
1396
1404
|
var data = this$1.createDataTable(chart.data, chart.xtype);
|
|
1397
1405
|
|
|
1398
1406
|
this$1.drawChart(chart, "LineChart", data, options);
|
|
1399
1407
|
});
|
|
1400
1408
|
};
|
|
1401
1409
|
|
|
1402
|
-
defaultExport
|
|
1410
|
+
defaultExport.prototype.renderPieChart = function renderPieChart (chart) {
|
|
1403
1411
|
var this$1 = this;
|
|
1404
1412
|
|
|
1405
1413
|
this.waitForLoaded(chart, function () {
|
|
@@ -1417,12 +1425,12 @@
|
|
|
1417
1425
|
chartOptions.pieHole = 0.5;
|
|
1418
1426
|
}
|
|
1419
1427
|
if ("legend" in chart.options) {
|
|
1420
|
-
hideLegend
|
|
1428
|
+
hideLegend(chartOptions, chart.options.legend);
|
|
1421
1429
|
}
|
|
1422
1430
|
if (chart.options.title) {
|
|
1423
|
-
setTitle
|
|
1431
|
+
setTitle(chartOptions, chart.options.title);
|
|
1424
1432
|
}
|
|
1425
|
-
var options = merge(merge(defaultOptions
|
|
1433
|
+
var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {});
|
|
1426
1434
|
|
|
1427
1435
|
var data = new this$1.library.visualization.DataTable();
|
|
1428
1436
|
data.addColumn("string", "");
|
|
@@ -1433,18 +1441,18 @@
|
|
|
1433
1441
|
});
|
|
1434
1442
|
};
|
|
1435
1443
|
|
|
1436
|
-
defaultExport
|
|
1444
|
+
defaultExport.prototype.renderColumnChart = function renderColumnChart (chart) {
|
|
1437
1445
|
var this$1 = this;
|
|
1438
1446
|
|
|
1439
1447
|
this.waitForLoaded(chart, function () {
|
|
1440
|
-
var options = jsOptions
|
|
1448
|
+
var options = jsOptions(chart, chart.options);
|
|
1441
1449
|
var data = this$1.createDataTable(chart.data, chart.xtype);
|
|
1442
1450
|
|
|
1443
1451
|
this$1.drawChart(chart, "ColumnChart", data, options);
|
|
1444
1452
|
});
|
|
1445
1453
|
};
|
|
1446
1454
|
|
|
1447
|
-
defaultExport
|
|
1455
|
+
defaultExport.prototype.renderBarChart = function renderBarChart (chart) {
|
|
1448
1456
|
var this$1 = this;
|
|
1449
1457
|
|
|
1450
1458
|
this.waitForLoaded(chart, function () {
|
|
@@ -1455,14 +1463,14 @@
|
|
|
1455
1463
|
}
|
|
1456
1464
|
}
|
|
1457
1465
|
};
|
|
1458
|
-
var options = jsOptionsFunc(defaultOptions
|
|
1466
|
+
var options = jsOptionsFunc(defaultOptions, hideLegend, setTitle, setBarMin, setBarMax, setStacked, setXtitle, setYtitle)(chart, chart.options, chartOptions);
|
|
1459
1467
|
var data = this$1.createDataTable(chart.data, chart.xtype);
|
|
1460
1468
|
|
|
1461
1469
|
this$1.drawChart(chart, "BarChart", data, options);
|
|
1462
1470
|
});
|
|
1463
1471
|
};
|
|
1464
1472
|
|
|
1465
|
-
defaultExport
|
|
1473
|
+
defaultExport.prototype.renderAreaChart = function renderAreaChart (chart) {
|
|
1466
1474
|
var this$1 = this;
|
|
1467
1475
|
|
|
1468
1476
|
this.waitForLoaded(chart, function () {
|
|
@@ -1472,14 +1480,14 @@
|
|
|
1472
1480
|
areaOpacity: 0.5
|
|
1473
1481
|
};
|
|
1474
1482
|
|
|
1475
|
-
var options = jsOptions
|
|
1483
|
+
var options = jsOptions(chart, chart.options, chartOptions);
|
|
1476
1484
|
var data = this$1.createDataTable(chart.data, chart.xtype);
|
|
1477
1485
|
|
|
1478
1486
|
this$1.drawChart(chart, "AreaChart", data, options);
|
|
1479
1487
|
});
|
|
1480
1488
|
};
|
|
1481
1489
|
|
|
1482
|
-
defaultExport
|
|
1490
|
+
defaultExport.prototype.renderGeoChart = function renderGeoChart (chart) {
|
|
1483
1491
|
var this$1 = this;
|
|
1484
1492
|
|
|
1485
1493
|
this.waitForLoaded(chart, "geochart", function () {
|
|
@@ -1489,7 +1497,7 @@
|
|
|
1489
1497
|
colors: chart.options.colors || ["#f6c7b6", "#ce502d"]
|
|
1490
1498
|
}
|
|
1491
1499
|
};
|
|
1492
|
-
var options = merge(merge(defaultOptions
|
|
1500
|
+
var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {});
|
|
1493
1501
|
|
|
1494
1502
|
var data = new this$1.library.visualization.DataTable();
|
|
1495
1503
|
data.addColumn("string", "");
|
|
@@ -1500,12 +1508,12 @@
|
|
|
1500
1508
|
});
|
|
1501
1509
|
};
|
|
1502
1510
|
|
|
1503
|
-
defaultExport
|
|
1511
|
+
defaultExport.prototype.renderScatterChart = function renderScatterChart (chart) {
|
|
1504
1512
|
var this$1 = this;
|
|
1505
1513
|
|
|
1506
1514
|
this.waitForLoaded(chart, function () {
|
|
1507
1515
|
var chartOptions = {};
|
|
1508
|
-
var options = jsOptions
|
|
1516
|
+
var options = jsOptions(chart, chart.options, chartOptions);
|
|
1509
1517
|
|
|
1510
1518
|
var series = chart.data, rows2 = [], i, j, data, d;
|
|
1511
1519
|
for (i = 0; i < series.length; i++) {
|
|
@@ -1530,7 +1538,7 @@
|
|
|
1530
1538
|
});
|
|
1531
1539
|
};
|
|
1532
1540
|
|
|
1533
|
-
defaultExport
|
|
1541
|
+
defaultExport.prototype.renderTimeline = function renderTimeline (chart) {
|
|
1534
1542
|
var this$1 = this;
|
|
1535
1543
|
|
|
1536
1544
|
this.waitForLoaded(chart, "timeline", function () {
|
|
@@ -1541,7 +1549,7 @@
|
|
|
1541
1549
|
if (chart.options.colors) {
|
|
1542
1550
|
chartOptions.colors = chart.options.colors;
|
|
1543
1551
|
}
|
|
1544
|
-
var options = merge(merge(defaultOptions
|
|
1552
|
+
var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {});
|
|
1545
1553
|
|
|
1546
1554
|
var data = new this$1.library.visualization.DataTable();
|
|
1547
1555
|
data.addColumn({type: "string", id: "Name"});
|
|
@@ -1555,14 +1563,16 @@
|
|
|
1555
1563
|
});
|
|
1556
1564
|
};
|
|
1557
1565
|
|
|
1558
|
-
|
|
1566
|
+
// TODO remove resize events
|
|
1567
|
+
defaultExport.prototype.destroy = function destroy (chart) {
|
|
1559
1568
|
if (chart.chart) {
|
|
1560
1569
|
chart.chart.clearChart();
|
|
1561
1570
|
}
|
|
1562
1571
|
};
|
|
1563
1572
|
|
|
1564
|
-
defaultExport
|
|
1573
|
+
defaultExport.prototype.drawChart = function drawChart (chart, type, data, options) {
|
|
1565
1574
|
this.destroy(chart);
|
|
1575
|
+
if (chart.destroyed) { return; }
|
|
1566
1576
|
|
|
1567
1577
|
if (chart.options.code) {
|
|
1568
1578
|
window.console.log("var data = new google.visualization.DataTable(" + data.toJSON() + ");\nvar chart = new google.visualization." + type + "(element);\nchart.draw(data, " + JSON.stringify(options) + ");");
|
|
@@ -1574,7 +1584,7 @@
|
|
|
1574
1584
|
});
|
|
1575
1585
|
};
|
|
1576
1586
|
|
|
1577
|
-
defaultExport
|
|
1587
|
+
defaultExport.prototype.waitForLoaded = function waitForLoaded (chart, pack, callback) {
|
|
1578
1588
|
var this$1 = this;
|
|
1579
1589
|
|
|
1580
1590
|
if (!callback) {
|
|
@@ -1606,7 +1616,7 @@
|
|
|
1606
1616
|
}
|
|
1607
1617
|
};
|
|
1608
1618
|
|
|
1609
|
-
defaultExport
|
|
1619
|
+
defaultExport.prototype.runCallbacks = function runCallbacks () {
|
|
1610
1620
|
var cb, call;
|
|
1611
1621
|
for (var i = 0; i < callbacks.length; i++) {
|
|
1612
1622
|
cb = callbacks[i];
|
|
@@ -1620,7 +1630,7 @@
|
|
|
1620
1630
|
};
|
|
1621
1631
|
|
|
1622
1632
|
// cant use object as key
|
|
1623
|
-
defaultExport
|
|
1633
|
+
defaultExport.prototype.createDataTable = function createDataTable (series, columnType) {
|
|
1624
1634
|
var i, j, s, d, key, rows = [], sortedLabels = [];
|
|
1625
1635
|
for (i = 0; i < series.length; i++) {
|
|
1626
1636
|
s = series[i];
|
|
@@ -1764,7 +1774,12 @@
|
|
|
1764
1774
|
}
|
|
1765
1775
|
}
|
|
1766
1776
|
|
|
1767
|
-
function fetchDataSource(chart, dataSource) {
|
|
1777
|
+
function fetchDataSource(chart, dataSource, showLoading) {
|
|
1778
|
+
// only show loading message for urls and callbacks
|
|
1779
|
+
if (showLoading && chart.options.loading && (typeof dataSource === "string" || typeof dataSource === "function")) {
|
|
1780
|
+
setText(chart.element, chart.options.loading);
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1768
1783
|
if (typeof dataSource === "string") {
|
|
1769
1784
|
pushRequest(dataSource, function (data) {
|
|
1770
1785
|
chart.rawData = data;
|
|
@@ -1874,9 +1889,9 @@
|
|
|
1874
1889
|
if (library.product === "Highcharts") {
|
|
1875
1890
|
return defaultExport$1;
|
|
1876
1891
|
} else if (library.charts) {
|
|
1877
|
-
return defaultExport$2;
|
|
1878
|
-
} else if (isFunction(library)) {
|
|
1879
1892
|
return defaultExport;
|
|
1893
|
+
} else if (isFunction(library)) {
|
|
1894
|
+
return defaultExport$2;
|
|
1880
1895
|
}
|
|
1881
1896
|
}
|
|
1882
1897
|
throw new Error("Unknown adapter");
|
|
@@ -1919,8 +1934,9 @@
|
|
|
1919
1934
|
}
|
|
1920
1935
|
|
|
1921
1936
|
function renderChart(chartType, chart) {
|
|
1922
|
-
if (
|
|
1923
|
-
|
|
1937
|
+
if (dataEmpty(chart.data, chartType)) {
|
|
1938
|
+
var message = chart.options.empty || (chart.options.messages && chart.options.messages.empty) || "No data";
|
|
1939
|
+
setText(chart.element, message);
|
|
1924
1940
|
} else {
|
|
1925
1941
|
callAdapter(chartType, chart);
|
|
1926
1942
|
if (chart.options.download && !chart.__downloadAttached && chart.adapter === "chartjs") {
|
|
@@ -2039,9 +2055,9 @@
|
|
|
2039
2055
|
// see if one series or multiple
|
|
2040
2056
|
if (!isArray(series) || typeof series[0] !== "object" || isArray(series[0])) {
|
|
2041
2057
|
series = [{name: opts.label, data: series}];
|
|
2042
|
-
chart.
|
|
2058
|
+
chart.singleSeriesFormat = true;
|
|
2043
2059
|
} else {
|
|
2044
|
-
chart.
|
|
2060
|
+
chart.singleSeriesFormat = false;
|
|
2045
2061
|
}
|
|
2046
2062
|
|
|
2047
2063
|
// convert to array
|
|
@@ -2086,7 +2102,7 @@
|
|
|
2086
2102
|
|
|
2087
2103
|
Chartkick.charts[element.id] = this;
|
|
2088
2104
|
|
|
2089
|
-
fetchDataSource(this, dataSource);
|
|
2105
|
+
fetchDataSource(this, dataSource, true);
|
|
2090
2106
|
|
|
2091
2107
|
if (this.options.refresh) {
|
|
2092
2108
|
this.startRefresh();
|
|
@@ -2122,7 +2138,7 @@
|
|
|
2122
2138
|
if (options) {
|
|
2123
2139
|
this.__updateOptions(options);
|
|
2124
2140
|
}
|
|
2125
|
-
fetchDataSource(this, dataSource);
|
|
2141
|
+
fetchDataSource(this, dataSource, true);
|
|
2126
2142
|
};
|
|
2127
2143
|
|
|
2128
2144
|
Chart.prototype.setOptions = function setOptions (options) {
|
|
@@ -2197,6 +2213,9 @@
|
|
|
2197
2213
|
};
|
|
2198
2214
|
|
|
2199
2215
|
Chart.prototype.destroy = function destroy () {
|
|
2216
|
+
this.destroyed = true;
|
|
2217
|
+
this.stopRefresh();
|
|
2218
|
+
|
|
2200
2219
|
if (this.__adapterObject) {
|
|
2201
2220
|
this.__adapterObject.destroy(this);
|
|
2202
2221
|
}
|
|
@@ -2441,6 +2460,14 @@
|
|
|
2441
2460
|
}
|
|
2442
2461
|
}
|
|
2443
2462
|
},
|
|
2463
|
+
destroyAll: function() {
|
|
2464
|
+
for (var chartId in Chartkick.charts) {
|
|
2465
|
+
if (Chartkick.charts.hasOwnProperty(chartId)) {
|
|
2466
|
+
Chartkick.charts[chartId].destroy();
|
|
2467
|
+
delete Chartkick.charts[chartId];
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
},
|
|
2444
2471
|
config: config,
|
|
2445
2472
|
options: {},
|
|
2446
2473
|
adapters: adapters,
|
|
@@ -2454,6 +2481,16 @@
|
|
|
2454
2481
|
// not ideal, but allows for simpler integration
|
|
2455
2482
|
if (typeof window !== "undefined" && !window.Chartkick) {
|
|
2456
2483
|
window.Chartkick = Chartkick;
|
|
2484
|
+
|
|
2485
|
+
// clean up previous charts before Turbolinks loads new page
|
|
2486
|
+
document.addEventListener("turbolinks:before-render", function() {
|
|
2487
|
+
Chartkick.destroyAll();
|
|
2488
|
+
});
|
|
2489
|
+
|
|
2490
|
+
// use setTimeout so charting library can come later in same JS file
|
|
2491
|
+
setTimeout(function() {
|
|
2492
|
+
window.dispatchEvent(new Event("chartkick:load"));
|
|
2493
|
+
}, 0);
|
|
2457
2494
|
}
|
|
2458
2495
|
|
|
2459
2496
|
// backwards compatibility for esm require
|