Changeset 8081:922aa219574d in orange
 Timestamp:
 07/05/11 17:34:08 (3 years ago)
 Branch:
 default
 Convert:
 e685194341d7c07496b852f3cd5d63ead71c801d
 Location:
 orange/OrangeWidgets/Unsupervised
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

orange/OrangeWidgets/Unsupervised/OWNxCanvas.py
r8061 r8081 15 15 from orngScaleScatterPlotData import * 16 16 17 class N etworkVertex():17 class NodeItem(): 18 18 def __init__(self, index=1): 19 19 self.index = index … … 34 34 self.style = 1 35 35 36 class NetworkEdge():36 class EdgeItem(): 37 37 def __init__(self, u=None, v=None, weight=0, arrowu=0, arrowv=0, 38 38 links_index=None, label=[]): … … 52 52 QwtPlotCurve.__init__(self, "Network Curve") 53 53 54 self.coors = None55 self.vertices = []54 self.coors = {} 55 self.vertices = {} 56 56 self.edges = [] 57 57 self.setItemAttribute(QwtPlotItem.Legend, 0) 58 58 self.showEdgeLabels = 0 59 59 60 def move SelectedVertices(self, dx, dy):61 selected = self.get SelectedVertices()60 def move_selected_nodes(self, dx, dy): 61 selected = self.get_selected_nodes() 62 62 63 63 self.coors[0][selected] = self.coors[0][selected] + dx … … 67 67 return selected 68 68 69 def set VertexColor(self, v, color):69 def set_node_color(self, v, color): 70 70 pen = self.vertices[v].pen 71 71 self.vertices[v].color = color 72 72 self.vertices[v].pen = QPen(color, pen.width()) 73 73 74 def set EdgeColor(self, index, color, nocolor=0):74 def set_edge_color(self, index, color, nocolor=0): 75 75 pen = self.edges[index].pen 76 76 if nocolor: … … 79 79 self.edges[index].pen.setCapStyle(Qt.RoundCap) 80 80 81 def get SelectedVertices(self):82 return [vertex.index for vertex in self.vertices if vertex.selected]83 84 def get UnselectedVertices(self):85 return [vertex.index for vertex in self.vertices if not vertex.selected]86 87 def get MarkedVertices(self):88 return [vertex.index for vertex in self.vertices if vertex.marked]81 def get_selected_nodes(self): 82 return [vertex.index for vertex in self.vertices.itervalues() if vertex.selected] 83 84 def get_unselected_nodes(self): 85 return [vertex.index for vertex in self.vertices.itervalues() if not vertex.selected] 86 87 def get_marked_nodes(self): 88 return [vertex.index for vertex in self.vertices.itervalues() if vertex.marked] 89 89 90 def set MarkedVertices(self, vertices):91 for vertex in self.vertices :90 def set_marked_nodes(self, vertices): 91 for vertex in self.vertices.itervalues(): 92 92 if vertex.index in vertices: 93 93 vertex.marked = True … … 95 95 vertex.marked = False 96 96 97 def mark ToSel(self):98 for vertex in self.vertices :97 def mark_to_sel(self): 98 for vertex in self.vertices.itervalues(): 99 99 if vertex.marked == True: 100 100 vertex.selected = True 101 101 102 def sel ToMark(self):103 for vertex in self.vertices :102 def sel_to_mark(self): 103 for vertex in self.vertices.itervalues(): 104 104 if vertex.selected == True: 105 105 vertex.selected = False 106 106 vertex.marked = True 107 107 108 def un Mark(self):109 for vertex in self.vertices :108 def unmark(self): 109 for vertex in self.vertices.itervalues(): 110 110 vertex.marked = False 111 111 112 def un Select(self):113 for vertex in self.vertices :112 def unselect(self): 113 for vertex in self.vertices.itervalues(): 114 114 vertex.selected = False 115 115 116 def set HiddenVertices(self, nodes):117 for vertex in self.vertices :116 def set_hidden_nodes(self, nodes): 117 for vertex in self.vertices.itervalues(): 118 118 if vertex.index in nodes: 119 119 vertex.show = False … … 121 121 vertex.show = True 122 122 123 def hide SelectedVertices(self):124 for vertex in self.vertices :123 def hide_selected_nodes(self): 124 for vertex in self.vertices.itervalues(): 125 125 if vertex.selected: 126 126 vertex.show = False 127 127 128 def hide UnSelectedVertices(self):129 for vertex in self.vertices :128 def hide_unselected_nodes(self): 129 for vertex in self.vertices.itervalues(): 130 130 if not vertex.selected: 131 131 vertex.show = False 132 132 133 def show AllVertices(self):134 for vertex in self.vertices :133 def show_all_vertices(self): 134 for vertex in self.vertices.itervalues(): 135 135 vertex.show = True 136 136 … … 143 143 painter.setPen(edge.pen) 144 144 145 px1 = xMap.transform(self.coors[ 0][edge.u.index]) #ali pa tudi self.x1, itd146 py1 = yMap.transform(self.coors[ 1][edge.u.index])147 px2 = xMap.transform(self.coors[ 0][edge.v.index])148 py2 = yMap.transform(self.coors[ 1][edge.v.index])145 px1 = xMap.transform(self.coors[edge.u.index][0]) #ali pa tudi self.x1, itd 146 py1 = yMap.transform(self.coors[edge.u.index][1]) 147 px2 = xMap.transform(self.coors[edge.v.index][0]) 148 py2 = yMap.transform(self.coors[edge.v.index][1]) 149 149 150 150 painter.drawLine(px1, py1, px2, py2) … … 185 185 painter.drawText(r, Qt.AlignHCenter + Qt.AlignVCenter, lbl) 186 186 187 for vertex in self.vertices:187 for key, vertex in self.vertices.iteritems(): 188 188 if vertex.show: 189 pX = xMap.transform(self.coors[ 0][vertex.index]) #dobimo koordinati v pikslih (tipa integer)190 pY = yMap.transform(self.coors[ 1][vertex.index]) #ki se stejeta od zgornjega levega kota canvasa189 pX = xMap.transform(self.coors[vertex.index][0]) #dobimo koordinati v pikslih (tipa integer) 190 pY = yMap.transform(self.coors[vertex.index][1]) #ki se stejeta od zgornjega levega kota canvasa 191 191 if vertex.selected: 192 192 painter.setPen(QPen(Qt.yellow, 3)) … … 205 205 painter.drawEllipse(rect) 206 206 207 208 def closest_node(self, px, py): 209 ndx = min(self.coors, key=lambda x: abs(self.coors[x][0]px) + abs(self.coors[x][1]py)) 210 return ndx, math.sqrt((self.coors[ndx][0]px)**2 + (self.coors[ndx][0]px)**2) 211 212 def get_nodes_in_rect(self, x1, y1, x2, y2): 213 if x1 > x2: 214 x1, x2 = x2, x1 215 if y1 > y2: 216 y1, y2 = y2, y1 217 return [key for key in self.coors if x1 < self.coors[key][0] < x2 and y1 < self.coors[key][1] < y2] 218 207 219 class OWNxCanvas(OWGraph): 208 220 def __init__(self, master, parent=None, name="None"): … … 212 224 self.labelText = [] 213 225 self.tooltipText = [] 214 self.vertices_old = {} # distionary of nodes (orngIndex: vertex_objekt)215 self.edges_old = {} # distionary of edges (curveKey: edge_objekt)216 self.vertices = []217 self.edges = []226 #self.vertices_old = {} # distionary of nodes (orngIndex: vertex_objekt) 227 #self.edges_old = {} # distionary of edges (curveKey: edge_objekt) 228 #self.vertices = [] 229 #self.edges = [] 218 230 self.indexPairs = {} # distionary of type CurveKey: orngIndex (for nodes) 219 231 #self.selection = [] # list of selected nodes (indices) … … 278 290 279 291 def getSelection(self): 280 return self.networkCurve.get SelectedVertices()281 282 def get MarkedVertices(self):283 return self.networkCurve.get MarkedVertices()292 return self.networkCurve.get_selected_nodes() 293 294 def get_marked_nodes(self): 295 return self.networkCurve.get_marked_nodes() 284 296 285 297 def getVertexSize(self, index): 286 298 return 6 287 299 288 def set HiddenVertices(self, nodes):289 self.networkCurve.set HiddenVertices(nodes)290 291 def hide SelectedVertices(self):292 self.networkCurve.hide SelectedVertices()300 def set_hidden_nodes(self, nodes): 301 self.networkCurve.set_hidden_nodes(nodes) 302 303 def hide_selected_nodes(self): 304 self.networkCurve.hide_selected_nodes() 293 305 self.drawPlotItems() 294 306 295 def hide UnSelectedVertices(self):296 self.networkCurve.hide UnSelectedVertices()307 def hide_unselected_nodes(self): 308 self.networkCurve.hide_unselected_nodes() 297 309 self.drawPlotItems() 298 310 299 def show AllVertices(self):300 self.networkCurve.show AllVertices()311 def show_all_vertices(self): 312 self.networkCurve.show_all_vertices() 301 313 self.drawPlotItems() 302 314 … … 329 341 330 342 def markedToSelection(self): 331 self.networkCurve.mark ToSel()343 self.networkCurve.mark_to_sel() 332 344 self.drawPlotItems() 333 345 334 346 def selectionToMarked(self): 335 self.networkCurve.sel ToMark()347 self.networkCurve.sel_to_mark() 336 348 self.drawPlotItems() 337 349 338 350 if self.sendMarkedNodes != None: 339 self.sendMarkedNodes(self.networkCurve.get MarkedVertices())351 self.sendMarkedNodes(self.networkCurve.get_marked_nodes()) 340 352 341 353 def removeSelection(self, replot=True): 342 self.networkCurve.un Select()354 self.networkCurve.unselect() 343 355 344 356 if replot: … … 356 368 357 369 def getSelectedExamples(self): 358 selection = self.networkCurve.get SelectedVertices()370 selection = self.networkCurve.get_selected_nodes() 359 371 360 372 if len(selection) == 0: … … 366 378 return None 367 379 368 def get UnselectedExamples(self):369 unselection = self.networkCurve.get UnselectedVertices()380 def getunselectedExamples(self): 381 unselection = self.networkCurve.get_unselected_nodes() 370 382 371 383 if len(unselection) == 0: … … 378 390 379 391 def getSelectedGraph(self): 380 selection = self.networkCurve.get SelectedVertices()392 selection = self.networkCurve.get_selected_nodes() 381 393 382 394 if len(selection) == 0: … … 387 399 return subnet 388 400 389 def get SelectedVertices(self):390 return self.networkCurve.get SelectedVertices()401 def get_selected_nodes(self): 402 return self.networkCurve.get_selected_nodes() 391 403 392 404 def getNeighboursUpTo(self, ndx, dist): … … 403 415 if not self.freezeNeighbours and self.selectionNeighbours: 404 416 toMark = set() 405 for ndx in self.networkCurve.get SelectedVertices():417 for ndx in self.networkCurve.get_selected_nodes(): 406 418 toMark = self.getNeighboursUpTo(ndx, self.selectionNeighbours) 407 419 408 self.networkCurve.set MarkedVertices(toMark)420 self.networkCurve.set_marked_nodes(toMark) 409 421 self.drawPlotItems() 410 422 411 423 elif not self.freezeNeighbours and self.selectionNeighbours == 0: 412 self.networkCurve.set MarkedVertices(self.networkCurve.getSelectedVertices())424 self.networkCurve.set_marked_nodes(self.networkCurve.get_selected_nodes()) 413 425 self.drawPlotItems() 414 426 415 427 if self.sendMarkedNodes != None: 416 self.sendMarkedNodes(self.networkCurve.get MarkedVertices())417 418 def un Mark(self):419 self.networkCurve.un Mark()428 self.sendMarkedNodes(self.networkCurve.get_marked_nodes()) 429 430 def unmark(self): 431 self.networkCurve.unmark() 420 432 self.drawPlotItems(replot=0) 421 433 … … 423 435 self.sendMarkedNodes([]) 424 436 425 def set MarkedVertices(self, vertices):426 self.networkCurve.set MarkedVertices(vertices)437 def set_marked_nodes(self, vertices): 438 self.networkCurve.set_marked_nodes(vertices) 427 439 self.drawPlotItems(replot=0) 428 440 429 441 if self.sendMarkedNodes != None: 430 self.sendMarkedNodes(self.networkCurve.get MarkedVertices())442 self.sendMarkedNodes(self.networkCurve.get_marked_nodes()) 431 443 432 444 def activateMoveSelection(self): … … 443 455 dx = newX  self.invTransform(2, self.GMmouseMoveEvent.x()) 444 456 dy = newY  self.invTransform(0, self.GMmouseMoveEvent.y()) 445 movedVertices = self.networkCurve.move SelectedVertices(dx, dy)457 movedVertices = self.networkCurve.move_selected_nodes(dx, dy) 446 458 447 459 self.GMmouseMoveEvent.setX(event.pos().x()) #zacetni dogodek postane trenutni … … 457 469 px = self.invTransform(2, event.x()) 458 470 py = self.invTransform(0, event.y()) 459 ndx, mind = self. layout.closest_vertex(px, py)460 dX = self.transform(QwtPlot.xBottom, self. layout.coors[0][ndx])  event.x()461 dY = self.transform(QwtPlot.yLeft, self. layout.coors[1][ndx])  event.y()471 ndx, mind = self.networkCurve.closest_node(px, py) 472 dX = self.transform(QwtPlot.xBottom, self.networkCurve.coors[ndx][0])  event.x() 473 dY = self.transform(QwtPlot.yLeft, self.networkCurve.coors[ndx][1])  event.y() 462 474 # transform to pixel distance 463 475 distance = math.sqrt(dX**2 + dY**2) 464 476 465 if ndx != 1 and distance <= self. vertices[ndx].size / 2:477 if ndx != 1 and distance <= self.networkCurve.vertices[ndx].size: 466 478 toMark = set(self.getNeighboursUpTo(ndx, self.tooltipNeighbours)) 467 self.networkCurve.set MarkedVertices(toMark)479 self.networkCurve.set_marked_nodes(toMark) 468 480 self.drawPlotItems() 469 481 470 482 if self.sendMarkedNodes != None: 471 self.sendMarkedNodes(self.networkCurve.get MarkedVertices())483 self.sendMarkedNodes(self.networkCurve.get_marked_nodes()) 472 484 else: 473 self.networkCurve.un Mark()485 self.networkCurve.unmark() 474 486 self.drawPlotItems() 475 487 … … 478 490 479 491 if self.showDistances: 480 selection = self.networkCurve.get SelectedVertices()492 selection = self.networkCurve.get_selected_nodes() 481 493 if len(selection) > 0: 482 494 px = self.invTransform(2, event.x()) 483 495 py = self.invTransform(0, event.y()) 484 496 485 v, mind = self. layout.closest_vertex(px, py)486 dX = self.transform(QwtPlot.xBottom, self. layout.coors[0][v])  event.x()487 dY = self.transform(QwtPlot.yLeft, self. layout.coors[1][v])  event.y()497 v, mind = self.networkCurve.closest_node(px, py) 498 dX = self.transform(QwtPlot.xBottom, self.networkCurve.coors[v][0])  event.x() 499 dY = self.transform(QwtPlot.yLeft, self.networkCurve.coors[v][1])  event.y() 488 500 # transform to pixel distance 489 501 distance = math.sqrt(dX**2 + dY**2) 490 if v != 1 and distance <= self. vertices[v].size / 2:502 if v != 1 and distance <= self.networkCurve.vertices[v].size: 491 503 if self.items_matrix == None: 492 504 dst = 'vertex distance signal not set' … … 557 569 elif self.mouseSelectedVertex == 0: 558 570 559 selection = self. layout.get_vertices_in_rect(x1, y1, x2, y2)571 selection = self.networkCurve.get_nodes_in_rect(x1, y1, x2, y2) 560 572 561 573 def selectVertex(ndx): 562 if self. vertices[ndx].show:563 self. vertices[ndx].selected = True574 if self.networkCurve.vertices[ndx].show: 575 self.networkCurve.vertices[ndx].selected = True 564 576 565 577 map(selectVertex, selection) … … 567 579 if len(selection) == 0 and x1 == x2 and y1 == y2: 568 580 self.removeSelection() 569 self.un Mark()581 self.unmark() 570 582 571 583 self.markSelectionNeighbours() … … 591 603 592 604 if e.key() == 87 or e.key() == 81: 593 selection = [v.index for v in self. verticesif v.selected]605 selection = [v.index for v in self.networkCurve.vertices.itervalues() if v.selected] 594 606 if len(selection) > 0: 595 607 phi = [math.pi / 180 if e.key() == 87 else math.pi / 180] … … 625 637 py = self.invTransform(0, pos.y()) 626 638 627 ndx, min = self. layout.closest_vertex(px, py)628 dX = self.transform(QwtPlot.xBottom, self. layout.coors[0][ndx])  pos.x()629 dY = self.transform(QwtPlot.yLeft, self. layout.coors[1][ndx])  pos.y()639 ndx, min = self.networkCurve.closest_node(px, py) 640 dX = self.transform(QwtPlot.xBottom, self.networkCurve.coors[ndx][0])  pos.x() 641 dY = self.transform(QwtPlot.yLeft, self.networkCurve.coors[ndx][1])  pos.y() 630 642 # transform to pixel distance 631 643 distance = math.sqrt(dX**2 + dY**2) 632 if ndx != 1 and distance <= self.vertices[ndx].size / 2: 633 return self.vertices[ndx].selected 644 645 #self.networkCurve 646 647 if ndx != 1 and distance <= self.networkCurve.vertices[ndx].size: 648 return self.networkCurve.vertices[ndx].selected 634 649 else: 635 650 return False … … 642 657 py = self.invTransform(0, pos.y()) 643 658 644 ndx, min = self. layout.closest_vertex(px, py)645 dX = self.transform(QwtPlot.xBottom, self. layout.coors[0][ndx])  pos.x()646 dY = self.transform(QwtPlot.yLeft, self. layout.coors[1][ndx])  pos.y()659 ndx, min = self.networkCurve.closest_node(px, py) 660 dX = self.transform(QwtPlot.xBottom, self.networkCurve.coors[ndx][0])  pos.x() 661 dY = self.transform(QwtPlot.yLeft, self.networkCurve.coors[ndx][1])  pos.y() 647 662 # transform to pixel distance 648 663 distance = math.sqrt(dX**2 + dY**2) 649 if ndx != 1 and distance <= self. vertices[ndx].size / 2:664 if ndx != 1 and distance <= self.networkCurve.vertices[ndx].size: 650 665 return True 651 666 else: … … 659 674 py = self.invTransform(0, pos.y()) 660 675 661 ndx, min = self. layout.closest_vertex(px, py)662 663 dX = self.transform(QwtPlot.xBottom, self. layout.coors[0][ndx])  pos.x()664 dY = self.transform(QwtPlot.yLeft, self. layout.coors[1][ndx])  pos.y()676 ndx, min = self.networkCurve.closest_node(px, py) 677 678 dX = self.transform(QwtPlot.xBottom, self.networkCurve.coors[ndx][0])  pos.x() 679 dY = self.transform(QwtPlot.yLeft, self.networkCurve.coors[ndx][1])  pos.y() 665 680 # transform to pixel distance 666 681 distance = math.sqrt(dX**2 + dY**2) 667 if ndx != 1 and distance <= self. vertices[ndx].size / 2:682 if ndx != 1 and distance <= self.networkCurve.vertices[ndx].size: 668 683 if not self.appendToSelection and not self.controlPressed: 669 684 self.removeSelection() 670 685 671 686 if self.insideview: 672 self.networkCurve.un Select()673 self. vertices[ndx].selected = not self.vertices[ndx].selected687 self.networkCurve.unselect() 688 self.networkCurve.vertices[ndx].selected = not self.networkCurve.vertices[ndx].selected 674 689 self.optimize(100) 675 690 676 691 self.markSelectionNeighbours() 677 692 else: 678 self. vertices[ndx].selected = not self.vertices[ndx].selected693 self.networkCurve.vertices[ndx].selected = not self.networkCurve.vertices[ndx].selected 679 694 self.markSelectionNeighbours() 680 695 … … 683 698 return False 684 699 self.removeSelection() 685 self.un Mark()700 self.unmark() 686 701 687 702 def updateData(self): … … 721 736 # edges = [(ind / matrix.dim, ind % matrix.dim) for v, ind in vals] 722 737 # print "number of component edges:", len(edges), "number of components:", len(components) 723 components_c = [(sum(self. layout.coors[0][c]) / len(c), sum(self.layout.coors[1][c]) / len(c)) for c in components]738 components_c = [(sum(self.networkCurve.coors[c][0]) / len(c), sum(self.networkCurve.coors[c][1]) / len(c)) for c in components] 724 739 weights = [1  matrix[u,v] for u,v in edges] 725 740 … … 744 759 745 760 if self.insideview == 1: 746 selection = self.networkCurve.get SelectedVertices()761 selection = self.networkCurve.get_selected_nodes() 747 762 if len(selection) >= 1: 748 763 visible = set() 749 764 visible = set(selection) 750 765 visible = self.getNeighboursUpTo(selection[0], self.insideviewNeighbours) 751 self.networkCurve.set HiddenVertices(set(range(self.graph.number_of_nodes()))  visible)766 self.networkCurve.set_hidden_nodes(set(range(self.graph.number_of_nodes()))  visible) 752 767 753 768 edgesCount = 0 … … 783 798 if len(vertices) > 0: 784 799 for vertex in vertices: 785 x1 = float(self. layout.coors[0][vertex])786 y1 = float(self. layout.coors[1][vertex])800 x1 = float(self.networkCurve.coors[vertex][0]) 801 y1 = float(self.networkCurve.coors[vertex][1]) 787 802 788 803 if vertex in self.markerKeys: … … 826 841 continue 827 842 828 vertices = [vertex for vertex in component if self. vertices[vertex].show]843 vertices = [vertex for vertex in component if self.networkCurve.vertices[vertex].show] 829 844 830 845 if len(vertices) == 0: 831 846 continue 832 847 833 xes = [self. layout.coors[0][vertex] for vertex in vertices]834 yes = [self. layout.coors[1][vertex] for vertex in vertices]848 xes = [self.networkCurve.coors[vertex][0] for vertex in vertices] 849 yes = [self.networkCurve.coors[vertex][1] for vertex in vertices] 835 850 836 851 x1 = sum(xes) / len(xes) … … 847 862 self.tips.removeAll() 848 863 if len(self.tooltipText) > 0: 849 for vertex in self. vertices:864 for vertex in self.networkCurve.vertices.itervalues(): 850 865 if not vertex.show: 851 866 continue 852 867 853 x1 = self. layout.coors[0][vertex.index]854 y1 = self. layout.coors[1][vertex.index]868 x1 = self.networkCurve.coors[vertex.index][0] 869 y1 = self.networkCurve.coors[vertex.index][1] 855 870 lbl = "" 856 871 values = self.graph.items()[vertex.index] … … 875 890 def drawLabels(self): 876 891 if len(self.labelText) > 0: 877 for vertex in self. vertices:892 for vertex in self.networkCurve.vertices.itervalues(): 878 893 if not vertex.show: 879 894 continue … … 882 897 continue 883 898 884 x1 = self. layout.coors[0][vertex.index]885 y1 = self. layout.coors[1][vertex.index]899 x1 = self.networkCurve.coors[vertex.index][0] 900 y1 = self.networkCurve.coors[vertex.index][1] 886 901 lbl = "" 887 902 values = self.graph.items()[vertex.index] … … 900 915 def drawIndexes(self): 901 916 if self.showIndexes: 902 for vertex in self. vertices:917 for vertex in self.networkCurve.vertices.itervalues(): 903 918 if not vertex.show: 904 919 continue … … 907 922 continue 908 923 909 x1 = self. layout.coors[0][vertex.index]910 y1 = self. layout.coors[1][vertex.index]924 x1 = self.networkCurve.coors[vertex.index][0] 925 y1 = self.networkCurve.coors[vertex.index][1] 911 926 912 927 lbl = str(vertex.index) … … 923 938 continue 924 939 925 x1 = (self. layout.coors[0][edge.u.index] + self.layout.coors[0][edge.v.index]) / 2926 y1 = (self. layout.coors[1][edge.u.index] + self.layout.coors[1][edge.v.index]) / 2940 x1 = (self.networkCurve.coors[edge.u.index][0] + self.networkCurve.coors[edge.v.index][0]) / 2 941 y1 = (self.networkCurve.coors[edge.u.index][1] + self.networkCurve.coors[edge.v.index][1]) / 2 927 942 928 943 if edge.weight == None: … … 965 980 return colorIndices, colorIndex, minValue, maxValue 966 981 967 def set EdgeColor(self, attribute):982 def set_edge_color(self, attribute): 968 983 if self.graph is None: 969 984 return … … 986 1001 newColor = self.contEdgePalette[value] 987 1002 988 self.networkCurve.set EdgeColor(index, newColor)1003 self.networkCurve.set_edge_color(index, newColor) 989 1004 990 1005 elif self.graph.links().domain[colorIndex].varType == orange.VarTypes.Discrete: 991 1006 newColor = self.discEdgePalette[colorIndices[self.graph.links()[links_index][colorIndex].value]] 992 1007 if self.graph.links()[links_index][colorIndex].value == "0": 993 self.networkCurve.set EdgeColor(index, newColor, nocolor=1)1008 self.networkCurve.set_edge_color(index, newColor, nocolor=1) 994 1009 else: 995 self.networkCurve.set EdgeColor(index, newColor)1010 self.networkCurve.set_edge_color(index, newColor) 996 1011 997 1012 else: 998 1013 newColor = self.discEdgePalette[0] 999 self.networkCurve.set EdgeColor(index, newColor)1014 self.networkCurve.set_edge_color(index, newColor) 1000 1015 1001 1016 self.replot() 1002 1017 1003 def set VertexColor(self, attribute):1018 def set_node_color(self, attribute): 1004 1019 if self.graph is None: 1005 1020 return … … 1007 1022 colorIndices, colorIndex, minValue, maxValue = self.getColorIndeces(self.graph.items(), attribute, self.discPalette) 1008 1023 1009 for v in range(self.graph.number_of_nodes()): 1024 for key, vertex in self.networkCurve.vertices.iteritems(): 1025 v = vertex.index 1010 1026 if colorIndex != None: 1011 1027 if self.graph.items().domain[colorIndex].varType == orange.VarTypes.Continuous: … … 1019 1035 newColor = self.contPalette[value] 1020 1036 1021 self.networkCurve.set VertexColor(v, newColor)1037 self.networkCurve.set_node_color(v, newColor) 1022 1038 1023 1039 elif self.graph.items().domain[colorIndex].varType == orange.VarTypes.Discrete: 1024 1040 newColor = self.discPalette[colorIndices[self.graph.items()[v][colorIndex].value]] 1025 1041 #print newColor 1026 self.networkCurve.set VertexColor(v, newColor)1042 self.networkCurve.set_node_color(v, newColor) 1027 1043 1028 1044 else: 1029 1045 newColor = self.discPalette[0] 1030 self.networkCurve.set VertexColor(v, newColor)1046 self.networkCurve.set_node_color(v, newColor) 1031 1047 1032 1048 self.replot() … … 1070 1086 self.clear() 1071 1087 self.vertexDegree = [] 1072 self.vertices_old = {}1073 self.vertices = []1074 self.edges_old = {}1075 self.edges = []1088 #self.vertices_old = {} 1089 #self.vertices = [] 1090 #self.edges_old = {} 1091 #self.edges = [] 1076 1092 self.minEdgeWeight = sys.maxint 1077 1093 self.maxEdgeWeight = 0 … … 1095 1111 1096 1112 #add nodes 1097 self.vertices_old = [(None, []) for v in self.graph]1098 self.vertices = [NetworkVertex(v) for v in self.graph]1113 #self.vertices_old = [(None, []) for v in self.graph] 1114 vertices = dict((v, NodeItem(v)) for v in self.graph) 1099 1115 1100 1116 #build edge index … … 1118 1134 1119 1135 if self.graph.is_directed(): 1120 self.edges = [NetworkEdge(self.vertices[i], self.vertices[j],1136 edges = [EdgeItem(vertices[i], vertices[j], 1121 1137 graph[i][j].get('weight', 1), 0, 1, links_index, label) for \ 1122 1138 ((i, j), links_index, label) in zip(self.graph.edges(), \ 1123 1139 links_indices, labels)] 1124 1140 else: 1125 self.edges = [NetworkEdge(self.vertices[i], self.vertices[j],1141 edges = [EdgeItem(vertices[i], vertices[j], 1126 1142 graph[i][j].get('weight', 1), links_index, label) for \ 1127 1143 ((i, j), links_index, label) in zip(self.graph.edges(), \ 1128 1144 links_indices, labels)] 1129 1145 elif self.graph.is_directed(): 1130 self.edges = [NetworkEdge(self.vertices[i], self.vertices[j],1146 edges = [EdgeItem(vertices[i], vertices[j], 1131 1147 graph[i][j].get('weight', 1), 0, 1) for (i, j) in self.graph.edges()] 1132 1148 else: 1133 self.edges = [NetworkEdge(self.vertices[i], self.vertices[j],1149 edges = [EdgeItem(vertices[i], vertices[j], 1134 1150 graph[i][j].get('weight', 1)) for (i, j) in self.graph.edges()] 1135 1151 1136 self.minEdgeWeight = min(edge.weight for edge in self.edges) if len(self.edges) > 0 else 01137 self.maxEdgeWeight = max(edge.weight for edge in self.edges) if len(self.edges) > 0 else 01152 self.minEdgeWeight = min(edge.weight for edge in edges) if len(edges) > 0 else 0 1153 self.maxEdgeWeight = max(edge.weight for edge in edges) if len(edges) > 0 else 0 1138 1154 1139 1155 if self.minEdgeWeight is None: … … 1148 1164 self.setVerticesSize() 1149 1165 1150 self.networkCurve.coors = self.layout. coors1151 self.networkCurve.vertices = self.vertices1152 self.networkCurve.edges = self.edges1166 self.networkCurve.coors = self.layout.map_to_graph(self.graph) 1167 self.networkCurve.vertices = vertices 1168 self.networkCurve.edges = edges 1153 1169 self.networkCurve.changed() 1154 1170 … … 1159 1175 #print 'minEdgeWeight',self.minEdgeWeight 1160 1176 k = (self.maxEdgeSize  1) / (self.maxEdgeWeight  self.minEdgeWeight) 1161 for edge in self. edges:1177 for edge in self.networkCurve.edges: 1162 1178 if edge.weight == None: 1163 1179 size = 1 … … 1172 1188 edge.pen.setCapStyle(Qt.RoundCap) 1173 1189 else: 1174 for edge in self. edges:1190 for edge in self.networkCurve.edges: 1175 1191 edge.pen = QPen(edge.pen.color(), 1) 1176 1192 edge.pen.setCapStyle(Qt.RoundCap) … … 1205 1221 1206 1222 if inverted: 1207 for vertex in self.vertices:1223 for key, vertex in self.networkCurve.vertices.iteritems(): 1208 1224 if column in self.graph.items().domain: 1209 1225 vertex.size = self.maxVertexSize  ((getValue(self.graph.items()[vertex.index][column])  minVertexWeight) * k) … … 1214 1230 vertex.pen.setWidthF(1 + float(vertex.size) / 20) 1215 1231 else: 1216 for vertex in self.vertices:1232 for key, vertex in self.networkCurve.vertices.iteritems(): 1217 1233 if column in self.graph.items().domain: 1218 1234 vertex.size = (getValue(self.graph.items()[vertex.index][column])  minVertexWeight) * k + self.minVertexSize … … 1223 1239 vertex.pen.setWidthF(1 + float(vertex.size) / 20) 1224 1240 else: 1225 for vertex in self.vertices:1241 for key, vertex in self.networkCurve.vertices.iteritems(): 1226 1242 vertex.size = self.maxVertexSize 1227 1243 vertex.pen.setWidthF(1 + float(vertex.size) / 20) … … 1239 1255 1240 1256 def zoomSelection(self): 1241 selection = self.networkCurve.get SelectedVertices()1257 selection = self.networkCurve.get_selected_nodes() 1242 1258 if len(selection) > 0: 1243 x = [self. layout.coors[0][v] for v in selection]1244 y = [self. layout.coors[1][v] for v in selection]1259 x = [self.networkCurve.coors[v][0] for v in selection] 1260 y = [self.networkCurve.coors[v][1] for v in selection] 1245 1261 1246 1262 oldXMin = self.axisScaleDiv(QwtPlot.xBottom).interval().minValue() 
orange/OrangeWidgets/Unsupervised/OWNxExplorer.py
r8061 r8081 45 45 OWWidget.__init__(self, parent, signalManager, name) 46 46 #self.contextHandlers = {"": DomainContextHandler("", [ContextField("attributes", selected="markerAttributes"), ContextField("attributes", selected="tooltipAttributes"), "color"])} 47 self.inputs = [("Network", Orange.network.Graph, self.set_graph, Default), 47 self.inputs = [("Network", Orange.network.Graph, self.set_graph, Default), 48 ("Nx View", Orange.network.NxView, self.set_network_view), 48 49 ("Items", Orange.data.Table, self.setItems), 49 50 ("Items to Mark", Orange.data.Table, self.markItems), … … 116 117 self.number_of_nodes_label = 1 117 118 self.number_of_edges_label = 1 119 self._items = None 120 self._links = None 118 121 self.loadSettings() 119 122 123 self._network_view = None 120 124 self.layout = Orange.network.GraphLayout() 121 125 self.graph = None … … 1216 1220 self.number_of_nodes_label = 1 1217 1221 self.number_of_edges_label = 1 1218 return 1222 self._items = None 1223 self._links = None 1224 return 1225 1226 self._items = graph.items() 1227 self._links = graph.links() 1228 1229 if self._network_view is not None: 1230 graph = self._network_view.init_network(graph) 1231 1219 1232 1220 1233 #print "OWNetwork/setGraph: new visualizer..." 1221 1234 self.graph = graph 1222 1235 1223 if graph.items() is not None and 'x' in graph.items().domain and 'y' in graph.items().domain: 1224 positions = [(ex['x'].value, ex['y'].value) for ex in graph.items() if ex['x'].value != '?' and ex['y'].value != '?'] 1236 if self._items is not None and 'x' in self._items.domain and 'y' in self._items.domain: 1237 positions = [(self._items[node]['x'].value, self._items[node]['y'].value) \ 1238 for node in sorted(graph) if self._items[node]['x'].value != '?' \ 1239 and self._items[node]['y'].value != '?'] 1225 1240 self.layout.set_graph(graph, positions) 1226 1241 else: … … 1318 1333 self.graph_layout() 1319 1334 self.information(0) 1320 #self.controlArea.setEnabled(True) 1321 self.networkCanvas.updateCanvas() 1335 #self.networkCanvas.updateCanvas() 1336 1337 def set_network_view(self, nxView): 1338 self._network_view = nxView 1339 self.set_graph(self.graph) 1322 1340 1323 1341 def setItems(self, items=None): … … 1336 1354 self.networkCanvas.showIndexes = self.showIndexes 1337 1355 self.networkCanvas.showWeights = self.showWeights 1338 self.networkCanvas.showEdgeLabels = self.showEdgeLabels 1356 self.networkCanvas.showEdgeLabels = self.showEdgeLabels 1339 1357 self.setCombos() 1340 1358 self.networkCanvas.updateData() … … 1483 1501 1484 1502 self.optButton.setChecked(False) 1503 self.networkCanvas.networkCurve.coors = self.layout.map_to_graph(self.graph) 1485 1504 self.networkCanvas.updateCanvas() 1486 1505 qApp.processEvents() … … 1548 1567 iteration += 1 1549 1568 qApp.processEvents() 1569 self.networkCanvas.networkCurve.coors = self.layout.map_to_graph(self.graph) 1550 1570 self.networkCanvas.updateCanvas() 1551 1571 … … 1555 1575 initTemp = self.layout.fr(o, initTemp, coolFactor, weighted) 1556 1576 qApp.processEvents() 1577 self.networkCanvas.networkCurve.coors = self.layout.map_to_graph(self.graph) 1557 1578 self.networkCanvas.updateCanvas() 1558 1579 else: … … 1564 1585 iteration += 1 1565 1586 qApp.processEvents() 1587 self.networkCanvas.networkCurve.coors = self.layout.map_to_graph(self.graph) 1566 1588 self.networkCanvas.updateCanvas() 1567 1589 … … 1670 1692 return 1671 1693 1672 self.networkCanvas.set VertexColor(self.colorCombo.currentText())1694 self.networkCanvas.set_node_color(self.colorCombo.currentText()) 1673 1695 self.lastColorColumn = self.colorCombo.currentText() 1674 1696 self.networkCanvas.updateData() … … 1679 1701 return 1680 1702 1681 self.networkCanvas.set EdgeColor(self.edgeColorCombo.currentText())1703 self.networkCanvas.set_edge_color(self.edgeColorCombo.currentText()) 1682 1704 self.lastEdgeColorColumn = self.edgeColorCombo.currentText() 1683 1705 self.networkCanvas.updateData()
Note: See TracChangeset
for help on using the changeset viewer.