Example #1
0
    def getNodeItemForSubgraph(self, subgraph, highlight_level, scene=None):
        # let pydot imitate pygraphviz api
        attr = {}
        for name in subgraph.get_attributes().keys():
            value = get_unquoted(subgraph, name)
            attr[name] = value
        obj_dic = subgraph.__getattribute__('obj_dict')
        for name in obj_dic:
            if name not in ['nodes', 'attributes', 'parent_graph'
                            ] and obj_dic[name] is not None:
                attr[name] = get_unquoted(obj_dic, name)
            elif name == 'nodes':
                for key in obj_dic['nodes']['graph'][0]['attributes']:
                    attr[key] = get_unquoted(
                        obj_dic['nodes']['graph'][0]['attributes'], key)
        subgraph.attr = attr

        bb = subgraph.attr.get('bb', None)
        if bb is None:
            # no bounding box
            return None
        bb = bb.strip('"').split(',')
        if len(bb) < 4:
            # bounding box is empty
            return None
        bounding_box = QRectF(0, 0,
                              float(bb[2]) - float(bb[0]),
                              float(bb[3]) - float(bb[1]))
        if 'lp' in subgraph.attr:
            label_pos = subgraph.attr['lp'].strip('"').split(',')
        else:
            label_pos = (float(bb[0]) + (float(bb[2]) - float(bb[0])) / 2,
                         float(bb[1]) + (float(bb[3]) - float(bb[1])) -
                         LABEL_HEIGHT / 2)
        bounding_box.moveCenter(
            QPointF(
                float(bb[0]) + (float(bb[2]) - float(bb[0])) / 2,
                -float(bb[1]) - (float(bb[3]) - float(bb[1])) / 2))
        name = subgraph.attr.get('label', '')
        color = QColor(
            subgraph.attr['color']) if 'color' in subgraph.attr else None
        subgraph_nodeitem = NodeItem(
            highlight_level,
            bounding_box,
            label=name,
            shape='box',
            color=color,
            parent=scene.activePanel() if scene is not None else None,
            label_pos=QPointF(float(label_pos[0]), -float(label_pos[1])))
        bounding_box = QRectF(bounding_box)
        # With clusters we have the problem that mouse hovers cannot
        # decide whether to be over the cluster or a subnode. Using
        # just the "title area" solves this. TODO: Maybe using a
        # border region would be even better (multiple RectF)
        bounding_box.setHeight(LABEL_HEIGHT)
        subgraph_nodeitem.set_hovershape(bounding_box)

        if scene is not None:
            scene.addItem(subgraph_nodeitem)
        return subgraph_nodeitem
    def create_node(self, bounding_box, shape, label, label_pos=None, url=None, parent=None, cluster=False, **kwargs):
        self._check_constraints(kwargs)
        node_item = HoveredNodeItem(bounding_box, shape, label, label_pos, url, parent, **kwargs)

        if cluster:
            bounding_box = QRectF(bounding_box)
            bounding_box.setHeight(30)
            node_item.set_hover_shape(bounding_box)

        return node_item
Example #3
0
    def getNodeItemForSubgraph(self, subgraph, highlight_level):
        # let pydot imitate pygraphviz api
        attr = {}
        for name in subgraph.get_attributes().iterkeys():
            value = get_unquoted(subgraph, name)
            attr[name] = value
        obj_dic = subgraph.__getattribute__("obj_dict")
        for name in obj_dic:
            if name not in ["nodes", "attributes", "parent_graph"] and obj_dic[name] is not None:
                attr[name] = get_unquoted(obj_dic, name)
            elif name == "nodes":
                for key in obj_dic["nodes"]["graph"][0]["attributes"]:
                    attr[key] = get_unquoted(obj_dic["nodes"]["graph"][0]["attributes"], key)
        subgraph.attr = attr

        bb = subgraph.attr.get("bb", None)
        if bb is None:
            # no bounding box
            return None
        bb = bb.strip('"').split(",")
        if len(bb) < 4:
            # bounding box is empty
            return None
        bounding_box = QRectF(0, 0, float(bb[2]) - float(bb[0]), float(bb[3]) - float(bb[1]))
        if "lp" in subgraph.attr:
            label_pos = subgraph.attr["lp"].strip('"').split(",")
        else:
            label_pos = (
                float(bb[0]) + (float(bb[2]) - float(bb[0])) / 2,
                float(bb[1]) + (float(bb[3]) - float(bb[1])) - LABEL_HEIGHT / 2,
            )
        bounding_box.moveCenter(
            QPointF(float(bb[0]) + (float(bb[2]) - float(bb[0])) / 2, -float(bb[1]) - (float(bb[3]) - float(bb[1])) / 2)
        )
        name = subgraph.attr.get("label", "")
        color = QColor(subgraph.attr["color"]) if "color" in subgraph.attr else None
        subgraph_nodeitem = NodeItem(
            highlight_level,
            bounding_box,
            label=name,
            shape="box",
            color=color,
            label_pos=QPointF(float(label_pos[0]), -float(label_pos[1])),
        )
        bounding_box = QRectF(bounding_box)
        # With clusters we have the problem that mouse hovers cannot
        # decide whether to be over the cluster or a subnode. Using
        # just the "title area" solves this. TODO: Maybe using a
        # border region would be even better (multiple RectF)
        bounding_box.setHeight(LABEL_HEIGHT)
        subgraph_nodeitem.set_hovershape(bounding_box)
        return subgraph_nodeitem
    def create_node(self, bounding_box, shape, label, label_pos=None, url=None, parent=None, cluster=False, **kwargs):
        self._check_constraints(kwargs)

        if label.startswith('<') and label.endswith('>'):
            node_item = DmgHtmlNodeItem(bounding_box, shape, label[1:-1], label_pos, url, parent, **kwargs)
        else:
            node_item = DmgNodeItem(bounding_box, shape, label, label_pos, url, parent, **kwargs)

            if cluster:
                bounding_box = QRectF(bounding_box)
                bounding_box.setHeight(30)
                node_item.set_hover_shape(bounding_box)

        return node_item
Example #5
0
    def create_node(self,
                    bounding_box,
                    shape,
                    label,
                    label_pos=None,
                    url=None,
                    parent=None,
                    cluster=False,
                    **kwargs):
        self._check_constraints(kwargs)
        node_item = HoveredNodeItem(bounding_box, shape, label, label_pos, url,
                                    parent, **kwargs)

        if cluster:
            bounding_box = QRectF(bounding_box)
            bounding_box.setHeight(30)
            node_item.set_hover_shape(bounding_box)

        return node_item
Example #6
0
    def create_node(self,
                    bounding_box,
                    shape,
                    label,
                    label_pos=None,
                    url=None,
                    parent=None,
                    cluster=False,
                    **kwargs):
        self._check_constraints(kwargs)

        if label.startswith('<') and label.endswith('>'):
            node_item = DmgHtmlNodeItem(bounding_box, shape, label[1:-1],
                                        label_pos, url, parent, **kwargs)
        else:
            node_item = DmgNodeItem(bounding_box, shape, label, label_pos, url,
                                    parent, **kwargs)

            if cluster:
                bounding_box = QRectF(bounding_box)
                bounding_box.setHeight(30)
                node_item.set_hover_shape(bounding_box)

        return node_item