SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BoxSeriesCollection.java
1/*
2 * Class: BoxSeriesCollection
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.charts;
26
27import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
28import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
29
30import java.util.List;
31import java.util.ArrayList;
32import java.util.Locale;
33import java.util.Formatter;
34
46 final double BARWIDTH = 0.1;
47
52 renderer = new BoxAndWhiskerRenderer();
53 seriesCollection = new DefaultBoxAndWhiskerCategoryDataset();
54 ((BoxAndWhiskerRenderer) renderer).setMaximumBarWidth(BARWIDTH);
55 }
56
65 public BoxSeriesCollection(double[] data, int numPoints) {
66 renderer = new BoxAndWhiskerRenderer();
67
68 ((BoxAndWhiskerRenderer) renderer).setMaximumBarWidth(BARWIDTH);
69 seriesCollection = new DefaultBoxAndWhiskerCategoryDataset();
70
71 DefaultBoxAndWhiskerCategoryDataset tempSeriesCollection = (DefaultBoxAndWhiskerCategoryDataset) seriesCollection;
72
73 final List<Double> list = new ArrayList<Double>();
74 for (int i = 0; i < numPoints; i++)
75 list.add(data[i]);
76
77 tempSeriesCollection.add(list, 0, 0);
78 }
79
86 public BoxSeriesCollection(double[]... data) {
87 renderer = new BoxAndWhiskerRenderer();
88 seriesCollection = new DefaultBoxAndWhiskerCategoryDataset();
89
90 DefaultBoxAndWhiskerCategoryDataset tempSeriesCollection = (DefaultBoxAndWhiskerCategoryDataset) seriesCollection;
91
92 for (int i = 0; i < data.length; i++) {
93 if (data[i].length == 0)
94 throw new IllegalArgumentException("Unable to render the plot. data[" + i + "] contains no row");
95 final List<Double> list = new ArrayList<Double>();
96 for (int j = 0; j < data[i].length - 1; j++)
97 list.add(data[i][j]);
98 tempSeriesCollection.add(list, 0, "Serie " + i);
99 list.clear();
100 }
101 ((BoxAndWhiskerRenderer) renderer).setMaximumBarWidth(BARWIDTH);
102 }
103
111 public BoxSeriesCollection(DefaultBoxAndWhiskerCategoryDataset data) {
112 renderer = new BoxAndWhiskerRenderer();
113 ((BoxAndWhiskerRenderer) renderer).setFillBox(false);
114 seriesCollection = data;
115 ((BoxAndWhiskerRenderer) renderer).setMaximumBarWidth(BARWIDTH);
116 }
117
121
130 public int add(double[] data) {
131 return add(data, data.length);
132 }
133
144 public int add(double[] data, int numPoints) {
145 DefaultBoxAndWhiskerCategoryDataset tempSeriesCollection = (DefaultBoxAndWhiskerCategoryDataset) seriesCollection;
146
147 final List<Double> list = new ArrayList<Double>();
148 for (int i = 0; i < numPoints; i++)
149 list.add(data[i]);
150
151 int count = tempSeriesCollection.getColumnCount();
152 tempSeriesCollection.add(list, 0, "Serie " + count);
153 return count;
154 }
155
162 public String getName(int series) {
163 return (String) ((DefaultBoxAndWhiskerCategoryDataset) seriesCollection).getColumnKey(series);
164 }
165
171 public double[] getRangeBounds() {
172 double max = 0, min = 0;
173 DefaultBoxAndWhiskerCategoryDataset tempSeriesCollection = (DefaultBoxAndWhiskerCategoryDataset) seriesCollection;
174
175 if (tempSeriesCollection.getColumnCount() != 0 && tempSeriesCollection.getRowCount() != 0) {
176 max = tempSeriesCollection.getItem(0, 0).getMaxOutlier().doubleValue();
177 min = tempSeriesCollection.getItem(0, 0).getMinOutlier().doubleValue();
178 }
179
180 for (int i = 0; i < tempSeriesCollection.getRowCount(); i++) {
181 for (int j = 0; j < tempSeriesCollection.getColumnCount(); j++) {
182 max = Math.max(max, tempSeriesCollection.getItem(i, j).getMaxOutlier().doubleValue());
183 min = Math.min(min, tempSeriesCollection.getItem(i, j).getMinOutlier().doubleValue());
184 }
185 }
186
187 double[] retour = { min, max };
188 return retour;
189 }
190
196 public String toString() {
197 Formatter formatter = new Formatter(Locale.US);
198 for (int i = 0; i < seriesCollection.getRowCount(); i++) {
199 formatter.format(" Series " + i + " : %n");
200 for (int j = 0; j < seriesCollection.getColumnCount(); j++)
201 formatter.format(",%15e%n", seriesCollection.getValue(i, j));
202 }
203 return formatter.toString();
204 }
205
213 public String toLatex(double YScale, double YShift, double ymin, double ymax) {
214 throw new UnsupportedOperationException(" NOT implemented yet");
215 /*
216 * // Calcule les bornes reelles du graphique, en prenant en compte la position
217 * des axes
218 *
219 * ymin = Math.min(YShift, ymin); ymax = Math.max(YShift, ymax);
220 *
221 * DefaultBoxAndWhiskerCategoryDataset tempSeriesCollection =
222 * (DefaultBoxAndWhiskerCategoryDataset)seriesCollection; Formatter formatter =
223 * new Formatter(Locale.US); // double var; // double margin =
224 * ((BoxAndWhiskerRenderer)renderer).getMargin();
225 *
226 * // for (int i = tempSeriesCollection.getColumnCount() - 1; i >= 0; i--) { //
227 * List temp = tempSeriesCollection.getBins(i); // ListIterator iter =
228 * temp.listIterator(); // // Color color = (Color)renderer.getSeriesPaint(i);
229 * // String colorString = detectXColorClassic(color); // if (colorString ==
230 * null) { // colorString = "color"+i; // formatter.format(
231 * "\\definecolor{%s}{rgb}{%.2f, %.2f, %.2f}%n", // colorString,
232 * color.getRed()/255.0, color.getGreen()/255.0, color.getBlue()/255.0); // } //
233 * // HistogramBin currentBin=null; // while(iter.hasNext()) { // double
234 * currentMargin; // currentBin = (HistogramBin)iter.next(); // currentMargin =
235 * ((margin*(currentBin.getEndBoundary()-currentBin.getStartBoundary()))-XShift)
236 * *XScale; // if ((currentBin.getStartBoundary() >= xmin &&
237 * currentBin.getStartBoundary() <= xmax) // && (currentBin.getCount() >= ymin
238 * && currentBin.getCount() <= ymax) ) // { // var = Math.min(
239 * currentBin.getEndBoundary(), xmax); // if (filled[i]) { // formatter.
240 * format("\\filldraw [line width=%.2fpt, opacity=%.2f, color=%s] ([xshift=%.4f] %.4f, %.4f) rectangle ([xshift=-%.4f] %.4f, %.4f); %%%n"
241 * , // lineWidth[i], (color.getAlpha()/255.0), colorString, // currentMargin,
242 * (currentBin.getStartBoundary()-XShift)*XScale, 0.0, // currentMargin,
243 * (var-XShift)*XScale, (currentBin.getCount()-YShift)*YScale); // } // else {
244 * // formatter.
245 * format("\\draw [line width=%.2fpt, color=%s] ([xshift=%.4f] %.4f, %.4f) rectangle ([xshift=-%.4f] %.4f, %.4f); %%%n"
246 * , // lineWidth[i], colorString, // currentMargin,
247 * (currentBin.getStartBoundary()-XShift)*XScale, 0.0, // currentMargin,
248 * (var-XShift)*XScale, (currentBin.getCount()-YShift)*YScale); // } // } //
249 * else if ( (currentBin.getStartBoundary() >= xmin &&
250 * currentBin.getStartBoundary() <= xmax) // && (currentBin.getCount() >= ymin
251 * && currentBin.getCount() > ymax) ) // { // Cas ou notre rectangle ne peut pas
252 * etre affiche en entier (trop haut) // var = Math.min(
253 * currentBin.getEndBoundary(), xmax); // if (filled[i]) { // formatter.
254 * format("\\filldraw [line width=%.2fpt, opacity=%.2f, color=%s] ([xshift=%.4f] %.4f, %.4f) rectangle ([xshift=-%.4f] %.4f, %.4f); %%%n"
255 * , // lineWidth[i], (color.getAlpha()/255.0), colorString, // currentMargin,
256 * (currentBin.getStartBoundary()-XShift)*XScale, 0.0, // currentMargin,
257 * (var-XShift)*XScale, (ymax-YShift)*YScale); // formatter.
258 * format("\\draw [line width=%.2fpt, color=%s, style=dotted] ([xshift=%.4f] %.4f, %.4f) rectangle ([yshift=3mm, xshift=-%.4f] %.4f, %.4f); %%%n"
259 * , // lineWidth[i], colorString, // currentMargin,
260 * (currentBin.getStartBoundary()-XShift)*XScale, (ymax-YShift)*YScale, //
261 * currentMargin, (var-XShift)*XScale, (ymax-YShift)*YScale); // } // else { //
262 * formatter.
263 * format("\\draw [line width=%.2fpt, color=%s] ([xshift=%.4f] %.4f, %.4f) rectangle ([xshift=-%.4f] %.4f, %.4f); %%%n"
264 * , // lineWidth[i], colorString, // currentMargin,
265 * (currentBin.getStartBoundary()-XShift)*XScale, 0.0, // currentMargin,
266 * (var-XShift)*XScale, (ymax-YShift)*YScale); // // formatter.
267 * format("\\draw [line width=%.2fpt, color=%s, style=dotted] ([xshift=%.4f] %.4f, %.4f) rectangle ([yshift=3mm, xshift=-%.4f] %.4f, %.4f); %%%n"
268 * , // lineWidth[i], colorString, // currentMargin,
269 * (currentBin.getStartBoundary()-XShift)*XScale, (ymax-YShift)*YScale, //
270 * currentMargin, (var-XShift)*XScale, (ymax-YShift)*YScale); // } // } // } //
271 * } return formatter.toString();
272 */
273 }
274
275}
276
String getName(int series)
Gets the current name of the selected series.
int add(double[] data, int numPoints)
Adds a data series into the series collection.
BoxSeriesCollection(DefaultBoxAndWhiskerCategoryDataset data)
Creates a new BoxSeriesCollection instance with default parameters and given data series.
int add(double[] data)
Adds a data series into the series collection.
BoxSeriesCollection(double[]... data)
Creates a new BoxSeriesCollection instance with default parameters and given data series.
BoxSeriesCollection(double[] data, int numPoints)
Creates a new BoxSeriesCollection instance with default parameters and input series data.
double[] getRangeBounds()
Returns the range ( -coordinates) min and max values.
BoxSeriesCollection()
Creates a new BoxSeriesCollection instance with an empty dataset.
String toLatex(double YScale, double YShift, double ymin, double ymax)
NOT IMPLEMENTED: To do.
String toString()
Returns in a String all data contained in the current object.