Prechádzať zdrojové kódy

integrate external highchart element

Falko Schindler 1 rok pred
rodič
commit
baeb89a9c9
3 zmenil súbory, kde vykonal 15 pridanie a 28 odobranie
  1. 5 27
      nicegui/elements/chart.py
  2. 7 0
      nicegui/elements/highchart.py
  3. 3 1
      nicegui/ui.py

+ 5 - 27
nicegui/elements/chart.py

@@ -1,27 +1,5 @@
-from typing import Callable, Dict, List, Optional
-
-from .. import optional_features
-
-try:
-    from nicegui_highcharts import highcharts
-    optional_features.register('highcharts')
-except ImportError:
-    pass
-
-
-class Chart(highcharts):
-
-    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:
-        super().__init__(options, type=type, extras=extras,
-                         on_point_click=on_point_click,
-                         on_point_drag_start=on_point_drag_start,
-                         on_point_drag=on_point_drag,
-                         on_point_drop=on_point_drop)
-        if not optional_features.has('highcharts'):
-            raise ImportError('Highcharts is not installed. Please run "pip install nicegui_highcharts".')
+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.')

+ 7 - 0
nicegui/elements/highchart.py

@@ -0,0 +1,7 @@
+try:
+    from nicegui_highcharts import highchart
+    __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]`.')

+ 3 - 1
nicegui/ui.py

@@ -26,6 +26,7 @@ __all__ = [
     'editor',
     'editor',
     'expansion',
     'expansion',
     'grid',
     'grid',
+    'highchart',
     'html',
     'html',
     'icon',
     'icon',
     'image',
     'image',
@@ -109,7 +110,7 @@ from .elements.card import CardActions as card_actions
 from .elements.card import CardSection as card_section
 from .elements.card import CardSection as card_section
 from .elements.carousel import Carousel as carousel
 from .elements.carousel import Carousel as carousel
 from .elements.carousel import CarouselSlide as carousel_slide
 from .elements.carousel import CarouselSlide as carousel_slide
-from .elements.chart import Chart as chart
+from .elements.chart import chart
 from .elements.chat_message import ChatMessage as chat_message
 from .elements.chat_message import ChatMessage as chat_message
 from .elements.checkbox import Checkbox as checkbox
 from .elements.checkbox import Checkbox as checkbox
 from .elements.code import Code as code
 from .elements.code import Code as code
@@ -125,6 +126,7 @@ from .elements.echart import EChart as echart
 from .elements.editor import Editor as editor
 from .elements.editor import Editor as editor
 from .elements.expansion import Expansion as expansion
 from .elements.expansion import Expansion as expansion
 from .elements.grid import Grid as grid
 from .elements.grid import Grid as grid
+from .elements.highchart import highchart
 from .elements.html import Html as html
 from .elements.html import Html as html
 from .elements.icon import Icon as icon
 from .elements.icon import Icon as icon
 from .elements.image import Image as image
 from .elements.image import Image as image