KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > polepos > reporters > ChartBuilder


1 /*
2 This file is part of the PolePosition database benchmark
3 http://www.polepos.org
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 MA 02111-1307, USA. */

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 JavaDoc 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 JavaDoc 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