-
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.
fix: vertical zoom for spectra and integrals (#1416)
close #1416
- Loading branch information
1 parent
e32584f
commit c2df1ec
Showing
25 changed files
with
266 additions
and
412 deletions.
There are no files selected for viewing
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 was deleted.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { ScaleLinear } from 'd3'; | ||
import { xyIntegral, xyReduce } from 'ml-spectra-processing'; | ||
import { useMemo } from 'react'; | ||
|
||
import { Data1D } from '../../data/types/data1d'; | ||
import { getIntegralYScale } from '../1d/utilities/scale'; | ||
import { useChartData } from '../context/ChartContext'; | ||
import { PathBuilder } from '../utility/PathBuilder'; | ||
|
||
import { useXScale } from './useXScale'; | ||
|
||
function useIntegralYDomain(): ScaleLinear<number, number, number> { | ||
const { height, margin, verticalAlign, activeSpectrum, integralsYDomains } = | ||
useChartData(); | ||
|
||
return useMemo( | ||
() => | ||
getIntegralYScale({ | ||
height, | ||
margin, | ||
verticalAlign, | ||
activeSpectrum, | ||
integralsYDomains, | ||
}), | ||
[activeSpectrum, height, integralsYDomains, margin, verticalAlign], | ||
); | ||
} | ||
|
||
export default function useIntegralPath(integralOptions: { | ||
from: number; | ||
to: number; | ||
}) { | ||
const { data, activeSpectrum } = useChartData(); | ||
|
||
const scaleX = useXScale(); | ||
const scaleY = useIntegralYDomain(); | ||
const integral = useMemo(() => { | ||
if (activeSpectrum) { | ||
const { x, re } = data[activeSpectrum?.index].data as Data1D; | ||
const { from, to } = integralOptions; | ||
return xyIntegral( | ||
{ x, y: re }, | ||
{ | ||
from, | ||
to, | ||
reverse: true, | ||
}, | ||
); | ||
} | ||
return { x: [], y: [] }; | ||
}, [activeSpectrum, data, integralOptions]); | ||
|
||
const paths = useMemo(() => { | ||
if (integral) { | ||
const xySeries = xyReduce(integral, { | ||
// from: xDomain[0], | ||
// to: xDomain[1], | ||
nbPoints: 200, | ||
optimize: true, | ||
}); | ||
|
||
const pathBuilder = new PathBuilder(); | ||
pathBuilder.moveTo(scaleX(xySeries.x[0]), scaleY(xySeries.y[0])); | ||
for (let i = 1; i < xySeries.x.length; i++) { | ||
pathBuilder.lineTo(scaleX(xySeries.x[i]), scaleY(xySeries.y[i])); | ||
} | ||
|
||
return pathBuilder.toString(); | ||
} else { | ||
return ''; | ||
} | ||
}, [integral, scaleX, scaleY]); | ||
|
||
return paths; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ScaleLinear } from 'd3'; | ||
import { useMemo } from 'react'; | ||
|
||
import { getXScale } from '../1d/utilities/scale'; | ||
import { useChartData } from '../context/ChartContext'; | ||
|
||
export function useXScale(): ScaleLinear<any, any, never> { | ||
const { width, margin, xDomains, xDomain, mode } = useChartData(); | ||
|
||
return useMemo( | ||
() => getXScale({ width, margin, xDomains, xDomain, mode }), | ||
[margin, mode, width, xDomain, xDomains], | ||
); | ||
} |
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.