SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
SSJXYSeriesCollection.java
1/*
2 * Class: SSJXYSeriesCollection
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.data.xy.XYDataset;
28import org.jfree.chart.renderer.xy.XYItemRenderer;
29
30import java.util.Locale;
31import java.util.Formatter;
32import java.awt.Color;
33
41public abstract class SSJXYSeriesCollection {
42 protected XYItemRenderer renderer;
43 protected XYDataset seriesCollection;
44
48
56 public double getX(int series, int index) {
57 return seriesCollection.getXValue(series, index);
58 }
59
67 public double getY(int series, int index) {
68 return seriesCollection.getYValue(series, index);
69 }
70
76 public XYDataset getSeriesCollection() {
77 return seriesCollection;
78 }
79
85 public double[] getDomainBounds() {
86 double max = -1.0e307, min = 1.0e307;
87
88 if (seriesCollection.getSeriesCount() != 0 && seriesCollection.getItemCount(0) != 0)
89 max = min = seriesCollection.getXValue(0, 0);
90
91 for (int i = 0; i < seriesCollection.getSeriesCount(); i++) {
92 for (int j = 0; j < seriesCollection.getItemCount(i); j++) {
93 max = Math.max(max, seriesCollection.getXValue(i, j));
94 min = Math.min(min, seriesCollection.getXValue(i, j));
95 }
96 }
97
98 double[] retour = { min, max };
99 return retour;
100 }
101
107 public double[] getRangeBounds() {
108 double max = -1.7e307, min = 1.7e307;
109
110 if (seriesCollection.getSeriesCount() != 0 && seriesCollection.getItemCount(0) != 0)
111 max = min = seriesCollection.getYValue(0, 0);
112
113 for (int i = 0; i < seriesCollection.getSeriesCount(); i++) {
114 for (int j = 0; j < seriesCollection.getItemCount(i); j++) {
115 max = Math.max(max, seriesCollection.getYValue(i, j));
116 min = Math.min(min, seriesCollection.getYValue(i, j));
117 }
118 }
119
120 double[] retour = { min, max };
121 return retour;
122 }
123
129 public String toString() {
130 Formatter formatter = new Formatter(Locale.US);
131 for (int i = 0; i < seriesCollection.getSeriesCount(); i++) {
132 formatter.format(" Series " + i + " : %n");
133 for (int j = 0; j < seriesCollection.getItemCount(i); j++)
134 formatter.format("%15e,%15e%n", getX(i, j), getY(i, j));
135 }
136 return formatter.toString();
137 }
138
142
146
152 public XYItemRenderer getRenderer() {
153 return renderer;
154 }
155
163 public void setRenderer(XYItemRenderer renderer) {
164 this.renderer = renderer;
165 }
166
172 public Color getColor(int series) {
173 return (Color) renderer.getSeriesPaint(series);
174 }
175
182 public void setColor(int series, Color color) {
183 renderer.setSeriesPaint(series, color);
184 }
185
202 public abstract String toLatex(double XScale, double YScale, double XShift, double YShift, double xmin, double xmax,
203 double ymin, double ymax);
204
212 protected static String detectXColorClassic(Color color) {
213 String retour = null;
214
215 int red = color.getRed();
216 int green = color.getGreen();
217 int blue = color.getBlue();
218
219 // On utilise pas la method Color.equals(Color ) car on ne veut pas tester le
220 // parametre de transparence : Alpha
221 if (red == Color.GREEN.getRed() && blue == Color.GREEN.getBlue() && green == Color.GREEN.getGreen())
222 return "green";
223 else if (red == Color.RED.getRed() && blue == Color.RED.getBlue() && green == Color.RED.getGreen())
224 return "red";
225 else if (red == Color.WHITE.getRed() && blue == Color.WHITE.getBlue() && green == Color.WHITE.getGreen())
226 return "white";
227 else if (red == Color.GRAY.getRed() && blue == Color.GRAY.getBlue() && green == Color.GRAY.getGreen())
228 return "gray";
229 else if (red == Color.BLACK.getRed() && blue == Color.BLACK.getBlue() && green == Color.BLACK.getGreen())
230 return "black";
231 else if (red == Color.YELLOW.getRed() && blue == Color.YELLOW.getBlue() && green == Color.YELLOW.getGreen())
232 return "yellow";
233 else if (red == Color.MAGENTA.getRed() && blue == Color.MAGENTA.getBlue() && green == Color.MAGENTA.getGreen())
234 return "magenta";
235 else if (red == Color.CYAN.getRed() && blue == Color.CYAN.getBlue() && green == Color.CYAN.getGreen())
236 return "cyan";
237 else if (red == Color.BLUE.getRed() && blue == Color.BLUE.getBlue() && green == Color.BLUE.getGreen())
238 return "blue";
239 else if (red == Color.DARK_GRAY.getRed() && blue == Color.DARK_GRAY.getBlue()
240 && green == Color.DARK_GRAY.getGreen())
241 return "darkgray";
242 else if (red == Color.LIGHT_GRAY.getRed() && blue == Color.LIGHT_GRAY.getBlue()
243 && green == Color.LIGHT_GRAY.getGreen())
244 return "lightgray";
245 else if (red == Color.ORANGE.getRed() && blue == Color.ORANGE.getBlue() && green == Color.ORANGE.getGreen())
246 return "orange";
247 else if (red == Color.PINK.getRed() && blue == Color.PINK.getBlue() && green == Color.PINK.getGreen())
248 return "pink";
249
250 if (red == 192 && blue == 128 && green == 64)
251 return "brown";
252 else if (red == 128 && blue == 128 && green == 0)
253 return "olive";
254 else if (red == 128 && blue == 0 && green == 128)
255 return "violet";
256 else if (red == 192 && blue == 0 && green == 64)
257 return "purple";
258 else
259 return null;
260 }
261
268 protected static Color getDefaultColor(int index) {
269 if (index % 6 == 0)
270 return Color.RED;
271 else if (index % 6 == 1)
272 return Color.BLUE;
273 else if (index % 6 == 2)
274 return Color.GREEN;
275 else if (index % 6 == 3)
276 return Color.YELLOW;
277 else if (index % 6 == 4)
278 return Color.MAGENTA;
279 else
280 return Color.CYAN;
281 }
282
283 // Returns maximum value in table t
284 protected static double max(double[] t) {
285 double aux = t[0];
286 for (int i = 1; i < t.length; i++)
287 if (t[i] > aux)
288 aux = t[i];
289 return aux;
290 }
291
292 // Returns minimum value in table t
293 protected static double min(double[] t) {
294 double aux = t[0];
295 for (int i = 1; i < t.length; i++)
296 if (t[i] < aux)
297 aux = t[i];
298 return aux;
299 }
300}
301
double getY(int series, int index)
Returns the -value at the specified index in the specified series.
static Color getDefaultColor(int index)
Gives the default color associated with a series.
abstract 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...
XYDataset getSeriesCollection()
Returns the XYDataset object associated with the current object.
double[] getRangeBounds()
Returns range ( -coordinates) min and max values.
double getX(int series, int index)
Returns the -value at the specified index in the specified series.
double[] getDomainBounds()
Returns domain ( -coordinates) min and max values.
XYItemRenderer getRenderer()
Returns the XYItemRenderer object associated with the current object.
static String detectXColorClassic(Color color)
Converts a java Color object into a friendly and readable LaTeX/xcolor string.
void setRenderer(XYItemRenderer renderer)
Sets the XYItemRenderer object associated with the current variable.
void setColor(int series, Color color)
Sets a new plotting color to the series .
Color getColor(int series)
Gets the current plotting color of the selected series.
String toString()
Returns in a String all data contained in the current object.