1 19 20 package org.polepos.reporters; 21 22 import java.awt.*; 23 24 import org.jfree.chart.*; 25 import org.jfree.chart.axis.*; 26 import org.jfree.chart.plot.*; 27 import org.jfree.chart.renderer.category.*; 28 import org.jfree.data.category.*; 29 import org.jfree.ui.*; 30 import org.polepos.framework.*; 31 32 33 public class ChartBuilder { 34 private static final Font TITLE_FONT = new Font("SansSerif", Font.BOLD, 14); 35 private static final Font LEGEND_FONT = new Font("SansSerif", Font.PLAIN, 12); 36 private static final Font VALUE_LABEL_FONT = new Font("SansSerif", Font.ITALIC, 12); 37 private static final Font VALUE_TICKLABEL_FONT = new Font("SansSerif", Font.PLAIN, 10); 38 private static final Font CATEGORY_LABEL_FONT = new Font("SansSerif", Font.ITALIC, 12); 39 private static final Font CATEGORY_TICKLABEL_FONT = new Font("SansSerif", Font.PLAIN, 10); 40 41 public JFreeChart createChart(Graph graph) { 42 CategoryDataset dataset=createDataset(graph); 43 String n = graph.setups().get(0).getMostImportantNameForGraph(); 44 CategoryAxis categoryAxis = new CategoryAxis(""); 45 categoryAxis.setLabelFont(CATEGORY_LABEL_FONT); 46 categoryAxis.setTickLabelFont(CATEGORY_TICKLABEL_FONT); 47 ValueAxis valueAxis = new NumberAxis(" 1 / log(t) better >"); 48 valueAxis.setLabelFont(VALUE_LABEL_FONT); 49 valueAxis.setTickLabelFont(VALUE_TICKLABEL_FONT); 50 LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false); 51 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); 52 plot.setOrientation(PlotOrientation.VERTICAL); 53 JFreeChart chart = new JFreeChart("", TITLE_FONT, plot, false); 54 StandardLegend legend = new StandardLegend(); 55 legend.setItemFont(LEGEND_FONT); 56 legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); 57 legend.setBackgroundPaint(Color.white); 58 chart.setLegend(legend); 59 return chart; 60 } 61 62 private CategoryDataset createDataset(Graph graph) { 63 DefaultCategoryDataset dataset=new DefaultCategoryDataset(); 64 for(TeamCar teamCar : graph.teamCars()) { 65 for(TurnSetup setup : graph.setups()) { 66 String legend = "" + setup.getMostImportantValueForGraph(); 67 double time = graph.timeFor(teamCar,setup); 68 double logTime = Math.log( time ); 69 double valForOutput = 0; 70 if(logTime != 0){ 71 valForOutput = ((double)1)/logTime; 72 } 73 dataset.addValue(valForOutput,teamCar.toString(),legend); 74 } 75 } 76 return dataset; 77 } 78 79 } 80
| Popular Tags
|