vis.js Level sorting in Hierarchical Layout
Asked Answered
H

2

7

I have a fairly simple hierarchical structure of nodes, but when vis.js draws them, the order of nodes on each level doesn't make much sense - there are a lot of crossed edges (screenshot: Default Layout )

I am hoping to get a layout similar to that given here: Expected Layout

My vis.js options are as follows;

{
    "layout": {
        "hierarchical": {
            "direction": "LR",
            "sortMethod": "directed",
            "nodeSpacing": 200,
            "treeSpacing": 400
        }
    },
    "edges": {
        "smooth": {
            "type": "continuous"
        }
    },
    "nodes": {
        "physics": false
    }
};

What is the best method to produce this sorted layout?

Herc answered 22/12, 2016 at 13:21 Comment(2)
The issue may be version-dependent: see https://mcmap.net/q/1627720/-vis-js-crossed-edges-in-4-21-hierarchical-graph/3995261Diphyodont
perhaps something like this might work, check the example in this fiddle jsfiddle.net/86vqfgeo, in case you could supply a fiddle like that with your data it could be very helpfulComnenus
H
0

I suggest your try enabling physics, which will sort out the edges crossing, etc.

However, in hierarchical layout, it's a good idea to disable the engine once it's done the first iterations by catching the 'stabilizationIterationsDone' event as follows:

network.on("stabilizationIterationsDone", function(){
  network.setOptions( { physics: false } );
});
Heres answered 20/9, 2018 at 13:33 Comment(0)
A
-4

you should remove the quotation marks. these are object's properties, not strings. it should look like this:

layout: {
    hierarchical: {
        direction: "LR",
        sortMethod: "directed",
        nodeSpacing: 200,
        treeSpacing: 400
    }
},
edges: {
    smooth: {
        type: "continuous"
    }
},
nodes: {
    physics: false
}
Acrylic answered 3/1, 2017 at 16:40 Comment(1)
using quotation marks is a valid syntax, so this can't be a source of any problem (moreover, this is required in JSON which is valid JS)Diphyodont

© 2022 - 2024 — McMap. All rights reserved.