chartkick 4.2.1 → 5.2.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 +4 -4
- data/CHANGELOG.md +78 -0
- data/LICENSE.txt +1 -1
- data/README.md +39 -127
- data/lib/chartkick/core_ext.rb +26 -0
- data/lib/chartkick/engine.rb +1 -1
- data/lib/chartkick/helper.rb +4 -28
- data/lib/chartkick/utils.rb +24 -0
- data/lib/chartkick/version.rb +1 -1
- data/lib/chartkick.rb +10 -5
- data/licenses/LICENSE-chart.js.txt +1 -1
- data/licenses/LICENSE-kurkle-color.txt +9 -0
- data/vendor/assets/javascripts/Chart.bundle.js +7599 -10161
- data/vendor/assets/javascripts/chartkick.js +673 -621
- metadata +7 -9
- 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: 7a5f1633a78d2567d005d45366a1d13e85c98feb784220658270ac32b0bd666e
|
4
|
+
data.tar.gz: b317306658b5e4f557c1acf9a6c1055acf1dff9e284f3927ebf25a60bb8c87f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83675f87191af965cdee382091eb73206f48614ba4b668619e7d396664f4695def489cccfd824d84b22d7ea1ca0fae0e866c5ecc467829115faf2e329d7538df
|
7
|
+
data.tar.gz: 73e8abf43cf9f35221610e20f5c18e0804496aa7c7197b648314e0b74a95e70106cb400511cbae9eb83b8b173d04b260991f1aee43f07a6569b37076e8fc5887
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,69 @@
|
|
1
|
+
## 5.2.0 (2025-06-16)
|
2
|
+
|
3
|
+
- Updated Chart.js to 4.5.0
|
4
|
+
- Dropped support for Ruby < 3.2
|
5
|
+
|
6
|
+
## 5.1.5 (2025-04-15)
|
7
|
+
|
8
|
+
- Updated Chart.js to 4.4.9
|
9
|
+
|
10
|
+
## 5.1.4 (2025-02-19)
|
11
|
+
|
12
|
+
- Updated Chart.js to 4.4.8
|
13
|
+
|
14
|
+
## 5.1.3 (2025-02-01)
|
15
|
+
|
16
|
+
- Updated Chart.js to 4.4.7
|
17
|
+
|
18
|
+
## 5.1.2 (2024-10-29)
|
19
|
+
|
20
|
+
- Updated Chart.js to 4.4.6
|
21
|
+
|
22
|
+
## 5.1.1 (2024-10-16)
|
23
|
+
|
24
|
+
- Updated Chart.js to 4.4.5
|
25
|
+
|
26
|
+
## 5.1.0 (2024-08-20)
|
27
|
+
|
28
|
+
- Updated Chart.js to 4.4.4
|
29
|
+
- Dropped support for Ruby < 3.1
|
30
|
+
|
31
|
+
## 5.0.7 (2024-05-21)
|
32
|
+
|
33
|
+
- Updated Chart.js to 4.4.3
|
34
|
+
|
35
|
+
## 5.0.6 (2024-02-28)
|
36
|
+
|
37
|
+
- Updated Chart.js to 4.4.2
|
38
|
+
|
39
|
+
## 5.0.5 (2023-12-07)
|
40
|
+
|
41
|
+
- Updated Chart.js to 4.4.1
|
42
|
+
|
43
|
+
## 5.0.4 (2023-08-27)
|
44
|
+
|
45
|
+
- Updated Chart.js to 4.4.0
|
46
|
+
|
47
|
+
## 5.0.3 (2023-07-24)
|
48
|
+
|
49
|
+
- Updated Chart.js to 4.3.1
|
50
|
+
|
51
|
+
## 5.0.2 (2023-05-02)
|
52
|
+
|
53
|
+
- Updated Chart.js to 4.3.0
|
54
|
+
|
55
|
+
## 5.0.1 (2023-01-19)
|
56
|
+
|
57
|
+
- Updated Chartkick.js to 5.0.1
|
58
|
+
|
59
|
+
## 5.0.0 (2023-01-18)
|
60
|
+
|
61
|
+
- Added support for Chart.js 4
|
62
|
+
- Changed `chart_json` to be defined on `Hash` and `Array` instead of `Enumerable`
|
63
|
+
- Updated Chartkick.js to 5.0.0
|
64
|
+
- Removed support for Chart.js 3
|
65
|
+
- Removed support for Ruby < 2.7 and Rails < 6
|
66
|
+
|
1
67
|
## 4.2.1 (2022-08-02)
|
2
68
|
|
3
69
|
- Updated Chart.js to 3.9.0
|
@@ -334,3 +400,15 @@ Breaking changes
|
|
334
400
|
## 0.0.4 (2013-05-13)
|
335
401
|
|
336
402
|
- Fix for `Uncaught ReferenceError: Chartkick is not defined` when chartkick.js is included in the `<head>`
|
403
|
+
|
404
|
+
## 0.0.3 (2013-05-12)
|
405
|
+
|
406
|
+
- Improved error messages
|
407
|
+
|
408
|
+
## 0.0.2 (2013-05-10)
|
409
|
+
|
410
|
+
- Added `min` and `max` options
|
411
|
+
|
412
|
+
## 0.0.1 (2013-05-07)
|
413
|
+
|
414
|
+
- First release
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ 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
|
-
[](https://github.com/ankane/chartkick/actions)
|
12
12
|
|
13
13
|
## Quick Start
|
14
14
|
|
@@ -18,16 +18,15 @@ Add this line to your application’s Gemfile:
|
|
18
18
|
gem "chartkick"
|
19
19
|
```
|
20
20
|
|
21
|
-
Then follow the instructions for your
|
21
|
+
Then follow the instructions for your JavaScript setup:
|
22
22
|
|
23
|
-
- [
|
24
|
-
- [
|
25
|
-
- [
|
26
|
-
- [Rails 5 / Sprockets](#rails-5--sprockets)
|
23
|
+
- [Importmap](#importmap) (Rails 7+ default)
|
24
|
+
- [Bun, esbuild, rollup.js, or Webpack](#bun-esbuild-rollupjs-or-webpack)
|
25
|
+
- [Sprockets](#sprockets)
|
27
26
|
|
28
|
-
This sets up Chartkick with [Chart.js](https://www.chartjs.org/). For other charting libraries and frameworks, see [
|
27
|
+
This sets up Chartkick with [Chart.js](https://www.chartjs.org/). For other charting libraries and frameworks, see [these instructions](#additional-charting-libraries).
|
29
28
|
|
30
|
-
###
|
29
|
+
### Importmap
|
31
30
|
|
32
31
|
In `config/importmap.rb`, add:
|
33
32
|
|
@@ -43,11 +42,13 @@ import "chartkick"
|
|
43
42
|
import "Chart.bundle"
|
44
43
|
```
|
45
44
|
|
46
|
-
###
|
45
|
+
### Bun, esbuild, rollup.js, or Webpack
|
47
46
|
|
48
47
|
Run:
|
49
48
|
|
50
49
|
```sh
|
50
|
+
bun add chartkick chart.js
|
51
|
+
# or
|
51
52
|
yarn add chartkick chart.js
|
52
53
|
```
|
53
54
|
|
@@ -57,21 +58,7 @@ And in `app/javascript/application.js`, add:
|
|
57
58
|
import "chartkick/chart.js"
|
58
59
|
```
|
59
60
|
|
60
|
-
###
|
61
|
-
|
62
|
-
Run:
|
63
|
-
|
64
|
-
```sh
|
65
|
-
yarn add chartkick chart.js
|
66
|
-
```
|
67
|
-
|
68
|
-
And in `app/javascript/packs/application.js`, add:
|
69
|
-
|
70
|
-
```js
|
71
|
-
import "chartkick/chart.js"
|
72
|
-
```
|
73
|
-
|
74
|
-
### Rails 5 / Sprockets
|
61
|
+
### Sprockets
|
75
62
|
|
76
63
|
In `app/assets/javascripts/application.js`, add:
|
77
64
|
|
@@ -138,8 +125,8 @@ Multiple series
|
|
138
125
|
|
139
126
|
```erb
|
140
127
|
<%= line_chart [
|
141
|
-
{name: "Workout", data: {"
|
142
|
-
{name: "Call parents", data: {"
|
128
|
+
{name: "Workout", data: {"2025-01-01" => 3, "2025-01-02" => 4}},
|
129
|
+
{name: "Call parents", data: {"2025-01-01" => 5, "2025-01-02" => 3}}
|
143
130
|
] %>
|
144
131
|
```
|
145
132
|
|
@@ -156,13 +143,13 @@ Data can be a hash, array, or URL.
|
|
156
143
|
#### Hash
|
157
144
|
|
158
145
|
```erb
|
159
|
-
<%= line_chart({"
|
146
|
+
<%= line_chart({"2025-01-01" => 2, "2025-01-02" => 3}) %>
|
160
147
|
```
|
161
148
|
|
162
149
|
#### Array
|
163
150
|
|
164
151
|
```erb
|
165
|
-
<%= line_chart [["
|
152
|
+
<%= line_chart [["2025-01-01", 2], ["2025-01-02", 3]] %>
|
166
153
|
```
|
167
154
|
|
168
155
|
#### URL
|
@@ -208,7 +195,7 @@ Min and max values
|
|
208
195
|
Min and max for x-axis - *Chart.js*
|
209
196
|
|
210
197
|
```erb
|
211
|
-
<%= line_chart data, xmin: "
|
198
|
+
<%= line_chart data, xmin: "2025-01-01", xmax: "2025-02-01" %>
|
212
199
|
```
|
213
200
|
|
214
201
|
Colors
|
@@ -343,7 +330,7 @@ You can pass options directly to the charting library with:
|
|
343
330
|
<%= line_chart data, library: {backgroundColor: "#eee"} %>
|
344
331
|
```
|
345
332
|
|
346
|
-
See the documentation for [Chart.js](https://www.chartjs.org/docs/), [Google Charts](https://developers.google.com/chart/interactive/docs/gallery), and [Highcharts](https://api.highcharts.com/highcharts) for more info.
|
333
|
+
See the documentation for [Chart.js](https://www.chartjs.org/docs/), [Google Charts](https://developers.google.com/chart/interactive/docs/gallery), and [Highcharts](https://api.highcharts.com/highcharts) for more info. For Chart.js plugins, check out [this guide](guides/Chartjs-Plugins.md).
|
347
334
|
|
348
335
|
To customize datasets in Chart.js, use:
|
349
336
|
|
@@ -437,55 +424,11 @@ Set title
|
|
437
424
|
<%= line_chart data, title: "Awesome chart" %>
|
438
425
|
```
|
439
426
|
|
440
|
-
##
|
441
|
-
|
442
|
-
Add this line to your application's Gemfile:
|
427
|
+
## Additional Charting Libraries
|
443
428
|
|
444
|
-
```ruby
|
445
|
-
gem "chartkick"
|
446
|
-
```
|
447
|
-
|
448
|
-
Next, choose your charting library.
|
449
|
-
|
450
|
-
- [Chart.js](#chart-js)
|
451
429
|
- [Google Charts](#google-charts)
|
452
430
|
- [Highcharts](#highcharts)
|
453
431
|
|
454
|
-
### Chart.js
|
455
|
-
|
456
|
-
For Rails 7 / Importmap, in `config/importmap.rb`, add:
|
457
|
-
|
458
|
-
```ruby
|
459
|
-
pin "chartkick", to: "chartkick.js"
|
460
|
-
pin "Chart.bundle", to: "Chart.bundle.js"
|
461
|
-
```
|
462
|
-
|
463
|
-
And in `app/javascript/application.js`, add:
|
464
|
-
|
465
|
-
```js
|
466
|
-
import "chartkick"
|
467
|
-
import "Chart.bundle"
|
468
|
-
```
|
469
|
-
|
470
|
-
For Rails 6 / Webpacker, run:
|
471
|
-
|
472
|
-
```sh
|
473
|
-
yarn add chartkick chart.js
|
474
|
-
```
|
475
|
-
|
476
|
-
And in `app/javascript/packs/application.js`, add:
|
477
|
-
|
478
|
-
```js
|
479
|
-
import "chartkick/chart.js"
|
480
|
-
```
|
481
|
-
|
482
|
-
For Rails 5 / Sprockets, in `app/assets/javascripts/application.js`, add:
|
483
|
-
|
484
|
-
```js
|
485
|
-
//= require chartkick
|
486
|
-
//= require Chart.bundle
|
487
|
-
```
|
488
|
-
|
489
432
|
### Google Charts
|
490
433
|
|
491
434
|
In your layout or views, add:
|
@@ -494,7 +437,7 @@ In your layout or views, add:
|
|
494
437
|
<%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" %>
|
495
438
|
```
|
496
439
|
|
497
|
-
For Rails 7
|
440
|
+
For Importmap (Rails 7+ default), in `config/importmap.rb`, add:
|
498
441
|
|
499
442
|
```ruby
|
500
443
|
pin "chartkick", to: "chartkick.js"
|
@@ -506,9 +449,11 @@ And in `app/javascript/application.js`, add:
|
|
506
449
|
import "chartkick"
|
507
450
|
```
|
508
451
|
|
509
|
-
For
|
452
|
+
For Bun, esbuild, rollup.js, or Webpack, run:
|
510
453
|
|
511
454
|
```sh
|
455
|
+
bun add chartkick
|
456
|
+
# or
|
512
457
|
yarn add chartkick
|
513
458
|
```
|
514
459
|
|
@@ -518,7 +463,7 @@ And in `app/javascript/packs/application.js`, add:
|
|
518
463
|
import "chartkick"
|
519
464
|
```
|
520
465
|
|
521
|
-
For
|
466
|
+
For Sprockets, in `app/assets/javascripts/application.js`, add:
|
522
467
|
|
523
468
|
```js
|
524
469
|
//= require chartkick
|
@@ -534,7 +479,7 @@ before your charts.
|
|
534
479
|
|
535
480
|
### Highcharts
|
536
481
|
|
537
|
-
For Rails 7
|
482
|
+
For Importmap (Rails 7+ default), run:
|
538
483
|
|
539
484
|
```sh
|
540
485
|
bin/importmap pin highcharts --download
|
@@ -555,9 +500,11 @@ import Highcharts from "highcharts"
|
|
555
500
|
window.Highcharts = Highcharts
|
556
501
|
```
|
557
502
|
|
558
|
-
For
|
503
|
+
For Bun, esbuild, rollup.js, or Webpack, run:
|
559
504
|
|
560
505
|
```sh
|
506
|
+
bun add chartkick highcharts
|
507
|
+
# or
|
561
508
|
yarn add chartkick highcharts
|
562
509
|
```
|
563
510
|
|
@@ -567,14 +514,22 @@ And in `app/javascript/packs/application.js`, add:
|
|
567
514
|
import "chartkick/highcharts"
|
568
515
|
```
|
569
516
|
|
570
|
-
For
|
517
|
+
For Sprockets, download [highcharts.js](https://code.highcharts.com/highcharts.js) into `vendor/assets/javascripts` (or use `yarn add highcharts`), and in `app/assets/javascripts/application.js`, add:
|
571
518
|
|
572
519
|
```js
|
573
520
|
//= require chartkick
|
574
521
|
//= require highcharts
|
575
522
|
```
|
576
523
|
|
577
|
-
###
|
524
|
+
### Multiple Libraries
|
525
|
+
|
526
|
+
If more than one charting library is loaded, choose between them with:
|
527
|
+
|
528
|
+
```erb
|
529
|
+
<%= line_chart data, adapter: "google" %> <!-- or highcharts or chartjs -->
|
530
|
+
```
|
531
|
+
|
532
|
+
## Sinatra and Padrino
|
578
533
|
|
579
534
|
Download [chartkick.js](https://raw.githubusercontent.com/ankane/chartkick/master/vendor/assets/javascripts/chartkick.js) and include it manually.
|
580
535
|
|
@@ -584,7 +539,7 @@ Download [chartkick.js](https://raw.githubusercontent.com/ankane/chartkick/maste
|
|
584
539
|
|
585
540
|
Then include the charting library.
|
586
541
|
|
587
|
-
Chart.js - download [Chart.js](https://unpkg.com/chart.js@
|
542
|
+
Chart.js - download [Chart.js](https://unpkg.com/chart.js@4/dist/chart.umd.js) and the [date-fns adapter bundle](https://unpkg.com/chartjs-adapter-date-fns@3/dist/chartjs-adapter-date-fns.bundle.js)
|
588
543
|
|
589
544
|
```html
|
590
545
|
<script src="chart.js"></script>
|
@@ -603,14 +558,6 @@ Highcharts - download [highcharts.js](https://code.highcharts.com/highcharts.js)
|
|
603
558
|
<script src="highcharts.js"></script>
|
604
559
|
```
|
605
560
|
|
606
|
-
### Multiple Libraries
|
607
|
-
|
608
|
-
If more than one charting library is loaded, choose between them with:
|
609
|
-
|
610
|
-
```erb
|
611
|
-
<%= line_chart data, adapter: "google" %> <!-- or highcharts or chartjs -->
|
612
|
-
```
|
613
|
-
|
614
561
|
## JavaScript API
|
615
562
|
|
616
563
|
Access a chart with:
|
@@ -669,7 +616,7 @@ chart.destroy()
|
|
669
616
|
Loop over charts with:
|
670
617
|
|
671
618
|
```javascript
|
672
|
-
Chartkick.eachChart(
|
619
|
+
Chartkick.eachChart(function (chart) {
|
673
620
|
// do something
|
674
621
|
})
|
675
622
|
```
|
@@ -678,10 +625,6 @@ Chartkick.eachChart( function(chart) {
|
|
678
625
|
|
679
626
|
Check out [how to configure CSP](https://github.com/ankane/chartkick/blob/master/guides/Content-Security-Policy.md)
|
680
627
|
|
681
|
-
## No Ruby? No Problem
|
682
|
-
|
683
|
-
Check out [chartkick.js](https://github.com/ankane/chartkick.js)
|
684
|
-
|
685
628
|
## Tutorials
|
686
629
|
|
687
630
|
- [Charts with Chartkick and Groupdate](https://gorails.com/episodes/charts-with-chartkick-and-groupdate)
|
@@ -689,37 +632,6 @@ Check out [chartkick.js](https://github.com/ankane/chartkick.js)
|
|
689
632
|
- [Make Easy Graphs and Charts on Rails with Chartkick](https://www.sitepoint.com/make-easy-graphs-and-charts-on-rails-with-chartkick/)
|
690
633
|
- [Practical Graphs on Rails: Chartkick in Practice](https://www.sitepoint.com/graphs-on-rails-chartkick-in-practice/)
|
691
634
|
|
692
|
-
## Upgrading
|
693
|
-
|
694
|
-
### 4.0
|
695
|
-
|
696
|
-
If you use Sprockets, update the gem and you’re good to go!
|
697
|
-
|
698
|
-
If you use Webpacker, run:
|
699
|
-
|
700
|
-
```sh
|
701
|
-
yarn upgrade chartkick --latest
|
702
|
-
```
|
703
|
-
|
704
|
-
If you use Chart.js with Webpacker, also run:
|
705
|
-
|
706
|
-
```sh
|
707
|
-
yarn upgrade chart.js --latest
|
708
|
-
```
|
709
|
-
|
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
635
|
## History
|
724
636
|
|
725
637
|
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/engine.rb
CHANGED
@@ -4,7 +4,7 @@ module Chartkick
|
|
4
4
|
|
5
5
|
# for importmap
|
6
6
|
initializer "chartkick.importmap" do |app|
|
7
|
-
if defined?(Importmap)
|
7
|
+
if app.config.respond_to?(:assets) && defined?(Importmap) && defined?(Sprockets)
|
8
8
|
app.config.assets.precompile << "chartkick.js"
|
9
9
|
app.config.assets.precompile << "Chart.bundle.js"
|
10
10
|
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
|
@@ -81,7 +78,7 @@ module Chartkick
|
|
81
78
|
# limit to alphanumeric and % for simplicity
|
82
79
|
# this prevents things like calc() but safety is the priority
|
83
80
|
# dot does not need escaped in square brackets
|
84
|
-
raise ArgumentError, "Invalid #{k}" unless
|
81
|
+
raise ArgumentError, "Invalid #{k}" unless /\A[a-zA-Z0-9%.]*\z/.match?(html_vars[k])
|
85
82
|
end
|
86
83
|
|
87
84
|
html_vars.each_key do |k|
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2014-
|
3
|
+
Copyright (c) 2014-2024 Chart.js Contributors
|
4
4
|
|
5
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
6
|
|
@@ -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.
|