Skip to content
Open
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
38 changes: 34 additions & 4 deletions frontend/src/components/ImageModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export const ImageModal = observer(
if (!imgRef.current) return;

const handleImageLoad = () => {
const naturalWidth = assets[safeIndex]?.width || imgRef.current?.naturalWidth;
const naturalWidth =
assets[safeIndex]?.width || imgRef.current?.naturalWidth;
const naturalHeight =
assets[safeIndex]?.height || imgRef.current?.naturalHeight;
const displayWidth = imgRef.current?.clientWidth;
Expand Down Expand Up @@ -203,7 +204,10 @@ export const ImageModal = observer(
}, [rects]);

const hasNonTrivialAnnotations = imageStore.encounterAnnotations?.some(
(a) => !a.isTrivial && (a.boundingBox?.[2] || 0) > 0 && (a.boundingBox?.[3] || 0) > 0
(a) =>
!a.isTrivial &&
(a.boundingBox?.[2] || 0) > 0 &&
(a.boundingBox?.[3] || 0) > 0,
);

return (
Expand Down Expand Up @@ -448,6 +452,32 @@ export const ImageModal = observer(
? 2000
: baseZ;

const containerWidth = boxRef.current?.clientWidth || 0;
const containerHeight =
boxRef.current?.clientHeight || 0;
const iconSize = 20;
const iconCount = 2;
const totalIconHeight = iconSize * iconCount;

const annotationRight = newRect.x + newRect.width;

let iconTop = newRect.y;
let iconLeft = annotationRight;

if (iconLeft + iconSize > containerWidth) {
iconLeft = newRect.x - iconSize;
}
if (iconLeft < 0) {
iconLeft = 0;
}

if (iconTop + totalIconHeight > containerHeight) {
iconTop = containerHeight - totalIconHeight;
}
if (iconTop < 0) {
iconTop = 0;
}

return (
<div
id={`annotation-rect-${index}`}
Expand Down Expand Up @@ -499,8 +529,8 @@ export const ImageModal = observer(
className="d-flex flex-column"
style={{
position: "absolute",
top: 0,
right: 0,
top: iconTop - newRect.y,
left: iconLeft - newRect.x,
zIndex: 20,
}}
onClick={(e) => e.stopPropagation()}
Expand Down
38 changes: 33 additions & 5 deletions frontend/src/pages/Encounter/ImageCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ const ImageCard = observer(({ store = {} }) => {
const handleLeave = () => setTip({ show: false, x: 0, y: 0, text: "" });

const hasNonTrivialAnnotations = store.encounterAnnotations?.some(
(a) => !a.isTrivial && (a.boundingBox?.[2] || 0) > 0 && (a.boundingBox?.[3] || 0) > 0
(a) =>
!a.isTrivial &&
(a.boundingBox?.[2] || 0) > 0 &&
(a.boundingBox?.[3] || 0) > 0,
);

useEffect(() => {
Expand Down Expand Up @@ -367,6 +370,31 @@ const ImageCard = observer(({ store = {} }) => {
const finalZ =
rect.annotationId === clickedAnnotation?.id ? 2000 : baseZ;

const containerWidth = boxRef.current?.clientWidth || 0;
const containerHeight = boxRef.current?.clientHeight || 0;
const iconSize = 20;
const iconCount = 2;
const totalIconHeight = iconSize * iconCount;

const annotationRight = newRect.x + newRect.width;

let iconTop = newRect.y;
let iconLeft = annotationRight;

if (iconLeft + iconSize > containerWidth) {
iconLeft = newRect.x - iconSize;
}
if (iconLeft < 0) {
iconLeft = 0;
}

if (iconTop + totalIconHeight > containerHeight) {
iconTop = containerHeight - totalIconHeight;
}
if (iconTop < 0) {
iconTop = 0;
}

return (
<div
id={`rect-${index}`}
Expand Down Expand Up @@ -413,8 +441,8 @@ const ImageCard = observer(({ store = {} }) => {
className="d-flex flex-column"
style={{
position: "absolute",
top: 0,
right: 0,
top: iconTop - newRect.y,
left: iconLeft - newRect.x,
zIndex: 20,
}}
onClick={(e) => e.stopPropagation()}
Expand Down Expand Up @@ -550,8 +578,8 @@ const ImageCard = observer(({ store = {} }) => {
className="d-flex"
style={{
position: "absolute",
top: 0,
right: -2,
top: iconTop - newRect.y,
left: iconLeft - newRect.x,
zIndex: 20,
}}
onClick={(e) => e.stopPropagation()}
Expand Down
Loading