def drawSteps(self, painter, xMap, yMap, canvasRect, from_, to): doAlign = QwtPainter.roundingAlignment(painter) polygon = QPolygonF(2 * (to - from_) + 1) inverted = self.orientation() == Qt.Vertical if self.__data.attributes & self.Inverted: inverted = not inverted series = self.data() ip = 0 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 ip > 0: p0 = polygon[ip - 2] if inverted: polygon[ip - 1] = QPointF(p0.x(), yi) else: polygon[ip - 1] = QPointF(xi, p0.y()) polygon[ip] = QPointF(xi, yi) ip += 2 if self.__data.paintAttributes & self.ClipPolygons: clipped = QwtClipper().clipPolygonF(canvasRect, polygon, False) QwtPainter.drawPolyline(painter, clipped) else: QwtPainter.drawPolyline(painter, polygon) if self.__data.brush.style() != Qt.NoBrush: self.fillCurve(painter, xMap, yMap, canvasRect, polygon)
def qwtDrawHexagonSymbols(painter, points, numPoints, symbol): painter.setBrush(symbol.brush()) painter.setPen(symbol.pen()) cos30 = np.cos(30*np.pi/180.) dx = .5*(symbol.size().width()-cos30) dy = .25*symbol.size().height() doAlign = QwtPainter.roundingAlignment(painter) for pos in points: if doAlign: x = round(pos.x()) y = round(pos.y()) x1 = np.ceil(x-dx) y1 = np.ceil(y-2*dy) else: x = pos.x() y = pos.y() x1 = x-dx y1 = y-2*dy x2 = x1+1*dx x3 = x1+2*dx y2 = y1+1*dy y3 = y1+3*dy y4 = y1+4*dy hexa = [QPointF(x2, y1), QPointF(x3, y2), QPointF(x3, y3), QPointF(x2, y4), QPointF(x1, y3), QPointF(x1, y2)] QwtPainter.drawPolygon(painter, QPolygonF(hexa))
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 drawSteps(self, painter, xMap, yMap, canvasRect, from_, to): doAlign = QwtPainter.roundingAlignment(painter) polygon = QPolygonF(2*(to-from_)+1) inverted = self.orientation() == Qt.Vertical if self.__data.attributes & self.Inverted: inverted = not inverted series = self.data() ip = 0 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 ip > 0: p0 = polygon[ip-2] if inverted: polygon[ip-1] = QPointF(p0.x(), yi) else: polygon[ip-1] = QPointF(xi, p0.y()) polygon[ip] = QPointF(xi, yi) ip += 2 if self.__data.paintAttributes & self.ClipPolygons: clipped = QwtClipper().clipPolygonF(canvasRect, polygon, False) QwtPainter.drawPolyline(painter, clipped) else: QwtPainter.drawPolyline(painter, polygon) if self.__data.brush.style() != Qt.NoBrush: self.fillCurve(painter, xMap, yMap, canvasRect, polygon)
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 closePolyline(self, painter, xMap, yMap, polygon): """ Complete a polygon to be a closed polygon including the area between the original polygon and the baseline. :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 QPolygonF polygon: Polygon to be completed """ if polygon.size() < 2: return doAlign = QwtPainter.roundingAlignment(painter) baseline = self.__data.baseline if self.orientation() == Qt.Vertical: if yMap.transformation(): baseline = yMap.transformation().bounded(baseline) refY = yMap.transform(baseline) if doAlign: refY = round(refY) polygon += QPointF(polygon.last().x(), refY) polygon += QPointF(polygon.first().x(), refY) else: if xMap.transformation(): baseline = xMap.transformation().bounded(baseline) refX = xMap.transform(baseline) if doAlign: refX = round(refX) polygon += QPointF(refX, polygon.last().y()) polygon += QPointF(refX, polygon.first().y())
def qwtDrawRectSymbols(painter, points, numPoints, symbol): size = symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) painter.setRenderHint(QPainter.Antialiasing, False) if QwtPainter.roundingAlignment(painter): sw = size.width() sh = size.height() sw2 = size.width() // 2 sh2 = size.height() // 2 for pos in points: x = round(pos.x()) y = round(pos.y()) r = QRectF(x - sw2, y - sh2, sw, sh) QwtPainter.drawRect(painter, r) else: sw = size.width() sh = size.height() sw2 = .5 * size.width() sh2 = .5 * size.height() for pos in points: x = pos.x() y = pos.y() r = QRectF(x - sw2, y - sh2, sw, sh) QwtPainter.drawRect(painter, r)
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 drawSymbols(self, painter, symbol, xMap, yMap, canvasRect, from_, to): """ Draw symbols :param QPainter painter: Painter :param qwt.symbol.QwtSymbol symbol: Curve symbol :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:`setSymbol()`, :py:meth:`drawSeries()`, :py:meth:`drawCurve()` """ mapper = QwtPointMapper() mapper.setFlag(QwtPointMapper.RoundPoints, QwtPainter.roundingAlignment(painter)) mapper.setFlag(QwtPointMapper.WeedOutPoints, self.testPaintAttribute(QwtPlotCurve.FilterPoints)) mapper.setBoundingRect(canvasRect) chunkSize = 500 for i in range(from_, to + 1, chunkSize): n = min([chunkSize, to - i + 1]) points = mapper.toPointsF(xMap, yMap, self.data(), i, i + n - 1) if points.size() > 0: symbol.drawSymbols(painter, points)
def closePolyline(self, painter, xMap, yMap, polygon): """ Complete a polygon to be a closed polygon including the area between the original polygon and the baseline. :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 QPolygonF polygon: Polygon to be completed """ if polygon.size() < 2: return doAlign = QwtPainter.roundingAlignment(painter) baseline = self.__data.baseline if self.orientation() == Qt.Vertical: if yMap.transformation(): baseline = yMap.transformation().bounded(baseline) refY = yMap.transform(baseline) if doAlign: refY = round(refY) polygon += QPointF(polygon.last().x(), refY) polygon += QPointF(polygon.first().x(), refY) else: if xMap.transformation(): baseline = xMap.transformation().bounded(baseline) refX = xMap.transform(baseline) if doAlign: refX = round(refX) polygon += QPointF(refX, polygon.last().y()) polygon += QPointF(refX, polygon.first().y())
def qwtDrawTriangleSymbols(painter, type, points, numPoint, symbol): size = symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) doAlign = QwtPainter.roundingAlignment(painter) sw2 = .5 * size.width() sh2 = .5 * size.height() if doAlign: sw2 = np.floor(sw2) sh2 = np.floor(sh2) for pos in points: x = pos.x() y = pos.y() if doAlign: x = round(x) y = round(y) x1 = x - sw2 x2 = x1 + size.width() y1 = y - sh2 y2 = y1 + size.height() if type == QwtTriangle.Left: triangle = [QPointF(x2, y1), QPointF(x1, y), QPointF(x2, y2)] elif type == QwtTriangle.Right: triangle = [QPointF(x1, y1), QPointF(x2, y), QPointF(x1, y2)] elif type == QwtTriangle.Up: triangle = [QPointF(x1, y2), QPointF(x, y1), QPointF(x2, y2)] elif type == QwtTriangle.Down: triangle = [QPointF(x1, y1), QPointF(x, y2), QPointF(x2, y1)] QwtPainter.drawPolygon(painter, QPolygonF(triangle))
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 qwtDrawHexagonSymbols(painter, points, numPoints, symbol): painter.setBrush(symbol.brush()) painter.setPen(symbol.pen()) cos30 = np.cos(30 * np.pi / 180.) dx = .5 * (symbol.size().width() - cos30) dy = .25 * symbol.size().height() doAlign = QwtPainter.roundingAlignment(painter) for pos in points: if doAlign: x = round(pos.x()) y = round(pos.y()) x1 = np.ceil(x - dx) y1 = np.ceil(y - 2 * dy) else: x = pos.x() y = pos.y() x1 = x - dx y1 = y - 2 * dy x2 = x1 + 1 * dx x3 = x1 + 2 * dx y2 = y1 + 1 * dy y3 = y1 + 3 * dy y4 = y1 + 4 * dy hexa = [ QPointF(x2, y1), QPointF(x3, y2), QPointF(x3, y3), QPointF(x2, y4), QPointF(x1, y3), QPointF(x1, y2) ] QwtPainter.drawPolygon(painter, QPolygonF(hexa))
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 qwtDrawDiamondSymbols(painter, points, numPoints, symbol): size = symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) if QwtPainter.roundingAlignment(painter): for pos in points: x = round(pos.x()) y = round(pos.y()) x1 = x - size.width() // 2 y1 = y - size.height() // 2 x2 = x1 + size.width() y2 = y1 + size.height() polygon = QPolygonF() polygon += QPointF(x, y1) polygon += QPointF(x1, y) polygon += QPointF(x, y2) polygon += QPointF(x2, y) QwtPainter.drawPolygon(painter, polygon) else: for pos in points: x1 = pos.x() - .5 * size.width() y1 = pos.y() - .5 * size.height() x2 = x1 + size.width() y2 = y1 + size.height() polygon = QPolygonF() polygon += QPointF(pos.x(), y1) polygon += QPointF(x1, pos.y()) polygon += QPointF(pos.x(), y2) polygon += QPointF(x2, pos.y()) QwtPainter.drawPolygon(painter, polygon)
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 drawSymbols(self, painter, symbol, xMap, yMap, canvasRect, from_, to): """ Draw symbols :param QPainter painter: Painter :param qwt.symbol.QwtSymbol symbol: Curve symbol :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:`setSymbol()`, :py:meth:`drawSeries()`, :py:meth:`drawCurve()` """ mapper = QwtPointMapper() mapper.setFlag(QwtPointMapper.RoundPoints, QwtPainter.roundingAlignment(painter)) mapper.setFlag(QwtPointMapper.WeedOutPoints, self.testPaintAttribute(QwtPlotCurve.FilterPoints)) mapper.setBoundingRect(canvasRect) chunkSize = 500 for i in range(from_, to+1, chunkSize): n = min([chunkSize, to-i+1]) points = mapper.toPointsF(xMap, yMap, self.data(), i, i+n-1) if points.size() > 0: symbol.drawSymbols(painter, points)
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 qwtDrawRectSymbols(painter, points, numPoints, symbol): size = symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) painter.setRenderHint(QPainter.Antialiasing, False) if QwtPainter.roundingAlignment(painter): sw = size.width() sh = size.height() sw2 = size.width()//2 sh2 = size.height()//2 for pos in points: x = round(pos.x()) y = round(pos.y()) r = QRectF(x-sw2, y-sh2, sw, sh) QwtPainter.drawRect(painter, r) else: sw = size.width() sh = size.height() sw2 = .5*size.width() sh2 = .5*size.height() for pos in points: x = pos.x() y = pos.y() r = QRectF(x-sw2, y-sh2, sw, sh) QwtPainter.drawRect(painter, r)
def qwtDrawDiamondSymbols(painter, points, numPoints, symbol): size =symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) if QwtPainter.roundingAlignment(painter): for pos in points: x = round(pos.x()) y = round(pos.y()) x1 = x-size.width()//2 y1 = y-size.height()//2 x2 = x1+size.width() y2 = y1+size.height() polygon = QPolygonF() polygon += QPointF(x, y1) polygon += QPointF(x1, y) polygon += QPointF(x, y2) polygon += QPointF(x2, y) QwtPainter.drawPolygon(painter, polygon) else: for pos in points: x1 = pos.x()-.5*size.width() y1 = pos.y()-.5*size.height() x2 = x1+size.width() y2 = y1+size.height() polygon = QPolygonF() polygon += QPointF(pos.x(), y1) polygon += QPointF(x1, pos.y()) polygon += QPointF(pos.x(), y2) polygon += QPointF(x2, pos.y()) QwtPainter.drawPolygon(painter, polygon)
def qwtDrawTriangleSymbols(painter, type, points, numPoint, symbol): size =symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) doAlign = QwtPainter.roundingAlignment(painter) sw2 = .5*size.width() sh2 = .5*size.height() if doAlign: sw2 = np.floor(sw2) sh2 = np.floor(sh2) for pos in points: x = pos.x() y = pos.y() if doAlign: x = round(x) y = round(y) x1 = x-sw2 x2 = x1+size.width() y1 = y-sh2 y2 = y1+size.height() if type == QwtTriangle.Left: triangle = [QPointF(x2, y1), QPointF(x1, y), QPointF(x2, y2)] elif type == QwtTriangle.Right: triangle = [QPointF(x1, y1), QPointF(x2, y), QPointF(x1, y2)] elif type == QwtTriangle.Up: triangle = [QPointF(x1, y2), QPointF(x, y1), QPointF(x2, y2)] elif type == QwtTriangle.Down: triangle = [QPointF(x1, y1), QPointF(x, y2), QPointF(x2, y1)] QwtPainter.drawPolygon(painter, QPolygonF(triangle))
def drawLines(self, painter, xMap, yMap, canvasRect, from_, to): """ Draw lines :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:`drawSticks()` """ if from_ > to: return doAlign = QwtPainter.roundingAlignment(painter) doFill = self.__data.brush.style() != Qt.NoBrush\ and self.__data.brush.color().alpha() > 0 clipRect = QRectF() if self.__data.paintAttributes & self.ClipPolygons: pw = max([1., painter.pen().widthF()]) clipRect = canvasRect.adjusted(-pw, -pw, pw, pw) doIntegers = False if QT_VERSION < 0x040800: if painter.paintEngine().type() == QPaintEngine.Raster: if not doFill: doIntegers = True noDuplicates = self.__data.paintAttributes & self.FilterPoints mapper = QwtPointMapper() mapper.setFlag(QwtPointMapper.RoundPoints, doAlign) mapper.setFlag(QwtPointMapper.WeedOutPoints, noDuplicates) mapper.setBoundingRect(canvasRect) if doIntegers: polyline = mapper.toPolygon(xMap, yMap, self.data(), from_, to) if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygon(clipRect.toAlignedRect(), polyline, False) QwtPainter.drawPolyline(painter, polyline) else: polyline = mapper.toPolygonF(xMap, yMap, self.data(), from_, to) if doFill: if painter.pen().style() != Qt.NoPen: filled = QPolygonF(polyline) self.fillCurve(painter, xMap, yMap, canvasRect, filled) filled.clear() if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF(clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline) else: self.fillCurve(painter, xMap, yMap, canvasRect, polyline) else: if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF(clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline)
def drawLines(self, painter, xMap, yMap, canvasRect, from_, to): """ Draw lines :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:`drawSticks()` """ if from_ > to: return doAlign = QwtPainter.roundingAlignment(painter) doFill = self.__data.brush.style() != Qt.NoBrush\ and self.__data.brush.color().alpha() > 0 clipRect = QRectF() if self.__data.paintAttributes & self.ClipPolygons: pw = max([1., painter.pen().widthF()]) clipRect = canvasRect.adjusted(-pw, -pw, pw, pw) doIntegers = False if QT_VERSION < 0x040800: if painter.paintEngine().type() == QPaintEngine.Raster: if not doFill: doIntegers = True noDuplicates = self.__data.paintAttributes & self.FilterPoints mapper = QwtPointMapper() mapper.setFlag(QwtPointMapper.RoundPoints, doAlign) mapper.setFlag(QwtPointMapper.WeedOutPoints, noDuplicates) mapper.setBoundingRect(canvasRect) if doIntegers: polyline = mapper.toPolygon(xMap, yMap, self.data(), from_, to) if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygon(clipRect.toAlignedRect(), polyline, False) QwtPainter.drawPolyline(painter, polyline) else: polyline = mapper.toPolygonF(xMap, yMap, self.data(), from_, to) if doFill: if painter.pen().style() != Qt.NoPen: filled = QPolygonF(polyline) self.fillCurve(painter, xMap, yMap, canvasRect, filled) filled.clear() if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF( clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline) else: self.fillCurve(painter, xMap, yMap, canvasRect, polyline) else: if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF( clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline)
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 drawSymbols(self, painter, points, numPoints=None): """ Render an array of symbols Painting several symbols is more effective than drawing symbols one by one, as a couple of layout calculations and setting of pen/brush can be done once for the complete array. :param QPainter painter: Painter :param QPolygonF points: Positions of the symbols in screen coordinates """ #TODO: remove argument numPoints (not necessary in `PythonQwt`) if numPoints is not None and numPoints <= 0: return useCache = False if QwtPainter.roundingAlignment(painter) and\ not painter.transform().isScaling(): if self.__data.cache.policy == QwtSymbol.Cache: useCache = True elif self.__data.cache.policy == QwtSymbol.AutoCache: if painter.paintEngine().type() == QPaintEngine.Raster: useCache = True else: if self.__data.style in (QwtSymbol.XCross, QwtSymbol.HLine, QwtSymbol.VLine, QwtSymbol.Cross): pass elif self.__data.style == QwtSymbol.Pixmap: if not self.__data.size.isEmpty() and\ self.__data.size != self.__data.pixmap.pixmap.size(): useCache = True else: useCache = True if useCache: br = QRect(self.boundingRect()) rect = QRect(0, 0, br.width(), br.height()) if self.__data.cache.pixmap.isNull(): self.__data.cache.pixmap = QwtPainter.backingStore( None, br.size()) self.__data.cache.pixmap.fill(Qt.transparent) p = QPainter(self.__data.cache.pixmap) p.setRenderHints(painter.renderHints()) p.translate(-br.topLeft()) pos = QPointF() self.renderSymbols(p, pos, 1) dx = br.left() dy = br.top() for point in points: left = round(point.x()) + dx top = round(point.y()) + dy painter.drawPixmap(left, top, self.__data.cache.pixmap) else: painter.save() self.renderSymbols(painter, points, numPoints) painter.restore()
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 drawSymbols(self, painter, points, numPoints=None): """ Render an array of symbols Painting several symbols is more effective than drawing symbols one by one, as a couple of layout calculations and setting of pen/brush can be done once for the complete array. :param QPainter painter: Painter :param QPolygonF points: Positions of the symbols in screen coordinates """ #TODO: remove argument numPoints (not necessary in `PythonQwt`) if numPoints is not None and numPoints <= 0: return useCache = False if QwtPainter.roundingAlignment(painter) and\ not painter.transform().isScaling(): if self.__data.cache.policy == QwtSymbol.Cache: useCache = True elif self.__data.cache.policy == QwtSymbol.AutoCache: if painter.paintEngine().type() == QPaintEngine.Raster: useCache = True else: if self.__data.style in (QwtSymbol.XCross, QwtSymbol.HLine, QwtSymbol.VLine, QwtSymbol.Cross): pass elif self.__data.style == QwtSymbol.Pixmap: if not self.__data.size.isEmpty() and\ self.__data.size != self.__data.pixmap.pixmap.size(): useCache = True else: useCache = True if useCache: br = QRect(self.boundingRect()) rect = QRect(0, 0, br.width(), br.height()) if self.__data.cache.pixmap.isNull(): self.__data.cache.pixmap = QwtPainter.backingStore(None, br.size()) self.__data.cache.pixmap.fill(Qt.transparent) p = QPainter(self.__data.cache.pixmap) p.setRenderHints(painter.renderHints()) p.translate(-br.topLeft()) pos = QPointF() self.renderSymbols(p, pos, 1) dx = br.left() dy = br.top() for point in points: left = round(point.x())+dx top = round(point.y())+dy painter.drawPixmap(left, top, self.__data.cache.pixmap) else: painter.save() self.renderSymbols(painter, points, numPoints) painter.restore()
def drawColumn(self, painter, rect, sample): if self.__data.symbol and\ self.__data.symbol.style() != QwtColumnSymbol.NoStyle: self.__data.symbol.draw(painter, rect) else: r = QRectF(rect.toRect()) if QwtPainter.roundingAlignment(painter): r.setLeft(round(r.left())) r.setRight(round(r.right())) r.setTop(round(r.top())) r.setBottom(round(r.bottom())) QwtPainter.drawRect(painter, r)
def drawSymbols(self, painter, symbol, xMap, yMap, canvasRect, from_, to): mapper = QwtPointMapper() mapper.setFlag(QwtPointMapper.RoundPoints, QwtPainter.roundingAlignment(painter)) mapper.setFlag(QwtPointMapper.WeedOutPoints, self.testPaintAttribute(QwtPlotCurve.FilterPoints)) mapper.setBoundingRect(canvasRect) chunkSize = 500 for i in range(from_, to + 1, chunkSize): n = min([chunkSize, to - i + 1]) points = mapper.toPointsF(xMap, yMap, self.data(), i, i + n - 1) if points.size() > 0: symbol.drawSymbols(painter, points)
def drawSymbols(self, painter, symbol, xMap, yMap, canvasRect, from_, to): mapper = QwtPointMapper() mapper.setFlag(QwtPointMapper.RoundPoints, QwtPainter.roundingAlignment(painter)) mapper.setFlag(QwtPointMapper.WeedOutPoints, self.testPaintAttribute(QwtPlotCurve.FilterPoints)) mapper.setBoundingRect(canvasRect) chunkSize = 500 for i in range(from_, to+1, chunkSize): n = min([chunkSize, to-i+1]) points = mapper.toPointsF(xMap, yMap, self.data(), i, i+n-1) if points.size() > 0: symbol.drawSymbols(painter, points)
def drawLines(self, painter, xMap, yMap, canvasRect, from_, to): if from_ > to: return doAlign = QwtPainter.roundingAlignment(painter) doFit = (self.__data.attributes & self.Fitted)\ and self.__data.curveFitter doFill = self.__data.brush.style() != Qt.NoBrush\ and self.__data.brush.color().alpha() > 0 clipRect = QRectF() if self.__data.paintAttributes & self.ClipPolygons: pw = max([1., painter.pen().widthF()]) clipRect = canvasRect.adjusted(-pw, -pw, pw, pw) doIntegers = False if QT_VERSION < 0x040800: if painter.paintEngine().type() == QPaintEngine.Raster: if not doFit and not doFill: doIntegers = True noDuplicates = self.__data.paintAttributes & self.FilterPoints mapper = QwtPointMapper() mapper.setFlag(QwtPointMapper.RoundPoints, doAlign) mapper.setFlag(QwtPointMapper.WeedOutPoints, noDuplicates) mapper.setBoundingRect(canvasRect) if doIntegers: polyline = mapper.toPolygon(xMap, yMap, self.data(), from_, to) if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygon(clipRect.toAlignedRect(), polyline, False) QwtPainter.drawPolyline(painter, polyline) else: polyline = mapper.toPolygonF(xMap, yMap, self.data(), from_, to) if doFit: polyline = self.__data.curveFitter.fitCurve(polyline) if doFill: if painter.pen().style() != Qt.NoPen: filled = QPolygonF(polyline) self.fillCurve(painter, xMap, yMap, canvasRect, filled) filled.clear() if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF(clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline) else: self.fillCurve(painter, xMap, yMap, canvasRect, polyline) else: if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF(clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline)
def drawLines(self, painter, xMap, yMap, canvasRect, from_, to): if from_ > to: return doAlign = QwtPainter.roundingAlignment(painter) doFit = (self.__data.attributes & self.Fitted)\ and self.__data.curveFitter doFill = self.__data.brush.style() != Qt.NoBrush\ and self.__data.brush.color().alpha() > 0 clipRect = QRectF() if self.__data.paintAttributes & self.ClipPolygons: pw = max([1., painter.pen().widthF()]) clipRect = canvasRect.adjusted(-pw, -pw, pw, pw) doIntegers = False if QT_VERSION < 0x040800: if painter.paintEngine().type() == QPaintEngine.Raster: if not doFit and not doFill: doIntegers = True noDuplicates = self.__data.paintAttributes & self.FilterPoints mapper = QwtPointMapper() mapper.setFlag(QwtPointMapper.RoundPoints, doAlign) mapper.setFlag(QwtPointMapper.WeedOutPoints, noDuplicates) mapper.setBoundingRect(canvasRect) if doIntegers: polyline = mapper.toPolygon(xMap, yMap, self.data(), from_, to) if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygon(clipRect.toAlignedRect(), polyline, False) QwtPainter.drawPolyline(painter, polyline) else: polyline = mapper.toPolygonF(xMap, yMap, self.data(), from_, to) if doFit: polyline = self.__data.curveFitter.fitCurve(polyline) if doFill: if painter.pen().style() != Qt.NoPen: filled = QPolygonF(polyline) self.fillCurve(painter, xMap, yMap, canvasRect, filled) filled.clear() if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF( clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline) else: self.fillCurve(painter, xMap, yMap, canvasRect, polyline) else: if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF( clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline)
def qwtDrawStar2Symbols(painter, points, numPoints, symbol): pen = QPen(symbol.pen()) if pen.width() > 1: pen.setCapStyle(Qt.FlatCap) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) cos30 = np.cos(30 * np.pi / 180.) dy = .25 * symbol.size().height() dx = .5 * symbol.size().width() * cos30 / 3. doAlign = QwtPainter.roundingAlignment(painter) for pos in points: if doAlign: x = round(pos.x()) y = round(pos.y()) x1 = round(x - 3 * dx) y1 = round(y - 2 * dy) else: x = pos.x() y = pos.y() x1 = x - 3 * dx y1 = y - 2 * dy x2 = x1 + 1 * dx x3 = x1 + 2 * dx x4 = x1 + 3 * dx x5 = x1 + 4 * dx x6 = x1 + 5 * dx x7 = x1 + 6 * dx y2 = y1 + 1 * dy y3 = y1 + 2 * dy y4 = y1 + 3 * dy y5 = y1 + 4 * dy star = [ QPointF(x4, y1), QPointF(x5, y2), QPointF(x7, y2), QPointF(x6, y3), QPointF(x7, y4), QPointF(x5, y4), QPointF(x4, y5), QPointF(x3, y4), QPointF(x1, y4), QPointF(x2, y3), QPointF(x1, y2), QPointF(x3, y2) ] QwtPainter.drawPolygon(painter, QPolygonF(star))
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 drawDots(self, painter, xMap, yMap, canvasRect, from_, to): """ Draw dots :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:`drawSticks()`, :py:meth:`drawSteps()`, :py:meth:`drawLines()` """ color = painter.pen().color() if painter.pen().style() == Qt.NoPen or color.alpha() == 0: return doFill = self.__data.brush.style() != Qt.NoBrush\ and self.__data.brush.color().alpha() > 0 doAlign = QwtPainter.roundingAlignment(painter) mapper = QwtPointMapper() mapper.setBoundingRect(canvasRect) mapper.setFlag(QwtPointMapper.RoundPoints, doAlign) if self.__data.paintAttributes & self.FilterPoints: if color.alpha() == 255\ and not (painter.renderHints() & QPainter.Antialiasing): mapper.setFlag(QwtPointMapper.WeedOutPoints, True) if doFill: mapper.setFlag(QwtPointMapper.WeedOutPoints, False) points = mapper.toPointsF(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points) self.fillCurve(painter, xMap, yMap, canvasRect, points) elif self.__data.paintAttributes & self.ImageBuffer: image = mapper.toImage( xMap, yMap, self.data(), from_, to, self.__data.pen, painter.testRenderHint(QPainter.Antialiasing)) painter.drawImage(canvasRect.toAlignedRect(), image) else: if doAlign: points = mapper.toPoints(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points) else: points = mapper.toPointsF(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points)
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 drawDots(self, painter, xMap, yMap, canvasRect, from_, to): """ Draw dots :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:`drawSticks()`, :py:meth:`drawSteps()`, :py:meth:`drawLines()` """ color = painter.pen().color() if painter.pen().style() == Qt.NoPen or color.alpha() == 0: return doFill = self.__data.brush.style() != Qt.NoBrush\ and self.__data.brush.color().alpha() > 0 doAlign = QwtPainter.roundingAlignment(painter) mapper = QwtPointMapper() mapper.setBoundingRect(canvasRect) mapper.setFlag(QwtPointMapper.RoundPoints, doAlign) if self.__data.paintAttributes & self.FilterPoints: if color.alpha() == 255\ and not (painter.renderHints() & QPainter.Antialiasing): mapper.setFlag(QwtPointMapper.WeedOutPoints, True) if doFill: mapper.setFlag(QwtPointMapper.WeedOutPoints, False) points = mapper.toPointsF(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points) self.fillCurve(painter, xMap, yMap, canvasRect, points) elif self.__data.paintAttributes & self.ImageBuffer: image = mapper.toImage(xMap, yMap, self.data(), from_, to, self.__data.pen, painter.testRenderHint(QPainter.Antialiasing)) painter.drawImage(canvasRect.toAlignedRect(), image) else: if doAlign: points = mapper.toPoints(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points) else: points = mapper.toPointsF(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points)
def drawSteps(self, painter, xMap, yMap, canvasRect, from_, to): """ Draw steps :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:`drawSticks()`, :py:meth:`drawDots()`, :py:meth:`drawLines()` """ doAlign = QwtPainter.roundingAlignment(painter) polygon = QPolygonF(2 * (to - from_) + 1) inverted = self.orientation() == Qt.Vertical if self.__data.attributes & self.Inverted: inverted = not inverted series = self.data() ip = 0 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 ip > 0: p0 = polygon[ip - 2] if inverted: polygon[ip - 1] = QPointF(p0.x(), yi) else: polygon[ip - 1] = QPointF(xi, p0.y()) polygon[ip] = QPointF(xi, yi) ip += 2 if self.__data.paintAttributes & self.ClipPolygons: clipped = QwtClipper().clipPolygonF(canvasRect, polygon, False) QwtPainter.drawPolyline(painter, clipped) else: QwtPainter.drawPolyline(painter, polygon) if self.__data.brush.style() != Qt.NoBrush: self.fillCurve(painter, xMap, yMap, canvasRect, polygon)
def drawOutline(self, painter, xMap, yMap, from_, to): doAlign = QwtPainter.roundingAlignment(painter) if self.orientation() == Qt.Horizontal: v0 = xMap.transform(self.baseline()) else: v0 = yMap.transform(self.baseline()) if doAlign: v0 = round(v0) previous = QwtIntervalSample() polygon = QPolygonF() for i in range(from_, to + 1): sample = self.sample(i) if not sample.interval.isValid(): self.flushPolygon(painter, v0, polygon) previous = sample continue if previous.interval.isValid(): if not qwtIsCombinable(previous.interval, sample.interval): self.flushPolygon(painter, v0, polygon) if self.orientation() == Qt.Vertical: x1 = xMap.transform(sample.interval.minValue()) x2 = xMap.transform(sample.interval.maxValue()) y = yMap.transform(sample.value) if doAlign: x1 = round(x1) x2 = round(x2) y = round(y) if polygon.size() == 0: polygon += QPointF(x1, v0) polygon += QPointF(x1, y) polygon += QPointF(x2, y) else: y1 = yMap.transform(sample.interval.minValue()) y2 = yMap.transform(sample.interval.maxValue()) x = xMap.transform(sample.value) if doAlign: y1 = round(y1) y2 = round(y2) x = round(x) if polygon.size() == 0: polygon += QPointF(v0, y1) polygon += QPointF(x, y1) polygon += QPointF(x, y2) previous = sample self.flushPolygon(painter, v0, polygon)
def drawSteps(self, painter, xMap, yMap, canvasRect, from_, to): """ Draw steps :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:`drawSticks()`, :py:meth:`drawDots()`, :py:meth:`drawLines()` """ doAlign = QwtPainter.roundingAlignment(painter) polygon = QPolygonF(2*(to-from_)+1) inverted = self.orientation() == Qt.Vertical if self.__data.attributes & self.Inverted: inverted = not inverted series = self.data() ip = 0 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 ip > 0: p0 = polygon[ip-2] if inverted: polygon[ip-1] = QPointF(p0.x(), yi) else: polygon[ip-1] = QPointF(xi, p0.y()) polygon[ip] = QPointF(xi, yi) ip += 2 if self.__data.paintAttributes & self.ClipPolygons: clipped = QwtClipper().clipPolygonF(canvasRect, polygon, False) QwtPainter.drawPolyline(painter, clipped) else: QwtPainter.drawPolyline(painter, polygon) if self.__data.brush.style() != Qt.NoBrush: self.fillCurve(painter, xMap, yMap, canvasRect, polygon)
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_): 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 drawSymbols(self, painter, points, numPoints=None): #TODO: remove argument numPoints (not necessary in Python's qwt) if numPoints is not None and numPoints <= 0: return useCache = False if QwtPainter.roundingAlignment(painter) and\ not painter.transform().isScaling(): if self.__data.cache.policy == QwtSymbol.Cache: useCache = True elif self.__data.cache.policy == QwtSymbol.AutoCache: if painter.paintEngine().type() == QPaintEngine.Raster: useCache = True else: if self.__data.style in (QwtSymbol.XCross, QwtSymbol.HLine, QwtSymbol.VLine, QwtSymbol.Cross): pass elif self.__data.style == QwtSymbol.Pixmap: if not self.__data.size.isEmpty() and\ self.__data.size != self.__data.pixmap.pixmap.size(): useCache = True else: useCache = True if useCache: br = QRect(self.boundingRect()) rect = QRect(0, 0, br.width(), br.height()) if self.__data.cache.pixmap.isNull(): self.__data.cache.pixmap = QwtPainter.backingStore(None, br.size()) self.__data.cache.pixmap.fill(Qt.transparent) p = QPainter(self.__data.cache.pixmap) p.setRenderHints(painter.renderHints()) p.translate(-br.topLeft()) pos = QPointF() self.renderSymbols(p, pos, 1) dx = br.left() dy = br.top() for point in points: left = round(point.x())+dx top = round(point.y())+dy painter.drawPixmap(left, top, self.__data.cache.pixmap) else: painter.save() self.renderSymbols(painter, points, numPoints) painter.restore()
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 drawDots(self, painter, xMap, yMap, canvasRect, from_, to): color = painter.pen().color() if painter.pen().style() == Qt.NoPen or color.alpha() == 0: return doFill = self.__data.brush.style() != Qt.NoBrush\ and self.__data.brush.color().alpha() > 0 doAlign = QwtPainter.roundingAlignment(painter) mapper = QwtPointMapper() mapper.setBoundingRect(canvasRect) mapper.setFlag(QwtPointMapper.RoundPoints, doAlign) if self.__data.paintAttributes & self.FilterPoints: if color.alpha() == 255\ and not (painter.renderHints() & QPainter.Antialiasing): mapper.setFlag(QwtPointMapper.WeedOutPoints, True) if doFill: mapper.setFlag(QwtPointMapper.WeedOutPoints, False) points = mapper.toPointsF(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points) self.fillCurve(painter, xMap, yMap, canvasRect, points) elif self.__data.paintAttributes & self.ImageBuffer: image = mapper.toImage(xMap, yMap, self.data(), from_, to, self.__data.pen, painter.testRenderHint(QPainter.Antialiasing), self.renderThreadCount()) painter.drawImage(canvasRect.toAlignedRect(), image) elif self.__data.paintAttributes & self.MinimizeMemory: 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) QwtPainter.drawPoint(painter, QPointF(xi, yi)) else: if doAlign: points = mapper.toPoints(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points) else: points = mapper.toPointsF(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points)
def drawDots(self, painter, xMap, yMap, canvasRect, from_, to): color = painter.pen().color() if painter.pen().style() == Qt.NoPen or color.alpha() == 0: return doFill = self.__data.brush.style() != Qt.NoBrush\ and self.__data.brush.color().alpha() > 0 doAlign = QwtPainter.roundingAlignment(painter) mapper = QwtPointMapper() mapper.setBoundingRect(canvasRect) mapper.setFlag(QwtPointMapper.RoundPoints, doAlign) if self.__data.paintAttributes & self.FilterPoints: if color.alpha() == 255\ and not (painter.renderHints() & QPainter.Antialiasing): mapper.setFlag(QwtPointMapper.WeedOutPoints, True) if doFill: mapper.setFlag(QwtPointMapper.WeedOutPoints, False) points = mapper.toPointsF(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points) self.fillCurve(painter, xMap, yMap, canvasRect, points) elif self.__data.paintAttributes & self.ImageBuffer: image = mapper.toImage( xMap, yMap, self.data(), from_, to, self.__data.pen, painter.testRenderHint(QPainter.Antialiasing), self.renderThreadCount()) painter.drawImage(canvasRect.toAlignedRect(), image) elif self.__data.paintAttributes & self.MinimizeMemory: 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) QwtPainter.drawPoint(painter, QPointF(xi, yi)) else: if doAlign: points = mapper.toPoints(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points) else: points = mapper.toPointsF(xMap, yMap, self.data(), from_, to) QwtPainter.drawPoints(painter, points)
def closePolyline(self, painter, xMap, yMap, polygon): if polygon.size() < 2: return doAlign = QwtPainter.roundingAlignment(painter) baseline = self.__data.baseline if self.orientation() == Qt.Vertical: if yMap.transformation(): baseline = yMap.transformation().bounded(baseline) refY = yMap.transform(baseline) if doAlign: refY = round(refY) polygon += QPointF(polygon.last().x(), refY) polygon += QPointF(polygon.first().x(), refY) else: if xMap.transformation(): baseline = xMap.transformation().bounded(baseline) refX = xMap.transform(baseline) if doAlign: refX = round(refX) polygon += QPointF(refX, polygon.last().y()) polygon += QPointF(refX, polygon.first().y())
def closePolyline(self, painter, xMap, yMap, polygon): if polygon.size() < 2: return doAlign = QwtPainter.roundingAlignment(painter) baseline = self.__data.baseline if self.orientation() == Qt.Vertical: if yMap.transformation(): baseline = yMap.transformation().bounded(baseline) refY = yMap.transform(baseline) if doAlign: refY = round(refY) polygon += QPointF(polygon.last().x(), refY) polygon += QPointF(polygon.first().x(), refY) else: if xMap.transformation(): baseline = xMap.transformation().bounded(baseline) refX = xMap.transform(baseline) if doAlign: refX = round(refX) polygon += QPointF(refX, polygon.last().y()) polygon += QPointF(refX, polygon.first().y())
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 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 qwtDrawStar2Symbols(painter, points, numPoints, symbol): pen = QPen(symbol.pen()) if pen.width() > 1: pen.setCapStyle(Qt.FlatCap) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) cos30 = np.cos(30*np.pi/180.) dy = .25*symbol.size().height() dx = .5*symbol.size().width()*cos30/3. doAlign = QwtPainter.roundingAlignment(painter) for pos in points: if doAlign: x = round(pos.x()) y = round(pos.y()) x1 = round(x-3*dx) y1 = round(y-2*dy) else: x = pos.x() y = pos.y() x1 = x-3*dx y1 = y-2*dy x2 = x1+1*dx x3 = x1+2*dx x4 = x1+3*dx x5 = x1+4*dx x6 = x1+5*dx x7 = x1+6*dx y2 = y1+1*dy y3 = y1+2*dy y4 = y1+3*dy y5 = y1+4*dy star = [QPointF(x4, y1), QPointF(x5, y2), QPointF(x7, y2), QPointF(x6, y3), QPointF(x7, y4), QPointF(x5, y4), QPointF(x4, y5), QPointF(x3, y4), QPointF(x1, y4), QPointF(x2, y3), QPointF(x1, y2), QPointF(x3, y2)] QwtPainter.drawPolygon(painter, QPolygonF(star))
def qwtDrawEllipseSymbols(painter, points, numPoints, symbol): painter.setBrush(symbol.brush()) painter.setPen(symbol.pen()) size =symbol.size() if QwtPainter.roundingAlignment(painter): sw = size.width() sh = size.height() sw2 = size.width()//2 sh2 = size.height()//2 for pos in points: x = round(pos.x()) y = round(pos.y()) r = QRectF(x-sw2, y-sh2, sw, sh) QwtPainter.drawEllipse(painter, r) else: sw = size.width() sh = size.height() sw2 = .5*size.width() sh2 = .5*size.height() for pos in points: x = pos.x() y = pos.y() r = QRectF(x-sw2, y-sh2, sw, sh) QwtPainter.drawEllipse(painter, r)