MATSIM
PtCountsSimRealPerHourGraph.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * CountsSimRealPerHourGraph.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.pt.counts.obsolete;
22 
23 import java.awt.Color;
24 import java.awt.Font;
25 import java.awt.geom.Ellipse2D;
26 import java.awt.geom.Rectangle2D;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Vector;
32 
33 import org.jfree.chart.ChartFactory;
34 import org.jfree.chart.JFreeChart;
35 import org.jfree.chart.annotations.XYTextAnnotation;
36 import org.jfree.chart.axis.LogarithmicAxis;
37 import org.jfree.chart.labels.CustomXYToolTipGenerator;
38 import org.jfree.chart.plot.PlotOrientation;
39 import org.jfree.chart.plot.XYPlot;
40 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
41 import org.jfree.chart.urls.CustomXYURLGenerator;
42 import org.jfree.data.xy.DefaultXYDataset;
43 import org.jfree.data.xy.XYSeries;
44 import org.jfree.data.xy.XYSeriesCollection;
50 
51 public final class PtCountsSimRealPerHourGraph extends CountsGraph {
56  private int hour;
61 
62  @Deprecated // use standard counts package
63  public PtCountsSimRealPerHourGraph(final List<CountSimComparison> ccl,
64  final int iteration, final String filename, PtCountsType countsType) {
65  super(ccl, iteration, filename, filename);
66  this.countsType = countsType;
67  }
68 
74  @Override
75  @Deprecated // use standard counts package
76  public JFreeChart createChart(final int hour) {
77  this.hour = hour;
78 
79  XYSeriesCollection dataset0 = new XYSeriesCollection();
80  XYSeries series = new XYSeries("MATSim volumes");
81  // easier to use another dataset
82  XYSeriesCollection dataset_outliers = new XYSeriesCollection();
83  XYSeries series_outliers = new XYSeries("MATSim outliers");
84 
85  CustomXYURLGenerator url_gen = new CustomXYURLGenerator();
86  CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator();
87 
88  final ArrayList<String> urls = new ArrayList<String>();
89  final ArrayList<String> tooltips = new ArrayList<String>();
90  List<Comp> comps = new Vector<Comp>();
91 
92  Iterator<CountSimComparison> l_it = this.ccl_.iterator();
93  // int elementCounter=0;
94  while (l_it.hasNext()) {
95  CountSimComparison cc = l_it.next();
96 
97  /*
98  * values with simVal==0.0 or countVal==0.0 are drawn on the x==1
99  * or/and y==1-line Such values are the result of a poor simulation
100  * run, but they can also represent a valid result (closing summer
101  * road during winter time)
102  */
103  if (cc.getHour() == hour) {
104  // elementCounter++;
105  double realVal = 1.0;
106  double simVal = 1.0;
107  if (cc.getCountValue() > 0.0 && cc.getSimulationValue() > 0.0) {
108  realVal = cc.getCountValue();
109  simVal = cc.getSimulationValue();
110  series.add(realVal, simVal);
111  comps.add(new Comp(realVal, "link" + cc.getId() + ".html",
112  "Link " + cc.getId() + "; " + "Count: " + realVal
113  + ", Sim: " + simVal));
114  } else {
115  realVal = Math.max(1.0, cc.getCountValue());
116  simVal = Math.max(1.0, cc.getSimulationValue());
117  series_outliers.add(realVal, simVal);
118  }
119 
120  }// if
121  }// while
122  dataset0.addSeries(series);
123  dataset_outliers.addSeries(series_outliers);
124 
125  /*
126  * first we have to sort the vector according to the rendering ordering
127  * (which is the x value). REALLY??? After hours of searching no better
128  * solution found! please help!
129  */
130 
131  Collections.sort(comps, new MyComparator());
132 
133  for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) {
134  Comp cp = iter.next();
135  urls.add(cp.getURL());
136  tooltips.add(cp.getTooltip());
137  }
138 
139  url_gen.addURLSeries(urls);
140  tt_gen.addToolTipSeries(tooltips);
141 
142  String title = "[" + this.countsType + "]\tVolumes " + (hour - 1)
143  + ":00 - " + (hour) + ":00, Iteration: " + this.iteration_;
144  this.setChartTitle(title);
145  this.chart_ = ChartFactory.createXYLineChart(title,
146  "Count Volumes [veh/h]", // x axis label
147  "Sim Volumes [veh/h]", // y axis label
148  dataset0, // data
149  PlotOrientation.VERTICAL, false, // include legend
150  true, // tooltips
151  true // urls
152  );
153  XYPlot plot = this.chart_.getXYPlot();
154  final LogarithmicAxis axis_x = new LogarithmicAxis(
155  "Count Volumes [veh/h]");
156  final LogarithmicAxis axis_y = new LogarithmicAxis(
157  "Sim Volumes [veh/h]");
158  axis_x.setAllowNegativesFlag(false);
159  axis_y.setAllowNegativesFlag(false);
160 
161  // regular values
162  XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
163  renderer.setDefaultLinesVisible(false);
164  renderer.setURLGenerator(url_gen);
165  renderer.setSeriesPaint(0, Color.black);
166  renderer.setSeriesToolTipGenerator(0, tt_gen);
167  renderer
168  .setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));
169 
170  // outliers
171  XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
172  renderer2.setDefaultLinesVisible(false);
173  renderer2.setSeriesPaint(0, Color.red);
174  renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));
175 
176  // error band
177  DefaultXYDataset dataset1 = new DefaultXYDataset();
178  dataset1.addSeries("f1x", new double[][] { { 1.0, 10000.0 },
179  { 1.0, 10000.0 } });
180  dataset1.addSeries("f2x", new double[][] { { 1.0, 10000.0 },
181  { 2.0, 20000.0 } });
182  dataset1.addSeries("f05x", new double[][] { { 2.0, 10000.0 },
183  { 1.0, 5000.0 } });
184 
185  XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer();
186  renderer3.setDefaultShapesVisible(false);
187  renderer3.setSeriesPaint(0, Color.blue);
188  renderer3.setSeriesPaint(1, Color.blue);
189  renderer3.setSeriesPaint(2, Color.blue);
190  renderer3.setDefaultSeriesVisibleInLegend(false);
191  renderer3.setSeriesItemLabelsVisible(0, true);
192  renderer3.setSeriesItemLabelsVisible(1, false);
193  renderer3.setSeriesItemLabelsVisible(2, false);
194 
195  XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count",
196  12000.0, 15500.0);
197  annotation0.setFont(new Font("SansSerif", Font.BOLD, 11));
198  plot.addAnnotation(annotation0);
199  XYTextAnnotation annotation1 = new XYTextAnnotation("count", 13000.0,
200  10000.0);
201  annotation1.setFont(new Font("SansSerif", Font.BOLD, 11));
202  plot.addAnnotation(annotation1);
203  XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count",
204  11000.0, 3500.0);
205  annotation2.setFont(new Font("SansSerif", Font.BOLD, 11));
206  plot.addAnnotation(annotation2);
207 
208  plot.setDomainAxis(axis_x);
209  plot.setRangeAxis(axis_y);
210  plot.setRenderer(0, renderer);
211 
212  plot.setRenderer(1, renderer2);
213  plot.setDataset(1, dataset_outliers);
214 
215  plot.setRenderer(2, renderer3);
216  plot.setDataset(2, dataset1);
217 
218  plot.getRangeAxis().setRange(1.0, 19000.0);
219  plot.getDomainAxis().setRange(1.0, 19000.0);
220 
221  return this.chart_;
222  }// drawGraph
223 
230  @Deprecated // use standard counts package
231  public int getHour() {
232  return this.hour;
233  }
234 }
void setChartTitle(final String chartTitle)
PtCountsSimRealPerHourGraph(final List< CountSimComparison > ccl, final int iteration, final String filename, PtCountsType countsType)