mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 03:36:44 +00:00
Improve graph tooltips (#15887
* Improve graph tooltips * Use xy for state charts * intersect, bigger hitRadius * improve energy * fix position tooltips
This commit is contained in:
parent
0df096d68b
commit
dcac853b71
@ -302,6 +302,7 @@ export default class HaChartBase extends LitElement {
|
|||||||
return css`
|
return css`
|
||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
.chartContainer {
|
.chartContainer {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -61,6 +61,10 @@ class StateHistoryChartLine extends LitElement {
|
|||||||
this._chartOptions = {
|
this._chartOptions = {
|
||||||
parsing: false,
|
parsing: false,
|
||||||
animation: false,
|
animation: false,
|
||||||
|
interaction: {
|
||||||
|
mode: "nearest",
|
||||||
|
axis: "x",
|
||||||
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
type: "time",
|
type: "time",
|
||||||
@ -108,7 +112,6 @@ class StateHistoryChartLine extends LitElement {
|
|||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
mode: "nearest",
|
|
||||||
callbacks: {
|
callbacks: {
|
||||||
label: (context) =>
|
label: (context) =>
|
||||||
`${context.dataset.label}: ${formatNumber(
|
`${context.dataset.label}: ${formatNumber(
|
||||||
@ -127,16 +130,13 @@ class StateHistoryChartLine extends LitElement {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
hover: {
|
|
||||||
mode: "nearest",
|
|
||||||
},
|
|
||||||
elements: {
|
elements: {
|
||||||
line: {
|
line: {
|
||||||
tension: 0.1,
|
tension: 0.1,
|
||||||
borderWidth: 1.5,
|
borderWidth: 1.5,
|
||||||
},
|
},
|
||||||
point: {
|
point: {
|
||||||
hitRadius: 5,
|
hitRadius: 50,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -102,6 +102,7 @@ class StatisticsChart extends LitElement {
|
|||||||
if (
|
if (
|
||||||
changedProps.has("statisticsData") ||
|
changedProps.has("statisticsData") ||
|
||||||
changedProps.has("statTypes") ||
|
changedProps.has("statTypes") ||
|
||||||
|
changedProps.has("chartType") ||
|
||||||
changedProps.has("hideLegend")
|
changedProps.has("hideLegend")
|
||||||
) {
|
) {
|
||||||
this._generateData();
|
this._generateData();
|
||||||
@ -149,6 +150,10 @@ class StatisticsChart extends LitElement {
|
|||||||
this._chartOptions = {
|
this._chartOptions = {
|
||||||
parsing: false,
|
parsing: false,
|
||||||
animation: false,
|
animation: false,
|
||||||
|
interaction: {
|
||||||
|
mode: "nearest",
|
||||||
|
axis: "x",
|
||||||
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
type: "time",
|
type: "time",
|
||||||
@ -186,7 +191,6 @@ class StatisticsChart extends LitElement {
|
|||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
mode: "nearest",
|
|
||||||
callbacks: {
|
callbacks: {
|
||||||
label: (context) =>
|
label: (context) =>
|
||||||
`${context.dataset.label}: ${formatNumber(
|
`${context.dataset.label}: ${formatNumber(
|
||||||
@ -208,9 +212,6 @@ class StatisticsChart extends LitElement {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
hover: {
|
|
||||||
mode: "nearest",
|
|
||||||
},
|
|
||||||
elements: {
|
elements: {
|
||||||
line: {
|
line: {
|
||||||
tension: 0.4,
|
tension: 0.4,
|
||||||
@ -219,7 +220,7 @@ class StatisticsChart extends LitElement {
|
|||||||
},
|
},
|
||||||
bar: { borderWidth: 1.5, borderRadius: 4 },
|
bar: { borderWidth: 1.5, borderRadius: 4 },
|
||||||
point: {
|
point: {
|
||||||
hitRadius: 5,
|
hitRadius: 50,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
@ -316,6 +317,7 @@ class StatisticsChart extends LitElement {
|
|||||||
}
|
}
|
||||||
statDataSets.forEach((d, i) => {
|
statDataSets.forEach((d, i) => {
|
||||||
if (
|
if (
|
||||||
|
this.chartType === "line" &&
|
||||||
prevEndTime &&
|
prevEndTime &&
|
||||||
prevValues &&
|
prevValues &&
|
||||||
prevEndTime.getTime() !== start.getTime()
|
prevEndTime.getTime() !== start.getTime()
|
||||||
|
@ -157,6 +157,9 @@ export class HuiEnergyGasGraphCard
|
|||||||
const options: ChartOptions = {
|
const options: ChartOptions = {
|
||||||
parsing: false,
|
parsing: false,
|
||||||
animation: false,
|
animation: false,
|
||||||
|
interaction: {
|
||||||
|
mode: "x",
|
||||||
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
type: "time",
|
type: "time",
|
||||||
@ -171,9 +174,6 @@ export class HuiEnergyGasGraphCard
|
|||||||
maxRotation: 0,
|
maxRotation: 0,
|
||||||
sampleSize: 5,
|
sampleSize: 5,
|
||||||
autoSkipPadding: 20,
|
autoSkipPadding: 20,
|
||||||
major: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
font: (context) =>
|
font: (context) =>
|
||||||
context.tick && context.tick.major
|
context.tick && context.tick.major
|
||||||
? ({ weight: "bold" } as any)
|
? ({ weight: "bold" } as any)
|
||||||
@ -213,7 +213,7 @@ export class HuiEnergyGasGraphCard
|
|||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
mode: "nearest",
|
position: "nearest",
|
||||||
callbacks: {
|
callbacks: {
|
||||||
title: (datasets) => {
|
title: (datasets) => {
|
||||||
if (dayDifference > 0) {
|
if (dayDifference > 0) {
|
||||||
@ -244,13 +244,10 @@ export class HuiEnergyGasGraphCard
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
hover: {
|
|
||||||
mode: "nearest",
|
|
||||||
},
|
|
||||||
elements: {
|
elements: {
|
||||||
bar: { borderWidth: 1.5, borderRadius: 4 },
|
bar: { borderWidth: 1.5, borderRadius: 4 },
|
||||||
point: {
|
point: {
|
||||||
hitRadius: 5,
|
hitRadius: 50,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -154,6 +154,9 @@ export class HuiEnergySolarGraphCard
|
|||||||
const options: ChartOptions = {
|
const options: ChartOptions = {
|
||||||
parsing: false,
|
parsing: false,
|
||||||
animation: false,
|
animation: false,
|
||||||
|
interaction: {
|
||||||
|
mode: "x",
|
||||||
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
type: "time",
|
type: "time",
|
||||||
@ -168,9 +171,6 @@ export class HuiEnergySolarGraphCard
|
|||||||
maxRotation: 0,
|
maxRotation: 0,
|
||||||
sampleSize: 5,
|
sampleSize: 5,
|
||||||
autoSkipPadding: 20,
|
autoSkipPadding: 20,
|
||||||
major: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
font: (context) =>
|
font: (context) =>
|
||||||
context.tick && context.tick.major
|
context.tick && context.tick.major
|
||||||
? ({ weight: "bold" } as any)
|
? ({ weight: "bold" } as any)
|
||||||
@ -209,7 +209,7 @@ export class HuiEnergySolarGraphCard
|
|||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
mode: "nearest",
|
position: "nearest",
|
||||||
callbacks: {
|
callbacks: {
|
||||||
title: (datasets) => {
|
title: (datasets) => {
|
||||||
if (dayDifference > 0) {
|
if (dayDifference > 0) {
|
||||||
@ -240,9 +240,6 @@ export class HuiEnergySolarGraphCard
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
hover: {
|
|
||||||
mode: "nearest",
|
|
||||||
},
|
|
||||||
elements: {
|
elements: {
|
||||||
line: {
|
line: {
|
||||||
tension: 0.3,
|
tension: 0.3,
|
||||||
|
@ -148,6 +148,9 @@ export class HuiEnergyUsageGraphCard
|
|||||||
const options: ChartOptions = {
|
const options: ChartOptions = {
|
||||||
parsing: false,
|
parsing: false,
|
||||||
animation: false,
|
animation: false,
|
||||||
|
interaction: {
|
||||||
|
mode: "x",
|
||||||
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
type: "time",
|
type: "time",
|
||||||
@ -162,9 +165,6 @@ export class HuiEnergyUsageGraphCard
|
|||||||
maxRotation: 0,
|
maxRotation: 0,
|
||||||
sampleSize: 5,
|
sampleSize: 5,
|
||||||
autoSkipPadding: 20,
|
autoSkipPadding: 20,
|
||||||
major: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
font: (context) =>
|
font: (context) =>
|
||||||
context.tick && context.tick.major
|
context.tick && context.tick.major
|
||||||
? ({ weight: "bold" } as any)
|
? ({ weight: "bold" } as any)
|
||||||
@ -204,8 +204,6 @@ export class HuiEnergyUsageGraphCard
|
|||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
mode: "x",
|
|
||||||
intersect: true,
|
|
||||||
position: "nearest",
|
position: "nearest",
|
||||||
filter: (val) => val.formattedValue !== "0",
|
filter: (val) => val.formattedValue !== "0",
|
||||||
callbacks: {
|
callbacks: {
|
||||||
@ -265,13 +263,10 @@ export class HuiEnergyUsageGraphCard
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
hover: {
|
|
||||||
mode: "nearest",
|
|
||||||
},
|
|
||||||
elements: {
|
elements: {
|
||||||
bar: { borderWidth: 1.5, borderRadius: 4 },
|
bar: { borderWidth: 1.5, borderRadius: 4 },
|
||||||
point: {
|
point: {
|
||||||
hitRadius: 5,
|
hitRadius: 50,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -157,6 +157,9 @@ export class HuiEnergyWaterGraphCard
|
|||||||
const options: ChartOptions = {
|
const options: ChartOptions = {
|
||||||
parsing: false,
|
parsing: false,
|
||||||
animation: false,
|
animation: false,
|
||||||
|
interaction: {
|
||||||
|
mode: "x",
|
||||||
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
type: "time",
|
type: "time",
|
||||||
@ -171,9 +174,6 @@ export class HuiEnergyWaterGraphCard
|
|||||||
maxRotation: 0,
|
maxRotation: 0,
|
||||||
sampleSize: 5,
|
sampleSize: 5,
|
||||||
autoSkipPadding: 20,
|
autoSkipPadding: 20,
|
||||||
major: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
font: (context) =>
|
font: (context) =>
|
||||||
context.tick && context.tick.major
|
context.tick && context.tick.major
|
||||||
? ({ weight: "bold" } as any)
|
? ({ weight: "bold" } as any)
|
||||||
@ -213,7 +213,7 @@ export class HuiEnergyWaterGraphCard
|
|||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
mode: "nearest",
|
position: "nearest",
|
||||||
callbacks: {
|
callbacks: {
|
||||||
title: (datasets) => {
|
title: (datasets) => {
|
||||||
if (dayDifference > 0) {
|
if (dayDifference > 0) {
|
||||||
@ -244,13 +244,10 @@ export class HuiEnergyWaterGraphCard
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
hover: {
|
|
||||||
mode: "nearest",
|
|
||||||
},
|
|
||||||
elements: {
|
elements: {
|
||||||
bar: { borderWidth: 1.5, borderRadius: 4 },
|
bar: { borderWidth: 1.5, borderRadius: 4 },
|
||||||
point: {
|
point: {
|
||||||
hitRadius: 5,
|
hitRadius: 50,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user