Skip to content

Commit

Permalink
JavaFX Charts working now
Browse files Browse the repository at this point in the history
fixed some bugs

Signed-off-by: vstarlinger <valentin@starlinger.net>
  • Loading branch information
vstarlinger committed Aug 21, 2017
1 parent a863e3b commit 93db42f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 68 deletions.
Expand Up @@ -61,7 +61,7 @@ Used conventions:
datatype="FLOAT32" numpoints="1" frequency="1" unit="0.1mbar" isLittleEndian="TRUE"/>
</sensor>
<sensor type="TIMER" name="GNSS TIME">
<var start="2519" datatype="UINT32" numpoints="1" frequency="1" unit="HHMMSSCC" isLittleEndian="TRUE"/>
<var start="2519" dataname="GNSS Time" datatype="UINT32" numpoints="1" frequency="1" unit="HHMMSSCC" isLittleEndian="TRUE"/>
</sensor>
<sensor type="TEMPERATURE" name="Thermocouple_Iridium">
<var dataname="Thermocouple_Iridium" start="2551" datatype="INT16" numpoints="1" frequency="1" unit="°C" isLittleEndian="TRUE"/>
Expand Down
@@ -1,120 +1,131 @@
package com.ksatstuttgart.usoc.gui.controller;
package com.ksatstuttgart.usoc.gui.controller;

import com.ksatstuttgart.usoc.controller.DataModification;
import java.net.URL;
import java.net.URL;
import com.ksatstuttgart.usoc.controller.MainController;
import com.ksatstuttgart.usoc.controller.MessageController;
import com.ksatstuttgart.usoc.data.ErrorEvent;
import com.ksatstuttgart.usoc.data.USOCEvent;
import com.ksatstuttgart.usoc.data.message.Var;
import com.ksatstuttgart.usoc.data.message.dataPackage.Sensor;
import java.util.Map;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.XYChart;
/**
*
* @author Victor
*/

public class MainPanelController extends DataController implements Initializable {

public LineChart<Long, Object> lineChart1;
public XYChart.Series series1;
public LineChart<Long, Object> lineChart2;
public XYChart.Series series2;
public LineChart<Long, Object> lineChart3;
public XYChart.Series series3;
public LineChart<Long, Object> lineChart4;
public XYChart.Series series4;
public LineChart<Long, Object> lineChart5;
public XYChart.Series series5;
public LineChart<Long, Object> lineChart6;
public XYChart.Series series6;


/**
*
* @author Victor
*/

public class MainPanelController extends DataController implements Initializable {

@FXML
public LineChart<Number, Number> lineChart1;
@FXML
public LineChart<Number, Number> lineChart2;
@FXML
public LineChart<Number, Number> lineChart3;
@FXML
public LineChart<Number, Number> lineChart4;
@FXML
public LineChart<Number, Number> lineChart5;
@FXML
public LineChart<Number, Number> lineChart6;

@Override
public void updateData(MessageController mc, USOCEvent e) {

lineChart1.getXAxis().setAutoRanging(true);
lineChart1.getXAxis().setAutoRanging(true);
lineChart1.getYAxis().setAutoRanging(true);
lineChart2.getXAxis().setAutoRanging(true);
lineChart2.getYAxis().setAutoRanging(true);
lineChart3.getXAxis().setAutoRanging(true);
lineChart3.getYAxis().setAutoRanging(true);
lineChart4.getXAxis().setAutoRanging(true);
lineChart2.getXAxis().setAutoRanging(true);
lineChart2.getYAxis().setAutoRanging(true);
lineChart3.getXAxis().setAutoRanging(true);
lineChart3.getYAxis().setAutoRanging(true);
lineChart4.getXAxis().setAutoRanging(true);
lineChart4.getYAxis().setAutoRanging(true);
lineChart5.getXAxis().setAutoRanging(true);
lineChart5.getYAxis().setAutoRanging(true);

lineChart5.getXAxis().setAutoRanging(true);
lineChart5.getYAxis().setAutoRanging(true);


//in case this is an error event, ignore it
if(e instanceof ErrorEvent){
if (e instanceof ErrorEvent) {
return;
}

//go through the data and update the charts
for (Sensor sensor : mc.getData().getSensors()) {
//adjust values for the sensor specific to the current experiment
Sensor adjusted = DataModification.adjustSensorData(sensor);

//search for thermocouple sensors
if (adjusted.getSensorName().startsWith("Thermocouple")) {
//thermocouple sensors have only one variable with the current
//data scheme it uses the sensor name as variable name
//TODO: this needs to be fixed
Map.Entry<Long, Object> entry = adjusted.getVars().get(0).getValues().lastEntry();
series1.getData().add(new XYChart.Data(entry.getKey(), entry.getValue()));
lineChart1.getData().add(series1);
for (Var var : adjusted.getVars()) {
addVarToChart(var,lineChart1);
}
}

//search for pressure sensors
if (adjusted.getSensorName().contains("Pressure")) {
//pressure sensors have only one variable with the current
//data scheme and it uses the sensor name as variable name
//TODO: this needs to be fixed
Map.Entry<Long, Object> entry = adjusted.getVars().get(0).getValues().lastEntry();
series2.getData().add(new XYChart.Data(entry.getKey(), entry.getValue()));
lineChart2.getData().add(series2);
for (Var var : adjusted.getVars()) {
addVarToChart(var,lineChart2);
}
}

//search for pressure sensors
if (adjusted.getSensorName().contains("GNSS TIME")) {
//pressure sensors have only one variable with the current
//data scheme and it uses the sensor name as variable name
//TODO: this needs to be fixed
Map.Entry<Long, Object> entry = adjusted.getVars().get(0).getValues().lastEntry();
series3.getData().add(new XYChart.Data(entry.getKey(), entry.getValue()));
lineChart3.getData().add(series3);
for (Var var : adjusted.getVars()) {
addVarToChart(var,lineChart3);
}
}

//search for voltage sensors
if (adjusted.getSensorName().startsWith("Battery")) {
//voltage sensors have only one variable with the current
//data scheme and it uses the sensor name as variable name
//TODO: this needs to be fixed
Map.Entry<Long, Object> entry = adjusted.getVars().get(0).getValues().lastEntry();
series4.getData().add(new XYChart.Data(entry.getKey(), entry.getValue()));
lineChart4.getData().add(series4);
for (Var var : adjusted.getVars()) {
addVarToChart(var,lineChart4);
}
}

//search for IMU data
if (adjusted.getSensorName().contains("IMU")){
if (adjusted.getSensorName().contains("IMU")) {
for (Var var : adjusted.getVars()) {
//only visualize quaternion data ignore calibration data
//for chart
Map.Entry<Long, Object> entry = adjusted.getVars().get(0).getValues().lastEntry();
series5.getData().add(new XYChart.Data(entry.getKey(), entry.getValue()));
lineChart5.getData().add(series5);
addVarToChart(var,lineChart5);
}
}
}
}

@Override
public void initialize(URL url, ResourceBundle rb) {
private void addVarToChart(Var var, LineChart<Number, Number> chart) {
XYChart.Series series = getSeriesForChart(var, chart);
for (Long time : var.getValues().keySet()) {
series.getData().add(new XYChart.Data<>(time, var.getValues().get(time)));
}
}

private XYChart.Series getSeriesForChart(Var var, LineChart<Number, Number> chart) {
for (XYChart.Series<Number, Number> series : chart.getData()) {
if (series.getName().equals(var.getDataName())) {
return series;
}
}
XYChart.Series series = new XYChart.Series<>();
series.setName(var.getDataName());
chart.getData().add(series);
return series;
}

@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
MainController.getInstance().addDataUpdateListener(new UpdateListener());
//setData();
Expand Down
Expand Up @@ -16,47 +16,47 @@
<children>
<LineChart fx:id="lineChart1" title="Chart 1" GridPane.columnIndex="0" GridPane.rowIndex="0">
<xAxis>
<CategoryAxis label="Time [s]" side="BOTTOM" />
<NumberAxis label="Time [s]" side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis label="Current [A]" side="LEFT" />
</yAxis>
</LineChart>
<LineChart fx:id="lineChart2" title="Chart 2" GridPane.columnIndex="1" GridPane.rowIndex="0">
<xAxis>
<CategoryAxis label="Time [s]" side="BOTTOM" />
<NumberAxis label="Time [s]" side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis label="Power [W]" side="LEFT" />
</yAxis>
</LineChart>
<LineChart fx:id="lineChart3" title="Chart 3" GridPane.columnIndex="0" GridPane.rowIndex="1">
<xAxis>
<CategoryAxis label="Time [s]" side="BOTTOM" />
<NumberAxis label="Time [s]" side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis label="Height [m]" side="LEFT" />
</yAxis>
</LineChart>
<LineChart fx:id="lineChart4" title="Chart 4" GridPane.columnIndex="1" GridPane.rowIndex="1">
<xAxis>
<CategoryAxis label="Time [s]" side="BOTTOM" />
<NumberAxis label="Time [s]" side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis label="Current [A]" side="LEFT" />
</yAxis>
</LineChart>
<LineChart fx:id="lineChart5" title="Chart 5" GridPane.columnIndex="0" GridPane.rowIndex="2">
<xAxis>
<CategoryAxis label="Time [s]" side="BOTTOM" />
<NumberAxis label="Time [s]" side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis label="Power [W]" side="LEFT" />
</yAxis>
</LineChart>
<LineChart fx:id="lineChart6" title="Chart 6" GridPane.columnIndex="1" GridPane.rowIndex="2">
<xAxis>
<CategoryAxis label="Time [s]" side="BOTTOM" />
<NumberAxis label="Time [s]" side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis label="Height [m]" side="LEFT" />
Expand Down

0 comments on commit 93db42f

Please sign in to comment.