def legendIcon(self, index, size): """ :param int index: Index of the legend entry (ignored as there is only one) :param QSizeF size: Icon size :return: Icon representing the marker on the legend .. seealso:: :py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`, :py:meth:`qwt.plot.QwtPlotItem.legendData()` """ if size.isEmpty(): return QwtGraphic() icon = QwtGraphic() icon.setDefaultSize(size) icon.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(icon) painter.setRenderHint( QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.style != QwtPlotMarker.NoLine: painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = .5 * size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = .5 * size.width() QwtPainter.drawLine(painter, x, 0., x, size.height()) if self.__data.symbol: r = QRect(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return icon
def drawLines(self, painter, canvasRect, pos): """ Draw the lines marker :param QPainter painter: Painter :param QRectF canvasRect: Contents rectangle of the canvas in painter coordinates :param QPointF pos: Position of the marker, translated into widget coordinates .. seealso:: :py:meth:`drawLabel()`, :py:meth:`qwt.symbol.QwtSymbol.drawSymbol()` """ if self.__data.style == self.NoLine: return doAlign = QwtPainter.roundingAlignment(painter) painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = pos.y() if doAlign: y = round(y) QwtPainter.drawLine(painter, canvasRect.left(), y, canvasRect.right()-1., y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = pos.x() if doAlign: x = round(x) QwtPainter.drawLine(painter, x, canvasRect.top(), x, canvasRect.bottom()-1.)
def legendIcon(self, index, size): """ :param int index: Index of the legend entry (ignored as there is only one) :param QSizeF size: Icon size :return: Icon representing the marker on the legend .. seealso:: :py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`, :py:meth:`qwt.plot.QwtPlotItem.legendData()` """ if size.isEmpty(): return QwtGraphic() icon = QwtGraphic() icon.setDefaultSize(size) icon.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(icon) painter.setRenderHint(QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.style != QwtPlotMarker.NoLine: painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = .5*size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = .5*size.width() QwtPainter.drawLine(painter, x, 0., x, size.height()) if self.__data.symbol: r = QRect(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return icon
def drawLines(self, painter, canvasRect, pos): """ Draw the lines marker :param QPainter painter: Painter :param QRectF canvasRect: Contents rectangle of the canvas in painter coordinates :param QPointF pos: Position of the marker, translated into widget coordinates .. seealso:: :py:meth:`drawLabel()`, :py:meth:`qwt.symbol.QwtSymbol.drawSymbol()` """ if self.__data.style == self.NoLine: return doAlign = QwtPainter.roundingAlignment(painter) painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = pos.y() if doAlign: y = round(y) QwtPainter.drawLine(painter, canvasRect.left(), y, canvasRect.right() - 1., y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = pos.x() if doAlign: x = round(x) QwtPainter.drawLine(painter, x, canvasRect.top(), x, canvasRect.bottom() - 1.)
def legendIcon(self, index, size): if size.isEmpty(): return QwtGraphic() graphic = QwtGraphic() graphic.setDefaultSize(size) graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(graphic) painter.setRenderHint( QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.legendAttributes == 0 or\ (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush): brush = self.__data.brush if brush.style( ) == Qt.NoBrush and self.__data.legendAttributes == 0: if self.style() != QwtPlotCurve.NoCurve: brush = QBrush(self.pen().color()) elif self.__data.symbol and\ self.__data.symbol.style() != QwtSymbol.NoSymbol: brush = QBrush(self.__data.symbol.pen().color()) if brush.style() != Qt.NoBrush: r = QRectF(0, 0, size.width(), size.height()) painter.fillRect(r, brush) if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine: if self.pen() != Qt.NoPen: pn = self.pen() # pn.setCapStyle(Qt.FlatCap) painter.setPen(pn) y = .5 * size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol: if self.__data.symbol: r = QRectF(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return graphic
def legendIcon(self, index, size): if size.isEmpty(): return QwtGraphic() graphic = QwtGraphic() graphic.setDefaultSize(size) graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(graphic) painter.setRenderHint(QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.legendAttributes == 0 or\ (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush): brush = self.__data.brush if brush.style() == Qt.NoBrush and self.__data.legendAttributes == 0: if self.style() != QwtPlotCurve.NoCurve: brush = QBrush(self.pen().color()) elif self.__data.symbol and\ self.__data.symbol.style() != QwtSymbol.NoSymbol: brush = QBrush(self.__data.symbol.pen().color()) if brush.style() != Qt.NoBrush: r = QRectF(0, 0, size.width(), size.height()) painter.fillRect(r, brush) if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine: if self.pen() != Qt.NoPen: pn = self.pen() # pn.setCapStyle(Qt.FlatCap) painter.setPen(pn) y = .5*size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol: if self.__data.symbol: r = QRectF(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return graphic
def drawBackbone(self, painter): doAlign = QwtPainter.roundingAlignment(painter) pos = self.__data.pos len_ = self.__data.len pw = max([self.penWidth(), 1]) if doAlign: if self.alignment() in (self.LeftScale, self.TopScale): off = (pw - 1) / 2 else: off = pw / 2 else: off = .5 * self.penWidth() if self.alignment() == self.LeftScale: x = pos.x() - off if doAlign: x = round(x) QwtPainter.drawLine(painter, x, pos.y(), x, pos.y() + len_) elif self.alignment() == self.RightScale: x = pos.x() + off if doAlign: x = round(x) QwtPainter.drawLine(painter, x, pos.y(), x, pos.y() + len_) elif self.alignment() == self.TopScale: y = pos.y() - off if doAlign: y = round(y) QwtPainter.drawLine(painter, pos.x(), y, pos.x() + len_, y) elif self.alignment() == self.BottomScale: y = pos.y() + off if doAlign: y = round(y) QwtPainter.drawLine(painter, pos.x(), y, pos.x() + len_, y)
def qwtDrawXCrossSymbols(painter, points, numPoints, symbol): size =symbol.size() off = 0 pen = QPen(symbol.pen()) if pen.width() > 1: pen.setCapStyle(Qt.FlatCap) off = 1 painter.setPen(pen) if QwtPainter.roundingAlignment(painter): sw = np.floor(size.width()) sh = np.floor(size.height()) sw2 = size.width()//2 sh2 = size.height()//2 for pos in points: x = round(pos.x()) y = round(pos.y()) x1 = x-sw2 x2 = x1+sw+off y1 = y-sh2 y2 = y1+sh+off QwtPainter.drawLine(painter, x1, y1, x2, y2) QwtPainter.drawLine(painter, x2, y1, x1, y2) else: sw = size.width() sh = size.height() sw2 = .5*size.width() sh2 = .5*size.height() for pos in points: x1 = pos.x()-sw2 x2 = x1+sw y1 = pos.y()-sh2 y2 = y1+sh QwtPainter.drawLine(painter, x1, y1, x2, y2) QwtPainter.drawLine(painter, x2, y1, x1, y2)
def drawBackbone(self, painter): doAlign = QwtPainter.roundingAlignment(painter) pos = self.__data.pos len_ = self.__data.len pw = max([self.penWidth(), 1]) if doAlign: if self.alignment() in (self.LeftScale, self.TopScale): off = (pw-1)/2 else: off = pw/2 else: off = .5*self.penWidth() if self.alignment() == self.LeftScale: x = pos.x() - off if doAlign: x = round(x) QwtPainter.drawLine(painter, x, pos.y(), x, pos.y()+len_) elif self.alignment() == self.RightScale: x = pos.x() + off if doAlign: x = round(x) QwtPainter.drawLine(painter, x, pos.y(), x, pos.y()+len_) elif self.alignment() == self.TopScale: y = pos.y() - off if doAlign: y = round(y) QwtPainter.drawLine(painter, pos.x(), y, pos.x()+len_, y) elif self.alignment() == self.BottomScale: y = pos.y() + off if doAlign: y = round(y) QwtPainter.drawLine(painter, pos.x(), y, pos.x()+len_, y)
def qwtDrawXCrossSymbols(painter, points, numPoints, symbol): size = symbol.size() off = 0 pen = QPen(symbol.pen()) if pen.width() > 1: pen.setCapStyle(Qt.FlatCap) off = 1 painter.setPen(pen) if QwtPainter.roundingAlignment(painter): sw = np.floor(size.width()) sh = np.floor(size.height()) sw2 = size.width() // 2 sh2 = size.height() // 2 for pos in points: x = round(pos.x()) y = round(pos.y()) x1 = x - sw2 x2 = x1 + sw + off y1 = y - sh2 y2 = y1 + sh + off QwtPainter.drawLine(painter, x1, y1, x2, y2) QwtPainter.drawLine(painter, x2, y1, x1, y2) else: sw = size.width() sh = size.height() sw2 = .5 * size.width() sh2 = .5 * size.height() for pos in points: x1 = pos.x() - sw2 x2 = x1 + sw y1 = pos.y() - sh2 y2 = y1 + sh QwtPainter.drawLine(painter, x1, y1, x2, y2) QwtPainter.drawLine(painter, x2, y1, x1, y2)
def drawLines(self, painter, canvasRect, pos): if self.__data.style == self.NoLine: return doAlign = QwtPainter.roundingAlignment(painter) painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = pos.y() if doAlign: y = round(y) QwtPainter.drawLine(painter, canvasRect.left(), y, canvasRect.right()-1., y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = pos.x() if doAlign: x = round(x) QwtPainter.drawLine(painter, x, canvasRect.top(), x, canvasRect.bottom()-1.)
def drawLines(self, painter, canvasRect, pos): if self.__data.style == self.NoLine: return doAlign = QwtPainter.roundingAlignment(painter) painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = pos.y() if doAlign: y = round(y) QwtPainter.drawLine(painter, canvasRect.left(), y, canvasRect.right() - 1., y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = pos.x() if doAlign: x = round(x) QwtPainter.drawLine(painter, x, canvasRect.top(), x, canvasRect.bottom() - 1.)
def legendIcon(self, index, size): """ :param int index: Index of the legend entry (ignored as there is only one) :param QSizeF size: Icon size :return: Icon representing the curve on the legend .. seealso:: :py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`, :py:meth:`qwt.plot.QwtPlotItem.legendData()` """ if size.isEmpty(): return QwtGraphic() graphic = QwtGraphic() graphic.setDefaultSize(size) graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(graphic) painter.setRenderHint( QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.legendAttributes == 0 or\ (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush): brush = self.__data.brush if brush.style( ) == Qt.NoBrush and self.__data.legendAttributes == 0: if self.style() != QwtPlotCurve.NoCurve: brush = QBrush(self.pen().color()) elif self.__data.symbol and\ self.__data.symbol.style() != QwtSymbol.NoSymbol: brush = QBrush(self.__data.symbol.pen().color()) if brush.style() != Qt.NoBrush: r = QRectF(0, 0, size.width(), size.height()) painter.fillRect(r, brush) if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine: if self.pen() != Qt.NoPen: pn = self.pen() # pn.setCapStyle(Qt.FlatCap) painter.setPen(pn) y = .5 * size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol: if self.__data.symbol: r = QRectF(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return graphic
def drawLines(self, painter, canvasRect, orientation, scaleMap, values): x1 = canvasRect.left() x2 = canvasRect.right()-1. y1 = canvasRect.top() y2 = canvasRect.bottom()-1. doAlign = QwtPainter.roundingAlignment(painter) for val in values: value = scaleMap.transform(val) if doAlign: value = round(value) if orientation == Qt.Horizontal: if qwtFuzzyGreaterOrEqual(value, y1) and\ qwtFuzzyLessOrEqual(value, y2): QwtPainter.drawLine(painter, x1, value, x2, value) else: if qwtFuzzyGreaterOrEqual(value, x1) and\ qwtFuzzyLessOrEqual(value, x2): QwtPainter.drawLine(painter, value, y1, value, y2)
def drawLines(self, painter, canvasRect, orientation, scaleMap, values): x1 = canvasRect.left() x2 = canvasRect.right() - 1. y1 = canvasRect.top() y2 = canvasRect.bottom() - 1. doAlign = QwtPainter.roundingAlignment(painter) for val in values: value = scaleMap.transform(val) if doAlign: value = round(value) if orientation == Qt.Horizontal: if qwtFuzzyGreaterOrEqual(value, y1) and\ qwtFuzzyLessOrEqual(value, y2): QwtPainter.drawLine(painter, x1, value, x2, value) else: if qwtFuzzyGreaterOrEqual(value, x1) and\ qwtFuzzyLessOrEqual(value, x2): QwtPainter.drawLine(painter, value, y1, value, y2)
def drawTick(self, painter, value, len_): """ Draw a tick :param QPainter painter: Painter :param float value: Value of the tick :param float len: Length of the tick .. seealso:: :py:meth:`drawBackbone()`, :py:meth:`drawLabel()` """ if len_ <= 0: return roundingAlignment = QwtPainter.roundingAlignment(painter) pos = self.__data.pos tval = self.scaleMap().transform(value) if roundingAlignment: tval = round(tval) pw = self.penWidth() a = 0 if pw > 1 and roundingAlignment: a = 1 if self.alignment() == self.LeftScale: x1 = pos.x() + a x2 = pos.x() + a - pw - len_ if roundingAlignment: x1 = round(x1) x2 = round(x2) QwtPainter.drawLine(painter, x1, tval, x2, tval) elif self.alignment() == self.RightScale: x1 = pos.x() x2 = pos.x() + pw + len_ if roundingAlignment: x1 = round(x1) x2 = round(x2) QwtPainter.drawLine(painter, x1, tval, x2, tval) elif self.alignment() == self.BottomScale: y1 = pos.y() y2 = pos.y() + pw + len_ if roundingAlignment: y1 = round(y1) y2 = round(y2) QwtPainter.drawLine(painter, tval, y1, tval, y2) elif self.alignment() == self.TopScale: y1 = pos.y() + a y2 = pos.y() - pw - len_ + a if roundingAlignment: y1 = round(y1) y2 = round(y2) QwtPainter.drawLine(painter, tval, y1, tval, y2)
def drawTick(self, painter, value, len_): """ Draw a tick :param QPainter painter: Painter :param float value: Value of the tick :param float len: Length of the tick .. seealso:: :py:meth:`drawBackbone()`, :py:meth:`drawLabel()` """ if len_ <= 0: return roundingAlignment = QwtPainter.roundingAlignment(painter) pos = self.__data.pos tval = self.scaleMap().transform(value) if roundingAlignment: tval = round(tval) pw = self.penWidth() a = 0 if pw > 1 and roundingAlignment: a = 1 if self.alignment() == self.LeftScale: x1 = pos.x() + a x2 = pos.x() + a - pw - len_ if roundingAlignment: x1 = round(x1) x2 = round(x2) QwtPainter.drawLine(painter, x1, tval, x2, tval) elif self.alignment() == self.RightScale: x1 = pos.x() x2 = pos.x() + pw + len_ if roundingAlignment: x1 = round(x1) x2 = round(x2) QwtPainter.drawLine(painter, x1, tval, x2, tval) elif self.alignment() == self.BottomScale: y1 = pos.y() y2 = pos.y() + pw + len_ if roundingAlignment: y1 = round(y1) y2 = round(y2) QwtPainter.drawLine(painter, tval, y1, tval, y2) elif self.alignment() == self.TopScale: y1 = pos.y() + a y2 = pos.y() - pw - len_ + a if roundingAlignment: y1 = round(y1) y2 = round(y2) QwtPainter.drawLine(painter, tval, y1, tval, y2)
def legendIcon(self, index, size): """ :param int index: Index of the legend entry (ignored as there is only one) :param QSizeF size: Icon size :return: Icon representing the curve on the legend .. seealso:: :py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`, :py:meth:`qwt.plot.QwtPlotItem.legendData()` """ if size.isEmpty(): return QwtGraphic() graphic = QwtGraphic() graphic.setDefaultSize(size) graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(graphic) painter.setRenderHint(QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.legendAttributes == 0 or\ (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush): brush = self.__data.brush if brush.style() == Qt.NoBrush and self.__data.legendAttributes == 0: if self.style() != QwtPlotCurve.NoCurve: brush = QBrush(self.pen().color()) elif self.__data.symbol and\ self.__data.symbol.style() != QwtSymbol.NoSymbol: brush = QBrush(self.__data.symbol.pen().color()) if brush.style() != Qt.NoBrush: r = QRectF(0, 0, size.width(), size.height()) painter.fillRect(r, brush) if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine: if self.pen() != Qt.NoPen: pn = self.pen() # pn.setCapStyle(Qt.FlatCap) painter.setPen(pn) y = .5*size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol: if self.__data.symbol: r = QRectF(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return graphic
def legendIcon(self, index, size): if size.isEmpty(): return QwtGraphic() icon = QwtGraphic() icon.setDefaultSize(size) icon.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(icon) painter.setRenderHint(QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.style != QwtPlotMarker.NoLine: painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = .5*size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = .5*size.width() QwtPainter.drawLine(painter, x, 0., x, size.height()) if self.__data.symbol: r = QRect(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return icon
def legendIcon(self, index, size): if size.isEmpty(): return QwtGraphic() icon = QwtGraphic() icon.setDefaultSize(size) icon.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(icon) painter.setRenderHint( QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.style != QwtPlotMarker.NoLine: painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = .5 * size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = .5 * size.width() QwtPainter.drawLine(painter, x, 0., x, size.height()) if self.__data.symbol: r = QRect(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return icon
def drawSticks(self, painter, xMap, yMap, canvasRect, from_, to): """ Draw sticks :param QPainter painter: Painter :param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates. :param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates. :param QRectF canvasRect: Contents rectangle of the canvas :param int from_: Index of the first point to be painted :param int to: Index of the last point to be painted. If to < 0 the curve will be painted to its last point. .. seealso:: :py:meth:`draw()`, :py:meth:`drawDots()`, :py:meth:`drawSteps()`, :py:meth:`drawLines()` """ painter.save() painter.setRenderHint(QPainter.Antialiasing, False) doAlign = QwtPainter.roundingAlignment(painter) x0 = xMap.transform(self.__data.baseline) y0 = yMap.transform(self.__data.baseline) if doAlign: x0 = round(x0) y0 = round(y0) o = self.orientation() series = self.data() for i in range(from_, to + 1): sample = series.sample(i) xi = xMap.transform(sample.x()) yi = yMap.transform(sample.y()) if doAlign: xi = round(xi) yi = round(yi) if o == Qt.Horizontal: QwtPainter.drawLine(painter, x0, yi, xi, yi) else: QwtPainter.drawLine(painter, xi, y0, xi, yi) painter.restore()
def drawSticks(self, painter, xMap, yMap, canvasRect, from_, to): """ Draw sticks :param QPainter painter: Painter :param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates. :param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates. :param QRectF canvasRect: Contents rectangle of the canvas :param int from_: Index of the first point to be painted :param int to: Index of the last point to be painted. If to < 0 the curve will be painted to its last point. .. seealso:: :py:meth:`draw()`, :py:meth:`drawDots()`, :py:meth:`drawSteps()`, :py:meth:`drawLines()` """ painter.save() painter.setRenderHint(QPainter.Antialiasing, False) doAlign = QwtPainter.roundingAlignment(painter) x0 = xMap.transform(self.__data.baseline) y0 = yMap.transform(self.__data.baseline) if doAlign: x0 = round(x0) y0 = round(y0) o = self.orientation() series = self.data() for i in range(from_, to+1): sample = series.sample(i) xi = xMap.transform(sample.x()) yi = yMap.transform(sample.y()) if doAlign: xi = round(xi) yi = round(yi) if o == Qt.Horizontal: QwtPainter.drawLine(painter, x0, yi, xi, yi) else: QwtPainter.drawLine(painter, xi, y0, xi, yi) painter.restore()
def drawSticks(self, painter, xMap, yMap, canvasRect, from_, to): painter.save() painter.setRenderHint(QPainter.Antialiasing, False) doAlign = QwtPainter.roundingAlignment(painter) x0 = xMap.transform(self.__data.baseline) y0 = yMap.transform(self.__data.baseline) if doAlign: x0 = round(x0) y0 = round(y0) o = self.orientation() series = self.data() for i in range(from_, to+1): sample = series.sample(i) xi = xMap.transform(sample.x()) yi = yMap.transform(sample.y()) if doAlign: xi = round(xi) yi = round(yi) if o == Qt.Horizontal: QwtPainter.drawLine(painter, x0, yi, xi, yi) else: QwtPainter.drawLine(painter, xi, y0, xi, yi) painter.restore()
def drawSticks(self, painter, xMap, yMap, canvasRect, from_, to): painter.save() painter.setRenderHint(QPainter.Antialiasing, False) doAlign = QwtPainter.roundingAlignment(painter) x0 = xMap.transform(self.__data.baseline) y0 = yMap.transform(self.__data.baseline) if doAlign: x0 = round(x0) y0 = round(y0) o = self.orientation() series = self.data() for i in range(from_, to + 1): sample = series.sample(i) xi = xMap.transform(sample.x()) yi = yMap.transform(sample.y()) if doAlign: xi = round(xi) yi = round(yi) if o == Qt.Horizontal: QwtPainter.drawLine(painter, x0, yi, xi, yi) else: QwtPainter.drawLine(painter, xi, y0, xi, yi) painter.restore()
def drawTick(self, painter, value, len_): if len_ <= 0: return roundingAlignment = QwtPainter.roundingAlignment(painter) pos = self.__data.pos tval = self.scaleMap().transform(value) if roundingAlignment: tval = round(tval) pw = self.penWidth() a = 0 if pw > 1 and roundingAlignment: a = 1 if self.alignment() == self.LeftScale: x1 = pos.x() + a x2 = pos.x() + a - pw - len_ if roundingAlignment: x1 = round(x1) x2 = round(x2) QwtPainter.drawLine(painter, x1, tval, x2, tval) elif self.alignment() == self.RightScale: x1 = pos.x() x2 = pos.x() + pw + len_ if roundingAlignment: x1 = round(x1) x2 = round(x2) QwtPainter.drawLine(painter, x1, tval, x2, tval) elif self.alignment() == self.BottomScale: y1 = pos.y() y2 = pos.y() + pw + len_ if roundingAlignment: y1 = round(y1) y2 = round(y2) QwtPainter.drawLine(painter, tval, y1, tval, y2) elif self.alignment() == self.TopScale: y1 = pos.y() + a y2 = pos.y() - pw - len_ + a if roundingAlignment: y1 = round(y1) y2 = round(y2) QwtPainter.drawLine(painter, tval, y1, tval, y2)
def drawBackbone(self, painter): """ Draws the baseline of the scale :param QPainter painter: Painter .. seealso:: :py:meth:`drawTick()`, :py:meth:`drawLabel()` """ doAlign = QwtPainter.roundingAlignment(painter) pos = self.__data.pos len_ = self.__data.len pw = max([self.penWidth(), 1]) if doAlign: if self.alignment() in (self.LeftScale, self.TopScale): off = (pw - 1) / 2 else: off = pw / 2 else: off = .5 * self.penWidth() if self.alignment() == self.LeftScale: x = pos.x() - off if doAlign: x = round(x) QwtPainter.drawLine(painter, x, pos.y(), x, pos.y() + len_) elif self.alignment() == self.RightScale: x = pos.x() + off if doAlign: x = round(x) QwtPainter.drawLine(painter, x, pos.y(), x, pos.y() + len_) elif self.alignment() == self.TopScale: y = pos.y() - off if doAlign: y = round(y) QwtPainter.drawLine(painter, pos.x(), y, pos.x() + len_, y) elif self.alignment() == self.BottomScale: y = pos.y() + off if doAlign: y = round(y) QwtPainter.drawLine(painter, pos.x(), y, pos.x() + len_, y)
def drawTick(self, painter, value, len_): if len_ <= 0: return roundingAlignment = QwtPainter.roundingAlignment(painter) pos = self.__data.pos tval = self.scaleMap().transform(value) if roundingAlignment: tval = round(tval) pw = self.penWidth() a = 0 if pw > 1 and roundingAlignment: a = 1 if self.alignment() == self.LeftScale: x1 = pos.x() + a x2 = pos.x() + a - pw - len_ if roundingAlignment: x1 = round(x1) x2 = round(x2) QwtPainter.drawLine(painter, x1, tval, x2, tval) elif self.alignment() == self.RightScale: x1 = pos.x() x2 = pos.x() + pw + len_ if roundingAlignment: x1 = round(x1) x2 = round(x2) QwtPainter.drawLine(painter, x1, tval, x2, tval) elif self.alignment() == self.BottomScale: y1 = pos.y() y2 = pos.y() + pw + len_ if roundingAlignment: y1 = round(y1) y2 = round(y2) QwtPainter.drawLine(painter, tval, y1, tval, y2) elif self.alignment() == self.TopScale: y1 = pos.y() + a y2 = pos.y() - pw - len_ + a if roundingAlignment: y1 = round(y1) y2 = round(y2) QwtPainter.drawLine(painter, tval, y1, tval, y2)
def drawBackbone(self, painter): """ Draws the baseline of the scale :param QPainter painter: Painter .. seealso:: :py:meth:`drawTick()`, :py:meth:`drawLabel()` """ doAlign = QwtPainter.roundingAlignment(painter) pos = self.__data.pos len_ = self.__data.len pw = max([self.penWidth(), 1]) if doAlign: if self.alignment() in (self.LeftScale, self.TopScale): off = (pw-1)/2 else: off = pw/2 else: off = .5*self.penWidth() if self.alignment() == self.LeftScale: x = pos.x() - off if doAlign: x = round(x) QwtPainter.drawLine(painter, x, pos.y(), x, pos.y()+len_) elif self.alignment() == self.RightScale: x = pos.x() + off if doAlign: x = round(x) QwtPainter.drawLine(painter, x, pos.y(), x, pos.y()+len_) elif self.alignment() == self.TopScale: y = pos.y() - off if doAlign: y = round(y) QwtPainter.drawLine(painter, pos.x(), y, pos.x()+len_, y) elif self.alignment() == self.BottomScale: y = pos.y() + off if doAlign: y = round(y) QwtPainter.drawLine(painter, pos.x(), y, pos.x()+len_, y)
def qwtDrawLineSymbols(painter, orientations, points, numPoints, symbol): size =symbol.size() off = 0 pen = QPen(symbol.pen()) if pen.width() > 1: pen.setCapStyle(Qt.FlatCap) off = 1 painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing, False) if QwtPainter.roundingAlignment(painter): sw = np.floor(size.width()) sh = np.floor(size.height()) sw2 = size.width()//2 sh2 = size.height()//2 for pos in points: if orientations & Qt.Horizontal: x = round(pos.x())-sw2 y = round(pos.y()) QwtPainter.drawLine(painter, x, y, x+sw+off, y) if orientations & Qt.Vertical: x = round(pos.x()) y = round(pos.y())-sh2 QwtPainter.drawLine(painter, x, y, x, y+sh+off) else: sw = size.width() sh = size.height() sw2 = .5*size.width() sh2 = .5*size.height() for pos in points: if orientations & Qt.Horizontal: x = round(pos.x())-sw2 y = round(pos.y()) QwtPainter.drawLine(painter, x, y, x+sw, y) if orientations & Qt.Vertical: x = round(pos.x()) y = round(pos.y())-sh2 QwtPainter.drawLine(painter, x, y, x, y+sh)
def qwtDrawLineSymbols(painter, orientations, points, numPoints, symbol): size = symbol.size() off = 0 pen = QPen(symbol.pen()) if pen.width() > 1: pen.setCapStyle(Qt.FlatCap) off = 1 painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing, False) if QwtPainter.roundingAlignment(painter): sw = np.floor(size.width()) sh = np.floor(size.height()) sw2 = size.width() // 2 sh2 = size.height() // 2 for pos in points: if orientations & Qt.Horizontal: x = round(pos.x()) - sw2 y = round(pos.y()) QwtPainter.drawLine(painter, x, y, x + sw + off, y) if orientations & Qt.Vertical: x = round(pos.x()) y = round(pos.y()) - sh2 QwtPainter.drawLine(painter, x, y, x, y + sh + off) else: sw = size.width() sh = size.height() sw2 = .5 * size.width() sh2 = .5 * size.height() for pos in points: if orientations & Qt.Horizontal: x = round(pos.x()) - sw2 y = round(pos.y()) QwtPainter.drawLine(painter, x, y, x + sw, y) if orientations & Qt.Vertical: x = round(pos.x()) y = round(pos.y()) - sh2 QwtPainter.drawLine(painter, x, y, x, y + sh)
def drawLines(self, painter, xMap, yMap, from_, to): doAlign = QwtPainter.roundingAlignment(painter) painter.setPen(self.__data.pen) painter.setBrush(self.__data.brush) series = self.data() for i in range(from_, to + 1): sample = series.sample(i) if not sample.interval.isNull(): rect = self.columnRect(sample, xMap, yMap) r = QRectF(rect.toRect()) if doAlign: r.setLeft(round(r.left())) r.setRight(round(r.right())) r.setTop(round(r.top())) r.setBottom(round(r.bottom())) if rect.direction == QwtColumnRect.LeftToRight: QwtPainter.drawLine(painter, r.topRight(), r.bottomRight()) elif rect.direction == QwtColumnRect.RightToLeft: QwtPainter.drawLine(painter, r.topLeft(), r.bottomLeft()) elif rect.direction == QwtColumnRect.TopToBottom: QwtPainter.drawLine(painter, r.bottomRight(), r.bottomLeft()) elif rect.direction == QwtColumnRect.BottomToTop: QwtPainter.drawLine(painter, r.topRight(), r.topLeft())
def qwtDrawStar1Symbols(painter, points, numPoints, symbol): size =symbol.size() painter.setPen(symbol.pen()) sqrt1_2 = np.sqrt(.5) if QwtPainter.roundingAlignment(painter): r = QRect(0, 0, size.width(), size.height()) for pos in points: r.moveCenter(pos.toPoint()) d1 = r.width()/2.*(1.-sqrt1_2) QwtPainter.drawLine(painter, round(r.left()+d1), round(r.top()+d1), round(r.right()-d1), round(r.bottom()-d1)) QwtPainter.drawLine(painter, round(r.left()+d1), round(r.bottom()-d1), round(r.right()-d1), round(r.top()+d1)) c = QPoint(r.center()) QwtPainter.drawLine(painter, c.x(), r.top(), c.x(), r.bottom()) QwtPainter.drawLine(painter, r.left(), c.y(), r.right(), c.y()) else: r = QRectF(0, 0, size.width(), size.height()) for pos in points: r.moveCenter(pos.toPoint()) c = QPointF(r.center()) d1 = r.width()/2.*(1.-sqrt1_2) QwtPainter.drawLine(painter, r.left()+d1, r.top()+d1, r.right()-d1, r.bottom()-d1) QwtPainter.drawLine(painter, r.left()+d1, r.bottom()-d1, r.right()-d1, r.top()+d1) QwtPainter.drawLine(painter, c.x(), r.top(), c.x(), r.bottom()) QwtPainter.drawLine(painter, r.left(), c.y(), r.right(), c.y())
def qwtDrawStar1Symbols(painter, points, numPoints, symbol): size = symbol.size() painter.setPen(symbol.pen()) sqrt1_2 = np.sqrt(.5) if QwtPainter.roundingAlignment(painter): r = QRect(0, 0, size.width(), size.height()) for pos in points: r.moveCenter(pos.toPoint()) d1 = r.width() / 2. * (1. - sqrt1_2) QwtPainter.drawLine(painter, round(r.left() + d1), round(r.top() + d1), round(r.right() - d1), round(r.bottom() - d1)) QwtPainter.drawLine(painter, round(r.left() + d1), round(r.bottom() - d1), round(r.right() - d1), round(r.top() + d1)) c = QPoint(r.center()) QwtPainter.drawLine(painter, c.x(), r.top(), c.x(), r.bottom()) QwtPainter.drawLine(painter, r.left(), c.y(), r.right(), c.y()) else: r = QRectF(0, 0, size.width(), size.height()) for pos in points: r.moveCenter(pos.toPoint()) c = QPointF(r.center()) d1 = r.width() / 2. * (1. - sqrt1_2) QwtPainter.drawLine(painter, r.left() + d1, r.top() + d1, r.right() - d1, r.bottom() - d1) QwtPainter.drawLine(painter, r.left() + d1, r.bottom() - d1, r.right() - d1, r.top() + d1) QwtPainter.drawLine(painter, c.x(), r.top(), c.x(), r.bottom()) QwtPainter.drawLine(painter, r.left(), c.y(), r.right(), c.y())