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