chartkick 2.1.1 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 848d18904d57decb720961b641517820104fd6cc
4
- data.tar.gz: 878e5deed5566486939c041003fffb354c1ad1c4
3
+ metadata.gz: 6c0dcec810efb2cf5b62a2329f89727b492bafa5
4
+ data.tar.gz: 4ac0c0fdfe58ef357f9ac690789d3bb30d7b0e9c
5
5
  SHA512:
6
- metadata.gz: 1916921d38f7cddb051f9e8ac1d6599449f95c4b30d2b6168f80e1155a3c405c53ecd10521b88202298261df6a211d2c3747af0f239083c745d1a072510442c3
7
- data.tar.gz: 6a54d67e004bd435689b787be2063be304f4ee0b1e6d52fc81b2ebcd3f000b23f703b676332980e7eaa399dd725fb94b11fe47d5e62a610794b977e77934f69c
6
+ metadata.gz: 85ad01a7d5f0e83129a32849f3cc3703d2d06b997bf5477ed2a86d2b18063fb4c3e2396361ef7cdcb23b2cea8041cb9d98f87bb7c05123f22270bb5f3660542b
7
+ data.tar.gz: 5bc4531ebb50c7a139a94dfbaae452075571445e161227e3c7c1c615f32bfd3babde9c734c341db6a800b06054d0b9fcb81f901efbf75c50b7d7186d5a08a754
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 2.1.2
2
+
3
+ - Added `defer` option
4
+ - Added `nonce` option
5
+ - Updated Chartkick.js to 2.1.1
6
+
1
7
  ## 2.1.1
2
8
 
3
9
  - Use custom version of Chart.js to fix label overlap
data/README.md CHANGED
@@ -180,8 +180,8 @@ Chartkick.options[:content_for] = :charts_js
180
180
  Then, in your layout:
181
181
 
182
182
  ```erb
183
- <%= yield :charts_js %> <%# Rails %>
184
- <%= yield_content :charts_js %> <%# Padrino %>
183
+ <%= yield :charts_js %> <!-- Rails -->
184
+ <%= yield_content :charts_js %> <!-- Padrino -->
185
185
  ```
186
186
 
187
187
  This is great for including all of your JavaScript at the bottom of the page.
@@ -242,7 +242,7 @@ In `application.js`, add:
242
242
  In your views, before `application.js`, add:
243
243
 
244
244
  ```erb
245
- <%= javascript_include_tag "https://www.google.com/jsapi" %>
245
+ <%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" %>
246
246
  ```
247
247
 
248
248
  #### Highcharts
@@ -258,23 +258,14 @@ In `application.js`, add:
258
258
 
259
259
  Works with Highcharts 2.1+
260
260
 
261
- ### For Sinatra
261
+ ### Sinatra and Padrino
262
262
 
263
- You must include `chartkick.js` manually. [Download it here](https://raw.github.com/ankane/chartkick/master/app/assets/javascripts/chartkick.js)
263
+ You must include `chartkick.js` manually. [Download it here](https://raw.github.com/ankane/chartkick/master/app/assets/javascripts/chartkick.js)
264
264
 
265
265
  ```html
266
- <script src="https://www.google.com/jsapi"></script>
267
266
  <script src="chartkick.js"></script>
268
267
  ```
269
268
 
270
- ### For Padrino
271
-
272
- You must include `chartkick.js` manually. [Download it here](https://raw.github.com/ankane/chartkick/master/app/assets/javascripts/chartkick.js)
273
-
274
- ```erb
275
- <%= javascript_include_tag "https://www.google.com/jsapi", "chartkick" %>
276
- ```
277
-
278
269
  ### Localization
279
270
 
280
271
  To specify a language for Google Charts, add:
@@ -285,6 +276,14 @@ Chartkick.configure({"language": "de"});
285
276
 
286
277
  after the JavaScript files and before your charts.
287
278
 
279
+ ### Multiple Libraries
280
+
281
+ If more than one charting library is loaded, choose between them with:
282
+
283
+ ```erb
284
+ <%= line_chart data, adapter: "google" %> <!-- or highcharts -->
285
+ ```
286
+
288
287
  ## JavaScript API
289
288
 
290
289
  Access a chart with:
@@ -1,8 +1,8 @@
1
1
  /*
2
2
  * Chartkick.js
3
- * Create beautiful JavaScript charts with minimal code
3
+ * Create beautiful charts with one line of JavaScript
4
4
  * https://github.com/ankane/chartkick.js
5
- * v2.1.0
5
+ * v2.1.1
6
6
  * MIT License
7
7
  */
8
8
 
@@ -835,7 +835,10 @@
835
835
  }
836
836
  ]
837
837
  },
838
- legend: {}
838
+ legend: {},
839
+ tooltips: {
840
+ displayColors: false
841
+ }
839
842
  };
840
843
 
841
844
  // http://there4.io/2012/05/02/google-chart-color-list/
@@ -984,7 +987,8 @@
984
987
  }
985
988
  labels.push(value);
986
989
  for (j = 0; j < series.length; j++) {
987
- rows2[j].push(rows[i][j]);
990
+ // Chart.js doesn't like undefined
991
+ rows2[j].push(rows[i][j] || null);
988
992
  }
989
993
  }
990
994
 
@@ -1032,7 +1036,8 @@
1032
1036
  } else if (day || timeDiff > 10) {
1033
1037
  options.scales.xAxes[0].time.unit = "day";
1034
1038
  step = 1;
1035
- } else if (hour) {
1039
+ } else if (hour || timeDiff > 0.5) {
1040
+ options.scales.xAxes[0].time.displayFormats = {hour: "MMM D, h a"};
1036
1041
  options.scales.xAxes[0].time.unit = "hour";
1037
1042
  step = 1 / 24.0;
1038
1043
  } else if (minute) {
@@ -1041,7 +1046,6 @@
1041
1046
  step = 1 / 24.0 / 60.0;
1042
1047
  }
1043
1048
 
1044
-
1045
1049
  if (step && timeDiff > 0) {
1046
1050
  var unitStepSize = Math.ceil(timeDiff / step / (chart.element.offsetWidth / 100.0));
1047
1051
  if (week && step === 1) {
@@ -43,16 +43,36 @@ module Chartkick
43
43
  element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}"
44
44
  height = options.delete(:height) || "300px"
45
45
  width = options.delete(:width) || "100%"
46
+ defer = !!options.delete(:defer)
46
47
  # content_for: nil must override default
47
48
  content_for = options.key?(:content_for) ? options.delete(:content_for) : Chartkick.content_for
48
-
49
+ nonce = options.key?(:nonce) ? " nonce=\"#{ERB::Util.html_escape(options.delete(:nonce))}\"" : nil
49
50
  html = (options.delete(:html) || %(<div id="%{id}" style="height: %{height}; width: %{width}; text-align: center; color: #999; line-height: %{height}; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">Loading...</div>)) % {id: ERB::Util.html_escape(element_id), height: ERB::Util.html_escape(height), width: ERB::Util.html_escape(width)}
50
51
 
51
- js = <<JS
52
- <script type="text/javascript">
53
- new Chartkick.#{klass}(#{element_id.to_json}, #{data_source.respond_to?(:chart_json) ? data_source.chart_json : data_source.to_json}, #{options.to_json});
52
+ createjs = "new Chartkick.#{klass}(#{element_id.to_json}, #{data_source.respond_to?(:chart_json) ? data_source.chart_json : data_source.to_json}, #{options.to_json});"
53
+ if defer
54
+ js = <<JS
55
+ <script type="text/javascript"#{nonce}>
56
+ (function() {
57
+ var createChart = function() { #{createjs} };
58
+ if (window.addEventListener) {
59
+ window.addEventListener("load", createChart, true);
60
+ } else if (window.attachEvent) {
61
+ window.attachEvent("onload", createChart);
62
+ } else {
63
+ createChart();
64
+ }
65
+ })();
66
+ </script>
67
+ JS
68
+ else
69
+ js = <<JS
70
+ <script type="text/javascript"#{nonce}>
71
+ #{createjs}
54
72
  </script>
55
73
  JS
74
+ end
75
+
56
76
  if content_for
57
77
  content_for(content_for) { js.respond_to?(:html_safe) ? js.html_safe : js }
58
78
  else
@@ -1,3 +1,3 @@
1
1
  module Chartkick
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
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.1.1
4
+ version: 2.1.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: 2016-09-12 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler