Skip to content

Commit

Permalink
small update to test graph and word fix when pydot is not present
Browse files Browse the repository at this point in the history
Signed-off-by: Christian López Barrón <[email protected]>
  • Loading branch information
chrizzFTD committed Dec 8, 2024
1 parent 2c09055 commit 66f1176
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 105 deletions.
14 changes: 10 additions & 4 deletions grill/views/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@

_NO_PEN = QtGui.QPen(QtCore.Qt.NoPen)

_DOT_ENVIRONMENT_ERROR = """In order to display composition arcs in a graph,
_DOT_ENVIRONMENT_ERROR = """In order to display content in this graph view,
the 'dot' command must be available on the current environment.
Please make sure graphviz is installed and 'dot' available on the system's PATH environment variable.
For more details on installing graphviz, visit https://graphviz.org/download/ or https://grill.readthedocs.io/en/latest/install.html#conda-environment-example
For more details on installing graphviz, visit:
- https://graphviz.org/download/ or
- https://grill.readthedocs.io/en/latest/install.html#conda-environment-example
"""


Expand Down Expand Up @@ -591,21 +593,24 @@ def _load_graph(self, graph):
self.scene().clear()
self.viewport().update()

_default_text_interaction = QtCore.Qt.LinksAccessibleByMouse if _IS_QT5 else QtCore.Qt.TextBrowserInteraction

if not _core._which("dot"): # dot has not been installed
print(_DOT_ENVIRONMENT_ERROR)
text_item = QtWidgets.QGraphicsTextItem()
text_item.setPlainText(_DOT_ENVIRONMENT_ERROR)
text_item.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse if _IS_QT5 else QtCore.Qt.TextBrowserInteraction)
text_item.setTextInteractionFlags(_default_text_interaction)

Check warning on line 602 in grill/views/_graph.py

View check run for this annotation

Codecov / codecov/patch

grill/views/_graph.py#L602

Added line #L602 was not covered by tests
self.scene().addItem(text_item)
return

try: # exit early if pydot is not installed, needed for positions
positions = drawing.nx_pydot.graphviz_layout(graph, prog='dot')
except ImportError as exc:
message = str(exc)
message = f"{exc}\n\n{_DOT_ENVIRONMENT_ERROR}"

Check warning on line 609 in grill/views/_graph.py

View check run for this annotation

Codecov / codecov/patch

grill/views/_graph.py#L609

Added line #L609 was not covered by tests
print(message)
text_item = QtWidgets.QGraphicsTextItem()
text_item.setPlainText(message)
text_item.setTextInteractionFlags(_default_text_interaction)

Check warning on line 613 in grill/views/_graph.py

View check run for this annotation

Codecov / codecov/patch

grill/views/_graph.py#L613

Added line #L613 was not covered by tests
self.scene().addItem(text_item)
return

Expand Down Expand Up @@ -752,6 +757,7 @@ def __init__(self, *args, **kwargs):
layout.addWidget(self._error_view)
layout.setContentsMargins(0, 0, 0, 0)
self._error_view.setVisible(False)
self._error_view.setLineWrapMode(QtWidgets.QTextBrowser.NoWrap)
self.setLayout(layout)
self._dot2svg = None
self._threadpool = QtCore.QThreadPool()
Expand Down
26 changes: 15 additions & 11 deletions tests/test_data/_mini_graph.dot
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
digraph {
rankdir=LR;
edge [color=crimson];
1 [label="{<0>x:y:z|<1>z}", style="rounded,filled", shape=record];
2 [label="{<0>a|<1>b}", style="rounded,filled", shape=record];
3 [label="{<0>c|<1>d}", style="rounded,filled", shape=record];
4 [label="{<0>k}", style=invis];
ancestor [active_plugs="{'surface', 'cycle_out', 'cycle_in', 'roughness'}", shape=none, connections="{'surface': [('successor', 'surface')], 'cycle_out': [('ancestor', 'cycle_in')]}", label=<<table border="1" cellspacing="2" style="ROUNDED" bgcolor="#F0FFFF" color="#4682B4"><tr><td port="" border="0" bgcolor="white" style="ROUNDED"><font color="#4682B4"><b>ancestor</b></font></td></tr><tr><td port="cycle_in" border="0" bgcolor="#F0FFFF" style="ROUNDED"><font color="#242828">cycle_in</font></td></tr><tr><td port="roughness" border="0" bgcolor="#F0FFFF" style="ROUNDED"><font color="#242828">roughness</font></td></tr><tr><td port="cycle_out" border="0" bgcolor="#F08080" style="ROUNDED"><font color="#242828">cycle_out</font></td></tr><tr><td port="surface" border="0" bgcolor="#F08080" style="ROUNDED"><font color="#242828">surface</font></td></tr></table>>];
successor [active_plugs="{'surface'}", shape=none, connections="{}", label=<<table border="1" cellspacing="2" style="ROUNDED" bgcolor="#F0FFFF" color="#4682B4"><tr><td port="" border="0" bgcolor="white" style="ROUNDED"><font color="#4682B4"><b>successor</b></font></td></tr><tr><td port="surface" border="0" bgcolor="#F0FFFF" style="ROUNDED"><font color="#242828">surface</font></td></tr></table>>];
1 [label="{<one>x:y:z|<two>z}", style=rounded, shape=record];
2 [label="{<three>a|<four>b}", style=rounded, shape=record];
3 [label="{<five>c|<six>d}", style=rounded, shape=record];
parent [shape=box, fillcolor="#afd7ff", color="#1E90FF", style="filled,rounded"];
child1 [shape=box, fillcolor="#afd7ff", color="#1E90FF", style="filled,rounded"];
child2 [shape=box, fillcolor="#afd7ff", color="#1E90FF", style=invis];
ancestor [shape=none, label=<<table border="1" cellspacing="2" style="ROUNDED" bgcolor="#F0FFFF" color="#4682B4"><tr><td port="" border="0" bgcolor="white" style="ROUNDED"><font color="#4682B4"><b>ancestor</b></font></td></tr><tr><td port="cycle_in" border="0" bgcolor="#F0FFFF" style="ROUNDED"><font color="#242828">cycle_in</font></td></tr><tr><td port="roughness" border="0" bgcolor="#F0FFFF" style="ROUNDED"><font color="#242828">roughness</font></td></tr><tr><td port="cycle_out" border="0" bgcolor="#F08080" style="ROUNDED"><font color="#242828">cycle_out</font></td></tr><tr><td port="surface" border="0" bgcolor="#F08080" style="ROUNDED"><font color="#242828">surface</font></td></tr></table>>];
successor [shape=none, label=<<table border="1" cellspacing="2" style="ROUNDED" bgcolor="#F0FFFF" color="#4682B4"><tr><td port="" border="0" bgcolor="white" style="ROUNDED"><font color="#4682B4"><b>successor</b></font></td></tr><tr><td port="surface" border="0" bgcolor="#F0FFFF" style="ROUNDED"><font color="#242828">surface</font></td></tr></table>>];
1 -> 1 [key=0, color="sienna:crimson:orange"];
1 -> 2 [key=0, color=crimson];
2 -> 1 [key=0, color=green];
2 -> 4 [key=0, color=yellow, label="edge_label"];
3 -> 2 [key=0, color=blue, tailport=0];
ancestor -> ancestor [key=0, tailport="cycle_in", headport="cycle_out", tooltip="ancestor.cycle_in -> ancestor.cycle_out"];
successor -> ancestor [key=0, tailport=surface, headport=surface, tooltip="successor.surface -> ancestor.surface"];
2 -> 1 [key=0, color=seagreen];
3 -> 2 [key=0, color=steelblue, tailport=five];
3 -> 1 [key=0, color=hotpink, tailport=five];
parent -> child1 [key=0];
parent -> child2 [key=0, label=invis];
ancestor -> ancestor [key=0, tailport="cycle_out", headport="cycle_in", tooltip="ancestor.cycle_out -> ancestor.cycle_in"];
ancestor -> successor [key=0, tailport=surface, headport=surface, tooltip="ancestor.surface -> successor.surface"];
}
Loading

0 comments on commit 66f1176

Please sign in to comment.