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

HorizontalBarChartView drawValueAboveBarEnabled label rendering issue #124

Open
mcooksey opened this issue Jun 1, 2015 · 7 comments
Open

Comments

@mcooksey
Copy link

mcooksey commented Jun 1, 2015

When i set my HorizontalBarChartView's drawValueAboveBarEnabled to false, I get the following layout issue when the BarChart has a y Value too small to fit the value label

capture

In this case, I set the third bar to have a value of 1.00.

Do you have any ideas of how I can get that label to render on the right side of the bar instead of the left?

@danielgindi danielgindi added the bug label Jun 2, 2015
@danielgindi
Copy link
Collaborator

@PhilJay I'm thinking if label width > bar width (horz) or if label height > bar height (vert) - draw above bar...

@mcooksey
Copy link
Author

mcooksey commented Jun 3, 2015

@danielgindi Was wondering if you could point me in the right direction of where that label would be drawn. I was going to experiment a little bit and see if I could fix this myself, but I can't seem to find what I'm looking for.

Thanks in advance!

@mcooksey
Copy link
Author

@danielgindi in order to fix this, i compared the valueTextWidth to the actual value of the BarChartDataEntry, as the width of the bar seems to be equal to the value of data entry.

Starting at line 358 of HorizontalBarChartRenderer, I did the following:

    // calculate the correct offset depending on the draw position of the value
    var valueTextWidth = valueText.sizeWithAttributes([NSFontAttributeName: valueFont]).width
    if (Double(valueTextWidth)> val && !drawValueAboveBar) 
    {
         //use the offset for drawValueAboveBar = true
         posOffset = valueOffsetPlus
         negOffset = -(valueTextWidth + valueOffsetPlus)
    }
    else 
    {
         posOffset = (drawValueAboveBar ? valueOffsetPlus : -(valueTextWidth + valueOffsetPlus))
         negOffset = (drawValueAboveBar ? -(valueTextWidth + valueOffsetPlus) : valueOffsetPlus)
    }

I'm sure the same fix could work for the vertical bar charts, just with height instead of width, but I'm not familiar with them, as I'm not using vertical bar charts with labels in my project.

If you want to let me know where you think this fix would need to be implemented, I can try to get a pull request done, otherwise I can make a pull request just for this one.

@iosware
Copy link

iosware commented Aug 1, 2015

@mcooksey It seems this fix doesn't work.
screenshot

@mcooksey
Copy link
Author

mcooksey commented Aug 3, 2015

@pashikua What version of ios-charts are you on? I haven't had a chance to try it on the latest code base.

@iosware
Copy link

iosware commented Aug 4, 2015

@mcooksey I used latest source.

@dhaneshgosai
Copy link

is there any update on above bug ?

I am not able to see label on Bar while i use Horizontal Bar in my app.

Thanks in advance!

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

No branches or pull requests

4 participants