12

I am trying to create a SimpleLabelStyle with the word wrapping enabled, as the second box of the interactive demo. However, I am not able to reproduce it.

I am trying:

var /**yfiles.drawing.SimpleLabelStyle*/ simpleLabelStyle = new yfiles.drawing.SimpleLabelStyle();
simpleLabelStyle.trimming = yfiles.system.StringTrimming.WORD;

But it's not working. In fact, in the documentation, I see that trimming "gets the value that determines how to trim the text." (it just says "gets" and not "sets").

Any help is appreciated!

Andrea
  • 6,032
  • 2
  • 28
  • 55

2 Answers2

1

Actually you can set the value - this documentation is misleading here. The property is declared READ-ONLY in the interface (see the badge):

ISimpleLabelStyle.trimming API

But the instance that you have instanciated implements the interface and makes the property READ-WRITE. Unfortunately the documentation is inherited from the interface and the only indication that the property is READ-WRITE is that the READ-ONLY badge is missing in the API browser. Any property that is not READ-ONLY or WRITE-ONLY is implicitly readable and writable so setting the value will work using the property on the instance (SimpleLabelStyle.trimming API)

Note that if you are changing the value for an existing style, the change will not immediately be visible. You should invalidate the graph's displays using the IGraph.invalidateDisplays() API

var style = new yfiles.drawing.SimpleLabelStyle() 
style.trimming = yfiles.system.StringTrimming.ELLIPSIS_WORD;
graph.setLabelStyle(label, style);

// and later
style.trimming = yfiles.system.StringTrimming.ELLIPSIS_CHARACTER;
graph.invalidateDisplays();
Sebastian
  • 7,729
  • 2
  • 37
  • 69
0

trimming is read-only, as indicated here, so you can't use it to set anything.

It appears that it's not intended to set a wrapping style for a simpleLabelStyle object directly as it provides neither a parameter not a function to do so, but you can set it at the time you add text to it. The addText and placeText functions allow you to pass a trimming parameter, which will take the WORD argument.

TheThirdMan
  • 1,482
  • 1
  • 14
  • 27
  • Thank you, it makes sense, indeed. I will try as soon as I can and let you now! – Andrea Aug 03 '16 at 09:37
  • OK, I am trying the approach suggested, but both `addText` and `placeText` require a `SVGTextElement` parameter, and I have literally no idea how to set that. I am trying `yfiles.drawing.TextRenderSupport.addText(node1, "Test with long text", c, new yfiles.geometry.SizeD(10, 10), yfiles.system.StringTrimming.WORD);`, with `c` being a `Typeface` previously defined, and `node1` my `INode` instance (I know, it's wrong, cause is not a `SVGTextElement`. Do you have any insights? Thank you. – Andrea Aug 04 '16 at 08:55
  • @Andrea: I was under the impression that you would need to provide your `SimpleLabelStyle` element, so in your original example, that would be the element stores in the `simpleLabelStyle` variable. The individual elements are SVG elements, so that's why they're named in such a way in the documentation (though as already established, the documentation isn't what you would call exhaustive...) – TheThirdMan Aug 04 '16 at 09:14