Compare commits

..
3 Commits
Author SHA1 Message Date
Paul Bottein 9338b91f18 Show the integration type in the entity type list (#55958) 2026-11-19 10:00:51 +00:00
Jan Bouwhuis b41693b8d2 Move dragged network graph nodes without layout animation (#55993)
* Move dragged network graph nodes without layout animation

* Keep the position of a node dragged without layout animation on a new layout run
2026-11-19 09:55:22 +00:00
Chanelle 407cf9e6a4 Give the onboarding welcome cards a button role (#55999) 2026-11-19 09:45:16 +00:00
6 changed files with 1500 additions and 1012 deletions

No files matched your search

+57
View File
@@ -95,6 +95,10 @@ const SELECTED_NODE_FIT_MARGIN = 72;
const FOLLOW_ROAM = "follow-selected-node";
type Displayable = ReturnType<
ReturnType<EChartsType["getZr"]>["storage"]["getDisplayList"]
>[number];
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/consistent-type-imports
let GraphChart: typeof import("echarts/lib/chart/graph/install");
@@ -152,6 +156,8 @@ export class HaNetworkGraph extends LitElement {
private _dragMoved = false;
private _dragTarget?: Displayable;
private _followSelectedNode = false;
private _followedChart?: EChartsType;
@@ -565,6 +571,7 @@ export class HaNetworkGraph extends LitElement {
private _handleChartSetup() {
const chart = this._baseChart?.chart;
chart?.on("mousedown", this._handleNodeMouseDown);
chart?.getZr().on("dragstart", this._handleDragStart);
chart?.getZr().on("drag", this._handleDrag);
chart?.getZr().on("dragend", this._handleDragEnd);
for (const event of LEGEND_SELECT_EVENTS) {
@@ -608,6 +615,54 @@ export class HaNetworkGraph extends LitElement {
this._dragMoved = false;
};
// The dragged element gets the drag before the ECharts handler of its node
private _handleDragStart = (ev: { target?: Displayable }) => {
this._dragTarget?.off("drag", this._handleNodeDrag);
this._dragTarget = ev.target;
this._dragTarget?.on("drag", this._handleNodeDrag);
};
// Without layout animation, the ECharts handler runs the whole force layout
// on every move, which puts the node back before it reads its position. So
// the node moves here, and the other nodes stay where they are.
private _handleNodeDrag = (ev: { cancelBubble?: boolean }) => {
const chart = this._baseChart?.chart;
const series = this._getGraphSeries(chart);
const node =
this._dragNode === undefined
? undefined
: series?.getGraph().getNodeById(this._dragNode);
if (
!chart ||
!node ||
!series.forceLayout ||
series.get(["force", "layoutAnimation"])
) {
return;
}
ev.cancelBubble = true;
const data = series.getData();
const el = data.getItemGraphicEl(node.dataIndex);
data.setItemLayout(node.dataIndex, [el.x, el.y]);
// A new layout run starts from here, e.g. after a legend change
if (series.preservedPoints) {
series.preservedPoints[node.id] = [el.x, el.y];
}
series.forceLayout.setFixed(node.dataIndex);
for (const edge of node.edges) {
const source: number[] | undefined = edge.node1.getLayout();
const target: number[] | undefined = edge.node2.getLayout();
// The nodes of hidden legend categories have no layout
if (source && target) {
edge.setLayout([[...source], [...target]]);
}
}
// @ts-ignore private method but no other way to draw the new layout
chart.getViewOfSeriesModel(series).updateLayout(series);
// The handlers of the chart miss the drag now
chart.getZr().handler.trigger("drag", ev);
};
private _handleDrag = () => {
this._dragMoved = true;
};
@@ -617,6 +672,8 @@ export class HaNetworkGraph extends LitElement {
const moved = this._dragMoved;
this._dragNode = undefined;
this._dragMoved = false;
this._dragTarget?.off("drag", this._handleNodeDrag);
this._dragTarget = undefined;
// A click also ends a drag, which releases a pinned node in ECharts
if (!id || (!moved && !this._pinnedNodes.includes(id))) {
return;
@@ -1,6 +1,7 @@
import type { TemplateResult } from "lit";
import { LitElement, css, html } from "lit";
import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import { consume } from "../common/decorators/consume";
import "../components/ha-card";
import "../components/ha-ripple";
@@ -23,6 +24,7 @@ class OnboardingWelcomeLink extends LitElement {
protected render(): TemplateResult {
return html`
<ha-card
role=${ifDefined(this.noninteractive ? undefined : "button")}
.tabIndex=${this.noninteractive ? "-1" : "0"}
@keydown=${this._handleKeyDown}
>
@@ -35,6 +37,7 @@ class OnboardingWelcomeLink extends LitElement {
private _handleKeyDown(ev: KeyboardEvent): void {
if (ev.key === "Enter" || ev.key === " ") {
ev.preventDefault();
(ev.target as HTMLElement).click();
}
}
@@ -221,9 +221,7 @@ const computeDeviceClassOptions = (
const groups: string[][] = OVERRIDE_DEVICE_CLASSES[domain];
for (const group of groups) {
if (originalDeviceClass && group.includes(originalDeviceClass)) {
related.push(
...group.filter((deviceClass) => deviceClass !== originalDeviceClass)
);
related.push(...group);
} else {
others.push(...group);
}
@@ -345,10 +343,7 @@ export class EntityRegistrySettingsEditor extends LitElement {
this._name = this.entry.name || this._originalName;
this._isMainEntity = !!this._device && !this._entryName;
this._icon = this.entry.icon || "";
this._deviceClass =
this.entry.device_class === this._originalDeviceClass
? null
: (this.entry.device_class ?? null);
this._deviceClass = this.entry.device_class ?? null;
this._origEntityId = this.entry.entity_id;
this._areaId = this.entry.area_id;
this._mainEntityWithOwnArea = this._isMainEntity && !!this.entry.area_id;
@@ -81,24 +81,6 @@ function processData(
return { positive, negative };
}
type LineData = NonNullable<LineSeriesOption["data"]>;
// A series that stays at 0 would draw its line over the x axis, so break the
// line there and keep only the zeros next to a non-zero value.
const hideZeroRuns = (data: LineData): LineData => {
const values = data.map(
(point) =>
(typeof point === "object" && "value" in point!
? point.value
: point) as [number, number]
);
return data.map((point, i) =>
values[i][1] === 0 && !values[i - 1]?.[1] && !values[i + 1]?.[1]
? [values[i][0], null]
: point
);
};
const sourceSeriesId = (type: PowerSourceType, statRate: string) =>
`${type}-${statRate}`;
@@ -516,9 +498,6 @@ export function generatePowerSourcesGraphData(
usageData.push([(stat.start + stat.end) / 2, Math.max(0, stat.mean!)]);
}
}
for (const series of chartData) {
series.data = hideZeroRuns(series.data!);
}
chartData.push({
...commonSeriesOptions,
id: "usage",
File diff suppressed because it is too large. Load diff
@@ -474,30 +474,6 @@ describe("generatePowerSourcesGraphData with separate sources", () => {
});
});
describe("generatePowerSourcesGraphData with idle sources", () => {
it("breaks the line where a source stays at 0, keeping the slope to 0", () => {
const result = generatePowerSourcesGraphData({
localize: mockLocalize,
formatPower: (w: number) => `${w} W`,
states: {} as HassEntities,
computedStyles,
energyData: buildHomeEnergyData([solarSource], {
[RATE_IDS.solar]: hourlyStats([0, 0, 0, 2, 0, 0]),
}),
start: new Date(FIXED_EPOCH_MS),
end: new Date(FIXED_EPOCH_MS + dayMs),
now: FIXED_EPOCH_MS + dayMs + 60 * 60 * 1000,
});
const solar = result.chartData.find((series) => series.id === "solar")!;
expect(
(solar.data as ({ value: number[] } | number[])[]).map(
(p) => ("value" in p ? p.value : p)[1]
)
).toEqual([null, null, 0, 2, 0, null]);
});
});
describe("getPowerLegendValues with a home meter", () => {
const format = (w: number) => `${w} W`;
const power = (id: string, value: string) =>