Răsfoiți Sursa

update ui.line_plot

Falko Schindler 2 ani în urmă
părinte
comite
4a3fefde88
3 a modificat fișierele cu 9 adăugiri și 7 ștergeri
  1. 4 3
      api_docs_and_examples.py
  2. 4 4
      nicegui/elements/line_plot.py
  3. 1 0
      nicegui/ui.py

+ 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)
             y = np.cos(2 * np.pi * x) * np.exp(-x)
             plt.plot(x, y, '-')
             plt.plot(x, y, '-')
 
 
-    # @example(ui.line_plot)
+    @example(ui.line_plot, skip=False)
     def line_plot_example():
     def line_plot_example():
         global line_checkbox
         global line_checkbox
         from datetime import datetime
         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)
             y2 = np.cos(x)
             line_plot.push([now], [[y1], [y2]])
             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)
     @example(ui.linear_progress, skip=False)
     def linear_progress_example():
     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):
 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
         """Line Plot
 
 
         Create a line plot. The `push` method provides live updating when utilized in combination with `ui.timer`.
         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):
     def with_legend(self, titles: List[str], **kwargs):
         self.fig.gca().legend(titles, **kwargs)
         self.fig.gca().legend(titles, **kwargs)
-        self.view.set_figure(self.fig)
+        self._convert_to_html()
         return self
         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.push_counter += 1
 
 
         self.x = [*self.x, *x][self.slice]
         self.x = [*self.x, *x][self.slice]
@@ -53,5 +53,5 @@ class LinePlot(Plot):
         pad_y = 0.01 * (max_y - min_y)
         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_xlim(min_x - pad_x, max_x + pad_x)
         self.fig.gca().set_ylim(min_y - pad_y, max_y + pad_y)
         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()
         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.input import Input as input
 from .elements.joystick import Joystick as joystick
 from .elements.joystick import Joystick as joystick
 from .elements.label import Label as label
 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 Link as link
 from .elements.link import LinkTarget as link_target
 from .elements.link import LinkTarget as link_target
 from .elements.log import Log as log
 from .elements.log import Log as log