public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Sterz <s.sterz@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com,
	pmg-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH widget-toolkit v1 3/6] gauge widget: add support for a dark theme and dynamic theme switching
Date: Wed,  8 Mar 2023 17:36:57 +0100	[thread overview]
Message-ID: <20230308163658.2453420-2-s.sterz@proxmox.com> (raw)
In-Reply-To: <20230308163658.2453420-1-s.sterz@proxmox.com>

the gauges in the data center overview should use a dark style if the
relevant css variables are set. this also makes it possible to switch
the colors dynamically by adding an event listener

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
---
 src/panel/GaugeWidget.js | 45 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/src/panel/GaugeWidget.js b/src/panel/GaugeWidget.js
index 0cc2079..00567a2 100644
--- a/src/panel/GaugeWidget.js
+++ b/src/panel/GaugeWidget.js
@@ -61,6 +61,36 @@ Ext.define('Proxmox.panel.GaugeWidget', {
 
     initialValue: 0,
 
+    checkThemeColors: function() {
+	let me = this;
+	let rootStyle = getComputedStyle(document.documentElement);
+
+	// get colors
+	let panelBg = rootStyle.getPropertyValue("--pwt-panel-background").trim() || "#ffffff";
+	let textColor = rootStyle.getPropertyValue("--pwt-text-color").trim() || "#000000";
+	me.defaultColor = rootStyle.getPropertyValue("--pwt-gauge-default").trim() || '#c2ddf2';
+	me.criticalColor = rootStyle.getPropertyValue("--pwt-gauge-crit").trim() || '#ff6c59';
+	me.warningColor = rootStyle.getPropertyValue("--pwt-gauge-warn").trim() || '#fc0';
+	me.backgroundColor = rootStyle.getPropertyValue("--pwt-gauge-back").trim() || '#f5f5f5';
+
+	// set gauge colors
+	let value = me.chart.series[0].getValue() / 100;
+
+	let color = me.defaultColor;
+
+	if (value >= me.criticalThreshold) {
+	    color = me.criticalColor;
+	} else if (value >= me.warningThreshold) {
+	    color = me.warningColor;
+	}
+
+	me.chart.series[0].setColors([color, me.backgroundColor]);
+
+	// set text and background colors
+	me.chart.setBackground(panelBg);
+	me.valueSprite.setAttributes({ fillStyle: textColor }, true);
+	me.chart.redraw();
+    },
 
     updateValue: function(value, text) {
 	let me = this;
@@ -100,5 +130,20 @@ Ext.define('Proxmox.panel.GaugeWidget', {
 	me.text = me.getComponent('text');
 	me.chart = me.getComponent('chart');
 	me.valueSprite = me.chart.getSurface('chart').get('valueSprite');
+
+	me.checkThemeColors();
+
+	// switch colors on media query changes
+	me.mediaQueryList = window.matchMedia("(prefers-color-scheme: dark)");
+	me.themeListener = (e) => { me.checkThemeColors(); };
+	me.mediaQueryList.addEventListener("change", me.themeListener);
+    },
+
+    doDestroy: function() {
+	let me = this;
+
+	me.mediaQueryList.removeEventListener("change", me.themeListener);
+
+	me.callParent();
     },
 });
-- 
2.30.2





  reply	other threads:[~2023-03-08 16:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 16:18 [pbs-devel] [PATCH widget-toolkit v1] Proxmox Dark Theme Stefan Sterz
2023-03-08 16:25 ` Stefan Sterz
2023-03-08 16:33 ` [pbs-devel] [PATCH widget-toolkit v1 1/6] dark-theme: add initial version of the proxmox-dark theme Stefan Sterz
2023-03-08 16:36 ` [pbs-devel] [PATCH widget-toolkit v1 2/6] subscription/summary/backup: stop setting the background color Stefan Sterz
2023-03-08 16:36   ` Stefan Sterz [this message]
2023-03-08 16:36   ` [pbs-devel] [PATCH widget-toolkit v1 4/6] rrd chart: add support for the dark theme and dynamic theme switching Stefan Sterz
2023-03-08 16:37 ` [pbs-devel] [PATCH widget-toolkit v1 5/6] util/window/form: add a theme selector Stefan Sterz
2023-03-08 16:37   ` [pbs-devel] [PATCH widget-toolkit v1 6/6] dark-theme: add support for the pmg quarantine theme toggle Stefan Sterz
2023-03-08 16:41 ` [pbs-devel] [PATCH proxmox-backup v1 1/3] proxy/ui: implement theme switcher Stefan Sterz
2023-03-08 16:41   ` [pbs-devel] [PATCH proxmox-backup v1 2/3] ui: remove white backgrounds from package versions and system report Stefan Sterz
2023-03-14 16:56   ` [pbs-devel] applied: [PATCH proxmox-backup v1 1/3] proxy/ui: implement theme switcher Thomas Lamprecht
2023-03-08 16:43 ` [pbs-devel] [PATCH proxmox-backup v1 2/3] ui: remove white backgrounds from package versions and system report Stefan Sterz
2023-03-08 16:45 ` [pbs-devel] From 39998aadbf833c19a83fea3549105e625b029c50 Mon Sep 17 00:00:00 2001 Stefan Sterz
2023-03-08 16:51   ` Stefan Sterz
2023-03-08 17:04 ` [pbs-devel] applied-series: [pve-devel] [PATCH widget-toolkit v1] Proxmox Dark Theme Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230308163658.2453420-2-s.sterz@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal