rails_charts 0.0.9 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 830e81299e65a8cff82d47efc2b25dd561c3791b0e910717e4277543b3b8d152
4
- data.tar.gz: 5f0f96ae1917f0155aac538e1dbd6084d236da857eeb519d42f9b48ef42bc2d1
3
+ metadata.gz: d9cfc32633452b56465d15e918121fdf8d94e4862645c6c065d0b781fb95be4a
4
+ data.tar.gz: bede48fdda5764a7c67b8ef06829956ff1464cccd979d631d03eb73a9702b965
5
5
  SHA512:
6
- metadata.gz: d07dab2edfbe53f2912cf10334ae47cf4933620339c029862b2f3d678361af10318a02c2e606a002433c54b3a1057f3f966d66aa05545cb326ef2f9dc964df8a
7
- data.tar.gz: 8b4f8b9334096c7807114b4275906ce54cca6f4cee290d7f45ee3efcef25b4cd3a9b7734c5035d3a3e41daf76d1d6f412de21f67ffa05c2451eaccd87b5f8b1f
6
+ metadata.gz: c9377a50726f2189c447d9088791ac4deba4082688d3f4db93b162d1025af7e53e582b9bb645b0b01400c9ff9adfd069620dcc1ef364ce6b73a57fa8218e788c
7
+ data.tar.gz: d8146af06cc195a2029c20f48d091db467f65d82a81bafe61ee8364d631c4ac4e073378557754a6a316690f507bfff89c0842460bc96b6cbe99a71dc93964f9b
data/README.md CHANGED
@@ -129,6 +129,27 @@ import "echarts/theme/dark"
129
129
 
130
130
  4) customize charts if needed. See available options or [official documentation](https://echarts.apache.org/examples/en/index.html).
131
131
 
132
+ ### Loading Themes
133
+
134
+ Themes can be loaded as shown in examples above. However, in some cases where
135
+ themes are included in environment where `this` does not point to `window`, you
136
+ might get errors. In that case, you can use loadTheme helper to load themes by
137
+ name. For example, instead of
138
+
139
+ ```javascript
140
+ import 'echarts/theme/dark'
141
+ ```
142
+ you can do
143
+
144
+ ```javascript
145
+ // application.js
146
+ import "echarts"
147
+ import "echarts.themeloader"
148
+
149
+ // Load the desired theme dynamically
150
+ RailsCharts.loadTheme('dark');
151
+ ```
152
+
132
153
  ## Options
133
154
 
134
155
  ```ruby
@@ -0,0 +1,29 @@
1
+ (function() {
2
+ window.RailsCharts = window.RailsCharts || {};
3
+ window.RailsCharts.loadedThemes = window.RailsCharts.loadedThemes || [];
4
+
5
+ window.RailsCharts.loadTheme = function(themeName) {
6
+ document.addEventListener('DOMContentLoaded', () => {
7
+ if (typeof echarts === 'undefined') {
8
+ console.error('ECharts is not loaded. Please ensure echarts.js is included.');
9
+ return;
10
+ }
11
+
12
+ if (window.RailsCharts.loadedThemes.includes(themeName)) {
13
+ console.warn(`Theme '${themeName}' is already loaded.`);
14
+ return;
15
+ }
16
+
17
+ const script = document.createElement('script');
18
+ script.type = 'text/javascript';
19
+ script.src = `/assets/echarts/theme/${themeName}.js`;
20
+ script.onload = () => {
21
+ console.log(`Theme '${themeName}' loaded successfully.`);
22
+ };
23
+ script.onerror = () => {
24
+ console.error(`Failed to load theme: /assets/echarts/theme/${themeName}.js`);
25
+ };
26
+ document.head.appendChild(script);
27
+ });
28
+ };
29
+ })();
@@ -80,6 +80,11 @@ module RailsCharts
80
80
  window.addEventListener('turbo:load', init_#{chart_id});
81
81
  window.addEventListener('turbolinks:load', init_#{chart_id});
82
82
 
83
+ window.addEventListener('turbo:frame-render', init_#{chart_id});
84
+ window.addEventListener('turbo:frame-load', ()=> {
85
+ window.removeEventListener('turbo:frame-render', init_#{chart_id});
86
+ });
87
+
83
88
  document.addEventListener("turbolinks:before-render", destroy_#{chart_id});
84
89
  document.addEventListener("turbo:before-render", destroy_#{chart_id});
85
90
  </script>
@@ -1,3 +1,3 @@
1
1
  module RailsCharts
2
- VERSION = "0.0.9"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_charts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
@@ -134,6 +134,7 @@ files:
134
134
  - README.md
135
135
  - Rakefile
136
136
  - app/assets/javascripts/echarts.min.js
137
+ - app/assets/javascripts/echarts.themeloader.js
137
138
  - app/assets/javascripts/echarts/extension/bmap.js
138
139
  - app/assets/javascripts/echarts/extension/bmap.js.map
139
140
  - app/assets/javascripts/echarts/extension/bmap.min.js