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 hourToShow = this._config.hours_to_show ?? DEFAULT_HOURS_TO_SHOW;
|
||||||
|
const detail = this._config.detail !== false; // default to true (high detail)
|
||||||
|
|
||||||
return subscribeHistoryStatesTimeWindow(
|
return subscribeHistoryStatesTimeWindow(
|
||||||
this.hass!,
|
this.hass!,
|
||||||
(historyStates) => {
|
(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 } =
|
const { points, yAxisOrigin } =
|
||||||
coordinatesMinimalResponseCompressedState(
|
coordinatesMinimalResponseCompressedState(
|
||||||
historyStates[this.context!.entity_id!],
|
historyStates[this.context!.entity_id!],
|
||||||
this.clientWidth,
|
this.clientWidth,
|
||||||
this.clientHeight,
|
this.clientHeight,
|
||||||
this.clientWidth / 5 // sample to 1 point per 5 pixels
|
maxDetails,
|
||||||
|
undefined,
|
||||||
|
useMean
|
||||||
);
|
);
|
||||||
this._coordinates = points;
|
this._coordinates = points;
|
||||||
this._yAxisOrigin = yAxisOrigin;
|
this._yAxisOrigin = yAxisOrigin;
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ export interface UpdateActionsCardFeatureConfig {
|
|||||||
export interface TrendGraphCardFeatureConfig {
|
export interface TrendGraphCardFeatureConfig {
|
||||||
type: "trend-graph";
|
type: "trend-graph";
|
||||||
hours_to_show?: number;
|
hours_to_show?: number;
|
||||||
|
detail?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AREA_CONTROLS = [
|
export const AREA_CONTROLS = [
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ const SCHEMA = [
|
|||||||
default: DEFAULT_HOURS_TO_SHOW,
|
default: DEFAULT_HOURS_TO_SHOW,
|
||||||
selector: { number: { min: 1, mode: "box" } },
|
selector: { number: { min: 1, mode: "box" } },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "detail",
|
||||||
|
selector: { boolean: {} },
|
||||||
|
},
|
||||||
] as const satisfies HaFormSchema[];
|
] as const satisfies HaFormSchema[];
|
||||||
|
|
||||||
@customElement("hui-trend-graph-card-feature-editor")
|
@customElement("hui-trend-graph-card-feature-editor")
|
||||||
@@ -48,6 +52,10 @@ export class HuiTrendGraphCardFeatureEditor
|
|||||||
data.hours_to_show = DEFAULT_HOURS_TO_SHOW;
|
data.hours_to_show = DEFAULT_HOURS_TO_SHOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._config.detail === undefined) {
|
||||||
|
data.detail = true;
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-form
|
<ha-form
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@@ -69,6 +77,10 @@ export class HuiTrendGraphCardFeatureEditor
|
|||||||
return this.hass!.localize(
|
return this.hass!.localize(
|
||||||
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
||||||
);
|
);
|
||||||
|
case "detail":
|
||||||
|
return this.hass!.localize(
|
||||||
|
"ui.panel.lovelace.editor.features.types.trend-graph.detail"
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8434,7 +8434,8 @@
|
|||||||
"max": "Maximum value"
|
"max": "Maximum value"
|
||||||
},
|
},
|
||||||
"trend-graph": {
|
"trend-graph": {
|
||||||
"label": "Trend graph"
|
"label": "Trend graph",
|
||||||
|
"detail": "Show more detail"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user