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.
Files changed (280) hide show
  1. package/README.md +4 -0
  2. package/dist/Annotation/logic/Annotation.d.ts +17 -0
  3. package/dist/Annotation/logic/Annotation.js +1 -0
  4. package/dist/Annotation/ui/AnnotationComponent.d.ts +24 -0
  5. package/dist/Annotation/ui/AnnotationComponent.js +1 -0
  6. package/dist/Annotation/ui/atoms/AnnoBar.d.ts +15 -0
  7. package/dist/Annotation/ui/atoms/AnnoBar.js +1 -0
  8. package/dist/Annotation/ui/atoms/DaviIcon.d.ts +9 -0
  9. package/dist/Annotation/ui/atoms/DaviIcon.js +19 -0
  10. package/dist/Annotation/ui/atoms/Edge.d.ts +17 -0
  11. package/dist/Annotation/ui/atoms/Edge.js +1 -0
  12. package/dist/Annotation/ui/atoms/Node.d.ts +17 -0
  13. package/dist/Annotation/ui/atoms/Node.js +1 -0
  14. package/dist/Annotation/ui/atoms/PolygonArea.d.ts +16 -0
  15. package/dist/Annotation/ui/atoms/PolygonArea.js +1 -0
  16. package/dist/Annotation/ui/tools/BBox.d.ts +21 -0
  17. package/dist/Annotation/ui/tools/BBox.js +1 -0
  18. package/dist/Annotation/ui/tools/Line.d.ts +21 -0
  19. package/dist/Annotation/ui/tools/Line.js +1 -0
  20. package/dist/Annotation/ui/tools/Point.d.ts +16 -0
  21. package/dist/Annotation/ui/tools/Point.js +1 -0
  22. package/dist/Annotation/ui/tools/Polygon.d.ts +23 -0
  23. package/dist/Annotation/ui/tools/Polygon.js +1 -0
  24. package/dist/Canvas/Canvas.d.ts +31 -0
  25. package/dist/Canvas/Canvas.js +1 -0
  26. package/dist/Canvas/LabelInput.d.ts +11 -0
  27. package/dist/Canvas/LabelInput.js +1 -0
  28. package/dist/IconButton.d.ts +25 -0
  29. package/dist/IconButton.js +1 -0
  30. package/dist/Sia.d.ts +33 -0
  31. package/dist/Sia.js +1 -0
  32. package/dist/Toolbar/Toolbar.d.ts +21 -0
  33. package/dist/Toolbar/Toolbar.js +1 -0
  34. package/dist/Toolbar/ToolbarItems/AccessibilityTools.d.ts +7 -0
  35. package/dist/Toolbar/ToolbarItems/AccessibilityTools.js +1 -0
  36. package/dist/Toolbar/ToolbarItems/AnnoToolSelector.d.ts +11 -0
  37. package/dist/Toolbar/ToolbarItems/AnnoToolSelector.js +1 -0
  38. package/dist/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.d.ts +11 -0
  39. package/dist/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.js +1 -0
  40. package/dist/Toolbar/ToolbarItems/ImageToolItems/TagLabel.d.ts +11 -0
  41. package/dist/Toolbar/ToolbarItems/ImageToolItems/TagLabel.js +1 -0
  42. package/dist/Toolbar/ToolbarItems/ImageTools.d.ts +13 -0
  43. package/dist/Toolbar/ToolbarItems/ImageTools.js +1 -0
  44. package/dist/Toolbar/ToolbarItems/Instructions.d.ts +2 -0
  45. package/dist/Toolbar/ToolbarItems/Instructions.js +1 -0
  46. package/dist/Toolbar/ToolbarItems/InstructionsModal.d.ts +6 -0
  47. package/dist/Toolbar/ToolbarItems/InstructionsModal.js +1 -0
  48. package/dist/assets/SIA-BV1tYu3P.css +1 -0
  49. package/dist/assets/brand-icons-Cu_C0hZ4.svg +1008 -0
  50. package/dist/assets/brand-icons-F3SPCeH1.woff +0 -0
  51. package/dist/assets/brand-icons-XL9sxUpA.woff2 +0 -0
  52. package/dist/assets/brand-icons-sqJ2Pg7a.eot +0 -0
  53. package/dist/assets/brand-icons-ubhWoxly.ttf +0 -0
  54. package/dist/assets/flags-DOLqOU7Y.png +0 -0
  55. package/dist/assets/icons-BOCtAERH.woff +0 -0
  56. package/dist/assets/icons-CHzK1VD9.eot +0 -0
  57. package/dist/assets/icons-D29ZQHHw.ttf +0 -0
  58. package/dist/assets/icons-Du6TOHnR.woff2 +0 -0
  59. package/dist/assets/icons-RwhydX30.svg +1518 -0
  60. package/dist/assets/node_modules/semantic-ui-css/semantic.min-Bvulf91l.css +346 -0
  61. package/dist/assets/outline-icons-BfdLr8tr.svg +366 -0
  62. package/dist/assets/outline-icons-DD8jm0uy.ttf +0 -0
  63. package/dist/assets/outline-icons-DInHoiqI.woff2 +0 -0
  64. package/dist/assets/outline-icons-LX8adJ4n.eot +0 -0
  65. package/dist/assets/outline-icons-aQ88nltS.woff +0 -0
  66. package/dist/index.d.ts +5 -0
  67. package/dist/index.js +1 -0
  68. package/dist/models/AnnotationMode.d.ts +11 -0
  69. package/dist/models/AnnotationMode.js +1 -0
  70. package/dist/models/AnnotationStatus.d.ts +8 -0
  71. package/dist/models/AnnotationStatus.js +1 -0
  72. package/dist/models/AnnotationTool.d.ts +7 -0
  73. package/dist/models/AnnotationTool.js +1 -0
  74. package/dist/models/CanvasAction.d.ts +28 -0
  75. package/dist/models/CanvasAction.js +1 -0
  76. package/dist/models/Direction.d.ts +7 -0
  77. package/dist/models/Direction.js +1 -0
  78. package/dist/models/EditorModes.d.ts +11 -0
  79. package/dist/models/EditorModes.js +1 -0
  80. package/dist/models/KeyAction.d.ts +22 -0
  81. package/dist/models/KeyAction.js +1 -0
  82. package/dist/models/NotificationType.d.ts +7 -0
  83. package/dist/models/NotificationType.js +1 -0
  84. package/dist/models/index.d.ts +6 -0
  85. package/dist/models/index.js +1 -0
  86. package/dist/stories/AnnotationTools.stories.d.ts +40 -0
  87. package/dist/stories/Canvas/Canvas.stories.d.ts +50 -0
  88. package/dist/stories/Canvas/CanvasOffset.d.ts +13 -0
  89. package/dist/stories/Canvas/CanvasWithOffset.stories.d.ts +36 -0
  90. package/dist/stories/FilterDropdown.stories.d.ts +19 -0
  91. package/dist/stories/MinimalSia.stories.d.ts +66 -0
  92. package/dist/stories/SIA/DemoWrapper.d.ts +8 -0
  93. package/dist/stories/SIA/DemoWrapper.stories.d.ts +27 -0
  94. package/dist/stories/SIA/SIA.stories.d.ts +72 -0
  95. package/dist/stories/Toolbar/ImageTools/TagLabel.stories.d.ts +21 -0
  96. package/dist/stories/Toolbar/Instructions.stories.d.ts +11 -0
  97. package/dist/stories/Toolbar/Toolbar.stories.d.ts +37 -0
  98. package/dist/stories/exampleData/exampleAnnotations.d.ts +8 -0
  99. package/dist/stories/exampleData/exampleExternalAnnotations.d.ts +8 -0
  100. package/dist/stories/exampleData/exampleImage.d.ts +2 -0
  101. package/dist/stories/exampleData/exampleLabels.d.ts +6 -0
  102. package/dist/types.d.ts +57 -0
  103. package/dist/types.js +1 -0
  104. package/dist/utils/KeyMapper.d.ts +9 -0
  105. package/dist/utils/KeyMapper.js +1 -0
  106. package/dist/utils/TimeUtils.d.ts +4 -0
  107. package/dist/utils/TimeUtils.js +1 -0
  108. package/dist/utils/color.d.ts +2 -0
  109. package/dist/utils/color.js +1 -0
  110. package/dist/utils/index.d.ts +2 -0
  111. package/dist/utils/index.js +1 -0
  112. package/dist/utils/mouse.d.ts +6 -0
  113. package/dist/utils/mouse.js +1 -0
  114. package/dist/utils/siaIcons.js +12 -0
  115. package/dist/utils/transform.d.ts +28 -0
  116. package/dist/utils/transform.js +1 -0
  117. package/dist/utils/uiConfig.js +1 -0
  118. package/dist/utils/windowViewport.d.ts +22 -0
  119. package/dist/utils/windowViewport.js +1 -0
  120. package/package.json +19 -16
  121. package/src/AnnoExampleViewer.jsx +18 -18
  122. package/src/Annotation/logic/Annotation.ts +24 -26
  123. package/src/Annotation/ui/AnnotationComponent.tsx +115 -86
  124. package/src/Annotation/ui/atoms/AnnoBar.tsx +51 -53
  125. package/src/Annotation/ui/atoms/DaviIcon.tsx +12 -22
  126. package/src/Annotation/ui/atoms/Edge.tsx +25 -22
  127. package/src/Annotation/ui/atoms/Node.tsx +56 -50
  128. package/src/Annotation/ui/atoms/PolygonArea.tsx +30 -35
  129. package/src/Annotation/ui/tools/BBox.tsx +136 -150
  130. package/src/Annotation/ui/tools/Line.tsx +94 -91
  131. package/src/Annotation/ui/tools/Point.tsx +19 -17
  132. package/src/Annotation/ui/tools/Polygon.tsx +126 -95
  133. package/src/Canvas/Canvas.tsx +748 -594
  134. package/src/Canvas/LabelInput.tsx +68 -45
  135. package/src/IconButton.tsx +119 -0
  136. package/src/InfoBoxes/AnnoDetails.jsx +53 -53
  137. package/src/InfoBoxes/AnnoStats.jsx +41 -41
  138. package/src/InfoBoxes/InfoBox.jsx +16 -16
  139. package/src/InfoBoxes/InfoBoxArea.jsx +32 -34
  140. package/src/InfoBoxes/LabelInfo.jsx +30 -30
  141. package/src/SIASettingButton.jsx +25 -25
  142. package/src/Sia.tsx +484 -0
  143. package/src/Toolbar/Toolbar.tsx +38 -31
  144. package/src/Toolbar/ToolbarItems/AccessibilityTools.tsx +26 -46
  145. package/src/Toolbar/ToolbarItems/AnnoToolSelector.tsx +53 -46
  146. package/src/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.tsx +127 -0
  147. package/src/Toolbar/ToolbarItems/ImageToolItems/TagLabel.tsx +29 -28
  148. package/src/Toolbar/ToolbarItems/ImageTools.tsx +43 -40
  149. package/src/Toolbar/ToolbarItems/Instructions.tsx +47 -50
  150. package/src/Toolbar/ToolbarItems/InstructionsModal.tsx +8 -8
  151. package/src/index.ts +9 -13
  152. package/src/models/{AnnotationMode.tsx → AnnotationMode.ts} +1 -1
  153. package/src/models/{AnnotationStatus.tsx → AnnotationStatus.ts} +1 -1
  154. package/src/models/{AnnotationTool.tsx → AnnotationTool.ts} +1 -1
  155. package/src/models/{CanvasAction.tsx → CanvasAction.ts} +1 -1
  156. package/src/models/{Direction.tsx → Direction.ts} +1 -1
  157. package/src/models/{EditorModes.tsx → EditorModes.ts} +1 -1
  158. package/src/models/{KeyAction.tsx → KeyAction.ts} +3 -1
  159. package/src/models/NotificationType.ts +8 -0
  160. package/src/models/index.ts +6 -7
  161. package/src/siaDummyData.js +71 -71
  162. package/src/stories/AnnotationTools.mdx +27 -0
  163. package/src/stories/AnnotationTools.stories.tsx +104 -0
  164. package/src/stories/Canvas/Canvas.stories.tsx +59 -113
  165. package/src/stories/Canvas/CanvasOffset.tsx +54 -38
  166. package/src/stories/Canvas/CanvasWithOffset.stories.tsx +42 -113
  167. package/src/stories/FilterDropdown.stories.ts +13 -11
  168. package/src/stories/MinimalSIA.mdx +20 -0
  169. package/src/stories/MinimalSia.stories.tsx +90 -0
  170. package/src/stories/SIA/DemoWrapper.stories.tsx +71 -0
  171. package/src/stories/SIA/DemoWrapper.tsx +55 -0
  172. package/src/stories/SIA/SIA.stories.tsx +79 -45
  173. package/src/stories/Toolbar/ImageTools/TagLabel.stories.tsx +11 -12
  174. package/src/stories/Toolbar/Instructions.stories.tsx +11 -11
  175. package/src/stories/Toolbar/Toolbar.stories.tsx +32 -47
  176. package/src/stories/Welcome.mdx +5 -0
  177. package/src/stories/development/CoordinateSystems.mdx +25 -0
  178. package/src/stories/exampleData/exampleAnnotations.ts +65 -0
  179. package/src/stories/exampleData/exampleExternalAnnotations.ts +115 -0
  180. package/src/stories/{siaDummyData2.ts → exampleData/exampleImage.ts} +3 -264
  181. package/src/stories/exampleData/exampleLabels.ts +146 -0
  182. package/src/stories/main.scss +6 -0
  183. package/src/styles/style.scss +1 -26
  184. package/src/types.ts +67 -0
  185. package/src/utils/KeyMapper.ts +76 -74
  186. package/src/utils/TimeUtils.ts +11 -0
  187. package/src/utils/color.ts +25 -25
  188. package/src/utils/hist.js +22 -22
  189. package/src/utils/index.ts +2 -3
  190. package/src/utils/mouse.ts +45 -0
  191. package/src/utils/siaIcons.jsx +5 -7
  192. package/src/utils/transform.ts +186 -0
  193. package/src/utils/uiConfig.js +19 -22
  194. package/src/utils/windowViewport.ts +34 -0
  195. package/src/AnnoLabelInput.jsx +0 -109
  196. package/src/AnnoToolBar.jsx +0 -153
  197. package/src/Annotation/AnnoBar.jsx +0 -154
  198. package/src/Annotation/Annotation.jsx +0 -395
  199. package/src/Annotation/Annotation.scss +0 -47
  200. package/src/Annotation/BBox.jsx +0 -299
  201. package/src/Annotation/Edge.jsx +0 -92
  202. package/src/Annotation/InfSelectionArea.jsx +0 -72
  203. package/src/Annotation/Line.jsx +0 -68
  204. package/src/Annotation/Node.jsx +0 -282
  205. package/src/Annotation/Point.jsx +0 -200
  206. package/src/Annotation/Polygon.jsx +0 -404
  207. package/src/Annotation/logic/AnnotationUtils.ts +0 -30
  208. package/src/Canvas.jsx +0 -2194
  209. package/src/ImgBar.jsx +0 -131
  210. package/src/LabelInput.jsx +0 -238
  211. package/src/Prompt.jsx +0 -45
  212. package/src/SIAFilterButton.jsx +0 -186
  213. package/src/Sia.jsx +0 -478
  214. package/src/Sia2.tsx +0 -392
  215. package/src/SiaPopup.jsx +0 -15
  216. package/src/ToolBar.jsx +0 -463
  217. package/src/Toolbar/NavigationButtons.tsx +0 -21
  218. package/src/Toolbar/ToolbarItem.jsx +0 -30
  219. package/src/Toolbar/ToolbarItems/ImageToolItems/ImageLabel.tsx +0 -62
  220. package/src/Toolbar.css +0 -13
  221. package/src/ToolbarItem.jsx +0 -31
  222. package/src/filterTools.js +0 -5
  223. package/src/models/AllowedTools.tsx +0 -9
  224. package/src/models/AnnotationSettings.tsx +0 -9
  225. package/src/models/ExternalAnnotation.ts +0 -15
  226. package/src/models/Label.tsx +0 -8
  227. package/src/models/UiConfig.tsx +0 -6
  228. package/src/stories/Button.jsx +0 -54
  229. package/src/stories/Button.stories.js +0 -48
  230. package/src/stories/Header.jsx +0 -69
  231. package/src/stories/Header.stories.js +0 -28
  232. package/src/stories/Page.jsx +0 -87
  233. package/src/stories/Page.stories.js +0 -28
  234. package/src/stories/SIA2/DemoWrapper.stories.tsx +0 -167
  235. package/src/stories/SIA2/DemoWrapper.tsx +0 -54
  236. package/src/stories/SIA2/Sia2.stories.tsx +0 -62
  237. package/src/stories/Toolbar/ImageTools/ImageLabel.stories.tsx +0 -32
  238. package/src/stories/assets/accessibility.png +0 -0
  239. package/src/stories/assets/accessibility.svg +0 -5
  240. package/src/stories/assets/addon-library.png +0 -0
  241. package/src/stories/assets/assets.png +0 -0
  242. package/src/stories/assets/avif-test-image.avif +0 -0
  243. package/src/stories/assets/context.png +0 -0
  244. package/src/stories/assets/discord.svg +0 -15
  245. package/src/stories/assets/docs.png +0 -0
  246. package/src/stories/assets/figma-plugin.png +0 -0
  247. package/src/stories/assets/github.svg +0 -3
  248. package/src/stories/assets/share.png +0 -0
  249. package/src/stories/assets/styling.png +0 -0
  250. package/src/stories/assets/testing.png +0 -0
  251. package/src/stories/assets/theming.png +0 -0
  252. package/src/stories/assets/tutorials.svg +0 -12
  253. package/src/stories/assets/youtube.svg +0 -4
  254. package/src/stories/button.css +0 -30
  255. package/src/stories/header.css +0 -32
  256. package/src/stories/lost.js +0 -54
  257. package/src/stories/page.css +0 -69
  258. package/src/stories/siaDummyData.js +0 -263
  259. package/src/stories/store.js +0 -18
  260. package/src/test.js +0 -7
  261. package/src/types/annoStatus.js +0 -4
  262. package/src/types/canvasActions.js +0 -58
  263. package/src/types/cursorstyles.js +0 -3
  264. package/src/types/modes.js +0 -9
  265. package/src/types/notificationType.js +0 -11
  266. package/src/types/toolbarEvents.js +0 -35
  267. package/src/types/tools.js +0 -17
  268. package/src/types.tsx +0 -11
  269. package/src/utils/annoConversion.js +0 -145
  270. package/src/utils/annoConversion2.ts +0 -145
  271. package/src/utils/colorlut.js +0 -68
  272. package/src/utils/constraints.js +0 -81
  273. package/src/utils/index.js +0 -1
  274. package/src/utils/keyActions.js +0 -113
  275. package/src/utils/mouse.js +0 -14
  276. package/src/utils/mouse2.ts +0 -35
  277. package/src/utils/transform.js +0 -336
  278. package/src/utils/transform2.ts +0 -343
  279. package/src/utils/windowViewport.js +0 -34
  280. package/src/utils/windowViewport2.ts +0 -50
@@ -0,0 +1,186 @@
1
+ import type { Point, Vector2 } from '../types'
2
+
3
+ const convertImageCoordinatesToStage = (
4
+ imageCoordinates: Point[],
5
+ imageSize: Vector2,
6
+ stageSize: Vector2,
7
+ ): Point[] => {
8
+ // the image is scaled to match the width of the canvas
9
+ // assume the aspect ratio is kept
10
+ const imageToCanvasScale = stageSize.x / imageSize.x
11
+
12
+ const stageCoordinates = imageCoordinates.map((imagePoint: Point) => ({
13
+ x: imagePoint.x * imageToCanvasScale,
14
+ y: imagePoint.y * imageToCanvasScale,
15
+ }))
16
+
17
+ return stageCoordinates
18
+ }
19
+
20
+ const convertPercentagedCoordinatesToImage = (
21
+ percentagedCoordinates: Point[],
22
+ imageSize: Vector2,
23
+ ): Point[] => {
24
+ const imageCoordinates: Point[] = percentagedCoordinates.map((point: Point) => {
25
+ return {
26
+ x: point.x * imageSize.x,
27
+ y: point.y * imageSize.y,
28
+ }
29
+ })
30
+
31
+ return imageCoordinates
32
+ }
33
+
34
+ const convertPercentagedCoordinatesToStage = (
35
+ percentagedCoordinates: Point[],
36
+ imageSize: Vector2,
37
+ stageSize: Vector2,
38
+ ): Point[] => {
39
+ const imageCoordinates = convertPercentagedCoordinatesToImage(
40
+ percentagedCoordinates,
41
+ imageSize,
42
+ )
43
+ const stageCoordinates = convertImageCoordinatesToStage(
44
+ imageCoordinates,
45
+ imageSize,
46
+ stageSize,
47
+ )
48
+ return stageCoordinates
49
+ }
50
+
51
+ const convertStageCoordinatesToImage = (
52
+ stageCoordinates: Point[],
53
+ imageToStageFactor: number,
54
+ ): Point[] => {
55
+ const coordinatesInImageSpace: Point[] = stageCoordinates.map((coordinate: Point) => {
56
+ return {
57
+ x: coordinate.x / imageToStageFactor,
58
+ y: coordinate.y / imageToStageFactor,
59
+ }
60
+ })
61
+ return coordinatesInImageSpace
62
+ }
63
+
64
+ const convertStageCoordinatesToPercentaged = (
65
+ scaledCoordinates: Point[],
66
+ imageToStageFactor: number,
67
+ imageSize: Vector2,
68
+ ): Point[] => {
69
+ const imageCoordinates: Point[] = convertStageCoordinatesToImage(
70
+ scaledCoordinates,
71
+ imageToStageFactor,
72
+ )
73
+
74
+ // make sure the coordinates are inside the image bounds
75
+ const polishedImageCoordinates = imageCoordinates.map((point: Point) => {
76
+ if (point.x < 0) point.x = 0
77
+ if (point.y < 0) point.y = 0
78
+ if (point.x > imageSize.x) point.x = imageSize.x
79
+ if (point.y > imageSize.y) point.y = imageSize.y
80
+
81
+ return point
82
+ })
83
+
84
+ // someone decided to use percentages as the image coordinates
85
+ // convert them from pixel coordinates back to percentages here
86
+ const percentagedCoordinates = polishedImageCoordinates.map((point: Point) => {
87
+ return {
88
+ x: point.x / imageSize.x,
89
+ y: point.y / imageSize.y,
90
+ }
91
+ })
92
+
93
+ return percentagedCoordinates
94
+ }
95
+
96
+ /**
97
+ * converts coordinates from the stage system into the page system
98
+ * the coordinates are
99
+ * @param pageToStageOffset vector2 from the start of the page to the start of the stage
100
+ * @param svgScale the scaling factor of the canvas svg element (can be zoomed in by user)
101
+ * @returns
102
+ */
103
+ const convertStageToPage = (
104
+ stageCoordinates: Point,
105
+ pageToStageOffset: Point,
106
+ svgScale: number,
107
+ svgTranslation: Vector2,
108
+ ): Point => {
109
+ const scaledStageCoordinates: Point = {
110
+ x: stageCoordinates.x + svgTranslation.x,
111
+ y: stageCoordinates.y + svgTranslation.y,
112
+ }
113
+
114
+ // now we need to counter the scaling to get from the transformation system into the stage system
115
+ const transformedStageCoordinates: Point = {
116
+ x: scaledStageCoordinates.x * svgScale,
117
+ y: scaledStageCoordinates.y * svgScale,
118
+ }
119
+
120
+ // convert them into (translated) stage coordinates by subtracting the offset between the page (0,0) and the stage (0,0)
121
+ const pageCoordinates: Point = {
122
+ x: transformedStageCoordinates.x + pageToStageOffset.x,
123
+ y: transformedStageCoordinates.y + pageToStageOffset.y,
124
+ }
125
+
126
+ return pageCoordinates
127
+ }
128
+
129
+ /**
130
+ * Get point that is closest to the left browser side.
131
+ *
132
+ * @param points list of points {x,y}
133
+ * @returns {object} A list of point [{x,y}...]. Multiple points are
134
+ * returned when multiple points have the same distance to the left side.
135
+ */
136
+ export const getMostLeftPoints = (points: Point[]): Point[] => {
137
+ let minX = Infinity
138
+ let minXList: Point[] = []
139
+ points.forEach((point: Point) => {
140
+ if (point.x < minX) {
141
+ // new most left point - replace list
142
+ minX = point.x
143
+ minXList = []
144
+ minXList.push(point)
145
+ } else if (point.x === minX) {
146
+ // same x as current most left point - add to list
147
+ minXList.push(point)
148
+ }
149
+ })
150
+ return minXList
151
+ }
152
+
153
+ /**
154
+ * Get point that is closest to the top of the browser.
155
+ *
156
+ * @param points list of points [x,y]
157
+ * @returns A list of point [[x,y]...]. Multiple points are
158
+ * returned when multiple points have the same distance to the top.
159
+ */
160
+ export const getTopPoint = (points: Point[]): Point[] => {
161
+ let minY = Infinity
162
+ let minYList: Point[] = []
163
+ points.forEach((point: Point) => {
164
+ if (point.y < minY) {
165
+ // new hightest point - replace list
166
+ minY = point.y
167
+ minYList = []
168
+ minYList.push(point)
169
+ } else if (point.y === minY) {
170
+ // same height as highest point - add to list
171
+ minYList.push(point)
172
+ }
173
+ })
174
+ return minYList
175
+ }
176
+
177
+ export default {
178
+ convertImageCoordinatesToStage,
179
+ convertPercentagedCoordinatesToImage,
180
+ convertPercentagedCoordinatesToStage,
181
+ convertStageCoordinatesToImage,
182
+ convertStageCoordinatesToPercentaged,
183
+ convertStageToPage,
184
+ getMostLeftPoints,
185
+ getTopPoint,
186
+ }
@@ -10,12 +10,12 @@ export const SIA_INITIAL_UI_CONFIG = {
10
10
  annoStats: {
11
11
  visible: false,
12
12
  },
13
- };
13
+ }
14
14
 
15
15
  // read sia-ui-config from localStorage
16
- const iniFromStorage = localStorage.getItem("sia-ui-config")
17
- ? JSON.parse(localStorage.getItem("sia-ui-config"))
18
- : SIA_INITIAL_UI_CONFIG;
16
+ const iniFromStorage = localStorage.getItem('sia-ui-config')
17
+ ? JSON.parse(localStorage.getItem('sia-ui-config'))
18
+ : SIA_INITIAL_UI_CONFIG
19
19
 
20
20
  // collect object keys and its type in order to describe the object
21
21
  const collectDescription = (obj, array) => {
@@ -23,35 +23,32 @@ const collectDescription = (obj, array) => {
23
23
  const description = {
24
24
  key: key,
25
25
  type: typeof obj[key],
26
- };
27
- array.push(description);
26
+ }
27
+ array.push(description)
28
28
 
29
- if (typeof obj[key] === "object") {
30
- collectDescription(obj[key], array);
29
+ if (typeof obj[key] === 'object') {
30
+ collectDescription(obj[key], array)
31
31
  }
32
- });
33
- };
32
+ })
33
+ }
34
34
 
35
35
  // collect object description for ini and storage ui-config
36
36
 
37
- let iniObjectDescriptor = [];
38
- let storageObjectDescriptor = [];
37
+ let iniObjectDescriptor = []
38
+ let storageObjectDescriptor = []
39
39
 
40
- collectDescription(SIA_INITIAL_UI_CONFIG, iniObjectDescriptor);
41
- collectDescription(iniFromStorage, storageObjectDescriptor);
40
+ collectDescription(SIA_INITIAL_UI_CONFIG, iniObjectDescriptor)
41
+ collectDescription(iniFromStorage, storageObjectDescriptor)
42
42
 
43
43
  // compare both object descriptions
44
44
 
45
45
  const getUiConfig = () => {
46
- if (
47
- JSON.stringify(iniObjectDescriptor) ===
48
- JSON.stringify(storageObjectDescriptor)
49
- ) {
50
- return iniFromStorage;
46
+ if (JSON.stringify(iniObjectDescriptor) === JSON.stringify(storageObjectDescriptor)) {
47
+ return iniFromStorage
51
48
  } else {
52
49
  // ini description dif from storage: send ini ui-config and store it to local storage
53
- return SIA_INITIAL_UI_CONFIG;
50
+ return SIA_INITIAL_UI_CONFIG
54
51
  }
55
- };
52
+ }
56
53
 
57
- export const uiConfig = getUiConfig();
54
+ export const uiConfig = getUiConfig()
@@ -0,0 +1,34 @@
1
+ import { Point, Vector2 } from '../types'
2
+
3
+ const getViewportCoordinates = (
4
+ svgTranslation: Vector2,
5
+ canvasSize: Vector2,
6
+ svgScale: number,
7
+ pointInViewport: Point,
8
+ ) => {
9
+ const window = {
10
+ xMin: -1 * svgTranslation.x,
11
+ xMax: -1 * svgTranslation.x + canvasSize.x / svgScale,
12
+ yMin: -1 * svgTranslation.y,
13
+ yMax: -1 * svgTranslation.y + canvasSize.y / svgScale,
14
+ }
15
+
16
+ const viewport = {
17
+ xMin: 0,
18
+ xMax: canvasSize.x,
19
+ yMin: 0,
20
+ yMax: canvasSize.y,
21
+ }
22
+
23
+ const scaleX = (viewport.xMax - viewport.xMin) / (window.xMax - window.xMin)
24
+ const scaleY = (viewport.yMax - viewport.yMin) / (window.yMax - window.yMin)
25
+
26
+ const vX = viewport.xMin + (pointInViewport.x - window.xMin) * scaleX
27
+ const vY = viewport.yMin + (pointInViewport.y - window.yMin) * scaleY
28
+
29
+ return { window, viewport, vX, vY, scaleX, scaleY }
30
+ }
31
+
32
+ export default {
33
+ getViewportCoordinates,
34
+ }
@@ -1,109 +0,0 @@
1
- import React, { Component } from "react";
2
- import LabelInput from "./LabelInput";
3
- import * as constraints from "./utils/constraints";
4
- import * as annoStatus from "./types/annoStatus";
5
-
6
- class AnnoLabelInput extends Component {
7
- constructor(props) {
8
- super(props);
9
- this.state = {
10
- top: 400,
11
- left: 100,
12
- label: undefined,
13
- visibility: "hidden",
14
- possibleLabels: [],
15
- };
16
- this.inputGroupRef = React.createRef();
17
- }
18
-
19
- componentWillMount() {
20
- this.setPosition();
21
- }
22
-
23
- componentDidUpdate(prevProps) {
24
- if (this.props.visible) {
25
- this.setPosition();
26
- }
27
- }
28
-
29
- /*************
30
- * LOGIC *
31
- *************/
32
- setPosition() {
33
- if (this.props.mousePos) {
34
- const top = this.props.mousePos.y + this.props.svg.top - 10;
35
- const left = this.props.mousePos.x + this.props.svg.left - 10;
36
- if (this.state.top !== top || this.state.left !== left) {
37
- this.setState({
38
- top: top,
39
- left: left,
40
- });
41
- }
42
- }
43
- }
44
-
45
- onClose() {
46
- if (this.props.onClose) {
47
- this.props.onClose();
48
- }
49
- }
50
-
51
- annoLabelUpdate(anno) {
52
- if (this.props.onLabelUpdate) {
53
- this.props.onLabelUpdate(anno);
54
- }
55
- }
56
-
57
- updateAnnoLabel(label) {
58
- if (
59
- !constraints.allowedToLabel(
60
- this.props.allowedActions,
61
- this.props.selectedAnno,
62
- )
63
- )
64
- return;
65
- this.annoLabelUpdate({
66
- ...this.props.selectedAnno,
67
- labelIds: label,
68
- status:
69
- this.props.selectedAnno.status !== annoStatus.NEW
70
- ? annoStatus.CHANGED
71
- : annoStatus.NEW,
72
- });
73
- }
74
-
75
- /*************
76
- * RENDERING *
77
- **************/
78
- render() {
79
- if (!this.props.visible) return null;
80
- return (
81
- <div
82
- ref={this.inputGroupRef}
83
- style={{
84
- position: "fixed",
85
- top: this.state.top,
86
- left: this.state.left,
87
- }}
88
- >
89
- <LabelInput
90
- svg={this.props.svg}
91
- onClose={() => this.onClose()}
92
- initLabelIds={this.props.selectedAnno.labelIds}
93
- relatedId={this.props.selectedAnno.id}
94
- visible={this.props.visible}
95
- onLabelUpdate={(label) => this.updateAnnoLabel(label)}
96
- possibleLabelsProp={this.props.possibleLabels}
97
- multilabels={this.props.multilabels}
98
- disabled={!this.props.allowedActions.label}
99
- renderPopup
100
- focusOnRender
101
- open={true}
102
- defaultLabel={this.props.defaultLabel}
103
- />
104
- </div>
105
- );
106
- }
107
- }
108
-
109
- export default AnnoLabelInput;
@@ -1,153 +0,0 @@
1
- import React, { Component } from "react";
2
-
3
- import * as transform from "./utils/transform";
4
-
5
- class AnnoToolBar extends Component {
6
- constructor(props) {
7
- super(props);
8
- this.state = {
9
- top: 400,
10
- left: 100,
11
- width: 50,
12
- label: undefined,
13
- visibility: "hidden",
14
- possibleLabels: [],
15
- };
16
- this.inputGroupRef = React.createRef();
17
- }
18
-
19
- componentWillMount() {
20
- this.setPosition();
21
- }
22
-
23
- componentDidUpdate(prevProps) {
24
- if (this.props.visible) {
25
- this.setPosition();
26
- }
27
- }
28
-
29
- /*************
30
- * LOGIC *
31
- *************/
32
- setPosition() {
33
- if (this.props.selectedAnno) {
34
- // const center = transform.getCenter(this.props.selectedAnno.data, this.props.selectedAnno.type)
35
- // const annoBox = transform.getBox(this.props.selectedAnno.data, this.props.selectedAnno.type)
36
- let topPoint = transform.getTopPoint(this.props.selectedAnno.data);
37
- topPoint = transform.getMostLeftPoint(topPoint)[0];
38
- const inputRect = this.inputGroupRef.current.getBoundingClientRect();
39
- let top =
40
- this.props.svg.top +
41
- (topPoint.y + this.props.svg.translateY) * this.props.svg.scale -
42
- 44;
43
- let left =
44
- this.props.svg.left +
45
- (topPoint.x + this.props.svg.translateX) * this.props.svg.scale -
46
- inputRect.width / 2.0 -
47
- 1;
48
- // if (left < this.props.svg.left) left = this.props.svg.left
49
- // if (left+inputRect.width > this.props.svg.left+this.props.svg.width){
50
- // left = this.props.svg.left+this.props.svg.width - inputRect.width
51
- // }
52
- if (top < 0)
53
- top =
54
- this.props.svg.top +
55
- (topPoint.y + this.props.svg.translateY + 10) * this.props.svg.scale;
56
- if (this.state.top !== top || this.state.left !== left) {
57
- this.setState({
58
- top,
59
- left,
60
- // width: annoBox[1].x - annoBox[0].x
61
- });
62
- }
63
- }
64
- }
65
-
66
- onClose() {
67
- if (this.props.onClose) {
68
- this.props.onClose();
69
- }
70
- }
71
-
72
- handleClick(e) {
73
- if (this.props.onClick) {
74
- this.props.onClick(e);
75
- }
76
- }
77
-
78
- renderDaviIcon() {
79
- return (
80
- <svg
81
- version="1.1"
82
- xmlns="http://www.w3.org/2000/svg"
83
- // x="0px" y="0px"
84
- // width="1190.549px" height="841.891px"
85
- viewBox="0 0 1190.549 841.891"
86
- width="60px"
87
- onClick={(e) => this.handleClick(e)}
88
- >
89
- <g id="Info">
90
- <path
91
- id="Maps"
92
- fill={this.props.color}
93
- d="M620.561,817.217c-1.568-3.62-3.771-7.101-4.611-10.885
94
- c-24.452-109.811-74.341-207.569-139.215-298.675c-27.507-38.628-55.814-77.404-77.438-119.371
95
- C324.363,242.85,402.696,58.71,574.209,26.508c145.509-27.32,282.953,75.871,296.543,222.773
96
- c4.659,50.356-7.471,97.96-32.152,141.022c-27.812,48.526-58.75,95.364-90.073,141.758
97
- c-50.917,75.411-91.062,155.558-113.421,244.091c-2.438,9.652-3.936,19.543-6.271,29.227c-0.992,4.104-3.023,7.961-4.584,11.93
98
- C623.021,817.277,621.789,817.247,620.561,817.217z"
99
- />
100
- <path
101
- id="Text"
102
- fillRule="evenodd"
103
- clipRule="evenodd"
104
- fill="#FFFFFF"
105
- d="M724.709,250.898
106
- c-0.055-3.974,0.047-7.949,0.033-11.923c-0.007-1.228-1.54-2.767-2.76-2.777c-2.428-0.021-4.862-0.015-7.29-0.015
107
- c-22.466,0.001-44.934,0.005-67.404,0.009c-2.475,0.001-3.658,1.154-3.658,3.588c-0.001,47.365-0.001,94.73-0.001,142.096
108
- c0,13.526,0,27.05,0.001,40.577c0,2.305,1.274,3.584,3.562,3.59c6.623,0.004,9.256-0.07,19.873,0.004
109
- c10.618,0.072,14.146,8.543,14.146,14.189c-0.002,5.645-4.233,13.055-14.299,13.367c-13.135,0.061-26.277-0.02-39.414-0.014
110
- c-14.575,0.004-29.146,0.004-43.722,0.02c-4.191-0.084-13.717-2.789-13.717-13.492s6.233-13.643,13.132-14.117
111
- c4.979,0.037,13.802,0.057,20.701,0.049c1.695,0,3.11-1.537,3.11-3.361c0.003-13.912-0.004-27.823-0.004-41.736
112
- c0-30.252,0-60.503,0.002-90.754c0.002-17.03,0.005-33.649,0.002-50.678c0-1.991-1.38-3.336-3.396-3.336
113
- c-24.79,0-49.577,0-74.362,0c-2.133,0-3.38,1.22-3.383,3.308c-0.006,3.754-0.011,7.509,0.005,11.262
114
- c-0.023,6.339-3.067,13.143-12.456,13.143c-9.389,0-14.337-4.647-14.915-13.23c-0.128-4.305,0.004-8.612,0.004-12.918
115
- c0-8.392,0-16.781,0-25.173c0-0.321,0.228-5.156,4.091-9.277c3.864-4.122,8.014-3.822,8.445-3.822
116
- c25.835,0.003,51.672,0.002,77.507,0.002c46.813,0.001,140.443,0.001,140.443,0.001s6.153-0.088,10.926-0.052
117
- c0.3-0.008,5.713,0.363,9.178,3.994c3.46,3.631,3.046,8.407,3.046,8.635c-0.007,12.862,0.079,25.725-0.003,38.587
118
- c-0.074,8.051-6.938,12.819-13.703,12.847C731.482,263.519,724.956,259.059,724.709,250.898z"
119
- />
120
- </g>
121
- </svg>
122
- );
123
- }
124
-
125
- /*************
126
- * RENDERING *
127
- **************/
128
- render() {
129
- if (!this.props.visible) return null;
130
- return (
131
- <div
132
- ref={this.inputGroupRef}
133
- style={{
134
- position: "fixed",
135
- top: this.state.top,
136
- left: this.state.left,
137
- cursor: "pointer",
138
- }}
139
- >
140
- {/* <Button icon circular basic
141
- onClick={e => this.handleClick(e)}
142
- > */}
143
- {/* <Icon name="pencil"
144
- onClick={e => this.handleClick(e)}
145
- /> */}
146
- {/* </Button> */}
147
- {this.renderDaviIcon()}
148
- </div>
149
- );
150
- }
151
- }
152
-
153
- export default AnnoToolBar;
@@ -1,154 +0,0 @@
1
- import React, { Component } from "react";
2
- import * as transform from "../utils/transform";
3
- import * as modes from "../types/modes";
4
-
5
- const defaultFontSize = 10;
6
- const defaultRectHeight = 15;
7
-
8
- class AnnoBar extends Component {
9
- constructor(props) {
10
- super(props);
11
- this.state = {
12
- top: 0,
13
- left: 0,
14
- width: 50,
15
- height: defaultRectHeight,
16
- fontSize: defaultFontSize,
17
- };
18
- this.textRef = React.createRef();
19
- }
20
-
21
- /*************
22
- * EVENTS *
23
- **************/
24
- componentWillMount() {
25
- if (this.props.mode !== modes.CREATE) this.setPosition();
26
- }
27
-
28
- componentDidUpdate() {
29
- if (this.props.mode !== modes.CREATE) {
30
- this.setPosition();
31
- }
32
- }
33
-
34
- handleClick(e) {
35
- e.preventDefault();
36
- if (this.props.onClick) {
37
- this.props.onClick(e);
38
- }
39
- }
40
- /*************
41
- * LOGIC *
42
- *************/
43
- setPosition() {
44
- // const center = transform.getCenter(this.props.anno.data, this.props.anno.type)
45
- // const top = center.y
46
- // const left = center.x
47
- // if (this.state.top !== top || this.state.left !== left){
48
- // this.setState({
49
- // top,
50
- // left
51
- // })
52
- // }
53
- let topPoint = transform.getTopPoint(this.props.anno.data);
54
- topPoint = transform.getMostLeftPoint(topPoint)[0];
55
- if (this.textRef.current) {
56
- const text = this.textRef.current.getBoundingClientRect();
57
- const textPadding = 2;
58
- let rectWidth = (text.width + textPadding) / this.props.svg.scale;
59
- if (rectWidth !== this.state.width) {
60
- this.setState({
61
- width: rectWidth,
62
- fontSize: Math.ceil(defaultFontSize / this.props.svg.scale),
63
- // height: Math.ceil(defaultFontSize/this.props.svg.scale)
64
- });
65
- }
66
- }
67
- let top = topPoint.y - 10;
68
- let left = topPoint.x + 7;
69
- if (top < 0) top = topPoint.y + 10;
70
- if (this.state.top !== top || this.state.left !== left) {
71
- this.setState({
72
- top,
73
- left,
74
- // width: annoBox[1].x - annoBox[0].x
75
- });
76
- }
77
- }
78
-
79
- /*************
80
- * RENDERING *
81
- **************/
82
-
83
- render() {
84
- let label = "";
85
- if (!this.props.possibleLabels) return null;
86
- let labelObject;
87
- if (this.props.anno.labelIds && this.props.anno.labelIds.length > 0) {
88
- this.props.anno.labelIds.forEach((lbl, idx) => {
89
- labelObject = this.props.possibleLabels.find((el) => {
90
- return el.id === lbl;
91
- });
92
- if (idx > 0) label += ", ";
93
- label += labelObject.label;
94
- });
95
- } else {
96
- if (this.props.defaultLabel) {
97
- if (Number.isInteger(this.props.defaultLabel)) {
98
- labelObject = this.props.possibleLabels.find((el) => {
99
- return el.id === this.props.defaultLabel;
100
- });
101
- label = labelObject.label;
102
- } else {
103
- label = this.props.defaultLabel;
104
- }
105
- } else {
106
- label = "no label";
107
- }
108
- }
109
- switch (this.props.mode) {
110
- case modes.VIEW:
111
- return (
112
- <g>
113
- <rect
114
- x={this.state.left}
115
- y={this.state.top - 6}
116
- width={this.state.width}
117
- height={this.state.height}
118
- rx="5"
119
- opacity="0.5"
120
- style={this.props.style}
121
- />
122
- <text
123
- x={this.state.left}
124
- y={this.state.top}
125
- fill="white"
126
- onClick={(e) => this.handleClick(e)}
127
- textAnchor="start"
128
- alignmentBaseline="central"
129
- ref={this.textRef}
130
- fontSize={this.state.fontSize + "pt"}
131
- // textLength="50"
132
- // style={{...this.props.style, strokeWidth:1}}
133
- >
134
- {label}
135
- </text>
136
- {/* This second rect is to prevent text from getting marked */}
137
- <rect
138
- x={this.state.left}
139
- y={this.state.top - 6}
140
- width={this.state.width}
141
- height={this.state.height}
142
- rx="5"
143
- opacity="0.01"
144
- style={this.props.style}
145
- />
146
- </g>
147
- );
148
- default:
149
- return null;
150
- }
151
- }
152
- }
153
-
154
- export default AnnoBar;