11import Plotly from 'plotly.js-dist' ;
2+ import { getDisplayValue } from "@/utils/unitConversions.js" ;
23
34const COLOR = "rgb(100, 100, 100)"
45const EVENT_MAP = {
5- 0 : { name : "ev_moving" , color : COLOR } ,
6- 1 : { name : "ev_ready" , color : COLOR } ,
7- 2 : { name : "ev_liftoff" , color : COLOR } ,
8- 3 : { name : "ev_burnout" , color : COLOR } ,
9- 4 : { name : "ev_apogee" , color : COLOR } ,
10- 5 : { name : "ev_main_deployment" , color : COLOR } ,
11- 6 : { name : "ev_touchdown" , color : COLOR } ,
12- 7 : { name : "ev_custom1" , color : COLOR } ,
13- 8 : { name : "ev_custom2" , color : COLOR } ,
6+ 0 : { name : "ev_moving" , color : COLOR } ,
7+ 1 : { name : "ev_ready" , color : COLOR } ,
8+ 2 : { name : "ev_liftoff" , color : COLOR } ,
9+ 3 : { name : "ev_burnout" , color : COLOR } ,
10+ 4 : { name : "ev_apogee" , color : COLOR } ,
11+ 5 : { name : "ev_main_deployment" , color : COLOR } ,
12+ 6 : { name : "ev_touchdown" , color : COLOR } ,
13+ 7 : { name : "ev_custom1" , color : COLOR } ,
14+ 8 : { name : "ev_custom2" , color : COLOR } ,
1415}
1516
17+ function adaptTraceNameForConverterFunction ( name ) {
18+ if ( name === 'height' ) return 'altitude' ;
19+ if ( name === 'Ax' ) return 'acceleration' ;
20+ if ( name === 'Ay' ) return 'acceleration' ;
21+ if ( name === 'Az' ) return 'acceleration' ;
22+ if ( name === 'T' ) return 'temperature' ;
23+ if ( name === 'P' ) return 'pressure' ;
24+ if ( name === 'filteredAltitudeAGL' ) return 'altitude' ;
25+ return name ;
26+ }
27+
28+ const TRACES_TO_CONVERT = [ 'height' , 'acceleration' , 'velocity' , 'Ax' , 'Ay' , 'Az' , 'T' , 'P' , 'filteredAltitudeAGL' ] ;
1629
17- function makePlot ( data , elementId , title , ylabel , traceNames , eventInfo ) {
30+ function makePlot ( data , elementId , title , ylabel , traceNames , eventInfo , useImperialUnits ) {
1831
1932 let lines = [ ]
2033 let x = [ ]
@@ -27,6 +40,16 @@ function makePlot(data, elementId, title, ylabel, traceNames, eventInfo) {
2740 } )
2841 }
2942 }
43+
44+ if ( useImperialUnits ) {
45+ data = structuredClone ( data )
46+ for ( const o of data ) {
47+ for ( let key of traceNames . filter ( value => TRACES_TO_CONVERT . includes ( value ) ) ) {
48+ o [ key ] = getDisplayValue ( o [ key ] , adaptTraceNameForConverterFunction ( key ) ) ;
49+ }
50+ }
51+ }
52+
3053 for ( const o of data ) {
3154 let i = 0 ;
3255 for ( let key of traceNames ) {
@@ -43,10 +66,10 @@ function makePlot(data, elementId, title, ylabel, traceNames, eventInfo) {
4366 elementId ,
4467 lines ,
4568 {
46- title : { text : title } ,
69+ title : { text : title } ,
4770 margin : { t : 50 } ,
4871 xaxis : { title : "Timestamp [s]" } ,
49- yaxis : { title : ylabel } ,
72+ yaxis : { title : ylabel , tickFormat : ',.0f' } ,
5073 shapes : eventInfo . shapes ,
5174 annotations : eventInfo . annotations ,
5275 template : 'plotly_dark' ,
@@ -199,43 +222,44 @@ function makeEventInfoTraces(flightlog) {
199222 return { shapes : shapes , annotations : annotations }
200223}
201224
202- export function makePlots ( flightlog , element ) {
225+ export function makePlots ( flightlog , element , useImperialUnits ) {
203226 let eventInfo = makeEventInfoTraces ( flightlog )
204227
205228 element . replaceChildren ( [ ] )
206229
207230 let el = document . createElement ( "div" )
208- document . create
209231 element . append ( el )
210- makePlot ( flightlog . flightInfo , el , "State Estimation - Altitude" , "Altitude [m]" , [ "height" ] , eventInfo )
232+ const altitudeYLabel = useImperialUnits ? "Altitude [ft]" : "Altitude [m]"
233+ makePlot ( flightlog . flightInfo , el , "State Estimation - Altitude" , altitudeYLabel , [ "height" ] , eventInfo , useImperialUnits )
211234
212235 el = document . createElement ( "div" )
213236 element . append ( el )
214- makePlot ( flightlog . flightInfo , el , "State Estimation - Velocity" , "Velocity [m/s]" , [ "velocity" ] , eventInfo )
215-
216- // el = document.createElement("div")
217- // element.append(el)
218- // makePlot(flightlog.flightInfo, el, "Acceleration [m/s^2]", ["acceleration"], eventInfo)
237+ const velocityYLabel = useImperialUnits ? "Velocity [ft/s]" : "Velocity [m/s]"
238+ makePlot ( flightlog . flightInfo , el , "State Estimation - Velocity" , velocityYLabel , [ "velocity" ] , eventInfo , useImperialUnits )
219239
220240 el = document . createElement ( "div" )
221241 element . append ( el )
222- makePlot ( flightlog . imu , el , "IMU - Acceleration" , "Acceleration [m/s^2]" , [ "Ax" , "Ay" , "Az" ] , eventInfo )
242+ const accelerationYLabel = useImperialUnits ? "Acceleration [ft/s²]" : "Acceleration [m/s²]"
243+ makePlot ( flightlog . imu , el , "IMU - Acceleration" , accelerationYLabel , [ "Ax" , "Ay" , "Az" ] , eventInfo , useImperialUnits )
223244
224245 el = document . createElement ( "div" )
225246 element . append ( el )
226247 makePlot ( flightlog . imu , el , "IMU - Gyroscope" , "Angular Movement [deg/s]" , [ "Gx" , "Gy" , "Gz" ] , eventInfo )
227248
228249 el = document . createElement ( "div" )
229250 element . append ( el )
230- makePlot ( flightlog . baro , el , "Temperature" , "Temperature [°C]" , [ "T" ] , eventInfo )
251+ const temperatureYLabel = useImperialUnits ? "Temperature [°F]" : "Temperature [°C]"
252+ makePlot ( flightlog . baro , el , "Temperature" , temperatureYLabel , [ "T" ] , eventInfo , useImperialUnits )
231253
232254 el = document . createElement ( "div" )
233255 element . append ( el )
234- makePlot ( flightlog . baro , el , "Pressure" , "Pressure [hPa]" , [ "P" ] , eventInfo )
256+ const pressureYLabel = useImperialUnits ? "Pressure [psi]" : "Pressure [hPa]"
257+ makePlot ( flightlog . baro , el , "Pressure" , pressureYLabel , [ "P" ] , eventInfo , useImperialUnits )
235258
236259 el = document . createElement ( "div" )
237260 element . append ( el )
238- makePlot ( flightlog . filteredDataInfo , el , "Filtered Barometer Altitude" , "Altitude [m]" , [ "filteredAltitudeAGL" ] , eventInfo )
261+ const filteredAltitudeYLabel = useImperialUnits ? "Altitude [ft]" : "Altitude [m]"
262+ makePlot ( flightlog . filteredDataInfo , el , "Filtered Barometer Altitude" , filteredAltitudeYLabel , [ "filteredAltitudeAGL" ] , eventInfo , useImperialUnits )
239263
240264 el = document . createElement ( "div" )
241265 element . append ( el )
0 commit comments