Skip to content

Commit

Permalink
reverted userTickUnit split
Browse files Browse the repository at this point in the history
  • Loading branch information
ennerf authored and wirew0rm committed Aug 8, 2023
1 parent 15b47e7 commit 5703417
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 48 deletions.
15 changes: 8 additions & 7 deletions chartfx-chart/src/main/java/io/fair_acc/chartfx/axes/Axis.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package io.fair_acc.chartfx.axes;

import javafx.beans.property.*;
import java.util.List;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
Expand Down Expand Up @@ -145,8 +150,6 @@ public interface Axis extends AxisDescription {

double getTickUnit();

double getUserTickUnit();

/**
* @return axis primary unit scaling
*/
Expand Down Expand Up @@ -308,7 +311,7 @@ default void invokeListener(final UpdateEvent updateEvent, final boolean execute

void setSide(Side newSide);

void setUserTickUnit(double tickUnit);
void setTickUnit(double tickUnit);

/**
* This is {@code true} when the axis labels and data point should be plotted according to some time-axis definition
Expand All @@ -334,9 +337,7 @@ default void invokeListener(final UpdateEvent updateEvent, final boolean execute

ObjectProperty<Side> sideProperty();

ReadOnlyDoubleProperty tickUnitProperty();

DoubleProperty userTickUnitProperty();
DoubleProperty tickUnitProperty();

/**
* This is {@code true} when the axis labels and data point should be plotted according to some time-axis definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ protected void updateAxisContents() {
}

// Tick units
double mTickUnit = getUserTickUnit();
double mTickUnit = getTickUnit();
if (isAutoRanging() || isAutoGrowRanging() || true /* TODO: zoom never changes scale */){
mTickUnit = computePreferredTickUnit(length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,22 +348,14 @@ protected void invalidated() {
}
};

/**
* user-set tick units when doing auto-ranging
*/
protected final transient StyleableDoubleProperty userTickUnit = CSS.createDoubleProperty(this, "userTickUnit", DEFAULT_TICK_UNIT, () -> {
protected final transient StyleableDoubleProperty tickUnit = CSS.createDoubleProperty(this, "tickUnit", DEFAULT_TICK_UNIT, () -> {
if (isAutoRanging() || isAutoGrowRanging()) {
return;
}
invalidate();
invokeListener(new AxisChangeEvent(AbstractAxisParameter.this));
});

/**
* system-set tick units for getting the currently displayed units
*/
protected final transient DoubleProperty tickUnit = new SimpleDoubleProperty(Double.NaN);

protected final transient ChangeListener<? super Number> scaleChangeListener = (ch, o, n) -> {
final double axisLength = getLength(); // [pixel]
final double lowerBound = getMin();
Expand Down Expand Up @@ -797,11 +789,6 @@ public double getTickUnit() {
return tickUnitProperty().get();
}

@Override
public double getUserTickUnit() {
return userTickUnitProperty().get();
}

@Override
public String getUnit() {
return unitProperty().get();
Expand Down Expand Up @@ -1198,13 +1185,9 @@ public void setTickMarkVisible(final boolean value) {
*
* @param unit major tick unit
*/
protected void setTickUnit(final double unit) {
tickUnit.set(unit);
}

@Override
public void setUserTickUnit(final double unit) {
userTickUnit.set(unit);
public void setTickUnit(final double unit) {
tickUnitProperty().set(unit);
}

/**
Expand Down Expand Up @@ -1287,15 +1270,10 @@ public BooleanProperty tickMarkVisibleProperty() {
* @return tickUnit property
*/
@Override
public ReadOnlyDoubleProperty tickUnitProperty() {
public DoubleProperty tickUnitProperty() {
return tickUnit;
}

@Override
public DoubleProperty userTickUnitProperty() {
return userTickUnit;
}

/**
* This is {@code true} when the axis labels and data point should be plotted according to some time-axis definition
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ private void changeAxisRangeLimit(final Axis axis, final boolean isHorizontal, f

if (axis instanceof AbstractAxis) {
// ((AbstractAxis) axis).recomputeTickMarks();
((AbstractAxis) axis).setAutoRanging(false); // TODO: this used to set internal units. Is this ok?
axis.setUserTickUnit(((AbstractAxis) axis).computePreferredTickUnit(axis.getLength()));
axis.setTickUnit(((AbstractAxis) axis).computePreferredTickUnit(axis.getLength()));
}
}

Expand Down Expand Up @@ -426,8 +425,7 @@ private TextField getBoundField(final Axis axis, final boolean isLowerBound) {

if (axis instanceof AbstractAxis) {
// ((AbstractAxis) axis).recomputeTickMarks();
((AbstractAxis) axis).setAutoRanging(false); // TODO: this used to set internal units. Is this ok?
axis.setUserTickUnit(((AbstractAxis) axis).computePreferredTickUnit(axis.getLength()));
axis.setTickUnit(((AbstractAxis) axis).computePreferredTickUnit(axis.getLength()));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("recompute axis tick unit to {}",
((AbstractAxis) axis).computePreferredTickUnit(axis.getLength()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
yAxis.setAutoRanging(false);
yAxis.setMin(zRangeMin);
yAxis.setMax(max);
yAxis.setUserTickUnit(Math.abs(max - zRangeMin) / 10.0);
yAxis.setTickUnit(Math.abs(max - zRangeMin) / 10.0);
yAxis.forceRedraw();
}
yAxis.setAutoRanging(autoRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void lowerBoundChanged(ObservableValue<? extends Number> property, Numbe
axis.setMin(value);
axis.setAutoRanging(false);
}
axis.setUserTickUnit(tickUnit);
axis.setTickUnit(tickUnit);
}
updating = false;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ private void upperBoundChanged(ObservableValue<? extends Number> property, Numbe
axis.setAutoRanging(false);
axis.setMax(value);
}
axis.setUserTickUnit(tickUnit);
axis.setTickUnit(tickUnit);
}
updating = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public MasterSlaveAxisSynchronizer(AbstractAxis master) {
public void add(AbstractAxis axis) {
slaves.add(axis);
axis.setAutoRanging(false);
axis.userTickUnitProperty().bind(master.tickUnitProperty());
axis.tickUnitProperty().bind(master.tickUnitProperty());
}

private void lowerBoundChanged(double value) {
Expand All @@ -46,7 +46,7 @@ private void lowerBoundChanged(double value) {

public void remove(AbstractAxis axis) {
slaves.remove(axis);
axis.userTickUnitProperty().unbind();
axis.tickUnitProperty().unbind();
axis.setAutoRanging(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public void run() {
xAxisDyn.minProperty().set(now - range);
final String text = "actual range [s]: " + String.format("%#.3f", range) + " ("
+ String.format("%#.1f", range / 3600 / 24) + " days)";
xAxisDyn.setAutoRanging(false);
xAxisDyn.setUserTickUnit(range / 12);
xAxisDyn.setTickUnit(range / 12);
xAxisDyn.forceRedraw();
xAxis9Text.setText(text);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public void setNumberOfSamples(int nSamples) {
chart.getDatasets().setAll(testFunction);
xAxis.setMax(nSamples - 1.0);
xAxis.setMin(0);
xAxis.setAutoRanging(false);
xAxis.setUserTickUnit(nSamples / 20.0);
xAxis.setTickUnit(nSamples / 20.0);
updateDataSet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Node getContent() {
chart.getYAxis(1).setAutoRanging(false);
chart.getYAxis().maxProperty().bindBidirectional(chart.getYAxis(1).maxProperty());
chart.getYAxis().minProperty().bindBidirectional(chart.getYAxis(1).minProperty());
chart.getYAxis().userTickUnitProperty().bindBidirectional(chart.getYAxis(1).userTickUnitProperty()); // TODO: used tickUnitProperty. Make sure it still works.
chart.getYAxis().tickUnitProperty().bindBidirectional(chart.getYAxis(1).tickUnitProperty());

LimitedQueue<DataSet> lastDataSets = new LimitedQueue<>(N_GRAPHS);
for (int i = 0; i < 20 * N_GRAPHS; i++) {
Expand Down

0 comments on commit 5703417

Please sign in to comment.