Exemple #1
0
class LegendItemCircle(ColorIndicator):
    """Legend circle item.

    The legend circle item is a small colored circle image that can be plugged
    into the legend in front of the text object.

    This should only really be used in conjunction with ˙LegendItem˙.

    Parameters
    ----------
    color : QColor
        The color of the square.
    parent : QGraphicsItem

    See Also
    --------
    LegendItemSquare

    """

    SIZE = QSizeF(12, 12)
    _size_hint = SIZE

    def __init__(self, color, parent):
        super().__init__(parent)

        height, width = self.SIZE.height(), self.SIZE.width()
        self.__circle = QGraphicsEllipseItem(0, 0, height, width)
        self.__circle.setBrush(QBrush(color))
        self.__circle.setPen(QPen(QColor(0, 0, 0, 0)))
        self.__circle.setParentItem(self)
        self._size_hint = QSizeF(self.__circle.boundingRect().size())

    def sizeHint(self, size_hint, size_constraint=None, *args, **kwargs):
        return self._size_hint
Exemple #2
0
class LegendItemCircle(ColorIndicator):
    """Legend circle item.

    The legend circle item is a small colored circle image that can be plugged
    into the legend in front of the text object.

    This should only really be used in conjunction with ˙LegendItem˙.

    Parameters
    ----------
    color : QColor
        The color of the square.
    parent : QGraphicsItem

    See Also
    --------
    LegendItemSquare

    """

    SIZE = QSizeF(12, 12)
    _size_hint = SIZE

    def __init__(self, color, parent):
        super().__init__(parent)

        height, width = self.SIZE.height(), self.SIZE.width()
        self.__circle = QGraphicsEllipseItem(0, 0, height, width)
        self.__circle.setBrush(QBrush(color))
        self.__circle.setPen(QPen(QColor(0, 0, 0, 0)))
        self.__circle.setParentItem(self)
        self._size_hint = QSizeF(self.__circle.boundingRect().size())

    def sizeHint(self, size_hint, size_constraint=None, *args, **kwargs):
        return self._size_hint
 def place_point(_x, _y, _c):
     item = QGraphicsEllipseItem()
     item.setX(_x)
     item.setY(_y)
     item.setRect(0, 0, self.POINT_R, self.POINT_R)
     color = QColor(*_c)
     item.setPen(QPen(color))
     item.setBrush(QBrush(color))
     self._group.addToGroup(item)
 def put_point(_x, _y):
     item = QGraphicsEllipseItem()
     item.setX(_x)
     item.setY(_y)
     item.setRect(0, 0, self.POINT_R, self.POINT_R)
     color = QColor(*colors.pop().astype(int))
     item.setPen(QPen(color))
     item.setBrush(QBrush(color))
     self.__group.addToGroup(item)
 def pie_chart(self, x, y, r, dist, colors):
     start_angle = 0
     dist = np.asarray(dist)
     spans = dist / (float(np.sum(dist)) or 1) * 360 * 16
     for span, color in zip(spans, colors):
         if not span:
             continue
         if self.explode:
             mid_ang = (start_angle + span / 2) / 360 / 16 * 2 * pi
             dx = r / 30 * cos(mid_ang)
             dy = r / 30 * sin(mid_ang)
         else:
             dx = dy = 0
         ellipse = QGraphicsEllipseItem(x - r / 2 + dx, y - r / 2 - dy, r, r)
         if len(spans) > 1:
             ellipse.setStartAngle(start_angle)
             ellipse.setSpanAngle(span)
         ellipse.setBrush(QColor(*color))
         self.scene.addItem(ellipse)
         start_angle += span
 def pie_chart(self, x, y, r, dist, colors):
     start_angle = 0
     dist = np.asarray(dist)
     spans = dist / (float(np.sum(dist)) or 1) * 360 * 16
     for span, color in zip(spans, colors):
         if not span:
             continue
         if self.explode:
             mid_ang = (start_angle + span / 2) / 360 / 16 * 2 * pi
             dx = r / 30 * cos(mid_ang)
             dy = r / 30 * sin(mid_ang)
         else:
             dx = dy = 0
         ellipse = QGraphicsEllipseItem(x - r / 2 + dx, y - r / 2 - dy, r,
                                        r)
         if len(spans) > 1:
             ellipse.setStartAngle(start_angle)
             ellipse.setSpanAngle(span)
         ellipse.setBrush(QColor(*color))
         self.scene.addItem(ellipse)
         start_angle += span
Exemple #7
0
class CircleCurve(OWCurve):
    """
        Displays a circle on the plot

        :param pen: The pen used to draw the outline of the circle
        :type pen: QPen

        :param brush: The brush used to paint the inside of the circle
        :type brush: QBrush

        :param xCenter: The x coordinate of the circle's center
        :type xCenter: float

        :param yCenter: The y coordinate of the circle's center
        :type yCenter: float

        :param radius: The circle's radius
        :type radius: float
    """
    def __init__(self, pen = QPen(Qt.black), brush = QBrush(Qt.NoBrush), xCenter = 0.0, yCenter = 0.0, radius = 1.0):
        OWCurve.__init__(self)
        self._item = QGraphicsEllipseItem(self)
        self.center = xCenter, yCenter
        self.radius = radius
        self._rect = QRectF(xCenter-radius, yCenter-radius, 2*radius, 2*radius)
        self.set_pen(pen)
        self.set_brush(brush)

    def update_properties(self):
        self._item.setRect(self.graph_transform().mapRect(self.data_rect()))
        self._item.setPen(self.pen())
        self._item.setBrush(self.brush())

    def data_rect(self):
        x, y = self.center
        r = self.radius
        return QRectF(x-r, y-r, 2*r, 2*r)