diff --git a/assets/admin/components/dashboard/TauriCharts.test.tsx b/assets/admin/components/dashboard/TauriCharts.test.tsx index 3d1f856a..ee8a0e68 100644 --- a/assets/admin/components/dashboard/TauriCharts.test.tsx +++ b/assets/admin/components/dashboard/TauriCharts.test.tsx @@ -34,6 +34,31 @@ describe('TauriBarChart', () => { expect(container.querySelectorAll('.bg-\\[\\#5559CE\\]')).toHaveLength(31); }); + /** + * A fixed-width bar makes its column's intrinsic min-width 24px, so a 31-day + * month sums past the plot width and the row overflows out of the card + * (bars land on the neighbouring chart). Columns must be shrinkable and the + * bar fluid-but-capped. + */ + it('keeps a dense month inside the card: shrinkable columns, fluid bars', () => { + const month: ChartPoint[] = Array.from({ length: 31 }, (_, i) => ({ label: String(i + 1), value: i % 5 })); + const { container } = render(); + + const bar = container.querySelector('.bg-\\[\\#5559CE\\]') as HTMLElement; + // کسری از ستون، نه تمام آن — وگرنه میله‌ها بدون فاصله به هم می‌چسبند + expect(bar.className).toMatch(/\bw-\[\d+%\]/); + expect(bar.className.split(/\s+/)).not.toContain('w-full'); + expect(bar.className).toContain('max-w-[24px]'); + // فقط سقف عرض، نه عرض ثابت (max-w-[24px] خودش شامل رشته‌ی w-[24px] است) + expect(bar.className.split(/\s+/)).not.toContain('w-[24px]'); + + const column = bar.parentElement as HTMLElement; + expect(column.className).toContain('min-w-0'); + + const plot = container.querySelector('.relative.flex-1') as HTMLElement; + expect(plot.className).toContain('overflow-hidden'); + }); + /** * styles.css ships an unlayered legacy `.flex { align-items: center }` that * beats Tailwind's `items-*` utilities and collapses the plot column to zero diff --git a/assets/admin/components/dashboard/TauriCharts.tsx b/assets/admin/components/dashboard/TauriCharts.tsx index f89243f6..95b649c8 100644 --- a/assets/admin/components/dashboard/TauriCharts.tsx +++ b/assets/admin/components/dashboard/TauriCharts.tsx @@ -65,7 +65,8 @@ function ChartFrame({ ))} {/* plot area */} -
+ {/* overflow-hidden keeps a dense series (a 31-day month) inside the card */} +
{ticks.map((_, i) => (
{labels.map((l, i) => ( - + {l} ))} @@ -98,12 +99,17 @@ export function TauriBarChart({ data }: { data: ChartPoint[] }) { const top = ticks[0] || 1; return ( d.label)} yWidth={42}> + {/* `min-w-0` on every column is required: without it each column's + intrinsic min-width is the bar's own width, so a 31-day month sums to + more than the plot width and the whole row overflows out of the card. + The bar is therefore a fraction of its column (which leaves the gap + between bars) and only capped at the source's 24px. */}
{data.map((d, i) => ( -
+
0 ? 4 : 0,