Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Exposes passing kwargs to graphviz object #125

Merged
merged 1 commit into from
May 2, 2022
Merged

Conversation

skrawcz
Copy link
Collaborator

@skrawcz skrawcz commented May 1, 2022

This should be a backwards compatible API change for everything.

To be able to control, for instance the ratio, of the produced image,
it's not a render time argument. Instead, it's a property of the graph.
To be able to manipulate it, we need to wire through passing in attributes.
e.g. https://graphviz.org/doc/info/attrs.html shows what could be set.

These attributes are either graph, node, or edge attributes.
The kwargs I'm specifically trying to expose are:

graph_attr – Mapping of (attribute, value) pairs for the graph.
node_attr – Mapping of (attribute, value) pairs set for all nodes.
edge_attr – Mapping of (attribute, value) pairs set for all edges.

The above was taken from https://graphviz.readthedocs.io/en/stable/api.html?highlight=ratio#digraph.

Note, this will enable anything else to be also passed to the graph, which I
think is a useful thing too. Since that will allow someone who knows graphviz
to really customize it I think.

Changes

  • Adds a graphviz_kwargs parameter and wires it through to all the displays.

Testing

  1. Ran local hello world script passing in graphviz_kwargs.

Notes

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist

Python - local testing

  • python 3.6
  • python 3.7

Copy link
Collaborator

@elijahbenizzy elijahbenizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just make sure to clarify when one might use this as opposed to render_kwargs

except ImportError as e:
logger.warning(f'Unable to import {e}', exc_info=True)

def visualize_execution(self,
final_vars: List[str],
output_file_path: str,
render_kwargs: dict,
inputs: Dict[str, Any] = None):
inputs: Dict[str, Any] = None,
graphviz_kwargs: dict = None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the difference between this and **render_kwargs? I think it makes sense but its not obvious.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Render is called after you construct the graph and want to create an image from it.

https://graphviz.readthedocs.io/en/stable/api.html#graphviz.Graph.render

This should be a backwards compatible API change for everything.

To be able to control, for instance the ratio, of the produced image,
it's not a render time argument. Instead, it's a property of the graph.
To be able to manipulate it, we need to wire through passing in attributes.
e.g. https://graphviz.org/doc/info/attrs.html shows what could be set.

These attributes are either graph, node, or edge attributes.
The kwargs I'm specifically trying to expose are:
```
graph_attr – Mapping of (attribute, value) pairs for the graph.
node_attr – Mapping of (attribute, value) pairs set for all nodes.
edge_attr – Mapping of (attribute, value) pairs set for all edges.
```
The above was taken from https://graphviz.readthedocs.io/en/stable/api.html?highlight=ratio#digraph.

Note, this will  enable anything else to be also passed to the graph, which I
think is a useful thing too. Since that will allow someone who knows graphviz
to really customize it I think.
@skrawcz skrawcz merged commit 8e7c4e0 into main May 2, 2022
@skrawcz skrawcz deleted the expose_graphviz_kwargs branch May 2, 2022 04:28
@jameslamb jameslamb mentioned this pull request May 4, 2022
12 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants