Commits

Miha Stajdohar  committed b649b74

Plot accuracy and attribute intersection features back.

  • Participants
  • Parent commits f2263e6

Comments (0)

Files changed (1)

File _modelmaps/widgets/OWModelMap.py

 <priority>6520</priority>
 """
 import os.path
+from operator import itemgetter
 
 import OWToolbars
 import OWColorPalette
-import OWNxCanvasQt
 
 from Orange import classification, data, feature, misc, modelmaps
+from OWNxCanvasQt import OWNxCanvas
 
 from orngScaleLinProjData import *
 from OWNxExplorer import *
                     size = vertex.image.size().width()
                     painter.drawImage(QRect(pX - size / 2, pY - size / 2, size, size), vertex.image)
 
-class OWModelMapCanvas(OWNxCanvasQt.OWNxCanvas):
+class OWModelMapCanvas(OWNxCanvas):
 
     def __init__(self, master, parent=None, name="None"):
-        OWNxCanvasQt.OWNxCanvas.__init__(self, master, parent, name)
+        OWNxCanvas.__init__(self, master, parent, name)
         self.networkCurve = ModelCurve()
         self.NodeItem = ModelItem
 
         self.vizAttributes = None
         self.radius = 100
 
-#    def mouseMoveEvent(self, event):
-#        if self.graph is None or self.layout is None:
-#          return
-#        
-#        if self.plotAccuracy or self.vizAttributes:
-#            px = self.invTransform(QwtPlot.xBottom, event.x())
-#            py = self.invTransform(QwtPlot.yLeft, event.y())
-#            ndx, mind = self.layout.closest_vertex(px, py)
-#            
-#            dX = self.transform(QwtPlot.xBottom, self.layout.coors[0][ndx]) - event.x()
-#            dY = self.transform(QwtPlot.yLeft,   self.layout.coors[1][ndx]) - event.y()
-#            # transform to pixel distance
-#            distance = math.sqrt(dX**2 + dY**2) 
-#            if ndx != -1 and distance <= (self.vertices[ndx].size + 5) / 2:
-#                toMark = set(self.getNeighboursUpTo(ndx, self.tooltipNeighbours))
-#                toMark = list(toMark)
-#                self.networkCurve.setMarkedVertices(toMark)
-#                if self.plotAccuracy:
-#                    self.plotAccuracy(toMark)
-#                if self.vizAttributes:
-#                    self.vizAttributes(toMark)
-#                self.drawPlotItems()
-#            else:
-#                vd = sorted(self.layout.vertex_distances(px, py))[:10]
-#                vd = [(math.sqrt((self.transform(QwtPlot.xBottom, self.layout.coors[0][v]) - event.x())**2 + \
-#                                 (self.transform(QwtPlot.yLeft,   self.layout.coors[1][v]) - event.y())**2), v) for d,v in vd]
-#                vd = [v for d,v in vd if d < self.radius]
-#                self.networkCurve.setMarkedVertices(vd)
-#                if self.plotAccuracy:
-#                    self.plotAccuracy(vd)
-#                if self.vizAttributes:
-#                    self.vizAttributes(vd)
-#                self.drawPlotItems()
-#        else:
-#            OWNxCanvas.mouseMoveEvent(self, event)
+    def mouseMoveEvent(self, event):
+        OWNxCanvas.mouseMoveEvent(self, event)
+
+        if self.graph is None or self.layout is None:
+            return
+
+        if self.plotAccuracy or self.vizAttributes:
+            cursor = self.mapToScene(event.pos())
+            nearest = self.nearest_point(cursor)
+
+            if nearest is not None:
+                toMark = set(self.get_neighbors_upto(nearest.index(), self.tooltipNeighbours))
+                toMark = list(toMark)
+                self.networkCurve.clear_node_marks()
+                self.networkCurve.set_node_marks(dict((i, True) for i in toMark))
+                if self.plotAccuracy:
+                    self.plotAccuracy(toMark)
+                if self.vizAttributes:
+                    self.vizAttributes(toMark)
+            else:
+                nodes = self.networkCurve.nodes().items()
+                nodes = [i for i, n in nodes if (n.pos() - cursor).manhattanLength() < self.radius]
+
+                self.networkCurve.clear_node_marks()
+                self.networkCurve.set_node_marks(dict((i, True) for i in nodes))
+
+                if self.plotAccuracy:
+                    self.plotAccuracy(nodes)
+                if self.vizAttributes:
+                    self.vizAttributes(nodes)
 
     def set_tooltip_attributes(self, attributes):
         if self.graph is None or self.items is None or \
         # VISUALIZATION CONTROLS
         vizPredAcc = OWGUI.widgetBox(self.modelTab, "Prediction Accuracy", orientation="vertical")
         OWGUI.checkBox(vizPredAcc, self, "vizAccurancy", "Visualize prediction accurancy", callback=self.visualizeInfo)
-        OWGUI.spin(vizPredAcc, self, "radius", 10, 300, 1, label="Radius: ", callback=self.visualizeInfo)
+        OWGUI.spin(vizPredAcc, self, "radius", 10, 1000, 1, label="Radius: ", callback=self.visualizeInfo)
         self.predGraph = OWDistributionGraph(self, vizPredAcc)
         self.predGraph.setMaximumSize(QSize(300, 300))
         self.predGraph.setYRlabels(None)