-
-
Notifications
You must be signed in to change notification settings - Fork 605
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this pull request, @Piguite! Being able to change the renderer is a great addition to the ui.echart
element.
The code looks good to me, but I think we should change the parameter from enable_svg: bool
to renderer: Literal['canvas', 'svg']
. This is more in line with the original ECharts library, indicates both options more clearly, and is extendable should there be more renderers in the future.
I would have made the required changes myself, but I don't have the necessary rights to push to your branch. ("Maintainers are allowed to edit this pull request" is not enabled.) Therefore I proposed the code changes in comments. You should be able to accept them directly from the web interface. Thanks!
if (this.enable_svg) { | ||
this.chart = echarts.init(this.$el, null, {renderer: 'svg'}); | ||
} else { | ||
this.chart = echarts.init(this.$el); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 }); |
@@ -90,5 +95,6 @@ export default { | |||
props: { | |||
options: Object, | |||
enable_3d: Boolean, | |||
enable_svg: Boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enable_svg: Boolean | |
renderer: String, |
@@ -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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._props['enable_svg'] = enable_svg | |
self._props['renderer'] = renderer |
add
enable_svg
option on echart to change chart renderer fromcanvas
tosvg