Example #1
0
    def buildMinorTicks(self, ticks, maxMinorSteps, stepSize):
        logBase = self.base()

        if stepSize < 1.1:
            minStep = self.divideInterval(stepSize, maxMinorSteps + 1)
            if minStep == 0.:
                return

            numSteps = int(round(stepSize / minStep))

            mediumTickIndex = -1
            if numSteps > 2 and numSteps % 2 == 0:
                mediumTickIndex = numSteps / 2

            for v in ticks[QwtScaleDiv.MajorTick]:
                s = logBase / numSteps
                if s >= 1.:
                    if not qFuzzyCompare(s, 1.):
                        ticks[QwtScaleDiv.MinorTick] += [v * s]
                    for j in range(2, numSteps):
                        ticks[QwtScaleDiv.MinorTick] += [v * j * s]
                else:
                    for j in range(1, numSteps):
                        tick = v + j * v * (logBase - 1) / numSteps
                        if j == mediumTickIndex:
                            ticks[QwtScaleDiv.MediumTick] += [tick]
                        else:
                            ticks[QwtScaleDiv.MinorTick] += [tick]

        else:
            minStep = self.divideInterval(stepSize, maxMinorSteps)
            if minStep == 0.:
                return

            if minStep < 1.:
                minStep = 1.

            numTicks = int(round(stepSize / minStep)) - 1

            if qwtFuzzyCompare(
                (numTicks + 1) * minStep, stepSize, stepSize) > 0:
                numTicks = 0

            if numTicks < 1:
                return

            mediumTickIndex = -1
            if numTicks > 2 and numTicks % 2:
                mediumTickIndex = numTicks / 2

            minFactor = max([np.power(logBase, minStep), float(logBase)])

            for tick in ticks[QwtScaleDiv.MajorTick]:
                for j in range(numTicks):
                    tick *= minFactor
                    if j == mediumTickIndex:
                        ticks[QwtScaleDiv.MediumTick] += [tick]
                    else:
                        ticks[QwtScaleDiv.MinorTick] += [tick]
Example #2
0
 def buildMinorTicks(self, ticks, maxMinorSteps, stepSize):
     logBase = self.base()
     
     if stepSize < 1.1:
         minStep = self.divideInterval(stepSize, maxMinorSteps+1)
         if minStep == 0.:
             return
         
         numSteps = int(round(stepSize/minStep))
         
         mediumTickIndex = -1
         if numSteps > 2 and numSteps % 2 == 0:
             mediumTickIndex = numSteps/2
         
         for v in ticks[QwtScaleDiv.MajorTick]:
             s = logBase/numSteps
             if s >= 1.:
                 if not qFuzzyCompare(s, 1.):
                     ticks[QwtScaleDiv.MinorTick] += [v*s]
                 for j in range(2, numSteps):
                     ticks[QwtScaleDiv.MinorTick] += [v*j*s]
             else:
                 for j in range(1, numSteps):
                     tick = v + j*v*(logBase-1)/numSteps
                     if j == mediumTickIndex:
                         ticks[QwtScaleDiv.MediumTick] += [tick]
                     else:
                         ticks[QwtScaleDiv.MinorTick] += [tick]
                         
     else:
         minStep = self.divideInterval(stepSize, maxMinorSteps)
         if minStep == 0.:
             return
         
         if minStep < 1.:
             minStep = 1.
         
         numTicks = int(round(stepSize/minStep))-1
         
         if qwtFuzzyCompare((numTicks+1)*minStep, stepSize, stepSize) > 0:
             numTicks = 0
         
         if numTicks < 1:
             return
         
         mediumTickIndex = -1
         if numTicks > 2 and numTicks % 2:
             mediumTickIndex = numTicks/2
         
         minFactor = max([np.power(logBase, minStep), float(logBase)])
         
         for tick in ticks[QwtScaleDiv.MajorTick]:
             for j in range(numTicks):
                 tick *= minFactor
                 if j == mediumTickIndex:
                     ticks[QwtScaleDiv.MediumTick] += [tick]
                 else:
                     ticks[QwtScaleDiv.MinorTick] += [tick]
Example #3
0
    def minLabelDist(self, font):
        if not self.hasComponent(QwtAbstractScaleDraw.Labels):
            return 0

        ticks = self.scaleDiv().ticks(QwtScaleDiv.MajorTick)
        if not ticks:
            return 0

        fm = QFontMetrics(font)
        vertical = self.orientation() == Qt.Vertical

        bRect1 = QRectF()
        bRect2 = self.labelRect(font, ticks[0])
        if vertical:
            bRect2.setRect(-bRect2.bottom(), 0., bRect2.height(),
                           bRect2.width())

        maxDist = 0.

        for tick in ticks:
            bRect1 = bRect2
            bRect2 = self.labelRect(font, tick)
            if vertical:
                bRect2.setRect(-bRect2.bottom(), 0., bRect2.height(),
                               bRect2.width())

            dist = fm.leading()
            if bRect1.right() > 0:
                dist += bRect1.right()
            if bRect2.left() < 0:
                dist += -bRect2.left()

            if dist > maxDist:
                maxDist = dist

        angle = qwtRadians(self.labelRotation())
        if vertical:
            angle += np.pi / 2

        sinA = np.sin(angle)
        if qFuzzyCompare(sinA + 1., 1.):
            return np.ceil(maxDist)

        fmHeight = fm.ascent() - 2

        labelDist = fmHeight / np.sin(angle) * np.cos(angle)
        if labelDist < 0:
            labelDist = -labelDist

        if labelDist > maxDist:
            labelDist = maxDist

        if labelDist < fmHeight:
            labelDist = fmHeight

        return np.ceil(labelDist)
Example #4
0
 def minLabelDist(self, font):
     if not self.hasComponent(QwtAbstractScaleDraw.Labels):
         return 0
     
     ticks = self.scaleDiv().ticks(QwtScaleDiv.MajorTick)
     if not ticks:
         return 0
     
     fm = QFontMetrics(font)
     vertical = self.orientation() == Qt.Vertical
     
     bRect1 = QRectF()
     bRect2 = self.labelRect(font, ticks[0])
     if vertical:
         bRect2.setRect(-bRect2.bottom(), 0.,
                        bRect2.height(), bRect2.width())
     
     maxDist = 0.
     
     for tick in ticks:
         bRect1 = bRect2
         bRect2 = self.labelRect(font, tick)
         if vertical:
             bRect2.setRect(-bRect2.bottom(), 0.,
                            bRect2.height(), bRect2.width())
         
         dist = fm.leading()
         if bRect1.right() > 0:
             dist += bRect1.right()
         if bRect2.left() < 0:
             dist += -bRect2.left()
         
         if dist > maxDist:
             maxDist = dist
         
     angle = qwtRadians(self.labelRotation())
     if vertical:
         angle += np.pi/2
     
     sinA = np.sin(angle)
     if qFuzzyCompare(sinA+1., 1.):
         return np.ceil(maxDist)
     
     fmHeight = fm.ascent()-2
     
     labelDist = fmHeight/np.sin(angle)*np.cos(angle)
     if labelDist < 0:
         labelDist = -labelDist
     
     if labelDist > maxDist:
         labelDist = maxDist
     
     if labelDist < fmHeight:
         labelDist = fmHeight
     
     return np.ceil(labelDist)
Example #5
0
    def minLabelDist(self, font):
        """
        Determine the minimum distance between two labels, that is necessary
        that the texts don't overlap.

        :param QFont font: Font
        :return: The maximum width of a label
        
        .. seealso::
        
            :py:meth:`getBorderDistHint()`
        """
        if not self.hasComponent(QwtAbstractScaleDraw.Labels):
            return 0
        
        ticks = self.scaleDiv().ticks(QwtScaleDiv.MajorTick)
        if not ticks:
            return 0
        
        fm = QFontMetrics(font)
        vertical = self.orientation() == Qt.Vertical
        
        bRect1 = QRectF()
        bRect2 = self.labelRect(font, ticks[0])
        if vertical:
            bRect2.setRect(-bRect2.bottom(), 0.,
                           bRect2.height(), bRect2.width())
        
        maxDist = 0.
        
        for tick in ticks:
            bRect1 = bRect2
            bRect2 = self.labelRect(font, tick)
            if vertical:
                bRect2.setRect(-bRect2.bottom(), 0.,
                               bRect2.height(), bRect2.width())
            
            dist = fm.leading()
            if bRect1.right() > 0:
                dist += bRect1.right()
            if bRect2.left() < 0:
                dist += -bRect2.left()
            
            if dist > maxDist:
                maxDist = dist
            
        angle = qwtRadians(self.labelRotation())
        if vertical:
            angle += np.pi/2
        
        sinA = np.sin(angle)
        if qFuzzyCompare(sinA+1., 1.):
            return np.ceil(maxDist)
        
        fmHeight = fm.ascent()-2
        
        labelDist = fmHeight/np.sin(angle)*np.cos(angle)
        if labelDist < 0:
            labelDist = -labelDist
        
        if labelDist > maxDist:
            labelDist = maxDist
        
        if labelDist < fmHeight:
            labelDist = fmHeight
        
        return np.ceil(labelDist)
Example #6
0
def qwtFuzzyLessOrEqual(d1, d2):
    return (d1 <= d2) or qFuzzyCompare(d1, d2)
Example #7
0
def qwtFuzzyGreaterOrEqual(d1, d2):
    return (d1 >= d2) or qFuzzyCompare(d1, d2)
Example #8
0
def qwtFuzzyLessOrEqual(d1, d2):
    return (d1 <= d2) or qFuzzyCompare(d1, d2)
Example #9
0
def qwtFuzzyGreaterOrEqual(d1, d2):
    return (d1 >= d2) or qFuzzyCompare(d1, d2)
    def minLabelDist(self, font):
        """
        Determine the minimum distance between two labels, that is necessary
        that the texts don't overlap.

        :param QFont font: Font
        :return: The maximum width of a label
        
        .. seealso::
        
            :py:meth:`getBorderDistHint()`
        """
        if not self.hasComponent(QwtAbstractScaleDraw.Labels):
            return 0
        
        ticks = self.scaleDiv().ticks(QwtScaleDiv.MajorTick)
        if not ticks:
            return 0
        
        fm = QFontMetrics(font)
        vertical = self.orientation() == Qt.Vertical
        
        bRect1 = QRectF()
        bRect2 = self.labelRect(font, ticks[0])
        if vertical:
            bRect2.setRect(-bRect2.bottom(), 0.,
                           bRect2.height(), bRect2.width())
        
        maxDist = 0.
        
        for tick in ticks:
            bRect1 = bRect2
            bRect2 = self.labelRect(font, tick)
            if vertical:
                bRect2.setRect(-bRect2.bottom(), 0.,
                               bRect2.height(), bRect2.width())
            
            dist = fm.leading()
            if bRect1.right() > 0:
                dist += bRect1.right()
            if bRect2.left() < 0:
                dist += -bRect2.left()
            
            if dist > maxDist:
                maxDist = dist
            
        angle = qwtRadians(self.labelRotation())
        if vertical:
            angle += np.pi/2
        
        sinA = np.sin(angle)
        if qFuzzyCompare(sinA+1., 1.):
            return np.ceil(maxDist)
        
        fmHeight = fm.ascent()-2
        
        labelDist = fmHeight/np.sin(angle)*np.cos(angle)
        if labelDist < 0:
            labelDist = -labelDist
        
        if labelDist > maxDist:
            labelDist = maxDist
        
        if labelDist < fmHeight:
            labelDist = fmHeight
        
        return np.ceil(labelDist)