Skip to content

Commit

Permalink
added category axis update
Browse files Browse the repository at this point in the history
  • Loading branch information
ennerf committed Sep 27, 2023
1 parent ee5fb7d commit 8f9a4d0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
17 changes: 17 additions & 0 deletions chartfx-chart/src/main/java/io/fair_acc/chartfx/XYChart.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.fair_acc.chartfx;

import io.fair_acc.chartfx.axes.spi.CategoryAxis;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
Expand Down Expand Up @@ -228,7 +229,23 @@ 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
}

}

}

private final AxisRange axisRange = new AxisRange();
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 @@ -2,6 +2,7 @@

import java.security.InvalidParameterException;

import io.fair_acc.chartfx.axes.spi.CategoryAxis;
import javafx.geometry.Orientation;
import javafx.scene.canvas.GraphicsContext;

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 8f9a4d0

Please sign in to comment.