0

I have legend of a chart like this with svg:

  <g class="legend">
    <g class="scrollbox">
      <g><text>aaa</text></g>
      <g><text>bbb</text></g>
      <g><text>ccc</text></g>
      <g><text>ddd</text></g>
      <g><text>eee</text></g>
    </g>
  </g>

this would good if each text is not really long, but if text is long, it make legend(g) unnecessary bigger.

So I want legend (g) to have fixed width, and if text inside it is long, I want it to be wrapped.

How can I achieve this?
I know that I cannot really give style to <g>, so append some elements inside legend to achieve this?

kay
  • 1,369
  • 4
  • 15
  • 27

2 Answers2

0

try this:

<style>
text {
    white-space: wrap;
}
</style>
Fanyo SILIADIN
  • 802
  • 5
  • 11
0

You can add this css rule to the <text> to add ellipses to really long text.

Just add the class truncate to your elements or drop the class specificity-modifier from the rule below.

text.truncate {
  width: /* Your preferred width */;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

Alternatively:

.legend .scrollbox text { /* ... */ }
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132