chartkick 3.3.0 → 3.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
- * v3.2.0
5
+ * v3.2.1
6
6
  * MIT License
7
7
  */
8
8
 
@@ -241,6 +241,8 @@
241
241
  return typeof obj === "number";
242
242
  }
243
243
 
244
+ var byteSuffixes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB"];
245
+
244
246
  function formatValue(pre, value, options, axis) {
245
247
  pre = pre || "";
246
248
  if (options.prefix) {
@@ -256,26 +258,42 @@
256
258
  var round = options.round;
257
259
 
258
260
  if (options.byteScale) {
261
+ var suffixIdx;
259
262
  var baseValue = axis ? options.byteScale : value;
260
- if (baseValue >= 1099511627776) {
263
+
264
+ if (baseValue >= 1152921504606846976) {
265
+ value /= 1152921504606846976;
266
+ suffixIdx = 6;
267
+ } else if (baseValue >= 1125899906842624) {
268
+ value /= 1125899906842624;
269
+ suffixIdx = 5;
270
+ } else if (baseValue >= 1099511627776) {
261
271
  value /= 1099511627776;
262
- suffix = " TB";
272
+ suffixIdx = 4;
263
273
  } else if (baseValue >= 1073741824) {
264
274
  value /= 1073741824;
265
- suffix = " GB";
275
+ suffixIdx = 3;
266
276
  } else if (baseValue >= 1048576) {
267
277
  value /= 1048576;
268
- suffix = " MB";
278
+ suffixIdx = 2;
269
279
  } else if (baseValue >= 1024) {
270
280
  value /= 1024;
271
- suffix = " KB";
281
+ suffixIdx = 1;
272
282
  } else {
273
- suffix = " bytes";
283
+ suffixIdx = 0;
274
284
  }
275
285
 
286
+ // TODO handle manual precision case
276
287
  if (precision === undefined && round === undefined) {
277
- precision = 3;
288
+ if (value >= 1023.5) {
289
+ if (suffixIdx < byteSuffixes.length - 1) {
290
+ value = 1.0;
291
+ suffixIdx += 1;
292
+ }
293
+ }
294
+ precision = value >= 1000 ? 4 : 3;
278
295
  }
296
+ suffix = " " + byteSuffixes[suffixIdx];
279
297
  }
280
298
 
281
299
  if (precision !== undefined && round !== undefined) {
@@ -746,6 +764,22 @@
746
764
  }
747
765
  }
748
766
 
767
+ // for empty datetime chart
768
+ if (chart.xtype === "datetime" && labels.length === 0) {
769
+ if (notnull(xmin)) {
770
+ labels.push(toDate(xmin));
771
+ }
772
+ if (notnull(xmax)) {
773
+ labels.push(toDate(xmax));
774
+ }
775
+ day = false;
776
+ week = false;
777
+ month = false;
778
+ year = false;
779
+ hour = false;
780
+ minute = false;
781
+ }
782
+
749
783
  if (chart.xtype === "datetime" && labels.length > 0) {
750
784
  var minTime = (notnull(xmin) ? toDate(xmin) : labels[0]).getTime();
751
785
  var maxTime = (notnull(xmax) ? toDate(xmax) : labels[0]).getTime();
@@ -1448,7 +1482,7 @@
1448
1482
  defaultExport$2.prototype.renderGeoChart = function renderGeoChart (chart) {
1449
1483
  var this$1 = this;
1450
1484
 
1451
- this.waitForLoaded(chart, function () {
1485
+ this.waitForLoaded(chart, "geochart", function () {
1452
1486
  var chartOptions = {
1453
1487
  legend: "none",
1454
1488
  colorAxis: {
@@ -1564,7 +1598,7 @@
1564
1598
  if (config.language) {
1565
1599
  loadOptions.language = config.language;
1566
1600
  }
1567
- if (pack === "corechart" && config.mapsApiKey) {
1601
+ if (pack === "geochart" && config.mapsApiKey) {
1568
1602
  loadOptions.mapsApiKey = config.mapsApiKey;
1569
1603
  }
1570
1604
 
@@ -1576,7 +1610,7 @@
1576
1610
  var cb, call;
1577
1611
  for (var i = 0; i < callbacks.length; i++) {
1578
1612
  cb = callbacks[i];
1579
- call = this.library.visualization && ((cb.pack === "corechart" && this.library.visualization.LineChart) || (cb.pack === "timeline" && this.library.visualization.Timeline));
1613
+ call = this.library.visualization && ((cb.pack === "corechart" && this.library.visualization.LineChart) || (cb.pack === "timeline" && this.library.visualization.Timeline) || (cb.pack === "geochart" && this.library.visualization.GeoChart));
1580
1614
  if (call) {
1581
1615
  cb.callback();
1582
1616
  callbacks.splice(i, 1);
@@ -1951,8 +1985,14 @@
1951
1985
  return r;
1952
1986
  };
1953
1987
 
1954
- function detectXType(series, noDatetime) {
1955
- if (detectXTypeWithFunction(series, isNumber)) {
1988
+ function detectXType(series, noDatetime, options) {
1989
+ if (dataEmpty(series)) {
1990
+ if ((options.xmin || options.xmax) && (!options.xmin || isDate(options.xmin)) && (!options.xmax || isDate(options.xmax))) {
1991
+ return "datetime";
1992
+ } else {
1993
+ return "number";
1994
+ }
1995
+ } else if (detectXTypeWithFunction(series, isNumber)) {
1956
1996
  return "number";
1957
1997
  } else if (!noDatetime && detectXTypeWithFunction(series, isDate)) {
1958
1998
  return "datetime";
@@ -2004,12 +2044,18 @@
2004
2044
  chart.hideLegend = false;
2005
2045
  }
2006
2046
 
2007
- chart.xtype = keyType ? keyType : (opts.discrete ? "string" : detectXType(series, noDatetime));
2047
+ // convert to array
2048
+ // must come before dataEmpty check
2049
+ series = copySeries(series);
2050
+ for (i = 0; i < series.length; i++) {
2051
+ series[i].data = toArr(series[i].data);
2052
+ }
2053
+
2054
+ chart.xtype = keyType ? keyType : (opts.discrete ? "string" : detectXType(series, noDatetime, opts));
2008
2055
 
2009
2056
  // right format
2010
- series = copySeries(series);
2011
2057
  for (i = 0; i < series.length; i++) {
2012
- series[i].data = formatSeriesData(toArr(series[i].data), chart.xtype);
2058
+ series[i].data = formatSeriesData(series[i].data, chart.xtype);
2013
2059
  }
2014
2060
 
2015
2061
  return series;
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: 3.3.0
4
+ version: 3.4.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: 2019-11-10 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -59,14 +59,17 @@ extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
61
  - CHANGELOG.md
62
- - CONTRIBUTING.md
63
62
  - LICENSE.txt
64
63
  - README.md
65
64
  - lib/chartkick.rb
66
65
  - lib/chartkick/engine.rb
66
+ - lib/chartkick/enumerable.rb
67
67
  - lib/chartkick/helper.rb
68
68
  - lib/chartkick/sinatra.rb
69
69
  - lib/chartkick/version.rb
70
+ - licenses/LICENSE-chart.js.txt
71
+ - licenses/LICENSE-chartkick.js.txt
72
+ - licenses/LICENSE-moment.txt
70
73
  - vendor/assets/javascripts/Chart.bundle.js
71
74
  - vendor/assets/javascripts/chartkick.js
72
75
  homepage: https://chartkick.com
@@ -88,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
91
  - !ruby/object:Gem::Version
89
92
  version: '0'
90
93
  requirements: []
91
- rubygems_version: 3.0.3
94
+ rubygems_version: 3.1.2
92
95
  signing_key:
93
96
  specification_version: 4
94
97
  summary: Create beautiful JavaScript charts with one line of Ruby
@@ -1,46 +0,0 @@
1
- # Contributing
2
-
3
- First, thanks for wanting to contribute. You’re awesome! :heart:
4
-
5
- ## Help
6
-
7
- We’re not able to provide support through GitHub Issues. If you’re looking for help with your code, try posting on [Stack Overflow](https://stackoverflow.com/).
8
-
9
- All features should be documented. If you don’t see a feature in the docs, assume it doesn’t exist.
10
-
11
- ## Bugs
12
-
13
- Think you’ve discovered a bug?
14
-
15
- 1. Search existing issues to see if it’s been reported.
16
- 2. Try the `master` branch to make sure it hasn’t been fixed.
17
-
18
- ```rb
19
- gem "chartkick", github: "ankane/chartkick"
20
- ```
21
-
22
- If the above steps don’t help, create an issue. Include:
23
-
24
- - Detailed steps to reproduce
25
- - JavaScript rendered by Chartkick
26
- - Complete backtraces for exceptions
27
-
28
- ## New Features
29
-
30
- If you’d like to discuss a new feature, create an issue and start the title with `[Idea]`.
31
-
32
- ## Pull Requests
33
-
34
- Fork the project and create a pull request. A few tips:
35
-
36
- - Submit JavaScript changes to the [Chartkick.js](https://github.com/ankane/chartkick.js) repo.
37
- - Keep changes to a minimum. If you have multiple features or fixes, submit multiple pull requests.
38
- - Follow the existing style. The code should read like it’s written by a single person.
39
-
40
- Feel free to open an issue to get feedback on your idea before spending too much time on it.
41
-
42
- Also, note that we aren’t currently accepting new chart types.
43
-
44
- ---
45
-
46
- This contributing guide is released under [CCO](https://creativecommons.org/publicdomain/zero/1.0/) (public domain). Use it for your own project without attribution.