MCPcopy
hub / github.com/react-grid-layout/react-grid-layout / calcXY

Function calcXY

src/core/calculate.ts:176–196  ·  view source on GitHub ↗
(
  positionParams: PositionParams,
  top: number,
  left: number,
  w: number,
  h: number
)

Source from the content-addressed store, hash-verified

174 * @returns x and y in grid units
175 */
176export function calcXY(
177 positionParams: PositionParams,
178 top: number,
179 left: number,
180 w: number,
181 h: number
182): { x: number; y: number } {
183 const { margin, containerPadding, cols, rowHeight, maxRows } = positionParams;
184 const colWidth = calcGridColWidth(positionParams);
185
186 // left = containerPaddingX + x * (colWidth + marginX)
187 // x = (left - containerPaddingX) / (colWidth + marginX)
188 let x = Math.round((left - containerPadding[0]) / (colWidth + margin[0]));
189 let y = Math.round((top - containerPadding[1]) / (rowHeight + margin[1]));
190
191 // Clamp to grid bounds
192 x = clamp(x, 0, cols - w);
193 y = clamp(y, 0, maxRows - h);
194
195 return { x, y };
196}
197
198/**
199 * Translate pixel coordinates to grid units without clamping.

Callers 5

utils-test.jsFile · 0.90
GridLayoutFunction · 0.85

Calls 2

calcGridColWidthFunction · 0.85
clampFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…