class QwtColumnRect(object): # enum Direction LeftToRight, RightToLeft, BottomToTop, TopToBottom = list(range(4)) def __init__(self): self.hInterval = QwtInterval() self.vInterval = QwtInterval() self.direction = 0 def toRect(self): r = QRectF(self.hInterval.minValue(), self.vInterval.minValue(), self.hInterval.maxValue() - self.hInterval.minValue(), self.vInterval.maxValue() - self.vInterval.minValue()) r = r.normalized() if self.hInterval.borderFlags() & QwtInterval.ExcludeMinimum: r.adjust(1, 0, 0, 0) if self.hInterval.borderFlags() & QwtInterval.ExcludeMaximum: r.adjust(0, 0, -1, 0) if self.vInterval.borderFlags() & QwtInterval.ExcludeMinimum: r.adjust(0, 1, 0, 0) if self.vInterval.borderFlags() & QwtInterval.ExcludeMaximum: r.adjust(0, 0, 0, -1) return r def orientation(self): if self.direction in (self.LeftToRight, self.RightToLeft): return Qt.Horizontal return Qt.Vertical
def autoScale(self, maxNumSteps, x1, x2, stepSize): """ Align and divide an interval :param int maxNumSteps: Max. number of steps :param float x1: First limit of the interval (In/Out) :param float x2: Second limit of the interval (In/Out) :param float stepSize: Step size :return: tuple (x1, x2, stepSize) .. seealso:: :py:meth:`setAttribute()` """ interval = QwtInterval(x1, x2) interval = interval.normalized() interval.setMinValue(interval.minValue() - self.lowerMargin()) interval.setMaxValue(interval.maxValue() + self.upperMargin()) if self.testAttribute(QwtScaleEngine.Symmetric): interval = interval.symmetrize(self.reference()) if self.testAttribute(QwtScaleEngine.IncludeReference): interval = interval.extend(self.reference()) if interval.width() == 0.0: interval = self.buildInterval(interval.minValue()) stepSize = divideInterval(interval.width(), max([maxNumSteps, 1]), self.base()) if not self.testAttribute(QwtScaleEngine.Floating): interval = self.align(interval, stepSize) x1 = interval.minValue() x2 = interval.maxValue() if self.testAttribute(QwtScaleEngine.Inverted): x1, x2 = x2, x1 stepSize = -stepSize return x1, x2, stepSize
def autoScale(self, maxNumSteps, x1, x2, stepSize): """ Align and divide an interval :param int maxNumSteps: Max. number of steps :param float x1: First limit of the interval (In/Out) :param float x2: Second limit of the interval (In/Out) :param float stepSize: Step size :return: tuple (x1, x2, stepSize) .. seealso:: :py:meth:`setAttribute()` """ interval = QwtInterval(x1, x2) interval = interval.normalized() interval.setMinValue(interval.minValue()-self.lowerMargin()) interval.setMaxValue(interval.maxValue()+self.upperMargin()) if self.testAttribute(QwtScaleEngine.Symmetric): interval = interval.symmetrize(self.reference()) if self.testAttribute(QwtScaleEngine.IncludeReference): interval = interval.extend(self.reference()) if interval.width() == 0.: interval = self.buildInterval(interval.minValue()) stepSize = divideInterval(interval.width(), max([maxNumSteps, 1]), self.base()) if not self.testAttribute(QwtScaleEngine.Floating): interval = self.align(interval, stepSize) x1 = interval.minValue() x2 = interval.maxValue() if self.testAttribute(QwtScaleEngine.Inverted): x1, x2 = x2, x1 stepSize = -stepSize return x1, x2, stepSize
class QwtColumnRect(object): # enum Direction LeftToRight, RightToLeft, BottomToTop, TopToBottom = list(range(4)) def __init__(self): self.hInterval = QwtInterval() self.vInterval = QwtInterval() self.direction = 0 def toRect(self): r = QRectF(self.hInterval.minValue(), self.vInterval.minValue(), self.hInterval.maxValue()-self.hInterval.minValue(), self.vInterval.maxValue()-self.vInterval.minValue()) r = r.normalized() if self.hInterval.borderFlags() & QwtInterval.ExcludeMinimum: r.adjust(1, 0, 0, 0) if self.hInterval.borderFlags() & QwtInterval.ExcludeMaximum: r.adjust(0, 0, -1, 0) if self.vInterval.borderFlags() & QwtInterval.ExcludeMinimum: r.adjust(0, 1, 0, 0) if self.vInterval.borderFlags() & QwtInterval.ExcludeMaximum: r.adjust(0, 0, 0, -1) return r def orientation(self): if self.direction in (self.LeftToRight, self.RightToLeft): return Qt.Horizontal return Qt.Vertical
def autoScale(self, maxNumSteps, x1, x2, stepSize): if x1 > x2: x1, x2 = x2, x1 logBase = self.base() interval = QwtInterval(x1/np.power(logBase, self.lowerMargin()), x2*np.power(logBase, self.upperMargin())) if interval.maxValue()/interval.minValue() < logBase: linearScaler = QwtLinearScaleEngine() linearScaler.setAttributes(self.attributes()) linearScaler.setReference(self.reference()) linearScaler.setMargins(self.lowerMargin(), self.upperMargin()) x1, x2, stepSize = linearScaler.autoScale(maxNumSteps, x1, x2, stepSize) linearInterval = QwtInterval(x1, x2).normalized() linearInterval = linearInterval.limited(LOG_MIN, LOG_MAX) if linearInterval.maxValue()/linearInterval.minValue() < logBase: if stepSize < 0.: stepSize = -qwtLog(logBase, abs(stepSize)) else: stepSize = qwtLog(logBase, stepSize) return x1, x2, stepSize logRef = 1. if self.reference() > LOG_MIN/2: logRef = min([self.reference(), LOG_MAX/2]) if self.testAttribute(QwtScaleEngine.Symmetric): delta = max([interval.maxValue()/logRef, logRef/interval.minValue()]) interval.setInterval(logRef/delta, logRef*delta) if self.testAttribute(QwtScaleEngine.IncludeReference): interval = interval.extend(logRef) interval = interval.limited(LOG_MIN, LOG_MAX) if interval.width() == 0.: interval = self.buildInterval(interval.minValue()) stepSize = self.divideInterval( qwtLogInterval(logBase, interval).width(), max([maxNumSteps, 1])) if stepSize < 1.: stepSize = 1. if not self.testAttribute(QwtScaleEngine.Floating): interval = self.align(interval, stepSize) x1 = interval.minValue() x2 = interval.maxValue() if self.testAttribute(QwtScaleEngine.Inverted): x1, x2 = x2, x1 stepSize = -stepSize
def autoScale(self, maxNumSteps, x1, x2, stepSize): if x1 > x2: x1, x2 = x2, x1 logBase = self.base() interval = QwtInterval(x1 / np.power(logBase, self.lowerMargin()), x2 * np.power(logBase, self.upperMargin())) if interval.maxValue() / interval.minValue() < logBase: linearScaler = QwtLinearScaleEngine() linearScaler.setAttributes(self.attributes()) linearScaler.setReference(self.reference()) linearScaler.setMargins(self.lowerMargin(), self.upperMargin()) x1, x2, stepSize = linearScaler.autoScale(maxNumSteps, x1, x2, stepSize) linearInterval = QwtInterval(x1, x2).normalized() linearInterval = linearInterval.limited(LOG_MIN, LOG_MAX) if linearInterval.maxValue() / linearInterval.minValue() < logBase: if stepSize < 0.: stepSize = -qwtLog(logBase, abs(stepSize)) else: stepSize = qwtLog(logBase, stepSize) return x1, x2, stepSize logRef = 1. if self.reference() > LOG_MIN / 2: logRef = min([self.reference(), LOG_MAX / 2]) if self.testAttribute(QwtScaleEngine.Symmetric): delta = max( [interval.maxValue() / logRef, logRef / interval.minValue()]) interval.setInterval(logRef / delta, logRef * delta) if self.testAttribute(QwtScaleEngine.IncludeReference): interval = interval.extend(logRef) interval = interval.limited(LOG_MIN, LOG_MAX) if interval.width() == 0.: interval = self.buildInterval(interval.minValue()) stepSize = self.divideInterval( qwtLogInterval(logBase, interval).width(), max([maxNumSteps, 1])) if stepSize < 1.: stepSize = 1. if not self.testAttribute(QwtScaleEngine.Floating): interval = self.align(interval, stepSize) x1 = interval.minValue() x2 = interval.maxValue() if self.testAttribute(QwtScaleEngine.Inverted): x1, x2 = x2, x1 stepSize = -stepSize
def autoScale(self, maxNumSteps, x1, x2, stepSize): interval = QwtInterval(x1, x2) interval = interval.normalized() interval.setMinValue(interval.minValue()-self.lowerMargin()) interval.setMaxValue(interval.maxValue()+self.upperMargin()) if self.testAttribute(QwtScaleEngine.Symmetric): interval = interval.symmetrize(self.reference()) if self.testAttribute(QwtScaleEngine.IncludeReference): interval = interval.extend(self.reference()) if interval.width() == 0.: interval = self.buildInterval(interval.minValue()) stepSize = divideInterval(interval.width(), max([maxNumSteps, 1]), self.base()) if not self.testAttribute(QwtScaleEngine.Floating): interval = self.align(interval, stepSize) x1 = interval.minValue() x2 = interval.maxValue() if self.testAttribute(QwtScaleEngine.Inverted): x1, x2 = x2, x1 stepSize = -stepSize return x1, x2, stepSize
def autoScale(self, maxNumSteps, x1, x2, stepSize): interval = QwtInterval(x1, x2) interval = interval.normalized() interval.setMinValue(interval.minValue() - self.lowerMargin()) interval.setMaxValue(interval.maxValue() + self.upperMargin()) if self.testAttribute(QwtScaleEngine.Symmetric): interval = interval.symmetrize(self.reference()) if self.testAttribute(QwtScaleEngine.IncludeReference): interval = interval.extend(self.reference()) if interval.width() == 0.: interval = self.buildInterval(interval.minValue()) stepSize = divideInterval(interval.width(), max([maxNumSteps, 1]), self.base()) if not self.testAttribute(QwtScaleEngine.Floating): interval = self.align(interval, stepSize) x1 = interval.minValue() x2 = interval.maxValue() if self.testAttribute(QwtScaleEngine.Inverted): x1, x2 = x2, x1 stepSize = -stepSize return x1, x2, stepSize
def divideScale(self, x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.): """ Calculate a scale division for an interval :param float x1: First interval limit :param float x2: Second interval limit :param int maxMajorSteps: Maximum for the number of major steps :param int maxMinorSteps: Maximum number of minor steps :param float stepSize: Step size. If stepSize == 0.0, the scaleEngine calculates one :return: Calculated scale division """ interval = QwtInterval(x1, x2).normalized() interval = interval.limited(LOG_MIN, LOG_MAX) if interval.width() <= 0: return QwtScaleDiv() logBase = self.base() if interval.maxValue()/interval.minValue() < logBase: linearScaler = QwtLinearScaleEngine() linearScaler.setAttributes(self.attributes()) linearScaler.setReference(self.reference()) linearScaler.setMargins(self.lowerMargin(), self.upperMargin()) if stepSize != 0.: if stepSize < 0.: stepSize = -np.power(logBase, -stepSize) else: stepSize = np.power(logBase, stepSize) return linearScaler.divideScale(x1, x2, maxMajorSteps, maxMinorSteps, stepSize) stepSize = abs(stepSize) if stepSize == 0.: if maxMajorSteps < 1: maxMajorSteps = 1 stepSize = self.divideInterval( qwtLogInterval(logBase, interval).width(), maxMajorSteps) if stepSize < 1.: stepSize = 1. scaleDiv = QwtScaleDiv() if stepSize != 0.: ticks = self.buildTicks(interval, stepSize, maxMinorSteps) scaleDiv = QwtScaleDiv(interval, ticks) if x1 > x2: scaleDiv.invert() return scaleDiv
def divideScale(self, x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.): """ Calculate a scale division for an interval :param float x1: First interval limit :param float x2: Second interval limit :param int maxMajorSteps: Maximum for the number of major steps :param int maxMinorSteps: Maximum number of minor steps :param float stepSize: Step size. If stepSize == 0.0, the scaleEngine calculates one :return: Calculated scale division """ interval = QwtInterval(x1, x2).normalized() interval = interval.limited(LOG_MIN, LOG_MAX) if interval.width() <= 0: return QwtScaleDiv() logBase = self.base() if interval.maxValue()/interval.minValue() < logBase: linearScaler = QwtLinearScaleEngine() linearScaler.setAttributes(self.attributes()) linearScaler.setReference(self.reference()) linearScaler.setMargins(self.lowerMargin(), self.upperMargin()) if stepSize != 0.: if stepSize < 0.: stepSize = -np.power(logBase, -stepSize) else: stepSize = np.power(logBase, stepSize) return linearScaler.divideScale(x1, x2, maxMajorSteps, maxMinorSteps, stepSize) stepSize = abs(stepSize) if stepSize == 0.: if maxMajorSteps < 1: maxMajorSteps = 1 stepSize = self.divideInterval( qwtLogInterval(logBase, interval).width(), maxMajorSteps) if stepSize < 1.: stepSize = 1. scaleDiv = QwtScaleDiv() if stepSize != 0.: ticks = self.buildTicks(interval, stepSize, maxMinorSteps) scaleDiv = QwtScaleDiv(interval, ticks) if x1 > x2: scaleDiv.invert() return scaleDiv
def divideScale(self, x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.): interval = QwtInterval(x1, x2).normalized() interval = interval.limited(LOG_MIN, LOG_MAX) if interval.width() <= 0: return QwtScaleDiv() logBase = self.base() if interval.maxValue()/interval.minValue() < logBase: linearScaler = QwtLinearScaleEngine() linearScaler.setAttributes(self.attributes()) linearScaler.setReference(self.reference()) linearScaler.setMargins(self.lowerMargin(), self.upperMargin()) if stepSize != 0.: if stepSize < 0.: stepSize = -np.power(logBase, -stepSize) else: stepSize = np.power(logBase, stepSize) return linearScaler.divideScale(x1, x2, maxMajorSteps, maxMinorSteps, stepSize) stepSize = abs(stepSize) if stepSize == 0.: if maxMajorSteps < 1: maxMajorSteps = 1 stepSize = self.divideInterval( qwtLogInterval(logBase, interval).width(), maxMajorSteps) if stepSize < 1.: stepSize = 1. scaleDiv = QwtScaleDiv() if stepSize != 0.: ticks = self.buildTicks(interval, stepSize, maxMinorSteps) scaleDiv = QwtScaleDiv(interval, ticks) if x1 > x2: scaleDiv.invert() return scaleDiv
def divideScale(self, x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.): interval = QwtInterval(x1, x2).normalized() interval = interval.limited(LOG_MIN, LOG_MAX) if interval.width() <= 0: return QwtScaleDiv() logBase = self.base() if interval.maxValue() / interval.minValue() < logBase: linearScaler = QwtLinearScaleEngine() linearScaler.setAttributes(self.attributes()) linearScaler.setReference(self.reference()) linearScaler.setMargins(self.lowerMargin(), self.upperMargin()) if stepSize != 0.: if stepSize < 0.: stepSize = -np.power(logBase, -stepSize) else: stepSize = np.power(logBase, stepSize) return linearScaler.divideScale(x1, x2, maxMajorSteps, maxMinorSteps, stepSize) stepSize = abs(stepSize) if stepSize == 0.: if maxMajorSteps < 1: maxMajorSteps = 1 stepSize = self.divideInterval( qwtLogInterval(logBase, interval).width(), maxMajorSteps) if stepSize < 1.: stepSize = 1. scaleDiv = QwtScaleDiv() if stepSize != 0.: ticks = self.buildTicks(interval, stepSize, maxMinorSteps) scaleDiv = QwtScaleDiv(interval, ticks) if x1 > x2: scaleDiv.invert() return scaleDiv
def autoScale(self, maxNumSteps, x1, x2, stepSize): """ Align and divide an interval :param int maxNumSteps: Max. number of steps :param float x1: First limit of the interval (In/Out) :param float x2: Second limit of the interval (In/Out) :param float stepSize: Step size :return: tuple (x1, x2, stepSize) .. seealso:: :py:meth:`setAttribute()` """ if x1 > x2: x1, x2 = x2, x1 logBase = self.base() interval = QwtInterval( x1 / math.pow(logBase, self.lowerMargin()), x2 * math.pow(logBase, self.upperMargin()), ) interval = interval.limited(LOG_MIN, LOG_MAX) if interval.maxValue() / interval.minValue() < logBase: linearScaler = QwtLinearScaleEngine() linearScaler.setAttributes(self.attributes()) linearScaler.setReference(self.reference()) linearScaler.setMargins(self.lowerMargin(), self.upperMargin()) x1, x2, stepSize = linearScaler.autoScale(maxNumSteps, x1, x2, stepSize) linearInterval = QwtInterval(x1, x2).normalized() linearInterval = linearInterval.limited(LOG_MIN, LOG_MAX) if linearInterval.maxValue() / linearInterval.minValue() < logBase: if stepSize < 0.0: stepSize = -math.log(abs(stepSize), logBase) else: stepSize = math.log(stepSize, logBase) return x1, x2, stepSize logRef = 1.0 if self.reference() > LOG_MIN / 2: logRef = min([self.reference(), LOG_MAX / 2]) if self.testAttribute(QwtScaleEngine.Symmetric): delta = max( [interval.maxValue() / logRef, logRef / interval.minValue()]) interval.setInterval(logRef / delta, logRef * delta) if self.testAttribute(QwtScaleEngine.IncludeReference): interval = interval.extend(logRef) interval = interval.limited(LOG_MIN, LOG_MAX) if interval.width() == 0.0: interval = self.buildInterval(interval.minValue()) stepSize = self.divideInterval( qwtLogInterval(logBase, interval).width(), max([maxNumSteps, 1])) if stepSize < 1.0: stepSize = 1.0 if not self.testAttribute(QwtScaleEngine.Floating): interval = self.align(interval, stepSize) x1 = interval.minValue() x2 = interval.maxValue() if self.testAttribute(QwtScaleEngine.Inverted): x1, x2 = x2, x1 stepSize = -stepSize return x1, x2, stepSize
def autoScale(self, maxNumSteps, x1, x2, stepSize): """ Align and divide an interval :param int maxNumSteps: Max. number of steps :param float x1: First limit of the interval (In/Out) :param float x2: Second limit of the interval (In/Out) :param float stepSize: Step size :return: tuple (x1, x2, stepSize) .. seealso:: :py:meth:`setAttribute()` """ if x1 > x2: x1, x2 = x2, x1 logBase = self.base() interval = QwtInterval(x1 / np.power(logBase, self.lowerMargin()), x2 * np.power(logBase, self.upperMargin())) if interval.maxValue() / interval.minValue() < logBase: linearScaler = QwtLinearScaleEngine() linearScaler.setAttributes(self.attributes()) linearScaler.setReference(self.reference()) linearScaler.setMargins(self.lowerMargin(), self.upperMargin()) x1, x2, stepSize = linearScaler.autoScale(maxNumSteps, x1, x2, stepSize) linearInterval = QwtInterval(x1, x2).normalized() linearInterval = linearInterval.limited(LOG_MIN, LOG_MAX) if linearInterval.maxValue() / linearInterval.minValue() < logBase: if stepSize < 0.0: stepSize = -qwtLog(logBase, abs(stepSize)) else: stepSize = qwtLog(logBase, stepSize) return x1, x2, stepSize logRef = 1.0 if self.reference() > LOG_MIN / 2: logRef = min([self.reference(), LOG_MAX / 2]) if self.testAttribute(QwtScaleEngine.Symmetric): delta = max([interval.maxValue() / logRef, logRef / interval.minValue()]) interval.setInterval(logRef / delta, logRef * delta) if self.testAttribute(QwtScaleEngine.IncludeReference): interval = interval.extend(logRef) interval = interval.limited(LOG_MIN, LOG_MAX) if interval.width() == 0.0: interval = self.buildInterval(interval.minValue()) stepSize = self.divideInterval(qwtLogInterval(logBase, interval).width(), max([maxNumSteps, 1])) if stepSize < 1.0: stepSize = 1.0 if not self.testAttribute(QwtScaleEngine.Floating): interval = self.align(interval, stepSize) x1 = interval.minValue() x2 = interval.maxValue() if self.testAttribute(QwtScaleEngine.Inverted): x1, x2 = x2, x1 stepSize = -stepSize return x1, x2, stepSize