diff --git a/Orange/OrangeWidgets/Unsupervised/OWDistanceMap.py b/Orange/OrangeWidgets/Unsupervised/OWDistanceMap.py
index c471eea96..256fff0ff 100644
--- a/Orange/OrangeWidgets/Unsupervised/OWDistanceMap.py
+++ b/Orange/OrangeWidgets/Unsupervised/OWDistanceMap.py
@@ -1,10 +1,10 @@
"""
Distance Map
-Displays distance matrix as a heat map.
+Displays distance matrix as a heat map with sorting by selected.
icons/DistanceMatrix.svg
Blaz Zupan (blaz.zupan(@at@)fri.uni-lj.si)
1200
-"""
+""" ## + Distance Map Ord
from __future__ import with_statement
import orange, math, sys
import OWGUI, OWToolbars
@@ -68,7 +68,7 @@ class OWDistanceMap(OWWidget):
"Grid", "savedGrid",
"ShowItemsInBalloon", "SendOnRelease", "colorSettings", "selectedSchemaIndex", "palette"]
- def __init__(self, parent=None, signalManager = None):
+ def __init__(self, parent=None, signalManager = None): ##### 'Distance Map Ord' ???
OWWidget.__init__(self, parent, signalManager, 'Distance Map', wantGraph=True)
self.inputs = [("Distances", orange.SymMatrix, self.setMatrix)]
@@ -99,7 +99,7 @@ def __init__(self, parent=None, signalManager = None):
self.CutLow = 0
self.CutHigh = 0
self.CutEnabled = 0
- self.Sort = 0
+ self.Sort = 0 ##### index of the sorting ???
self.SquareCells = 0
self.ShowLegend = 1
self.ShowLabels = 1
@@ -110,13 +110,16 @@ def __init__(self, parent=None, signalManager = None):
self.loadSettings()
self.maxHSize = 30; self.maxVSize = 30
- self.sorting = [("No sorting", self.sortNone),
+ self.sorting = [("No sorting", self.sortNone), ### all the sorting methods
("Adjacent distance", self.sortAdjDist),
("Random order", self.sortRandom),
("Clustering", self.sortClustering),
- ("Clustering with ordered leafs", self.sortClusteringOrdered)]
+ ("Clustering with ordered leafs", self.sortClusteringOrdered),
+ ("by Selected", self.sortBySel),
+ ("Inverse by Selected", self.sortInvBySel),
+ ("by Label", self.sortLabel)]
- self.matrix = self.order = None
+ self.matrix = self.order = None ##### self.order : indexes of the sorting ???
self.rootCluster = None
# GUI definition
@@ -149,10 +152,10 @@ def __init__(self, parent=None, signalManager = None):
callback=self.createDistanceMap, ticks=0)
OWGUI.separator(tab)
- self.labelCombo = OWGUI.comboBox(tab, self, "Sort", box="Sort",
- items=[x[0] for x in self.sorting],
+ self.labelCombo = OWGUI.comboBox(tab, self, "Sort", box="Sort", ### comboBox to for sorting method
+ items=[x[0] for x in self.sorting], ## items - list of the names of the sort methods
tooltip="Sorting method for items in distance matrix.",
- callback=self.sortItems)
+ callback=self.sortItems) ### funtion to change the sort method
OWGUI.rubber(tab)
# FILTER TAB
@@ -231,12 +234,12 @@ def __init__(self, parent=None, signalManager = None):
self.selector.setPen(QPen(self.qrgbToQColor(color),v_sel_width))
self.selector.setZValue(20)
- self.selection = SelectionManager()
+ self.selection = SelectionManager() ### cells selected by user
- self.selectionLines = []
+ self.selectionLines = [] ### ???
self.annotationText = []
self.clusterItems = []
- self.selectionRects = []
+ self.selectionRects = [] # ?
self.legendText1 = QGraphicsSimpleTextItem(None, self.scene)
self.legendText2 = QGraphicsSimpleTextItem(None, self.scene)
@@ -255,7 +258,7 @@ def sendReport(self):
[("Matrix dimension", self.matrix.dim)])
self.reportSettings("Settings",
[("Merge", "%i elements in a cell" % self.Merge if self.Merge > 1 else "none"),
- ("Sorting", self.sorting[self.Sort][0].lower()),
+ ("Sorting", self.sorting[self.Sort][0].lower()), ## sort method name
("Thresholds", "low %.1f, high %.1f" % (self.CutLow, self.CutHigh) if self.CutEnabled else "none"),
("Gamma", "%.2f" % self.Gamma)])
if self.matrix:
@@ -298,8 +301,8 @@ def getItemFromPos(self, i):
else:
j = self.distanceMap.elementIndices[i]
- if self.distanceMapConstructor.order:
- j = self.distanceMapConstructor.order[j]
+ if self.distanceMapConstructor.order: ## if distint of "no Order"
+ j = self.distanceMapConstructor.order[j] ## convert index of item from "aparent" order to "real"
return j
@@ -307,7 +310,7 @@ def sendOutput(self):
items = getattr(self.matrix, "items", None)
if items is None or (not isinstance(items, orange.ExampleTable) and
not all(isinstance(item, orange.Variable)
- for item in items)):
+ for item in items)): ## continue only if all items are orange.Variable
return
selectedIndices = []
@@ -405,13 +408,13 @@ def createColorDialog(self):
def setCutEnabled(self):
self.sliderCutLow.box.setDisabled(not self.CutEnabled)
self.sliderCutHigh.box.setDisabled(not self.CutEnabled)
- self.drawDistanceMap()
+ self.drawDistanceMap() ## to call afer order ??
- def constructDistanceMap(self):
+ def constructDistanceMap(self): ## to call afer order ??
if self.matrix:
self.distanceMapConstructor = orange.DistanceMapConstructor(distanceMatrix = self.matrix)
- self.sortItems()
- self.createDistanceMap()
+ self.sortItems() ## to call afer ordering change ??
+ self.createDistanceMap() ## to call afer order ??
def createDistanceMap(self):
"""creates distance map objects"""
@@ -420,8 +423,8 @@ def createDistanceMap(self):
merge = min(self.Merge, float(self.matrix.dim))
squeeze = 1. / merge
- self.distanceMapConstructor.order = self.order
- self.distanceMap, self.lowerBound, self.upperBound = self.distanceMapConstructor(squeeze)
+ self.distanceMapConstructor.order = self.order ###### !!!!!!!
+ self.distanceMap, self.lowerBound, self.upperBound = self.distanceMapConstructor(squeeze) ###### !!!!!!!
self.sliderCutLow.setRange(self.lowerBound, self.upperBound, 0.1)
self.sliderCutHigh.setRange(self.lowerBound, self.upperBound, 0.1)
@@ -430,8 +433,8 @@ def createDistanceMap(self):
self.sliderCutLow.setValue(self.CutLow)
self.sliderCutHigh.setValue(self.CutHigh)
- self.selection.clear()
- self.drawDistanceMap()
+ self.selection.clear() ###### !!!!!!!
+ self.drawDistanceMap() ###### !!!!!!!
def drawDistanceMap(self):
"""renders distance map object on canvas"""
@@ -726,10 +729,10 @@ def mouseMove(self, event):
i = self.getItemFromPos(col)
j = self.getItemFromPos(row)
- head = str(self.matrix[i, j])
+ head = str(self.matrix[i, j]) ## the value!
if self.ShowItemsInBalloon == 1:
- namei, namej = items[i], items[j]
+ namei, namej = items[i], items[j] # the example names
if isinstance(namei, (orange.Example, orange.Variable)):
namei = namei.name
else:
@@ -786,6 +789,8 @@ def mouseRelease(self, x,y):
self.updateSelectionRect()
if self.SendOnRelease==1:
self.sendOutput()
+ if self.sorting[self.Sort][0] in ("by Selected", "Inverse by Selected"):
+ self.sortItems()
def actionUndo(self):
self.selection.undo()
@@ -797,10 +802,10 @@ def actionRemoveAllSelections(self):
# input signal management
- def sortNone(self):
+ def sortNone(self): # !!!!!!!!!!!!!
self.order = None
- def sortAdjDist(self):
+ def sortAdjDist(self): # !!!!!!!!!!!!!!
self.order = None
def sortRandom(self):
@@ -833,6 +838,73 @@ def sortClusteringOrdered(self):
self.rootCluster = cluster
self.order = list(self.rootCluster.mapping)
+ def itemCmp(self, l,r):
+ return 1 if l[1]>r[1] else -1 if l[1] 0:
del self.selection[len(self.selection)-1]
- def getSelection(self):
- res = list(self.selection)
+ def getSelection(self): ## to use !!!!!!!!!!!!
+ res = list(self.selection) ## a copie !
if self.selecting == True:
- res += [self.currSel.united(self.currSelEnd).normalized()]
+ res += [self.currSel.united(self.currSelEnd).normalized()] ## all posible selection ????
return res
if __name__=="__main__":