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. //Change the StreamReceiver in this else block to change the default data source.
else{ else{
//sr = new StreamReceiver("localhost", 4949, "RaceStream"); //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(); sr.start();
@@ -1,5 +1,6 @@
package seng302.controllers; package seng302.controllers;
import java.util.concurrent.ConcurrentLinkedQueue;
import javafx.animation.KeyFrame; import javafx.animation.KeyFrame;
import javafx.animation.Timeline; import javafx.animation.Timeline;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
@@ -7,6 +8,10 @@ import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; 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.Button;
import javafx.scene.control.CheckBox; import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox; import javafx.scene.control.ComboBox;
@@ -36,6 +41,8 @@ import java.util.*;
*/ */
public class RaceViewController extends Thread implements ImportantAnnotationDelegate { public class RaceViewController extends Thread implements ImportantAnnotationDelegate {
public LineChart raceSparkLine;
@FXML @FXML
private VBox positionVbox; private VBox positionVbox;
@FXML @FXML
@@ -61,6 +68,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
private Race race; private Race race;
private Stage stage; private Stage stage;
private int index = 0;
private ImportantAnnotationsState importantAnnotations; private ImportantAnnotationsState importantAnnotations;
private Yacht selectedBoat; private Yacht selectedBoat;
@@ -82,7 +91,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
initialiseAnnotationSlider(); initialiseAnnotationSlider();
initialiseBoatSelectionComboBox(); initialiseBoatSelectionComboBox();
includedCanvasController.timer.start(); includedCanvasController.timer.start();
initializeSparkline();
selectAnnotationBtn.setOnAction(event -> { selectAnnotationBtn.setOnAction(event -> {
loadSelectAnnotationView(); loadSelectAnnotationView();
}); });
@@ -173,6 +182,16 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
annotationSlider.setValue(2); 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 * Initalises a timer which updates elements of the RaceView such as wind direction, boat
+32
View File
@@ -1,5 +1,9 @@
package seng302.models; 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 javafx.scene.paint.Color;
import java.text.DateFormat; import java.text.DateFormat;
@@ -16,6 +20,9 @@ public class Yacht {
private Color colour; private Color colour;
private double velocity; private double velocity;
private int index;
private ConcurrentLinkedQueue<Number> dataQ1;
private String boatType; private String boatType;
private Integer sourceID; private Integer sourceID;
private String hullID; //matches HullNum in the XML spec. private String hullID; //matches HullNum in the XML spec.
@@ -33,6 +40,9 @@ public class Yacht {
// Mark rounding // Mark rounding
private Long markRoundingTime; private Long markRoundingTime;
// Used for sparkline
private XYChart.Series<Number, Number> sparklinePosition;
/** /**
* Used in EventTest and RaceTest. * Used in EventTest and RaceTest.
* *
@@ -54,6 +64,11 @@ public class Yacht {
this.velocity = boatVelocity; this.velocity = boatVelocity;
this.shortName = shortName; this.shortName = shortName;
this.sourceID = id; 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) { 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.shortName = shortName;
this.boatName = boatName; this.boatName = boatName;
this.country = country; this.country = country;
this.sparklinePosition = new XYChart.Series<>();
this.sparklinePosition.setName(boatName);
index = 0;
dataQ1 = new ConcurrentLinkedQueue<>();
} }
public String getBoatType() { public String getBoatType() {
@@ -140,6 +159,15 @@ public class Yacht {
} }
public void setPosition(String position) { 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; this.position = position;
} }
@@ -167,6 +195,10 @@ public class Yacht {
this.markRoundingTime = markRoundingTime; this.markRoundingTime = markRoundingTime;
} }
public Series<Number, Number> getSparklinePosition() {
return sparklinePosition;
}
@Override @Override
public String toString() { public String toString() {
return boatName; return boatName;
+6 -6
View File
@@ -62,7 +62,12 @@
<Button fx:id="selectAnnotationBtn" layoutX="35.0" layoutY="578.0" mnemonicParsing="false" prefHeight="18.0" prefWidth="170.0" styleClass="blue-ui-btn" text="Select Annotations" textFill="WHITE" /> <Button fx:id="selectAnnotationBtn" layoutX="35.0" layoutY="578.0" mnemonicParsing="false" prefHeight="18.0" prefWidth="170.0" styleClass="blue-ui-btn" text="Select Annotations" textFill="WHITE" />
<Text fill="WHITE" layoutX="11.0" layoutY="649.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Boat Selection" /> <Text fill="WHITE" layoutX="11.0" layoutY="649.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Boat Selection" />
<ComboBox fx:id="boatSelectionComboBox" layoutX="37.0" layoutY="664.0" prefHeight="25.0" prefWidth="170.0" promptText="Select Boat" styleClass="combo-box-base" /> <ComboBox fx:id="boatSelectionComboBox" layoutX="37.0" layoutY="664.0" prefHeight="25.0" prefWidth="170.0" promptText="Select Boat" styleClass="combo-box-base" />
<LineChart fx:id="raceSparkLine" layoutX="12.0" layoutY="790.0" prefHeight="188.0" prefWidth="217.0"> </children>
</AnchorPane>
<AnchorPane fx:id="contentAnchorPane" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: skyblue;" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowSpan="2147483647" GridPane.valignment="TOP">
<children>
<fx:include fx:id="includedCanvas" source="CanvasView.fxml" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<LineChart fx:id="raceSparkLine" layoutX="43.0" layoutY="597.0" prefHeight="277.0" prefWidth="727.0">
<xAxis> <xAxis>
<CategoryAxis side="BOTTOM" /> <CategoryAxis side="BOTTOM" />
</xAxis> </xAxis>
@@ -70,11 +75,6 @@
<NumberAxis side="LEFT" tickLabelGap="1.0" upperBound="6.0" /> <NumberAxis side="LEFT" tickLabelGap="1.0" upperBound="6.0" />
</yAxis> </yAxis>
</LineChart> </LineChart>
</children>
</AnchorPane>
<AnchorPane fx:id="contentAnchorPane" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: skyblue;" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowSpan="2147483647" GridPane.valignment="TOP">
<children>
<fx:include fx:id="includedCanvas" source="CanvasView.fxml" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children></AnchorPane> </children></AnchorPane>
</children> </children>
</GridPane> </GridPane>