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

913 manual annotation page #984

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
126 changes: 126 additions & 0 deletions frontend/package-lock.json

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

10 changes: 7 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"react-dom": "^18.2.0",
"react-hook-form": "^7.52.1",
"react-intl": "^6.6.2",
"react-konva": "^18.2.10",
"react-paginate": "^8.2.0",
"react-router-bootstrap": "^0.26.2",
"react-router-dom": "^6.22.0",
Expand Down Expand Up @@ -100,10 +101,13 @@
"webpack-bundle-analyzer": "^4.10.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
},
"jest":{
},
"jest": {
"collectCoverage": true,
"coverageReporters": ["lcov", "text"],
"coverageReporters": [
"lcov",
"text"
],
"coverageDirectory": "./coverage"
}
}
5 changes: 5 additions & 0 deletions frontend/src/AuthenticatedSwitch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import AdminLogs from "./pages/AdminLogs";
import ReportEncounter from "./pages/ReportsAndManagamentPages/ReportEncounter";
import ReportConfirm from "./pages/ReportsAndManagamentPages/ReportConfirm";
import ProjectList from "./pages/ProjectList";
import ManualAnnotation from "./pages/ManualAnnotation";

export default function AuthenticatedSwitch({
showAlert,
Expand Down Expand Up @@ -67,6 +68,10 @@ export default function AuthenticatedSwitch({
<Route path="/reportConfirm" element={<ReportConfirm />} />
<Route path="/encounter-search" element={<EncounterSearch />} />
<Route path="/admin/logs" element={<AdminLogs />} />
<Route path="/manual-annotation" element={<ManualAnnotation

/>} />

<Route path="/login" element={<Login />} />
<Route path="/" element={<Home />} />
<Route path="*" element={<NotFound setHeader={setHeader} />} />
Expand Down
114 changes: 114 additions & 0 deletions frontend/src/components/ResizableRotatableRect.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React, { useEffect, useRef, useState } from "react";
import { Stage, Layer, Rect, Transformer } from "react-konva";

const ResizableRotatableRect = ({
rect,
imgHeight,
imgWidth,
setRect,
setValue,
drawStatus,
}) => {
const [rectProps, setRectProps] = useState({});

useEffect(() => {
if (drawStatus !== "DELETE") {
setRectProps(
{
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height,
fill: null,
stroke: "red",
strokeWidth: 2,
draggable: true,
}
);
}
}, [rect.x, rect.y, rect.width, rect.height, drawStatus]);


const rectRef = useRef(null);
const transformerRef = useRef(null);

const handleTransform = () => {

const node = rectRef.current;
const scaleX = node.scaleX();
const scaleY = node.scaleY();

const newWidth = Math.max(5, node.width() * scaleX);
const newHeight = Math.max(5, node.height() * scaleY);

const updatedRect = {
x: node.x(),
y: node.y(),
width: newWidth,
height: newHeight,
rotation: node.rotation(),
};
setRectProps({
...rectProps,
...updatedRect,
});

setRect({
...rect,
...updatedRect,
});

node.scaleX(1);
node.scaleY(1);
setValue(node.rotation());
console.log("x after resizing: ", node.x());
console.log("y after resizing:", node.y());
};

const handleDragEnd = () => {
const node = rectRef.current;
const updatedRect = {
x: node.x(),
y: node.y(),
};

setRectProps({
...rectProps,
...updatedRect,
});

setRect({
...rectProps,
...updatedRect,
});
};

const handleSelect = (e) => {
transformerRef.current.nodes([rectRef.current]);
transformerRef.current.getLayer().batchDraw();
};

return (
<Stage width={imgWidth} height={imgHeight}>
<Layer>
<Rect
{...rectProps}
ref={rectRef}
onClick={handleSelect}
onDragStart={handleSelect}
onDragEnd={handleDragEnd}
onTransformEnd={handleTransform}
draggable={true}
/>
<Transformer
ref={transformerRef}
rotateEnabled={true}
resizeEnabled={true}
keepRatio={false}
/>
</Layer>
</Stage>
);
};

export default ResizableRotatableRect;
Loading
Loading