Skip to content

Commit

Permalink
Merge pull request #3681 from inception-project/bugfix/3656-The-color…
Browse files Browse the repository at this point in the history
…-of-the-existing-layers-changes-after-adding-another-layer

#3656 - The color of the existing layers changes after adding another layer
  • Loading branch information
reckart authored Jan 4, 2023
2 parents 31e8e08 + f6169b1 commit 797485f
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 797485f

Please sign in to comment.