Position of selectionAdornmentTemplate

Is it possible to dynamically set selectionAdnornmentTemplate position? I have a fairly long context menu and it is cut off when its bottom is go over the canvas’s bottom.
For example, if an icon is around the top of the canvas, context menu’s top should be at the same position of icon’s top. If an icon is around the bottom of the canvas, context menu’s bottom should be at the same position of icon’s bottom.

Thank you.

If you are talking about context menus, those are different from selection adornments.

The position of context menus is determined by the ContextMenuTool.positionContextMenu method. You can override that method to position it however you like.

Here is the built-in definition of that method:

ContextMenuTool.prototype.positionContextMenu = function(contextmenu, obj) { if (contextmenu.placeholder !== null) return; var diagram = this.diagram; if (diagram === null) return; var p = diagram.lastInput.documentPoint.copy(); var ttb = contextmenu.measuredBounds; var viewb = diagram.viewportBounds; // when touch event -- shift towards the left, so it's not obscured by the finger if (diagram.lastInput.isTouchEvent) { p.x -= ttb.width; } // if extends too far to the right -- shift left if (p.x + ttb.width > viewb.right) { p.x -= ttb.width + 5; } // but don't go beyond the left edge of the viewport if (p.x < viewb.x) { p.x = viewb.x; } // if extends too far down -- shift up if (p.y + ttb.height > viewb.bottom) { p.y -= ttb.height + 5; } // but don't go beyond the top edge of the viewport if (p.y < viewb.y) { p.y = viewb.y; } contextmenu.position = p; };
What’s odd is that I think this code already covers the case that you are concerned about:
// if extends too far down – shift up

I shouldn’t say context menu. It is actually a selection adornment. It is for showing some detail info of an icon when the icon is clicked (left click).

I suppose it’s possible that your adornment template could depend on a data binding that would change its location relative to the selected part, but it isn’t simple to do.

Would you expect such smarts to apply to every selection adornment? That would require additional work, because you would need to handle cases involving many selected nodes. Furthermore when the diagram was scrolled, all of the adornments would need to be reconsidered.