lost-sia 0.8.0 → 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 CHANGED
@@ -5,6 +5,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
 
8
+ ## [0.9.0] - 2021-12-23
9
+ ### Added
10
+ - Delete annotation in creation mode when hitting *Escape*-Key
11
+ - Show img description in ImgBar if available
12
+ - Max canvas size mode. Where canvas takes the maximum container size and is not
13
+ image oriented as before. Add prop *maxCanvas={true}* to canvas in order to enable.
14
+ ### Changed
15
+ - Be able to deal with mixed color possible labels -> where a part of labels
16
+ will have a specified color and the other part has no provided color
17
+
8
18
  ## [0.8.0] - 2021-10-14
9
19
  ### Added
10
20
  - Added lockedAnnos prop for Canvas in order to lock annos by id. Locked annos
package/dist/index.es.js CHANGED
@@ -4,13 +4,13 @@ import _ from 'lodash';
4
4
 
5
5
  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); } }
6
6
 
7
- function toSia(data, image, type) {
7
+ function toSia(data, image, type, imgOffset) {
8
8
  switch (type) {
9
9
  case 'bBox':
10
10
  var w = image.width * data.w;
11
11
  var h = image.height * data.h;
12
- var x0 = image.width * data.x - w / 2.0;
13
- var y0 = image.height * data.y - h / 2.0;
12
+ var x0 = imgOffset.x + image.width * data.x - w / 2.0;
13
+ var y0 = imgOffset.y + image.height * data.y - h / 2.0;
14
14
  return [{
15
15
  x: x0,
16
16
  y: y0
@@ -26,15 +26,15 @@ function toSia(data, image, type) {
26
26
  }];
27
27
  case 'point':
28
28
  return [{
29
- x: image.width * data.x,
30
- y: image.height * data.y
29
+ x: imgOffset.x + image.width * data.x,
30
+ y: imgOffset.y + image.height * data.y
31
31
  }];
32
32
  case 'line':
33
33
  case 'polygon':
34
34
  return data.map(function (e) {
35
35
  return {
36
- x: image.width * e.x,
37
- y: image.height * e.y
36
+ x: imgOffset.x + image.width * e.x,
37
+ y: imgOffset.y + image.height * e.y
38
38
  };
39
39
  });
40
40
  default:
@@ -46,17 +46,21 @@ function toSia(data, image, type) {
46
46
  * Transform a sia annotation to backend format.
47
47
  *
48
48
  * @param {Array} data Annotation data
49
- * @param {*} image Image object {width, height}
49
+ * @param {*} svg Image object {width, height}
50
50
  * @param {String} type Type of the annotation bBox, point, line, polygon
51
51
  * @returns Annotation data in backend style (relative, centered)
52
52
  */
53
- function toBackend(data, image, type) {
53
+ function toBackend(data, svg, type) {
54
+ var imgOffset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { x: 0, y: 0 };
55
+
56
+ var imgWidth = svg.width - 2 * imgOffset.x;
57
+ var imgHeight = svg.height - 2 * imgOffset.y;
54
58
  switch (type) {
55
59
  case 'bBox':
56
- // const w = image.width * data.w
57
- // const h = image.height * data.h
58
- // const x0 = image.width * data.x - w/2.0
59
- // const y0 = image.height * data.y - h/2.0
60
+ // const w = svg.width * data.w
61
+ // const h = svg.height * data.h
62
+ // const x0 = svg.width * data.x - w/2.0
63
+ // const y0 = svg.height * data.y - h/2.0
60
64
 
61
65
  // console.error('GO On Here! w = max_x - min_x; h = max_y - min_y')
62
66
  var xList = data.map(function (e) {
@@ -65,30 +69,30 @@ function toBackend(data, image, type) {
65
69
  var yList = data.map(function (e) {
66
70
  return e.y;
67
71
  });
68
- var minX = Math.min.apply(Math, _toConsumableArray(xList));
69
- var maxX = Math.max.apply(Math, _toConsumableArray(xList));
70
- var minY = Math.min.apply(Math, _toConsumableArray(yList));
71
- var maxY = Math.max.apply(Math, _toConsumableArray(yList));
72
+ var minX = Math.min.apply(Math, _toConsumableArray(xList)) - imgOffset.x;
73
+ var maxX = Math.max.apply(Math, _toConsumableArray(xList)) - imgOffset.x;
74
+ var minY = Math.min.apply(Math, _toConsumableArray(yList)) - imgOffset.y;
75
+ var maxY = Math.max.apply(Math, _toConsumableArray(yList)) - imgOffset.y;
72
76
  var w = maxX - minX;
73
77
  var h = maxY - minY;
74
78
  var x = minX + w / 2.0;
75
79
  var y = minY + h / 2.0;
76
80
  return {
77
- x: x / image.width,
78
- y: y / image.height,
79
- w: w / image.width,
80
- h: h / image.height };
81
+ x: x / imgWidth,
82
+ y: y / imgHeight,
83
+ w: w / imgWidth,
84
+ h: h / imgHeight };
81
85
  case 'point':
82
86
  return {
83
- x: data[0].x / image.width,
84
- y: data[0].y / image.height
87
+ x: (data[0].x - imgOffset.x) / imgWidth,
88
+ y: (data[0].y - imgOffset.y) / imgHeight
85
89
  };
86
90
  case 'line':
87
91
  case 'polygon':
88
92
  return data.map(function (e) {
89
93
  return {
90
- x: e.x / image.width,
91
- y: e.y / image.height
94
+ x: (e.x - imgOffset.x) / imgWidth,
95
+ y: (e.y - imgOffset.y) / imgHeight
92
96
  };
93
97
  });
94
98
  default:
@@ -3153,6 +3157,19 @@ var ImgBar = function (_Component) {
3153
3157
  return null;
3154
3158
  }
3155
3159
  }
3160
+ }, {
3161
+ key: 'renderImgDescription',
3162
+ value: function renderImgDescription() {
3163
+ if (this.props.annos.image.description) {
3164
+ return React.createElement(
3165
+ Menu.Item,
3166
+ null,
3167
+ this.props.annos.image.description
3168
+ );
3169
+ } else {
3170
+ return null;
3171
+ }
3172
+ }
3156
3173
  }, {
3157
3174
  key: 'render',
3158
3175
  value: function render() {
@@ -3160,7 +3177,7 @@ var ImgBar = function (_Component) {
3160
3177
 
3161
3178
  if (!this.props.visible) return null;
3162
3179
  if (!this.props.annos.image) return null;
3163
- if (!this.props.annos.image.url) return null;
3180
+ // if (!this.props.annos.image.url) return null
3164
3181
  return React.createElement(
3165
3182
  'div',
3166
3183
  { style: {
@@ -3177,10 +3194,11 @@ var ImgBar = function (_Component) {
3177
3194
  React.createElement(
3178
3195
  Menu,
3179
3196
  { inverted: true, style: { opacity: 0.9, justifyContent: 'center', alignItems: 'center' } },
3197
+ this.renderImgDescription(),
3180
3198
  React.createElement(
3181
3199
  Menu.Item,
3182
3200
  null,
3183
- this.props.annos.image.url.split('/').pop() + " (ID: " + this.props.annos.image.id + ")"
3201
+ "ID: " + this.props.annos.image.id
3184
3202
  ),
3185
3203
  React.createElement(
3186
3204
  Menu.Item,
@@ -3432,7 +3450,7 @@ function fixBackendAnnos(backendAnnos) {
3432
3450
  return annos;
3433
3451
  }
3434
3452
 
3435
- function backendAnnosToCanvas(backendAnnos, imgSize) {
3453
+ function backendAnnosToCanvas(backendAnnos, imgSize, imgOffset) {
3436
3454
  var annos = [].concat(_toConsumableArray$3(backendAnnos.bBoxes.map(function (element) {
3437
3455
  return _extends$8({}, element, { type: 'bBox',
3438
3456
  mode: element.mode ? element.mode : VIEW,
@@ -3453,7 +3471,7 @@ function backendAnnosToCanvas(backendAnnos, imgSize) {
3453
3471
  })));
3454
3472
  annos = annos.map(function (el) {
3455
3473
  return _extends$8({}, el, {
3456
- data: toSia(el.data, imgSize, el.type) });
3474
+ data: toSia(el.data, imgSize, el.type, imgOffset) });
3457
3475
  });
3458
3476
  // this.setState({annos: [...annos]})
3459
3477
  return annos;
@@ -3461,6 +3479,7 @@ function backendAnnosToCanvas(backendAnnos, imgSize) {
3461
3479
 
3462
3480
  function canvasToBackendAnnos(annos, imgSize) {
3463
3481
  var forBackendPost = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
3482
+ var imgOffset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { x: 0, y: 0 };
3464
3483
 
3465
3484
  var myAnnos = annos;
3466
3485
  var bAnnos = myAnnos.map(function (el) {
@@ -3476,7 +3495,7 @@ function canvasToBackendAnnos(annos, imgSize) {
3476
3495
  return _extends$8({}, el, {
3477
3496
  id: annoId,
3478
3497
  mode: VIEW,
3479
- data: toBackend(el.data, imgSize, el.type)
3498
+ data: toBackend(el.data, imgSize, el.type, imgOffset)
3480
3499
  });
3481
3500
  });
3482
3501
 
@@ -3516,6 +3535,7 @@ var CAM_MOVE_STOP = 'camMoveStop';
3516
3535
  var COPY_ANNOTATION = 'copyAnnotation';
3517
3536
  var PASTE_ANNOTATION = 'pasteAnnotation';
3518
3537
  var RECREATE_ANNO = 'recreateAnnotation';
3538
+ var DELETE_ANNO_IN_CREATION = 'deleteAnnoInCreation';
3519
3539
 
3520
3540
  var KeyMapper = function () {
3521
3541
  function KeyMapper() {
@@ -3582,6 +3602,9 @@ var KeyMapper = function () {
3582
3602
  this.triggerKeyAction(PASTE_ANNOTATION);
3583
3603
  }
3584
3604
  break;
3605
+ case 'Escape':
3606
+ this.triggerKeyAction(DELETE_ANNO_IN_CREATION);
3607
+ break;
3585
3608
  default:
3586
3609
  break;
3587
3610
  }
@@ -3760,11 +3783,11 @@ function _inherits$e(subClass, superClass) { if (typeof superClass !== "function
3760
3783
  * {
3761
3784
  * image : {
3762
3785
  * id: int,
3763
- * url: string,
3764
3786
  * number: int,
3765
3787
  * amount: int,
3766
3788
  * isFirst: bool,
3767
- * isLast: bool
3789
+ * isLast: bool,
3790
+ * description: string, // -> optional
3768
3791
  * },
3769
3792
  * annotations: {
3770
3793
  * bBoxes: [{
@@ -3826,6 +3849,7 @@ function _inherits$e(subClass, superClass) { if (typeof superClass !== "function
3826
3849
  * {left:int, top:int, right:int, bottom:int} values in pixels.
3827
3850
  * @param {bool} centerCanvasInContainer - Center the canvas in the
3828
3851
  * middle of the container.
3852
+ * @param {bool} maxCanvas - Maximize Canvas Size. Do not fit canvas to image size
3829
3853
  * @param {str or int} defaultLabel (optional) - Name or ID of the default label that is used
3830
3854
  * when no label was selected by the annotator. If not set "no label" will be used.
3831
3855
  * If ID is used, it needs to be one of the possible label ids.
@@ -3869,6 +3893,10 @@ var Canvas = function (_Component) {
3869
3893
  width: undefined,
3870
3894
  height: undefined
3871
3895
  },
3896
+ imageOffset: {
3897
+ x: 0,
3898
+ y: 0
3899
+ },
3872
3900
  annos: [],
3873
3901
  mode: VIEW,
3874
3902
  // selectedAnnoId: {id:undefined},
@@ -3981,7 +4009,8 @@ var Canvas = function (_Component) {
3981
4009
  if (prevProps.layoutUpdate !== this.props.layoutUpdate) {
3982
4010
  this.selectAnnotation(undefined);
3983
4011
  // this.updateCanvasView(this.getAnnoBackendFormat())
3984
- this.updateCanvasView(canvasToBackendAnnos(this.state.annos, this.state.svg));
4012
+ // const {imageOffset} = this.updateImageSize()
4013
+ this.updateCanvasView(canvasToBackendAnnos(this.state.annos, this.state.svg, false, this.state.imageOffset));
3985
4014
  }
3986
4015
  }
3987
4016
  }
@@ -4107,6 +4136,9 @@ var Canvas = function (_Component) {
4107
4136
  case DELETE_ANNO:
4108
4137
  this.deleteAnnotation(anno);
4109
4138
  break;
4139
+ case DELETE_ANNO_IN_CREATION:
4140
+ this.deleteAnnoInCreationMode(anno);
4141
+ break;
4110
4142
  case ENTER_ANNO_ADD_MODE:
4111
4143
  if (anno) {
4112
4144
  this.updateSelectedAnno(anno, ADD);
@@ -4435,11 +4467,13 @@ var Canvas = function (_Component) {
4435
4467
  if (!this.props.possibleLabels) return;
4436
4468
  if (this.props.possibleLabels.length <= 0) return;
4437
4469
  var lbls = this.props.possibleLabels;
4438
- if (!('color' in lbls[0])) {
4439
- lbls = lbls.map(function (e) {
4470
+ lbls = lbls.map(function (e) {
4471
+ if (!('color' in e)) {
4440
4472
  return _extends$9({}, e, { color: getColor(e.id) });
4441
- });
4442
- }
4473
+ } else {
4474
+ return _extends$9({}, e);
4475
+ }
4476
+ });
4443
4477
  this.setState({
4444
4478
  possibleLabels: [].concat(_toConsumableArray$4(lbls))
4445
4479
  });
@@ -4530,6 +4564,17 @@ var Canvas = function (_Component) {
4530
4564
  }
4531
4565
  }
4532
4566
  }
4567
+ }, {
4568
+ key: 'deleteAnnoInCreationMode',
4569
+ value: function deleteAnnoInCreationMode(anno) {
4570
+ if (anno) {
4571
+ if (anno.mode === CREATE) {
4572
+ // const ar = this.findAnnoRef(this.state.selectedAnnoId)
4573
+ // if (ar !== undefined) ar.current.myAnno.current.removeLastNode()
4574
+ this.onAnnoPerformedAction(anno, ANNO_DELETED);
4575
+ }
4576
+ }
4577
+ }
4533
4578
  }, {
4534
4579
  key: 'deleteAllAnnos',
4535
4580
  value: function deleteAllAnnos() {
@@ -4648,7 +4693,7 @@ var Canvas = function (_Component) {
4648
4693
 
4649
4694
  var myAnnos = annos ? annos : this.state.annos;
4650
4695
  // const backendFormat = this.getAnnoBackendFormat(removeFrontedIds, myAnnos)
4651
- var backendFormat = canvasToBackendAnnos(myAnnos, this.state.svg, removeFrontedIds);
4696
+ var backendFormat = canvasToBackendAnnos(myAnnos, this.state.svg, removeFrontedIds, this.state.imageOffset);
4652
4697
  var finalData = {
4653
4698
  imgId: this.props.annos.image.id,
4654
4699
  imgLabelIds: this.state.imgLabelIds,
@@ -4999,28 +5044,40 @@ var Canvas = function (_Component) {
4999
5044
  imgWidth = maxImgHeight * ratio;
5000
5045
  imgHeight = maxImgHeight;
5001
5046
  }
5002
- if (this.props.centerCanvasInContainer) {
5003
- var resSpaceX = maxImgWidth - imgWidth;
5004
- if (resSpaceX > 2) {
5005
- canvasLeft = canvasLeft + resSpaceX / 2;
5006
- }
5007
- var resSpaceY = maxImgHeight - imgHeight;
5008
- if (resSpaceY > 2) {
5009
- canvasTop = canvasTop + resSpaceY / 2;
5047
+ var svg;
5048
+ var imgOffset = { x: 0, y: 0 };
5049
+ if (this.props.maxCanvas) {
5050
+ imgOffset.x = (maxImgWidth - imgWidth) / 2;
5051
+ imgOffset.y = (maxImgHeight - imgHeight) / 2;
5052
+ console.log('imgOffset: ', imgOffset);
5053
+ svg = _extends$9({}, this.state.svg, { width: maxImgWidth, height: maxImgHeight,
5054
+ left: canvasLeft, top: canvasTop
5055
+ });
5056
+ } else {
5057
+ if (this.props.centerCanvasInContainer) {
5058
+ var resSpaceX = maxImgWidth - imgWidth;
5059
+ if (resSpaceX > 2) {
5060
+ canvasLeft = canvasLeft + resSpaceX / 2;
5061
+ }
5062
+ var resSpaceY = maxImgHeight - imgHeight;
5063
+ if (resSpaceY > 2) {
5064
+ canvasTop = canvasTop + resSpaceY / 2;
5065
+ }
5010
5066
  }
5067
+ svg = _extends$9({}, this.state.svg, { width: imgWidth, height: imgHeight,
5068
+ left: canvasLeft, top: canvasTop
5069
+ });
5011
5070
  }
5012
- var svg = _extends$9({}, this.state.svg, { width: imgWidth, height: imgHeight,
5013
- left: canvasLeft, top: canvasTop
5014
- });
5015
5071
  this.setState({
5016
5072
  svg: svg,
5017
5073
  image: {
5018
5074
  width: this.img.current.naturalWidth,
5019
5075
  height: this.img.current.naturalHeight
5020
- }
5076
+ },
5077
+ imageOffset: imgOffset
5021
5078
  });
5022
5079
  this.svgUpdate(svg);
5023
- return { imgWidth: imgWidth, imgHeight: imgHeight };
5080
+ return { imgWidth: imgWidth, imgHeight: imgHeight, imgOffset: imgOffset };
5024
5081
  }
5025
5082
  }, {
5026
5083
  key: 'svgUpdate',
@@ -5045,7 +5102,7 @@ var Canvas = function (_Component) {
5045
5102
  //for svg should be calculated
5046
5103
  if (annotations) {
5047
5104
  var imgSize = this.updateImageSize();
5048
- this.setState({ annos: [].concat(_toConsumableArray$4(backendAnnosToCanvas(annotations, { width: imgSize.imgWidth, height: imgSize.imgHeight }))) });
5105
+ this.setState({ annos: [].concat(_toConsumableArray$4(backendAnnosToCanvas(annotations, { width: imgSize.imgWidth, height: imgSize.imgHeight }, imgSize.imgOffset))) });
5049
5106
  }
5050
5107
  }
5051
5108
  }, {