diff --git a/visualiser/src/main/java/seng302/Controllers/RaceController.java b/visualiser/src/main/java/seng302/Controllers/RaceController.java index 2ec5784d..61a2e6b0 100644 --- a/visualiser/src/main/java/seng302/Controllers/RaceController.java +++ b/visualiser/src/main/java/seng302/Controllers/RaceController.java @@ -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 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(); + + // all boats start in 'last' place for (int i=0; i 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().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); - // 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); - - updateSparkline(boats); + // set x axis details + xAxis.setAutoRanging(false); + xAxis.setTickMarkVisible(false); + xAxis.setTickLabelsVisible(false); + xAxis.setMinorTickVisible(false); + + // 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 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() {