示例#1
0
    def transform(self, *args):
        """
        Transform a rectangle from scale to paint coordinates

        .. py:method:: transform(scalar)

            :param float scalar: Scalar

        .. py:method:: transform(xMap, yMap, rect)

            Transform a rectangle from scale to paint coordinates

            :param qwt.scale_map.QwtScaleMap xMap: X map
            :param qwt.scale_map.QwtScaleMap yMap: Y map
            :param QRectF rect: Rectangle in paint coordinates

        .. py:method:: transform(xMap, yMap, pos)

            Transform a point from scale to paint coordinates

            :param qwt.scale_map.QwtScaleMap xMap: X map
            :param qwt.scale_map.QwtScaleMap yMap: Y map
            :param QPointF pos: Position in scale coordinates

        Scalar: scalemap.transform(scalar)
        Point (QPointF): scalemap.transform(xMap, yMap, pos)
        Rectangle (QRectF): scalemap.transform(xMap, yMap, rect)

        .. seealso::

            :py:meth:`invTransform()`
        """
        if len(args) == 1:
            # Scalar transform
            return self.transform_scalar(args[0])
        elif len(args) == 3 and isinstance(args[2], QPointF):
            xMap, yMap, pos = args
            return QPointF(xMap.transform(pos.x()), yMap.transform(pos.y()))
        elif len(args) == 3 and isinstance(args[2], QRectF):
            xMap, yMap, rect = args
            x1 = xMap.transform(rect.left())
            x2 = xMap.transform(rect.right())
            y1 = yMap.transform(rect.top())
            y2 = yMap.transform(rect.bottom())
            if x2 < x1:
                x1, x2 = x2, x1
            if y2 < y1:
                y1, y2 = y2, y1
            if qwtFuzzyCompare(x1, 0.0, x2 - x1) == 0:
                x1 = 0.0
            if qwtFuzzyCompare(x2, 0.0, x2 - x1) == 0:
                x2 = 0.0
            if qwtFuzzyCompare(y1, 0.0, y2 - y1) == 0:
                y1 = 0.0
            if qwtFuzzyCompare(y2, 0.0, y2 - y1) == 0:
                y2 = 0.0
            return QRectF(x1, y1, x2 - x1 + 1, y2 - y1 + 1)
        else:
            raise TypeError("%s().transform() takes 1 or 3 argument(s) (%s "
                            "given)" % (self.__class__.__name__, len(args)))
示例#2
0
 def buildMinorTicks(self, ticks, maxMinorSteps, stepSize):
     """
     Calculate minor ticks for an interval
     
     :param list ticks: Major ticks (returned)
     :param int maxMinorSteps: Maximum number of minor steps
     :param float stepSize: Step size
     """
     minStep = qwtStepSize(stepSize, maxMinorSteps, self.base())
     if minStep == 0.0:
         return
     numTicks = int(math.ceil(abs(stepSize / minStep)) - 1)
     medIndex = -1
     if numTicks % 2:
         medIndex = numTicks / 2
     for val in ticks[QwtScaleDiv.MajorTick]:
         for k in range(numTicks):
             val += minStep
             alignedValue = val
             if qwtFuzzyCompare(val, 0.0, stepSize) == 0:
                 alignedValue = 0.0
             if k == medIndex:
                 ticks[QwtScaleDiv.MediumTick] += [alignedValue]
             else:
                 ticks[QwtScaleDiv.MinorTick] += [alignedValue]
示例#3
0
 def contains(self, interval, value):
     """
     Check if an interval "contains" a value
     
     :param float intervalSize: Interval size
     :param float value: Value
     :return: True, when the value is inside the interval
     """
     if not interval.isValid():
         return False
     elif qwtFuzzyCompare(value, interval.minValue(), interval.width()) < 0:
         return False
     elif qwtFuzzyCompare(value, interval.maxValue(), interval.width()) > 0:
         return False
     else:
         return True
示例#4
0
def qwtStepSize(intervalSize, maxSteps, base):
    """this version often doesn't find the best ticks: f.e for 15: 5, 10"""
    minStep = divideInterval(intervalSize, maxSteps, base)
    if minStep != 0.0:
        #  # ticks per interval
        numTicks = math.ceil(abs(intervalSize / minStep)) - 1
        #  Do the minor steps fit into the interval?
        if (qwtFuzzyCompare((numTicks + 1) * abs(minStep), abs(intervalSize),
                            intervalSize) > 0):
            #  The minor steps doesn't fit into the interval
            return 0.5 * intervalSize
    return minStep
示例#5
0
    def align(self, interval, stepSize):
        """
        Align an interval to a step size

        The limits of an interval are aligned that both are integer
        multiples of the step size.
        
        :param qwt.interval.QwtInterval interval: Interval
        :param float stepSize: Step size
        :return: Aligned interval
        """
        intv = qwtLogInterval(self.base(), interval)

        x1 = floorEps(intv.minValue(), stepSize)
        if qwtFuzzyCompare(interval.minValue(), x1, stepSize) == 0:
            x1 = interval.minValue()

        x2 = ceilEps(intv.maxValue(), stepSize)
        if qwtFuzzyCompare(interval.maxValue(), x2, stepSize) == 0:
            x2 = interval.maxValue()

        return qwtPowInterval(self.base(), QwtInterval(x1, x2))
示例#6
0
 def buildTicks(self, interval, stepSize, maxMinorSteps):
     """
     Calculate ticks for an interval
     
     :param qwt.interval.QwtInterval interval: Interval
     :param float stepSize: Step size
     :param int maxMinorSteps: Maximum number of minor steps
     :return: Calculated ticks
     """
     ticks = [[] for _i in range(QwtScaleDiv.NTickTypes)]
     boundingInterval = self.align(interval, stepSize)
     ticks[QwtScaleDiv.MajorTick] = self.buildMajorTicks(
         boundingInterval, stepSize)
     if maxMinorSteps > 0:
         self.buildMinorTicks(ticks, maxMinorSteps, stepSize)
     for i in range(QwtScaleDiv.NTickTypes):
         ticks[i] = self.strip(ticks[i], interval)
         for j in range(len(ticks[i])):
             if qwtFuzzyCompare(ticks[i][j], 0.0, stepSize) == 0:
                 ticks[i][j] = 0.0
     return ticks
示例#7
0
    def buildMinorTicks(self, ticks, maxMinorSteps, stepSize):
        """
        Calculate minor ticks for an interval
        
        :param list ticks: Major ticks (returned)
        :param int maxMinorSteps: Maximum number of minor steps
        :param float stepSize: Step size
        """
        logBase = self.base()

        if stepSize < 1.1:
            minStep = self.divideInterval(stepSize, maxMinorSteps + 1)
            if minStep == 0.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.0:
                    if not qFuzzyCompare(s, 1.0):
                        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.0:
                return

            if minStep < 1.0:
                minStep = 1.0

            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([math.pow(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]