From 5de13b6c5b923cb1c432498ddde99d398f11d1de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20V=C3=A9lez=20Palacios?= Date: Wed, 18 May 2016 20:22:43 +0200 Subject: [PATCH] dashboard redesign --- .../controller/DashboardController.java | 76 ++- .../es/kauron/estraba/fxml/Dashboard.fxml | 448 +++++++++--------- .../resources/es/kauron/estraba/img/climb.png | Bin 0 -> 1932 bytes .../es/kauron/estraba/img/distance.png | Bin 822 -> 2697 bytes 4 files changed, 267 insertions(+), 257 deletions(-) create mode 100644 src/main/resources/es/kauron/estraba/img/climb.png diff --git a/src/main/java/es/kauron/estraba/controller/DashboardController.java b/src/main/java/es/kauron/estraba/controller/DashboardController.java index 90ab116..d8e058e 100644 --- a/src/main/java/es/kauron/estraba/controller/DashboardController.java +++ b/src/main/java/es/kauron/estraba/controller/DashboardController.java @@ -5,6 +5,10 @@ import com.jfoenix.controls.JFXListView; import com.jfoenix.controls.JFXSnackbar; import com.lynden.gmapsfx.GoogleMapView; import com.lynden.gmapsfx.javascript.object.GoogleMap; +import com.lynden.gmapsfx.javascript.object.LatLong; +import com.lynden.gmapsfx.javascript.object.MVCArray; +import com.lynden.gmapsfx.shapes.Polyline; +import com.lynden.gmapsfx.shapes.PolylineOptions; import es.kauron.estraba.App; import javafx.collections.ObservableList; import javafx.event.ActionEvent; @@ -98,18 +102,34 @@ public class DashboardController implements Initializable { @FXML private Tab tabSettings; - private GoogleMap map; private TrackData trackData; private JFXSnackbar snackbar; + private final double DISTANCE_EPSILON = 1; @Override public void initialize(URL location, ResourceBundle resources) { + // populate map icons ((ImageView)elevationButton.getGraphic()).setImage(new Image(App.class.getResourceAsStream("img/elevation.png"))); ((ImageView)speedButton.getGraphic()).setImage(new Image(App.class.getResourceAsStream("img/speed.png"))); ((ImageView)hrButton.getGraphic()).setImage(new Image(App.class.getResourceAsStream("img/hr.png"))); ((ImageView)cadenceButton.getGraphic()).setImage(new Image(App.class.getResourceAsStream("img/cadence.png"))); + } + + @FXML + private void onMapButton(ActionEvent event){ + System.out.println(((JFXButton)event.getSource()).getId()); + } + + public void postinit() { + snackbar = new JFXSnackbar(); + snackbar.registerSnackbarContainer(root); + try {load();} catch (JAXBException e) {e.printStackTrace();} + } + + private void loadTrack(TrackData track) { + // populate dashboard trackData.getStartTime(); trackData.getTotalDuration(); trackData.getMovingTime(); @@ -124,37 +144,45 @@ public class DashboardController implements Initializable { trackData.getMaxCadence(); trackData.getAverageCadence(); - // populate charts - ObservableList chunks = trackData.getChunks(); + // create charts data XYChart.Series elevationChartData = new XYChart.Series<>(); XYChart.Series speedChartData = new XYChart.Series<>(); XYChart.Series hrChartData = new XYChart.Series<>(); XYChart.Series cadenceChartData = new XYChart.Series<>(); - double lastDistance = Double.MIN_VALUE; - for (int i = 0; i < chunks.size(); i++) { - //map - //elevationChart (range min-max+10) - elevationChartData.getData().add(new XYChart.Data<>(chunk.getDistance(), chunk.getAscent())); - //speedChart (range 0-max+10) - speedChartData.getData().add(new XYChart.Data<>(chunk.getDistance(), chunk.getAscent())); - //hrChart (range 30-200) - //cadenceChart (range 0-200 (rollapalluza)) + MVCArray pathArray = new MVCArray(); + + ObservableList chunks = trackData.getChunks(); + double currentDistance = 0.0; + for (Chunk chunk : chunks) { + currentDistance += chunk.getDistance(); + if (chunk.getDistance() < DISTANCE_EPSILON) continue; + + pathArray.push(new LatLong(chunk.getLastPoint().getLatitude(), chunk.getLastPoint().getLongitude())); + elevationChartData.getData().add(new XYChart.Data<>(currentDistance, chunk.getAscent())); + speedChartData.getData().add(new XYChart.Data<>(currentDistance, chunk.getSpeed())); + hrChartData.getData().add(new XYChart.Data<>(currentDistance, chunk.getAvgHeartRate())); + cadenceChartData.getData().add(new XYChart.Data<>(currentDistance, chunk.getAvgCadence())); } + // populate the charts + elevationChart.getData().add(elevationChartData); + speedChart.getData().add(speedChartData); + hrChart.getData().add(hrChartData); + cadenceChart.getData().add(cadenceChartData); + + // populate and render the map + GoogleMap map = mapView.createMap(); + map.addMapShape(new Polyline( + new PolylineOptions() + .path(pathArray) + .strokeColor("red") + .strokeWeight(2)) + ); + } @FXML - private void onMapButton(ActionEvent event){ - System.out.println(((JFXButton)event.getSource()).getId()); - } - - public void postinit() { - snackbar = new JFXSnackbar(); - snackbar.registerSnackbarContainer(root); - } - - @FXML - private void load(ActionEvent event) throws JAXBException { + private void load() throws JAXBException { FileChooser fileChooser = new FileChooser(); File file = fileChooser.showOpenDialog(root.getScene().getWindow()); if (file == null) return; @@ -166,7 +194,7 @@ public class DashboardController implements Initializable { GpxType gpx = (GpxType) jaxbElement.getValue(); if (gpx != null) { - trackData = new TrackData(new Track(gpx.getTrk().get(0))); + loadTrack(new TrackData(new Track(gpx.getTrk().get(0)))); snackbar.show("GPX file: " + name + "successfully loaded", 3000); } else { snackbar.show("Error loading GPX file: " + name, 3000); diff --git a/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml b/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml index 8c707b5..ee46335 100644 --- a/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml +++ b/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml @@ -1,7 +1,6 @@ - @@ -22,106 +21,103 @@ - + - + - + + - + - + - - - - - - - - - - - - - - - - + - + - - + - + - + - + - - - - - - - - - - - - - - - + - + - + - + - - + @@ -219,51 +209,80 @@ - + - + - + - + - - - + + - + - + - + - - - + + - + - + - - - - - - - - - - - - - - - + + + + + + - - + + - - - - - - - - - - - - - - - - + @@ -399,16 +382,20 @@ - + -