From: Dominik Csapak <d.csapak@proxmox.com>
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 [thread overview]
Message-ID: <20261126145410.3011676-6-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261126145410.3011676-1-d.csapak@proxmox.com>
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 <d.csapak@proxmox.com>
---
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<AttrValue>,
tooltip_info: Option<TooltipInfo>,
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>) -> Self {
+ fn create(ctx: &yew::Context<Self>) -> 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<Self>, _old_props: &Self::Properties) -> bool {
+ self.graph_backgrounds = graph_backgrounds(ctx.props());
+ true
+ }
+
fn view(&self, ctx: &yew::Context<Self>) -> 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<Option<f64>>, threshold: f64) -> Container {
+/// Returns the CSS 'background-image' value for the usage graph of the given data.
+fn graph_background(data: &[Option<f64>], 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<Option<f64>>, 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<AttrValue> {
+ props
+ .entities
+ .iter()
+ .map(|entity| graph_background(&entity.rrd_data.data, props.threshold))
+ .collect()
}
pub fn create_top_entities_panel(
--
2.47.3
next prev parent reply other threads:[~2026-11-26 14:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 14:49 [PATCH datacenter-manager 00/10] dashborad: add widget settings and leaderboard graph types Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 01/10] ui: dashboard: use plural for the container panel Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 02/10] ui: views: keep the icon for custom widget titles Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 03/10] ui: views: add options panel for editing widgets Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 04/10] ui: views: add only one menu entry per widget type Dominik Csapak
2026-11-26 14:49 ` Dominik Csapak [this message]
2026-11-26 14:49 ` [PATCH datacenter-manager 06/10] ui: dashboard: top entities: center data points in their interval Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 07/10] ui: dashboard: top entities: limit color stops by graph width Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 08/10] ui: dashboard: top entities: add line, area and bar graph types Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 09/10] ui: dashboard: top entities: show indicator line for tooltip point Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 10/10] docs: custom views: mention the graph types of the leaderboard widget Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126145410.3011676-6-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox