* [PATCH datacenter-manager 00/10] dashborad: add widget settings and leaderboard graph types
@ 2026-11-26 14:49 Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 01/10] ui: dashboard: use plural for the container panel Dominik Csapak
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Dominik Csapak @ 2026-11-26 14:49 UTC (permalink / raw)
To: pdm-devel
The leaderboard 'heatmap' graph type is nice for some, but in certain
scenarios not that good to decipher, especially when one is visually
impaired or the values are simply too close together. For that, add
multiple graph types (line,area,bar) for those.
To be able to set these, add a widget options panel where the option for
each widget can be set individually.
The dashboard layout types already had some settings, but they were only
configurable either by hand or indirect (by using a differen variant
from the add menu).
This now makes the add menu a bit more sparse, since the user can simply
configure the wanted options themselves.
With that, the previously unexposed custom title option for each widget
is also exposed, giving users the possibility to give the widget other
titles if they so desire.
Some of the patches are more fixes found along the way, that could be
applied independently, e.g. 1, 5, 6, 7.
Dominik Csapak (10):
ui: dashboard: use plural for the container panel
ui: views: keep the icon for custom widget titles
ui: views: add options panel for editing widgets
ui: views: add only one menu entry per widget type
ui: dashboard: top entities: only build graph gradients on change
ui: dashboard: top entities: center data points in their interval
ui: dashboard: top entities: limit color stops by graph width
ui: dashboard: top entities: add line, area and bar graph types
ui: dashboard: top entities: show indicator line for tooltip point
docs: custom views: mention the graph types of the leaderboard widget
docs/views.rst | 3 +-
lib/pdm-api-types/src/views.rs | 45 ++
ui/src/dashboard/gauge_panel.rs | 22 +-
ui/src/dashboard/guest_panel.rs | 7 -
ui/src/dashboard/node_status_panel.rs | 8 -
ui/src/dashboard/pbs_datastores_panel.rs | 5 -
ui/src/dashboard/remote_panel.rs | 6 +-
ui/src/dashboard/resource_tree.rs | 1 -
ui/src/dashboard/sdn_zone_panel.rs | 5 +-
ui/src/dashboard/subscription_info.rs | 8 -
ui/src/dashboard/tasks.rs | 24 +-
ui/src/dashboard/top_entities.rs | 563 +++++++++++++++++++----
ui/src/dashboard/view.rs | 123 +++--
ui/src/dashboard/view/row_element.rs | 29 +-
ui/src/dashboard/view/row_view.rs | 283 +++++-------
ui/src/dashboard/view/widget_options.rs | 302 ++++++++++++
16 files changed, 1072 insertions(+), 362 deletions(-)
create mode 100644 ui/src/dashboard/view/widget_options.rs
--
2.47.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH datacenter-manager 01/10] ui: dashboard: use plural for the container panel
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 ` Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 02/10] ui: views: keep the icon for custom widget titles Dominik Csapak
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dominik Csapak @ 2026-11-26 14:49 UTC (permalink / raw)
To: pdm-devel
in its title and in the menu for adding it, like for the other guest
panels, e.g. 'Virtual Machines'.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/src/dashboard/guest_panel.rs | 2 +-
ui/src/dashboard/view/row_view.rs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/ui/src/dashboard/guest_panel.rs b/ui/src/dashboard/guest_panel.rs
index 3583de24..2a5b4fca 100644
--- a/ui/src/dashboard/guest_panel.rs
+++ b/ui/src/dashboard/guest_panel.rs
@@ -222,7 +222,7 @@ pub fn create_guest_panel(
) -> Panel {
let (icon, title) = match guest_type {
Some(GuestType::Qemu) => ("desktop", tr!("Virtual Machines")),
- Some(GuestType::Lxc) => ("cubes", tr!("Linux Container")),
+ Some(GuestType::Lxc) => ("cubes", tr!("Linux Containers")),
None => ("desktop", tr!("Guests")),
};
let status = status.read();
diff --git a/ui/src/dashboard/view/row_view.rs b/ui/src/dashboard/view/row_view.rs
index 0efeb066..535230c9 100644
--- a/ui/src/dashboard/view/row_view.rs
+++ b/ui/src/dashboard/view/row_view.rs
@@ -610,7 +610,7 @@ fn create_menu(ctx: &yew::Context<RowViewComp>, new_coords: Position) -> Menu {
)),
)
.with_item(
- MenuItem::new(tr!("Linux Container")).on_select(create_callback(
+ MenuItem::new(tr!("Linux Containers")).on_select(create_callback(
WidgetType::Guests {
guest_type: Some(GuestType::Lxc),
},
--
2.47.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH datacenter-manager 02/10] ui: views: keep the icon for custom widget titles
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 ` Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 03/10] ui: views: add options panel for editing widgets Dominik Csapak
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dominik Csapak @ 2026-11-26 14:49 UTC (permalink / raw)
To: pdm-devel
a custom title replaced the whole title of the panel, including its
icon, since the icon was part of the title the panel creators set.
Move the default icons and titles of all widgets into one function and
set the title when rendering the widget, so a custom title only
replaces the text.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/src/dashboard/gauge_panel.rs | 22 +----
ui/src/dashboard/guest_panel.rs | 7 --
ui/src/dashboard/node_status_panel.rs | 8 --
ui/src/dashboard/pbs_datastores_panel.rs | 5 -
ui/src/dashboard/remote_panel.rs | 6 +-
ui/src/dashboard/resource_tree.rs | 1 -
ui/src/dashboard/sdn_zone_panel.rs | 5 +-
ui/src/dashboard/subscription_info.rs | 8 --
ui/src/dashboard/tasks.rs | 24 ++---
ui/src/dashboard/top_entities.rs | 50 +++++-----
ui/src/dashboard/view.rs | 112 ++++++++++++++++++-----
11 files changed, 122 insertions(+), 126 deletions(-)
diff --git a/ui/src/dashboard/gauge_panel.rs b/ui/src/dashboard/gauge_panel.rs
index 24d0f323..b697ec0e 100644
--- a/ui/src/dashboard/gauge_panel.rs
+++ b/ui/src/dashboard/gauge_panel.rs
@@ -12,15 +12,13 @@ use pdm_api_types::remotes::RemoteType;
use pdm_api_types::{resource::ResourcesStatus, views::NodeResourceType};
use crate::LoadResult;
-use crate::dashboard::{create_title_with_icon, loading_column};
+use crate::dashboard::loading_column;
struct PanelConfig {
show_cpu: bool,
show_mem: bool,
show_storage: bool,
- title: String,
subtitle: bool,
- icon: &'static str,
}
impl PanelConfig {
@@ -30,33 +28,25 @@ impl PanelConfig {
show_cpu: true,
show_mem: false,
show_storage: false,
- title: tr!("CPU Usage"),
subtitle: false,
- icon: "cpu",
},
Some(NodeResourceType::Memory) => PanelConfig {
show_cpu: false,
show_mem: true,
show_storage: false,
- title: tr!("Memory Usage"),
subtitle: false,
- icon: "memory",
},
Some(NodeResourceType::Storage) => PanelConfig {
show_cpu: false,
show_mem: false,
show_storage: true,
- title: tr!("Storage Usage"),
subtitle: false,
- icon: "database",
},
None => PanelConfig {
show_cpu: true,
show_mem: true,
show_storage: true,
- title: tr!("Resource Usage"),
subtitle: true,
- icon: "tachometer",
},
}
}
@@ -74,19 +64,9 @@ pub fn create_gauge_panel(
let status = status.read();
let conf = PanelConfig::new(resource_type);
- let suffix = match remote_type {
- Some(RemoteType::Pve) => " - Virtual Environment",
- Some(RemoteType::Pbs) => " - Backup Server",
- None => "",
- };
-
let is_loading = !status.has_data();
Panel::new()
- .title(create_title_with_icon(
- conf.icon,
- format!("{}{suffix}", conf.title),
- ))
.border(true)
.with_optional_child(status.data.as_ref().map(|data| {
let (cpu, mem, storage) = match remote_type {
diff --git a/ui/src/dashboard/guest_panel.rs b/ui/src/dashboard/guest_panel.rs
index 2a5b4fca..b962d09d 100644
--- a/ui/src/dashboard/guest_panel.rs
+++ b/ui/src/dashboard/guest_panel.rs
@@ -16,7 +16,6 @@ use pdm_api_types::resource::{GuestStatusCount, ResourceType, ResourcesStatus};
use pdm_search::{Search, SearchTerm};
use crate::LoadResult;
-use crate::dashboard::create_title_with_icon;
use crate::dashboard::view::add_current_view_to_search;
use crate::pve::GuestType;
use crate::search_provider::get_search_provider;
@@ -220,14 +219,8 @@ pub fn create_guest_panel(
guest_type: Option<GuestType>,
status: SharedState<LoadResult<ResourcesStatus, Error>>,
) -> Panel {
- let (icon, title) = match guest_type {
- Some(GuestType::Qemu) => ("desktop", tr!("Virtual Machines")),
- Some(GuestType::Lxc) => ("cubes", tr!("Linux Containers")),
- None => ("desktop", tr!("Guests")),
- };
let status = status.read();
Panel::new()
- .title(create_title_with_icon(icon, title))
.with_child(GuestPanel::new(guest_type, status.data.clone()))
.with_optional_child(
status
diff --git a/ui/src/dashboard/node_status_panel.rs b/ui/src/dashboard/node_status_panel.rs
index 6bfcf85f..18fd648e 100644
--- a/ui/src/dashboard/node_status_panel.rs
+++ b/ui/src/dashboard/node_status_panel.rs
@@ -14,7 +14,6 @@ use pdm_api_types::resource::NodeStatusCount;
use pdm_api_types::{remotes::RemoteType, resource::ResourcesStatus};
use crate::LoadResult;
-use crate::dashboard::create_title_with_icon;
use crate::dashboard::view::add_current_view_to_search;
use crate::search_provider::get_search_provider;
@@ -161,12 +160,6 @@ pub fn create_node_panel(
remote_type: Option<RemoteType>,
status: SharedState<LoadResult<ResourcesStatus, Error>>,
) -> Panel {
- let (icon, title) = match remote_type {
- Some(RemoteType::Pve) => ("building", tr!("Virtual Environment Nodes")),
- Some(RemoteType::Pbs) => ("building-o", tr!("Backup Server Nodes")),
- None => ("building", tr!("Nodes")),
- };
-
let status = status.read();
let (nodes_status, failed_remotes) = match &status.data {
@@ -194,7 +187,6 @@ pub fn create_node_panel(
};
Panel::new()
- .title(create_title_with_icon(icon, title))
.border(true)
.with_child(NodeStatusPanel::new(
remote_type,
diff --git a/ui/src/dashboard/pbs_datastores_panel.rs b/ui/src/dashboard/pbs_datastores_panel.rs
index ba7c9b89..2bb1cfe6 100644
--- a/ui/src/dashboard/pbs_datastores_panel.rs
+++ b/ui/src/dashboard/pbs_datastores_panel.rs
@@ -12,7 +12,6 @@ use pwt::state::SharedState;
use pwt::widget::{Container, Fa, List, ListTile, Panel};
use crate::LoadResult;
-use crate::dashboard::create_title_with_icon;
use crate::dashboard::view::add_current_view_to_search;
use crate::search_provider::get_search_provider;
@@ -170,10 +169,6 @@ pub fn create_pbs_datastores_panel(
.map(|status| status.pbs_datastores.clone());
Panel::new()
- .title(create_title_with_icon(
- "database",
- tr!("Backup Server Datastores"),
- ))
.border(true)
.with_child(PbsDatastoresPanel::new(pbs_datastores))
}
diff --git a/ui/src/dashboard/remote_panel.rs b/ui/src/dashboard/remote_panel.rs
index 2e631d7c..bc2cf8b2 100644
--- a/ui/src/dashboard/remote_panel.rs
+++ b/ui/src/dashboard/remote_panel.rs
@@ -17,7 +17,7 @@ use pdm_api_types::resource::ResourcesStatus;
use crate::LoadResult;
use crate::dashboard::view::add_current_view_to_search;
-use crate::{dashboard::create_title_with_icon, search_provider::get_search_provider};
+use crate::search_provider::get_search_provider;
#[derive(Properties, PartialEq)]
/// A panel for showing the overall remotes status
@@ -148,9 +148,7 @@ pub fn create_remote_panel(
on_pbs_wizard: Option<impl IntoEventCallback<MenuEvent>>,
) -> Panel {
let status = status.read();
- let mut panel = Panel::new()
- .title(create_title_with_icon("server", tr!("Remotes")))
- .with_child(RemotePanel::new(status.data.clone()));
+ let mut panel = Panel::new().with_child(RemotePanel::new(status.data.clone()));
if on_pve_wizard.is_some() || on_pbs_wizard.is_some() {
let mut menu = Menu::new();
diff --git a/ui/src/dashboard/resource_tree.rs b/ui/src/dashboard/resource_tree.rs
index 51f2d1d2..4b233fc2 100644
--- a/ui/src/dashboard/resource_tree.rs
+++ b/ui/src/dashboard/resource_tree.rs
@@ -48,6 +48,5 @@ fn ResourceTreeWithSearch(props: &ResourceTreeWithSearchProps) -> Html {
pub fn create_resource_tree(redraw_controller: RedrawController) -> Panel {
Panel::new()
.class(css::FlexFit)
- .title(tr!("Resources"))
.with_child(html! {<ResourceTreeWithSearch {redraw_controller} />})
}
diff --git a/ui/src/dashboard/sdn_zone_panel.rs b/ui/src/dashboard/sdn_zone_panel.rs
index 24b0299f..5d5328db 100644
--- a/ui/src/dashboard/sdn_zone_panel.rs
+++ b/ui/src/dashboard/sdn_zone_panel.rs
@@ -16,7 +16,6 @@ use yew::{
};
use crate::LoadResult;
-use crate::dashboard::create_title_with_icon;
use crate::dashboard::view::add_current_view_to_search;
use crate::search_provider::get_search_provider;
@@ -175,7 +174,5 @@ pub fn create_sdn_panel(status: SharedState<LoadResult<ResourcesStatus, Error>>)
.as_ref()
.map(|status| status.sdn_zones.clone());
- Panel::new()
- .title(create_title_with_icon("sdn", tr!("SDN Zones")))
- .with_child(SdnZonePanel::new(sdn_zones_status))
+ Panel::new().with_child(SdnZonePanel::new(sdn_zones_status))
}
diff --git a/ui/src/dashboard/subscription_info.rs b/ui/src/dashboard/subscription_info.rs
index a344010b..d19896a4 100644
--- a/ui/src/dashboard/subscription_info.rs
+++ b/ui/src/dashboard/subscription_info.rs
@@ -157,15 +157,7 @@ pub fn create_subscription_panel(
subs: SharedState<LoadResult<Vec<RemoteSubscriptions>, Error>>,
on_details_clicked: Callback<MouseEvent>,
) -> Panel {
- let title: Html = Row::new()
- .class(AlignItems::Center)
- .gap(2)
- .with_child(Fa::new("ticket"))
- .with_child(tr!("Remote Subscription Status"))
- .into();
-
let mut panel = Panel::new()
- .title(title)
.border(true)
.with_child(SubscriptionInfo::new(subs.read().data.clone()));
diff --git a/ui/src/dashboard/tasks.rs b/ui/src/dashboard/tasks.rs
index 9c91fab2..06ba49de 100644
--- a/ui/src/dashboard/tasks.rs
+++ b/ui/src/dashboard/tasks.rs
@@ -22,7 +22,6 @@ use pwt_macros::{builder, widget};
use pdm_api_types::TaskStatistics;
use crate::LoadResult;
-use crate::dashboard::create_title_with_icon;
use crate::dashboard::loading_column;
use crate::dashboard::refresh_config_edit::DEFAULT_TASK_SUMMARY_HOURS;
use crate::tasks::TaskWorkerType;
@@ -308,27 +307,20 @@ impl Component for ProxmoxTaskSummary {
pub fn create_task_summary_panel(
statistics: SharedState<LoadResult<TaskStatistics, Error>>,
remotes: Option<u32>,
- hours: u32,
since: i64,
) -> Panel {
- let title = match remotes {
- Some(_count) => tr!("Task Summary Sorted by Failed Tasks (Last {0}h)", hours),
- None => tr!("Task Summary by Category (Last {0}h)", hours),
- };
let loading = !statistics.read().has_data();
let guard = statistics.read();
let data = guard.data.clone();
let error = guard.error.as_ref();
- Panel::new()
- .title(create_title_with_icon("list", title))
- .with_child(
- Container::new()
- .class(css::FlexFit)
- .padding(2)
- .with_optional_child(data.map(|data| TaskSummary::new(data, since, remotes)))
- .with_optional_child((loading).then_some(loading_column()))
- .with_optional_child(error.map(|err| error_message(&err.to_string()))),
- )
+ Panel::new().with_child(
+ Container::new()
+ .class(css::FlexFit)
+ .padding(2)
+ .with_optional_child(data.map(|data| TaskSummary::new(data, since, remotes)))
+ .with_optional_child((loading).then_some(loading_column()))
+ .with_optional_child(error.map(|err| error_message(&err.to_string()))),
+ )
}
pub fn get_task_options(last_hours: Option<u32>) -> (u32, i64) {
diff --git a/ui/src/dashboard/top_entities.rs b/ui/src/dashboard/top_entities.rs
index cdc3b465..122f8287 100644
--- a/ui/src/dashboard/top_entities.rs
+++ b/ui/src/dashboard/top_entities.rs
@@ -24,7 +24,7 @@ use pdm_client::types::{Resource, TopEntity};
use crate::LoadResult;
use crate::{
- dashboard::{create_title_with_icon, loading_column},
+ dashboard::loading_column,
get_deep_url, navigate_to,
renderer::{render_resource_icon, render_resource_name},
};
@@ -338,35 +338,27 @@ pub fn create_top_entities_panel(
leaderboard_type: LeaderboardType,
) -> Panel {
let top_entities = top_entities.read();
- let (entities, icon, title, metrics_title, metrics_empty_message, threshold) =
- match leaderboard_type {
- LeaderboardType::GuestCpu => (
- top_entities.data.as_ref().map(|e| e.guest_cpu.clone()),
- "desktop",
- tr!("Guests With the Highest CPU Usage"),
- tr!("CPU usage"),
- tr!("No guests available"),
- 0.85,
- ),
- LeaderboardType::NodeCpu => (
- top_entities.data.as_ref().map(|e| e.node_cpu.clone()),
- "building",
- tr!("Nodes With the Highest CPU Usage"),
- tr!("CPU usage"),
- tr!("No nodes available"),
- 0.85,
- ),
- LeaderboardType::NodeMemory => (
- top_entities.data.as_ref().map(|e| e.node_memory.clone()),
- "building",
- tr!("Nodes With the Highest Memory Usage"),
- tr!("Memory usage"),
- tr!("No nodes available"),
- 0.95,
- ),
- };
+ let (entities, metrics_title, metrics_empty_message, threshold) = match leaderboard_type {
+ LeaderboardType::GuestCpu => (
+ top_entities.data.as_ref().map(|e| e.guest_cpu.clone()),
+ tr!("CPU usage"),
+ tr!("No guests available"),
+ 0.85,
+ ),
+ LeaderboardType::NodeCpu => (
+ top_entities.data.as_ref().map(|e| e.node_cpu.clone()),
+ tr!("CPU usage"),
+ tr!("No nodes available"),
+ 0.85,
+ ),
+ LeaderboardType::NodeMemory => (
+ top_entities.data.as_ref().map(|e| e.node_memory.clone()),
+ tr!("Memory usage"),
+ tr!("No nodes available"),
+ 0.95,
+ ),
+ };
Panel::new()
- .title(create_title_with_icon(icon, title))
.with_optional_child(entities.and_then(|entities| {
let html: Html = if entities.is_empty() {
Row::new()
diff --git a/ui/src/dashboard/view.rs b/ui/src/dashboard/view.rs
index 64480310..8d8f83a9 100644
--- a/ui/src/dashboard/view.rs
+++ b/ui/src/dashboard/view.rs
@@ -28,7 +28,7 @@ use crate::dashboard::{
DashboardStatusRow, create_gauge_panel, create_guest_panel, create_map_panel,
create_node_panel, create_pbs_datastores_panel, create_refresh_config_edit_window,
create_remote_panel, create_resource_tree, create_sdn_panel, create_subscription_panel,
- create_task_summary_panel, create_top_entities_panel,
+ create_task_summary_panel, create_title_with_icon, create_top_entities_panel,
};
use crate::remotes::AddWizard;
use crate::renderer::empty_state;
@@ -36,10 +36,11 @@ use crate::widget::RedrawController;
use crate::{LoadResult, RemoteList, pdm_client};
use pdm_api_types::remotes::RemoteType;
-use pdm_api_types::resource::ResourcesStatus;
+use pdm_api_types::resource::{GuestType, ResourcesStatus};
use pdm_api_types::subscription::RemoteSubscriptions;
use pdm_api_types::views::{
- RowWidget, TaskSummaryGrouping, ViewConfig, ViewLayout, ViewTemplate, WidgetType,
+ LeaderboardType, NodeResourceType, RowWidget, TaskSummaryGrouping, ViewConfig, ViewLayout,
+ ViewTemplate, WidgetType,
};
use pdm_api_types::{CachedLocationInfo, TaskStatistics};
use pdm_client::types::TopEntities;
@@ -149,6 +150,8 @@ fn render_widget(
redraw_controller,
} = render_args;
+ let (task_hours, task_since) = get_task_options(refresh_config.task_last_hours);
+
let mut widget = match &item.r#type {
WidgetType::Nodes { remote_type } => create_node_panel(*remote_type, status),
WidgetType::Guests { guest_type } => {
@@ -174,8 +177,7 @@ fn render_widget(
TaskSummaryGrouping::Category => None,
TaskSummaryGrouping::Remote => Some(5),
};
- let (hours, since) = get_task_options(refresh_config.task_last_hours);
- create_task_summary_panel(statistics, remotes, hours, since)
+ create_task_summary_panel(statistics, remotes, task_since)
}
WidgetType::ResourceTree => create_resource_tree(redraw_controller),
WidgetType::NodeResourceGauge {
@@ -186,13 +188,80 @@ fn render_widget(
WidgetType::UnknownWidget { widget_type, .. } => create_unknown_widget_panel(widget_type),
};
- if let Some(title) = &item.title {
- widget.set_title(title.clone());
+ let (icon, default_title) = default_widget_title(&item.r#type, task_hours);
+ if let Some(title) = item.title.clone().or(default_title) {
+ match icon {
+ Some(icon) => widget.set_title(create_title_with_icon(icon, title)),
+ None => widget.set_title(title),
+ }
}
widget.border(false).class(css::FlexFit).into()
}
+/// Returns the default icon and title of a widget, if it has any.
+fn default_widget_title(
+ widget_type: &WidgetType,
+ task_hours: u32,
+) -> (Option<&'static str>, Option<String>) {
+ let (icon, title) = match widget_type {
+ WidgetType::Nodes { remote_type } => match remote_type {
+ Some(RemoteType::Pve) => ("building", tr!("Virtual Environment Nodes")),
+ Some(RemoteType::Pbs) => ("building-o", tr!("Backup Server Nodes")),
+ None => ("building", tr!("Nodes")),
+ },
+ WidgetType::Guests { guest_type } => match guest_type {
+ Some(GuestType::Qemu) => ("desktop", tr!("Virtual Machines")),
+ Some(GuestType::Lxc) => ("cubes", tr!("Linux Containers")),
+ None => ("desktop", tr!("Guests")),
+ },
+ WidgetType::PbsDatastores => ("database", tr!("Backup Server Datastores")),
+ WidgetType::Remotes { .. } => ("server", tr!("Remotes")),
+ WidgetType::Subscription => ("ticket", tr!("Remote Subscription Status")),
+ WidgetType::Sdn => ("sdn", tr!("SDN Zones")),
+ WidgetType::Leaderboard { leaderboard_type } => match leaderboard_type {
+ LeaderboardType::GuestCpu => ("desktop", tr!("Guests With the Highest CPU Usage")),
+ LeaderboardType::NodeCpu => ("building", tr!("Nodes With the Highest CPU Usage")),
+ LeaderboardType::NodeMemory => ("building", tr!("Nodes With the Highest Memory Usage")),
+ },
+ WidgetType::TaskSummary { grouping } => match grouping {
+ TaskSummaryGrouping::Category => (
+ "list",
+ tr!("Task Summary by Category (Last {0}h)", task_hours),
+ ),
+ TaskSummaryGrouping::Remote => (
+ "list",
+ tr!(
+ "Task Summary Sorted by Failed Tasks (Last {0}h)",
+ task_hours
+ ),
+ ),
+ },
+ WidgetType::NodeResourceGauge {
+ resource,
+ remote_type,
+ } => {
+ let (icon, title) = match resource {
+ Some(NodeResourceType::Cpu) => ("cpu", tr!("CPU Usage")),
+ Some(NodeResourceType::Memory) => ("memory", tr!("Memory Usage")),
+ Some(NodeResourceType::Storage) => ("database", tr!("Storage Usage")),
+ None => ("tachometer", tr!("Resource Usage")),
+ };
+ let suffix = match remote_type {
+ Some(RemoteType::Pve) => " - Virtual Environment",
+ Some(RemoteType::Pbs) => " - Backup Server",
+ None => "",
+ };
+ (icon, format!("{title}{suffix}"))
+ }
+ WidgetType::ResourceTree => return (None, Some(tr!("Resources"))),
+ WidgetType::Map => return (None, None),
+ WidgetType::UnknownWidget { .. } => return (None, Some(tr!("Unknown Widget"))),
+ };
+
+ (Some(icon), Some(title))
+}
+
impl ViewComp {
fn reload(&mut self, ctx: &yew::Context<Self>) {
let max_age = if self.load_finished_time.is_some() {
@@ -790,20 +859,17 @@ pub fn add_current_view_to_search<T: yew::Component>(ctx: &yew::Context<T>, sear
}
fn create_unknown_widget_panel(widget_type: &str) -> Panel {
- Panel::new()
- .title(tr!("Unknown Widget"))
- .border(true)
- .with_child(
- Column::new()
- .class(css::FlexFit)
- .class(css::JustifyContent::Center)
- .class(css::AlignItems::Center)
- .with_child(
- Row::new()
- .gap(1)
- .class(css::AlignItems::Center)
- .with_child(Fa::from(Status::Warning).large_2x())
- .with_child(span(tr!("Unknown Widget of type '{0}'", widget_type))),
- ),
- )
+ Panel::new().border(true).with_child(
+ Column::new()
+ .class(css::FlexFit)
+ .class(css::JustifyContent::Center)
+ .class(css::AlignItems::Center)
+ .with_child(
+ Row::new()
+ .gap(1)
+ .class(css::AlignItems::Center)
+ .with_child(Fa::from(Status::Warning).large_2x())
+ .with_child(span(tr!("Unknown Widget of type '{0}'", widget_type))),
+ ),
+ )
}
--
2.47.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH datacenter-manager 03/10] ui: views: add options panel for editing widgets
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 ` Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 04/10] ui: views: add only one menu entry per widget type Dominik Csapak
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dominik Csapak @ 2026-11-26 14:49 UTC (permalink / raw)
To: pdm-devel
so users can change the options of an existing widget, instead of
having to remove it and add another variant from the menu. This also
makes it possible to set a custom title, which was only possible by
editing the layout manually.
In edit mode, each widget now has a pencil button that opens a panel
on the right side with the widget's options. Changes are applied to
the layout immediately, so the widget acts as a live preview, and are
saved or reverted together with the rest of the layout changes.
I opted for a dedicated button instead of opening the options when
clicking the widget, since in edit mode a pointer down on the widget
already starts dragging it.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/src/dashboard/view.rs | 2 +
ui/src/dashboard/view/row_element.rs | 29 ++-
ui/src/dashboard/view/row_view.rs | 87 +++++++-
ui/src/dashboard/view/widget_options.rs | 281 ++++++++++++++++++++++++
4 files changed, 394 insertions(+), 5 deletions(-)
create mode 100644 ui/src/dashboard/view/widget_options.rs
diff --git a/ui/src/dashboard/view.rs b/ui/src/dashboard/view.rs
index 8d8f83a9..c46a85b0 100644
--- a/ui/src/dashboard/view.rs
+++ b/ui/src/dashboard/view.rs
@@ -51,6 +51,8 @@ pub use row_view::RowView;
mod row_element;
+mod widget_options;
+
#[derive(Debug, Clone, PartialEq, Copy)]
pub enum EditingMessage {
Start,
diff --git a/ui/src/dashboard/view/row_element.rs b/ui/src/dashboard/view/row_element.rs
index 01d868e6..40686160 100644
--- a/ui/src/dashboard/view/row_element.rs
+++ b/ui/src/dashboard/view/row_element.rs
@@ -3,7 +3,7 @@ use yew::html::IntoEventCallback;
use pwt::css;
use pwt::prelude::*;
use pwt::props::RenderFn;
-use pwt::widget::{ActionIcon, Card, Fa, Panel, Row};
+use pwt::widget::{ActionIcon, Card, Fa, Panel, Row, Tooltip};
use pwt_macros::{builder, widget};
use pdm_api_types::views::RowWidget;
@@ -23,6 +23,11 @@ pub struct RowElement {
#[prop_or_default]
is_dragging: bool,
+ #[builder]
+ #[prop_or_default]
+ /// Highlights the element, e.g. while its options are edited
+ selected: bool,
+
#[builder_cb(IntoEventCallback, into_event_callback, ())]
#[prop_or_default]
on_remove: Option<Callback<()>>,
@@ -30,6 +35,10 @@ pub struct RowElement {
#[builder_cb(IntoEventCallback, into_event_callback, u32)]
#[prop_or_default]
on_flex_change: Option<Callback<u32>>,
+
+ #[builder_cb(IntoEventCallback, into_event_callback, ())]
+ #[prop_or_default]
+ on_edit: Option<Callback<()>>,
}
impl RowElement {
@@ -84,6 +93,7 @@ impl Component for RowElementComp {
.padding(2)
.style("z-index", "10")
.class(css::AlignItems::Center)
+ .class(css::Display::Flex)
.with_child(Fa::new("bars").style("cursor", "grab").padding_end(1))
.with_child(tr!("Flex"))
.with_child(
@@ -95,6 +105,17 @@ impl Component for RowElementComp {
ActionIcon::new("fa fa-plus")
.on_activate(ctx.link().callback(|_| Msg::FlexIncrease)),
)
+ .with_child(
+ Tooltip::new(ActionIcon::new("fa fa-pencil").on_activate({
+ let on_edit = props.on_edit.clone();
+ move |_| {
+ if let Some(on_edit) = &on_edit {
+ on_edit.emit(());
+ }
+ }
+ }))
+ .tip(tr!("Edit Options")),
+ )
.with_child(ActionIcon::new("fa fa-times").on_activate({
let on_remove = props.on_remove.clone();
move |_| {
@@ -109,6 +130,12 @@ impl Component for RowElementComp {
.listeners(&props.listeners)
.border(true)
.class(props.is_dragging.then_some("dragging-item"))
+ .style(
+ "outline",
+ props
+ .selected
+ .then_some("2px solid var(--pwt-color-primary)"),
+ )
.attribute("draggable", if props.edit_mode { "true" } else { "false" })
.style("position", "relative")
.with_child(widget)
diff --git a/ui/src/dashboard/view/row_view.rs b/ui/src/dashboard/view/row_view.rs
index 535230c9..2f94b4d3 100644
--- a/ui/src/dashboard/view/row_view.rs
+++ b/ui/src/dashboard/view/row_view.rs
@@ -18,6 +18,7 @@ use pwt_macros::builder;
use crate::dashboard::view::EditingMessage;
use crate::dashboard::view::row_element::RowElement;
+use crate::dashboard::view::widget_options::WidgetOptions;
use pdm_api_types::remotes::RemoteType;
use pdm_api_types::views::{
@@ -81,6 +82,9 @@ pub enum Msg {
AddWidget(Position, WidgetType),
RemoveWidget(Position),
MoveRow(usize, MoveDirection), // idx
+ EditWidget(Position), // key
+ CloseWidgetOptions,
+ UpdateWidget(Position, RowWidget), // key
HandleEditMessages,
}
@@ -99,6 +103,7 @@ pub struct RowViewComp {
drag_timeout: Option<Timeout>,
next_row_indices: HashMap<usize, usize>, // for saving the max index for new widgets
+ edited_widget: Option<Position>, // key of the widget whose options are shown
node_ref: NodeRef,
edit_mode: bool,
@@ -150,6 +155,7 @@ impl Component for RowViewComp {
dragging_target: None,
drag_timeout: None,
next_row_indices,
+ edited_widget: None,
node_ref: NodeRef::default(),
edit_mode: false,
_editing_observer,
@@ -159,7 +165,10 @@ impl Component for RowViewComp {
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::RemoveRow(idx) => {
- self.current_layout.remove(idx);
+ let row = self.current_layout.remove(idx);
+ if row.iter().any(|(key, _)| self.edited_widget == Some(*key)) {
+ self.edited_widget = None;
+ }
}
Msg::AddRow => {
self.current_layout.push(Vec::new());
@@ -246,7 +255,10 @@ impl Component for RowViewComp {
);
}
Msg::RemoveWidget(coords) => {
- self.current_layout[coords.row].remove(coords.item);
+ let (key, _) = self.current_layout[coords.row].remove(coords.item);
+ if self.edited_widget == Some(key) {
+ self.edited_widget = None;
+ }
}
Msg::MoveRow(old, direction) => {
let mut new_layout = self.current_layout.clone();
@@ -258,6 +270,25 @@ impl Component for RowViewComp {
new_layout.insert(new_idx, row);
self.current_layout = new_layout;
}
+ Msg::EditWidget(key) => {
+ self.edited_widget = match self.edited_widget {
+ Some(current) if current == key => None,
+ _ => Some(key),
+ };
+ }
+ Msg::CloseWidgetOptions => {
+ self.edited_widget = None;
+ }
+ Msg::UpdateWidget(key, widget) => {
+ if let Some((_, item)) = self
+ .current_layout
+ .iter_mut()
+ .flatten()
+ .find(|(position, _)| *position == key)
+ {
+ *item = widget;
+ }
+ }
Msg::HandleEditMessages => {
let props = ctx.props();
let state = match props.editing_state.clone() {
@@ -306,6 +337,7 @@ impl Component for RowViewComp {
self.dragging = None;
self.dragging_target = None;
self.drag_timeout = None;
+ self.edited_widget = None;
}
}
}
@@ -318,6 +350,7 @@ impl Component for RowViewComp {
let new_layout = extract_row_layout(&props.rows);
if new_layout != self.current_layout {
self.current_layout = new_layout;
+ self.edited_widget = None;
}
}
@@ -333,7 +366,6 @@ impl Component for RowViewComp {
let layout = self.new_layout.as_ref().unwrap_or(&self.current_layout);
let mut row = Row::new()
.padding_x(2)
- .class("pwt-content-spacer-colors")
.class(css::FlexDirection::Row)
.class(css::FlexWrap::Wrap);
@@ -377,6 +409,7 @@ impl Component for RowViewComp {
.margin_bottom(4)
.edit_mode(self.edit_mode)
.is_dragging(self.dragging_target == Some(current_coords))
+ .selected(self.edit_mode && self.edited_widget == Some(*coords))
.key(format!("item-{}-{}", coords.row, coords.item))
.style("flex", flex_style)
.style("touch-action", self.edit_mode.then_some("none"))
@@ -388,6 +421,10 @@ impl Component for RowViewComp {
ctx.link()
.callback(move |flex| Msg::EditFlex(current_coords, flex)),
)
+ .on_edit({
+ let key = *coords;
+ ctx.link().callback(move |_| Msg::EditWidget(key))
+ })
.ondragstart(ctx.link().callback(move |event: DragEvent| {
let data = event.data_transfer().unwrap();
let _ = data.clear_data();
@@ -532,7 +569,49 @@ impl Component for RowViewComp {
),
);
}
- view.add_child(row);
+
+ let widget_options = self
+ .edited_widget
+ .filter(|_| self.edit_mode)
+ .and_then(|key| {
+ layout
+ .iter()
+ .flatten()
+ .find(|(position, _)| *position == key)
+ })
+ .map(|(key, widget)| {
+ let key = *key;
+ Container::new()
+ .key(format!("options-{}-{}", key.row, key.item))
+ .margin_end(4)
+ .margin_bottom(4)
+ .style("flex", "0 0 auto")
+ .style("width", "400px")
+ .style("max-width", "40%")
+ // keep the options visible while scrolling through long layouts
+ .style("position", "sticky")
+ .style("top", "0")
+ .with_child(
+ WidgetOptions::new(widget.clone())
+ .on_change(
+ ctx.link()
+ .callback(move |widget| Msg::UpdateWidget(key, widget)),
+ )
+ .on_close(ctx.link().callback(|_| Msg::CloseWidgetOptions)),
+ )
+ });
+
+ view.add_child(
+ Row::new()
+ .class(css::AlignItems::Start)
+ .class("pwt-content-spacer-colors")
+ .with_child(
+ row.key("rows")
+ .class(css::Flex::Fill)
+ .style("min-width", "0"),
+ )
+ .with_optional_child(widget_options),
+ );
view.into_html_with_ref(self.node_ref.clone())
}
}
diff --git a/ui/src/dashboard/view/widget_options.rs b/ui/src/dashboard/view/widget_options.rs
new file mode 100644
index 00000000..9418d67f
--- /dev/null
+++ b/ui/src/dashboard/view/widget_options.rs
@@ -0,0 +1,281 @@
+use yew::html::IntoEventCallback;
+use yew::virtual_dom::{VComp, VNode};
+
+use pwt::prelude::*;
+use pwt::widget::form::{Checkbox, Combobox, DisplayField, Field};
+use pwt::widget::{ActionIcon, InputPanel, Panel, Tooltip};
+use pwt_macros::builder;
+
+use pdm_api_types::remotes::RemoteType;
+use pdm_api_types::resource::GuestType;
+use pdm_api_types::views::{
+ LeaderboardType, NodeResourceType, RowWidget, TaskSummaryGrouping, WidgetType,
+};
+
+/// Returns the name of the kind of widget, independent of its options.
+pub fn widget_type_name(widget_type: &WidgetType) -> String {
+ match widget_type {
+ WidgetType::Nodes { .. } => tr!("Node Panel"),
+ WidgetType::Guests { .. } => tr!("Guest Panel"),
+ WidgetType::PbsDatastores => tr!("PBS Datastores"),
+ WidgetType::Remotes { .. } => tr!("Remote Panel"),
+ WidgetType::Subscription => tr!("Subscription Panel"),
+ WidgetType::Sdn => tr!("SDN Panel"),
+ WidgetType::Leaderboard { .. } => tr!("Leaderboard"),
+ WidgetType::TaskSummary { .. } => tr!("Task Summary"),
+ WidgetType::ResourceTree => tr!("Resource Tree"),
+ WidgetType::NodeResourceGauge { .. } => tr!("Resource Usage"),
+ WidgetType::Map => tr!("Map"),
+ WidgetType::UnknownWidget { widget_type, .. } => {
+ tr!("Unknown Widget of type '{0}'", widget_type)
+ }
+ }
+}
+
+#[derive(Properties, PartialEq)]
+#[builder]
+/// Shows and edits the options of a single dashboard widget.
+///
+/// Every change is emitted immediately via `on_change`, so that the dashboard can show a live
+/// preview of the widget.
+pub struct WidgetOptions {
+ widget: RowWidget,
+
+ #[builder_cb(IntoEventCallback, into_event_callback, RowWidget)]
+ #[prop_or_default]
+ on_change: Option<Callback<RowWidget>>,
+
+ #[builder_cb(IntoEventCallback, into_event_callback, ())]
+ #[prop_or_default]
+ on_close: Option<Callback<()>>,
+}
+
+impl WidgetOptions {
+ pub fn new(widget: RowWidget) -> Self {
+ yew::props!(Self { widget })
+ }
+}
+
+impl From<WidgetOptions> for VNode {
+ fn from(val: WidgetOptions) -> Self {
+ let comp = VComp::new::<WidgetOptionsComp>(std::rc::Rc::new(val), None);
+ VNode::from(comp)
+ }
+}
+
+pub struct WidgetOptionsComp;
+
+impl Component for WidgetOptionsComp {
+ type Message = ();
+ type Properties = WidgetOptions;
+
+ fn create(_ctx: &Context<Self>) -> Self {
+ Self
+ }
+
+ fn view(&self, ctx: &Context<Self>) -> Html {
+ let props = ctx.props();
+ let widget = &props.widget;
+ let on_change = props.on_change.clone().unwrap_or_default();
+
+ let set_title = on_change.reform({
+ let widget = widget.clone();
+ move |title: String| RowWidget {
+ title: (!title.is_empty()).then_some(title),
+ ..widget.clone()
+ }
+ });
+ let set_type = on_change.reform({
+ let widget = widget.clone();
+ move |r#type| RowWidget {
+ r#type,
+ ..widget.clone()
+ }
+ });
+
+ let mut panel = InputPanel::new()
+ .padding(4)
+ .with_field(
+ tr!("Type"),
+ DisplayField::new().value(widget_type_name(&widget.r#type)),
+ )
+ .with_field(
+ tr!("Title"),
+ Field::new()
+ .placeholder(tr!("Default"))
+ .value(widget.title.clone().unwrap_or_default())
+ .on_change(set_title),
+ );
+
+ match &widget.r#type {
+ WidgetType::Nodes { remote_type } => {
+ panel.add_field(
+ tr!("Remote Type"),
+ remote_type_selector(
+ *remote_type,
+ set_type.reform(|remote_type| WidgetType::Nodes { remote_type }),
+ ),
+ );
+ }
+ WidgetType::Guests { guest_type } => {
+ panel.add_field(
+ tr!("Guest Type"),
+ option_selector(
+ *guest_type,
+ vec![
+ (None, tr!("All Guests")),
+ (Some(GuestType::Qemu), tr!("Virtual Machines")),
+ (Some(GuestType::Lxc), tr!("Linux Containers")),
+ ],
+ set_type.reform(|guest_type| WidgetType::Guests { guest_type }),
+ ),
+ );
+ }
+ WidgetType::Remotes { show_wizard } => {
+ panel.add_field(
+ tr!("Show Add Buttons"),
+ Checkbox::new().checked(*show_wizard).on_change(
+ set_type.reform(|show_wizard| WidgetType::Remotes { show_wizard }),
+ ),
+ );
+ }
+ WidgetType::Leaderboard { leaderboard_type } => {
+ panel.add_field(
+ tr!("Ranking"),
+ option_selector(
+ *leaderboard_type,
+ vec![
+ (
+ LeaderboardType::GuestCpu,
+ tr!("Guests with Highest CPU Usage"),
+ ),
+ (
+ LeaderboardType::NodeCpu,
+ tr!("Nodes with Highest CPU Usage"),
+ ),
+ (
+ LeaderboardType::NodeMemory,
+ tr!("Nodes with Highest Memory Usage"),
+ ),
+ ],
+ set_type.reform(|leaderboard_type| WidgetType::Leaderboard {
+ leaderboard_type,
+ }),
+ ),
+ );
+ }
+ WidgetType::TaskSummary { grouping } => {
+ panel.add_field(
+ tr!("Grouping"),
+ option_selector(
+ *grouping,
+ vec![
+ (TaskSummaryGrouping::Category, tr!("By Category")),
+ (
+ TaskSummaryGrouping::Remote,
+ tr!("By Remote, Sorted by Failed Tasks"),
+ ),
+ ],
+ set_type.reform(|grouping| WidgetType::TaskSummary { grouping }),
+ ),
+ );
+ }
+ &WidgetType::NodeResourceGauge {
+ resource,
+ remote_type,
+ } => {
+ panel.add_field(
+ tr!("Resource"),
+ option_selector(
+ resource,
+ vec![
+ (None, tr!("All Resources")),
+ (Some(NodeResourceType::Cpu), tr!("CPU")),
+ (Some(NodeResourceType::Memory), tr!("Memory")),
+ (Some(NodeResourceType::Storage), tr!("Storage")),
+ ],
+ set_type.reform(move |resource| WidgetType::NodeResourceGauge {
+ resource,
+ remote_type,
+ }),
+ ),
+ );
+ panel.add_field(
+ tr!("Remote Type"),
+ remote_type_selector(
+ remote_type,
+ set_type.reform(move |remote_type| WidgetType::NodeResourceGauge {
+ resource,
+ remote_type,
+ }),
+ ),
+ );
+ }
+ WidgetType::PbsDatastores
+ | WidgetType::Subscription
+ | WidgetType::Sdn
+ | WidgetType::ResourceTree
+ | WidgetType::Map
+ | WidgetType::UnknownWidget { .. } => {}
+ }
+
+ Panel::new()
+ .border(true)
+ .title(tr!("Widget Options"))
+ .with_tool(
+ Tooltip::new(ActionIcon::new("fa fa-times").on_activate({
+ let on_close = props.on_close.clone();
+ move |_| {
+ if let Some(on_close) = &on_close {
+ on_close.emit(());
+ }
+ }
+ }))
+ .tip(tr!("Close")),
+ )
+ .with_child(panel)
+ .into()
+ }
+}
+
+fn remote_type_selector(
+ current: Option<RemoteType>,
+ on_select: Callback<Option<RemoteType>>,
+) -> Combobox {
+ option_selector(
+ current,
+ vec![
+ (None, tr!("All")),
+ (Some(RemoteType::Pve), tr!("Virtual Environment")),
+ (Some(RemoteType::Pbs), tr!("Backup Server")),
+ ],
+ on_select,
+ )
+}
+
+/// Creates a combobox to select one of the given values, labeled by the accompanying text.
+fn option_selector<T: Copy + PartialEq + 'static>(
+ current: T,
+ options: Vec<(T, String)>,
+ on_select: Callback<T>,
+) -> Combobox {
+ let current = options
+ .iter()
+ .position(|(value, _)| *value == current)
+ .map(|idx| idx.to_string());
+ let values: Vec<T> = options.iter().map(|(value, _)| *value).collect();
+
+ Combobox::from_key_value_pairs(
+ options
+ .into_iter()
+ .enumerate()
+ .map(|(idx, (_, label))| (idx.to_string(), label)),
+ )
+ .required(true)
+ .value(current)
+ .on_change(move |key: String| {
+ if let Some(value) = key.parse::<usize>().ok().and_then(|idx| values.get(idx)) {
+ on_select.emit(*value);
+ }
+ })
+}
--
2.47.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH datacenter-manager 04/10] ui: views: add only one menu entry per widget type
2026-11-26 14:49 [PATCH datacenter-manager 00/10] dashborad: add widget settings and leaderboard graph types Dominik Csapak
` (2 preceding siblings ...)
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 ` Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 05/10] ui: dashboard: top entities: only build graph gradients on change Dominik Csapak
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dominik Csapak @ 2026-11-26 14:49 UTC (permalink / raw)
To: pdm-devel
since the variants of a widget can now be chosen in its options panel,
there is no need anymore to list every variant in nested submenus.
Add new widgets with sensible default options instead, and open the
options panel for them directly, so users can adapt them right away.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/src/dashboard/view/row_view.rs | 197 ++++++------------------------
1 file changed, 39 insertions(+), 158 deletions(-)
diff --git a/ui/src/dashboard/view/row_view.rs b/ui/src/dashboard/view/row_view.rs
index 2f94b4d3..e58d7c74 100644
--- a/ui/src/dashboard/view/row_view.rs
+++ b/ui/src/dashboard/view/row_view.rs
@@ -2,7 +2,6 @@ use std::collections::HashMap;
use std::rc::Rc;
use gloo_timers::callback::Timeout;
-use pdm_api_types::resource::GuestType;
use wasm_bindgen::JsCast;
use web_sys::Element;
use yew::html::{IntoEventCallback, IntoPropValue};
@@ -18,11 +17,10 @@ use pwt_macros::builder;
use crate::dashboard::view::EditingMessage;
use crate::dashboard::view::row_element::RowElement;
-use crate::dashboard::view::widget_options::WidgetOptions;
+use crate::dashboard::view::widget_options::{WidgetOptions, widget_type_name};
-use pdm_api_types::remotes::RemoteType;
use pdm_api_types::views::{
- LeaderboardType, NodeResourceType, RowWidget, TaskSummaryGrouping, ViewLayout, WidgetType,
+ LeaderboardType, RowWidget, TaskSummaryGrouping, ViewLayout, WidgetType,
};
#[derive(Properties, PartialEq)]
@@ -239,13 +237,15 @@ impl Component for RowViewComp {
let next_idx = *self.next_row_indices.get(&coords.row).unwrap_or(&0);
self.next_row_indices
.insert(coords.row, next_idx.saturating_add(1));
+ let key = Position {
+ row: coords.row,
+ item: next_idx,
+ };
+ self.edited_widget = Some(key);
self.current_layout[coords.row].insert(
coords.item,
(
- Position {
- row: coords.row,
- item: next_idx,
- },
+ key,
RowWidget {
flex: None,
title: None,
@@ -617,155 +617,36 @@ impl Component for RowViewComp {
}
fn create_menu(ctx: &yew::Context<RowViewComp>, new_coords: Position) -> Menu {
- let create_callback = |widget: WidgetType| {
- ctx.link()
- .callback(move |_| Msg::AddWidget(new_coords, widget.clone()))
- };
- let create_gauge_menu = |remote_type: Option<RemoteType>| -> Menu {
- Menu::new()
- .with_item(
- MenuItem::new(tr!("All Resources")).on_select(create_callback(
- WidgetType::NodeResourceGauge {
- resource: None,
- remote_type,
- },
- )),
- )
- .with_item(MenuItem::new(tr!("CPU")).on_select(create_callback(
- WidgetType::NodeResourceGauge {
- resource: Some(NodeResourceType::Cpu),
- remote_type,
- },
- )))
- .with_item(MenuItem::new(tr!("Memory")).on_select(create_callback(
- WidgetType::NodeResourceGauge {
- resource: Some(NodeResourceType::Memory),
- remote_type,
- },
- )))
- .with_item(MenuItem::new(tr!("Storage")).on_select(create_callback(
- WidgetType::NodeResourceGauge {
- resource: Some(NodeResourceType::Storage),
- remote_type,
- },
- )))
- };
- Menu::new()
- .with_item(
- MenuItem::new(tr!("Remote Panel"))
- .on_select(create_callback(WidgetType::Remotes { show_wizard: true })),
- )
- .with_item(
- MenuItem::new(tr!("Node Panels")).menu(
- Menu::new()
- .with_item(
- MenuItem::new(tr!("All Nodes"))
- .on_select(create_callback(WidgetType::Nodes { remote_type: None })),
- )
- .with_item(MenuItem::new(tr!("PBS Nodes")).on_select(create_callback(
- WidgetType::Nodes {
- remote_type: Some(RemoteType::Pbs),
- },
- )))
- .with_item(MenuItem::new(tr!("PVE Nodes")).on_select(create_callback(
- WidgetType::Nodes {
- remote_type: Some(RemoteType::Pve),
- },
- ))),
- ),
- )
- .with_item(
- MenuItem::new(tr!("Guest Panels")).menu(
- Menu::new()
- .with_item(
- MenuItem::new(tr!("All Guests"))
- .on_select(create_callback(WidgetType::Guests { guest_type: None })),
- )
- .with_item(
- MenuItem::new(tr!("Virtual Machines")).on_select(create_callback(
- WidgetType::Guests {
- guest_type: Some(GuestType::Qemu),
- },
- )),
- )
- .with_item(
- MenuItem::new(tr!("Linux Containers")).on_select(create_callback(
- WidgetType::Guests {
- guest_type: Some(GuestType::Lxc),
- },
- )),
- ),
- ),
- )
- .with_item(
- MenuItem::new(tr!("Subscription Panel"))
- .on_select(create_callback(WidgetType::Subscription)),
- )
- .with_item(
- MenuItem::new(tr!("PBS Datastores"))
- .on_select(create_callback(WidgetType::PbsDatastores)),
- )
- .with_item(
- MenuItem::new(tr!("Leaderboards")).menu(
- Menu::new()
- .with_item(
- MenuItem::new(tr!("Guests with Highest CPU Usage")).on_select(
- create_callback(WidgetType::Leaderboard {
- leaderboard_type: LeaderboardType::GuestCpu,
- }),
- ),
- )
- .with_item(
- MenuItem::new(tr!("Nodes with Highest CPU Usage")).on_select(
- create_callback(WidgetType::Leaderboard {
- leaderboard_type: LeaderboardType::NodeCpu,
- }),
- ),
- )
- .with_item(
- MenuItem::new(tr!("Nodes with Highest Memory Usage")).on_select(
- create_callback(WidgetType::Leaderboard {
- leaderboard_type: LeaderboardType::NodeMemory,
- }),
- ),
- ),
- ),
- )
- .with_item(
- MenuItem::new(tr!("Task Summaries")).menu(
- Menu::new()
- .with_item(MenuItem::new(tr!("Task Summary by Category")).on_select(
- create_callback(WidgetType::TaskSummary {
- grouping: TaskSummaryGrouping::Category,
- }),
- ))
- .with_item(
- MenuItem::new(tr!("Task Summary Sorted by Failed Tasks")).on_select(
- create_callback(WidgetType::TaskSummary {
- grouping: TaskSummaryGrouping::Remote,
- }),
- ),
- ),
+ // the specific variant can be chosen afterwards in the widget options
+ let widget_types = [
+ WidgetType::Remotes { show_wizard: true },
+ WidgetType::Nodes { remote_type: None },
+ WidgetType::Guests { guest_type: None },
+ WidgetType::Subscription,
+ WidgetType::PbsDatastores,
+ WidgetType::Leaderboard {
+ leaderboard_type: LeaderboardType::GuestCpu,
+ },
+ WidgetType::TaskSummary {
+ grouping: TaskSummaryGrouping::Category,
+ },
+ WidgetType::Sdn,
+ WidgetType::Map,
+ WidgetType::ResourceTree,
+ WidgetType::NodeResourceGauge {
+ resource: None,
+ remote_type: None,
+ },
+ ];
+
+ let mut menu = Menu::new();
+ for widget_type in widget_types {
+ menu.add_item(
+ MenuItem::new(widget_type_name(&widget_type)).on_select(
+ ctx.link()
+ .callback(move |_| Msg::AddWidget(new_coords, widget_type.clone())),
),
- )
- .with_item(MenuItem::new(tr!("SDN Panel")).on_select(create_callback(WidgetType::Sdn)))
- .with_item(MenuItem::new(tr!("Map")).on_select(create_callback(WidgetType::Map)))
- .with_item(
- MenuItem::new(tr!("Resource Tree"))
- .on_select(create_callback(WidgetType::ResourceTree)),
- )
- .with_item(
- MenuItem::new(tr!("Resource Usage")).menu(
- Menu::new()
- .with_item(MenuItem::new(tr!("All")).menu(create_gauge_menu(None)))
- .with_item(
- MenuItem::new(tr!("Virtual Environment"))
- .menu(create_gauge_menu(Some(RemoteType::Pve))),
- )
- .with_item(
- MenuItem::new(tr!("Backup Server"))
- .menu(create_gauge_menu(Some(RemoteType::Pbs))),
- ),
- ),
- )
+ );
+ }
+ menu
}
--
2.47.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH datacenter-manager 05/10] ui: dashboard: top entities: only build graph gradients on change
2026-11-26 14:49 [PATCH datacenter-manager 00/10] dashborad: add widget settings and leaderboard graph types Dominik Csapak
` (3 preceding siblings ...)
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
2026-11-26 14:49 ` [PATCH datacenter-manager 06/10] ui: dashboard: top entities: center data points in their interval Dominik Csapak
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dominik Csapak @ 2026-11-26 14:49 UTC (permalink / raw)
To: pdm-devel
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
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH datacenter-manager 06/10] ui: dashboard: top entities: center data points in their interval
2026-11-26 14:49 [PATCH datacenter-manager 00/10] dashborad: add widget settings and leaderboard graph types Dominik Csapak
` (4 preceding siblings ...)
2026-11-26 14:49 ` [PATCH datacenter-manager 05/10] ui: dashboard: top entities: only build graph gradients on change Dominik Csapak
@ 2026-11-26 14:49 ` Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 07/10] ui: dashboard: top entities: limit color stops by graph width Dominik Csapak
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dominik Csapak @ 2026-11-26 14:49 UTC (permalink / raw)
To: pdm-devel
since every data point covers the time up to the next one, but was
drawn at the start of that interval. This shifted the whole graph half
a data point to the left, and the gaps for missing data reached into
the intervals of the data points around them.
Draw the data points at the center of their interval instead, let the
gaps cover exactly the interval of the missing data point, and select
the data point for the tooltip whose interval contains the pointer.
This makes no big difference for the colored usage bar, but graphs
that draw the data points directly, e.g. as bars, would otherwise be
cut off at the left edge.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/src/dashboard/top_entities.rs | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/ui/src/dashboard/top_entities.rs b/ui/src/dashboard/top_entities.rs
index 8985ebbc..b96240f5 100644
--- a/ui/src/dashboard/top_entities.rs
+++ b/ui/src/dashboard/top_entities.rs
@@ -104,8 +104,9 @@ impl Component for TopEntitiesComp {
continue;
}
+ // every data point covers the interval up to the next one
let idx = (relative_pos * rrd.data.len() as f64)
- .round()
+ .floor()
.clamp(0.0, (rrd.data.len() - 1) as f64)
as usize;
@@ -306,7 +307,7 @@ fn graph_background(data: &[Option<f64>], threshold: f64) -> AttrValue {
WARN_COLOR,
(1.0 - point) * 100.0,
GOOD_COLOR,
- (i as f64) * 100.0 / data.len() as f64,
+ (i as f64 + 0.5) * 100.0 / data.len() as f64,
)
} else {
let point = ((point - threshold) / (1.0 - threshold)).clamp(0.0, 1.0);
@@ -315,7 +316,7 @@ fn graph_background(data: &[Option<f64>], threshold: f64) -> AttrValue {
ERR_COLOR,
(1.0 - point) * 100.0,
WARN_COLOR,
- (i as f64) * 100.0 / data.len() as f64,
+ (i as f64 + 0.5) * 100.0 / data.len() as f64,
)
};
list.push(format!(
@@ -326,7 +327,7 @@ fn graph_background(data: &[Option<f64>], threshold: f64) -> AttrValue {
// data points that were not collected yet.
list.push(format!(
"{BACKGROUND_COLOR} {:.0}% {:.0}%",
- (i as f64 - 1.0) * 100.0 / data.len() as f64,
+ i as f64 * 100.0 / data.len() as f64,
(i as f64 + 1.0) * 100.0 / data.len() as f64,
));
};
--
2.47.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH datacenter-manager 07/10] ui: dashboard: top entities: limit color stops by graph width
2026-11-26 14:49 [PATCH datacenter-manager 00/10] dashborad: add widget settings and leaderboard graph types Dominik Csapak
` (5 preceding siblings ...)
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 ` 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
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dominik Csapak @ 2026-11-26 14:49 UTC (permalink / raw)
To: pdm-devel
the rrd data for the default 'day' timeframe contains 1440 data
points, and we added a color stop for each one. That resulted in
roughly 150 KB of css per graph, even though most of these stops
were not visible at all, since the positions were rounded to whole
percent.
Instead, split the data into buckets, so that each color stop covers
at least two pixels. The gradient interpolates between the stops, so
this looks the same as one stop per pixel. Measure the width of the
graphs when the size of the component or the entities change, since
the column with the names takes up a varying part of it. Also merge
consecutive stops with the same color, as that renders the same.
Use the highest value of a bucket for its color instead of the
average, since short spikes of high usage are what matters most in a
list of the top consumers, and averaging would hide them in narrow
graphs.
Note that short dips and gaps in the data are not visible in narrow
graphs anymore, but the tooltip still shows the raw values.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/src/dashboard/top_entities.rs | 217 +++++++++++++++++++++++++------
1 file changed, 174 insertions(+), 43 deletions(-)
diff --git a/ui/src/dashboard/top_entities.rs b/ui/src/dashboard/top_entities.rs
index b96240f5..deebfd1d 100644
--- a/ui/src/dashboard/top_entities.rs
+++ b/ui/src/dashboard/top_entities.rs
@@ -4,6 +4,7 @@ use web_sys::HtmlElement;
use yew::virtual_dom::{VComp, VNode};
use proxmox_yew_comp::utils::render_epoch;
+use pwt::dom::DomSizeObserver;
use pwt::prelude::*;
use pwt::state::SharedState;
use pwt::widget::Fa;
@@ -58,6 +59,8 @@ impl From<TopEntities> for VNode {
pub enum Msg {
ShowTooltip(PointerEvent, Resource),
HideTooltip,
+ /// Measure the graph width again, e.g. when the size of the component changed.
+ Measure,
}
struct TooltipInfo {
@@ -69,8 +72,16 @@ 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.
+ /// properties or the number of buckets change and not on every re-render, e.g. when moving the
+ /// tooltip.
graph_backgrounds: Vec<AttrValue>,
+ /// The maximum number of buckets the data of a graph gets split into.
+ max_buckets: usize,
+ /// Whether the graph width needs to be measured again after the next render, since the
+ /// entities and with them the width of the name column changed.
+ measure_width: bool,
+ size_observer: Option<DomSizeObserver>,
+ root_ref: NodeRef,
tooltip_info: Option<TooltipInfo>,
tooltip_ref: NodeRef,
tooltip_anchor: NodeRef,
@@ -81,8 +92,14 @@ impl Component for TopEntitiesComp {
type Properties = TopEntities;
fn create(ctx: &yew::Context<Self>) -> Self {
+ // the real width is only known after the first render, see `rendered`
+ let max_buckets = 0;
Self {
- graph_backgrounds: graph_backgrounds(ctx.props()),
+ graph_backgrounds: graph_backgrounds(ctx.props(), max_buckets),
+ max_buckets,
+ measure_width: false,
+ size_observer: None,
+ root_ref: NodeRef::default(),
tooltip_info: None,
tooltip_ref: NodeRef::default(),
tooltip_anchor: NodeRef::default(),
@@ -124,13 +141,25 @@ impl Component for TopEntitiesComp {
Msg::HideTooltip => {
self.tooltip_info = None;
}
+ Msg::Measure => {
+ let Some(width) = self.measure_graph_width() else {
+ return false;
+ };
+ let max_buckets = (width / PIXELS_PER_BUCKET).ceil() as usize;
+ if max_buckets == self.max_buckets {
+ return false;
+ }
+ self.max_buckets = max_buckets;
+ self.graph_backgrounds = graph_backgrounds(props, max_buckets);
+ }
}
true
}
fn changed(&mut self, ctx: &yew::Context<Self>, _old_props: &Self::Properties) -> bool {
- self.graph_backgrounds = graph_backgrounds(ctx.props());
+ self.graph_backgrounds = graph_backgrounds(ctx.props(), self.max_buckets);
+ self.measure_width = true;
true
}
@@ -226,10 +255,22 @@ impl Component for TopEntitiesComp {
.with_child(tooltip)
.into_html_with_ref(self.tooltip_ref.clone())
}))
- .into()
+ .into_html_with_ref(self.root_ref.clone())
}
- fn rendered(&mut self, _ctx: &yew::Context<Self>, _first_render: bool) {
+ fn rendered(&mut self, ctx: &yew::Context<Self>, first_render: bool) {
+ if first_render {
+ if let Some(el) = self.root_ref.cast::<web_sys::Element>() {
+ let link = ctx.link().clone();
+ self.size_observer = Some(DomSizeObserver::new(&el, move |_: (f64, f64)| {
+ link.send_message(Msg::Measure);
+ }));
+ }
+ } else if self.measure_width {
+ self.measure_width = false;
+ ctx.link().send_message(Msg::Measure);
+ }
+
if let Some(tooltip_node) = self.tooltip_ref.get() {
if let Some(anchor) = self.tooltip_anchor.get() {
let _ = align_to(
@@ -249,6 +290,19 @@ impl Component for TopEntitiesComp {
}
}
+impl TopEntitiesComp {
+ /// Returns the width of the graphs, which share the grid column next to the names, or `None`
+ /// if there is no graph.
+ fn measure_graph_width(&self) -> Option<f64> {
+ let graph = self
+ .root_ref
+ .cast::<web_sys::Element>()?
+ .query_selector(".line-usage-graph")
+ .ok()??;
+ Some(graph.get_bounding_client_rect().width())
+ }
+}
+
fn create_tooltip(
remote: &str,
resource: &Resource,
@@ -294,56 +348,133 @@ const BACKGROUND_COLOR: &str = "var(--pwt-color-surface)";
const COLOR_SPACE: &str = "oklab";
+/// The minimum width in pixels a bucket of data points covers in the graph. The RRD data can contain
+/// more points (e.g. 1440 for a day) than the graph is wide in pixels, and every point makes the
+/// style data bigger without any visible difference. Since the gradient interpolates between the
+/// color stops, this looks the same as a stop per pixel.
+const PIXELS_PER_BUCKET: f64 = 2.0;
+
+fn usage_color(value: f64, threshold: f64) -> String {
+ let (ratio, high_color, low_color) = if value < threshold {
+ (value / threshold, WARN_COLOR, GOOD_COLOR)
+ } else {
+ (
+ (value - threshold) / (1.0 - threshold),
+ ERR_COLOR,
+ WARN_COLOR,
+ )
+ };
+
+ match (ratio.clamp(0.0, 1.0) * 100.0).round() as u8 {
+ 0 => low_color.to_string(),
+ 100 => high_color.to_string(),
+ percent => format!("color-mix(in {COLOR_SPACE}, {high_color} {percent}%, {low_color})"),
+ }
+}
+
+/// A range of data points with the highest of their values.
+struct Bucket {
+ start: usize,
+ end: usize,
+ value: Option<f64>,
+}
+
+impl Bucket {
+ /// The position of the bucket, in units of data point indices. Every data point covers the
+ /// interval up to the next one, so this is the center of all intervals of the bucket.
+ fn center(&self) -> f64 {
+ (self.start + self.end) as f64 / 2.0
+ }
+}
+
+/// Splits the data points into at most `max_buckets` buckets of about the same size.
+fn buckets(data: &[Option<f64>], max_buckets: usize) -> impl Iterator<Item = Bucket> + '_ {
+ // the rrd data sometimes contains a last data point that was not collected yet, which should
+ // not be shown as a gap
+ let points = match data.split_last() {
+ Some((None, rest)) => rest,
+ _ => data,
+ };
+ let bucket_count = points.len().min(max_buckets);
+
+ (0..bucket_count).map(move |bucket| {
+ let start = bucket * points.len() / bucket_count;
+ let end = (bucket + 1) * points.len() / bucket_count;
+
+ // the highest value instead of the average, so that short spikes stay visible
+ let max = points[start..end]
+ .iter()
+ .flatten()
+ .copied()
+ .reduce(f64::max);
+
+ Bucket {
+ start,
+ end,
+ value: max,
+ }
+ })
+}
+
/// 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 {
- let (left, left_color, right, right_color, percent) = if *point < threshold {
- let point = (point / threshold).clamp(0.0, 1.0);
-
- (
- point * 100.0,
- WARN_COLOR,
- (1.0 - point) * 100.0,
- GOOD_COLOR,
- (i as f64 + 0.5) * 100.0 / data.len() as f64,
- )
- } else {
- let point = ((point - threshold) / (1.0 - threshold)).clamp(0.0, 1.0);
- (
- point * 100.0,
- ERR_COLOR,
- (1.0 - point) * 100.0,
- WARN_COLOR,
- (i as f64 + 0.5) * 100.0 / data.len() as f64,
- )
- };
- list.push(format!(
- "color-mix(in {COLOR_SPACE}, {left_color} {left:.0}%, {right_color} {right:.0}%) {percent:.0}%",
- ));
- } else if (i + 1) < data.len() {
- // only add empty point if it's not the last, since the rrd data sometimes adds
- // data points that were not collected yet.
- list.push(format!(
- "{BACKGROUND_COLOR} {:.0}% {:.0}%",
- i as f64 * 100.0 / data.len() as f64,
- (i as f64 + 1.0) * 100.0 / data.len() as f64,
- ));
+fn graph_background(data: &[Option<f64>], threshold: f64, max_buckets: usize) -> AttrValue {
+ let len = data.len() as f64;
+
+ // color stops as (color, start, end), with the positions in percent
+ let mut stops: Vec<(String, f64, f64)> = Vec::new();
+ for bucket in buckets(data, max_buckets) {
+ let (color, start_pos, end_pos) = match bucket.value {
+ Some(value) => {
+ let pos = bucket.center() * 100.0 / len;
+ (usage_color(value, threshold), pos, pos)
+ }
+ None => (
+ BACKGROUND_COLOR.to_string(),
+ bucket.start as f64 * 100.0 / len,
+ bucket.end as f64 * 100.0 / len,
+ ),
};
+
+ match stops.last_mut() {
+ // extending the previous stop renders identically, but keeps the gradient short
+ Some((last_color, _, last_end)) if *last_color == color => *last_end = end_pos,
+ _ => stops.push((color, start_pos, end_pos)),
+ }
+ }
+
+ match stops.as_slice() {
+ [] => return AttrValue::Static("none"),
+ // older browsers need at least two color stops, so write out the single color twice
+ [(color, _, _)] => return format!("linear-gradient({color}, {color})").into(),
+ _ => {}
}
+
+ let stops: Vec<String> = stops
+ .into_iter()
+ .map(|(color, start, end)| {
+ let (start, end) = (format!("{start:.1}%"), format!("{end:.1}%"));
+ // a stop that does not span a range only needs a single position
+ if start == end {
+ format!("{color} {start}")
+ } else {
+ format!("{color} {start} {end}")
+ }
+ })
+ .collect();
+
format!(
"linear-gradient(in {COLOR_SPACE} to right, {})",
- list.join(", ")
+ stops.join(", ")
)
.into()
}
-fn graph_backgrounds(props: &TopEntities) -> Vec<AttrValue> {
+/// Returns the graph backgrounds for all entities.
+fn graph_backgrounds(props: &TopEntities, max_buckets: usize) -> Vec<AttrValue> {
props
.entities
.iter()
- .map(|entity| graph_background(&entity.rrd_data.data, props.threshold))
+ .map(|entity| graph_background(&entity.rrd_data.data, props.threshold, max_buckets))
.collect()
}
--
2.47.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH datacenter-manager 08/10] ui: dashboard: top entities: add line, area and bar graph types
2026-11-26 14:49 [PATCH datacenter-manager 00/10] dashborad: add widget settings and leaderboard graph types Dominik Csapak
` (6 preceding siblings ...)
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 ` 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
9 siblings, 0 replies; 11+ messages in thread
From: Dominik Csapak @ 2026-11-26 14:49 UTC (permalink / raw)
To: pdm-devel
the heatmap shows how loaded an entity was over time, but it's hard to
see the actual usage from it. Line, area and bar graphs show that
directly by their height.
Draw them as svg paths, which keeps the DOM small, scales without
redrawing and can use the theme colors via css variables. All graphs
of a panel share a vertical gradient, so every height has the same
color as the usage it represents in the heatmap.
Make the graph type an option of the leaderboard widget, so it can be
chosen in the widget options panel. It defaults to the heatmap and is
only saved as the 'graph-type' property of the widget if it differs
from that, which keeps the layouts minimal and existing ones look the
same as before.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
lib/pdm-api-types/src/views.rs | 45 ++++
ui/src/dashboard/top_entities.rs | 312 ++++++++++++++++++++----
ui/src/dashboard/view.rs | 11 +-
ui/src/dashboard/view/row_view.rs | 1 +
ui/src/dashboard/view/widget_options.rs | 29 ++-
5 files changed, 341 insertions(+), 57 deletions(-)
diff --git a/lib/pdm-api-types/src/views.rs b/lib/pdm-api-types/src/views.rs
index 5d288e31..f1d2d7f3 100644
--- a/lib/pdm-api-types/src/views.rs
+++ b/lib/pdm-api-types/src/views.rs
@@ -320,6 +320,8 @@ pub enum WidgetType {
#[serde(rename_all = "kebab-case")]
Leaderboard {
leaderboard_type: LeaderboardType,
+ #[serde(default, skip_serializing_if = "LeaderboardGraphType::is_default")]
+ graph_type: LeaderboardGraphType,
},
TaskSummary {
grouping: TaskSummaryGrouping,
@@ -354,6 +356,28 @@ pub enum LeaderboardType {
NodeMemory,
}
+#[derive(Serialize, Deserialize, PartialEq, Clone, Copy, Default)]
+#[serde(rename_all = "kebab-case")]
+/// How the usage over time of an entity is drawn. Except for [`LeaderboardGraphType::Heat`], the
+/// graphs are colored by height, so the colors match the ones of the heat graph for the same usage.
+pub enum LeaderboardGraphType {
+ /// A bar colored by the usage at each point in time.
+ #[default]
+ Heat,
+ /// A line showing the usage.
+ Line,
+ /// The filled area below the usage line.
+ Area,
+ /// Vertical bars showing the usage.
+ Bar,
+}
+
+impl LeaderboardGraphType {
+ fn is_default(&self) -> bool {
+ *self == Self::default()
+ }
+}
+
#[derive(Serialize, Deserialize, PartialEq, Clone, Copy)]
#[serde(rename_all = "kebab-case")]
pub enum TaskSummaryGrouping {
@@ -399,6 +423,27 @@ mod test {
assert!(parse_and_check_display("remote:a").is_err());
}
+ #[test]
+ fn test_leaderboard_graph_type() -> Result<(), Error> {
+ let widget = |graph_type| WidgetType::Leaderboard {
+ leaderboard_type: LeaderboardType::GuestCpu,
+ graph_type,
+ };
+ let minimal = r#"{"widget-type":"leaderboard","leaderboard-type":"guest-cpu"}"#;
+
+ assert_eq!(
+ serde_json::to_string(&widget(LeaderboardGraphType::Heat))?,
+ minimal
+ );
+ assert_eq!(
+ serde_json::to_string(&widget(LeaderboardGraphType::Bar))?,
+ r#"{"widget-type":"leaderboard","leaderboard-type":"guest-cpu","graph-type":"bar"}"#
+ );
+ assert!(serde_json::from_str::<WidgetType>(minimal)? == widget(LeaderboardGraphType::Heat));
+
+ Ok(())
+ }
+
#[test]
fn config_smoke_test() {
let config = "
diff --git a/ui/src/dashboard/top_entities.rs b/ui/src/dashboard/top_entities.rs
index deebfd1d..a5e51538 100644
--- a/ui/src/dashboard/top_entities.rs
+++ b/ui/src/dashboard/top_entities.rs
@@ -1,3 +1,4 @@
+use std::fmt::Write;
use std::rc::Rc;
use web_sys::HtmlElement;
@@ -7,7 +8,8 @@ use proxmox_yew_comp::utils::render_epoch;
use pwt::dom::DomSizeObserver;
use pwt::prelude::*;
use pwt::state::SharedState;
-use pwt::widget::Fa;
+use pwt::widget::canvas::{Canvas, Path, SvgLength};
+use pwt::widget::{Fa, get_unique_element_id};
use pwt::{
css::{AlignItems, Display, FlexFit, JustifyContent},
dom::align::{AlignOptions, align_to},
@@ -20,7 +22,7 @@ use pwt::{
};
use pdm_api_types::resource::AsResourceView;
-use pdm_api_types::views::LeaderboardType;
+use pdm_api_types::views::{LeaderboardGraphType as GraphType, LeaderboardType};
use pdm_client::types::{Resource, TopEntity};
use crate::LoadResult;
@@ -37,6 +39,7 @@ pub struct TopEntities {
/// The threshold for the oklab color gradient relaying how much load there is.
/// Will be clamped between 0.001 and 0.999 to ensure invariants to avoid division by zero.
threshold: f64,
+ graph_type: GraphType,
}
impl TopEntities {
@@ -45,8 +48,28 @@ impl TopEntities {
entities,
metrics_title,
threshold: threshold.clamp(0.001, 0.999),
+ graph_type: GraphType::default(),
}
}
+
+ /// Builder style method to set how the usage over time is drawn.
+ pub fn graph_type(mut self, graph_type: GraphType) -> Self {
+ self.graph_type = graph_type;
+ self
+ }
+}
+
+/// The minimum width in pixels a bucket of data points covers in the graph. The RRD data can contain
+/// more points (e.g. 1440 for a day) than the graph is wide in pixels, and every point makes the
+/// style or path data bigger without any visible difference.
+fn pixels_per_bucket(graph_type: GraphType) -> f64 {
+ match graph_type {
+ // the gradient and lines interpolate between the points, so this looks the same as a point
+ // per pixel
+ GraphType::Heat | GraphType::Line | GraphType::Area => 2.0,
+ // bars that are too thin cannot be told apart
+ GraphType::Bar => 6.0,
+ }
}
impl From<TopEntities> for VNode {
@@ -71,15 +94,19 @@ struct TooltipInfo {
}
struct TopEntitiesComp {
- /// The graph backgrounds in the same order as the entities, only calculated when the
- /// properties or the number of buckets change and not on every re-render, e.g. when moving the
- /// tooltip.
- graph_backgrounds: Vec<AttrValue>,
+ /// The graph data in the same order as the entities, the CSS background for
+ /// [`GraphType::Heat`] and the SVG path data otherwise. Only calculated when the properties or
+ /// the number of buckets change and not on every re-render, e.g. when moving the tooltip.
+ graphs: Vec<AttrValue>,
/// The maximum number of buckets the data of a graph gets split into.
max_buckets: usize,
+ /// The width of the graphs, see `measure_graph_width`.
+ width: f64,
/// Whether the graph width needs to be measured again after the next render, since the
/// entities and with them the width of the name column changed.
measure_width: bool,
+ /// The ID of the SVG gradient used by all graphs except [`GraphType::Heat`].
+ gradient_id: AttrValue,
size_observer: Option<DomSizeObserver>,
root_ref: NodeRef,
tooltip_info: Option<TooltipInfo>,
@@ -92,18 +119,21 @@ impl Component for TopEntitiesComp {
type Properties = TopEntities;
fn create(ctx: &yew::Context<Self>) -> Self {
- // the real width is only known after the first render, see `rendered`
- let max_buckets = 0;
- Self {
- graph_backgrounds: graph_backgrounds(ctx.props(), max_buckets),
- max_buckets,
+ let mut this = Self {
+ graphs: Vec::new(),
+ max_buckets: 0,
+ // the real width is only known after the first render, see `rendered`
+ width: 0.0,
measure_width: false,
+ gradient_id: get_unique_element_id().into(),
size_observer: None,
root_ref: NodeRef::default(),
tooltip_info: None,
tooltip_ref: NodeRef::default(),
tooltip_anchor: NodeRef::default(),
- }
+ };
+ this.update_graphs(ctx.props(), true);
+ this
}
fn update(&mut self, ctx: &yew::Context<Self>, msg: Self::Message) -> bool {
@@ -145,12 +175,8 @@ impl Component for TopEntitiesComp {
let Some(width) = self.measure_graph_width() else {
return false;
};
- let max_buckets = (width / PIXELS_PER_BUCKET).ceil() as usize;
- if max_buckets == self.max_buckets {
- return false;
- }
- self.max_buckets = max_buckets;
- self.graph_backgrounds = graph_backgrounds(props, max_buckets);
+ self.width = width;
+ return self.update_graphs(props, false);
}
}
@@ -158,7 +184,7 @@ impl Component for TopEntitiesComp {
}
fn changed(&mut self, ctx: &yew::Context<Self>, _old_props: &Self::Properties) -> bool {
- self.graph_backgrounds = graph_backgrounds(ctx.props(), self.max_buckets);
+ self.update_graphs(ctx.props(), true);
self.measure_width = true;
true
}
@@ -172,8 +198,9 @@ impl Component for TopEntitiesComp {
.style("grid-template-columns", "min-content auto")
.style("gap", "var(--pwt-spacer-3)");
let mut tooltip = None;
+ let gradient_paint = AttrValue::from(format!("url(#{})", self.gradient_id));
let data = &props.entities;
- for (entity, graph_background) in data.iter().zip(&self.graph_backgrounds).rev() {
+ for (entity, graph) in data.iter().zip(&self.graphs).rev() {
let resource = &entity.resource;
let remote = &entity.remote;
@@ -227,23 +254,56 @@ impl Component for TopEntitiesComp {
.style("white-space", "nowrap"),
);
- list.add_child(
- 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();
- move |event| Msg::ShowTooltip(event, resource.clone())
- }))
- .onpointerleave(ctx.link().callback(|_| Msg::HideTooltip))
- .style("position", "relative")
- .with_optional_child(tooltip_anchor),
- );
+ let mut graph_container = Container::new()
+ .width(CssLength::Fraction(1.0))
+ .class("line-usage-graph")
+ .style("background-color", BACKGROUND_COLOR)
+ .style("overflow", "hidden")
+ .style("flex", "5 0")
+ .onpointermove(ctx.link().callback({
+ let resource = resource.clone();
+ move |event| Msg::ShowTooltip(event, resource.clone())
+ }))
+ .onpointerleave(ctx.link().callback(|_| Msg::HideTooltip))
+ .style("position", "relative")
+ .with_optional_child(tooltip_anchor);
+
+ let len = entity.rrd_data.data.len();
+ match props.graph_type {
+ GraphType::Heat => graph_container.set_style("background-image", graph.clone()),
+ GraphType::Line => {
+ // the line is centered on the edges for no or full usage, so it needs some
+ // space outside of the graph to not get cut in half
+ graph_container.set_style("box-sizing", "border-box");
+ graph_container.set_style("padding-block", "0.75px");
+ graph_container.add_child(
+ graph_svg(
+ len,
+ Path::new()
+ .d(graph.clone())
+ .fill("none")
+ .stroke(gradient_paint.clone())
+ .stroke_width(1.5)
+ // the graph gets stretched, but the line should keep its width
+ .attribute("vector-effect", "non-scaling-stroke"),
+ )
+ .style("overflow", "visible"),
+ )
+ }
+ GraphType::Area | GraphType::Bar => graph_container.add_child(graph_svg(
+ len,
+ Path::new().d(graph.clone()).fill(gradient_paint.clone()),
+ )),
+ }
+
+ list.add_child(graph_container);
}
Container::new()
.class(FlexFit)
+ .with_optional_child(
+ (props.graph_type != GraphType::Heat)
+ .then(|| usage_gradient(self.gradient_id.clone(), props.threshold)),
+ )
.with_child(list)
.with_optional_child(tooltip.map(|tooltip| {
Container::new()
@@ -301,6 +361,30 @@ impl TopEntitiesComp {
.ok()??;
Some(graph.get_bounding_client_rect().width())
}
+
+ /// Recalculates the graphs if forced or the number of buckets changed, returns if they were
+ /// recalculated.
+ fn update_graphs(&mut self, props: &TopEntities, force: bool) -> bool {
+ let max_buckets = (self.width / pixels_per_bucket(props.graph_type)).ceil() as usize;
+ if !force && max_buckets == self.max_buckets {
+ return false;
+ }
+ self.max_buckets = max_buckets;
+ self.graphs = props
+ .entities
+ .iter()
+ .map(|entity| {
+ let data = &entity.rrd_data.data;
+ match props.graph_type {
+ GraphType::Heat => heat_background(data, props.threshold, max_buckets),
+ GraphType::Line => line_path(data, max_buckets),
+ GraphType::Area => area_path(data, max_buckets),
+ GraphType::Bar => bar_path(data, max_buckets),
+ }
+ })
+ .collect();
+ true
+ }
}
fn create_tooltip(
@@ -348,12 +432,10 @@ const BACKGROUND_COLOR: &str = "var(--pwt-color-surface)";
const COLOR_SPACE: &str = "oklab";
-/// The minimum width in pixels a bucket of data points covers in the graph. The RRD data can contain
-/// more points (e.g. 1440 for a day) than the graph is wide in pixels, and every point makes the
-/// style data bigger without any visible difference. Since the gradient interpolates between the
-/// color stops, this looks the same as a stop per pixel.
-const PIXELS_PER_BUCKET: f64 = 2.0;
+/// The relative width of the gap between two bars of a [`GraphType::Bar`] graph.
+const BAR_GAP: f64 = 0.25;
+/// The color representing the given usage.
fn usage_color(value: f64, threshold: f64) -> String {
let (ratio, high_color, low_color) = if value < threshold {
(value / threshold, WARN_COLOR, GOOD_COLOR)
@@ -416,8 +498,8 @@ fn buckets(data: &[Option<f64>], max_buckets: usize) -> impl Iterator<Item = Buc
})
}
-/// Returns the CSS 'background-image' value for the usage graph of the given data.
-fn graph_background(data: &[Option<f64>], threshold: f64, max_buckets: usize) -> AttrValue {
+/// Returns the CSS 'background-image' value for a [`GraphType::Heat`] graph.
+fn heat_background(data: &[Option<f64>], threshold: f64, max_buckets: usize) -> AttrValue {
let len = data.len() as f64;
// color stops as (color, start, end), with the positions in percent
@@ -469,13 +551,142 @@ fn graph_background(data: &[Option<f64>], threshold: f64, max_buckets: usize) ->
.into()
}
-/// Returns the graph backgrounds for all entities.
-fn graph_backgrounds(props: &TopEntities, max_buckets: usize) -> Vec<AttrValue> {
- props
- .entities
- .iter()
- .map(|entity| graph_background(&entity.rrd_data.data, props.threshold, max_buckets))
- .collect()
+// The SVG graphs use a coordinate system where the x coordinate is the index of the data point and
+// the y coordinate goes from 1 for no usage at the bottom to 0 for full usage at the top, see
+// `graph_svg`.
+
+/// The SVG y coordinate of the given usage.
+fn usage_y(value: f64) -> f64 {
+ 1.0 - value.clamp(0.0, 1.0)
+}
+
+/// Splits the bucketed data into segments without gaps, as (x, y) points in SVG coordinates. The
+/// returned segments are never empty and contain at least two points.
+fn line_segments(data: &[Option<f64>], max_buckets: usize) -> Vec<Vec<(f64, f64)>> {
+ let mut segments = Vec::new();
+ let mut segment = Vec::new();
+
+ // a single point would not be visible, so draw it across its whole interval instead
+ let finish = |segment: Vec<(Bucket, f64)>| match segment.as_slice() {
+ [(bucket, y)] => vec![(bucket.start as f64, *y), (bucket.end as f64, *y)],
+ _ => segment
+ .iter()
+ .map(|(bucket, y)| (bucket.center(), *y))
+ .collect(),
+ };
+
+ for bucket in buckets(data, max_buckets) {
+ match bucket.value {
+ Some(value) => segment.push((bucket, usage_y(value))),
+ None if !segment.is_empty() => segments.push(finish(std::mem::take(&mut segment))),
+ None => {}
+ }
+ }
+
+ if !segment.is_empty() {
+ segments.push(finish(segment));
+ }
+
+ segments
+}
+
+/// Returns the SVG path data for a [`GraphType::Line`] graph.
+fn line_path(data: &[Option<f64>], max_buckets: usize) -> AttrValue {
+ let mut path = String::new();
+
+ for segment in line_segments(data, max_buckets) {
+ let mut command = 'M';
+ for (x, y) in segment {
+ let _ = write!(path, "{command}{x:.1},{y:.3}");
+ command = 'L';
+ }
+ }
+
+ path.into()
+}
+
+/// Returns the SVG path data for a [`GraphType::Area`] graph.
+fn area_path(data: &[Option<f64>], max_buckets: usize) -> AttrValue {
+ let mut path = String::new();
+
+ for segment in line_segments(data, max_buckets) {
+ // start at the bottom, follow the line and go back to the bottom to close the area
+ let (start_x, _) = segment[0];
+ let _ = write!(path, "M{start_x:.1},1");
+ for (x, y) in segment {
+ let _ = write!(path, "L{x:.1},{y:.3}");
+ }
+ path.push_str("V1Z");
+ }
+
+ path.into()
+}
+
+/// Returns the SVG path data for a [`GraphType::Bar`] graph.
+fn bar_path(data: &[Option<f64>], max_buckets: usize) -> AttrValue {
+ let mut path = String::new();
+
+ for bucket in buckets(data, max_buckets) {
+ let Some(value) = bucket.value else {
+ continue;
+ };
+
+ // centered on the bucket position, like the points of the other graph types
+ let width = (bucket.end - bucket.start) as f64 * (1.0 - BAR_GAP);
+ let x = bucket.center() - width / 2.0;
+ let _ = write!(path, "M{x:.2},1V{:.3}h{width:.2}V1Z", usage_y(value));
+ }
+
+ path.into()
+}
+
+/// Creates an SVG for the path of a graph with `len` data points, stretched to the size of its
+/// parent.
+fn graph_svg(len: usize, path: Path) -> Canvas {
+ Canvas::new()
+ .width(SvgLength::Fraction(1.0))
+ .height(SvgLength::Fraction(1.0))
+ .attribute("viewBox", format!("0 0 {len} 1"))
+ .attribute("preserveAspectRatio", "none")
+ .style("display", "block")
+ // so that the pointer events for the tooltip always target the graph container
+ .style("pointer-events", "none")
+ .with_child(path)
+}
+
+/// Creates an invisible SVG with the vertical gradient used by the SVG graphs, which colors every
+/// height with the color of the usage it represents. The stops in between approximate the
+/// interpolation in the color space used by the heat graphs.
+fn usage_gradient(id: AttrValue, threshold: f64) -> Canvas {
+ const STEPS: u32 = 4;
+ let below = (0..STEPS).map(|step| threshold * step as f64 / STEPS as f64);
+ let above = (0..=STEPS).map(|step| threshold + (1.0 - threshold) * step as f64 / STEPS as f64);
+ let stops: Html = below
+ .chain(above)
+ .map(|value| {
+ html! {
+ <stop
+ offset={value.to_string()}
+ style={format!("stop-color: {}", usage_color(value, threshold))}
+ />
+ }
+ })
+ .collect();
+
+ // not using 'display: none', since some browsers then do not render the gradient at all
+ Canvas::new()
+ .width(0)
+ .height(0)
+ .style("position", "absolute")
+ .with_child(html! {
+ <defs>
+ // user space coordinates, so that the colors map to the same values in every graph,
+ // and a dynamic tag, since the html macro would lowercase the name
+ <@{"linearGradient"} {id} gradientUnits="userSpaceOnUse" x1="0" y1="1" x2="0" y2="0">
+ {stops}
+ </@>
+ </defs>
+ })
}
pub fn create_top_entities_panel(
@@ -483,6 +694,7 @@ pub fn create_top_entities_panel(
LoadResult<pdm_api_types::resource::TopEntities, proxmox_client::Error>,
>,
leaderboard_type: LeaderboardType,
+ graph_type: GraphType,
) -> Panel {
let top_entities = top_entities.read();
let (entities, metrics_title, metrics_empty_message, threshold) = match leaderboard_type {
@@ -515,7 +727,9 @@ pub fn create_top_entities_panel(
.with_child(&metrics_empty_message)
.into()
} else {
- TopEntities::new(entities, metrics_title, threshold).into()
+ TopEntities::new(entities, metrics_title, threshold)
+ .graph_type(graph_type)
+ .into()
};
Some(html)
diff --git a/ui/src/dashboard/view.rs b/ui/src/dashboard/view.rs
index c46a85b0..61d52924 100644
--- a/ui/src/dashboard/view.rs
+++ b/ui/src/dashboard/view.rs
@@ -171,9 +171,10 @@ fn render_widget(
.callback(move |_| Msg::ShowSubscriptionsDialog(true)),
),
WidgetType::Sdn => create_sdn_panel(status),
- WidgetType::Leaderboard { leaderboard_type } => {
- create_top_entities_panel(top_entities, *leaderboard_type)
- }
+ WidgetType::Leaderboard {
+ leaderboard_type,
+ graph_type,
+ } => create_top_entities_panel(top_entities, *leaderboard_type, *graph_type),
WidgetType::TaskSummary { grouping } => {
let remotes = match grouping {
TaskSummaryGrouping::Category => None,
@@ -221,7 +222,9 @@ fn default_widget_title(
WidgetType::Remotes { .. } => ("server", tr!("Remotes")),
WidgetType::Subscription => ("ticket", tr!("Remote Subscription Status")),
WidgetType::Sdn => ("sdn", tr!("SDN Zones")),
- WidgetType::Leaderboard { leaderboard_type } => match leaderboard_type {
+ WidgetType::Leaderboard {
+ leaderboard_type, ..
+ } => match leaderboard_type {
LeaderboardType::GuestCpu => ("desktop", tr!("Guests With the Highest CPU Usage")),
LeaderboardType::NodeCpu => ("building", tr!("Nodes With the Highest CPU Usage")),
LeaderboardType::NodeMemory => ("building", tr!("Nodes With the Highest Memory Usage")),
diff --git a/ui/src/dashboard/view/row_view.rs b/ui/src/dashboard/view/row_view.rs
index e58d7c74..70ac9a0d 100644
--- a/ui/src/dashboard/view/row_view.rs
+++ b/ui/src/dashboard/view/row_view.rs
@@ -626,6 +626,7 @@ fn create_menu(ctx: &yew::Context<RowViewComp>, new_coords: Position) -> Menu {
WidgetType::PbsDatastores,
WidgetType::Leaderboard {
leaderboard_type: LeaderboardType::GuestCpu,
+ graph_type: Default::default(),
},
WidgetType::TaskSummary {
grouping: TaskSummaryGrouping::Category,
diff --git a/ui/src/dashboard/view/widget_options.rs b/ui/src/dashboard/view/widget_options.rs
index 9418d67f..c8ca45b5 100644
--- a/ui/src/dashboard/view/widget_options.rs
+++ b/ui/src/dashboard/view/widget_options.rs
@@ -9,7 +9,8 @@ use pwt_macros::builder;
use pdm_api_types::remotes::RemoteType;
use pdm_api_types::resource::GuestType;
use pdm_api_types::views::{
- LeaderboardType, NodeResourceType, RowWidget, TaskSummaryGrouping, WidgetType,
+ LeaderboardGraphType, LeaderboardType, NodeResourceType, RowWidget, TaskSummaryGrouping,
+ WidgetType,
};
/// Returns the name of the kind of widget, independent of its options.
@@ -139,11 +140,14 @@ impl Component for WidgetOptionsComp {
),
);
}
- WidgetType::Leaderboard { leaderboard_type } => {
+ &WidgetType::Leaderboard {
+ leaderboard_type,
+ graph_type,
+ } => {
panel.add_field(
tr!("Ranking"),
option_selector(
- *leaderboard_type,
+ leaderboard_type,
vec![
(
LeaderboardType::GuestCpu,
@@ -158,8 +162,25 @@ impl Component for WidgetOptionsComp {
tr!("Nodes with Highest Memory Usage"),
),
],
- set_type.reform(|leaderboard_type| WidgetType::Leaderboard {
+ set_type.reform(move |leaderboard_type| WidgetType::Leaderboard {
+ leaderboard_type,
+ graph_type,
+ }),
+ ),
+ );
+ panel.add_field(
+ tr!("Graph Type"),
+ option_selector(
+ graph_type,
+ vec![
+ (LeaderboardGraphType::Heat, tr!("Heatmap")),
+ (LeaderboardGraphType::Line, tr!("Line Graph")),
+ (LeaderboardGraphType::Area, tr!("Area Graph")),
+ (LeaderboardGraphType::Bar, tr!("Bar Graph")),
+ ],
+ set_type.reform(move |graph_type| WidgetType::Leaderboard {
leaderboard_type,
+ graph_type,
}),
),
);
--
2.47.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH datacenter-manager 09/10] ui: dashboard: top entities: show indicator line for tooltip point
2026-11-26 14:49 [PATCH datacenter-manager 00/10] dashborad: add widget settings and leaderboard graph types Dominik Csapak
` (7 preceding siblings ...)
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 ` 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
9 siblings, 0 replies; 11+ messages in thread
From: Dominik Csapak @ 2026-11-26 14:49 UTC (permalink / raw)
To: pdm-devel
with many data points per graph, it's hard to tell which point the
tooltip refers to. So show a vertical line at the position of that
point, using the same relative position as the graphs.
The line snaps to the data point instead of following the pointer
exactly, so it always matches the shown values. Reuse the tooltip
anchor for this and align the tooltip to its top, which keeps the
tooltip at the same position as before.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/src/dashboard/top_entities.rs | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/ui/src/dashboard/top_entities.rs b/ui/src/dashboard/top_entities.rs
index a5e51538..3cbff87f 100644
--- a/ui/src/dashboard/top_entities.rs
+++ b/ui/src/dashboard/top_entities.rs
@@ -87,7 +87,8 @@ pub enum Msg {
}
struct TooltipInfo {
- pos: i32,
+ /// The index of the shown data point.
+ index: usize,
id: String,
value: Option<f64>,
time: i64,
@@ -158,7 +159,7 @@ impl Component for TopEntitiesComp {
as usize;
self.tooltip_info = Some(TooltipInfo {
- pos: offset,
+ index: idx,
id: resource.global_id().to_string(),
value: rrd.data.get(idx).copied().unwrap_or_default(),
time: (rrd.start + rrd.resolution * idx as u64) as i64,
@@ -205,15 +206,25 @@ impl Component for TopEntitiesComp {
let remote = &entity.remote;
let node = resource.as_resource_view().node().map(|n| n.to_string());
+ let len = entity.rrd_data.data.len();
let tooltip_anchor = if let Some(info) = self.tooltip_info.as_ref() {
if info.id == resource.global_id() {
tooltip = Some(create_tooltip(remote, resource, info, &props.metrics_title));
+ // a vertical line at the shown data point, which is at the same relative
+ // position as in the graphs, so it is clear which point the tooltip refers to
Some(
Container::new()
.style("position", "absolute")
.style("pointer-events", "none")
- .style("left", format!("{}px", info.pos))
+ .style("top", "0")
+ .style("bottom", "0")
+ .style("width", "1px")
+ .style("background-color", INDICATOR_COLOR)
+ .style(
+ "left",
+ format!("{}%", (info.index as f64 + 0.5) * 100.0 / len as f64),
+ )
.into_html_with_ref(self.tooltip_anchor.clone()),
)
} else {
@@ -268,7 +279,6 @@ impl Component for TopEntitiesComp {
.style("position", "relative")
.with_optional_child(tooltip_anchor);
- let len = entity.rrd_data.data.len();
match props.graph_type {
GraphType::Heat => graph_container.set_style("background-image", graph.clone()),
GraphType::Line => {
@@ -338,7 +348,7 @@ impl Component for TopEntitiesComp {
tooltip_node,
Some(
AlignOptions::new(
- pwt::dom::align::Point::BottomStart,
+ pwt::dom::align::Point::TopStart,
pwt::dom::align::Point::TopStart,
pwt::dom::align::GrowDirection::None,
)
@@ -429,6 +439,8 @@ const GOOD_COLOR: &str = "var(--pwt-color-success)";
const WARN_COLOR: &str = "var(--pwt-color-warning)";
const ERR_COLOR: &str = "var(--pwt-color-error)";
const BACKGROUND_COLOR: &str = "var(--pwt-color-surface)";
+// must stay visible on top of all usage colors
+const INDICATOR_COLOR: &str = "var(--pwt-color-on-surface)";
const COLOR_SPACE: &str = "oklab";
--
2.47.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH datacenter-manager 10/10] docs: custom views: mention the graph types of the leaderboard widget
2026-11-26 14:49 [PATCH datacenter-manager 00/10] dashborad: add widget settings and leaderboard graph types Dominik Csapak
` (8 preceding siblings ...)
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 ` Dominik Csapak
9 siblings, 0 replies; 11+ messages in thread
From: Dominik Csapak @ 2026-11-26 14:49 UTC (permalink / raw)
To: pdm-devel
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
docs/views.rst | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/docs/views.rst b/docs/views.rst
index e7db5a7a..db7735eb 100644
--- a/docs/views.rst
+++ b/docs/views.rst
@@ -69,7 +69,8 @@ The following widgets are available:
- The `sdn` widget shows the status of the Software-Defined Networking (SDN)
zones.
- The `leaderboard` widget ranks resources by a metric, such as guest or node
- CPU or node memory usage, and lists the top consumers.
+ CPU or node memory usage, and lists the top consumers. Their usage over time
+ is shown as a heatmap by default, or as a line, area, or bar graph.
- The `task-summary` widget summarizes recent tasks, grouped by a chosen
criterion.
- The `resource-tree` widget shows the selected resources in a hierarchical
--
2.47.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-11-26 14:54 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH datacenter-manager 05/10] ui: dashboard: top entities: only build graph gradients on change Dominik Csapak
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
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.