@@ -33,6 +33,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
3333 _enableLeftReferenceFrameLine = YES ;
3434 _enableBottomReferenceFrameLine = YES ;
3535 _interpolateNullValues = YES ;
36+ self.clipsToBounds = YES ;
3637 }
3738 return self;
3839}
@@ -59,8 +60,8 @@ - (void)drawRect:(CGRect)rect {
5960 if (self.enableReferenceFrame == YES ) {
6061 if (self.enableBottomReferenceFrameLine ) {
6162 // Bottom Line
62- [referenceFramePath moveToPoint: CGPointMake (0 , self .frame.size.height)];
63- [referenceFramePath addLineToPoint: CGPointMake (self .frame.size.width, self .frame.size.height)];
63+ [referenceFramePath moveToPoint: CGPointMake (0 , self .frame.size.height- self .referenceLineWidth/ 4 )];
64+ [referenceFramePath addLineToPoint: CGPointMake (self .frame.size.width, self .frame.size.height- self .referenceLineWidth/ 4 )];
6465 }
6566
6667 if (self.enableLeftReferenceFrameLine ) {
@@ -71,8 +72,8 @@ - (void)drawRect:(CGRect)rect {
7172
7273 if (self.enableTopReferenceFrameLine ) {
7374 // Top Line
74- [referenceFramePath moveToPoint: CGPointMake (0 +self .referenceLineWidth/4 , 0 )];
75- [referenceFramePath addLineToPoint: CGPointMake (self .frame.size.width, 0 )];
75+ [referenceFramePath moveToPoint: CGPointMake (0 +self .referenceLineWidth/4 , self .referenceLineWidth/ 4 )];
76+ [referenceFramePath addLineToPoint: CGPointMake (self .frame.size.width, self .referenceLineWidth/ 4 )];
7677 }
7778
7879 if (self.enableRightReferenceFrameLine ) {
@@ -192,12 +193,12 @@ - (void)drawRect:(CGRect)rect {
192193 fillBottom = [BEMLine quadCurvedPathWithPoints: self .bottomPointsArray open: NO ];
193194 fillTop = [BEMLine quadCurvedPathWithPoints: self .topPointsArray open: NO ];
194195 } else if (!self.disableMainLine && !self.bezierCurveIsEnabled ) {
195- line = [BEMLine linesToPoints: self .points];
196- fillBottom = [BEMLine linesToPoints: self .bottomPointsArray];
197- fillTop = [BEMLine linesToPoints: self .topPointsArray];
196+ line = [BEMLine linesToPoints: self .points open: YES ];
197+ fillBottom = [BEMLine linesToPoints: self .bottomPointsArray open: NO ];
198+ fillTop = [BEMLine linesToPoints: self .topPointsArray open: NO ];
198199 } else {
199- fillBottom = [BEMLine linesToPoints: self .bottomPointsArray];
200- fillTop = [BEMLine linesToPoints: self .topPointsArray];
200+ fillBottom = [BEMLine linesToPoints: self .bottomPointsArray open: NO ];
201+ fillTop = [BEMLine linesToPoints: self .topPointsArray open: NO ];
201202 }
202203
203204 // ----------------------------//
@@ -340,15 +341,22 @@ - (void)drawRect:(CGRect)rect {
340341 return bottomPoints;
341342}
342343
343- + (UIBezierPath *)linesToPoints : (NSArray <NSValue *> *)points {
344+ + (UIBezierPath *)linesToPoints : (NSArray <NSValue *> *)points open : ( BOOL ) canSkipPoints {
344345 UIBezierPath *path = [UIBezierPath bezierPath ];
345346 NSValue *value = points[0 ];
346347 CGPoint p1 = [value CGPointValue ];
347348 [path moveToPoint: p1];
348349
349350 for (NSValue * point in points) {
351+ if (point == value) continue ; // already at first point
350352 CGPoint p2 = [point CGPointValue ];
351- [path addLineToPoint: p2];
353+
354+ if (canSkipPoints && (p1.y >= BEMNullGraphValue || p2.y >= BEMNullGraphValue)) {
355+ [path moveToPoint: p2];
356+ } else {
357+ [path addLineToPoint: p2];
358+ }
359+ p1 = p2;
352360 }
353361 return path;
354362}
0 commit comments