In vis-network, how is horizontal order determined in hierarchical layout?
Asked Answered
C

2

6

In this example, "level" is used to control the vertical position a node is put at (assuming hierarchical.direction is up-down).

enter image description here

However, I didn't find how to set the horizontal order for nodes on the same hierarchy. For example, if I want to put node 6 in front of node 1, is there a way to do it?

My understanding is that the horizontal order is purely determined by node insertion order, is it correct?

Coeliac answered 6/8, 2020 at 6:40 Comment(0)
C
6

According to https://github.com/visjs/vis-network/issues/926, the order is non-deterministic. Quote:

Q: I didn't find how to set the horizontal order for nodes on the same hierarchy. For example, if I want to put node 6 in front of node 1, is there a way to do it?

A: As far as the public API goes: No, the order is not guaranteed in any way, do not rely on it, it may change with any new release or between browsers.

Q: My understanding is that the horizontal order is purely determined by node insertion order, is it correct?

A: As far as the CURRENT implementation and decent browsers go: Yes.

Coeliac answered 9/8, 2020 at 0:0 Comment(1)
I understand it's not supported with public API. Is there any custom way to change data nodes manipulated by expecting its position outside and set it back, ideally not resetting all nodes, but children nodes only?Mellman
K
0

Just want to add that if you're generating nodes and edges dynamically via user interactions and want to ensure the nodes and edges are ordered correctly, here's the way to do it:

After the user interaction, clear the nodes and edges first via the clear method, then use add to add the newest nodes and edges by the desired insertion order.

Kop answered 31/7, 2021 at 0:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.