-
-
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
Horizontal Bar Bounds #2515
Comments
Actually First, where do you set your I compared horizontal bar chart's
if !containsStacks || vals == nil
{
let bottom = CGFloat(x - barWidthHalf)
let top = CGFloat(x + barWidthHalf)
var right = isInverted
? (y <= 0.0 ? CGFloat(y) : 0)
: (y >= 0.0 ? CGFloat(y) : 0)
var left = isInverted
? (y >= 0.0 ? CGFloat(y) : 0)
: (y <= 0.0 ? CGFloat(y) : 0)
// multiply the height of the rect with the phase
if right > 0
{
right *= CGFloat(phaseY)
}
else
{
left *= CGFloat(phaseY)
}
barRect.origin.x = left
barRect.size.width = right - left
barRect.origin.y = top
barRect.size.height = bottom - top
buffer.rects[bufferIndex] = barRect
bufferIndex += 1
} vs. open override func getBarBounds(entry e: BarChartDataEntry) -> CGRect
{
guard
let data = _data as? BarChartData,
let set = data.getDataSetForEntry(e) as? IBarChartDataSet
else { return CGRect.null }
let y = e.y
let x = e.x
let barWidth = data.barWidth
let top = x - 0.5 + barWidth / 2.0
let bottom = x + 0.5 - barWidth / 2.0
let left = y >= 0.0 ? y : 0.0
let right = y <= 0.0 ? y : 0.0
var bounds = CGRect(x: left, y: top, width: right - left, height: bottom - top)
getTransformer(forAxis: set.axisDependency).rectValueToPixel(&bounds)
return bounds
} I think it's a bug, but I don't know why there is a method for getting bar bounds. |
@danielgindi do you remember why +- 0.5 in horizontal bar chart @AaronVinh can you help verify, if you just remove +-0.5 in getBarBounds, will it fix your issue? If so, seems we have a simple clean fix for this issue. |
After some digging, found out you have to add the So yes it's buggy using getBarBounds as it's not the same as what in renderer code. I will check how to make a full fix. open override func getBarBounds(entry e: BarChartDataEntry) -> CGRect
{
guard
let data = _data as? BarChartData,
let set = data.getDataSetForEntry(e) as? IBarChartDataSet
else { return CGRect.null }
let y = e.y
let x = e.x
let isInverted = self.isInverted(axis: set.axisDependency)
let barWidth = data.barWidth
let top = x + barWidth / 2.0
let bottom = x - barWidth / 2.0
let right = isInverted
? (y <= 0.0 ? y : 0.0)
: (y >= 0.0 ? y : 0.0)
let left = isInverted
? (y >= 0.0 ? y : 0.0)
: (y <= 0.0 ? y : 0.0)
var bounds = CGRect(x: left, y: top, width: right - left, height: bottom - top)
getTransformer(forAxis: set.axisDependency).rectValueToPixel(&bounds)
return bounds
} also, you have to be careful that you must add the layers after the You can setup a delay like: dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
for (int i = 0; i < yVals.count; i++) {
ChartDataEntry *entry = [set1 entryForIndex:i];
if (entry != nil) {
CGRect bound = [_chartView getBarBoundsWithEntry:entry];
CAGradientLayer *layer = [CAGradientLayer layer];
[layer setFrame:bound];
layer.colors = @[(id)[UIColor redColor].CGColor, (id)[UIColor greenColor].CGColor];
layer.startPoint = CGPointMake(0.0, 0.5);
layer.endPoint = CGPointMake(1.0, 0.5);
[_chartView.layer addSublayer:layer];
}
}
}); or set a observer when the matrix is fully set after calling |
is this possible using CombinedChartView()? |
I believe that the getBarBounds function is bugged. I am trying to draw a gradient layer over each bar by grabbing the bounds for each bar. Here is my code
`
var chartEntries = BarChartDataEntry
you can see in the screenshot the actualy bars in the light blue color and the gradient layer on top of them. The gradient layers' positions are off as well as the wrong size. Am I misunderstanding how the getBounds functions works or is it bugged?
The text was updated successfully, but these errors were encountered: