Closed 2bndy5 closed 1 year ago
As a workaround, I think I can restructure the graph with clusters, but I wanted to document the experience here.
The easiest course of actions, although disappointing, would be to explicitly not support record-based graphs with this theme's modified graphviz extension. I'm not sure how to robustly support the xref feature when the label uses HTML special characters. There are similar instances in dot syntax that allow for HTML-like labels to be used as a node's content (which is great for making graph legends).
It does not appear that it is possible to make just an individual field of a record node a hyperlink, but we should be able to make the entire thing a hyperlink.
The theme currently generates a label
attribute using the graphviz "HTML" syntax label=<...>
simply because then I could use html.escape
to ensure any special characters were properly escaped. I wasn't sure if escaping is possible in the regular label="..."
syntax. If so, we could just use the regular double-quoted syntax, which I think would basically make record nodes work, as long as the xref doesn't expand to something with angle brackets that would interfere with the record syntax. Even if escaping is not possible with the plain label = "..."
syntax, we could still use that syntax in cases where the text does not contain any embedded double quotes.
I wasn't sure if escaping is possible in the regular label="..." syntax.
As far as I know you can escape special chars in quoted labels with \
label = "<f0> \<device\> | <f1> attributes | <f2> nodes"
results in
as long as the xref doesn't expand to something with angle brackets that would interfere with the record syntax
This would be harder to avoid. Its not something we can tell users to avoid since its more of an under-the-hood implementation detail.
cases where the text does not contain any embedded double quotes
When I experimented with HTML-like labels to make a graph legend, I found that quotes are very important for label values that span multiple lines (in the dot src).
I find the docs about graphviz xref attribute a little confusing because it uses the word "node" (as in docutils node) when talking about a graph node's attributes.
If there is at least one
reference
node, only the last such node is considered
I wasn't sure if escaping is possible in the regular label="..." syntax.
As far as I know you can escape special chars in quoted labels with
\
label = "<f0> \<device\> | <f1> attributes | <f2> nodes"
results in
I think this quoting is being handled by the graphviz parser of the record node syntax. What if you want the label to include a literal double quote "
character?
as long as the xref doesn't expand to something with angle brackets that would interfere with the record syntax
This would be harder to avoid. Its not something we can tell users to avoid since its more of an under-the-hood implementation detail.
I guess as you noted it is possible to escape the angle brackets. However, to do that we would need to know that it is a record node, and to figure that out automatically would, I think, require a real DOT parser.
Another option is that users could specify xref
to get a cross reference and then manually specify the label as well, to override the label generated for the xref. That might make more sense than trying to handle rST syntax inside of the record node syntax.
cases where the text does not contain any embedded double quotes
When I experimented with HTML-like labels to make a graph legend, I found that quotes are very important for label values that span multiple lines (in the dot src).
I find the docs about graphviz xref attribute a little confusing because it uses the word "node" (as in docutils node) when talking about a graph node's attributes.
If there is at least one
reference
node, only the last such node is considered
Agreed that this could be made clearer.
What if you want the label to include a literal double quote " character?
You can use \"
, but you can't use ' " '
as it complains about the string format (at least in a record label).
Another option is that users could specify xref to get a cross reference and then manually specify the label as well, to override the label generated for the xref
I especially like this idea. 💯 TBH, this is kinda what I was expecting when I first tried it on this graph.
It does not appear that it is possible to make just an individual field of a record node a hyperlink, but we should be able to make the entire thing a hyperlink.
Yeah, this is my first attempt at using record-based labels. I'm totally fine with making the whole node a hyperlink. I can override the CSS for all but the first field so the font color only changes for the first field.
Another option is that users could specify xref to get a cross reference and then manually specify the label as well, to override the label generated for the xref
I took a swing at doing this and it works, but my approach is to assume that label
attr immediately follows the xref
attr in the dot syntax. I'm not sure if there's a better way to parse the dot syntax since the code style is rather flexible.
I'm writing a graph that shows data structures using record-based nodes.
Here's a sample without any xrefs:
<symbol>
syntax to identify the cell within the node when drawing connecting edges.What I'd like to do is have a the top cell in the record link to a python class, but the replacements from this theme's graphviz ext crash the dot executable.
The warning emitted in the build log includes all my env vars (which I have removed), but doesn't show any of the dot code that was passed.
This code causes the following warning
```rst .. graphviz:: digraph g { graph [rankdir = "LR"] "device" [ xref = "By adjusting the warning prompt in the theme's source, I was able to see the resulting altered dot syntax:
So, it looks like the line that escapes HTML syntax in the replaced label is causing dot to misinterpret the record-based node.
https://github.com/jbms/sphinx-immaterial/blob/21f2aeeb7fd182955a78893c30aaa6b84d6d5e8e/sphinx_immaterial/graphviz.py#L44