Create a diagram from the data supplied to the constructor. @return the diagram as a BufferedImage
()
| 30 | * @return the diagram as a {@link BufferedImage} |
| 31 | */ |
| 32 | public BufferedImage plot() { |
| 33 | BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); |
| 34 | Graphics2D g2d = img.createGraphics(); |
| 35 | |
| 36 | g2d.setFont(ImageGenerationUtils.getResourceFont("assets/fonts/Uni-Sans-Heavy.ttf", 30).orElseThrow()); |
| 37 | |
| 38 | g2d.setBackground(Color.WHITE); |
| 39 | g2d.fillRect(0, 0, width, height); |
| 40 | g2d.setColor(Color.BLACK); |
| 41 | |
| 42 | centeredText(g2d, title, width/2, 50); |
| 43 | |
| 44 | plotEntries(g2d, 100, 100, width-200, height-200); |
| 45 | |
| 46 | return img; |
| 47 | } |
| 48 | |
| 49 | private void plotEntries(Graphics2D g2d, int x, int y, int width, int height) { |
| 50 | double maxValue = entries.stream().<Bar>map(Pair::second).mapToDouble(Bar::sum).max().orElse(0); |
no test coverage detected