-
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: delete the phase correction trace
Hover the mouse over the phase correction trace and press the 'Backspace' key. fix: traces
- Loading branch information
1 parent
af0d95b
commit 0a8331d
Showing
6 changed files
with
146 additions
and
25 deletions.
There are no files selected for viewing
95 changes: 82 additions & 13 deletions
95
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 |
---|---|---|
@@ -1,32 +1,101 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
import { css } from '@emotion/react'; | ||
|
||
import { useChartData } from '../../../context/ChartContext'; | ||
import { HighlightEventSource, useHighlight } from '../../../highlight'; | ||
import { SpectrumTrace, TraceDirection } from '../../../reducer/Reducer'; | ||
import { get2DXScale, get2DYScale } from '../../utilities/scale'; | ||
|
||
import { SpectrumPhaseTrace } from './SpectrumPhaseTrace'; | ||
import { useActivePhaseTraces } from './useActivePhaseTraces'; | ||
|
||
export function SpectraPhaseTraces() { | ||
const { width, height, margin, yDomain, xDomain } = useChartData(); | ||
const { spectra = [], color, activeTraceDirection } = useActivePhaseTraces(); | ||
const BOX_SIZE = 20; | ||
|
||
if (!width || !height) { | ||
return null; | ||
const style = css` | ||
.target { | ||
fill: transparent; | ||
} | ||
const scale2dX = get2DXScale({ margin, width, xDomain }); | ||
const scale2dY = get2DYScale({ margin, height, yDomain }); | ||
&:hover { | ||
.target { | ||
fill: #ff6f0057; | ||
} | ||
} | ||
`; | ||
|
||
export function SpectraPhaseTraces() { | ||
const { width, height } = useChartData(); | ||
const { spectra = [], color, activeTraceDirection } = useActivePhaseTraces(); | ||
|
||
if (spectra.length === 0) { | ||
if (!width || !height || spectra.length === 0) { | ||
return null; | ||
} | ||
|
||
return spectra.map(({ id, data, x, y }) => { | ||
return spectra.map((spectrumTrace) => { | ||
return ( | ||
<SpectrumPhaseTrace | ||
key={id} | ||
data={data} | ||
position={{ x: scale2dX(x), y: scale2dY(y) }} | ||
<PhaseTrace | ||
key={spectrumTrace.id} | ||
spectrum={spectrumTrace} | ||
color={color} | ||
direction={activeTraceDirection} | ||
/> | ||
); | ||
}); | ||
} | ||
|
||
interface SpectrumTraceProps { | ||
spectrum: SpectrumTrace; | ||
color: string; | ||
direction: TraceDirection; | ||
} | ||
|
||
function PhaseTrace(props: SpectrumTraceProps) { | ||
const { width, height, margin, yDomain, xDomain } = useChartData(); | ||
|
||
const { | ||
spectrum: { data, x, y, id }, | ||
color, | ||
direction, | ||
} = props; | ||
const highligh = useHighlight([id], { | ||
type: HighlightEventSource.PHASE_CORRECTION_TRACE, | ||
extra: { id }, | ||
}); | ||
|
||
const scale2dX = get2DXScale({ margin, width, xDomain }); | ||
const scale2dY = get2DYScale({ margin, height, yDomain }); | ||
|
||
const innerheight = height - margin.top - margin.bottom; | ||
const innerWidth = width - margin.left - margin.right; | ||
const transformY = innerheight - BOX_SIZE / 2; | ||
const transformX = innerWidth - BOX_SIZE / 2; | ||
|
||
return ( | ||
<SpectrumPhaseTrace | ||
data={data} | ||
position={{ x: scale2dX(x), y: scale2dY(y) }} | ||
color={color} | ||
direction={direction} | ||
{...highligh.onHover} | ||
css={style} | ||
> | ||
{direction === 'horizontal' && ( | ||
<rect | ||
className="target" | ||
y={transformY} | ||
x={margin.left} | ||
width={`${innerWidth}px`} | ||
height={`${BOX_SIZE}px`} | ||
/> | ||
)} | ||
{direction === 'vertical' && ( | ||
<rect | ||
className="target" | ||
y={margin.top} | ||
x={transformX} | ||
width={`${BOX_SIZE}px`} | ||
height={innerheight} | ||
/> | ||
)} | ||
</SpectrumPhaseTrace> | ||
); | ||
} |
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
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