lost-sia 2.0.1-alpha8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/Annotation/logic/Annotation.d.ts +17 -0
- package/dist/Annotation/logic/Annotation.js +1 -0
- package/dist/Annotation/ui/AnnotationComponent.d.ts +24 -0
- package/dist/Annotation/ui/AnnotationComponent.js +1 -0
- package/dist/Annotation/ui/atoms/AnnoBar.d.ts +15 -0
- package/dist/Annotation/ui/atoms/AnnoBar.js +1 -0
- package/dist/Annotation/ui/atoms/DaviIcon.d.ts +9 -0
- package/dist/Annotation/ui/atoms/DaviIcon.js +19 -0
- package/dist/Annotation/ui/atoms/Edge.d.ts +17 -0
- package/dist/Annotation/ui/atoms/Edge.js +1 -0
- package/dist/Annotation/ui/atoms/Node.d.ts +17 -0
- package/dist/Annotation/ui/atoms/Node.js +1 -0
- package/dist/Annotation/ui/atoms/PolygonArea.d.ts +16 -0
- package/dist/Annotation/ui/atoms/PolygonArea.js +1 -0
- package/dist/Annotation/ui/tools/BBox.d.ts +21 -0
- package/dist/Annotation/ui/tools/BBox.js +1 -0
- package/dist/Annotation/ui/tools/Line.d.ts +21 -0
- package/dist/Annotation/ui/tools/Line.js +1 -0
- package/dist/Annotation/ui/tools/Point.d.ts +16 -0
- package/dist/Annotation/ui/tools/Point.js +1 -0
- package/dist/Annotation/ui/tools/Polygon.d.ts +23 -0
- package/dist/Annotation/ui/tools/Polygon.js +1 -0
- package/dist/Canvas/Canvas.d.ts +31 -0
- package/dist/Canvas/Canvas.js +1 -0
- package/dist/Canvas/LabelInput.d.ts +11 -0
- package/dist/Canvas/LabelInput.js +1 -0
- package/dist/IconButton.d.ts +25 -0
- package/dist/IconButton.js +1 -0
- package/dist/Sia.d.ts +33 -0
- package/dist/Sia.js +1 -0
- package/dist/Toolbar/Toolbar.d.ts +21 -0
- package/dist/Toolbar/Toolbar.js +1 -0
- package/dist/Toolbar/ToolbarItems/AccessibilityTools.d.ts +7 -0
- package/dist/Toolbar/ToolbarItems/AccessibilityTools.js +1 -0
- package/dist/Toolbar/ToolbarItems/AnnoToolSelector.d.ts +11 -0
- package/dist/Toolbar/ToolbarItems/AnnoToolSelector.js +1 -0
- package/dist/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.d.ts +11 -0
- package/dist/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.js +1 -0
- package/dist/Toolbar/ToolbarItems/ImageToolItems/TagLabel.d.ts +11 -0
- package/dist/Toolbar/ToolbarItems/ImageToolItems/TagLabel.js +1 -0
- package/dist/Toolbar/ToolbarItems/ImageTools.d.ts +13 -0
- package/dist/Toolbar/ToolbarItems/ImageTools.js +1 -0
- package/dist/Toolbar/ToolbarItems/Instructions.d.ts +2 -0
- package/dist/Toolbar/ToolbarItems/Instructions.js +1 -0
- package/dist/Toolbar/ToolbarItems/InstructionsModal.d.ts +6 -0
- package/dist/Toolbar/ToolbarItems/InstructionsModal.js +1 -0
- package/dist/assets/SIA-BV1tYu3P.css +1 -0
- package/dist/assets/brand-icons-Cu_C0hZ4.svg +1008 -0
- package/dist/assets/brand-icons-F3SPCeH1.woff +0 -0
- package/dist/assets/brand-icons-XL9sxUpA.woff2 +0 -0
- package/dist/assets/brand-icons-sqJ2Pg7a.eot +0 -0
- package/dist/assets/brand-icons-ubhWoxly.ttf +0 -0
- package/dist/assets/flags-DOLqOU7Y.png +0 -0
- package/dist/assets/icons-BOCtAERH.woff +0 -0
- package/dist/assets/icons-CHzK1VD9.eot +0 -0
- package/dist/assets/icons-D29ZQHHw.ttf +0 -0
- package/dist/assets/icons-Du6TOHnR.woff2 +0 -0
- package/dist/assets/icons-RwhydX30.svg +1518 -0
- package/dist/assets/node_modules/semantic-ui-css/semantic.min-Bvulf91l.css +346 -0
- package/dist/assets/outline-icons-BfdLr8tr.svg +366 -0
- package/dist/assets/outline-icons-DD8jm0uy.ttf +0 -0
- package/dist/assets/outline-icons-DInHoiqI.woff2 +0 -0
- package/dist/assets/outline-icons-LX8adJ4n.eot +0 -0
- package/dist/assets/outline-icons-aQ88nltS.woff +0 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1 -0
- package/dist/models/AnnotationMode.d.ts +11 -0
- package/dist/models/AnnotationMode.js +1 -0
- package/dist/models/AnnotationStatus.d.ts +8 -0
- package/dist/models/AnnotationStatus.js +1 -0
- package/dist/models/AnnotationTool.d.ts +7 -0
- package/dist/models/AnnotationTool.js +1 -0
- package/dist/models/CanvasAction.d.ts +28 -0
- package/dist/models/CanvasAction.js +1 -0
- package/dist/models/Direction.d.ts +7 -0
- package/dist/models/Direction.js +1 -0
- package/dist/models/EditorModes.d.ts +11 -0
- package/dist/models/EditorModes.js +1 -0
- package/dist/models/KeyAction.d.ts +22 -0
- package/dist/models/KeyAction.js +1 -0
- package/dist/models/NotificationType.d.ts +7 -0
- package/dist/models/NotificationType.js +1 -0
- package/dist/models/index.d.ts +6 -0
- package/dist/models/index.js +1 -0
- package/dist/stories/AnnotationTools.stories.d.ts +40 -0
- package/dist/stories/Canvas/Canvas.stories.d.ts +50 -0
- package/dist/stories/Canvas/CanvasOffset.d.ts +13 -0
- package/dist/stories/Canvas/CanvasWithOffset.stories.d.ts +36 -0
- package/dist/stories/FilterDropdown.stories.d.ts +19 -0
- package/dist/stories/MinimalSia.stories.d.ts +66 -0
- package/dist/stories/SIA/DemoWrapper.d.ts +8 -0
- package/dist/stories/SIA/DemoWrapper.stories.d.ts +27 -0
- package/dist/stories/SIA/SIA.stories.d.ts +72 -0
- package/dist/stories/Toolbar/ImageTools/TagLabel.stories.d.ts +21 -0
- package/dist/stories/Toolbar/Instructions.stories.d.ts +11 -0
- package/dist/stories/Toolbar/Toolbar.stories.d.ts +37 -0
- package/dist/stories/exampleData/exampleAnnotations.d.ts +8 -0
- package/dist/stories/exampleData/exampleExternalAnnotations.d.ts +8 -0
- package/dist/stories/exampleData/exampleImage.d.ts +2 -0
- package/dist/stories/exampleData/exampleLabels.d.ts +6 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.js +1 -0
- package/dist/utils/KeyMapper.d.ts +9 -0
- package/dist/utils/KeyMapper.js +1 -0
- package/dist/utils/TimeUtils.d.ts +4 -0
- package/dist/utils/TimeUtils.js +1 -0
- package/dist/utils/color.d.ts +2 -0
- package/dist/utils/color.js +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/mouse.d.ts +6 -0
- package/dist/utils/mouse.js +1 -0
- package/dist/utils/siaIcons.js +12 -0
- package/dist/utils/transform.d.ts +28 -0
- package/dist/utils/transform.js +1 -0
- package/dist/utils/uiConfig.js +1 -0
- package/dist/utils/windowViewport.d.ts +22 -0
- package/dist/utils/windowViewport.js +1 -0
- package/package.json +19 -16
- package/src/AnnoExampleViewer.jsx +18 -18
- package/src/Annotation/logic/Annotation.ts +24 -26
- package/src/Annotation/ui/AnnotationComponent.tsx +115 -86
- package/src/Annotation/ui/atoms/AnnoBar.tsx +51 -53
- package/src/Annotation/ui/atoms/DaviIcon.tsx +12 -22
- package/src/Annotation/ui/atoms/Edge.tsx +25 -22
- package/src/Annotation/ui/atoms/Node.tsx +56 -50
- package/src/Annotation/ui/atoms/PolygonArea.tsx +30 -35
- package/src/Annotation/ui/tools/BBox.tsx +136 -150
- package/src/Annotation/ui/tools/Line.tsx +94 -91
- package/src/Annotation/ui/tools/Point.tsx +19 -17
- package/src/Annotation/ui/tools/Polygon.tsx +126 -95
- package/src/Canvas/Canvas.tsx +748 -594
- package/src/Canvas/LabelInput.tsx +68 -45
- package/src/IconButton.tsx +119 -0
- package/src/InfoBoxes/AnnoDetails.jsx +53 -53
- package/src/InfoBoxes/AnnoStats.jsx +41 -41
- package/src/InfoBoxes/InfoBox.jsx +16 -16
- package/src/InfoBoxes/InfoBoxArea.jsx +32 -34
- package/src/InfoBoxes/LabelInfo.jsx +30 -30
- package/src/SIASettingButton.jsx +25 -25
- package/src/Sia.tsx +484 -0
- package/src/Toolbar/Toolbar.tsx +38 -31
- package/src/Toolbar/ToolbarItems/AccessibilityTools.tsx +26 -46
- package/src/Toolbar/ToolbarItems/AnnoToolSelector.tsx +53 -46
- package/src/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.tsx +127 -0
- package/src/Toolbar/ToolbarItems/ImageToolItems/TagLabel.tsx +29 -28
- package/src/Toolbar/ToolbarItems/ImageTools.tsx +43 -40
- package/src/Toolbar/ToolbarItems/Instructions.tsx +47 -50
- package/src/Toolbar/ToolbarItems/InstructionsModal.tsx +8 -8
- package/src/index.ts +9 -13
- package/src/models/{AnnotationMode.tsx → AnnotationMode.ts} +1 -1
- package/src/models/{AnnotationStatus.tsx → AnnotationStatus.ts} +1 -1
- package/src/models/{AnnotationTool.tsx → AnnotationTool.ts} +1 -1
- package/src/models/{CanvasAction.tsx → CanvasAction.ts} +1 -1
- package/src/models/{Direction.tsx → Direction.ts} +1 -1
- package/src/models/{EditorModes.tsx → EditorModes.ts} +1 -1
- package/src/models/{KeyAction.tsx → KeyAction.ts} +3 -1
- package/src/models/NotificationType.ts +8 -0
- package/src/models/index.ts +6 -7
- package/src/siaDummyData.js +71 -71
- package/src/stories/AnnotationTools.mdx +27 -0
- package/src/stories/AnnotationTools.stories.tsx +104 -0
- package/src/stories/Canvas/Canvas.stories.tsx +59 -113
- package/src/stories/Canvas/CanvasOffset.tsx +54 -38
- package/src/stories/Canvas/CanvasWithOffset.stories.tsx +42 -113
- package/src/stories/FilterDropdown.stories.ts +13 -11
- package/src/stories/MinimalSIA.mdx +20 -0
- package/src/stories/MinimalSia.stories.tsx +90 -0
- package/src/stories/SIA/DemoWrapper.stories.tsx +71 -0
- package/src/stories/SIA/DemoWrapper.tsx +55 -0
- package/src/stories/SIA/SIA.stories.tsx +79 -45
- package/src/stories/Toolbar/ImageTools/TagLabel.stories.tsx +11 -12
- package/src/stories/Toolbar/Instructions.stories.tsx +11 -11
- package/src/stories/Toolbar/Toolbar.stories.tsx +32 -47
- package/src/stories/Welcome.mdx +5 -0
- package/src/stories/development/CoordinateSystems.mdx +25 -0
- package/src/stories/exampleData/exampleAnnotations.ts +65 -0
- package/src/stories/exampleData/exampleExternalAnnotations.ts +115 -0
- package/src/stories/{siaDummyData2.ts → exampleData/exampleImage.ts} +3 -264
- package/src/stories/exampleData/exampleLabels.ts +146 -0
- package/src/stories/main.scss +6 -0
- package/src/styles/style.scss +1 -26
- package/src/types.ts +67 -0
- package/src/utils/KeyMapper.ts +76 -74
- package/src/utils/TimeUtils.ts +11 -0
- package/src/utils/color.ts +25 -25
- package/src/utils/hist.js +22 -22
- package/src/utils/index.ts +2 -3
- package/src/utils/mouse.ts +45 -0
- package/src/utils/siaIcons.jsx +5 -7
- package/src/utils/transform.ts +186 -0
- package/src/utils/uiConfig.js +19 -22
- package/src/utils/windowViewport.ts +34 -0
- package/src/AnnoLabelInput.jsx +0 -109
- package/src/AnnoToolBar.jsx +0 -153
- package/src/Annotation/AnnoBar.jsx +0 -154
- package/src/Annotation/Annotation.jsx +0 -395
- package/src/Annotation/Annotation.scss +0 -47
- package/src/Annotation/BBox.jsx +0 -299
- package/src/Annotation/Edge.jsx +0 -92
- package/src/Annotation/InfSelectionArea.jsx +0 -72
- package/src/Annotation/Line.jsx +0 -68
- package/src/Annotation/Node.jsx +0 -282
- package/src/Annotation/Point.jsx +0 -200
- package/src/Annotation/Polygon.jsx +0 -404
- package/src/Annotation/logic/AnnotationUtils.ts +0 -30
- package/src/Canvas.jsx +0 -2194
- package/src/ImgBar.jsx +0 -131
- package/src/LabelInput.jsx +0 -238
- package/src/Prompt.jsx +0 -45
- package/src/SIAFilterButton.jsx +0 -186
- package/src/Sia.jsx +0 -478
- package/src/Sia2.tsx +0 -392
- package/src/SiaPopup.jsx +0 -15
- package/src/ToolBar.jsx +0 -463
- package/src/Toolbar/NavigationButtons.tsx +0 -21
- package/src/Toolbar/ToolbarItem.jsx +0 -30
- package/src/Toolbar/ToolbarItems/ImageToolItems/ImageLabel.tsx +0 -62
- package/src/Toolbar.css +0 -13
- package/src/ToolbarItem.jsx +0 -31
- package/src/filterTools.js +0 -5
- package/src/models/AllowedTools.tsx +0 -9
- package/src/models/AnnotationSettings.tsx +0 -9
- package/src/models/ExternalAnnotation.ts +0 -15
- package/src/models/Label.tsx +0 -8
- package/src/models/UiConfig.tsx +0 -6
- package/src/stories/Button.jsx +0 -54
- package/src/stories/Button.stories.js +0 -48
- package/src/stories/Header.jsx +0 -69
- package/src/stories/Header.stories.js +0 -28
- package/src/stories/Page.jsx +0 -87
- package/src/stories/Page.stories.js +0 -28
- package/src/stories/SIA2/DemoWrapper.stories.tsx +0 -167
- package/src/stories/SIA2/DemoWrapper.tsx +0 -54
- package/src/stories/SIA2/Sia2.stories.tsx +0 -62
- package/src/stories/Toolbar/ImageTools/ImageLabel.stories.tsx +0 -32
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +0 -5
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +0 -15
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +0 -3
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +0 -12
- package/src/stories/assets/youtube.svg +0 -4
- package/src/stories/button.css +0 -30
- package/src/stories/header.css +0 -32
- package/src/stories/lost.js +0 -54
- package/src/stories/page.css +0 -69
- package/src/stories/siaDummyData.js +0 -263
- package/src/stories/store.js +0 -18
- package/src/test.js +0 -7
- package/src/types/annoStatus.js +0 -4
- package/src/types/canvasActions.js +0 -58
- package/src/types/cursorstyles.js +0 -3
- package/src/types/modes.js +0 -9
- package/src/types/notificationType.js +0 -11
- package/src/types/toolbarEvents.js +0 -35
- package/src/types/tools.js +0 -17
- package/src/types.tsx +0 -11
- package/src/utils/annoConversion.js +0 -145
- package/src/utils/annoConversion2.ts +0 -145
- package/src/utils/colorlut.js +0 -68
- package/src/utils/constraints.js +0 -81
- package/src/utils/index.js +0 -1
- package/src/utils/keyActions.js +0 -113
- package/src/utils/mouse.js +0 -14
- package/src/utils/mouse2.ts +0 -35
- package/src/utils/transform.js +0 -336
- package/src/utils/transform2.ts +0 -343
- package/src/utils/windowViewport.js +0 -34
- package/src/utils/windowViewport2.ts +0 -50
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { CSSProperties, useEffect, useRef, useState } from
|
|
1
|
+
import { CSSProperties, MouseEvent, useEffect, useRef, useState } from 'react'
|
|
2
2
|
|
|
3
3
|
// rename type to avoid naming conflict
|
|
4
|
-
import { Point } from
|
|
5
|
-
import Node from
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import Edge from "../atoms/Edge";
|
|
4
|
+
import { AnnotationSettings, Point } from '../../../types'
|
|
5
|
+
import Node from '../atoms/Node'
|
|
6
|
+
import AnnotationMode from '../../../models/AnnotationMode'
|
|
7
|
+
import mouse from '../../../utils/mouse'
|
|
8
|
+
import PolygonArea from '../atoms/PolygonArea'
|
|
9
|
+
import Edge from '../atoms/Edge'
|
|
11
10
|
|
|
12
11
|
type BBoxProps = {
|
|
13
|
-
annotationMode: AnnotationMode
|
|
14
|
-
annotationSettings: AnnotationSettings
|
|
15
|
-
pageToStageOffset: Point
|
|
16
|
-
startCoords: Point
|
|
17
|
-
endCoords: Point
|
|
18
|
-
svgScale: number
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
annotationMode: AnnotationMode
|
|
13
|
+
annotationSettings: AnnotationSettings
|
|
14
|
+
pageToStageOffset: Point
|
|
15
|
+
startCoords: Point
|
|
16
|
+
endCoords: Point
|
|
17
|
+
svgScale: number
|
|
18
|
+
svgTranslation: Point
|
|
19
|
+
isSelected: boolean
|
|
20
|
+
style: CSSProperties
|
|
21
|
+
onDeleteNode: (coordinates: Point[]) => void
|
|
22
|
+
onFinishAnnoCreate: () => void
|
|
23
|
+
onIsDraggingStateChanged: (newDraggingState: boolean) => void
|
|
24
|
+
onMoving: (coordinates: Point[]) => void // during moving - update coordinates in parent
|
|
25
|
+
onMoved: () => void // moving finished - send annotation changed event
|
|
26
|
+
}
|
|
27
27
|
|
|
28
28
|
const BBox = ({
|
|
29
29
|
annotationMode,
|
|
@@ -32,6 +32,7 @@ const BBox = ({
|
|
|
32
32
|
startCoords,
|
|
33
33
|
endCoords,
|
|
34
34
|
svgScale,
|
|
35
|
+
svgTranslation,
|
|
35
36
|
isSelected,
|
|
36
37
|
style,
|
|
37
38
|
onDeleteNode,
|
|
@@ -46,143 +47,132 @@ const BBox = ({
|
|
|
46
47
|
{ x: startCoords.x, y: endCoords.y },
|
|
47
48
|
endCoords,
|
|
48
49
|
{ x: endCoords.x, y: startCoords.y },
|
|
49
|
-
]
|
|
50
|
+
]
|
|
50
51
|
|
|
51
52
|
const [isAnnoCreating, setIsAnnoCreating] = useState<boolean>(
|
|
52
53
|
annotationMode === AnnotationMode.CREATE,
|
|
53
|
-
)
|
|
54
|
-
const [isAnnoDragging, setIsAnnoDragging] = useState<boolean>(false)
|
|
55
|
-
const [isEdgeDragging, setIsEdgeDragging] = useState<boolean>(false)
|
|
56
|
-
const [dragSelectedEdgeIndex, setDragSelectedEdgeIndex] = useState<number>(0)
|
|
54
|
+
)
|
|
55
|
+
const [isAnnoDragging, setIsAnnoDragging] = useState<boolean>(false)
|
|
56
|
+
const [isEdgeDragging, setIsEdgeDragging] = useState<boolean>(false)
|
|
57
|
+
const [dragSelectedEdgeIndex, setDragSelectedEdgeIndex] = useState<number>(0)
|
|
57
58
|
|
|
58
59
|
// onMove and onMouseUp events are fired in the same frame
|
|
59
60
|
// use a ref to access the updated value without waiting until the next frame
|
|
60
|
-
const [didAnnoActuallyMove, setDidAnnoActuallyMove] =
|
|
61
|
-
|
|
62
|
-
const didAnnoActuallyMoveRef = useRef<boolean>(didAnnoActuallyMove);
|
|
61
|
+
const [didAnnoActuallyMove, setDidAnnoActuallyMove] = useState<boolean>(false)
|
|
62
|
+
const didAnnoActuallyMoveRef = useRef<boolean>(didAnnoActuallyMove)
|
|
63
63
|
|
|
64
64
|
useEffect(() => {
|
|
65
|
-
didAnnoActuallyMoveRef.current = didAnnoActuallyMove
|
|
66
|
-
}, [didAnnoActuallyMove])
|
|
65
|
+
didAnnoActuallyMoveRef.current = didAnnoActuallyMove
|
|
66
|
+
}, [didAnnoActuallyMove])
|
|
67
67
|
|
|
68
68
|
const onMouseDown = (e: MouseEvent) => {
|
|
69
|
-
if (annotationSettings.canEdit === false) return
|
|
69
|
+
if (annotationSettings.canEdit === false) return
|
|
70
70
|
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
e.button === 0
|
|
75
|
-
)
|
|
76
|
-
setIsAnnoDragging(true);
|
|
77
|
-
};
|
|
71
|
+
if (isSelected && annotationMode !== AnnotationMode.CREATE && e.button === 0)
|
|
72
|
+
setIsAnnoDragging(true)
|
|
73
|
+
}
|
|
78
74
|
|
|
79
75
|
const onMouseEdgeDown = (e: MouseEvent) => {
|
|
80
|
-
if (annotationSettings.canEdit === false) return
|
|
76
|
+
if (annotationSettings.canEdit === false) return
|
|
81
77
|
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
e.button === 0
|
|
86
|
-
)
|
|
87
|
-
setIsEdgeDragging(true);
|
|
88
|
-
};
|
|
78
|
+
if (isSelected && annotationMode !== AnnotationMode.CREATE && e.button === 0)
|
|
79
|
+
setIsEdgeDragging(true)
|
|
80
|
+
}
|
|
89
81
|
|
|
90
82
|
const onMouseMove = (e: MouseEvent) => {
|
|
91
83
|
if (isAnnoDragging) {
|
|
92
84
|
// we always get 4 coordinates (the rectangle corners)
|
|
93
85
|
// only the top left and bottom right corner are important - other coordinates are redundant
|
|
94
|
-
const newRectangle: Point[] = [
|
|
95
|
-
{ ...coordinates[0] },
|
|
96
|
-
{ ...coordinates[2] },
|
|
97
|
-
];
|
|
86
|
+
const newRectangle: Point[] = [{ ...coordinates[0] }, { ...coordinates[2] }]
|
|
98
87
|
|
|
99
88
|
// apply mouse move to the rectangle coordinates
|
|
100
|
-
const movedCoordinates: Point[] = newRectangle.map(
|
|
101
|
-
(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
)
|
|
89
|
+
const movedCoordinates: Point[] = newRectangle.map((coordinate: Point) => {
|
|
90
|
+
// counter the canvas scaling (it will be automatically applied when rendering the annotation coordinates)
|
|
91
|
+
const newX = (coordinate.x += e.movementX / svgScale)
|
|
92
|
+
const newY = (coordinate.y += e.movementY / svgScale)
|
|
93
|
+
return {
|
|
94
|
+
x: newX,
|
|
95
|
+
y: newY,
|
|
96
|
+
}
|
|
97
|
+
})
|
|
109
98
|
|
|
110
99
|
// only escalate event when mouse actually moved
|
|
111
100
|
if (e.movementX !== 0 || e.movementY !== 0) {
|
|
112
|
-
setDidAnnoActuallyMove(true)
|
|
113
|
-
onMoving(movedCoordinates)
|
|
101
|
+
setDidAnnoActuallyMove(true)
|
|
102
|
+
onMoving(movedCoordinates)
|
|
114
103
|
}
|
|
115
104
|
}
|
|
116
105
|
|
|
117
106
|
if (annotationMode === AnnotationMode.CREATE) {
|
|
118
|
-
const mousePointInStage =
|
|
107
|
+
const mousePointInStage = mouse.getAntiScaledMouseStagePosition(
|
|
119
108
|
e,
|
|
120
109
|
pageToStageOffset,
|
|
121
110
|
svgScale,
|
|
122
|
-
|
|
111
|
+
svgTranslation,
|
|
112
|
+
)
|
|
123
113
|
|
|
124
|
-
|
|
114
|
+
const newCoords: Point[] = [...coordinates]
|
|
125
115
|
|
|
126
116
|
// we always get 4 coordinates (the rectangle corners)
|
|
127
117
|
// only the top left (start) is important - the end will be our mouse position and the others are redundant
|
|
128
|
-
const newRectangle: Point[] = [newCoords[0], mousePointInStage]
|
|
118
|
+
const newRectangle: Point[] = [newCoords[0], mousePointInStage]
|
|
129
119
|
|
|
130
|
-
onMoving(newRectangle)
|
|
120
|
+
onMoving(newRectangle)
|
|
131
121
|
}
|
|
132
|
-
}
|
|
122
|
+
}
|
|
133
123
|
|
|
134
124
|
useEffect(() => {
|
|
135
|
-
if (!isAnnoCreating) return
|
|
125
|
+
if (!isAnnoCreating) return
|
|
136
126
|
|
|
137
|
-
const handleMouseUp = (e: MouseEvent) => {
|
|
127
|
+
const handleMouseUp = (e: globalThis.MouseEvent) => {
|
|
138
128
|
if (e.button === 2) {
|
|
139
|
-
onFinishAnnoCreate()
|
|
140
|
-
setIsAnnoCreating(false)
|
|
129
|
+
onFinishAnnoCreate()
|
|
130
|
+
setIsAnnoCreating(false)
|
|
141
131
|
}
|
|
142
|
-
}
|
|
132
|
+
}
|
|
143
133
|
|
|
144
|
-
|
|
134
|
+
globalThis.addEventListener('mouseup', handleMouseUp)
|
|
145
135
|
|
|
146
136
|
return () => {
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
}, [isAnnoCreating])
|
|
137
|
+
globalThis.removeEventListener('mouseup', handleMouseUp)
|
|
138
|
+
}
|
|
139
|
+
}, [isAnnoCreating])
|
|
150
140
|
|
|
151
141
|
useEffect(() => {
|
|
152
|
-
onIsDraggingStateChanged(isAnnoDragging)
|
|
153
|
-
if (!isAnnoDragging) return
|
|
142
|
+
onIsDraggingStateChanged(isAnnoDragging)
|
|
143
|
+
if (!isAnnoDragging) return
|
|
154
144
|
|
|
155
145
|
const handleMouseUp = () => {
|
|
156
|
-
setIsAnnoDragging(false)
|
|
146
|
+
setIsAnnoDragging(false)
|
|
157
147
|
|
|
158
|
-
if (didAnnoActuallyMoveRef.current) onMoved()
|
|
159
|
-
setDidAnnoActuallyMove(false)
|
|
160
|
-
}
|
|
148
|
+
if (didAnnoActuallyMoveRef.current) onMoved()
|
|
149
|
+
setDidAnnoActuallyMove(false)
|
|
150
|
+
}
|
|
161
151
|
|
|
162
|
-
|
|
152
|
+
globalThis.addEventListener('mouseup', handleMouseUp)
|
|
163
153
|
|
|
164
154
|
return () => {
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
}, [isAnnoDragging])
|
|
155
|
+
globalThis.removeEventListener('mouseup', handleMouseUp)
|
|
156
|
+
}
|
|
157
|
+
}, [isAnnoDragging])
|
|
168
158
|
|
|
169
159
|
useEffect(() => {
|
|
170
|
-
onIsDraggingStateChanged(isEdgeDragging)
|
|
171
|
-
if (!isEdgeDragging) return
|
|
160
|
+
onIsDraggingStateChanged(isEdgeDragging)
|
|
161
|
+
if (!isEdgeDragging) return
|
|
172
162
|
|
|
173
163
|
const handleMouseUp = () => {
|
|
174
|
-
setIsEdgeDragging(false)
|
|
164
|
+
setIsEdgeDragging(false)
|
|
175
165
|
|
|
176
|
-
if (didAnnoActuallyMoveRef.current) onMoved()
|
|
177
|
-
setDidAnnoActuallyMove(false)
|
|
178
|
-
}
|
|
166
|
+
if (didAnnoActuallyMoveRef.current) onMoved()
|
|
167
|
+
setDidAnnoActuallyMove(false)
|
|
168
|
+
}
|
|
179
169
|
|
|
180
|
-
|
|
170
|
+
globalThis.addEventListener('mouseup', handleMouseUp)
|
|
181
171
|
|
|
182
172
|
return () => {
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
}, [isEdgeDragging])
|
|
173
|
+
globalThis.removeEventListener('mouseup', handleMouseUp)
|
|
174
|
+
}
|
|
175
|
+
}, [isEdgeDragging])
|
|
186
176
|
|
|
187
177
|
const renderNodes = () => {
|
|
188
178
|
const svgNodes = coordinates.map((coordinate: Point, index: number) => (
|
|
@@ -193,80 +183,79 @@ const BBox = ({
|
|
|
193
183
|
coordinates={coordinate}
|
|
194
184
|
pageToStageOffset={pageToStageOffset}
|
|
195
185
|
svgScale={svgScale}
|
|
186
|
+
svgTranslation={svgTranslation}
|
|
196
187
|
style={style}
|
|
197
188
|
onDeleteNode={() => {
|
|
198
|
-
const newCoordinates = [...coordinates]
|
|
199
|
-
newCoordinates.splice(index, 1)
|
|
200
|
-
onDeleteNode(newCoordinates)
|
|
189
|
+
const newCoordinates = [...coordinates]
|
|
190
|
+
newCoordinates.splice(index, 1)
|
|
191
|
+
onDeleteNode(newCoordinates)
|
|
201
192
|
}}
|
|
202
193
|
onMoving={(index: number, newPoint: Point) => {
|
|
203
194
|
// we always get 4 coordinates (the rectangle corners)
|
|
204
195
|
// only the top left and bottom right corner are important - other coordinates are redundant
|
|
205
|
-
const newRectangle: Point[] = [coordinates[0], coordinates[2]]
|
|
196
|
+
const newRectangle: Point[] = [coordinates[0], coordinates[2]]
|
|
206
197
|
|
|
207
198
|
// update start + end coordinates depending on which corner is moved
|
|
208
199
|
switch (index) {
|
|
209
200
|
case 0: // top left corner
|
|
210
|
-
newRectangle[0] = newPoint
|
|
211
|
-
break
|
|
201
|
+
newRectangle[0] = newPoint
|
|
202
|
+
break
|
|
212
203
|
case 1: // bottom left corner
|
|
213
|
-
newRectangle[0].x = newPoint.x
|
|
214
|
-
newRectangle[1].y = newPoint.y
|
|
215
|
-
break
|
|
204
|
+
newRectangle[0].x = newPoint.x
|
|
205
|
+
newRectangle[1].y = newPoint.y
|
|
206
|
+
break
|
|
216
207
|
case 2: // bottom right corner
|
|
217
|
-
newRectangle[1] = newPoint
|
|
218
|
-
break
|
|
208
|
+
newRectangle[1] = newPoint
|
|
209
|
+
break
|
|
219
210
|
case 3: // top right corner
|
|
220
|
-
newRectangle[1].x = newPoint.x
|
|
221
|
-
newRectangle[0].y = newPoint.y
|
|
222
|
-
break
|
|
211
|
+
newRectangle[1].x = newPoint.x
|
|
212
|
+
newRectangle[0].y = newPoint.y
|
|
213
|
+
break
|
|
223
214
|
}
|
|
224
215
|
|
|
225
|
-
onMoving(newRectangle)
|
|
216
|
+
onMoving(newRectangle)
|
|
226
217
|
}}
|
|
227
218
|
onMoved={() => onMoved()}
|
|
228
219
|
onIsDraggingStateChanged={onIsDraggingStateChanged}
|
|
229
220
|
/>
|
|
230
|
-
))
|
|
221
|
+
))
|
|
231
222
|
|
|
232
|
-
return svgNodes
|
|
233
|
-
}
|
|
223
|
+
return svgNodes
|
|
224
|
+
}
|
|
234
225
|
|
|
235
226
|
const moveEdge = (edgeIndex: number, e: MouseEvent) => {
|
|
236
227
|
// we always get 4 coordinates (the rectangle corners)
|
|
237
228
|
// only the top left and bottom right corner are important - other coordinates are redundant
|
|
238
|
-
const newRectangle: Point[] = [coordinates[0], coordinates[2]]
|
|
229
|
+
const newRectangle: Point[] = [coordinates[0], coordinates[2]]
|
|
239
230
|
switch (edgeIndex) {
|
|
240
231
|
case 0:
|
|
241
|
-
newRectangle[0].x += e.movementX / svgScale
|
|
242
|
-
break
|
|
232
|
+
newRectangle[0].x += e.movementX / svgScale
|
|
233
|
+
break
|
|
243
234
|
case 1:
|
|
244
|
-
newRectangle[1].y += e.movementY / svgScale
|
|
245
|
-
break
|
|
235
|
+
newRectangle[1].y += e.movementY / svgScale
|
|
236
|
+
break
|
|
246
237
|
case 2:
|
|
247
|
-
newRectangle[1].x += e.movementX / svgScale
|
|
248
|
-
break
|
|
238
|
+
newRectangle[1].x += e.movementX / svgScale
|
|
239
|
+
break
|
|
249
240
|
case 3:
|
|
250
|
-
newRectangle[0].y += e.movementY / svgScale
|
|
251
|
-
break
|
|
241
|
+
newRectangle[0].y += e.movementY / svgScale
|
|
242
|
+
break
|
|
252
243
|
}
|
|
253
244
|
|
|
254
245
|
// only escalate event when mouse actually moved
|
|
255
246
|
if (e.movementX !== 0 || e.movementY !== 0) {
|
|
256
|
-
setDidAnnoActuallyMove(true)
|
|
257
|
-
onMoving(newRectangle)
|
|
247
|
+
setDidAnnoActuallyMove(true)
|
|
248
|
+
onMoving(newRectangle)
|
|
258
249
|
}
|
|
259
|
-
}
|
|
250
|
+
}
|
|
260
251
|
|
|
261
252
|
const renderEdges = () => {
|
|
262
253
|
const svgEdges = coordinates.map((coordinate: Point, index: number) => {
|
|
263
254
|
const endCoordinates: Point =
|
|
264
|
-
index + 1 < coordinates.length
|
|
265
|
-
? coordinates[index + 1]
|
|
266
|
-
: coordinates[0];
|
|
255
|
+
index + 1 < coordinates.length ? coordinates[index + 1] : coordinates[0]
|
|
267
256
|
|
|
268
257
|
// corresponding cursor for horizontal or vertical edges
|
|
269
|
-
const cursor = index % 2 === 0 ?
|
|
258
|
+
const cursor = index % 2 === 0 ? 'ew-resize' : 'ns-resize'
|
|
270
259
|
|
|
271
260
|
return (
|
|
272
261
|
<Edge
|
|
@@ -275,48 +264,45 @@ const BBox = ({
|
|
|
275
264
|
endCoordinate={endCoordinates}
|
|
276
265
|
pageToStageOffset={pageToStageOffset}
|
|
277
266
|
svgScale={svgScale}
|
|
267
|
+
svgTranslation={svgTranslation}
|
|
278
268
|
style={{ ...style, cursor }}
|
|
279
269
|
onMouseDown={onMouseEdgeDown}
|
|
280
270
|
onMouseMove={(e: MouseEvent) => {
|
|
281
|
-
setDragSelectedEdgeIndex(index)
|
|
282
|
-
isEdgeDragging
|
|
271
|
+
setDragSelectedEdgeIndex(index)
|
|
272
|
+
if (isEdgeDragging) moveEdge(index, e)
|
|
283
273
|
}}
|
|
284
274
|
/>
|
|
285
|
-
)
|
|
286
|
-
})
|
|
287
|
-
return svgEdges
|
|
288
|
-
}
|
|
275
|
+
)
|
|
276
|
+
})
|
|
277
|
+
return svgEdges
|
|
278
|
+
}
|
|
289
279
|
|
|
290
280
|
const renderInfiniteSelectionArea = (isForEdge: boolean) => {
|
|
291
281
|
return (
|
|
292
282
|
<circle
|
|
293
283
|
cx={coordinates[0].x}
|
|
294
284
|
cy={coordinates[0].y}
|
|
295
|
-
r={
|
|
285
|
+
r={'100%'}
|
|
296
286
|
style={{ opacity: 0 }}
|
|
297
287
|
onMouseDown={onMouseDown}
|
|
298
288
|
onMouseMove={(e: MouseEvent) => {
|
|
299
|
-
isForEdge && isEdgeDragging
|
|
300
|
-
!isForEdge
|
|
289
|
+
if (isForEdge && isEdgeDragging) moveEdge(dragSelectedEdgeIndex, e)
|
|
290
|
+
if (!isForEdge) onMouseMove(e)
|
|
301
291
|
}}
|
|
302
292
|
onContextMenu={(e) => e.preventDefault()}
|
|
303
293
|
/>
|
|
304
|
-
)
|
|
305
|
-
}
|
|
294
|
+
)
|
|
295
|
+
}
|
|
306
296
|
|
|
307
297
|
return (
|
|
308
298
|
<g>
|
|
309
299
|
{(isAnnoDragging || annotationMode === AnnotationMode.CREATE) &&
|
|
310
300
|
renderInfiniteSelectionArea(false)}
|
|
311
301
|
<PolygonArea
|
|
312
|
-
annotationSettings={annotationSettings}
|
|
313
302
|
coordinates={coordinates}
|
|
314
303
|
isSelected={isSelected}
|
|
315
304
|
annotationMode={annotationMode}
|
|
316
|
-
pageToStageOffset={pageToStageOffset}
|
|
317
305
|
style={style}
|
|
318
|
-
svgScale={svgScale}
|
|
319
|
-
onIsDraggingStateChanged={onIsDraggingStateChanged}
|
|
320
306
|
onMouseDown={onMouseDown}
|
|
321
307
|
onMouseMove={onMouseMove}
|
|
322
308
|
/>
|
|
@@ -324,7 +310,7 @@ const BBox = ({
|
|
|
324
310
|
{isSelected && annotationSettings.canEdit && renderEdges()}
|
|
325
311
|
{isSelected && annotationMode !== AnnotationMode.CREATE && renderNodes()}
|
|
326
312
|
</g>
|
|
327
|
-
)
|
|
328
|
-
}
|
|
313
|
+
)
|
|
314
|
+
}
|
|
329
315
|
|
|
330
|
-
export default BBox
|
|
316
|
+
export default BBox
|