69 chart = ChartFactory.createXYLineChart(
null,
73 PlotOrientation.VERTICAL,
true,
78 datasetList =
new ArrayList<SSJXYSeriesCollection>();
80 XAxis =
new Axis((NumberAxis) ((XYPlot) chart.getPlot()).getDomainAxis(),
Axis.ORIENTATION_HORIZONTAL);
81 YAxis =
new Axis((NumberAxis) ((XYPlot) chart.getPlot()).getRangeAxis(),
Axis.ORIENTATION_VERTICAL);
95 chart = ChartFactory.createXYLineChart(title,
99 PlotOrientation.VERTICAL,
true,
104 datasetList =
new ArrayList<SSJXYSeriesCollection>();
106 XAxis =
new Axis((NumberAxis) ((XYPlot) chart.getPlot()).getDomainAxis(),
Axis.ORIENTATION_HORIZONTAL);
107 YAxis =
new Axis((NumberAxis) ((XYPlot) chart.getPlot()).getRangeAxis(),
Axis.ORIENTATION_VERTICAL);
161 double[][] temp =
new double[2][datasetList.size()];
162 for (
int i = 0; i < datasetList.size(); i++) {
163 temp[0][i] = (datasetList.get(i).getDomainBounds())[0];
164 temp[1][i] = (datasetList.get(i).getDomainBounds())[1];
166 XAxis.getAxis().setLowerBound(min(temp[0]));
167 XAxis.getAxis().setUpperBound(max(temp[1]));
169 for (
int i = 0; i < datasetList.size(); i++) {
170 temp[0][i] = (datasetList.get(i).getRangeBounds())[0];
171 temp[1][i] = (datasetList.get(i).getRangeBounds())[1];
173 YAxis.getAxis().setLowerBound(min(temp[0]));
174 YAxis.getAxis().setUpperBound(max(temp[1]));
184 if (axisRange.length != 4)
185 throw new IllegalArgumentException(
"axisRange must share the format: [xmin, xmax, ymin, ymax]");
187 XAxis.getAxis().setLowerBound(axisRange[0]);
188 XAxis.getAxis().setUpperBound(axisRange[1]);
189 YAxis.getAxis().setLowerBound(axisRange[2]);
190 YAxis.getAxis().setUpperBound(axisRange[3]);
273 public JFrame
view(
int width,
int height) {
275 if (chart.getTitle() !=
null)
276 myFrame =
new JFrame(
"MultipleDatasetChart from SSJ: " + chart.getTitle().getText());
278 myFrame =
new JFrame(
"MultipleDatasetChart from SSJ");
279 ChartPanel chartPanel =
new ChartPanel(chart);
280 chartPanel.setPreferredSize(
new java.awt.Dimension(width, height));
281 myFrame.setContentPane(chartPanel);
283 myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
284 myFrame.setLocationRelativeTo(
null);
285 myFrame.setVisible(
true);
322 public String
toLatex(
double width,
double height) {
324 double[] save =
new double[4];
326 if (datasetList.size() == 0)
327 throw new IllegalArgumentException(
"Empty chart");
330 double XScale = computeXScale(XAxis.getTwinAxisPosition());
331 double YScale = computeYScale(YAxis.getTwinAxisPosition());
333 xunit = width / ((Math.max(XAxis.getAxis().getRange().getUpperBound(), XAxis.getTwinAxisPosition()) * XScale)
334 - (Math.min(XAxis.getAxis().getRange().getLowerBound(), XAxis.getTwinAxisPosition()) * XScale));
336 yunit = height / ((Math.max(YAxis.getAxis().getRange().getUpperBound(), YAxis.getTwinAxisPosition()) * YScale)
337 - (Math.min(YAxis.getAxis().getRange().getLowerBound(), YAxis.getTwinAxisPosition()) * YScale));
340 Formatter formatter =
new Formatter(Locale.US);
344 formatter.format(
"\\documentclass[12pt]{article}%n%n");
345 formatter.format(
"\\usepackage{tikz}%n\\usetikzlibrary{plotmarks}%n\\begin{document}%n%n");
347 if (chart.getTitle() !=
null)
348 formatter.format(
"%% PGF/TikZ picture from SSJ : %s%n", chart.getTitle().getText());
350 formatter.format(
"%% PGF/TikZ picture from SSJ %n");
351 formatter.format(
"%% XScale = %s, YScale = %s, XShift = %s, YShift = %s%n", XScale, YScale,
352 XAxis.getTwinAxisPosition(), YAxis.getTwinAxisPosition());
353 formatter.format(
"%% Therefore, thisFileXValue = (originalSeriesXValue+XShift)*XScale%n");
354 formatter.format(
"%% and thisFileYValue = (originalSeriesYValue+YShift)*YScale%n%n");
355 if (chart.getTitle() !=
null)
356 formatter.format(
"\\begin{figure}%n");
357 formatter.format(
"\\begin{center}%n");
358 formatter.format(
"\\begin{tikzpicture}[x=%scm, y=%scm]%n", xunit, yunit);
359 formatter.format(
"\\footnotesize%n");
361 formatter.format(
"\\draw[color=lightgray] (%s, %s) grid[xstep = %s, ystep=%s] (%s, %s);%n",
362 (Math.min(XAxis.getAxis().getRange().getLowerBound(), XAxis.getTwinAxisPosition())
363 - XAxis.getTwinAxisPosition()) * XScale,
364 (Math.min(YAxis.getAxis().getRange().getLowerBound(), YAxis.getTwinAxisPosition())
365 - YAxis.getTwinAxisPosition()) * YScale,
366 xstepGrid * XScale, ystepGrid * YScale,
367 (Math.max(XAxis.getAxis().getRange().getUpperBound(), XAxis.getTwinAxisPosition())
368 - XAxis.getTwinAxisPosition()) * XScale,
369 (Math.max(YAxis.getAxis().getRange().getUpperBound(), YAxis.getTwinAxisPosition())
370 - YAxis.getTwinAxisPosition()) * YScale);
372 formatter.format(
"%s", XAxis.toLatex(XScale));
373 formatter.format(
"%s", YAxis.toLatex(YScale));
375 for (
int i = 0; i < datasetList.size(); i++)
376 formatter.format(
"%s",
377 datasetList.get(i).toLatex(XScale, YScale, XAxis.getTwinAxisPosition(), YAxis.getTwinAxisPosition(),
378 XAxis.getAxis().getLowerBound(), XAxis.getAxis().getUpperBound(), YAxis.getAxis().getLowerBound(),
379 YAxis.getAxis().getUpperBound()));
381 formatter.format(
"\\end{tikzpicture}%n");
382 formatter.format(
"\\end{center}%n");
383 if (chart.getTitle() !=
null) {
384 formatter.format(
"\\caption{");
385 formatter.format(chart.getTitle().getText());
386 formatter.format(
"}%n\\end{figure}%n");
389 formatter.format(
"\\end{document}%n");
390 return formatter.toString();