Changeset 3487:9a0db0f40e89 in orange


Ignore:
Timestamp:
04/04/07 13:32:51 (7 years ago)
Author:
Gregor <Gregor@…>
Branch:
default
Convert:
8e40c98fbc1432ce2f14519bccaec08bd4c31c24
Message:
  • color palette now returns colors from a list (it doesn't always create a new instance of a color) - this feature is used for faster drawing in scatterplot, linproj, ..
  • added class UnconnectedLinesCurve for fast drawing of unconnected lines
  • changed and removed some classes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/OWGraphTools.py

    r3330 r3487  
    2323        self.rgbColors = rgbColors 
    2424        self.numberOfColors = numberOfColors 
     25        if rgbColors: 
     26            self.rgbQColors = [QColor(*color) for color in self.rgbColors] 
     27         
    2528 
    2629    def __getitem__(self, index, brightness = None): 
     
    3437        else: 
    3538            if index < len(self.rgbColors): 
    36                 color = QColor(*self.rgbColors[index]) 
    37                 if brightness == None: return color 
    38                 h,s,v = color.getHsv() 
    39                 color.setHsv(h, int(brightness), v) 
    40                 return color 
     39                if brightness == None: 
     40                    return self.rgbQColors[index] 
     41                else: 
     42                    color = QColor(*self.rgbColors[index]) 
     43                    h,s,v = color.getHsv() 
     44                    color.setHsv(h, int(brightness), v) 
     45                    return color 
    4146            else: 
    4247                col = QColor() 
     
    231236 
    232237 
     238class UnconnectedLinesCurve(QwtPlotCurve): 
     239    def __init__(self, parent, pen = QPen(Qt.black), xData = None, yData = None): 
     240        QwtPlotCurve.__init__(self, parent) 
     241        self.setPen(pen) 
     242        self.Pen = pen 
     243        self.setStyle(QwtCurve.Lines) 
     244        if xData != None and yData != None: 
     245            self.setData(xData, yData) 
     246 
     247    def drawCurve(self, painter, style, xMap, yMap, start, stop): 
     248        start = max(start + start%2, 0) 
     249        if stop == -1: 
     250            stop = self.dataSize() 
     251        for i in range(start, stop, 2): 
     252            QwtPlotCurve.drawLines(self, painter, xMap, yMap, i, i+1) 
     253             
     254 
    233255# ########################################################### 
    234256# a class that is able to draw arbitrary polygon curves. 
     
    242264        self.Pen = pen 
    243265        self.Brush = brush 
    244         self.setStyle(QwtCurve.UserCurve) 
     266        self.setStyle(QwtCurve.Lines) 
    245267        if xData != None and yData != None: 
    246268            self.setData(xData, yData) 
    247269 
    248     # Draws rectangles with the corners taken from the x- and y-arrays.         
    249     def draw(self, painter, xMap, yMap, start, stop): 
    250         #painter.setPen(self.Pen) 
    251         #painter.setBrush(self.Brush) 
    252         painter.setPen(self.pen()) 
    253         painter.setBrush(self.brush()) 
    254         if stop == -1: stop = self.dataSize() 
    255         start = max(start, 0) 
    256         stop = max(stop, 0) 
    257         array = QPointArray(stop-start) 
    258         for i in range(start, stop): 
    259             array.setPoint(i-start, xMap.transform(self.x(i)), yMap.transform(self.y(i))) 
    260  
    261         if stop-start > 2: 
    262             painter.drawPolygon(array) 
    263              
    264  
    265 # #################################################################### 
    266 # draw a rectangle 
    267 # this class of curves is not yet drawn if you export picture to matplotlib 
    268 class RectanglePlotCurve(QwtPlotCurve): 
    269     def __init__(self, parent = None, pen = QPen(Qt.black), brush = QBrush(), text = None): 
    270         QwtPlotCurve.__init__(self, parent, text) 
    271         self.setPen(pen) 
    272         self.setBrush(brush) 
    273         self.setStyle(QwtCurve.UserCurve) 
    274  
    275     def draw(self, p, xMap, yMap, f, t): 
    276         # save ex settings 
    277         back = p.backgroundMode() 
    278         pen = p.pen() 
    279         brush = p.brush() 
    280          
    281         p.setPen(self.pen()) 
    282         p.setBrush(self.brush()) 
    283          
    284         if t < 0: t = self.dataSize() - 1 
    285         if divmod(f, 2)[1] != 0: f -= 1 
    286         if divmod(t, 2)[1] == 0:  t += 1 
    287         for i in range(f, t+1, 2): 
    288             px1 = xMap.transform(self.x(i)) 
    289             py1 = yMap.transform(self.y(i)) 
    290             px2 = xMap.transform(self.x(i+1)) 
    291             py2 = yMap.transform(self.y(i+1)) 
    292             p.drawRect(px1, py1, (px2 - px1), (py2 - py1)) 
    293  
    294         # restore ex settings 
    295         p.setBackgroundMode(back) 
    296         p.setPen(pen) 
    297         p.setBrush(brush) 
    298  
     270    def drawCurve(self, painter, style, xMap, yMap, start, stop): 
     271        for i in range(start, stop, 4): 
     272            QwtPlotCurve.drawLines(self, painter, xMap, yMap, i, i+3) 
    299273 
    300274# #################################################################### 
Note: See TracChangeset for help on using the changeset viewer.