chartkick 3.1.0 → 3.2.0
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 +4 -0
- data/README.md +1 -3
- data/lib/chartkick/helper.rb +33 -2
- data/lib/chartkick/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b6eb4f5b6f498a122e58ca1dd4cf7e3e1f5d610e19faa5a702291e422549026
|
4
|
+
data.tar.gz: ec143cc0f819cdd1ccd955f43425d992daa87052aeede53f563beda9bace04a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a494948bc4eeb5c1567e82777601982d7f3f90bfeb5c8b8b29335620cc0eaac7659a8b91e72fe9672d29a3b580b2c512fd0524c553be2de9fb57b4dcfa27b7a
|
7
|
+
data.tar.gz: 9f2e116c8c529e744e078b368ece8aebd7235dec00aa297a0745f309a494e57a2e29b2243dd5873d159a4346be0ee331f1df474f2a4166133a8a9e6159a0e9d7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -29,8 +29,6 @@ require("chartkick")
|
|
29
29
|
require("chart.js")
|
30
30
|
```
|
31
31
|
|
32
|
-
> You can also use `import` instead of `require()`
|
33
|
-
|
34
32
|
For Rails 5 / Sprockets, in `app/assets/javascripts/application.js`, add:
|
35
33
|
|
36
34
|
```js
|
@@ -148,7 +146,7 @@ Min and max values
|
|
148
146
|
|
149
147
|
`min` defaults to 0 for charts with non-negative values. Use `nil` to let the charting library decide.
|
150
148
|
|
151
|
-
Min and max for x-axis - *Chart.js*
|
149
|
+
Min and max for x-axis - *Chart.js*
|
152
150
|
|
153
151
|
```erb
|
154
152
|
<%= line_chart data, xmin: "2018-01-01", xmax: "2019-01-01" %>
|
data/lib/chartkick/helper.rb
CHANGED
@@ -61,9 +61,29 @@ module Chartkick
|
|
61
61
|
end
|
62
62
|
nonce_html = nonce ? " nonce=\"#{ERB::Util.html_escape(nonce)}\"" : nil
|
63
63
|
|
64
|
-
|
64
|
+
# html vars
|
65
|
+
html_vars = {
|
66
|
+
id: element_id,
|
67
|
+
height: height,
|
68
|
+
width: width
|
69
|
+
}
|
70
|
+
html_vars.each_key do |k|
|
71
|
+
html_vars[k] = ERB::Util.html_escape(html_vars[k])
|
72
|
+
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
|
74
|
+
|
75
|
+
# js vars
|
76
|
+
js_vars = {
|
77
|
+
type: klass, # don't convert to JSON, but still escape
|
78
|
+
id: element_id.to_json,
|
79
|
+
data: data_source.respond_to?(:chart_json) ? data_source.chart_json : data_source.to_json,
|
80
|
+
options: options.to_json
|
81
|
+
}
|
82
|
+
js_vars.each_key do |k|
|
83
|
+
js_vars[k] = chartkick_json_escape(js_vars[k])
|
84
|
+
end
|
85
|
+
createjs = "new Chartkick.%{type}(%{id}, %{data}, %{options});" % js_vars
|
65
86
|
|
66
|
-
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});"
|
67
87
|
if defer
|
68
88
|
js = <<JS
|
69
89
|
<script type="text/javascript"#{nonce_html}>
|
@@ -105,5 +125,16 @@ JS
|
|
105
125
|
end
|
106
126
|
hash_a
|
107
127
|
end
|
128
|
+
|
129
|
+
# from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/output_safety.rb
|
130
|
+
JSON_ESCAPE = { "&" => '\u0026', ">" => '\u003e', "<" => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
|
131
|
+
JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u
|
132
|
+
def chartkick_json_escape(s)
|
133
|
+
if ERB::Util.respond_to?(:json_escape)
|
134
|
+
ERB::Util.json_escape(s)
|
135
|
+
else
|
136
|
+
s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
|
137
|
+
end
|
138
|
+
end
|
108
139
|
end
|
109
140
|
end
|
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: 3.
|
4
|
+
version: 3.2.0
|
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
|
+
date: 2019-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|