react-plot
Version:
Library of React components to render SVG 2D plots.
24 lines • 1.35 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { Rectangle } from '../components/Annotations/Rectangle.js';
import { useStartMoveEnd } from './useStartMoveEnd.js';
export function useDrawRectangle(options = {}) {
const { controllerId, disabled, horizontalAxisId = 'x', verticalAxisId = 'y', color = 'red', style, onEnd, } = options;
const startMoveEnd = useStartMoveEnd({
controllerId,
disabled,
onEnd(_, start, end) {
const x1 = start.clampedCoordinates[horizontalAxisId];
const x2 = end.clampedCoordinates[horizontalAxisId];
const y1 = start.clampedCoordinates[verticalAxisId];
const y2 = end.clampedCoordinates[verticalAxisId];
if (x1 === x2 || y1 === y2) {
return;
}
onEnd?.({ x1, x2, y1, y2 });
},
});
return {
annotations: startMoveEnd?.end ? (_jsx(Rectangle, { xAxis: horizontalAxisId, yAxis: verticalAxisId, color: color, style: { fillOpacity: 0.2, stroke: color, ...style }, x1: startMoveEnd.start.clampedCoordinates[horizontalAxisId], x2: startMoveEnd.end.clampedCoordinates[horizontalAxisId], y1: startMoveEnd.start.clampedCoordinates[verticalAxisId], y2: startMoveEnd.end.clampedCoordinates[verticalAxisId] })) : null,
};
}
//# sourceMappingURL=useDrawRectangle.js.map