Fix colors in network graphs (#26397)

This commit is contained in:
Bram Kragten 2025-08-05 15:14:21 +02:00 committed by GitHub
parent c363995718
commit cdfd6431c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 37 deletions

View File

@ -29,7 +29,6 @@ import { formatTimeLabel } from "./axis-label";
import { ensureArray } from "../../common/array/ensure-array"; import { ensureArray } from "../../common/array/ensure-array";
import "../chips/ha-assist-chip"; import "../chips/ha-assist-chip";
import { downSampleLineData } from "./down-sample"; import { downSampleLineData } from "./down-sample";
import { colorVariables } from "../../resources/theme/color/color.globals";
export const MIN_TIME_BETWEEN_UPDATES = 60 * 5 * 1000; export const MIN_TIME_BETWEEN_UPDATES = 60 * 5 * 1000;
const LEGEND_OVERFLOW_LIMIT = 10; const LEGEND_OVERFLOW_LIMIT = 10;
@ -344,7 +343,8 @@ export class HaChartBase extends LitElement {
echarts.use(this.extraComponents); echarts.use(this.extraComponents);
} }
echarts.registerTheme("custom", this._createTheme()); const style = getComputedStyle(this);
echarts.registerTheme("custom", this._createTheme(style));
this.chart = echarts.init(container, "custom"); this.chart = echarts.init(container, "custom");
this.chart.on("datazoom", (e: any) => { this.chart.on("datazoom", (e: any) => {
@ -396,7 +396,7 @@ export class HaChartBase extends LitElement {
...axis.axisPointer, ...axis.axisPointer,
status: "show", status: "show",
handle: { handle: {
color: colorVariables["primary-color"], color: style.getPropertyValue("primary-color"),
margin: 0, margin: 0,
size: 20, size: 20,
...axis.axisPointer?.handle, ...axis.axisPointer?.handle,
@ -570,8 +570,7 @@ export class HaChartBase extends LitElement {
return options; return options;
} }
private _createTheme() { private _createTheme(style: CSSStyleDeclaration) {
const style = getComputedStyle(this);
return { return {
color: getAllGraphColors(style), color: getAllGraphColors(style),
backgroundColor: "transparent", backgroundColor: "transparent",

View File

@ -26,7 +26,6 @@ import {
} from "../../../../../data/bluetooth"; } from "../../../../../data/bluetooth";
import type { DeviceRegistryEntry } from "../../../../../data/device_registry"; import type { DeviceRegistryEntry } from "../../../../../data/device_registry";
import "../../../../../layouts/hass-subpage"; import "../../../../../layouts/hass-subpage";
import { colorVariables } from "../../../../../resources/theme/color/color.globals";
import type { HomeAssistant, Route } from "../../../../../types"; import type { HomeAssistant, Route } from "../../../../../types";
import { bluetoothAdvertisementMonitorTabs } from "./bluetooth-advertisement-monitor"; import { bluetoothAdvertisementMonitorTabs } from "./bluetooth-advertisement-monitor";
@ -131,33 +130,34 @@ export class BluetoothNetworkVisualization extends LitElement {
data: BluetoothDeviceData[], data: BluetoothDeviceData[],
scanners: BluetoothScannersDetails scanners: BluetoothScannersDetails
): NetworkData => { ): NetworkData => {
const style = getComputedStyle(this);
const categories = [ const categories = [
{ {
name: CORE_SOURCE_LABEL, name: CORE_SOURCE_LABEL,
symbol: "roundRect", symbol: "roundRect",
itemStyle: { itemStyle: {
color: colorVariables["primary-color"], color: style.getPropertyValue("--primary-color"),
}, },
}, },
{ {
name: this.hass.localize("ui.panel.config.bluetooth.scanners"), name: this.hass.localize("ui.panel.config.bluetooth.scanners"),
symbol: "circle", symbol: "circle",
itemStyle: { itemStyle: {
color: colorVariables["cyan-color"], color: style.getPropertyValue("--cyan-color"),
}, },
}, },
{ {
name: this.hass.localize("ui.panel.config.bluetooth.known_devices"), name: this.hass.localize("ui.panel.config.bluetooth.known_devices"),
symbol: "circle", symbol: "circle",
itemStyle: { itemStyle: {
color: colorVariables["teal-color"], color: style.getPropertyValue("--teal-color"),
}, },
}, },
{ {
name: this.hass.localize("ui.panel.config.bluetooth.unknown_devices"), name: this.hass.localize("ui.panel.config.bluetooth.unknown_devices"),
symbol: "circle", symbol: "circle",
itemStyle: { itemStyle: {
color: colorVariables["disabled-color"], color: style.getPropertyValue("--disabled-color"),
}, },
}, },
]; ];
@ -192,7 +192,7 @@ export class BluetoothNetworkVisualization extends LitElement {
symbol: "none", symbol: "none",
lineStyle: { lineStyle: {
width: 3, width: 3,
color: colorVariables["primary-color"], color: style.getPropertyValue("--primary-color"),
}, },
}); });
}); });
@ -206,7 +206,7 @@ export class BluetoothNetworkVisualization extends LitElement {
symbol: "none", symbol: "none",
lineStyle: { lineStyle: {
width: this._getLineWidth(node.rssi), width: this._getLineWidth(node.rssi),
color: colorVariables["primary-color"], color: style.getPropertyValue("--primary-color"),
}, },
}); });
return; return;
@ -227,8 +227,8 @@ export class BluetoothNetworkVisualization extends LitElement {
lineStyle: { lineStyle: {
width: this._getLineWidth(node.rssi), width: this._getLineWidth(node.rssi),
color: device color: device
? colorVariables["primary-color"] ? style.getPropertyValue("--primary-color")
: colorVariables["disabled-color"], : style.getPropertyValue("--disabled-color"),
}, },
}); });
}); });

View File

@ -16,7 +16,6 @@ import type {
import type { ZHADevice } from "../../../../../data/zha"; import type { ZHADevice } from "../../../../../data/zha";
import { fetchDevices, refreshTopology } from "../../../../../data/zha"; import { fetchDevices, refreshTopology } from "../../../../../data/zha";
import "../../../../../layouts/hass-tabs-subpage"; import "../../../../../layouts/hass-tabs-subpage";
import { colorVariables } from "../../../../../resources/theme/color/color.globals";
import type { HomeAssistant, Route } from "../../../../../types"; import type { HomeAssistant, Route } from "../../../../../types";
import { formatAsPaddedHex } from "./functions"; import { formatAsPaddedHex } from "./functions";
import { zhaTabs } from "./zha-config-dashboard"; import { zhaTabs } from "./zha-config-dashboard";
@ -156,10 +155,12 @@ export class ZHANetworkVisualizationPage extends LitElement {
} }
private _createChartData(devices: ZHADevice[]): NetworkData { private _createChartData(devices: ZHADevice[]): NetworkData {
const primaryColor = colorVariables["primary-color"]; const style = getComputedStyle(this);
const routerColor = colorVariables["cyan-color"];
const endDeviceColor = colorVariables["teal-color"]; const primaryColor = style.getPropertyValue("--primary-color");
const offlineColor = colorVariables["error-color"]; const routerColor = style.getPropertyValue("--cyan-color");
const endDeviceColor = style.getPropertyValue("--teal-color");
const offlineColor = style.getPropertyValue("--error-color");
const nodes: NetworkNode[] = []; const nodes: NetworkNode[] = [];
const links: NetworkLink[] = []; const links: NetworkLink[] = [];
const categories = [ const categories = [
@ -282,7 +283,7 @@ export class ZHANetworkVisualizationPage extends LitElement {
color: color:
route.route_status === "Active" route.route_status === "Active"
? primaryColor ? primaryColor
: colorVariables["disabled-color"], : style.getPropertyValue("--disabled-color"),
type: ["Child", "Parent"].includes(neighbor.relationship) type: ["Child", "Parent"].includes(neighbor.relationship)
? "solid" ? "solid"
: "dotted", : "dotted",
@ -322,7 +323,7 @@ export class ZHANetworkVisualizationPage extends LitElement {
symbolSize: 5, symbolSize: 5,
lineStyle: { lineStyle: {
width: 1, width: 1,
color: colorVariables["disabled-color"], color: style.getPropertyValue("--disabled-color"),
type: "dotted", type: "dotted",
}, },
ignoreForceLayout: true, ignoreForceLayout: true,

View File

@ -25,7 +25,6 @@ import {
} from "../../../../../data/zwave_js"; } from "../../../../../data/zwave_js";
import "../../../../../layouts/hass-tabs-subpage"; import "../../../../../layouts/hass-tabs-subpage";
import { SubscribeMixin } from "../../../../../mixins/subscribe-mixin"; import { SubscribeMixin } from "../../../../../mixins/subscribe-mixin";
import { colorVariables } from "../../../../../resources/theme/color/color.globals";
import type { HomeAssistant, Route } from "../../../../../types"; import type { HomeAssistant, Route } from "../../../../../types";
import { configTabs } from "./zwave_js-config-router"; import { configTabs } from "./zwave_js-config-router";
@ -147,8 +146,10 @@ export class ZWaveJSNetworkVisualization extends SubscribeMixin(LitElement) {
nodeStatuses: Record<number, ZWaveJSNodeStatus>, nodeStatuses: Record<number, ZWaveJSNodeStatus>,
nodeStatistics: Record<number, ZWaveJSNodeStatisticsUpdatedMessage> nodeStatistics: Record<number, ZWaveJSNodeStatisticsUpdatedMessage>
): NetworkData => { ): NetworkData => {
const style = getComputedStyle(this);
const nodes: NetworkNode[] = []; const nodes: NetworkNode[] = [];
const links: NetworkLink[] = []; const links: NetworkLink[] = [];
const categories = [ const categories = [
{ {
name: this.hass.localize( name: this.hass.localize(
@ -156,7 +157,7 @@ export class ZWaveJSNetworkVisualization extends SubscribeMixin(LitElement) {
), ),
symbol: "roundRect", symbol: "roundRect",
itemStyle: { itemStyle: {
color: colorVariables["primary-color"], color: style.getPropertyValue("--primary-color"),
}, },
}, },
{ {
@ -165,7 +166,7 @@ export class ZWaveJSNetworkVisualization extends SubscribeMixin(LitElement) {
), ),
symbol: "circle", symbol: "circle",
itemStyle: { itemStyle: {
color: colorVariables["cyan-color"], color: style.getPropertyValue("--cyan-color"),
}, },
}, },
{ {
@ -174,7 +175,7 @@ export class ZWaveJSNetworkVisualization extends SubscribeMixin(LitElement) {
), ),
symbol: "circle", symbol: "circle",
itemStyle: { itemStyle: {
color: colorVariables["disabled-color"], color: style.getPropertyValue("--disabled-color"),
}, },
}, },
{ {
@ -183,7 +184,7 @@ export class ZWaveJSNetworkVisualization extends SubscribeMixin(LitElement) {
), ),
symbol: "circle", symbol: "circle",
itemStyle: { itemStyle: {
color: colorVariables["error-color"], color: style.getPropertyValue("--error-color"),
}, },
}, },
]; ];
@ -214,12 +215,12 @@ export class ZWaveJSNetworkVisualization extends SubscribeMixin(LitElement) {
itemStyle: { itemStyle: {
color: color:
node.status === NodeStatus.Dead node.status === NodeStatus.Dead
? colorVariables["error-color"] ? style.getPropertyValue("--error-color")
: node.status === NodeStatus.Asleep : node.status === NodeStatus.Asleep
? colorVariables["disabled-color"] ? style.getPropertyValue("--disabled-color")
: node.is_controller_node : node.is_controller_node
? colorVariables["primary-color"] ? style.getPropertyValue("--primary-color")
: colorVariables["cyan-color"], : style.getPropertyValue("--cyan-color"),
}, },
polarDistance: node.is_controller_node polarDistance: node.is_controller_node
? 0 ? 0
@ -269,8 +270,8 @@ export class ZWaveJSNetworkVisualization extends SubscribeMixin(LitElement) {
width, width,
color: color:
repeater === controllerNode repeater === controllerNode
? colorVariables["primary-color"] ? style.getPropertyValue("--primary-color")
: colorVariables["disabled-color"], : style.getPropertyValue("--disabled-color"),
type: route.protocol_data_rate > 1 ? "solid" : "dotted", type: route.protocol_data_rate > 1 ? "solid" : "dotted",
}, },
symbolSize: width * 3, symbolSize: width * 3,

View File

@ -1,8 +1,5 @@
import { css } from "lit"; import { css } from "lit";
import { import { extractVar } from "../../../common/style/derived-css-vars";
extractVar,
extractVars,
} from "../../../common/style/derived-css-vars";
import { coreColorVariables } from "./core.globals"; import { coreColorVariables } from "./core.globals";
export const colorStyles = css` export const colorStyles = css`
@ -365,7 +362,6 @@ export const darkColorStyles = css`
--ha-button-neutral-light-color: #6a7081; --ha-button-neutral-light-color: #6a7081;
} }
`; `;
export const colorVariables = extractVars(colorStyles);
export const DefaultPrimaryColor = extractVar( export const DefaultPrimaryColor = extractVar(
colorStyles, colorStyles,