-
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: apodization window preview (#1647)
* feat: apodization window preview * refactor: change the apodization window y scale * refactor: ApdoizationLine component * refactor: set default value for lineBroadeningCenter is 0 * style: make the input field width smaller * chore: update dependencies * feat: unchecking live preview should reset the preview * feat: unchecking live preview should reset the preview
- Loading branch information
1 parent
7be801f
commit 16b97b3
Showing
8 changed files
with
153 additions
and
127 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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import * as Filters from '../../data/Filters'; | ||
import { | ||
apodizationFilter, | ||
defaultApodizationOptions, | ||
} from '../../data/data1d/filter1d/apodization'; | ||
import { Datum1D } from '../../data/types/data1d'; | ||
import { useChartData } from '../context/ChartContext'; | ||
import { useScaleChecked } from '../context/ScaleContext'; | ||
import useSpectrum from '../hooks/useSpectrum'; | ||
import useXYReduce, { XYReducerDomainAxis } from '../hooks/useXYReduce'; | ||
import { PathBuilder } from '../utility/PathBuilder'; | ||
|
||
import { getYScale } from './utilities/scale'; | ||
|
||
const emptyData = { data: {}, info: {} }; | ||
|
||
function useWindowYScale() { | ||
const { height, margin, verticalAlign } = useChartData(); | ||
return getYScale({ | ||
height, | ||
margin, | ||
verticalAlign, | ||
yDomain: [0, 1], | ||
}); | ||
} | ||
|
||
function ApdoizationLine() { | ||
const { | ||
activeSpectrum, | ||
toolOptions: { | ||
selectedTool, | ||
data: { apodizationOptions }, | ||
}, | ||
} = useChartData(); | ||
const { scaleX } = useScaleChecked(); | ||
const spectrum = useSpectrum({ emptyData }) as Datum1D; | ||
const xyReduce = useXYReduce(XYReducerDomainAxis.XAxis); | ||
const scaleY = useWindowYScale(); | ||
|
||
if (!activeSpectrum?.id || selectedTool !== Filters.apodization.id) { | ||
return null; | ||
} | ||
|
||
const paths = () => { | ||
const pathBuilder = new PathBuilder(); | ||
const { windowData: y } = apodizationFilter( | ||
spectrum, | ||
apodizationOptions || defaultApodizationOptions, | ||
); | ||
const x = spectrum.data?.x; | ||
|
||
if (x && y) { | ||
const pathPoints = xyReduce({ x, y }); | ||
|
||
pathBuilder.moveTo(scaleX()(pathPoints.x[0]), scaleY(pathPoints.y[0])); | ||
for (let i = 1; i < pathPoints.x.length; i++) { | ||
pathBuilder.lineTo(scaleX()(pathPoints.x[i]), scaleY(pathPoints.y[i])); | ||
} | ||
|
||
return pathBuilder.toString(); | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
|
||
return ( | ||
<path | ||
data-test-id="apodization-line" | ||
stroke="green" | ||
fill="none" | ||
strokeWidth="2" | ||
d={paths()} | ||
/> | ||
); | ||
} | ||
|
||
export default ApdoizationLine; |
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
Oops, something went wrong.