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

Static diagram sizing option #1080

Closed
pangloss opened this issue Mar 23, 2023 · 16 comments · Fixed by #1413
Closed

Static diagram sizing option #1080

pangloss opened this issue Mar 23, 2023 · 16 comments · Fixed by #1413

Comments

@pangloss
Copy link

Hi, I use d2 on a daily basis for analyzing program graphs for the compiler I'm working on. It works great for me in general but I'd love to convince you to make diagram scaling optional.

Given the wide variation of both diagram sizes user viewport sizes, I think viewport scaling must rarely be the optimal setting. Most likely only when it happens to produce graphs that are close to the diagram's natural size anyway. I really wish that I could change this behaviour.

My diagrams are sometimes quite large, often with a long sequence of steps rendered either top to bottom or left to right.

In early versions of d2, large graphs were no problem because the graph was not scaled. Everything was a fixed size and I could simply pan around in the browser, and possibly zoom out if I needed to orient myself.

Once viewport scaling came in, things became much more complex for me. In In order for the graph to be legible, I must zoom my browser out as far as possible, reload the page, then zoom in as far as possible. This involves something like 20 steps on the zoom controls. In fact, I had to customize Firefox to allow me a wider range of zoom steps because I needed nearly 100x zoom to read the text on one of the larger diagrams I wanted to look at!

If the diagram has too many elements, it frequently comes out looking like Fig. 1 below.

What I would like is in Fig. 2. To produce that, I opened up the web inspector and made just one edit! By removing the width and height attributes from the svg tag, the diagram magically re-scaled itself to exactly the right size!

It's very inconvenient to mess with the zoom or go in and edit the svg. I really wish I could just provide an --unscaled option when I start the d2 watcher on the console...

Thanks!
Darrick

Before:

<svg id="d2-svg" class="d2-2154263955" width="25.638187993899898" height="953.9999999999999" viewBox="-89 -89 2477 57704">

Fig. 1 "Diff view of 15 compiler transform steps, rendered by d2 in 10.7s"
Difficult to read diagram

After

<svg id="d2-svg" class="d2-2154263955" viewBox="-89 -89 2477 57704">

Fig. 2:
image

@alixander
Copy link
Collaborator

thanks for the feedback @pangloss , we'll have this for the next release: #721 (comment)

@bo-ku-ra
Copy link
Contributor

what i really want are

  • fit only the width
  • fit only the length
  • and this

@alixander
Copy link
Collaborator

@bo-ku-ra what about if direction is left/right, fit height, if direction is up/down, fit width?

and this.

@bo-ku-ra
Copy link
Contributor

@alixander
that may be the tendency, but it's a matter of preference.
fitting it on one side can make it appear larger.
it's a choice of whether to scroll vertically or horizontally for the viewer to easily understand it, I believe.

@pangloss
Copy link
Author

pangloss commented Mar 24, 2023

I experimented a bit more with a large diagram today. I misunderstood how the browser behaves when the width and height attributes are removed from the svg tag.

The change I recommended earlier was incorrect and will not have the desired effect.

To get a fixed scale version of the diagram, the only change I needed to make was to add height and width attributes to the outer svg tag. That worked but the diagram was very zoomed in. It was much better when I divided both of those values by 2. Here is the before and after with the first few opening tags of the file:

Before:

<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" d2Version="0.2.6" 
  preserveAspectRatio="xMinYMin meet" viewBox="0 0 7681 3045">
<svg id="d2-svg" class="d2-1358957321" width="7681" height="3045" viewBox="-89 -89 7681 3045">

image

After:

<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" d2Version="0.2.6" 
  preserveAspectRatio="xMinYMin meet" viewBox="0 0 7681 3045" 
  width="3840" height="1522">
<svg id="d2-svg" class="d2-1358957321" width="7681" height="3045" viewBox="-89 -89 7681 3045">

image

@alixander
Copy link
Collaborator

It was much better when I divided both of those values by 2.

@pangloss is this just an arbitrary zoom level to get text readable though? which differs depending on the diagram? i'm not sure what D2 can do here

@pangloss
Copy link
Author

pangloss commented Apr 6, 2023

I mean text readability. The default text/label size is constant, no matter how many nodes in the diagram. At some point it's personal preference, but I am aiming for something about the size I pasted above, which I think balances readability with maximizing the amount of diagram visible.

@alixander
Copy link
Collaborator

oh i think i know what you're talking about. you're saying, scale such that a "font-size: 12" word always takes up the same amount of pixels on the screen.

is that right?

@pangloss
Copy link
Author

pangloss commented Apr 6, 2023 via email

@pangloss
Copy link
Author

Hey, this one seems to have fallen by the wayside. Is there still any interest in resolving it?

@alixander
Copy link
Collaborator

thanks for bumping this. @gavin-ts any ideas how to do this?

@gavin-ts
Copy link
Contributor

gavin-ts commented May 27, 2023

I think if we can just merge in #721, that combined with zooming to 50% in the browser should have the desired effect. I created #1346 to resolve merge conflicts and update to work with watch mode

@alixander
Copy link
Collaborator

i don't think that's the desired effect.

"scale such that a "font-size: 12" word always takes up the same amount of pixels on the screen."

i think optimizing for text readability has a wide range of zoom levels depending on size of diagram.

@gavin-ts
Copy link
Contributor

"scale such that a "font-size: 12" word always takes up the same amount of pixels on the screen."

when we set the dimensions, font-size: 12 is always the same size

@bo-ku-ra
Copy link
Contributor

was this not implemented in d2 v0.5.0? (#721)

@gavin-ts
Copy link
Contributor

was this not implemented in d2 v0.5.0? (#721)

#1346 is still waiting on review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants