@@ -300,6 +300,36 @@ def _make_graph(self):
300
300
nx .relabel_nodes (graph , mapping , copy = False )
301
301
return graph
302
302
303
+ @staticmethod
304
+ def _encapsulate_edge_attributes (graph ):
305
+ """
306
+ Modifies the `nx.Graph`'s edge attribute `attr_map` to be a string representation
307
+ of the attribute map, and encapsulates the string in double quotes.
308
+ Changes the graph in place.
309
+
310
+ Implements workaround described in
311
+ https://github.com/pydot/pydot/issues/258#issuecomment-795798099
312
+ """
313
+ for u , v , * _ , edgedata in graph .edges (data = True ):
314
+ if "attr_map" in edgedata :
315
+ graph .edges [u , v ]["attr_map" ] = '"{0}"' .format (edgedata ["attr_map" ])
316
+
317
+ @staticmethod
318
+ def _encapsulate_node_names (graph ):
319
+ """
320
+ Modifies the `nx.Graph`'s node names string representations encapsulated in
321
+ double quotes.
322
+ Changes the graph in place.
323
+
324
+ Implements workaround described in
325
+ https://github.com/datajoint/datajoint-python/pull/1176
326
+ """
327
+ nx .relabel_nodes (
328
+ graph ,
329
+ {node : '"{0}"' .format (node ) for node in graph .nodes ()},
330
+ copy = False ,
331
+ )
332
+
303
333
def make_dot (self ):
304
334
graph = self ._make_graph ()
305
335
graph .nodes ()
@@ -368,6 +398,8 @@ def make_dot(self):
368
398
for node , d in dict (graph .nodes (data = True )).items ()
369
399
}
370
400
401
+ self ._encapsulate_node_names (graph )
402
+ self ._encapsulate_edge_attributes (graph )
371
403
dot = nx .drawing .nx_pydot .to_pydot (graph )
372
404
for node in dot .get_nodes ():
373
405
node .set_shape ("circle" )
@@ -408,9 +440,14 @@ def make_dot(self):
408
440
409
441
for edge in dot .get_edges ():
410
442
# see https://graphviz.org/doc/info/attrs.html
411
- src = edge .get_source (). strip ( '"' )
412
- dest = edge .get_destination (). strip ( '"' )
443
+ src = edge .get_source ()
444
+ dest = edge .get_destination ()
413
445
props = graph .get_edge_data (src , dest )
446
+ if props is None :
447
+ raise DataJointError (
448
+ "Could not find edge with source "
449
+ "'{}' and destination '{}'" .format (src , dest )
450
+ )
414
451
edge .set_color ("#00000040" )
415
452
edge .set_style ("solid" if props ["primary" ] else "dashed" )
416
453
master_part = graph .nodes [dest ][
0 commit comments