Changeset 10874:197217d3f57f in orange
 Timestamp:
 05/17/12 19:52:14 (2 years ago)
 Branch:
 default
 rebase_source:
 3000c9bba5d1dba558b84be144a789466c9ecab1
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Orange/OrangeWidgets/OWHist.py
r9671 r10874 15 15 self.parent = parent 16 16 self.type = type 17 17 18 18 self.enableXaxis(1) 19 19 self.enableYLaxis(1) 20 20 21 21 self.xData = [] 22 22 self.yData = [] 23 23 24 24 self.minValue = 0 25 25 self.maxValue = 0 … … 28 28 self.lowerBoundaryKey = None 29 29 self.upperBoundaryKey = None 30 30 31 31 self.enableGridXB(False) 32 32 self.enableGridYL(False) … … 36 36 37 37 def setValues(self, values): 38 if len(values) <= 0: 39 self.yData, self.xData = [], [] 40 self.minx = 1 41 self.maxx = 1 42 self.miny = 1 43 self.maxy = 1 44 self.minValue = 1 45 self.maxValue = 1 46 self.updateData() 47 self.replot() 48 return 49 38 50 nBins = 100 39 51 if len(values) < 100: … … 43 55 #if numpy version greater than 1.3 44 56 if len(self.xData) == len(self.yData) + 1: 45 self.xData = [(self.xData[i] + self.xData[i +1]) / 2. for i in range(len(self.xData)  1)]46 47 self.minx = min(self.xData) 57 self.xData = [(self.xData[i] + self.xData[i + 1]) / 2. for i in range(len(self.xData)  1)] 58 59 self.minx = min(self.xData) 48 60 self.maxx = max(self.xData) 49 61 self.miny = min(self.yData) 50 62 self.maxy = max(self.yData) 51 63 52 64 self.minValue = min(values) 53 65 self.maxValue = max(values) 54 66 55 67 self.updateData() 56 68 self.replot() 57 69 58 70 def setBoundary(self, lower, upper): 59 71 if len(self.xData) == 0 and len(self.yData) == 0: 60 72 return 61 73 62 74 self.lowerBoundary = lower 63 75 self.upperBoundary = upper 64 76 maxy = max(self.yData) 65 77 66 78 self.lowerBoundaryKey.setData([float(self.lowerBoundary), float(self.lowerBoundary)], [0., float(maxy)]) 67 79 self.upperBoundaryKey.setData([float(self.upperBoundary), float(self.upperBoundary)], [0., float(maxy)]) 68 80 # self.updateData() 69 81 self.replot() 70 82 71 83 def updateData(self): 72 self.removeDrawingCurves(removeLegendItems =0, removeMarkers=1)73 74 self.key = self.addCurve("histogramCurve", Qt.blue, Qt.blue, 6, symbol = QwtSymbol.NoSymbol, style = QwtPlotCurve.Steps, xData = self.xData, yData =self.yData)75 84 self.removeDrawingCurves(removeLegendItems=0, removeMarkers=1) 85 86 self.key = self.addCurve("histogramCurve", Qt.blue, Qt.blue, 6, symbol=QwtSymbol.NoSymbol, style=QwtPlotCurve.Steps, xData=self.xData, yData=self.yData) 87 76 88 maxy = self.maxy 77 self.lowerBoundaryKey = self.addCurve("lowerBoundaryCurve", Qt.red, Qt.red, 6, symbol = QwtSymbol.NoSymbol, style = QwtPlotCurve.Lines, xData = [float(self.lowerBoundary), float(self.lowerBoundary)], yData =[0., float(maxy)])78 self.upperBoundaryKey = self.addCurve("upperBoundaryCurve", Qt.red, Qt.red, 6, symbol = QwtSymbol.NoSymbol, style = QwtPlotCurve.Lines, xData = [float(self.upperBoundary), float(self.upperBoundary)], yData =[0., float(maxy)])89 self.lowerBoundaryKey = self.addCurve("lowerBoundaryCurve", Qt.red, Qt.red, 6, symbol=QwtSymbol.NoSymbol, style=QwtPlotCurve.Lines, xData=[float(self.lowerBoundary), float(self.lowerBoundary)], yData=[0., float(maxy)]) 90 self.upperBoundaryKey = self.addCurve("upperBoundaryCurve", Qt.red, Qt.red, 6, symbol=QwtSymbol.NoSymbol, style=QwtPlotCurve.Lines, xData=[float(self.upperBoundary), float(self.upperBoundary)], yData=[0., float(maxy)]) 79 91 80 92 minx = self.minx … … 89 101 def updateData(self): 90 102 OWHist.updateData(self) 91 self.upperTailShadeKey = self.addCurve("upperTailShade", Qt.blue, Qt.blue, 6, symbol = QwtSymbol.NoSymbol, style =QwtPlotCurve.Steps)92 self.lowerTailShadeKey = self.addCurve("lowerTailShade", Qt.blue, Qt.blue, 6, symbol = QwtSymbol.NoSymbol, style =QwtPlotCurve.Steps)93 self.middleShadeKey = self.addCurve("middleShade", Qt.blue, Qt.blue, 6, symbol = QwtSymbol.NoSymbol, style =QwtPlotCurve.Steps)103 self.upperTailShadeKey = self.addCurve("upperTailShade", Qt.blue, Qt.blue, 6, symbol=QwtSymbol.NoSymbol, style=QwtPlotCurve.Steps) 104 self.lowerTailShadeKey = self.addCurve("lowerTailShade", Qt.blue, Qt.blue, 6, symbol=QwtSymbol.NoSymbol, style=QwtPlotCurve.Steps) 105 self.middleShadeKey = self.addCurve("middleShade", Qt.blue, Qt.blue, 6, symbol=QwtSymbol.NoSymbol, style=QwtPlotCurve.Steps) 94 106 95 107 self.upperTailShadeKey.setBrush(QBrush(Qt.blue)) … … 103 115 if len(self.xData) == 0 and len(self.yData) == 0: 104 116 return 105 117 106 118 if self.type in ["hiTail", "twoTail"]: 107 index = max(min(int(math.ceil(100 *(self.upperBoundaryself.minx)/(self.maxxself.minx))), 100), 0)119 index = max(min(int(math.ceil(100 * (self.upperBoundary  self.minx) / (self.maxx  self.minx))), 100), 0) 108 120 x = [self.upperBoundary] + list(self.xData[index:]) 109 121 y = [self.yData[min(index, 99)]] + list(self.yData[index:]) … … 112 124 self.upperTailShadeKey.setData(x, y) 113 125 if self.type in ["lowTail", "twoTail"]: 114 index = max(min(int(math.ceil(100 *(self.lowerBoundaryself.minx)/(self.maxxself.minx))),100), 0)126 index = max(min(int(math.ceil(100 * (self.lowerBoundary  self.minx) / (self.maxx  self.minx))), 100), 0) 115 127 x = list(self.xData[:index]) + [self.lowerBoundary] 116 y = list(self.yData[:index]) + [self.yData[min(index, 99)]]128 y = list(self.yData[:index]) + [self.yData[min(index, 99)]] 117 129 x = [float(a) for a in x] 118 130 y = [float(a) for a in y] 119 131 self.lowerTailShadeKey.setData(x, y) 120 132 if self.type in ["middle"]: 121 indexLow = max(min(int(100 *(self.lowerBoundaryself.minx)/(self.maxxself.minx)),99), 0)122 indexHi = max(min(int(100 *(self.upperBoundaryself.minx)/(self.maxxself.minx)), 100)1, 0)123 x = [self.lowerBoundary] + list(self.xData[indexLow: indexHi]) + [self.upperBoundary]124 y = [self.yData[max(index, 0)]] + list(self.yData[indexLow: indexHi]) +[self.yData[max(indexHi, 99)]]133 indexLow = max(min(int(100 * (self.lowerBoundary  self.minx) / (self.maxx  self.minx)), 99), 0) 134 indexHi = max(min(int(100 * (self.upperBoundary  self.minx) / (self.maxx  self.minx)), 100)  1, 0) 135 x = [self.lowerBoundary] + list(self.xData[indexLow: indexHi]) + [self.upperBoundary] 136 y = [self.yData[max(index, 0)]] + list(self.yData[indexLow: indexHi]) + [self.yData[max(indexHi, 99)]] 125 137 x = [float(a) for a in x] 126 138 y = [float(a) for a in y] … … 132 144 if self.type in ["lowTail", "hiTail", "twoTail"]: 133 145 self.middleShadeKey.setData([], []) 134 146 135 147 def setBoundary(self, low, hi): 136 148 OWHist.setBoundary(self, low, hi) … … 138 150 # self.updateData() 139 151 self.replot() 140 152 141 153 def _setBoundary(self, boundary, cut): 142 154 if self.type in ["twoTail", "middle"]: … … 150 162 else: 151 163 self.setBoundary(cut, cut) 152 164 153 165 def mousePressEvent(self, e): 154 166 if self.state == SELECT and self.getBoundaryAt(e.pos()) and e.button() == Qt.LeftButton: … … 161 173 else: 162 174 return OWHist.mousePressEvent(self, e) 163 175 164 176 def mouseMoveEvent(self, e): 165 177 if self.state == SELECT: … … 174 186 self.canvas().setCursor(self._cursor) 175 187 else: 176 return OWHist.mouseMoveEvent(self , e)188 return OWHist.mouseMoveEvent(self , e) 177 189 178 190 def mouseReleaseEvent(self, e): … … 195 207 else: 196 208 return None 197 209
Note: See TracChangeset
for help on using the changeset viewer.