StatDisplayUtils { public static AreaChart<Number, Number> buildAreaChart(LinkedList<FixationPoint> points, final Region root) { final NumberAxis xAxis = new NumberAxis(); final NumberAxis yAxis = new NumberAxis(); xAxis.setTickLabelsVisible(false); yAxis.setLabel("Coordinates"); AreaChart<Number, Number> colorBands = new AreaChart<>(xAxis, yAxis); colorBands.setTitle("Color Bands"); colorBands.setCreateSymbols(true); colorBands.setLegendVisible(true); if (points.size() > 0) { Series<Number, Number> xEyeCoordinates = new Series<>(); xEyeCoordinates.setName("X coordinate"); Series<Number, Number> yEyeCoordinates = new Series<>(); yEyeCoordinates.setName("Y coordinate"); for (FixationPoint p : points) { xEyeCoordinates.getData().add(new Data<>(p.getTimeGaze(), p.getY())); yEyeCoordinates.getData().add(new Data<>(p.getTimeGaze(), p.getX())); } colorBands.getData().addAll(xEyeCoordinates, yEyeCoordinates); EventHandler<Event> openAreaChartEvent = createZoomInAreaChartEventHandler(colorBands, root); colorBands.addEventHandler(MouseEvent.MOUSE_CLICKED, openAreaChartEvent); root.widthProperty().addListener( (observable, oldValue, newValue) -> colorBands.setMaxWidth(newValue.doubleValue() * 0.4)); root.heightProperty().addListener( (observable, oldValue, newValue) -> colorBands.setMaxHeight(newValue.doubleValue() * 0.4)); colorBands.setMaxWidth(root.getWidth() * 0.4); colorBands.setMaxHeight(root.getHeight() * 0.4); return colorBands; } else return null; }  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 shouldBuildAreaChartWithPoints() { final LinkedList<FixationPoint> mockPoints = new LinkedList<>(List.of( new FixationPoint(50, 50, 1, 2), new FixationPoint(100, 100, 2, 3), new FixationPoint(150, 150, 4, 5) )); final AreaChart<Number, Number> areaChart = StatDisplayUtils.buildAreaChart(mockPoints, mockRegion); assertEquals(2, areaChart.getData().size()); assertEquals(3, areaChart.getData().get(0).getData().size()); assertEquals("X coordinate", areaChart.getData().get(0).getName()); assertEquals(3, areaChart.getData().get(1).getData().size()); assertEquals("Y coordinate", areaChart.getData().get(1).getName()); }
@Test void shouldZoomInToAreaChart() { final LinkedList<FixationPoint> mockPoints = new LinkedList<>(List.of( new FixationPoint(50, 50, 1, 2), new FixationPoint(100, 100, 2, 3), new FixationPoint(150, 150, 4, 5) )); final AreaChart<Number, Number> areaChart = StatDisplayUtils.buildAreaChart(mockPoints, mockRegion); final VBox parent = new VBox(); parent.getChildren().add(areaChart); areaChart.fireEvent(mouseClickEvent(areaChart)); assertEquals(0, areaChart.getTranslateX()); assertEquals(0, areaChart.getTranslateY()); }
@Test void shouldZoomOutOfAreaChart() { final LinkedList<FixationPoint> mockPoints = new LinkedList<>(List.of( new FixationPoint(50, 50, 1, 2), new FixationPoint(100, 100, 2, 3), new FixationPoint(150, 150, 4, 5) )); final AreaChart<Number, Number> areaChart = StatDisplayUtils.buildAreaChart(mockPoints, mockRegion); final VBox parent = new VBox(); parent.getChildren().add(areaChart); areaChart.fireEvent(mouseClickEvent(areaChart)); areaChart.fireEvent(mouseClickEvent(areaChart)); assertEquals(1, areaChart.getScaleX()); assertEquals(1, areaChart.getScaleY()); }
@Test void shouldReturnNullBuildAreaWithNoPoints() { final LinkedList<FixationPoint> mockPoints = new LinkedList<>(); final AreaChart<Number, Number> areaChart = StatDisplayUtils.buildAreaChart(mockPoints, mockRegion); assertNull(areaChart); }