Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoRangePadding changes data point values instead of increasing axis range #469

Closed
roberto0013 opened this issue Nov 11, 2021 · 4 comments
Assignees
Labels
bug:major Something isn't working bug

Comments

@roberto0013
Copy link

Describe the bug
In the newly released version 11.2.6 when adding AutoRangePadding to an Axis the axis range isn't increased instead the shown data-points changes value.
image
A sine-curve with the amplitude 40 and no padding.
image
The same sine-curve but with 0.3 (30%) padding. As can clearly be seen the axis-range doesn't increase, instead the sine-waves amplitude is decreased.

To Reproduce
The problem is visible in the PaddedAutoGrowAxisSample.java, but can also be reproduced by creating a simple sine-wave and adding AutoRangePadding.

public class TimeChartTester extends Application{
    @Override
    public void start(final Stage aPrimaryStage) throws Exception {
        final var xAxis = new DefaultNumericAxis();
        final var yAxis = new DefaultNumericAxis();
        final var chart = new XYChart(xAxis, yAxis);
        chart.getPlugins().add(new EditAxis());
        chart.getPlugins().add(new Zoomer());

        yAxis.setAutoRangePadding(0.3);
        yAxis.setAutoRanging(false);
        yAxis.setAutoGrowRanging(true);
        yAxis.set(0, 10);

        final var ds = new CircularDoubleErrorDataSet("", 150);
        chart.getDatasets().addAll(ds);
                for (int i = 0; i < 500; i++) {
                    ds.add(i, 40 * Math.sin(i * 0.1), 0, 0);
                    }

        final Scene scene = new Scene(chart, 800, 600);
        aPrimaryStage.setScene(scene);
        aPrimaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(final String[] args) {
        Application.launch(args);
    }
}

Environment:

  • OS: Windows
  • Java version: 11
  • JavaFx version: 11.0.2
  • ChartFx version: 11.2.6
@wirew0rm
Copy link
Member

Hey, thanks for the bug report.

In #466 we fixed another problem with the combination of autoGrowRanging and axisPadding. Did you take a look at that PR and the sample submitted with it? I'm away from my IDE at the moment, but from looking at the code, the main difference seems to be that you add the data and then only afterwards add the chart to the scenegraph.

What probably happens is that the axis is drawn and only afterwards rescaled to the data range and this new (correct) range is used for rendering the sine wave.
As a workaround you can probably manually trigger an update using requestLayout on the chart or axis but this should not be necessary, we'll have to look into it, at the moment I'm not sure what caused the correct redraw before the change.

@roberto0013
Copy link
Author

Hello, thanks for the fast response.

Just to clarify, the problem is still present when running the provided PaddedAutoGrowAxisSample.java. So the difference between the implementations should not be the reason for the error.
Perhaps you are right that there are some type of update that has to be triggered, I however did try to perform requestLayout/requestAxisLayout on both the chart and axes with no effect.

@wirew0rm
Copy link
Member

Indeed, the rendering of the axis tickmarks doesn't seem to take the padding into account. Previously this was not a problem, because the padding was applied to the general axis limits, but this lead to other problems. I'll try to come up with a fix for this.

@wirew0rm wirew0rm added the bug:major Something isn't working label Nov 16, 2021
@wirew0rm wirew0rm self-assigned this Nov 16, 2021
wirew0rm added a commit that referenced this issue Nov 16, 2021
solves #469 by also using the computed autoRange() result which includes
the padding when calculating the tick marks.
wirew0rm added a commit that referenced this issue Feb 11, 2022
solves #469 by also using the computed autoRange() result which includes
the padding when calculating the tick marks.
@wirew0rm
Copy link
Member

solved in #470

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:major Something isn't working bug
Projects
None yet
Development

No branches or pull requests

2 participants