From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 2F82C1FF0B3 for ; Thu, 26 Nov 2026 15:54:18 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id D1CAB21706; Thu, 26 Nov 2026 15:54:16 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager 05/10] ui: dashboard: top entities: only build graph gradients on change Date: Thu, 26 Nov 2026 15:49:18 +0100 Message-ID: <20261126145410.3011676-6-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261126145410.3011676-1-d.csapak@proxmox.com> References: <20261126145410.3011676-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.260 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: NN2YKQUR6V4DPZH6FAZ3Y6S46QUEA6QK X-Message-ID-Hash: NN2YKQUR6V4DPZH6FAZ3Y6S46QUEA6QK X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: moving the pointer over a graph updates the tooltip, which re-renders the whole component. Since the gradients were generated in 'view', they were rebuilt for all graphs every time, even though they only depend on the properties. Calculate them only when the properties change and save them in the component instead. Signed-off-by: Dominik Csapak --- ui/src/dashboard/top_entities.rs | 45 +++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/ui/src/dashboard/top_entities.rs b/ui/src/dashboard/top_entities.rs index 122f8287..8985ebbc 100644 --- a/ui/src/dashboard/top_entities.rs +++ b/ui/src/dashboard/top_entities.rs @@ -68,6 +68,9 @@ struct TooltipInfo { } struct TopEntitiesComp { + /// The graph backgrounds in the same order as the entities, only calculated when the + /// properties change and not on every re-render, e.g. when moving the tooltip. + graph_backgrounds: Vec, tooltip_info: Option, tooltip_ref: NodeRef, tooltip_anchor: NodeRef, @@ -77,8 +80,9 @@ impl Component for TopEntitiesComp { type Message = Msg; type Properties = TopEntities; - fn create(_ctx: &yew::Context) -> Self { + fn create(ctx: &yew::Context) -> Self { Self { + graph_backgrounds: graph_backgrounds(ctx.props()), tooltip_info: None, tooltip_ref: NodeRef::default(), tooltip_anchor: NodeRef::default(), @@ -124,6 +128,11 @@ impl Component for TopEntitiesComp { true } + fn changed(&mut self, ctx: &yew::Context, _old_props: &Self::Properties) -> bool { + self.graph_backgrounds = graph_backgrounds(ctx.props()); + true + } + fn view(&self, ctx: &yew::Context) -> yew::Html { let props = ctx.props(); let mut list = Container::new() @@ -134,9 +143,8 @@ impl Component for TopEntitiesComp { .style("gap", "var(--pwt-spacer-3)"); let mut tooltip = None; let data = &props.entities; - for entity in data.iter().rev() { + for (entity, graph_background) in data.iter().zip(&self.graph_backgrounds).rev() { let resource = &entity.resource; - let rrd = &entity.rrd_data; let remote = &entity.remote; let node = resource.as_resource_view().node().map(|n| n.to_string()); @@ -190,7 +198,10 @@ impl Component for TopEntitiesComp { ); list.add_child( - graph_from_data(&rrd.data, props.threshold) + Container::new() + .width(CssLength::Fraction(1.0)) + .class("line-usage-graph") + .style("background-image", graph_background.clone()) .style("flex", "5 0") .onpointermove(ctx.link().callback({ let resource = resource.clone(); @@ -282,7 +293,8 @@ const BACKGROUND_COLOR: &str = "var(--pwt-color-surface)"; const COLOR_SPACE: &str = "oklab"; -fn graph_from_data(data: &Vec>, threshold: f64) -> Container { +/// Returns the CSS 'background-image' value for the usage graph of the given data. +fn graph_background(data: &[Option], threshold: f64) -> AttrValue { let mut list = Vec::new(); for (i, point) in data.iter().enumerate() { if let Some(point) = point { @@ -319,16 +331,19 @@ fn graph_from_data(data: &Vec>, threshold: f64) -> Container { )); }; } - Container::new() - .width(CssLength::Fraction(1.0)) - .class("line-usage-graph") - .style( - "background-image", - format!( - "linear-gradient(in {COLOR_SPACE} to right, {})", - list.join(", ") - ), - ) + format!( + "linear-gradient(in {COLOR_SPACE} to right, {})", + list.join(", ") + ) + .into() +} + +fn graph_backgrounds(props: &TopEntities) -> Vec { + props + .entities + .iter() + .map(|entity| graph_background(&entity.rrd_data.data, props.threshold)) + .collect() } pub fn create_top_entities_panel( -- 2.47.3