Skip to content

Commit

Permalink
Axis: expose method to recompute transformation cache
Browse files Browse the repository at this point in the history
If the axis gets changed multiple times during event handling, but the
cache is only updated during layout, axes transforms from the event
handlers use outdated transformations.

This has the effect that e.g. panning only applies the first mouse event
in each pulse and the panning is a lot slower than the actual mouse
movement.

This adds a method to the axes which can be called by plugins which use
and update the axis range.
  • Loading branch information
wirew0rm committed Aug 17, 2023
1 parent da296dd commit d1304a1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,11 @@ public interface Axis extends AxisDescription {
* @return the canvas of the axis
*/
Canvas getCanvas();

/**
* Hook to manually update the cached axis transforms outside of the render loop.
* This is needed e.g. when plugins adjust the axes and at the same time need to perform
* transformations with the modified ranges.
*/
default void updateCachedTransforms() {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ protected void updateAxisRange(double length) {
updateScaleAndUnitPrefix();

// Update the cache to the new range
updateCachedVariables();
updateCachedTransforms();

// Compute new tick marks and locations
updateMajorTickMarks(range);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Objects;

import io.fair_acc.chartfx.ui.css.*;
import io.fair_acc.chartfx.ui.layout.ChartPane;
import io.fair_acc.chartfx.utils.PropUtil;
import io.fair_acc.dataset.events.BitState;
import io.fair_acc.dataset.events.ChartBits;
Expand All @@ -15,10 +14,7 @@
import javafx.css.*;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
import javafx.util.StringConverter;

import io.fair_acc.chartfx.Chart;
Expand Down Expand Up @@ -360,7 +356,8 @@ public String getUserAgentStylesheet() {
/**
* to be overwritten by derived class that want to cache variables for efficiency reasons
*/
protected void updateCachedVariables() { // NOPMD by rstein function can but does not have to be overwritten
@Override
public void updateCachedTransforms() { // NOPMD by rstein function can but does not have to be overwritten
// called once new axis parameters have been established
cachedOffset = getSide().isHorizontal() ? 0 : getLength();
}
Expand Down Expand Up @@ -816,7 +813,8 @@ public ObjectProperty<AxisLabelOverlapPolicy> overlapPolicyProperty() {

@Override
public boolean set(final double min, final double max) {
return PropUtil.set(minProp, min) | PropUtil.set(maxProp, max);
final boolean result = PropUtil.set(minProp, min) | PropUtil.set(maxProp, max);
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package io.fair_acc.chartfx.axes.spi;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import io.fair_acc.chartfx.utils.PropUtil;
import io.fair_acc.dataset.spi.fastutil.DoubleArrayList;
import javafx.beans.property.BooleanProperty;
Expand Down Expand Up @@ -540,8 +535,8 @@ protected double computeTickUnit(final double rawTickUnit) {
}

@Override
protected void updateCachedVariables() {
super.updateCachedVariables();
public void updateCachedTransforms() {
super.updateCachedTransforms();
if (cache == null) { // lgtm [java/useless-null-check] NOPMD NOSONAR -- called from static initializer
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ protected void recomputeClampedRange() {
}

@Override
protected void updateCachedVariables() {
super.updateCachedVariables();
public void updateCachedTransforms() {
super.updateCachedTransforms();
if (cache == null) { // lgtm [java/useless-null-check] NOPMD NOSONAR -- called from static initializer
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void parameterTests() {
assertTrue(axis.isLogAxis());
assertEquals(LogAxisType.LOG10_SCALE, axis.getLogAxisType());
axis.setMin(0.1);
axis.updateCachedVariables();
axis.updateCachedTransforms();
axis.layoutChildren();
assertEquals(axis.getZeroPosition(), axis.getDisplayPosition(axis.getMin()));
assertEquals(10, axis.getLogarithmBase());
Expand All @@ -89,7 +89,7 @@ public void parameterTests() {

axis.setLogAxis(false);
assertFalse(axis.isLogAxis());
axis.updateCachedVariables();
axis.updateCachedTransforms();
tickValues.clear();
axis.calculateMinorTickValues(tickValues);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void identityTests() {
final OscilloscopeAxis axis = new OscilloscopeAxis("axis title", 0.0, 100.0, 10.0);

assertDoesNotThrow(() -> axis.setSide(Side.BOTTOM));
assertDoesNotThrow(axis::updateCachedVariables);
assertDoesNotThrow(axis::updateCachedTransforms);

final double zero = axis.getDisplayPosition(axis.getValueForDisplay(0));
assertEquals(0.0, zero);
Expand Down Expand Up @@ -167,13 +167,13 @@ public void setterGetterTests() {
axis.setTickUnitSupplier(testTickUnitSupplier);
assertEquals(testTickUnitSupplier, axis.getTickUnitSupplier());

assertDoesNotThrow(axis::updateCachedVariables);
assertDoesNotThrow(axis::updateCachedTransforms);

assertDoesNotThrow(() -> axis.setSide(Side.BOTTOM));
assertDoesNotThrow(axis::updateCachedVariables);
assertDoesNotThrow(axis::updateCachedTransforms);

assertDoesNotThrow(() -> axis.setSide(Side.LEFT));
assertDoesNotThrow(axis::updateCachedVariables);
assertDoesNotThrow(axis::updateCachedTransforms);

assertNotNull(axis.getAxisTransform());

Expand Down

0 comments on commit d1304a1

Please sign in to comment.