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]
This commit is contained in:
@@ -7,18 +7,14 @@ import javafx.scene.chart.LineChart;
|
||||
import javafx.scene.chart.NumberAxis;
|
||||
import javafx.scene.chart.XYChart;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import seng302.Mock.StreamedRace;
|
||||
import seng302.Model.*;
|
||||
import seng302.VisualiserInput;
|
||||
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 15/03/2017.
|
||||
@@ -88,7 +84,6 @@ public class RaceController extends Controller {
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
//createSparkLine();
|
||||
//listener for fps
|
||||
startBoats = new ArrayList<>();
|
||||
showFPS.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
@@ -101,39 +96,51 @@ public class RaceController extends Controller {
|
||||
}
|
||||
|
||||
public void createSparkLine(ObservableList<Boat> boats){
|
||||
// TODO replace for loop with boatsInRace
|
||||
//int [] boats = {1, 2, 3, 4, 5, 6};
|
||||
// set a line for each boat
|
||||
// NOTE: Y axis is in negatives to display correct positions
|
||||
|
||||
makeColours();
|
||||
startBoats.addAll(boats);
|
||||
mapBoatColours();
|
||||
for (int i=0; i<startBoats.size(); i++){
|
||||
Float startPos = ((float)startBoats.size()+1)/2;
|
||||
XYChart.Series<Number, Number> series = new XYChart.Series();
|
||||
series.getData().add(new XYChart.Data(0, i + 1));
|
||||
sparklineChart.getData().add(series);
|
||||
}
|
||||
|
||||
// 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);
|
||||
// all boats start in 'last' place
|
||||
for (int i=0; i<startBoats.size(); i++){
|
||||
XYChart.Series<Number, Number> series = new XYChart.Series();
|
||||
series.getData().add(new XYChart.Data(0, -startBoats.size()));
|
||||
series.getData().add(new XYChart.Data(0, -startBoats.size()));
|
||||
sparklineChart.getData().add(series);
|
||||
sparklineChart.getData().get(i).getNode().setStyle("-fx-stroke: " +
|
||||
""+boatColours.get(startBoats.get(i).getSourceID())+";");
|
||||
}
|
||||
|
||||
sparklineChart.setCreateSymbols(false);
|
||||
|
||||
// hide axis ticks and labels
|
||||
sparklineChart.getXAxis().setTickLabelsVisible(false);
|
||||
sparklineChart.getYAxis().setTickLabelsVisible(false);
|
||||
sparklineChart.getXAxis().setTickMarkVisible(false);
|
||||
sparklineChart.getYAxis().setTickMarkVisible(false);
|
||||
sparklineChart.getXAxis().
|
||||
lookup(".axis-minor-tick-mark").setVisible(false);
|
||||
sparklineChart.getYAxis().
|
||||
lookup(".axis-minor-tick-mark").setVisible(false);
|
||||
// set x axis details
|
||||
xAxis.setAutoRanging(false);
|
||||
xAxis.setTickMarkVisible(false);
|
||||
xAxis.setTickLabelsVisible(false);
|
||||
xAxis.setMinorTickVisible(false);
|
||||
|
||||
updateSparkline(boats);
|
||||
// set y axis details
|
||||
yAxis.setLowerBound(-(startBoats.size()+1));
|
||||
yAxis.setUpperBound(0);
|
||||
yAxis.setAutoRanging(false);
|
||||
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){
|
||||
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();
|
||||
//System.out.println(boatsInRace.get(0).toString());
|
||||
sparkLineNumber++;
|
||||
|
||||
for (int i = boatsInRace.size() - 1; i >= 0; i--){
|
||||
for (int j = startBoats.size() - 1; j >= 0; j--){
|
||||
if (boatsInRace.get(i)==startBoats.get(j)){
|
||||
sparklineChart.getData().get(j).getData().add(new XYChart.Data<>
|
||||
(sparkLineNumber, placingVal));
|
||||
sparklineChart.getData().get(j).getNode().setStyle("-fx-stroke: "+boatColours.get(boatsInRace.get(i).getSourceID())+";");
|
||||
|
||||
// when a boat is on its first leg
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
xAxis.setUpperBound(sparkLineNumber);
|
||||
xAxis.setTickUnit(sparkLineNumber);
|
||||
}
|
||||
|
||||
private void makeColours() {
|
||||
|
||||
Reference in New Issue
Block a user