visual fixes

This commit is contained in:
jhartworks committed 2026-07-07 10:37:26 +02:00
1 parent 2c055fcb63
commit 7a1fe401f2
5 files changed
+77306 -24

No files matched your search

+33 -11
View File
@@ -72,9 +72,12 @@ export default function TrendChart({
allowExports = true,
allowFocusMode = true,
compact = false,
lineWidth = 1.8,
}) {
const wrapperRef = useRef(null);
const chartHostRef = useRef(null);
const dragBoxRef = useRef(null);
const domainRef = useRef({ x: [0, 1], y: [0, 1] });
const [selectedKeys, setSelectedKeys] = useState([]);
const [dragBox, setDragBox] = useState(null);
const [zoomDomain, setZoomDomain] = useState(null);
@@ -116,17 +119,23 @@ export default function TrendChart({
const xDomain = zoomDomain?.x || baseXDomain;
const yDomain = zoomDomain?.y || baseYDomain;
const hasFocusSelection = selectedKeys.length > 0 && selectedKeys.length < series.length;
const normalizedLineWidth = Number.isFinite(Number(lineWidth)) ? Number(lineWidth) : 1.8;
useEffect(() => {
domainRef.current = { x: xDomain, y: yDomain };
}, [xDomain, yDomain]);
const mapDragToDomain = (clientX, clientY) => {
const rect = wrapperRef.current?.getBoundingClientRect();
const rect = chartHostRef.current?.getBoundingClientRect() || wrapperRef.current?.getBoundingClientRect();
if (!rect) {
return null;
}
const activeDomain = domainRef.current;
const xRatio = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
const yRatio = Math.max(0, Math.min(1, (clientY - rect.top) / rect.height));
const xValue = xDomain[0] + (xDomain[1] - xDomain[0]) * xRatio;
const yValue = yDomain[1] - (yDomain[1] - yDomain[0]) * yRatio;
const xValue = activeDomain.x[0] + (activeDomain.x[1] - activeDomain.x[0]) * xRatio;
const yValue = activeDomain.y[1] - (activeDomain.y[1] - activeDomain.y[0]) * yRatio;
return {
xValue,
@@ -145,7 +154,9 @@ export default function TrendChart({
if (!mapped) {
return;
}
setDragBox({ start: mapped, end: mapped });
const nextDragBox = { start: mapped, end: mapped };
dragBoxRef.current = nextDragBox;
setDragBox(nextDragBox);
};
const updateDragBox = (clientX, clientY) => {
@@ -153,7 +164,14 @@ export default function TrendChart({
if (!mapped) {
return;
}
setDragBox((current) => current ? { ...current, end: mapped } : current);
setDragBox((current) => {
if (!current) {
return current;
}
const nextDragBox = { ...current, end: mapped };
dragBoxRef.current = nextDragBox;
return nextDragBox;
});
};
const finalizeDragBox = (box) => {
@@ -163,15 +181,18 @@ export default function TrendChart({
const deltaX = Math.abs(box.end.xPixel - box.start.xPixel);
const deltaY = Math.abs(box.end.yPixel - box.start.yPixel);
if (deltaX < 12 || deltaY < 12) {
if (deltaX < 12 && deltaY < 12) {
dragBoxRef.current = null;
setDragBox(null);
return;
}
const currentDomain = domainRef.current;
setZoomDomain({
x: [Math.min(box.start.xValue, box.end.xValue), Math.max(box.start.xValue, box.end.xValue)],
y: [Math.min(box.start.yValue, box.end.yValue), Math.max(box.start.yValue, box.end.yValue)],
x: deltaX < 12 ? currentDomain.x : [Math.min(box.start.xValue, box.end.xValue), Math.max(box.start.xValue, box.end.xValue)],
y: deltaY < 12 ? currentDomain.y : [Math.min(box.start.yValue, box.end.yValue), Math.max(box.start.yValue, box.end.yValue)],
});
dragBoxRef.current = null;
setDragBox(null);
};
@@ -185,7 +206,7 @@ export default function TrendChart({
};
const handleWindowMouseUp = () => {
finalizeDragBox(dragBox);
finalizeDragBox(dragBoxRef.current);
};
window.addEventListener("mousemove", handleWindowMouseMove);
@@ -444,10 +465,11 @@ export default function TrendChart({
<Line
key={entry.key}
yAxisId={entry.kind === "digital" ? "digital" : "analog"}
type={entry.kind === "digital" ? "stepAfter" : "monotone"}
type={entry.kind === "digital" ? "stepAfter" : "linear"}
dataKey={entry.key}
dot={false}
strokeWidth={selectedKeys.includes(entry.key) ? 2.35 : 1.8}
connectNulls
strokeWidth={selectedKeys.includes(entry.key) ? normalizedLineWidth + 0.55 : normalizedLineWidth}
stroke={entry.color}
strokeOpacity={isolated ? 0.1 : 1}
isAnimationActive={false}