Finding viewPoint center coordinates relative to a Shape?

Assume I have a digram 6x6.

| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |

I insert a Shape 3x3 square into this document in the bottom right.

| | | | | | |
| | | | | | |
| | | | | | |
| | | |o|o|o|
| | | |o|x|o|
| | | |o|o|o|

Problem: When I hover over this shape using mouseHover, how do I retrieve the center coordinate of the shape relative to the document (the x), ie. (5,5)?

Currently, if I perform getDocumentPoint(go.Spot.Center) on the Shape it returns me the coordinates of the center relative to the shape, (2,2). But I am looking for the coordinates relative to the entire diagram.

e.viewPoint only returns the center coordinates relative to the entire diagram.

Is your 6x6 diagram talking about the Diagram.documentBounds or the Diagram.viewportBounds?

Note that almost everything in GoJS is in document units, which are unaffected by scrolling/panning/zooming. The position and size of Parts are in document coordinates. The very few places where one encounters viewport coordinates are clearly documented. http://gojs.net/latest/intro/viewport.html

Certainly GraphObject.getDocumentPoint returns a point in document coordinates. That point is in the same coordinate system as Diagram.documentBounds.

I guess I shouldn’t have drawn a grid. :smiley:

It was a more a generic question… if I had a shape somewhere on the diagram, how do I get the exact center of that shape? Whenever I do node.getDocumentPoint(go.Spot.Center) it does indeed return me the center (x,y) of the shape, but not relative to the canvas, just relative to itself, if that makes sense.

Does that clarify?

Read http://gojs.net/latest/intro/viewport.html for an explanation and example showing the differences between viewport and document coordinates.