25package umontreal.ssj.charts;
27import org.jfree.chart.JFreeChart;
28import javax.swing.JFrame;
56 protected JFreeChart chart;
57 protected boolean latexDocFlag =
true;
59 protected boolean autoRange;
60 protected double[] manualRange;
62 protected boolean grid =
false;
63 protected double ystepGrid;
65 final protected double BOR = 0.1;
93 public abstract JFrame
view(
int width,
int height);
101 return chart.getTitle().getText();
111 chart.setTitle(title);
120 double BorneMin = Math.abs((dataset.getRangeBounds())[0]);
121 double BorneMax = Math.abs((dataset.getRangeBounds())[1]);
123 double max = Math.max(BorneMin, BorneMax) * BOR;
124 YAxis.getAxis().setLowerBound(BorneMin - max);
125 YAxis.getAxis().setUpperBound(BorneMax + max);
126 YAxis.setLabelsAuto();
135 private void setManualRange(
double[] range) {
136 if (range.length != 2)
137 throw new IllegalArgumentException(
"range must have the format: [ymin, ymax]");
139 YAxis.
getAxis().setLowerBound(Math.min(range[0], range[1]));
140 YAxis.
getAxis().setUpperBound(Math.max(range[0], range[1]));
155 this.ystepGrid = ystep;
172 public abstract String
toLatex(
double width,
double height);
181 protected double computeYScale(
double position) {
182 double[] bounds =
new double[2];
183 bounds[0] = YAxis.
getAxis().getLowerBound();
184 bounds[1] = YAxis.
getAxis().getUpperBound();
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);
195 protected double computeScale(
double[] bounds) {
196 int tenPowerRatio = 0;
198 while (bounds[1] > 1000 || bounds[0] < -1000) {
204 while (bounds[1] < 100 && bounds[0] > -100) {
209 return 1 / Math.pow(10, tenPowerRatio);
Represents an axis of a chart encapsulated by an instance of XYChart.
NumberAxis getAxis()
Returns the NumberAxis instance (from JFreeChart) linked with the current variable.
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.
Stores data used in a CategoryChart.