@@ -10,34 +10,15 @@ import Select, { OptionProps } from 'antd/lib/select';
10
10
import Checkbox , { CheckboxChangeEvent } from 'antd/lib/checkbox' ;
11
11
import Tooltip from 'antd/lib/tooltip' ;
12
12
import Tag from 'antd/lib/tag' ;
13
- import notification from 'antd/lib/notification' ;
14
13
import Text from 'antd/lib/typography/Text' ;
15
14
import InputNumber from 'antd/lib/input-number' ;
16
-
17
- import { Model , StringObject } from 'reducers/interfaces' ;
18
15
import Button from 'antd/lib/button' ;
16
+ import notification from 'antd/lib/notification' ;
19
17
18
+ import { Model , StringObject } from 'reducers/interfaces' ;
20
19
21
- function colorGenerator ( ) : ( ) => string {
22
- const values = [
23
- 'magenta' , 'green' , 'geekblue' ,
24
- 'orange' , 'red' , 'cyan' ,
25
- 'blue' , 'volcano' , 'purple' ,
26
- ] ;
27
-
28
- let index = 0 ;
29
-
30
- return ( ) : string => {
31
- const color = values [ index ++ ] ;
32
- if ( index >= values . length ) {
33
- index = 0 ;
34
- }
35
-
36
- return color ;
37
- } ;
38
- }
39
20
40
- const nextColor = colorGenerator ( ) ;
21
+ import consts from 'consts' ;
41
22
42
23
interface Props {
43
24
withCleanup : boolean ;
@@ -56,7 +37,6 @@ function DetectorRunner(props: Props): JSX.Element {
56
37
57
38
const [ modelID , setModelID ] = useState < string | null > ( null ) ;
58
39
const [ mapping , setMapping ] = useState < StringObject > ( { } ) ;
59
- const [ colors , setColors ] = useState < StringObject > ( { } ) ;
60
40
const [ threshold , setThreshold ] = useState < number > ( 0.5 ) ;
61
41
const [ distance , setDistance ] = useState < number > ( 50 ) ;
62
42
const [ cleanup , setCleanup ] = useState < boolean > ( false ) ;
@@ -90,21 +70,15 @@ function DetectorRunner(props: Props): JSX.Element {
90
70
function updateMatch ( modelLabel : string | null , taskLabel : string | null ) : void {
91
71
if ( match . model && taskLabel ) {
92
72
const newmatch : { [ index : string ] : string } = { } ;
93
- const newcolor : { [ index : string ] : string } = { } ;
94
73
newmatch [ match . model ] = taskLabel ;
95
- newcolor [ match . model ] = nextColor ( ) ;
96
- setColors ( { ...colors , ...newcolor } ) ;
97
74
setMapping ( { ...mapping , ...newmatch } ) ;
98
75
setMatch ( { model : null , task : null } ) ;
99
76
return ;
100
77
}
101
78
102
79
if ( match . task && modelLabel ) {
103
80
const newmatch : { [ index : string ] : string } = { } ;
104
- const newcolor : { [ index : string ] : string } = { } ;
105
81
newmatch [ modelLabel ] = match . task ;
106
- newcolor [ modelLabel ] = nextColor ( ) ;
107
- setColors ( { ...colors , ...newcolor } ) ;
108
82
setMapping ( { ...mapping , ...newmatch } ) ;
109
83
setMatch ( { model : null , task : null } ) ;
110
84
return ;
@@ -157,18 +131,15 @@ function DetectorRunner(props: Props): JSX.Element {
157
131
onChange = { ( _modelID : string ) : void => {
158
132
const newmodel = models
159
133
. filter ( ( _model ) : boolean => _model . id === _modelID ) [ 0 ] ;
160
- const newcolors : StringObject = { } ;
161
134
const newmapping = task . labels
162
135
. reduce ( ( acc : StringObject , label : any ) : StringObject => {
163
136
if ( newmodel . labels . includes ( label . name ) ) {
164
137
acc [ label . name ] = label . name ;
165
- newcolors [ label . name ] = nextColor ( ) ;
166
138
}
167
139
return acc ;
168
140
} , { } ) ;
169
141
170
142
setMapping ( newmapping ) ;
171
- setColors ( newcolors ) ;
172
143
setMatch ( { model : null , task : null } ) ;
173
144
setModelID ( _modelID ) ;
174
145
} }
@@ -180,29 +151,34 @@ function DetectorRunner(props: Props): JSX.Element {
180
151
</ Col >
181
152
</ Row >
182
153
{ isDetector && ! ! Object . keys ( mapping ) . length && (
183
- Object . keys ( mapping ) . map ( ( modelLabel : string ) => (
184
- < Row key = { modelLabel } type = 'flex' justify = 'start' align = 'middle' >
185
- < Col span = { 10 } >
186
- < Tag color = { colors [ modelLabel ] } > { modelLabel } </ Tag >
187
- </ Col >
188
- < Col span = { 10 } offset = { 1 } >
189
- < Tag color = { colors [ modelLabel ] } > { mapping [ modelLabel ] } </ Tag >
190
- </ Col >
191
- < Col offset = { 1 } >
192
- < Tooltip title = 'Remove the mapped values' mouseLeaveDelay = { 0 } >
193
- < Icon
194
- className = 'cvat-danger-circle-icon'
195
- type = 'close-circle'
196
- onClick = { ( ) : void => {
197
- const newmapping = { ...mapping } ;
198
- delete newmapping [ modelLabel ] ;
199
- setMapping ( newmapping ) ;
200
- } }
201
- />
202
- </ Tooltip >
203
- </ Col >
204
- </ Row >
205
- ) )
154
+ Object . keys ( mapping ) . map ( ( modelLabel : string ) => {
155
+ const label = task . labels
156
+ . filter ( ( _label : any ) : boolean => _label . name === mapping [ modelLabel ] ) [ 0 ] ;
157
+ const color = label ? label . color : consts . NEW_LABEL_COLOR ;
158
+ return (
159
+ < Row key = { modelLabel } type = 'flex' justify = 'start' align = 'middle' >
160
+ < Col span = { 10 } >
161
+ < Tag color = { color } > { modelLabel } </ Tag >
162
+ </ Col >
163
+ < Col span = { 10 } offset = { 1 } >
164
+ < Tag color = { color } > { mapping [ modelLabel ] } </ Tag >
165
+ </ Col >
166
+ < Col offset = { 1 } >
167
+ < Tooltip title = 'Remove the mapped values' mouseLeaveDelay = { 0 } >
168
+ < Icon
169
+ className = 'cvat-danger-circle-icon'
170
+ type = 'close-circle'
171
+ onClick = { ( ) : void => {
172
+ const newmapping = { ...mapping } ;
173
+ delete newmapping [ modelLabel ] ;
174
+ setMapping ( newmapping ) ;
175
+ } }
176
+ />
177
+ </ Tooltip >
178
+ </ Col >
179
+ </ Row >
180
+ ) ;
181
+ } )
206
182
) }
207
183
{ isDetector && ! ! taskLabels . length && ! ! modelLabels . length && (
208
184
< >
0 commit comments