Fixed sparkline y axis labelling. Reverted it to how it previously worked (negative data values instead of negative scale).
issue #32
This commit is contained in:
@@ -115,7 +115,7 @@ public class Sparkline {
|
||||
}
|
||||
|
||||
//Update height of y axis.
|
||||
yAxis.setLowerBound(boats.size());
|
||||
setYAxisLowerBound();
|
||||
});
|
||||
|
||||
});
|
||||
@@ -143,17 +143,47 @@ public class Sparkline {
|
||||
xAxis.setUpperBound(race.getLegCount());
|
||||
xAxis.setTickUnit(1);
|
||||
|
||||
|
||||
//The y-axis uses negative values, with the minus sign hidden (e.g., boat in 1st has position -1, which becomes 1, boat in 6th has position -6, which becomes 6).
|
||||
//This is necessary to actually get the y-axis labelled correctly. Negative tick count doesn't work.
|
||||
//Set y axis details
|
||||
yAxis.setLowerBound(boats.size());
|
||||
yAxis.setUpperBound(1);
|
||||
yAxis.setAutoRanging(false);
|
||||
|
||||
yAxis.setTickUnit(1);
|
||||
yAxis.setMinorTickCount(0);
|
||||
|
||||
yAxis.setUpperBound(0);
|
||||
setYAxisLowerBound();
|
||||
|
||||
yAxis.setLabel("Position in Race");
|
||||
yAxis.setTickUnit(-1);//Negative tick reverses the y axis.
|
||||
|
||||
yAxis.setTickMarkVisible(true);
|
||||
yAxis.setTickLabelsVisible(true);
|
||||
yAxis.setTickMarkVisible(true);
|
||||
yAxis.setMinorTickVisible(true);
|
||||
yAxis.setMinorTickVisible(false);
|
||||
|
||||
|
||||
|
||||
//Hide minus number from displaying on axis.
|
||||
yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis) {
|
||||
@Override
|
||||
public String toString(Number value) {
|
||||
if ((value.intValue() == 0) || (value.intValue() < -boats.size())) {
|
||||
return "";
|
||||
|
||||
} else {
|
||||
return String.format("%d", -value.intValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the lower bound of the y-axis.
|
||||
*/
|
||||
private void setYAxisLowerBound() {
|
||||
yAxis.setLowerBound( -(boats.size() + 1));
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +209,7 @@ public class Sparkline {
|
||||
|
||||
|
||||
//All boats start in "last" place.
|
||||
series.getData().add(new XYChart.Data<>(0, boats.size()));
|
||||
series.getData().add(new XYChart.Data<>(0, -(boats.size())));
|
||||
|
||||
//Listen for changes in the boat's leg - we only update the graph when it changes leg.
|
||||
boat.legProperty().addListener(
|
||||
@@ -188,7 +218,7 @@ public class Sparkline {
|
||||
//Get the data to plot.
|
||||
List<VisualiserBoat> boatOrder = race.getLegCompletionOrder().get(oldValue);
|
||||
//Find boat position in list.
|
||||
int boatPosition = boatOrder.indexOf(boat) + 1;
|
||||
int boatPosition = -(boatOrder.indexOf(boat) + 1);
|
||||
|
||||
//Get leg number.
|
||||
int legNumber = oldValue.getLegNumber() + 1;
|
||||
|
||||
Reference in New Issue
Block a user