Prechádzať zdrojové kódy

update ui.line_plot

Falko Schindler 2 rokov pred
rodič
commit
4a3fefde88

+ 4 - 3
api_docs_and_examples.py

@@ -322,7 +322,7 @@ To overlay an SVG, make the `viewBox` exactly the size of the image and provide
             y = np.cos(2 * np.pi * x) * np.exp(-x)
             plt.plot(x, y, '-')
 
-    # @example(ui.line_plot)
+    @example(ui.line_plot, skip=False)
     def line_plot_example():
         global line_checkbox
         from datetime import datetime
@@ -339,8 +339,9 @@ To overlay an SVG, make the `viewBox` exactly the size of the image and provide
             y2 = np.cos(x)
             line_plot.push([now], [[y1], [y2]])
 
-        line_updates = ui.timer(0.1, update_line_plot, active=False)
-        line_checkbox = ui.checkbox('active').bind_value(line_updates, 'active')
+        # line_updates = ui.timer(0.1, update_line_plot, active=False)
+        # line_checkbox = ui.checkbox('active').bind_value(line_updates, 'active')
+        ui.button('update', on_click=update_line_plot)  # TODO: use ui.timer instead
 
     @example(ui.linear_progress, skip=False)
     def linear_progress_example():

+ 4 - 4
nicegui/elements/old/line_plot.py → nicegui/elements/line_plot.py

@@ -5,7 +5,7 @@ from .plot import Plot
 
 class LinePlot(Plot):
 
-    def __init__(self, *, n: int = 1, limit: int = 100, update_every: int = 1, close: bool = True, **kwargs):
+    def __init__(self, *, n: int = 1, limit: int = 100, update_every: int = 1, close: bool = True, **kwargs) -> None:
         """Line Plot
 
         Create a line plot. The `push` method provides live updating when utilized in combination with `ui.timer`.
@@ -27,10 +27,10 @@ class LinePlot(Plot):
 
     def with_legend(self, titles: List[str], **kwargs):
         self.fig.gca().legend(titles, **kwargs)
-        self.view.set_figure(self.fig)
+        self._convert_to_html()
         return self
 
-    def push(self, x: List[float], Y: List[List[float]]):
+    def push(self, x: List[float], Y: List[List[float]]) -> None:
         self.push_counter += 1
 
         self.x = [*self.x, *x][self.slice]
@@ -53,5 +53,5 @@ class LinePlot(Plot):
         pad_y = 0.01 * (max_y - min_y)
         self.fig.gca().set_xlim(min_x - pad_x, max_x + pad_x)
         self.fig.gca().set_ylim(min_y - pad_y, max_y + pad_y)
-        self.view.set_figure(self.fig)
+        self._convert_to_html()
         self.update()

+ 1 - 0
nicegui/ui.py

@@ -13,6 +13,7 @@ from .elements.image import Image as image
 from .elements.input import Input as input
 from .elements.joystick import Joystick as joystick
 from .elements.label import Label as label
+from .elements.line_plot import LinePlot as line_plot
 from .elements.link import Link as link
 from .elements.link import LinkTarget as link_target
 from .elements.log import Log as log