if it’s impossible
It’s not impossible, but it’s also no easy or simple or done with any APIs that we normally demonstrate. Square has a center coordinate in data-space, and a size (in pixel/screen space). So. to get the corner coordinates, you would have to: convert the center data coordinate to a screen coordinate, apply the size to compute the corner screen coordinates, then apply the inverse mapping to convert those screen coordinate back in to data-space coordinate. And BTW of course, remember, the size is in pixels so anything that changes the scale (e.g. a zoom) will make those data-space coordinates of the corners change.
If you need the corner coordinates to be stable in data-space even after zooms, etc then a square
is just absolutely the wrong thing to use to begin with, because it was not created for that. The intended purpose of square is as a “point” scatter maker, that has a constant size in pixels, regardless of scale.
All that said, if this is really what you want to pursue, the things you should look to for reference in the BokehJS codebase are calls to v_compute
(to map data space into screen space) and v_invert
(to map screen space into data space)
On the other hand,
rect
data source could provide only one point(x,y)
Rects are specified by a single point, and a width and a height (all in data-space dimensions). You would need to compute the corner coordinates from that information.
I suppose it’s also worth mentioning, what you are after is actually a polygon with explicit coordinates for every point, that is the patches
glyph. But the edit tool for patches allows any polygon to be drawn, and won’t constrain users to only drawing rects/squares. It’s unclear what your actual requirements are, though.