01: /*
02: This file is part of the PolePosition database benchmark
03: http://www.polepos.org
04:
05: This program is free software; you can redistribute it and/or
06: modify it under the terms of the GNU General Public License
07: as published by the Free Software Foundation; either version 2
08: of the License, or (at your option) any later version.
09:
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: public class ChartBuilder {
33: private static final Font TITLE_FONT = new Font("SansSerif",
34: Font.BOLD, 14);
35: private static final Font LEGEND_FONT = new Font("SansSerif",
36: Font.PLAIN, 12);
37: private static final Font VALUE_LABEL_FONT = new Font("SansSerif",
38: Font.ITALIC, 12);
39: private static final Font VALUE_TICKLABEL_FONT = new Font(
40: "SansSerif", Font.PLAIN, 10);
41: private static final Font CATEGORY_LABEL_FONT = new Font(
42: "SansSerif", Font.ITALIC, 12);
43: private static final Font CATEGORY_TICKLABEL_FONT = new Font(
44: "SansSerif", Font.PLAIN, 10);
45:
46: public JFreeChart createChart(Graph graph) {
47: CategoryDataset dataset = createDataset(graph);
48: String n = graph.setups().get(0).getMostImportantNameForGraph();
49: CategoryAxis categoryAxis = new CategoryAxis("");
50: categoryAxis.setLabelFont(CATEGORY_LABEL_FONT);
51: categoryAxis.setTickLabelFont(CATEGORY_TICKLABEL_FONT);
52: ValueAxis valueAxis = new NumberAxis(
53: " 1 / log(t) better >");
54: valueAxis.setLabelFont(VALUE_LABEL_FONT);
55: valueAxis.setTickLabelFont(VALUE_TICKLABEL_FONT);
56: LineAndShapeRenderer renderer = new LineAndShapeRenderer(true,
57: false);
58: CategoryPlot plot = new CategoryPlot(dataset, categoryAxis,
59: valueAxis, renderer);
60: plot.setOrientation(PlotOrientation.VERTICAL);
61: JFreeChart chart = new JFreeChart("", TITLE_FONT, plot, false);
62: StandardLegend legend = new StandardLegend();
63: legend.setItemFont(LEGEND_FONT);
64: legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
65: legend.setBackgroundPaint(Color.white);
66: chart.setLegend(legend);
67: return chart;
68: }
69:
70: private CategoryDataset createDataset(Graph graph) {
71: DefaultCategoryDataset dataset = new DefaultCategoryDataset();
72: for (TeamCar teamCar : graph.teamCars()) {
73: for (TurnSetup setup : graph.setups()) {
74: String legend = ""
75: + setup.getMostImportantValueForGraph();
76: double time = graph.timeFor(teamCar, setup);
77: double logTime = Math.log(time);
78: double valForOutput = 0;
79: if (logTime != 0) {
80: valForOutput = ((double) 1) / logTime;
81: }
82: dataset.addValue(valForOutput, teamCar.toString(),
83: legend);
84: }
85: }
86: return dataset;
87: }
88:
89: }
|