BEMSimpleLineGraph icon indicating copy to clipboard operation
BEMSimpleLineGraph copied to clipboard

Strange drawing result

Open duzenko opened this issue 9 years ago • 2 comments

Hi, I'm new to this library. I'm trying to get a partial graph. The result is almost right - except for the white triangle where the the partial line ends. My code is very basic: total 8 points, two of them have data and others are left out

- (NSInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView *)graph {
    NSIndexPath *indexPath = graphLinks[graph];
    NSDictionary *indicator = [self findIndicator:indexPath];
    NSArray *values = indicator[@"graphData"][@"labels"];
    return values.count;
}

- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSInteger)index {
    NSIndexPath *indexPath = graphLinks[graph];
    NSDictionary *indicator = [self findIndicator:indexPath];
    NSArray *values = indicator[@"graphData"][@"values"];
    if (values.count > index) {
        return [values[index] floatValue];
    } else
        return BEMNullGraphValue;
}

simulator screen shot apr 11 2016 7 36 10 pm

duzenko avatar Apr 11 '16 16:04 duzenko

The culprit seems to be the bottomPointsArray method. My workaround below:

- (NSArray *)bottomPointsArray {
    CGPoint bottomPointZero = CGPointMake(0, self.frame.size.height);
    CGPoint bottomPointFull = CGPointMake(self.frame.size.width, self.frame.size.height);
    NSMutableArray *bottomPoints = [NSMutableArray arrayWithArray:self.points];
    [bottomPoints insertObject:[NSValue valueWithCGPoint:bottomPointZero] atIndex:0];

// add one point to complete the polygon
    CGPoint oneMore = CGPointMake(self.frame.size.width, 0);
    [bottomPoints addObject:[NSValue valueWithCGPoint:oneMore]];

    [bottomPoints addObject:[NSValue valueWithCGPoint:bottomPointFull]];
    return bottomPoints;
}

duzenko avatar Apr 12 '16 09:04 duzenko

I needed to change the visuals so now my code looks like this

- (NSArray *)bottomPointsArray {
    CGPoint bottomPointZero = CGPointMake(0, self.frame.size.height);
//    CGPoint bottomPointFull = CGPointMake(self.frame.size.width, self.frame.size.height);
    CGPoint bottomPointFull = [self.points.lastObject CGPointValue];
    bottomPointFull.y = self.frame.size.height;
    NSMutableArray *bottomPoints = [NSMutableArray arrayWithArray:self.points];
    [bottomPoints insertObject:[NSValue valueWithCGPoint:bottomPointZero] atIndex:0];
    [bottomPoints addObject:[NSValue valueWithCGPoint:bottomPointFull]];
    return bottomPoints;
}

simulator screen shot jun 12 2016 2 13 07 pm

duzenko avatar Jun 12 '16 11:06 duzenko