SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
CategoryChart.java
1/*
2 * Class: CategoryChart
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.JFreeChart;
28import javax.swing.JFrame;
29
52public abstract class CategoryChart {
53
54 protected Axis YAxis;
55 protected SSJCategorySeriesCollection dataset;
56 protected JFreeChart chart;
57 protected boolean latexDocFlag = true;
58
59 protected boolean autoRange;
60 protected double[] manualRange;
61
62 protected boolean grid = false;
63 protected double ystepGrid;
64
65 final protected double BOR = 0.1;
66
72 public JFreeChart getJFreeChart() {
73 return chart;
74 }
75
81 public Axis getYAxis() {
82 return YAxis;
83 }
84
93 public abstract JFrame view(int width, int height);
94
100 public String getTitle() {
101 return chart.getTitle().getText();
102 }
103
110 public void setTitle(String title) {
111 chart.setTitle(title);
112 }
113
117 public void setAutoRange() {
118 autoRange = true;
119
120 double BorneMin = Math.abs((dataset.getRangeBounds())[0]);
121 double BorneMax = Math.abs((dataset.getRangeBounds())[1]);
122
123 double max = Math.max(BorneMin, BorneMax) * BOR;
124 YAxis.getAxis().setLowerBound(BorneMin - max);
125 YAxis.getAxis().setUpperBound(BorneMax + max);
126 YAxis.setLabelsAuto();
127 }
128
135 private void setManualRange(double[] range) {
136 if (range.length != 2)
137 throw new IllegalArgumentException("range must have the format: [ymin, ymax]");
138 autoRange = false;
139 YAxis.getAxis().setLowerBound(Math.min(range[0], range[1]));
140 YAxis.getAxis().setUpperBound(Math.max(range[0], range[1]));
141 }
142
153 public void enableGrid(double xstep, double ystep) {
154 this.grid = true;
155 this.ystepGrid = ystep;
156 }
157
161 public void disableGrid() {
162 this.grid = false;
163 }
164
168
172 public abstract String toLatex(double width, double height);
173
177 public void setLatexDocFlag(boolean flag) {
178 latexDocFlag = flag;
179 }
180
181 protected double computeYScale(double position) {
182 double[] bounds = new double[2];
183 bounds[0] = YAxis.getAxis().getLowerBound();
184 bounds[1] = YAxis.getAxis().getUpperBound();
185
186 if (position < bounds[0])
187 bounds[0] = position;
188 if (position > bounds[1])
189 bounds[1] = position;
190 bounds[0] -= position;
191 bounds[1] -= position;
192 return computeScale(bounds);
193 }
194
195 protected double computeScale(double[] bounds) {
196 int tenPowerRatio = 0;
197 // echelle < 1 si les valeurs sont grandes
198 while (bounds[1] > 1000 || bounds[0] < -1000) {
199 bounds[1] /= 10;
200 bounds[0] /= 10;
201 tenPowerRatio++;
202 }
203 // echelle > 1 si les valeurs sont petites
204 while (bounds[1] < 100 && bounds[0] > -100) {
205 bounds[1] *= 10;
206 bounds[0] *= 10;
207 tenPowerRatio--;
208 }
209 return 1 / Math.pow(10, tenPowerRatio);
210 }
211}
212
Represents an axis of a chart encapsulated by an instance of XYChart.
Definition Axis.java:42
NumberAxis getAxis()
Returns the NumberAxis instance (from JFreeChart) linked with the current variable.
Definition Axis.java:98
This class provides tools to create charts from data in a simple way.
void setLatexDocFlag(boolean flag)
Same as in XYChart.
Axis getYAxis()
Returns the chart’s range axis ( -axis) object.
void enableGrid(double xstep, double ystep)
Puts a grid on the background.
void setAutoRange()
Sets chart range to automatic values.
JFreeChart getJFreeChart()
Returns the JFreeChart object associated with this chart.
void setTitle(String title)
Sets a title to this chart.
abstract String toLatex(double width, double height)
Transforms the chart into LaTeX form and returns it as a String.
void disableGrid()
Disables the background grid.
abstract JFrame view(int width, int height)
Displays the chart on the screen using Swing.
String getTitle()
Gets the current chart title.