diff --git a/src/component/1d-2d/tools/BrushXY.tsx b/src/component/1d-2d/tools/BrushXY.tsx
index 99f809c4b..00d6fbf70 100644
--- a/src/component/1d-2d/tools/BrushXY.tsx
+++ b/src/component/1d-2d/tools/BrushXY.tsx
@@ -1,5 +1,6 @@
import styled from '@emotion/styled';
import { isSpectrum1D, isSpectrum2D } from '@zakodium/nmrium-core';
+import clamp from 'lodash/clamp.js';
import type { CSSProperties } from 'react';
import { useScale2DX } from '../../2d/utilities/scale.js';
@@ -81,11 +82,6 @@ interface BrushCoordinates {
endX?: number;
endY?: number;
}
-const defaultDimensionBorder: BrushCoordinates = {
- startX: 0,
- startY: 0,
-};
-
interface BrushXYProps {
axis: BrushAxis;
dimensionBorder?: BrushCoordinates;
@@ -99,7 +95,7 @@ interface BrushXYProps {
export default function BrushXY(props: BrushXYProps) {
const {
axis = 'XY',
- dimensionBorder = defaultDimensionBorder,
+ dimensionBorder,
width: widthProps,
height: heightProps,
margin: externalMargin,
@@ -118,48 +114,34 @@ export default function BrushXY(props: BrushXYProps) {
const { step, mouseButton } = brushTracker;
let { startX, endX, startY, endY } = brushTracker;
const { isPrimary } = useKeyModifiers();
+ const finalWidth = widthProps ?? width - margin.left - margin.right;
+ const finalHeight = heightProps ?? height - margin.top - margin.bottom;
+ const minX = dimensionBorder?.startX ?? margin.left;
+ const minY = dimensionBorder?.startY ?? margin.top;
+ const maxX = dimensionBorder?.endX ?? minX + finalWidth;
+ const maxY = dimensionBorder?.endY ?? minY + finalHeight;
if (
!isBrushAllowed(selectedTool, isPrimary) ||
step !== 'brushing' ||
mouseButton !== 'main' ||
- !dimensionBorder ||
- (dimensionBorder.startX && startX < dimensionBorder.startX) ||
- (dimensionBorder.startY && startY < dimensionBorder.startY) ||
- ((dimensionBorder.endX && Math.sign(endX - startX) === 1
- ? endX > dimensionBorder.endX
- : endX < dimensionBorder.startX) &&
- (dimensionBorder.endX &&
- dimensionBorder.endY &&
- Math.sign(endY - startY) === 1
- ? endY > dimensionBorder.endY
- : endY < dimensionBorder.startY))
+ startX < minX ||
+ startX > maxX ||
+ startY < minY ||
+ startY > maxY
) {
return null;
}
- const finalWidth = widthProps || width - margin.left - margin.right;
- const finalHeight = heightProps || height - margin.top - margin.bottom;
-
- endX =
- dimensionBorder.endX && endX > dimensionBorder.endX
- ? dimensionBorder.endX
- : dimensionBorder.startX && endX < dimensionBorder.startX
- ? dimensionBorder.startX
- : endX;
-
- endY =
- dimensionBorder.endY && endY > dimensionBorder.endY
- ? dimensionBorder.endY
- : dimensionBorder.startY && endY < dimensionBorder.startY
- ? dimensionBorder.startY
- : endY;
+ endX = clamp(endX, minX, maxX);
+ endY = clamp(endY, minY, maxY);
const brush = detectBrushing(
{ startX, startY, endX, endY },
{
width: finalWidth,
height: finalHeight,
...brushDetectionOptions,
+ axis,
},
);
@@ -182,10 +164,10 @@ export default function BrushXY(props: BrushXYProps) {
if (scaleX === 0 || scaleY === 0) return;
- startX = axis === 'Y' ? margin.left : brush.startX || margin.left;
- startY = axis === 'X' ? margin.top : brush.startY || margin.top;
- endX = axis === 'Y' ? finalWidth : brush.endX || finalWidth;
- endY = axis === 'X' ? finalHeight : brush.endY || finalHeight;
+ startX = axis === 'Y' || brush.type === 'Y' ? minX : brush.startX;
+ startY = axis === 'X' || brush.type === 'X' ? minY : brush.startY;
+ endX = axis === 'Y' || brush.type === 'Y' ? maxX : brush.endX;
+ endY = axis === 'X' || brush.type === 'X' ? maxY : brush.endY;
const invScaleX = 1 / scaleX;
const invScaleY = 1 / scaleY;
diff --git a/src/component/1d-2d/tools/CrossLinePointer.tsx b/src/component/1d-2d/tools/CrossLinePointer.tsx
index 4b7f5a1ed..b88ec1fdd 100644
--- a/src/component/1d-2d/tools/CrossLinePointer.tsx
+++ b/src/component/1d-2d/tools/CrossLinePointer.tsx
@@ -45,26 +45,23 @@ interface DimensionBorder {
endY?: number;
}
-const defaultDimensionBorder: DimensionBorder = {
- startX: 0,
- startY: 0,
-};
-
interface CrossLinePointerProps {
axis?: BrushAxis;
dimensionBorder?: DimensionBorder;
width?: number;
height?: number;
margin?: Margin;
+ fullView?: boolean;
}
function CrossLinePointer(props: CrossLinePointerProps) {
const {
axis = 'XY',
- dimensionBorder = defaultDimensionBorder,
+ dimensionBorder,
width: externalWidth,
height: externalHeight,
margin: externalMargin,
+ fullView = false,
} = props;
const {
@@ -77,15 +74,12 @@ function CrossLinePointer(props: CrossLinePointerProps) {
const brushState = useBrushTracker();
const margin = externalMargin ?? innerMargin;
- const finalWidth = externalWidth || width - margin.left - margin.right;
- const finalHeight = externalHeight || height - margin.top - margin.bottom;
-
- const {
- startX,
- startY,
- endX = finalWidth,
- endY = finalHeight,
- } = dimensionBorder;
+ const finalWidth = externalWidth ?? width - margin.left - margin.right;
+ const finalHeight = externalHeight ?? height - margin.top - margin.bottom;
+ const startX = dimensionBorder?.startX ?? margin.left;
+ const startY = dimensionBorder?.startY ?? margin.top;
+ const endX = dimensionBorder?.endX ?? startX + finalWidth;
+ const endY = dimensionBorder?.endY ?? startY + finalHeight;
const visibility = toolsVisibility[selectedTool];
@@ -109,32 +103,41 @@ function CrossLinePointer(props: CrossLinePointerProps) {
return null;
}
+ const left = fullView ? 0 : startX;
+ const top = fullView ? 0 : startY;
+
return (
-