Skip to content

Commit

Permalink
#3656 - The color of the existing layers changes after adding another…
Browse files Browse the repository at this point in the history
… layer

- Sort layers by "creation order" to ensure colors do not shift when a new layer is added
  • Loading branch information
reckart committed Jan 4, 2023
1 parent 31e8e08 commit f6169b1
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering;

import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toList;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCauseMessage;
import static org.slf4j.LoggerFactory.getLogger;

Expand Down Expand Up @@ -98,8 +100,14 @@ public void render(VDocument aVDoc, RenderRequest aRequest)
allLayers = schemaService.listAnnotationLayer(aRequest.getProject());
}

// Sort layers by creation order (i.e. by ID) to ensure the colors remain the same even
// if a new layer is added to a project
var sortedLayers = allLayers.stream() //
.sorted(comparing(AnnotationLayer::getId)) //
.collect(toList());

Map<String[], Queue<String>> colorQueues = new HashMap<>();
for (AnnotationLayer layer : allLayers) {
for (AnnotationLayer layer : sortedLayers) {
ColoringStrategy coloringStrategy = aRequest.getColoringStrategyOverride()
.orElse(coloringService.getStrategy(layer, prefs.get(), colorQueues));

Expand Down

0 comments on commit f6169b1

Please sign in to comment.