mingrammer / diagrams

:art: Diagram as Code for prototyping cloud system architectures
https://diagrams.mingrammer.com
MIT License
35.41k stars 2.29k forks source link

How to draw 1..N ? #677

Open alexInhert opened 2 years ago

alexInhert commented 2 years ago

Using your example diagram: https://github.com/mingrammer/diagrams#examples

https://camo.githubusercontent.com/7915bf96167b4d99d977ba7143e609335635a8b154abd71c9528acbd28d651a6/68747470733a2f2f6469616772616d732e6d696e6772616d6d65722e636f6d2f696d672f6576656e745f70726f63657373696e675f6469616772616d2e706e67

you have 3 workers listed as worker1, worker2, worker3 Say I have 50 workers.. I don't want the diagram to actually show 50 instances. How can I make it show worker1, worker3, ..., worker50 ?

clayms commented 2 years ago

Try a list comprehension.

alexInhert commented 2 years ago

@clayms can you please clarify? I'm not sure what you mean My goal is to see in the diagram 1 2 ... 50 e.g only 3 icons

clayms commented 2 years ago

@alexInhert

A Node with the shape="plaintext" and the label="..." might be what your after.

Pasting your existing code and some sketch of what you are after would help.

alexInhert commented 2 years ago

Thanks @clayms Is there a way to control if the label will appear in the top/center/bottom?

clayms commented 2 years ago

https://graphviz.org/docs/attrs/labelloc/

govindsinghrawat commented 2 years ago

@alexInhert - FWIW building on similar use case as suggested by @clayms I did some thing like below.

from diagrams import Diagram
from diagrams.aws.compute import EC2
from diagrams.aws.database import RDS
from diagrams.aws.network import ELB

with Diagram("Grouped Workers", show=True, direction="TB"):
    ELB("lb") >> [EC2("worker1"),
                  EC2("......"),
                  EC2("worker10")] >> RDS("events")
AWS_Diag
alexInhert commented 1 year ago

This is a nice workaround I'll use that. I think that this scenario is better to be solved as a feature rather than as a workaround so I keep the issue open The reason I think it's better to be a feature is because the workaround adds another image/icon with just title of ... it can easily be misdeed with high complex diagrams... I think when acting as item1, item2, ..., itemn the behavior should be as group rather than as each item individually. The ... should be in the center between the items.

if you feel otherwise then you can close it