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

Don't force graphviz diagrams to render in Courier #76776

Closed

Conversation

ecstatic-morse
Copy link
Contributor

@ecstatic-morse ecstatic-morse commented Sep 16, 2020

I went to render a graphviz diagram for rust-lang/rustc-dev-guide#882, and found that they are now much harder to read on my 13 inch laptop monitor. Courier is very thin (for interesting historical reasons), so I'm not happy that we are overriding the system monospace font with it.

@richkadel Could you just use a VSCode extension that handles monospace correctly? This one works just fine. I'm surprised such a simple feature is broken, and I'd prefer not to bend over backwards to support its absence.

r? @richkadel (We're probably the only two people who care ATM)

@richkadel
Copy link
Contributor

richkadel commented Sep 16, 2020

Sorry for the problems this seems to be causing, but reverting the change isn't a perfect solution either, I'm afraid.

I tried the extension you suggested, from EFanZh, and I think it has several deficiencies compared to the one I finally picked. (I think I've tried all of them?)

This is the one I use (by João Pinto): https://marketplace.visualstudio.com/items?itemName=joaompinto.vscode-graphviz

I see EFanZh's previewer doesn't handle the Courier font well. I agree with you there, but it seems like that may be a bug in the EFanZh extension.

The EFanZh extension has only 13k users, whereas Pinto's extension has 47K. Those aren't huge numbers, but Pinto does have over 3-times the number of users.

Pinto's extension lays out the Courier font graph perfectly, with the exact required sizes.

When I try EFanZh's extension and just use "monospace", the layout is close but it is still miscalculating the sizes, especially for longer labels, which extend beyond the borders of the nodes.

Plus, Pinto's extension includes dot-file syntax highlighting, and a convenient context menu to open the graph to the side.

The EFanZh extension has neither of these.

Would you be willing to try the Pinto extension? Would that work for you?

Or if not, we could add another option to allow the user to select an alternative font.

Regarding the choice of Courier, I only get Courier when the font is "monospace". The d3-graphviz renderer used by the extension I use, and some others, supports Courier (and substitutes Courier for monospace, but doesn't calculate the correct layout size if monospace is the first or only font).

I don't know if other fonts work.

It doesn't seem that "thin" to me, on my display, but if there's another option that works for everyone, I'm certainly not tied to Courier specifically. It just has to be a font that works (IMO).

@richkadel
Copy link
Contributor

This seems to be a well-known limitation of d3-graphviz, when I Google it.

Here's one note, for example:

https://github.com/mdaines/viz.js/wiki/Caveats#fonts

When used in Viz.js, Graphviz only knows about font metrics for Courier, Times, Helvetica, and Arial, even though it will include other font names in its output if they are specified. When another font name is specified, Graphviz will fall back to using the metrics for Times. This can result in a label being drawn outside of its node

Every derivative product I see appears to solve the problem in the same way (with "Courier, monospace").

@ecstatic-morse
Copy link
Contributor Author

I don't use any VSCode extensions. I use dot or xdot, both of which use pango and render everything correctly. If both plugins are broken (have you tried setting your system's monospace font to Courier for the less broken one btw?), we can configure this via an environment variable.

@richkadel
Copy link
Contributor

Got it. I did test with dot as well, output to PDF.
dot.pdf

The font doesn't seem "thin" to me.

How are you using it?

@ecstatic-morse
Copy link
Contributor Author

ecstatic-morse commented Sep 16, 2020

With -Zdump-mir-dataflow diagrams. You're free to use Courier if it works for you. It doesn't work for me. I would rather not hardcode the font and allow the system (and user) to choose. However, we can use an environment variable instead, since it seems anything using vis.js will be broken otherwise.

richkadel added a commit to richkadel/rust that referenced this pull request Sep 16, 2020
Alternative to PR #rust-lang#76776.

To change the graphviz output to use an alternative `fontname` value,
add a command line option like: `rustc --graphviz-font=monospace`.
@richkadel
Copy link
Contributor

Please take a look at PR #76794 and let me know if you have any feedback, or if this will give you the results you need.

Again, sorry for the disruption with this change.

Thanks!
Rich

@ecstatic-morse
Copy link
Contributor Author

No worries. Obviously, it's just a minor annoyance, but I do rely on these diagrams quite frequently when something breaks.

tmandry added a commit to tmandry/rust that referenced this pull request Sep 16, 2020
…-morse

Make graphviz font configurable

Alternative to PR rust-lang#76776.

To change the graphviz output to use an alternative `fontname` value,
add a command line option like: `rustc --graphviz-font=monospace`.

r? @ecstatic-morse
@richkadel
Copy link
Contributor

@ecstatic-morse - #76794 was successfully merged, so this PR can probably be closed, if you agree.

Thanks!

@bors
Copy link
Contributor

bors commented Sep 16, 2020

☔ The latest upstream changes (presumably #76804) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants