Align charts when show_names: false (#15782)

* Align charts when show_names: false

* fixes per code review
This commit is contained in:
karwosts 2023-03-15 04:29:45 -07:00 committed by GitHub
parent 27808c9853
commit 020aab0584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -143,11 +143,16 @@ export class StateHistoryChartTimeline extends LitElement {
}
},
afterUpdate: (y) => {
const yWidth = this.showNames
? y.width ?? 0
: computeRTL(this.hass)
? 0
: y.left ?? 0;
if (
this._yWidth !== Math.floor(y.width) &&
this._yWidth !== Math.floor(yWidth) &&
y.ticks.length === this.data.length
) {
this._yWidth = Math.floor(y.width);
this._yWidth = Math.floor(yWidth);
fireEvent(this, "y-width-changed", {
value: this._yWidth,
chartIndex: this.chartIndex,

View File

@ -175,15 +175,14 @@ export class StateHistoryCharts extends LitElement {
if (changedProps.has("_chartCount")) {
if (this._chartCount < this._childYWidths.length) {
this._childYWidths.length = this._chartCount;
this._maxYWidth =
this._childYWidths.length === 0 ? 0 : Math.max(...this._childYWidths);
this._maxYWidth = Math.max(...Object.values(this._childYWidths), 0);
}
}
}
private _yWidthChanged(e: CustomEvent<HASSDomEvents["y-width-changed"]>) {
this._childYWidths[e.detail.chartIndex] = e.detail.value;
this._maxYWidth = Math.max(...this._childYWidths);
this._maxYWidth = Math.max(...Object.values(this._childYWidths), 0);
}
private _isHistoryEmpty(): boolean {