rails_charts 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +66 -37
  3. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/extension/bmap.js +0 -0
  4. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/extension/bmap.js.map +0 -0
  5. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/extension/bmap.min.js +0 -0
  6. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/extension/dataTool.js +0 -0
  7. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/extension/dataTool.js.map +0 -0
  8. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/extension/dataTool.min.js +0 -0
  9. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langCS-obj.js +0 -0
  10. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langCS.js +0 -0
  11. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langDE-obj.js +0 -0
  12. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langDE.js +0 -0
  13. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langEN-obj.js +0 -0
  14. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langEN.js +0 -0
  15. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langES-obj.js +0 -0
  16. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langES.js +0 -0
  17. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langFI-obj.js +0 -0
  18. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langFI.js +0 -0
  19. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langFR-obj.js +0 -0
  20. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langFR.js +0 -0
  21. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langIT-obj.js +0 -0
  22. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langIT.js +0 -0
  23. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langJA-obj.js +0 -0
  24. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langJA.js +0 -0
  25. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langKO-obj.js +0 -0
  26. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langKO.js +0 -0
  27. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langPL-obj.js +0 -0
  28. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langPL.js +0 -0
  29. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langPT-br-obj.js +0 -0
  30. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langPT-br.js +0 -0
  31. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langRO-obj.js +0 -0
  32. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langRO.js +0 -0
  33. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langRU-obj.js +0 -0
  34. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langRU.js +0 -0
  35. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langSI-obj.js +0 -0
  36. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langSI.js +0 -0
  37. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langTH-obj.js +0 -0
  38. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langTH.js +0 -0
  39. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langZH-obj.js +0 -0
  40. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/i18n/langZH.js +0 -0
  41. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/azul.js +1 -1
  42. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/bee-inspired.js +1 -1
  43. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/blue.js +1 -1
  44. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/caravan.js +1 -1
  45. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/carp.js +1 -1
  46. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/cool.js +1 -1
  47. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/dark-blue.js +1 -1
  48. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/dark-bold.js +1 -1
  49. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/dark-digerati.js +1 -1
  50. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/dark-fresh-cut.js +1 -1
  51. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/dark-mushroom.js +1 -1
  52. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/dark.js +1 -1
  53. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/eduardo.js +1 -1
  54. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/forest.js +1 -1
  55. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/fresh-cut.js +1 -1
  56. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/fruit.js +1 -1
  57. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/gray.js +1 -1
  58. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/green.js +1 -1
  59. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/helianthus.js +1 -1
  60. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/infographic.js +1 -1
  61. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/inspired.js +1 -1
  62. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/jazz.js +1 -1
  63. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/london.js +1 -1
  64. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/macarons.js +1 -1
  65. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/macarons2.js +1 -1
  66. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/mint.js +1 -1
  67. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/red-velvet.js +1 -1
  68. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/red.js +1 -1
  69. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/roma.js +1 -1
  70. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/royal.js +1 -1
  71. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/sakura.js +1 -1
  72. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/shine.js +1 -1
  73. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/tech-blue.js +1 -1
  74. data/{vendor/assets/rails_charts → app/assets/javascripts/echarts}/theme/vintage.js +1 -1
  75. data/{vendor/assets/rails_charts → app/assets/javascripts}/echarts.min.js +0 -0
  76. data/lib/install/with_importmap.rb +11 -0
  77. data/lib/install/with_node.rb +20 -0
  78. data/lib/install/with_sprockets.rb +12 -0
  79. data/lib/rails_charts/base_chart.rb +3 -3
  80. data/lib/rails_charts/engine.rb +15 -17
  81. data/lib/rails_charts/javascript.rb +4 -8
  82. data/lib/rails_charts/version.rb +1 -1
  83. data/lib/rails_charts.rb +4 -0
  84. data/lib/tasks/rails_charts_tasks.rake +35 -0
  85. metadata +82 -76
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d37477aa0733f7871c04744cd0ac01c4364210bbb115baa68926cc28900c9f7d
4
- data.tar.gz: 10377955bf42d126819dc8422b96a1519ccb66a2ee96678d5268af60e2c00d77
3
+ metadata.gz: 50c27a4b7e73edf104326a0c43e498158b15b6983a445ada2bb253ff79ebeeee
4
+ data.tar.gz: 2f30630d19ac238e32aca3648ba60adc57d3e82bde8ff3822057165ed2a9efd0
5
5
  SHA512:
6
- metadata.gz: 9e1745b0e47ed759fcbae21a00a888b4b884011a1b6807904b43273cb2b5749920370112a5548244bf9c0d17af28c400d43af0fb75f21657db8a41a430d1a445
7
- data.tar.gz: 163f8f54a5f6edd7659f3d560c14713df15c4c3bcd123a66420f6fe10aecd3ef8af003db8ab9ab8582253f7408c9703cc1f073b0fa700e38e028a3de5d4547a6
6
+ metadata.gz: f005aa895ad8979ff0dfbd76c0f11743695ec1bd0ee80a073cd90be2ab7f92823bef2002859ac7f67c4392e36f49ca87ab659be62fbdbdc80a15b8e46c7181fa
7
+ data.tar.gz: 6be80b111bbfbaf227c43f1e55cc2bf447a456b7f06e435c5441774faf10afc35b27a14813a05e9969ba507802d72bdd452eaaed991facffacb9e6a02b1a99f8
data/README.md CHANGED
@@ -24,81 +24,111 @@ What you can build with it:
24
24
  - stacked bar chart
25
25
  - custom chart
26
26
 
27
- In most cases with one line of code you can have a nice chart. The idea of this gem was inspired by [Charkick](https://github.com/ankane/chartkick) gem which is great and allows you to build charts very quickly. It works the best with cooperation of [groupdate](https://github.com/ankane/groupdate) gem. Unfortunatelly it's missing many needed types of charts or other customization options.
27
+ In most cases with one line of code you can have a nice chart. The idea of this gem was inspired by [Charkick](https://github.com/ankane/chartkick) gem which is great and allows you to build charts very quickly. It works best in cooperation with [groupdate](https://github.com/ankane/groupdate) gem. Unfortunatelly it's missing many needed types of charts or other customization options.
28
28
 
29
- This implementation have more options and similar "interface" how to build charts (thanks to more Apache eCharts).
29
+ This implementation have more options and similar "interface" for building charts.
30
+
31
+
32
+ ## Installation
33
+
34
+ Add gem to your application's Gemfile:
30
35
 
31
- 1) add gem in Gemfile,
32
36
  ```ruby
33
37
  gem "rails_charts"
34
38
  ```
35
- 2) add JS, for example in `application.js`
36
39
 
37
- ```js
38
- //= require rails_charts/echarts.min.js
39
- //= require rails_charts/theme/vintage.js
40
+ Then execute:
41
+ ```bash
42
+ $ ./bin/bundle install
43
+ ```
44
+
45
+ You can install ECharts with installation command
46
+
47
+ ```bash
48
+ $ ./bin/rails rails_charts:install
40
49
  ```
41
50
 
42
- Note you can specify different themes.
51
+ or do it manualy
52
+
53
+ ### Sprockets
54
+
55
+ 1) add eCharts in main JS bundle, e.g. `app/assets/javascripts/application.js`
56
+
57
+ ```javascript
58
+ //= require echarts.min.js
59
+ //= require echarts/theme/dark.js
60
+ ```
43
61
 
44
- 3) add your first chart
62
+ 3) add your first chart e.g.
45
63
  ```ruby
46
64
  <%= line_chart User.group(:age).count %>
47
65
  ```
66
+
48
67
  4) customize charts if needed. See available options or [official documentation](https://echarts.apache.org/examples/en/index.html).
49
68
 
50
- ## Installation
51
69
 
52
- Add this line to your application's Gemfile:
70
+ ### Webpack / esbuild
53
71
 
54
- ```ruby
55
- gem "rails_charts"
56
- ```
72
+ 1) Run:
57
73
 
58
- And then execute:
59
74
  ```bash
60
- $ bundle
75
+ yarn add echarts
61
76
  ```
62
77
 
63
- ### Sprockets
78
+ #### For Rails 7
79
+ 2) In `app/javascript/application.js` add this:
64
80
 
65
- 1) add eCharts in main JS bundle, e.g. `app/assets/javascripts/application.js`
81
+ ```javascript
82
+ import * as echarts from 'echarts';
83
+ import 'echarts/theme/dark';
84
+
85
+ window.echarts = echarts;
86
+ ```
87
+
88
+ #### For Rails 6
89
+ 2) In `app/javascript/packs/application.js` add this:
66
90
 
67
91
  ```javascript
68
- //= require rails_charts/echarts.min.js
69
- //= require rails_charts/theme/dark.js
92
+ import * as echarts from 'echarts';
93
+ import 'echarts/theme/dark';
94
+
95
+ window.echarts = echarts;
70
96
  ```
71
97
 
72
- 2) start using :)
98
+ 3) add your first chart e.g.
99
+ ```ruby
100
+ <%= line_chart User.group(:age).count %>
101
+ ```
102
+
103
+ 4) customize charts if needed. See available options or [official documentation](https://echarts.apache.org/examples/en/index.html).
73
104
 
74
105
  ### Importmaps
75
106
 
76
107
  1) change `config/importmap.rb`
77
108
 
78
109
  ```ruby
79
- pin "rails_charts/echarts.min.js", to: "rails_charts/echarts.min.js", preload: true
80
- pin "rails_charts/theme/dark.js", to: "rails_charts/theme/dark.js", preload: true
110
+ pin "echarts", to: "echarts.min.js"
111
+ pin "echarts/theme/dark", to: "echarts/theme/dark.js"
81
112
  ```
82
113
 
83
- 2) change manifest `app/assets/config/manifest.js`
114
+ 2) add eCharts in main JS
84
115
 
85
116
  ```javascript
86
- //= link rails_charts/echarts.min.js
87
- //= link rails_charts/theme/dark.js
117
+ import "echarts"
118
+ import "echarts/theme/dark"
88
119
  ```
89
120
 
90
- 3) add eCharts in main JS
91
-
92
- ```javascript
93
- import "rails_charts/echarts.min.js"
121
+ 3) add your first chart e.g.
122
+ ```ruby
123
+ <%= line_chart User.group(:age).count %>
94
124
  ```
95
125
 
96
- 4) start using :)
126
+ 4) customize charts if needed. See available options or [official documentation](https://echarts.apache.org/examples/en/index.html).
97
127
 
98
128
  ## Options
99
129
 
100
130
  ```ruby
101
- <%= link_chart data, {
131
+ <%= line_chart data, {
102
132
  width: '250px',
103
133
  height: '250px',
104
134
  theme: 'dark',
@@ -109,7 +139,7 @@ import "rails_charts/echarts.min.js"
109
139
 
110
140
  Available options:
111
141
 
112
- ```
142
+ ```yaml
113
143
  width: specify width of the chart
114
144
  height: specify height of the chart
115
145
  theme: specify theme of the chart (available themes examples https://echarts.apache.org/en/download-theme.html)
@@ -129,7 +159,7 @@ If you need to format tooltip (or other javascript function as an option) you ca
129
159
  ```ruby
130
160
  options: {
131
161
  tooltip: {
132
- valueFormatter: RailsCharts::Javascript.new("(value) => '$' + Math.round(value)")
162
+ valueFormatter: RailsCharts.js("(value) => '$' + Math.round(value)")
133
163
  }
134
164
  }
135
165
  ```
@@ -176,7 +206,7 @@ Every chart has a built in default configuration for tooltips, or other options
176
206
  barWidth: '50%'
177
207
  },
178
208
  tooltip: {
179
- valueFormatter: RailsCharts::Javascript.new("(value) => '$' + Math.round(value)")
209
+ valueFormatter: RailsCharts.js("(value) => '$' + Math.round(value)")
180
210
  }
181
211
  }
182
212
  %>
@@ -458,8 +488,7 @@ Every chart has a built in default configuration for tooltips, or other options
458
488
 
459
489
  You are welcome to contributes. Some open tasks:
460
490
 
461
- - importmaps support?
462
- - webpacker support
491
+ - support turbo streams?
463
492
  - add more specs
464
493
  - add more examples to the dummy app
465
494
  - customization, options overides, default values?
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -32,7 +32,7 @@
32
32
  // Browser globals
33
33
  factory({}, root.echarts);
34
34
  }
35
- })(this, function(exports, echarts) {
35
+ })(window, function(exports, echarts) {
36
36
  var log = function(msg) {
37
37
  if (typeof console !== 'undefined') {
38
38
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -30,7 +30,7 @@
30
30
  // Browser globals
31
31
  factory({}, root.echarts);
32
32
  }
33
- })(this, function(exports, echarts) {
33
+ })(window, function(exports, echarts) {
34
34
  var log = function(msg) {
35
35
  if (typeof console !== 'undefined') {
36
36
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -31,7 +31,7 @@
31
31
  // Browser globals
32
32
  factory({}, root.echarts);
33
33
  }
34
- })(this, function(exports, echarts) {
34
+ })(window, function(exports, echarts) {
35
35
  var log = function(msg) {
36
36
  if (typeof console !== 'undefined') {
37
37
  console && console.error && console.error(msg);
@@ -0,0 +1,11 @@
1
+ say "Import ECharts"
2
+ append_to_file "app/javascript/application.js", <<~JS
3
+ import "echarts"
4
+ import "echarts/theme/dark"
5
+ JS
6
+
7
+ say "Pin ECharts"
8
+ append_to_file "config/importmap.rb", <<~RUBY
9
+ pin "echarts", to: "echarts.min.js"
10
+ pin "echarts/theme/dark", to: "echarts/theme/dark.js"
11
+ RUBY
@@ -0,0 +1,20 @@
1
+ js_code = <<~JS
2
+ import * as echarts from "echarts";
3
+ import "echarts/theme/dark";
4
+
5
+ window.echarts = echarts;
6
+ JS
7
+
8
+ if Rails.root.join("app/javascript/application.js").exist?
9
+ say "Import ECharts"
10
+ append_to_file "app/javascript/application.js", js_code
11
+ elsif Rails.root.join("app/javascript/packs/application.js").exist?
12
+ say "Import ECharts"
13
+ append_to_file "app/javascript/packs/application.js", js_code
14
+ else
15
+ say "You must import add these lines in your JavaScript entrypoint file", :red
16
+ say js_code
17
+ end
18
+
19
+ say "Install ECharts"
20
+ run "yarn add echarts"
@@ -0,0 +1,12 @@
1
+ js_code = <<~JS
2
+ //= require echarts.min.js
3
+ //= require echarts/theme/vintage.js
4
+ JS
5
+
6
+ if Rails.root.join("app/assets/javascripts/application.js").exist?
7
+ say "Import ECharts"
8
+ append_to_file "app/assets/javascripts/application.js", js_code
9
+ else
10
+ say "You must import add these lines in your JavaScript entrypoint file", :red
11
+ say js_code
12
+ end
@@ -1,5 +1,7 @@
1
1
  module RailsCharts
2
2
  class BaseChart
3
+ CHART_JS_PATTERN = /"RAILS_CHART_JS:(.*):RAILS_CHART_JS_END"/
4
+
3
5
  using RubyExt
4
6
 
5
7
  attr_reader :data, :options, :container_id, :defaults
@@ -79,9 +81,7 @@ module RailsCharts
79
81
 
80
82
  def option
81
83
  str = build_options.to_json
82
- Thread.current[:rails_charts_js_code].each do |k, v|
83
- str.gsub!("\"#{k}\"", v)
84
- end if Thread.current[:rails_charts_js_code]
84
+ str.gsub!(CHART_JS_PATTERN) { Base64.decode64 $1 }
85
85
  str
86
86
  end
87
87
 
@@ -3,30 +3,28 @@ module RailsCharts
3
3
 
4
4
  initializer "rails_charts.importmap", before: "importmap" do |app|
5
5
  if defined?(Importmap)
6
- app.config.assets.paths << File.expand_path('../..', __dir__) + "/vendor/assets"
7
- app.config.assets.precompile << ".js"
6
+ app.config.importmap.cache_sweepers << root.join("app/assets/javascripts")
7
+ end
8
+ end
8
9
 
9
- app.config.assets.precompile += [
10
- 'vendor/assets/**/*',
11
- 'vendor/assets/rails_charts/**/*'
12
- ]
10
+ # If you don't want to precompile Echarts's assets (eg. because you're using webpack),
11
+ # you can do this in an intiailzer:
12
+ #
13
+ # config.after_initialize do
14
+ # config.assets.precompile -= RailsCharts::Engine::PRECOMPILE_ASSETS
15
+ # end
13
16
 
14
- app.config.importmap.cache_sweepers << Engine.root.join("vendor/assets/rails_charts")
15
- app.config.importmap.cache_sweepers << Engine.root.join("vendor/assets")
17
+ PRECOMPILE_ASSETS = Dir[root.join("app/assets/javascripts/**/*")]
18
+ initializer 'rails_charts.assets' do |app|
19
+ if app.config.respond_to?(:assets)
20
+ app.config.assets.precompile += PRECOMPILE_ASSETS
16
21
  end
17
22
  end
18
-
19
- initializer 'rails_charts.assets_precompile' do |app|
20
- app.config.assets.paths << File.expand_path('../..', __dir__) + "/vendor/assets"
21
- app.config.assets.precompile += [
22
- 'vendor/assets/**/*',
23
- ]
24
- end
25
23
 
26
- initializer 'rails_charts.helpers' do
24
+ initializer 'rails_charts.helpers', before: :load_config_initializers do
27
25
  ActiveSupport.on_load :action_view do
28
26
  include RailsCharts::Helpers
29
- end
27
+ end
30
28
  end
31
29
 
32
30
  end
@@ -1,17 +1,13 @@
1
1
  module RailsCharts
2
2
  class Javascript
3
- attr_reader :code, :record_id
3
+ attr_reader :code
4
4
 
5
5
  def initialize(code)
6
- @code = code
7
- @record_id = Digest::SHA1.hexdigest([Time.now, rand].join)
8
-
9
- Thread.current[:rails_charts_js_code] ||= {}
10
- Thread.current[:rails_charts_js_code][record_id] = code
6
+ @code = code
11
7
  end
12
8
 
13
9
  def as_json(attrs)
14
- record_id
10
+ "RAILS_CHART_JS:#{Base64.strict_encode64(code)}:RAILS_CHART_JS_END"
15
11
  end
16
12
  end
17
- end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsCharts
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/rails_charts.rb CHANGED
@@ -25,6 +25,10 @@ module RailsCharts
25
25
 
26
26
  class << self
27
27
  attr_accessor :options, :defaults
28
+
29
+ def js(code)
30
+ RailsCharts::Javascript.new code
31
+ end
28
32
  end
29
33
 
30
34
  self.options = {
@@ -0,0 +1,35 @@
1
+ def run_rails_charts_install_template(path)
2
+ system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}"
3
+ end
4
+
5
+ namespace :rails_charts do
6
+ desc "Install Rails Charts into the app"
7
+ task :install do
8
+ if Rails.root.join("config/importmap.rb").exist?
9
+ Rake::Task["rails_charts:install:importmap"].invoke
10
+ elsif Rails.root.join("package.json").exist?
11
+ Rake::Task["rails_charts:install:node"].invoke
12
+ elsif defined?(Sprockets)
13
+ Rake::Task["rails_charts:install:sprockets"].invoke
14
+ else
15
+ puts "Unable to install ECharts with current configuration"
16
+ end
17
+ end
18
+
19
+ namespace :install do
20
+ desc "Install Rails Charts into the app with asset pipeline"
21
+ task :importmap do
22
+ run_rails_charts_install_template "with_importmap"
23
+ end
24
+
25
+ desc "Install Rails Charts into the app with webpacker/esbuild"
26
+ task :node do
27
+ run_rails_charts_install_template "with_node"
28
+ end
29
+
30
+ desc "Install Rails Charts into the app with sprockets"
31
+ task :sprockets do
32
+ run_rails_charts_install_template "with_sprockets"
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_charts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
- - ''
7
+ - Igor Kasyanchuk
8
+ - Liubomyr Manastyretskyi
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2022-04-26 00:00:00.000000000 Z
12
+ date: 2022-04-28 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rails
@@ -139,6 +140,7 @@ dependencies:
139
140
  description: One more solution to create charts in Ruby on Rails application
140
141
  email:
141
142
  - igorkasyanchuk@gmail.com
143
+ - manastyretskyi@gmail.com
142
144
  executables: []
143
145
  extensions: []
144
146
  extra_rdoc_files: []
@@ -146,6 +148,82 @@ files:
146
148
  - MIT-LICENSE
147
149
  - README.md
148
150
  - Rakefile
151
+ - app/assets/javascripts/echarts.min.js
152
+ - app/assets/javascripts/echarts/extension/bmap.js
153
+ - app/assets/javascripts/echarts/extension/bmap.js.map
154
+ - app/assets/javascripts/echarts/extension/bmap.min.js
155
+ - app/assets/javascripts/echarts/extension/dataTool.js
156
+ - app/assets/javascripts/echarts/extension/dataTool.js.map
157
+ - app/assets/javascripts/echarts/extension/dataTool.min.js
158
+ - app/assets/javascripts/echarts/i18n/langCS-obj.js
159
+ - app/assets/javascripts/echarts/i18n/langCS.js
160
+ - app/assets/javascripts/echarts/i18n/langDE-obj.js
161
+ - app/assets/javascripts/echarts/i18n/langDE.js
162
+ - app/assets/javascripts/echarts/i18n/langEN-obj.js
163
+ - app/assets/javascripts/echarts/i18n/langEN.js
164
+ - app/assets/javascripts/echarts/i18n/langES-obj.js
165
+ - app/assets/javascripts/echarts/i18n/langES.js
166
+ - app/assets/javascripts/echarts/i18n/langFI-obj.js
167
+ - app/assets/javascripts/echarts/i18n/langFI.js
168
+ - app/assets/javascripts/echarts/i18n/langFR-obj.js
169
+ - app/assets/javascripts/echarts/i18n/langFR.js
170
+ - app/assets/javascripts/echarts/i18n/langIT-obj.js
171
+ - app/assets/javascripts/echarts/i18n/langIT.js
172
+ - app/assets/javascripts/echarts/i18n/langJA-obj.js
173
+ - app/assets/javascripts/echarts/i18n/langJA.js
174
+ - app/assets/javascripts/echarts/i18n/langKO-obj.js
175
+ - app/assets/javascripts/echarts/i18n/langKO.js
176
+ - app/assets/javascripts/echarts/i18n/langPL-obj.js
177
+ - app/assets/javascripts/echarts/i18n/langPL.js
178
+ - app/assets/javascripts/echarts/i18n/langPT-br-obj.js
179
+ - app/assets/javascripts/echarts/i18n/langPT-br.js
180
+ - app/assets/javascripts/echarts/i18n/langRO-obj.js
181
+ - app/assets/javascripts/echarts/i18n/langRO.js
182
+ - app/assets/javascripts/echarts/i18n/langRU-obj.js
183
+ - app/assets/javascripts/echarts/i18n/langRU.js
184
+ - app/assets/javascripts/echarts/i18n/langSI-obj.js
185
+ - app/assets/javascripts/echarts/i18n/langSI.js
186
+ - app/assets/javascripts/echarts/i18n/langTH-obj.js
187
+ - app/assets/javascripts/echarts/i18n/langTH.js
188
+ - app/assets/javascripts/echarts/i18n/langZH-obj.js
189
+ - app/assets/javascripts/echarts/i18n/langZH.js
190
+ - app/assets/javascripts/echarts/theme/azul.js
191
+ - app/assets/javascripts/echarts/theme/bee-inspired.js
192
+ - app/assets/javascripts/echarts/theme/blue.js
193
+ - app/assets/javascripts/echarts/theme/caravan.js
194
+ - app/assets/javascripts/echarts/theme/carp.js
195
+ - app/assets/javascripts/echarts/theme/cool.js
196
+ - app/assets/javascripts/echarts/theme/dark-blue.js
197
+ - app/assets/javascripts/echarts/theme/dark-bold.js
198
+ - app/assets/javascripts/echarts/theme/dark-digerati.js
199
+ - app/assets/javascripts/echarts/theme/dark-fresh-cut.js
200
+ - app/assets/javascripts/echarts/theme/dark-mushroom.js
201
+ - app/assets/javascripts/echarts/theme/dark.js
202
+ - app/assets/javascripts/echarts/theme/eduardo.js
203
+ - app/assets/javascripts/echarts/theme/forest.js
204
+ - app/assets/javascripts/echarts/theme/fresh-cut.js
205
+ - app/assets/javascripts/echarts/theme/fruit.js
206
+ - app/assets/javascripts/echarts/theme/gray.js
207
+ - app/assets/javascripts/echarts/theme/green.js
208
+ - app/assets/javascripts/echarts/theme/helianthus.js
209
+ - app/assets/javascripts/echarts/theme/infographic.js
210
+ - app/assets/javascripts/echarts/theme/inspired.js
211
+ - app/assets/javascripts/echarts/theme/jazz.js
212
+ - app/assets/javascripts/echarts/theme/london.js
213
+ - app/assets/javascripts/echarts/theme/macarons.js
214
+ - app/assets/javascripts/echarts/theme/macarons2.js
215
+ - app/assets/javascripts/echarts/theme/mint.js
216
+ - app/assets/javascripts/echarts/theme/red-velvet.js
217
+ - app/assets/javascripts/echarts/theme/red.js
218
+ - app/assets/javascripts/echarts/theme/roma.js
219
+ - app/assets/javascripts/echarts/theme/royal.js
220
+ - app/assets/javascripts/echarts/theme/sakura.js
221
+ - app/assets/javascripts/echarts/theme/shine.js
222
+ - app/assets/javascripts/echarts/theme/tech-blue.js
223
+ - app/assets/javascripts/echarts/theme/vintage.js
224
+ - lib/install/with_importmap.rb
225
+ - lib/install/with_node.rb
226
+ - lib/install/with_sprockets.rb
149
227
  - lib/rails_charts.rb
150
228
  - lib/rails_charts/area_chart.rb
151
229
  - lib/rails_charts/bar_chart.rb
@@ -168,79 +246,7 @@ files:
168
246
  - lib/rails_charts/scatter_chart.rb
169
247
  - lib/rails_charts/stacked_bar_chart.rb
170
248
  - lib/rails_charts/version.rb
171
- - vendor/assets/rails_charts/echarts.min.js
172
- - vendor/assets/rails_charts/extension/bmap.js
173
- - vendor/assets/rails_charts/extension/bmap.js.map
174
- - vendor/assets/rails_charts/extension/bmap.min.js
175
- - vendor/assets/rails_charts/extension/dataTool.js
176
- - vendor/assets/rails_charts/extension/dataTool.js.map
177
- - vendor/assets/rails_charts/extension/dataTool.min.js
178
- - vendor/assets/rails_charts/i18n/langCS-obj.js
179
- - vendor/assets/rails_charts/i18n/langCS.js
180
- - vendor/assets/rails_charts/i18n/langDE-obj.js
181
- - vendor/assets/rails_charts/i18n/langDE.js
182
- - vendor/assets/rails_charts/i18n/langEN-obj.js
183
- - vendor/assets/rails_charts/i18n/langEN.js
184
- - vendor/assets/rails_charts/i18n/langES-obj.js
185
- - vendor/assets/rails_charts/i18n/langES.js
186
- - vendor/assets/rails_charts/i18n/langFI-obj.js
187
- - vendor/assets/rails_charts/i18n/langFI.js
188
- - vendor/assets/rails_charts/i18n/langFR-obj.js
189
- - vendor/assets/rails_charts/i18n/langFR.js
190
- - vendor/assets/rails_charts/i18n/langIT-obj.js
191
- - vendor/assets/rails_charts/i18n/langIT.js
192
- - vendor/assets/rails_charts/i18n/langJA-obj.js
193
- - vendor/assets/rails_charts/i18n/langJA.js
194
- - vendor/assets/rails_charts/i18n/langKO-obj.js
195
- - vendor/assets/rails_charts/i18n/langKO.js
196
- - vendor/assets/rails_charts/i18n/langPL-obj.js
197
- - vendor/assets/rails_charts/i18n/langPL.js
198
- - vendor/assets/rails_charts/i18n/langPT-br-obj.js
199
- - vendor/assets/rails_charts/i18n/langPT-br.js
200
- - vendor/assets/rails_charts/i18n/langRO-obj.js
201
- - vendor/assets/rails_charts/i18n/langRO.js
202
- - vendor/assets/rails_charts/i18n/langRU-obj.js
203
- - vendor/assets/rails_charts/i18n/langRU.js
204
- - vendor/assets/rails_charts/i18n/langSI-obj.js
205
- - vendor/assets/rails_charts/i18n/langSI.js
206
- - vendor/assets/rails_charts/i18n/langTH-obj.js
207
- - vendor/assets/rails_charts/i18n/langTH.js
208
- - vendor/assets/rails_charts/i18n/langZH-obj.js
209
- - vendor/assets/rails_charts/i18n/langZH.js
210
- - vendor/assets/rails_charts/theme/azul.js
211
- - vendor/assets/rails_charts/theme/bee-inspired.js
212
- - vendor/assets/rails_charts/theme/blue.js
213
- - vendor/assets/rails_charts/theme/caravan.js
214
- - vendor/assets/rails_charts/theme/carp.js
215
- - vendor/assets/rails_charts/theme/cool.js
216
- - vendor/assets/rails_charts/theme/dark-blue.js
217
- - vendor/assets/rails_charts/theme/dark-bold.js
218
- - vendor/assets/rails_charts/theme/dark-digerati.js
219
- - vendor/assets/rails_charts/theme/dark-fresh-cut.js
220
- - vendor/assets/rails_charts/theme/dark-mushroom.js
221
- - vendor/assets/rails_charts/theme/dark.js
222
- - vendor/assets/rails_charts/theme/eduardo.js
223
- - vendor/assets/rails_charts/theme/forest.js
224
- - vendor/assets/rails_charts/theme/fresh-cut.js
225
- - vendor/assets/rails_charts/theme/fruit.js
226
- - vendor/assets/rails_charts/theme/gray.js
227
- - vendor/assets/rails_charts/theme/green.js
228
- - vendor/assets/rails_charts/theme/helianthus.js
229
- - vendor/assets/rails_charts/theme/infographic.js
230
- - vendor/assets/rails_charts/theme/inspired.js
231
- - vendor/assets/rails_charts/theme/jazz.js
232
- - vendor/assets/rails_charts/theme/london.js
233
- - vendor/assets/rails_charts/theme/macarons.js
234
- - vendor/assets/rails_charts/theme/macarons2.js
235
- - vendor/assets/rails_charts/theme/mint.js
236
- - vendor/assets/rails_charts/theme/red-velvet.js
237
- - vendor/assets/rails_charts/theme/red.js
238
- - vendor/assets/rails_charts/theme/roma.js
239
- - vendor/assets/rails_charts/theme/royal.js
240
- - vendor/assets/rails_charts/theme/sakura.js
241
- - vendor/assets/rails_charts/theme/shine.js
242
- - vendor/assets/rails_charts/theme/tech-blue.js
243
- - vendor/assets/rails_charts/theme/vintage.js
249
+ - lib/tasks/rails_charts_tasks.rake
244
250
  homepage: https://github.com/railsjazz/rails_charts
245
251
  licenses:
246
252
  - MIT