Skip to content

Commit 259f442

Browse files
authored
Add detail option to trend card feature (home-assistant#27993)
1 parent 1ac3cf1 commit 259f442

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

src/panels/lovelace/card-features/hui-trend-graph-card-feature.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,24 @@ class HuiHistoryChartCardFeature
124124
}
125125

126126
const hourToShow = this._config.hours_to_show ?? DEFAULT_HOURS_TO_SHOW;
127+
const detail = this._config.detail !== false; // default to true (high detail)
127128

128129
return subscribeHistoryStatesTimeWindow(
129130
this.hass!,
130131
(historyStates) => {
132+
// sample to 1 point per hour for low detail or 1 point per 5 pixels for high detail
133+
const maxDetails = detail
134+
? Math.max(10, this.clientWidth / 5, hourToShow)
135+
: Math.max(10, hourToShow);
136+
const useMean = !detail;
131137
const { points, yAxisOrigin } =
132138
coordinatesMinimalResponseCompressedState(
133139
historyStates[this.context!.entity_id!],
134140
this.clientWidth,
135141
this.clientHeight,
136-
this.clientWidth / 5 // sample to 1 point per 5 pixels
142+
maxDetails,
143+
undefined,
144+
useMean
137145
);
138146
this._coordinates = points;
139147
this._yAxisOrigin = yAxisOrigin;

src/panels/lovelace/card-features/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export interface UpdateActionsCardFeatureConfig {
199199
export interface TrendGraphCardFeatureConfig {
200200
type: "trend-graph";
201201
hours_to_show?: number;
202+
detail?: boolean;
202203
}
203204

204205
export const AREA_CONTROLS = [

src/panels/lovelace/editor/config-elements/hui-trend-graph-card-feature-editor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const SCHEMA = [
2020
default: DEFAULT_HOURS_TO_SHOW,
2121
selector: { number: { min: 1, mode: "box" } },
2222
},
23+
{
24+
name: "detail",
25+
selector: { boolean: {} },
26+
},
2327
] as const satisfies HaFormSchema[];
2428

2529
@customElement("hui-trend-graph-card-feature-editor")
@@ -48,6 +52,10 @@ export class HuiTrendGraphCardFeatureEditor
4852
data.hours_to_show = DEFAULT_HOURS_TO_SHOW;
4953
}
5054

55+
if (this._config.detail === undefined) {
56+
data.detail = true;
57+
}
58+
5159
return html`
5260
<ha-form
5361
.hass=${this.hass}
@@ -69,6 +77,10 @@ export class HuiTrendGraphCardFeatureEditor
6977
return this.hass!.localize(
7078
`ui.panel.lovelace.editor.card.generic.${schema.name}`
7179
);
80+
case "detail":
81+
return this.hass!.localize(
82+
"ui.panel.lovelace.editor.features.types.trend-graph.detail"
83+
);
7284
default:
7385
return "";
7486
}

src/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8434,7 +8434,8 @@
84348434
"max": "Maximum value"
84358435
},
84368436
"trend-graph": {
8437-
"label": "Trend graph"
8437+
"label": "Trend graph",
8438+
"detail": "Show more detail"
84388439
}
84398440
}
84408441
},

0 commit comments

Comments
 (0)