chartkick 4.2.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/LICENSE.txt +1 -1
- data/README.md +18 -27
- data/lib/chartkick/core_ext.rb +26 -0
- data/lib/chartkick/helper.rb +3 -27
- data/lib/chartkick/utils.rb +24 -0
- data/lib/chartkick/version.rb +1 -1
- data/lib/chartkick.rb +10 -5
- data/licenses/LICENSE-kurkle-color.txt +9 -0
- data/vendor/assets/javascripts/Chart.bundle.js +11339 -9427
- data/vendor/assets/javascripts/chartkick.js +636 -616
- metadata +7 -5
- data/lib/chartkick/enumerable.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e3e26d84662ff0821322864aa4481daefc1c8a33c90210cf69fa3e2641122c1
|
4
|
+
data.tar.gz: 65098ca753ee49fa221f93dc24cd630bc007a0bfbe81885143287c3640f1f221
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 781b9376d0f979e0fee356b5f872bbe339d2975c1fd46833262bc16476f83e0e2dc0149452616915a4c5eab323022db901b416722146dc7982fdc1a71bdc7240
|
7
|
+
data.tar.gz: ff8d09974073e3b09555654770c6d42534d0dffd87271b5f79d6bc15b58a5cec6d9695d23541e69ac32cafb428790ddf0fb6f697f5631bf1a3dca5aa5d1da44b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 5.0.0 (2022-01-18)
|
2
|
+
|
3
|
+
- Added support for Chart.js 4
|
4
|
+
- Changed `chart_json` to be defined on `Hash` and `Array` instead of `Enumerable`
|
5
|
+
- Updated Chartkick.js to 5.0.0
|
6
|
+
- Removed support for Chart.js 3
|
7
|
+
- Removed support for Ruby < 2.7 and Rails < 6
|
8
|
+
|
9
|
+
## 4.2.1 (2022-08-02)
|
10
|
+
|
11
|
+
- Updated Chart.js to 3.9.0
|
12
|
+
|
1
13
|
## 4.2.0 (2022-06-12)
|
2
14
|
|
3
15
|
- Updated Chartkick.js to 4.2.0
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,8 @@ Create beautiful JavaScript charts with one line of Ruby. No more fighting with
|
|
4
4
|
|
5
5
|
[See it in action](https://chartkick.com)
|
6
6
|
|
7
|
+
**Chartkick 5.0 was recently released** - see [how to upgrade](#upgrading)
|
8
|
+
|
7
9
|
:fire: For admin charts and dashboards, check out [Blazer](https://github.com/ankane/blazer/), and for advanced visualizations, check out [Vega](https://github.com/ankane/vega)
|
8
10
|
|
9
11
|
: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)
|
@@ -18,16 +20,16 @@ Add this line to your application’s Gemfile:
|
|
18
20
|
gem "chartkick"
|
19
21
|
```
|
20
22
|
|
21
|
-
Then follow the instructions for your
|
23
|
+
Then follow the instructions for your JavaScript setup:
|
22
24
|
|
23
|
-
- [
|
24
|
-
- [
|
25
|
-
- [
|
26
|
-
- [
|
25
|
+
- [Importmap](#rails-7--importmap) (Rails 7 default)
|
26
|
+
- [esbuild, rollup.js, or Webpack](#rails-7--esbuild-rollupjs-or-webpack)
|
27
|
+
- [Webpacker](#rails-6--webpacker) (Rails 6 default)
|
28
|
+
- [Sprockets](#rails-5--sprockets)
|
27
29
|
|
28
30
|
This sets up Chartkick with [Chart.js](https://www.chartjs.org/). For other charting libraries and frameworks, see [detailed instructions](#installation).
|
29
31
|
|
30
|
-
###
|
32
|
+
### Importmap
|
31
33
|
|
32
34
|
In `config/importmap.rb`, add:
|
33
35
|
|
@@ -43,7 +45,7 @@ import "chartkick"
|
|
43
45
|
import "Chart.bundle"
|
44
46
|
```
|
45
47
|
|
46
|
-
###
|
48
|
+
### esbuild, rollup.js, or Webpack
|
47
49
|
|
48
50
|
Run:
|
49
51
|
|
@@ -57,7 +59,9 @@ And in `app/javascript/application.js`, add:
|
|
57
59
|
import "chartkick/chart.js"
|
58
60
|
```
|
59
61
|
|
60
|
-
|
62
|
+
Note: For rollup.js, this requires `format: "iife"` in `rollup.config.js`.
|
63
|
+
|
64
|
+
### Webpacker
|
61
65
|
|
62
66
|
Run:
|
63
67
|
|
@@ -71,7 +75,7 @@ And in `app/javascript/packs/application.js`, add:
|
|
71
75
|
import "chartkick/chart.js"
|
72
76
|
```
|
73
77
|
|
74
|
-
###
|
78
|
+
### Sprockets
|
75
79
|
|
76
80
|
In `app/assets/javascripts/application.js`, add:
|
77
81
|
|
@@ -447,7 +451,7 @@ gem "chartkick"
|
|
447
451
|
|
448
452
|
Next, choose your charting library.
|
449
453
|
|
450
|
-
- [Chart.js](#
|
454
|
+
- [Chart.js](#chartjs)
|
451
455
|
- [Google Charts](#google-charts)
|
452
456
|
- [Highcharts](#highcharts)
|
453
457
|
|
@@ -691,35 +695,22 @@ Check out [chartkick.js](https://github.com/ankane/chartkick.js)
|
|
691
695
|
|
692
696
|
## Upgrading
|
693
697
|
|
694
|
-
###
|
698
|
+
### 5.0
|
695
699
|
|
696
|
-
If you use Sprockets, update the gem and you’re good to go!
|
700
|
+
If you use Importmaps or Sprockets, update the gem and you’re good to go!
|
697
701
|
|
698
|
-
If you use Webpacker, run:
|
702
|
+
If you use esbuild, Webpack, or Webpacker, run:
|
699
703
|
|
700
704
|
```sh
|
701
705
|
yarn upgrade chartkick --latest
|
702
706
|
```
|
703
707
|
|
704
|
-
If you use Chart.js with Webpacker, also run:
|
708
|
+
If you use Chart.js with esbuild, Webpack, or Webpacker, also run:
|
705
709
|
|
706
710
|
```sh
|
707
711
|
yarn upgrade chart.js --latest
|
708
712
|
```
|
709
713
|
|
710
|
-
And in `app/javascript/packs/application.js`, change:
|
711
|
-
|
712
|
-
```js
|
713
|
-
require("chartkick")
|
714
|
-
require("chart.js")
|
715
|
-
```
|
716
|
-
|
717
|
-
to:
|
718
|
-
|
719
|
-
```js
|
720
|
-
require("chartkick/chart.js")
|
721
|
-
```
|
722
|
-
|
723
714
|
## History
|
724
715
|
|
725
716
|
View the [changelog](https://github.com/ankane/chartkick/blob/master/CHANGELOG.md)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# for both multiple series and
|
2
|
+
# making sure hash order is preserved in JavaScript
|
3
|
+
|
4
|
+
class Array
|
5
|
+
def chart_json
|
6
|
+
map do |v|
|
7
|
+
if v.is_a?(Hash) && v[:data].is_a?(Hash)
|
8
|
+
v = v.dup
|
9
|
+
v[:data] = v[:data].to_a
|
10
|
+
end
|
11
|
+
v
|
12
|
+
end.to_json
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Hash
|
17
|
+
def chart_json
|
18
|
+
if (key = keys.first) && key.is_a?(Array) && key.size == 2
|
19
|
+
group_by { |k, _v| k[0] }.map do |name, data|
|
20
|
+
{name: name, data: data.map { |k, v| [k[1], v] }}
|
21
|
+
end
|
22
|
+
else
|
23
|
+
to_a
|
24
|
+
end.to_json
|
25
|
+
end
|
26
|
+
end
|
data/lib/chartkick/helper.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require "json"
|
2
|
-
require "erb"
|
3
|
-
|
4
1
|
module Chartkick
|
5
2
|
module Helper
|
6
3
|
def line_chart(data_source, **options)
|
@@ -39,7 +36,7 @@ module Chartkick
|
|
39
36
|
|
40
37
|
# don't break out options since need to merge with default options
|
41
38
|
def chartkick_chart(klass, data_source, **options)
|
42
|
-
options =
|
39
|
+
options = Chartkick::Utils.deep_merge(Chartkick.options, options)
|
43
40
|
|
44
41
|
@chartkick_chart_id ||= 0
|
45
42
|
element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}"
|
@@ -57,7 +54,7 @@ module Chartkick
|
|
57
54
|
# Secure Headers also defines content_security_policy_nonce but it takes an argument
|
58
55
|
# Rails 5.2 overrides this method, but earlier versions do not
|
59
56
|
if respond_to?(:content_security_policy_nonce) && (content_security_policy_nonce rescue nil)
|
60
|
-
# Rails 5.2
|
57
|
+
# Rails 5.2+
|
61
58
|
nonce = content_security_policy_nonce
|
62
59
|
elsif respond_to?(:content_security_policy_script_nonce)
|
63
60
|
# Secure Headers
|
@@ -101,7 +98,7 @@ module Chartkick
|
|
101
98
|
options: options.to_json
|
102
99
|
}
|
103
100
|
js_vars.each_key do |k|
|
104
|
-
js_vars[k] =
|
101
|
+
js_vars[k] = Chartkick::Utils.json_escape(js_vars[k])
|
105
102
|
end
|
106
103
|
createjs = "new Chartkick[%{type}](%{id}, %{data}, %{options});" % js_vars
|
107
104
|
|
@@ -137,26 +134,5 @@ module Chartkick
|
|
137
134
|
|
138
135
|
html.respond_to?(:html_safe) ? html.html_safe : html
|
139
136
|
end
|
140
|
-
|
141
|
-
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
|
142
|
-
def chartkick_deep_merge(hash_a, hash_b)
|
143
|
-
hash_a = hash_a.dup
|
144
|
-
hash_b.each_pair do |k, v|
|
145
|
-
tv = hash_a[k]
|
146
|
-
hash_a[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? chartkick_deep_merge(tv, v) : v
|
147
|
-
end
|
148
|
-
hash_a
|
149
|
-
end
|
150
|
-
|
151
|
-
# from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/output_safety.rb
|
152
|
-
JSON_ESCAPE = { "&" => '\u0026', ">" => '\u003e', "<" => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
|
153
|
-
JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u
|
154
|
-
def chartkick_json_escape(s)
|
155
|
-
if ERB::Util.respond_to?(:json_escape)
|
156
|
-
ERB::Util.json_escape(s)
|
157
|
-
else
|
158
|
-
s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
|
159
|
-
end
|
160
|
-
end
|
161
137
|
end
|
162
138
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Chartkick
|
2
|
+
module Utils
|
3
|
+
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
|
4
|
+
def self.deep_merge(hash_a, hash_b)
|
5
|
+
hash_a = hash_a.dup
|
6
|
+
hash_b.each_pair do |k, v|
|
7
|
+
tv = hash_a[k]
|
8
|
+
hash_a[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? deep_merge(tv, v) : v
|
9
|
+
end
|
10
|
+
hash_a
|
11
|
+
end
|
12
|
+
|
13
|
+
# from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/output_safety.rb
|
14
|
+
JSON_ESCAPE = { "&" => '\u0026', ">" => '\u003e', "<" => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
|
15
|
+
JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u
|
16
|
+
def self.json_escape(s)
|
17
|
+
if ERB::Util.respond_to?(:json_escape)
|
18
|
+
ERB::Util.json_escape(s)
|
19
|
+
else
|
20
|
+
s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/chartkick/version.rb
CHANGED
data/lib/chartkick.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
|
+
# stdlib
|
2
|
+
require "erb"
|
3
|
+
require "json"
|
4
|
+
|
1
5
|
# modules
|
2
|
-
|
3
|
-
|
4
|
-
|
6
|
+
require_relative "chartkick/core_ext"
|
7
|
+
require_relative "chartkick/helper"
|
8
|
+
require_relative "chartkick/utils"
|
9
|
+
require_relative "chartkick/version"
|
5
10
|
|
6
11
|
# integrations
|
7
|
-
|
8
|
-
|
12
|
+
require_relative "chartkick/engine" if defined?(Rails)
|
13
|
+
require_relative "chartkick/sinatra" if defined?(Sinatra)
|
9
14
|
|
10
15
|
if defined?(ActiveSupport.on_load)
|
11
16
|
ActiveSupport.on_load(:action_view) do
|
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018-2021 Jukka Kurkela
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|