chartkick 2.3.2 → 2.3.3

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