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