Skip to content

Commit

Permalink
Fixed the way the bottom & top part of the graph are drawn with Bezie…
Browse files Browse the repository at this point in the history
…r Curves
  • Loading branch information
Boris-Em committed Feb 24, 2014
1 parent 78448d0 commit 6d72cb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions Classes/BEMLine.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,56 @@ - (id)initWithFrame:(CGRect)frame {
}

- (void)drawRect:(CGRect)rect {
// FILL TOP

CGPoint CP1;
CGPoint CP2;

if (self.bezierCurveIsEnabled == YES) { // BEZIER CURVE
CP1 = CGPointMake(self.P1.x + (self.P2.x - self.P1.x)/3, self.P1.y - (self.P1.y - self.P2.y)/3 - (self.P0.y - self.P1.y)*0.3); // First control point
CP2 = CGPointMake(self.P1.x + 2*(self.P2.x - self.P1.x)/3, (self.P1.y - 2*(self.P1.y - self.P2.y)/3) + (self.P2.y - self.P3.y)*0.3); // Second control point
}

CGContextRef ctx = UIGraphicsGetCurrentContext();


// FILL TOP

CGContextSetFillColorWithColor(ctx, [self.topColor CGColor]);
CGContextSetAlpha(ctx, self.topAlpha);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, round(self.P1.x), self.P1.y);
CGContextAddLineToPoint(ctx, round(self.P2.x), self.P2.y);
if (self.bezierCurveIsEnabled == YES) {
CGContextAddCurveToPoint(ctx, CP1.x, CP1.y, CP2.x, CP2.y, self.P2.x, self.P2.y);
} else {
CGContextAddLineToPoint(ctx, round(self.P2.x), self.P2.y);
}
CGContextAddLineToPoint(ctx, round(self.P2.x), self.frame.origin.y);
CGContextAddLineToPoint(ctx, round(self.P1.x), self.frame.origin.x);
CGContextClosePath(ctx);

CGContextDrawPath(ctx, kCGPathFill);

// FILL BOTOM
CGContextSetFillColorWithColor(ctx, [self.bottomColor CGColor]);
CGContextSetAlpha(ctx, self.bottomAlpha);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, round(self.P1.x), self.P1.y);
CGContextAddLineToPoint(ctx, round(self.P2.x), self.P2.y);
if (self.bezierCurveIsEnabled == YES) {
CGContextAddCurveToPoint(ctx, CP1.x, CP1.y, CP2.x, CP2.y, self.P2.x, self.P2.y);
} else {
CGContextAddLineToPoint(ctx, round(self.P2.x), self.P2.y);
}
CGContextAddLineToPoint(ctx, round(self.P2.x), self.frame.size.height);
CGContextAddLineToPoint(ctx, round(self.P1.x), self.frame.size.height);
CGContextClosePath(ctx);

CGContextDrawPath(ctx, kCGPathFill);

//BEZIER CURVE

CGContextDrawPath(ctx, kCGPathFill);
UIBezierPath *path1 = [UIBezierPath bezierPath];
[path1 setLineWidth:self.lineWidth];
[path1 moveToPoint:self.P1];

if (self.bezierCurveIsEnabled == YES) { // BEZIER CURVE
CGPoint CP1 = CGPointMake(self.P1.x + (self.P2.x - self.P1.x)/3, self.P1.y - (self.P1.y - self.P2.y)/3 - (self.P0.y - self.P1.y)*0.3); // First control point
CGPoint CP2 = CGPointMake(self.P1.x + 2*(self.P2.x - self.P1.x)/3, (self.P1.y - 2*(self.P1.y - self.P2.y)/3) + (self.P2.y - self.P3.y)*0.3); // Second control point
[path1 addCurveToPoint:self.P2 controlPoint1:CP1 controlPoint2:CP2];
} else { // SIMPLE LINE
[path1 addLineToPoint:self.P2];
Expand Down
Binary file not shown.

0 comments on commit 6d72cb6

Please sign in to comment.