Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Padding of custom nodes #410

Open
evanr70 opened this issue Dec 15, 2020 · 2 comments
Open

Padding of custom nodes #410

evanr70 opened this issue Dec 15, 2020 · 2 comments

Comments

@evanr70
Copy link

evanr70 commented Dec 15, 2020

I've created some custom nodes with png icons. When I render the graph with direction="TB" I get a lot of padding above the icons. With direction="LR" it also shows up by giving linking arrows a position which is above the icon. My icons have dimension [208 x 208].

Is there a way of reducing this white-space padding?

Left to right:
image

Top to bottom:

image

@clayms
Copy link

clayms commented Dec 16, 2020

Try using Node directly and then set the width and height attributes.

For example:

from diagrams import Diagram, Edge, Node

common_node_attr = {
    "fixedsize": "true",            # true | false
    "imagescale": "true",           # true | false | width | height | both 
    "labelloc":"b",                 # t | c | b
    "penwidth": "0",
    "width": "2",
    "height": "2",
}

with Diagram("\n\nNode Sizing", direction="TB", show=False) as diag:
    N1 = Node("N2", image="icon1.png",  **common_node_attr)
    N2 = Node("N1", image="icon2.png",  **common_node_attr)

    N1 >> Edge() >> N2

diag

For Node attribute details, see: https://graphviz.gitlab.io/doc/info/attrs.html

@clayms
Copy link

clayms commented Dec 18, 2020

You can also use an HTML Node, then adjust the Nodes width or height attribute parameters to your liking.

For more info on "HTML-Like Labels" see: https://graphviz.gitlab.io/doc/info/shapes.html#html

Example code and output below.

from diagrams import Diagram, Node, Edge

graph_attr = {
    "splines":"spline",
}

html_img_node_base = """<
    <TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0">
    <TR><TD fixedsize="true" width="100" height="100"><IMG SRC="{0}" /></TD></TR>
    <TR><TD>{1}</TD></TR>
    </TABLE>
    >"""

img1 = "etcd.png"
label1 = "etcd"
img2 = "pod_w_docker.png"
label2 = "pod_w_docker"

html_node_1 = html_img_node_base.format(img1, label1)
html_node_2 = html_img_node_base.format(img2, label2)


with Diagram("\n\nHTML Node Option", direction="TB", show=False) as diag:
    etcd = Node(shape="plaintext", label=html_node_1, width="1.0", height="1.5",)
    pod = Node(shape="plaintext", label=html_node_2, width="1.0", height="1.5",)
    
    etcd >> Edge() >> pod

diag

image

Also see these issue comments:
#389 (comment)
#389 (comment)
#389 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants