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

Conversation

Piguite
Copy link

@Piguite Piguite commented Oct 31, 2024

add enable_svg option on echart to change chart renderer from canvas to svg

@Piguite Piguite marked this pull request as ready for review October 31, 2024 15:00
Copy link
Contributor

@falkoschindler falkoschindler left a 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!

Comment on lines +12 to +17
if (this.enable_svg) {
this.chart = echarts.init(this.$el, null, {renderer: 'svg'});
} else {
this.chart = echarts.init(this.$el);
}

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 });

@@ -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,

@@ -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:

@@ -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

@falkoschindler falkoschindler added this to the 2.6 milestone Nov 7, 2024
@falkoschindler falkoschindler added the enhancement New feature or request label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants