Skip to content

Fix more-info chart rendering #23619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/chart/ha-chart-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export class HaChartBase extends LitElement {
this._hiddenDatasets.add(index);
}
});
if (!this.height) {
// lock the height so it doesn't change when the parent element resizes
this.height = this._getDefaultHeight();
}
}

public shouldUpdate(changedProps: PropertyValues): boolean {
Expand Down Expand Up @@ -234,7 +238,7 @@ export class HaChartBase extends LitElement {
<div
class="chart-container"
style=${styleMap({
height: `${this.height ?? this.clientWidth / 2}px`,
height: `${this.height ?? this._getDefaultHeight()}px`,
"padding-left": `${this._paddingYAxisInternal}px`,
"padding-right": 0,
"padding-inline-start": `${this._paddingYAxisInternal}px`,
Expand Down Expand Up @@ -419,6 +423,10 @@ export class HaChartBase extends LitElement {
};
}

private _getDefaultHeight() {
return this.clientWidth / 2;
}

private _handleChartScroll(ev: MouseEvent) {
const modifier = isMac ? "metaKey" : "ctrlKey";
this._tooltip = undefined;
Expand Down
3 changes: 0 additions & 3 deletions src/components/chart/state-history-chart-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export class StateHistoryChartLine extends LitElement {

@property({ attribute: "fit-y-data", type: Boolean }) public fitYData = false;

@property({ attribute: false, type: Number }) public height?: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the height option completely? I think we can keep this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't there before so isn't used. I didn't want to add extra attributes without a use case. We can always add it if we need it.


@state() private _chartData?: ChartData<"line">;

@state() private _entityIds: string[] = [];
Expand All @@ -76,7 +74,6 @@ export class StateHistoryChartLine extends LitElement {
.options=${this._chartOptions}
.paddingYAxis=${this.paddingYAxis - this._yWidth}
chart-type="line"
.height=${this.height}
></ha-chart-base>
`;
}
Expand Down
3 changes: 0 additions & 3 deletions src/components/chart/state-history-charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ export class StateHistoryCharts extends LitElement {

@property({ attribute: "fit-y-data", type: Boolean }) public fitYData = false;

@property({ attribute: false, type: Number }) public height?: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the height option completely? I think we can keep this?


private _computedStartTime!: Date;

private _computedEndTime!: Date;
Expand Down Expand Up @@ -153,7 +151,6 @@ export class StateHistoryCharts extends LitElement {
.maxYAxis=${this.maxYAxis}
.fitYData=${this.fitYData}
@y-width-changed=${this._yWidthChanged}
.height=${this.height}
></state-history-chart-line>
</div> `;
}
Expand Down
3 changes: 0 additions & 3 deletions src/components/chart/statistics-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ export class StatisticsChart extends LitElement {

@property() public period?: string;

@property({ attribute: false, type: Number }) public height?: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the height option completely?


@state() private _chartData: ChartData = { datasets: [] };

@state() private _chartDatasetExtra: ChartDatasetExtra[] = [];
Expand Down Expand Up @@ -167,7 +165,6 @@ export class StatisticsChart extends LitElement {
.chartType=${this.chartType}
@dataset-hidden=${this._datasetHidden}
@dataset-unhidden=${this._datasetUnhidden}
.height=${this.height}
></ha-chart-base>
`;
}
Expand Down
8 changes: 0 additions & 8 deletions src/dialogs/more-info/ha-more-info-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ export class MoreInfoHistory extends LitElement {

private _metadata?: Record<string, StatisticsMetaData>;

private _chartHeight?: number;

protected firstUpdated() {
this._chartHeight = this.clientWidth / 2;
}

protected render() {
if (!this.entityId) {
return nothing;
Expand Down Expand Up @@ -87,7 +81,6 @@ export class MoreInfoHistory extends LitElement {
.names=${this._statNames}
hide-legend
.clickForMoreInfo=${false}
.height=${this._chartHeight}
></statistics-chart>`
: html`<state-history-charts
up-to-now
Expand All @@ -96,7 +89,6 @@ export class MoreInfoHistory extends LitElement {
.isLoadingData=${!this._stateHistory}
.showNames=${false}
.clickForMoreInfo=${false}
.height=${this._chartHeight}
></state-history-charts>`}`
: ""}`;
}
Expand Down
Loading