mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 23:36:36 +00:00
Fix chart tooltip format for line charts (#1099)
* position tooltip correctly if chart is in history_graph card * format & localize title in linechart * tweak tooltip style/position
This commit is contained in:
parent
0a60ec2298
commit
2aa02ff561
@ -41,7 +41,7 @@
|
|||||||
color: white;
|
color: white;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
transform: translate(-50%, 5px);
|
transform: translate(-50%, 12px);
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
width: 200px;
|
width: 200px;
|
||||||
transition: opacity 0.15s ease-in-out;
|
transition: opacity 0.15s ease-in-out;
|
||||||
@ -50,7 +50,7 @@
|
|||||||
.chartTooltip ul {
|
.chartTooltip ul {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 0 0px;
|
padding: 0 0px;
|
||||||
margin: 8px 0 0 0;
|
margin: 5px 0 0 0;
|
||||||
width: 100%
|
width: 100%
|
||||||
}
|
}
|
||||||
.chartTooltip li {
|
.chartTooltip li {
|
||||||
@ -59,6 +59,7 @@
|
|||||||
}
|
}
|
||||||
.chartTooltip .title {
|
.chartTooltip .title {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
.chartLegend li {
|
.chartLegend li {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@ -161,8 +162,8 @@
|
|||||||
opacity: '0',
|
opacity: '0',
|
||||||
left: '0',
|
left: '0',
|
||||||
top: '0',
|
top: '0',
|
||||||
xPadding: '0',
|
xPadding: '5',
|
||||||
yPadding: '0'
|
yPadding: '3'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
unit: Object,
|
unit: Object,
|
||||||
@ -245,20 +246,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const title = tooltip.title ? tooltip.title[0] || '' : '';
|
const title = tooltip.title ? tooltip.title[0] || '' : '';
|
||||||
let titleDate = null;
|
this.set(['tooltip', 'title'], title);
|
||||||
let formattedTitle;
|
|
||||||
if (title instanceof Date) {
|
|
||||||
titleDate = title;
|
|
||||||
} else if (title instanceof moment) {
|
|
||||||
titleDate = title.toDate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (titleDate === null) {
|
|
||||||
formattedTitle = title;
|
|
||||||
} else {
|
|
||||||
formattedTitle = window.hassUtil.formatDateTime(titleDate);
|
|
||||||
}
|
|
||||||
this.set(['tooltip', 'title'], formattedTitle);
|
|
||||||
|
|
||||||
const bodyLines = tooltip.body.map(n => n.lines);
|
const bodyLines = tooltip.body.map(n => n.lines);
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
padding-top: 8px;
|
padding-top: 8px;
|
||||||
padding-right: 8px;
|
padding-right: 8px;
|
||||||
transform: translateZ(0);
|
transform: translateZ(0);
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.badges {
|
.badges {
|
||||||
|
@ -235,6 +235,13 @@ class StateHistoryChartLine extends Polymer.Element {
|
|||||||
Array.prototype.push.apply(datasets, data);
|
Array.prototype.push.apply(datasets, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const formatTooltipTitle = function (items, data) {
|
||||||
|
const item = items[0];
|
||||||
|
const date = data.datasets[item.datasetIndex].data[item.index].x;
|
||||||
|
|
||||||
|
return window.hassUtil.formatDateTime(date);
|
||||||
|
};
|
||||||
|
|
||||||
const chartOptions = {
|
const chartOptions = {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
unit: unit,
|
unit: unit,
|
||||||
@ -257,6 +264,9 @@ class StateHistoryChartLine extends Polymer.Element {
|
|||||||
},
|
},
|
||||||
tooltips: {
|
tooltips: {
|
||||||
mode: 'neareach',
|
mode: 'neareach',
|
||||||
|
callbacks: {
|
||||||
|
title: formatTooltipTitle
|
||||||
|
},
|
||||||
},
|
},
|
||||||
hover: {
|
hover: {
|
||||||
mode: 'neareach',
|
mode: 'neareach',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user