Replies: 2 comments 4 replies
-
Hi Ralph, Thanks for the (partial) contribution! My experience with a similar use case was that, by moving the behavior to an IVNodePostprocessor (instead of the View itself), we could adjust the SVG Element after it has been rendered, making it possible to actually test the real rendered size of the text spans (rather than trying to estimate it). This is similar to how Sprotty uses a (hidden) rendered SVG Diagram, to compute the actual size of the rendered nodes, and then uses this data to apply layout. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for sharing this work @rsoika! This certainly looks better than resorting to HTML for this use case. @rsoika Can you please open a PR against glsp-client with your proposal, we could then continue the discussion there. Thank you very much! |
Beta Was this translation helpful? Give feedback.
-
Today I want to share my implementation of a client side viewer component showing a multi-line label. The idea of this component is to display a long label or text wrap over multiple lines. The line break automatically adjusts to the size of the container. The implementation if 100% SVG so the text can be exported as a SVG graphic too:
The component expects the text to display in the model attribute 'text'. I will explain the implementation details below:
As you can see from my implementation the viewer splits the text into words and build line by line. The method tests how many words fit in one line by comparing the line length with the component width. To display the text lines I use
<tspan>
elements. The text can be displayed centred, left or right aligned.The computation of the number of lines is very naive as I simply count the characters assuming a average character width. A more elegant solution would be testing the real width of the Tspan. I think this is possible with
currentTspan.getComputedTextLength()
:But I wasn't able to implement this myself because my knowledge of JSX and React is not sufficient. I think this kind of width-calculation only works when the tspan element is already visible.
Maybe someone find this component helpful. And maybe someone will find a way to further improve the component.
Beta Was this translation helpful? Give feedback.
All reactions