@@ -60,27 +60,56 @@ def __as_label(self,head,body:str)->str:
6060 label = f"{ head } \n { dash } \n { body } "
6161 return label
6262
63- def draw_vertex (self , vertex : Vertex ):
63+ def get_vertex_properties (self ,vertex :Vertex )-> list :
6464 """
65- draw a single given vertex
65+ get the properties for a given vertex
6666 """
67- # avoid drawing to many vertices
68- if len (self .v_drawn )>= self .config .v_limit :
69- return
70- if vertex .id in self .v_drawn :
71- return
7267 # developer note: see https://github.com/apache/tinkerpop/blob/master/gremlin-python/src/main/python/gremlin_python/structure/graph.py#LL58C23-L58C23
73- # when gremlin-python 3.7.0 is released, the following code can be improved (get the properties using vertex.properties)
74- # then, g can also be removed as a parameter
68+ # has properties but these are not set as for gremlin-python 3.7.0
7569
76- # get the properties of the vertex
70+ # get the properties of the vertex (work around)
7771 kvp_list = list (next (self .g .V (vertex ).element_map ()).items ())
7872 # non-property items are of type aenum
7973 properties = [item for item in kvp_list if not isinstance (item [0 ], Enum )]
8074 assert len (properties ) == len (kvp_list ) - 2 # ID and label are not properties
8175 if self .config .vertex_properties is not None :
8276 properties = [item for item in properties if item [0 ] in self .config .vertex_properties ]
83-
77+ return properties
78+
79+ def get_edge_properties (self ,edge :Edge )-> list :
80+ # developer note: see https://github.com/apache/tinkerpop/blob/master/gremlin-python/src/main/python/gremlin_python/structure/graph.py#L66
81+ # when gremlin-python 3.7.0 is released, the following code might be improved (get the properties using edge.properties)
82+ # e_props=edge.properties
83+ # 2023-08-21: WF tested - but properties are not set ...
84+ # then, g can also be removed as a parameter
85+ # get the properties of the edge
86+ edge_t = self .g .E (edge )
87+ try :
88+ edge_map = edge_t .element_map ().next ()
89+ kvp_list = list (edge_map .items ())
90+ except StopIteration :
91+ pass
92+ return []
93+
94+ # Workaround, because the above line does not work due to inconsistencies / bugs in the gremlin-python library
95+ #kvp_list = [edge_element_map for edge_element_map in self.g.E().element_map().to_list() if edge_element_map[T.id] == edge.id][0].items()
96+ # non-property items are of type aenum
97+ properties = [item for item in kvp_list if not isinstance (item [0 ], Enum )]
98+ assert len (properties ) == len (kvp_list ) - 4 # ID, label, in, and out are not properties
99+ if self .config .edge_properties is not None :
100+ properties = [item for item in properties if item [0 ] in self .config .edge_properties ]
101+ return properties
102+
103+ def draw_vertex (self , vertex : Vertex ):
104+ """
105+ draw a single given vertex
106+ """
107+ # avoid drawing to many vertices
108+ if len (self .v_drawn )>= self .config .v_limit :
109+ return
110+ if vertex .id in self .v_drawn :
111+ return
112+ properties = self .get_vertex_properties (vertex )
84113 properties_label = "\n " .join (f"{ key } : { value } " for key , value in properties )
85114 head = f"{ str (vertex .id )} \n { vertex .label } "
86115 body = f"{ properties_label } "
@@ -108,21 +137,7 @@ def draw_edge(self, edge: Edge,with_vertices:bool=True):
108137 self .draw_vertex (edge .inV )
109138 self .draw_vertex (edge .outV )
110139 pass
111- # developer note: see https://github.com/apache/tinkerpop/blob/master/gremlin-python/src/main/python/gremlin_python/structure/graph.py#L66
112- # when gremlin-python 3.7.0 is released, the following code might be improved (get the properties using edge.properties)
113- # e_props=edge.properties
114- # 2023-08-21: WF tested - but properties are not set ...
115- # then, g can also be removed as a parameter
116- # get the properties of the edge
117- kvp_list = list (next (self .g .E (edge ).element_map ()).items ())
118- # Workaround, because the above line does not work due to inconsistencies / bugs in the gremlin-python library
119- #kvp_list = [edge_element_map for edge_element_map in self.g.E().element_map().to_list() if edge_element_map[T.id] == edge.id][0].items()
120- # non-property items are of type aenum
121- properties = [item for item in kvp_list if not isinstance (item [0 ], Enum )]
122- assert len (properties ) == len (kvp_list ) - 4 # ID, label, in, and out are not properties
123- if self .config .edge_properties is not None :
124- properties = [item for item in properties if item [0 ] in self .config .edge_properties ]
125-
140+ properties = self .get_edge_properties (edge )
126141 properties_label = "\n " .join (f"{ key } : { value } " for key , value in properties )
127142 head = f"{ str (edge .id )} \n { edge .label } "
128143 body = properties_label
0 commit comments