chartkick 2.2.1 → 2.2.2
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 +5 -1
- data/README.md +20 -20
- data/app/assets/javascripts/chartkick.js +116 -58
- data/lib/chartkick/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50c3b4007d5f0cdb2e0f190a841a70c7ccf9e792
|
4
|
+
data.tar.gz: d872ab6cca73563160825ac9112d44959b57324a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e28ff4ac40e81455c479e49b414cfafe34614097b0bdcae3fddc9b2da34d1ff9165d45f1fa71c86e22173cb9932e0d40765ac820ced017259f12a4ca084404d7
|
7
|
+
data.tar.gz: dbb9590ab3e3ca4732cf32de2244adb4381b444cc3161125d7d5182fddf0c795a944d4743594666aec15f4b11ca34d407b6ef60ffda54e5155b4e468da1829d1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -119,7 +119,7 @@ Min and max values
|
|
119
119
|
Colors
|
120
120
|
|
121
121
|
```erb
|
122
|
-
<%= line_chart data, colors: ["
|
122
|
+
<%= line_chart data, colors: ["#b00", "#666"] %>
|
123
123
|
```
|
124
124
|
|
125
125
|
Stacked columns or bars
|
@@ -191,7 +191,7 @@ To set options for all of your charts, create an initializer `config/initializer
|
|
191
191
|
```ruby
|
192
192
|
Chartkick.options = {
|
193
193
|
height: "400px",
|
194
|
-
colors: ["
|
194
|
+
colors: ["#b00", "#666"]
|
195
195
|
}
|
196
196
|
```
|
197
197
|
|
@@ -216,24 +216,6 @@ Then, in your layout:
|
|
216
216
|
|
217
217
|
This is great for including all of your JavaScript at the bottom of the page.
|
218
218
|
|
219
|
-
### Download Charts
|
220
|
-
|
221
|
-
*Chart.js only*
|
222
|
-
|
223
|
-
Give users the ability to download charts. It all happens in the browser - no server-side code needed.
|
224
|
-
|
225
|
-
```erb
|
226
|
-
<%= line_chart data, download: true %>
|
227
|
-
```
|
228
|
-
|
229
|
-
Set the filename
|
230
|
-
|
231
|
-
```erb
|
232
|
-
<%= line_chart data, download: "boom" %>
|
233
|
-
```
|
234
|
-
|
235
|
-
**Note:** Safari will open the image in a new window instead of downloading.
|
236
|
-
|
237
219
|
### Data
|
238
220
|
|
239
221
|
Pass data as a Hash or Array
|
@@ -258,6 +240,24 @@ Times can be a time, a timestamp, or a string (strings are parsed)
|
|
258
240
|
<%= line_chart({20.day.ago => 5, 1368174456 => 4, "2013-05-07 00:00:00 UTC" => 7}) %>
|
259
241
|
```
|
260
242
|
|
243
|
+
### Download Charts
|
244
|
+
|
245
|
+
*Chart.js only*
|
246
|
+
|
247
|
+
Give users the ability to download charts. It all happens in the browser - no server-side code needed.
|
248
|
+
|
249
|
+
```erb
|
250
|
+
<%= line_chart data, download: true %>
|
251
|
+
```
|
252
|
+
|
253
|
+
Set the filename
|
254
|
+
|
255
|
+
```erb
|
256
|
+
<%= line_chart data, download: "boom" %>
|
257
|
+
```
|
258
|
+
|
259
|
+
**Note:** Safari will open the image in a new window instead of downloading.
|
260
|
+
|
261
261
|
## Installation
|
262
262
|
|
263
263
|
Add this line to your application's Gemfile:
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* Chartkick.js
|
3
3
|
* Create beautiful charts with one line of JavaScript
|
4
4
|
* https://github.com/ankane/chartkick.js
|
5
|
-
* v2.2.
|
5
|
+
* v2.2.2
|
6
6
|
* MIT License
|
7
7
|
*/
|
8
8
|
|
@@ -15,6 +15,7 @@
|
|
15
15
|
var Chartkick, ISO8601_PATTERN, DECIMAL_SEPARATOR, adapters = [];
|
16
16
|
var DATE_PATTERN = /^(\d\d\d\d)(\-)?(\d\d)(\-)?(\d\d)$/i;
|
17
17
|
var GoogleChartsAdapter, HighchartsAdapter, ChartjsAdapter;
|
18
|
+
var pendingRequests = [], runningRequests = 0, maxRequests = 4;
|
18
19
|
|
19
20
|
// helpers
|
20
21
|
|
@@ -166,6 +167,27 @@
|
|
166
167
|
element.style.color = "#ff0000";
|
167
168
|
}
|
168
169
|
|
170
|
+
function pushRequest(element, url, success) {
|
171
|
+
pendingRequests.push([element, url, success]);
|
172
|
+
runNext();
|
173
|
+
}
|
174
|
+
|
175
|
+
function runNext() {
|
176
|
+
if (runningRequests < maxRequests) {
|
177
|
+
var request = pendingRequests.shift()
|
178
|
+
if (request) {
|
179
|
+
runningRequests++;
|
180
|
+
getJSON(request[0], request[1], request[2]);
|
181
|
+
runNext();
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
function requestComplete() {
|
187
|
+
runningRequests--;
|
188
|
+
runNext();
|
189
|
+
}
|
190
|
+
|
169
191
|
function getJSON(element, url, success) {
|
170
192
|
ajaxCall(url, success, function (jqXHR, textStatus, errorThrown) {
|
171
193
|
var message = (typeof errorThrown === "string") ? errorThrown : errorThrown.message;
|
@@ -181,13 +203,15 @@
|
|
181
203
|
dataType: "json",
|
182
204
|
url: url,
|
183
205
|
success: success,
|
184
|
-
error: error
|
206
|
+
error: error,
|
207
|
+
complete: requestComplete
|
185
208
|
});
|
186
209
|
} else {
|
187
210
|
var xhr = new XMLHttpRequest();
|
188
211
|
xhr.open("GET", url, true);
|
189
212
|
xhr.setRequestHeader("Content-Type", "application/json");
|
190
213
|
xhr.onload = function () {
|
214
|
+
requestComplete();
|
191
215
|
if (xhr.status === 200) {
|
192
216
|
success(JSON.parse(xhr.responseText), xhr.statusText, xhr);
|
193
217
|
} else {
|
@@ -209,7 +233,7 @@
|
|
209
233
|
|
210
234
|
function fetchDataSource(chart, callback, dataSource) {
|
211
235
|
if (typeof dataSource === "string") {
|
212
|
-
|
236
|
+
pushRequest(chart.element, dataSource, function (data, textStatus, jqXHR) {
|
213
237
|
chart.rawData = data;
|
214
238
|
errorCatcher(chart, callback);
|
215
239
|
});
|
@@ -891,7 +915,24 @@
|
|
891
915
|
waitForLoaded(function () {
|
892
916
|
var chartOptions = {};
|
893
917
|
var options = jsOptions(chart, chart.options, chartOptions);
|
894
|
-
|
918
|
+
|
919
|
+
var series = chart.data, rows2 = [], i, j, data, d;
|
920
|
+
for (i = 0; i < series.length; i++) {
|
921
|
+
d = series[i].data;
|
922
|
+
for (j = 0; j < d.length; j++) {
|
923
|
+
var row = new Array(series.length + 1);
|
924
|
+
row[0] = d[j][0];
|
925
|
+
row[i + 1] = d[j][1];
|
926
|
+
rows2.push(row);
|
927
|
+
}
|
928
|
+
}
|
929
|
+
|
930
|
+
var data = new google.visualization.DataTable();
|
931
|
+
data.addColumn("number", "");
|
932
|
+
for (i = 0; i < series.length; i++) {
|
933
|
+
data.addColumn("number", series[i].name);
|
934
|
+
}
|
935
|
+
data.addRows(rows2);
|
895
936
|
|
896
937
|
chart.chart = new google.visualization.ScatterChart(chart.element);
|
897
938
|
resize(function () {
|
@@ -1146,15 +1187,16 @@
|
|
1146
1187
|
for (i = 0; i < series.length; i++) {
|
1147
1188
|
s = series[i];
|
1148
1189
|
|
1149
|
-
var
|
1190
|
+
var color = s.color || colors[i];
|
1191
|
+
var backgroundColor = chartType !== "line" ? addOpacity(color, 0.5) : color;
|
1150
1192
|
|
1151
1193
|
var dataset = {
|
1152
1194
|
label: s.name,
|
1153
1195
|
data: rows2[i],
|
1154
1196
|
fill: chartType === "area",
|
1155
|
-
borderColor:
|
1197
|
+
borderColor: color,
|
1156
1198
|
backgroundColor: backgroundColor,
|
1157
|
-
pointBackgroundColor:
|
1199
|
+
pointBackgroundColor: color,
|
1158
1200
|
borderWidth: 2
|
1159
1201
|
};
|
1160
1202
|
|
@@ -1308,7 +1350,9 @@
|
|
1308
1350
|
self.renderColumnChart(chart, "bar");
|
1309
1351
|
};
|
1310
1352
|
|
1311
|
-
this.renderScatterChart = function (chart) {
|
1353
|
+
this.renderScatterChart = function (chart, chartType) {
|
1354
|
+
chartType = chartType || "line";
|
1355
|
+
|
1312
1356
|
var options = jsOptions(chart, chart.options);
|
1313
1357
|
|
1314
1358
|
var colors = chart.options.colors || defaultColors;
|
@@ -1319,19 +1363,25 @@
|
|
1319
1363
|
var s = series[i];
|
1320
1364
|
var d = [];
|
1321
1365
|
for (var j = 0; j < s.data.length; j++) {
|
1322
|
-
|
1366
|
+
var point = {
|
1323
1367
|
x: toFloat(s.data[j][0]),
|
1324
1368
|
y: toFloat(s.data[j][1])
|
1325
|
-
}
|
1369
|
+
};
|
1370
|
+
if (chartType === "bubble") {
|
1371
|
+
point.r = toFloat(s.data[j][2]);
|
1372
|
+
}
|
1373
|
+
d.push(point);
|
1326
1374
|
}
|
1327
1375
|
|
1376
|
+
var color = s.color || colors[i];
|
1377
|
+
|
1328
1378
|
datasets.push({
|
1329
1379
|
label: s.name,
|
1330
1380
|
showLine: false,
|
1331
1381
|
data: d,
|
1332
|
-
borderColor:
|
1333
|
-
backgroundColor:
|
1334
|
-
pointBackgroundColor:
|
1382
|
+
borderColor: color,
|
1383
|
+
backgroundColor: color,
|
1384
|
+
pointBackgroundColor: color
|
1335
1385
|
})
|
1336
1386
|
}
|
1337
1387
|
|
@@ -1340,7 +1390,11 @@
|
|
1340
1390
|
options.scales.xAxes[0].type = "linear";
|
1341
1391
|
options.scales.xAxes[0].position = "bottom";
|
1342
1392
|
|
1343
|
-
drawChart(chart,
|
1393
|
+
drawChart(chart, chartType, data, options);
|
1394
|
+
};
|
1395
|
+
|
1396
|
+
this.renderBubbleChart = function (chart) {
|
1397
|
+
this.renderScatterChart(chart, "bubble");
|
1344
1398
|
};
|
1345
1399
|
};
|
1346
1400
|
|
@@ -1390,8 +1444,12 @@
|
|
1390
1444
|
var formatSeriesData = function (data, keyType) {
|
1391
1445
|
var r = [], key, j;
|
1392
1446
|
for (j = 0; j < data.length; j++) {
|
1393
|
-
|
1394
|
-
|
1447
|
+
if (keyType === "bubble") {
|
1448
|
+
r.push([toFloat(data[j][0]), toFloat(data[j][1]), toFloat(data[j][2])]);
|
1449
|
+
} else {
|
1450
|
+
key = toFormattedKey(data[j][0], keyType);
|
1451
|
+
r.push([key, toFloat(data[j][1])]);
|
1452
|
+
}
|
1395
1453
|
}
|
1396
1454
|
if (keyType === "datetime") {
|
1397
1455
|
r.sort(sortByTime);
|
@@ -1466,7 +1524,7 @@
|
|
1466
1524
|
} else {
|
1467
1525
|
chart.hideLegend = false;
|
1468
1526
|
}
|
1469
|
-
if ((opts.discrete === null || opts.discrete === undefined)) {
|
1527
|
+
if ((opts.discrete === null || opts.discrete === undefined) && keyType !== "bubble" && keyType !== "number") {
|
1470
1528
|
chart.discrete = detectDiscrete(series);
|
1471
1529
|
} else {
|
1472
1530
|
chart.discrete = opts.discrete;
|
@@ -1502,46 +1560,30 @@
|
|
1502
1560
|
}
|
1503
1561
|
|
1504
1562
|
function processLineData(chart) {
|
1505
|
-
|
1506
|
-
renderChart("LineChart", chart);
|
1563
|
+
return processSeries(chart, "datetime");
|
1507
1564
|
}
|
1508
1565
|
|
1509
1566
|
function processColumnData(chart) {
|
1510
|
-
|
1511
|
-
renderChart("ColumnChart", chart);
|
1512
|
-
}
|
1513
|
-
|
1514
|
-
function processPieData(chart) {
|
1515
|
-
chart.data = processSimple(chart);
|
1516
|
-
renderChart("PieChart", chart);
|
1567
|
+
return processSeries(chart, "string");
|
1517
1568
|
}
|
1518
1569
|
|
1519
1570
|
function processBarData(chart) {
|
1520
|
-
|
1521
|
-
renderChart("BarChart", chart);
|
1571
|
+
return processSeries(chart, "string");
|
1522
1572
|
}
|
1523
1573
|
|
1524
1574
|
function processAreaData(chart) {
|
1525
|
-
|
1526
|
-
renderChart("AreaChart", chart);
|
1527
|
-
}
|
1528
|
-
|
1529
|
-
function processGeoData(chart) {
|
1530
|
-
chart.data = processSimple(chart);
|
1531
|
-
renderChart("GeoChart", chart);
|
1575
|
+
return processSeries(chart, "datetime");
|
1532
1576
|
}
|
1533
1577
|
|
1534
1578
|
function processScatterData(chart) {
|
1535
|
-
|
1536
|
-
renderChart("ScatterChart", chart);
|
1579
|
+
return processSeries(chart, "number");
|
1537
1580
|
}
|
1538
1581
|
|
1539
|
-
function
|
1540
|
-
|
1541
|
-
renderChart("Timeline", chart);
|
1582
|
+
function processBubbleData(chart) {
|
1583
|
+
return processSeries(chart, "bubble");
|
1542
1584
|
}
|
1543
1585
|
|
1544
|
-
function
|
1586
|
+
function createChart(chartType, chart, element, dataSource, opts, processData) {
|
1545
1587
|
var elementId;
|
1546
1588
|
if (typeof element === "string") {
|
1547
1589
|
elementId = element;
|
@@ -1556,6 +1598,12 @@
|
|
1556
1598
|
chart.options = opts;
|
1557
1599
|
chart.dataSource = dataSource;
|
1558
1600
|
|
1601
|
+
if (!processData) {
|
1602
|
+
processData = function (chart) {
|
1603
|
+
return chart.rawData;
|
1604
|
+
}
|
1605
|
+
}
|
1606
|
+
|
1559
1607
|
// getters
|
1560
1608
|
chart.getElement = function () {
|
1561
1609
|
return element;
|
@@ -1576,6 +1624,11 @@
|
|
1576
1624
|
return chart.adapter;
|
1577
1625
|
};
|
1578
1626
|
|
1627
|
+
var callback = function () {
|
1628
|
+
chart.data = processData(chart);
|
1629
|
+
renderChart(chartType, chart);
|
1630
|
+
};
|
1631
|
+
|
1579
1632
|
// functions
|
1580
1633
|
chart.updateData = function (dataSource, options) {
|
1581
1634
|
chart.dataSource = dataSource;
|
@@ -1626,29 +1679,32 @@
|
|
1626
1679
|
// define classes
|
1627
1680
|
|
1628
1681
|
Chartkick = {
|
1629
|
-
LineChart: function (element, dataSource,
|
1630
|
-
|
1682
|
+
LineChart: function (element, dataSource, options) {
|
1683
|
+
createChart("LineChart", this, element, dataSource, options, processLineData);
|
1684
|
+
},
|
1685
|
+
PieChart: function (element, dataSource, options) {
|
1686
|
+
createChart("PieChart", this, element, dataSource, options, processSimple);
|
1631
1687
|
},
|
1632
|
-
|
1633
|
-
|
1688
|
+
ColumnChart: function (element, dataSource, options) {
|
1689
|
+
createChart("ColumnChart", this, element, dataSource, options, processColumnData);
|
1634
1690
|
},
|
1635
|
-
|
1636
|
-
|
1691
|
+
BarChart: function (element, dataSource, options) {
|
1692
|
+
createChart("BarChart", this, element, dataSource, options, processBarData);
|
1637
1693
|
},
|
1638
|
-
|
1639
|
-
|
1694
|
+
AreaChart: function (element, dataSource, options) {
|
1695
|
+
createChart("AreaChart", this, element, dataSource, options, processAreaData);
|
1640
1696
|
},
|
1641
|
-
|
1642
|
-
|
1697
|
+
GeoChart: function (element, dataSource, options) {
|
1698
|
+
createChart("GeoChart", this, element, dataSource, options, processSimple);
|
1643
1699
|
},
|
1644
|
-
|
1645
|
-
|
1700
|
+
ScatterChart: function (element, dataSource, options) {
|
1701
|
+
createChart("ScatterChart", this, element, dataSource, options, processScatterData);
|
1646
1702
|
},
|
1647
|
-
|
1648
|
-
|
1703
|
+
BubbleChart: function (element, dataSource, options) {
|
1704
|
+
createChart("BubbleChart", this, element, dataSource, options, processBubbleData);
|
1649
1705
|
},
|
1650
|
-
Timeline: function (element, dataSource,
|
1651
|
-
|
1706
|
+
Timeline: function (element, dataSource, options) {
|
1707
|
+
createChart("Timeline", this, element, dataSource, options, processTime);
|
1652
1708
|
},
|
1653
1709
|
charts: {},
|
1654
1710
|
configure: function (options) {
|
@@ -1665,7 +1721,9 @@
|
|
1665
1721
|
}
|
1666
1722
|
}
|
1667
1723
|
},
|
1668
|
-
options: {}
|
1724
|
+
options: {},
|
1725
|
+
adapters: adapters,
|
1726
|
+
createChart: createChart
|
1669
1727
|
};
|
1670
1728
|
|
1671
1729
|
if (typeof module === "object" && typeof module.exports === "object") {
|
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: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.6.8
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Create beautiful JavaScript charts with one line of Ruby
|