Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit 99da72c

Browse files
committed
Ability to control smoothing settings per-graphline
1 parent f918be9 commit 99da72c

File tree

3 files changed

+125
-37
lines changed

3 files changed

+125
-37
lines changed

app/css/main.css

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ html.has-log .log-graph-config {
163163
.config-graph dd {
164164
margin-top:0.5em;
165165
}
166-
.config-graph-field {
167-
margin:0.5em 0;
168-
}
169-
.config-graph-field select {
170-
margin-right:4px;
171-
}
172166
.config-graph h4,
173167
.config-graph .remove-single-graph-button {
174168
display:inline-block;
@@ -177,6 +171,10 @@ html.has-log .log-graph-config {
177171
.config-graph h4 button {
178172
margin-left:0.5em;
179173
}
174+
.config-graph .table > tbody > tr > td,
175+
.config-graph .table > thead:first-child > tr:first-child > th {
176+
border: none;
177+
}
180178

181179
#graphCanvas {
182180
position:absolute;

app/js/graph_config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,15 @@ function GraphConfig(graphConfig) {
7373
colorIndex++;
7474
}
7575

76-
if (field.smoothing === undefined) {
76+
if (field.smoothing === undefined || field.smoothing == "default") {
7777
field.smoothing = GraphConfig.getDefaultSmoothingForField(flightLog, field.name);
78+
} else {
79+
let
80+
smoothing = parseInt(field.smoothing, 10);
81+
82+
if (!isNaN(smoothing)) {
83+
field.smoothing = smoothing;
84+
}
7885
}
7986

8087
return field;

app/js/graph_config_dialog.js

Lines changed: 113 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,46 @@ const
88
{Presets} = require("./presets.js"),
99
PresetPicker = require("./preset_picker.js");
1010

11+
function formatTinyInterval(nanos) {
12+
let
13+
millis = Math.floor(nanos / 1000);
14+
15+
nanos = nanos % 1000;
16+
17+
if (millis > 0) {
18+
if (nanos == 0) {
19+
return millis + "ms";
20+
} else {
21+
return (millis + nanos / 1000).toFixed(1) + "ms";
22+
}
23+
} else {
24+
return nanos + "ns";
25+
}
26+
}
27+
1128
/**
1229
*
1330
* @param {HTMLElement} dialog - Root dialog element to attach to
1431
* @param {Presets} graphPresets
1532
* @constructor
1633
*/
1734
function GraphConfigurationDialog(dialog, graphPresets) {
35+
const
36+
// Some fields it doesn't make sense to graph
37+
BLACKLISTED_FIELDS = {time:true, loopIteration:true},
38+
39+
SUGGESTED_SMOOTHING_INTERVALS = [
40+
500, 1000, 1500, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 15000, 20000, 30000, 40000, 50000
41+
],
42+
43+
SMOOTHING_OPTIONS = SUGGESTED_SMOOTHING_INTERVALS.map(interval => ({
44+
name: formatTinyInterval(interval),
45+
value: interval
46+
})),
47+
48+
that = this;
49+
1850
var
19-
// Some fields it doesn't make sense to graph
20-
BLACKLISTED_FIELDS = {time:true, loopIteration:true},
2151
offeredFieldNames = [],
2252
exampleGraphs = [],
2353

@@ -41,17 +71,14 @@ function GraphConfigurationDialog(dialog, graphPresets) {
4171

4272
}
4373

44-
function renderFieldOption(fieldName, selectedName) {
45-
var
46-
option = $("<option></option>")
47-
.text(FlightLogFieldPresenter.fieldNameToFriendly(fieldName))
48-
.attr("value", fieldName);
49-
50-
if (fieldName == selectedName) {
51-
option.attr("selected", "selected");
52-
}
53-
54-
return option;
74+
function renderOptionElem(value, displayName) {
75+
var
76+
result = document.createElement("option");
77+
78+
result.innerText = displayName;
79+
result.value = value;
80+
81+
return result;
5582
}
5683

5784
/**
@@ -60,19 +87,46 @@ function GraphConfigurationDialog(dialog, graphPresets) {
6087
*/
6188
function renderField(field) {
6289
let
63-
elem = $(
64-
'<li class="config-graph-field">'
65-
+ '<select class="form-control"><option value="">(choose a field)</option></select>'
66-
+ '<button type="button" class="btn btn-default btn-sm">Remove</button>'
67-
+ '</li>'
68-
),
69-
select = $('select', elem),
90+
elem = $(`
91+
<tr class="config-graph-field">
92+
<td>
93+
<select class="form-control graph-field-name">
94+
<option value="">(choose a field)</option>
95+
</select>
96+
</td>
97+
<td>
98+
<select class="form-control graph-field-smoothing"></select>
99+
</td>
100+
<td>
101+
<button type="button" class="btn btn-default btn-sm">Remove</button>
102+
</td>
103+
</tr>
104+
`),
105+
fieldNameSelect = $('.graph-field-name', elem),
106+
smoothingSelect = $('.graph-field-smoothing', elem),
107+
70108
selectedFieldName = fieldfield.name : false;
71-
72-
for (let fieldName of offeredFieldNames) {
73-
select.append(renderFieldOption(fieldName, selectedFieldName));
74-
}
75-
109+
110+
fieldNameSelect.append(offeredFieldNames.map(name => renderOptionElem(name, FlightLogFieldPresenter.fieldNameToFriendly(name))));
111+
fieldNameSelect.val(selectedFieldName);
112+
113+
let
114+
defaultSmoothingMessage = "Default";
115+
116+
if (selectedFieldName) {
117+
let
118+
defaultSmoothing = GraphConfig.getDefaultSmoothingForField(that.flightLog, selectedFieldName);
119+
120+
defaultSmoothingMessage += " (" + (defaultSmoothing ? formatTinyInterval(defaultSmoothing) : "none") + ")";
121+
}
122+
123+
smoothingSelect.append(renderOptionElem("default", defaultSmoothingMessage));
124+
smoothingSelect.append(renderOptionElem("0", "None"));
125+
126+
smoothingSelect.append(SMOOTHING_OPTIONS.map(suggestion => renderOptionElem(suggestion.value, suggestion.name)));
127+
128+
smoothingSelect.val(field.smoothing === undefined ? "default" : field.smoothing);
129+
76130
return elem;
77131
}
78132

@@ -96,7 +150,23 @@ function GraphConfigurationDialog(dialog, graphPresets) {
96150
<div class="form-group">
97151
<label class="col-sm-2 control-label">Fields</label>
98152
<div class="col-sm-10">
99-
<ul class="config-graph-field-list form-group-sm form-inline list-unstyled"></ul>
153+
<table class="config-graph-field-list form-group-sm table table-condensed">
154+
<thead>
155+
<tr>
156+
<th>
157+
Field name
158+
</th>
159+
<th>
160+
Smoothing
161+
</th>
162+
<th>
163+
&nbsp;
164+
</th>
165+
</tr>
166+
</thead>
167+
<tbody>
168+
</tbody>
169+
</table>
100170
<button type="button" class="btn btn-default btn-sm add-field-button"><span class="glyphicon glyphicon-plus"></span> Add field</button>
101171
</div>
102172
</div>
@@ -105,7 +175,7 @@ function GraphConfigurationDialog(dialog, graphPresets) {
105175
</dl>
106176
</li>
107177
`),
108-
fieldList = $(".config-graph-field-list", graphElem),
178+
fieldList = $(".config-graph-field-list tbody", graphElem),
109179
graphNameField = $("input", graphElem);
110180

111181
graphNameField
@@ -130,14 +200,25 @@ function GraphConfigurationDialog(dialog, graphPresets) {
130200
.append(graph.fields.map(renderField))
131201

132202
// Catch field dropdown changes
133-
.on("change", "select", function(e) {
203+
.on("change", ".graph-field-name", function(e) {
134204
let
135205
fieldIndex = $(this).parents('.config-graph-field').index();
136206

137207
updateActivePreset(preset => preset.graphs[graphIndex].fields[fieldIndex].name = $(e.target).val());
138208
})
139-
140-
// Remove field button
209+
.on("change", ".graph-field-smoothing", function(e) {
210+
let
211+
fieldIndex = $(this).parents('.config-graph-field').index(),
212+
newVal = $(e.target).val();
213+
214+
if (!isNaN(parseInt(newVal, 10))) {
215+
newVal = parseInt(newVal, 10);
216+
}
217+
218+
updateActivePreset(preset => preset.graphs[graphIndex].fields[fieldIndex].smoothing = newVal);
219+
})
220+
221+
// Remove field button
141222
.on('click', 'button', function(e) {
142223
let
143224
fieldIndex = $(this).parents('.config-graph-field').index();
@@ -248,6 +329,8 @@ function GraphConfigurationDialog(dialog, graphPresets) {
248329
// We'll restore this backup if the user cancels the dialog
249330
graphPresetsBackup = graphPresets.clone();
250331

332+
this.flightLog = flightLog;
333+
251334
populateExampleGraphs(flightLog, exampleGraphsMenu);
252335
buildOfferedFieldNamesList(flightLog, graphPresets.getActivePreset().graphs);
253336

0 commit comments

Comments
 (0)