Skip to content

Commit

Permalink
refactor: use ResizerWithScale component
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Nov 2, 2023
1 parent 15bb594 commit ebde8f0
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/component/1d/multiAnalysis/AnalysisRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import { css } from '@emotion/react';
import { useCallback } from 'react';

import { useGlobal } from '../../context/GlobalContext';
import { usePreferences } from '../../context/PreferencesContext';
import { useScaleChecked } from '../../context/ScaleContext';
import Resizer from '../../elements/resizer/Resizer';
import { ResizerWithScale } from '../../elements/ResizerWithScale';
import { useHighlight } from '../../highlight';
import { useResizerStatus } from '../../hooks/useResizerStatus';

Expand Down Expand Up @@ -55,7 +54,6 @@ function AnalysisRange({
});
const { scaleX } = useScaleChecked();
const { dispatch } = usePreferences();
const { viewerRef } = useGlobal();

const resizeEndHandler = useCallback(
(resized) => {
Expand All @@ -71,18 +69,15 @@ function AnalysisRange({
[activeTab, columnKey, dispatch, scaleX],
);

const from = scaleX()(rangeData.from);
const to = scaleX()(rangeData.to);
const isResizeingActive = useResizerStatus('multipleSpectraAnalysis');
const { from, to } = rangeData;
const isResizingActive = useResizerStatus('multipleSpectraAnalysis');
return (
<g {...highlight.onHover} {...highlight.onHover}>
<Resizer
tag="svg"
<ResizerWithScale
onEnd={resizeEndHandler}
initialPosition={{ x2: from, x1: to }}
parentElement={viewerRef}
key={`${columnKey}_${to}_${from}`}
disabled={!isResizeingActive}
from={from}
to={to}
disabled={!isResizingActive}
>
{({ x1, x2 }, isActive) => (
<g
Expand Down Expand Up @@ -114,7 +109,7 @@ function AnalysisRange({
</text>
</g>
)}
</Resizer>
</ResizerWithScale>
</g>
);
}
Expand Down

0 comments on commit ebde8f0

Please sign in to comment.