--- /dev/null
+/*
+ * Copyright © 2017 Keith Packard <keithp@keithp.com>
+ *
+ * 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, 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+package org.altusmetrum.altosuilib_12;
+
+import org.altusmetrum.altoslib_12.*;
+
+public interface AltosEepromGrapher {
+
+ public void graph_flights(AltosEepromList list);
+}
public class AltosGraph extends AltosUIGraph {
- static final private Color height_color = new Color(194,31,31);
- static final private Color kalman_height_color = new Color(255,0,0);
- static final private Color gps_height_color = new Color(150,31,31);
- static final private Color pressure_color = new Color (225,31,31);
- static final private Color range_color = new Color(100, 31, 31);
- static final private Color distance_color = new Color(100, 31, 194);
- static final private Color speed_color = new Color(31,194,31);
- static final private Color kalman_speed_color = new Color(0,255,0);
- static final private Color thrust_color = new Color(31,194,31);
- static final private Color accel_color = new Color(31,31,194);
- static final private Color vert_accel_color = new Color(64,164,164);
- static final private Color kalman_accel_color = new Color(0,0,255);
- static final private Color voltage_color = new Color(194, 194, 31);
- static final private Color battery_voltage_color = new Color(194, 194, 31);
- static final private Color drogue_voltage_color = new Color(150, 150, 31);
- static final private Color main_voltage_color = new Color(100, 100, 31);
- static final private Color igniter_voltage_color = new Color(80, 80, 31);
- static final private Color igniter_marker_color = new Color(255, 0, 0);
- static final private Color gps_nsat_color = new Color (194, 31, 194);
- static final private Color gps_nsat_solution_color = new Color (194, 31, 194);
- static final private Color gps_nsat_view_color = new Color (150, 31, 150);
- static final private Color gps_course_color = new Color (100, 31, 112);
- static final private Color gps_ground_speed_color = new Color (31, 112, 100);
- static final private Color gps_speed_color = new Color (31, 112, 100);
- static final private Color gps_climb_rate_color = new Color (31, 31, 112);
- static final private Color gps_pdop_color = new Color(50, 194, 0);
- static final private Color gps_hdop_color = new Color(50, 0, 194);
- static final private Color gps_vdop_color = new Color(194, 0, 50);
- static final private Color temperature_color = new Color (31, 194, 194);
- static final private Color dbm_color = new Color(31, 100, 100);
- static final private Color state_color = new Color(0,0,0);
- static final private Color accel_along_color = new Color(255, 0, 0);
- static final private Color accel_across_color = new Color(0, 255, 0);
- static final private Color accel_through_color = new Color(0, 0, 255);
- static final private Color gyro_roll_color = new Color(192, 0, 0);
- static final private Color gyro_pitch_color = new Color(0, 192, 0);
- static final private Color gyro_yaw_color = new Color(0, 0, 192);
- static final private Color mag_along_color = new Color(128, 0, 0);
- static final private Color mag_across_color = new Color(0, 128, 0);
- static final private Color mag_through_color = new Color(0, 0, 128);
- static final private Color orient_color = new Color(31, 31, 31);
+ /* These are in 'priority' order so that earlier ones get simpler line styles,
+ * then they are grouped so that adjacent ones get sequential colors
+ */
+ static final private AltosUILineStyle height_color = new AltosUILineStyle();
+ static final private AltosUILineStyle speed_color = new AltosUILineStyle();
+ static final private AltosUILineStyle accel_color = new AltosUILineStyle();
+ static final private AltosUILineStyle vert_accel_color = new AltosUILineStyle();
+ static final private AltosUILineStyle orient_color = new AltosUILineStyle();
+
+ static final private AltosUILineStyle gps_height_color = new AltosUILineStyle();
+ static final private AltosUILineStyle altitude_color = new AltosUILineStyle();
+
+ static final private AltosUILineStyle battery_voltage_color = new AltosUILineStyle();
+ static final private AltosUILineStyle pyro_voltage_color = new AltosUILineStyle();
+ static final private AltosUILineStyle drogue_voltage_color = new AltosUILineStyle();
+ static final private AltosUILineStyle main_voltage_color = new AltosUILineStyle();
+ static final private AltosUILineStyle igniter_marker_color = new AltosUILineStyle(1);
+
+ static final private AltosUILineStyle kalman_height_color = new AltosUILineStyle();
+ static final private AltosUILineStyle kalman_speed_color = new AltosUILineStyle();
+ static final private AltosUILineStyle kalman_accel_color = new AltosUILineStyle();
+
+ static final private AltosUILineStyle gps_nsat_color = new AltosUILineStyle ();
+ static final private AltosUILineStyle gps_nsat_solution_color = new AltosUILineStyle ();
+ static final private AltosUILineStyle gps_nsat_view_color = new AltosUILineStyle ();
+ static final private AltosUILineStyle gps_course_color = new AltosUILineStyle ();
+ static final private AltosUILineStyle gps_ground_speed_color = new AltosUILineStyle ();
+ static final private AltosUILineStyle gps_speed_color = new AltosUILineStyle ();
+ static final private AltosUILineStyle gps_climb_rate_color = new AltosUILineStyle ();
+ static final private AltosUILineStyle gps_pdop_color = new AltosUILineStyle();
+ static final private AltosUILineStyle gps_hdop_color = new AltosUILineStyle();
+ static final private AltosUILineStyle gps_vdop_color = new AltosUILineStyle();
+
+ static final private AltosUILineStyle temperature_color = new AltosUILineStyle ();
+ static final private AltosUILineStyle dbm_color = new AltosUILineStyle();
+ static final private AltosUILineStyle pressure_color = new AltosUILineStyle ();
+
+ static final private AltosUILineStyle state_color = new AltosUILineStyle(0);
+ static final private AltosUILineStyle accel_along_color = new AltosUILineStyle();
+ static final private AltosUILineStyle accel_across_color = new AltosUILineStyle();
+ static final private AltosUILineStyle accel_through_color = new AltosUILineStyle();
+ static final private AltosUILineStyle gyro_roll_color = new AltosUILineStyle();
+ static final private AltosUILineStyle gyro_pitch_color = new AltosUILineStyle();
+ static final private AltosUILineStyle gyro_yaw_color = new AltosUILineStyle();
+ static final private AltosUILineStyle mag_along_color = new AltosUILineStyle();
+ static final private AltosUILineStyle mag_across_color = new AltosUILineStyle();
+ static final private AltosUILineStyle mag_through_color = new AltosUILineStyle();
static AltosUnits dop_units = null;
static AltosUnits tick_units = null;
AltosCalData cal_data = flight_series.cal_data();
AltosUIAxis height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
- AltosUIAxis distance_axis, pressure_axis, thrust_axis;
+ AltosUIAxis pressure_axis, thrust_axis;
AltosUIAxis gyro_axis, orient_axis, mag_axis;
AltosUIAxis course_axis, dop_axis, tick_axis;
height_axis = newAxis("Height", AltosConvert.height, height_color);
pressure_axis = newAxis("Pressure", AltosConvert.pressure, pressure_color, 0);
speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
- thrust_axis = newAxis("Thrust", AltosConvert.force, thrust_color);
+ thrust_axis = newAxis("Thrust", AltosConvert.force, accel_color);
tick_axis = newAxis("Tick", tick_units, accel_color, 0);
accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
- voltage_axis = newAxis("Voltage", AltosConvert.voltage, voltage_color);
+ voltage_axis = newAxis("Voltage", AltosConvert.voltage, battery_voltage_color);
temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
nsat_axis = newAxis("Satellites", null, gps_nsat_color,
AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
dbm_axis = newAxis("Signal Strength", null, dbm_color, 0);
- distance_axis = newAxis("Distance", AltosConvert.distance, range_color);
gyro_axis = newAxis("Rotation Rate", AltosConvert.rotation_rate, gyro_roll_color, 0);
orient_axis = newAxis("Tilt Angle", AltosConvert.orient, orient_color, 0);
height_axis);
flight_series.register_axis(AltosUIFlightSeries.altitude_name,
- height_color,
+ altitude_color,
false,
height_axis);
false,
voltage_axis);
+ flight_series.register_axis(AltosUIFlightSeries.pyro_voltage_name,
+ pyro_voltage_color,
+ false,
+ voltage_axis);
+
flight_series.register_axis(AltosUIFlightSeries.apogee_voltage_name,
drogue_voltage_color,
false,
false,
orient_axis);
- for (int channel = 0; channel < 26; channel++) {
+ flight_series.register_axis(AltosUIFlightSeries.thrust_name,
+ accel_color,
+ true,
+ thrust_axis);
+
+ for (int channel = 0; channel < 8; channel++) {
flight_series.register_axis(flight_series.igniter_voltage_name(channel),
- igniter_voltage_color,
+ new AltosUILineStyle(),
false,
voltage_axis);
}
- flight_series.register_axis(AltosUIFlightSeries.thrust_name,
- thrust_color,
- true,
- thrust_axis);
+ flight_series.check_axes();
return flight_series.series(cal_data);
}
public interface AltosShapeListener {
void set_shapes_visible(boolean visible);
+ void set_line_width(float width);
}
import org.jfree.data.*;
public class AltosUIAxis extends NumberAxis {
- String label;
- AltosUnits units;
- Color color;
- int ref;
- int visible;
- int index;
+ String label;
+ AltosUnits units;
+ AltosUILineStyle line_style;
+ int ref;
+ int visible;
+ int index;
public final static int axis_integer = 1;
public final static int axis_include_zero = 2;
}
}
- public AltosUIAxis(String label, AltosUnits units, Color color, int index, int flags) {
+ public AltosUIAxis(String label, AltosUnits units, AltosUILineStyle line_style, int index, int flags) {
this.label = label;
this.units = units;
+ this.line_style = line_style;
this.index = index;
this.visible = 0;
this.ref = 0;
- setLabelPaint(color);
- setTickLabelPaint(color);
+ setLabelPaint(line_style.color);
+ setTickLabelPaint(line_style.color);
setVisible(false);
if ((flags & axis_integer) != 0)
setStandardTickUnits(NumberAxis.createIntegerTickUnits());
setAutoRangeIncludesZero((flags & axis_include_zero) != 0);
}
- public AltosUIAxis(String label, AltosUnits units, Color color, int index) {
- this(label, units, color, index, axis_default);
+ public AltosUIAxis(String label, AltosUnits units, AltosUILineStyle line_style, int index) {
+ this(label, units, line_style, index, axis_default);
}
}
int x;
JCheckBox imperial_units;
JCheckBox show_shapes;
+ JLabel line_width_label;
+ JSpinner line_width;
JLabel speed_filter_label;
JSlider speed_filter;
JLabel accel_filter_label;
}
public void set_shapes_visible(boolean visible) {
- System.out.printf("set shapes %b\n", visible);
if (shape_listener != null)
shape_listener.set_shapes_visible(visible);
}
+ public void set_line_width(float width) {
+ if (shape_listener != null)
+ shape_listener.set_line_width(width);
+ }
+
public void register_shape_listener(AltosShapeListener shape_listener) {
this.shape_listener = shape_listener;
}
add(show_shapes, c);
+ line_width_label = new JLabel("Line Width");
+ c = new GridBagConstraints();
+ c.gridx = 1; c.gridy = 1001;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.LINE_START;
+ c.insets = il;
+ add(line_width_label, c);
+
+ line_width = new JSpinner();
+ line_width.setValue(new Integer(1));
+ line_width.addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ int w = (Integer) line_width.getValue();
+ if (w < 1) {
+ w = 1;
+ line_width.setValue(new Integer(w));
+ }
+ System.out.printf("line width set to %d\n", w);
+ set_line_width(w);
+ }
+ });
+ c = new GridBagConstraints();
+ c.gridx = 2; c.gridy = 1001;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.LINE_START;
+ c.insets = il;
+ add(line_width, c);
+
speed_filter_label = new JLabel("Speed Filter(ms)");
c = new GridBagConstraints();
c.gridx = 0; c.gridy = 1002;
import org.jfree.data.*;
class AltosUITimeSeriesAxis {
- Color color;
- boolean enabled;
- boolean marker;
- boolean marker_top;
- AltosUIAxis axis;
- XYPlot plot;
-
- public AltosUITimeSeriesAxis(Color color, boolean enabled, AltosUIAxis axis, XYPlot plot, boolean marker, boolean marker_top) {
- this.color = color;
+ AltosUILineStyle line_style;
+ boolean enabled;
+ boolean marker;
+ boolean marker_top;
+ AltosUIAxis axis;
+ XYPlot plot;
+
+ public AltosUITimeSeriesAxis(AltosUILineStyle line_style, boolean enabled,
+ AltosUIAxis axis, XYPlot plot, boolean marker, boolean marker_top) {
+ this.line_style = line_style;
this.enabled = enabled;
this.axis = axis;
this.plot = plot;
Hashtable<String,AltosUITimeSeriesAxis> axes;
- AltosUIFlightSeries flight_series;
-
void fill_axes(String label, AltosUITimeSeriesAxis axis) {
for (AltosTimeSeries ts : series) {
AltosUITimeSeries uts = (AltosUITimeSeries) ts;
- if (label.equals(ts.label) || (label.equals("default") && uts.color == null)) {
+ if (label.equals(ts.label) || (label.equals("default") && uts.line_style == null)) {
+ uts.custom_axis_set = true;
if (axis.marker)
- uts.set_marker(axis.color, axis.enabled, axis.plot, axis.marker_top);
+ uts.set_marker(axis.line_style, axis.enabled, axis.plot, axis.marker_top);
else
- uts.set_axis(axis.color, axis.enabled, axis.axis);
+ uts.set_axis(axis.line_style, axis.enabled, axis.axis);
}
}
}
+ void check_axes() {
+ for (AltosTimeSeries ts : series) {
+ AltosUITimeSeries uts = (AltosUITimeSeries) ts;
+
+ if (!uts.custom_axis_set)
+ System.out.printf("%s using default axis\n", ts.label);
+ }
+ }
+
public void register_axis(String label,
- Color color,
+ AltosUILineStyle line_style,
boolean enabled,
AltosUIAxis axis) {
- AltosUITimeSeriesAxis tsa = new AltosUITimeSeriesAxis(color,
+ AltosUITimeSeriesAxis tsa = new AltosUITimeSeriesAxis(line_style,
enabled,
axis,
null,
}
public void register_marker(String label,
- Color color,
+ AltosUILineStyle line_style,
boolean enabled,
XYPlot plot,
boolean marker_top) {
- AltosUITimeSeriesAxis tsa = new AltosUITimeSeriesAxis(color,
+ AltosUITimeSeriesAxis tsa = new AltosUITimeSeriesAxis(line_style,
enabled,
null,
plot,
public AltosTimeSeries make_series(String label, AltosUnits units) {
-
AltosUITimeSeries time_series = new AltosUITimeSeries(label, units);
AltosUITimeSeriesAxis tsa = axes.get(label);
if (tsa == null)
tsa = axes.get("default");
+ else
+ time_series.custom_axis_set = true;
if (tsa != null) {
if (tsa.marker)
- time_series.set_marker(tsa.color, tsa.enabled, tsa.plot, tsa.marker_top);
+ time_series.set_marker(tsa.line_style, tsa.enabled, tsa.plot, tsa.marker_top);
else
- time_series.set_axis(tsa.color, tsa.enabled, tsa.axis);
+ time_series.set_axis(tsa.line_style, tsa.enabled, tsa.axis);
}
return time_series;
}
return panel;
}
- public AltosUIAxis newAxis(String label, AltosUnits units, Color color, int flags) {
- AltosUIAxis axis = new AltosUIAxis(label, units, color, axis_index++, flags);
+ public AltosUIAxis newAxis(String label, AltosUnits units, AltosUILineStyle line_style, int flags) {
+ AltosUIAxis axis = new AltosUIAxis(label, units, line_style, 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 AltosUIAxis newAxis(String label, AltosUnits units, AltosUILineStyle line_style) {
+ return newAxis(label, units, line_style, AltosUIAxis.axis_default);
}
void addAxis(AltosUIAxis axis) {
s.set_shapes_visible(visible);
}
+ public void set_line_width(float width) {
+ for (AltosUITimeSeries s : series)
+ s.set_line_width(width);
+ }
+
public void setName (String name) {
chart.setTitle(name);
}
--- /dev/null
+/*
+ * Copyright © 2017 Keith Packard <keithp@keithp.com>
+ *
+ * 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, 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+package org.altusmetrum.altosuilib_12;
+
+import java.io.*;
+import java.util.ArrayList;
+
+import java.awt.*;
+import javax.swing.*;
+import org.altusmetrum.altoslib_12.*;
+
+import org.jfree.ui.*;
+import org.jfree.chart.*;
+import org.jfree.chart.plot.*;
+import org.jfree.chart.axis.*;
+import org.jfree.chart.renderer.*;
+import org.jfree.chart.renderer.xy.*;
+import org.jfree.chart.labels.*;
+import org.jfree.data.xy.*;
+import org.jfree.data.*;
+
+public class AltosUILineStyle {
+ public Color color;
+ public float[] dash;
+
+ static private Color color(int r, int g, int b) {
+ return new Color(r,g,b);
+ }
+
+ static final private Color[] colors = {
+ new Color(0,0,0),
+ new Color(230,0,0), // red
+ new Color(216,103,0), // orange
+ new Color(200,200,0), // yellow
+ new Color(0,180,0), // green
+ new Color(0,140,140), // cyan
+ new Color(130,0,0), // dark red
+ new Color(0,100,0), // dark green
+ new Color(0,0,255), // blue
+ new Color(140,0,140), // magenta
+ new Color(150,150,150), // gray
+ };
+
+ static final private float[][] dashes = {
+ { 0 },
+ { 2, 4 },
+ { 4, 4 },
+ { 6, 4 },
+ { 6, 4, 2, 4 }
+ };
+
+ static int color_index, dash_index;
+
+ public AltosUILineStyle () {
+ color = colors[color_index];
+ dash = dashes[dash_index];
+ color_index = (color_index + 1) % colors.length;
+ if (color_index == 0) {
+ dash_index = (dash_index + 1) % dashes.length;
+ if (dash_index == 0)
+ System.out.printf("too many line styles\n");
+ }
+ }
+
+ public AltosUILineStyle(int index) {
+ index = index % (colors.length * dashes.length);
+ int c = index % colors.length;
+ int d = index / colors.length;
+ color = colors[c];
+ dash = dashes[d];
+ }
+}
}
public class AltosUITimeSeries extends AltosTimeSeries implements AltosUIGrapher {
- Color color;
- boolean enable;
- AltosUIAxis axis;
- boolean marker;
- boolean marker_top;
+ AltosUILineStyle line_style;
+ boolean enable;
+ boolean custom_axis_set;
+ AltosUIAxis axis;
+ boolean marker;
+ boolean marker_top;
XYLineAndShapeRenderer renderer;
- XYPlot plot;
- AltosXYSeries xy_series;
+ XYPlot plot;
+ AltosXYSeries xy_series;
ArrayList<ValueMarker> markers;
-
+ float width;
/* AltosUIGrapher interface */
public boolean need_reset() {
marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
marker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
}
- marker.setPaint(color);
+ marker.setPaint(line_style.color);
+ marker.setStroke(new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
if (enable)
plot.addDomainMarker(marker);
markers.add(marker);
}
}
- public void set_axis(Color color, boolean enable, AltosUIAxis axis) {
- this.color = color;
+ // public BasicStroke(float width, int cap, int join, float miterlimit,
+ // float dash[], float dash_phase)
+
+ public void set_line_width(float width) {
+ this.width = width;
+ if (markers != null) {
+ for (ValueMarker marker : markers) {
+ marker.setStroke(new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
+ }
+ } else {
+ if (line_style.dash[0] == 0.0)
+ renderer.setSeriesStroke(0, new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+ else
+ renderer.setSeriesStroke(0, new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10.0f, line_style.dash, 0.0f));
+ }
+ }
+
+ public void set_axis(AltosUILineStyle line_style, boolean enable, AltosUIAxis axis) {
+ this.line_style = line_style;
this.enable = enable;
this.axis = axis;
this.marker = false;
+ this.width = 1.0f;
axis.ref(this.enable);
renderer = new XYLineAndShapeRenderer(true, false);
- renderer.setSeriesPaint(0, color);
- renderer.setSeriesStroke(0, new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+ renderer.setSeriesPaint(0, line_style.color);
+ set_line_width(this.width);
renderer.setSeriesVisible(0, enable);
xy_series = new AltosXYSeries(label);
}
- public void set_marker(Color color, boolean enable, XYPlot plot, boolean marker_top) {
- this.color = color;
+ public void set_marker(AltosUILineStyle line_style, boolean enable, XYPlot plot, boolean marker_top) {
+ this.line_style = line_style;
this.enable = enable;
this.marker = true;
this.plot = plot;
}
public AltosUITimeSeries(String label, AltosUnits units,
- Color color, boolean enable,
+ AltosUILineStyle line_style, boolean enable,
AltosUIAxis axis) {
this(label, units);
- set_axis(color, enable, axis);
+ set_axis(line_style, enable, axis);
}
}
AltosConfigFreqUI.java \
AltosScanUI.java \
AltosEepromDelete.java \
+ AltosEepromGrapher.java \
AltosEepromManage.java \
AltosEepromMonitorUI.java \
AltosEepromSelect.java \
AltosBTDeviceIterator.java \
AltosBTManage.java \
AltosBTKnown.java \
+ AltosUILineStyle.java \
AltosUIMap.java \
AltosUIMapPreload.java \
AltosUIFlightTab.java \