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

Layout Algorithm Struggle #244

Open
TomStevenson1 opened this issue Feb 27, 2025 · 5 comments
Open

Layout Algorithm Struggle #244

TomStevenson1 opened this issue Feb 27, 2025 · 5 comments

Comments

@TomStevenson1
Copy link

Hi,

I've been trying to display a dependency map DOT file by converting it into a format that ipysigma can better accept. Unfortunately, after setting everything up, the Sigma visualization hasn't yielded any meaningful results yet.

I tried loading the DOT file into Gephi and got almost the same output. I assume this is because both tools rely on similar graphics engines for node placement. I'm wondering if I'm missing something major or if there's something else I should try.

My current Sigma setup is as follows:

from ipysigma import Sigma

Sigma(NewGraph,
      node_metrics=['louvain'],
      node_color='louvain',
      node_size_range=(4, 5),
      max_categorical_colors=30,
      default_edge_type='curve',
      node_border_color_from='node',
      default_node_label_size=5,  # Increased label size
      node_size=NewGraph.degree,
      layout_settings={
          "scalingRatio": 150000.0,  # Spread out the layout further
          "strongGravityMode": False,
          "gravity": 1,
      }
)

This produces the following output:

Image

I know I should look into this, but even after adjusting the layout settings, I see no noticeable change.

Where else should I look? My main struggle is making this dense graph more free-flowing, like in the demo site. I feel like I may be missing something obvious, so please feel free to point out any major issues.

Thanks!

@Yomguithereal
Copy link
Member

@TomStevenson1 you need to actually run the algorithm by clicking on the button with a play icon. Both Gephi and ipysigma work like this because there is no deterministic way to know when the layout might be complete, so we need to rely on the user to actually stop the layout once it is done. You can give the start_layout=True to the Sigma widget to have it start automatically when the widget appears. Or even use start_layout=5 or some other number to have it running a fixed number of seconds before stopping.

@TomStevenson1
Copy link
Author

TomStevenson1 commented Feb 27, 2025

Hi @Yomguithereal,

Unfortunately, I ran the scatter and run buttons before it, but that wasn’t the ideal solution. What helped was using spring_layout via NetworkX, then multiplying the coordinates by a certain scale factor and incorporating a random scale factor. However, I’ve had some difficulty reducing the visual density.

Even if the X and Y coordinates are off by 200 units or pixels (?), they still appear very close together upon closer inspection. I’ve adjusted the edge and node sizes, but I still can’t get anything as sparse as the demo visualization.

Any guidance would be appreciated. Realistically, how can I get my nodes and edges to look more like what you had in the demo? I noticed that in your demo, the coordinates were in the double digits and still had proper spacing, so I assume the issue lies with my node and edge sizing.

Thanks,
Tom

@TomStevenson1
Copy link
Author

Image
Image

@TomStevenson1
Copy link
Author

I applied the same settings you used for the demo and the data still took roughly the same shape. I may try some other methods in the meantime, but it doesn't seem like it is a Sigma settings problem unless you have a smart throught @Yomguithereal

@Yomguithereal
Copy link
Member

I think you don't let the layout run long enough. One thing to notice is that sigma/iypsigma and Gephi have different philosophies regarding the scale of the nodes wrt the space (x, y) they exist in, so you should probably drop your layout_settings because they won't have the same effect on Gephi where you need to tweak those by hand. With sigma/ipysigma the space is automatically rescaled and normalized while the node sizes have a value understood in pixels, and FA2's collision detection (which usually hampers convergence of this kind of graph) does not really apply. People tend to run FA2 to some satisfactory output without considering node size then run some anti-collision in the end as a finishing touch.

Then I also encourage you to play with values given to node_size_range and edge_size_range to tweak the readability of the representation. The given values are expressed in pixel radius (or diameter, I don't recall) of nodes, and thickness of edges in pixels, and are not expressed in some abstract size related to the coordinate system.

Something that you can try also is to start from a circular layout (https://networkx.org/documentation/stable/reference/generated/networkx.drawing.layout.circular_layout.html) because for some graphs it tends to improve convergence vs. a random square space.

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

No branches or pull requests

2 participants