chartkick 3.2.1 → 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: 93ec8731d7c59fefb8a68177487d611056e7b97ad239d71fb40e2fbe3ecb3765
4
- data.tar.gz: 188133762bb0f53b70bd5a4bde03f8fef59233affae22f007908b1f9effd7272
3
+ metadata.gz: 5afacd4c10d0cfddc6a2a660efead206ee042e80d48dd749f9de79feb365c1fd
4
+ data.tar.gz: c7fc99b0b2b467a6326df99f5832de2b3674f5f80415749cf57177142eecfc45
5
5
  SHA512:
6
- metadata.gz: d88b8cd9d7a5afef0a372a52c2b50e6833a445f3824ad14d00645d558546db8c1b3396c6a4c970510404eaa33bbae0bf816a582f77576d065f1e17e7ab5b7e59
7
- data.tar.gz: 63bc3b1d692d0fcaff545e326b632fd2f59cc71ff41bf414fa6df2568c7a712b7cdc1a53dd4a50244c5a80bce313c5ef6f37c72e4828f29bfc74be64850e2046
6
+ metadata.gz: 75b1793b427c5d9d4604b813773253adb864b6134fad48f952c72377f75da40c8daa19eaf06fd7ce0b2da31a1ba436cfe54bde318ac849ec2080652582ac7076
7
+ data.tar.gz: 8f47e12f6e9c746871d02f0d5bd3093da1017c5a222837696b5b0d7b7e4008c400c8556e4f85ec7b0ccd79c15a9cb510a91a7d9ecf896d1a106b7c82e68ddc36
@@ -1,27 +1,50 @@
1
- ## 3.2.1
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)
2
25
 
3
26
  - Updated Chartkick.js to 3.1.1
4
27
 
5
- ## 3.2.0
28
+ ## 3.2.0 (2019-06-04)
6
29
 
7
30
  - Fixed XSS vulnerability - see [#488](https://github.com/ankane/chartkick/issues/488)
8
31
 
9
- ## 3.1.0
32
+ ## 3.1.0 (2019-05-26)
10
33
 
11
34
  - Updated Chartkick.js to 3.1.0
12
35
  - Updated Chart.js to 2.8.0
13
36
 
14
- ## 3.0.2
37
+ ## 3.0.2 (2019-01-03)
15
38
 
16
39
  - Fixed error with `nonce` option with Secure Headers and Rails < 5.2
17
40
  - Updated Chartkick.js to 3.0.2
18
41
  - Updated Chart.js to 2.7.3
19
42
 
20
- ## 3.0.1
43
+ ## 3.0.1 (2018-08-13)
21
44
 
22
45
  - Updated Chartkick.js to 3.0.1
23
46
 
24
- ## 3.0.0
47
+ ## 3.0.0 (2018-08-08)
25
48
 
26
49
  - Updated Chartkick.js to 3.0.0
27
50
  - Added `code` option
@@ -35,55 +58,55 @@ Breaking changes
35
58
  - Removed `window.Chartkick = {...}` way to set config - use `Chartkick.configure` instead
36
59
  - Removed support for the Google Charts jsapi loader - use loader.js instead
37
60
 
38
- ## 2.3.5
61
+ ## 2.3.5 (2018-06-15)
39
62
 
40
63
  - Updated Chartkick.js to 2.3.6
41
64
 
42
- ## 2.3.4
65
+ ## 2.3.4 (2018-04-10)
43
66
 
44
67
  - Updated Chartkick.js to 2.3.5
45
68
  - Updated Chart.js to 2.7.2
46
69
 
47
- ## 2.3.3
70
+ ## 2.3.3 (2018-03-25)
48
71
 
49
72
  - Updated Chartkick.js to 2.3.4
50
73
 
51
- ## 2.3.2
74
+ ## 2.3.2 (2018-02-26)
52
75
 
53
76
  - Updated Chartkick.js to 2.3.3
54
77
 
55
- ## 2.3.1
78
+ ## 2.3.1 (2018-02-23)
56
79
 
57
80
  - Updated Chartkick.js to 2.3.1
58
81
 
59
- ## 2.3.0
82
+ ## 2.3.0 (2018-02-21)
60
83
 
61
84
  - Fixed deep merge error for non-Rails apps
62
85
  - Updated Chartkick.js to 2.3.0
63
86
 
64
- ## 2.2.5
87
+ ## 2.2.5 (2017-10-28)
65
88
 
66
89
  - Updated Chart.js to 2.7.1
67
90
 
68
- ## 2.2.4
91
+ ## 2.2.4 (2017-05-14)
69
92
 
70
93
  - Added compatibility with Rails API
71
94
  - Updated Chartkick.js to 2.2.4
72
95
 
73
- ## 2.2.3
96
+ ## 2.2.3 (2017-02-22)
74
97
 
75
98
  - Updated Chartkick.js to 2.2.3
76
99
  - Updated Chart.js to 2.5.0
77
100
 
78
- ## 2.2.2
101
+ ## 2.2.2 (2017-01-07)
79
102
 
80
103
  - Updated Chartkick.js to 2.2.2
81
104
 
82
- ## 2.2.1
105
+ ## 2.2.1 (2016-12-05)
83
106
 
84
107
  - Updated Chartkick.js to 2.2.1
85
108
 
86
- ## 2.2.0
109
+ ## 2.2.0 (2016-12-03)
87
110
 
88
111
  - Updated Chartkick.js to 2.2.0
89
112
  - Improved JavaScript API
@@ -91,59 +114,59 @@ Breaking changes
91
114
  - Added `refresh` option
92
115
  - Added `donut` option to pie chart
93
116
 
94
- ## 2.1.3
117
+ ## 2.1.3 (2016-11-29)
95
118
 
96
119
  - Updated Chartkick.js to 2.1.2 - fixes missing zero values for Chart.js
97
120
 
98
- ## 2.1.2
121
+ ## 2.1.2 (2016-11-28)
99
122
 
100
123
  - Added `defer` option
101
124
  - Added `nonce` option
102
125
  - Updated Chartkick.js to 2.1.1
103
126
 
104
- ## 2.1.1
127
+ ## 2.1.1 (2016-09-11)
105
128
 
106
129
  - Use custom version of Chart.js to fix label overlap
107
130
 
108
- ## 2.1.0
131
+ ## 2.1.0 (2016-09-10)
109
132
 
110
133
  - Added basic support for new Google Charts loader
111
134
  - Added `configure` function
112
135
  - Dropped jQuery and Zepto dependencies for AJAX
113
136
  - Updated Chart.js to 2.2.2
114
137
 
115
- ## 2.0.2
138
+ ## 2.0.2 (2016-08-11)
116
139
 
117
140
  - Updated Chartkick.js to 2.0.1
118
141
  - Updated Chart.js to 2.2.1
119
142
 
120
- ## 2.0.1
143
+ ## 2.0.1 (2016-07-29)
121
144
 
122
145
  - Small Chartkick.js fixes
123
146
  - Updated Chart.js to 2.2.0
124
147
 
125
- ## 2.0.0
148
+ ## 2.0.0 (2016-05-30)
126
149
 
127
150
  - Chart.js is now the default adapter - yay open source!
128
151
  - Axis types are automatically detected - no need for `discrete: true`
129
152
  - Better date support
130
153
  - New JavaScript API
131
154
 
132
- ## 1.5.2
155
+ ## 1.5.2 (2016-05-05)
133
156
 
134
157
  - Fixed Sprockets error
135
158
 
136
- ## 1.5.1
159
+ ## 1.5.1 (2016-05-03)
137
160
 
138
161
  - Updated chartkick.js to latest version
139
162
  - Included `Chart.bundle.js`
140
163
 
141
- ## 1.5.0
164
+ ## 1.5.0 (2016-05-01)
142
165
 
143
166
  - Added Chart.js adapter **beta**
144
167
  - Fixed line height on timeline charts
145
168
 
146
- ## 1.4.2
169
+ ## 1.4.2 (2016-02-29)
147
170
 
148
171
  - Added `width` option
149
172
  - Added `label` option
@@ -152,86 +175,86 @@ Breaking changes
152
175
  - Better tooltip for dates for Google Charts
153
176
  - Fixed asset precompilation issue with Rails 5
154
177
 
155
- ## 1.4.1
178
+ ## 1.4.1 (2015-09-07)
156
179
 
157
180
  - Fixed regression with `min: nil`
158
181
 
159
- ## 1.4.0
182
+ ## 1.4.0 (2015-08-31)
160
183
 
161
184
  - Added scatter chart
162
185
  - Added axis titles
163
186
 
164
- ## 1.3.2
187
+ ## 1.3.2 (2014-07-04)
165
188
 
166
189
  - Fixed `except` error when not using Rails
167
190
 
168
- ## 1.3.1
191
+ ## 1.3.1 (2014-06-30)
169
192
 
170
193
  - Fixed blank screen bug
171
194
  - Fixed language support
172
195
 
173
- ## 1.3.0
196
+ ## 1.3.0 (2014-06-28)
174
197
 
175
198
  - Added timelines
176
199
 
177
- ## 1.2.5
200
+ ## 1.2.5 (2014-06-12)
178
201
 
179
202
  - Added support for multiple groups
180
203
  - Added `html` option
181
204
 
182
- ## 1.2.4
205
+ ## 1.2.4 (2014-03-24)
183
206
 
184
207
  - Added global options
185
208
  - Added `colors` option
186
209
 
187
- ## 1.2.3
210
+ ## 1.2.3 (2014-03-23)
188
211
 
189
212
  - Added geo chart
190
213
  - Added `discrete` option
191
214
 
192
- ## 1.2.2
215
+ ## 1.2.2 (2014-02-23)
193
216
 
194
217
  - Added global `content_for` option
195
218
  - Added `stacked` option
196
219
 
197
- ## 1.2.1
220
+ ## 1.2.1 (2013-12-08)
198
221
 
199
222
  - Added localization for Google Charts
200
223
 
201
- ## 1.2.0
224
+ ## 1.2.0 (2013-07-27)
202
225
 
203
226
  - Added bar chart and area chart
204
227
  - Resize Google Charts on window resize
205
228
 
206
- ## 1.1.3
229
+ ## 1.1.3 (2013-06-26)
207
230
 
208
231
  - Added content_for option
209
232
 
210
- ## 1.1.2
233
+ ## 1.1.2 (2013-06-11)
211
234
 
212
235
  - Updated chartkick.js to v1.0.1
213
236
 
214
- ## 1.1.1
237
+ ## 1.1.1 (2013-06-10)
215
238
 
216
239
  - Added support for Sinatra
217
240
 
218
- ## 1.1.0
241
+ ## 1.1.0 (2013-06-03)
219
242
 
220
243
  - Added support for Padrino and Rails 2.3+
221
244
 
222
- ## 1.0.1
245
+ ## 1.0.1 (2013-05-23)
223
246
 
224
247
  - Updated chartkick.js to v1.0.1
225
248
 
226
- ## 1.0.0
249
+ ## 1.0.0 (2013-05-15)
227
250
 
228
251
  - Use semantic versioning (no changes)
229
252
 
230
- ## 0.0.5
253
+ ## 0.0.5 (2013-05-14)
231
254
 
232
255
  - Removed `:min => 0` default for charts with negative values
233
256
  - Show legend when data given in `{:name => "", :data => {}}` format
234
257
 
235
- ## 0.0.4
258
+ ## 0.0.4 (2013-05-13)
236
259
 
237
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,14 +63,27 @@ 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 = {
@@ -85,6 +98,7 @@ module Chartkick
85
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}