Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a workaround for node names not being used as labels #219

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

mdaines
Copy link
Owner

@mdaines mdaines commented Oct 23, 2023

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 node label 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.

@mdaines mdaines force-pushed the viz-label-issue-218 branch 2 times, most recently from a4697fc to 89bbb47 Compare October 25, 2023 13:52
@mdaines mdaines changed the title Address node labels not appearing in some cases (WIP) Address node labels not appearing in some cases Oct 25, 2023
@mdaines mdaines changed the title Address node labels not appearing in some cases Add a workaround for node names not being used as labels Oct 25, 2023
@mdaines mdaines merged commit cd2d233 into v3 Oct 25, 2023
4 checks passed
@mdaines mdaines deleted the viz-label-issue-218 branch October 25, 2023 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant