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,30 +1,28 @@
|
|
|
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 Edge from "../atoms/Edge";
|
|
10
|
-
import mouse2 from "../../../utils/mouse2";
|
|
4
|
+
import { AnnotationSettings, Point } from '../../../types'
|
|
5
|
+
import Node from '../atoms/Node'
|
|
6
|
+
import AnnotationMode from '../../../models/AnnotationMode'
|
|
7
|
+
import Edge from '../atoms/Edge'
|
|
8
|
+
import mouse from '../../../utils/mouse'
|
|
11
9
|
|
|
12
10
|
type LineProps = {
|
|
13
|
-
annotationSettings: AnnotationSettings
|
|
14
|
-
coordinates: Point[]
|
|
15
|
-
isSelected: boolean
|
|
16
|
-
annotationMode: AnnotationMode
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
style: CSSProperties
|
|
21
|
-
onAddNode: (coordinates: Point[]) => void
|
|
22
|
-
onDeleteNode: (coordinates: Point[]) => void
|
|
23
|
-
onFinishAnnoCreate: () => void
|
|
24
|
-
onIsDraggingStateChanged: (
|
|
25
|
-
onMoving: (coordinates: Point[]) => void
|
|
26
|
-
onMoved: () => void
|
|
27
|
-
}
|
|
11
|
+
annotationSettings: AnnotationSettings
|
|
12
|
+
coordinates: Point[]
|
|
13
|
+
isSelected: boolean
|
|
14
|
+
annotationMode: AnnotationMode
|
|
15
|
+
pageToStageOffset: Point
|
|
16
|
+
svgScale: number
|
|
17
|
+
svgTranslation: Point
|
|
18
|
+
style: CSSProperties
|
|
19
|
+
onAddNode: (coordinates: Point[]) => void
|
|
20
|
+
onDeleteNode: (coordinates: Point[]) => void
|
|
21
|
+
onFinishAnnoCreate: () => void
|
|
22
|
+
onIsDraggingStateChanged: (newDraggingState: boolean) => void
|
|
23
|
+
onMoving: (coordinates: Point[]) => void // during moving - update coordinates in parent
|
|
24
|
+
onMoved: () => void // moving finished - send annotation changed event
|
|
25
|
+
}
|
|
28
26
|
|
|
29
27
|
const Line = ({
|
|
30
28
|
annotationSettings,
|
|
@@ -33,6 +31,7 @@ const Line = ({
|
|
|
33
31
|
annotationMode,
|
|
34
32
|
pageToStageOffset,
|
|
35
33
|
svgScale,
|
|
34
|
+
svgTranslation,
|
|
36
35
|
style,
|
|
37
36
|
onAddNode,
|
|
38
37
|
onDeleteNode,
|
|
@@ -41,106 +40,109 @@ const Line = ({
|
|
|
41
40
|
onMoved,
|
|
42
41
|
onIsDraggingStateChanged,
|
|
43
42
|
}: LineProps) => {
|
|
44
|
-
const [isAnnoDragging, setIsAnnoDragging] = useState<boolean>(false)
|
|
43
|
+
const [isAnnoDragging, setIsAnnoDragging] = useState<boolean>(false)
|
|
45
44
|
|
|
46
45
|
// onMove and onMouseUp events are fired in the same frame
|
|
47
46
|
// use a ref to access the updated value without waiting until the next frame
|
|
48
|
-
const [didAnnoActuallyMove, setDidAnnoActuallyMove] =
|
|
49
|
-
|
|
50
|
-
const didAnnoActuallyMoveRef = useRef<boolean>(didAnnoActuallyMove);
|
|
47
|
+
const [didAnnoActuallyMove, setDidAnnoActuallyMove] = useState<boolean>(false)
|
|
48
|
+
const didAnnoActuallyMoveRef = useRef<boolean>(didAnnoActuallyMove)
|
|
51
49
|
|
|
52
50
|
useEffect(() => {
|
|
53
|
-
didAnnoActuallyMoveRef.current = didAnnoActuallyMove
|
|
54
|
-
}, [didAnnoActuallyMove])
|
|
51
|
+
didAnnoActuallyMoveRef.current = didAnnoActuallyMove
|
|
52
|
+
}, [didAnnoActuallyMove])
|
|
55
53
|
|
|
56
54
|
const onMouseDown = (e: MouseEvent) => {
|
|
57
|
-
if (annotationSettings.canEdit === false) return
|
|
55
|
+
if (annotationSettings.canEdit === false) return
|
|
58
56
|
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
annotationMode !== AnnotationMode.CREATE &&
|
|
62
|
-
e.button === 0
|
|
63
|
-
)
|
|
64
|
-
setIsAnnoDragging(true);
|
|
57
|
+
if (isSelected && annotationMode !== AnnotationMode.CREATE && e.button === 0)
|
|
58
|
+
setIsAnnoDragging(true)
|
|
65
59
|
|
|
66
60
|
if (e.button === 2 && annotationMode == AnnotationMode.CREATE) {
|
|
67
61
|
const antiScaledMousePositionInStageCoordinates =
|
|
68
|
-
|
|
62
|
+
mouse.getAntiScaledMouseStagePosition(
|
|
63
|
+
e,
|
|
64
|
+
pageToStageOffset,
|
|
65
|
+
svgScale,
|
|
66
|
+
svgTranslation,
|
|
67
|
+
)
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
newCoordinates.push(antiScaledMousePositionInStageCoordinates)
|
|
69
|
+
const newCoordinates = [...coordinates]
|
|
70
|
+
newCoordinates.push(antiScaledMousePositionInStageCoordinates)
|
|
72
71
|
|
|
73
|
-
onAddNode(newCoordinates)
|
|
72
|
+
onAddNode(newCoordinates)
|
|
74
73
|
}
|
|
75
|
-
}
|
|
74
|
+
}
|
|
76
75
|
|
|
77
76
|
const onMouseMove = (e: MouseEvent) => {
|
|
78
77
|
if (isAnnoDragging) {
|
|
79
78
|
// apply mouse move to all coordinates
|
|
80
79
|
const movedCoordinates: Point[] = coordinates.map((coordinate: Point) => {
|
|
80
|
+
// counter the canvas scaling (it will be automatically applied when rendering the annotation coordinates)
|
|
81
|
+
const newX = (coordinate.x += e.movementX / svgScale)
|
|
82
|
+
const newY = (coordinate.y += e.movementY / svgScale)
|
|
81
83
|
return {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
84
|
+
x: newX,
|
|
85
|
+
y: newY,
|
|
86
|
+
}
|
|
87
|
+
})
|
|
87
88
|
|
|
88
89
|
// only escalate event when mouse actually moved
|
|
89
90
|
if (e.movementX !== 0 || e.movementY !== 0) {
|
|
90
|
-
setDidAnnoActuallyMove(true)
|
|
91
|
-
onMoving(movedCoordinates)
|
|
91
|
+
setDidAnnoActuallyMove(true)
|
|
92
|
+
onMoving(movedCoordinates)
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
if (annotationMode === AnnotationMode.CREATE) {
|
|
96
|
-
const mousePointInStage =
|
|
97
|
+
const mousePointInStage = mouse.getAntiScaledMouseStagePosition(
|
|
97
98
|
e,
|
|
98
99
|
pageToStageOffset,
|
|
99
100
|
svgScale,
|
|
100
|
-
|
|
101
|
+
svgTranslation,
|
|
102
|
+
)
|
|
101
103
|
|
|
102
|
-
let newCoords: Point[] = [...coordinates]
|
|
104
|
+
let newCoords: Point[] = [...coordinates]
|
|
103
105
|
|
|
104
106
|
// last coordinate = mouse position - update it
|
|
105
|
-
if (coordinates.length > 1) newCoords = coordinates.slice(0, -1)
|
|
107
|
+
if (coordinates.length > 1) newCoords = coordinates.slice(0, -1)
|
|
106
108
|
|
|
107
|
-
newCoords.push(mousePointInStage)
|
|
109
|
+
newCoords.push(mousePointInStage)
|
|
108
110
|
|
|
109
|
-
onMoving(newCoords)
|
|
111
|
+
onMoving(newCoords)
|
|
110
112
|
}
|
|
111
|
-
}
|
|
113
|
+
}
|
|
112
114
|
|
|
113
115
|
useEffect(() => {
|
|
114
|
-
onIsDraggingStateChanged(isAnnoDragging)
|
|
115
|
-
if (!isAnnoDragging) return
|
|
116
|
+
onIsDraggingStateChanged(isAnnoDragging)
|
|
117
|
+
if (!isAnnoDragging) return
|
|
116
118
|
|
|
117
119
|
const handleMouseUp = () => {
|
|
118
|
-
setIsAnnoDragging(false)
|
|
120
|
+
setIsAnnoDragging(false)
|
|
119
121
|
|
|
120
|
-
if (didAnnoActuallyMoveRef.current) onMoved()
|
|
121
|
-
setDidAnnoActuallyMove(false)
|
|
122
|
-
}
|
|
122
|
+
if (didAnnoActuallyMoveRef.current) onMoved()
|
|
123
|
+
setDidAnnoActuallyMove(false)
|
|
124
|
+
}
|
|
123
125
|
|
|
124
|
-
|
|
126
|
+
globalThis.addEventListener('mouseup', handleMouseUp)
|
|
125
127
|
|
|
126
128
|
return () => {
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
}, [isAnnoDragging])
|
|
129
|
+
globalThis.removeEventListener('mouseup', handleMouseUp)
|
|
130
|
+
}
|
|
131
|
+
}, [isAnnoDragging])
|
|
130
132
|
|
|
131
133
|
const renderInfiniteSelectionArea = () => {
|
|
132
134
|
return (
|
|
133
135
|
<circle
|
|
134
136
|
cx={coordinates[0].x}
|
|
135
137
|
cy={coordinates[0].y}
|
|
136
|
-
r={
|
|
138
|
+
r={'100%'}
|
|
137
139
|
style={{ opacity: 0 }}
|
|
138
140
|
onMouseDown={onMouseDown}
|
|
139
141
|
onMouseMove={onMouseMove}
|
|
140
142
|
onContextMenu={(e) => e.preventDefault()}
|
|
141
143
|
/>
|
|
142
|
-
)
|
|
143
|
-
}
|
|
144
|
+
)
|
|
145
|
+
}
|
|
144
146
|
|
|
145
147
|
const renderNodes = () => {
|
|
146
148
|
const svgNodes = coordinates.map((coordinate: Point, index: number) => (
|
|
@@ -151,29 +153,30 @@ const Line = ({
|
|
|
151
153
|
coordinates={coordinate}
|
|
152
154
|
pageToStageOffset={pageToStageOffset}
|
|
153
155
|
svgScale={svgScale}
|
|
156
|
+
svgTranslation={svgTranslation}
|
|
154
157
|
style={style}
|
|
155
158
|
onDeleteNode={() => {
|
|
156
|
-
const newCoordinates = [...coordinates]
|
|
157
|
-
newCoordinates.splice(index, 1)
|
|
158
|
-
onDeleteNode(newCoordinates)
|
|
159
|
+
const newCoordinates = [...coordinates]
|
|
160
|
+
newCoordinates.splice(index, 1)
|
|
161
|
+
onDeleteNode(newCoordinates)
|
|
159
162
|
}}
|
|
160
163
|
onMoving={(index, newPoint) => {
|
|
161
|
-
const newCoordinates = [...coordinates]
|
|
162
|
-
newCoordinates[index] = newPoint
|
|
163
|
-
onMoving(newCoordinates)
|
|
164
|
+
const newCoordinates = [...coordinates]
|
|
165
|
+
newCoordinates[index] = newPoint
|
|
166
|
+
onMoving(newCoordinates)
|
|
164
167
|
}}
|
|
165
168
|
onMoved={() => onMoved()}
|
|
166
169
|
onIsDraggingStateChanged={onIsDraggingStateChanged}
|
|
167
170
|
/>
|
|
168
|
-
))
|
|
171
|
+
))
|
|
169
172
|
|
|
170
|
-
return svgNodes
|
|
171
|
-
}
|
|
173
|
+
return svgNodes
|
|
174
|
+
}
|
|
172
175
|
|
|
173
176
|
const renderEdges = () => {
|
|
174
|
-
|
|
177
|
+
const svgEdges = coordinates.map((coordinate: Point, index: number) => {
|
|
175
178
|
// last coordinate has no end - dont draw it
|
|
176
|
-
if (index + 1 >= coordinates.length) return
|
|
179
|
+
if (index + 1 >= coordinates.length) return
|
|
177
180
|
|
|
178
181
|
return (
|
|
179
182
|
<Edge
|
|
@@ -182,14 +185,15 @@ const Line = ({
|
|
|
182
185
|
endCoordinate={coordinates[index + 1]}
|
|
183
186
|
pageToStageOffset={pageToStageOffset}
|
|
184
187
|
svgScale={svgScale}
|
|
188
|
+
svgTranslation={svgTranslation}
|
|
185
189
|
style={style}
|
|
186
190
|
onAddNode={(coordinate: Point) => {
|
|
187
|
-
const newCoordinates = [...coordinates]
|
|
191
|
+
const newCoordinates = [...coordinates]
|
|
188
192
|
|
|
189
193
|
// add element at index while keeping the others
|
|
190
|
-
newCoordinates.splice(index + 1, 0, coordinate)
|
|
194
|
+
newCoordinates.splice(index + 1, 0, coordinate)
|
|
191
195
|
|
|
192
|
-
onAddNode(newCoordinates)
|
|
196
|
+
onAddNode(newCoordinates)
|
|
193
197
|
}}
|
|
194
198
|
onDoubleClick={() =>
|
|
195
199
|
annotationMode === AnnotationMode.CREATE && onFinishAnnoCreate()
|
|
@@ -197,14 +201,13 @@ const Line = ({
|
|
|
197
201
|
onMouseDown={onMouseDown}
|
|
198
202
|
onMouseMove={onMouseMove}
|
|
199
203
|
/>
|
|
200
|
-
)
|
|
201
|
-
})
|
|
204
|
+
)
|
|
205
|
+
})
|
|
202
206
|
|
|
203
|
-
return svgEdges
|
|
204
|
-
}
|
|
207
|
+
return svgEdges
|
|
208
|
+
}
|
|
205
209
|
|
|
206
|
-
const canRenderNodes: boolean =
|
|
207
|
-
isSelected && annotationMode !== AnnotationMode.CREATE;
|
|
210
|
+
const canRenderNodes: boolean = isSelected && annotationMode !== AnnotationMode.CREATE
|
|
208
211
|
|
|
209
212
|
// nodes need to be drawn after the edges to make them fully clickable
|
|
210
213
|
return (
|
|
@@ -214,7 +217,7 @@ const Line = ({
|
|
|
214
217
|
{renderEdges()}
|
|
215
218
|
{canRenderNodes && renderNodes()}
|
|
216
219
|
</g>
|
|
217
|
-
)
|
|
218
|
-
}
|
|
220
|
+
)
|
|
221
|
+
}
|
|
219
222
|
|
|
220
|
-
export default Line
|
|
223
|
+
export default Line
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { CSSProperties } from
|
|
1
|
+
import { CSSProperties } from 'react'
|
|
2
2
|
|
|
3
3
|
// rename type to avoid naming conflict
|
|
4
|
-
import { Point as TPoint } from
|
|
5
|
-
import
|
|
6
|
-
import Node from "../atoms/Node";
|
|
4
|
+
import { AnnotationSettings, Point as TPoint } from '../../../types'
|
|
5
|
+
import Node from '../atoms/Node'
|
|
7
6
|
|
|
8
7
|
type PointProps = {
|
|
9
|
-
annotationSettings: AnnotationSettings
|
|
10
|
-
coordinates: TPoint
|
|
11
|
-
isSelected: boolean
|
|
12
|
-
pageToStageOffset: TPoint
|
|
13
|
-
svgScale: number
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
annotationSettings: AnnotationSettings
|
|
9
|
+
coordinates: TPoint
|
|
10
|
+
isSelected: boolean
|
|
11
|
+
pageToStageOffset: TPoint
|
|
12
|
+
svgScale: number
|
|
13
|
+
svgTranslation: TPoint
|
|
14
|
+
style: CSSProperties
|
|
15
|
+
onIsDraggingStateChanged: (bool) => void
|
|
16
|
+
onMoving: (coordinates: TPoint) => void // during moving - update coordinates in parent
|
|
17
|
+
onMoved: (coordinates: TPoint[]) => void // moving finished - send annotation changed event
|
|
18
|
+
}
|
|
19
19
|
|
|
20
20
|
const Point = ({
|
|
21
21
|
annotationSettings,
|
|
@@ -23,6 +23,7 @@ const Point = ({
|
|
|
23
23
|
isSelected,
|
|
24
24
|
pageToStageOffset,
|
|
25
25
|
svgScale,
|
|
26
|
+
svgTranslation,
|
|
26
27
|
style,
|
|
27
28
|
onMoving,
|
|
28
29
|
onMoved,
|
|
@@ -35,6 +36,7 @@ const Point = ({
|
|
|
35
36
|
coordinates={coordinates}
|
|
36
37
|
pageToStageOffset={pageToStageOffset}
|
|
37
38
|
svgScale={svgScale}
|
|
39
|
+
svgTranslation={svgTranslation}
|
|
38
40
|
style={style}
|
|
39
41
|
onDeleteNode={
|
|
40
42
|
// just do nothing (we cannot delete a node from a point - delete the whole point instead)
|
|
@@ -44,7 +46,7 @@ const Point = ({
|
|
|
44
46
|
onMoved={() => onMoved([coordinates])}
|
|
45
47
|
onIsDraggingStateChanged={onIsDraggingStateChanged}
|
|
46
48
|
/>
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
+
)
|
|
50
|
+
}
|
|
49
51
|
|
|
50
|
-
export default Point
|
|
52
|
+
export default Point
|