def picture_children(): # Return a QPicture displaying all children patches of this # node. pic = QPicture() painter = QPainter(pic) for ch in child_patches(): painter.drawPicture(0, 0, ch.picture()) painter.end() return pic
def __paint(self): picture = QPicture() painter = QPainter(picture) pen = QPen(QBrush(Qt.white), 0.5) pen.setCosmetic(True) painter.setPen(pen) geom = self.geometry x, y = geom.x(), geom.y() w, h = geom.width(), geom.height() wsingle = w / len(self.dist) for d, c in zip(self.dist, self.colors): painter.setBrush(QBrush(c)) painter.drawRect(QRectF(x, y, wsingle, d * h)) x += wsingle painter.end() self.__picture = picture
def picture_this_level(): # Create a QPicture drawing the contribution from this # level only. This is all regions where the contingency is # not empty and does not have a computed sub-contingency # (i.e. the node does not have a child in that cell). pic = QPicture() painter = QPainter(pic) ctng = node.contingencies colors = create_image(ctng, palette, scale=scale) x, y, w, h = node.brect N, M = ctng.shape[:2] # Nonzero contingency mask any_mask = Node_mask(node) if node.is_leaf: skip = itertools.repeat(False) else: # Skip all None children they were already painted. skip = (ch is not None for ch in node.children.flat) painter.save() painter.translate(x, y) painter.scale(w / node.nbins, h / node.nbins) indices = itertools.product(range(N), range(M)) for (i, j), skip, any_ in zip(indices, skip, any_mask.flat): if not skip and any_: painter.setBrush(QColor(*colors[i, j])) if shape == Rect: painter.drawRect(i, j, 1, 1) elif shape == Circle: painter.drawEllipse(i, j, 1, 1) elif shape == RoundRect: painter.drawRoundedRect(i, j, 1, 1, 25.0, 25.0, Qt.RelativeSize) painter.restore() painter.end() return pic
def Patch_create(node, palette=None, scale=None, shape=Rect): """ Return a `Patch` for visualizing `node`. .. note:: The patch (picture and children fields) are evaluated lazily. :type node: Tree :type palette: colorpalette.PaletteGenerator :type scale: nparray -> ndarray :type shape: int :rtype: Patch """ if node.is_empty: return Patch(node, once(lambda: QPicture()), once(lambda: ())) else: @once def picture_this_level(): # Create a QPicture drawing the contribution from this # level only. This is all regions where the contingency is # not empty and does not have a computed sub-contingency # (i.e. the node does not have a child in that cell). pic = QPicture() painter = QPainter(pic) ctng = node.contingencies colors = create_image(ctng, palette, scale=scale) x, y, w, h = node.brect N, M = ctng.shape[:2] # Nonzero contingency mask any_mask = Node_mask(node) if node.is_leaf: skip = itertools.repeat(False) else: # Skip all None children they were already painted. skip = (ch is not None for ch in node.children.flat) painter.save() painter.translate(x, y) painter.scale(w / node.nbins, h / node.nbins) indices = itertools.product(range(N), range(M)) for (i, j), skip, any_ in zip(indices, skip, any_mask.flat): if not skip and any_: painter.setBrush(QColor(*colors[i, j])) if shape == Rect: painter.drawRect(i, j, 1, 1) elif shape == Circle: painter.drawEllipse(i, j, 1, 1) elif shape == RoundRect: painter.drawRoundedRect(i, j, 1, 1, 25.0, 25.0, Qt.RelativeSize) painter.restore() painter.end() return pic @once def child_patches(): # Return a tuple of all non empty child patches for this node. if node.is_leaf: children = [] else: children = filter(is_not_none, node.children.flat) return tuple(Patch_create(child, palette, scale, shape) for child in children) + \ (Patch(node, picture_this_level, once(lambda: ())),) @once def picture_children(): # Return a QPicture displaying all children patches of this # node. pic = QPicture() painter = QPainter(pic) for ch in child_patches(): painter.drawPicture(0, 0, ch.picture()) painter.end() return pic return Patch(node, picture_children, child_patches)