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

avoidFirstLastClippingEnabled broken between versions #2429

Open
Zarwan opened this issue Nov 1, 2016 · 5 comments
Open

avoidFirstLastClippingEnabled broken between versions #2429

Zarwan opened this issue Nov 1, 2016 · 5 comments

Comments

@Zarwan
Copy link

Zarwan commented Nov 1, 2016

I'm trying to upgrade from 2.2.5 to the new release. My last label is getting cut off because the alignment has changed. I've tried using avoidFirstLastClippingEnabled but it didn't seem to do anything. I also tried adding offsets on either side but this moves the entire graph, not just the labels.

Before updating:
screen shot 2016-11-01 at 5 06 18 pm

After updating:
screen shot 2016-11-01 at 5 06 24 pm

@Zarwan
Copy link
Author

Zarwan commented Nov 1, 2016

Okay after some more research it seems that avoidFirstLastClippingEnabled was broken between versions. I went back to 2.2.5 and deleted avoidFirstLastClippingEnabled(true) and got the same result I'm getting on 3.0.0 with the call there.

However, note that only the last label has the incorrect alignment; the first one is fine. If I remove the call in 2.2.5 both labels have incorrect alignment.

I am calling setLabelCount(2, true) on my x-axis as well.

@Zarwan Zarwan changed the title Label alignment changed in different versions causing clipping avoidFirstLastClippingEnabled broken between versions Nov 1, 2016
@Zarwan Zarwan closed this as completed Nov 1, 2016
@Zarwan Zarwan reopened this Nov 1, 2016
@Zarwan
Copy link
Author

Zarwan commented Nov 2, 2016

After debugging a bit, I think the problem is in XAxisRenderer.

for (int i = 0; i < positions.length; i += 2) {

    float x = positions[i];

    if (mViewPortHandler.isInBoundsX(x)) {

        String label = mXAxis.getValueFormatter().getFormattedValue(mXAxis.mEntries[i / 2], mXAxis);

        if (mXAxis.isAvoidFirstLastClippingEnabled()) {

            // avoid clipping of the last
            if (i == mXAxis.mEntryCount - 1 && mXAxis.mEntryCount > 1) {
                float width = Utils.calcTextWidth(mAxisLabelPaint, label);

                if (width > mViewPortHandler.offsetRight() * 2
                        && x + width > mViewPortHandler.getChartWidth())
                    x -= width / 2;

                // avoid clipping of the first
            } else if (i == 0) {

                float width = Utils.calcTextWidth(mAxisLabelPaint, label);
                x += width / 2;
            }
        }

        drawLabel(c, label, x, pos, anchor, labelRotationAngleDegrees);
    }
}

Since i is being incremented by 2, it will never equal mXAxis.mEntryCount - 1 unless the number of entries is odd, so the clipping logic won't be applied. @PhilJay

The problem isn't in 2.2.5 because I didn't need the call to setLabelCount, I just had a label for every value which was blank except for the first and last one.

@eapache
Copy link

eapache commented Nov 10, 2016

Possibly 3928e28 ?

@eapache
Copy link

eapache commented Jan 5, 2017

Still broken in 3.0.1.

@Zarwan
Copy link
Author

Zarwan commented Jan 16, 2017

I didn't look into this in detail, but maybe a fix for the same issue? @eapache #2719

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

2 participants