Skip to content

Commit

Permalink
Merge branch 'master' into pr/90
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris-Em committed Nov 9, 2014
2 parents 743b180 + 2739cce commit 859c806
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 39 deletions.
3 changes: 2 additions & 1 deletion Classes/BEMLine.h
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
15 changes: 11 additions & 4 deletions Classes/BEMSimpleLineGraphView.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,23 @@
@property (nonatomic) BOOL enableYAxisLabel;


/** Show X-Axis label on the side. Default value is NO.
/** Show X-Axis label at the bottom of the graph. Default value is YES.
@see \p labelOnXAxisForIndex
*/
@property (nonatomic) BOOL enableXAxisLabel;

/** When set to YES, the points on the Y-axis will be set to all fit in the graph view. When set to NO, the points on the Y-axis will be set with their absolute value (which means that certain points might not be visible because they are outside of the view). Default value is YES. */
@property (nonatomic) BOOL autoScaleYAxis;


/// Draws a translucent vertical lines along the graph for each X-Axis label, when set to YES. Default value is NO.
@property (nonatomic) BOOL enableReferenceAxisLines;
/// Draws a translucent vertical lines along the graph for each X-Axis when set to YES. Default value is NO.
@property (nonatomic) BOOL enableReferenceXAxisLines;

/// Draws a translucent horizontal lines along the graph for each Y-Axis label, when set to YES. Default value is NO.
@property (nonatomic) BOOL enableReferenceYAxisLines;

/** Draws a translucent frame between the graph and any enabled axis, when set to YES. Default value is NO.
@see enableReferenceAxisLines must be set to YES for this property to have any affect. */
@see enableReferenceXAxisLines or enableReferenceYAxisLines must be set to YES for this property to have any affect. */
@property (nonatomic) BOOL enableReferenceAxisFrame;


Expand Down Expand Up @@ -212,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
27 changes: 17 additions & 10 deletions Classes/BEMSimpleLineGraphView.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ - (void)commonInit {
_enableTouchReport = NO;
_enablePopUpReport = NO;
_enableBezierCurve = NO;
_enableXAxisLabel = NO;
_enableXAxisLabel = YES;
_enableYAxisLabel = NO;
_YAxisLabelXOffset = 0;
_autoScaleYAxis = YES;
Expand Down Expand Up @@ -306,7 +306,7 @@ - (void)layoutTouchReport {
- (void)drawEntireGraph {
// The following method calls are in this specific order for a reason
// Changing the order of the method calls below can result in drawing glitches and even crashes

// Set the Y-Axis Offset if the Y-Axis is enabled. The offset is relative to the size of the longest label on the Y-Axis.
if (self.enableYAxisLabel) {
NSDictionary *attributes = @{NSFontAttributeName: self.labelFont};
Expand All @@ -322,13 +322,13 @@ - (void)drawEntireGraph {
self.YAxisLabelXOffset = [longestString sizeWithAttributes:attributes].width + 5;
}
} else self.YAxisLabelXOffset = 0;

// Draw the X-Axis
[self drawXAxis];

// Draw the graph
[self drawDots];

// Draw the Y-Axis
if (self.enableYAxisLabel) [self drawYAxis];
}
Expand Down Expand Up @@ -447,13 +447,13 @@ - (void)drawLine {
} else {
line.xAxisBackgroundColor = self.colorBackgroundXaxis;
}
if (self.enableReferenceAxisLines == YES) {
if (self.enableReferenceAxisFrame) line.enableRefrenceFrame = YES;
else line.enableRefrenceFrame = NO;
if (self.enableReferenceXAxisLines || self.enableReferenceYAxisLines) {
line.enableRefrenceFrame = self.enableReferenceAxisFrame;

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

line.frameOffset = self.XAxisLabelYOffset;
Expand Down Expand Up @@ -905,6 +905,13 @@ - (NSArray *)graphLabelsForXAxis {
return xAxisLabels;
}

- (void)setAnimationGraphStyle:(BEMLineAnimation)animationGraphStyle
{
_animationGraphStyle = animationGraphStyle;
if (_animationGraphStyle == BEMLineAnimationNone)
self.animationGraphEntranceTime = 0.f;
}


#pragma mark - Touch Gestures

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ The other way to install <b>BEMSimpleLineGraph</b>, is to drag and drop the *Cla
####Swift Projects
To use <b>BEMSimpleLineGraph</b> in a Swift project add the following to your bridging header:

#import "BEMSimpleLineGraph.h"
#import "BEMSimpleLineGraphView.h”

### Setup
Setting up <b>BEMSimpleLineGraph</b> in your project is simple. If you're familiar with UITableView, then <b>BEMSimpleLineGraph </b>should be a breeze. Follow the steps below to get everything up and running.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@
<string>SimpleLineChart</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>0A440630-CD17-4098-B4B4-CB6D9CEA2228</key>
<key>1CA8AD815677B6FB0DD135F65EC4576AE68426CF</key>
<string>https://github.com/Boris-Em/BEMSimpleLineGraph.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>Sample Project/SimpleLineChart.xcodeproj/project.xcworkspace</string>
<string>Sample Project/SimpleLineChart.xcodeproj</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>0A440630-CD17-4098-B4B4-CB6D9CEA2228</key>
<key>1CA8AD815677B6FB0DD135F65EC4576AE68426CF</key>
<string>../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/Boris-Em/BEMSimpleLineGraph.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>0A440630-CD17-4098-B4B4-CB6D9CEA2228</string>
<string>1CA8AD815677B6FB0DD135F65EC4576AE68426CF</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>0A440630-CD17-4098-B4B4-CB6D9CEA2228</string>
<string>1CA8AD815677B6FB0DD135F65EC4576AE68426CF</string>
<key>IDESourceControlWCCName</key>
<string>BEMSimpleLineGraph</string>
</dict>
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion Sample Project/SimpleLineChart/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ - (void)viewDidLoad {
self.myGraph.enableYAxisLabel = YES;
self.myGraph.autoScaleYAxis = YES;
self.myGraph.alwaysDisplayDots = NO;
self.myGraph.enableReferenceAxisLines = YES;
self.myGraph.enableReferenceXAxisLines = YES;
self.myGraph.enableReferenceYAxisLines = YES;
self.myGraph.enableReferenceAxisFrame = YES;
self.myGraph.animationGraphStyle = BEMLineAnimationDraw;

Expand Down

0 comments on commit 859c806

Please sign in to comment.