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 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 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 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 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 fillCurve(self, painter, xMap, yMap, canvasRect, polygon): """ Fill the area between the curve and the baseline with the curve brush :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 QPolygonF polygon: Polygon - will be modified ! .. seealso:: :py:meth:`setBrush()`, :py:meth:`setBaseline()`, :py:meth:`setStyle()` """ if self.__data.brush.style() == Qt.NoBrush: return self.closePolyline(painter, xMap, yMap, polygon) if polygon.count() <= 2: return brush = self.__data.brush if not brush.color().isValid(): brush.setColor(self.__data.pen.color()) if self.__data.paintAttributes & self.ClipPolygons: polygon = QwtClipper().clipPolygonF(canvasRect, polygon, True) painter.save() painter.setPen(Qt.NoPen) painter.setBrush(brush) QwtPainter.drawPolygon(painter, polygon) painter.restore()
def fillCurve(self, painter, xMap, yMap, canvasRect, polygon): if self.__data.brush.style() == Qt.NoBrush: return self.closePolyline(painter, xMap, yMap, polygon) if polygon.count() <= 2: return brush = self.__data.brush if not brush.color().isValid(): brush.setColor(self.__data.pen.color()) if self.__data.paintAttributes & self.ClipPolygons: polygon = QwtClipper().clipPolygonF(canvasRect, polygon, True) painter.save() painter.setPen(Qt.NoPen) painter.setBrush(brush) QwtPainter.drawPolygon(painter, polygon) painter.restore()
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 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 flushPolygon(self, painter, baseline, polygon): if polygon.size() == 0: return if self.orientation() == Qt.Horizontal: polygon += QPointF(baseline, polygon[-1].y()) else: polygon += QPointF(polygon[-1].x(), baseline) if self.__data.brush.style() != Qt.NoBrush: painter.setPen(Qt.NoPen) painter.setBrush(self.__data.brush) if self.orientation() == Qt.Horizontal: polygon += QPointF(polygon[-1].x(), baseline) polygon += QPointF(polygon[0].x(), baseline) else: polygon += QPointF(baseline, polygon[-1].y()) polygon += QPointF(baseline, polygon[0].y()) QwtPainter.drawPolygon(painter, polygon) polygon.pop(-1) polygon.pop(-1) if self.__data.pen.style != Qt.NoPen: painter.setBrush(Qt.NoBrush) painter.setPen(self.__data.pen) QwtPainter.drawPolyline(painter, polygon) polygon.clear()