Skip to content

Commit

Permalink
Improve chart height and narrow option in grid section (#24046)
Browse files Browse the repository at this point in the history
* Fix chart size in grid

* Set minimal height to 2 for history chart

* Update history chart
  • Loading branch information
piitaya authored Feb 3, 2025
1 parent 38bcdaa commit 67b970f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/panels/lovelace/cards/hui-history-graph-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
return {
columns: 12,
min_columns: 6,
min_rows: this._config?.entities?.length || 1,
min_rows: 2,
};
}

Expand Down Expand Up @@ -244,7 +244,8 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
})}`;

const columns = this._config.grid_options?.columns ?? 12;
const narrow = Number.isNaN(columns) || Number(columns) <= 12;
const narrow = typeof columns === "number" && columns <= 12;
const hasFixedHeight = typeof this._config.grid_options?.rows === "number";

return html`
<ha-card>
Expand Down Expand Up @@ -284,9 +285,7 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
.minYAxis=${this._config.min_y_axis}
.maxYAxis=${this._config.max_y_axis}
.fitYData=${this._config.fit_y_data || false}
.height=${this._config.grid_options?.rows
? "100%"
: undefined}
.height=${hasFixedHeight ? "100%" : undefined}
.narrow=${narrow}
></state-history-charts>
`}
Expand Down
4 changes: 3 additions & 1 deletion src/panels/lovelace/cards/hui-statistics-graph-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
return nothing;
}

const hasFixedHeight = typeof this._config.grid_options?.rows === "number";

return html`
<ha-card .header=${this._config.title}>
<div
Expand Down Expand Up @@ -290,7 +292,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
.daysToShow=${this._energyStart && this._energyEnd
? differenceInDays(this._energyEnd, this._energyStart)
: this._config.days_to_show || DEFAULT_DAYS_TO_SHOW}
.height=${this._config.grid_options?.rows ? "100%" : undefined}
.height=${hasFixedHeight ? "100%" : undefined}
></statistics-chart>
</div>
</ha-card>
Expand Down

0 comments on commit 67b970f

Please sign in to comment.