Skip to content

Commit

Permalink
fix: LEAP-148: Fix MagicWand in MIG scenario with image preloading (H…
Browse files Browse the repository at this point in the history
…umanSignal#1685)

When both MIG and image preloading are enabled, there was no canvas overlay for the Magic Wand which caused the Magic Wand to fail.

* fix: LSDV-4864: Fix MagicWand in MIG scenario with image preloading

(cherry picked from commit d2330f7)

* Update ls-test dependency

* Fix tests

---------

Co-authored-by: Nick Skriabin <[email protected]>
Co-authored-by: hlomzik <[email protected]>
  • Loading branch information
3 people authored and MasherJames committed Feb 29, 2024
1 parent 634d3c4 commit 52336a2
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 68 deletions.
6 changes: 4 additions & 2 deletions src/components/ImageView/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const Image = observer(forwardRef(({
updateImageSize,
usedValue,
size,
overlay,
}, ref) => {
const imageSize = useMemo(() => {
return {
Expand All @@ -45,6 +46,7 @@ export const Image = observer(forwardRef(({

return (
<Block name="image" style={imageSize}>
{overlay}
<ImageProgress
downloading={imageEntity.downloading}
progress={imageEntity.progress}
Expand Down Expand Up @@ -76,7 +78,7 @@ const ImageProgress = observer(({
return downloading ? (
<Block name="image-progress">
<Elem name="message">Downloading image</Elem>
<Elem tag="progress" name="bar" value={progress} min="0" max={1} step={0.0001}/>
<Elem tag="progress" name="bar" value={progress} min="0" max={1} step={0.0001} />
</Block>
) : error ? (
<ImageLoadingError src={src} value={usedValue} />
Expand Down Expand Up @@ -121,6 +123,6 @@ const ImageLoadingError = ({ src, value }) => {
}, [src]);

return (
<ErrorMessage error={error}/>
<ErrorMessage error={error} />
);
};
27 changes: 18 additions & 9 deletions src/components/ImageView/ImageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,22 @@ const Crosshair = memo(forwardRef(({ width, height }, ref) => {
);
}));

/**
* Component that creates an overlay on top
* of the image to support Magic Wand tool
*/
const CanvasOverlay = observer(({ item }) => {
return isFF(FF_DEV_4081) ? (
<canvas
className={styles.overlay}
ref={ref => {
item.setOverlayRef(ref);
}}
style={item.imageTransform}
/>
) : null;
});

export default observer(
class ImageView extends Component {
// stored position of canvas before creating region
Expand Down Expand Up @@ -1020,6 +1036,7 @@ export default observer(
imageTransform={item.imageTransform}
updateImageSize={item.updateImageSize}
size={item.canvasSize}
overlay={<CanvasOverlay item={item} />}
/>
) : (
<div
Expand All @@ -1045,15 +1062,7 @@ export default observer(
crossOrigin={item.imageCrossOrigin}
alt="LS"
/>
{isFF(FF_DEV_4081) ? (
<canvas
className={styles.overlay}
ref={ref => {
item.setOverlayRef(ref);
}}
style={item.imageTransform}
/>
) : null}
<CanvasOverlay item={item} />
</div>
)}
{/* @todo this is dirty hack; rewrite to proper async waiting for data to load */}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/MagicWand.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ const _Tool = types
msg = 'The Magic Wand is not supported on rotated images';
} else {
msg = 'The Magic Wand is not supported if the crosshair is turned on';
}
}

alert(msg);
throw msg;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"cvg:summary": "nyc report --temp-dir=.nyc_output --reporter=text-summary --cwd=. --exclude-after-remap false"
},
"dependencies": {
"@heartexlabs/ls-test": "heartexlabs/ls-frontend-test#2619550d365dbfdb2b29fc07cf5ca70278a6928f"
"@heartexlabs/ls-test": "heartexlabs/ls-frontend-test#3d0d889d31fefa5ca3e3466482bab2664539115e"
},
"devDependencies": {
"ts-loader": "^9.4.2",
Expand Down
53 changes: 28 additions & 25 deletions tests/functional/specs/relations/basic.cy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ImageView, LabelStudio, Relations, ToolBar } from '@heartexlabs/ls-test/helpers/LSF';
import { Hotkeys, ImageView, LabelStudio, Relations, ToolBar } from '@heartexlabs/ls-test/helpers/LSF';
import {
imageConfigWithRelations,
simpleImageConfig,
simpleImageData, simpleImageResult,
simpleImageData,
simpleImageResult,
simpleImageResultWithRelation,
simpleImageResultWithRelations, simpleImageResultWithRelationsAndLabels, simpleImageResultWithRelationsAndLabelsAlt
simpleImageResultWithRelations,
simpleImageResultWithRelationsAndLabels,
simpleImageResultWithRelationsAndLabelsAlt
} from '../../data/relations/basic';

describe('Relations: Basic', () => {
Expand Down Expand Up @@ -176,19 +179,19 @@ describe('Relations: Basic', () => {

Relations.hasRelations(0);

ImageView.clickAtRelative(.30, .30);
ImageView.clickAtRelative(0.3, 0.3);
Relations.toggleCreationWithHotkey();
ImageView.clickAtRelative(.60, .60);
ImageView.clickAtRelative(0.6, 0.6);

cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(2);
});

cy.get('body').type('{ctrl+z}');
Hotkeys.undo();
Relations.hasRelations(0);
cy.get('body').type('{ctrl+shift+z}');
Hotkeys.redo();
Relations.hasRelations(1);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(2);
});
});
Expand All @@ -203,26 +206,26 @@ describe('Relations: Basic', () => {
ImageView.waitForImage();

Relations.hasRelations(1);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(1);
});

Relations.deleteRelationAction(0);

Relations.hasRelations(0);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(2);
});

cy.get('body').type('{ctrl+z}');
Hotkeys.undo();
Relations.hasRelations(1);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(2);
});

cy.get('body').type('{ctrl+shift+z}');
Hotkeys.redo();
Relations.hasRelations(0);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(2);
});
});
Expand All @@ -237,14 +240,14 @@ describe('Relations: Basic', () => {
ImageView.waitForImage();

Relations.hasRelations(1);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(1);
});

Relations.toggleRelationDirection(0);

Relations.hasRelations(1);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(2);
});
});
Expand All @@ -263,19 +266,19 @@ describe('Relations: Basic', () => {
Relations.clickShowRelationLabels(0);
Relations.addLabelToRelation('Blue label', 0);
Relations.hasRelationLabels(['Blue label'], 0);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(2);
});

cy.get('body').type('{ctrl+z}');
Hotkeys.undo();
Relations.hasRelationLabels([], 0);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(2);
});

cy.get('body').type('{ctrl+shift+z}');
Hotkeys.redo();
Relations.hasRelationLabels(['Blue label'], 0);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(2);
});
});
Expand All @@ -292,7 +295,7 @@ describe('Relations: Basic', () => {
Relations.hoverOverRelation(0);
Relations.stopHoveringOverRelation(0);

cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(1);
});
});
Expand All @@ -307,12 +310,12 @@ describe('Relations: Basic', () => {
ImageView.waitForImage();

Relations.hasRelations(1);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(1);
});

Relations.hideRelationAction(0);
cy.window().then((win) => {
cy.window().then(win => {
expect(win.Htx.annotationStore.selected.history.history.length).to.equal(1);
});
});
Expand Down
Loading

0 comments on commit 52336a2

Please sign in to comment.