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
3 changed files with 62 additions and 7 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;