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

fix: enable loading images from the same webSource #120

Merged
merged 6 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
17 changes: 9 additions & 8 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@
"react-kbs": "^2.1.1",
"react-map-interaction": "^2.1.0",
"react-plot": "^1.4.2",
"react-roi": "^1.4.0",
"react-roi": "^1.4.2",
"react-science": "^3.1.0",
"react-use": "^17.4.0"
"react-use": "^17.4.0",
"tiff": "^6.1.0"
},
"volta": {
"node": "18.16.0",
Expand Down
12 changes: 8 additions & 4 deletions src/components/AutoLoader.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { WebSource } from 'filelist-utils';
import { memo, ReactNode, useEffect } from 'react';

import useFileLoader from '../hooks/useFileLoader';
import useLog from '../hooks/useLog';

import { useWebSource } from './context/WebSourceContext';

interface AutoLoaderProps {
webSource?: WebSource;
children: ReactNode;
}

function AutoLoader({ children, webSource }: AutoLoaderProps) {
function AutoLoader({ children }: AutoLoaderProps) {
const { webSource, setWebSource } = useWebSource();

const { handleWebSource } = useFileLoader();
const { logger } = useLog();

Expand All @@ -19,7 +21,9 @@ function AutoLoader({ children, webSource }: AutoLoaderProps) {
handleWebSource(webSource).catch((error) => {
logger.error(`Error while loading websource: ${error.message}`);
});
}, [handleWebSource, logger, webSource]);

setWebSource?.(undefined);
}, [handleWebSource, logger, webSource, setWebSource]);

return children;
}
Expand Down
8 changes: 6 additions & 2 deletions src/components/FastSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface FastSelectorProps<T> {
options: T[];
selected: T | undefined;
setSelected: (value: T) => void;
defaultItem?: T | undefined;
}

const Container = styled.div`
Expand All @@ -19,7 +20,7 @@ const List = styled.ul`
border-radius: 6px;
`;

const ListElement = styled.li<{ selected: boolean }>`
const ListElement = styled.li<{ selected: boolean; defaultItem: boolean }>`
padding: 10px;
border: 1px solid #9e9e9e;
border-top-width: 0px;
Expand All @@ -41,14 +42,16 @@ const ListElement = styled.li<{ selected: boolean }>`
border-bottom-right-radius: 6px;
}

background-color: ${({ selected }) => (selected ? 'royalblue' : 'white')};
background-color: ${({ selected, defaultItem }) =>
selected ? 'royalblue' : defaultItem ? 'lightgray' : 'white'};
color: ${({ selected }) => (selected ? 'white' : 'black')};
`;

export default function FastSelector<T extends string>({
options,
selected,
setSelected,
defaultItem,
}: FastSelectorProps<T>) {
// eslint-disable-next-line unicorn/no-array-reduce
const refs: { [key: string]: RefObject<HTMLLIElement> } = options.reduce(
Expand Down Expand Up @@ -106,6 +109,7 @@ export default function FastSelector<T extends string>({
selected={option === selected}
onClick={() => setSelected(option)}
ref={refs[option]}
defaultItem={option === defaultItem}
>
{option}
</ListElement>
Expand Down
70 changes: 15 additions & 55 deletions src/components/ImageViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import {
CSSProperties,
memo,
MutableRefObject,
useCallback,
useEffect,
useMemo,
} from 'react';
import { RoiContainer, RoiProvider, useTargetRef } from 'react-roi';
import { RoiContainer, useTargetRef } from 'react-roi';

import useImage from '../hooks/useImage';
import useView from '../hooks/useView';
import useViewDispatch from '../hooks/useViewDispatch';
import { SET_PAN_ZOOM } from '../state/view/ViewActionTypes';

import ROIAnnotations from './roi/ROIAnnotations';

Expand Down Expand Up @@ -45,66 +41,30 @@ function ImageViewer({
image,
annotable = false,
}: ImageViewerProps) {
const view = useView();
const viewDispatch = useViewDispatch();

const { original, pipelined } = useImage();

const imageToShow = useMemo(() => {
if (image !== undefined) return image;
return showOriginal ? original : pipelined;
}, [image, original, pipelined, showOriginal]);

const panZoom = useMemo(() => {
return (
view.imageViewerProps[identifier] || {
scale: 1,
translation: [0, 0],
}
);
}, [identifier, view.imageViewerProps]);

const setPanZoom = useCallback(
(panZoom) => {
viewDispatch({
type: SET_PAN_ZOOM,
payload: { identifier, panZoom },
});
},
[identifier, viewDispatch],
);

return (
<RoiProvider
initialConfig={{
zoom: {
initial: panZoom,
min: 0.1,
max: 30,
spaceAroundTarget: 0,
},
resizeStrategy: 'contain',
mode: 'select',
<RoiContainer
zoomWithoutModifierKey
target={<TargetCanvas imageToShow={imageToShow} />}
style={{
width: '100%',
height: '100%',
}}
onAfterZoomChange={setPanZoom}
>
<RoiContainer
zoomWithoutModifierKey
target={<TargetCanvas imageToShow={imageToShow} />}
style={{
width: '100%',
height: '100%',
}}
>
{annotable && (
<ROIAnnotations
width={imageToShow?.width}
height={imageToShow?.height}
identifier={identifier}
/>
)}
</RoiContainer>
</RoiProvider>
{annotable && (
<ROIAnnotations
width={imageToShow?.width}
height={imageToShow?.height}
identifier={identifier}
/>
)}
</RoiContainer>
);
}

Expand Down
146 changes: 0 additions & 146 deletions src/components/Pixelium.tsx

This file was deleted.

Loading