We've removed the limitation of Graph Visualiser where it would not render vertex and edge labels if the graph size was above a certain threshold.
What are the changes implemented in this PR?
Drawing text in Compose is much more expensive than drawing polygons. So we need to be more aggressive in choosing which texts to actually draw. Clearly, any text that we know to be fully outside the viewport should not be drawn.
We aim to ensure the initial "explosion" is as smooth as possible, and the resulting stable visualisation as rich as possible. The variables to consider are: total vertices/edges in graph; total vertices/edges in viewport; viewport scale; physics alpha.
Vertex rendering
If vertex is entirely outside viewport, don't draw it
If viewport scale < 0.2 (20%), OR if (no. of vertices in viewport > 100 AND physics alpha > 0.25), don't draw vertex labels. This ensures smooth performance when zoomed out and during the initial explosion.
Edge rendering
For edges, we have two draw modes: simple and detailed. A detailed edge has a label, and also, detailed edges can be curved. Because DrawScope.drawPoints is so cheap, we can draw all edges as simple by default, and detailed when they meet certain criteria:
Draw edges as detailed if the label is in the viewport, AND viewport scale is > 0.2, AND (physics alpha < 0.25 OR total no. of detailed edges is < 100). This ensures smooth performance when zoomed out and during the initial explosion.
As an additional optimisation, if viewport scale < 0.2 AND total edges in graph > 500, ALL edges are drawn in simple mode. This ensures smooth performance when zoomed out, and in this case we don't need to determine which edge labels are visible, saving resources.
What is the goal of this PR?
We've removed the limitation of Graph Visualiser where it would not render vertex and edge labels if the graph size was above a certain threshold.
What are the changes implemented in this PR?
Drawing text in Compose is much more expensive than drawing polygons. So we need to be more aggressive in choosing which texts to actually draw. Clearly, any text that we know to be fully outside the viewport should not be drawn.
We aim to ensure the initial "explosion" is as smooth as possible, and the resulting stable visualisation as rich as possible. The variables to consider are: total vertices/edges in graph; total vertices/edges in viewport; viewport scale; physics alpha.
Vertex rendering
Edge rendering
For edges, we have two draw modes: simple and detailed. A detailed edge has a label, and also, detailed edges can be curved. Because
DrawScope.drawPoints
is so cheap, we can draw all edges as simple by default, and detailed when they meet certain criteria: