blazer 2.2.6 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of blazer might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/LICENSE.txt +1 -1
- data/README.md +105 -29
- data/app/assets/javascripts/blazer/Chart.js +13794 -12099
- data/app/assets/javascripts/blazer/Sortable.js +3695 -1526
- data/app/assets/javascripts/blazer/chartkick.js +296 -46
- data/app/assets/javascripts/blazer/daterangepicker.js +194 -269
- data/app/assets/javascripts/blazer/jquery.js +1150 -642
- data/app/assets/javascripts/blazer/moment-timezone-with-data.js +621 -287
- data/app/assets/javascripts/blazer/moment.js +5085 -2460
- data/app/assets/stylesheets/blazer/application.css +4 -0
- data/app/assets/stylesheets/blazer/daterangepicker.css +394 -253
- data/app/controllers/blazer/base_controller.rb +12 -4
- data/app/controllers/blazer/dashboards_controller.rb +7 -2
- data/app/controllers/blazer/queries_controller.rb +119 -3
- data/app/controllers/blazer/uploads_controller.rb +147 -0
- data/app/mailers/blazer/slack_notifier.rb +1 -1
- data/app/models/blazer/query.rb +8 -1
- data/app/models/blazer/upload.rb +11 -0
- data/app/models/blazer/uploads_connection.rb +7 -0
- data/app/views/blazer/_nav.html.erb +3 -0
- data/app/views/blazer/_variables.html.erb +3 -1
- data/app/views/blazer/checks/_form.html.erb +1 -1
- data/app/views/blazer/checks/index.html.erb +3 -0
- data/app/views/blazer/dashboards/_form.html.erb +1 -1
- data/app/views/blazer/dashboards/show.html.erb +1 -1
- data/app/views/blazer/queries/_caching.html.erb +16 -0
- data/app/views/blazer/queries/_cohorts.html.erb +48 -0
- data/app/views/blazer/queries/docs.html.erb +6 -0
- data/app/views/blazer/queries/home.html.erb +3 -0
- data/app/views/blazer/queries/run.html.erb +20 -22
- data/app/views/blazer/queries/show.html.erb +1 -1
- data/app/views/blazer/uploads/_form.html.erb +27 -0
- data/app/views/blazer/uploads/edit.html.erb +3 -0
- data/app/views/blazer/uploads/index.html.erb +55 -0
- data/app/views/blazer/uploads/new.html.erb +3 -0
- data/config/routes.rb +5 -0
- data/lib/blazer.rb +18 -0
- data/lib/blazer/adapters/base_adapter.rb +8 -0
- data/lib/blazer/adapters/sql_adapter.rb +42 -1
- data/lib/blazer/data_source.rb +1 -1
- data/lib/blazer/version.rb +1 -1
- data/lib/generators/blazer/templates/config.yml.tt +6 -0
- data/lib/generators/blazer/templates/install.rb.tt +3 -2
- data/lib/generators/blazer/templates/uploads.rb.tt +10 -0
- data/lib/generators/blazer/uploads_generator.rb +18 -0
- data/lib/tasks/blazer.rake +9 -0
- data/licenses/LICENSE-ace.txt +24 -0
- data/licenses/LICENSE-bootstrap.txt +21 -0
- data/licenses/LICENSE-chart.js.txt +9 -0
- data/licenses/LICENSE-chartkick.js.txt +22 -0
- data/licenses/LICENSE-daterangepicker.txt +21 -0
- data/licenses/LICENSE-fuzzysearch.txt +20 -0
- data/licenses/LICENSE-highlight.js.txt +29 -0
- data/licenses/LICENSE-jquery-ujs.txt +20 -0
- data/licenses/LICENSE-jquery.txt +20 -0
- data/licenses/LICENSE-moment-timezone.txt +20 -0
- data/licenses/LICENSE-moment.txt +22 -0
- data/licenses/LICENSE-selectize.txt +202 -0
- data/licenses/LICENSE-sortable.txt +21 -0
- data/licenses/LICENSE-stickytableheaders.txt +20 -0
- data/licenses/LICENSE-stupidtable.txt +19 -0
- data/licenses/LICENSE-vue.txt +21 -0
- metadata +34 -7
@@ -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
|
-
* v3.
|
5
|
+
* v3.2.1
|
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
|
-
|
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] = {};
|
@@ -237,7 +241,9 @@
|
|
237
241
|
return typeof obj === "number";
|
238
242
|
}
|
239
243
|
|
240
|
-
|
244
|
+
var byteSuffixes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB"];
|
245
|
+
|
246
|
+
function formatValue(pre, value, options, axis) {
|
241
247
|
pre = pre || "";
|
242
248
|
if (options.prefix) {
|
243
249
|
if (value < 0) {
|
@@ -247,6 +253,74 @@
|
|
247
253
|
pre += options.prefix;
|
248
254
|
}
|
249
255
|
|
256
|
+
var suffix = options.suffix || "";
|
257
|
+
var precision = options.precision;
|
258
|
+
var round = options.round;
|
259
|
+
|
260
|
+
if (options.byteScale) {
|
261
|
+
var suffixIdx;
|
262
|
+
var baseValue = axis ? options.byteScale : value;
|
263
|
+
|
264
|
+
if (baseValue >= 1152921504606846976) {
|
265
|
+
value /= 1152921504606846976;
|
266
|
+
suffixIdx = 6;
|
267
|
+
} else if (baseValue >= 1125899906842624) {
|
268
|
+
value /= 1125899906842624;
|
269
|
+
suffixIdx = 5;
|
270
|
+
} else if (baseValue >= 1099511627776) {
|
271
|
+
value /= 1099511627776;
|
272
|
+
suffixIdx = 4;
|
273
|
+
} else if (baseValue >= 1073741824) {
|
274
|
+
value /= 1073741824;
|
275
|
+
suffixIdx = 3;
|
276
|
+
} else if (baseValue >= 1048576) {
|
277
|
+
value /= 1048576;
|
278
|
+
suffixIdx = 2;
|
279
|
+
} else if (baseValue >= 1024) {
|
280
|
+
value /= 1024;
|
281
|
+
suffixIdx = 1;
|
282
|
+
} else {
|
283
|
+
suffixIdx = 0;
|
284
|
+
}
|
285
|
+
|
286
|
+
// TODO handle manual precision case
|
287
|
+
if (precision === undefined && round === undefined) {
|
288
|
+
if (value >= 1023.5) {
|
289
|
+
if (suffixIdx < byteSuffixes.length - 1) {
|
290
|
+
value = 1.0;
|
291
|
+
suffixIdx += 1;
|
292
|
+
}
|
293
|
+
}
|
294
|
+
precision = value >= 1000 ? 4 : 3;
|
295
|
+
}
|
296
|
+
suffix = " " + byteSuffixes[suffixIdx];
|
297
|
+
}
|
298
|
+
|
299
|
+
if (precision !== undefined && round !== undefined) {
|
300
|
+
throw Error("Use either round or precision, not both");
|
301
|
+
}
|
302
|
+
|
303
|
+
if (!axis) {
|
304
|
+
if (precision !== undefined) {
|
305
|
+
value = value.toPrecision(precision);
|
306
|
+
if (!options.zeros) {
|
307
|
+
value = parseFloat(value);
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
if (round !== undefined) {
|
312
|
+
if (round < 0) {
|
313
|
+
var num = Math.pow(10, -1 * round);
|
314
|
+
value = parseInt((1.0 * value / num).toFixed(0)) * num;
|
315
|
+
} else {
|
316
|
+
value = value.toFixed(round);
|
317
|
+
if (!options.zeros) {
|
318
|
+
value = parseFloat(value);
|
319
|
+
}
|
320
|
+
}
|
321
|
+
}
|
322
|
+
}
|
323
|
+
|
250
324
|
if (options.thousands || options.decimal) {
|
251
325
|
value = toStr(value);
|
252
326
|
var parts = value.split(".");
|
@@ -259,7 +333,16 @@
|
|
259
333
|
}
|
260
334
|
}
|
261
335
|
|
262
|
-
return pre + value +
|
336
|
+
return pre + value + suffix;
|
337
|
+
}
|
338
|
+
|
339
|
+
function seriesOption(chart, series, option) {
|
340
|
+
if (option in series) {
|
341
|
+
return series[option];
|
342
|
+
} else if (option in chart.options) {
|
343
|
+
return chart.options[option];
|
344
|
+
}
|
345
|
+
return null;
|
263
346
|
}
|
264
347
|
|
265
348
|
function allZeros(data) {
|
@@ -381,6 +464,12 @@
|
|
381
464
|
return result ? "rgba(" + parseInt(result[1], 16) + ", " + parseInt(result[2], 16) + ", " + parseInt(result[3], 16) + ", " + opacity + ")" : hex;
|
382
465
|
};
|
383
466
|
|
467
|
+
// check if not null or undefined
|
468
|
+
// https://stackoverflow.com/a/27757708/1177228
|
469
|
+
var notnull = function(x) {
|
470
|
+
return x != null;
|
471
|
+
};
|
472
|
+
|
384
473
|
var setLabelSize = function (chart, data, options) {
|
385
474
|
var maxLabelSize = Math.ceil(chart.element.offsetWidth / 4.0 / data.labels.length);
|
386
475
|
if (maxLabelSize > 25) {
|
@@ -405,18 +494,58 @@
|
|
405
494
|
prefix: chart.options.prefix,
|
406
495
|
suffix: chart.options.suffix,
|
407
496
|
thousands: chart.options.thousands,
|
408
|
-
decimal: chart.options.decimal
|
497
|
+
decimal: chart.options.decimal,
|
498
|
+
precision: chart.options.precision,
|
499
|
+
round: chart.options.round,
|
500
|
+
zeros: chart.options.zeros
|
409
501
|
};
|
410
502
|
|
503
|
+
if (chart.options.bytes) {
|
504
|
+
var series = chart.data;
|
505
|
+
if (chartType === "pie") {
|
506
|
+
series = [{data: series}];
|
507
|
+
}
|
508
|
+
|
509
|
+
// calculate max
|
510
|
+
var max = 0;
|
511
|
+
for (var i = 0; i < series.length; i++) {
|
512
|
+
var s = series[i];
|
513
|
+
for (var j = 0; j < s.data.length; j++) {
|
514
|
+
if (s.data[j][1] > max) {
|
515
|
+
max = s.data[j][1];
|
516
|
+
}
|
517
|
+
}
|
518
|
+
}
|
519
|
+
|
520
|
+
// calculate scale
|
521
|
+
var scale = 1;
|
522
|
+
while (max >= 1024) {
|
523
|
+
scale *= 1024;
|
524
|
+
max /= 1024;
|
525
|
+
}
|
526
|
+
|
527
|
+
// set step size
|
528
|
+
formatOptions.byteScale = scale;
|
529
|
+
}
|
530
|
+
|
411
531
|
if (chartType !== "pie") {
|
412
532
|
var myAxes = options.scales.yAxes;
|
413
533
|
if (chartType === "bar") {
|
414
534
|
myAxes = options.scales.xAxes;
|
415
535
|
}
|
416
536
|
|
537
|
+
if (formatOptions.byteScale) {
|
538
|
+
if (!myAxes[0].ticks.stepSize) {
|
539
|
+
myAxes[0].ticks.stepSize = formatOptions.byteScale / 2;
|
540
|
+
}
|
541
|
+
if (!myAxes[0].ticks.maxTicksLimit) {
|
542
|
+
myAxes[0].ticks.maxTicksLimit = 4;
|
543
|
+
}
|
544
|
+
}
|
545
|
+
|
417
546
|
if (!myAxes[0].ticks.callback) {
|
418
547
|
myAxes[0].ticks.callback = function (value) {
|
419
|
-
return formatValue("", value, formatOptions);
|
548
|
+
return formatValue("", value, formatOptions, true);
|
420
549
|
};
|
421
550
|
}
|
422
551
|
}
|
@@ -471,7 +600,7 @@
|
|
471
600
|
|
472
601
|
var jsOptions = jsOptionsFunc(merge(baseOptions, defaultOptions), hideLegend, setTitle, setMin, setMax, setStacked, setXtitle, setYtitle);
|
473
602
|
|
474
|
-
var createDataTable = function (chart, options, chartType) {
|
603
|
+
var createDataTable = function (chart, options, chartType, library) {
|
475
604
|
var datasets = [];
|
476
605
|
var labels = [];
|
477
606
|
|
@@ -594,11 +723,13 @@
|
|
594
723
|
dataset.stack = s.stack;
|
595
724
|
}
|
596
725
|
|
597
|
-
|
726
|
+
var curve = seriesOption(chart, s, "curve");
|
727
|
+
if (curve === false) {
|
598
728
|
dataset.lineTension = 0;
|
599
729
|
}
|
600
730
|
|
601
|
-
|
731
|
+
var points = seriesOption(chart, s, "points");
|
732
|
+
if (points === false) {
|
602
733
|
dataset.pointRadius = 0;
|
603
734
|
dataset.pointHitRadius = 5;
|
604
735
|
}
|
@@ -610,9 +741,49 @@
|
|
610
741
|
datasets.push(dataset);
|
611
742
|
}
|
612
743
|
|
744
|
+
var xmin = chart.options.xmin;
|
745
|
+
var xmax = chart.options.xmax;
|
746
|
+
|
747
|
+
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
|
+
if (notnull(xmin)) {
|
753
|
+
options.scales.xAxes[0][ticksKey].min = toDate(xmin).getTime();
|
754
|
+
}
|
755
|
+
if (notnull(xmax)) {
|
756
|
+
options.scales.xAxes[0][ticksKey].max = toDate(xmax).getTime();
|
757
|
+
}
|
758
|
+
} else if (chart.xtype === "number") {
|
759
|
+
if (notnull(xmin)) {
|
760
|
+
options.scales.xAxes[0].ticks.min = xmin;
|
761
|
+
}
|
762
|
+
if (notnull(xmax)) {
|
763
|
+
options.scales.xAxes[0].ticks.max = xmax;
|
764
|
+
}
|
765
|
+
}
|
766
|
+
|
767
|
+
// for empty datetime chart
|
768
|
+
if (chart.xtype === "datetime" && labels.length === 0) {
|
769
|
+
if (notnull(xmin)) {
|
770
|
+
labels.push(toDate(xmin));
|
771
|
+
}
|
772
|
+
if (notnull(xmax)) {
|
773
|
+
labels.push(toDate(xmax));
|
774
|
+
}
|
775
|
+
day = false;
|
776
|
+
week = false;
|
777
|
+
month = false;
|
778
|
+
year = false;
|
779
|
+
hour = false;
|
780
|
+
minute = false;
|
781
|
+
}
|
782
|
+
|
613
783
|
if (chart.xtype === "datetime" && labels.length > 0) {
|
614
|
-
var minTime = labels[0].getTime();
|
615
|
-
var maxTime = labels[0].getTime();
|
784
|
+
var minTime = (notnull(xmin) ? toDate(xmin) : labels[0]).getTime();
|
785
|
+
var maxTime = (notnull(xmax) ? toDate(xmax) : labels[0]).getTime();
|
786
|
+
|
616
787
|
for (i = 1; i < labels.length; i++) {
|
617
788
|
var value$1 = labels[i].getTime();
|
618
789
|
if (value$1 < minTime) {
|
@@ -689,7 +860,7 @@
|
|
689
860
|
var options = jsOptions(chart, merge(chartOptions, chart.options));
|
690
861
|
setFormatOptions(chart, options, chartType);
|
691
862
|
|
692
|
-
var data = createDataTable(chart, options, chartType || "line");
|
863
|
+
var data = createDataTable(chart, options, chartType || "line", this.library);
|
693
864
|
|
694
865
|
if (chart.xtype === "number") {
|
695
866
|
options.scales.xAxes[0].type = "linear";
|
@@ -743,12 +914,14 @@
|
|
743
914
|
defaultExport.prototype.renderColumnChart = function renderColumnChart (chart, chartType) {
|
744
915
|
var options;
|
745
916
|
if (chartType === "bar") {
|
746
|
-
|
917
|
+
var barOptions = merge(baseOptions, defaultOptions);
|
918
|
+
delete barOptions.scales.yAxes[0].ticks.maxTicksLimit;
|
919
|
+
options = jsOptionsFunc(barOptions, hideLegend, setTitle, setBarMin, setBarMax, setStacked, setXtitle, setYtitle)(chart, chart.options);
|
747
920
|
} else {
|
748
921
|
options = jsOptions(chart, chart.options);
|
749
922
|
}
|
750
923
|
setFormatOptions(chart, options, chartType);
|
751
|
-
var data = createDataTable(chart, options, "column");
|
924
|
+
var data = createDataTable(chart, options, "column", this.library);
|
752
925
|
if (chartType !== "bar") {
|
753
926
|
setLabelSize(chart, data, options);
|
754
927
|
}
|
@@ -773,7 +946,7 @@
|
|
773
946
|
options.showLines = false;
|
774
947
|
}
|
775
948
|
|
776
|
-
var data = createDataTable(chart, options, chartType);
|
949
|
+
var data = createDataTable(chart, options, chartType, this.library);
|
777
950
|
|
778
951
|
options.scales.xAxes[0].type = "linear";
|
779
952
|
options.scales.xAxes[0].position = "bottom";
|
@@ -847,6 +1020,7 @@
|
|
847
1020
|
},
|
848
1021
|
plotOptions: {
|
849
1022
|
areaspline: {},
|
1023
|
+
area: {},
|
850
1024
|
series: {
|
851
1025
|
marker: {}
|
852
1026
|
}
|
@@ -883,7 +1057,10 @@
|
|
883
1057
|
};
|
884
1058
|
|
885
1059
|
var setStacked$1 = function (options, stacked) {
|
886
|
-
|
1060
|
+
var stackedValue = stacked ? (stacked === true ? "normal" : stacked) : null;
|
1061
|
+
options.plotOptions.series.stacking = stackedValue;
|
1062
|
+
options.plotOptions.area.stacking = stackedValue;
|
1063
|
+
options.plotOptions.areaspline.stacking = stackedValue;
|
887
1064
|
};
|
888
1065
|
|
889
1066
|
var setXtitle$1 = function (options, title) {
|
@@ -901,7 +1078,10 @@
|
|
901
1078
|
prefix: chart.options.prefix,
|
902
1079
|
suffix: chart.options.suffix,
|
903
1080
|
thousands: chart.options.thousands,
|
904
|
-
decimal: chart.options.decimal
|
1081
|
+
decimal: chart.options.decimal,
|
1082
|
+
precision: chart.options.precision,
|
1083
|
+
round: chart.options.round,
|
1084
|
+
zeros: chart.options.zeros
|
905
1085
|
};
|
906
1086
|
|
907
1087
|
if (chartType !== "pie" && !options.yAxis.labels.formatter) {
|
@@ -912,7 +1092,7 @@
|
|
912
1092
|
|
913
1093
|
if (!options.tooltip.pointFormatter) {
|
914
1094
|
options.tooltip.pointFormatter = function () {
|
915
|
-
return '<span style="color:' + this.color + '>\u25CF</span> ' + formatValue(this.series.name + ': <b>', this.y, formatOptions) + '</b><br/>';
|
1095
|
+
return '<span style="color:' + this.color + '">\u25CF</span> ' + formatValue(this.series.name + ': <b>', this.y, formatOptions) + '</b><br/>';
|
916
1096
|
};
|
917
1097
|
}
|
918
1098
|
};
|
@@ -1302,7 +1482,7 @@
|
|
1302
1482
|
defaultExport$2.prototype.renderGeoChart = function renderGeoChart (chart) {
|
1303
1483
|
var this$1 = this;
|
1304
1484
|
|
1305
|
-
this.waitForLoaded(chart, function () {
|
1485
|
+
this.waitForLoaded(chart, "geochart", function () {
|
1306
1486
|
var chartOptions = {
|
1307
1487
|
legend: "none",
|
1308
1488
|
colorAxis: {
|
@@ -1418,7 +1598,7 @@
|
|
1418
1598
|
if (config.language) {
|
1419
1599
|
loadOptions.language = config.language;
|
1420
1600
|
}
|
1421
|
-
if (pack === "
|
1601
|
+
if (pack === "geochart" && config.mapsApiKey) {
|
1422
1602
|
loadOptions.mapsApiKey = config.mapsApiKey;
|
1423
1603
|
}
|
1424
1604
|
|
@@ -1427,12 +1607,10 @@
|
|
1427
1607
|
};
|
1428
1608
|
|
1429
1609
|
defaultExport$2.prototype.runCallbacks = function runCallbacks () {
|
1430
|
-
var this$1 = this;
|
1431
|
-
|
1432
1610
|
var cb, call;
|
1433
1611
|
for (var i = 0; i < callbacks.length; i++) {
|
1434
1612
|
cb = callbacks[i];
|
1435
|
-
call = this
|
1613
|
+
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));
|
1436
1614
|
if (call) {
|
1437
1615
|
cb.callback();
|
1438
1616
|
callbacks.splice(i, 1);
|
@@ -1531,7 +1709,7 @@
|
|
1531
1709
|
function ajaxCall(url, success, error) {
|
1532
1710
|
var $ = window.jQuery || window.Zepto || window.$;
|
1533
1711
|
|
1534
|
-
if ($) {
|
1712
|
+
if ($ && $.ajax) {
|
1535
1713
|
$.ajax({
|
1536
1714
|
dataType: "json",
|
1537
1715
|
url: url,
|
@@ -1568,8 +1746,12 @@
|
|
1568
1746
|
}
|
1569
1747
|
}
|
1570
1748
|
|
1571
|
-
|
1572
|
-
|
1749
|
+
// TODO remove prefix for all messages
|
1750
|
+
function chartError(element, message, noPrefix) {
|
1751
|
+
if (!noPrefix) {
|
1752
|
+
message = "Error Loading Chart: " + message;
|
1753
|
+
}
|
1754
|
+
setText(element, message);
|
1573
1755
|
element.style.color = "#ff0000";
|
1574
1756
|
}
|
1575
1757
|
|
@@ -1590,6 +1772,17 @@
|
|
1590
1772
|
}, function (message) {
|
1591
1773
|
chartError(chart.element, message);
|
1592
1774
|
});
|
1775
|
+
} else if (typeof dataSource === "function") {
|
1776
|
+
try {
|
1777
|
+
dataSource(function (data) {
|
1778
|
+
chart.rawData = data;
|
1779
|
+
errorCatcher(chart);
|
1780
|
+
}, function (message) {
|
1781
|
+
chartError(chart.element, message, true);
|
1782
|
+
});
|
1783
|
+
} catch (err) {
|
1784
|
+
chartError(chart.element, err, true);
|
1785
|
+
}
|
1593
1786
|
} else {
|
1594
1787
|
chart.rawData = dataSource;
|
1595
1788
|
errorCatcher(chart);
|
@@ -1599,7 +1792,15 @@
|
|
1599
1792
|
function addDownloadButton(chart) {
|
1600
1793
|
var element = chart.element;
|
1601
1794
|
var link = document.createElement("a");
|
1602
|
-
|
1795
|
+
|
1796
|
+
var download = chart.options.download;
|
1797
|
+
if (download === true) {
|
1798
|
+
download = {};
|
1799
|
+
} else if (typeof download === "string") {
|
1800
|
+
download = {filename: download};
|
1801
|
+
}
|
1802
|
+
link.download = download.filename || "chart.png"; // https://caniuse.com/download
|
1803
|
+
|
1603
1804
|
link.style.position = "absolute";
|
1604
1805
|
link.style.top = "20px";
|
1605
1806
|
link.style.right = "20px";
|
@@ -1622,7 +1823,7 @@
|
|
1622
1823
|
var related = e.relatedTarget;
|
1623
1824
|
// check download option again to ensure it wasn't changed
|
1624
1825
|
if ((!related || (related !== this && !childOf(this, related))) && chart.options.download) {
|
1625
|
-
link.href = chart.toImage();
|
1826
|
+
link.href = chart.toImage(download);
|
1626
1827
|
element.appendChild(link);
|
1627
1828
|
}
|
1628
1829
|
});
|
@@ -1784,8 +1985,14 @@
|
|
1784
1985
|
return r;
|
1785
1986
|
};
|
1786
1987
|
|
1787
|
-
function detectXType(series, noDatetime) {
|
1788
|
-
if (
|
1988
|
+
function detectXType(series, noDatetime, options) {
|
1989
|
+
if (dataEmpty(series)) {
|
1990
|
+
if ((options.xmin || options.xmax) && (!options.xmin || isDate(options.xmin)) && (!options.xmax || isDate(options.xmax))) {
|
1991
|
+
return "datetime";
|
1992
|
+
} else {
|
1993
|
+
return "number";
|
1994
|
+
}
|
1995
|
+
} else if (detectXTypeWithFunction(series, isNumber)) {
|
1789
1996
|
return "number";
|
1790
1997
|
} else if (!noDatetime && detectXTypeWithFunction(series, isDate)) {
|
1791
1998
|
return "datetime";
|
@@ -1837,12 +2044,18 @@
|
|
1837
2044
|
chart.hideLegend = false;
|
1838
2045
|
}
|
1839
2046
|
|
1840
|
-
|
2047
|
+
// convert to array
|
2048
|
+
// must come before dataEmpty check
|
2049
|
+
series = copySeries(series);
|
2050
|
+
for (i = 0; i < series.length; i++) {
|
2051
|
+
series[i].data = toArr(series[i].data);
|
2052
|
+
}
|
2053
|
+
|
2054
|
+
chart.xtype = keyType ? keyType : (opts.discrete ? "string" : detectXType(series, noDatetime, opts));
|
1841
2055
|
|
1842
2056
|
// right format
|
1843
|
-
series = copySeries(series);
|
1844
2057
|
for (i = 0; i < series.length; i++) {
|
1845
|
-
series[i].data = formatSeriesData(
|
2058
|
+
series[i].data = formatSeriesData(series[i].data, chart.xtype);
|
1846
2059
|
}
|
1847
2060
|
|
1848
2061
|
return series;
|
@@ -1927,6 +2140,8 @@
|
|
1927
2140
|
var sep = this.dataSource.indexOf("?") === -1 ? "?" : "&";
|
1928
2141
|
var url = this.dataSource + sep + "_=" + (new Date()).getTime();
|
1929
2142
|
fetchDataSource(this, url);
|
2143
|
+
} else if (typeof this.dataSource === "function") {
|
2144
|
+
fetchDataSource(this, this.dataSource);
|
1930
2145
|
}
|
1931
2146
|
};
|
1932
2147
|
|
@@ -1935,6 +2150,10 @@
|
|
1935
2150
|
|
1936
2151
|
var refresh = this.options.refresh;
|
1937
2152
|
|
2153
|
+
if (refresh && typeof this.dataSource !== "string" && typeof this.dataSource !== "function") {
|
2154
|
+
throw new Error("Data source must be a URL or callback for refresh");
|
2155
|
+
}
|
2156
|
+
|
1938
2157
|
if (!this.intervalId) {
|
1939
2158
|
if (refresh) {
|
1940
2159
|
this.intervalId = setInterval( function () {
|
@@ -1953,10 +2172,26 @@
|
|
1953
2172
|
}
|
1954
2173
|
};
|
1955
2174
|
|
1956
|
-
Chart.prototype.toImage = function toImage () {
|
2175
|
+
Chart.prototype.toImage = function toImage (download) {
|
1957
2176
|
if (this.adapter === "chartjs") {
|
1958
|
-
|
2177
|
+
if (download && download.background && download.background !== "transparent") {
|
2178
|
+
// https://stackoverflow.com/questions/30464750/chartjs-line-chart-set-background-color
|
2179
|
+
var canvas = this.chart.chart.canvas;
|
2180
|
+
var ctx = this.chart.chart.ctx;
|
2181
|
+
var tmpCanvas = document.createElement("canvas");
|
2182
|
+
var tmpCtx = tmpCanvas.getContext("2d");
|
2183
|
+
tmpCanvas.width = ctx.canvas.width;
|
2184
|
+
tmpCanvas.height = ctx.canvas.height;
|
2185
|
+
tmpCtx.fillStyle = download.background;
|
2186
|
+
tmpCtx.fillRect(0, 0, tmpCanvas.width, tmpCanvas.height);
|
2187
|
+
tmpCtx.drawImage(canvas, 0, 0);
|
2188
|
+
return tmpCanvas.toDataURL("image/png");
|
2189
|
+
} else {
|
2190
|
+
return this.chart.toBase64Image();
|
2191
|
+
}
|
1959
2192
|
} else {
|
2193
|
+
// TODO throw error in next major version
|
2194
|
+
// throw new Error("Feature only available for Chart.js");
|
1960
2195
|
return null;
|
1961
2196
|
}
|
1962
2197
|
};
|
@@ -1993,7 +2228,7 @@
|
|
1993
2228
|
return config;
|
1994
2229
|
};
|
1995
2230
|
|
1996
|
-
var LineChart = (function (Chart) {
|
2231
|
+
var LineChart = /*@__PURE__*/(function (Chart) {
|
1997
2232
|
function LineChart () {
|
1998
2233
|
Chart.apply(this, arguments);
|
1999
2234
|
}
|
@@ -2013,7 +2248,7 @@
|
|
2013
2248
|
return LineChart;
|
2014
2249
|
}(Chart));
|
2015
2250
|
|
2016
|
-
var PieChart = (function (Chart) {
|
2251
|
+
var PieChart = /*@__PURE__*/(function (Chart) {
|
2017
2252
|
function PieChart () {
|
2018
2253
|
Chart.apply(this, arguments);
|
2019
2254
|
}
|
@@ -2033,7 +2268,7 @@
|
|
2033
2268
|
return PieChart;
|
2034
2269
|
}(Chart));
|
2035
2270
|
|
2036
|
-
var ColumnChart = (function (Chart) {
|
2271
|
+
var ColumnChart = /*@__PURE__*/(function (Chart) {
|
2037
2272
|
function ColumnChart () {
|
2038
2273
|
Chart.apply(this, arguments);
|
2039
2274
|
}
|
@@ -2053,7 +2288,7 @@
|
|
2053
2288
|
return ColumnChart;
|
2054
2289
|
}(Chart));
|
2055
2290
|
|
2056
|
-
var BarChart = (function (Chart) {
|
2291
|
+
var BarChart = /*@__PURE__*/(function (Chart) {
|
2057
2292
|
function BarChart () {
|
2058
2293
|
Chart.apply(this, arguments);
|
2059
2294
|
}
|
@@ -2073,7 +2308,7 @@
|
|
2073
2308
|
return BarChart;
|
2074
2309
|
}(Chart));
|
2075
2310
|
|
2076
|
-
var AreaChart = (function (Chart) {
|
2311
|
+
var AreaChart = /*@__PURE__*/(function (Chart) {
|
2077
2312
|
function AreaChart () {
|
2078
2313
|
Chart.apply(this, arguments);
|
2079
2314
|
}
|
@@ -2093,7 +2328,7 @@
|
|
2093
2328
|
return AreaChart;
|
2094
2329
|
}(Chart));
|
2095
2330
|
|
2096
|
-
var GeoChart = (function (Chart) {
|
2331
|
+
var GeoChart = /*@__PURE__*/(function (Chart) {
|
2097
2332
|
function GeoChart () {
|
2098
2333
|
Chart.apply(this, arguments);
|
2099
2334
|
}
|
@@ -2113,7 +2348,7 @@
|
|
2113
2348
|
return GeoChart;
|
2114
2349
|
}(Chart));
|
2115
2350
|
|
2116
|
-
var ScatterChart = (function (Chart) {
|
2351
|
+
var ScatterChart = /*@__PURE__*/(function (Chart) {
|
2117
2352
|
function ScatterChart () {
|
2118
2353
|
Chart.apply(this, arguments);
|
2119
2354
|
}
|
@@ -2133,7 +2368,7 @@
|
|
2133
2368
|
return ScatterChart;
|
2134
2369
|
}(Chart));
|
2135
2370
|
|
2136
|
-
var BubbleChart = (function (Chart) {
|
2371
|
+
var BubbleChart = /*@__PURE__*/(function (Chart) {
|
2137
2372
|
function BubbleChart () {
|
2138
2373
|
Chart.apply(this, arguments);
|
2139
2374
|
}
|
@@ -2153,7 +2388,7 @@
|
|
2153
2388
|
return BubbleChart;
|
2154
2389
|
}(Chart));
|
2155
2390
|
|
2156
|
-
var Timeline = (function (Chart) {
|
2391
|
+
var Timeline = /*@__PURE__*/(function (Chart) {
|
2157
2392
|
function Timeline () {
|
2158
2393
|
Chart.apply(this, arguments);
|
2159
2394
|
}
|
@@ -2196,6 +2431,9 @@
|
|
2196
2431
|
}
|
2197
2432
|
}
|
2198
2433
|
},
|
2434
|
+
setDefaultOptions: function (opts) {
|
2435
|
+
Chartkick.options = opts;
|
2436
|
+
},
|
2199
2437
|
eachChart: function (callback) {
|
2200
2438
|
for (var chartId in Chartkick.charts) {
|
2201
2439
|
if (Chartkick.charts.hasOwnProperty(chartId)) {
|
@@ -2206,9 +2444,21 @@
|
|
2206
2444
|
config: config,
|
2207
2445
|
options: {},
|
2208
2446
|
adapters: adapters,
|
2209
|
-
addAdapter: addAdapter
|
2447
|
+
addAdapter: addAdapter,
|
2448
|
+
use: function(adapter) {
|
2449
|
+
addAdapter(adapter);
|
2450
|
+
return Chartkick;
|
2451
|
+
}
|
2210
2452
|
};
|
2211
2453
|
|
2454
|
+
// not ideal, but allows for simpler integration
|
2455
|
+
if (typeof window !== "undefined" && !window.Chartkick) {
|
2456
|
+
window.Chartkick = Chartkick;
|
2457
|
+
}
|
2458
|
+
|
2459
|
+
// backwards compatibility for esm require
|
2460
|
+
Chartkick.default = Chartkick;
|
2461
|
+
|
2212
2462
|
return Chartkick;
|
2213
2463
|
|
2214
2464
|
})));
|