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

text flow/wrap in actor box of sequence diagram #422

Closed
whyzdev opened this issue Nov 30, 2016 · 3 comments
Closed

text flow/wrap in actor box of sequence diagram #422

whyzdev opened this issue Nov 30, 2016 · 3 comments

Comments

@whyzdev
Copy link

whyzdev commented Nov 30, 2016

I tried the latest today. It seems to me that text no-wrap and "overflow" problem still exist in actor (within <text>), and in note with longs word with no-space (within <tsspan>)

Saw several existing issues on wrap, svg text, tspan, and foreignObject. Looks like tspan is the preferred direction over foreignObject. Is this correct? Any thoughts on using svg 1.2 feature? (Tried version="1.2" attribut in svg but no luck.)

If the tspan approach is agreed upon, drawActor needs similar code as in drawNote to break description string into tspan, with/without explict <br> or \n. Otherwise, is it still acceptable to change it with foreignObject/switch div/div+text/tspan?

I tried changing the current code:

exports.drawActor = function (elem, left, verticalPos, description, conf) {
...
    g.append('text') // text label for the x axis
    .attr('x', center).attr('y', verticalPos + conf.height / 2 + 5).attr('class', 'actor').style('text-anchor', 'middle').text(description);

to something like below

    var s = g.append('switch');
    var f =s.append("foreignObject")
    .attr('x',rect.x).attr('y',rect.y)
    .attr('width',rect.width).attr('height',rect.height);

    f.append('div').style('display','table')
       .style('height','100%').style('width','100%')
       .append('div').style('display','table-cell')
         .style('text-align','center').style('vertical-align','middle')
         .text(description)

    //same as before, or change to text+tspan
    s.append('text')
    .attr('x', center).attr('y', verticalPos + conf.height / 2 + 5).attr('class', 'actor').style('text-anchor', 'middle').text(description);

which produce something like below.

<switch><foreignObject x="400" y="0" width="150" height="65"><div xmlns="http://www.w3.org/1999/xhtml" style="display: table; height: 100%; width: 100%;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: table-cell; text-align: center; vertical-align: middle;">very very very vyer vyer very long</div></div></foreignObject><text x="475" y="37.5" class="actor" style="text-anchor: middle;">very very very vyer vyer very long</text></switch>

which worked for me locally.

Thanks,

@knsv
Copy link
Collaborator

knsv commented Nov 30, 2016 via email

knsv added a commit that referenced this issue Dec 2, 2016
…t_by_fo

#422 use foreignObject/div to place actor label in sequence diagram
@whyzdev
Copy link
Author

whyzdev commented Dec 7, 2016

i am quite close to add a candidate function for drawing actor text similar to d3textwrap, also made vertical alignment to middle works as much as possible. However, the d3textwrap for some reason in Firefox 5x misses the word "long" 3rd line for the above example, only showing two lines. Chrome works okay. So keep looking.

Before further consolidation drawText, we shall see which text render method is better, using d3textwrap with PR there, or not.

I would like to be able to just add some tests on the text placement. Like put text in a box to verify the code.

@whyzdev
Copy link
Author

whyzdev commented Dec 18, 2016

this should be fixed for text in sequence diagram actor. text placement default to use "tspan" method (alternatives being "fo" and "old"). Will move on beyond actor text to text in other places such as flow chart.

Please reopen or open new issue if there is problems.

@whyzdev whyzdev closed this as completed Dec 18, 2016
mgenereu pushed a commit to mgenereu/mermaid that referenced this issue Jun 25, 2022
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