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

Commit

Permalink
Merge pull request #88 from gavinbunney/master
Browse files Browse the repository at this point in the history
Reference line color & draw order
  • Loading branch information
Boris-Em committed Nov 3, 2014
2 parents aee4ad1 + 76c5f9f commit 63bab0d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Classes/BEMLine.h
Expand Up @@ -90,7 +90,8 @@ typedef NS_ENUM(NSInteger, BEMLineAnimation) {
@todo This property is non-functional at this point in time. It only serves as a marker for further implementation. */
@property (assign, nonatomic) CGGradientRef gradient;


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

//----- ALPHA -----//

Expand Down
45 changes: 29 additions & 16 deletions Classes/BEMLine.m
Expand Up @@ -189,16 +189,41 @@ - (void)drawRect:(CGRect)rect {
// ----- Animate Drawing -----//
// ---------------------------//
if (self.animationTime == 0) {
[self.color set];
if (self.enableRefrenceLines == YES) {
[referenceLinesPath setLineWidth:self.lineWidth/2];

if (self.refrenceLineColor) {
[self.refrenceLineColor set];
} else {
[self.color set];
}

[referenceLinesPath strokeWithBlendMode:kCGBlendModeNormal alpha:self.lineAlpha/2];
}

[self.color set];
[line setLineWidth:self.lineWidth];
[line strokeWithBlendMode:kCGBlendModeNormal alpha:self.lineAlpha];

} else {
if (self.enableRefrenceLines == YES) {
[referenceLinesPath setLineWidth:self.lineWidth/2];
[referenceLinesPath strokeWithBlendMode:kCGBlendModeNormal alpha:self.lineAlpha/2];
CAShapeLayer *referenceLinesPathLayer = [CAShapeLayer layer];
referenceLinesPathLayer.frame = self.bounds;
referenceLinesPathLayer.path = referenceLinesPath.CGPath;
referenceLinesPathLayer.opacity = self.lineAlpha/2;
referenceLinesPathLayer.fillColor = nil;
referenceLinesPathLayer.lineWidth = self.lineWidth/2;

if (self.refrenceLineColor) {
referenceLinesPathLayer.strokeColor = self.refrenceLineColor.CGColor;
} else {
referenceLinesPathLayer.strokeColor = self.color.CGColor;
}

[self animateForLayer:referenceLinesPathLayer withAnimationType:self.animationType isAnimatingReferenceLine:YES];
[self.layer addSublayer:referenceLinesPathLayer];
}
} else {
CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = self.bounds;
pathLayer.path = line.CGPath;
Expand All @@ -209,18 +234,6 @@ - (void)drawRect:(CGRect)rect {
pathLayer.lineCap = kCALineCapRound;
[self animateForLayer:pathLayer withAnimationType:self.animationType isAnimatingReferenceLine:NO];
[self.layer addSublayer:pathLayer];

if (self.enableRefrenceLines == YES) {
CAShapeLayer *referenceLinesPathLayer = [CAShapeLayer layer];
referenceLinesPathLayer.frame = self.bounds;
referenceLinesPathLayer.path = referenceLinesPath.CGPath;
referenceLinesPathLayer.opacity = self.lineAlpha/2;
referenceLinesPathLayer.strokeColor = self.color.CGColor;
referenceLinesPathLayer.fillColor = nil;
referenceLinesPathLayer.lineWidth = self.lineWidth/2;
[self animateForLayer:referenceLinesPathLayer withAnimationType:self.animationType isAnimatingReferenceLine:YES];
[self.layer addSublayer:referenceLinesPathLayer];
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions Classes/BEMSimpleLineGraphView.h
Expand Up @@ -216,6 +216,9 @@
/// Width of the line of the graph. Default value is 1.0.
@property (nonatomic) CGFloat widthLine;

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


/// The size of the circles that represent each point. Default is 10.0.
@property (nonatomic) CGFloat sizePoint;
Expand Down
1 change: 1 addition & 0 deletions Classes/BEMSimpleLineGraphView.m
Expand Up @@ -441,6 +441,7 @@ - (void)drawLine {
line.enableRefrenceFrame = self.enableReferenceAxisFrame;

line.enableRefrenceLines = YES;
line.refrenceLineColor = self.colorReferenceLines;
line.arrayOfVerticalRefrenceLinePoints = self.enableReferenceXAxisLines ? xAxisLabelPoints : nil;
line.arrayOfHorizontalRefrenceLinePoints = self.enableReferenceYAxisLines ? yAxisLabelPoints : nil;
}
Expand Down

0 comments on commit 63bab0d

Please sign in to comment.