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

Reference line color & draw order #88

Merged
merged 2 commits into from Nov 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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