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

YAxis Labels are clipped with some settings #1233

Closed
aelam opened this issue Jul 8, 2016 · 7 comments
Closed

YAxis Labels are clipped with some settings #1233

aelam opened this issue Jul 8, 2016 · 7 comments

Comments

@aelam
Copy link
Contributor

aelam commented Jul 8, 2016

   _bottomChartView.minOffset = 0;
    ChartYAxis *leftAxis = _bottomChartView.leftAxis;
    leftAxis.labelPosition = YAxisLabelPositionInsideChart;
    leftAxis.showOnlyMinMaxEnabled = YES;
@liuxuan30
Copy link
Member

are you able to explain? If you are someone else looking at this issue, you won't be able to know what are you trying to ask.

@aelam
Copy link
Contributor Author

aelam commented Jul 11, 2016

screen shot 2016-07-11 at 10 43 30 am

With the four settings the maxValue and minValue on YAxis are clipped.

@liuxuan30
Copy link
Member

OK, I just did a quick test, it seems a bug of showOnlyMinMaxEnabled.
BTW, setting minOffset = 0 usually not have any effect, unless you know how it works.

@liuxuan30 liuxuan30 added the bug label Jul 12, 2016
@liuxuan30
Copy link
Member

liuxuan30 commented Jul 12, 2016

I looked into the code, it seems like it's not really a bug but how you use it.
showOnlyMinMaxEnabled is defined as "show only the minimum and maximum value", so it simply take whatever the max and min value are (calculated), and display them.

The issue here is that, you set minOffset = 0, later while calculating the contentRect, the offsetTop value is then 0, which leads to no enough space to show the text:

            _viewPortHandler.restrainViewPort(
                offsetLeft: max(self.minOffset, offsetLeft),
                offsetTop: max(self.minOffset, offsetTop),
                offsetRight: max(self.minOffset, offsetRight),
                offsetBottom: max(self.minOffset, offsetBottom))

here offsetTop is 0, and minOffset is 0, so the final value is 0.
The reason why the text is clipped is because, as the chart rendering area takes most of the chartView frame, the text is being clipped by the chartView bound edge.

I don't think it's a bug here, so you should not set minOffset unless you know how it works, or you can change the code to meet your needs, but as the library, this is not much to fix right now

@liuxuan30 liuxuan30 removed the bug label Jul 12, 2016
@aelam
Copy link
Contributor Author

aelam commented Jul 12, 2016

As I understand, the minOffset is used to set paddings of chart, it's exactly what I want.
And I've found it works differently from Android version
When I set whatever minOffset greater than 0, the labels won't go out of chart rect.(But I still get some 'left Offset' in Android)
Then I set as the following code, the left padding will be zero.

        lineChart.getAxisLeft().setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
        lineChart.setMinOffset(0);
        lineChart.setExtraLeftOffset(40);  

The setting extraLeftOffset is a little weird, I thought -40 can let me get less left padding. but it works opposite, then I tried 40 it works, that I think it's incorrect,

In iOS version, if I set minOffset to 0. I can get no padding of the chart which is what I want, but the clip problem comes up.
SO I think Android version has a problem about extraOffsets, iOS version has a problem about 'label offset', though you don't think it's a problem.
But if you want to take a look of the problem of Android version, I'd like to reproduce it.

@liuxuan30
Copy link
Member

if you think Android portion has issue, you can file a issue and refer this one.

I know you had your understanding based on the name, but if you take a look at the code:

            offsetTop += self.extraTopOffset
            offsetRight += self.extraRightOffset
            offsetBottom += self.extraBottomOffset
            offsetLeft += self.extraLeftOffset

            _viewPortHandler.restrainViewPort(
                offsetLeft: max(self.minOffset, offsetLeft),
                offsetTop: max(self.minOffset, offsetTop),
                offsetRight: max(self.minOffset, offsetRight),
                offsetBottom: max(self.minOffset, offsetBottom))

This is the logic how minOffset and extraOffset works. It basically consider the label space plus extraOffset, and use the bigger one compared to minOffset.

Because you don't have top axis labels, so the offsetTop is 0, and minOffset is 0, this leads to the clipped y labels, plus you only show the max value. The max value is used to define the edge of the chart, so, it's clipped.

I am seeing you only want to set up the left axis, could you explain what you want to achieve? Like you want to use INSIDE_CHART for left label position, but on my side, this will leads to the label overlaps with the bars, which is not a good design. I am guessing you want to have some spaces between the labels and bars?

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 13, 2016

also, please take a look at internal override func calculateOffsets()

when considering if left axis needsOffset, it only check labelPosition == .OutsideChart

So, when you use .InsideDhart, no offset is calculated

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