Remove name from the chart series when using showNames = false (#23995)

* Remove name from the chart series when using showNames = false

* Remove translations
This commit is contained in:
Paul Bottein 2025-01-31 17:38:50 +01:00 committed by GitHub
parent d4497ca39c
commit 816989ab4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 92 additions and 39 deletions

View File

@ -152,7 +152,10 @@ export class StateHistoryChartLine extends LitElement {
value += source; value += source;
} }
return `${param.marker} ${param.seriesName}: ${value}`; if (param.seriesName) {
return `${param.marker} ${param.seriesName}: ${value}`;
}
return `${param.marker} ${value}`;
}) })
.join("<br>") .join("<br>")
); );
@ -410,13 +413,21 @@ export class StateHistoryChartLine extends LitElement {
entityState.attributes.target_temp_low entityState.attributes.target_temp_low
); );
addDataSet( addDataSet(
`${this.hass.localize("ui.card.climate.current_temperature", { this.showNames
name: name, ? this.hass.localize("ui.card.climate.current_temperature", {
})}` name: name,
})
: this.hass.localize(
"component.climate.entity_component._.state_attributes.current_temperature.name"
)
); );
if (hasHeat) { if (hasHeat) {
addDataSet( addDataSet(
`${this.hass.localize("ui.card.climate.heating", { name: name })}`, this.showNames
? this.hass.localize("ui.card.climate.heating", { name: name })
: this.hass.localize(
"component.climate.entity_component._.state_attributes.hvac_action.state.heating"
),
computedStyles.getPropertyValue("--state-climate-heat-color"), computedStyles.getPropertyValue("--state-climate-heat-color"),
true true
); );
@ -425,7 +436,11 @@ export class StateHistoryChartLine extends LitElement {
} }
if (hasCool) { if (hasCool) {
addDataSet( addDataSet(
`${this.hass.localize("ui.card.climate.cooling", { name: name })}`, this.showNames
? this.hass.localize("ui.card.climate.cooling", { name: name })
: this.hass.localize(
"component.climate.entity_component._.state_attributes.hvac_action.state.cooling"
),
computedStyles.getPropertyValue("--state-climate-cool-color"), computedStyles.getPropertyValue("--state-climate-cool-color"),
true true
); );
@ -435,22 +450,37 @@ export class StateHistoryChartLine extends LitElement {
if (hasTargetRange) { if (hasTargetRange) {
addDataSet( addDataSet(
`${this.hass.localize("ui.card.climate.target_temperature_mode", { this.showNames
name: name, ? this.hass.localize("ui.card.climate.target_temperature_mode", {
mode: this.hass.localize("ui.card.climate.high"), name: name,
})}` mode: this.hass.localize("ui.card.climate.high"),
})
: this.hass.localize(
"component.climate.entity_component._.state_attributes.target_temp_high.name"
)
); );
addDataSet( addDataSet(
`${this.hass.localize("ui.card.climate.target_temperature_mode", { this.showNames
name: name, ? this.hass.localize("ui.card.climate.target_temperature_mode", {
mode: this.hass.localize("ui.card.climate.low"), name: name,
})}` mode: this.hass.localize("ui.card.climate.low"),
})
: this.hass.localize(
"component.climate.entity_component._.state_attributes.target_temp_low.name"
)
); );
} else { } else {
addDataSet( addDataSet(
`${this.hass.localize("ui.card.climate.target_temperature_entity", { this.showNames
name: name, ? this.hass.localize(
})}` "ui.card.climate.target_temperature_entity",
{
name: name,
}
)
: this.hass.localize(
"component.climate.entity_component._.state_attributes.temperature.name"
)
); );
} }
@ -503,19 +533,27 @@ export class StateHistoryChartLine extends LitElement {
); );
addDataSet( addDataSet(
`${this.hass.localize("ui.card.humidifier.target_humidity_entity", { this.showNames
name: name, ? this.hass.localize("ui.card.humidifier.target_humidity_entity", {
})}` name: name,
})
: this.hass.localize(
"component.humidifier.entity_component._.state_attributes.humidity.name"
)
); );
if (hasCurrent) { if (hasCurrent) {
addDataSet( addDataSet(
`${this.hass.localize( this.showNames
"ui.card.humidifier.current_humidity_entity", ? this.hass.localize(
{ "ui.card.humidifier.current_humidity_entity",
name: name, {
} name: name,
)}` }
)
: this.hass.localize(
"component.humidifier.entity_component._.state_attributes.current_humidity.name"
)
); );
} }
@ -523,25 +561,37 @@ export class StateHistoryChartLine extends LitElement {
// If action attribute is not available, we shade the area when the device is on // If action attribute is not available, we shade the area when the device is on
if (hasHumidifying) { if (hasHumidifying) {
addDataSet( addDataSet(
`${this.hass.localize("ui.card.humidifier.humidifying", { this.showNames
name: name, ? this.hass.localize("ui.card.humidifier.humidifying", {
})}`, name: name,
})
: this.hass.localize(
"component.humidifier.entity_component._.state_attributes.action.state.humidifying"
),
computedStyles.getPropertyValue("--state-humidifier-on-color"), computedStyles.getPropertyValue("--state-humidifier-on-color"),
true true
); );
} else if (hasDrying) { } else if (hasDrying) {
addDataSet( addDataSet(
`${this.hass.localize("ui.card.humidifier.drying", { this.showNames
name: name, ? this.hass.localize("ui.card.humidifier.drying", {
})}`, name: name,
})
: this.hass.localize(
"component.humidifier.entity_component._.state_attributes.action.state.drying"
),
computedStyles.getPropertyValue("--state-humidifier-on-color"), computedStyles.getPropertyValue("--state-humidifier-on-color"),
true true
); );
} else { } else {
addDataSet( addDataSet(
`${this.hass.localize("ui.card.humidifier.on_entity", { this.showNames
name: name, ? this.hass.localize("ui.card.humidifier.on_entity", {
})}`, name: name,
})
: this.hass.localize(
"component.humidifier.entity_component._.state.on"
),
undefined, undefined,
true true
); );
@ -574,7 +624,7 @@ export class StateHistoryChartLine extends LitElement {
pushData(new Date(entityState.last_changed), series); pushData(new Date(entityState.last_changed), series);
}); });
} else { } else {
addDataSet(name); addDataSet(this.showNames ? name : "");
let lastValue: number; let lastValue: number;
let lastDate: Date; let lastDate: Date;

View File

@ -132,7 +132,9 @@ export class StateHistoryChartTimeline extends LitElement {
const { value, name, marker } = Array.isArray(params) const { value, name, marker } = Array.isArray(params)
? params[0] ? params[0]
: params; : params;
const title = `<h4 style="text-align: center; margin: 0;">${value![0]}</h4>`; const title = value![0]
? `<h4 style="text-align: center; margin: 0;">${value![0]}</h4>`
: "";
const durationInMs = value![2] - value![1]; const durationInMs = value![2] - value![1];
const formattedDuration = `${this.hass.localize( const formattedDuration = `${this.hass.localize(
"ui.components.history_charts.duration" "ui.components.history_charts.duration"
@ -281,8 +283,9 @@ export class StateHistoryChartTimeline extends LitElement {
let prevState: string | null = null; let prevState: string | null = null;
let locState: string | null = null; let locState: string | null = null;
let prevLastChanged = startTime; let prevLastChanged = startTime;
const entityDisplay: string = const entityDisplay: string = this.showNames
names[stateInfo.entity_id] || stateInfo.name; ? names[stateInfo.entity_id] || stateInfo.name
: "";
const dataRow: unknown[] = []; const dataRow: unknown[] = [];
stateInfo.data.forEach((entityState) => { stateInfo.data.forEach((entityState) => {