Skip to content
Snippets Groups Projects

consider situations where there are custom colors in genetic overlay

Merged Piotr Gawron requested to merge 1686-legend into devel_16.1.x
3 files
+ 24
10
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -80,22 +80,33 @@ public class LegendGenerator {
Color oldColor = graphics.getColor();
Font oldFont = graphics.getFont();
Map<Integer, Color> colors = new HashMap<>();
Map<Integer, Set<Color>> colorByCount = new HashMap<>();
for (DataOverlayEntry entry : overlay.getEntries()) {
colors.put(((GeneVariantDataOverlayEntry) entry).getGeneVariants().size(), colorExtractor.getNormalizedColor(entry));
int count = ((GeneVariantDataOverlayEntry) entry).getGeneVariants().size();
Set<Color> colors = colorByCount.get(count);
if (colors == null) {
colors = new HashSet<>();
colorByCount.put(count, colors);
}
colors.add(colorExtractor.getNormalizedColor(entry));
}
int width = WIDTH - 2 * MARGIN;
double elementWidth = ((double) width) / (double) (colors.size());
double elementWidth = ((double) width) / (double) (colorByCount.size());
List<Integer> counters = new ArrayList<>(colors.keySet());
List<Integer> counters = new ArrayList<>(colorByCount.keySet());
Collections.sort(counters);
for (int i = 0; i < counters.size(); i++) {
int count = counters.get(i);
Rectangle2D rectangle = new Rectangle2D.Double(MARGIN + i * elementWidth, MARGIN, elementWidth, COLOR_HEIGHT);
graphics.setColor(colors.get(count));
graphics.fill(rectangle);
List<Color> colors = new ArrayList<>(colorByCount.get(count));
for (int j = 0; j < colors.size(); j++) {
Color color = colors.get(j);
double x = MARGIN + i * elementWidth + elementWidth / colors.size() * j;
Rectangle2D rectangle = new Rectangle2D.Double(x, MARGIN, elementWidth / colors.size(), COLOR_HEIGHT);
graphics.setColor(color);
graphics.fill(rectangle);
}
}
graphics.setFont(new Font(Font.SANS_SERIF, 0, 18));
@@ -196,7 +207,7 @@ public class LegendGenerator {
for (int i = 0; i < width; i++) {
Rectangle2D rectangle = new Rectangle2D.Double(MARGIN + i, MARGIN, 1, COLOR_HEIGHT);
GenericDataOverlayEntry entry = new GenericDataOverlayEntry();
entry.setValue(((double) (i - width / 2)) / (double) (width / 2.0));
entry.setValue((i - width / 2) / (width / 2.0));
graphics.setColor(colorExtractor.getNormalizedColor(entry));
graphics.fill(rectangle);
}
Loading