lost-sia 0.5.2 → 0.9.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/CHANGELOG.md +23 -0
- package/dist/index.css +2 -2
- package/dist/index.es.js +241 -67
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +241 -67
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,13 +9,13 @@ var _ = _interopDefault(require('lodash'));
|
|
|
9
9
|
|
|
10
10
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
11
11
|
|
|
12
|
-
function toSia(data, image, type) {
|
|
12
|
+
function toSia(data, image, type, imgOffset) {
|
|
13
13
|
switch (type) {
|
|
14
14
|
case 'bBox':
|
|
15
15
|
var w = image.width * data.w;
|
|
16
16
|
var h = image.height * data.h;
|
|
17
|
-
var x0 = image.width * data.x - w / 2.0;
|
|
18
|
-
var y0 = image.height * data.y - h / 2.0;
|
|
17
|
+
var x0 = imgOffset.x + image.width * data.x - w / 2.0;
|
|
18
|
+
var y0 = imgOffset.y + image.height * data.y - h / 2.0;
|
|
19
19
|
return [{
|
|
20
20
|
x: x0,
|
|
21
21
|
y: y0
|
|
@@ -31,15 +31,15 @@ function toSia(data, image, type) {
|
|
|
31
31
|
}];
|
|
32
32
|
case 'point':
|
|
33
33
|
return [{
|
|
34
|
-
x: image.width * data.x,
|
|
35
|
-
y: image.height * data.y
|
|
34
|
+
x: imgOffset.x + image.width * data.x,
|
|
35
|
+
y: imgOffset.y + image.height * data.y
|
|
36
36
|
}];
|
|
37
37
|
case 'line':
|
|
38
38
|
case 'polygon':
|
|
39
39
|
return data.map(function (e) {
|
|
40
40
|
return {
|
|
41
|
-
x: image.width * e.x,
|
|
42
|
-
y: image.height * e.y
|
|
41
|
+
x: imgOffset.x + image.width * e.x,
|
|
42
|
+
y: imgOffset.y + image.height * e.y
|
|
43
43
|
};
|
|
44
44
|
});
|
|
45
45
|
default:
|
|
@@ -51,17 +51,21 @@ function toSia(data, image, type) {
|
|
|
51
51
|
* Transform a sia annotation to backend format.
|
|
52
52
|
*
|
|
53
53
|
* @param {Array} data Annotation data
|
|
54
|
-
* @param {*}
|
|
54
|
+
* @param {*} svg Image object {width, height}
|
|
55
55
|
* @param {String} type Type of the annotation bBox, point, line, polygon
|
|
56
56
|
* @returns Annotation data in backend style (relative, centered)
|
|
57
57
|
*/
|
|
58
|
-
function toBackend(data,
|
|
58
|
+
function toBackend(data, svg, type) {
|
|
59
|
+
var imgOffset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { x: 0, y: 0 };
|
|
60
|
+
|
|
61
|
+
var imgWidth = svg.width - 2 * imgOffset.x;
|
|
62
|
+
var imgHeight = svg.height - 2 * imgOffset.y;
|
|
59
63
|
switch (type) {
|
|
60
64
|
case 'bBox':
|
|
61
|
-
// const w =
|
|
62
|
-
// const h =
|
|
63
|
-
// const x0 =
|
|
64
|
-
// const y0 =
|
|
65
|
+
// const w = svg.width * data.w
|
|
66
|
+
// const h = svg.height * data.h
|
|
67
|
+
// const x0 = svg.width * data.x - w/2.0
|
|
68
|
+
// const y0 = svg.height * data.y - h/2.0
|
|
65
69
|
|
|
66
70
|
// console.error('GO On Here! w = max_x - min_x; h = max_y - min_y')
|
|
67
71
|
var xList = data.map(function (e) {
|
|
@@ -70,30 +74,30 @@ function toBackend(data, image, type) {
|
|
|
70
74
|
var yList = data.map(function (e) {
|
|
71
75
|
return e.y;
|
|
72
76
|
});
|
|
73
|
-
var minX = Math.min.apply(Math, _toConsumableArray(xList));
|
|
74
|
-
var maxX = Math.max.apply(Math, _toConsumableArray(xList));
|
|
75
|
-
var minY = Math.min.apply(Math, _toConsumableArray(yList));
|
|
76
|
-
var maxY = Math.max.apply(Math, _toConsumableArray(yList));
|
|
77
|
+
var minX = Math.min.apply(Math, _toConsumableArray(xList)) - imgOffset.x;
|
|
78
|
+
var maxX = Math.max.apply(Math, _toConsumableArray(xList)) - imgOffset.x;
|
|
79
|
+
var minY = Math.min.apply(Math, _toConsumableArray(yList)) - imgOffset.y;
|
|
80
|
+
var maxY = Math.max.apply(Math, _toConsumableArray(yList)) - imgOffset.y;
|
|
77
81
|
var w = maxX - minX;
|
|
78
82
|
var h = maxY - minY;
|
|
79
83
|
var x = minX + w / 2.0;
|
|
80
84
|
var y = minY + h / 2.0;
|
|
81
85
|
return {
|
|
82
|
-
x: x /
|
|
83
|
-
y: y /
|
|
84
|
-
w: w /
|
|
85
|
-
h: h /
|
|
86
|
+
x: x / imgWidth,
|
|
87
|
+
y: y / imgHeight,
|
|
88
|
+
w: w / imgWidth,
|
|
89
|
+
h: h / imgHeight };
|
|
86
90
|
case 'point':
|
|
87
91
|
return {
|
|
88
|
-
x: data[0].x /
|
|
89
|
-
y: data[0].y /
|
|
92
|
+
x: (data[0].x - imgOffset.x) / imgWidth,
|
|
93
|
+
y: (data[0].y - imgOffset.y) / imgHeight
|
|
90
94
|
};
|
|
91
95
|
case 'line':
|
|
92
96
|
case 'polygon':
|
|
93
97
|
return data.map(function (e) {
|
|
94
98
|
return {
|
|
95
|
-
x: e.x /
|
|
96
|
-
y: e.y /
|
|
99
|
+
x: (e.x - imgOffset.x) / imgWidth,
|
|
100
|
+
y: (e.y - imgOffset.y) / imgHeight
|
|
97
101
|
};
|
|
98
102
|
});
|
|
99
103
|
default:
|
|
@@ -2453,7 +2457,7 @@ var Annotation$1 = function (_Component) {
|
|
|
2453
2457
|
}, {
|
|
2454
2458
|
key: 'getColor',
|
|
2455
2459
|
value: function getColor$$1() {
|
|
2456
|
-
if (this.state.anno.labelIds.length > 0) {
|
|
2460
|
+
if (this.state.anno.labelIds && this.state.anno.labelIds.length > 0) {
|
|
2457
2461
|
return this.getLabel(this.state.anno.labelIds[0]).color;
|
|
2458
2462
|
} else {
|
|
2459
2463
|
return getDefaultColor();
|
|
@@ -3158,6 +3162,19 @@ var ImgBar = function (_Component) {
|
|
|
3158
3162
|
return null;
|
|
3159
3163
|
}
|
|
3160
3164
|
}
|
|
3165
|
+
}, {
|
|
3166
|
+
key: 'renderImgDescription',
|
|
3167
|
+
value: function renderImgDescription() {
|
|
3168
|
+
if (this.props.annos.image.description) {
|
|
3169
|
+
return React__default.createElement(
|
|
3170
|
+
semanticUiReact.Menu.Item,
|
|
3171
|
+
null,
|
|
3172
|
+
this.props.annos.image.description
|
|
3173
|
+
);
|
|
3174
|
+
} else {
|
|
3175
|
+
return null;
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3161
3178
|
}, {
|
|
3162
3179
|
key: 'render',
|
|
3163
3180
|
value: function render() {
|
|
@@ -3165,7 +3182,7 @@ var ImgBar = function (_Component) {
|
|
|
3165
3182
|
|
|
3166
3183
|
if (!this.props.visible) return null;
|
|
3167
3184
|
if (!this.props.annos.image) return null;
|
|
3168
|
-
if (!this.props.annos.image.url) return null
|
|
3185
|
+
// if (!this.props.annos.image.url) return null
|
|
3169
3186
|
return React__default.createElement(
|
|
3170
3187
|
'div',
|
|
3171
3188
|
{ style: {
|
|
@@ -3182,10 +3199,11 @@ var ImgBar = function (_Component) {
|
|
|
3182
3199
|
React__default.createElement(
|
|
3183
3200
|
semanticUiReact.Menu,
|
|
3184
3201
|
{ inverted: true, style: { opacity: 0.9, justifyContent: 'center', alignItems: 'center' } },
|
|
3202
|
+
this.renderImgDescription(),
|
|
3185
3203
|
React__default.createElement(
|
|
3186
3204
|
semanticUiReact.Menu.Item,
|
|
3187
3205
|
null,
|
|
3188
|
-
|
|
3206
|
+
"ID: " + this.props.annos.image.id
|
|
3189
3207
|
),
|
|
3190
3208
|
React__default.createElement(
|
|
3191
3209
|
semanticUiReact.Menu.Item,
|
|
@@ -3408,7 +3426,36 @@ var _extends$8 = Object.assign || function (target) { for (var i = 1; i < argume
|
|
|
3408
3426
|
|
|
3409
3427
|
function _toConsumableArray$3(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
3410
3428
|
|
|
3411
|
-
function
|
|
3429
|
+
function _fixBackendAnnoElement(element) {
|
|
3430
|
+
return _extends$8({}, element, {
|
|
3431
|
+
id: element.id ? element.id : _.uniqueId('new'),
|
|
3432
|
+
annoTime: element.annoTime ? element.annoTime : 0.0,
|
|
3433
|
+
mode: element.mode ? element.mode : VIEW,
|
|
3434
|
+
status: element.status ? element.status : DATABASE,
|
|
3435
|
+
labelIds: element.labelIds ? element.labelIds : []
|
|
3436
|
+
});
|
|
3437
|
+
}
|
|
3438
|
+
|
|
3439
|
+
function fixBackendAnnos(backendAnnos) {
|
|
3440
|
+
var annos = {
|
|
3441
|
+
bBoxes: [].concat(_toConsumableArray$3(backendAnnos.bBoxes.map(function (element) {
|
|
3442
|
+
return _fixBackendAnnoElement(element);
|
|
3443
|
+
}))),
|
|
3444
|
+
lines: [].concat(_toConsumableArray$3(backendAnnos.lines.map(function (element) {
|
|
3445
|
+
return _fixBackendAnnoElement(element);
|
|
3446
|
+
}))),
|
|
3447
|
+
polygons: [].concat(_toConsumableArray$3(backendAnnos.polygons.map(function (element) {
|
|
3448
|
+
return _fixBackendAnnoElement(element);
|
|
3449
|
+
}))),
|
|
3450
|
+
points: [].concat(_toConsumableArray$3(backendAnnos.points.map(function (element) {
|
|
3451
|
+
return _fixBackendAnnoElement(element);
|
|
3452
|
+
})))
|
|
3453
|
+
};
|
|
3454
|
+
console.log('fixBackendAnnos', annos);
|
|
3455
|
+
return annos;
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3458
|
+
function backendAnnosToCanvas(backendAnnos, imgSize, imgOffset) {
|
|
3412
3459
|
var annos = [].concat(_toConsumableArray$3(backendAnnos.bBoxes.map(function (element) {
|
|
3413
3460
|
return _extends$8({}, element, { type: 'bBox',
|
|
3414
3461
|
mode: element.mode ? element.mode : VIEW,
|
|
@@ -3429,7 +3476,7 @@ function backendAnnosToCanvas(backendAnnos, imgSize) {
|
|
|
3429
3476
|
})));
|
|
3430
3477
|
annos = annos.map(function (el) {
|
|
3431
3478
|
return _extends$8({}, el, {
|
|
3432
|
-
data: toSia(el.data, imgSize, el.type) });
|
|
3479
|
+
data: toSia(el.data, imgSize, el.type, imgOffset) });
|
|
3433
3480
|
});
|
|
3434
3481
|
// this.setState({annos: [...annos]})
|
|
3435
3482
|
return annos;
|
|
@@ -3437,6 +3484,7 @@ function backendAnnosToCanvas(backendAnnos, imgSize) {
|
|
|
3437
3484
|
|
|
3438
3485
|
function canvasToBackendAnnos(annos, imgSize) {
|
|
3439
3486
|
var forBackendPost = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
3487
|
+
var imgOffset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { x: 0, y: 0 };
|
|
3440
3488
|
|
|
3441
3489
|
var myAnnos = annos;
|
|
3442
3490
|
var bAnnos = myAnnos.map(function (el) {
|
|
@@ -3452,7 +3500,7 @@ function canvasToBackendAnnos(annos, imgSize) {
|
|
|
3452
3500
|
return _extends$8({}, el, {
|
|
3453
3501
|
id: annoId,
|
|
3454
3502
|
mode: VIEW,
|
|
3455
|
-
data: toBackend(el.data, imgSize, el.type)
|
|
3503
|
+
data: toBackend(el.data, imgSize, el.type, imgOffset)
|
|
3456
3504
|
});
|
|
3457
3505
|
});
|
|
3458
3506
|
|
|
@@ -3491,6 +3539,8 @@ var CAM_MOVE_RIGHT = 'camMoveRight';
|
|
|
3491
3539
|
var CAM_MOVE_STOP = 'camMoveStop';
|
|
3492
3540
|
var COPY_ANNOTATION = 'copyAnnotation';
|
|
3493
3541
|
var PASTE_ANNOTATION = 'pasteAnnotation';
|
|
3542
|
+
var RECREATE_ANNO = 'recreateAnnotation';
|
|
3543
|
+
var DELETE_ANNO_IN_CREATION = 'deleteAnnoInCreation';
|
|
3494
3544
|
|
|
3495
3545
|
var KeyMapper = function () {
|
|
3496
3546
|
function KeyMapper() {
|
|
@@ -3544,6 +3594,9 @@ var KeyMapper = function () {
|
|
|
3544
3594
|
case 'd':
|
|
3545
3595
|
this.triggerKeyAction(CAM_MOVE_RIGHT);
|
|
3546
3596
|
break;
|
|
3597
|
+
case 'e':
|
|
3598
|
+
this.triggerKeyAction(RECREATE_ANNO);
|
|
3599
|
+
break;
|
|
3547
3600
|
case 'c':
|
|
3548
3601
|
if (this.controlDown) {
|
|
3549
3602
|
this.triggerKeyAction(COPY_ANNOTATION);
|
|
@@ -3554,6 +3607,9 @@ var KeyMapper = function () {
|
|
|
3554
3607
|
this.triggerKeyAction(PASTE_ANNOTATION);
|
|
3555
3608
|
}
|
|
3556
3609
|
break;
|
|
3610
|
+
case 'Escape':
|
|
3611
|
+
this.triggerKeyAction(DELETE_ANNO_IN_CREATION);
|
|
3612
|
+
break;
|
|
3557
3613
|
default:
|
|
3558
3614
|
break;
|
|
3559
3615
|
}
|
|
@@ -3707,7 +3763,7 @@ function getZoomTranslation(w0, svg, s1) {
|
|
|
3707
3763
|
return translation;
|
|
3708
3764
|
}
|
|
3709
3765
|
|
|
3710
|
-
var css$1 = ".SIA_sia-fullscreen__1P3FS {\n position: fixed;\n top: 0;\n left: 0;\n z-index:
|
|
3766
|
+
var css$1 = ".SIA_sia-fullscreen__1P3FS {\n position: fixed;\n top: 0;\n left: 0;\n z-index: 9999;\n width: 100%;\n height: 100%;\n background-color: #FFFF; }\n";
|
|
3711
3767
|
styleInject(css$1);
|
|
3712
3768
|
|
|
3713
3769
|
var _extends$9 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
@@ -3732,17 +3788,19 @@ function _inherits$e(subClass, superClass) { if (typeof superClass !== "function
|
|
|
3732
3788
|
* {
|
|
3733
3789
|
* image : {
|
|
3734
3790
|
* id: int,
|
|
3735
|
-
* url: string,
|
|
3736
3791
|
* number: int,
|
|
3737
3792
|
* amount: int,
|
|
3738
3793
|
* isFirst: bool,
|
|
3739
|
-
* isLast: bool
|
|
3794
|
+
* isLast: bool,
|
|
3795
|
+
* description: string, // -> optional
|
|
3740
3796
|
* },
|
|
3741
3797
|
* annotations: {
|
|
3742
3798
|
* bBoxes: [{
|
|
3743
|
-
* id: int,
|
|
3744
|
-
*
|
|
3745
|
-
*
|
|
3799
|
+
* id: int, // -> Not required if status === annoStatus.NEW
|
|
3800
|
+
* data: {},
|
|
3801
|
+
* labelIds: list of int, // -> optional
|
|
3802
|
+
* status: see annoStatus, // -> optional
|
|
3803
|
+
* annoTime: float, // -> optional
|
|
3746
3804
|
* },...],
|
|
3747
3805
|
* points: []
|
|
3748
3806
|
* lines: []
|
|
@@ -3796,10 +3854,13 @@ function _inherits$e(subClass, superClass) { if (typeof superClass !== "function
|
|
|
3796
3854
|
* {left:int, top:int, right:int, bottom:int} values in pixels.
|
|
3797
3855
|
* @param {bool} centerCanvasInContainer - Center the canvas in the
|
|
3798
3856
|
* middle of the container.
|
|
3857
|
+
* @param {bool} maxCanvas - Maximize Canvas Size. Do not fit canvas to image size
|
|
3799
3858
|
* @param {str or int} defaultLabel (optional) - Name or ID of the default label that is used
|
|
3800
3859
|
* when no label was selected by the annotator. If not set "no label" will be used.
|
|
3801
3860
|
* If ID is used, it needs to be one of the possible label ids.
|
|
3802
3861
|
* @param {bool} blocked Block canvas view with loading dimmer.
|
|
3862
|
+
* @param {bool} lockedAnnos A list of AnnoIds of annos that should only be displayed.
|
|
3863
|
+
* Such annos can not be edited in any way.
|
|
3803
3864
|
* @event onSVGUpdate - Fires when the svg in canvas changed.
|
|
3804
3865
|
* args: {width: int, height: int, scale: float, translateX: float,
|
|
3805
3866
|
* translateY:float}
|
|
@@ -3837,6 +3898,10 @@ var Canvas = function (_Component) {
|
|
|
3837
3898
|
width: undefined,
|
|
3838
3899
|
height: undefined
|
|
3839
3900
|
},
|
|
3901
|
+
imageOffset: {
|
|
3902
|
+
x: 0,
|
|
3903
|
+
y: 0
|
|
3904
|
+
},
|
|
3840
3905
|
annos: [],
|
|
3841
3906
|
mode: VIEW,
|
|
3842
3907
|
// selectedAnnoId: {id:undefined},
|
|
@@ -3891,6 +3956,9 @@ var Canvas = function (_Component) {
|
|
|
3891
3956
|
imgLoadTimestamp: performance.now()
|
|
3892
3957
|
// isJunk: this.props.annos.image.isJunk
|
|
3893
3958
|
});
|
|
3959
|
+
if (this.state.imageData) {
|
|
3960
|
+
this.updateCanvasView(fixBackendAnnos(this.props.annos.annotations));
|
|
3961
|
+
}
|
|
3894
3962
|
// this.setState({
|
|
3895
3963
|
// imageLoaded: false,
|
|
3896
3964
|
// // imageData: undefined
|
|
@@ -3937,7 +4005,7 @@ var Canvas = function (_Component) {
|
|
|
3937
4005
|
// Selected annotation should be on top
|
|
3938
4006
|
this.putSelectedOnTop(prevState);
|
|
3939
4007
|
if (prevState.imgLoadCount !== this.state.imgLoadCount) {
|
|
3940
|
-
this.updateCanvasView(this.props.annos.annotations);
|
|
4008
|
+
this.updateCanvasView(fixBackendAnnos(this.props.annos.annotations));
|
|
3941
4009
|
this.setImageLabels(this.props.annos.image.labelIds);
|
|
3942
4010
|
this.setState({
|
|
3943
4011
|
performedImageInit: true
|
|
@@ -3946,7 +4014,8 @@ var Canvas = function (_Component) {
|
|
|
3946
4014
|
if (prevProps.layoutUpdate !== this.props.layoutUpdate) {
|
|
3947
4015
|
this.selectAnnotation(undefined);
|
|
3948
4016
|
// this.updateCanvasView(this.getAnnoBackendFormat())
|
|
3949
|
-
this.
|
|
4017
|
+
// const {imageOffset} = this.updateImageSize()
|
|
4018
|
+
this.updateCanvasView(canvasToBackendAnnos(this.state.annos, this.state.svg, false, this.state.imageOffset));
|
|
3950
4019
|
}
|
|
3951
4020
|
}
|
|
3952
4021
|
}
|
|
@@ -4070,14 +4139,10 @@ var Canvas = function (_Component) {
|
|
|
4070
4139
|
this.editAnnoLabel(myAnno);
|
|
4071
4140
|
break;
|
|
4072
4141
|
case DELETE_ANNO:
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
} else {
|
|
4078
|
-
this.onAnnoPerformedAction(anno, ANNO_DELETED);
|
|
4079
|
-
}
|
|
4080
|
-
}
|
|
4142
|
+
this.deleteAnnotation(anno);
|
|
4143
|
+
break;
|
|
4144
|
+
case DELETE_ANNO_IN_CREATION:
|
|
4145
|
+
this.deleteAnnoInCreationMode(anno);
|
|
4081
4146
|
break;
|
|
4082
4147
|
case ENTER_ANNO_ADD_MODE:
|
|
4083
4148
|
if (anno) {
|
|
@@ -4122,6 +4187,10 @@ var Canvas = function (_Component) {
|
|
|
4122
4187
|
case PASTE_ANNOTATION:
|
|
4123
4188
|
this.pasteAnnotation(0);
|
|
4124
4189
|
break;
|
|
4190
|
+
case RECREATE_ANNO:
|
|
4191
|
+
// recreate selected annotation using the anno id
|
|
4192
|
+
if (this.state.selectedAnnoId) this.recreateAnnotation(this.state.selectedAnnoId);
|
|
4193
|
+
break;
|
|
4125
4194
|
default:
|
|
4126
4195
|
console.warn('Unknown key action', action);
|
|
4127
4196
|
}
|
|
@@ -4403,11 +4472,13 @@ var Canvas = function (_Component) {
|
|
|
4403
4472
|
if (!this.props.possibleLabels) return;
|
|
4404
4473
|
if (this.props.possibleLabels.length <= 0) return;
|
|
4405
4474
|
var lbls = this.props.possibleLabels;
|
|
4406
|
-
|
|
4407
|
-
|
|
4475
|
+
lbls = lbls.map(function (e) {
|
|
4476
|
+
if (!('color' in e)) {
|
|
4408
4477
|
return _extends$9({}, e, { color: getColor(e.id) });
|
|
4409
|
-
}
|
|
4410
|
-
|
|
4478
|
+
} else {
|
|
4479
|
+
return _extends$9({}, e);
|
|
4480
|
+
}
|
|
4481
|
+
});
|
|
4411
4482
|
this.setState({
|
|
4412
4483
|
possibleLabels: [].concat(_toConsumableArray$4(lbls))
|
|
4413
4484
|
});
|
|
@@ -4486,6 +4557,29 @@ var Canvas = function (_Component) {
|
|
|
4486
4557
|
this.setCanvasState(cState.entry.annotations, cState.entry.imgLabelIds, cState.entry.selectedAnnoId, cState.entry.showSingleAnno);
|
|
4487
4558
|
}
|
|
4488
4559
|
}
|
|
4560
|
+
}, {
|
|
4561
|
+
key: 'deleteAnnotation',
|
|
4562
|
+
value: function deleteAnnotation(anno) {
|
|
4563
|
+
if (anno) {
|
|
4564
|
+
if (anno.mode === CREATE) {
|
|
4565
|
+
var ar = this.findAnnoRef(this.state.selectedAnnoId);
|
|
4566
|
+
if (ar !== undefined) ar.current.myAnno.current.removeLastNode();
|
|
4567
|
+
} else {
|
|
4568
|
+
this.onAnnoPerformedAction(anno, ANNO_DELETED);
|
|
4569
|
+
}
|
|
4570
|
+
}
|
|
4571
|
+
}
|
|
4572
|
+
}, {
|
|
4573
|
+
key: 'deleteAnnoInCreationMode',
|
|
4574
|
+
value: function deleteAnnoInCreationMode(anno) {
|
|
4575
|
+
if (anno) {
|
|
4576
|
+
if (anno.mode === CREATE) {
|
|
4577
|
+
// const ar = this.findAnnoRef(this.state.selectedAnnoId)
|
|
4578
|
+
// if (ar !== undefined) ar.current.myAnno.current.removeLastNode()
|
|
4579
|
+
this.onAnnoPerformedAction(anno, ANNO_DELETED);
|
|
4580
|
+
}
|
|
4581
|
+
}
|
|
4582
|
+
}
|
|
4489
4583
|
}, {
|
|
4490
4584
|
key: 'deleteAllAnnos',
|
|
4491
4585
|
value: function deleteAllAnnos() {
|
|
@@ -4519,9 +4613,27 @@ var Canvas = function (_Component) {
|
|
|
4519
4613
|
this.selectAnnotation(selectedAnnoId);
|
|
4520
4614
|
this.setState({ showSingleAnno: showSingleAnno });
|
|
4521
4615
|
}
|
|
4616
|
+
}, {
|
|
4617
|
+
key: 'isLocked',
|
|
4618
|
+
value: function isLocked(annoId) {
|
|
4619
|
+
if (this.props.lockedAnnos) {
|
|
4620
|
+
if (this.props.lockedAnnos.includes(annoId)) {
|
|
4621
|
+
return true;
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4624
|
+
return false;
|
|
4625
|
+
}
|
|
4522
4626
|
}, {
|
|
4523
4627
|
key: 'selectAnnotation',
|
|
4524
4628
|
value: function selectAnnotation(annoId) {
|
|
4629
|
+
if (this.isLocked(annoId)) {
|
|
4630
|
+
this.handleNotification({
|
|
4631
|
+
title: "Annotation locked",
|
|
4632
|
+
message: 'Annotation with id ' + annoId + ' is locked and can not be edited',
|
|
4633
|
+
type: WARNING
|
|
4634
|
+
});
|
|
4635
|
+
return;
|
|
4636
|
+
}
|
|
4525
4637
|
if (annoId) {
|
|
4526
4638
|
var anno = this.findAnno(annoId);
|
|
4527
4639
|
this.setState({
|
|
@@ -4560,7 +4672,7 @@ var Canvas = function (_Component) {
|
|
|
4560
4672
|
|
|
4561
4673
|
if (this.state.annos.length > 0) {
|
|
4562
4674
|
var myAnnos = this.state.annos.filter(function (e) {
|
|
4563
|
-
return e.status !== DELETED$1;
|
|
4675
|
+
return e.status !== DELETED$1 && !_this2.isLocked(e.id);
|
|
4564
4676
|
});
|
|
4565
4677
|
if (myAnnos.length > 0) {
|
|
4566
4678
|
if (!this.state.selectedAnnoId) {
|
|
@@ -4586,7 +4698,7 @@ var Canvas = function (_Component) {
|
|
|
4586
4698
|
|
|
4587
4699
|
var myAnnos = annos ? annos : this.state.annos;
|
|
4588
4700
|
// const backendFormat = this.getAnnoBackendFormat(removeFrontedIds, myAnnos)
|
|
4589
|
-
var backendFormat = canvasToBackendAnnos(myAnnos, this.state.svg, removeFrontedIds);
|
|
4701
|
+
var backendFormat = canvasToBackendAnnos(myAnnos, this.state.svg, removeFrontedIds, this.state.imageOffset);
|
|
4590
4702
|
var finalData = {
|
|
4591
4703
|
imgId: this.props.annos.image.id,
|
|
4592
4704
|
imgLabelIds: this.state.imgLabelIds,
|
|
@@ -4735,6 +4847,56 @@ var Canvas = function (_Component) {
|
|
|
4735
4847
|
}
|
|
4736
4848
|
}
|
|
4737
4849
|
}
|
|
4850
|
+
|
|
4851
|
+
/**
|
|
4852
|
+
* recreate an existing annotation in case the creation process was not finished
|
|
4853
|
+
* @param {string} id of annotation
|
|
4854
|
+
*/
|
|
4855
|
+
|
|
4856
|
+
}, {
|
|
4857
|
+
key: 'recreateAnnotation',
|
|
4858
|
+
value: function recreateAnnotation(annoID) {
|
|
4859
|
+
|
|
4860
|
+
var annos = this.state.annos;
|
|
4861
|
+
|
|
4862
|
+
// search for id of selected anno in all annos (should normally be last item in list, but to be sure)
|
|
4863
|
+
var annoIndex = void 0;
|
|
4864
|
+
var anno = void 0;
|
|
4865
|
+
|
|
4866
|
+
for (var k in annos) {
|
|
4867
|
+
if (annos[k].id == annoID) {
|
|
4868
|
+
annoIndex = k;
|
|
4869
|
+
anno = annos[k];
|
|
4870
|
+
break;
|
|
4871
|
+
}
|
|
4872
|
+
} // editing is only allowed on line and polygon
|
|
4873
|
+
if (!['line', 'polygon'].includes(anno.type)) return console.log("Cant recreate annotation: Type " + anno.type + " is forbidden");
|
|
4874
|
+
|
|
4875
|
+
// remove the old annotation
|
|
4876
|
+
this.state.annos.splice(annoIndex, 1);
|
|
4877
|
+
|
|
4878
|
+
// create a new annotation based on the datapoints of the old annotation
|
|
4879
|
+
var newAnno = {
|
|
4880
|
+
id: anno.id,
|
|
4881
|
+
type: anno.type,
|
|
4882
|
+
data: anno.data,
|
|
4883
|
+
mode: CREATE,
|
|
4884
|
+
status: anno.status == 'database' ? CHANGED : NEW,
|
|
4885
|
+
labelIds: anno.labelIds,
|
|
4886
|
+
selectedNode: anno.data.length - 1,
|
|
4887
|
+
annoTime: anno.annoTime
|
|
4888
|
+
};
|
|
4889
|
+
|
|
4890
|
+
newAnno = this.startAnnotimeMeasure(newAnno);
|
|
4891
|
+
this.setState({
|
|
4892
|
+
annos: [].concat(_toConsumableArray$4(this.state.annos), [newAnno]),
|
|
4893
|
+
selectedAnnoId: newAnno.id,
|
|
4894
|
+
showSingleAnno: newAnno.id,
|
|
4895
|
+
annoToolBarVisible: false
|
|
4896
|
+
});
|
|
4897
|
+
|
|
4898
|
+
console.log("Annotation recreated");
|
|
4899
|
+
}
|
|
4738
4900
|
}, {
|
|
4739
4901
|
key: 'putSelectedOnTop',
|
|
4740
4902
|
value: function putSelectedOnTop(prevState) {
|
|
@@ -4887,28 +5049,40 @@ var Canvas = function (_Component) {
|
|
|
4887
5049
|
imgWidth = maxImgHeight * ratio;
|
|
4888
5050
|
imgHeight = maxImgHeight;
|
|
4889
5051
|
}
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
5052
|
+
var svg;
|
|
5053
|
+
var imgOffset = { x: 0, y: 0 };
|
|
5054
|
+
if (this.props.maxCanvas) {
|
|
5055
|
+
imgOffset.x = (maxImgWidth - imgWidth) / 2;
|
|
5056
|
+
imgOffset.y = (maxImgHeight - imgHeight) / 2;
|
|
5057
|
+
console.log('imgOffset: ', imgOffset);
|
|
5058
|
+
svg = _extends$9({}, this.state.svg, { width: maxImgWidth, height: maxImgHeight,
|
|
5059
|
+
left: canvasLeft, top: canvasTop
|
|
5060
|
+
});
|
|
5061
|
+
} else {
|
|
5062
|
+
if (this.props.centerCanvasInContainer) {
|
|
5063
|
+
var resSpaceX = maxImgWidth - imgWidth;
|
|
5064
|
+
if (resSpaceX > 2) {
|
|
5065
|
+
canvasLeft = canvasLeft + resSpaceX / 2;
|
|
5066
|
+
}
|
|
5067
|
+
var resSpaceY = maxImgHeight - imgHeight;
|
|
5068
|
+
if (resSpaceY > 2) {
|
|
5069
|
+
canvasTop = canvasTop + resSpaceY / 2;
|
|
5070
|
+
}
|
|
4898
5071
|
}
|
|
5072
|
+
svg = _extends$9({}, this.state.svg, { width: imgWidth, height: imgHeight,
|
|
5073
|
+
left: canvasLeft, top: canvasTop
|
|
5074
|
+
});
|
|
4899
5075
|
}
|
|
4900
|
-
var svg = _extends$9({}, this.state.svg, { width: imgWidth, height: imgHeight,
|
|
4901
|
-
left: canvasLeft, top: canvasTop
|
|
4902
|
-
});
|
|
4903
5076
|
this.setState({
|
|
4904
5077
|
svg: svg,
|
|
4905
5078
|
image: {
|
|
4906
5079
|
width: this.img.current.naturalWidth,
|
|
4907
5080
|
height: this.img.current.naturalHeight
|
|
4908
|
-
}
|
|
5081
|
+
},
|
|
5082
|
+
imageOffset: imgOffset
|
|
4909
5083
|
});
|
|
4910
5084
|
this.svgUpdate(svg);
|
|
4911
|
-
return { imgWidth: imgWidth, imgHeight: imgHeight };
|
|
5085
|
+
return { imgWidth: imgWidth, imgHeight: imgHeight, imgOffset: imgOffset };
|
|
4912
5086
|
}
|
|
4913
5087
|
}, {
|
|
4914
5088
|
key: 'svgUpdate',
|
|
@@ -4933,7 +5107,7 @@ var Canvas = function (_Component) {
|
|
|
4933
5107
|
//for svg should be calculated
|
|
4934
5108
|
if (annotations) {
|
|
4935
5109
|
var imgSize = this.updateImageSize();
|
|
4936
|
-
this.setState({ annos: [].concat(_toConsumableArray$4(backendAnnosToCanvas(annotations, { width: imgSize.imgWidth, height: imgSize.imgHeight }))) });
|
|
5110
|
+
this.setState({ annos: [].concat(_toConsumableArray$4(backendAnnosToCanvas(annotations, { width: imgSize.imgWidth, height: imgSize.imgHeight }, imgSize.imgOffset))) });
|
|
4937
5111
|
}
|
|
4938
5112
|
}
|
|
4939
5113
|
}, {
|