图表包中的某些项位于顶部至底部,其他项位于左侧至右侧

2024-04-19 11:28:06 发布

您现在位置:Python中文网/ 问答频道 /正文

编辑:在我即将提交时找到答案。这篇文章讨论了不可见边:Graphviz top to bottom AND left to right

我目前正在使用python包“diagrams”为我的项目构建流程图。不幸的是,由于从左到右或从上到下(据我所知,没有能力将两者混合),它会导致一些丑陋的显示

以下是我的图表的代码片段:

from diagrams import Diagram, Cluster

from diagrams.generic.database import SQL
from diagrams.generic.place import Datacenter
from diagrams.generic.compute import Rack
from diagrams.generic.network import Subnet

from diagrams.aws.general import User


with Diagram('Sample', show=False, outformat='png', direction='LR'):
    database_1 = SQL('Database 1')

    database_2 = SQL('Database 2')

    database_3 = SQL('Database 3')

    server = Datacenter('Datacenter')

    human = User('Human Reviewer')

    with Cluster('Additional items to group separately', direction='TB'):
        process = Subnet('Connection')
        compute = Rack('Compute')
        compute_other = Rack('Compute Other')

    with Cluster('Files to group together'):
        database_4 = SQL('Database 4')
        database_5 = SQL('Database 5')
        database_6 = SQL('Database 6')
    [database_4, database_5, database_6] >> compute

    database_1 >> server
    database_2 >> server
    database_3 >> server

    server >> process >> compute >> compute_other >> human

它回来了 image_current

但是所需的图像将是其中集群'Files to group together'将水平分布以使图更加紧凑的图像。有关所需的输出,请参见此图。 enter image description here

有没有一种方法可以使集群'Files to group together'水平对齐,同时图的其余部分仍然从左向右流动?我在想,我只需要在集群中的项目之间创建不可见的边,但我似乎在graphviz中找不到将边设置为不可见的选项(而且似乎没有graphviz中没有的图表的唯一选项)

注意:我尝试了Edge(color=None),但您仍然可以看到一个箭头,并且没有从db4到db5到db6的流,因此该边只是试图强制对齐

是否有更好的包用于构建这些图

谢谢


Tags: tofromimportsqlserverwithgroupdatabase
1条回答
网友
1楼 · 发布于 2024-04-19 11:28:06

搜索时找不到类似的帖子,但AI神读了我的帖子,并指出这篇帖子是最重要的建议: Graphviz top to bottom AND left to right

在那篇文章中,用户提到了Edge(style='invi')的graphviz选项。我实现了这一点,而不是尝试使用Edge(color=None),并且按照预期效果工作

相关问题 更多 >