imohitmayank / jaal

Your interactive network visualizing dashboard
MIT License
321 stars 41 forks source link

Max width for edges and nodes #65

Open Famondir opened 1 year ago

Famondir commented 1 year ago

Hi, I have problems setting the max width for edges. I tried many of the visjs-settings like value, width, widthConstrain resulting in a common width for all edges or without any effect. I find the default max width to big.

I also tried Jaal(edge_df, node_df).plot(directed=True, vis_opts={'physics':{'stabilization':{'iterations': 100}, 'solver' : 'repulsion'}, 'edges': {'scaling': {'min': 1, 'max': 2}}}) with no result (taken from layout.py.

Same would be good for node size as well. Especially if you have only few different values (e. g. 1 and 2) it becomes really obscure:

image

As a work around for the edges I found the posibility to add an edge that connects two non existent nodes and has higher value in the size determing column. E.g. a 10. It won't show up.

For nodes this is not so easy, because the node will show up anywaay. But you can filter it out. If you add a node that you filter out anyway you can use its id as from and to in the edge_df as well:

image

then becomes

image

Sincerely Simon

Famondir commented 1 year ago

I tried passing visjs options like this as well:

'edges': {'scaling': {'customScalingFunction': 'function (min, max, total, value) {return value / total;}', 'min': 5, 'max': 150}}

I took it from this example.

Famondir commented 1 year ago

You can disable the dummy node by accessing the Jaal objects data entry and setting the hidden and physics attributes there:

node_df.loc[len(node_df)] = ['dummy', '', '', 100, 100] # last node is the dummy node
edge_df.loc[len(edge_df)] = ['dummy', 'dummy', 'NA', 10, 10]

j = Jaal(edge_df, node_df)
j.data['nodes'][-1]['hidden'] = True # last node is the dummy node
j.data['nodes'][-1]['physics'] = False # last node is the dummy node
j.plot(directed=True, vis_opts={'physics': {'stabilization':{'iterations': 100}, 'barnesHut': {'centralGravity': 1, 'springConstant': 0.01}}})
imohitmayank commented 1 year ago

Hey @Famondir thanks for reporting this. This seems to be happening due to coded scaling which in your case is making the scaled weights 0 and 20 respectively for the original 1 and 2 defined weights. Need to find a better way to handle corner cases. Will get back here.