MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / rotate

Method rotate

src/gridstack.ts:1729–1747  ·  view source on GitHub ↗

* Rotate widgets by swapping their width and height. This is typically called when the user presses 'r' during dragging. * The rotation swaps the w/h dimensions and adjusts min/max constraints accordingly. * * @param els widget element(s) or selector to rotate * @param relative optional

(els: GridStackElement, relative?: Position)

Source from the content-addressed store, hash-verified

1727 * grid.rotate(widget, { left: 50, top: 30 });
1728 */
1729 public rotate(els: GridStackElement, relative?: Position): GridStack {
1730 GridStack.getElements(els).forEach(el => {
1731 const n = el.gridstackNode;
1732 if (!Utils.canBeRotated(n)) return;
1733 const rot: GridStackWidget = { w: n.h, h: n.w, minH: n.minW, minW: n.minH, maxH: n.maxW, maxW: n.maxH };
1734 // if given an offset, adjust x/y by column/row bounds when user presses 'r' during dragging
1735 if (relative) {
1736 const pivotX = relative.left > 0 ? Math.floor(relative.left / this.cellWidth()) : 0;
1737 const pivotY = relative.top > 0 ? Math.floor(relative.top / (this.opts.cellHeight as number)) : 0;
1738 rot.x = n.x + pivotX - (n.h - (pivotY+1));
1739 rot.y = (n.y + pivotY) - pivotX;
1740 }
1741 Object.keys(rot).forEach(k => { if (rot[k] === undefined) delete rot[k]; });
1742 const _orig = n._orig;
1743 this.update(el, rot);
1744 n._orig = _orig; // restore as move() will delete it
1745 });
1746 return this;
1747 }
1748
1749 /**
1750 * Updates the margins which will set all 4 sides at once - see `GridStackOptions.margin` for format options.

Callers 1

_keyEventMethod · 0.80

Calls 4

cellWidthMethod · 0.95
updateMethod · 0.95
canBeRotatedMethod · 0.80
getElementsMethod · 0.45

Tested by

no test coverage detected