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

Center graphics and determine bounds automatically #8

Open
corneliusroemer opened this issue Jan 1, 2022 · 1 comment
Open

Center graphics and determine bounds automatically #8

corneliusroemer opened this issue Jan 1, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@corneliusroemer
Copy link
Member

Right now the width of the graphic has to be set manually.

It would be great if the width was determined automatically.

Even if that's not possible, the graph should be centered. Right now it seems to be left aligned:
image

@corneliusroemer corneliusroemer added the enhancement New feature or request label Jan 1, 2022
@ivan-aksamentov
Copy link
Member

ivan-aksamentov commented Jan 4, 2022

I looked at the d3.js code and could not figure out how to restrict drawing to a given size.

Despite width and height are provided here:

const treemap = d3.tree().size([height, width])

the resulting elements can still be drawn outside the canvas.

Also width and height are swapped and y,x are used throughout the function in reverse order it seems. Maybe this is the clue.

Centering relies on width and height, so I think it is not possible to do, because the final dimensions are unknown, because of what I wrote above.

For now, to keep it simple, after data update, I think we could manually tweak width, height and margins as needed.

If someone attempts to fix that, make sure you keep the viewBox property of SVG. As far as I know it's the only reliable way to scale SVG images responsively (in the downstream projects)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants