X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosuilib%2FAltosUIGraph.java;h=ef0cc6772daa8e80e8f06d216ddfdabed136c5fe;hp=e212093ab64c516fa2a222a7cc0370b518d59cec;hb=2ad31bad20b20615e9d8b29088e2488fddc81ac9;hpb=0169e56ad030c0096b1068d00f06957990dfb31f diff --git a/altosuilib/AltosUIGraph.java b/altosuilib/AltosUIGraph.java index e212093a..ef0cc677 100644 --- a/altosuilib/AltosUIGraph.java +++ b/altosuilib/AltosUIGraph.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.jfree.ui.*; import org.jfree.chart.*; @@ -43,7 +43,8 @@ public class AltosUIGraph implements AltosUnitsListener { AltosUIEnable enable; ArrayList graphers; AltosUIDataSet dataSet; - int index; + int axis_index; + int series_index; static final private Color gridline_color = new Color(0, 0, 0); static final private Color border_color = new Color(255, 255, 255); @@ -53,19 +54,33 @@ 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); + 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; + } + + public AltosUIAxis newAxis(String label, AltosUnits units, Color color) { + return newAxis(label, units, color, AltosUIAxis.axis_default); + } + + public void addSeries(String label, int fetch, AltosUnits units, Color color, + boolean enabled, AltosUIAxis axis) { + AltosUISeries series = new AltosUISeries(label, fetch, units, color, enabled, axis); XYSeriesCollection dataset = new XYSeriesCollection(series); series.renderer.setPlot(plot); - plot.setRangeAxis(index, series.axis); - plot.setDataset(index, dataset); - plot.setRenderer(index, series.renderer); - plot.mapDatasetToRangeAxis(index, index); + plot.setDataset(series_index, dataset); + plot.setRenderer(series_index, series.renderer); + plot.mapDatasetToRangeAxis(series_index, axis.index); if (enable != null) - enable.add(label, series, true); + enable.add(label, series, enabled); this.graphers.add(series); - index++; + series_index++; + } + + public void addSeries(String label, int fetch, AltosUnits units, Color color) { + addSeries(label, fetch, units, color, true, newAxis(label, units, color)); } public void addMarker(String label, int fetch, Color color) { @@ -76,13 +91,19 @@ public class AltosUIGraph implements AltosUnitsListener { } public void resetData() { - for (AltosUIGrapher g : graphers) + for (AltosUIGrapher g : graphers) { g.clear(); + g.setNotify(false); + } if (dataSet != null) { for (AltosUIDataPoint dataPoint : dataSet.dataPoints()) for (AltosUIGrapher g : graphers) g.add(dataPoint); } + for (AltosUIGrapher g : graphers) { + g.setNotify(true); + g.fireSeriesChanged(); + } } public void units_changed(boolean imperial_units) { @@ -97,16 +118,17 @@ public class AltosUIGraph implements AltosUnitsListener { public void setDataSet (AltosUIDataSet dataSet) { this.dataSet = dataSet; + resetData(); if (dataSet != null) setName(dataSet.name()); - resetData(); } public AltosUIGraph(AltosUIEnable enable) { this.enable = enable; this.graphers = new ArrayList(); - this.index = 0; + this.series_index = 0; + this.axis_index = 0; xAxis = new NumberAxis("Time (s)");