Sfoglia il codice sorgente

code review, simplify example

Falko Schindler 3 anni fa
parent
commit
e164e23484
2 ha cambiato i file con 11 aggiunte e 14 eliminazioni
  1. 7 10
      main.py
  2. 4 4
      nicegui/elements/chart.py

+ 7 - 10
main.py

@@ -263,7 +263,10 @@ with example(ui.scene):
         scene.stl(teapot).scale(0.2).move(-3, 4)
         scene.stl(teapot).scale(0.2).move(-3, 4)
 
 
 with example(ui.chart):
 with example(ui.chart):
-    from random import random
+    from numpy.random import random
+
+    def update():
+        chart.view.options.series[0].data[:] = random(2)
 
 
     options = {
     options = {
         'title': False,
         'title': False,
@@ -271,17 +274,11 @@ with example(ui.chart):
         'xAxis': {'categories': ['A', 'B']},
         'xAxis': {'categories': ['A', 'B']},
         'series': [
         'series': [
             {'name': 'Alpha', 'data': [0.1, 0.2]},
             {'name': 'Alpha', 'data': [0.1, 0.2]},
-            {'name': 'Beta', 'data': [0.4, 0.3]},
+            {'name': 'Beta', 'data': [0.3, 0.4]},
         ],
         ],
     }
     }
-
-    def regenerate(chart):
-        chart.view.options.series[1] = {
-            'name': 'Beta', 'data': [random() for _ in range(2)]
-        }
-
-    chart = ui.chart(options).style('width: 200px;height: 200px')
-    ui.button('Generate values', on_click=lambda: regenerate(chart))
+    chart = ui.chart(options).classes('max-w-full h-64')
+    ui.button('Update', on_click=update)
 
 
 with example(ui.joystick):
 with example(ui.joystick):
     ui.joystick(
     ui.joystick(

+ 4 - 4
nicegui/elements/chart.py

@@ -1,15 +1,15 @@
 import justpy as jp
 import justpy as jp
-
+from typing import Dict
 from .element import Element
 from .element import Element
 
 
 
 
 class Chart(Element):
 class Chart(Element):
-    def __init__(self, options):
+    def __init__(self, options: Dict):
         """Chart
         """Chart
 
 
-        An element to create a chart (`<https://www.highcharts.com/>`_).
+        An element to create a chart using `Highcharts <https://www.highcharts.com/>`_.
 
 
-        :param options: dictionary of highchart options
+        :param options: dictionary of highcharts options
         """
         """
         view = jp.HighCharts(classes='m-2 p-2 border', style='width: 600px')
         view = jp.HighCharts(classes='m-2 p-2 border', style='width: 600px')
         view.options = self.options = jp.Dict(**options)
         view.options = self.options = jp.Dict(**options)