Changeset 7974:5b7902ce9e61 in orange


Ignore:
Timestamp:
06/02/11 23:12:23 (3 years ago)
Author:
miha <miha.stajdohar@…>
Branch:
default
Convert:
82a7aebf1119a9326580b8befdad52276f08dfe5
Message:

Refactored to use NetworkX.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Prototypes/OWModelMap.py

    r7953 r7974  
    1212import orange 
    1313import orngVizRank 
    14 import orngNetwork 
    1514import orngStat 
    1615 
     
    1918 
    2019from orngScaleLinProjData import * 
    21 from OWNetExplorer import * 
    22 from OWNetworkCanvas import * 
     20from OWNxExplorer import * 
     21from OWNxCanvas import * 
    2322from OWkNNOptimization import OWVizRank 
    24 from OWNetworkHist import * 
     23from OWNxHist import * 
    2524from OWDistributions import OWDistributionGraph 
    2625 
     
    155154                    painter.drawImage(QRect(pX - size/2, pY - size/2, size, size), vertex.image) 
    156155                     
    157 class OWModelMapCanvas(OWNetworkCanvas): 
     156class OWModelMapCanvas(OWNxCanvas): 
    158157     
    159158    def __init__(self, master, parent=None, name="None"): 
    160         OWNetworkCanvas.__init__(self, master, parent, name) 
     159        OWNxCanvas.__init__(self, master, parent, name) 
    161160        self.networkCurve = ModelCurve(self) 
    162161        self.selectionNeighbours = 1 
     
    167166         
    168167    def mouseMoveEvent(self, event): 
    169         if not self.visualizer: 
    170             return 
     168        if not self.graph: 
     169          return 
    171170         
    172171        if self.plotAccuracy or self.vizAttributes: 
     
    200199                self.drawPlotItems() 
    201200        else: 
    202             OWNetworkCanvas.mouseMoveEvent(self, event) 
     201            OWNxCanvas.mouseMoveEvent(self, event) 
    203202         
    204203    def drawToolTips(self): 
     
    212211                continue 
    213212             
    214             clusterCA = self.visualizer.graph.items[vertex.index]["cluster CA"].value 
     213            clusterCA = self.graph.items()[vertex.index]["cluster CA"].value 
    215214            if type(clusterCA) == type(1.): clusterCA = "%.4g" % clusterCA  
    216215             
    217             x1 = self.visualizer.network.coors[0][vertex.index] 
    218             y1 = self.visualizer.network.coors[1][vertex.index] 
    219             lbl  = "%s\n" % self.visualizer.graph.items[vertex.index]["label"].value 
    220             lbl += "CA: %.4g\n" % self.visualizer.graph.items[vertex.index]["CA"].value 
    221             #lbl += "AUC: %.4g\n" % self.visualizer.graph.items[vertex.index]["AUC"].value 
     216            x1 = self.layout.coors[0][vertex.index] 
     217            y1 = self.layout.coors[1][vertex.index] 
     218            lbl  = "%s\n" % self.graph.items()[vertex.index]["label"].value 
     219            lbl += "CA: %.4g\n" % self.graph.items()[vertex.index]["CA"].value 
     220            #lbl += "AUC: %.4g\n" % self.graph.items()[vertex.index]["AUC"].value 
    222221            #lbl += "CA best: %s\n" % clusterCA  
    223             lbl += "Attributes: %d\n" % len(self.visualizer.graph.items[vertex.index]["attributes"].value.split(", ")) 
    224             lbl += ", ".join(sorted(self.visualizer.graph.items[vertex.index]["attributes"].value.split(", "))) 
     222            lbl += "Attributes: %d\n" % len(self.graph.items()[vertex.index]["attributes"].value.split(", ")) 
     223            lbl += ", ".join(sorted(self.graph.items()[vertex.index]["attributes"].value.split(", "))) 
    225224            self.tips.addToolTip(x1, y1, lbl) 
    226225            self.tooltipKeys[vertex.index] = len(self.tips.texts) - 1 
     
    236235     
    237236    def loadIcons(self): 
    238         items = self.visualizer.graph.items 
     237        items = self.graph.items() 
    239238        maxsize = str(max(map(int, ICON_SIZES))) 
    240239        minsize = min(map(int, ICON_SIZES)) 
     
    250249            v.image = QImage(MODEL_IMAGES[imageKey]) 
    251250 
    252     def addVisualizer(self, networkOptimization): 
    253         OWNetworkCanvas.addVisualizer(self, networkOptimization, ModelCurve(self)) 
    254  
    255 class OWModelMap(OWNetExplorer, OWNetworkHist): 
     251    def set_graph_layout(self, graph, layout): 
     252        OWNxCanvas.set_graph_layout(self, graph, layout, ModelCurve(self)) 
     253 
     254class OWModelMap(OWNxExplorer, OWNxHist): 
    256255    settingsList = ["vertexSize", "lastSizeAttribute", "lastColorAttribute",  
    257256                    "maxVertexSize", "minVertexSize", "tabIndex",  
     
    271270     
    272271    def __init__(self, parent=None, signalManager=None, name="Model Map"): 
    273         OWNetExplorer.__init__(self, parent, signalManager, name,  
     272        OWNxExplorer.__init__(self, parent, signalManager, name,  
    274273                               NetworkCanvas=OWModelMapCanvas) 
    275274         
     
    350349        self.predGraph.setAxisScale(QwtPlot.yLeft, -0.5, len(self.matrix.originalData.domain.classVar.values) - 0.5, 1) 
    351350         
    352         scores = [[float(ca) for ca in ex["CA by class"].value.split(", ")] for ex in self.graph.items.getitems(vertices)] 
     351        scores = [[float(ca) for ca in ex["CA by class"].value.split(", ")] for ex in self.graph.items().getitems(vertices)] 
    353352        scores = [sum(score) / len(score) for score in zip(*scores)] 
    354353         
     
    374373            return 
    375374         
    376         attrList = [self.graph.items[v]["attributes"].value.split(", ") for v in vertices] 
     375        attrList = [self.graph.items()[v]["attributes"].value.split(", ") for v in vertices] 
    377376         
    378377        attrIntersection = set(attrList[0]) 
     
    431430            ex["attributes"] = ", ".join(sorted(ex["attributes"].value.split(", "))) 
    432431             
    433         OWNetworkHist.setMatrix(self, matrix) 
     432        OWNxHist.setMatrix(self, matrix) 
    434433         
    435434    def setVertexSize(self): 
    436         OWNetExplorer.setVertexSize(self) 
     435        OWNxExplorer.setVertexSize(self) 
    437436        self.networkCanvas.loadIcons() 
    438437        self.networkCanvas.replot() 
     
    440439    def setVertexStyle(self): 
    441440        for v in self.networkCanvas.vertices: 
    442             auc = self.graph.items[v.index] 
     441            auc = self.graph.items()[v.index] 
    443442            v.style = 1 #auc             
    444443         
     
    446445        self.warning() 
    447446         
    448         if self.graph is None or self.graph.items is None or self.graph_matrix is None: 
     447        if self.graph is None or self.graph.items() is None or self.graph_matrix is None: 
    449448            self.send("Model", None) 
    450449            self.send("Selected Models", None) 
    451450            return 
    452451         
    453         if self.graph.nVertices != self.graph_matrix.dim: 
     452        if self.graph.number_of_nodes() != self.graph_matrix.dim: 
    454453            self.warning('Network items and matrix results not of equal length.') 
    455454            self.send("Model", None) 
     
    460459         
    461460        if len(selection) == 1: 
    462             modelInstance = self.graph.items[selection[0]] 
     461            modelInstance = self.graph.items()[selection[0]] 
    463462            # modelInfo - Python Dict; keys: method, classifier, probabilities, 
    464463            # results, XAnchors, YAnchors, attributes 
    465             modelInfo = self.graph_matrix.results[selection[0]] 
     464            modelInfo = self.graph_matrix.results[modelInstance['uuid'].value] 
    466465            uuid = modelInstance["uuid"].value 
    467466            #method, vizr_result, projection_points, classifier, attrs = self.matrix.results[uuid] 
     
    479478                 
    480479            self.send("Model", modelInstance) 
    481             self.send("Selected Models", self.graph.items.getitems(selection)) 
     480            self.send("Selected Models", self.graph.items().getitems(selection)) 
    482481        elif len(selection) > 1:  
    483482            self.send("Model", None) 
    484             self.send("Selected Models", self.graph.items.getitems(selection)) 
     483            self.send("Selected Models", self.graph.items().getitems(selection)) 
    485484        else: 
    486485            self.send("Model", None) 
     
    498497             
    499498    def setVertexColor(self): 
    500         if self.optimization is None or self.networkCanvas is None: 
     499        if self.graph is None: 
    501500            return 
    502501         
     
    510509            return 
    511510         
    512         self.setGraph(self.graph) 
    513         self.setVertexDistance(self.graph_matrix) 
     511        self.set_graph(self.graph) 
     512        self.set_items_distance_matrix(self.graph_matrix) 
    514513        # TODO clickedAttLstBox -> setLabelText(["attributes"] 
    515514         
    516         for i, ex in enumerate(self.graph.items): 
     515        for i, ex in enumerate(self.graph.items()): 
    517516            self.networkCanvas.vertices[i].uuid = ex["uuid"].value 
    518517         
Note: See TracChangeset for help on using the changeset viewer.