Absolute Part location/position

I noticed that sometimes the X or Y position values of a node are negative. I believe that the negative value is relative to…?
How can i get the node absolute (X,Y) values within a diagram ?

The Diagram.documentBounds x/y values can be negative, which will result in negative coordinates for parts. If you want to know everything’s position as if the Diagram were at 0, 0, you will need to subtract the Diagram.documentBounds.x/y and Diagram.padding.

All Part coordinate values are in the “document” coordinate system. Please read GoJS Coordinate Systems-- Northwoods Software.

So the answer to your first question is “relative to the origin, (0, 0), in the document coordinate system”.

And the answer to your second question is “call Diagram.transformDocToView to convert document coordinates into viewport coordinates”.

Walter, jhardy,
The motivation behind this question is due to a long long frustration that i’m facing with GOJS in the past two years :
Every time i create a group, it is created “wherever” GOJS decides. I cannot control the location/position of a group. I take the blame on me cause i lack to understand the document/viewport system. I’m having problem to understand why x/y gets negtaive values.

Anyway, let me share a user case with of a group creation in my appliaction :
1-NodeSelection
The above picture shows a bunch of nodes. Two of them are selected (marked with arrow).
I right click on one of the nodes and create a custom group, that holds the two nodes.
The code that i run :


And the default group template is as follows :

Upon group creation, the group is createed outside the view port, causing the end user to be confused :
2-AfterGrouping1
You can see, in the above picture that the group is not seen. If i scroll down, i can see the group :

I cannot understand why the group was created so far outside of the viewport.
By the way, if i change the group template, so that the created group will stay expanded, the group is created behind the selected nodes :
6-unExpandedGroup
I need your help badly !!!
Where have i gone wrong ?
As of today, my application is considered by my customers, unusable.
Regards,
Tany

What is your group template? Does it use a Placeholder?

It appears that your groups may be expanded and collapsed, is that true? Do you create them collapsed or expanded? When you create them, do their member nodes already exist with real Node.location*s?

Yes,
My group template does have PlaceHolder.
My group does collapse/expand.
The nodes group member do have Node.location, yet the nodes are located on the top right of the diagram before and when selected, thus i don’t understand why their location do not define the group location.
Sent u the group and node template by email.

Did you get the templates ?
Sent by email

Yes, I did, and I replied 24 minutes later. Basically I was asking what the custom Group class does.

Anyway,
I’m trying to understand why Node.position is having negative values while the node is located in the center of the diagram.

Due to scrolling. GoJS Coordinate Systems-- Northwoods Software

If you want me to try to help you, I need to know what that custom Placeholder does.

It only overrides the computeBorder.
Sent u the code by email.
I get the same behavior, even if i use the native go.Placeholder

Placeholder.computeBorder is what determines where the Group is.

If you have not overridden that method, then the odd positioning of an expanded Group depends on the positions of all its member nodes and links.

Even if return to the original PlaceHolder, the group is created outside the view port.
Very frustrating.

I have tested the diagramDiagram.documentBounds right before the group is created and the diagram y is negative. How come ?

The Diagram.documentBounds is computed as the union of the Part.actualBounds of all of the Parts, including Nodes and Links. The Diagram.computeBounds method then adds the Diagram.padding, and Diagram.documentBounds remembers the value.

So you must have some nodes or links that exist at negative Y coordinates. Unless it’s negative only by the padding.

Is your problem only happening when the group is collapsed? Note that when Group.isSubGraphExpanded is false, the member parts are not visible, so the placeholder does not determine where the group is. Just call Group.move to move it where you want it to be.

This is what i mentioned in the beginning of the thread. The selected nodes have negative y value.
I cant tell why.
Yes, it happens only when the group is collapsed.
I will try to “move” the group.

If I group.move(new go.Point(-200,-600)), the group is moved “up” to the center of the diagram.
I still don’t understand why my nodes position have negative values.

When you create the Group, it’s collapsed, yes? At that time, what are the positions of the member Nodes?

Try creating it expanded, and then collapse it later, in a setTimeout function.

Yep this one works.
I also found out : Do you know why the collapsed group is getting out of the view port ? 3 guesses…
Because i set the diagram scrollMode to infiniteScroll. I can’t recall why…
As soon as I commented out this line, the group was created withing the view port.
Still, it was created NOT where i expected it to be created, but at least it was shown within the view port.
I’ll probably use the timeout method and create an expanded group that is collapsed after timeout(500).

By the way what is the best way to collapse a group ?
by Setting :
group.isSubgraphExpanded = false;

???
Or other way ?