Follow moving nodes in network graph position, first render and tooltip hide

- getNodePosition reads the drawn symbol, so it follows a node that animates
- fire network-graph-rendered once after setup, as the first frame is drawn before the listener is added
- cancel the deferred tooltip hide on the next pointer move, so it does not hide a later tooltip

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
jbouwhandClaude Opus 5.5 committed 2026-12-01 11:58:13 +00:00
1 parent d00503bf31
commit 8a6fe8cee1
1 file changed
+31 -6
+31 -6
View File
@@ -188,6 +188,8 @@ export class HaNetworkGraph extends LitElement {
private _followedChart?: EChartsType;
private _cancelSettledHide?: () => void;
@query("ha-chart-base") private _baseChart?: HaChartBase;
constructor() {
@@ -649,6 +651,8 @@ export class HaNetworkGraph extends LitElement {
// last render
this.requestUpdate();
this._updateFollowing();
// The base chart drew the first frame before the listener was added
this._handleRendered();
}
private _handleLegendChange = (params: unknown) => {
@@ -866,10 +870,21 @@ export class HaNetworkGraph extends LitElement {
if (!chart || chart.isDisposed()) {
return undefined;
}
const position: number[] | undefined = this._getGraphSeries(chart)
?.getGraph()
.getNodeById(id)
?.getLayout();
const series = this._getGraphSeries(chart);
const node = series?.getGraph().getNodeById(id);
if (!node) {
return undefined;
}
// The layout already holds where a moving node ends up, the drawn symbol
// where it is now
const transform: number[] | null | undefined = series
.getData()
.getItemGraphicEl(node.dataIndex)
?.getComputedTransform();
if (transform) {
return { x: transform[4], y: transform[5] };
}
const position: number[] | undefined = node.getLayout();
if (!position) {
return undefined;
}
@@ -883,13 +898,23 @@ export class HaNetworkGraph extends LitElement {
return;
}
chart.dispatchAction({ type: "hideTip" });
this._cancelSettledHide?.();
// A resize waits for running animations and shows the tooltip again, so
// it is hidden once more when the chart has settled
// it is hidden once more when the chart has settled. Without a resize it
// would hide the next tooltip, so moving the pointer cancels it.
const zr = chart.getZr();
const hideWhenSettled = () => {
chart.off("finished", hideWhenSettled);
this._cancelSettledHide?.();
chart.dispatchAction({ type: "hideTip" });
};
const cancel = () => {
chart.off("finished", hideWhenSettled);
zr.off("mousemove", cancel);
this._cancelSettledHide = undefined;
};
chart.on("finished", hideWhenSettled);
zr.on("mousemove", cancel);
this._cancelSettledHide = cancel;
}
private _centerOnSelectedNode = () => {