From 323913a0c85342ecf2e7170e5fd01bf24ae3ceba Mon Sep 17 00:00:00 2001 From: Cory ODaniel Date: Fri, 17 Apr 2020 09:39:19 -0700 Subject: [PATCH 1/3] 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: From 1d04713e1ccdc852dff7ef554528003703e6c6e5 Mon Sep 17 00:00:00 2001 From: Cory ODaniel Date: Tue, 21 Apr 2020 13:38:26 -0700 Subject: [PATCH 2/3] tooltips --- diagrams/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/diagrams/__init__.py b/diagrams/__init__.py index f3d3b589..3b180a9b 100644 --- a/diagrams/__init__.py +++ b/diagrams/__init__.py @@ -262,7 +262,7 @@ class Node: _height = 1.9 - def __init__(self, label: str = "", URL: str = ""): + def __init__(self, label: str = "", URL: str = "", tooltip: str = ""): """Node represents a system component. :param label: Node label. @@ -271,6 +271,7 @@ class Node: # Generates a hash for identifying a node. self._hash = self._rand_hash() self.label = label + self.attrs.update({"URL": URL, "tooltip": tooltip}) # fmt: off # If a node has an icon, increase the height slightly to avoid @@ -284,9 +285,6 @@ 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: From 7ecb31993333838da0acfd288083b43e68bde116 Mon Sep 17 00:00:00 2001 From: Cory ODaniel Date: Tue, 21 Apr 2020 13:41:03 -0700 Subject: [PATCH 3/3] tooltips --- diagrams/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diagrams/__init__.py b/diagrams/__init__.py index 3b180a9b..ce272363 100644 --- a/diagrams/__init__.py +++ b/diagrams/__init__.py @@ -271,7 +271,6 @@ class Node: # Generates a hash for identifying a node. self._hash = self._rand_hash() self.label = label - self.attrs.update({"URL": URL, "tooltip": tooltip}) # fmt: off # If a node has an icon, increase the height slightly to avoid @@ -285,6 +284,8 @@ class Node: } if self._icon else {} # fmt: on + self.attrs.update({"URL": URL, "tooltip": tooltip}) + # Node must be belong to a diagrams. self._diagram = getdiagram() if self._diagram is None: