自定义图标未在图中显示为代码

发布于 2025-02-07 01:52:53 字数 1381 浏览 3 评论 0原文

我正在尝试在此Python图中使用自定义节点类型作为代码库(网站/文档]&以下是我的代码(一个最小的可重现示例段)):

from diagrams import Diagram
from diagrams import Edge
from diagrams.custom import Custom
from diagrams.gcp.devtools import ContainerRegistry
from diagrams.gcp.ml import AIPlatform

with Diagram(name="my_diagram",
    filename="diagrams/my_diagram_rec",
    show=True,
):

    # nodes
    vertexai = AIPlatform("Vertex AI")
    gcr = ContainerRegistry("Container Registry")
    gitlab_repo = Custom("Git Repo", "./diagrams/resources/gitlablogo.png")

    # diagram structure includind Edge attributes
    gitlab_repo >> Edge(label="Code \nConfig.yml \nEnvironment.yml") >> gcr
    gcr >> Edge(label="Docker Image") >> vertexai
    vertexai >> Edge(label="launches \nspecified \nmachine-size")

并确认gitlablogo.png在位置上存在文件,我将其引用:

 ~/my-repo  issue49-diagrams $  ls diagrams/resources                ok py  17:24:23
gitlablogo.png

但是当我运行python图表/so_q_diagram.py.py.py.py时,弹出的图像不会显示我的自定义图标(gitlab徽标):

I'm trying to use a Custom Node Type in this python diagrams as code library (website/docs] & pypi link). Below is (a minimal reproduceable example snippet of) my code:

from diagrams import Diagram
from diagrams import Edge
from diagrams.custom import Custom
from diagrams.gcp.devtools import ContainerRegistry
from diagrams.gcp.ml import AIPlatform

with Diagram(name="my_diagram",
    filename="diagrams/my_diagram_rec",
    show=True,
):

    # nodes
    vertexai = AIPlatform("Vertex AI")
    gcr = ContainerRegistry("Container Registry")
    gitlab_repo = Custom("Git Repo", "./diagrams/resources/gitlablogo.png")

    # diagram structure includind Edge attributes
    gitlab_repo >> Edge(label="Code \nConfig.yml \nEnvironment.yml") >> gcr
    gcr >> Edge(label="Docker Image") >> vertexai
    vertexai >> Edge(label="launches \nspecified \nmachine-size")

And confirmation that the gitlablogo.png file exists at the location I reference it at:

 ~/my-repo  issue49-diagrams $  ls diagrams/resources                ok py  17:24:23
gitlablogo.png

But when I run python diagrams/so_q_diagram.py, the image that pops up doesn't show my custom icon (the gitlab logo):
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情丝乱 2025-02-14 01:52:54

好的,这很烦人,感觉就像一个错误,但显然包括fileName 带有图(... 语句导致自定义图标消失。 gitlablogo.png的位置,在上面运行一个单个更改的确切代码 - 征服fileName =“ difagrams/my_diagram_rec_rec”, - 现在使图映像渲染图像正如预期的:

ok this was annoying and feels like a bug but apparently including a filename param in the with Diagram(... statement causes the custom icon to disappear. Because, without changing the location of gitlablogo.png, running the exact code above with one single change --commenting out filename="diagrams/my_diagram_rec",-- now causes the diagram image to render as expected:
enter image description here

独自唱情﹋歌 2025-02-14 01:52:54

以前的答案对我不起作用。我发现您必须下载图标PNG,而不仅仅是图片以使自定义功能起作用。您可以在您的情况下使用诸如“ gitlab徽标图标”之类的内容,并且您应该能够找到没有任何背景的徽标图标(看起来像网格或马赛克)。然后使用您现在拥有的相同代码,并且应该使用。希望这有帮助。

PS:Raspberry Pi徽标图标的示例链接 - https://icons8.com/icons/icons/icons/set/set/ Raspberry-pi

我的结果也附有:
带有rasp_pi图标的流程图

The previous answer doesn't work for me. I found that you have to download the icon png instead of just a picture to make the Custom function work. You can google something like "GitLab logo icon" for your situation, and you should be able to find a logo icon without any background (look like grids or mosaic). Then use the same codes you have now and it should work. Hopefully, this is helpful.

PS: example link of raspberry pi logo icon - https://icons8.com/icons/set/raspberry-pi

My result is also attached:
flow chart with rasp_pi icon

尽揽少女心 2025-02-14 01:52:54

如果有人仍在挣扎,我建议您提及您图标资源的完整途径。 我


  • 放置:project/resources/icon.png

经过大量探索,我最终在文件系统中提供了Icon.png文件的完整路径:/home/< sub-directories>/project/resources/resources/icon。 PNG

对我有用,这应该在文档中存在!

If anyone is still struggling, I would suggest to mention the full path to your icon resource. In my case I had a nested folder structure something like:

  • Where icon was used: project/app/diagram_generator.py
  • where icon was
    placed: project/resources/icon.png

After much exploration, I ended up providing the full path of the icon.png file in my file system: /home/<sub-directories>/project/resources/icon.png

And it worked for me,this should have been there in the documentation!

情话墙 2025-02-14 01:52:54

我也遇到了同样的问题,从我得到的问题中,这来自我正在使用的fileName参数()。

就我而言,要解决问题并使图标PNG正确渲染,我使用了从** fileName = **的相对路径,位置并指向图标png存储的位置。

I had the same issue and, from what I get, this is coming from the use of the filename parameter in the Diagram() that I was using.

In my case, to solve the issue and get the icon PNG to render properly, I used a relative path starting from the** filename= **location and pointing to where the icon PNG is stored.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文