informatics-isi-edu / openseadragon-viewer

2D viewer with openseadragon
Apache License 2.0
5 stars 2 forks source link

Empty annotation bug #70

Closed rastogi-bhavya closed 3 years ago

rastogi-bhavya commented 3 years ago

The issue is due to getNumOfAnnotations function which is used to determine whether there are annotations present or not. As per the current implementation of the code, whenever a draw tool is clicked a new annotation object is created. This newly created object (even though empty) will be counted in getNumOfAnnotations, and hence the number returned would not be 0 and therefore no error is thrown when the Save button is clicked.

To throw the error Please draw annotation on the image. the condition is that the number of annotations should be 0.

To correct this I made the following corrections to the code. In getNumOfAnnotations function I am only counting those annotations that have been drawn, i.e. annotations for which isDrawing is False. This makes sure that the empty annotations are not counted, and therefore this function returns 0, even when one of the draw icon is clicked as mentioned in the issue.

This approach only fixes this particular bug and not the issue that the annotation object is created as soon as the draw icon is clicked (the right approach should be, adding the new object just before the draw event starts). Related to issue #26

RFSH commented 3 years ago

As you mentioned this will only fix this particular case. With this change, osd viewer still is going to create an empty annotation when user draw one annotation, and clicked on draw button (so two drawings.) It also is not properly working for polygon case since isDrawing will be true even if users drew something.

I need to think more about it, but I feel like we cannot easily refactor the code to not create an empty annotation while drawing. We could instead properly change the saveAnatomySVG and exportToSVG functions to check for these empty annotations and ignore them.

rastogi-bhavya commented 3 years ago

Since this is a very case specific solution, I am going go with a different approach, where I will try to make sure that no empty annotation is passed when I click on save (as mentioned in the above comment by Aref). This type of approach will make sure that in case, there are no annotations drawn the appropriate error message will be shown.