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

Added Cluster icon and iconsize #853

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

tanure
Copy link

@tanure tanure commented Feb 13, 2023

I added an implementation to be able to add icon for a Cluster

@AutomationD
Copy link

AutomationD commented Jul 31, 2023

FYI, seems like it won't be merged as probably doesn't conform with standards.

Thanks to @tanure I was able to create an external option which works just fine:

def icon(node: object, label: str, size=30):
    """
    Function adds a Diagrams-compatible icon

    :param node: Diagrams object, like VPC or Docker
    :param label: Label text, like "subnet-a"
    :param size: Icon size in px.
    :returns: "Label prefixed with a specified icon"
    """
    # o = node.__new__(cls=None, label=label, size=size)

    class Node(node):
        def __init__(self):
            pass

    icon_path = Node()._load_icon()
    return '<<table border="0" width="100%"><tr><td fixedsize="true" width="' + str(size) + '" height="' + str(
        size) + '"><img src="' + icon_path + '" /></td><td>' + label + '</td></tr></table>>'

To be used like this:

    with Cluster(icon(VPC, "prod-vpc")):
        ...

@tanure
Copy link
Author

tanure commented Jul 31, 2023

I missed the conflict. I didn't see the notification about it. However, I'm really happy because @AutomationD created an alternative and improved code. Thanks a lot and it's good to learn with you!

@AutomationD
Copy link

I missed the conflict. I didn't see the notification about it. However, I'm really happy because @AutomationD created an alternative and improved code. Thanks a lot and it's good to learn with you!

You're too kind!

I don't think I've improved anything, it would be still great to do it without external functions. Maybe @mingrammer can give a hint what can be improved on the PR?

@AutomationD
Copy link

Also, seems like there is an issue with my code. I'm getting an actual node on the diagram in addition to the icon. I'll see if I can fix it.

@tanure
Copy link
Author

tanure commented Jul 31, 2023

This is really community! Let's contribute and learn. I'm going to test it as well!

Thanks a lot @AutomationD

@AutomationD
Copy link

AutomationD commented Jul 31, 2023

@tanure OK, seems like overriding __init__ was good enough.
I've updated the original snippet.

Anddd7 added a commit to Anddd7/diagrams-ext that referenced this pull request Dec 13, 2023
Anddd7 added a commit to Anddd7/diagrams-ext that referenced this pull request Dec 13, 2023
@Anddd7
Copy link

Anddd7 commented Dec 14, 2023

Thanks for @tanure, I made some adjustment based on your changes. Use the type of Node instead of the Node instance, so no node generated actually. Overwrite the color of the clusters, it looks better now.

image

Anddd7#1
Anddd7#2

@JobaDiniz
Copy link

why isn't this merged yet?

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

Successfully merging this pull request may close these issues.

None yet

4 participants