Exemple #1
0
    def test_render__with_style(self):
        master_graph = MasterGraph.from_tuple_list([("a", "b"), ("b", "c")])
        graph = Graph(master_graph)

        graph.style(
            node("b"), color=Color.Blue, fontcolor=Color.Red, penwidth=PenWidth.Bold
        )
        renderer = GraphRenderer(graph=graph)

        g = Digraph()
        default_node_style = NodeStyle().to_dict()
        node_style = NodeStyle().to_dict()
        node_style.update(
            {
                "color": "blue",
                "fontcolor": "red",
                "penwidth": PenWidth.to_size(PenWidth.Bold),
            }
        )
        g.node("a", **default_node_style)
        g.node("b", **node_style)
        g.node("c", **default_node_style)

        edge_style = EdgeStyle().to_dict()
        edge_style.update(
            {
                "color": "blue",
                "fontcolor": "red",
                "penwidth": PenWidth.to_size(PenWidth.Bold),
            }
        )
        g.edge("a", "b", **edge_style)
        g.edge("b", "c", **edge_style)

        assert str(renderer.render()) == str(g)
Exemple #2
0
    def test_render__with_hidden_node(self):
        # +---+    +---+    +---+
        # |   |--->| b |--->|   |
        # |   |    +---+    |   |
        # | a |             | d |
        # |   |    +---+    |   |
        # |   |--->| c |--->|   |
        # +---+    +---+    +---+
        master_graph = MasterGraph.from_tuple_list(
            [("a", "b"), ("a", "c"), ("b", "d"), ("c", "d")]
        )
        graph = Graph(master_graph)
        renderer = GraphRenderer(graph=graph)

        graph.hide_node(node("b"))

        g = Digraph()

        default_node_style = NodeStyle().to_dict()
        hidden_node_style = NodeStyle(invisible=True).to_dict()
        g.node("a", **default_node_style)
        g.node("b", **hidden_node_style)
        g.node("c", **default_node_style)
        g.node("d", **default_node_style)

        default_edge_style = EdgeStyle().to_dict()
        hidden_edge_style = EdgeStyle(invisible=True).to_dict()
        g.edge("a", "b", **hidden_edge_style)
        g.edge("a", "c", **default_edge_style)
        g.edge("b", "d", **hidden_edge_style)
        g.edge("c", "d", **default_edge_style)

        assert str(renderer.render()) == str(g)
Exemple #3
0
    def test_filter_node_style(self):
        f = HideFilter()

        f.add_node(node("jig.cli"))

        current_style = NodeStyle(invisible=False)
        hidden_style = NodeStyle(invisible=True)

        assert f.filter_node_style(node("xxx"), current_style) == current_style
        assert f.filter_node_style(node("jig"), current_style) == current_style
        assert f.filter_node_style(node("jig.cli"),
                                   current_style) == hidden_style
        assert f.filter_node_style(node("jig.cli.main"),
                                   current_style) == hidden_style
Exemple #4
0
    def test_find_node_style(self):
        graph_style = GraphStyle()

        style = node_style("jig.collector", NodeStyle(color=Color.Blue))
        graph_style.add_node_style(style)

        assert graph_style.find_node_style(path("jig")) is None
        assert graph_style.find_node_style(path("jig.collector")) == style
        assert graph_style.find_node_style(path("jig.collector.domain")) == style

        # より詳細度の低いスタイルの適用
        jig_style = node_style("jig", NodeStyle(color=Color.Green))
        graph_style.add_node_style(jig_style)
        assert graph_style.find_node_style(path("jig")) == jig_style
        assert graph_style.find_node_style(path("jig.collector")) == style
        assert graph_style.find_node_style(path("jig.collector.domain")) == style
Exemple #5
0
    def test_add_node_style(self):
        graph_style = GraphStyle()

        assert len(graph_style.node_styles) == 0

        jig_style = node_style("jig", NodeStyle(color=Color.Blue))

        graph_style.add_node_style(jig_style)
        assert len(graph_style.node_styles) == 1

        tests_style = node_style("tests")
        graph_style.add_node_style(tests_style)

        assert len(graph_style.node_styles) == 2
        assert graph_style.node_styles == [jig_style, tests_style]

        jig_style2 = node_style("jig", NodeStyle(color=Color.Red))

        graph_style.add_node_style(jig_style2)
        assert len(graph_style.node_styles) == 2
        assert graph_style.node_styles == [tests_style, jig_style2]
Exemple #6
0
    def test_render__with_autohighlight(self):
        # +---+    +---+    +---+    +---+
        # |   |    |   |--->|   |    |   |
        # | a |--->| b |    | c |--->| d |
        # |   |    |   |<---|   |    |   |
        # +---+    +---+    +---+    +---+
        master_graph = MasterGraph.from_tuple_list(
            [("a", "b"), ("b", "c"), ("c", "b"), ("c", "d")]
        )
        graph = Graph(master_graph)
        renderer = GraphRenderer(graph=graph)

        graph.auto_highlight()

        g = Digraph()

        default_node_style = NodeStyle().to_dict()
        entry_point_node_style = NodeStyle(
            color=Color.Teal, fontcolor=Color.White, filled=True
        ).to_dict()
        fundamental_node_style = NodeStyle(
            color=Color.Purple, fontcolor=Color.White, filled=True
        ).to_dict()
        g.node("a", **entry_point_node_style)
        g.node("b", **default_node_style)
        g.node("c", **default_node_style)
        g.node("d", **fundamental_node_style)

        default_edge_style = EdgeStyle().to_dict()
        warning_edge_style = EdgeStyle(
            color=Color.Red, penwidth=PenWidth.Bold
        ).to_dict()
        g.edge("a", "b", **default_edge_style)
        g.edge("b", "c", **warning_edge_style)
        g.edge("c", "b", **warning_edge_style)
        g.edge("c", "d", **default_edge_style)

        assert str(renderer.render()) == str(g)
Exemple #7
0
    def auto_highlight(self):
        source_nodes: Dict[ModuleNode, List[ModuleEdge]] = dict(
            [(node, []) for node in self.nodes]
        )
        dest_nodes: Dict[ModuleNode, List[ModuleEdge]] = dict(
            [(node, []) for node in self.nodes]
        )
        for edge in self.edges:
            dest_nodes[edge.tail].append(edge)
            source_nodes[edge.head].append(edge)

        # entrypoint
        entrypoint_node_style = NodeStyle(
            color=Color.Teal, fontcolor=Color.White, filled=True
        )
        for node, edges in source_nodes.items():
            if len(edges) == 0:
                self.nodes.remove(node)
                self.nodes.add(node.with_style(style=entrypoint_node_style))

        # fundamental
        fundamental_node_style = NodeStyle(
            color=Color.Purple, fontcolor=Color.White, filled=True
        )
        for node, edges in dest_nodes.items():
            if len(edges) == 0:
                self.nodes.remove(node)
                self.nodes.add(node.with_style(style=fundamental_node_style))

        # both reference
        both_reference_edge_style = EdgeStyle(color=Color.Red, penwidth=PenWidth.Bold)
        for edge in self.edges:
            reverse = edge.build_reverse()
            if reverse in self.edges:
                self.edges.remove(edge)
                self.edges.add(edge.with_style(style=both_reference_edge_style))
Exemple #8
0
    def style(
        self, node: ModuleNode, color: Color, fontcolor: Color, penwidth: PenWidth
    ):
        node_style = NodeStyle(color=color, fontcolor=fontcolor, penwidth=penwidth)
        edge_style = EdgeStyle(color=color, fontcolor=fontcolor, penwidth=penwidth)

        if self.master_graph.has_module(node.path):
            self.graph_style.add_node_style(
                ModuleNodeStyle(module_path=node.path, style=node_style)
            )

        edges = list(filter(lambda e: e.has_node(node), self.edges))
        for edge in edges:
            self.graph_style.add_edge_style(
                ModuleEdgeStyle(
                    tail=edge.tail.path, head=edge.head.path, style=edge_style
                )
            )
Exemple #9
0
    def test_render__reset_style(self):
        master_graph = MasterGraph.from_tuple_list([("a", "b"), ("b", "c")])
        graph = Graph(master_graph)

        graph.style(
            node("b"), color=Color.Blue, fontcolor=Color.Red, penwidth=PenWidth.Bold
        )
        graph.reset_style()
        renderer = GraphRenderer(graph=graph)

        g = Digraph()
        default_node_style = NodeStyle().to_dict()
        g.node("a", **default_node_style)
        g.node("b", **default_node_style)
        g.node("c", **default_node_style)

        default_edge_style = EdgeStyle().to_dict()
        g.edge("a", "b", **default_edge_style)
        g.edge("b", "c", **default_edge_style)

        assert str(renderer.render()) == str(g)
Exemple #10
0
    def test_render(self):
        cluster = Cluster(module_path=path("jig"), children={node("jig.analyzer")})
        sub_cluster = Cluster(
            module_path=path("jig.collector"),
            children={node("jig.collector.application"), node("jig.collector.domain")},
        )
        cluster.add_cluster(sub_cluster)

        graph = Graph()
        graph.add_edge(edge("jig.analyzer", "jig.collector"))
        graph.add_cluster(cluster)

        renderer = GraphRenderer(graph=graph)

        g = Digraph()

        node_style = NodeStyle().to_dict()
        g.node("jig.analyzer", **node_style)
        g.node("jig.collector", **node_style)

        edge_style = EdgeStyle().to_dict()
        g.edge("jig.analyzer", "jig.collector", **edge_style)

        child = Digraph(name="cluster_jig")
        child.attr(label="jig")
        child.node("jig.analyzer")

        grandchild = Digraph(name="cluster_jig.collector")
        grandchild.attr(label="jig.collector")
        grandchild.node("jig.collector.application")
        grandchild.node("jig.collector.domain")

        child.subgraph(grandchild)
        g.subgraph(child)

        assert str(renderer.render()) == str(g)
Exemple #11
0
 def to_invisible(self) -> "ModuleNode":
     return self.build(path=self.path, style=NodeStyle(invisible=True))
Exemple #12
0
 def build(cls,
           path: ModulePath,
           style: Optional[NodeStyle] = None) -> "ModuleNode":
     return cls(path=path, style=style or NodeStyle())
Exemple #13
0
    def filter_node_style(self, node: ModuleNode,
                          current_style: NodeStyle) -> NodeStyle:
        if not self.is_hidden_node(node):
            return current_style

        return current_style.with_invisible(True)