@@ -133,11 +133,18 @@ def __init__(self, id="", radius=5, **kwargs):
133133 self .fill = kwargs .pop ("fill" , None )
134134 self .stroke = kwargs .pop ("stroke" , (0 , 0 , 0 , 1 ))
135135 self .strokewidth = kwargs .pop ("strokewidth" , 1 )
136+
137+ if not isinstance (id , unicode ):
138+ id = str (id ).decode ("utf-8" , "ignore" )
139+
140+ # FIXME this is a mess.
136141 self .text = kwargs .get ("text" , True ) and \
137- Text (isinstance ( id , unicode ) and id or str ( id ). decode ( "utf-8" , "ignore" ) ,
142+ Text (id ,
138143 width = 85 ,
139144 fill = kwargs .pop ("text" , (0 , 0 , 0 , 1 )),
140- fontsize = kwargs .pop ("fontsize" , 11 ), ** kwargs ) or None
145+ fontsize = kwargs .pop ("fontsize" , 11 ),
146+ ** kwargs ) or None
147+
141148 self ._weight = None # Calculated by Graph.eigenvector_centrality().
142149 # Calculated by Graph.betweenness_centrality().
143150 self ._centrality = None
@@ -260,11 +267,19 @@ def contains(self, x, y):
260267 def __repr__ (self ):
261268 return "%s(id=%s)" % (self .__class__ .__name__ , repr (self .id ))
262269
263- def __eq__ (self , node ):
264- return isinstance (node , Node ) and self .id == node .id
270+ def __eq__ (self , other ):
271+ return isinstance (other , Node ) and self .id == other .id
272+
273+ def __ne__ (self , other ):
274+ return not self .__eq__ (other )
275+
276+ def __lt__ (self , other ):
277+ return isinstance (other , Node ) and self .id < other .id
265278
266- def __ne__ (self , node ):
267- return not self .__eq__ (node )
279+ def __hash__ (self ):
280+ # an alternative might be to use hash(self.id) in some way
281+ # since this is supposed to be unique.
282+ return id (self )
268283
269284#--- NODE LINKS ----------------------------------------------------------
270285
@@ -1181,7 +1196,7 @@ def partition(graph):
11811196 g [i ] = union (g [i ], g [j ])
11821197 g [j ] = []
11831198 g = [graph .copy (nodes = [graph [id ] for id in n ]) for n in g if n ]
1184- g .sort (lambda a , b : len ( b ) - len ( a ) )
1199+ g .sort (key = len , reverse = True )
11851200 return g
11861201
11871202
0 commit comments