Fixed FPS issues and beautified sparkline display

- set upper and lower bounds for axis height
- formatted Y axis to show/hide necessary info
- reduced some looped actions
- added conditions for the first leg
- all boats start in 'last' place

#story[876]
main
Jessica McAuslin 9 years ago
parent eba2eb3cd6
commit 3f2ad8886e

@ -7,18 +7,14 @@ import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis; import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart; import javafx.scene.chart.XYChart;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import seng302.Mock.StreamedRace; import seng302.Mock.StreamedRace;
import seng302.Model.*; import seng302.Model.*;
import seng302.VisualiserInput; import seng302.VisualiserInput;
import java.net.URL; import java.net.URL;
import java.util.*; import java.util.*;
import java.util.List;
/** /**
* Created by fwy13 on 15/03/2017. * Created by fwy13 on 15/03/2017.
@ -88,7 +84,6 @@ public class RaceController extends Controller {
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
//createSparkLine();
//listener for fps //listener for fps
startBoats = new ArrayList<>(); startBoats = new ArrayList<>();
showFPS.selectedProperty().addListener((ov, old_val, new_val) -> { showFPS.selectedProperty().addListener((ov, old_val, new_val) -> {
@ -101,39 +96,51 @@ public class RaceController extends Controller {
} }
public void createSparkLine(ObservableList<Boat> boats){ public void createSparkLine(ObservableList<Boat> boats){
// TODO replace for loop with boatsInRace // NOTE: Y axis is in negatives to display correct positions
//int [] boats = {1, 2, 3, 4, 5, 6};
// set a line for each boat
makeColours(); makeColours();
startBoats.addAll(boats); startBoats.addAll(boats);
mapBoatColours(); mapBoatColours();
// all boats start in 'last' place
for (int i=0; i<startBoats.size(); i++){ for (int i=0; i<startBoats.size(); i++){
Float startPos = ((float)startBoats.size()+1)/2;
XYChart.Series<Number, Number> series = new XYChart.Series(); XYChart.Series<Number, Number> series = new XYChart.Series();
series.getData().add(new XYChart.Data(0, i + 1)); series.getData().add(new XYChart.Data(0, -startBoats.size()));
series.getData().add(new XYChart.Data(0, -startBoats.size()));
sparklineChart.getData().add(series); sparklineChart.getData().add(series);
sparklineChart.getData().get(i).getNode().setStyle("-fx-stroke: " +
""+boatColours.get(startBoats.get(i).getSourceID())+";");
} }
// reverse Y axis order (0 at top) and set axis height/width
// TODO change lower bound to boatsInRace + 1
yAxis.setLowerBound(startBoats.size()+1);
yAxis.setUpperBound(0);
yAxis.setAutoRanging(false);
xAxis.setAutoRanging(false);
sparklineChart.setCreateSymbols(false); sparklineChart.setCreateSymbols(false);
// hide axis ticks and labels // set x axis details
sparklineChart.getXAxis().setTickLabelsVisible(false); xAxis.setAutoRanging(false);
sparklineChart.getYAxis().setTickLabelsVisible(false); xAxis.setTickMarkVisible(false);
sparklineChart.getXAxis().setTickMarkVisible(false); xAxis.setTickLabelsVisible(false);
sparklineChart.getYAxis().setTickMarkVisible(false); xAxis.setMinorTickVisible(false);
sparklineChart.getXAxis().
lookup(".axis-minor-tick-mark").setVisible(false); // set y axis details
sparklineChart.getYAxis(). yAxis.setLowerBound(-(startBoats.size()+1));
lookup(".axis-minor-tick-mark").setVisible(false); yAxis.setUpperBound(0);
yAxis.setAutoRanging(false);
updateSparkline(boats); yAxis.setLabel("Position in Race");
yAxis.setTickUnit(1);
yAxis.setTickMarkVisible(false);
yAxis.setMinorTickVisible(false);
// hide minus number from displaying on axis
yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis) {
@Override
public String toString(Number value) {
if ((Double)value == 0.0
|| (Double)value < -startBoats.size()){
return "";
}
else {
return String.format("%7.0f", -value.doubleValue());
}
}
});
} }
/** /**
@ -215,24 +222,44 @@ public class RaceController extends Controller {
} }
public void updateSparkline(ObservableList<Boat> boatsInRace){ public void updateSparkline(ObservableList<Boat> boatsInRace){
System.out.println(sparklineChart.getData().size());
// TODO replace for loops with correct boats - Done
//int [] startingBoats = {1, 2, 3, 4, 5, 6};
//int [] boatsInRace = {1, 2, 3, 4, 5, 6};
int placingVal = boatsInRace.size(); int placingVal = boatsInRace.size();
//System.out.println(boatsInRace.get(0).toString());
sparkLineNumber++; sparkLineNumber++;
for (int i = boatsInRace.size() - 1; i >= 0; i--){ for (int i = boatsInRace.size() - 1; i >= 0; i--){
for (int j = startBoats.size() - 1; j >= 0; j--){ for (int j = startBoats.size() - 1; j >= 0; j--){
if (boatsInRace.get(i)==startBoats.get(j)){ if (boatsInRace.get(i)==startBoats.get(j)){
sparklineChart.getData().get(j).getData().add(new XYChart.Data<>
(sparkLineNumber, placingVal)); // when a boat is on its first leg
sparklineChart.getData().get(j).getNode().setStyle("-fx-stroke: "+boatColours.get(boatsInRace.get(i).getSourceID())+";"); if (boatsInRace.get(i).getCurrentLeg().getLegNumber()==0){
// adjust boats latest point on X axis
sparklineChart.getData().get(j).getData().get(1)
.setXValue(sparkLineNumber);
}
// when a boat first enters its second leg
else if (boatsInRace.get(i).getCurrentLeg().getLegNumber
()==1 && sparklineChart.getData().get(j).getData
().size()==2){
// adjust boats position from start mark
sparklineChart.getData().get(j).getData().get(1)
.setYValue(-placingVal);
sparklineChart.getData().get(j).getData().get(1)
.setXValue(sparkLineNumber);
sparklineChart.getData().get(j).getData().add(new XYChart.Data<>
(sparkLineNumber, -placingVal));
}
// plot new point for boats current position
else {
sparklineChart.getData().get(j).getData().add
(new XYChart.Data<>(sparkLineNumber, -placingVal));
}
placingVal-=1; placingVal-=1;
} }
} }
} }
xAxis.setUpperBound(sparkLineNumber); xAxis.setUpperBound(sparkLineNumber);
xAxis.setTickUnit(sparkLineNumber);
} }
private void makeColours() { private void makeColours() {

Loading…
Cancel
Save