chartkick 3.2.0 → 3.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b6eb4f5b6f498a122e58ca1dd4cf7e3e1f5d610e19faa5a702291e422549026
4
- data.tar.gz: ec143cc0f819cdd1ccd955f43425d992daa87052aeede53f563beda9bace04a5
3
+ metadata.gz: 5afacd4c10d0cfddc6a2a660efead206ee042e80d48dd749f9de79feb365c1fd
4
+ data.tar.gz: c7fc99b0b2b467a6326df99f5832de2b3674f5f80415749cf57177142eecfc45
5
5
  SHA512:
6
- metadata.gz: 1a494948bc4eeb5c1567e82777601982d7f3f90bfeb5c8b8b29335620cc0eaac7659a8b91e72fe9672d29a3b580b2c512fd0524c553be2de9fb57b4dcfa27b7a
7
- data.tar.gz: 9f2e116c8c529e744e078b368ece8aebd7235dec00aa297a0745f309a494e57a2e29b2243dd5873d159a4346be0ee331f1df474f2a4166133a8a9e6159a0e9d7
6
+ metadata.gz: 75b1793b427c5d9d4604b813773253adb864b6134fad48f952c72377f75da40c8daa19eaf06fd7ce0b2da31a1ba436cfe54bde318ac849ec2080652582ac7076
7
+ data.tar.gz: 8f47e12f6e9c746871d02f0d5bd3093da1017c5a222837696b5b0d7b7e4008c400c8556e4f85ec7b0ccd79c15a9cb510a91a7d9ecf896d1a106b7c82e68ddc36
data/CHANGELOG.md CHANGED
@@ -1,23 +1,50 @@
1
- ## 3.2.0
1
+ ## 3.4.0 (2020-08-04)
2
+
3
+ - Fixed CSS injection with `width` and `height` options
4
+
5
+ ## 3.3.2 (2020-07-23)
6
+
7
+ - Updated Chartkick.js to 3.2.1
8
+
9
+ ## 3.3.1 (2019-12-26)
10
+
11
+ - Updated Chart.js to 2.9.3
12
+ - Fixed deprecating warnings in Ruby 2.7
13
+
14
+ ## 3.3.0 (2019-11-09)
15
+
16
+ - Updated Chartkick.js to 3.2.0
17
+ - Rolled back Chart.js to 2.8.0 due to legend change
18
+
19
+ ## 3.2.2 (2019-10-27)
20
+
21
+ - Updated Chartkick.js to 3.1.3
22
+ - Updated Chart.js to 2.9.1
23
+
24
+ ## 3.2.1 (2019-07-15)
25
+
26
+ - Updated Chartkick.js to 3.1.1
27
+
28
+ ## 3.2.0 (2019-06-04)
2
29
 
3
30
  - Fixed XSS vulnerability - see [#488](https://github.com/ankane/chartkick/issues/488)
4
31
 
5
- ## 3.1.0
32
+ ## 3.1.0 (2019-05-26)
6
33
 
7
34
  - Updated Chartkick.js to 3.1.0
8
35
  - Updated Chart.js to 2.8.0
9
36
 
10
- ## 3.0.2
37
+ ## 3.0.2 (2019-01-03)
11
38
 
12
39
  - Fixed error with `nonce` option with Secure Headers and Rails < 5.2
13
40
  - Updated Chartkick.js to 3.0.2
14
41
  - Updated Chart.js to 2.7.3
15
42
 
16
- ## 3.0.1
43
+ ## 3.0.1 (2018-08-13)
17
44
 
18
45
  - Updated Chartkick.js to 3.0.1
19
46
 
20
- ## 3.0.0
47
+ ## 3.0.0 (2018-08-08)
21
48
 
22
49
  - Updated Chartkick.js to 3.0.0
23
50
  - Added `code` option
@@ -31,55 +58,55 @@ Breaking changes
31
58
  - Removed `window.Chartkick = {...}` way to set config - use `Chartkick.configure` instead
32
59
  - Removed support for the Google Charts jsapi loader - use loader.js instead
33
60
 
34
- ## 2.3.5
61
+ ## 2.3.5 (2018-06-15)
35
62
 
36
63
  - Updated Chartkick.js to 2.3.6
37
64
 
38
- ## 2.3.4
65
+ ## 2.3.4 (2018-04-10)
39
66
 
40
67
  - Updated Chartkick.js to 2.3.5
41
68
  - Updated Chart.js to 2.7.2
42
69
 
43
- ## 2.3.3
70
+ ## 2.3.3 (2018-03-25)
44
71
 
45
72
  - Updated Chartkick.js to 2.3.4
46
73
 
47
- ## 2.3.2
74
+ ## 2.3.2 (2018-02-26)
48
75
 
49
76
  - Updated Chartkick.js to 2.3.3
50
77
 
51
- ## 2.3.1
78
+ ## 2.3.1 (2018-02-23)
52
79
 
53
80
  - Updated Chartkick.js to 2.3.1
54
81
 
55
- ## 2.3.0
82
+ ## 2.3.0 (2018-02-21)
56
83
 
57
84
  - Fixed deep merge error for non-Rails apps
58
85
  - Updated Chartkick.js to 2.3.0
59
86
 
60
- ## 2.2.5
87
+ ## 2.2.5 (2017-10-28)
61
88
 
62
89
  - Updated Chart.js to 2.7.1
63
90
 
64
- ## 2.2.4
91
+ ## 2.2.4 (2017-05-14)
65
92
 
66
93
  - Added compatibility with Rails API
67
94
  - Updated Chartkick.js to 2.2.4
68
95
 
69
- ## 2.2.3
96
+ ## 2.2.3 (2017-02-22)
70
97
 
71
98
  - Updated Chartkick.js to 2.2.3
72
99
  - Updated Chart.js to 2.5.0
73
100
 
74
- ## 2.2.2
101
+ ## 2.2.2 (2017-01-07)
75
102
 
76
103
  - Updated Chartkick.js to 2.2.2
77
104
 
78
- ## 2.2.1
105
+ ## 2.2.1 (2016-12-05)
79
106
 
80
107
  - Updated Chartkick.js to 2.2.1
81
108
 
82
- ## 2.2.0
109
+ ## 2.2.0 (2016-12-03)
83
110
 
84
111
  - Updated Chartkick.js to 2.2.0
85
112
  - Improved JavaScript API
@@ -87,59 +114,59 @@ Breaking changes
87
114
  - Added `refresh` option
88
115
  - Added `donut` option to pie chart
89
116
 
90
- ## 2.1.3
117
+ ## 2.1.3 (2016-11-29)
91
118
 
92
119
  - Updated Chartkick.js to 2.1.2 - fixes missing zero values for Chart.js
93
120
 
94
- ## 2.1.2
121
+ ## 2.1.2 (2016-11-28)
95
122
 
96
123
  - Added `defer` option
97
124
  - Added `nonce` option
98
125
  - Updated Chartkick.js to 2.1.1
99
126
 
100
- ## 2.1.1
127
+ ## 2.1.1 (2016-09-11)
101
128
 
102
129
  - Use custom version of Chart.js to fix label overlap
103
130
 
104
- ## 2.1.0
131
+ ## 2.1.0 (2016-09-10)
105
132
 
106
133
  - Added basic support for new Google Charts loader
107
134
  - Added `configure` function
108
135
  - Dropped jQuery and Zepto dependencies for AJAX
109
136
  - Updated Chart.js to 2.2.2
110
137
 
111
- ## 2.0.2
138
+ ## 2.0.2 (2016-08-11)
112
139
 
113
140
  - Updated Chartkick.js to 2.0.1
114
141
  - Updated Chart.js to 2.2.1
115
142
 
116
- ## 2.0.1
143
+ ## 2.0.1 (2016-07-29)
117
144
 
118
145
  - Small Chartkick.js fixes
119
146
  - Updated Chart.js to 2.2.0
120
147
 
121
- ## 2.0.0
148
+ ## 2.0.0 (2016-05-30)
122
149
 
123
150
  - Chart.js is now the default adapter - yay open source!
124
151
  - Axis types are automatically detected - no need for `discrete: true`
125
152
  - Better date support
126
153
  - New JavaScript API
127
154
 
128
- ## 1.5.2
155
+ ## 1.5.2 (2016-05-05)
129
156
 
130
157
  - Fixed Sprockets error
131
158
 
132
- ## 1.5.1
159
+ ## 1.5.1 (2016-05-03)
133
160
 
134
161
  - Updated chartkick.js to latest version
135
162
  - Included `Chart.bundle.js`
136
163
 
137
- ## 1.5.0
164
+ ## 1.5.0 (2016-05-01)
138
165
 
139
166
  - Added Chart.js adapter **beta**
140
167
  - Fixed line height on timeline charts
141
168
 
142
- ## 1.4.2
169
+ ## 1.4.2 (2016-02-29)
143
170
 
144
171
  - Added `width` option
145
172
  - Added `label` option
@@ -148,86 +175,86 @@ Breaking changes
148
175
  - Better tooltip for dates for Google Charts
149
176
  - Fixed asset precompilation issue with Rails 5
150
177
 
151
- ## 1.4.1
178
+ ## 1.4.1 (2015-09-07)
152
179
 
153
180
  - Fixed regression with `min: nil`
154
181
 
155
- ## 1.4.0
182
+ ## 1.4.0 (2015-08-31)
156
183
 
157
184
  - Added scatter chart
158
185
  - Added axis titles
159
186
 
160
- ## 1.3.2
187
+ ## 1.3.2 (2014-07-04)
161
188
 
162
189
  - Fixed `except` error when not using Rails
163
190
 
164
- ## 1.3.1
191
+ ## 1.3.1 (2014-06-30)
165
192
 
166
193
  - Fixed blank screen bug
167
194
  - Fixed language support
168
195
 
169
- ## 1.3.0
196
+ ## 1.3.0 (2014-06-28)
170
197
 
171
198
  - Added timelines
172
199
 
173
- ## 1.2.5
200
+ ## 1.2.5 (2014-06-12)
174
201
 
175
202
  - Added support for multiple groups
176
203
  - Added `html` option
177
204
 
178
- ## 1.2.4
205
+ ## 1.2.4 (2014-03-24)
179
206
 
180
207
  - Added global options
181
208
  - Added `colors` option
182
209
 
183
- ## 1.2.3
210
+ ## 1.2.3 (2014-03-23)
184
211
 
185
212
  - Added geo chart
186
213
  - Added `discrete` option
187
214
 
188
- ## 1.2.2
215
+ ## 1.2.2 (2014-02-23)
189
216
 
190
217
  - Added global `content_for` option
191
218
  - Added `stacked` option
192
219
 
193
- ## 1.2.1
220
+ ## 1.2.1 (2013-12-08)
194
221
 
195
222
  - Added localization for Google Charts
196
223
 
197
- ## 1.2.0
224
+ ## 1.2.0 (2013-07-27)
198
225
 
199
226
  - Added bar chart and area chart
200
227
  - Resize Google Charts on window resize
201
228
 
202
- ## 1.1.3
229
+ ## 1.1.3 (2013-06-26)
203
230
 
204
231
  - Added content_for option
205
232
 
206
- ## 1.1.2
233
+ ## 1.1.2 (2013-06-11)
207
234
 
208
235
  - Updated chartkick.js to v1.0.1
209
236
 
210
- ## 1.1.1
237
+ ## 1.1.1 (2013-06-10)
211
238
 
212
239
  - Added support for Sinatra
213
240
 
214
- ## 1.1.0
241
+ ## 1.1.0 (2013-06-03)
215
242
 
216
243
  - Added support for Padrino and Rails 2.3+
217
244
 
218
- ## 1.0.1
245
+ ## 1.0.1 (2013-05-23)
219
246
 
220
247
  - Updated chartkick.js to v1.0.1
221
248
 
222
- ## 1.0.0
249
+ ## 1.0.0 (2013-05-15)
223
250
 
224
251
  - Use semantic versioning (no changes)
225
252
 
226
- ## 0.0.5
253
+ ## 0.0.5 (2013-05-14)
227
254
 
228
255
  - Removed `:min => 0` default for charts with negative values
229
256
  - Show legend when data given in `{:name => "", :data => {}}` format
230
257
 
231
- ## 0.0.4
258
+ ## 0.0.4 (2013-05-13)
232
259
 
233
260
  - Fix for `Uncaught ReferenceError: Chartkick is not defined` when chartkick.js is included in the `<head>`
data/README.md CHANGED
@@ -8,6 +8,8 @@ Create beautiful JavaScript charts with one line of Ruby. No more fighting with
8
8
 
9
9
  :two_hearts: A perfect companion to [Groupdate](https://github.com/ankane/groupdate), [Hightop](https://github.com/ankane/hightop), and [ActiveMedian](https://github.com/ankane/active_median)
10
10
 
11
+ [![Build Status](https://travis-ci.org/ankane/chartkick.svg?branch=master)](https://travis-ci.org/ankane/chartkick)
12
+
11
13
  ## Quick Start
12
14
 
13
15
  Add this line to your application's Gemfile:
@@ -242,6 +244,30 @@ Set a decimal separator - *Chart.js, Highcharts*
242
244
  <%= line_chart data, decimal: "," %>
243
245
  ```
244
246
 
247
+ Set significant digits - *Chart.js, Highcharts*
248
+
249
+ ```erb
250
+ <%= line_chart data, precision: 3 %>
251
+ ```
252
+
253
+ Set rounding - *Chart.js, Highcharts*
254
+
255
+ ```erb
256
+ <%= line_chart data, round: 2 %>
257
+ ```
258
+
259
+ Show insignificant zeros, useful for currency - *Chart.js, Highcharts*
260
+
261
+ ```erb
262
+ <%= line_chart data, round: 2, zeros: true %>
263
+ ```
264
+
265
+ Friendly byte sizes - *Chart.js 2.8+*
266
+
267
+ ```erb
268
+ <%= line_chart data, bytes: true %>
269
+ ```
270
+
245
271
  Show a message when data is empty
246
272
 
247
273
  ```erb
@@ -299,7 +325,7 @@ Then, in your layout, use:
299
325
  <%= yield :charts_js %>
300
326
  ```
301
327
 
302
- > For Padrino, use `yield_content` instead of `yield`
328
+ For Padrino, use `yield_content` instead of `yield`.
303
329
 
304
330
  This is great for including all of your JavaScript at the bottom of the page.
305
331
 
@@ -346,9 +372,7 @@ If you want to use the charting library directly, get the code with:
346
372
  <%= line_chart data, code: true %>
347
373
  ```
348
374
 
349
- The code will be logged to the JavaScript console.
350
-
351
- > JavaScript functions cannot be logged, so it may not be identical.
375
+ The code will be logged to the JavaScript console. JavaScript functions cannot be logged, so it may not be identical.
352
376
 
353
377
  ### Download Charts
354
378
 
@@ -360,7 +384,7 @@ Give users the ability to download charts. It all happens in the browser - no se
360
384
  <%= line_chart data, download: true %>
361
385
  ```
362
386
 
363
- > Safari will open the image in a new window instead of downloading.
387
+ Safari will open the image in a new window instead of downloading.
364
388
 
365
389
  Set the filename
366
390
 
@@ -394,7 +418,7 @@ Next, choose your charting library.
394
418
  - [Google Charts](#google-charts)
395
419
  - [Highcharts](#highcharts)
396
420
 
397
- > In the instructions below, `application.js` must be included **before** the charts in your views, unless using the `:content_for` option.
421
+ In the instructions below, `application.js` must be included **before** the charts in your views, unless using the `:content_for` option.
398
422
 
399
423
  ### Chart.js
400
424
 
@@ -538,6 +562,12 @@ Redraw the chart with:
538
562
  chart.redraw()
539
563
  ```
540
564
 
565
+ Destroy the chart with:
566
+
567
+ ```javascript
568
+ chart.destroy()
569
+ ```
570
+
541
571
  Loop over charts with:
542
572
 
543
573
  ```javascript
@@ -573,14 +603,6 @@ Breaking changes
573
603
  - Removed `window.Chartkick = {...}` way to set config - use `Chartkick.configure` instead
574
604
  - Removed support for the Google Charts jsapi loader - use loader.js instead
575
605
 
576
- ### 2.0
577
-
578
- Breaking changes
579
-
580
- - Chart.js is now the default adapter if multiple are loaded - yay open source!
581
- - Axis types are automatically detected - no need for `discrete: true`
582
- - Better date support - dates are no longer treated as UTC
583
-
584
606
  ## Credits
585
607
 
586
608
  Chartkick uses [iso8601.js](https://github.com/Do/iso8601.js) to parse dates and times.
@@ -589,8 +611,6 @@ Chartkick uses [iso8601.js](https://github.com/Do/iso8601.js) to parse dates and
589
611
 
590
612
  View the [changelog](https://github.com/ankane/chartkick/blob/master/CHANGELOG.md)
591
613
 
592
- Chartkick follows [Semantic Versioning](https://semver.org/)
593
-
594
614
  ## Contributing
595
615
 
596
616
  Everyone is encouraged to help improve this project. Here are a few ways you can help:
@@ -599,3 +619,12 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
599
619
  - Fix bugs and [submit pull requests](https://github.com/ankane/chartkick/pulls)
600
620
  - Write, clarify, or fix documentation
601
621
  - Suggest or add new features
622
+
623
+ To get started with development:
624
+
625
+ ```sh
626
+ git clone https://github.com/ankane/chartkick.git
627
+ cd chartkick
628
+ bundle install
629
+ bundle exec rake test
630
+ ```
@@ -4,35 +4,35 @@ require "erb"
4
4
  module Chartkick
5
5
  module Helper
6
6
  def line_chart(data_source, **options)
7
- chartkick_chart "LineChart", data_source, options
7
+ chartkick_chart "LineChart", data_source, **options
8
8
  end
9
9
 
10
10
  def pie_chart(data_source, **options)
11
- chartkick_chart "PieChart", data_source, options
11
+ chartkick_chart "PieChart", data_source, **options
12
12
  end
13
13
 
14
14
  def column_chart(data_source, **options)
15
- chartkick_chart "ColumnChart", data_source, options
15
+ chartkick_chart "ColumnChart", data_source, **options
16
16
  end
17
17
 
18
18
  def bar_chart(data_source, **options)
19
- chartkick_chart "BarChart", data_source, options
19
+ chartkick_chart "BarChart", data_source, **options
20
20
  end
21
21
 
22
22
  def area_chart(data_source, **options)
23
- chartkick_chart "AreaChart", data_source, options
23
+ chartkick_chart "AreaChart", data_source, **options
24
24
  end
25
25
 
26
26
  def scatter_chart(data_source, **options)
27
- chartkick_chart "ScatterChart", data_source, options
27
+ chartkick_chart "ScatterChart", data_source, **options
28
28
  end
29
29
 
30
30
  def geo_chart(data_source, **options)
31
- chartkick_chart "GeoChart", data_source, options
31
+ chartkick_chart "GeoChart", data_source, **options
32
32
  end
33
33
 
34
34
  def timeline(data_source, **options)
35
- chartkick_chart "Timeline", data_source, options
35
+ chartkick_chart "Timeline", data_source, **options
36
36
  end
37
37
 
38
38
  private
@@ -41,8 +41,8 @@ module Chartkick
41
41
  @chartkick_chart_id ||= 0
42
42
  options = chartkick_deep_merge(Chartkick.options, options)
43
43
  element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}"
44
- height = options.delete(:height) || "300px"
45
- width = options.delete(:width) || "100%"
44
+ height = (options.delete(:height) || "300px").to_s
45
+ width = (options.delete(:width) || "100%").to_s
46
46
  defer = !!options.delete(:defer)
47
47
  # content_for: nil must override default
48
48
  content_for = options.key?(:content_for) ? options.delete(:content_for) : Chartkick.content_for
@@ -63,18 +63,31 @@ module Chartkick
63
63
 
64
64
  # html vars
65
65
  html_vars = {
66
- id: element_id,
67
- height: height,
68
- width: width
66
+ id: element_id
69
67
  }
70
68
  html_vars.each_key do |k|
71
69
  html_vars[k] = ERB::Util.html_escape(html_vars[k])
72
70
  end
73
- 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>)) % html_vars
71
+
72
+ # css vars
73
+ css_vars = {
74
+ height: height,
75
+ width: width
76
+ }
77
+ css_vars.each_key do |k|
78
+ # limit to alphanumeric and % for simplicity
79
+ # this prevents things like calc() but safety is the priority
80
+ raise ArgumentError, "Invalid #{k}" unless css_vars[k] =~ /\A[a-zA-Z0-9%]*\z/
81
+ # we limit above, but escape for safety as fail-safe
82
+ # to prevent XSS injection in worse-case scenario
83
+ css_vars[k] = ERB::Util.html_escape(css_vars[k])
84
+ end
85
+
86
+ 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>)) % html_vars.merge(css_vars)
74
87
 
75
88
  # js vars
76
89
  js_vars = {
77
- type: klass, # don't convert to JSON, but still escape
90
+ type: klass.to_json,
78
91
  id: element_id.to_json,
79
92
  data: data_source.respond_to?(:chart_json) ? data_source.chart_json : data_source.to_json,
80
93
  options: options.to_json
@@ -82,9 +95,10 @@ module Chartkick
82
95
  js_vars.each_key do |k|
83
96
  js_vars[k] = chartkick_json_escape(js_vars[k])
84
97
  end
85
- createjs = "new Chartkick.%{type}(%{id}, %{data}, %{options});" % js_vars
98
+ createjs = "new Chartkick[%{type}](%{id}, %{data}, %{options});" % js_vars
86
99
 
87
100
  if defer
101
+ # TODO remove type in 4.0
88
102
  js = <<JS
89
103
  <script type="text/javascript"#{nonce_html}>
90
104
  (function() {
@@ -100,6 +114,7 @@ module Chartkick
100
114
  </script>
101
115
  JS
102
116
  else
117
+ # TODO remove type in 4.0
103
118
  js = <<JS
104
119
  <script type="text/javascript"#{nonce_html}>
105
120
  #{createjs}