MCPcopy Create free account
hub / github.com/Java-Discord/JavaBot / plot

Method plot

src/main/java/net/discordjug/javabot/util/Plotter.java:32–47  ·  view source on GitHub ↗

Create a diagram from the data supplied to the constructor. @return the diagram as a BufferedImage

()

Source from the content-addressed store, hash-verified

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);

Callers 2

generatePlotMethod · 0.80
executeMethod · 0.80

Calls 3

getResourceFontMethod · 0.95
centeredTextMethod · 0.95
plotEntriesMethod · 0.95

Tested by

no test coverage detected