-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Barchart label offset when its text is too long #3800
Comments
where is the overlap? Not seeing it |
@liuxuan30 if text is long enough, it will overlap |
hmm.. seems a bug that didn't get the right rotated width |
but I'm not sure when we have time to look into. if you have time and willing to try it out, please go ahead and maybe you can find the fix. or just wait :( |
I've taken a look into renderer and found out that the reason of such behaviour is in selection of anchor point. For
And the result would look like this (now top right corner of the text frame is right below the grid line): @jjatie @liuxuan30 what do you think of these two changes? (I can create a PR, but it requires some more work then I've already done on it, so I'd prefer discussing it first) @LeeJoey77 You can make these changes in your app by overriding |
@anton-filimonov thanks for helping out! @objc open func computeSize()
{
guard let
xAxis = self.axis as? XAxis
else { return }
let longest = xAxis.getLongestLabel()
let labelSize = longest.size(withAttributes: [NSAttributedString.Key.font: xAxis.labelFont])
let labelWidth = labelSize.width
let labelHeight = labelSize.height
let labelRotatedSize = labelSize.rotatedBy(degrees: xAxis.labelRotationAngle)
xAxis.labelWidth = labelWidth
xAxis.labelHeight = labelHeight
xAxis.labelRotatedWidth = labelRotatedSize.width
xAxis.labelRotatedHeight = labelRotatedSize.height
} I'm thinking the bug comes from If you were able to use the rotated label size, you don't have to add a parameter? anyway, if we can fix the overlap issue, you are welcome to file a PR that you think is best suitable. BTW, I search a little that seems overlaping is always an issue that's not fixed no matter what. e.g. #1969. if we can fix them once and for all that's even better. but take your time. we don't want to force you |
I took a look that what I said
seems totally gone or I am wrong. Currently labelCount is entirely a property for user to control. It will just display without considering overlap, so it seems user's duty to not to use too many labels. but the problem exists that if the formatted label is too long, it will overlap anyway? @jjatie should we bring the feature to avoid overlap? or you think it's users' duty to control the label count and overlap? and we only have to care about if @anton-filimonov's change is valid to address some bugs in rotation? |
What did you do?
barchart label offset when its text is too long, and may overlap next label if long enough.
Charts version: V3.2.1
Xcode version: 10.1
Swift version: 4.2
Demo Project
`
let xAxis = chartView.xAxis
xAxis.axisLineWidth = 1
xAxis.labelPosition = .bottom
xAxis.labelRotationAngle = CGFloat(-50)
xAxis.labelRotatedHeight = CGFloat(120)
xAxis.drawGridLinesEnabled = false
xAxis.forceLabelsEnabled = false
xAxis.labelTextColor = UIColor.black
xAxis.labelFont = UIFont.systemFont(ofSize: 13)
xAxis.granularity = 1
xAxis.labelCount = xValues.count
xAxis.valueFormatter = self`
`
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
if Int(value) == 4 {
return "fadafadfadfafdafafadffadf"
}
return xValues[(Int(value)) % xValues.count]
}
`
The text was updated successfully, but these errors were encountered: