Add a workaround for node names not being used as labels #219
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a workaround for issue #218.
When rendering from a string, Viz.js reads the string before it creates a Graphviz context. It then creates a context which it uses for layout and rendering.
However, this can sometimes cause labels to not be displayed, but only for the first call to
render()
. Creating a Graphviz context initializes the global default nodelabel
attribute to be\N
, which is replaced with the node's name if no label is set on a node. So if we don't create a context before reading the first graph, we don't set the default label. The result is that for the first graph we render, nodes without labels set explicitly won't have their name used for their label.The usual sequence seems to be: create a context first, then read the graph and do layout and rendering, then free the context.
The workaround in this PR sets the default label for nodes before reading a graph, as would be done when creating a context. It might be preferable to simply create a context before reading the graph and use it for layout and rendering, but that would require a larger change.