Skip to content

Commit

Permalink
load echarts dependencies via npm.py
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Aug 17, 2023
1 parent 71e0ef7 commit 3bb0927
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 300,815 deletions.
1 change: 1 addition & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- socket.io: 4.7.1
- es-module-shims: 1.7.3
- aggrid: 30.0.3
- echarts: 5.4.3
- highcharts: 11.1.0
- mermaid: 10.2.4
- nipplejs: 0.10.1
Expand Down
10 changes: 3 additions & 7 deletions nicegui/elements/echarts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ export default {
template: "<div></div>",
mounted() {
setTimeout(() => {
const imports = this.extras.map((extra) => import(window.path_prefix + extra));
Promise.allSettled(imports).then(() => {
this.chart = echarts.init(this.$el);
this.chart.setOption(this.options);
this.chart.resize();
});
this.chart = echarts.init(this.$el);
this.chart.setOption(this.options);
this.chart.resize();
}, 0); // NOTE: wait for window.path_prefix to be set in app.mounted()
},
beforeDestroy() {
Expand All @@ -30,6 +27,5 @@ export default {
},
props: {
options: Object,
extras: Array,
},
};
12 changes: 3 additions & 9 deletions nicegui/elements/echarts.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
from typing import Dict, List
from typing import Dict

from ..element import Element


class ECharts(Element,
component='echarts.js',
libraries=['lib/echarts/*.js'],
extra_libraries=['lib/echarts/extensions/*.js']):
class ECharts(Element, component='echarts.js', libraries=['lib/echarts/echarts.min.js']):

def __init__(self, options: Dict, *, extras: List[str] = []) -> None:
def __init__(self, options: Dict) -> None:
"""Apache ECharts
An element to create a chart using `ECharts <https://echarts.apache.org/>`_.
Updates can be pushed to the chart by changing the `options` property.
After data has changed, call the `update` method to refresh the chart.
:param options: dictionary of EChart options
:param extras: list of extra extensions to include
"""
super().__init__()
self._props['options'] = options
self._props['extras'] = extras
self.libraries.extend(library for library in self.extra_libraries if library.path.stem in extras)
self._classes = ['nicegui-echarts']

@property
Expand Down
Loading

0 comments on commit 3bb0927

Please sign in to comment.