Skip to content

Commit 35b5aba

Browse files
committed
Handle spiral_equidistant
1 parent 518f23f commit 35b5aba

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mathicsscript/format.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ def tree_layout(G):
269269
node_size = min_sep * 2000
270270
return pos
271271

272+
def spiral_equidistant_layout(G, *args, **kwargs):
273+
return nx.spiral_layout(G, equidistant=True, *args, **kwargs)
272274

273275
NETWORKX_LAYOUTS = {
274276
"circular": nx.circular_layout,
@@ -277,6 +279,8 @@ def tree_layout(G):
277279
"random": nx.random_layout,
278280
"shell": nx.shell_layout,
279281
"spectral": nx.spectral_layout,
282+
"spiral": nx.spiral_layout,
283+
"spiral_equidistant": spiral_equidistant_layout,
280284
"spring": nx.spring_layout,
281285
"tree": tree_layout,
282286
}
@@ -304,7 +308,10 @@ def harmonize_parameters(G, draw_options: dict):
304308
# results
305309
tree_layout(G)
306310
draw_options["node_size"] = node_size
307-
elif graph_layout == "circular":
311+
elif graph_layout in ["circular", "spiral", "spiral_equidistant"]:
312+
# FIXME spiral is more 2D filling
313+
# Instead of Sqrt use adjusted exponent like **0.6
314+
# and mayb for spiral **0.7
308315
node_size = draw_options["node_size"] = (2 * DEFAULT_NODE_SIZE) / math.sqrt(
309316
len(G) + 1
310317
)
@@ -359,12 +366,11 @@ def format_graph(G):
359366
fig, ax = plt.subplots() # Create a figure and an axes
360367
ax.set_title(G.title)
361368

369+
layout_fn = None
362370
if graph_layout:
363371
if not isinstance(graph_layout, str):
364372
graph_layout = graph_layout.get_string_value()
365373
layout_fn = NETWORKX_LAYOUTS.get(graph_layout, None)
366-
else:
367-
layout_fn = None
368374

369375
harmonize_parameters(G, draw_options)
370376

0 commit comments

Comments
 (0)