altosuilib: Start creating new graph interface that takes time series data
[fw/altos] / altosuilib / AltosGraphNew.java
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.altosuilib_11;
20
21 import java.io.*;
22 import java.util.ArrayList;
23
24 import java.awt.*;
25 import javax.swing.*;
26 import org.altusmetrum.altoslib_11.*;
27
28 import org.jfree.ui.*;
29 import org.jfree.chart.*;
30 import org.jfree.chart.plot.*;
31 import org.jfree.chart.axis.*;
32 import org.jfree.chart.renderer.*;
33 import org.jfree.chart.renderer.xy.*;
34 import org.jfree.chart.labels.*;
35 import org.jfree.data.xy.*;
36 import org.jfree.data.*;
37
38 public class AltosGraphNew extends AltosUIGraphNew {
39
40         static final private Color height_color = new Color(194,31,31);
41         static final private Color gps_height_color = new Color(150,31,31);
42         static final private Color pressure_color = new Color (225,31,31);
43         static final private Color range_color = new Color(100, 31, 31);
44         static final private Color distance_color = new Color(100, 31, 194);
45         static final private Color speed_color = new Color(31,194,31);
46         static final private Color accel_color = new Color(31,31,194);
47         static final private Color voltage_color = new Color(194, 194, 31);
48         static final private Color battery_voltage_color = new Color(194, 194, 31);
49         static final private Color drogue_voltage_color = new Color(150, 150, 31);
50         static final private Color main_voltage_color = new Color(100, 100, 31);
51         static final private Color gps_nsat_color = new Color (194, 31, 194);
52         static final private Color gps_nsat_solution_color = new Color (194, 31, 194);
53         static final private Color gps_nsat_view_color = new Color (150, 31, 150);
54         static final private Color gps_course_color = new Color (100, 31, 112);
55         static final private Color gps_ground_speed_color = new Color (31, 112, 100);
56         static final private Color gps_climb_rate_color = new Color (31, 31, 112);
57         static final private Color gps_pdop_color = new Color(50, 194, 0);
58         static final private Color gps_hdop_color = new Color(50, 0, 194);
59         static final private Color gps_vdop_color = new Color(194, 0, 50);
60         static final private Color temperature_color = new Color (31, 194, 194);
61         static final private Color dbm_color = new Color(31, 100, 100);
62         static final private Color state_color = new Color(0,0,0);
63         static final private Color accel_x_color = new Color(255, 0, 0);
64         static final private Color accel_y_color = new Color(0, 255, 0);
65         static final private Color accel_z_color = new Color(0, 0, 255);
66         static final private Color gyro_x_color = new Color(192, 0, 0);
67         static final private Color gyro_y_color = new Color(0, 192, 0);
68         static final private Color gyro_z_color = new Color(0, 0, 192);
69         static final private Color mag_x_color = new Color(128, 0, 0);
70         static final private Color mag_y_color = new Color(0, 128, 0);
71         static final private Color mag_z_color = new Color(0, 0, 128);
72         static final private Color orient_color = new Color(31, 31, 31);
73
74         static AltosNsat nsat_units = new AltosNsat();
75         static AltosDbm dbm_units = new AltosDbm();
76         static AltosOrient orient_units = new AltosOrient();
77         static AltosMagUnits mag_units = new AltosMagUnits();
78         static AltosDopUnits dop_units = new AltosDopUnits();
79
80         AltosUIFlightSeries flight_series;
81
82         AltosUITimeSeries[] setup(AltosFlightStats stats, AltosRecordSet record_set) {
83
84                 AltosUIAxis     height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
85                 AltosUIAxis     distance_axis, pressure_axis;
86                 AltosUIAxis     gyro_axis, orient_axis, mag_axis;
87                 AltosUIAxis     course_axis, dop_axis;
88
89                 height_axis = newAxis("Height", AltosConvert.height, height_color);
90                 pressure_axis = newAxis("Pressure", AltosConvert.pressure, pressure_color, 0);
91                 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
92                 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
93                 voltage_axis = newAxis("Voltage", AltosConvert.voltage, voltage_color);
94                 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
95                 nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color,
96                                     AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
97                 dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0);
98                 distance_axis = newAxis("Distance", AltosConvert.distance, range_color);
99
100                 gyro_axis = newAxis("Rotation Rate", AltosConvert.rotation_rate, gyro_z_color, 0);
101                 orient_axis = newAxis("Tilt Angle", orient_units, orient_color, 0);
102                 mag_axis = newAxis("Magnetic Field", mag_units, mag_x_color, 0);
103                 course_axis = newAxis("Course", orient_units, gps_course_color, 0);
104                 dop_axis = newAxis("Dilution of Precision", dop_units, gps_pdop_color, 0);
105
106                 flight_series = new AltosUIFlightSeries();
107
108                 flight_series.register_extra("default",
109                                              speed_color,
110                                              false,
111                                              speed_axis);
112
113                 flight_series.register_extra(AltosUIFlightSeries.accel_name,
114                                              accel_color,
115                                              true,
116                                              accel_axis);
117
118                 flight_series.register_extra(AltosUIFlightSeries.pressure_name,
119                                              pressure_color,
120                                              true,
121                                              pressure_axis);
122
123 //              addMarker("State", AltosGraphDataPoint.data_state, state_color);
124
125                 record_set.capture_series(flight_series);
126
127                 return flight_series.series();
128 /*
129                 if (stats.has_flight_data) {
130                         addSeries("Height",
131                                   AltosGraphDataPoint.data_height,
132                                   AltosConvert.height,
133                                   height_color,
134                                   true,
135                                   height_axis);
136                         addSeries("Pressure",
137                                   AltosGraphDataPoint.data_pressure,
138                                   pressure_units,
139                                   pressure_color,
140                                   false,
141                                   pressure_axis);
142                         addSeries("Speed",
143                                   AltosGraphDataPoint.data_speed,
144                                   AltosConvert.speed,
145                                   speed_color,
146                                   true,
147                                   speed_axis);
148                         addSeries("Acceleration",
149                                   AltosGraphDataPoint.data_accel,
150                                   AltosConvert.accel,
151                                   accel_color,
152                                   true,
153                                   accel_axis);
154                 }
155                 if (stats.has_gps) {
156                         boolean enable_gps = false;
157
158                         if (!stats.has_flight_data)
159                                 enable_gps = true;
160
161                         addSeries("Range",
162                                   AltosGraphDataPoint.data_range,
163                                   AltosConvert.distance,
164                                   range_color,
165                                   false,
166                                   distance_axis);
167                         addSeries("Distance",
168                                   AltosGraphDataPoint.data_distance,
169                                   AltosConvert.distance,
170                                   distance_color,
171                                   enable_gps,
172                                   distance_axis);
173                         addSeries("GPS Height",
174                                   AltosGraphDataPoint.data_gps_height,
175                                   AltosConvert.height,
176                                   gps_height_color,
177                                   enable_gps,
178                                   height_axis);
179                         addSeries("GPS Altitude",
180                                   AltosGraphDataPoint.data_gps_altitude,
181                                   AltosConvert.height,
182                                   gps_height_color,
183                                   false,
184                                   height_axis);
185                         addSeries("GPS Satellites in Solution",
186                                   AltosGraphDataPoint.data_gps_nsat_solution,
187                                   nsat_units,
188                                   gps_nsat_solution_color,
189                                   false,
190                                   nsat_axis);
191                         if (stats.has_gps_sats) {
192                                 addSeries("GPS Satellites in View",
193                                           AltosGraphDataPoint.data_gps_nsat_view,
194                                           nsat_units,
195                                           gps_nsat_view_color,
196                                           false,
197                                           nsat_axis);
198                         }
199                         if (stats.has_gps_detail) {
200                                 addSeries("GPS Course",
201                                           AltosGraphDataPoint.data_gps_course,
202                                           orient_units,
203                                           gps_course_color,
204                                           false,
205                                           course_axis);
206                                 addSeries("GPS Ground Speed",
207                                           AltosGraphDataPoint.data_gps_ground_speed,
208                                           AltosConvert.speed,
209                                           gps_ground_speed_color,
210                                           enable_gps,
211                                           speed_axis);
212                                 addSeries("GPS Climb Rate",
213                                           AltosGraphDataPoint.data_gps_climb_rate,
214                                           AltosConvert.speed,
215                                           gps_climb_rate_color,
216                                           enable_gps,
217                                           speed_axis);
218                         }
219                         addSeries("GPS Position DOP",
220                                   AltosGraphDataPoint.data_gps_pdop,
221                                   dop_units,
222                                   gps_pdop_color,
223                                   false,
224                                   dop_axis);
225                         if (stats.has_gps_detail) {
226                                 addSeries("GPS Horizontal DOP",
227                                           AltosGraphDataPoint.data_gps_hdop,
228                                           dop_units,
229                                           gps_hdop_color,
230                                           false,
231                                           dop_axis);
232                                 addSeries("GPS Vertical DOP",
233                                           AltosGraphDataPoint.data_gps_vdop,
234                                           dop_units,
235                                           gps_vdop_color,
236                                           false,
237                                           dop_axis);
238                         }
239                 }
240                 if (stats.has_rssi)
241                         addSeries("Received Signal Strength",
242                                   AltosGraphDataPoint.data_rssi,
243                                   dbm_units,
244                                   dbm_color,
245                                   false,
246                                   dbm_axis);
247
248                 if (stats.has_battery)
249                         addSeries("Battery Voltage",
250                                   AltosGraphDataPoint.data_battery_voltage,
251                                   voltage_units,
252                                   battery_voltage_color,
253                                   false,
254                                   voltage_axis);
255
256                 if (stats.has_flight_adc) {
257                         addSeries("Temperature",
258                                   AltosGraphDataPoint.data_temperature,
259                                   AltosConvert.temperature,
260                                   temperature_color,
261                                   false,
262                                   temperature_axis);
263                         addSeries("Drogue Voltage",
264                                   AltosGraphDataPoint.data_drogue_voltage,
265                                   voltage_units,
266                                   drogue_voltage_color,
267                                   false,
268                                   voltage_axis);
269                         addSeries("Main Voltage",
270                                   AltosGraphDataPoint.data_main_voltage,
271                                   voltage_units,
272                                   main_voltage_color,
273                                   false,
274                                   voltage_axis);
275                 }
276
277                 if (stats.has_imu) {
278                         addSeries("Acceleration Along",
279                                   AltosGraphDataPoint.data_accel_along,
280                                   AltosConvert.accel,
281                                   accel_x_color,
282                                   false,
283                                   accel_axis);
284                         addSeries("Acceleration Across",
285                                   AltosGraphDataPoint.data_accel_across,
286                                   AltosConvert.accel,
287                                   accel_y_color,
288                                   false,
289                                   accel_axis);
290                         addSeries("Acceleration Through",
291                                   AltosGraphDataPoint.data_accel_through,
292                                   AltosConvert.accel,
293                                   accel_z_color,
294                                   false,
295                                   accel_axis);
296                         addSeries("Roll Rate",
297                                   AltosGraphDataPoint.data_gyro_roll,
298                                   gyro_units,
299                                   gyro_x_color,
300                                   false,
301                                   gyro_axis);
302                         addSeries("Pitch Rate",
303                                   AltosGraphDataPoint.data_gyro_pitch,
304                                   gyro_units,
305                                   gyro_y_color,
306                                   false,
307                                   gyro_axis);
308                         addSeries("Yaw Rate",
309                                   AltosGraphDataPoint.data_gyro_yaw,
310                                   gyro_units,
311                                   gyro_z_color,
312                                   false,
313                                   gyro_axis);
314                 }
315                 if (stats.has_mag) {
316                         addSeries("Magnetometer Along",
317                                   AltosGraphDataPoint.data_mag_along,
318                                   mag_units,
319                                   mag_x_color,
320                                   false,
321                                   mag_axis);
322                         addSeries("Magnetometer Across",
323                                   AltosGraphDataPoint.data_mag_across,
324                                   mag_units,
325                                   mag_y_color,
326                                   false,
327                                   mag_axis);
328                         addSeries("Magnetometer Through",
329                                   AltosGraphDataPoint.data_mag_through,
330                                   mag_units,
331                                   mag_z_color,
332                                   false,
333                                   mag_axis);
334                 }
335                 if (stats.has_orient)
336                         addSeries("Tilt Angle",
337                                   AltosGraphDataPoint.data_orient,
338                                   orient_units,
339                                   orient_color,
340                                   false,
341                                   orient_axis);
342                 if (stats.num_ignitor > 0) {
343                         for (int i = 0; i < stats.num_ignitor; i++)
344                                 addSeries(AltosLib.ignitor_name(i),
345                                           AltosGraphDataPoint.data_ignitor_0 + i,
346                                           voltage_units,
347                                           main_voltage_color,
348                                           false,
349                                           voltage_axis);
350                         for (int i = 0; i < stats.num_ignitor; i++)
351                                 addMarker(AltosLib.ignitor_name(i), AltosGraphDataPoint.data_ignitor_fired_0 + i, state_color);
352                 }
353 */
354         }
355
356         public AltosGraphNew(AltosUIEnable enable, AltosFlightStats stats, AltosRecordSet record_set) {
357                 super(enable, "Flight");
358
359                 set_series(setup(stats, record_set));
360         }
361 }