diff --git a/core/src/net/sf/openrocket/gui/plot/SimulationPlot.java b/core/src/net/sf/openrocket/gui/plot/SimulationPlot.java index 991672bc5..f5731805c 100644 --- a/core/src/net/sf/openrocket/gui/plot/SimulationPlot.java +++ b/core/src/net/sf/openrocket/gui/plot/SimulationPlot.java @@ -133,7 +133,12 @@ public class SimulationPlot { String name = getLabel(type, unit); List seriesNames = Util.generateSeriesLabels(simulation); - for (int branchIndex = 0; branchIndex < branchCount; branchIndex++) { + + // Populate data for each branch. + + // The primary branch (branchIndex = 0) is easy since all the data is copied + { + int branchIndex = 0; FlightDataBranch thisBranch = simulation.getSimulatedData().getBranch(branchIndex); // Store data in provided units List plotx = thisBranch.get(domainType); @@ -146,6 +151,39 @@ public class SimulationPlot { } data[axis].addSeries(series); } + // For each of the secondary branches, we use data from branch 0 for the earlier times + for (int branchIndex = 1; branchIndex < branchCount; branchIndex++) { + FlightDataBranch primaryBranch = simulation.getSimulatedData().getBranch(0); + FlightDataBranch thisBranch = simulation.getSimulatedData().getBranch(branchIndex); + + // Get first time index used in secondary branch; + double firstSampleTime = thisBranch.get(FlightDataType.TYPE_TIME).get(0); + + XYSeries series = new XYSeries(seriesNames.get(branchIndex) + ": " + name, false, true); + series.setDescription(thisBranch.getBranchName() + ": " + name); + + // Copy the first points from the primaryBranch. + List primaryT = primaryBranch.get(FlightDataType.TYPE_TIME); + List primaryx = primaryBranch.get(domainType); + List primaryy = primaryBranch.get(type); + + for (int j = 0; j < primaryT.size(); j++) { + if (primaryT.get(j) >= firstSampleTime) { + break; + } + series.add(domainUnit.toUnit(primaryx.get(j)), unit.toUnit(primaryy.get(j))); + } + + // Now copy all the data from the secondary branch + List plotx = thisBranch.get(domainType); + List ploty = thisBranch.get(type); + + int pointCount = plotx.size(); + for (int j = 0; j < pointCount; j++) { + series.add(domainUnit.toUnit(plotx.get(j)), unit.toUnit(ploty.get(j))); + } + data[axis].addSeries(series); + } // Update axis label if (axisLabel[axis] == null)