Merge pull request #1240 from SiboVG/issue-1128
[fixes #1128] Fix SimulationPlot range with boosters dataset
This commit is contained in:
commit
7d643f4787
@ -138,6 +138,10 @@ public class FlightData {
|
||||
return branches.get(n);
|
||||
}
|
||||
|
||||
public List<FlightDataBranch> getBranches() {
|
||||
return branches;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public double getMaxAltitude() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.sf.openrocket.gui.plot;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -426,8 +427,9 @@ public class PlotConfiguration implements Cloneable {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected void fitAxes(FlightDataBranch data) {
|
||||
this.fitAxes(Collections.singletonList(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fit the axes to hold the provided data. All of the plotDataAxis elements must
|
||||
@ -435,8 +437,7 @@ public class PlotConfiguration implements Cloneable {
|
||||
* <p>
|
||||
* NOTE: This method assumes that only two axes are used.
|
||||
*/
|
||||
protected void fitAxes(FlightDataBranch data) {
|
||||
|
||||
public void fitAxes(List<FlightDataBranch> data) {
|
||||
// Reset axes
|
||||
for (Axis a : allAxes) {
|
||||
a.reset();
|
||||
@ -453,8 +454,13 @@ public class PlotConfiguration implements Cloneable {
|
||||
}
|
||||
Axis axis = allAxes.get(index);
|
||||
|
||||
double min = unit.toUnit(data.getMinimum(type));
|
||||
double max = unit.toUnit(data.getMaximum(type));
|
||||
double min = unit.toUnit(data.get(0).getMinimum(type));
|
||||
double max = unit.toUnit(data.get(0).getMaximum(type));
|
||||
|
||||
for (int j = 1; j < data.size(); j++) {
|
||||
min = Math.min(min, unit.toUnit(data.get(j).getMinimum(type)));
|
||||
max = Math.max(max, unit.toUnit(data.get(j).getMaximum(type)));
|
||||
}
|
||||
|
||||
axis.addBound(min);
|
||||
axis.addBound(max);
|
||||
@ -491,41 +497,28 @@ public class PlotConfiguration implements Cloneable {
|
||||
|
||||
|
||||
//// Compute common zero
|
||||
// TODO: MEDIUM: This algorithm may require tweaking
|
||||
|
||||
double min1 = left.getMinValue();
|
||||
double max1 = left.getMaxValue();
|
||||
double min2 = right.getMinValue();
|
||||
double max2 = right.getMaxValue();
|
||||
|
||||
// Calculate and round scaling factor
|
||||
double scale = Math.max(left.getRangeLength(), right.getRangeLength()) /
|
||||
Math.min(left.getRangeLength(), right.getRangeLength());
|
||||
// Get the zero locations, scaled down to a value from 0 to 1 (0 = bottom of y axis, 1 = top)
|
||||
double zeroLoc1 = -min1 / left.getRangeLength();
|
||||
double zeroLoc2 = -min2 / right.getRangeLength();
|
||||
|
||||
//System.out.println("Scale: " + scale);
|
||||
|
||||
scale = roundScale(scale);
|
||||
if (right.getRangeLength() > left.getRangeLength()) {
|
||||
scale = 1 / scale;
|
||||
// Scale the right axis
|
||||
if (zeroLoc1 > zeroLoc2) {
|
||||
min2 = -max2 * (zeroLoc1 / (1 - zeroLoc1));
|
||||
} else {
|
||||
max2 = min2 * (-1 / zeroLoc1 + 1);
|
||||
}
|
||||
//System.out.println("Rounded scale: " + scale);
|
||||
|
||||
// Scale right axis, enlarge axes if necessary and scale back
|
||||
min2 *= scale;
|
||||
max2 *= scale;
|
||||
min1 = Math.min(min1, min2);
|
||||
min2 = min1;
|
||||
max1 = Math.max(max1, max2);
|
||||
max2 = max1;
|
||||
min2 /= scale;
|
||||
max2 /= scale;
|
||||
|
||||
// Apply scale
|
||||
left.addBound(min1);
|
||||
left.addBound(max1);
|
||||
right.addBound(min2);
|
||||
right.addBound(max2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@ import net.sf.openrocket.simulation.FlightDataType;
|
||||
import net.sf.openrocket.simulation.FlightEvent;
|
||||
import net.sf.openrocket.unit.Unit;
|
||||
import net.sf.openrocket.unit.UnitGroup;
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
import net.sf.openrocket.util.LinearInterpolator;
|
||||
|
||||
import net.sf.openrocket.utils.DecimalFormatter;
|
||||
@ -48,7 +49,6 @@ import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
|
||||
import org.jfree.chart.title.LegendTitle;
|
||||
import org.jfree.chart.title.TextTitle;
|
||||
import org.jfree.data.Range;
|
||||
import org.jfree.data.xy.XYDataItem;
|
||||
import org.jfree.data.xy.XYDataset;
|
||||
import org.jfree.data.xy.XYSeries;
|
||||
import org.jfree.data.xy.XYSeriesCollection;
|
||||
@ -134,7 +134,11 @@ public class SimulationPlot {
|
||||
// Fill the auto-selections based on first branch selected.
|
||||
FlightDataBranch mainBranch = simulation.getSimulatedData().getBranch(0);
|
||||
this.filled = config.fillAutoAxes(mainBranch);
|
||||
List<Axis> axes = filled.getAllAxes();
|
||||
|
||||
// Compute the axes based on the min and max value of all branches
|
||||
PlotConfiguration plotConfig = filled.clone();
|
||||
plotConfig.fitAxes(simulation.getSimulatedData().getBranches());
|
||||
List<Axis> minMaxAxes = plotConfig.getAllAxes();
|
||||
|
||||
// Create the data series for both axes
|
||||
XYSeriesCollection[] data = new XYSeriesCollection[2];
|
||||
@ -250,11 +254,11 @@ public class SimulationPlot {
|
||||
// Check whether axis has any data
|
||||
if (data[axisno].getSeriesCount() > 0) {
|
||||
// Create and set axis
|
||||
double min = axes.get(axisno).getMinValue();
|
||||
double max = axes.get(axisno).getMaxValue();
|
||||
double min = minMaxAxes.get(axisno).getMinValue();
|
||||
double max = minMaxAxes.get(axisno).getMaxValue();
|
||||
|
||||
NumberAxis axis = new PresetNumberAxis(min, max);
|
||||
axis.setLabel(axisLabel[axisno]);
|
||||
// axis.setRange(axes.get(i).getMinValue(), axes.get(i).getMaxValue());
|
||||
plot.setRangeAxis(axisno, axis);
|
||||
axis.setLabelFont(new Font("Dialog", Font.BOLD, 14));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user