X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosuilib%2FAltosUIGraph.java;h=0caabcfa4a009829b59a5ae55ddf0ae1d597307e;hb=a61217f0a6d0ef48b6471f632c4600255867e831;hp=e212093ab64c516fa2a222a7cc0370b518d59cec;hpb=0169e56ad030c0096b1068d00f06957990dfb31f;p=fw%2Faltos diff --git a/altosuilib/AltosUIGraph.java b/altosuilib/AltosUIGraph.java index e212093a..0caabcfa 100644 --- a/altosuilib/AltosUIGraph.java +++ b/altosuilib/AltosUIGraph.java @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -15,14 +16,15 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib_1; +package org.altusmetrum.altosuilib_12; import java.io.*; +import java.util.*; import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_12.*; import org.jfree.ui.*; import org.jfree.chart.*; @@ -41,9 +43,10 @@ public class AltosUIGraph implements AltosUnitsListener { public ChartPanel panel; NumberAxis xAxis; AltosUIEnable enable; - ArrayList graphers; - AltosUIDataSet dataSet; - int index; + AltosUITimeSeries[] series; + int axis_index; + int series_index; + Hashtable axes_added; static final private Color gridline_color = new Color(0, 0, 0); static final private Color border_color = new Color(255, 255, 255); @@ -53,63 +56,77 @@ public class AltosUIGraph implements AltosUnitsListener { return panel; } - public void addSeries(String label, int fetch, AltosUnits units, Color color) { - AltosUISeries series = new AltosUISeries(label, fetch, units, color); - XYSeriesCollection dataset = new XYSeriesCollection(series); + public AltosUIAxis newAxis(String label, AltosUnits units, Color color, int flags) { + AltosUIAxis axis = new AltosUIAxis(label, units, color, axis_index++, flags); + plot.setRangeAxis(axis.index, axis); + return axis; + } - series.renderer.setPlot(plot); - plot.setRangeAxis(index, series.axis); - plot.setDataset(index, dataset); - plot.setRenderer(index, series.renderer); - plot.mapDatasetToRangeAxis(index, index); - if (enable != null) - enable.add(label, series, true); - this.graphers.add(series); - index++; + public AltosUIAxis newAxis(String label, AltosUnits units, Color color) { + return newAxis(label, units, color, AltosUIAxis.axis_default); } - - public void addMarker(String label, int fetch, Color color) { - AltosUIMarker marker = new AltosUIMarker(fetch, color, plot); + + void addAxis(AltosUIAxis axis) { + if (!axes_added.containsKey(axis.index)) { + axes_added.put(axis.index, true); + plot.setRangeAxis(axis.index, axis); + } + } + + public void addSeries(AltosUITimeSeries series) { + XYSeriesCollection dataset = new XYSeriesCollection(series.xy_series()); + + addAxis(series.axis); + + series.renderer.setPlot(plot); + plot.setDataset(series_index, dataset); + plot.setRenderer(series_index, series.renderer); + plot.mapDatasetToRangeAxis(series_index, series.axis.index); if (enable != null) - enable.add(label, marker, true); - this.graphers.add(marker); + enable.add(series.label, series, series.enable); + series_index++; } - public void resetData() { - for (AltosUIGrapher g : graphers) - g.clear(); - if (dataSet != null) { - for (AltosUIDataPoint dataPoint : dataSet.dataPoints()) - for (AltosUIGrapher g : graphers) - g.add(dataPoint); - } + public void addMarker(AltosUITimeSeries series) { } public void units_changed(boolean imperial_units) { - for (AltosUIGrapher g : graphers) - g.set_units(); - resetData(); + for (AltosUITimeSeries s : series) + s.set_units(); } public void setName (String name) { chart.setTitle(name); } - public void setDataSet (AltosUIDataSet dataSet) { - this.dataSet = dataSet; - if (dataSet != null) - setName(dataSet.name()); - resetData(); + public void set_series(AltosUITimeSeries[] series) { + this.series = series; + boolean any_enabled = false; + + for (AltosUITimeSeries s : series) + if (s.enable) + any_enabled = true; + + if (!any_enabled) + for (AltosUITimeSeries s : series) + s.set_enable(true); + + for (AltosUITimeSeries s : series) + addSeries(s); + + units_changed(false); } - public AltosUIGraph(AltosUIEnable enable) { + public AltosUIGraph(AltosUIEnable enable, String title) { this.enable = enable; - this.graphers = new ArrayList(); - this.index = 0; + this.series = null; + this.axis_index = 0; + + axes_added = new Hashtable(); xAxis = new NumberAxis("Time (s)"); - + xAxis.setAutoRangeIncludesZero(true); plot = new XYPlot(); @@ -118,7 +135,7 @@ public class AltosUIGraph implements AltosUnitsListener { plot.setDomainPannable(true); plot.setRangePannable(true); - chart = new JFreeChart("Flight", JFreeChart.DEFAULT_TITLE_FONT, + chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); ChartUtilities.applyCurrentTheme(chart); @@ -135,5 +152,6 @@ public class AltosUIGraph implements AltosUnitsListener { panel.setPreferredSize(new java.awt.Dimension(800, 500)); AltosPreferences.register_units_listener(this); + } -} \ No newline at end of file +}