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

Tests failing after startAtZero was removed #767

Closed
pmairoldi opened this issue Feb 20, 2016 · 7 comments
Closed

Tests failing after startAtZero was removed #767

pmairoldi opened this issue Feb 20, 2016 · 7 comments

Comments

@pmairoldi
Copy link
Collaborator

I just looked into why the tests are failing and it seems to have happened here when startAtZero was deprecated.

Setting the customAxisMin = 0.0 in the tests does kind of make it look like it should but there is still an offset. @danielgindi any ideas?

@danielgindi
Copy link
Collaborator

Yes it seems like there's some kind of residue. Weird since startAtZero was effectively setting customAxisMin to 0.0, just with a lot more code...
I'm looking into it

@danielgindi
Copy link
Collaborator

We can see the problem here:

screen shot 2016-02-20 at 10 36 58 pm

@PhilJay I think that this originates here: https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartLib/src/com/github/mikephil/charting/charts/BarLineChartBase.java#L358
Do you know if we still need this?
This used to always render "a little bit more" of the grid - except when startAtZero was enabled, which meant we want to trim the axis there.
Maybe we should introduce a new property for how much more we want to draw past the min/max? Or just a boolean?

@PhilJay
Copy link
Collaborator

PhilJay commented Feb 20, 2016

Yes, we draw a "little bit more" in that case. But that case should only occur if the range is 0 and hence all values in the dataset are equal. If that is not the case, this should not be an issue.

@danielgindi
Copy link
Collaborator

@PhilJay Yes it seems that that's not the source of the issue... But it still happens, on the Android side also.

Try to replace the code in BarChartActivity with this:

        mChart = (BarChart) findViewById(R.id.chart1);

        // Sample data
        float[] values = new float[]{8, 104, 81, 93, 52, 44, 97, 101, 75, 28,
        76, 25, 20, 13, 52, 44, 57, 23, 45, 91,
        99, 14, 84, 48, 40, 71, 106, 41, 45, 61};

        ArrayList<BarEntry> entries = new ArrayList<>();
        ArrayList<String> xValues = new ArrayList<>();

        for (int i = 0; i < values.length; i++)
        {
            entries.add(new BarEntry(values[i], i));
            xValues.add(Integer.toString(i));
        }

        BarDataSet dataSet = new BarDataSet(entries, "Bar chart unit test data");

        mChart.setData(new BarData(xValues, dataSet));

@danielgindi
Copy link
Collaborator

Okay after further investigation - two things happened:

  1. I was so tired that I didn't notice I've added the customAxisMin when testing after the setData, without calling notifyDataSetChanged or calcMinMax or anything like that.
  2. Even when setting customAxisMin correctly - there's a slight difference in drawing the axis. Like the scale changed by a fraction. I'm still looking into the cause of this - as nothing should have actually changed.

@danielgindi
Copy link
Collaborator

So more info: axis ranges are multiplied by the spacing factor. But when there was startAtZero as a standalone property - the range was subtracted 0.0 instead of min.
It seems like the range does not take into account the customAxisMin (or max)

@danielgindi
Copy link
Collaborator

@PhilJay I've created a PR in MPAndroidChart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants