StatDisplayUtils { public static LineChart<String, Number> buildLineChart(Stats stats, final Region root) { final CategoryAxis xAxis = new CategoryAxis(); final NumberAxis yAxis = new NumberAxis(); LineChart<String, Number> lineChart = new LineChart<>(xAxis, yAxis); Series<String, Number> series = new Series<>(); Series<String, Number> average = new Series<>(); Series<String, Number> sdp = new Series<>(); Series<String, Number> sdm = new Series<>(); final List<Long> shots; if (stats instanceof ShootGamesStats) { shots = stats.getSortedDurationsBetweenGoals(); } else { shots = stats.getOriginalDurationsBetweenGoals(); } double sd = stats.computeRoundsDurationStandardDeviation(); String xValue = "0"; average.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration())); sdp.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() + sd)); sdm.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() - sd)); int i = 1; for (Long duration : shots) { xValue = Integer.toString(i); series.getData().add(new Data<>(xValue, duration)); average.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration())); sdp.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() + sd)); sdm.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() - sd)); i++; } xValue = Integer.toString(i); average.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration())); sdp.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() + sd)); sdm.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() - sd)); lineChart.setCreateSymbols(false); lineChart.getData().add(average); lineChart.getData().add(sdp); lineChart.getData().add(sdm); lineChart.getData().add(series); series.getNode().setStyle("-fx-stroke-width: 3; -fx-stroke: red; -fx-stroke-dash-offset:5;"); average.getNode().setStyle("-fx-stroke-width: 1; -fx-stroke: lightgreen;"); sdp.getNode().setStyle("-fx-stroke-width: 1; -fx-stroke: grey;"); sdm.getNode().setStyle("-fx-stroke-width: 1; -fx-stroke: grey;"); EventHandler<Event> openLineChartEvent = createZoomInLineChartEventHandler(lineChart, root); lineChart.addEventHandler(MouseEvent.MOUSE_CLICKED, openLineChartEvent); lineChart.setLegendVisible(false); root.widthProperty().addListener((observable, oldValue, newValue) -> lineChart.setMaxWidth(newValue.doubleValue() * 0.4)); root.heightProperty().addListener((observable, oldValue, newValue) -> lineChart.setMaxHeight(newValue.doubleValue() * 0.4)); lineChart.setMaxWidth(root.getWidth() * 0.4); lineChart.setMaxHeight(root.getHeight() * 0.4); return lineChart; }  static HomeButton createHomeButtonInStatsScreen(GazePlay gazePlay, StatsContext statsContext); static LineChart<String, Number> buildLineChart(Stats stats, final Region root); static AreaChart<Number, Number> buildAreaChart(LinkedList<FixationPoint> points, final Region root); static ImageView buildGazeMetrics(Stats stats, final Region root); static String convert(long totalTime);  }
@Test void shouldBuildLineChartForNormalGame() { final List<Long> mockShots = new ArrayList<>(List.of(1L, 2L, 3L)); when(mockStats.getOriginalDurationsBetweenGoals()).thenReturn(mockShots); when(mockStats.computeRoundsDurationStandardDeviation()).thenReturn(0d); when(mockStats.computeRoundsDurationAverageDuration()).thenReturn(2L); final LineChart<String, Number> lineChart = StatDisplayUtils.buildLineChart(mockStats, mockRegion); assertEquals(4, lineChart.getData().size()); assertEquals(5, lineChart.getData().get(0).getData().size()); assertEquals(5, lineChart.getData().get(1).getData().size()); assertEquals(5, lineChart.getData().get(2).getData().size()); assertEquals(3, lineChart.getData().get(3).getData().size()); }
@Test void shouldZoomInToLineChart() { final List<Long> mockShots = new ArrayList<>(List.of(1L, 2L, 3L)); when(mockStats.getOriginalDurationsBetweenGoals()).thenReturn(mockShots); when(mockStats.computeRoundsDurationStandardDeviation()).thenReturn(0d); when(mockStats.computeRoundsDurationAverageDuration()).thenReturn(2L); final LineChart<String, Number> lineChart = StatDisplayUtils.buildLineChart(mockStats, mockRegion); final VBox parent = new VBox(); parent.getChildren().add(lineChart); lineChart.fireEvent(mouseClickEvent(lineChart)); assertEquals(0, lineChart.getTranslateX()); assertEquals(0, lineChart.getTranslateY()); }
@Test void shouldZoomOutOfLineChart() { final List<Long> mockShots = new ArrayList<>(List.of(1L, 2L, 3L)); when(mockStats.getOriginalDurationsBetweenGoals()).thenReturn(mockShots); when(mockStats.computeRoundsDurationStandardDeviation()).thenReturn(0d); when(mockStats.computeRoundsDurationAverageDuration()).thenReturn(2L); final LineChart<String, Number> lineChart = StatDisplayUtils.buildLineChart(mockStats, mockRegion); final VBox parent = new VBox(); parent.getChildren().add(lineChart); lineChart.fireEvent(mouseClickEvent(lineChart)); lineChart.fireEvent(mouseClickEvent(lineChart)); assertEquals(1, lineChart.getScaleX()); assertEquals(1, lineChart.getScaleY()); }
@Test void shouldBuildLineChartForShootingGame() { final List<Long> mockShots = new ArrayList<>(List.of(1L, 2L, 3L)); when(mockShootStats.getSortedDurationsBetweenGoals()).thenReturn(mockShots); when(mockShootStats.computeRoundsDurationStandardDeviation()).thenReturn(0d); when(mockShootStats.computeRoundsDurationAverageDuration()).thenReturn(2L); final LineChart<String, Number> lineChart = StatDisplayUtils.buildLineChart(mockShootStats, mockRegion); assertEquals(4, lineChart.getData().size()); assertEquals(5, lineChart.getData().get(0).getData().size()); assertEquals(5, lineChart.getData().get(1).getData().size()); assertEquals(5, lineChart.getData().get(2).getData().size()); assertEquals(3, lineChart.getData().get(3).getData().size()); }