Skip to content

Commit be25529

Browse files
committed
Add VertexShapeFunction
1 parent b93c5a7 commit be25529

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

pymathics/graph/__main__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222

2323
from inspect import isgenerator
2424

25+
WL_MARKER_TO_MATPLOTLIB = {
26+
"Circle": "o",
27+
"Diamond" :"D",
28+
"Square" :"s",
29+
"Star": "*",
30+
"Pentagon": "p",
31+
"Octagon": "8",
32+
"Hexagon": "h",
33+
"Triangle": "^",
34+
# And many others. Is there a list somewhere?
35+
}
36+
2537
DEFAULT_GRAPH_OPTIONS = {
2638
"DirectedEdges": "False",
2739
"EdgeStyle": "{}",
@@ -30,6 +42,7 @@
3042
"PlotLabel": "Null",
3143
"VertexLabels": "False",
3244
"VertexSize": "{}",
45+
"VertexShape": "o",
3346
"VertexStyle": "{}",
3447
}
3548

@@ -660,6 +673,8 @@ def full_new_edge_properties(new_edge_style):
660673
g = Graph(G)
661674
g.vertex_labels = G.vertex_labels = options["System`VertexLabels"]
662675
G.title = g.title = options["System`PlotLabel"]
676+
shape = options["System`VertexShape"].get_string_value()
677+
G.node_shape = g.vertex_shape = WL_MARKER_TO_MATPLOTLIB.get(shape, shape)
663678
return g
664679

665680

pymathics/graph/graph_generators.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pymathics.graph.__main__ import (
22
Graph,
3+
WL_MARKER_TO_MATPLOTLIB,
34
_NetworkXBuiltin,
45
nx,
56
)
@@ -33,7 +34,9 @@ def graph_helper(
3334
return None
3435
G.graph_layout = options["System`GraphLayout"].get_string_value() or graph_layout
3536
g = Graph(G)
36-
G.vertex_labels = g.vertex_labels = options["System`VertexLabels"]
37+
G.vertex_labels = g.vertex_labels = options["System`VertexLabels"].get_string_value()
38+
shape = options["System`VertexShape"]
39+
G.node_shape = g.node_shape = WL_MARKER_TO_MATPLOTLIB.get(shape, shape)
3740

3841
if root is not None:
3942
G.root = g.root = root

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
2+
from pymathics.graph.__main__ import Graph, _graph_from_list, DEFAULT_GRAPH_OPTIONS, _NetworkXBuiltin, WL_MARKER_TO_MATPLOTLIB
33
from mathics.core.expression import String, Symbol
44

55
DEFAULT_TREE_OPTIONS = {

0 commit comments

Comments
 (0)