mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-14 04:46:34 +00:00
Fix more-info chart rendering (#23619)
* Fix more-info chart rendering * lint fix * remove animation-container & _chartHeight * don't change height on resize * handle default height in ha-chart-base * fix chart height in energy panel * lint * lint
This commit is contained in:
parent
abe8899f9b
commit
d3e832c09b
@ -4,6 +4,7 @@ import type {
|
|||||||
ChartData,
|
ChartData,
|
||||||
ChartOptions,
|
ChartOptions,
|
||||||
TooltipModel,
|
TooltipModel,
|
||||||
|
UpdateMode,
|
||||||
} from "chart.js";
|
} from "chart.js";
|
||||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||||
import { css, html, nothing, LitElement } from "lit";
|
import { css, html, nothing, LitElement } from "lit";
|
||||||
@ -20,12 +21,6 @@ import "../ha-icon-button";
|
|||||||
|
|
||||||
export const MIN_TIME_BETWEEN_UPDATES = 60 * 5 * 1000;
|
export const MIN_TIME_BETWEEN_UPDATES = 60 * 5 * 1000;
|
||||||
|
|
||||||
export interface ChartResizeOptions {
|
|
||||||
aspectRatio?: number;
|
|
||||||
height?: number;
|
|
||||||
width?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Tooltip
|
interface Tooltip
|
||||||
extends Omit<TooltipModel<any>, "tooltipPosition" | "hasValue" | "getProps"> {
|
extends Omit<TooltipModel<any>, "tooltipPosition" | "hasValue" | "getProps"> {
|
||||||
top: string;
|
top: string;
|
||||||
@ -61,8 +56,6 @@ export class HaChartBase extends LitElement {
|
|||||||
@property({ attribute: "external-hidden", type: Boolean })
|
@property({ attribute: "external-hidden", type: Boolean })
|
||||||
public externalHidden = false;
|
public externalHidden = false;
|
||||||
|
|
||||||
@state() private _chartHeight?: number;
|
|
||||||
|
|
||||||
@state() private _legendHeight?: number;
|
@state() private _legendHeight?: number;
|
||||||
|
|
||||||
@state() private _tooltip?: Tooltip;
|
@state() private _tooltip?: Tooltip;
|
||||||
@ -96,36 +89,10 @@ export class HaChartBase extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateChart = (
|
public updateChart = (mode?: UpdateMode): void => {
|
||||||
mode:
|
|
||||||
| "resize"
|
|
||||||
| "reset"
|
|
||||||
| "none"
|
|
||||||
| "hide"
|
|
||||||
| "show"
|
|
||||||
| "default"
|
|
||||||
| "active"
|
|
||||||
| undefined
|
|
||||||
): void => {
|
|
||||||
this.chart?.update(mode);
|
this.chart?.update(mode);
|
||||||
};
|
};
|
||||||
|
|
||||||
public resize = (options?: ChartResizeOptions): void => {
|
|
||||||
if (options?.aspectRatio && !options.height) {
|
|
||||||
options.height = Math.round(
|
|
||||||
(options.width ?? this.clientWidth) / options.aspectRatio
|
|
||||||
);
|
|
||||||
} else if (options?.aspectRatio && !options.width) {
|
|
||||||
options.width = Math.round(
|
|
||||||
(options.height ?? this.clientHeight) * options.aspectRatio
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.chart?.resize(
|
|
||||||
options?.width ?? this.clientWidth,
|
|
||||||
options?.height ?? this.clientHeight
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
protected firstUpdated() {
|
protected firstUpdated() {
|
||||||
this._setupChart();
|
this._setupChart();
|
||||||
this.data.datasets.forEach((dataset, index) => {
|
this.data.datasets.forEach((dataset, index) => {
|
||||||
@ -266,19 +233,10 @@ export class HaChartBase extends LitElement {
|
|||||||
</ul>
|
</ul>
|
||||||
</div>`
|
</div>`
|
||||||
: ""}
|
: ""}
|
||||||
<div
|
|
||||||
class="animation-container"
|
|
||||||
style=${styleMap({
|
|
||||||
height: `${this.height || this._chartHeight || 0}px`,
|
|
||||||
overflow: this._chartHeight ? "initial" : "hidden",
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
class="chart-container"
|
class="chart-container"
|
||||||
style=${styleMap({
|
style=${styleMap({
|
||||||
height: `${
|
height: `${this.height ?? this._getDefaultHeight()}px`,
|
||||||
this.height ?? this._chartHeight ?? this.clientWidth / 2
|
|
||||||
}px`,
|
|
||||||
"padding-left": `${this._paddingYAxisInternal}px`,
|
"padding-left": `${this._paddingYAxisInternal}px`,
|
||||||
"padding-right": 0,
|
"padding-right": 0,
|
||||||
"padding-inline-start": `${this._paddingYAxisInternal}px`,
|
"padding-inline-start": `${this._paddingYAxisInternal}px`,
|
||||||
@ -298,9 +256,7 @@ export class HaChartBase extends LitElement {
|
|||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
${isMac
|
${isMac
|
||||||
? this.hass.localize(
|
? this.hass.localize("ui.components.history_charts.zoom_hint_mac")
|
||||||
"ui.components.history_charts.zoom_hint_mac"
|
|
||||||
)
|
|
||||||
: this.hass.localize("ui.components.history_charts.zoom_hint")}
|
: this.hass.localize("ui.components.history_charts.zoom_hint")}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -357,7 +313,6 @@ export class HaChartBase extends LitElement {
|
|||||||
</div>`
|
</div>`
|
||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,11 +426,11 @@ export class HaChartBase extends LitElement {
|
|||||||
...(this.plugins || []),
|
...(this.plugins || []),
|
||||||
{
|
{
|
||||||
id: "resizeHook",
|
id: "resizeHook",
|
||||||
resize: (chart) => {
|
resize: (chart: Chart) => {
|
||||||
const change = chart.height - (this._chartHeight ?? 0);
|
if (!this.height) {
|
||||||
if (!this._chartHeight || change > 12 || change < -12) {
|
// lock the height
|
||||||
// hysteresis to prevent infinite render loops
|
// this removes empty space below the chart
|
||||||
this._chartHeight = chart.height;
|
this.height = chart.height;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
legend: {
|
legend: {
|
||||||
@ -486,6 +441,10 @@ export class HaChartBase extends LitElement {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _getDefaultHeight() {
|
||||||
|
return this.clientWidth / 2;
|
||||||
|
}
|
||||||
|
|
||||||
private _handleChartScroll(ev: MouseEvent) {
|
private _handleChartScroll(ev: MouseEvent) {
|
||||||
const modifier = isMac ? "metaKey" : "ctrlKey";
|
const modifier = isMac ? "metaKey" : "ctrlKey";
|
||||||
this._tooltip = undefined;
|
this._tooltip = undefined;
|
||||||
@ -573,11 +532,6 @@ export class HaChartBase extends LitElement {
|
|||||||
display: block;
|
display: block;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
.animation-container {
|
|
||||||
overflow: hidden;
|
|
||||||
height: 0;
|
|
||||||
transition: height 300ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
||||||
}
|
|
||||||
.chart-container {
|
.chart-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import type { ChartData, ChartDataset, ChartOptions } from "chart.js";
|
import type { ChartData, ChartDataset, ChartOptions } from "chart.js";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { html, LitElement } from "lit";
|
import { html, LitElement } from "lit";
|
||||||
import { property, query, state } from "lit/decorators";
|
import { property, state } from "lit/decorators";
|
||||||
import { getGraphColorByIndex } from "../../common/color/colors";
|
import { getGraphColorByIndex } from "../../common/color/colors";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { computeRTL } from "../../common/util/compute_rtl";
|
import { computeRTL } from "../../common/util/compute_rtl";
|
||||||
@ -12,7 +12,6 @@ import {
|
|||||||
} from "../../common/number/format_number";
|
} from "../../common/number/format_number";
|
||||||
import type { LineChartEntity, LineChartState } from "../../data/history";
|
import type { LineChartEntity, LineChartState } from "../../data/history";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import type { ChartResizeOptions, HaChartBase } from "./ha-chart-base";
|
|
||||||
import { MIN_TIME_BETWEEN_UPDATES } from "./ha-chart-base";
|
import { MIN_TIME_BETWEEN_UPDATES } from "./ha-chart-base";
|
||||||
import { clickIsTouch } from "./click_is_touch";
|
import { clickIsTouch } from "./click_is_touch";
|
||||||
|
|
||||||
@ -67,12 +66,6 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
|
|
||||||
private _chartTime: Date = new Date();
|
private _chartTime: Date = new Date();
|
||||||
|
|
||||||
@query("ha-chart-base") private _chart?: HaChartBase;
|
|
||||||
|
|
||||||
public resize = (options?: ChartResizeOptions): void => {
|
|
||||||
this._chart?.resize(options);
|
|
||||||
};
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<ha-chart-base
|
<ha-chart-base
|
||||||
|
@ -2,7 +2,7 @@ import type { ChartData, ChartDataset, ChartOptions } from "chart.js";
|
|||||||
import { getRelativePosition } from "chart.js/helpers";
|
import { getRelativePosition } from "chart.js/helpers";
|
||||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||||
import { css, html, LitElement } from "lit";
|
import { css, html, LitElement } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { formatDateTimeWithSeconds } from "../../common/datetime/format_date_time";
|
import { formatDateTimeWithSeconds } from "../../common/datetime/format_date_time";
|
||||||
import millisecondsToDuration from "../../common/datetime/milliseconds_to_duration";
|
import millisecondsToDuration from "../../common/datetime/milliseconds_to_duration";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
@ -10,7 +10,6 @@ import { numberFormatToLocale } from "../../common/number/format_number";
|
|||||||
import { computeRTL } from "../../common/util/compute_rtl";
|
import { computeRTL } from "../../common/util/compute_rtl";
|
||||||
import type { TimelineEntity } from "../../data/history";
|
import type { TimelineEntity } from "../../data/history";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import type { ChartResizeOptions, HaChartBase } from "./ha-chart-base";
|
|
||||||
import { MIN_TIME_BETWEEN_UPDATES } from "./ha-chart-base";
|
import { MIN_TIME_BETWEEN_UPDATES } from "./ha-chart-base";
|
||||||
import type { TimeLineData } from "./timeline-chart/const";
|
import type { TimeLineData } from "./timeline-chart/const";
|
||||||
import { computeTimelineColor } from "./timeline-chart/timeline-color";
|
import { computeTimelineColor } from "./timeline-chart/timeline-color";
|
||||||
@ -53,12 +52,6 @@ export class StateHistoryChartTimeline extends LitElement {
|
|||||||
|
|
||||||
private _chartTime: Date = new Date();
|
private _chartTime: Date = new Date();
|
||||||
|
|
||||||
@query("ha-chart-base") private _chart?: HaChartBase;
|
|
||||||
|
|
||||||
public resize = (options?: ChartResizeOptions): void => {
|
|
||||||
this._chart?.resize(options);
|
|
||||||
};
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<ha-chart-base
|
<ha-chart-base
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||||
import { css, html, LitElement } from "lit";
|
import { css, html, LitElement } from "lit";
|
||||||
import {
|
import { customElement, eventOptions, property, state } from "lit/decorators";
|
||||||
customElement,
|
|
||||||
eventOptions,
|
|
||||||
property,
|
|
||||||
queryAll,
|
|
||||||
state,
|
|
||||||
} from "lit/decorators";
|
|
||||||
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
|
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
|
||||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||||
import { restoreScroll } from "../../common/decorators/restore-scroll";
|
import { restoreScroll } from "../../common/decorators/restore-scroll";
|
||||||
@ -19,9 +13,6 @@ import { loadVirtualizer } from "../../resources/virtualizer";
|
|||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "./state-history-chart-line";
|
import "./state-history-chart-line";
|
||||||
import "./state-history-chart-timeline";
|
import "./state-history-chart-timeline";
|
||||||
import type { StateHistoryChartLine } from "./state-history-chart-line";
|
|
||||||
import type { StateHistoryChartTimeline } from "./state-history-chart-timeline";
|
|
||||||
import type { ChartResizeOptions } from "./ha-chart-base";
|
|
||||||
|
|
||||||
const CANVAS_TIMELINE_ROWS_CHUNK = 10; // Split up the canvases to avoid hitting the render limit
|
const CANVAS_TIMELINE_ROWS_CHUNK = 10; // Split up the canvases to avoid hitting the render limit
|
||||||
|
|
||||||
@ -91,16 +82,6 @@ export class StateHistoryCharts extends LitElement {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@restoreScroll(".container") private _savedScrollPos?: number;
|
@restoreScroll(".container") private _savedScrollPos?: number;
|
||||||
|
|
||||||
@queryAll("state-history-chart-line")
|
|
||||||
private _charts?: StateHistoryChartLine[];
|
|
||||||
|
|
||||||
public resize = (options?: ChartResizeOptions): void => {
|
|
||||||
this._charts?.forEach(
|
|
||||||
(chart: StateHistoryChartLine | StateHistoryChartTimeline) =>
|
|
||||||
chart.resize(options)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!isComponentLoaded(this.hass, "history")) {
|
if (!isComponentLoaded(this.hass, "history")) {
|
||||||
return html`<div class="info">
|
return html`<div class="info">
|
||||||
|
@ -6,7 +6,7 @@ import type {
|
|||||||
} from "chart.js";
|
} from "chart.js";
|
||||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||||
import { css, html, LitElement } from "lit";
|
import { css, html, LitElement } from "lit";
|
||||||
import { customElement, property, state, query } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { getGraphColorByIndex } from "../../common/color/colors";
|
import { getGraphColorByIndex } from "../../common/color/colors";
|
||||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||||
@ -30,11 +30,7 @@ import {
|
|||||||
} from "../../data/recorder";
|
} from "../../data/recorder";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "./ha-chart-base";
|
import "./ha-chart-base";
|
||||||
import type {
|
import type { ChartDatasetExtra } from "./ha-chart-base";
|
||||||
ChartResizeOptions,
|
|
||||||
ChartDatasetExtra,
|
|
||||||
HaChartBase,
|
|
||||||
} from "./ha-chart-base";
|
|
||||||
import { clickIsTouch } from "./click_is_touch";
|
import { clickIsTouch } from "./click_is_touch";
|
||||||
|
|
||||||
export const supportedStatTypeMap: Record<StatisticType, StatisticType> = {
|
export const supportedStatTypeMap: Record<StatisticType, StatisticType> = {
|
||||||
@ -98,14 +94,8 @@ export class StatisticsChart extends LitElement {
|
|||||||
|
|
||||||
@state() private _hiddenStats = new Set<string>();
|
@state() private _hiddenStats = new Set<string>();
|
||||||
|
|
||||||
@query("ha-chart-base") private _chart?: HaChartBase;
|
|
||||||
|
|
||||||
private _computedStyle?: CSSStyleDeclaration;
|
private _computedStyle?: CSSStyleDeclaration;
|
||||||
|
|
||||||
public resize = (options?: ChartResizeOptions): void => {
|
|
||||||
this._chart?.resize(options);
|
|
||||||
};
|
|
||||||
|
|
||||||
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
||||||
return changedProps.size > 1 || !changedProps.has("hass");
|
return changedProps.size > 1 || !changedProps.has("hass");
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import {
|
|||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { LitElement, css, html, nothing } from "lit";
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { cache } from "lit/directives/cache";
|
import { cache } from "lit/directives/cache";
|
||||||
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
|
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
@ -47,9 +47,7 @@ import {
|
|||||||
} from "./const";
|
} from "./const";
|
||||||
import "./controls/more-info-default";
|
import "./controls/more-info-default";
|
||||||
import "./ha-more-info-history-and-logbook";
|
import "./ha-more-info-history-and-logbook";
|
||||||
import type { MoreInfoHistoryAndLogbook } from "./ha-more-info-history-and-logbook";
|
|
||||||
import "./ha-more-info-info";
|
import "./ha-more-info-info";
|
||||||
import type { MoreInfoInfo } from "./ha-more-info-info";
|
|
||||||
import "./ha-more-info-settings";
|
import "./ha-more-info-settings";
|
||||||
import "./more-info-content";
|
import "./more-info-content";
|
||||||
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
||||||
@ -99,9 +97,6 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
|
|
||||||
@state() private _infoEditMode = false;
|
@state() private _infoEditMode = false;
|
||||||
|
|
||||||
@query("ha-more-info-info, ha-more-info-history-and-logbook")
|
|
||||||
private _history?: MoreInfoInfo | MoreInfoHistoryAndLogbook;
|
|
||||||
|
|
||||||
@state() private _sensorNumericDeviceClasses?: string[] = [];
|
@state() private _sensorNumericDeviceClasses?: string[] = [];
|
||||||
|
|
||||||
public showDialog(params: MoreInfoDialogParams) {
|
public showDialog(params: MoreInfoDialogParams) {
|
||||||
@ -295,7 +290,6 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
<ha-dialog
|
<ha-dialog
|
||||||
open
|
open
|
||||||
@closed=${this.closeDialog}
|
@closed=${this.closeDialog}
|
||||||
@opened=${this._handleOpened}
|
|
||||||
.heading=${title}
|
.heading=${title}
|
||||||
hideActions
|
hideActions
|
||||||
flexContent
|
flexContent
|
||||||
@ -546,10 +540,6 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
this.large = !this.large;
|
this.large = !this.large;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleOpened() {
|
|
||||||
this._history?.resize({ aspectRatio: 2 });
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles() {
|
static get styles() {
|
||||||
return [
|
return [
|
||||||
haStyleDialog,
|
haStyleDialog,
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
import type { CSSResultGroup } from "lit";
|
import type { CSSResultGroup } from "lit";
|
||||||
import { css, html, LitElement } from "lit";
|
import { css, html, LitElement } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import type { ChartResizeOptions } from "../../components/chart/ha-chart-base";
|
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import {
|
import {
|
||||||
computeShowHistoryComponent,
|
computeShowHistoryComponent,
|
||||||
computeShowLogBookComponent,
|
computeShowLogBookComponent,
|
||||||
} from "./const";
|
} from "./const";
|
||||||
import "./ha-more-info-history";
|
import "./ha-more-info-history";
|
||||||
import type { MoreInfoHistory } from "./ha-more-info-history";
|
|
||||||
import "./ha-more-info-logbook";
|
import "./ha-more-info-logbook";
|
||||||
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
||||||
|
|
||||||
@ -18,9 +16,6 @@ export class MoreInfoHistoryAndLogbook extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public entityId!: string;
|
@property({ attribute: false }) public entityId!: string;
|
||||||
|
|
||||||
@query("ha-more-info-history")
|
|
||||||
private _history?: MoreInfoHistory;
|
|
||||||
|
|
||||||
@state() private _sensorNumericDeviceClasses?: string[] = [];
|
@state() private _sensorNumericDeviceClasses?: string[] = [];
|
||||||
|
|
||||||
private async _loadNumericDeviceClasses() {
|
private async _loadNumericDeviceClasses() {
|
||||||
@ -33,10 +28,6 @@ export class MoreInfoHistoryAndLogbook extends LitElement {
|
|||||||
this._loadNumericDeviceClasses();
|
this._loadNumericDeviceClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
public resize(options?: ChartResizeOptions) {
|
|
||||||
this._history?.resize(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${computeShowHistoryComponent(this.hass, this.entityId)
|
${computeShowHistoryComponent(this.hass, this.entityId)
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
import { startOfYesterday, subHours } from "date-fns";
|
import { startOfYesterday, subHours } from "date-fns";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { LitElement, css, html, nothing } from "lit";
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||||
import { computeDomain } from "../../common/entity/compute_domain";
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import { createSearchParam } from "../../common/url/search-params";
|
import { createSearchParam } from "../../common/url/search-params";
|
||||||
import type { ChartResizeOptions } from "../../components/chart/ha-chart-base";
|
|
||||||
import "../../components/chart/state-history-charts";
|
import "../../components/chart/state-history-charts";
|
||||||
import type { StateHistoryCharts } from "../../components/chart/state-history-charts";
|
|
||||||
import "../../components/chart/statistics-chart";
|
import "../../components/chart/statistics-chart";
|
||||||
import type { StatisticsChart } from "../../components/chart/statistics-chart";
|
|
||||||
import type { HistoryResult } from "../../data/history";
|
import type { HistoryResult } from "../../data/history";
|
||||||
import {
|
import {
|
||||||
computeHistory,
|
computeHistory,
|
||||||
@ -54,16 +51,6 @@ export class MoreInfoHistory extends LitElement {
|
|||||||
|
|
||||||
private _metadata?: Record<string, StatisticsMetaData>;
|
private _metadata?: Record<string, StatisticsMetaData>;
|
||||||
|
|
||||||
@query("statistics-chart, state-history-charts") private _chart?:
|
|
||||||
| StateHistoryCharts
|
|
||||||
| StatisticsChart;
|
|
||||||
|
|
||||||
public resize = (options?: ChartResizeOptions): void => {
|
|
||||||
if (this._chart) {
|
|
||||||
this._chart.resize(options);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this.entityId) {
|
if (!this.entityId) {
|
||||||
return nothing;
|
return nothing;
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { computeDomain } from "../../common/entity/compute_domain";
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import type { ChartResizeOptions } from "../../components/chart/ha-chart-base";
|
|
||||||
import type { ExtEntityRegistryEntry } from "../../data/entity_registry";
|
import type { ExtEntityRegistryEntry } from "../../data/entity_registry";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import {
|
import {
|
||||||
@ -14,7 +13,6 @@ import {
|
|||||||
DOMAINS_WITH_MORE_INFO,
|
DOMAINS_WITH_MORE_INFO,
|
||||||
} from "./const";
|
} from "./const";
|
||||||
import "./ha-more-info-history";
|
import "./ha-more-info-history";
|
||||||
import type { MoreInfoHistory } from "./ha-more-info-history";
|
|
||||||
import "./ha-more-info-logbook";
|
import "./ha-more-info-logbook";
|
||||||
import "./more-info-content";
|
import "./more-info-content";
|
||||||
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
||||||
@ -31,9 +29,6 @@ export class MoreInfoInfo extends LitElement {
|
|||||||
|
|
||||||
@state() private _sensorNumericDeviceClasses?: string[] = [];
|
@state() private _sensorNumericDeviceClasses?: string[] = [];
|
||||||
|
|
||||||
@query("ha-more-info-history")
|
|
||||||
private _history?: MoreInfoHistory;
|
|
||||||
|
|
||||||
private async _loadNumericDeviceClasses() {
|
private async _loadNumericDeviceClasses() {
|
||||||
const deviceClasses = await getSensorNumericDeviceClasses(this.hass);
|
const deviceClasses = await getSensorNumericDeviceClasses(this.hass);
|
||||||
this._sensorNumericDeviceClasses = deviceClasses.numeric_device_classes;
|
this._sensorNumericDeviceClasses = deviceClasses.numeric_device_classes;
|
||||||
@ -44,10 +39,6 @@ export class MoreInfoInfo extends LitElement {
|
|||||||
this._loadNumericDeviceClasses();
|
this._loadNumericDeviceClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
public resize(options?: ChartResizeOptions) {
|
|
||||||
this._history?.resize(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const entityId = this.entityId;
|
const entityId = this.entityId;
|
||||||
const stateObj = this.hass.states[entityId] as HassEntity | undefined;
|
const stateObj = this.hass.states[entityId] as HassEntity | undefined;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user