Fix icon marker plotting for branch == -1

This commit is contained in:
SiboVG 2022-12-30 20:32:33 +01:00
parent 6cdc2d920e
commit c374f616b9

View File

@ -94,7 +94,6 @@ public class SimulationPlot {
void setShowBranch(int branch) { void setShowBranch(int branch) {
XYPlot plot = (XYPlot) chart.getPlot(); XYPlot plot = (XYPlot) chart.getPlot();
plot.clearAnnotations();
int datasetcount = plot.getDatasetCount(); int datasetcount = plot.getDatasetCount();
for (int i = 0; i < datasetcount; i++) { for (int i = 0; i < datasetcount; i++) {
int seriescount = ((XYSeriesCollection) plot.getDataset(i)).getSeriesCount(); int seriescount = ((XYSeriesCollection) plot.getDataset(i)).getSeriesCount();
@ -409,17 +408,44 @@ public class SimulationPlot {
XYPlot plot = chart.getXYPlot(); XYPlot plot = chart.getXYPlot();
FlightDataBranch dataBranch = simulation.getSimulatedData().getBranch(Math.max(branch, 0)); FlightDataBranch dataBranch = simulation.getSimulatedData().getBranch(Math.max(branch, 0));
// Clear existing domain markers // Clear existing domain markers and annotations
plot.clearDomainMarkers(); plot.clearDomainMarkers();
plot.clearAnnotations();
// Construct domain marker lists collapsing based on time. // Store flight event information
List<Double> eventTimes = new ArrayList<>();
List<String> eventLabels = new ArrayList<>();
List<Color> eventColors = new ArrayList<>();
List<Image> eventImages = new ArrayList<>();
List<Double> eventTimes = new ArrayList<Double>(); // Plot the markers
List<String> eventLabels = new ArrayList<String>(); if (config.getDomainAxisType() == FlightDataType.TYPE_TIME && !preferences.getBoolean(Preferences.MARKER_STYLE_ICON, false)) {
List<Color> eventColors = new ArrayList<Color>(); fillEventLists(branch, eventTimes, eventLabels, eventColors, eventImages);
List<Image> eventImages = new ArrayList<Image>(); plotVerticalMarkers(plot, eventTimes, eventLabels, eventColors);
{
HashSet<FlightEvent.Type> typeSet = new HashSet<FlightEvent.Type>(); } else { // Other domains are plotted as image annotations
if (branch == -1) {
// For icon markers, we need to do the plotting separately, otherwise you can have icon markers from e.g.
// branch 1 be plotted on branch 0
for (int b = 0; b < simulation.getSimulatedData().getBranchCount(); b++) {
fillEventLists(b, eventTimes, eventLabels, eventColors, eventImages);
dataBranch = simulation.getSimulatedData().getBranch(b);
plotIconMarkers(plot, dataBranch, eventTimes, eventLabels, eventImages);
eventTimes.clear();
eventLabels.clear();
eventColors.clear();
eventImages.clear();
}
} else {
fillEventLists(branch, eventTimes, eventLabels, eventColors, eventImages);
plotIconMarkers(plot, dataBranch, eventTimes, eventLabels, eventImages);
}
}
}
private void fillEventLists(int branch, List<Double> eventTimes, List<String> eventLabels,
List<Color> eventColors, List<Image> eventImages) {
HashSet<FlightEvent.Type> typeSet = new HashSet<>();
double prevTime = -100; double prevTime = -100;
String text = null; String text = null;
Color color = null; Color color = null;
@ -433,7 +459,6 @@ public class SimulationPlot {
FlightEvent.Type type = info.event.getType(); FlightEvent.Type type = info.event.getType();
if (Math.abs(t - prevTime) <= 0.05) { if (Math.abs(t - prevTime) <= 0.05) {
if (!typeSet.contains(type)) { if (!typeSet.contains(type)) {
text = text + ", " + type.toString(); text = text + ", " + type.toString();
color = EventGraphics.getEventColor(type); color = EventGraphics.getEventColor(type);
@ -442,7 +467,6 @@ public class SimulationPlot {
} }
} else { } else {
if (text != null) { if (text != null) {
eventTimes.add(prevTime); eventTimes.add(prevTime);
eventLabels.add(text); eventLabels.add(text);
@ -466,8 +490,7 @@ public class SimulationPlot {
} }
} }
// Plot the markers private static void plotVerticalMarkers(XYPlot plot, List<Double> eventTimes, List<String> eventLabels, List<Color> eventColors) {
if (config.getDomainAxisType() == FlightDataType.TYPE_TIME && !preferences.getBoolean(Preferences.MARKER_STYLE_ICON, false)) {
double markerWidth = 0.01 * plot.getDomainAxis().getUpperBound(); double markerWidth = 0.01 * plot.getDomainAxis().getUpperBound();
// Domain time is plotted as vertical markers // Domain time is plotted as vertical markers
@ -488,8 +511,10 @@ public class SimulationPlot {
plot.setDomainAxis(new PresetNumberAxis(plot.getDomainAxis().getLowerBound(), t + markerWidth)); plot.setDomainAxis(new PresetNumberAxis(plot.getDomainAxis().getLowerBound(), t + markerWidth));
} }
} }
}
} else { // Other domains are plotted as image annotations private void plotIconMarkers(XYPlot plot, FlightDataBranch dataBranch, List<Double> eventTimes,
List<String> eventLabels, List<Image> eventImages) {
List<Double> time = dataBranch.get(FlightDataType.TYPE_TIME); List<Double> time = dataBranch.get(FlightDataType.TYPE_TIME);
List<Double> domain = dataBranch.get(config.getDomainAxisType()); List<Double> domain = dataBranch.get(config.getDomainAxisType());
@ -499,8 +524,9 @@ public class SimulationPlot {
double t = eventTimes.get(i); double t = eventTimes.get(i);
Image image = eventImages.get(i); Image image = eventImages.get(i);
if (image == null) if (image == null) {
continue; continue;
}
double xcoord = domainInterpolator.getValue(t); double xcoord = domainInterpolator.getValue(t);
@ -537,7 +563,6 @@ public class SimulationPlot {
} }
} }
} }
}
private List<EventDisplayInfo> buildEventInfo() { private List<EventDisplayInfo> buildEventInfo() {
ArrayList<EventDisplayInfo> eventList = new ArrayList<EventDisplayInfo>(); ArrayList<EventDisplayInfo> eventList = new ArrayList<EventDisplayInfo>();