lost-sia 1.3.0 → 2.0.0-alpha0

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 (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/package.json +60 -47
  4. package/src/AnnoExampleViewer.jsx +57 -0
  5. package/src/AnnoLabelInput.jsx +99 -0
  6. package/src/AnnoToolBar.jsx +132 -0
  7. package/src/Annotation/AnnoBar.jsx +148 -0
  8. package/src/Annotation/Annotation.jsx +358 -0
  9. package/src/Annotation/Annotation.scss +47 -0
  10. package/src/Annotation/BBox.jsx +291 -0
  11. package/src/Annotation/Edge.jsx +82 -0
  12. package/src/Annotation/InfSelectionArea.jsx +71 -0
  13. package/src/Annotation/Line.jsx +60 -0
  14. package/src/Annotation/Node.jsx +278 -0
  15. package/src/Annotation/Point.jsx +196 -0
  16. package/src/Annotation/Polygon.jsx +361 -0
  17. package/src/Canvas.jsx +1839 -0
  18. package/src/ImgBar.jsx +123 -0
  19. package/src/InfoBoxes/AnnoDetails.jsx +166 -0
  20. package/src/InfoBoxes/AnnoStats.jsx +104 -0
  21. package/src/InfoBoxes/InfoBox.jsx +78 -0
  22. package/src/InfoBoxes/InfoBoxArea.jsx +155 -0
  23. package/src/InfoBoxes/LabelInfo.jsx +95 -0
  24. package/src/LabelInput.jsx +224 -0
  25. package/src/Prompt.jsx +46 -0
  26. package/src/SIA.scss +10 -0
  27. package/src/SIAFilterButton.jsx +178 -0
  28. package/src/SIASettingButton.jsx +122 -0
  29. package/src/Sia.jsx +485 -0
  30. package/src/SiaPopup.jsx +10 -0
  31. package/src/ToolBar.jsx +399 -0
  32. package/src/Toolbar.css +13 -0
  33. package/src/ToolbarItem.jsx +25 -0
  34. package/src/filterTools.js +3 -0
  35. package/src/index.js +17 -0
  36. package/src/siaDummyData.js +265 -0
  37. package/src/test.js +7 -0
  38. package/src/types/annoStatus.js +4 -0
  39. package/src/types/canvasActions.js +57 -0
  40. package/src/types/cursorstyles.js +3 -0
  41. package/src/types/modes.js +8 -0
  42. package/src/types/notificationType.js +4 -0
  43. package/src/types/toolbarEvents.js +33 -0
  44. package/src/types/tools.js +11 -0
  45. package/src/utils/annoConversion.js +115 -0
  46. package/src/utils/colorlut.js +67 -0
  47. package/src/utils/constraints.js +75 -0
  48. package/src/utils/hist.js +67 -0
  49. package/src/utils/keyActions.js +107 -0
  50. package/src/utils/mouse.js +14 -0
  51. package/src/utils/siaIcons.jsx +95 -0
  52. package/src/utils/transform.js +318 -0
  53. package/src/utils/uiConfig.js +57 -0
  54. package/src/utils/windowViewport.js +35 -0
  55. package/CHANGELOG.md +0 -169
  56. package/dist/index.css +0 -24823
  57. package/dist/index.es.js +0 -10482
  58. package/dist/index.es.js.map +0 -1
  59. package/dist/index.js +0 -10497
  60. package/dist/index.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Jonas Jäger & Gereon Reus.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
File without changes
package/package.json CHANGED
@@ -1,63 +1,76 @@
1
1
  {
2
2
  "name": "lost-sia",
3
- "version": "1.3.0",
4
- "description": "Single Image Annotation Tool for LOST",
5
- "author": "l3p-cv",
3
+ "version": "2.0.0-alpha0",
4
+ "description": "Single Image Annotation Tool",
6
5
  "license": "MIT",
7
- "repository": "l3p-cv/lost",
6
+ "repository": "l3p-cv/lost-sia",
8
7
  "main": "dist/index.js",
9
8
  "module": "dist/index.es.js",
10
9
  "jsnext:main": "dist/index.es.js",
10
+ "type": "module",
11
+ "keywords": [
12
+ "lost",
13
+ "annotation",
14
+ "image annotation",
15
+ "react annotation tool"
16
+ ],
11
17
  "engines": {
12
- "node": ">=8",
13
- "npm": ">=5"
18
+ "node": ">=18",
19
+ "npm": ">=8"
14
20
  },
21
+ "exports": {
22
+ ".": {
23
+ "import": "./src/index.js",
24
+ "require": "./src/index.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "src"
29
+ ],
15
30
  "scripts": {
16
- "test": "cross-env CI=1 react-scripts test --env=jsdom",
17
- "test:watch": "react-scripts test --env=jsdom",
18
- "build": "rollup -c",
19
- "start": "rollup -c -w",
20
- "prepare": "npm run build"
31
+ "build": "vite build",
32
+ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
33
+ "preview": "vite preview",
34
+ "publishpkg": "npm publish",
35
+ "test": "vitest run"
36
+ },
37
+ "dependencies": {
38
+ "@coreui/react": "^5.0.0",
39
+ "@fortawesome/free-regular-svg-icons": "^6.5.2",
40
+ "@fortawesome/free-solid-svg-icons": "^6.5.2",
41
+ "@fortawesome/react-fontawesome": "^0.2.0",
42
+ "react": "^18.0.0",
43
+ "react-dom": "^18.0.0",
44
+ "react-draggable": "^4.4.6",
45
+ "sass": "^1.77.1",
46
+ "semantic-ui-css": "2.5.0",
47
+ "semantic-ui-react": "^2.0.3"
21
48
  },
22
49
  "peerDependencies": {
23
- "prop-types": "^15.5.4",
24
- "react": "^15.0.0 || ^16.0.0",
25
- "react-dom": "^15.0.0 || ^16.0.0",
26
50
  "lodash": "^4.17.15",
27
- "semantic-ui-react": "^2.0.3"
51
+ "prop-types": "^15.5.4",
52
+ "react": "^18.0.0",
53
+ "react-dom": "^18.0.0"
28
54
  },
29
55
  "devDependencies": {
30
- "@svgr/rollup": "^2.4.1",
31
- "babel-core": "^6.26.3",
32
- "babel-eslint": "^8.2.5",
33
- "babel-plugin-external-helpers": "^6.22.0",
34
- "babel-preset-env": "^1.7.0",
35
- "babel-preset-react": "^6.24.1",
36
- "babel-preset-stage-0": "^6.24.1",
37
- "cross-env": "^5.1.4",
38
- "eslint": "^5.0.1",
39
- "eslint-config-standard": "^11.0.0",
40
- "eslint-config-standard-react": "^6.0.0",
41
- "eslint-plugin-import": "^2.13.0",
42
- "eslint-plugin-node": "^7.0.1",
43
- "eslint-plugin-promise": "^4.0.0",
44
- "eslint-plugin-react": "^7.10.0",
45
- "eslint-plugin-standard": "^3.1.0",
46
- "gh-pages": "^1.2.0",
47
- "node-sass": "^4.13.1",
48
- "react": "^16.4.1",
49
- "react-dom": "^16.4.1",
50
- "react-scripts": "^1.1.4",
51
- "rollup": "^0.64.1",
52
- "rollup-plugin-babel": "^3.0.7",
53
- "rollup-plugin-commonjs": "^9.1.3",
54
- "rollup-plugin-node-resolve": "^3.3.0",
55
- "rollup-plugin-peer-deps-external": "^2.2.0",
56
- "rollup-plugin-postcss": "^1.6.2",
57
- "rollup-plugin-scss": "^2.1.0",
58
- "rollup-plugin-url": "^1.4.0"
56
+ "@vitejs/plugin-react": "^4.3.0",
57
+ "cross-env": "^7.0.3",
58
+ "eslint": "^8.0.1",
59
+ "eslint-config-standard": "^17.1.0",
60
+ "eslint-config-standard-react": "^13.0.0",
61
+ "eslint-plugin-import": "^2.29.1",
62
+ "eslint-plugin-node": "^11.1.0",
63
+ "eslint-plugin-promise": "^6.2.0",
64
+ "eslint-plugin-react": "^7.34.2",
65
+ "eslint-plugin-standard": "^5.0.0",
66
+ "glob": "^10.4.1",
67
+ "vite": "^5.2.12",
68
+ "vitest": "^1.6.0"
59
69
  },
60
- "files": [
61
- "dist"
62
- ]
70
+ "eslintConfig": {
71
+ "extends": [
72
+ "plugin:storybook/recommended",
73
+ "plugin:storybook/recommended"
74
+ ]
75
+ }
63
76
  }
@@ -0,0 +1,57 @@
1
+ import Prompt from './Prompt'
2
+ import React from 'react'
3
+ import { Card, Divider, Header, Image } from 'semantic-ui-react'
4
+
5
+ const LabelExampleViewer = (props) => {
6
+
7
+ const requestExample = (e) => {
8
+ e.stopPropagation()
9
+ if (props.onRequestExample){
10
+ props.onRequestExample()
11
+ }
12
+ }
13
+ const renderContent = () => {
14
+ if (!props.lbl) return null
15
+ if (!props.exampleImg) return null
16
+ const description = <div>
17
+ {/* <Divider horizontal> Description </Divider> */}
18
+ {props.lbl.description}
19
+ <Divider horizontal> comment </Divider>
20
+ { props.exampleImg.anno ? props.exampleImg.anno.comment : "no comment" }
21
+ </div>
22
+ return <div>
23
+ <Card
24
+
25
+ // image={props.exampleImg.img}
26
+ // description={props.lbl.description}
27
+ // header={props.lbl.label}
28
+ // // description={props.exampleImg.anno.comment}
29
+ // extra={props.exampleImg.anno.comment}
30
+ >
31
+ <Image onClick={(e) => requestExample(e)} src={props.exampleImg.img} wrapped ui={false} />
32
+ <Card.Content>
33
+ <Card.Header >{props.lbl.label}</Card.Header>
34
+ {/* <Card.Description>{props.lbl.description}</Card.Description> */}
35
+ <Card.Description>{description}</Card.Description>
36
+ {/* <Card.Description>{props.exampleImg.anno.comment}</Card.Description> */}
37
+ </Card.Content>
38
+ </Card>
39
+ {/* <Header inverted>{props.lbl.label}</Header>
40
+ {props.lbl.description}
41
+ <Image src={props.exampleImg.img} centered size='medium'></Image> */}
42
+ </div>
43
+ }
44
+
45
+ const handlePromptClick = () => {
46
+ if (props.onClose){
47
+ props.onClose()
48
+ }
49
+ }
50
+
51
+ return <Prompt onClick={() => {handlePromptClick()}}
52
+ active={props.active} content={renderContent()}
53
+ />
54
+
55
+ }
56
+
57
+ export default LabelExampleViewer
@@ -0,0 +1,99 @@
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
+
8
+ constructor(props) {
9
+ super(props)
10
+ this.state = {
11
+ top: 400,
12
+ left: 100,
13
+ label: undefined,
14
+ visibility: 'hidden',
15
+ possibleLabels: []
16
+ }
17
+ this.inputGroupRef = React.createRef()
18
+ }
19
+
20
+ componentWillMount() {
21
+ this.setPosition()
22
+ }
23
+
24
+ componentDidUpdate(prevProps) {
25
+ if (this.props.visible) {
26
+ this.setPosition()
27
+ }
28
+
29
+
30
+ }
31
+
32
+ /*************
33
+ * LOGIC *
34
+ *************/
35
+ setPosition() {
36
+
37
+ if (this.props.mousePos) {
38
+ const top = this.props.mousePos.y + this.props.svg.top - 10
39
+ const left = this.props.mousePos.x + this.props.svg.left - 10
40
+ if (this.state.top !== top || this.state.left !== left) {
41
+ this.setState({
42
+ top: top,
43
+ left: left,
44
+ })
45
+ }
46
+ }
47
+ }
48
+
49
+ onClose() {
50
+ if (this.props.onClose) {
51
+ this.props.onClose()
52
+ }
53
+ }
54
+
55
+ annoLabelUpdate(anno) {
56
+ if (this.props.onLabelUpdate) {
57
+ this.props.onLabelUpdate(anno)
58
+ }
59
+ }
60
+
61
+ updateAnnoLabel(label) {
62
+ if (!constraints.allowedToLabel(
63
+ this.props.allowedActions, this.props.selectedAnno)) return
64
+ this.annoLabelUpdate({
65
+ ...this.props.selectedAnno,
66
+ labelIds: label,
67
+ status: this.props.selectedAnno.status !== annoStatus.NEW ? annoStatus.CHANGED : annoStatus.NEW
68
+ })
69
+ }
70
+
71
+
72
+ /*************
73
+ * RENDERING *
74
+ **************/
75
+ render() {
76
+ if (!this.props.visible) return null
77
+ return (
78
+ <div ref={this.inputGroupRef} style={{ position: 'fixed', top: this.state.top, left: this.state.left }}>
79
+ <LabelInput svg={this.props.svg}
80
+ onClose={() => this.onClose()}
81
+ initLabelIds={this.props.selectedAnno.labelIds}
82
+ relatedId={this.props.selectedAnno.id}
83
+ visible={this.props.visible}
84
+ onLabelUpdate={label => this.updateAnnoLabel(label)}
85
+ possibleLabelsProp={this.props.possibleLabels}
86
+ multilabels={this.props.multilabels}
87
+ disabled={!this.props.allowedActions.label}
88
+ renderPopup
89
+ focusOnRender
90
+ open={true}
91
+ defaultLabel={this.props.defaultLabel}
92
+ />
93
+ </div>
94
+ )
95
+ }
96
+
97
+ }
98
+
99
+ export default AnnoLabelInput
@@ -0,0 +1,132 @@
1
+ import React, {Component} from 'react'
2
+
3
+ import * as transform from './utils/transform'
4
+
5
+ class AnnoToolBar extends Component{
6
+
7
+ constructor(props){
8
+ super(props)
9
+ this.state = {
10
+ top: 400,
11
+ left: 100,
12
+ width: 50,
13
+ label: undefined,
14
+ visibility: 'hidden',
15
+ possibleLabels: []
16
+ }
17
+ this.inputGroupRef = React.createRef()
18
+ }
19
+
20
+ componentWillMount(){
21
+ this.setPosition()
22
+ }
23
+
24
+ componentDidUpdate(prevProps){
25
+ if (this.props.visible){
26
+ this.setPosition()
27
+ }
28
+
29
+
30
+ }
31
+
32
+ /*************
33
+ * LOGIC *
34
+ *************/
35
+ setPosition(){
36
+ if (this.props.selectedAnno){
37
+ // const center = transform.getCenter(this.props.selectedAnno.data, this.props.selectedAnno.type)
38
+ // const annoBox = transform.getBox(this.props.selectedAnno.data, this.props.selectedAnno.type)
39
+ let topPoint = transform.getTopPoint(this.props.selectedAnno.data)
40
+ topPoint = transform.getMostLeftPoint(topPoint)[0]
41
+ const inputRect = this.inputGroupRef.current.getBoundingClientRect()
42
+ let top = this.props.svg.top + (topPoint.y + this.props.svg.translateY) *this.props.svg.scale - 44
43
+ let left = this.props.svg.left + (topPoint.x + this.props.svg.translateX) *this.props.svg.scale - inputRect.width /2.0 - 1
44
+ // if (left < this.props.svg.left) left = this.props.svg.left
45
+ // if (left+inputRect.width > this.props.svg.left+this.props.svg.width){
46
+ // left = this.props.svg.left+this.props.svg.width - inputRect.width
47
+ // }
48
+ if (top < 0) top = this.props.svg.top + (topPoint.y + this.props.svg.translateY + 10) *this.props.svg.scale
49
+ if (this.state.top !== top || this.state.left !== left){
50
+ this.setState({
51
+ top,
52
+ left,
53
+ // width: annoBox[1].x - annoBox[0].x
54
+ })
55
+ }
56
+ }
57
+ }
58
+
59
+ onClose(){
60
+ if (this.props.onClose){
61
+ this.props.onClose()
62
+ }
63
+ }
64
+
65
+ handleClick(e){
66
+ if (this.props.onClick){
67
+ this.props.onClick(e)
68
+ }
69
+ }
70
+
71
+ renderDaviIcon(){
72
+ return <svg version="1.1" xmlns="http://www.w3.org/2000/svg"
73
+ // x="0px" y="0px"
74
+ // width="1190.549px" height="841.891px"
75
+ viewBox="0 0 1190.549 841.891"
76
+ width="60px"
77
+ onClick={e => this.handleClick(e)}
78
+ >
79
+ <g id="Info">
80
+ <path id="Maps" fill={this.props.color} d="M620.561,817.217c-1.568-3.62-3.771-7.101-4.611-10.885
81
+ 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
82
+ C324.363,242.85,402.696,58.71,574.209,26.508c145.509-27.32,282.953,75.871,296.543,222.773
83
+ c4.659,50.356-7.471,97.96-32.152,141.022c-27.812,48.526-58.75,95.364-90.073,141.758
84
+ 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
85
+ C623.021,817.277,621.789,817.247,620.561,817.217z"/>
86
+ <path id="Text" fillRule="evenodd" clipRule="evenodd" fill="#FFFFFF" d="M724.709,250.898
87
+ 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
88
+ 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
89
+ 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
90
+ 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
91
+ 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
92
+ 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
93
+ 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
94
+ 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
95
+ 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
96
+ 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
97
+ 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
98
+ 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
99
+ c-0.074,8.051-6.938,12.819-13.703,12.847C731.482,263.519,724.956,259.059,724.709,250.898z"/>
100
+ </g>
101
+ </svg>
102
+ }
103
+
104
+ /*************
105
+ * RENDERING *
106
+ **************/
107
+ render(){
108
+ if (!this.props.visible) return null
109
+ return (
110
+ <div ref={this.inputGroupRef}
111
+ style={{
112
+ position:'fixed',
113
+ top:this.state.top,
114
+ left:this.state.left,
115
+ cursor: 'pointer',
116
+ }}
117
+ >
118
+ {/* <Button icon circular basic
119
+ onClick={e => this.handleClick(e)}
120
+ > */}
121
+ {/* <Icon name="pencil"
122
+ onClick={e => this.handleClick(e)}
123
+ /> */}
124
+ {/* </Button> */}
125
+ {this.renderDaviIcon()}
126
+ </div>
127
+ )
128
+ }
129
+
130
+ }
131
+
132
+ export default AnnoToolBar
@@ -0,0 +1,148 @@
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
+
10
+ constructor(props) {
11
+ super(props)
12
+ this.state = {
13
+ top: 0,
14
+ left: 0,
15
+ width: 50,
16
+ height: defaultRectHeight,
17
+ fontSize: defaultFontSize,
18
+ }
19
+ this.textRef = React.createRef()
20
+ }
21
+
22
+ /*************
23
+ * EVENTS *
24
+ **************/
25
+ componentWillMount() {
26
+ if (this.props.mode !== modes.CREATE) this.setPosition()
27
+ }
28
+
29
+ componentDidUpdate() {
30
+ if (this.props.mode !== modes.CREATE) {
31
+ this.setPosition()
32
+ }
33
+ }
34
+
35
+ handleClick(e) {
36
+ e.preventDefault()
37
+ if (this.props.onClick) {
38
+ this.props.onClick(e)
39
+ }
40
+ }
41
+ /*************
42
+ * LOGIC *
43
+ *************/
44
+ setPosition() {
45
+ // const center = transform.getCenter(this.props.anno.data, this.props.anno.type)
46
+ // const top = center.y
47
+ // const left = center.x
48
+ // if (this.state.top !== top || this.state.left !== left){
49
+ // this.setState({
50
+ // top,
51
+ // left
52
+ // })
53
+ // }
54
+ let topPoint = transform.getTopPoint(this.props.anno.data)
55
+ topPoint = transform.getMostLeftPoint(topPoint)[0]
56
+ if (this.textRef.current) {
57
+ const text = this.textRef.current.getBoundingClientRect()
58
+ const textPadding = 2
59
+ let rectWidth = (text.width + textPadding) / this.props.svg.scale
60
+ if (rectWidth !== this.state.width) {
61
+ this.setState({
62
+ width: rectWidth,
63
+ fontSize: Math.ceil(defaultFontSize / this.props.svg.scale),
64
+ // height: Math.ceil(defaultFontSize/this.props.svg.scale)
65
+ })
66
+ }
67
+ }
68
+ let top = topPoint.y - 10
69
+ let left = topPoint.x + 7
70
+ if (top < 0) top = topPoint.y + 10
71
+ if (this.state.top !== top || this.state.left !== left) {
72
+ this.setState({
73
+ top,
74
+ left,
75
+ // width: annoBox[1].x - annoBox[0].x
76
+ })
77
+ }
78
+ }
79
+
80
+ /*************
81
+ * RENDERING *
82
+ **************/
83
+
84
+
85
+ render() {
86
+ let label = ''
87
+ if (!this.props.possibleLabels) return null
88
+ let labelObject
89
+ if (this.props.anno.labelIds && this.props.anno.labelIds.length > 0) {
90
+ this.props.anno.labelIds.forEach((lbl, idx) => {
91
+ labelObject = this.props.possibleLabels.find(el => {
92
+ return el.id === lbl
93
+ })
94
+ if (idx > 0) label += ', '
95
+ label += labelObject.label
96
+ })
97
+ } else {
98
+ if (this.props.defaultLabel) {
99
+ if (Number.isInteger(this.props.defaultLabel)) {
100
+ labelObject = this.props.possibleLabels.find(el => {
101
+ return el.id === this.props.defaultLabel
102
+ })
103
+ label = labelObject.label
104
+ } else {
105
+ label = this.props.defaultLabel
106
+ }
107
+ } else {
108
+ label = 'no label'
109
+ }
110
+ }
111
+ switch (this.props.mode) {
112
+ case modes.VIEW:
113
+ return (<g>
114
+ <rect x={this.state.left} y={this.state.top - 6}
115
+ width={this.state.width} height={this.state.height} rx="5"
116
+ opacity='0.5'
117
+ style={this.props.style}
118
+ />
119
+ <text x={this.state.left} y={this.state.top}
120
+ fill="white"
121
+ onClick={e => this.handleClick(e)}
122
+ textAnchor="start"
123
+ alignmentBaseline="central"
124
+ ref={this.textRef}
125
+ fontSize={this.state.fontSize + "pt"}
126
+ // textLength="50"
127
+ // style={{...this.props.style, strokeWidth:1}}
128
+ >
129
+ {label}
130
+ </text>
131
+ {/* This second rect is to prevent text from getting marked */}
132
+ <rect x={this.state.left} y={this.state.top - 6}
133
+ width={this.state.width}
134
+ height={this.state.height} rx="5"
135
+ opacity='0.01'
136
+ style={this.props.style}
137
+ />
138
+ </g>
139
+ )
140
+ default:
141
+ return null
142
+ }
143
+
144
+ }
145
+
146
+ }
147
+
148
+ export default AnnoBar