From baf8092065f103b38f9a478e16049efc6000d186 Mon Sep 17 00:00:00 2001 From: Mehul Date: Wed, 7 Oct 2026 01:29:24 +0530 Subject: [PATCH] Keep layer names clear of the pump label in the borewell drawing A pump lowered to the middle of a layer had its label drawn over the layer's name. Layer names now step around the pump label the same way they do the water label, on screen and for the thin-layer names written beside the drawing in print. --- app/src/components/geology/BorewellProfile.tsx | 16 +++++++--------- e2e/run.mjs | 11 +++++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/src/components/geology/BorewellProfile.tsx b/app/src/components/geology/BorewellProfile.tsx index 852a68f..75b11f5 100644 --- a/app/src/components/geology/BorewellProfile.tsx +++ b/app/src/components/geology/BorewellProfile.tsx @@ -52,18 +52,16 @@ export function BorewellProfile({ const pumpAt = borewell.pumpLowering != null && borewell.pumpLowering > 0 && borewell.pumpLowering <= depth ? borewell.pumpLowering : null; const pumpLabelY = pumpAt == null ? null : wl != null && Math.abs(y(pumpAt) - 4 - (y(wl) - 2)) < 13 ? y(wl) + 12 : y(pumpAt) - 4; - // Layer names share a column with the "Water … ft" label. Move a name above or below that label - // when they would overlap, or leave it out if the layer is too thin (the popup still has it). + // Layer names share a column with the "Water … ft" and "Pump … ft" labels. Move a name above or + // below those labels when they would overlap, or leave it out if the layer is too thin (the popup still has it). const waterLabelY = wl != null ? y(wl) - 2 : null; + const fixedLabels = [waterLabelY, pumpLabelY].filter((v) => v != null).sort((a, b) => a - b); const labelY = (y1: number, h: number): number | null => { if (h < 13) return null; + const clear = (at: number) => fixedLabels.every((f) => Math.abs(at - f) >= 13); const centre = y1 + h / 2 + 4; - if (waterLabelY == null || Math.abs(centre - waterLabelY) >= 13) return centre; - const below = waterLabelY + 14; - if (below <= y1 + h - 2) return below; - const above = waterLabelY - 14; - if (above >= y1 + 11) return above; - return null; + if (clear(centre)) return centre; + return fixedLabels.flatMap((f) => [f + 14, f - 14]).find((at) => at >= y1 + 11 && at <= y1 + h - 2 && clear(at)) ?? null; }; // In print, where each name goes: on its layer, clear of the water line; or, for a layer too thin @@ -78,7 +76,7 @@ export function BorewellProfile({ } else { const lastBeside = Math.max(-Infinity, ...printLabel.filter((p) => !p.on).map((p) => p.at)); let at = Math.max(y1 + h / 2 + 3, lastBeside + 9.5); - if (waterLabelY != null && Math.abs(at - waterLabelY) < 11) at = waterLabelY + 12; + for (const f of fixedLabels) if (Math.abs(at - f) < 11) at = f + 12; printLabel.push({ on: false, at, size: 9.5 }); } } diff --git a/e2e/run.mjs b/e2e/run.mjs index 1a40a03..324289f 100644 --- a/e2e/run.mjs +++ b/e2e/run.mjs @@ -593,6 +593,17 @@ try { return __t.text();`); check("Home shows the numbers, recently added borewells and the backup panel", /3 borewells across/.test(home) && /Back up now/.test(home) && /Needs attention/.test(home), home.split("\n").slice(0, 10).join(" | ")); + + // ── The drawing: a pump lowered to the middle of a layer does not cover the layer's name ── + const labels = await page(` + const b = await __t.invoke('borewell_create', { input: { borewellId: 'LABELS-1', ownerName: 'Label test', city: 'Lucknow', date: '2026-09-01', totalDepth: 200, waterLevel: 108, pumpLowering: 158 } }); + await __t.invoke('strata_save', { borewellId: b.id, layers: [{ startDepth: 0, endDepth: 135, material: 'Clay' }, { startDepth: 135, endDepth: 175, material: 'Sand' }, { startDepth: 175, endDepth: 200, material: 'Clay' }] }); + location.hash = '#/borewell/' + b.id; + const pump = await __t.until(() => [...document.querySelectorAll('main svg text')].find(t => t.textContent === 'Pump 158 ft'), 10000); + const beside = [...pump.closest('svg').querySelectorAll('text')].filter(t => /^(Pump|Water|Sand|Clay) /.test(t.textContent)) + .map(t => ({ name: t.textContent, y: Number(t.getAttribute('y')) })); // 11 px text: baselines closer than that touch + return { names: beside.map(t => t.name), covered: beside.flatMap((a, i) => beside.slice(i + 1).filter(o => Math.abs(a.y - o.y) < 11).map(o => a.name + ' / ' + o.name)) };`); + check("The drawing keeps a layer's name clear of the pump and water labels", labels.names.includes("Sand 135–175") && labels.covered.length === 0, JSON.stringify(labels)); } catch (e) { check("Test run finished", false, String(e)); } finally {