Width and height of shape

Hi,

I’m trying to get the width and height of the selected shape.
When checking the API it seems it’s only available in the GraphObject.

So what I did was first getting the ‘part’
and select the adornedObject (which returns the graphObject)

ex:
var adorn = obj.part;
var graph = adorn.adornedObject;
document.getElementById(“debug”).value = graph.width + " " + graph.height;

Problem is both give me always NaN as return value.

Although when I want to return the location of the object and use the ‘adornedPart’, it works.

Any ideas what I’m doing wrong?

Kind Regards,
Peter

GraphObject.width and .height are just “abbreviations” for GraphObject.desiredSize.width and .desiredSize.height. Most objects never get their desiredSize set to any value and the default value is NaN x NaN. Usually the only use of GraphObject.width or .height is to set it when initializing an object.

You probably want to use the GraphObject.actualBounds or the GraphObject.naturalBounds, depending on your purpose. What are you trying to do?

Well I’m recreating a whole mindmapping system.
The idea is when a node is selected, 2 buttons are shown (left and right of the node).
The left button would popup a window/panel with more options (like bold, italic, alignment, color, …)

Its for it’s location that I need the width of it. Or is there an easier solution?

Regards

Just create a custom Adornment for the node (.selectionAdornmentTemplate). In fact, the MindMap sample demonstrates this already, although with just a single button. No code needed (except for your button click event handler, of course).