Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 63bab0d

Browse files
committed
Merge pull request #88 from gavinbunney/master
Reference line color & draw order
2 parents aee4ad1 + 76c5f9f commit 63bab0d

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

Classes/BEMLine.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ typedef NS_ENUM(NSInteger, BEMLineAnimation) {
9090
@todo This property is non-functional at this point in time. It only serves as a marker for further implementation. */
9191
@property (assign, nonatomic) CGGradientRef gradient;
9292

93-
93+
/// The reference line color. Defaults to `color`.
94+
@property (strong, nonatomic) UIColor *refrenceLineColor;
9495

9596
//----- ALPHA -----//
9697

Classes/BEMLine.m

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,41 @@ - (void)drawRect:(CGRect)rect {
189189
// ----- Animate Drawing -----//
190190
// ---------------------------//
191191
if (self.animationTime == 0) {
192-
[self.color set];
192+
if (self.enableRefrenceLines == YES) {
193+
[referenceLinesPath setLineWidth:self.lineWidth/2];
194+
195+
if (self.refrenceLineColor) {
196+
[self.refrenceLineColor set];
197+
} else {
198+
[self.color set];
199+
}
200+
201+
[referenceLinesPath strokeWithBlendMode:kCGBlendModeNormal alpha:self.lineAlpha/2];
202+
}
193203

204+
[self.color set];
194205
[line setLineWidth:self.lineWidth];
195206
[line strokeWithBlendMode:kCGBlendModeNormal alpha:self.lineAlpha];
196207

208+
} else {
197209
if (self.enableRefrenceLines == YES) {
198-
[referenceLinesPath setLineWidth:self.lineWidth/2];
199-
[referenceLinesPath strokeWithBlendMode:kCGBlendModeNormal alpha:self.lineAlpha/2];
210+
CAShapeLayer *referenceLinesPathLayer = [CAShapeLayer layer];
211+
referenceLinesPathLayer.frame = self.bounds;
212+
referenceLinesPathLayer.path = referenceLinesPath.CGPath;
213+
referenceLinesPathLayer.opacity = self.lineAlpha/2;
214+
referenceLinesPathLayer.fillColor = nil;
215+
referenceLinesPathLayer.lineWidth = self.lineWidth/2;
216+
217+
if (self.refrenceLineColor) {
218+
referenceLinesPathLayer.strokeColor = self.refrenceLineColor.CGColor;
219+
} else {
220+
referenceLinesPathLayer.strokeColor = self.color.CGColor;
221+
}
222+
223+
[self animateForLayer:referenceLinesPathLayer withAnimationType:self.animationType isAnimatingReferenceLine:YES];
224+
[self.layer addSublayer:referenceLinesPathLayer];
200225
}
201-
} else {
226+
202227
CAShapeLayer *pathLayer = [CAShapeLayer layer];
203228
pathLayer.frame = self.bounds;
204229
pathLayer.path = line.CGPath;
@@ -209,18 +234,6 @@ - (void)drawRect:(CGRect)rect {
209234
pathLayer.lineCap = kCALineCapRound;
210235
[self animateForLayer:pathLayer withAnimationType:self.animationType isAnimatingReferenceLine:NO];
211236
[self.layer addSublayer:pathLayer];
212-
213-
if (self.enableRefrenceLines == YES) {
214-
CAShapeLayer *referenceLinesPathLayer = [CAShapeLayer layer];
215-
referenceLinesPathLayer.frame = self.bounds;
216-
referenceLinesPathLayer.path = referenceLinesPath.CGPath;
217-
referenceLinesPathLayer.opacity = self.lineAlpha/2;
218-
referenceLinesPathLayer.strokeColor = self.color.CGColor;
219-
referenceLinesPathLayer.fillColor = nil;
220-
referenceLinesPathLayer.lineWidth = self.lineWidth/2;
221-
[self animateForLayer:referenceLinesPathLayer withAnimationType:self.animationType isAnimatingReferenceLine:YES];
222-
[self.layer addSublayer:referenceLinesPathLayer];
223-
}
224237
}
225238
}
226239

Classes/BEMSimpleLineGraphView.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@
216216
/// Width of the line of the graph. Default value is 1.0.
217217
@property (nonatomic) CGFloat widthLine;
218218

219+
/// Color of the reference lines of the graph. Default is same color as `colorLine`.
220+
@property (strong, nonatomic) UIColor *colorReferenceLines;
221+
219222

220223
/// The size of the circles that represent each point. Default is 10.0.
221224
@property (nonatomic) CGFloat sizePoint;

Classes/BEMSimpleLineGraphView.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ - (void)drawLine {
441441
line.enableRefrenceFrame = self.enableReferenceAxisFrame;
442442

443443
line.enableRefrenceLines = YES;
444+
line.refrenceLineColor = self.colorReferenceLines;
444445
line.arrayOfVerticalRefrenceLinePoints = self.enableReferenceXAxisLines ? xAxisLabelPoints : nil;
445446
line.arrayOfHorizontalRefrenceLinePoints = self.enableReferenceYAxisLines ? yAxisLabelPoints : nil;
446447
}

0 commit comments

Comments
 (0)