Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling hierarchical layout and re-enabling it causes errors #178

Open
Tyler-Maclachlan opened this issue Oct 24, 2019 · 7 comments
Open
Assignees
Labels
question Further information is requested

Comments

@Tyler-Maclachlan
Copy link
Contributor

Tyler-Maclachlan commented Oct 24, 2019

Hi there,

I am using the hierarchical layout with edges that can be 'split?', when splitting the edges I disable the layout so that none of the nodes move (it's really frustrating having the node you were looking at suddenly move), however when I re-enable the layout afterwards I get the following error:

Uncaught Error: To use the hierarchical layout, nodes require either no predefined levels or levels have to be defined for all nodes.

I have predefined levels manually on every node, and looping through the DataSet shows that each node does indeed have a level.

Here's how I do it:

this.options.layout.hierarchical.enabled = false;
this.network.setOptions(this.options);

// split the edges

// loop over the data set and log the node level - every node has a level
this.graphNodes.forEach(n => {
     console.log(n.level);
})
this.options.layout.hierarchical.enabled = true;
this.network.setOptions(this.options);
@Thomaash
Copy link
Member

Hi @Tyler-Maclachlan,

could you provide an MWE on JSFiddle or somewhere, please?

Thanks.

@Tyler-Maclachlan
Copy link
Contributor Author

Tyler-Maclachlan commented Oct 24, 2019

Hi @Thomaash

Here is a codepen example.

It always gives the error on split, and every now and then when collapsing the edges back together

@Thomaash
Copy link
Member

This has me puzzled. When hierarchical layout is disabled some new hidden nodes are added. Not sure why though.

@Tyler-Maclachlan
Copy link
Contributor Author

I believe that happens when you have smoothing enabled on edges. Those support nodes shouldn't be taken into account in the check for node levels.

@Tyler-Maclachlan
Copy link
Contributor Author

Tyler-Maclachlan commented Oct 24, 2019

Disabling smoothing for edges stops the error from showing up, but doesn't work for this use case as the edges need to be curved to show each edge.

@Thomaash
Copy link
Member

Okay, thanks for investigating this. There are already two (#171 and #177) PRs messing with hierarchical layout that I'd like to merge before addressing this. So after @mojoaxel finds the time to review them I'll have a look if the support edges can be safely ignored in hierarchical layout.

@Thomaash Thomaash self-assigned this Oct 24, 2019
@mojoaxel mojoaxel added the question Further information is requested label Oct 27, 2019
Thomaash added a commit to visjs/vis-util that referenced this issue Dec 8, 2019
This is intended to replace the prototype plus hacks insanity used at
the moment. However this is still WIP. There is no documentations yet
and more testing is necessary.

TODO:
- Add off.
- Write docs.
- Probably some other things too.

In a quick test I was able to resolve the issue discussed in
visjs/vis-network#178 and visjs/vis-network#213 with just a few lines of
code. Which is much better than the massive mess of weird hacks that
doesn't work reliably anyway.

Putting this to use will be a lot of work but fortunately it should be
possible to do it in parts. I would first use this in LayoutEngine and
EdgesHandler to resolve the forementioned issues and then probably one
module at the time.

Features:
- Encapsulates options merging.
- Explicit layer/segment/key structure instead of prototype chains.
- Observable.
- Overrides. *
- Type safety in TypeScript.

* Hierarchical layout is incompatible with smooth edges and has to
disable them. Overrides combined with observing easily and elegently
solve that. See the forementioned issues for current state.
Thomaash added a commit to visjs/vis-util that referenced this issue Jan 26, 2020
This is intended to replace the prototype plus hacks insanity used at
the moment. However this is still WIP. There is no documentations yet
and more testing is necessary.

TODO:
- Add off.
- Write docs.
- Probably some other things too.

In a quick test I was able to resolve the issue discussed in
visjs/vis-network#178 and visjs/vis-network#213 with just a few lines of
code. Which is much better than the massive mess of weird hacks that
doesn't work reliably anyway.

Putting this to use will be a lot of work but fortunately it should be
possible to do it in parts. I would first use this in LayoutEngine and
EdgesHandler to resolve the forementioned issues and then probably one
module at the time.

Features:
- Encapsulates options merging.
- Explicit layer/segment/key structure instead of prototype chains.
- Observable.
- Overrides. *
- Type safety in TypeScript.

* Hierarchical layout is incompatible with smooth edges and has to
disable them. Overrides combined with observing easily and elegently
solve that. See the forementioned issues for current state.
@robsonn
Copy link

robsonn commented Feb 28, 2023

Recently I had the same error.

Error spam in second change, first remove hierarchical(ok)

const optionsRemoveHierarchy = { ...this.options, layout: { hierarchical: { enabled: false } }, edges: { physics: false }, nodes: { physics: false } }

this.network.storePositions()
this.network.setOptions(optionsRemoveHierarchy)

second time change back hierarchical span error

const optionsHierarchy = { ...this.options, layout: { hierarchical: { enabled: true } }, nodes: { physics: true }, edges: { physics: true } }
this.network.setOptions(optionsHierarchy)

@Thomaash @Tyler-Maclachlan I solved changing the smooth type for any value different of dynamic
ex: edges: { smooth: { enabled: false }} or edges: { smooth: { enabled: true, type: 'discrete'(for example)}

Note: vis-network version - 9.1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants