mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 02:38:53 +00:00
Add detail option to trend card feature (#27993)
This commit is contained in:
@@ -124,16 +124,24 @@ class HuiHistoryChartCardFeature
|
||||
}
|
||||
|
||||
const hourToShow = this._config.hours_to_show ?? DEFAULT_HOURS_TO_SHOW;
|
||||
const detail = this._config.detail !== false; // default to true (high detail)
|
||||
|
||||
return subscribeHistoryStatesTimeWindow(
|
||||
this.hass!,
|
||||
(historyStates) => {
|
||||
// sample to 1 point per hour for low detail or 1 point per 5 pixels for high detail
|
||||
const maxDetails = detail
|
||||
? Math.max(10, this.clientWidth / 5, hourToShow)
|
||||
: Math.max(10, hourToShow);
|
||||
const useMean = !detail;
|
||||
const { points, yAxisOrigin } =
|
||||
coordinatesMinimalResponseCompressedState(
|
||||
historyStates[this.context!.entity_id!],
|
||||
this.clientWidth,
|
||||
this.clientHeight,
|
||||
this.clientWidth / 5 // sample to 1 point per 5 pixels
|
||||
maxDetails,
|
||||
undefined,
|
||||
useMean
|
||||
);
|
||||
this._coordinates = points;
|
||||
this._yAxisOrigin = yAxisOrigin;
|
||||
|
||||
@@ -199,6 +199,7 @@ export interface UpdateActionsCardFeatureConfig {
|
||||
export interface TrendGraphCardFeatureConfig {
|
||||
type: "trend-graph";
|
||||
hours_to_show?: number;
|
||||
detail?: boolean;
|
||||
}
|
||||
|
||||
export const AREA_CONTROLS = [
|
||||
|
||||
@@ -20,6 +20,10 @@ const SCHEMA = [
|
||||
default: DEFAULT_HOURS_TO_SHOW,
|
||||
selector: { number: { min: 1, mode: "box" } },
|
||||
},
|
||||
{
|
||||
name: "detail",
|
||||
selector: { boolean: {} },
|
||||
},
|
||||
] as const satisfies HaFormSchema[];
|
||||
|
||||
@customElement("hui-trend-graph-card-feature-editor")
|
||||
@@ -48,6 +52,10 @@ export class HuiTrendGraphCardFeatureEditor
|
||||
data.hours_to_show = DEFAULT_HOURS_TO_SHOW;
|
||||
}
|
||||
|
||||
if (this._config.detail === undefined) {
|
||||
data.detail = true;
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-form
|
||||
.hass=${this.hass}
|
||||
@@ -69,6 +77,10 @@ export class HuiTrendGraphCardFeatureEditor
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
||||
);
|
||||
case "detail":
|
||||
return this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.features.types.trend-graph.detail"
|
||||
);
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -8434,7 +8434,8 @@
|
||||
"max": "Maximum value"
|
||||
},
|
||||
"trend-graph": {
|
||||
"label": "Trend graph"
|
||||
"label": "Trend graph",
|
||||
"detail": "Show more detail"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user