[yew-devel] [PATCH yew-comp 14/20] rrd: clamp view range when time_data changes

Dominik Csapak d.csapak at proxmox.com
Fri May 30 14:21:56 CEST 2025


otherwise it can happen that the selected range is outside the new
range. While it would be possible to handle that when drawing, it's less
costly to do it once here when we update the component.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/rrd/graph.rs | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/rrd/graph.rs b/src/rrd/graph.rs
index 161269f..b4e7a37 100644
--- a/src/rrd/graph.rs
+++ b/src/rrd/graph.rs
@@ -802,6 +802,23 @@ impl Component for PwtRRDGraph {
         panel.into()
     }
 
+    fn changed(&mut self, ctx: &Context<Self>, _old_props: &Self::Properties) -> bool {
+        let props = ctx.props();
+
+        // clamp view range to the new time data range
+        if let Some((start, end)) = self.view_range {
+            if props.time_data.len() < 10 {
+                self.view_range = None;
+            } else {
+                let end = end.min(props.time_data.len() - 1);
+                let start = start.min(end - 10);
+                self.view_range = Some((start, end));
+            }
+        }
+
+        true
+    }
+
     fn rendered(&mut self, ctx: &Context<Self>, first_render: bool) {
         if first_render {
             if let Some(el) = self.node_ref.cast::<web_sys::Element>() {
-- 
2.39.5





More information about the yew-devel mailing list