Implement clamping in while panning. Don't allow panning past the min
or max.
This commit is contained in:
parent
d9c0f68e64
commit
06e702839f
@ -63,27 +63,27 @@ public class SimulationPlot {
|
||||
|
||||
int branchCount;
|
||||
|
||||
void setShowPoints( boolean showPoints ) {
|
||||
void setShowPoints(boolean showPoints) {
|
||||
for (ModifiedXYItemRenderer r : renderers) {
|
||||
r.setBaseShapesVisible(showPoints);
|
||||
}
|
||||
}
|
||||
|
||||
void setShowBranch( int branch ) {
|
||||
void setShowBranch(int branch) {
|
||||
XYPlot plot = (XYPlot) chart.getPlot();
|
||||
int datasetcount = plot.getDatasetCount();
|
||||
for( int i =0; i< datasetcount; i++ ) {
|
||||
int seriescount = ((XYSeriesCollection)plot.getDataset(i)).getSeriesCount();
|
||||
XYItemRenderer r = ((XYPlot)chart.getPlot()).getRenderer(i);
|
||||
for( int j=0; j<seriescount; j++) {
|
||||
boolean show = (branch<0) || (j % branchCount == branch);
|
||||
for (int i = 0; i < datasetcount; i++) {
|
||||
int seriescount = ((XYSeriesCollection) plot.getDataset(i)).getSeriesCount();
|
||||
XYItemRenderer r = ((XYPlot) chart.getPlot()).getRenderer(i);
|
||||
for (int j = 0; j < seriescount; j++) {
|
||||
boolean show = (branch < 0) || (j % branchCount == branch);
|
||||
r.setSeriesVisible(j, show);
|
||||
}
|
||||
}
|
||||
drawDomainMarkers(branch);
|
||||
}
|
||||
|
||||
SimulationPlot( Simulation simulation, PlotConfiguration config, boolean initialShowPoints ) {
|
||||
SimulationPlot(Simulation simulation, PlotConfiguration config, boolean initialShowPoints) {
|
||||
this.simulation = simulation;
|
||||
this.config = config;
|
||||
|
||||
@ -104,7 +104,7 @@ public class SimulationPlot {
|
||||
this.branchCount = simulation.getSimulatedData().getBranchCount();
|
||||
|
||||
// Fill the auto-selections based on first branch selected.
|
||||
FlightDataBranch mainBranch = simulation.getSimulatedData().getBranch( 0 );
|
||||
FlightDataBranch mainBranch = simulation.getSimulatedData().getBranch(0);
|
||||
this.filled = config.fillAutoAxes(mainBranch);
|
||||
List<Axis> axes = filled.getAllAxes();
|
||||
|
||||
@ -133,13 +133,13 @@ public class SimulationPlot {
|
||||
String name = getLabel(type, unit);
|
||||
|
||||
List<String> seriesNames = Util.generateSeriesLabels(simulation);
|
||||
for( int branchIndex=0; branchIndex<branchCount; branchIndex++ ) {
|
||||
for (int branchIndex = 0; branchIndex < branchCount; branchIndex++) {
|
||||
FlightDataBranch thisBranch = simulation.getSimulatedData().getBranch(branchIndex);
|
||||
// Store data in provided units
|
||||
List<Double> plotx = thisBranch.get(domainType);
|
||||
List<Double> ploty = thisBranch.get(type);
|
||||
XYSeries series = new XYSeries(seriesNames.get(branchIndex) + ": " + name, false, true);
|
||||
series.setDescription(thisBranch.getBranchName()+": " + name);
|
||||
series.setDescription(thisBranch.getBranchName() + ": " + name);
|
||||
int pointCount = plotx.size();
|
||||
for (int j = 0; j < pointCount; j++) {
|
||||
series.add(domainUnit.toUnit(plotx.get(j)), unit.toUnit(ploty.get(j)));
|
||||
@ -171,6 +171,11 @@ public class SimulationPlot {
|
||||
// axis.setRange(axes.get(i).getMinValue(), axes.get(i).getMaxValue());
|
||||
plot.setRangeAxis(axisno, axis);
|
||||
|
||||
double domainMin = data[i].getDomainLowerBound(true);
|
||||
double domainMax = data[i].getDomainUpperBound(true);
|
||||
|
||||
plot.setDomainAxis(new PresetNumberAxis(domainMin, domainMax));
|
||||
|
||||
// Add data and map to the axis
|
||||
plot.setDataset(axisno, data[i]);
|
||||
ModifiedXYItemRenderer r = new ModifiedXYItemRenderer(branchCount);
|
||||
@ -212,9 +217,9 @@ public class SimulationPlot {
|
||||
return name;
|
||||
}
|
||||
|
||||
private void drawDomainMarkers( int stage ) {
|
||||
private void drawDomainMarkers(int stage) {
|
||||
XYPlot plot = chart.getXYPlot();
|
||||
FlightDataBranch mainBranch = simulation.getSimulatedData().getBranch( 0 );
|
||||
FlightDataBranch mainBranch = simulation.getSimulatedData().getBranch(0);
|
||||
|
||||
// Clear existing domain markers
|
||||
plot.clearDomainMarkers();
|
||||
@ -231,8 +236,8 @@ public class SimulationPlot {
|
||||
String text = null;
|
||||
Color color = null;
|
||||
Image image = null;
|
||||
for( EventDisplayInfo info : eventList ) {
|
||||
if ( stage >=0 && stage != info.stage ) {
|
||||
for (EventDisplayInfo info : eventList) {
|
||||
if (stage >= 0 && stage != info.stage) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -277,7 +282,7 @@ public class SimulationPlot {
|
||||
if (config.getDomainAxisType() == FlightDataType.TYPE_TIME) {
|
||||
|
||||
// Domain time is plotted as vertical markers
|
||||
for ( int i=0; i<eventTimes.size(); i++ ) {
|
||||
for (int i = 0; i < eventTimes.size(); i++) {
|
||||
double t = eventTimes.get(i);
|
||||
String event = eventLabels.get(i);
|
||||
Color color = eventColors.get(i);
|
||||
@ -296,9 +301,9 @@ public class SimulationPlot {
|
||||
List<Double> time = mainBranch.get(FlightDataType.TYPE_TIME);
|
||||
List<Double> domain = mainBranch.get(config.getDomainAxisType());
|
||||
|
||||
LinearInterpolator domainInterpolator = new LinearInterpolator( time, domain );
|
||||
LinearInterpolator domainInterpolator = new LinearInterpolator(time, domain);
|
||||
|
||||
for ( int i=0; i<eventTimes.size(); i++ ) {
|
||||
for (int i = 0; i < eventTimes.size(); i++) {
|
||||
double t = eventTimes.get(i);
|
||||
String event = eventLabels.get(i);
|
||||
Image image = eventImages.get(i);
|
||||
@ -336,11 +341,11 @@ public class SimulationPlot {
|
||||
private List<EventDisplayInfo> buildEventInfo() {
|
||||
ArrayList<EventDisplayInfo> eventList = new ArrayList<EventDisplayInfo>();
|
||||
|
||||
for( int branch=0; branch<branchCount; branch++ ) {
|
||||
for (int branch = 0; branch < branchCount; branch++) {
|
||||
List<FlightEvent> events = simulation.getSimulatedData().getBranch(branch).getEvents();
|
||||
for( FlightEvent event : events ) {
|
||||
for (FlightEvent event : events) {
|
||||
FlightEvent.Type type = event.getType();
|
||||
if ( type != FlightEvent.Type.ALTITUDE && config.isEventActive(type)) {
|
||||
if (type != FlightEvent.Type.ALTITUDE && config.isEventActive(type)) {
|
||||
EventDisplayInfo info = new EventDisplayInfo();
|
||||
info.stage = branch;
|
||||
info.time = event.getTime();
|
||||
@ -354,8 +359,10 @@ public class SimulationPlot {
|
||||
|
||||
@Override
|
||||
public int compare(EventDisplayInfo o1, EventDisplayInfo o2) {
|
||||
if ( o1.time< o2.time) return -1;
|
||||
if ( o1.time == o2.time)return 0;
|
||||
if (o1.time < o2.time)
|
||||
return -1;
|
||||
if (o1.time == o2.time)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -363,59 +370,6 @@ public class SimulationPlot {
|
||||
|
||||
return eventList;
|
||||
|
||||
/*
|
||||
double prevTime = -100;
|
||||
String text = null;
|
||||
Color color = null;
|
||||
Image image = null;
|
||||
for ( int branch=0; branch<branchCount; branch++ ) {
|
||||
List<FlightEvent> events = simulation.getSimulatedData().getBranch(branch).getEvents();
|
||||
for (int i = 0; i < events.size(); i++) {
|
||||
FlightEvent event = events.get(i);
|
||||
double t = event.getTime();
|
||||
FlightEvent.Type type = event.getType();
|
||||
|
||||
if (type != FlightEvent.Type.ALTITUDE && config.isEventActive(type)) {
|
||||
if (Math.abs(t - prevTime) <= 0.05) {
|
||||
|
||||
if (!typeSet.contains(type)) {
|
||||
text = text + ", " + type.toString();
|
||||
color = EventGraphics.getEventColor(type);
|
||||
image = EventGraphics.getEventImage(type);
|
||||
typeSet.add(type);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (text != null) {
|
||||
EventDisplayInfo info = new EventDisplayInfo();
|
||||
info.time = prevTime;
|
||||
info.event = text;
|
||||
info.color = color;
|
||||
info.image = image;
|
||||
eventList.add(info);
|
||||
}
|
||||
prevTime = t;
|
||||
text = type.toString();
|
||||
color = EventGraphics.getEventColor(type);
|
||||
image = EventGraphics.getEventImage(type);
|
||||
typeSet.clear();
|
||||
typeSet.add(type);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (text != null) {
|
||||
EventDisplayInfo info = new EventDisplayInfo();
|
||||
info.time = prevTime;
|
||||
info.event = text;
|
||||
info.color = color;
|
||||
info.image = image;
|
||||
eventList.add(info);
|
||||
}
|
||||
return eventList;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -438,53 +392,53 @@ public class SimulationPlot {
|
||||
|
||||
private final int branchCount;
|
||||
|
||||
private ModifiedXYItemRenderer( int branchCount ) {
|
||||
private ModifiedXYItemRenderer(int branchCount) {
|
||||
this.branchCount = branchCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paint lookupSeriesPaint(int series) {
|
||||
return super.lookupSeriesPaint(series/branchCount);
|
||||
return super.lookupSeriesPaint(series / branchCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paint lookupSeriesFillPaint(int series) {
|
||||
return super.lookupSeriesFillPaint(series/branchCount);
|
||||
return super.lookupSeriesFillPaint(series / branchCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paint lookupSeriesOutlinePaint(int series) {
|
||||
return super.lookupSeriesOutlinePaint(series/branchCount);
|
||||
return super.lookupSeriesOutlinePaint(series / branchCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stroke lookupSeriesStroke(int series) {
|
||||
return super.lookupSeriesStroke(series/branchCount);
|
||||
return super.lookupSeriesStroke(series / branchCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stroke lookupSeriesOutlineStroke(int series) {
|
||||
return super.lookupSeriesOutlineStroke(series/branchCount);
|
||||
return super.lookupSeriesOutlineStroke(series / branchCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shape lookupSeriesShape(int series) {
|
||||
return DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[series%branchCount%DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE.length];
|
||||
return DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[series % branchCount % DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE.length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shape lookupLegendShape(int series) {
|
||||
return DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[series%branchCount%DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE.length];
|
||||
return DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[series % branchCount % DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE.length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Font lookupLegendTextFont(int series) {
|
||||
return super.lookupLegendTextFont(series/branchCount);
|
||||
return super.lookupLegendTextFont(series / branchCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paint lookupLegendTextPaint(int series) {
|
||||
return super.lookupLegendTextPaint(series/branchCount);
|
||||
return super.lookupLegendTextPaint(series / branchCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -560,6 +514,19 @@ public class SimulationPlot {
|
||||
protected void autoAdjustRange() {
|
||||
this.setRange(min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRange(Range range) {
|
||||
double lowerValue = range.getLowerBound();
|
||||
double upperValue = range.getUpperBound();
|
||||
if (lowerValue < min || upperValue > max) {
|
||||
// Don't blow past the min & max of the range this is important to keep
|
||||
// panning constrained within the current bounds.
|
||||
return;
|
||||
}
|
||||
super.setRange(new Range(lowerValue, upperValue));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class EventDisplayInfo {
|
||||
|
Loading…
x
Reference in New Issue
Block a user