From 323913a0c85342ecf2e7170e5fd01bf24ae3ceba Mon Sep 17 00:00:00 2001 From: Cory ODaniel Date: Fri, 17 Apr 2020 09:39:19 -0700 Subject: [PATCH] URL, edgeURL, and labelURL support `edgeURL` and `labelURL` are technically already supported via the `**attrs` Dict in `Edge`'s initializer. I added a named parameter to `Node` to accept [`URL`](https://www.graphviz.org/doc/info/attrs.html#a:URL). SVG output natively supports links in the diagram. Links can also be added to jpg and png using `cmapx` which I added to the output types. To use cmapx you will need to run the diagram generation twice. Once for the png and once for the cmapx file. I had originally detected if a url was added to a node, edge, or label and autogenerated the cmapx file. I can add that back in if interested, but it seemed to break the paradigm of generating _one file_ from a diagram. --- diagrams/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/diagrams/__init__.py b/diagrams/__init__.py index e119a60a..f3d3b589 100644 --- a/diagrams/__init__.py +++ b/diagrams/__init__.py @@ -40,7 +40,7 @@ def setcluster(cluster): class Diagram: __directions = ("TB", "BT", "LR", "RL") - __outformats = ("png", "jpg", "svg", "pdf") + __outformats = ("png", "jpg", "svg", "pdf", "cmapx") # fmt: off _default_graph_attrs = { @@ -262,10 +262,11 @@ class Node: _height = 1.9 - def __init__(self, label: str = ""): + def __init__(self, label: str = "", URL: str = ""): """Node represents a system component. :param label: Node label. + :param URL: Node URL link. (svg, cmapx only) """ # Generates a hash for identifying a node. self._hash = self._rand_hash() @@ -283,6 +284,9 @@ class Node: } if self._icon else {} # fmt: on + if URL: + self.attrs.update({"URL": URL}) + # Node must be belong to a diagrams. self._diagram = getdiagram() if self._diagram is None: