Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve contours caching calculation #3243

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"ml-array-median": "^1.1.6",
"ml-array-xy-equally-spaced": "^1.2.1",
"ml-baseline-correction-regression": "^2.0.1",
"ml-conrec": "^5.0.2",
"ml-conrec": "^5.0.3",
"ml-gsd": "^12.1.6",
"ml-matrix": "^6.11.1",
"ml-signal-processing": "^1.0.4",
Expand Down
29 changes: 17 additions & 12 deletions src/component/2d/ft/Contours.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,8 @@ function ContoursPaths({
}: ContoursPathsProps) {
const activeSpectrum = useActiveSpectrum();
const preferences = usePreferences();
const level = useContoursLevel(spectrum, sign);

const contours = useMemo(() => {
const { contours, timeout } = drawContours(
level,
spectrum,
sign === 'negative',
);
if (timeout) {
onTimeout();
}
return contours;
}, [spectrum, level, onTimeout, sign]);
const contours = useContours(spectrum, sign, onTimeout);

const path = usePath(spectrum, contours);

Expand Down Expand Up @@ -171,3 +160,19 @@ export default function Contours() {

return <MemoizedContours {...{ spectra: spectra2d, displayerKey }} />;
}

function useContours(spectrum: Spectrum2D, sign, onTimeout) {
const cache = useRef(new Map());
const level = useContoursLevel(spectrum, sign);

return useMemo(() => {
const { contours, timeout } = drawContours(spectrum, level, {
negative: sign === 'negative',
cache: cache.current,
});
if (timeout) {
onTimeout();
}
return contours;
}, [spectrum, level, onTimeout, sign]);
}
Loading
Loading