Skip to content

Commit 189ebd9

Browse files
authored
Merge branch 'fair-acc:main' into feature/axis-name-generation-handle-missing-info
2 parents 927a65e + f8a5094 commit 189ebd9

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractRendererXY.java

+9
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public void render() {
7474

7575
@Override
7676
public void updateAxes() {
77+
final var xAxisBefore = xAxis;
78+
final var yAxisBefore = yAxis;
79+
7780
// Default to explicitly set axes
7881
xAxis = ensureAxisInChart(getFirstAxis(Orientation.HORIZONTAL));
7982
yAxis = ensureAxisInChart(getFirstAxis(Orientation.VERTICAL));
@@ -95,6 +98,10 @@ public void updateAxes() {
9598
if (yAxis instanceof CategoryAxis axis && !getDatasets().isEmpty()) {
9699
axis.updateCategories(getDatasets().get(0));
97100
}
101+
102+
if (xAxisBefore != xAxis || yAxisBefore != yAxis) {
103+
getAxes().setAll(xAxis, yAxis);
104+
}
98105
}
99106

100107
protected Axis ensureAxisInChart(Axis axis) {
@@ -122,6 +129,8 @@ protected void updateAxisRange(AxisRange range, int dim) {
122129
}
123130

124131
protected void updateAxisRange(DataSet dataSet, AxisRange range, int dim) {
132+
if (dataSet.getDataCount() == 0)
133+
return;
125134
var dsRange = dataSet.getAxisDescription(dim);
126135
if (!dsRange.isDefined()) {
127136
dataSet.recomputeLimits(dim);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package io.fair_acc.chartfx.plugins;
2+
3+
import static io.fair_acc.dataset.DataSet.DIM_X;
4+
import static io.fair_acc.dataset.DataSet.DIM_Y;
5+
import static org.testfx.util.NodeQueryUtils.hasText;
6+
7+
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.api.extension.ExtendWith;
9+
import org.testfx.api.FxAssert;
10+
import org.testfx.api.FxRobot;
11+
import org.testfx.framework.junit5.ApplicationExtension;
12+
import org.testfx.framework.junit5.Start;
13+
import org.testfx.util.DebugUtils;
14+
15+
import io.fair_acc.chartfx.XYChart;
16+
import io.fair_acc.chartfx.axes.Axis;
17+
import io.fair_acc.chartfx.axes.spi.DefaultNumericAxis;
18+
import io.fair_acc.chartfx.renderer.spi.ErrorDataSetRenderer;
19+
import io.fair_acc.chartfx.ui.geometry.Side;
20+
import io.fair_acc.dataset.DataSet;
21+
import io.fair_acc.dataset.testdata.spi.CosineFunction;
22+
import javafx.geometry.Point2D;
23+
import javafx.scene.Scene;
24+
import javafx.stage.Stage;
25+
26+
/**
27+
* Test the DataPointTooltip plugin in the case that axis were only added to the chart and not the renderers.
28+
*
29+
* @author Benjamin Peter
30+
*/
31+
@ExtendWith(ApplicationExtension.class)
32+
class DataPointTooltipAxisFromChartTest {
33+
34+
private XYChart chart;
35+
private CosineFunction ds;
36+
private Axis xAxis;
37+
private Axis yAxis;
38+
39+
@Start
40+
public void start(Stage stage) {
41+
chart = new XYChart();
42+
chart.getPlugins().add(new DataPointTooltip());
43+
chart.setPrefWidth(400);
44+
chart.setPrefHeight(300);
45+
46+
xAxis = new DefaultNumericAxis("xAxis", "t");
47+
xAxis.setSide(Side.BOTTOM);
48+
yAxis = new DefaultNumericAxis("yAxis", "m");
49+
yAxis.setSide(Side.LEFT);
50+
chart.getAxes().setAll(xAxis, yAxis);
51+
52+
final ErrorDataSetRenderer renderer = new ErrorDataSetRenderer();
53+
54+
ds = new CosineFunction("Cosine", 50);
55+
renderer.getDatasets().add(ds);
56+
57+
chart.getRenderers().setAll(renderer);
58+
Scene scene = new Scene(chart, 400, 300);
59+
stage.setScene(scene);
60+
stage.show();
61+
}
62+
63+
@Test
64+
void testThatTooltipIsShown(final FxRobot fxRobot) { // NOPMD JUnitTestsShouldIncludeAssert
65+
fxRobot.interrupt();
66+
67+
fxRobot.moveTo(getPointOnDataSet(xAxis, yAxis, ds, 36)).moveBy(1, 0);
68+
FxAssert.verifyThat(
69+
"." + DataPointTooltip.STYLE_CLASS_LABEL,
70+
hasText("'Cosine [36]'" + System.lineSeparator() + "36.0, 0.3090169943749491"),
71+
DebugUtils.informedErrorMessage(fxRobot));
72+
}
73+
74+
private Point2D getPointOnDataSet(final Axis xAxis, final Axis yAxis, final DataSet ds, final int index) {
75+
return chart.getCanvas()
76+
.localToScreen(
77+
new Point2D(xAxis.getDisplayPosition(ds.get(DIM_X, index)),
78+
yAxis.getDisplayPosition(ds.get(DIM_Y, index))));
79+
}
80+
81+
}

0 commit comments

Comments
 (0)