Adding race yacht series to the sparkline.

Next step is to make the series of the boats update when new position information is received.

#story[952]
This commit is contained in:
Kusal Ekanayake
2017-05-18 14:44:10 +12:00
parent b87008f590
commit 390aabc78f
4 changed files with 60 additions and 8 deletions
+2 -1
View File
@@ -63,7 +63,8 @@ public class App extends Application {
//Change the StreamReceiver in this else block to change the default data source.
else{
//sr = new StreamReceiver("localhost", 4949, "RaceStream");
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream");
// sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
}
sr.start();
@@ -1,5 +1,6 @@
package seng302.controllers;
import java.util.concurrent.ConcurrentLinkedQueue;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.collections.FXCollections;
@@ -7,6 +8,10 @@ import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
@@ -36,6 +41,8 @@ import java.util.*;
*/
public class RaceViewController extends Thread implements ImportantAnnotationDelegate {
public LineChart raceSparkLine;
@FXML
private VBox positionVbox;
@FXML
@@ -61,6 +68,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
private Race race;
private Stage stage;
private int index = 0;
private ImportantAnnotationsState importantAnnotations;
private Yacht selectedBoat;
@@ -82,7 +91,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
initialiseAnnotationSlider();
initialiseBoatSelectionComboBox();
includedCanvasController.timer.start();
initializeSparkline();
selectAnnotationBtn.setOnAction(event -> {
loadSelectAnnotationView();
});
@@ -173,6 +182,16 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
annotationSlider.setValue(2);
}
private void initializeSparkline(){
raceSparkLine.setTitle("Boat Positions");
for (Yacht yacht: startingBoats){
if (raceSparkLine.getData().contains(yacht.getSparklinePosition())) {
raceSparkLine.getData().remove(yacht.getSparklinePosition());
}
raceSparkLine.getData().add(yacht.getSparklinePosition());
System.out.println("Here");
}
}
/**
* Initalises a timer which updates elements of the RaceView such as wind direction, boat
+32
View File
@@ -1,5 +1,9 @@
package seng302.models;
import java.util.concurrent.ConcurrentLinkedQueue;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.paint.Color;
import java.text.DateFormat;
@@ -16,6 +20,9 @@ public class Yacht {
private Color colour;
private double velocity;
private int index;
private ConcurrentLinkedQueue<Number> dataQ1;
private String boatType;
private Integer sourceID;
private String hullID; //matches HullNum in the XML spec.
@@ -33,6 +40,9 @@ public class Yacht {
// Mark rounding
private Long markRoundingTime;
// Used for sparkline
private XYChart.Series<Number, Number> sparklinePosition;
/**
* Used in EventTest and RaceTest.
*
@@ -54,6 +64,11 @@ public class Yacht {
this.velocity = boatVelocity;
this.shortName = shortName;
this.sourceID = id;
this.sparklinePosition = new XYChart.Series<>();
this.sparklinePosition.setName(boatName);
index = 0;
dataQ1 = new ConcurrentLinkedQueue<>();
}
public Yacht(String boatType, Integer sourceID, String hullID, String shortName, String boatName, String country) {
@@ -63,6 +78,10 @@ public class Yacht {
this.shortName = shortName;
this.boatName = boatName;
this.country = country;
this.sparklinePosition = new XYChart.Series<>();
this.sparklinePosition.setName(boatName);
index = 0;
dataQ1 = new ConcurrentLinkedQueue<>();
}
public String getBoatType() {
@@ -140,6 +159,15 @@ public class Yacht {
}
public void setPosition(String position) {
try {
if (Integer.parseInt(position) != Integer.parseInt(this.position)){
dataQ1.add(Integer.parseInt(position));
sparklinePosition.getData().add(new XYChart.Data<>(index++, dataQ1.remove()));
System.out.println("new position found for " + boatName + " in position " + position + " old(" + this.position + ")");
}
} catch (NumberFormatException e) {
System.out.println("No position found");
}
this.position = position;
}
@@ -167,6 +195,10 @@ public class Yacht {
this.markRoundingTime = markRoundingTime;
}
public Series<Number, Number> getSparklinePosition() {
return sparklinePosition;
}
@Override
public String toString() {
return boatName;