Skip to content

Commit

Permalink
echart: enable svg rendering (#3936)
Browse files Browse the repository at this point in the history
add `enable_svg` option on echart to change chart renderer from `canvas
`to `svg`

---------

Co-authored-by: Falko Schindler <mail@falkoschindler.de>
  • Loading branch information
Piguite and falkoschindler authored Nov 19, 2024
1 parent 7eaaded commit bfaa142
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion nicegui/elements/echart.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
await import("echarts-gl");
}

this.chart = echarts.init(this.$el);
this.chart = echarts.init(this.$el, null, { renderer: this.renderer });
this.chart.on("click", (e) => this.$emit("pointClick", e));
for (const event of [
"click",
Expand Down Expand Up @@ -90,5 +90,6 @@ export default {
props: {
options: Object,
enable_3d: Boolean,
renderer: String,
},
};
11 changes: 9 additions & 2 deletions nicegui/elements/echart.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Dict, Optional
from typing import Callable, Dict, Literal, Optional

from typing_extensions import Self

Expand All @@ -22,7 +22,12 @@ class EChart(Element,
dependencies=['lib/echarts/echarts.min.js', 'lib/echarts-gl/echarts-gl.min.js'],
default_classes='nicegui-echart'):

def __init__(self, options: Dict, on_point_click: Optional[Handler[EChartPointClickEventArguments]] = None, *, enable_3d: bool = False) -> None:
def __init__(self,
options: Dict,
on_point_click: Optional[Handler[EChartPointClickEventArguments]] = None, *,
enable_3d: bool = False,
renderer: Literal['canvas', 'svg'] = 'canvas',
) -> None:
"""Apache EChart
An element to create a chart using `ECharts <https://echarts.apache.org/>`_.
Expand All @@ -32,10 +37,12 @@ def __init__(self, options: Dict, on_point_click: Optional[Handler[EChartPointCl
:param options: dictionary of EChart options
:param on_click_point: callback that is invoked when a point is clicked
:param enable_3d: enforce importing the echarts-gl library
:param renderer: renderer to use ("canvas" or "svg")
"""
super().__init__()
self._props['options'] = options
self._props['enable_3d'] = enable_3d or any('3D' in key for key in options)
self._props['renderer'] = renderer

if on_point_click:
self.on_point_click(on_point_click)
Expand Down

0 comments on commit bfaa142

Please sign in to comment.