Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

echart: enable svg rendering #3936

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion nicegui/elements/echart.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export default {
await import("echarts-gl");
}

this.chart = echarts.init(this.$el);
if (this.enable_svg) {
this.chart = echarts.init(this.$el, null, {renderer: 'svg'});
} else {
this.chart = echarts.init(this.$el);
}

Comment on lines +12 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.enable_svg) {
this.chart = echarts.init(this.$el, null, {renderer: 'svg'});
} else {
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 +95,6 @@ export default {
props: {
options: Object,
enable_3d: Boolean,
enable_svg: Boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enable_svg: Boolean
renderer: String,

},
};
4 changes: 3 additions & 1 deletion nicegui/elements/echart.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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, enable_svg: bool = False) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __init__(self, options: Dict, on_point_click: Optional[Handler[EChartPointClickEventArguments]] = None, *, enable_3d: bool = False, enable_svg: 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 +32,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 enable_svg: enable svg rendering for this chart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:param enable_svg: enable svg rendering for this chart
: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['enable_svg'] = enable_svg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._props['enable_svg'] = enable_svg
self._props['renderer'] = renderer


if on_point_click:
self.on_point_click(on_point_click)
Expand Down