gridstack_get_cell_from_pixel
Convert pixel coordinates to grid cell positions for precise widget placement in GridStack dashboard layouts.
Instructions
Convert pixel coordinates to grid cell position
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| position | Yes | ||
| useOffset | No | Use offset coordinates |
Implementation Reference
- src/tools/index.ts:1089-1099 (handler)The handler function that implements the tool logic. It destructures the input parameters (position and optional useOffset), then uses GridStackUtils to generate JavaScript code that invokes the GridStack library's getCellFromPixel method.private async getCellFromPixel(params: any): Promise<string> { const { position, useOffset = false } = params; return this.utils.generateGridStackCode("getCellFromPixel", { position, useOffset, code: `const cell = grid.getCellFromPixel(${JSON.stringify( position )}, ${useOffset});`, }); }
- src/tools/index.ts:570-592 (schema)The tool definition including name, description, and inputSchema for validation of parameters: position (with top and left pixels) and optional useOffset.{ name: "gridstack_get_cell_from_pixel", description: "Convert pixel coordinates to grid cell position", inputSchema: { type: "object", required: ["position"], properties: { position: { type: "object", required: ["top", "left"], properties: { top: { type: "number", description: "Top pixel position" }, left: { type: "number", description: "Left pixel position" }, }, }, useOffset: { type: "boolean", description: "Use offset coordinates", default: false, }, }, }, },
- src/tools/index.ts:831-832 (registration)The switch case in the callTool method that registers and dispatches calls to the specific handler for this tool.case "gridstack_get_cell_from_pixel": return this.getCellFromPixel(args);