@@ -7,41 +7,41 @@ function GraphConfigurationDialog(dialog, onSave) {
7
7
offeredFieldNames = [ ] ,
8
8
exampleGraphs = [ ] ,
9
9
activeFlightLog ;
10
-
10
+
11
11
12
12
function chooseColor ( currentSelection ) {
13
- var selectColor = $ ( '<select class="color-picker"></select>' ) ;
14
- for ( var i = 0 ; i < GraphConfig . PALETTE . length ; i ++ ) {
15
- var option = $ ( '<option></option>' )
16
- . text ( GraphConfig . PALETTE [ i ] . name )
17
- . attr ( 'value' , GraphConfig . PALETTE [ i ] . color )
18
- . css ( 'color' , GraphConfig . PALETTE [ i ] . color ) ;
19
- if ( currentSelection == GraphConfig . PALETTE [ i ] . color ) {
20
- option . attr ( 'selected' , 'selected' ) ;
21
- selectColor . css ( 'background' , GraphConfig . PALETTE [ i ] . color )
22
- . css ( 'color' , GraphConfig . PALETTE [ i ] . color ) ;
23
- }
24
- selectColor . append ( option ) ;
25
- }
26
-
27
- return selectColor ;
13
+ var selectColor = $ ( '<select class="color-picker"></select>' ) ;
14
+ for ( var i = 0 ; i < GraphConfig . PALETTE . length ; i ++ ) {
15
+ var option = $ ( '<option></option>' )
16
+ . text ( GraphConfig . PALETTE [ i ] . name )
17
+ . attr ( 'value' , GraphConfig . PALETTE [ i ] . color )
18
+ . css ( 'color' , GraphConfig . PALETTE [ i ] . color ) ;
19
+ if ( currentSelection == GraphConfig . PALETTE [ i ] . color ) {
20
+ option . attr ( 'selected' , 'selected' ) ;
21
+ selectColor . css ( 'background' , GraphConfig . PALETTE [ i ] . color )
22
+ . css ( 'color' , GraphConfig . PALETTE [ i ] . color ) ;
23
+ }
24
+ selectColor . append ( option ) ;
25
+ }
26
+
27
+ return selectColor ;
28
28
}
29
-
29
+
30
30
function chooseHeight ( currentSelection ) {
31
31
var MAX_HEIGHT = 5 ;
32
32
33
- var selectHeight = $ ( '<select class="form-control graph-height"></select>' ) ;
34
- for ( var i = 1 ; i <= MAX_HEIGHT ; i ++ ) {
35
- var option = $ ( '<option></option>' )
36
- . text ( i )
37
- . attr ( 'value' , i ) ;
38
- if ( currentSelection == i || ( currentSelection == null && i == 1 ) ) {
39
- option . attr ( 'selected' , 'selected' ) ;
40
- }
41
- selectHeight . append ( option ) ;
42
- }
43
-
44
- return selectHeight ;
33
+ var selectHeight = $ ( '<select class="form-control graph-height"></select>' ) ;
34
+ for ( var i = 1 ; i <= MAX_HEIGHT ; i ++ ) {
35
+ var option = $ ( '<option></option>' )
36
+ . text ( i )
37
+ . attr ( 'value' , i ) ;
38
+ if ( currentSelection == i || ( currentSelection == null && i == 1 ) ) {
39
+ option . attr ( 'selected' , 'selected' ) ;
40
+ }
41
+ selectHeight . append ( option ) ;
42
+ }
43
+
44
+ return selectHeight ;
45
45
}
46
46
47
47
// Show/Hide remove all button
@@ -67,18 +67,18 @@ function GraphConfigurationDialog(dialog, onSave) {
67
67
}
68
68
69
69
function renderFieldOption ( fieldName , selectedName ) {
70
- var
70
+ var
71
71
option = $ ( "<option></option>" )
72
72
. text ( FlightLogFieldPresenter . fieldNameToFriendly ( fieldName , activeFlightLog . getSysConfig ( ) . debug_mode ) )
73
73
. attr ( "value" , fieldName ) ;
74
-
74
+
75
75
if ( fieldName == selectedName ) {
76
76
option . attr ( "selected" , "selected" ) ;
77
77
}
78
-
78
+
79
79
return option ;
80
80
}
81
-
81
+
82
82
// Set the current smoothing options for a field
83
83
function renderSmoothingOptions ( elem , flightLog , field ) {
84
84
if ( elem ) {
@@ -100,7 +100,7 @@ function GraphConfigurationDialog(dialog, onSave) {
100
100
* initial selection.
101
101
*/
102
102
function renderField ( flightLog , field , color ) {
103
- var
103
+ var
104
104
elem = $ (
105
105
'<tr class="config-graph-field">'
106
106
+ '<td><select class="form-control"><option value="">(choose a field)</option></select></td>'
@@ -116,11 +116,11 @@ function GraphConfigurationDialog(dialog, onSave) {
116
116
select = $ ( 'select.form-control' , elem ) ,
117
117
selectedFieldName = field ?field . name : false ,
118
118
i ;
119
-
119
+
120
120
for ( i = 0 ; i < offeredFieldNames . length ; i ++ ) {
121
121
select . append ( renderFieldOption ( offeredFieldNames [ i ] , selectedFieldName ) ) ;
122
122
}
123
-
123
+
124
124
// Set the smoothing values
125
125
renderSmoothingOptions ( elem , flightLog , field ) ;
126
126
@@ -132,7 +132,7 @@ function GraphConfigurationDialog(dialog, onSave) {
132
132
133
133
//Populate the Color Picker
134
134
$ ( 'select.color-picker' , elem ) . replaceWith ( chooseColor ( color ) ) ;
135
-
135
+
136
136
137
137
// Add event when selection changed to retrieve the current smoothing settings.
138
138
$ ( 'select.form-control' , elem ) . change ( function ( ) {
@@ -147,13 +147,13 @@ function GraphConfigurationDialog(dialog, onSave) {
147
147
$ ( this ) . css ( 'background' , $ ( 'select.color-picker option:selected' , elem ) . val ( ) )
148
148
. css ( 'color' , $ ( 'select.color-picker option:selected' , elem ) . val ( ) ) ;
149
149
} ) ;
150
-
150
+
151
151
152
152
return elem ;
153
153
}
154
-
154
+
155
155
function renderGraph ( flightLog , index , graph ) {
156
- var
156
+ var
157
157
graphElem = $ (
158
158
'<li class="config-graph" id="' + index + '">'
159
159
+ '<dl>'
@@ -201,9 +201,9 @@ function GraphConfigurationDialog(dialog, onSave) {
201
201
+ '</li>'
202
202
) ,
203
203
fieldList = $ ( ".config-graph-field-list" , graphElem ) ;
204
-
204
+
205
205
$ ( "input" , graphElem ) . val ( graph . label ) ;
206
-
206
+
207
207
var fieldCount = graph . fields . length ;
208
208
209
209
// "Add field" button
@@ -221,23 +221,23 @@ function GraphConfigurationDialog(dialog, onSave) {
221
221
} ) ;
222
222
223
223
//Populate the Height seletor
224
- $ ( 'select.graph-height' , graphElem ) . replaceWith ( chooseHeight ( graph . height ?( graph . height ) :1 ) ) ;
224
+ $ ( 'select.graph-height' , graphElem ) . replaceWith ( chooseHeight ( graph . height ?( graph . height ) :1 ) ) ;
225
225
226
226
// Add Field List
227
227
for ( var i = 0 ; i < graph . fields . length ; i ++ ) {
228
- var
228
+ var
229
229
field = graph . fields [ i ] ,
230
230
fieldElem = renderField ( flightLog , field , field . color ?( field . color ) :( GraphConfig . PALETTE [ i ] . color ) ) ;
231
-
231
+
232
232
fieldList . append ( fieldElem ) ;
233
233
}
234
-
234
+
235
235
fieldList . on ( 'click' , 'button' , function ( e ) {
236
236
var
237
237
parentGraph = $ ( this ) . parents ( '.config-graph' ) ;
238
-
238
+
239
239
$ ( this ) . parents ( '.config-graph-field' ) . remove ( ) ;
240
-
240
+
241
241
// Remove the graph upon removal of the last field
242
242
if ( $ ( ".config-graph-field" , parentGraph ) . length === 0 ) {
243
243
parentGraph . remove ( ) ;
@@ -248,67 +248,67 @@ function GraphConfigurationDialog(dialog, onSave) {
248
248
} ) ;
249
249
250
250
updateRemoveAllButton ( ) ;
251
-
251
+
252
252
return graphElem ;
253
253
}
254
-
254
+
255
255
function renderGraphs ( flightLog , graphs ) {
256
256
var
257
257
graphList = $ ( ".config-graphs-list" , dialog ) ;
258
-
258
+
259
259
graphList . empty ( ) ;
260
-
260
+
261
261
for ( var i = 0 ; i < graphs . length ; i ++ ) {
262
262
graphList . append ( renderGraph ( flightLog , i , graphs [ i ] ) ) ;
263
263
}
264
264
}
265
-
265
+
266
266
function populateExampleGraphs ( flightLog , menu ) {
267
267
var
268
268
i ;
269
-
269
+
270
270
menu . empty ( ) ;
271
-
271
+
272
272
exampleGraphs = GraphConfig . getExampleGraphConfigs ( flightLog ) ;
273
-
273
+
274
274
exampleGraphs . unshift ( {
275
275
label : "Custom graph" ,
276
276
fields : [ { name :"" } ] ,
277
277
dividerAfter : true
278
278
} ) ;
279
-
279
+
280
280
for ( i = 0 ; i < exampleGraphs . length ; i ++ ) {
281
- var
281
+ var
282
282
graph = exampleGraphs [ i ] ,
283
283
li = $ ( '<li><a href="#"></a></li>' ) ;
284
-
284
+
285
285
$ ( 'a' , li )
286
286
. text ( graph . label )
287
287
. data ( 'graphIndex' , i ) ;
288
-
288
+
289
289
menu . append ( li ) ;
290
-
290
+
291
291
if ( graph . dividerAfter ) {
292
292
menu . append ( '<li class="divider"></li>' ) ;
293
293
}
294
294
}
295
295
}
296
-
296
+
297
297
function convertUIToGraphConfig ( ) {
298
- var
298
+ var
299
299
graphs = [ ] ,
300
300
graph ,
301
301
field ;
302
-
302
+
303
303
$ ( ".config-graph" , dialog ) . each ( function ( ) {
304
304
graph = {
305
305
fields : [ ] ,
306
306
height : 1
307
307
} ;
308
-
308
+
309
309
graph . label = $ ( "input[type='text']" , this ) . val ( ) ;
310
310
graph . height = parseInt ( $ ( 'select.graph-height option:selected' , this ) . val ( ) ) ;
311
-
311
+
312
312
$ ( ".config-graph-field" , this ) . each ( function ( ) {
313
313
field = {
314
314
name : $ ( "select" , this ) . val ( ) ,
@@ -326,15 +326,15 @@ function GraphConfigurationDialog(dialog, onSave) {
326
326
lineWidth : parseInt ( $ ( "input[name=linewidth]" , this ) . val ( ) ) ,
327
327
grid : $ ( 'input[name=grid]' , this ) . is ( ':checked' ) ,
328
328
} ;
329
-
329
+
330
330
if ( field . name . length > 0 ) {
331
331
graph . fields . push ( field ) ;
332
332
}
333
333
} ) ;
334
334
335
335
graphs . push ( graph ) ;
336
336
} ) ;
337
-
337
+
338
338
return graphs ;
339
339
}
340
340
@@ -345,64 +345,64 @@ function GraphConfigurationDialog(dialog, onSave) {
345
345
lastRoot = null ,
346
346
fieldNames = flightLog . getMainFieldNames ( ) ,
347
347
fieldsSeen = { } ;
348
-
348
+
349
349
offeredFieldNames = [ ] ;
350
-
350
+
351
351
for ( i = 0 ; i < fieldNames . length ; i ++ ) {
352
352
// For fields with multiple bracketed x[0], x[1] versions, add an "[all]" option
353
- var
353
+ var
354
354
fieldName = fieldNames [ i ] ,
355
355
matches = fieldName . match ( / ^ ( .+ ) \[ [ 0 - 9 ] + \] $ / ) ;
356
-
356
+
357
357
if ( BLACKLISTED_FIELDS [ fieldName ] )
358
358
continue ;
359
-
359
+
360
360
if ( matches ) {
361
361
if ( matches [ 1 ] != lastRoot ) {
362
362
lastRoot = matches [ 1 ] ;
363
-
363
+
364
364
offeredFieldNames . push ( lastRoot + "[all]" ) ;
365
365
fieldsSeen [ lastRoot + "[all]" ] = true ;
366
366
}
367
367
} else {
368
368
lastRoot = null ;
369
369
}
370
-
370
+
371
371
offeredFieldNames . push ( fieldName ) ;
372
372
fieldsSeen [ fieldName ] = true ;
373
373
}
374
-
375
- /*
374
+
375
+ /*
376
376
* If the graph config has any fields in it that we don't have available in our flight log, add them to
377
377
* the GUI anyway. (This way we can build a config when using a tricopter (which includes a tail servo) and
378
378
* keep that tail servo in the config when we're viewing a quadcopter).
379
379
*/
380
380
for ( i = 0 ; i < config . length ; i ++ ) {
381
- var
381
+ var
382
382
graph = config [ i ] ;
383
-
383
+
384
384
for ( j = 0 ; j < graph . fields . length ; j ++ ) {
385
- var
385
+ var
386
386
field = graph . fields [ j ] ;
387
-
387
+
388
388
if ( ! fieldsSeen [ field . name ] ) {
389
389
offeredFieldNames . push ( field . name ) ;
390
390
}
391
391
}
392
392
}
393
393
}
394
-
394
+
395
395
this . show = function ( flightLog , config ) {
396
396
dialog . modal ( 'show' ) ;
397
-
397
+
398
398
activeFlightLog = flightLog ;
399
-
399
+
400
400
buildOfferedFieldNamesList ( flightLog , config ) ;
401
401
402
402
populateExampleGraphs ( flightLog , exampleGraphsMenu ) ;
403
403
renderGraphs ( flightLog , config ) ;
404
404
} ;
405
-
405
+
406
406
$ ( ".graph-configuration-dialog-save" ) . click ( function ( ) {
407
407
onSave ( convertUIToGraphConfig ( ) ) ;
408
408
} ) ;
@@ -424,16 +424,16 @@ function GraphConfigurationDialog(dialog, onSave) {
424
424
425
425
exampleGraphsButton . dropdown ( ) ;
426
426
exampleGraphsMenu . on ( "click" , "a" , function ( e ) {
427
- var
427
+ var
428
428
graph = exampleGraphs [ $ ( this ) . data ( "graphIndex" ) ] ,
429
429
graphElem = renderGraph ( activeFlightLog , $ ( ".config-graph" , dialog ) . length , graph ) ;
430
-
430
+
431
431
$ ( configGraphsList , dialog ) . append ( graphElem ) ;
432
432
updateRemoveAllButton ( ) ;
433
-
433
+
434
434
// Dismiss the dropdown button
435
435
exampleGraphsButton . dropdown ( "toggle" ) ;
436
-
436
+
437
437
e . preventDefault ( ) ;
438
438
} ) ;
439
439
0 commit comments