-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move slicing function down to SpectrumPhaseTrace component
- Loading branch information
1 parent
eba9618
commit 54f26ee
Showing
6 changed files
with
94 additions
and
152 deletions.
There are no files selected for viewing
40 changes: 2 additions & 38 deletions
40
src/component/2d/1d-tracer/phase-correction-traces/PhaseTraceWithMouse.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,13 @@ | ||
import { Spectrum2D } from 'nmr-load-save'; | ||
|
||
import { getSlice } from '../../../../data/data2d/Spectrum2D'; | ||
import { useMouseTracker } from '../../../EventsTrackers/MouseTracker'; | ||
import { useChartData } from '../../../context/ChartContext'; | ||
import { useActiveSpectrum } from '../../../hooks/useActiveSpectrum'; | ||
import { useScale2DX, useScale2DY } from '../../utilities/scale'; | ||
|
||
import { SpectrumPhaseTrace } from './SpectrumPhaseTrace'; | ||
import { useActivePhaseTraces } from './useActivePhaseTraces'; | ||
|
||
export function PhaseTraceWithMouse() { | ||
const { width, height, tempData } = useChartData(); | ||
const activeSpectrum = useActiveSpectrum(); | ||
const { activeTraceDirection, color } = useActivePhaseTraces(); | ||
const position = useMouseTracker(); | ||
|
||
const scale2dX = useScale2DX(); | ||
const scale2dY = useScale2DY(); | ||
|
||
if (!position || !width || !height || !activeSpectrum?.id) { | ||
return null; | ||
} | ||
const spectrum = tempData[activeSpectrum.index] as Spectrum2D; | ||
|
||
const sliceData = getSlice( | ||
spectrum, | ||
{ | ||
x: scale2dX.invert(position.x), | ||
y: scale2dY.invert(position.y), | ||
}, | ||
{ sliceType: 'both' }, | ||
); | ||
|
||
const data = sliceData?.[activeTraceDirection]?.data; | ||
if (!data) { | ||
if (!position) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<SpectrumPhaseTrace | ||
dataSource="mouse" | ||
data={data} | ||
position={position} | ||
color={color} | ||
direction={activeTraceDirection} | ||
/> | ||
); | ||
return <SpectrumPhaseTrace positionUnit="Pixel" position={position} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.