mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Fix statistics bar chart time axis (#18450)
This commit is contained in:
parent
c3d809fcf3
commit
c5a0a5bbbf
@ -134,7 +134,7 @@ _adapters._date.override({
|
|||||||
this.options.config
|
this.options.config
|
||||||
);
|
);
|
||||||
case "week":
|
case "week":
|
||||||
return formatDate(
|
return formatDateVeryShort(
|
||||||
new Date(time),
|
new Date(time),
|
||||||
this.options.locale,
|
this.options.locale,
|
||||||
this.options.config
|
this.options.config
|
||||||
|
@ -73,6 +73,8 @@ export class StatisticsChart extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public isLoadingData = false;
|
@property({ type: Boolean }) public isLoadingData = false;
|
||||||
|
|
||||||
|
@property() public period?: string;
|
||||||
|
|
||||||
@state() private _chartData: ChartData = { datasets: [] };
|
@state() private _chartData: ChartData = { datasets: [] };
|
||||||
|
|
||||||
@state() private _statisticIds: string[] = [];
|
@state() private _statisticIds: string[] = [];
|
||||||
@ -92,7 +94,12 @@ export class StatisticsChart extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public willUpdate(changedProps: PropertyValues) {
|
public willUpdate(changedProps: PropertyValues) {
|
||||||
if (!this.hasUpdated || changedProps.has("unit")) {
|
if (
|
||||||
|
!this.hasUpdated ||
|
||||||
|
changedProps.has("unit") ||
|
||||||
|
changedProps.has("period") ||
|
||||||
|
changedProps.has("chartType")
|
||||||
|
) {
|
||||||
this._createOptions();
|
this._createOptions();
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
@ -160,6 +167,7 @@ export class StatisticsChart extends LitElement {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
ticks: {
|
ticks: {
|
||||||
|
source: this.chartType === "bar" ? "data" : undefined,
|
||||||
maxRotation: 0,
|
maxRotation: 0,
|
||||||
sampleSize: 5,
|
sampleSize: 5,
|
||||||
autoSkipPadding: 20,
|
autoSkipPadding: 20,
|
||||||
@ -173,6 +181,12 @@ export class StatisticsChart extends LitElement {
|
|||||||
},
|
},
|
||||||
time: {
|
time: {
|
||||||
tooltipFormat: "datetime",
|
tooltipFormat: "datetime",
|
||||||
|
unit:
|
||||||
|
this.chartType === "bar" &&
|
||||||
|
this.period &&
|
||||||
|
["hour", "day", "week", "month"].includes(this.period)
|
||||||
|
? this.period
|
||||||
|
: undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
y: {
|
y: {
|
||||||
|
@ -193,6 +193,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
|||||||
.isLoadingData=${!this._statistics}
|
.isLoadingData=${!this._statistics}
|
||||||
.statisticsData=${this._statistics}
|
.statisticsData=${this._statistics}
|
||||||
.metadata=${this._metadata}
|
.metadata=${this._metadata}
|
||||||
|
.period=${this._config.period}
|
||||||
.chartType=${this._config.chart_type || "line"}
|
.chartType=${this._config.chart_type || "line"}
|
||||||
.statTypes=${this._statTypes!}
|
.statTypes=${this._statTypes!}
|
||||||
.names=${this._names}
|
.names=${this._names}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user