Implemented functionality for sparkline to update throughout race.
-Sparkline reads in initial boats in race. -Sparkline updates throughout the race. -Sparkline updates are displayed on GUI. #story[876]
This commit is contained in:
@@ -11,7 +11,8 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
//import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 10/05/17.
|
||||
|
||||
@@ -3,8 +3,9 @@ package seng302.Model;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
//import static org.testng.AssertJUnit.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 29/03/17.
|
||||
|
||||
@@ -24,7 +24,7 @@ public class RaceController extends Controller {
|
||||
|
||||
//user saved data for annotation display
|
||||
private ArrayList<Boolean> presetAnno;
|
||||
|
||||
private ArrayList<Boat> startBoats;
|
||||
private Integer sparkLineNumber = 0;
|
||||
private ResizableRaceCanvas raceMap;
|
||||
private ResizableRaceMap raceBoundaries;
|
||||
@@ -82,8 +82,9 @@ public class RaceController extends Controller {
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
createSparkLine();
|
||||
//createSparkLine();
|
||||
//listener for fps
|
||||
startBoats = new ArrayList<>();
|
||||
showFPS.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (showFPS.isSelected()) {
|
||||
FPS.setVisible(true);
|
||||
@@ -93,11 +94,14 @@ public class RaceController extends Controller {
|
||||
});
|
||||
}
|
||||
|
||||
private void createSparkLine(){
|
||||
public void createSparkLine(ObservableList<Boat> boats){
|
||||
// TODO replace for loop with boatsInRace
|
||||
int [] boats = {1, 2, 3, 4, 5, 6};
|
||||
//int [] boats = {1, 2, 3, 4, 5, 6};
|
||||
// set a line for each boat
|
||||
for (int i=0; i<boats.length; i++){
|
||||
for (Boat boat : boats){
|
||||
startBoats.add(boat);
|
||||
}
|
||||
for (int i=0; i<startBoats.size(); i++){
|
||||
XYChart.Series<Number, Number> series = new XYChart.Series();
|
||||
series.getData().add(new XYChart.Data(0, i+1));
|
||||
sparklineChart.getData().add(series);
|
||||
@@ -105,7 +109,7 @@ public class RaceController extends Controller {
|
||||
|
||||
// reverse Y axis order (0 at top) and set axis height/width
|
||||
// TODO change lower bound to boatsInRace + 1
|
||||
yAxis.setLowerBound(boats.length+1);
|
||||
yAxis.setLowerBound(startBoats.size()+1);
|
||||
yAxis.setUpperBound(0);
|
||||
yAxis.setAutoRanging(false);
|
||||
xAxis.setAutoRanging(false);
|
||||
@@ -199,18 +203,20 @@ public class RaceController extends Controller {
|
||||
});
|
||||
}
|
||||
|
||||
public void updateSparkline(){
|
||||
// TODO replace for loops with correct boats
|
||||
int [] startingBoats = {1, 2, 3, 4, 5, 6};
|
||||
int [] boatsInRace = {1, 2, 3, 4, 5, 6};
|
||||
|
||||
sparkLineNumber ++;
|
||||
for (int i=0; i<startingBoats.length; i++){
|
||||
for (int j=0; j<boatsInRace.length; j++){
|
||||
// TODO if startingBoat[i] == boatsInRace[j]
|
||||
if (i==j){
|
||||
sparklineChart.getData().get(i).getData().add(new XYChart.Data<>
|
||||
(sparkLineNumber, j+1));
|
||||
public void updateSparkline(ObservableList<Boat> boatsInRace){
|
||||
// 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());
|
||||
System.out.println(startBoats.get(0).toString());
|
||||
sparkLineNumber++;
|
||||
for (int i=0; i<boatsInRace.size(); i++){
|
||||
for (int j=0; j<startBoats.size(); j++){
|
||||
if (boatsInRace.get(i)==startBoats.get(j)){
|
||||
sparklineChart.getData().get(j).getData().add(new XYChart.Data<>
|
||||
(sparkLineNumber, placingVal));
|
||||
placingVal-=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,6 +153,7 @@ public class StreamedRace implements Runnable {
|
||||
*/
|
||||
public void run() {
|
||||
setControllerListeners();
|
||||
Platform.runLater(() -> controller.createSparkLine(startingBoats));
|
||||
initialiseBoats();
|
||||
startRaceStream();
|
||||
}
|
||||
@@ -189,7 +190,7 @@ public class StreamedRace implements Runnable {
|
||||
public void handle(long arg0) {
|
||||
if (boatsFinished < startingBoats.size()) {
|
||||
boatsFinished = 0;
|
||||
controller.updateSparkline();
|
||||
controller.updateSparkline(startingBoats);
|
||||
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
||||
|
||||
for (Boat boat : startingBoats) {
|
||||
@@ -207,6 +208,7 @@ public class StreamedRace implements Runnable {
|
||||
}
|
||||
}
|
||||
//System.out.println(boatsFinished + ":" + startingBoats.size());
|
||||
|
||||
} else {
|
||||
controller.finishRace(startingBoats);
|
||||
stop();
|
||||
|
||||
Reference in New Issue
Block a user