public void initFX() { // This method is invoked on the JavaFX thread fxPanel.removeAll(); createScene(); chart.setAnimated(true); fxPanel.setScene(scene); }
public static void addMarker(final XYChart<?, ?> chart, final StackPane chartWrap) { final Line valueMarker = new Line(); final Node chartArea = chart.lookup(".chart-plot-background"); chartArea.setOnMouseMoved( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { Point2D scenePoint = chart.localToScene(event.getSceneX(), event.getSceneY()); Point2D position = chartWrap.sceneToLocal(scenePoint.getX(), scenePoint.getY()); Bounds chartAreaBounds = chartArea.localToScene(chartArea.getBoundsInLocal()); valueMarker.setStartY(0); valueMarker.setEndY( chartWrap.sceneToLocal(chartAreaBounds).getMaxY() - chartWrap.sceneToLocal(chartAreaBounds).getMinY()); valueMarker.setStartX(0); valueMarker.setEndX(0); valueMarker.setTranslateX(position.getX() - chartWrap.getWidth() / 2); double ydelta = chartArea.localToScene(0, 0).getY() - chartWrap.localToScene(0, 0).getY(); valueMarker.setTranslateY(-ydelta * 2); } }); chartWrap.getChildren().add(valueMarker); }
private void setColors() { Scenario scenario = (Scenario) Applicazione.getInstance().getModello().getBean(Scenario.class.getName()); for (int i = 0; i < chart.getData().size(); i++) { for (Node node : chart.lookupAll(".series" + i)) { node.getStyleClass().remove("default-color" + i); node.getStyleClass() .add("default-color" + mapColor.get(scenario.getToolsList().get(i).getName())); } int item = 0; for (Node node : chart.lookupAll(".chart-legend-item")) { if (node instanceof Label && ((Label) node).getGraphic() != null) { String color = mapColor.get(scenario.getToolsList().get(item).getName()); if (color != null && !color.isEmpty()) { ((Label) node).getGraphic().getStyleClass().remove("default-color" + item); ((Label) node).getGraphic().getStyleClass().add("default-color" + color); } } item++; } } }
private void createScene() { // defining the axes NumberAxis xAxis = new NumberAxis(0, 105, 10); NumberAxis yAxis = new NumberAxis(); xAxis.setLabel("Quality %"); yAxis.setLabel("User Interactions"); yAxis.forceZeroInRangeProperty(); // xAxis.setMinorTickCount(0); // yAxis.setMinorTickCount(0); // creating the chart if (chartType == null) { chartType = Constant.AREA_CHART; // overlapping area colors this.chart = new AreaChart<Number, Number>(xAxis, yAxis); // this.chart = new StackedAreaChart<Number, Number>(xAxis, yAxis); } else if (chartType.equals(Constant.LINE_CHART)) { this.chart = new LineChart<Number, Number>(xAxis, yAxis); } else { // overlapping area colors this.chart = new AreaChart<Number, Number>(xAxis, yAxis); // this.chart = new StackedAreaChart<Number, Number>(xAxis, yAxis); } if (logger.isDebugEnabled()) logger.debug("Chart created: " + this.chart); chart.setAnimated(true); scene = new Scene(chart, 600, 400); chart .getStylesheets() .add(this.getClass().getResource(Constant.FOLDER_CONF + "styleChart.css").toExternalForm()); createSeries(chart); // seriesOs = FXCollections.observableArrayList(); // createObservableSeries(); // chart.setData(seriesOs); chart.setLegendSide(Side.TOP); logger.debug("Thread chart active: " + Thread.activeCount()); }
public void refreshSeries() { // if (chart != null && !chart.getData().isEmpty()) { // chart.getData().removeAll(seriesOs); // seriesOs.removeAll(); // this.createObservableSeries(); if (chart == null) { initFX(); } chart.getData().removeAll(); chart.getData().clear(); this.createSeries(chart); // } else { // initFX(); // } }
private void createSeries(final XYChart chart) { // populating the series with data XYChart.Series series; Scenario scenario = (Scenario) Applicazione.getInstance().getModello().getBean(Scenario.class.getName()); for (MappingTool tool : scenario.getToolsList()) { if (logger.isTraceEnabled()) logger.trace("Tool Scan : " + tool.getName()); if (tool.getNumberExecutions() > 0) { series = new XYChart.Series(); series.setName(tool.getName()); if (!mapColor.containsKey(tool.getName())) { mapColor.put(tool.getName(), PropertiesLoader.loadColorName(tool.getName())); if (logger.isTraceEnabled()) logger.trace( "map color put" + tool.getName() + " value " + mapColor.get(tool.getName())); } series.getData().add(new XYChart.Data(0, 0)); List<MappingExecution> listExecution = new ArrayList<MappingExecution>(); listExecution.addAll(tool.getExecutionsList()); Collections.sort(listExecution); if (logger.isTraceEnabled()) logger.trace("Mapping executions: " + listExecution.size()); for (MappingExecution mappingTask : listExecution) { int effort = 0; if (logger.isTraceEnabled()) logger.trace("Mapping: " + mappingTask); if (mappingTask.getEffortRecording() != null) { if (logger.isTraceEnabled()) logger.trace("Updating effort:" + mappingTask.getEffortRecording()); effort = mappingTask.getEffortRecording().getTotalInteraction(); } series .getData() .add(new XYChart.Data(mappingTask.getQuality().getFmeasure() * 100, effort)); } chart.getData().add(series); } } setColors(); // printNodes(chart, 0); }
private void drawRebootSuspectLine(XYChart<Number, ? extends Number> target) { if (target.getData().isEmpty() || target.getData().get(0).getData().isEmpty()) { return; } AnchorPane anchor = (AnchorPane) target .getParent() .getChildrenUnmodifiable() .stream() .filter(n -> n instanceof AnchorPane) .findAny() .get(); ObservableList<Node> anchorChildren = anchor.getChildren(); anchorChildren.clear(); NumberAxis xAxis = (NumberAxis) target.getXAxis(); Axis yAxis = target.getYAxis(); Label chartTitle = (Label) target .getChildrenUnmodifiable() .stream() .filter(n -> n.getStyleClass().contains("chart-title")) .findFirst() .get(); double startX = xAxis.getLayoutX() + 4.0d; double yPos = yAxis.getLayoutY() + chartTitle.getLayoutY() + chartTitle.getHeight(); List<Rectangle> rectList = summaryData .get() .getRebootSuspectList() .stream() .map(d -> d.atZone(ZoneId.systemDefault()).toEpochSecond()) .map( s -> new Rectangle( xAxis.getDisplayPosition(s) + startX, yPos, 4d, yAxis.getHeight())) .peek(r -> ((Rectangle) r).setStyle("-fx-fill: yellow;")) .collect(Collectors.toList()); anchorChildren.addAll(rectList); }
public void assignSampleData(FXOMObject startObject) { assert startObject != null; final Object sceneGraphObject = startObject.getSceneGraphObject(); final AbstractSampleData currentData = sampleDataMap.get(startObject); final AbstractSampleData newData; if (sceneGraphObject == null) { // startObject is unresolved newData = null; } else { final Class<?> sceneGraphClass = sceneGraphObject.getClass(); if (sceneGraphClass == ChoiceBox.class) { final ChoiceBox<?> choiceBox = (ChoiceBox) sceneGraphObject; if (choiceBox.getItems().isEmpty()) { if (currentData instanceof ChoiceBoxSampleData) { newData = currentData; } else { newData = new ChoiceBoxSampleData(); } } else { newData = null; } } else if (sceneGraphClass == ComboBox.class) { final ComboBox<?> comboBox = (ComboBox) sceneGraphObject; if (comboBox.getItems().isEmpty()) { if (currentData instanceof ComboBoxSampleData) { newData = currentData; } else { newData = new ComboBoxSampleData(); } } else { newData = null; } } else if (sceneGraphClass == ListView.class) { final ListView<?> listView = (ListView) sceneGraphObject; if (listView.getItems().isEmpty()) { if (currentData instanceof ListViewSampleData) { newData = currentData; } else { newData = new ListViewSampleData(); } } else { newData = null; } } else if (sceneGraphClass == TreeView.class) { final TreeView<?> treeView = (TreeView) sceneGraphObject; if (treeView.getRoot() == null) { if (currentData instanceof TreeViewSampleData) { newData = currentData; } else { newData = new TreeViewSampleData(); } } else { newData = null; } } else if (sceneGraphClass == TableView.class) { final TableView<?> treeView = (TableView) sceneGraphObject; if (TableViewSampleData.canApplyTo(treeView)) { if (currentData instanceof TableViewSampleData) { newData = currentData; } else { newData = new TableViewSampleData(); } } else { newData = null; } } else if (sceneGraphClass == TreeTableView.class) { final TreeTableView<?> treeTableView = (TreeTableView) sceneGraphObject; if (treeTableView.getRoot() == null) { if (currentData instanceof TreeTableViewSampleData) { newData = currentData; } else { newData = new TreeTableViewSampleData(); } } else { newData = null; } } else if (sceneGraphClass == PieChart.class) { final PieChart pieChart = (PieChart) sceneGraphObject; if (pieChart.getData().isEmpty()) { if (currentData instanceof PieChartSampleData) { newData = currentData; } else { newData = new PieChartSampleData(); } } else { newData = null; } } else if (XYChartSampleData.isKnownXYChart(sceneGraphObject)) { final XYChart<?, ?> xyChart = (XYChart) sceneGraphObject; if (xyChart.getData().isEmpty()) { if (currentData instanceof XYChartSampleData) { newData = currentData; } else { newData = new XYChartSampleData(); } } else { newData = null; } } else { newData = null; } } if (newData == null) { if (currentData != null) { sampleDataMap.remove(startObject); } } else { newData.applyTo(sceneGraphObject); sampleDataMap.put(startObject, newData); } if (startObject instanceof FXOMInstance) { final FXOMInstance fxomInstance = (FXOMInstance) startObject; for (FXOMProperty p : fxomInstance.getProperties().values()) { if (p instanceof FXOMPropertyC) { final FXOMPropertyC pc = (FXOMPropertyC) p; for (FXOMObject v : pc.getValues()) { assignSampleData(v); } } } } else if (startObject instanceof FXOMCollection) { final FXOMCollection fxomCollection = (FXOMCollection) startObject; for (FXOMObject i : fxomCollection.getItems()) { assignSampleData(i); } } }