99 * Creates diagrams.
1010 */
1111public class Plotter {
12+ private String title ;
1213 private final List <Pair <String , Double >> entries ;
1314 private int width =3000 ;
1415 private int height =1500 ;
1516
1617 /**
1718 * Creates the plotter.
1819 * @param entries a list of all data points to plot, each represented as a {@link Pair} consisting of the name and value of the data point
20+ * @param title the title of the plot
1921 */
20- public Plotter (List <Pair <String , Double >> entries ) {
21- this .entries =entries ;
22+ public Plotter (List <Pair <String , Double >> entries , String title ) {
23+ this .entries = entries ;
24+ this .title = title ;
2225 }
2326
2427 /**
@@ -35,15 +38,15 @@ public BufferedImage plot() {
3538 g2d .fillRect (0 , 0 , width , height );
3639 g2d .setColor (Color .BLACK );
3740
38- centeredText (g2d , "gained help XP per month" , width /2 , 50 );
41+ centeredText (g2d , title , width /2 , 50 );
3942
4043 plotEntries (g2d , 100 , 100 , width -200 , height -200 );
4144
4245 return img ;
4346 }
4447
4548 private void plotEntries (Graphics2D g2d , int x , int y , int width , int height ) {
46- double maxValue = entries .stream ().mapToDouble (Pair ::second ).sum ( );
49+ double maxValue = entries .stream ().mapToDouble (Pair ::second ).max (). orElse ( 0 );
4750 int stepSize = 2 *(int )Math .pow (10 ,(int )Math .log10 (maxValue )-1 );
4851 if (stepSize ==0 ) {
4952 stepSize =1 ;
0 commit comments