chartkick 4.0.5 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecf49f61e1962e1952df47113fea621bafe1bb423e50903ce98e1b6213c3c9cb
4
- data.tar.gz: 29167dca418215178ea525061dc3113d186a53076ce77472241f54e99edc4b13
3
+ metadata.gz: ea8884a2d48b14492533dfb048fceba992f579b711d02576df6d998188068d6c
4
+ data.tar.gz: 1b918716b088e33d8a58e4bcb1669f79de634b8103ecef7d71c205a712eea0e6
5
5
  SHA512:
6
- metadata.gz: 4ba35050af1933c7d343125a291a515e26f6ae143b081d6346e0e709b920d299ff44a0f262559b1b358d778154b2a103132b751f9c37a905c5e789776bafca17
7
- data.tar.gz: 3a3f5d3c57e7af61bcfc7b86d5888b4f2124b5e07fa86256eb7eb6298125b14c5a6293e926802ea3ac2d45a48fdf5fd222a2c47ba9ffb08209f8dc5768ad6000
6
+ metadata.gz: afeb7f5d6339440e986b33e12130bb06e58c54eb1044cd30cbd4773efe01afe1ee376356fdca8659352290d36ec5d2d0169d023c698bd2e6f5a416409b91f9de
7
+ data.tar.gz: 4a09e32c9a78eec5c3e0fd7bdd50badde15bb19831786cd3541a9920eb8c5407bebd8fd6752ad30a00ce7a067f5bbdaa88cb017f1ba29b8f73039d749ff51d4e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 4.1.0 (2021-10-23)
2
+
3
+ - Added support for Turbo
4
+ - Added experimental support for `importmap-rails`
5
+ - Updated Chartkick.js to 4.1.0
6
+
1
7
  ## 4.0.5 (2021-07-07)
2
8
 
3
9
  - Updated Chartkick.js to 4.0.5
data/README.md CHANGED
@@ -39,6 +39,13 @@ For Rails 5 / Sprockets, in `app/assets/javascripts/application.js`, add:
39
39
  //= require Chart.bundle
40
40
  ```
41
41
 
42
+ For Rails 7 / Importmap (experimental), in `app/javascript/application.js`, add:
43
+
44
+ ```js
45
+ import "chartkick"
46
+ import "Chart.bundle"
47
+ ```
48
+
42
49
  This sets up Chartkick with [Chart.js](https://www.chartjs.org/). For other charting libraries, see [detailed instructions](#installation).
43
50
 
44
51
  ## Charts
@@ -98,9 +105,10 @@ Timeline - *Google Charts*
98
105
  Multiple series
99
106
 
100
107
  ```erb
101
- <%= line_chart @goals.map { |goal|
102
- {name: goal.name, data: goal.feats.group_by_week(:created_at).count}
103
- } %>
108
+ <%= line_chart [
109
+ {name: "Workout", data: {"2021-01-01" => 3, "2021-01-02" => 4}},
110
+ {name: "Call parents", data: {"2021-01-01" => 5, "2021-01-02" => 3}}
111
+ ] %>
104
112
  ```
105
113
 
106
114
  or
@@ -109,7 +117,23 @@ or
109
117
  <%= line_chart Feat.group(:goal_id).group_by_week(:created_at).count %>
110
118
  ```
111
119
 
112
- ### Say Goodbye To Timeouts
120
+ ## Data
121
+
122
+ Data can be a hash, array, or URL.
123
+
124
+ #### Hash
125
+
126
+ ```erb
127
+ <%= line_chart({"2021-01-01" => 2, "2021-01-02" => 3}) %>
128
+ ```
129
+
130
+ #### Array
131
+
132
+ ```erb
133
+ <%= line_chart [["2021-01-01", 2], ["2021-01-02", 3]] %>
134
+ ```
135
+
136
+ #### URL
113
137
 
114
138
  Make your pages load super fast and stop worrying about timeouts. Give each chart its own endpoint.
115
139
 
@@ -133,7 +157,7 @@ For multiple series, add `chart_json` at the end.
133
157
  render json: Task.group(:goal_id).group_by_day(:completed_at).count.chart_json
134
158
  ```
135
159
 
136
- ### Options
160
+ ## Options
137
161
 
138
162
  Id, width, and height
139
163
 
@@ -330,30 +354,6 @@ For Padrino, use `yield_content` instead of `yield`.
330
354
 
331
355
  This is great for including all of your JavaScript at the bottom of the page.
332
356
 
333
- ### Data
334
-
335
- Pass data as a hash or array
336
-
337
- ```erb
338
- <%= pie_chart({"Football" => 10, "Basketball" => 5}) %>
339
- <%= pie_chart [["Football", 10], ["Basketball", 5]] %>
340
- ```
341
-
342
- For multiple series, use the format
343
-
344
- ```erb
345
- <%= line_chart [
346
- {name: "Series A", data: series_a},
347
- {name: "Series B", data: series_b}
348
- ] %>
349
- ```
350
-
351
- Times can be a time or a string (strings are parsed)
352
-
353
- ```erb
354
- <%= line_chart({20.day.ago => 5, "2021-05-07 00:00:00 UTC" => 7}) %>
355
- ```
356
-
357
357
  ### Multiple Series
358
358
 
359
359
  You can pass a few options with a series:
@@ -440,6 +440,13 @@ For Rails 5 / Sprockets, in `app/assets/javascripts/application.js`, add:
440
440
  //= require Chart.bundle
441
441
  ```
442
442
 
443
+ For Rails 7 / Importmap (experimental), in `app/javascript/application.js`, add:
444
+
445
+ ```js
446
+ import "chartkick"
447
+ import "Chart.bundle"
448
+ ```
449
+
443
450
  ### Google Charts
444
451
 
445
452
  In your layout or views, add:
@@ -466,6 +473,12 @@ For Rails 5 / Sprockets, in `app/assets/javascripts/application.js`, add:
466
473
  //= require chartkick
467
474
  ```
468
475
 
476
+ For Rails 7 / Importmap (experimental), in `app/javascript/application.js`, add:
477
+
478
+ ```js
479
+ import "chartkick"
480
+ ```
481
+
469
482
  To specify a language or Google Maps API key, use:
470
483
 
471
484
  ```js
@@ -495,6 +508,21 @@ For Rails 5 / Sprockets, download [highcharts.js](https://code.highcharts.com/hi
495
508
  //= require highcharts
496
509
  ```
497
510
 
511
+ For Rails 7 / Importmap (experimental), run:
512
+
513
+ ```sh
514
+ bin/importmap pin highcharts --download
515
+ ```
516
+
517
+ And in `app/javascript/application.js`, add:
518
+
519
+ ```js
520
+ import "chartkick"
521
+ import Highcharts from "highcharts"
522
+
523
+ window.Highcharts = Highcharts
524
+ ```
525
+
498
526
  ### Sinatra and Padrino
499
527
 
500
528
  Download [chartkick.js](https://raw.githubusercontent.com/ankane/chartkick/master/vendor/assets/javascripts/chartkick.js) and include it manually.
@@ -0,0 +1 @@
1
+ pin_all_from File.expand_path("../vendor/assets/javascripts", __dir__)
@@ -1,5 +1,14 @@
1
1
  module Chartkick
2
2
  class Engine < ::Rails::Engine
3
3
  # for assets
4
+
5
+ # for importmap
6
+ if defined?(Importmap)
7
+ initializer "chartkick.importmap", after: "importmap" do |app|
8
+ app.importmap.draw(Engine.root.join("config/importmap.rb"))
9
+ app.config.assets.precompile << "chartkick.js"
10
+ app.config.assets.precompile << "Chart.bundle.js"
11
+ end
12
+ end
4
13
  end
5
14
  end
@@ -117,6 +117,7 @@ module Chartkick
117
117
  <script#{nonce_html}>
118
118
  (function() {
119
119
  if (document.documentElement.hasAttribute("data-turbolinks-preview")) return;
120
+ if (document.documentElement.hasAttribute("data-turbo-preview")) return;
120
121
 
121
122
  var createChart = function() { #{createjs} };
122
123
  if ("Chartkick" in window) {
@@ -1,3 +1,3 @@
1
1
  module Chartkick
2
- VERSION = "4.0.5"
2
+ VERSION = "4.1.0"
3
3
  end
@@ -2,7 +2,7 @@
2
2
  * Chartkick.js
3
3
  * Create beautiful charts with one line of JavaScript
4
4
  * https://github.com/ankane/chartkick.js
5
- * v4.0.5
5
+ * v4.1.0
6
6
  * MIT License
7
7
  */
8
8
 
@@ -2495,6 +2495,9 @@
2495
2495
  document.addEventListener("turbolinks:before-render", function() {
2496
2496
  Chartkick.destroyAll();
2497
2497
  });
2498
+ document.addEventListener("turbo:before-render", function() {
2499
+ Chartkick.destroyAll();
2500
+ });
2498
2501
 
2499
2502
  // use setTimeout so charting library can come later in same JS file
2500
2503
  setTimeout(function() {
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: 4.0.5
4
+ version: 4.1.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: 2021-07-07 00:00:00.000000000 Z
11
+ date: 2021-10-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: andrew@ankane.org
@@ -19,6 +19,7 @@ files:
19
19
  - CHANGELOG.md
20
20
  - LICENSE.txt
21
21
  - README.md
22
+ - config/importmap.rb
22
23
  - lib/chartkick.rb
23
24
  - lib/chartkick/engine.rb
24
25
  - lib/chartkick/enumerable.rb
@@ -50,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
51
  - !ruby/object:Gem::Version
51
52
  version: '0'
52
53
  requirements: []
53
- rubygems_version: 3.2.3
54
+ rubygems_version: 3.2.22
54
55
  signing_key:
55
56
  specification_version: 4
56
57
  summary: Create beautiful JavaScript charts with one line of Ruby