Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit ced2686

Browse files
authored
Merge pull request #280 from daita-technologies/update/annotation
Update: annotation enhancement and fix bugs
2 parents 418b12a + 3846b8d commit ced2686

29 files changed

Lines changed: 496 additions & 406 deletions

File tree

src/components/Annotation/Editor/const.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ export const CORNER_RADIUS = 5;
1414

1515
export const MAX_WIDTH_IMAGE_IN_EDITOR = 1000;
1616
export const MAX_HEIGHT_IMAGE_IN_EDITOR = 700;
17-
export const MAX_WIDTH_EDITOR = 1200;
18-
export const MAX_HEIGHT_EDITOR = 700;
17+
export const MAX_WIDTH_EDITOR = 1270;
18+
export const MAX_HEIGHT_EDITOR = 825;

src/components/Annotation/Formart/daita/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export const exportAnnotation = (
215215
)}`;
216216
const link = document.createElement("a");
217217
link.href = jsonString;
218-
link.download = `${imageName}.json`;
218+
link.download = `${imageName.replace(/\.[^.]+$/, "-DAITA")}.json`;
219219

220220
link.click();
221221
};

src/components/Annotation/Formart/labelbox/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export const convert = (
4949
return shape;
5050
};
5151
export const exportAnnotation = (
52-
drawObjectById: Record<string, DrawObject>
52+
drawObjectById: Record<string, DrawObject>,
53+
imageName: string | null
5354
) => {
5455
const shapes: LabelLabelBox = convert(drawObjectById);
5556
const annotationFormatter: AnnotationFormatter =
@@ -59,7 +60,9 @@ export const exportAnnotation = (
5960
)}`;
6061
const link = document.createElement("a");
6162
link.href = jsonString;
62-
link.download = "data.json";
63+
link.download = imageName
64+
? `${imageName.replace(/\.[^.]+$/, "-LabelBox")}.json`
65+
: "data.json";
6366

6467
link.click();
6568
};

src/components/Annotation/Formart/labelme/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ export const convert = (
171171
};
172172
export const exportAnnotation = (
173173
annotationImagesProperty: AnnotationImagesProperty,
174-
drawObjectById: Record<string, DrawObject>
174+
drawObjectById: Record<string, DrawObject>,
175+
imageName: string | null
175176
) => {
176177
const shapes: Shape[] = convert(drawObjectById);
177178
const { image } = annotationImagesProperty;
@@ -187,7 +188,9 @@ export const exportAnnotation = (
187188
)}`;
188189
const link = document.createElement("a");
189190
link.href = jsonString;
190-
link.download = "data.json";
191+
link.download = imageName
192+
? `${imageName.replace(/\.[^.]+$/, "-LabelMe")}.json`
193+
: "data.json";
191194

192195
link.click();
193196
};

src/components/Annotation/Formart/scaleai/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ export const importAnnotation = (
8585
};
8686
});
8787
export const exportAnnotation = (
88-
drawObjectById: Record<string, DrawObject>
88+
drawObjectById: Record<string, DrawObject>,
89+
imageName: string | null
8990
) => {
9091
const shapes: Shape[] = convert(drawObjectById);
9192
const annotationFormatter: AnnotationFormatter =
@@ -95,7 +96,9 @@ export const exportAnnotation = (
9596
)}`;
9697
const link = document.createElement("a");
9798
link.href = jsonString;
98-
link.download = "data.json";
99+
link.download = imageName
100+
? `${imageName.replace(/\.[^.]+$/, "-ScaleAI")}.json`
101+
: "data.json";
99102

100103
link.click();
101104
};

src/components/FeedbackComponent/FeedbackForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export const FeedbackForm = function ({
207207
color="text.secondary"
208208
display="inline-block"
209209
>
210-
File types supported: JPG, PNG, Max size: 5 MB
210+
File types supported: JPG, PNG, Max size: 2 MB
211211
</Typography>
212212
<Box mt={1}>
213213
<UploadZoneWrapper
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import ToggleButton, { ToggleButtonProps } from "@mui/material/ToggleButton";
2+
import Tooltip, { TooltipProps } from "@mui/material/Tooltip";
3+
import { forwardRef, VFC } from "react";
4+
5+
type TooltipToggleButtonProps = ToggleButtonProps & {
6+
TooltipProps: Omit<TooltipProps, "children">;
7+
};
8+
9+
const TooltipToggleButton: VFC<TooltipToggleButtonProps> = forwardRef(
10+
({ TooltipProps, ...props }, ref) => {
11+
return (
12+
<Tooltip {...TooltipProps}>
13+
<ToggleButton ref={ref} {...props} />
14+
</Tooltip>
15+
);
16+
}
17+
);
18+
19+
export default TooltipToggleButton;

src/reduxes/annotation/action.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import {
1515
SET_IS_DRAGGING_VIEW_PORT,
1616
SET_KEY_DOWN_IN_EDITOR,
1717
SET_LOCK_DRAW_OBJECT,
18-
SET_MOUSE_DOWN_OUT_LAYER_POSITION,
19-
SET_MOUSE_UP_OUT_LAYER_POSITION,
2018
SET_SELECT_SHAPE,
2119
SHOW_ALL_DRAW_OBJECTS_BY_AI,
2220
SHOW_DRAW_OBJECTS_BY_AI,
@@ -37,7 +35,6 @@ import {
3735
SetKeyDownPayload,
3836
SetLockDetectedAreaPayload,
3937
SetLockDrawObecjtPayload,
40-
SetMouseOutLayerPosition,
4138
SetSelectShapePayload,
4239
ShowDrawObjectStateIdByAIPayload,
4340
UpdateDrawObjectPayload,
@@ -141,15 +138,3 @@ export const setKeyDownInEditor = (payload: SetKeyDownPayload) => ({
141138
type: SET_KEY_DOWN_IN_EDITOR,
142139
payload,
143140
});
144-
export const setMouseUpOutLayerPosition = (
145-
payload: SetMouseOutLayerPosition
146-
) => ({
147-
type: SET_MOUSE_UP_OUT_LAYER_POSITION,
148-
payload,
149-
});
150-
export const setMouseDownOutLayerPosition = (
151-
payload: SetMouseOutLayerPosition
152-
) => ({
153-
type: SET_MOUSE_DOWN_OUT_LAYER_POSITION,
154-
payload,
155-
});

src/reduxes/annotation/constants.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,3 @@ export const RECOVER_PREVIOUS_DRAWSTATE = "RECOVER_PREVIOUS_DRAWSTATE";
2121
export const SHOW_ALL_DRAW_OBJECTS_BY_AI = "SHOW_ALL_DRAW_OBJECTS_BY_AI";
2222
export const HIDDEN_ALL_DRAW_OBJECTS_BY_AI = "HIDDEN_ALL_DRAW_OBJECTS_BY_AI";
2323
export const SET_KEY_DOWN_IN_EDITOR = "SET_KEY_DOWN_IN_EDITOR";
24-
export const SET_MOUSE_UP_OUT_LAYER_POSITION =
25-
"SET_MOUSE_UP_OUT_LAYER_POSITION";
26-
export const SET_MOUSE_DOWN_OUT_LAYER_POSITION =
27-
"SET_MOUSE_DOWN_OUT_LAYER_POSITION";

src/reduxes/annotation/reducer.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PolygonSpec } from "components/Annotation/Editor/type";
2-
import { SAVE_REMOTE_NEW_CLASS_LABEL } from "reduxes/annotationmanager/constants";
2+
import { SAVE_ANNOTATION_STATE_MANAGER } from "reduxes/annotationmanager/constants";
33
import { v4 as uuidv4 } from "uuid";
44
import {
55
ADD_DRAW_OBJECTS_BY_AI,
@@ -18,8 +18,6 @@ import {
1818
SET_IS_DRAGGING_VIEW_PORT,
1919
SET_KEY_DOWN_IN_EDITOR,
2020
SET_LOCK_DRAW_OBJECT,
21-
SET_MOUSE_DOWN_OUT_LAYER_POSITION,
22-
SET_MOUSE_UP_OUT_LAYER_POSITION,
2321
SET_SELECT_SHAPE,
2422
SHOW_ALL_DRAW_OBJECTS_BY_AI,
2523
SHOW_DRAW_OBJECTS_BY_AI,
@@ -46,7 +44,6 @@ import {
4644
SetKeyDownPayload,
4745
SetLockDetectedAreaPayload,
4846
SetLockDrawObecjtPayload,
49-
SetMouseOutLayerPosition,
5047
SetSelectShapePayload,
5148
ShowDrawObjectStateIdByAIPayload,
5249
StateHistory,
@@ -104,8 +101,6 @@ const inititalState: AnnotationReducer = {
104101
isDraggingViewport: false,
105102
drawObjectStateIdByAI: {},
106103
keyDownInEditor: null,
107-
mouseUpOutLayerPosition: null,
108-
mouseDownOutLayerPosition: null,
109104
};
110105
const updateStateHistory = (
111106
drawObjectById: Record<string, DrawObject>,
@@ -370,12 +365,9 @@ const annotationReducer = (
370365
};
371366
}
372367
case SET_DETECTED_AREA: {
373-
const { detectedArea, scale } = payload as SetLockDetectedAreaPayload;
368+
const { detectedArea } = payload as SetLockDetectedAreaPayload;
374369
const newDrawObjectStateIdByAI = { ...state.drawObjectStateIdByAI };
375370
if (detectedArea) {
376-
const scaleX = 1 / scale.x;
377-
const scaleY = 1 / scale.y;
378-
379371
Object.keys(state.drawObjectStateIdByAI).forEach((drawObjectId) => {
380372
const drawObject = state.drawObjectById[drawObjectId];
381373
if (drawObject) {
@@ -384,10 +376,10 @@ const annotationReducer = (
384376
const { points } = data as PolygonSpec;
385377
const isInvalid = points.some(
386378
(point) =>
387-
point.x < detectedArea.x * scaleX ||
388-
point.y < detectedArea.y * scaleY ||
389-
point.x > (detectedArea.x + detectedArea.width) * scaleX ||
390-
point.y > (detectedArea.y + detectedArea.height) * scaleY
379+
point.x < detectedArea.x ||
380+
point.y < detectedArea.y ||
381+
point.x > detectedArea.x + detectedArea.width ||
382+
point.y > detectedArea.y + detectedArea.height
391383
);
392384
if (!isInvalid) {
393385
delete newDrawObjectStateIdByAI[drawObjectId];
@@ -461,28 +453,14 @@ const annotationReducer = (
461453
const { keyDownInEditor } = payload as SetKeyDownPayload;
462454
return { ...state, keyDownInEditor };
463455
}
464-
case SET_MOUSE_UP_OUT_LAYER_POSITION: {
465-
const { position } = payload as SetMouseOutLayerPosition;
466-
return {
467-
...state,
468-
mouseUpOutLayerPosition: position,
469-
};
470-
}
471-
case SET_MOUSE_DOWN_OUT_LAYER_POSITION: {
472-
const { position } = payload as SetMouseOutLayerPosition;
473-
return {
474-
...state,
475-
mouseDownOutLayerPosition: position,
476-
};
477-
}
478-
case SAVE_REMOTE_NEW_CLASS_LABEL.SUCCEEDED: {
456+
case SAVE_ANNOTATION_STATE_MANAGER.SUCCEEDED: {
479457
const history = state.statehHistory;
480458
return {
481459
...state,
482460
statehHistory: {
483461
...history,
484462
savedStateHistoryId:
485-
history.stateHistoryItems[history.historyStep].id,
463+
history.stateHistoryItems[history.historyStep - 1].id,
486464
},
487465
};
488466
}

0 commit comments

Comments
 (0)