-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: phase correction traces for both directions
- Loading branch information
1 parent
ab7248e
commit c625982
Showing
19 changed files
with
557 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -147,4 +147,4 @@ | |
"vite": "^4.4.9", | ||
"vitest": "^0.34.5" | ||
} | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
src/component/2d/1d-tracer/phace-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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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 { SpectrumPhaseTrace } from './SpectrumPhaseTrace'; | ||
import { get2DXScale, get2DYScale } from '../../utilities/scale'; | ||
import { useActivePhaseTraces } from './useActivePhaseTraces'; | ||
|
||
export function PhaseTraceWithMouse() { | ||
const { | ||
width, | ||
margin, | ||
height, | ||
xDomain, | ||
data: spectra, | ||
yDomain, | ||
} = useChartData(); | ||
const activeSpectrum = useActiveSpectrum(); | ||
const { activeTraceDirection, color } = useActivePhaseTraces(); | ||
const position = useMouseTracker(); | ||
|
||
if (!position || !width || !height || !activeSpectrum?.id) { | ||
return null; | ||
} | ||
const spectrum = spectra[activeSpectrum.index] as Spectrum2D; | ||
|
||
const scale2dX = get2DXScale({ margin, width, xDomain }); | ||
const scale2dY = get2DYScale({ margin, height, yDomain }); | ||
|
||
const sliceData = getSlice(spectrum, { | ||
x: scale2dX.invert(position.x), | ||
y: scale2dY.invert(position.y), | ||
}); | ||
|
||
const data = sliceData?.[activeTraceDirection]?.data; | ||
if (!data) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<SpectrumPhaseTrace | ||
data={data} | ||
yShift={position.y} | ||
color={color} | ||
direction={activeTraceDirection} | ||
/> | ||
); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/component/2d/1d-tracer/phace-correction-traces/PhaseTraces.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useChartData } from '../../../context/ChartContext'; | ||
import { useActiveSpectrum } from '../../../hooks/useActiveSpectrum'; | ||
import { PhaseTraceWithMouse } from './PhaseTraceWithMouse'; | ||
import { SpectraPhaseTraces } from './SpectraPhaseTraces'; | ||
|
||
export function PhaseTraces() { | ||
const { width, height, margin, displayerKey } = useChartData(); | ||
const activeSpectrum = useActiveSpectrum(); | ||
|
||
if (!activeSpectrum?.id) return null; | ||
|
||
const clipWidth = width - margin.left - margin.right; | ||
const clipHeight = height - margin.top - margin.bottom; | ||
|
||
return ( | ||
<svg | ||
viewBox={`0 0 ${width} ${height}`} | ||
width={width} | ||
height={height} | ||
style={{ | ||
position: 'absolute', | ||
zIndex: 9, | ||
}} | ||
> | ||
<defs> | ||
<clipPath id={`${displayerKey}-clip-phase-traces`}> | ||
<rect | ||
width={clipWidth} | ||
height={clipHeight} | ||
x={margin.left} | ||
y={margin.top} | ||
/> | ||
</clipPath> | ||
</defs> | ||
<g clipPath={`url(#${displayerKey}-clip-phase-traces)`}> | ||
<PhaseTraceWithMouse /> | ||
<SpectraPhaseTraces /> | ||
</g> | ||
</svg> | ||
); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/component/2d/1d-tracer/phace-correction-traces/SpectraPhaseTraces.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useChartData } from '../../../context/ChartContext'; | ||
import { SpectrumPhaseTrace } from './SpectrumPhaseTrace'; | ||
import { get2DYScale } from '../../utilities/scale'; | ||
import { useActivePhaseTraces } from './useActivePhaseTraces'; | ||
|
||
export function SpectraPhaseTraces() { | ||
const { width, height, margin, yDomain } = useChartData(); | ||
const { spectra = [], color, activeTraceDirection } = useActivePhaseTraces(); | ||
|
||
if (!width || !height) { | ||
return null; | ||
} | ||
|
||
const scale2dY = get2DYScale({ margin, height, yDomain }); | ||
|
||
if (spectra.length === 0) { | ||
return null; | ||
} | ||
|
||
return spectra.map(({ id, data, y }) => { | ||
return ( | ||
<SpectrumPhaseTrace | ||
key={id} | ||
data={data} | ||
yShift={scale2dY(y)} | ||
color={color} | ||
direction={activeTraceDirection} | ||
/> | ||
); | ||
}); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/component/2d/1d-tracer/phace-correction-traces/SpectrumPhaseTrace.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useChartData } from '../../../context/ChartContext'; | ||
import { TraceDirection } from '../../../reducer/Reducer'; | ||
import { PathBuilder } from '../../../utility/PathBuilder'; | ||
import { get2DXScale } from '../../utilities/scale'; | ||
import { getYScale } from '../../utilities/SliceScale'; | ||
|
||
interface SpectrumPhaseTraceProps { | ||
data: { x: Float64Array; re: Float64Array }; | ||
yShift: number; | ||
color: string; | ||
direction: TraceDirection; | ||
} | ||
|
||
export function SpectrumPhaseTrace(props: SpectrumPhaseTraceProps) { | ||
const { data, yShift, color, direction } = props; | ||
const { width, margin, height, xDomain, yDomain } = useChartData(); | ||
|
||
const { x, re: y } = data; | ||
const scaleX = get2DXScale( | ||
{ margin, width, xDomain: direction === 'horizontal' ? xDomain : yDomain }, | ||
direction === 'vertical', | ||
); | ||
const scaleY = getYScale(height, y, margin.top + margin.bottom); | ||
|
||
const pathBuilder = new PathBuilder(); | ||
pathBuilder.moveTo(scaleX(x[0]), scaleY(y[0])); | ||
for (let i = 1; i < x.length; i++) { | ||
pathBuilder.lineTo(scaleX(x[i]), scaleY(y[i])); | ||
} | ||
|
||
const clipHeight = height - margin.top - margin.bottom; | ||
|
||
return ( | ||
<path | ||
className="line" | ||
stroke={color} | ||
strokeWidth="1" | ||
fill="transparent" | ||
d={pathBuilder.toString()} | ||
style={{ | ||
transform: `translate(0px,${yShift - clipHeight}px)`, | ||
}} | ||
/> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { PhaseTraces } from './PhaseTraces'; |
18 changes: 18 additions & 0 deletions
18
src/component/2d/1d-tracer/phace-correction-traces/useActivePhaseTraces.ts
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { COLORS } from '../../../../data/utilities/generateColor'; | ||
import { useChartData } from '../../../context/ChartContext'; | ||
|
||
export function useActivePhaseTraces() { | ||
const { | ||
toolOptions: { | ||
data: { | ||
twoDimensionPhaseCorrection: { traces, activeTraceDirection }, | ||
}, | ||
}, | ||
} = useChartData(); | ||
const color = activeTraceDirection === 'horizontal' ? COLORS[0] : COLORS[1]; | ||
return { | ||
spectra: traces[activeTraceDirection].spectra, | ||
activeTraceDirection, | ||
color, | ||
}; | ||
} |
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.