@@ -32,6 +32,7 @@ import {
32
32
vectorLength , ShapeSizeElement , DrawnState , rotate2DPoints ,
33
33
readPointsFromShape , setupSkeletonEdges , makeSVGFromTemplate ,
34
34
imageDataToDataURL , expandChannels , stringifyPoints , zipChannels ,
35
+ composeShapeDimensions ,
35
36
} from './shared' ;
36
37
import {
37
38
CanvasModel , Geometry , UpdateReasons , FrameZoom , ActiveElement ,
@@ -2444,10 +2445,10 @@ export class CanvasViewImpl implements CanvasView, Listener {
2444
2445
shape . untransform ( ) ;
2445
2446
}
2446
2447
2447
- if (
2448
- state . points . length !== drawnState . points . length ||
2449
- state . points . some ( ( p : number , id : number ) : boolean => p !== drawnState . points [ id ] )
2450
- ) {
2448
+ const pointsUpdated = state . points . length !== drawnState . points . length ||
2449
+ state . points . some ( ( p : number , id : number ) : boolean => p !== drawnState . points [ id ] ) ;
2450
+
2451
+ if ( pointsUpdated ) {
2451
2452
if ( state . shapeType === 'mask' ) {
2452
2453
// if masks points were updated, draw from scratch
2453
2454
this . deleteObjects ( [ this . drawnStates [ + clientID ] ] ) ;
@@ -2493,9 +2494,12 @@ export class CanvasViewImpl implements CanvasView, Listener {
2493
2494
2494
2495
const stateDescriptions = state . descriptions ;
2495
2496
const drawnStateDescriptions = drawnState . descriptions ;
2497
+ const rotationUpdated = drawnState . rotation !== state . rotation ;
2496
2498
2497
2499
if (
2498
2500
drawnState . label . id !== state . label . id ||
2501
+ pointsUpdated ||
2502
+ rotationUpdated ||
2499
2503
drawnStateDescriptions . length !== stateDescriptions . length ||
2500
2504
drawnStateDescriptions . some ( ( desc : string , id : number ) : boolean => desc !== stateDescriptions [ id ] )
2501
2505
) {
@@ -3090,6 +3094,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
3090
3094
const withLabel = content . includes ( 'label' ) ;
3091
3095
const withSource = content . includes ( 'source' ) ;
3092
3096
const withDescriptions = content . includes ( 'descriptions' ) ;
3097
+ const withDimensions = content . includes ( 'dimensions' ) ;
3093
3098
const textFontSize = this . configuration . textFontSize || 12 ;
3094
3099
const {
3095
3100
label, clientID, attributes, source, descriptions,
@@ -3116,30 +3121,50 @@ export class CanvasViewImpl implements CanvasView, Listener {
3116
3121
`${ withSource ? `(${ source } )` : '' } ` ) . style ( {
3117
3122
'text-transform' : 'uppercase' ,
3118
3123
} ) ;
3124
+
3125
+ if ( withDimensions && [ 'rectangle' , 'ellipse' ] . includes ( state . shapeType ) ) {
3126
+ let width = state . points [ 2 ] - state . points [ 0 ] ;
3127
+ let height = state . points [ 3 ] - state . points [ 1 ] ;
3128
+
3129
+ if ( state . shapeType === 'ellipse' ) {
3130
+ width *= 2 ;
3131
+ height *= - 2 ;
3132
+ }
3133
+
3134
+ block
3135
+ . tspan ( composeShapeDimensions ( width , height , state . rotation ) )
3136
+ . attr ( {
3137
+ dy : '1.25em' ,
3138
+ x : 0 ,
3139
+ } )
3140
+ . addClass ( 'cvat_canvas_text_dimensions' ) ;
3141
+ }
3119
3142
if ( withDescriptions ) {
3120
- for ( const desc of descriptions ) {
3143
+ descriptions . forEach ( ( desc : string , idx : number ) => {
3121
3144
block
3122
3145
. tspan ( `${ desc } ` )
3123
3146
. attr ( {
3124
- dy : '1em' ,
3147
+ dy : idx === 0 ? '1.25em' : '1em' ,
3125
3148
x : 0 ,
3126
3149
} )
3127
3150
. addClass ( 'cvat_canvas_text_description' ) ;
3128
- }
3151
+ } ) ;
3129
3152
}
3130
3153
if ( withAttr ) {
3131
- for ( const attrID of Object . keys ( attributes ) ) {
3132
- const values = `${ attributes [ attrID ] === undefinedAttrValue ? '' : attributes [ attrID ] } ` . split ( '\n' ) ;
3154
+ Object . keys ( attributes ) . forEach ( ( attrID : string , idx : number ) => {
3155
+ const values = `${ attributes [ attrID ] === undefinedAttrValue ?
3156
+ '' : attributes [ attrID ] } `. split ( '\n' ) ;
3133
3157
const parent = block . tspan ( `${ attrNames [ attrID ] } : ` )
3134
- . attr ( { attrID, dy : '1em' , x : 0 } ) . addClass ( 'cvat_canvas_text_attribute' ) ;
3158
+ . attr ( { attrID, dy : idx === 0 ? '1.25em' : '1em' , x : 0 } )
3159
+ . addClass ( 'cvat_canvas_text_attribute' ) ;
3135
3160
values . forEach ( ( attrLine : string , index : number ) => {
3136
3161
parent
3137
3162
. tspan ( attrLine )
3138
3163
. attr ( {
3139
3164
dy : index === 0 ? 0 : '1em' ,
3140
3165
} ) ;
3141
3166
} ) ;
3142
- }
3167
+ } ) ;
3143
3168
}
3144
3169
} )
3145
3170
. move ( 0 , 0 )
0 commit comments