25package umontreal.ssj.charts;
27import umontreal.ssj.stat.TallyStore;
29import org.jfree.data.xy.XYSeriesCollection;
30import org.jfree.data.xy.XYSeries;
31import cern.colt.list.DoubleArrayList;
33import java.util.Locale;
34import java.util.Formatter;
53 private final double EMPIR_EPS = 0.015625;
55 private String[] marksType;
56 private String[] dashPattern;
59 private double setZeroPoint(
double x1) {
61 return x1 - EMPIR_EPS * Math.abs(x1);
69 seriesCollection =
new XYSeriesCollection();
80 seriesCollection =
new XYSeriesCollection();
82 XYSeriesCollection tempSeriesCollection = (XYSeriesCollection) seriesCollection;
83 for (
int j = 0; j < data.length; j++) {
84 XYSeries serie =
new XYSeries(
" ");
85 serie.add(setZeroPoint(data[j][0]), 0);
86 for (
int k = 0; k < data[j].length; k++)
87 serie.add(data[j][k], (
double) (k + 1) / data[j].length);
88 tempSeriesCollection.addSeries(serie);
92 for (
int i = 0; i < tempSeriesCollection.getSeriesCount(); i++) {
97 marksType =
new String[tempSeriesCollection.getSeriesCount()];
98 dashPattern =
new String[tempSeriesCollection.getSeriesCount()];
99 for (
int i = 0; i < tempSeriesCollection.getSeriesCount(); i++) {
101 dashPattern[i] =
"solid";
115 seriesCollection =
new XYSeriesCollection();
117 XYSeriesCollection tempSeriesCollection = (XYSeriesCollection) seriesCollection;
118 XYSeries serie =
new XYSeries(
" ");
119 serie.add(setZeroPoint(data[0]), 0);
120 for (
int k = 0; k < numPoints; k++)
121 serie.add(data[k], (
double) (k + 1) / numPoints);
122 tempSeriesCollection.addSeries(serie);
128 marksType =
new String[1];
129 dashPattern =
new String[1];
131 dashPattern[0] =
"solid";
145 seriesCollection =
new XYSeriesCollection();
147 XYSeriesCollection tempSeriesCollection = (XYSeriesCollection) seriesCollection;
149 for (
int j = 0; j < data.length; j++) {
150 XYSeries serie =
new XYSeries(
" ");
151 serie.add(setZeroPoint(data[j].
get(0)), 0);
152 for (
int k = 0; k < data[j].size(); k++)
153 serie.add(data[j].get(k), (
double) (k + 1) / data[j].size());
154 tempSeriesCollection.addSeries(serie);
158 for (
int i = 0; i < tempSeriesCollection.getSeriesCount(); i++) {
163 marksType =
new String[tempSeriesCollection.getSeriesCount()];
164 dashPattern =
new String[tempSeriesCollection.getSeriesCount()];
165 for (
int i = 0; i < tempSeriesCollection.getSeriesCount(); i++) {
167 dashPattern[i] =
"solid";
180 seriesCollection =
new XYSeriesCollection();
182 XYSeriesCollection tempSeriesCollection = (XYSeriesCollection) seriesCollection;
184 for (
int j = 0; j < tallies.length; j++) {
188 XYSeries serie =
new XYSeries(
" ");
189 serie.add(setZeroPoint(array[0]), 0);
190 for (
int k = 0; k < tallies[j].numberObs(); k++)
191 serie.add(array[k], (
double) (k + 1) / tallies[j].numberObs());
192 tempSeriesCollection.addSeries(serie);
196 for (
int i = 0; i < tempSeriesCollection.getSeriesCount(); i++) {
201 marksType =
new String[tempSeriesCollection.getSeriesCount()];
202 dashPattern =
new String[tempSeriesCollection.getSeriesCount()];
203 for (
int i = 0; i < tempSeriesCollection.getSeriesCount(); i++) {
205 dashPattern[i] =
"solid";
218 seriesCollection = data;
221 for (
int i = 0; i < data.getSeriesCount(); i++) {
223 XYSeries ser = data.getSeries(i);
224 ser.add(setZeroPoint(ser.getX(0).doubleValue()), 0);
228 marksType =
new String[data.getSeriesCount()];
229 dashPattern =
new String[data.getSeriesCount()];
230 for (
int i = 0; i < data.getSeriesCount(); i++) {
232 dashPattern[i] =
"solid";
247 public int add(
double[] observationSet) {
248 return add(observationSet, observationSet.length);
260 public int add(
double[] observationSet,
int numPoints) {
261 XYSeriesCollection tempSeriesCollection = (XYSeriesCollection) seriesCollection;
263 XYSeries serie =
new XYSeries(
" ");
264 serie.add(setZeroPoint(observationSet[0]), 0);
265 for (
int k = 0; k < numPoints; k++)
266 serie.add(observationSet[k], (
double) (k + 1) / numPoints);
267 tempSeriesCollection.addSeries(serie);
270 int j = seriesCollection.getSeriesCount() - 1;
273 String[] newMarksType =
new String[seriesCollection.getSeriesCount()];
274 String[] newDashPattern =
new String[seriesCollection.getSeriesCount()];
275 for (j = 0; j < seriesCollection.getSeriesCount() - 1; j++) {
276 newMarksType[j] = marksType[j];
277 newDashPattern[j] = dashPattern[j];
280 newMarksType[j] =
"*";
281 newDashPattern[j] =
"solid";
282 marksType = newMarksType;
283 dashPattern = newDashPattern;
285 return seriesCollection.getSeriesCount() - 1;
295 public int add(DoubleArrayList observationSet) {
296 return add(observationSet.elements(), observationSet.size());
326 return marksType[series];
339 this.marksType[series] = marksType;
349 return dashPattern[series];
361 this.dashPattern[series] = dashPattern;
364 public String
toLatex(
double XScale,
double YScale,
double XShift,
double YShift,
double xmin,
double xmax,
365 double ymin,
double ymax) {
369 xmin = Math.min(XShift, xmin);
370 xmax = Math.max(XShift, xmax);
371 ymin = Math.min(YShift, ymin);
372 ymax = Math.max(YShift, ymax);
374 XYSeriesCollection tempSeriesCollection = (XYSeriesCollection) seriesCollection;
375 Formatter formatter =
new Formatter(Locale.US);
376 for (
int i = tempSeriesCollection.getSeriesCount() - 1; i >= 0; i--) {
378 Color color = (Color) renderer.getSeriesPaint(i);
380 if (colorString ==
null) {
381 colorString =
"color" + i;
382 formatter.format(
"\\definecolor{%s}{rgb}{%.2f, %.2f, %.2f}%n", colorString, color.getRed() / 255.0,
383 color.getGreen() / 255.0, color.getBlue() / 255.0);
386 double currentX, nextX;
387 for (
int j = 0; j < tempSeriesCollection.getItemCount(i); j++) {
388 currentX = tempSeriesCollection.getXValue(i, j);
389 if (j == tempSeriesCollection.getItemCount(i) - 1)
392 nextX = Math.min(tempSeriesCollection.getXValue(i, j + 1), xmax);
394 if ((currentX >= xmin && currentX <= xmax)) {
395 formatter.format(
"\\draw [color=%s] plot[mark=%s] (%.4f, %.4f) --plot[style=%s] (%.4f, %.4f); %%%n",
396 colorString, marksType[i], (currentX - XShift) * XScale,
397 (tempSeriesCollection.getYValue(i, j) - YShift) * YScale, dashPattern[i],
398 (nextX - XShift) * XScale, (tempSeriesCollection.getYValue(i, j) - YShift) * YScale);
402 return formatter.toString();
A renderer that draws horizontal lines between points and/or draws shapes at each data point to provi...
EmpiricalSeriesCollection()
Creates a new EmpiricalSeriesCollection instance with empty dataset.
String getMarksType(int series)
Returns the mark type associated with the series-th data series.
EmpiricalSeriesCollection(double[] data, int numPoints)
Creates a new EmpiricalSeriesCollection instance with default parameters and a given series data.
int add(DoubleArrayList observationSet)
Adds a data series into the series collection.
EmpiricalSeriesCollection(DoubleArrayList... data)
Creates a new EmpiricalSeriesCollection instance with default parameters and given data.
String toLatex(double XScale, double YScale, double XShift, double YShift, double xmin, double xmax, double ymin, double ymax)
Formats and returns a string containing a LaTeX-compatible source code which represents this data ser...
String getDashPattern(int series)
Returns the dash pattern associated with the series-th data series.
int add(double[] observationSet)
Adds a data series into the series collection.
int add(double[] observationSet, int numPoints)
Adds a data series into the series collection.
EmpiricalSeriesCollection(double[]... data)
Creates a new EmpiricalSeriesCollection instance with default parameters and given data series.
void setMarksType(int series, String marksType)
Adds marks on points to a data series.
int add(TallyStore tally)
Adds a data series into the series collection.
void setDashPattern(int series, String dashPattern)
Selects dash pattern for a data series.
EmpiricalSeriesCollection(TallyStore... tallies)
Creates a new EmpiricalSeriesCollection instance with default parameters and given data.
EmpiricalSeriesCollection(XYSeriesCollection data)
Creates a new EmpiricalSeriesCollection instance with default parameters and given data series.
Stores data used in a XYChart.
static Color getDefaultColor(int index)
Gives the default color associated with a series.
static String detectXColorClassic(Color color)
Converts a java Color object into a friendly and readable LaTeX/xcolor string.
This class is a variant of Tally for which the individual observations are stored in a list implement...
void quickSort()
Sorts the elements of this probe using the quicksort from Colt.
double[] getArray()
Returns the observations stored in this probe.
int numberObs()
Returns the number of observations given to this probe since its last initialization.