4141 # And many others. Is there a list somewhere?
4242}
4343
44+ WL_LAYOUT_TO_MATPLOTLIB = {
45+ "CircularEmbedding" : "circular" ,
46+ "SpiralEmbedding" : "spiral" ,
47+ "SpectralEmbedding" : "spectral" ,
48+ "SpringEmbedding" : "spring" ,
49+ # And many others. Is there a list somewhere?
50+ }
51+
4452DEFAULT_GRAPH_OPTIONS = {
4553 "DirectedEdges" : "False" ,
4654 "EdgeStyle" : "{}" ,
4755 "EdgeWeight" : "{}" ,
48- "GraphLayout" : "{} " ,
56+ "GraphLayout" : "Null " ,
4957 "PlotLabel" : "Null" ,
5058 "VertexLabels" : "False" ,
5159 "VertexSize" : "{}" ,
5967def has_directed_option (options : dict ) -> bool :
6068 return options .get ("System`DirectedEdges" , False ).to_python ()
6169
70+
6271def _process_graph_options (g , options : dict ) -> None :
6372 """
6473 Handle common graph-related options like VertexLabels, PlotLabel, VertexShape, etc.
@@ -85,6 +94,14 @@ def _process_graph_options(g, options: dict) -> None:
8594 else "Blue"
8695 )
8796
97+ g .graph_layout = (
98+ options ["System`GraphLayout" ].get_string_value ()
99+ if "System`GraphLayout" in options
100+ else ""
101+ )
102+
103+ g .G .graph_layout = g .graph_layout = WL_LAYOUT_TO_MATPLOTLIB .get (g .graph_layout , g .graph_layout )
104+
88105 g .G .node_color = g .node_color = WL_COLOR_TO_MATPLOTLIB .get (color , color )
89106
90107 g .G .title = g .title = (
@@ -834,6 +851,7 @@ def apply_1(self, vertices, edges, evaluation, options):
834851 edges .leaves , options = options , new_vertices = vertices .leaves
835852 )
836853
854+
837855class PathGraphQ (_NetworkXBuiltin ):
838856 """
839857 >> PathGraphQ[Graph[{1 -> 2, 2 -> 3}]]
@@ -1502,7 +1520,7 @@ def apply(self, graph, expression, evaluation, options):
15021520 )
15031521 return Expression (
15041522 "List" ,
1505- * [Real (centrality .get (v , 0.0 )) for v in graph .vertices .expressions ]
1523+ * [Real (centrality .get (v , 0.0 )) for v in graph .vertices .expressions ],
15061524 )
15071525
15081526
@@ -1526,7 +1544,7 @@ def apply(self, graph, expression, evaluation, options):
15261544 centrality = nx .closeness_centrality (G , distance = weight , wf_improved = False )
15271545 return Expression (
15281546 "List" ,
1529- * [Real (centrality .get (v , 0.0 )) for v in graph .vertices .expressions ]
1547+ * [Real (centrality .get (v , 0.0 )) for v in graph .vertices .expressions ],
15301548 )
15311549
15321550
@@ -1546,7 +1564,7 @@ def _from_dict(self, graph, centrality):
15461564 s = len (graph .G ) - 1 # undo networkx's normalization
15471565 return Expression (
15481566 "List" ,
1549- * [Integer (s * centrality .get (v , 0 )) for v in graph .vertices .expressions ]
1567+ * [Integer (s * centrality .get (v , 0 )) for v in graph .vertices .expressions ],
15501568 )
15511569
15521570 def apply (self , graph , expression , evaluation , options ):
@@ -1685,7 +1703,7 @@ def apply_alpha_beta(self, graph, alpha, expression, evaluation, options):
16851703 centrality = nx .pagerank (G , alpha = py_alpha , weight = weight , tol = 1.0e-7 )
16861704 return Expression (
16871705 "List" ,
1688- * [Real (centrality .get (v , 0 )) for v in graph .vertices .expressions ]
1706+ * [Real (centrality .get (v , 0 )) for v in graph .vertices .expressions ],
16891707 )
16901708
16911709
@@ -1775,7 +1793,7 @@ def apply_s_t(self, graph, s, t, expression, evaluation, options):
17751793 weight = graph .update_weights (evaluation )
17761794 return Expression (
17771795 "List" ,
1778- * list (nx .shortest_path (G , source = s , target = t , weight = weight ))
1796+ * list (nx .shortest_path (G , source = s , target = t , weight = weight )),
17791797 )
17801798 except nx .exception .NetworkXNoPath :
17811799 return Expression ("List" )
0 commit comments