use of com.github.lindenb.jvarkit.swing.GraphicsState in project jvarkit by lindenb.
the class CoveragePlotter method drawGenes.
private void drawGenes(final Graphics2D g, final Rectangle rect, final Locatable region) {
final IntToDoubleFunction position2pixel = X -> ((X - region.getStart()) / (double) region.getLengthOnReference()) * rect.getWidth();
final double y = rect.getMaxY() - 4.0;
try (GraphicsState state = GraphicsState.of(g)) {
final int geneSize = 10;
state.getGraphics().setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
g.setFont(new Font(g.getFont().getName(), Font.PLAIN, geneSize));
g.setColor(getColor("gene", Color.DARK_GRAY));
getGenes(region).forEach(gtfline -> {
final double x1 = position2pixel.applyAsDouble(gtfline.getStart());
final double x2 = position2pixel.applyAsDouble(gtfline.getEnd());
if (gtfline.getType().equals("gene")) {
g.drawString(gtfline.getAttribute("gene_name"), (int) Math.max(x1, 1), (int) (y - (geneSize + 3)));
} else if (gtfline.getType().equals("exon")) {
g.draw(new Rectangle2D.Double(x1, y - 1, (x2 - x1), 3));
} else if (gtfline.getType().equals("transcript")) {
g.draw(new Line2D.Double(x1, y, x2, y));
}
});
}
}
Aggregations