mingrammer / diagrams

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

C4 Nodes fontsize do not respect node_attr settings #830

Open markgreen-deloitte opened 1 year ago

markgreen-deloitte commented 1 year ago

from diagrams.c4 import Person, Container, Database, System, SystemBoundary, Relationship from diagrams.onprem.client import User node_attr = { "fontsize": "4", } with Diagram("test", show=True, direction="LR", outformat="svg", node_attr=node_attr): testservice = System( name="test service name", description="test description", external=False, ) testuser = User("test this node text")

The testservice text is not adjusted but the testuser text is.

JJRodg commented 1 year ago

Best I can tell, the current C4 node has its own node attributes that can be updated based on key word arguments rather than node_attr dictionary patterns. For example if you want to change the shape of a container to a circle, you need to pass shape: "circle" as an argument to the Container class, rather than relying on Diagram's node_attrs. For example:

spa = Container(
    name="Single-Page Application",
    technology="Javascript and Angular",
    description="Provides all of the Internet banking functionality to customers via their web browser.",
    shape="circle"
)

If there is no existing key then it should correctly use Diagram's node_attrs. The documentation could perhaps be a little clearer about this.

Fontsize is further complicated by the C4Node formatting its own graphviz label, which uses its own font point-sizing:

def _format_node_label(name, key, description):
    """Create a graphviz label string for a C4 node"""
    title = f'<font point-size="12"><b>{html.escape(name)}</b></font><br/>'
    subtitle = f'<font point-size="9">[{html.escape(key)}]<br/></font>' if key else ""
    text = f'<br/><font point-size="10">{_format_description(description)}</font>' if description else ""
    return f"<{title}{subtitle}{text}>"