New table rotation flip
This commit is contained in:
fraxle
2026-08-06 00:48:07 +01:00
parent 7f3fbb18c7
commit 60eee8e4c1
4 changed files with 315 additions and 24 deletions
+14 -4
View File
@@ -28,6 +28,7 @@ export function useTableScroll({
headTableRef,
bodyTableRef,
bodyScrollRef,
rotatedScrollRef,
headTrackRef,
tableWrapRef,
forecast,
@@ -41,7 +42,9 @@ export function useTableScroll({
showUnits,
// When the table is rotated it renders as ONE table whose sticky header
// row and sticky metric column are handled entirely in CSS. There is no
// second table to keep in step, so every effect below short-circuits.
// second table to keep in step, so the width-sync and scroll-indicator
// effects short-circuit — but drag-to-scroll still applies, just to the
// rotated pane (which scrolls in both axes) instead of the body table.
rotated = false,
}) {
// --- SCROLL INDICATORS ---------------------------------------------
@@ -57,21 +60,27 @@ export function useTableScroll({
// --- DRAG-TO-SCROLL ------------------------------------------------
useEffect(() => {
if (rotated) return;
const el = bodyScrollRef.current;
// Whichever element is actually the scroller in the current
// orientation. Rotated, it scrolls vertically too, so the drag
// follows both axes.
const el = rotated ? (rotatedScrollRef && rotatedScrollRef.current) : bodyScrollRef.current;
if (!el) return;
let isDown = false;
let startX = 0;
let startY = 0;
let startScroll = 0;
let startScrollTop = 0;
const onMouseDown = (e) => {
// Only act on clicks that land inside the body scroller
// Only act on clicks that land inside the scroller
if (!el.contains(e.target)) return;
if (e.button !== 0) return;
if (e.target.closest('button, a, input, select')) return;
isDown = true;
startX = e.clientX;
startY = e.clientY;
startScroll = el.scrollLeft;
startScrollTop = el.scrollTop;
el.style.cursor = 'grabbing';
document.body.style.userSelect = 'none';
document.body.style.webkitUserSelect = 'none';
@@ -80,6 +89,7 @@ export function useTableScroll({
if (!isDown) return;
const dx = e.clientX - startX;
el.scrollLeft = startScroll - dx;
if (rotated) el.scrollTop = startScrollTop - (e.clientY - startY);
};
const onMouseUp = () => {
if (!isDown) return;