mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 07:16:39 +00:00
Add manual limit selection to graph header/footer (#9126)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
9f032a61a9
commit
d308c5d9b9
@ -55,6 +55,7 @@ class HuiSensorCard extends HuiEntityCard {
|
|||||||
entity: config.entity,
|
entity: config.entity,
|
||||||
detail: detail || 1,
|
detail: detail || 1,
|
||||||
hours_to_show: hours_to_show || 24,
|
hours_to_show: hours_to_show || 24,
|
||||||
|
limits: config.limits!,
|
||||||
};
|
};
|
||||||
|
|
||||||
entityCardConfig.footer = footerConfig;
|
entityCardConfig.footer = footerConfig;
|
||||||
|
@ -286,6 +286,10 @@ export interface SensorCardConfig extends LovelaceCardConfig {
|
|||||||
detail?: number;
|
detail?: number;
|
||||||
theme?: string;
|
theme?: string;
|
||||||
hours_to_show?: number;
|
hours_to_show?: number;
|
||||||
|
limits?: {
|
||||||
|
min?: number;
|
||||||
|
max?: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ShoppingListCardConfig extends LovelaceCardConfig {
|
export interface ShoppingListCardConfig extends LovelaceCardConfig {
|
||||||
|
@ -57,15 +57,22 @@ export const coordinates = (
|
|||||||
history: any,
|
history: any,
|
||||||
hours: number,
|
hours: number,
|
||||||
width: number,
|
width: number,
|
||||||
detail: number
|
detail: number,
|
||||||
|
limits?: { min?: number; max?: number }
|
||||||
): number[][] | undefined => {
|
): number[][] | undefined => {
|
||||||
history.forEach((item) => {
|
history.forEach((item) => {
|
||||||
item.state = Number(item.state);
|
item.state = Number(item.state);
|
||||||
});
|
});
|
||||||
history = history.filter((item) => !Number.isNaN(item.state));
|
history = history.filter((item) => !Number.isNaN(item.state));
|
||||||
|
|
||||||
const min = Math.min(...history.map((item) => item.state));
|
const min =
|
||||||
const max = Math.max(...history.map((item) => item.state));
|
limits?.min !== undefined
|
||||||
|
? limits.min
|
||||||
|
: Math.min(...history.map((item) => item.state));
|
||||||
|
const max =
|
||||||
|
limits?.max !== undefined
|
||||||
|
? limits.max
|
||||||
|
: Math.max(...history.map((item) => item.state));
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
|
|
||||||
const reduce = (res, item, point) => {
|
const reduce = (res, item, point) => {
|
||||||
|
@ -190,12 +190,21 @@ export class HuiGraphHeaderFooter
|
|||||||
this._stateHistory!.push(...stateHistory[0]);
|
this._stateHistory!.push(...stateHistory[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const limits =
|
||||||
|
this._config!.limits === undefined &&
|
||||||
|
this._stateHistory?.some(
|
||||||
|
(entity) => entity.attributes?.unit_of_measurement === "%"
|
||||||
|
)
|
||||||
|
? { min: 0, max: 100 }
|
||||||
|
: this._config!.limits;
|
||||||
|
|
||||||
this._coordinates =
|
this._coordinates =
|
||||||
coordinates(
|
coordinates(
|
||||||
this._stateHistory,
|
this._stateHistory,
|
||||||
this._config!.hours_to_show!,
|
this._config!.hours_to_show!,
|
||||||
500,
|
500,
|
||||||
this._config!.detail!
|
this._config!.detail!,
|
||||||
|
limits
|
||||||
) || [];
|
) || [];
|
||||||
|
|
||||||
this._date = endTime;
|
this._date = endTime;
|
||||||
|
@ -15,6 +15,10 @@ export interface GraphHeaderFooterConfig extends LovelaceHeaderFooterConfig {
|
|||||||
entity: string;
|
entity: string;
|
||||||
detail?: number;
|
detail?: number;
|
||||||
hours_to_show?: number;
|
hours_to_show?: number;
|
||||||
|
limits?: {
|
||||||
|
min?: number;
|
||||||
|
max?: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PictureHeaderFooterConfig extends LovelaceHeaderFooterConfig {
|
export interface PictureHeaderFooterConfig extends LovelaceHeaderFooterConfig {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user