Skip to content

Commit 45a8544

Browse files
committed
Allow more networkx generators
also MATPLOTLAB -> NETWORKX
1 parent e0b9351 commit 45a8544

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

pymathics/graph/__main__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from inspect import isgenerator
2525

26-
WL_MARKER_TO_MATPLOTLIB = {
26+
WL_MARKER_TO_NETWORKX = {
2727
"Circle": "o",
2828
"Diamond": "D",
2929
"Square": "s",
@@ -35,13 +35,13 @@
3535
# And many others. Is there a list somewhere?
3636
}
3737

38-
WL_COLOR_TO_MATPLOTLIB = {
38+
WL_COLOR_TO_NETWORKX = {
3939
"Green": "g",
4040
"Blue": "b",
4141
# And many others. Is there a list somewhere?
4242
}
4343

44-
WL_LAYOUT_TO_MATPLOTLIB = {
44+
WL_LAYOUT_TO_NETWORKX = {
4545
"CircularEmbedding": "circular",
4646
"SpiralEmbedding": "spiral",
4747
"SpectralEmbedding": "spectral",
@@ -86,7 +86,7 @@ def _process_graph_options(g, options: dict) -> None:
8686
else "Circle"
8787
)
8888

89-
g.G.node_shape = g.node_shape = WL_MARKER_TO_MATPLOTLIB.get(shape, shape)
89+
g.G.node_shape = g.node_shape = WL_MARKER_TO_NETWORKX.get(shape, shape)
9090

9191
color = (
9292
options["System`VertexStyle"].get_string_value()
@@ -100,9 +100,9 @@ def _process_graph_options(g, options: dict) -> None:
100100
else ""
101101
)
102102

103-
g.G.graph_layout = g.graph_layout = WL_LAYOUT_TO_MATPLOTLIB.get(g.graph_layout, g.graph_layout)
103+
g.G.graph_layout = g.graph_layout = WL_LAYOUT_TO_NETWORKX.get(g.graph_layout, g.graph_layout)
104104

105-
g.G.node_color = g.node_color = WL_COLOR_TO_MATPLOTLIB.get(color, color)
105+
g.G.node_color = g.node_color = WL_COLOR_TO_NETWORKX.get(color, color)
106106

107107
g.G.title = g.title = (
108108
options["System`PlotLabel"].get_string_value()

pymathics/graph/generators.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from pymathics.graph.__main__ import (
1111
Graph,
12-
WL_MARKER_TO_MATPLOTLIB,
12+
WL_MARKER_TO_NETWORKX,
1313
_NetworkXBuiltin,
1414
_convert_networkx_graph,
1515
_graph_from_list,
@@ -643,6 +643,17 @@ def apply(self, name, expression, evaluation, options):
643643
"%(name)s[name_String, OptionsPattern[%(name)s]]"
644644
py_name = name.get_string_value()
645645
fn, layout = WL_TO_NETWORKX_FN.get(py_name, (None, None))
646+
if not fn:
647+
if not py_name.endswith("_graph"):
648+
py_name += "_graph"
649+
if py_name in ("LCF_graph", "make_small_graph"):
650+
# These graphs require parameters
651+
return
652+
import inspect
653+
fn = dict(inspect.getmembers(nx, inspect.isfunction)).get(py_name, None)
654+
# parameters = inspect.signature(nx.diamond_graph).parameters.values()
655+
# if len([p for p in list(parameters) if p.kind in [inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD]]) != 0:
656+
# return
646657
if fn:
647658
g = graph_helper(fn, options, False, layout)
648659
g.G.name = py_name

pymathics/graph/tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import networkx as nx
2-
from pymathics.graph.__main__ import Graph, _graph_from_list, DEFAULT_GRAPH_OPTIONS, _NetworkXBuiltin, WL_MARKER_TO_MATPLOTLIB
2+
from pymathics.graph.__main__ import Graph, _graph_from_list, DEFAULT_GRAPH_OPTIONS, _NetworkXBuiltin, WL_MARKER_TO_NETWORKX
33
from mathics.core.expression import String, Symbol
44

55
DEFAULT_TREE_OPTIONS = {

0 commit comments

Comments
 (0)