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

Support rotation of box labels #15

Closed
lorrden opened this issue May 9, 2020 · 6 comments
Closed

Support rotation of box labels #15

lorrden opened this issue May 9, 2020 · 6 comments

Comments

@lorrden
Copy link

lorrden commented May 9, 2020

When printing labels for shorter boxes, the text often do not fit.
It would be nice if we could rotate the labels in the. boxes in these cases (combined with increasing the row height).

@brunchboy
Copy link
Member

All right, to celebrate finally getting beat-link-trigger 0.6.2 released today, I spent a little time poking at this. We can, indeed, do it with SVG transforms, but unfortunately it’s going to take some enhancements to bytefield-svg itself to make it work. My original hope was that we could simply use the existing release and add a rotation to the text element, like so:

  (draw-box (text "Label" {:transform "rotate(-90)"}))

Unfortunately, while that does indeed rotate the text, it rotates it around the origin of the diagram, not the center of the text. And only the code inside bytefield-svg knows what the coordinates of the center of the text are.

So, this will be possible with some more code. Will you be able to test trial implementations by installing bytefield-svg from source? I’d like to make sure it is working for you before publishing another release.

@brunchboy
Copy link
Member

On my way to bed I remembered that I built in an escape hatch that we can use with the current release! The draw-box function can take a function to be used to draw the label, and it calls that function with the location and dimensions of the box. So that function can emit a proper SVG transform to rotate the text, and then draw it: https://bytefield-svg.deepsymmetry.org/bytefield-svg/1.4.1/funcs.html#draw-box

@brunchboy
Copy link
Member

@lorrden you can rotate your labels today by setting the CSS attribute writing-mode to "vertical-rl":

(draw-box (text "Label" {:writing-mode "vertical-rl"}))

This, combined with setting row-height appropriately might get you started with something halfway decent. If you want to fine-tune the positioning, or the direction of rotation, then one of us can try a custom label rendering function as described in my previous comment.

@lorrden
Copy link
Author

lorrden commented May 12, 2020

This works quite well. I think this is enough to kill-off packetdiag in our case. I find the bytefield-svg (though we mostly use it for bitfield diagrams) absolutely awsome!

@lorrden lorrden closed this as completed May 12, 2020
@brunchboy
Copy link
Member

Thank you! I’m delighted to hear that. I will add an example of doing this to the user guide since I am sure you will not be the only person who will want something like this.

@brunchboy
Copy link
Member

And thanks again for the idea, @lorrden. I have updated the user guide to include an explanation of how to do this. It has some additional refinements that might be interesting to you. Also, if you have a diagram that would be a better illustration, and are willing to contribute the source, I would be happy to feature it and link to your project.

https://bytefield-svg.deepsymmetry.org/bytefield-svg/funcs.html#draw-vertical-text

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

No branches or pull requests

2 participants