1313 Expression ,
1414 Symbol ,
1515 Atom ,
16- Real ,
1716 Integer ,
17+ Real ,
1818 system_symbols_dict ,
1919 from_python ,
2020)
@@ -151,6 +151,7 @@ class _NetworkXBuiltin(Builtin):
151151 "VertexStyle" : "{}" ,
152152 "EdgeStyle" : "{}" ,
153153 "EdgeWeight" : "{}" ,
154+ "PlotTheme" : "{}" ,
154155 }
155156
156157 messages = {
@@ -333,14 +334,12 @@ def _normalize_edges(edges):
333334
334335
335336class Graph (Atom ):
337+
336338 def __init__ (self , G , ** kwargs ):
337- super (Graph , self ).__init__ (** kwargs )
339+ super (Graph , self ).__init__ ()
340+ self .options = kwargs .get ("options" , None )
338341 self .G = G
339342
340- @property
341- def vertices (self ):
342- return self .G .nodes
343-
344343 @property
345344 def edges (self ):
346345 return self .G .edges
@@ -516,6 +515,10 @@ def _create_graph(new_edges, new_edge_properties, options, from_graph=None):
516515
517516 multigraph = [False ]
518517
518+ if "System`VertexStyle" in options :
519+ vertex_options = options ["System`VertexStyle" ].to_python ()
520+
521+
519522 known_vertices = set (vertices )
520523 known_edges = set (edges )
521524
@@ -570,6 +573,19 @@ def parse_edge(r, attr_dict):
570573 edges_container = undirected_edges
571574 head = undirected_edge_head
572575 track_edges ((u , v ), (v , u ))
576+ elif name == "PyMathics`Property" :
577+ for prop in edge .leaves :
578+ prop_str = str (prop .head )
579+ if prop_str in ("System`Rule" , "System`DirectedEdge" ):
580+ edges_container = directed_edges
581+ head = directed_edge_head
582+ track_edges ((u , v ))
583+ elif prop_str == "System`UndirectedEdge" :
584+ edges_container = undirected_edges
585+ head = undirected_edge_head
586+ else :
587+ pass
588+ pass
573589 else :
574590 raise _GraphParseError
575591
@@ -583,15 +599,28 @@ def parse_edge(r, attr_dict):
583599
584600 try :
585601
586- def full_new_edge_properties ():
602+ def full_new_edge_properties (new_edge_style ):
587603 for i , (attr_dict , w ) in enumerate (zip (new_edge_properties , edge_weights )):
588604 attr_dict = {} if attr_dict is None else attr_dict .copy ()
589605 attr_dict ["System`EdgeWeight" ] = w
590606 yield attr_dict
607+ # FIXME: figure out what to do here. Color is a mess.
608+ # for i, (attr_dict, s) in enumerate(zip(new_edge_style, new_edge_style)):
609+ # attr_dict = {} if attr_dict is None else attr_dict.copy()
610+ # attr_dict["System`EdgeStyle"] = s
611+ # yield attr_dict
591612 for attr_dict in new_edge_properties [len (edge_weights ) :]:
592613 yield attr_dict
593614
594- for edge , attr_dict in zip (new_edges , full_new_edge_properties ()):
615+ if "System`EdgeStyle" in options :
616+ # FIXME: Figure out what to do here:
617+ # Color is a f-ing mess.
618+ # edge_options = options["System`EdgeStyle"].to_python()
619+ edge_options = []
620+ else :
621+ edge_options = []
622+ edge_properties = list (full_new_edge_properties (edge_options ))
623+ for edge , attr_dict in zip (new_edges , edge_properties ):
595624 parse_edge (edge , attr_dict )
596625 except _GraphParseError :
597626 return
@@ -681,14 +710,14 @@ class GraphAtom(AtomBuiltin):
681710 >> Graph[{1->2, 2->3, 3->1}]
682711 = -Graph-
683712
684- >> Graph[{1->2, 2->3, 3->1}, EdgeStyle -> {Red, Blue, Green}]
685- = -Graph-
713+ # >> Graph[{1->2, 2->3, 3->1}, EdgeStyle -> {Red, Blue, Green}]
714+ # = -Graph-
686715
687716 >> Graph[{1->2, Property[2->3, EdgeStyle -> Thick], 3->1}]
688717 = -Graph-
689718
690- >> Graph[{1->2, 2->3, 3->1}, VertexStyle -> {1 -> Green, 3 -> Blue}]
691- = -Graph-
719+ # >> Graph[{1->2, 2->3, 3->1}, VertexStyle -> {1 -> Green, 3 -> Blue}]
720+ # = -Graph-
692721
693722 >> Graph[x]
694723 = Graph[x]
@@ -716,6 +745,7 @@ class GraphAtom(AtomBuiltin):
716745 "VertexStyle" : "{}" ,
717746 "EdgeStyle" : "{}" ,
718747 "DirectedEdges" : "True" ,
748+ "PlotTheme" : "Null" ,
719749 }
720750
721751 def apply (self , graph , evaluation , options ):
@@ -1794,39 +1824,6 @@ def apply_s_t(self, graph, s, t, expression, evaluation, options):
17941824 return Expression ("DirectedInfinity" , 1 )
17951825
17961826
1797- class CompleteGraph (_NetworkXBuiltin ):
1798- """
1799- >> CompleteGraph[8]
1800- = -Graph-
1801-
1802- #> CompleteGraph[0]
1803- : Expected a positive integer at position 1 in CompleteGraph[0].
1804- = CompleteGraph[0]
1805- """
1806-
1807- messages = {
1808- "ilsmp" : "Expected a positive integer at position 1 in ``." ,
1809- }
1810-
1811- def apply (self , n , expression , evaluation , options ):
1812- "%(name)s[n_Integer, OptionsPattern[%(name)s]]"
1813- py_n = n .get_int_value ()
1814-
1815- if py_n < 1 :
1816- evaluation .message (self .get_name (), "ilsmp" , expression )
1817- return
1818-
1819- G = nx .complete_graph (py_n )
1820- return Graph (G )
1821-
1822- def apply_multipartite (self , n , evaluation , options ):
1823- "%(name)s[n_List, OptionsPattern[%(name)s]]"
1824- if all (isinstance (i , Integer ) for i in n .leaves ):
1825- return Graph (
1826- nx .complete_multipartite_graph (* [i .get_int_value () for i in n .leaves ])
1827- )
1828-
1829-
18301827def _convert_networkx_graph (G , options ):
18311828 mapping = dict ((v , Integer (i )) for i , v in enumerate (G .nodes ))
18321829 G = nx .relabel_nodes (G , mapping )
0 commit comments