Skip to content

Commit 8322c4a

Browse files
committed
FindSpannngTree: use layout style of parent graph
1 parent b2d7441 commit 8322c4a

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

mathicsscript/__main__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import click
55
import sys
66
import os
7+
import re
78
from pathlib import Path
89

910
from mathicsscript.termshell import TerminalShell
@@ -24,6 +25,20 @@
2425

2526
from mathicsscript.version import __version__
2627

28+
wl_replace_dict = {"": "→", "": "↔"}
29+
wl_replace_dict_esc = dict((re.escape(k), v) for k, v in wl_replace_dict.items())
30+
wl_replace_pattern = re.compile("|".join(wl_replace_dict_esc.keys()))
31+
32+
33+
def replace_wl_to_unicode(wl_input: str) -> str:
34+
"""WL uses some non-unicode character for various things.
35+
Replace them with the unicode equivalent.
36+
Two known items are directed arrow and undirected arrow.
37+
"""
38+
return wl_replace_pattern.sub(
39+
lambda m: wl_replace_dict_esc[re.escape(m.group(0))], wl_input
40+
)
41+
2742

2843
def ensure_settings():
2944
home = Path.home()
@@ -314,7 +329,8 @@ def main(
314329
current_pos = GNU_readline.get_current_history_length()
315330
for pos in range(last_pos, current_pos - 1):
316331
GNU_readline.remove_history_item(pos)
317-
GNU_readline.add_history(source_code.rstrip())
332+
wl_input = replace_wl_to_unicode(source_code.rstrip())
333+
GNU_readline.add_history(wl_input)
318334

319335
if query is None:
320336
continue

mathicsscript/format.py

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

272+
272273
def spiral_equidistant_layout(G, *args, **kwargs):
273274
return nx.spiral_layout(G, equidistant=True, *args, **kwargs)
274275

276+
275277
NETWORKX_LAYOUTS = {
276278
"circular": nx.circular_layout,
277279
"multipartite": nx.multipartite_layout,
@@ -285,11 +287,8 @@ def spiral_equidistant_layout(G, *args, **kwargs):
285287
"tree": tree_layout,
286288
}
287289

288-
LAYOUT_DENSITY_EXPONENT = {
289-
"circular": 0.9,
290-
"spiral_equidistant": 0.7,
291-
"spiral": 0.6,
292-
}
290+
LAYOUT_DENSITY_EXPONENT = {"circular": 0.9, "spiral_equidistant": 0.7, "spiral": 0.6}
291+
293292

294293
def clamp(value, min=-math.inf, max=math.inf):
295294
if value <= min:
@@ -315,7 +314,9 @@ def harmonize_parameters(G, draw_options: dict):
315314
draw_options["node_size"] = node_size
316315
elif graph_layout in ["circular", "spiral", "spiral_equidistant"]:
317316
exponent = LAYOUT_DENSITY_EXPONENT[graph_layout]
318-
node_size = draw_options["node_size"] = (2 * DEFAULT_NODE_SIZE) / (len(G)+1) ** exponent
317+
node_size = draw_options["node_size"] = (2 * DEFAULT_NODE_SIZE) / (
318+
len(G) + 1
319+
) ** exponent
319320
# print("XX", node_size, exponent)
320321

321322
if draw_options.get("with_labels", False):
@@ -325,6 +326,8 @@ def harmonize_parameters(G, draw_options: dict):
325326
if "width" not in draw_options:
326327
width = clamp(node_size / DEFAULT_NODE_SIZE, min=0.15)
327328
draw_options["width"] = width
329+
print("width", draw_options["width"])
330+
print("graph_layout", graph_layout)
328331

329332
if "font_size" not in draw_options:
330333
# FIXME: should also take into consideration max width of label.

0 commit comments

Comments
 (0)