From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id D5E52947A; Wed, 8 Mar 2023 17:37:07 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B72A98FF9; Wed, 8 Mar 2023 17:37:07 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS; Wed, 8 Mar 2023 17:37:07 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id BCDB7462F8; Wed, 8 Mar 2023 17:37:06 +0100 (CET) From: Stefan Sterz To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com, pmg-devel@lists.proxmox.com Date: Wed, 8 Mar 2023 17:36:58 +0100 Message-Id: <20230308163658.2453420-3-s.sterz@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230308163658.2453420-1-s.sterz@proxmox.com> References: <20230308161840.2396113-1-s.sterz@proxmox.com> <20230308163658.2453420-1-s.sterz@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.098 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH widget-toolkit v1 4/6] rrd chart: add support for the dark theme and dynamic theme switching X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Mar 2023 16:37:07 -0000 by integrating the theme switching logic into the chart panel itself, themes can be switched more responsively based on css variables. Signed-off-by: Stefan Sterz --- src/panel/RRDChart.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/panel/RRDChart.js b/src/panel/RRDChart.js index 263070a..dc5940c 100644 --- a/src/panel/RRDChart.js +++ b/src/panel/RRDChart.js @@ -183,6 +183,27 @@ Ext.define('Proxmox.widget.RRDChart', { me.callParent([config]); }, + checkThemeColors: function() { + let me = this; + let rootStyle = getComputedStyle(document.documentElement); + + // get colors + let background = rootStyle.getPropertyValue("--pwt-panel-background").trim() || "#ffffff"; + let text = rootStyle.getPropertyValue("--pwt-text-color").trim() || "#000000"; + let primary = rootStyle.getPropertyValue("--pwt-chart-primary").trim() || "#000000"; + let gridStroke = rootStyle.getPropertyValue("--pwt-chart-grid-stroke").trim() || "#dddddd"; + + // set the colors + me.setBackground(background); + me.axes.forEach((axis) => { + axis.setLabel({ color: text }); + axis.setTitle({ color: text }); + axis.setStyle({ strokeStyle: primary }); + axis.setGrid({ stroke: gridStroke }); + }); + me.redraw(); + }, + initComponent: function() { let me = this; @@ -275,5 +296,21 @@ Ext.define('Proxmox.widget.RRDChart', { easing: 'easeIn', }); }, this, { single: true }); + + + 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