fix: prevent grid table overflow when union columns exceed zone bbox
When union columns from multiple content zones are applied, column boundaries can span wider than any single zone's bbox. Using zone.bbox_px.w as the scale reference caused the total scaled width to exceed the container, pushing the table off-screen. Now uses the actual total column width sum as the scale reference, guaranteeing columns always fit within the container. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -52,13 +52,18 @@ export function GridTable({
|
||||
// ----------------------------------------------------------------
|
||||
// Compute column widths from OCR measurements
|
||||
// ----------------------------------------------------------------
|
||||
const zoneWidthPx = zone.bbox_px.w || layoutMetrics?.page_width_px || 1
|
||||
const scale = containerWidth > 0 ? (containerWidth - ROW_NUM_WIDTH) / zoneWidthPx : 1
|
||||
|
||||
// Column widths in original pixels, then scaled to container
|
||||
// Use the actual total column span as reference width — NOT zone.bbox_px.w.
|
||||
// When union columns are applied across content zones, column boundaries
|
||||
// can extend beyond the zone's bbox, causing overflow if we scale by
|
||||
// the smaller zone width.
|
||||
const [colWidthOverrides, setColWidthOverrides] = useState<number[] | null>(null)
|
||||
|
||||
const columnWidthsPx = zone.columns.map((col) => col.x_max_px - col.x_min_px)
|
||||
const totalColWidthPx = columnWidthsPx.reduce((sum, w) => sum + w, 0)
|
||||
const zoneWidthPx = totalColWidthPx > 0
|
||||
? totalColWidthPx
|
||||
: (zone.bbox_px.w || layoutMetrics?.page_width_px || 1)
|
||||
const scale = containerWidth > 0 ? (containerWidth - ROW_NUM_WIDTH) / zoneWidthPx : 1
|
||||
|
||||
const effectiveColWidths = (colWidthOverrides ?? columnWidthsPx).map(
|
||||
(w) => Math.max(MIN_COL_WIDTH, w * scale),
|
||||
|
||||
Reference in New Issue
Block a user