Skip to content

Commit 964ce3f

Browse files
authored
Toggle trace/field visibility (#664)
* Toggle trace/field visibility * Fix sonar issues * Fix onClick flickering * Open analyser by clicking on settings and value
1 parent fa9df0c commit 964ce3f

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

css/main.css

+9
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,10 @@ html.has-config .configuration-list {
792792
padding-right: 0.7em;
793793
}
794794

795+
.graph-legend-field-name:hover {
796+
text-decoration: underline;
797+
}
798+
795799
.graph-legend-field-value {
796800
float: right;
797801
}
@@ -814,6 +818,11 @@ html.has-config .configuration-list {
814818
margin-left: 0.7em;
815819
}
816820

821+
.graph-legend-field-visibility {
822+
float: right;
823+
margin-left: 0.7em;
824+
}
825+
817826
html.has-video .graph-row,
818827
html.has-log .graph-row {
819828
display:-webkit-flex;

js/graph_config.js

+17
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function GraphConfig(graphConfig) {
1919
this.highlightGraphIndex = null;
2020
this.highlightFieldIndex = null;
2121

22+
const hiddenGraphFields = new Set();
23+
2224
this.getGraphs = function() {
2325
return graphs;
2426
};
@@ -29,6 +31,8 @@ function GraphConfig(graphConfig) {
2931
this.setGraphs = function(newGraphs) {
3032
graphs = newGraphs;
3133

34+
hiddenGraphFields.clear();
35+
3236
notifyListeners();
3337
};
3438

@@ -129,6 +133,19 @@ function GraphConfig(graphConfig) {
129133
this.addListener = function(listener) {
130134
listeners.push(listener);
131135
};
136+
137+
this.toggleGraphField = (graphIndex, fieldIndex) => {
138+
const item = graphIndex + ":" + fieldIndex;
139+
if (hiddenGraphFields.has(item)) {
140+
hiddenGraphFields.delete(item);
141+
} else {
142+
hiddenGraphFields.add(item);
143+
}
144+
};
145+
146+
this.isGraphFieldHidden = (graphIndex, fieldIndex) => {
147+
return hiddenGraphFields.has(graphIndex + ":" + fieldIndex);
148+
};
132149
}
133150

134151
GraphConfig.PALETTE = [

js/graph_legend.js

+31-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function GraphLegend(targetElem, config, onVisibilityChange, onNewSelectionChang
88
var
99
graphs = config.getGraphs(),
1010
i, j;
11-
11+
1212
targetElem.empty();
1313

1414
for (i = 0; i < graphs.length; i++) {
@@ -27,10 +27,11 @@ function GraphLegend(targetElem, config, onVisibilityChange, onNewSelectionChang
2727
li = $('<li class="graph-legend-field field-quick-adjust" name="' + field.name + '" graph="' + i + '" field="' + j +'"></li>'),
2828
nameElem = $('<span class="graph-legend-field-name field-quick-adjust" name="' + field.name + '" graph="' + i + '" field="' + j +'"></span>'),
2929
valueElem = $('<span class="graph-legend-field-value field-quick-adjust" name="' + field.name + '" graph="' + i + '" field="' + j +'"></span>'),
30-
settingsElem = $('<div class="graph-legend-field-settings field-quick-adjust" name="' + field.name + '" graph="' + i + '" field="' + j +'"></div>'),
31-
analyseElem = $('<span class="glyphicon glyphicon-equalizer"></span>');
30+
settingsElem = $('<div class="graph-legend-field-settings field-quick-adjust" name="' + field.name + '" graph="' + i + '" field="' + j + '"></div>'),
31+
visibilityIcon = config.isGraphFieldHidden(i, j) ? "glyphicon-eye-close" : "glyphicon-eye-open",
32+
visibilityElem = $('<span class="glyphicon ' + visibilityIcon + ' graph-legend-field-visibility" graph="' + i + '" field="' + j + '"></span>');
3233
li.append(nameElem);
33-
li.append(analyseElem);
34+
li.append(visibilityElem);
3435
li.append(valueElem);
3536
li.append(settingsElem);
3637

@@ -63,7 +64,7 @@ function GraphLegend(targetElem, config, onVisibilityChange, onNewSelectionChang
6364
});
6465

6566
// Add a trigger on legend; select the analyser graph/field to plot
66-
$('.graph-legend-field').on('click', function(e) {
67+
$('.graph-legend-field-name, .graph-legend-field-settings, .graph-legend-field-value').on('click', function (e) {
6768

6869
if(e.which!=1) return; // only accept left mouse clicks
6970

@@ -134,7 +135,31 @@ function GraphLegend(targetElem, config, onVisibilityChange, onNewSelectionChang
134135
});
135136

136137
// on first show, hide the analyser button
137-
if(!config.selectedFieldName) $('.hide-analyser-window').hide();
138+
if (!config.selectedFieldName) $('.hide-analyser-window').hide();
139+
140+
// Add a trigger on legend; select the analyser graph/field to plot
141+
$('.graph-legend-field-visibility').on('click', function (e) {
142+
if (e.which != 1) {
143+
return; // only accept left mouse clicks
144+
}
145+
146+
const $this = $(this),
147+
graphIndex = $this.attr('graph'),
148+
fieldIndex = $this.attr('field');
149+
150+
config.toggleGraphField(graphIndex, fieldIndex);
151+
onHighlightChange();
152+
153+
if (config.isGraphFieldHidden(graphIndex, fieldIndex)) {
154+
$this.removeClass("glyphicon-eye-open");
155+
$this.addClass("glyphicon-eye-close");
156+
} else {
157+
$this.addClass("glyphicon-eye-open");
158+
$this.removeClass("glyphicon-eye-close");
159+
}
160+
161+
e.preventDefault();
162+
});
138163
}
139164

140165
this.updateValues = function (flightLog, frame) {

js/grapher.js

+3
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,9 @@ function FlightLogGrapher(flightLog, graphConfig, canvas, stickCanvas, craftCanv
800800
drawAxisBackground(canvas.height * graph.height);
801801

802802
for (j = 0; j < graph.fields.length; j++) {
803+
if (graphConfig.isGraphFieldHidden(i, j)) {
804+
continue;
805+
}
803806
var field = graph.fields[j];
804807
plotField(chunks, startFrameIndex, field.index, field.curve, canvas.height * graph.height / 2,
805808
field.color ? field.color : GraphConfig.PALETTE[j % GraphConfig.PALETTE.length],

0 commit comments

Comments
 (0)