react-plot
Version:
Library of React components to render SVG 2D plots.
30 lines • 1.09 kB
JavaScript
import { usePlotControls, usePlotEvents, } from '../contexts/plotController/plotControllerContext.js';
import { useDrawRectangle } from './useDrawRectangle.js';
export function useRectangularZoom(options = {}) {
const { horizontalAxisId = 'x', verticalAxisId = 'y' } = options;
const plotControls = usePlotControls(options);
const { annotations } = useDrawRectangle({
...options,
onEnd({ x1, x2, y1, y2 }) {
plotControls.setAxes({
[horizontalAxisId]: {
min: Math.min(x1, x2),
max: Math.max(x1, x2),
},
[verticalAxisId]: {
min: Math.min(y1, y2),
max: Math.max(y1, y2),
},
});
},
});
usePlotEvents({
onDoubleClick({ event: { button } }) {
if (button !== 0)
return;
plotControls.resetAxes([horizontalAxisId, verticalAxisId]);
},
}, options);
return { annotations };
}
//# sourceMappingURL=useRectangularZoom.js.map