mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Update statistics chart to respect entity display precision, fix precision bug in history chart (#18334)
This commit is contained in:
parent
65112b36ce
commit
6cae11f0a6
@ -141,16 +141,10 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
`${context.dataset.label}: ${formatNumber(
|
`${context.dataset.label}: ${formatNumber(
|
||||||
context.parsed.y,
|
context.parsed.y,
|
||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
this.data[context.datasetIndex]?.entity_id
|
getNumberFormatOptions(
|
||||||
? getNumberFormatOptions(
|
undefined,
|
||||||
this.hass.states[
|
this.hass.entities[this._entityIds[context.datasetIndex]]
|
||||||
this.data[context.datasetIndex].entity_id
|
)
|
||||||
],
|
|
||||||
this.hass.entities[
|
|
||||||
this.data[context.datasetIndex].entity_id
|
|
||||||
]
|
|
||||||
)
|
|
||||||
: undefined
|
|
||||||
)} ${this.unit}`,
|
)} ${this.unit}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -19,6 +19,7 @@ import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
|||||||
import {
|
import {
|
||||||
formatNumber,
|
formatNumber,
|
||||||
numberFormatToLocale,
|
numberFormatToLocale,
|
||||||
|
getNumberFormatOptions,
|
||||||
} from "../../common/number/format_number";
|
} from "../../common/number/format_number";
|
||||||
import {
|
import {
|
||||||
getDisplayUnit,
|
getDisplayUnit,
|
||||||
@ -74,6 +75,8 @@ export class StatisticsChart extends LitElement {
|
|||||||
|
|
||||||
@state() private _chartData: ChartData = { datasets: [] };
|
@state() private _chartData: ChartData = { datasets: [] };
|
||||||
|
|
||||||
|
@state() private _statisticIds: string[] = [];
|
||||||
|
|
||||||
@state() private _chartOptions?: ChartOptions;
|
@state() private _chartOptions?: ChartOptions;
|
||||||
|
|
||||||
@query("ha-chart-base") private _chart?: HaChartBase;
|
@query("ha-chart-base") private _chart?: HaChartBase;
|
||||||
@ -189,7 +192,11 @@ export class StatisticsChart extends LitElement {
|
|||||||
label: (context) =>
|
label: (context) =>
|
||||||
`${context.dataset.label}: ${formatNumber(
|
`${context.dataset.label}: ${formatNumber(
|
||||||
context.parsed.y,
|
context.parsed.y,
|
||||||
this.hass.locale
|
this.hass.locale,
|
||||||
|
getNumberFormatOptions(
|
||||||
|
undefined,
|
||||||
|
this.hass.entities[this._statisticIds[context.datasetIndex]]
|
||||||
|
)
|
||||||
)} ${
|
)} ${
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
context.dataset.unit || ""
|
context.dataset.unit || ""
|
||||||
@ -248,6 +255,7 @@ export class StatisticsChart extends LitElement {
|
|||||||
let colorIndex = 0;
|
let colorIndex = 0;
|
||||||
const statisticsData = Object.entries(this.statisticsData);
|
const statisticsData = Object.entries(this.statisticsData);
|
||||||
const totalDataSets: ChartDataset<"line">[] = [];
|
const totalDataSets: ChartDataset<"line">[] = [];
|
||||||
|
const statisticIds: string[] = [];
|
||||||
let endTime: Date;
|
let endTime: Date;
|
||||||
|
|
||||||
if (statisticsData.length === 0) {
|
if (statisticsData.length === 0) {
|
||||||
@ -386,6 +394,7 @@ export class StatisticsChart extends LitElement {
|
|||||||
unit: meta?.unit_of_measurement,
|
unit: meta?.unit_of_measurement,
|
||||||
band,
|
band,
|
||||||
});
|
});
|
||||||
|
statisticIds.push(statistic_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -427,6 +436,7 @@ export class StatisticsChart extends LitElement {
|
|||||||
this._chartData = {
|
this._chartData = {
|
||||||
datasets: totalDataSets,
|
datasets: totalDataSets,
|
||||||
};
|
};
|
||||||
|
this._statisticIds = statisticIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user