Skip to content

Commit

Permalink
added category axis update
Browse files Browse the repository at this point in the history
  • Loading branch information
ennerf authored and wirew0rm committed Sep 27, 2023
1 parent ee5fb7d commit 2599a44
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
15 changes: 15 additions & 0 deletions chartfx-chart/src/main/java/io/fair_acc/chartfx/XYChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.fair_acc.bench.MeasurementRecorder;
import io.fair_acc.chartfx.axes.Axis;
import io.fair_acc.chartfx.axes.spi.AxisRange;
import io.fair_acc.chartfx.axes.spi.CategoryAxis;
import io.fair_acc.chartfx.plugins.ChartPlugin;
import io.fair_acc.chartfx.renderer.PolarTickStep;
import io.fair_acc.chartfx.renderer.Renderer;
Expand Down Expand Up @@ -228,6 +229,20 @@ public void updateAxisRange() {
if (changed && (axis.isAutoRanging() || axis.isAutoGrowRanging())) {
axis.invalidateRange();
}

// Feature for backwards compatibility: Category axes that do not have
// their categories set copy the categories of the first dataset of the
// first renderer that is using this axis.
if (axis instanceof CategoryAxis catAxis) {
for (Renderer renderer : getRenderers()) {
if (renderer.isUsingAxis(axis)) {
if (!renderer.getDatasets().isEmpty()) {
catAxis.updateCategories(renderer.getDatasets().get(0));
}
break;
}
}

Check warning on line 244 in chartfx-chart/src/main/java/io/fair_acc/chartfx/XYChart.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/XYChart.java#L244

Added line #L244 was not covered by tests
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ default void updateAxes() {
// empty by default
}

/**
* Checks whether a renderer is actively using a given axis. The
* result is only valid after updateAxes has been called.
* <p>
* @param axis axis to be checked
* @return true if the renderer is actively using the given axis
*/
default boolean isUsingAxis(Axis axis) {
return getAxes().contains(axis);

Check warning on line 106 in chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/Renderer.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/Renderer.java#L106

Added line #L106 was not covered by tests
}

/**
* Updates the range for the specified axis.
* Does nothing if the axis is not used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.fair_acc.chartfx.XYChart;
import io.fair_acc.chartfx.axes.Axis;
import io.fair_acc.chartfx.axes.spi.AxisRange;
import io.fair_acc.chartfx.axes.spi.CategoryAxis;
import io.fair_acc.chartfx.ui.css.DataSetNode;
import io.fair_acc.dataset.DataSet;
import io.fair_acc.dataset.utils.AssertUtils;
Expand Down Expand Up @@ -85,6 +86,22 @@ public void updateAxes() {
if (yAxis == null) {
yAxis = chart.getYAxis();
}

// Update category axes (TODO: remove this API?)
if (!getDatasets().isEmpty()) {
var ds = getDatasets().get(0);
if (xAxis instanceof CategoryAxis xCat) {
xCat.updateCategories(ds);
}
if (yAxis instanceof CategoryAxis yCat) {
yCat.updateCategories(ds);

Check warning on line 97 in chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractRendererXY.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L97 was not covered by tests
}
}
}

@Override
public boolean isUsingAxis(Axis axis) {
return axis == xAxis || axis == yAxis;
}

protected Axis ensureAxisInChart(Axis axis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public void updateAxes() {
}
}

@Override
public boolean isUsingAxis(Axis axis) {
return super.isUsingAxis(axis) || axis == zAxis;
}

@Override
public void updateAxisRange(Axis axis, AxisRange range) {
super.updateAxisRange(axis, range);
Expand Down

0 comments on commit 2599a44

Please sign in to comment.