Changeset 8707:8ca44f2c8145 in orange
 Timestamp:
 08/14/11 15:58:35 (3 years ago)
 Branch:
 default
 Convert:
 4339987af6ee1c99fb381d681fffac0077342698
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/OrangeWidgets/Visualize Qt/OWNxCanvasQt.py
r8700 r8707 101 101 self.items = None 102 102 self.links = None 103 self.edge_to_row = None 103 104 104 105 self.node_label_attributes = [] … … 281 282 return 282 283 283 colorIndices, colorIndex, minValue, maxValue = self.getColorIndeces(self. items, attribute, self.discPalette)284 colorIndices, colorIndex, minValue, maxValue = self.getColorIndeces(self.links, attribute, self.discPalette) 284 285 colors = [] 285 286 286 if colorIndex is not None and self. items.domain[colorIndex].varType == orange.VarTypes.Continuous and minValue == maxValue:287 if colorIndex is not None and self.links.domain[colorIndex].varType == orange.VarTypes.Continuous and minValue == maxValue: 287 288 colors = [self.discEdgePalette[0] for edge in self.networkCurve.edge_indices()] 288 289 289 elif colorIndex is not None and self. items.domain[colorIndex].varType == orange.VarTypes.Continuous:290 elif colorIndex is not None and self.links.domain[colorIndex].varType == orange.VarTypes.Continuous: 290 291 #colors.update((v, self.contPalette[(float(self.items[v][colorIndex].value)  minValue) / (maxValue  minValue)]) 291 292 # if str(self.items[v][colorIndex].value) != '?' else 292 293 # (v, self.discPalette[0]) for v in nodes) 293 294 print "TODO set continuous color" 294 elif colorIndex is not None and self. items.domain[colorIndex].varType == orange.VarTypes.Discrete:295 elif colorIndex is not None and self.links.domain[colorIndex].varType == orange.VarTypes.Discrete: 295 296 #colors.update((v, self.discPalette[colorIndices[self.items[v][colorIndex].value]]) for v in nodes) 296 297 print "TODO set discrete color" 298 colors = [self.discEdgePalette[colorIndices[self.links[edge.links_index][colorIndex].value]] for edge in self.networkCurve.edges()] 297 299 else: 298 300 colors = [self.discEdgePalette[0] for edge in self.networkCurve.edge_indices()] … … 347 349 self.items[node][att]) for att in tooltip_attributes)) \ 348 350 for node in self.graph)) 349 351 350 352 def change_graph(self, newgraph): 351 353 old_nodes = set(self.graph.nodes_iter()) … … 370 372 nodes = self.networkCurve.nodes() 371 373 372 #build edge index373 row_ind = {}374 if self.links is not None and len(self.links) > 0:375 for i, r in enumerate(self.links):376 u = int(r['u'].value)377 v = int(r['v'].value)378 if u in self.graph and v in self.graph:379 u_dict = row_ind.get(u, {})380 v_dict = row_ind.get(v, {})381 u_dict[v] = i382 v_dict[u] = i383 row_ind[u] = u_dict384 row_ind[v] = v_dict385 386 374 #add edges 387 375 new_edges = self.graph.edges(add_nodes) … … 389 377 if self.links is not None and len(self.links) > 0: 390 378 links = self.links 391 links_indices = (row_ind[i + 1][j + 1] for (i, j) in new_edges) 392 labels = ([str(row[r].value) for r in range(2, len(row))] for row \ 393 in (links[links_index] for links_index in links_indices)) 379 links_indices = (self.edge_to_row[i + 1][j + 1] for (i, j) in new_edges) 394 380 395 381 if self.graph.is_directed(): 396 382 edges = [EdgeItem(nodes[i], nodes[j], 397 self.graph[i][j].get('weight', 1), 0, 1, links_index, label,\398 parent=self.networkCurve) for ((i, j), links_index , label) in \399 zip(new_edges, links_indices , labels)]383 self.graph[i][j].get('weight', 1), 0, 1, links_index, \ 384 parent=self.networkCurve) for ((i, j), links_index) in \ 385 zip(new_edges, links_indices)] 400 386 else: 401 387 edges = [EdgeItem(nodes[i], nodes[j], 402 self.graph[i][j].get('weight', 1), links_index , label) for \403 ((i, j), links_index , label) in zip(new_edges, \404 links_indices, labels,parent=self.networkCurve)]388 self.graph[i][j].get('weight', 1), links_index) for \ 389 ((i, j), links_index) in zip(new_edges, \ 390 links_indices, parent=self.networkCurve)] 405 391 elif self.graph.is_directed(): 406 392 edges = [EdgeItem(nodes[i], nodes[j], self.graph[i][j].get('weight', 1), \ … … 441 427 self.networkCurve.set_nodes(vertices) 442 428 443 #build edge index444 row_ind= {}429 #build edge to row index 430 self.edge_to_row = {} 445 431 if self.links is not None and len(self.links) > 0: 446 for i, r in enumerate(self.links): 447 u = int(r['u'].value) 448 v = int(r['v'].value) 449 if u in self.graph and v in self.graph: 450 u_dict = row_ind.get(u, {}) 451 v_dict = row_ind.get(v, {}) 452 u_dict[v] = i 453 v_dict[u] = i 454 row_ind[u] = u_dict 455 row_ind[v] = v_dict 432 for i, r in enumerate(self.links): 433 u = int(r['u'].value) 434 v = int(r['v'].value) 435 if u  1 in self.graph and v  1 in self.graph: 436 u_dict = self.edge_to_row.get(u, {}) 437 v_dict = self.edge_to_row.get(v, {}) 438 u_dict[v] = i 439 v_dict[u] = i 440 self.edge_to_row[u] = u_dict 441 self.edge_to_row[v] = v_dict 442 else: 443 print 'could not find edge', u, v 456 444 457 445 #add edges 458 446 if self.links is not None and len(self.links) > 0: 459 447 links = self.links 460 links_indices = (row_ind[i + 1][j + 1] for (i, j) in self.graph.edges()) 461 labels = ([str(row[r].value) for r in range(2, len(row))] for row in (links[links_index] for links_index in links_indices)) 448 links_indices = (self.edge_to_row[i + 1][j + 1] for (i, j) in self.graph.edges()) 462 449 463 450 if self.graph.is_directed(): 464 451 edges = [EdgeItem(vertices[i], vertices[j], 465 graph[i][j].get('weight', 1), 0, 1, links_index, label, parent=self.networkCurve) for\466 ((i, j), links_index, label) in zip(self.graph.edges(),\467 links_indices, labels)]452 graph[i][j].get('weight', 1), 0, 1, links_index, \ 453 parent=self.networkCurve) for ((i, j), links_index) in \ 454 zip(self.graph.edges(), links_indices)] 468 455 else: 469 456 edges = [EdgeItem(vertices[i], vertices[j], 470 graph[i][j].get('weight', 1), links_index, label, parent=self.networkCurve) for \ 471 ((i, j), links_index, label) in zip(self.graph.edges(), \ 472 links_indices, labels)] 457 graph[i][j].get('weight', 1), links_index, \ 458 parent=self.networkCurve) for ((i, j), links_index) in \ 459 zip(self.graph.edges(), links_indices)] 460 473 461 elif self.graph.is_directed(): 474 462 edges = [EdgeItem(vertices[i], vertices[j],
Note: See TracChangeset
for help on using the changeset viewer.