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

Remove Highcharts dependency #1863

Merged
merged 6 commits into from
Oct 23, 2023
Merged
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
3 changes: 1 addition & 2 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
- es-module-shims: 1.7.3 ([MIT](https://opensource.org/licenses/MIT))
- aggrid: 30.0.3 ([MIT](https://opensource.org/licenses/MIT))
- echarts: 5.4.3 ([Apache-2.0](https://opensource.org/licenses/Apache-2.0))
- highcharts: 11.1.0 ([https://www.highcharts.com/license](https://www.highcharts.com/license))
- mermaid: 10.2.4 ([MIT](https://opensource.org/licenses/MIT))
- nipplejs: 0.10.1 ([MIT](https://opensource.org/licenses/MIT))
- plotly: 2.24.3 ([MIT](https://opensource.org/licenses/MIT))
- three: 0.154.0 ([MIT](https://opensource.org/licenses/MIT))
- tween: 21.0.0 ([MIT](https://opensource.org/licenses/MIT))
- vanilla-jsoneditor: 0.18.0 ([ISC](https://opensource.org/licenses/ISC))
- vanilla-jsoneditor: 0.18.0 ([ISC](https://opensource.org/licenses/ISC))
64 changes: 0 additions & 64 deletions nicegui/elements/chart.js

This file was deleted.

103 changes: 5 additions & 98 deletions nicegui/elements/chart.py
Original file line number Diff line number Diff line change
@@ -1,98 +1,5 @@
from typing import Callable, Dict, List, Optional

from ..element import Element
from ..events import (ChartPointClickEventArguments, ChartPointDragEventArguments, ChartPointDragStartEventArguments,
ChartPointDropEventArguments, GenericEventArguments, handle_event)


class Chart(Element,
component='chart.js',
libraries=['lib/highcharts/*.js'],
extra_libraries=['lib/highcharts/modules/*.js']):

def __init__(self, options: Dict, *,
type: str = 'chart', extras: List[str] = [], # pylint: disable=redefined-builtin
on_point_click: Optional[Callable] = None,
on_point_drag_start: Optional[Callable] = None,
on_point_drag: Optional[Callable] = None,
on_point_drop: Optional[Callable] = None,
) -> None:
"""Chart

An element to create a chart using `Highcharts <https://www.highcharts.com/>`_.
Updates can be pushed to the chart by changing the `options` property.
After data has changed, call the `update` method to refresh the chart.

By default, a `Highcharts.chart` is created.
To use, e.g., `Highcharts.stockChart` instead, set the `type` property to "stockChart".

:param options: dictionary of Highcharts options
:param type: chart type (e.g. "chart", "stockChart", "mapChart", ...; default: "chart")
:param extras: list of extra dependencies to include (e.g. "annotations", "arc-diagram", "solid-gauge", ...)
:param on_point_click: callback function that is called when a point is clicked
:param on_point_drag_start: callback function that is called when a point drag starts
:param on_point_drag: callback function that is called when a point is dragged
:param on_point_drop: callback function that is called when a point is dropped
"""
super().__init__()
self._props['type'] = type
self._props['options'] = options
self._props['extras'] = extras
self.libraries.extend(library for library in self.extra_libraries if library.path.stem in extras)

if on_point_click:
def handle_point_click(e: GenericEventArguments) -> None:
handle_event(on_point_click, ChartPointClickEventArguments(
sender=self,
client=self.client,
event_type='point_click',
point_index=e.args['point_index'],
point_x=e.args['point_x'],
point_y=e.args['point_y'],
series_index=e.args['series_index'],
))
self.on('pointClick', handle_point_click, ['point_index', 'point_x', 'point_y', 'series_index'])

if on_point_drag_start:
def handle_point_dragStart(_: GenericEventArguments) -> None:
handle_event(on_point_drag_start, ChartPointDragStartEventArguments(
sender=self,
client=self.client,
event_type='point_drag_start',
))
self.on('pointDragStart', handle_point_dragStart, [])

if on_point_drag:
def handle_point_drag(e: GenericEventArguments) -> None:
handle_event(on_point_drag, ChartPointDragEventArguments(
sender=self,
client=self.client,
event_type='point_drag',
point_index=e.args['point_index'],
point_x=e.args['point_x'],
point_y=e.args['point_y'],
series_index=e.args['series_index'],
))
self.on('pointDrag', handle_point_drag, ['point_index', 'point_x', 'point_y', 'series_index'])

if on_point_drop:
def handle_point_drop(e: GenericEventArguments) -> None:
handle_event(on_point_drop, ChartPointDropEventArguments(
sender=self,
client=self.client,
event_type='point_drop',
point_index=e.args['point_index'],
point_x=e.args['point_x'],
point_y=e.args['point_y'],
series_index=e.args['series_index'],
))
self.on('pointDrop', handle_point_drop, ['point_index', 'point_x', 'point_y', 'series_index'])

@property
def options(self) -> Dict:
"""The options dictionary."""
return self._props['options']

def update(self) -> None:
super().update()
self.run_method('update_chart')
def chart(*args, **kwargs) -> None:
"""Deprecated. Please use `ui.highchart` instead."""
# DEPRECATED
raise RuntimeError('`ui.chart` is now `ui.highchart`. '
'Please install `nicegui[highcharts]` and use `ui.highchart` instead.')
10 changes: 10 additions & 0 deletions nicegui/elements/highchart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .. import optional_features

try:
from nicegui_highcharts import highchart
optional_features.register('highcharts')
__all__ = ['highchart']
except ImportError:
class highchart: # type: ignore
def __init__(self, *args, **kwargs) -> None:
raise NotImplementedError('Highcharts is not installed. Please run `pip install nicegui[highcharts]`.')
Loading