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

Handle negative height & width in image annotations #7116

Merged
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
17 changes: 15 additions & 2 deletions e2e/tests/functional/plugins/imagery/exampleImagery.e2e.spec.js
scottbell marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ test.describe('Example Imagery Object', () => {
const canvasBoundingBox = await canvas.boundingBox();
const canvasCenterX = canvasBoundingBox.x + canvasBoundingBox.width / 2;
const canvasCenterY = canvasBoundingBox.y + canvasBoundingBox.height / 2;

await Promise.all(tagHotkey.map((x) => page.keyboard.down(x)));
await page.mouse.down();
// steps not working for me here
Expand All @@ -222,7 +221,7 @@ test.describe('Example Imagery Object', () => {
await expect(page.locator('[role="toolbar"][aria-label="Image controls"]')).toBeVisible();
await Promise.all(tagHotkey.map((x) => page.keyboard.up(x)));

//Wait for canvas to stabilize.
// Wait for canvas to stabilize.
scottbell marked this conversation as resolved.
Show resolved Hide resolved
await canvas.hover({ trial: true });

// add some tags
Expand All @@ -234,6 +233,20 @@ test.describe('Example Imagery Object', () => {
await page.getByRole('button', { name: /Add Tag/ }).click();
await page.getByPlaceholder('Type to select tag').click();
await page.getByText('Science').click();

// click on a separate part of the canvas to ensure no tags appear
await page.mouse.click(canvasCenterX + 10, canvasCenterY + 10);
await expect(page.getByText('Driving')).toBeHidden();
await expect(page.getByText('Science')).toBeHidden();

test.info().annotations.push({
type: 'issue',
description: 'https://github.com/nasa/openmct/issues/7083'
});
// click on annotation again and expect tags to appear
await page.mouse.click(canvasCenterX - 50, canvasCenterY - 50);
await expect(page.getByText('Driving')).toBeVisible();
await expect(page.getByText('Science')).toBeVisible();
});

test('Can use + - buttons to zoom on the image @unstable', async ({ page }) => {
Expand Down
25 changes: 20 additions & 5 deletions src/plugins/imagery/components/AnnotationsCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@
)?.rectangle;
const annotationRectangleForPixelDepth =
this.transformRectangleToPixelDense(annotationRectangle);
const indexNumber = builtAnnotationsIndex.add(
annotationRectangleForPixelDepth.x,
annotationRectangleForPixelDepth.y,
annotationRectangleForPixelDepth.x + annotationRectangleForPixelDepth.width,
annotationRectangleForPixelDepth.y + annotationRectangleForPixelDepth.height
const { x, y, x2, y2 } = this.transformAnnotationRectangleToFlatbushRectangle(

Check warning on line 81 in src/plugins/imagery/components/AnnotationsCanvas.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/imagery/components/AnnotationsCanvas.vue#L81

Added line #L81 was not covered by tests
annotationRectangleForPixelDepth
);
const indexNumber = builtAnnotationsIndex.add(x, y, x2, y2);

Check warning on line 84 in src/plugins/imagery/components/AnnotationsCanvas.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/imagery/components/AnnotationsCanvas.vue#L84

Added line #L84 was not covered by tests
this.indexToAnnotationMap[indexNumber] = annotation;
});
builtAnnotationsIndex.finish();
Expand Down Expand Up @@ -124,6 +122,23 @@
this.selectedAnnotations = annotations;
this.$emit('annotations-changed', annotations);
},
transformAnnotationRectangleToFlatbushRectangle(annotationRectangle) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect!

let { x, y, width, height } = annotationRectangle;

Check warning on line 126 in src/plugins/imagery/components/AnnotationsCanvas.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/imagery/components/AnnotationsCanvas.vue#L126

Added line #L126 was not covered by tests
let x2 = x + width;
let y2 = y + height;

Check warning on line 128 in src/plugins/imagery/components/AnnotationsCanvas.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/imagery/components/AnnotationsCanvas.vue#L128

Added line #L128 was not covered by tests

// if height or width are negative, we need to adjust the x and y
if (width < 0) {
x2 = x;
x = x + width;
}

Check warning on line 134 in src/plugins/imagery/components/AnnotationsCanvas.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/imagery/components/AnnotationsCanvas.vue#L131-L134

Added lines #L131 - L134 were not covered by tests
if (height < 0) {
y2 = y;
y = y + height;
}

Check warning on line 138 in src/plugins/imagery/components/AnnotationsCanvas.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/imagery/components/AnnotationsCanvas.vue#L137-L138

Added lines #L137 - L138 were not covered by tests

return { x, y, x2, y2 };

Check warning on line 140 in src/plugins/imagery/components/AnnotationsCanvas.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/imagery/components/AnnotationsCanvas.vue#L140

Added line #L140 was not covered by tests
},
updateSelection(selection) {
const selectionContext = selection?.[0]?.[0]?.context?.item;
const selectionType = selection?.[0]?.[0]?.context?.type;
Expand Down
Loading