Exemplo n.º 1
0
    def _find_or_create_clusters(self, path: ModulePath) -> Cluster:
        assert self.master_graph.has_module(path)

        holder: Union[Graph, Cluster] = self
        cluster = None
        for i in range(1, path.path_level + 1):
            cluster_path = path.path_in_depth(i)
            cluster = next(
                (
                    cluster
                    for cluster in holder.clusters.values()
                    if cluster.module_path == cluster_path
                ),
                None,
            )

            if not cluster:
                cluster = Cluster(module_path=cluster_path)
                holder.add_cluster(cluster)

            holder = cluster

        assert cluster is not None

        return cluster
Exemplo n.º 2
0
    def find_node_style(self, path: ModulePath) -> Optional[ModuleNodeStyle]:
        # 親のパスに対するスタイルも対象としてスタイルを取得する
        styles = [
            style for style in self.node_styles if path.belongs_to(style.module_path)
        ]

        if not styles:
            return None

        # 複数ある場合は詳細度が高い(path_levelが大きい) ものを優先して返す。
        return sorted(styles, reverse=True, key=lambda s: s.module_path.path_level)[0]
Exemplo n.º 3
0
    def find_edge_style(
        self, tail_path: ModulePath, head_path: ModulePath
    ) -> Optional[ModuleEdgeStyle]:
        # 親のパスに対するスタイルも対象としてスタイルを取得する
        styles = [
            style
            for style in self.edge_styles
            if tail_path.belongs_to(style.tail) and head_path.belongs_to(style.head)
        ]

        if not styles:
            return None

        # 複数ある場合は詳細度が高い(path_levelが大きい) ものを優先して返す。
        # 特に理由はないが、tailの詳細度をheadより優先する。
        return sorted(
            styles,
            reverse=True,
            key=lambda s: (
                s.tail.path_level,
                s.head.path_level,
            ),
        )[0]
Exemplo n.º 4
0
def path(path_str: str):
    return ModulePath(path_str)
Exemplo n.º 5
0
def path(name: str) -> ModulePath:
    return ModulePath(name)