chartkick 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chartkick might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +25 -12
- data/app/assets/javascripts/chartkick.js +156 -147
- data/lib/chartkick/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea705341b63c82aef63f8da9e1f98d8caad46097
|
4
|
+
data.tar.gz: 955115a1463d433fa2c14d70541ff7ac9f62c3eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48540e759da663290d91093ce58ef3e59258682f441401c1cde301057b83f8bcefda8a62a9d76ea8efbf4661eb9998c6d4463f8b4d239de75fd720d9a41d3f57
|
7
|
+
data.tar.gz: 845ca4aee7e2262a14dd46dfb73d5b975955f7bf86fd19de7f7407ea3889b9829789752b16441f9fb24b5b9e041650c8aca5821b172cc69034fb7b61ef8b1317
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Create beautiful Javascript charts with one line of Ruby. No more fighting with
|
|
6
6
|
|
7
7
|
Works with Rails, Sinatra and most browsers (including IE 6)
|
8
8
|
|
9
|
-
:two_hearts: A perfect companion to [groupdate](
|
9
|
+
:two_hearts: A perfect companion to [groupdate](https://github.com/ankane/groupdate) and [active_median](https://github.com/ankane/active_median)
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
@@ -31,13 +31,13 @@ Column chart
|
|
31
31
|
Bar chart
|
32
32
|
|
33
33
|
```erb
|
34
|
-
<%=
|
34
|
+
<%= bar_chart Shirt.group("size").sum(:price) %>
|
35
35
|
```
|
36
36
|
|
37
37
|
Area chart
|
38
38
|
|
39
39
|
```erb
|
40
|
-
<%= area_chart Visit.group_by_minute(:created_at).
|
40
|
+
<%= area_chart Visit.group_by_minute(:created_at).maximum(:load_time) %>
|
41
41
|
```
|
42
42
|
|
43
43
|
Multiple series (except pie chart)
|
@@ -73,25 +73,25 @@ end
|
|
73
73
|
Id and height
|
74
74
|
|
75
75
|
```erb
|
76
|
-
<%= line_chart
|
76
|
+
<%= line_chart data, :id => "users-chart", :height => "500px" %>
|
77
77
|
```
|
78
78
|
|
79
79
|
Min and max values (except pie chart)
|
80
80
|
|
81
81
|
```erb
|
82
|
-
<%= line_chart
|
82
|
+
<%= line_chart data, :min => 1000, :max => 5000 %>
|
83
83
|
```
|
84
84
|
|
85
85
|
You can pass options directly to the charting library with:
|
86
86
|
|
87
87
|
```erb
|
88
|
-
<%= line_chart
|
88
|
+
<%= line_chart data, :library => {:backgroundColor => "#eee"} %>
|
89
89
|
```
|
90
90
|
|
91
91
|
You can also pass a content_for option, which will put the javascript in a content block. This is great for including all of your javascript at the bottom of the page.
|
92
92
|
|
93
93
|
```erb
|
94
|
-
<%= line_chart
|
94
|
+
<%= line_chart data, :content_for => :js_initialization %>
|
95
95
|
```
|
96
96
|
Then, in your layout:
|
97
97
|
|
@@ -173,6 +173,18 @@ In addition, you must specify `http` or `https` if you use Google Charts, since
|
|
173
173
|
<%= javascript_include_tag "https://www.google.com/jsapi", "chartkick" %>
|
174
174
|
```
|
175
175
|
|
176
|
+
### Localization
|
177
|
+
|
178
|
+
To specify a language for Google Charts, add:
|
179
|
+
|
180
|
+
```html
|
181
|
+
<script>
|
182
|
+
var Chartkick = {"language": "de"};
|
183
|
+
</script>
|
184
|
+
```
|
185
|
+
|
186
|
+
**before** the javascript files.
|
187
|
+
|
176
188
|
## No Ruby? No Problem
|
177
189
|
|
178
190
|
Check out [chartkick.js](https://github.com/ankane/chartkick.js)
|
@@ -189,8 +201,9 @@ Chartkick follows [Semantic Versioning](http://semver.org/)
|
|
189
201
|
|
190
202
|
## Contributing
|
191
203
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
204
|
+
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
205
|
+
|
206
|
+
- [Report bugs](https://github.com/ankane/chartkick/issues)
|
207
|
+
- Fix bugs and [submit pull requests](https://github.com/ankane/chartkick/pulls)
|
208
|
+
- Write, clarify, or fix documentation
|
209
|
+
- Suggest or add new features
|
@@ -2,24 +2,34 @@
|
|
2
2
|
* Chartkick.js
|
3
3
|
* Create beautiful Javascript charts with minimal code
|
4
4
|
* https://github.com/ankane/chartkick.js
|
5
|
-
* v1.1.
|
5
|
+
* v1.1.1
|
6
6
|
* MIT License
|
7
7
|
*/
|
8
8
|
|
9
|
-
/*jslint browser: true, indent: 2, plusplus: true */
|
10
|
-
/*global google, $*/
|
9
|
+
/*jslint browser: true, indent: 2, plusplus: true, vars: true */
|
10
|
+
/*global google, Highcharts, $*/
|
11
11
|
|
12
|
-
(function() {
|
12
|
+
(function () {
|
13
13
|
'use strict';
|
14
14
|
|
15
|
+
var Chartkick, ISO8601_PATTERN, DECIMAL_SEPARATOR, defaultOptions, hideLegend,
|
16
|
+
setMin, setMax, jsOptions, loaded, waitForLoaded, setBarMin, setBarMax, createDataTable, resize;
|
17
|
+
|
18
|
+
// only functions that need defined specific to charting library
|
19
|
+
var renderLineChart, renderPieChart, renderColumnChart, renderBarChart, renderAreaChart;
|
20
|
+
|
15
21
|
// helpers
|
16
22
|
|
17
23
|
function isArray(variable) {
|
18
24
|
return Object.prototype.toString.call(variable) === "[object Array]";
|
19
25
|
}
|
20
26
|
|
27
|
+
function isFunction(variable) {
|
28
|
+
return variable instanceof Function;
|
29
|
+
}
|
30
|
+
|
21
31
|
function isPlainObject(variable) {
|
22
|
-
return variable instanceof Object;
|
32
|
+
return !isFunction(variable) && variable instanceof Object;
|
23
33
|
}
|
24
34
|
|
25
35
|
// https://github.com/madrobby/zepto/blob/master/src/zepto.js
|
@@ -34,8 +44,7 @@
|
|
34
44
|
target[key] = [];
|
35
45
|
}
|
36
46
|
extend(target[key], source[key]);
|
37
|
-
}
|
38
|
-
else if (source[key] !== undefined) {
|
47
|
+
} else if (source[key] !== undefined) {
|
39
48
|
target[key] = source[key];
|
40
49
|
}
|
41
50
|
}
|
@@ -49,8 +58,8 @@
|
|
49
58
|
}
|
50
59
|
|
51
60
|
// https://github.com/Do/iso8601.js
|
52
|
-
|
53
|
-
|
61
|
+
ISO8601_PATTERN = /(\d\d\d\d)(\-)?(\d\d)(\-)?(\d\d)(T)?(\d\d)(:)?(\d\d)?(:)?(\d\d)?([\.,]\d+)?($|Z|([\+\-])(\d\d)(:)?(\d\d)?)/i;
|
62
|
+
DECIMAL_SEPARATOR = String(1.5).charAt(1);
|
54
63
|
|
55
64
|
function parseISO8601(input) {
|
56
65
|
var day, hour, matches, milliseconds, minutes, month, offset, result, seconds, type, year;
|
@@ -97,7 +106,7 @@
|
|
97
106
|
}
|
98
107
|
|
99
108
|
function jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax) {
|
100
|
-
return function(series, opts, chartOptions) {
|
109
|
+
return function (series, opts, chartOptions) {
|
101
110
|
var options = merge({}, defaultOptions);
|
102
111
|
options = merge(options, chartOptions || {});
|
103
112
|
|
@@ -110,8 +119,7 @@
|
|
110
119
|
// min
|
111
120
|
if ("min" in opts) {
|
112
121
|
setMin(options, opts.min);
|
113
|
-
}
|
114
|
-
else if (!negativeValues(series)) {
|
122
|
+
} else if (!negativeValues(series)) {
|
115
123
|
setMin(options, 0);
|
116
124
|
}
|
117
125
|
|
@@ -127,12 +135,94 @@
|
|
127
135
|
};
|
128
136
|
}
|
129
137
|
|
130
|
-
|
131
|
-
|
138
|
+
function setText(element, text) {
|
139
|
+
if (document.body.innerText) {
|
140
|
+
element.innerText = text;
|
141
|
+
} else {
|
142
|
+
element.textContent = text;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
function chartError(element, message) {
|
147
|
+
setText(element, "Error Loading Chart: " + message);
|
148
|
+
element.style.color = "#ff0000";
|
149
|
+
}
|
150
|
+
|
151
|
+
function getJSON(element, url, success) {
|
152
|
+
$.ajax({
|
153
|
+
dataType: "json",
|
154
|
+
url: url,
|
155
|
+
success: success,
|
156
|
+
error: function (jqXHR, textStatus, errorThrown) {
|
157
|
+
var message = (typeof errorThrown === "string") ? errorThrown : errorThrown.message;
|
158
|
+
chartError(element, message);
|
159
|
+
}
|
160
|
+
});
|
161
|
+
}
|
162
|
+
|
163
|
+
function errorCatcher(element, data, opts, callback) {
|
164
|
+
try {
|
165
|
+
callback(element, data, opts);
|
166
|
+
} catch (err) {
|
167
|
+
chartError(element, err.message);
|
168
|
+
throw err;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
function fetchDataSource(element, dataSource, opts, callback) {
|
173
|
+
if (typeof dataSource === "string") {
|
174
|
+
getJSON(element, dataSource, function (data, textStatus, jqXHR) {
|
175
|
+
errorCatcher(element, data, opts, callback);
|
176
|
+
});
|
177
|
+
} else {
|
178
|
+
errorCatcher(element, dataSource, opts, callback);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
// type conversions
|
183
|
+
|
184
|
+
function toStr(n) {
|
185
|
+
return "" + n;
|
186
|
+
}
|
187
|
+
|
188
|
+
function toFloat(n) {
|
189
|
+
return parseFloat(n);
|
190
|
+
}
|
191
|
+
|
192
|
+
function toDate(n) {
|
193
|
+
if (typeof n !== "object") {
|
194
|
+
if (typeof n === "number") {
|
195
|
+
n = new Date(n * 1000); // ms
|
196
|
+
} else { // str
|
197
|
+
// try our best to get the str into iso8601
|
198
|
+
// TODO be smarter about this
|
199
|
+
var str = n.replace(/ /, "T").replace(" ", "").replace("UTC", "Z");
|
200
|
+
n = parseISO8601(str) || new Date(n);
|
201
|
+
}
|
202
|
+
}
|
203
|
+
return n;
|
204
|
+
}
|
205
|
+
|
206
|
+
function toArr(n) {
|
207
|
+
if (!isArray(n)) {
|
208
|
+
var arr = [], i;
|
209
|
+
for (i in n) {
|
210
|
+
if (n.hasOwnProperty(i)) {
|
211
|
+
arr.push([i, n[i]]);
|
212
|
+
}
|
213
|
+
}
|
214
|
+
n = arr;
|
215
|
+
}
|
216
|
+
return n;
|
217
|
+
}
|
218
|
+
|
219
|
+
function sortByTime(a, b) {
|
220
|
+
return a[0].getTime() - b[0].getTime();
|
221
|
+
}
|
132
222
|
|
133
223
|
if ("Highcharts" in window) {
|
134
224
|
|
135
|
-
|
225
|
+
defaultOptions = {
|
136
226
|
chart: {},
|
137
227
|
xAxis: {
|
138
228
|
labels: {
|
@@ -173,21 +263,21 @@
|
|
173
263
|
}
|
174
264
|
};
|
175
265
|
|
176
|
-
|
266
|
+
hideLegend = function (options) {
|
177
267
|
options.legend.enabled = false;
|
178
268
|
};
|
179
269
|
|
180
|
-
|
270
|
+
setMin = function (options, min) {
|
181
271
|
options.yAxis.min = min;
|
182
272
|
};
|
183
273
|
|
184
|
-
|
274
|
+
setMax = function (options, max) {
|
185
275
|
options.yAxis.max = max;
|
186
276
|
};
|
187
277
|
|
188
|
-
|
278
|
+
jsOptions = jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax);
|
189
279
|
|
190
|
-
renderLineChart = function(element, series, opts, chartType) {
|
280
|
+
renderLineChart = function (element, series, opts, chartType) {
|
191
281
|
chartType = chartType || "spline";
|
192
282
|
var chartOptions = {};
|
193
283
|
if (chartType === "areaspline") {
|
@@ -220,7 +310,7 @@
|
|
220
310
|
new Highcharts.Chart(options);
|
221
311
|
};
|
222
312
|
|
223
|
-
renderPieChart = function(element, series, opts) {
|
313
|
+
renderPieChart = function (element, series, opts) {
|
224
314
|
var options = merge(defaultOptions, opts.library || {});
|
225
315
|
options.chart.renderTo = element.id;
|
226
316
|
options.series = [{
|
@@ -231,7 +321,7 @@
|
|
231
321
|
new Highcharts.Chart(options);
|
232
322
|
};
|
233
323
|
|
234
|
-
renderColumnChart = function(element, series, opts, chartType) {
|
324
|
+
renderColumnChart = function (element, series, opts, chartType) {
|
235
325
|
chartType = chartType || "column";
|
236
326
|
var options = jsOptions(series, opts), i, j, s, d, rows = [];
|
237
327
|
options.chart.type = chartType;
|
@@ -274,22 +364,27 @@
|
|
274
364
|
new Highcharts.Chart(options);
|
275
365
|
};
|
276
366
|
|
277
|
-
renderBarChart = function(element, series, opts) {
|
367
|
+
renderBarChart = function (element, series, opts) {
|
278
368
|
renderColumnChart(element, series, opts, "bar");
|
279
369
|
};
|
280
370
|
|
281
|
-
renderAreaChart = function(element, series, opts) {
|
371
|
+
renderAreaChart = function (element, series, opts) {
|
282
372
|
renderLineChart(element, series, opts, "areaspline");
|
283
373
|
};
|
284
374
|
} else if ("google" in window) { // Google charts
|
285
375
|
// load from google
|
286
|
-
|
287
|
-
google.setOnLoadCallback(function() {
|
376
|
+
loaded = false;
|
377
|
+
google.setOnLoadCallback(function () {
|
288
378
|
loaded = true;
|
289
379
|
});
|
290
|
-
|
380
|
+
var loadOptions = {"packages": ["corechart"]};
|
381
|
+
var config = window.Chartkick || {};
|
382
|
+
if (config.language) {
|
383
|
+
loadOptions.language = config.language;
|
384
|
+
}
|
385
|
+
google.load("visualization", "1.0", loadOptions);
|
291
386
|
|
292
|
-
|
387
|
+
waitForLoaded = function (callback) {
|
293
388
|
google.setOnLoadCallback(callback); // always do this to prevent race conditions (watch out for other issues due to this)
|
294
389
|
if (loaded) {
|
295
390
|
callback();
|
@@ -297,7 +392,7 @@
|
|
297
392
|
};
|
298
393
|
|
299
394
|
// Set chart options
|
300
|
-
|
395
|
+
defaultOptions = {
|
301
396
|
chartArea: {},
|
302
397
|
fontName: "'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif",
|
303
398
|
pointSize: 6,
|
@@ -337,30 +432,30 @@
|
|
337
432
|
}
|
338
433
|
};
|
339
434
|
|
340
|
-
|
435
|
+
hideLegend = function (options) {
|
341
436
|
options.legend.position = "none";
|
342
437
|
};
|
343
438
|
|
344
|
-
|
439
|
+
setMin = function (options, min) {
|
345
440
|
options.vAxis.viewWindow.min = min;
|
346
441
|
};
|
347
442
|
|
348
|
-
|
443
|
+
setMax = function (options, max) {
|
349
444
|
options.vAxis.viewWindow.max = max;
|
350
445
|
};
|
351
446
|
|
352
|
-
|
447
|
+
setBarMin = function (options, min) {
|
353
448
|
options.hAxis.viewWindow.min = min;
|
354
449
|
};
|
355
450
|
|
356
|
-
|
451
|
+
setBarMax = function (options, max) {
|
357
452
|
options.hAxis.viewWindow.max = max;
|
358
453
|
};
|
359
454
|
|
360
|
-
|
455
|
+
jsOptions = jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax);
|
361
456
|
|
362
457
|
// cant use object as key
|
363
|
-
|
458
|
+
createDataTable = function (series, columnType) {
|
364
459
|
var data = new google.visualization.DataTable();
|
365
460
|
data.addColumn(columnType, "");
|
366
461
|
|
@@ -393,29 +488,28 @@
|
|
393
488
|
return data;
|
394
489
|
};
|
395
490
|
|
396
|
-
|
491
|
+
resize = function (callback) {
|
397
492
|
if (window.attachEvent) {
|
398
493
|
window.attachEvent("onresize", callback);
|
399
|
-
}
|
400
|
-
else if (window.addEventListener) {
|
494
|
+
} else if (window.addEventListener) {
|
401
495
|
window.addEventListener("resize", callback, true);
|
402
496
|
}
|
403
497
|
callback();
|
404
498
|
};
|
405
499
|
|
406
|
-
renderLineChart = function(element, series, opts) {
|
407
|
-
waitForLoaded(function() {
|
500
|
+
renderLineChart = function (element, series, opts) {
|
501
|
+
waitForLoaded(function () {
|
408
502
|
var options = jsOptions(series, opts);
|
409
503
|
var data = createDataTable(series, "datetime");
|
410
504
|
var chart = new google.visualization.LineChart(element);
|
411
|
-
resize(
|
505
|
+
resize(function () {
|
412
506
|
chart.draw(data, options);
|
413
507
|
});
|
414
508
|
});
|
415
509
|
};
|
416
510
|
|
417
|
-
renderPieChart = function(element, series, opts) {
|
418
|
-
waitForLoaded(function() {
|
511
|
+
renderPieChart = function (element, series, opts) {
|
512
|
+
waitForLoaded(function () {
|
419
513
|
var chartOptions = {
|
420
514
|
chartArea: {
|
421
515
|
top: "10%",
|
@@ -430,25 +524,25 @@
|
|
430
524
|
data.addRows(series);
|
431
525
|
|
432
526
|
var chart = new google.visualization.PieChart(element);
|
433
|
-
resize(
|
527
|
+
resize(function () {
|
434
528
|
chart.draw(data, options);
|
435
529
|
});
|
436
530
|
});
|
437
531
|
};
|
438
532
|
|
439
|
-
renderColumnChart = function(element, series, opts) {
|
440
|
-
waitForLoaded(function() {
|
533
|
+
renderColumnChart = function (element, series, opts) {
|
534
|
+
waitForLoaded(function () {
|
441
535
|
var options = jsOptions(series, opts);
|
442
536
|
var data = createDataTable(series, "string");
|
443
537
|
var chart = new google.visualization.ColumnChart(element);
|
444
|
-
resize(
|
538
|
+
resize(function () {
|
445
539
|
chart.draw(data, options);
|
446
540
|
});
|
447
541
|
});
|
448
542
|
};
|
449
543
|
|
450
|
-
renderBarChart = function(element, series, opts) {
|
451
|
-
|
544
|
+
renderBarChart = function (element, series, opts) {
|
545
|
+
waitForLoaded(function () {
|
452
546
|
var chartOptions = {
|
453
547
|
hAxis: {
|
454
548
|
gridlines: {
|
@@ -459,14 +553,14 @@
|
|
459
553
|
var options = jsOptionsFunc(defaultOptions, hideLegend, setBarMin, setBarMax)(series, opts, chartOptions);
|
460
554
|
var data = createDataTable(series, "string");
|
461
555
|
var chart = new google.visualization.BarChart(element);
|
462
|
-
resize(
|
556
|
+
resize(function () {
|
463
557
|
chart.draw(data, options);
|
464
558
|
});
|
465
559
|
});
|
466
560
|
};
|
467
561
|
|
468
|
-
renderAreaChart = function(element, series, opts) {
|
469
|
-
waitForLoaded(function() {
|
562
|
+
renderAreaChart = function (element, series, opts) {
|
563
|
+
waitForLoaded(function () {
|
470
564
|
var chartOptions = {
|
471
565
|
isStacked: true,
|
472
566
|
pointSize: 0,
|
@@ -475,104 +569,19 @@
|
|
475
569
|
var options = jsOptions(series, opts, chartOptions);
|
476
570
|
var data = createDataTable(series, "datetime");
|
477
571
|
var chart = new google.visualization.AreaChart(element);
|
478
|
-
resize(
|
572
|
+
resize(function () {
|
479
573
|
chart.draw(data, options);
|
480
574
|
});
|
481
575
|
});
|
482
576
|
};
|
483
577
|
} else { // no chart library installed
|
484
|
-
renderLineChart = renderPieChart = renderColumnChart = renderBarChart = renderAreaChart = function() {
|
578
|
+
renderLineChart = renderPieChart = renderColumnChart = renderBarChart = renderAreaChart = function () {
|
485
579
|
throw new Error("Please install Google Charts or Highcharts");
|
486
580
|
};
|
487
581
|
}
|
488
582
|
|
489
|
-
function setText(element, text) {
|
490
|
-
if (document.body.innerText) {
|
491
|
-
element.innerText = text;
|
492
|
-
} else {
|
493
|
-
element.textContent = text;
|
494
|
-
}
|
495
|
-
}
|
496
|
-
|
497
|
-
function chartError(element, message) {
|
498
|
-
setText(element, "Error Loading Chart: " + message);
|
499
|
-
element.style.color = "#ff0000";
|
500
|
-
}
|
501
|
-
|
502
|
-
function getJSON(element, url, success) {
|
503
|
-
$.ajax({
|
504
|
-
dataType: "json",
|
505
|
-
url: url,
|
506
|
-
success: success,
|
507
|
-
error: function(jqXHR, textStatus, errorThrown) {
|
508
|
-
var message = (typeof errorThrown === "string") ? errorThrown : errorThrown.message;
|
509
|
-
chartError(element, message);
|
510
|
-
}
|
511
|
-
});
|
512
|
-
}
|
513
|
-
|
514
|
-
function errorCatcher(element, data, opts, callback) {
|
515
|
-
try {
|
516
|
-
callback(element, data, opts);
|
517
|
-
} catch (err) {
|
518
|
-
chartError(element, err.message);
|
519
|
-
throw err;
|
520
|
-
}
|
521
|
-
}
|
522
|
-
|
523
|
-
function fetchDataSource(element, dataSource, opts, callback) {
|
524
|
-
if (typeof dataSource === "string") {
|
525
|
-
getJSON(element, dataSource, function(data, textStatus, jqXHR) {
|
526
|
-
errorCatcher(element, data, opts, callback);
|
527
|
-
});
|
528
|
-
} else {
|
529
|
-
errorCatcher(element, dataSource, opts, callback);
|
530
|
-
}
|
531
|
-
}
|
532
|
-
|
533
|
-
// type conversions
|
534
|
-
|
535
|
-
function toStr(n) {
|
536
|
-
return "" + n;
|
537
|
-
}
|
538
|
-
|
539
|
-
function toFloat(n) {
|
540
|
-
return parseFloat(n);
|
541
|
-
}
|
542
|
-
|
543
|
-
function toDate(n) {
|
544
|
-
if (typeof n !== "object") {
|
545
|
-
if (typeof n === "number") {
|
546
|
-
n = new Date(n * 1000); // ms
|
547
|
-
} else { // str
|
548
|
-
// try our best to get the str into iso8601
|
549
|
-
// TODO be smarter about this
|
550
|
-
var str = n.replace(/ /, "T").replace(" ", "").replace("UTC", "Z");
|
551
|
-
n = parseISO8601(str) || new Date(n);
|
552
|
-
}
|
553
|
-
}
|
554
|
-
return n;
|
555
|
-
}
|
556
|
-
|
557
|
-
function toArr(n) {
|
558
|
-
if (!isArray(n)) {
|
559
|
-
var arr = [], i;
|
560
|
-
for (i in n) {
|
561
|
-
if (n.hasOwnProperty(i)) {
|
562
|
-
arr.push([i, n[i]]);
|
563
|
-
}
|
564
|
-
}
|
565
|
-
n = arr;
|
566
|
-
}
|
567
|
-
return n;
|
568
|
-
}
|
569
|
-
|
570
583
|
// process data
|
571
584
|
|
572
|
-
function sortByTime(a, b) {
|
573
|
-
return a[0].getTime() - b[0].getTime();
|
574
|
-
}
|
575
|
-
|
576
585
|
function processSeries(series, opts, time) {
|
577
586
|
var i, j, data, r, key;
|
578
587
|
|
@@ -635,23 +644,23 @@
|
|
635
644
|
|
636
645
|
// define classes
|
637
646
|
|
638
|
-
|
639
|
-
LineChart: function(element, dataSource, opts) {
|
647
|
+
Chartkick = {
|
648
|
+
LineChart: function (element, dataSource, opts) {
|
640
649
|
setElement(element, dataSource, opts, processLineData);
|
641
650
|
},
|
642
|
-
PieChart: function(element, dataSource, opts) {
|
651
|
+
PieChart: function (element, dataSource, opts) {
|
643
652
|
setElement(element, dataSource, opts, processPieData);
|
644
653
|
},
|
645
|
-
ColumnChart: function(element, dataSource, opts) {
|
654
|
+
ColumnChart: function (element, dataSource, opts) {
|
646
655
|
setElement(element, dataSource, opts, processColumnData);
|
647
656
|
},
|
648
|
-
BarChart: function(element, dataSource, opts) {
|
657
|
+
BarChart: function (element, dataSource, opts) {
|
649
658
|
setElement(element, dataSource, opts, processBarData);
|
650
659
|
},
|
651
|
-
AreaChart: function(element, dataSource, opts) {
|
660
|
+
AreaChart: function (element, dataSource, opts) {
|
652
661
|
setElement(element, dataSource, opts, processAreaData);
|
653
662
|
}
|
654
663
|
};
|
655
664
|
|
656
665
|
window.Chartkick = Chartkick;
|
657
|
-
}
|
666
|
+
}());
|
data/lib/chartkick/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chartkick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|