use of eu.fthevenet.binjr.data.workspace.Chart in project selenium_java by sergueik.
the class ChartViewportsState method setSelection.
public void setSelection(Map<Chart<Double>, XYChartSelection<ZonedDateTime, Double>> selectionMap, boolean toHistory) {
this.suspendAxisListeners();
try {
selectionMap.forEach((chart, xyChartSelection) -> get(chart).ifPresent(y -> y.setSelection(xyChartSelection, toHistory)));
selectionMap.entrySet().stream().findFirst().ifPresent(entry -> {
ZonedDateTime newStartX = roundDateTime(entry.getValue().getStartX());
ZonedDateTime newEndX = roundDateTime(entry.getValue().getEndX());
boolean dontPlotChart = newStartX.isEqual(startX.get()) && newEndX.isEqual(endX.get());
this.startX.set(newStartX);
this.endX.set(newEndX);
selectionMap.forEach((chart, xyChartSelection) -> get(chart).ifPresent(y -> y.setSelection(xyChartSelection, toHistory)));
parent.invalidateAll(toHistory, dontPlotChart, false);
});
timeRange.set(TimeRangePicker.TimeRange.of(startX.getValue(), endX.getValue()));
} finally {
this.resumeAxisListeners();
}
}
use of eu.fthevenet.binjr.data.workspace.Chart in project selenium_java by sergueik.
the class WorksheetController method plotChart.
private void plotChart(ChartViewPort<Double> viewPort, XYChartSelection<ZonedDateTime, Double> currentSelection, boolean forceRefresh) {
try (Profiler p = Profiler.start("Adding series to chart " + viewPort.getDataStore().getName(), logger::trace)) {
worksheetMaskerPane.setVisible(true);
AsyncTaskManager.getInstance().submit(() -> {
viewPort.getDataStore().fetchDataFromSources(currentSelection.getStartX(), currentSelection.getEndX(), forceRefresh);
return viewPort.getDataStore().getSeries().stream().filter(series -> {
if (series.getProcessor() == null) {
logger.warn("Series " + series.getDisplayName() + " does not contain any data to plot");
return false;
}
if (!series.isSelected()) {
logger.debug(() -> "Series " + series.getDisplayName() + " is not selected");
return false;
}
return true;
}).map(ts -> makeXYChartSeries(viewPort.getDataStore(), ts)).collect(Collectors.toList());
}, event -> {
if (!closed.get()) {
worksheetMaskerPane.setVisible(false);
viewPort.getChart().getData().setAll((Collection<? extends XYChart.Series<ZonedDateTime, Double>>) event.getSource().getValue());
// Force a redraw of the charts and their Y Axis considering their proper width.
new DelayedAction(() -> viewPort.getChart().resize(0.0, 0.0), Duration.millis(50)).submit();
}
}, event -> {
if (!closed.get()) {
worksheetMaskerPane.setVisible(false);
Dialogs.notifyException("Failed to retrieve data from source", event.getSource().getException(), root);
}
});
}
}
use of eu.fthevenet.binjr.data.workspace.Chart in project selenium_java by sergueik.
the class WorksheetController method addBindings.
// region *** protected members ***
protected void addBindings(Collection<TimeSeriesBinding<Double>> bindings, Chart<Double> targetChart) {
InvalidationListener isVisibleListener = (observable) -> {
viewPorts.stream().filter(v -> v.getDataStore().equals(targetChart)).findFirst().ifPresent(v -> {
boolean andAll = true;
boolean orAll = false;
for (TimeSeriesInfo<?> t : targetChart.getSeries()) {
andAll &= t.isSelected();
orAll |= t.isSelected();
}
CheckBox showAllCheckBox = (CheckBox) v.getSeriesTable().getColumns().get(0).getGraphic();
showAllCheckBox.setIndeterminate(Boolean.logicalXor(andAll, orAll));
showAllCheckBox.setSelected(andAll);
});
};
for (TimeSeriesBinding<Double> b : bindings) {
TimeSeriesInfo<Double> newSeries = TimeSeriesInfo.fromBinding(b);
bindingManager.attachListener(newSeries.selectedProperty(), (observable, oldValue, newValue) -> viewPorts.stream().filter(v -> v.getDataStore().equals(targetChart)).findFirst().ifPresent(v -> invalidate(v, false, false)));
bindingManager.attachListener(newSeries.selectedProperty(), isVisibleListener);
targetChart.addSeries(newSeries);
// Explicitly call the listener to initialize the proper status of the checkbox
isVisibleListener.invalidated(null);
}
invalidateAll(false, false, false);
}
use of eu.fthevenet.binjr.data.workspace.Chart in project selenium_java by sergueik.
the class WorksheetController method setupOverlayChartLayout.
private void setupOverlayChartLayout() {
for (int i = 0; i < viewPorts.size(); i++) {
ChartViewPort<Double> v = viewPorts.get(i);
XYChart<ZonedDateTime, Double> chart = v.getChart();
int nbAdditionalCharts = getWorksheet().getCharts().size() - 1;
DoubleBinding n = Bindings.createDoubleBinding(() -> viewPorts.stream().filter(c -> !c.getChart().equals(chart)).map(c -> c.getChart().getYAxis().getWidth()).reduce(Double::sum).orElse(0.0) + (Y_AXIS_SEPARATION * nbAdditionalCharts), viewPorts.stream().map(c -> c.getChart().getYAxis().widthProperty()).toArray(ReadOnlyDoubleProperty[]::new));
HBox hBox = new HBox(chart);
hBox.setAlignment(Pos.CENTER_LEFT);
bindingManager.bind(hBox.prefHeightProperty(), chartParent.heightProperty());
bindingManager.bind(hBox.prefWidthProperty(), chartParent.widthProperty());
bindingManager.bind(chart.minWidthProperty(), chartParent.widthProperty().subtract(n));
bindingManager.bind(chart.prefWidthProperty(), chartParent.widthProperty().subtract(n));
bindingManager.bind(chart.maxWidthProperty(), chartParent.widthProperty().subtract(n));
if (i == 0) {
chart.getYAxis().setSide(Side.LEFT);
} else {
chart.getYAxis().setSide(Side.RIGHT);
chart.setVerticalZeroLineVisible(false);
chart.setHorizontalZeroLineVisible(false);
chart.setVerticalGridLinesVisible(false);
chart.setHorizontalGridLinesVisible(false);
bindingManager.bind(chart.translateXProperty(), viewPorts.get(0).getChart().getYAxis().widthProperty());
bindingManager.bind(chart.getYAxis().translateXProperty(), Bindings.createDoubleBinding(() -> viewPorts.stream().filter(c -> viewPorts.indexOf(c) != 0 && viewPorts.indexOf(c) < viewPorts.indexOf(v)).map(c -> c.getChart().getYAxis().getWidth()).reduce(Double::sum).orElse(0.0) + Y_AXIS_SEPARATION * (viewPorts.indexOf(v) - 1), viewPorts.stream().map(c -> c.getChart().getYAxis().widthProperty()).toArray(ReadOnlyDoubleProperty[]::new)));
}
chartParent.getChildren().add(hBox);
}
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.RFC_1123_DATE_TIME;
LinkedHashMap<XYChart<ZonedDateTime, Double>, Function<Double, String>> map = new LinkedHashMap<>();
viewPorts.forEach(v -> map.put(v.getChart(), v.getPrefixFormatter()::format));
crossHair = new XYChartCrosshair<>(map, chartParent, dateTimeFormatter::format);
crossHair.onSelectionDone(s -> {
logger.debug(() -> "Applying zoom selection: " + s.toString());
currentState.setSelection(convertSelection(s), true);
});
hCrosshair.selectedProperty().bindBidirectional(globalPrefs.horizontalMarkerOnProperty());
vCrosshair.selectedProperty().bindBidirectional(globalPrefs.verticalMarkerOnProperty());
bindingManager.bind(crossHair.horizontalMarkerVisibleProperty(), Bindings.createBooleanBinding(() -> globalPrefs.isShiftPressed() || hCrosshair.isSelected(), hCrosshair.selectedProperty(), globalPrefs.shiftPressedProperty()));
bindingManager.bind(crossHair.verticalMarkerVisibleProperty(), Bindings.createBooleanBinding(() -> globalPrefs.isCtrlPressed() || vCrosshair.isSelected(), vCrosshair.selectedProperty(), globalPrefs.ctrlPressedProperty()));
}
use of eu.fthevenet.binjr.data.workspace.Chart in project selenium_java by sergueik.
the class WorksheetController method setReloadRequiredHandler.
public void setReloadRequiredHandler(Consumer<WorksheetController> action) {
ChangeListener<Object> controllerReloadListener = (observable, oldValue, newValue) -> {
if (newValue != null) {
logger.debug("Reloading worksheet controller because property changed from: " + oldValue + " to " + newValue);
action.accept(this);
this.close();
}
};
bindingManager.attachListener(worksheet.chartLayoutProperty(), controllerReloadListener);
this.worksheet.getCharts().forEach(c -> {
bindingManager.attachListener(c.unitPrefixesProperty(), controllerReloadListener);
bindingManager.attachListener(c.chartTypeProperty(), controllerReloadListener);
});
ListChangeListener<Chart<Double>> chartListListener = c -> {
while (c.next()) {
if (c.wasPermutated()) {
for (int i = c.getFrom(); i < c.getTo(); ++i) {
// nothing for now
}
} else if (c.wasUpdated()) {
// nothing for now
} else {
if (!preventReload) {
if (c.wasAdded()) {
List<? extends Chart<Double>> added = c.getAddedSubList();
Chart<Double> chart = added.get(added.size() - 1);
int chartIndex = worksheet.getCharts().indexOf(chart);
worksheet.setSelectedChart(chartIndex);
chart.setShowProperties(true);
}
if (c.wasRemoved()) {
if (worksheet.getSelectedChart() == c.getFrom()) {
worksheet.setSelectedChart(Math.max(0, c.getFrom() - 1));
} else if (worksheet.getSelectedChart() > c.getFrom()) {
worksheet.setSelectedChart(Math.max(0, worksheet.getSelectedChart() - 1));
}
}
logger.debug(() -> "Reloading worksheet controller because list changed: " + c.toString() + " in controller " + this.toString());
action.accept(this);
} else {
logger.debug(() -> "Reload explicitly prevented on change " + c.toString());
}
}
}
};
bindingManager.attachListener(worksheet.getCharts(), chartListListener);
}
Aggregations