mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Added entity_id to history graph tooltip (#7310)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
97ca0b818e
commit
993d73c359
@ -85,6 +85,10 @@ class HaChartBase extends mixinBehaviors(
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
.chartTooltip .beforeBody {
|
||||||
|
text-align: center;
|
||||||
|
font-weight: 300;
|
||||||
|
}
|
||||||
.chartLegend li {
|
.chartLegend li {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 0 6px;
|
padding: 0 6px;
|
||||||
@ -139,6 +143,9 @@ class HaChartBase extends mixinBehaviors(
|
|||||||
style$="opacity:[[tooltip.opacity]]; top:[[tooltip.top]]; left:[[tooltip.left]]; padding:[[tooltip.yPadding]]px [[tooltip.xPadding]]px"
|
style$="opacity:[[tooltip.opacity]]; top:[[tooltip.top]]; left:[[tooltip.left]]; padding:[[tooltip.yPadding]]px [[tooltip.xPadding]]px"
|
||||||
>
|
>
|
||||||
<div class="title">[[tooltip.title]]</div>
|
<div class="title">[[tooltip.title]]</div>
|
||||||
|
<template is="dom-if" if="[[tooltip.beforeBody]]">
|
||||||
|
<div class="beforeBody">[[tooltip.beforeBody]]</div>
|
||||||
|
</template>
|
||||||
<div>
|
<div>
|
||||||
<ul>
|
<ul>
|
||||||
<template is="dom-repeat" items="[[tooltip.lines]]">
|
<template is="dom-repeat" items="[[tooltip.lines]]">
|
||||||
@ -270,6 +277,10 @@ class HaChartBase extends mixinBehaviors(
|
|||||||
const title = tooltip.title ? tooltip.title[0] || "" : "";
|
const title = tooltip.title ? tooltip.title[0] || "" : "";
|
||||||
this.set(["tooltip", "title"], title);
|
this.set(["tooltip", "title"], title);
|
||||||
|
|
||||||
|
if (tooltip.beforeBody) {
|
||||||
|
this.set(["tooltip", "beforeBody"], tooltip.beforeBody.join("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
const bodyLines = tooltip.body.map((n) => n.lines);
|
const bodyLines = tooltip.body.map((n) => n.lines);
|
||||||
|
|
||||||
// Set Text
|
// Set Text
|
||||||
|
@ -159,7 +159,7 @@ class StateHistoryChartTimeline extends LocalizeMixin(PolymerElement) {
|
|||||||
if (prevState !== null) {
|
if (prevState !== null) {
|
||||||
dataRow.push([prevLastChanged, endTime, locState, prevState]);
|
dataRow.push([prevLastChanged, endTime, locState, prevState]);
|
||||||
}
|
}
|
||||||
datasets.push({ data: dataRow });
|
datasets.push({ data: dataRow, entity_id: stateInfo.entity_id });
|
||||||
labels.push(entityDisplay);
|
labels.push(entityDisplay);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -173,12 +173,22 @@ class StateHistoryChartTimeline extends LocalizeMixin(PolymerElement) {
|
|||||||
return [state, start, end];
|
return [state, start, end];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const formatTooltipBeforeBody = (item, data) => {
|
||||||
|
if (!this.hass.userData || !this.hass.userData.showAdvanced || !item[0]) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
// Extract the entity ID from the dataset.
|
||||||
|
const values = data.datasets[item[0].datasetIndex];
|
||||||
|
return values.entity_id || "";
|
||||||
|
};
|
||||||
|
|
||||||
const chartOptions = {
|
const chartOptions = {
|
||||||
type: "timeline",
|
type: "timeline",
|
||||||
options: {
|
options: {
|
||||||
tooltips: {
|
tooltips: {
|
||||||
callbacks: {
|
callbacks: {
|
||||||
label: formatTooltipLabel,
|
label: formatTooltipLabel,
|
||||||
|
beforeBody: formatTooltipBeforeBody,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
scales: {
|
scales: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user