lost-sia 2.0.1-alpha12 → 2.0.1-alpha13
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/dist/Annotation/ui/atoms/AnnoBar.js +1 -1
- package/dist/Annotation/ui/atoms/Edge.js +1 -1
- package/dist/Annotation/ui/atoms/Node.js +1 -1
- package/dist/Annotation/ui/tools/BBox.js +1 -1
- package/dist/Annotation/ui/tools/Line.js +1 -1
- package/dist/Annotation/ui/tools/Polygon.js +1 -1
- package/dist/Canvas/Canvas.d.ts +2 -1
- package/dist/Canvas/Canvas.js +1 -1
- package/dist/Sia.js +1 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.js +1 -1
- package/dist/models/KeyAction.d.ts +2 -1
- package/dist/models/KeyAction.js +1 -1
- package/dist/stories/Canvas/Canvas.stories.d.ts +2 -1
- package/dist/utils/KeyMapper.js +1 -1
- package/dist/utils/mouse.js +1 -1
- package/dist/utils/siaIcons.js +5 -5
- package/dist/utils/transform.js +1 -1
- package/dist/utils/windowViewport.d.ts +22 -0
- package/dist/utils/windowViewport.js +1 -1
- package/package.json +9 -8
- package/src/Annotation/ui/atoms/AnnoBar.tsx +46 -46
- package/src/Annotation/ui/atoms/Edge.tsx +23 -23
- package/src/Annotation/ui/atoms/Node.tsx +51 -51
- package/src/Annotation/ui/tools/BBox.tsx +129 -145
- package/src/Annotation/ui/tools/Line.tsx +81 -87
- package/src/Annotation/ui/tools/Polygon.tsx +92 -95
- package/src/Canvas/Canvas.tsx +369 -397
- package/src/InfoBoxes/AnnoStats.jsx +1 -1
- package/src/InfoBoxes/InfoBoxArea.jsx +32 -34
- package/src/{Sia2.tsx → Sia.tsx} +156 -175
- package/src/index.ts +6 -17
- package/src/models/KeyAction.ts +1 -0
- package/src/stories/AnnotationTools.stories.tsx +21 -21
- package/src/stories/Canvas/Canvas.stories.tsx +31 -26
- package/src/stories/Canvas/CanvasOffset.tsx +23 -25
- package/src/stories/MinimalSia.stories.tsx +22 -22
- package/src/stories/SIA2/DemoWrapper.tsx +20 -24
- package/src/stories/SIA2/Sia2.stories.tsx +24 -24
- package/src/utils/KeyMapper.ts +3 -0
- package/src/utils/siaIcons.jsx +5 -7
- package/src/utils/windowViewport.ts +34 -0
- package/dist/AnnoExampleViewer.js +0 -1
- package/dist/AnnoLabelInput.js +0 -1
- package/dist/AnnoToolBar.js +0 -19
- package/dist/Annotation/AnnoBar.js +0 -1
- package/dist/Annotation/Annotation.js +0 -1
- package/dist/Annotation/BBox.js +0 -1
- package/dist/Annotation/Edge.js +0 -1
- package/dist/Annotation/InfSelectionArea.js +0 -1
- package/dist/Annotation/Line.js +0 -1
- package/dist/Annotation/Node.js +0 -1
- package/dist/Annotation/Point.js +0 -1
- package/dist/Annotation/Polygon.js +0 -1
- package/dist/Canvas.js +0 -1
- package/dist/ImgBar.js +0 -1
- package/dist/InfoBoxes/AnnoDetails.js +0 -1
- package/dist/InfoBoxes/AnnoStats.js +0 -1
- package/dist/InfoBoxes/InfoBox.js +0 -1
- package/dist/InfoBoxes/InfoBoxArea.js +0 -1
- package/dist/InfoBoxes/LabelInfo.js +0 -1
- package/dist/LabelInput.js +0 -1
- package/dist/Prompt.js +0 -1
- package/dist/SIAFilterButton.js +0 -1
- package/dist/SIASettingButton.js +0 -1
- package/dist/Sia2.js +0 -1
- package/dist/SiaPopup.js +0 -1
- package/dist/ToolBar.js +0 -1
- package/dist/ToolbarItem.js +0 -1
- package/dist/_virtual/_commonjsHelpers.js +0 -1
- package/dist/_virtual/lodash.js +0 -1
- package/dist/assets/Annotation/Annotation-Cd5Ua5TG.css +0 -1
- package/dist/assets/Toolbar-Cp1xyYeH.css +0 -1
- package/dist/filterTools.js +0 -1
- package/dist/siaDummyData.js +0 -7
- package/dist/stories/Canvas/CanvasOffset.js +0 -1
- package/dist/stories/FilterDropdown.stories.js +0 -1
- package/dist/stories/SIA/SIA.stories.d.ts +0 -36
- package/dist/stories/SIA2/DemoWrapper.js +0 -1
- package/dist/stories/Toolbar/ImageTools/ImageLabel.stories.d.ts +0 -13
- package/dist/stories/siaDummyData.js +0 -1
- package/dist/stories/siaDummyData2.js +0 -7
- package/dist/types/annoStatus.js +0 -1
- package/dist/types/canvasActions.js +0 -1
- package/dist/types/cursorstyles.js +0 -1
- package/dist/types/modes.js +0 -1
- package/dist/types/notificationType.js +0 -1
- package/dist/types/toolbarEvents.js +0 -1
- package/dist/types/tools.js +0 -1
- package/dist/utils/annoConversion.js +0 -1
- package/dist/utils/annoConversion2.d.ts +0 -27
- package/dist/utils/annoConversion2.js +0 -1
- package/dist/utils/colorlut.js +0 -1
- package/dist/utils/constraints.js +0 -1
- package/dist/utils/hist.js +0 -1
- package/dist/utils/keyActions.js +0 -1
- package/dist/utils/mouse2.js +0 -1
- package/dist/utils/transform2.js +0 -1
- 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/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/SiaPopup.jsx +0 -15
- package/src/ToolBar.jsx +0 -463
- package/src/Toolbar/ToolbarItem.jsx +0 -30
- package/src/Toolbar.css +0 -13
- package/src/ToolbarItem.jsx +0 -31
- package/src/filterTools.js +0 -5
- package/src/stories/SIA/SIA.stories.tsx +0 -64
- package/src/stories/Toolbar/ImageTools/ImageLabel.stories.tsx +0 -31
- package/src/stories/lost.js +0 -54
- 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/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/mouse.js +0 -14
- package/src/utils/transform.js +0 -336
- package/src/utils/windowViewport.js +0 -34
- /package/dist/{Sia2.d.ts → Sia.d.ts} +0 -0
- /package/dist/utils/{mouse2.d.ts → mouse.d.ts} +0 -0
- /package/dist/utils/{transform2.d.ts → transform.d.ts} +0 -0
- /package/src/utils/{mouse2.ts → mouse.ts} +0 -0
- /package/src/utils/{transform2.ts → transform.ts} +0 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { CSSProperties, MouseEvent, useEffect, useRef, useState } from
|
|
2
|
-
import { Point } from
|
|
3
|
-
import
|
|
4
|
-
import { AnnotationSettings } from
|
|
1
|
+
import { CSSProperties, MouseEvent, useEffect, useRef, useState } from 'react'
|
|
2
|
+
import { Point } from '../../../types'
|
|
3
|
+
import mouse from '../../../utils/mouse'
|
|
4
|
+
import { AnnotationSettings } from '../../../types'
|
|
5
5
|
|
|
6
6
|
type NodeProps = {
|
|
7
|
-
index: number
|
|
8
|
-
coordinates: Point
|
|
9
|
-
annotationSettings: AnnotationSettings
|
|
10
|
-
pageToStageOffset: Point
|
|
11
|
-
svgScale: number
|
|
12
|
-
svgTranslation: Point
|
|
13
|
-
style: CSSProperties
|
|
14
|
-
onDeleteNode: () => void
|
|
15
|
-
onMoving: (index: number, coordinates: Point) => void
|
|
16
|
-
onMoved: () => void
|
|
17
|
-
onIsDraggingStateChanged: (bool) => void
|
|
18
|
-
}
|
|
7
|
+
index: number
|
|
8
|
+
coordinates: Point
|
|
9
|
+
annotationSettings: AnnotationSettings
|
|
10
|
+
pageToStageOffset: Point
|
|
11
|
+
svgScale: number
|
|
12
|
+
svgTranslation: Point
|
|
13
|
+
style: CSSProperties
|
|
14
|
+
onDeleteNode: () => void
|
|
15
|
+
onMoving: (index: number, coordinates: Point) => void
|
|
16
|
+
onMoved: () => void
|
|
17
|
+
onIsDraggingStateChanged: (bool) => void
|
|
18
|
+
}
|
|
19
19
|
|
|
20
20
|
const Node = ({
|
|
21
21
|
index,
|
|
@@ -30,59 +30,59 @@ const Node = ({
|
|
|
30
30
|
onMoved, // moving finished - send annotation changed event
|
|
31
31
|
onIsDraggingStateChanged,
|
|
32
32
|
}: NodeProps) => {
|
|
33
|
-
const [hasHalo, setHasHalo] = useState<boolean>(false)
|
|
34
|
-
const [isDragging, setIsDragging] = useState<boolean>(false)
|
|
33
|
+
const [hasHalo, setHasHalo] = useState<boolean>(false)
|
|
34
|
+
const [isDragging, setIsDragging] = useState<boolean>(false)
|
|
35
35
|
|
|
36
36
|
// onMove and onMouseUp events are fired in the same frame
|
|
37
37
|
// use a ref to access the updated value without waiting until the next frame
|
|
38
|
-
const [didItActuallyMove, setDidItActuallyMove] = useState<boolean>(false)
|
|
39
|
-
const didItActuallyMoveRef = useRef<boolean>(didItActuallyMove)
|
|
38
|
+
const [didItActuallyMove, setDidItActuallyMove] = useState<boolean>(false)
|
|
39
|
+
const didItActuallyMoveRef = useRef<boolean>(didItActuallyMove)
|
|
40
40
|
|
|
41
41
|
useEffect(() => {
|
|
42
|
-
didItActuallyMoveRef.current = didItActuallyMove
|
|
43
|
-
}, [didItActuallyMove])
|
|
42
|
+
didItActuallyMoveRef.current = didItActuallyMove
|
|
43
|
+
}, [didItActuallyMove])
|
|
44
44
|
|
|
45
45
|
const onMouseMove = (e: MouseEvent) => {
|
|
46
|
-
if (!isDragging) return
|
|
46
|
+
if (!isDragging) return
|
|
47
47
|
|
|
48
48
|
const antiScaledMousePositionInStageCoordinates =
|
|
49
|
-
|
|
49
|
+
mouse.getAntiScaledMouseStagePosition(
|
|
50
50
|
e,
|
|
51
51
|
pageToStageOffset,
|
|
52
52
|
svgScale,
|
|
53
53
|
svgTranslation,
|
|
54
|
-
)
|
|
54
|
+
)
|
|
55
55
|
|
|
56
56
|
// only escalate event when mouse actually moved
|
|
57
57
|
if (e.movementX !== 0 || e.movementY !== 0) {
|
|
58
|
-
setDidItActuallyMove(true)
|
|
59
|
-
onMoving(index, antiScaledMousePositionInStageCoordinates)
|
|
58
|
+
setDidItActuallyMove(true)
|
|
59
|
+
onMoving(index, antiScaledMousePositionInStageCoordinates)
|
|
60
60
|
}
|
|
61
|
-
}
|
|
61
|
+
}
|
|
62
62
|
|
|
63
63
|
useEffect(() => {
|
|
64
|
-
onIsDraggingStateChanged(isDragging)
|
|
65
|
-
if (!isDragging) return
|
|
64
|
+
onIsDraggingStateChanged(isDragging)
|
|
65
|
+
if (!isDragging) return
|
|
66
66
|
|
|
67
67
|
const handleMouseUp = () => {
|
|
68
|
-
setIsDragging(false)
|
|
69
|
-
if (didItActuallyMoveRef.current) onMoved()
|
|
70
|
-
setDidItActuallyMove(false)
|
|
71
|
-
}
|
|
68
|
+
setIsDragging(false)
|
|
69
|
+
if (didItActuallyMoveRef.current) onMoved()
|
|
70
|
+
setDidItActuallyMove(false)
|
|
71
|
+
}
|
|
72
72
|
|
|
73
|
-
window.addEventListener(
|
|
73
|
+
window.addEventListener('mouseup', handleMouseUp)
|
|
74
74
|
|
|
75
75
|
return () => {
|
|
76
|
-
window.removeEventListener(
|
|
77
|
-
}
|
|
78
|
-
}, [isDragging])
|
|
76
|
+
window.removeEventListener('mouseup', handleMouseUp)
|
|
77
|
+
}
|
|
78
|
+
}, [isDragging])
|
|
79
79
|
|
|
80
80
|
const onMouseDown = (e: MouseEvent) => {
|
|
81
|
-
if (!annotationSettings.canEdit) return
|
|
81
|
+
if (!annotationSettings.canEdit) return
|
|
82
82
|
|
|
83
|
-
if (e.ctrlKey) onDeleteNode()
|
|
84
|
-
else setIsDragging(true)
|
|
85
|
-
}
|
|
83
|
+
if (e.ctrlKey) onDeleteNode()
|
|
84
|
+
else setIsDragging(true)
|
|
85
|
+
}
|
|
86
86
|
|
|
87
87
|
const renderHalo = () => {
|
|
88
88
|
return (
|
|
@@ -94,21 +94,21 @@ const Node = ({
|
|
|
94
94
|
onMouseDown={onMouseDown}
|
|
95
95
|
onContextMenu={(e) => e.preventDefault()}
|
|
96
96
|
/>
|
|
97
|
-
)
|
|
98
|
-
}
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
99
|
|
|
100
100
|
const renderInfiniteSelectionArea = () => {
|
|
101
101
|
return (
|
|
102
102
|
<circle
|
|
103
103
|
cx={coordinates.x}
|
|
104
104
|
cy={coordinates.y}
|
|
105
|
-
r={
|
|
105
|
+
r={'100%'}
|
|
106
106
|
style={{ opacity: 0 }}
|
|
107
107
|
onMouseMove={(e) => onMouseMove(e)}
|
|
108
108
|
onContextMenu={(e) => e.preventDefault()}
|
|
109
109
|
/>
|
|
110
|
-
)
|
|
111
|
-
}
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
112
|
|
|
113
113
|
return (
|
|
114
114
|
<g>
|
|
@@ -120,14 +120,14 @@ const Node = ({
|
|
|
120
120
|
r={10 / svgScale}
|
|
121
121
|
style={style}
|
|
122
122
|
onMouseOver={() => {
|
|
123
|
-
if (annotationSettings.canEdit) setHasHalo(true)
|
|
123
|
+
if (annotationSettings.canEdit) setHasHalo(true)
|
|
124
124
|
}}
|
|
125
125
|
onMouseDown={onMouseDown}
|
|
126
126
|
onMouseMove={(e) => onMouseMove(e)}
|
|
127
127
|
onContextMenu={(e) => e.preventDefault()}
|
|
128
128
|
/>
|
|
129
129
|
</g>
|
|
130
|
-
)
|
|
131
|
-
}
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
132
|
|
|
133
|
-
export default Node
|
|
133
|
+
export default Node
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { CSSProperties, MouseEvent, 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 { AnnotationSettings, Point } from
|
|
5
|
-
import Node from
|
|
6
|
-
import AnnotationMode from
|
|
7
|
-
import
|
|
8
|
-
import PolygonArea from
|
|
9
|
-
import Edge from
|
|
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'
|
|
10
10
|
|
|
11
11
|
type BBoxProps = {
|
|
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
|
|
25
|
-
onMoved: () => void
|
|
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,
|
|
@@ -47,144 +47,130 @@ const BBox = ({
|
|
|
47
47
|
{ x: startCoords.x, y: endCoords.y },
|
|
48
48
|
endCoords,
|
|
49
49
|
{ x: endCoords.x, y: startCoords.y },
|
|
50
|
-
]
|
|
50
|
+
]
|
|
51
51
|
|
|
52
52
|
const [isAnnoCreating, setIsAnnoCreating] = useState<boolean>(
|
|
53
53
|
annotationMode === AnnotationMode.CREATE,
|
|
54
|
-
)
|
|
55
|
-
const [isAnnoDragging, setIsAnnoDragging] = useState<boolean>(false)
|
|
56
|
-
const [isEdgeDragging, setIsEdgeDragging] = useState<boolean>(false)
|
|
57
|
-
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)
|
|
58
58
|
|
|
59
59
|
// onMove and onMouseUp events are fired in the same frame
|
|
60
60
|
// use a ref to access the updated value without waiting until the next frame
|
|
61
|
-
const [didAnnoActuallyMove, setDidAnnoActuallyMove] =
|
|
62
|
-
|
|
63
|
-
const didAnnoActuallyMoveRef = useRef<boolean>(didAnnoActuallyMove);
|
|
61
|
+
const [didAnnoActuallyMove, setDidAnnoActuallyMove] = useState<boolean>(false)
|
|
62
|
+
const didAnnoActuallyMoveRef = useRef<boolean>(didAnnoActuallyMove)
|
|
64
63
|
|
|
65
64
|
useEffect(() => {
|
|
66
|
-
didAnnoActuallyMoveRef.current = didAnnoActuallyMove
|
|
67
|
-
}, [didAnnoActuallyMove])
|
|
65
|
+
didAnnoActuallyMoveRef.current = didAnnoActuallyMove
|
|
66
|
+
}, [didAnnoActuallyMove])
|
|
68
67
|
|
|
69
68
|
const onMouseDown = (e: MouseEvent) => {
|
|
70
|
-
if (annotationSettings.canEdit === false) return
|
|
69
|
+
if (annotationSettings.canEdit === false) return
|
|
71
70
|
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
e.button === 0
|
|
76
|
-
)
|
|
77
|
-
setIsAnnoDragging(true);
|
|
78
|
-
};
|
|
71
|
+
if (isSelected && annotationMode !== AnnotationMode.CREATE && e.button === 0)
|
|
72
|
+
setIsAnnoDragging(true)
|
|
73
|
+
}
|
|
79
74
|
|
|
80
75
|
const onMouseEdgeDown = (e: MouseEvent) => {
|
|
81
|
-
if (annotationSettings.canEdit === false) return
|
|
76
|
+
if (annotationSettings.canEdit === false) return
|
|
82
77
|
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
e.button === 0
|
|
87
|
-
)
|
|
88
|
-
setIsEdgeDragging(true);
|
|
89
|
-
};
|
|
78
|
+
if (isSelected && annotationMode !== AnnotationMode.CREATE && e.button === 0)
|
|
79
|
+
setIsEdgeDragging(true)
|
|
80
|
+
}
|
|
90
81
|
|
|
91
82
|
const onMouseMove = (e: MouseEvent) => {
|
|
92
83
|
if (isAnnoDragging) {
|
|
93
84
|
// we always get 4 coordinates (the rectangle corners)
|
|
94
85
|
// only the top left and bottom right corner are important - other coordinates are redundant
|
|
95
|
-
const newRectangle: Point[] = [
|
|
96
|
-
{ ...coordinates[0] },
|
|
97
|
-
{ ...coordinates[2] },
|
|
98
|
-
];
|
|
86
|
+
const newRectangle: Point[] = [{ ...coordinates[0] }, { ...coordinates[2] }]
|
|
99
87
|
|
|
100
88
|
// apply mouse move to the rectangle coordinates
|
|
101
|
-
const movedCoordinates: Point[] = newRectangle.map(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
},
|
|
109
|
-
);
|
|
89
|
+
const movedCoordinates: Point[] = newRectangle.map((coordinate: Point) => {
|
|
90
|
+
return {
|
|
91
|
+
// counter the canvas scaling (it will be automatically applied when rendering the annotation coordinates)
|
|
92
|
+
x: (coordinate.x += e.movementX / svgScale),
|
|
93
|
+
y: (coordinate.y += e.movementY / svgScale),
|
|
94
|
+
}
|
|
95
|
+
})
|
|
110
96
|
|
|
111
97
|
// only escalate event when mouse actually moved
|
|
112
98
|
if (e.movementX !== 0 || e.movementY !== 0) {
|
|
113
|
-
setDidAnnoActuallyMove(true)
|
|
114
|
-
onMoving(movedCoordinates)
|
|
99
|
+
setDidAnnoActuallyMove(true)
|
|
100
|
+
onMoving(movedCoordinates)
|
|
115
101
|
}
|
|
116
102
|
}
|
|
117
103
|
|
|
118
104
|
if (annotationMode === AnnotationMode.CREATE) {
|
|
119
|
-
const mousePointInStage =
|
|
105
|
+
const mousePointInStage = mouse.getAntiScaledMouseStagePosition(
|
|
120
106
|
e,
|
|
121
107
|
pageToStageOffset,
|
|
122
108
|
svgScale,
|
|
123
109
|
svgTranslation,
|
|
124
|
-
)
|
|
110
|
+
)
|
|
125
111
|
|
|
126
|
-
const newCoords: Point[] = [...coordinates]
|
|
112
|
+
const newCoords: Point[] = [...coordinates]
|
|
127
113
|
|
|
128
114
|
// we always get 4 coordinates (the rectangle corners)
|
|
129
115
|
// only the top left (start) is important - the end will be our mouse position and the others are redundant
|
|
130
|
-
const newRectangle: Point[] = [newCoords[0], mousePointInStage]
|
|
116
|
+
const newRectangle: Point[] = [newCoords[0], mousePointInStage]
|
|
131
117
|
|
|
132
|
-
onMoving(newRectangle)
|
|
118
|
+
onMoving(newRectangle)
|
|
133
119
|
}
|
|
134
|
-
}
|
|
120
|
+
}
|
|
135
121
|
|
|
136
122
|
useEffect(() => {
|
|
137
|
-
if (!isAnnoCreating) return
|
|
123
|
+
if (!isAnnoCreating) return
|
|
138
124
|
|
|
139
125
|
const handleMouseUp = (e: globalThis.MouseEvent) => {
|
|
140
126
|
if (e.button === 2) {
|
|
141
|
-
onFinishAnnoCreate()
|
|
142
|
-
setIsAnnoCreating(false)
|
|
127
|
+
onFinishAnnoCreate()
|
|
128
|
+
setIsAnnoCreating(false)
|
|
143
129
|
}
|
|
144
|
-
}
|
|
130
|
+
}
|
|
145
131
|
|
|
146
|
-
window.addEventListener(
|
|
132
|
+
window.addEventListener('mouseup', handleMouseUp)
|
|
147
133
|
|
|
148
134
|
return () => {
|
|
149
|
-
window.removeEventListener(
|
|
150
|
-
}
|
|
151
|
-
}, [isAnnoCreating])
|
|
135
|
+
window.removeEventListener('mouseup', handleMouseUp)
|
|
136
|
+
}
|
|
137
|
+
}, [isAnnoCreating])
|
|
152
138
|
|
|
153
139
|
useEffect(() => {
|
|
154
|
-
onIsDraggingStateChanged(isAnnoDragging)
|
|
155
|
-
if (!isAnnoDragging) return
|
|
140
|
+
onIsDraggingStateChanged(isAnnoDragging)
|
|
141
|
+
if (!isAnnoDragging) return
|
|
156
142
|
|
|
157
143
|
const handleMouseUp = () => {
|
|
158
|
-
setIsAnnoDragging(false)
|
|
144
|
+
setIsAnnoDragging(false)
|
|
159
145
|
|
|
160
|
-
if (didAnnoActuallyMoveRef.current) onMoved()
|
|
161
|
-
setDidAnnoActuallyMove(false)
|
|
162
|
-
}
|
|
146
|
+
if (didAnnoActuallyMoveRef.current) onMoved()
|
|
147
|
+
setDidAnnoActuallyMove(false)
|
|
148
|
+
}
|
|
163
149
|
|
|
164
|
-
window.addEventListener(
|
|
150
|
+
window.addEventListener('mouseup', handleMouseUp)
|
|
165
151
|
|
|
166
152
|
return () => {
|
|
167
|
-
window.removeEventListener(
|
|
168
|
-
}
|
|
169
|
-
}, [isAnnoDragging])
|
|
153
|
+
window.removeEventListener('mouseup', handleMouseUp)
|
|
154
|
+
}
|
|
155
|
+
}, [isAnnoDragging])
|
|
170
156
|
|
|
171
157
|
useEffect(() => {
|
|
172
|
-
onIsDraggingStateChanged(isEdgeDragging)
|
|
173
|
-
if (!isEdgeDragging) return
|
|
158
|
+
onIsDraggingStateChanged(isEdgeDragging)
|
|
159
|
+
if (!isEdgeDragging) return
|
|
174
160
|
|
|
175
161
|
const handleMouseUp = () => {
|
|
176
|
-
setIsEdgeDragging(false)
|
|
162
|
+
setIsEdgeDragging(false)
|
|
177
163
|
|
|
178
|
-
if (didAnnoActuallyMoveRef.current) onMoved()
|
|
179
|
-
setDidAnnoActuallyMove(false)
|
|
180
|
-
}
|
|
164
|
+
if (didAnnoActuallyMoveRef.current) onMoved()
|
|
165
|
+
setDidAnnoActuallyMove(false)
|
|
166
|
+
}
|
|
181
167
|
|
|
182
|
-
window.addEventListener(
|
|
168
|
+
window.addEventListener('mouseup', handleMouseUp)
|
|
183
169
|
|
|
184
170
|
return () => {
|
|
185
|
-
window.removeEventListener(
|
|
186
|
-
}
|
|
187
|
-
}, [isEdgeDragging])
|
|
171
|
+
window.removeEventListener('mouseup', handleMouseUp)
|
|
172
|
+
}
|
|
173
|
+
}, [isEdgeDragging])
|
|
188
174
|
|
|
189
175
|
const renderNodes = () => {
|
|
190
176
|
const svgNodes = coordinates.map((coordinate: Point, index: number) => (
|
|
@@ -198,78 +184,76 @@ const BBox = ({
|
|
|
198
184
|
svgTranslation={svgTranslation}
|
|
199
185
|
style={style}
|
|
200
186
|
onDeleteNode={() => {
|
|
201
|
-
const newCoordinates = [...coordinates]
|
|
202
|
-
newCoordinates.splice(index, 1)
|
|
203
|
-
onDeleteNode(newCoordinates)
|
|
187
|
+
const newCoordinates = [...coordinates]
|
|
188
|
+
newCoordinates.splice(index, 1)
|
|
189
|
+
onDeleteNode(newCoordinates)
|
|
204
190
|
}}
|
|
205
191
|
onMoving={(index: number, newPoint: Point) => {
|
|
206
192
|
// we always get 4 coordinates (the rectangle corners)
|
|
207
193
|
// only the top left and bottom right corner are important - other coordinates are redundant
|
|
208
|
-
const newRectangle: Point[] = [coordinates[0], coordinates[2]]
|
|
194
|
+
const newRectangle: Point[] = [coordinates[0], coordinates[2]]
|
|
209
195
|
|
|
210
196
|
// update start + end coordinates depending on which corner is moved
|
|
211
197
|
switch (index) {
|
|
212
198
|
case 0: // top left corner
|
|
213
|
-
newRectangle[0] = newPoint
|
|
214
|
-
break
|
|
199
|
+
newRectangle[0] = newPoint
|
|
200
|
+
break
|
|
215
201
|
case 1: // bottom left corner
|
|
216
|
-
newRectangle[0].x = newPoint.x
|
|
217
|
-
newRectangle[1].y = newPoint.y
|
|
218
|
-
break
|
|
202
|
+
newRectangle[0].x = newPoint.x
|
|
203
|
+
newRectangle[1].y = newPoint.y
|
|
204
|
+
break
|
|
219
205
|
case 2: // bottom right corner
|
|
220
|
-
newRectangle[1] = newPoint
|
|
221
|
-
break
|
|
206
|
+
newRectangle[1] = newPoint
|
|
207
|
+
break
|
|
222
208
|
case 3: // top right corner
|
|
223
|
-
newRectangle[1].x = newPoint.x
|
|
224
|
-
newRectangle[0].y = newPoint.y
|
|
225
|
-
break
|
|
209
|
+
newRectangle[1].x = newPoint.x
|
|
210
|
+
newRectangle[0].y = newPoint.y
|
|
211
|
+
break
|
|
226
212
|
}
|
|
227
213
|
|
|
228
|
-
onMoving(newRectangle)
|
|
214
|
+
onMoving(newRectangle)
|
|
229
215
|
}}
|
|
230
216
|
onMoved={() => onMoved()}
|
|
231
217
|
onIsDraggingStateChanged={onIsDraggingStateChanged}
|
|
232
218
|
/>
|
|
233
|
-
))
|
|
219
|
+
))
|
|
234
220
|
|
|
235
|
-
return svgNodes
|
|
236
|
-
}
|
|
221
|
+
return svgNodes
|
|
222
|
+
}
|
|
237
223
|
|
|
238
224
|
const moveEdge = (edgeIndex: number, e: MouseEvent) => {
|
|
239
225
|
// we always get 4 coordinates (the rectangle corners)
|
|
240
226
|
// only the top left and bottom right corner are important - other coordinates are redundant
|
|
241
|
-
const newRectangle: Point[] = [coordinates[0], coordinates[2]]
|
|
227
|
+
const newRectangle: Point[] = [coordinates[0], coordinates[2]]
|
|
242
228
|
switch (edgeIndex) {
|
|
243
229
|
case 0:
|
|
244
|
-
newRectangle[0].x += e.movementX / svgScale
|
|
245
|
-
break
|
|
230
|
+
newRectangle[0].x += e.movementX / svgScale
|
|
231
|
+
break
|
|
246
232
|
case 1:
|
|
247
|
-
newRectangle[1].y += e.movementY / svgScale
|
|
248
|
-
break
|
|
233
|
+
newRectangle[1].y += e.movementY / svgScale
|
|
234
|
+
break
|
|
249
235
|
case 2:
|
|
250
|
-
newRectangle[1].x += e.movementX / svgScale
|
|
251
|
-
break
|
|
236
|
+
newRectangle[1].x += e.movementX / svgScale
|
|
237
|
+
break
|
|
252
238
|
case 3:
|
|
253
|
-
newRectangle[0].y += e.movementY / svgScale
|
|
254
|
-
break
|
|
239
|
+
newRectangle[0].y += e.movementY / svgScale
|
|
240
|
+
break
|
|
255
241
|
}
|
|
256
242
|
|
|
257
243
|
// only escalate event when mouse actually moved
|
|
258
244
|
if (e.movementX !== 0 || e.movementY !== 0) {
|
|
259
|
-
setDidAnnoActuallyMove(true)
|
|
260
|
-
onMoving(newRectangle)
|
|
245
|
+
setDidAnnoActuallyMove(true)
|
|
246
|
+
onMoving(newRectangle)
|
|
261
247
|
}
|
|
262
|
-
}
|
|
248
|
+
}
|
|
263
249
|
|
|
264
250
|
const renderEdges = () => {
|
|
265
251
|
const svgEdges = coordinates.map((coordinate: Point, index: number) => {
|
|
266
252
|
const endCoordinates: Point =
|
|
267
|
-
index + 1 < coordinates.length
|
|
268
|
-
? coordinates[index + 1]
|
|
269
|
-
: coordinates[0];
|
|
253
|
+
index + 1 < coordinates.length ? coordinates[index + 1] : coordinates[0]
|
|
270
254
|
|
|
271
255
|
// corresponding cursor for horizontal or vertical edges
|
|
272
|
-
const cursor = index % 2 === 0 ?
|
|
256
|
+
const cursor = index % 2 === 0 ? 'ew-resize' : 'ns-resize'
|
|
273
257
|
|
|
274
258
|
return (
|
|
275
259
|
<Edge
|
|
@@ -282,31 +266,31 @@ const BBox = ({
|
|
|
282
266
|
style={{ ...style, cursor }}
|
|
283
267
|
onMouseDown={onMouseEdgeDown}
|
|
284
268
|
onMouseMove={(e: MouseEvent) => {
|
|
285
|
-
setDragSelectedEdgeIndex(index)
|
|
286
|
-
if (isEdgeDragging) moveEdge(index, e)
|
|
269
|
+
setDragSelectedEdgeIndex(index)
|
|
270
|
+
if (isEdgeDragging) moveEdge(index, e)
|
|
287
271
|
}}
|
|
288
272
|
/>
|
|
289
|
-
)
|
|
290
|
-
})
|
|
291
|
-
return svgEdges
|
|
292
|
-
}
|
|
273
|
+
)
|
|
274
|
+
})
|
|
275
|
+
return svgEdges
|
|
276
|
+
}
|
|
293
277
|
|
|
294
278
|
const renderInfiniteSelectionArea = (isForEdge: boolean) => {
|
|
295
279
|
return (
|
|
296
280
|
<circle
|
|
297
281
|
cx={coordinates[0].x}
|
|
298
282
|
cy={coordinates[0].y}
|
|
299
|
-
r={
|
|
283
|
+
r={'100%'}
|
|
300
284
|
style={{ opacity: 0 }}
|
|
301
285
|
onMouseDown={onMouseDown}
|
|
302
286
|
onMouseMove={(e: MouseEvent) => {
|
|
303
|
-
if (isForEdge && isEdgeDragging) moveEdge(dragSelectedEdgeIndex, e)
|
|
304
|
-
if (!isForEdge) onMouseMove(e)
|
|
287
|
+
if (isForEdge && isEdgeDragging) moveEdge(dragSelectedEdgeIndex, e)
|
|
288
|
+
if (!isForEdge) onMouseMove(e)
|
|
305
289
|
}}
|
|
306
290
|
onContextMenu={(e) => e.preventDefault()}
|
|
307
291
|
/>
|
|
308
|
-
)
|
|
309
|
-
}
|
|
292
|
+
)
|
|
293
|
+
}
|
|
310
294
|
|
|
311
295
|
return (
|
|
312
296
|
<g>
|
|
@@ -328,7 +312,7 @@ const BBox = ({
|
|
|
328
312
|
{isSelected && annotationSettings.canEdit && renderEdges()}
|
|
329
313
|
{isSelected && annotationMode !== AnnotationMode.CREATE && renderNodes()}
|
|
330
314
|
</g>
|
|
331
|
-
)
|
|
332
|
-
}
|
|
315
|
+
)
|
|
316
|
+
}
|
|
333
317
|
|
|
334
|
-
export default BBox
|
|
318
|
+
export default BBox
|