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