recogito / text-annotator-js

A JavaScript library for text annotation.
BSD 3-Clause "New" or "Revised" License
21 stars 7 forks source link

The unsorted highlights in the `SPANS` renderer can lead to incorrect overlapping order #142

Closed oleksandr-danylchenko closed 1 month ago

oleksandr-danylchenko commented 2 months ago

Issue

When working with the SPANS renderer I noticed that the newer annotations can appear below the older ones in a seemingly random way. That has already been observed in the CANVAS renderer in https://github.com/recogito/text-annotator-js/issues/94 🔍

Example

The bluish highlight was added last to the annotator and it should be rendered over the rest of the existing highlights. However, the application and overlapping order seems to be random from selection to selection: image image

Possible Solution

Add highlights sorting in the similar manner I did for the CANVAS renderer - https://github.com/recogito/text-annotator-js/pull/96

rsimon commented 1 month ago

PR looks good. There's one tiny issue: timestamps are optional in the data model, so this would currently crash the sorting.

That's trivial to resolve though. Another issue: I realized that underneath the hood, Annotorious doesn't yet revive timestamps when loading Annotations from JSON. The W3C adapter does. But if you use Annotorious without adapter, you'll be dealing with strings as created, updated values. So this needs fixing first. Creating an issue here: https://github.com/annotorious/annotorious/issues/440

rsimon commented 1 month ago

With the recent updates, this should now work as intended.

oleksandr-danylchenko commented 1 month ago

With the recent updates, this should now work as intended.

Thanks, it works great now ✅