update
This commit is contained in:
@ -552,50 +552,31 @@ export class DeesDashboardgrid extends DeesElement {
|
|||||||
const margins = this.getMargins();
|
const margins = this.getMargins();
|
||||||
const cellHeightValue = this.getCellHeight();
|
const cellHeightValue = this.getCellHeight();
|
||||||
|
|
||||||
// Convert margin to percentage to match renderWidget calculations
|
// Get widget position relative to grid container
|
||||||
const marginHorizontalPercent = (margins.horizontal / containerRect.width) * 100;
|
|
||||||
const cellWidthPercent = (100 - marginHorizontalPercent * (this.columns + 1)) / this.columns;
|
|
||||||
const cellWidthPixels = containerRect.width * cellWidthPercent / 100;
|
|
||||||
|
|
||||||
// Get mouse position relative to grid container
|
|
||||||
const mouseX = e.clientX - containerRect.left - this.dragOffsetX;
|
const mouseX = e.clientX - containerRect.left - this.dragOffsetX;
|
||||||
const mouseY = e.clientY - containerRect.top - this.dragOffsetY;
|
const mouseY = e.clientY - containerRect.top - this.dragOffsetY;
|
||||||
|
|
||||||
// Calculate which cell the mouse is over by finding the closest cell center
|
// Use pixel calculations for accuracy
|
||||||
|
const totalWidth = containerRect.width;
|
||||||
|
const totalMarginWidth = margins.horizontal * (this.columns + 1);
|
||||||
|
const availableWidth = totalWidth - totalMarginWidth;
|
||||||
|
const cellWidthPx = availableWidth / this.columns;
|
||||||
|
|
||||||
|
// Calculate grid X position
|
||||||
|
// Account for the initial margin and then repeating pattern of cell+margin
|
||||||
let gridX = 0;
|
let gridX = 0;
|
||||||
let minDistance = Infinity;
|
if (mouseX > margins.horizontal) {
|
||||||
|
const adjustedX = mouseX - margins.horizontal;
|
||||||
// Check distance to center of each possible column position
|
const cellPlusMargin = cellWidthPx + margins.horizontal;
|
||||||
for (let i = 0; i < this.columns; i++) {
|
gridX = Math.floor(adjustedX / cellPlusMargin + 0.5); // +0.5 for rounding to nearest
|
||||||
// Calculate position in pixels (matching renderWidget percentage formula)
|
|
||||||
const leftPercent = i * cellWidthPercent + (i + 1) * marginHorizontalPercent;
|
|
||||||
const cellLeftPixels = containerRect.width * leftPercent / 100;
|
|
||||||
const cellCenterPixels = cellLeftPixels + cellWidthPixels / 2;
|
|
||||||
const distance = Math.abs(mouseX - cellCenterPixels);
|
|
||||||
|
|
||||||
if (distance < minDistance) {
|
|
||||||
minDistance = distance;
|
|
||||||
gridX = i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Y: find closest row center
|
// Calculate grid Y position
|
||||||
let gridY = 0;
|
let gridY = 0;
|
||||||
minDistance = Infinity;
|
if (mouseY > margins.vertical) {
|
||||||
|
const adjustedY = mouseY - margins.vertical;
|
||||||
// Check reasonable number of rows
|
const cellPlusMargin = cellHeightValue + margins.vertical;
|
||||||
for (let i = 0; i < 100; i++) {
|
gridY = Math.floor(adjustedY / cellPlusMargin + 0.5); // +0.5 for rounding to nearest
|
||||||
const cellTop = i * cellHeightValue + (i + 1) * margins.vertical;
|
|
||||||
const cellCenter = cellTop + cellHeightValue / 2;
|
|
||||||
const distance = Math.abs(mouseY - cellCenter);
|
|
||||||
|
|
||||||
if (distance < minDistance) {
|
|
||||||
minDistance = distance;
|
|
||||||
gridY = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop checking if we're too far away
|
|
||||||
if (cellTop > mouseY + cellHeightValue) break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const clampedX = Math.max(0, Math.min(gridX, this.columns - this.draggedWidget.w));
|
const clampedX = Math.max(0, Math.min(gridX, this.columns - this.draggedWidget.w));
|
||||||
|
Reference in New Issue
Block a user