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 +4 -4
- data/README.md +21 -0
- data/app/assets/javascripts/echarts.themeloader.js +29 -0
- data/lib/rails_charts/base_chart.rb +5 -0
- data/lib/rails_charts/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9cfc32633452b56465d15e918121fdf8d94e4862645c6c065d0b781fb95be4a
|
4
|
+
data.tar.gz: bede48fdda5764a7c67b8ef06829956ff1464cccd979d631d03eb73a9702b965
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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>
|
data/lib/rails_charts/version.rb
CHANGED
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
|
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
|