Skip to content

Commit

Permalink
VBPiePiece - made fully private, and all members are readonly
Browse files Browse the repository at this point in the history
from float -> double
some little more commnets
  • Loading branch information
sakrist committed Jan 20, 2016
1 parent 4a6585b commit 2c4f3af
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 81 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#### [1.1.0] - 2016-20-01
* `VBPiePiece` - made fully private, and all members are `readonly`
* from float -> double
* some little more commnets

#### [1.0.0] - 2016-19-01
* UIColor+HexColor - moved out of pod
* new documentation for `VBPieChart` class
Expand Down
13 changes: 6 additions & 7 deletions VBPieChart.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "VBPieChart"
s.version = "1.0.0"
s.version = "1.1.0"
s.summary = "Pie Chart with different animations to present."

s.description = <<-DESC
Expand All @@ -38,7 +38,6 @@ Pod::Spec.new do |s|
#

s.license = { :type => "MIT", :file => "README.md" }
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }


# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand All @@ -51,9 +50,9 @@ Pod::Spec.new do |s|
# profile URL.
#

s.author = "Volodymyr Boichentsov"
# s.author = "Volodymyr Boichentsov"
# Or just: s.author = "Volodymyr Boichentsov"
# s.authors = { "Volodymyr Boichentsov" => "[email protected]" }
s.authors = { "Volodymyr Boichentsov" => "[email protected]" }
s.social_media_url = "http://twitter.com/sakrist"

# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand All @@ -76,7 +75,7 @@ Pod::Spec.new do |s|
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/sakrist/VBPieChart.git", :tag => "1.0.0" }
s.source = { :git => "https://github.com/sakrist/VBPieChart.git", :tag => "1.1.0" }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand All @@ -90,7 +89,7 @@ Pod::Spec.new do |s|
s.source_files = "VBPieChart/Classes", "VBPieChart/Classes/*.{h,m}"
#s.exclude_files = "Classes/Exclude"

# s.public_header_files = "Classes/**/*.h"
s.public_header_files = "VBPieChart/Classes/VBPieChart.h"


# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand All @@ -113,7 +112,7 @@ Pod::Spec.new do |s|
# the lib prefix of their name.
#

s.framework = "QuartzCore"
s.frameworks = "UIKit", "QuartzCore"
# s.frameworks = "SomeFramework", "AnotherFramework"

# s.library = "iconv"
Expand Down
15 changes: 8 additions & 7 deletions VBPieChart/Classes/VBPieChart.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,30 @@ typedef CGPoint (^VBLabelBlock)(CALayer*layer, NSInteger index);
@abstract Hole in center of diagram, precent of radius
@note Default is 0.2, from 0 to 1
*/
@property (nonatomic) float holeRadiusPrecent;
@property (nonatomic) double holeRadiusPrecent;

/*!
@abstract Radius of diagram dependce to view size
@note Default is 0.9, possible value from 0 to 1.
*/
@property (nonatomic) float radiusPrecent;
@property (nonatomic) double radiusPrecent;

/*!
@abstract Default is 0.25, i.e. 25% of radius.
*/
@property (nonatomic) float maxAccentPrecent;
@property (nonatomic) double maxAccentPrecent;

/*!
@abstract Length of circle, from 0 to M_PI*2.
@note Default M_PI*2.
*/
@property (nonatomic) float length;
@property (nonatomic) double length;

/*!
@abstract Start angle, from 0 to M_PI*2
@note Default 0.
*/
@property (nonatomic) float startAngle;
@property (nonatomic) double startAngle;

/*!
@abstract Set new values by indexes for already exist pieces. Animated.
Expand Down Expand Up @@ -192,7 +192,7 @@ typedef CGPoint (^VBLabelBlock)(CALayer*layer, NSInteger index);
@abstract Setup chart values with animation options.
@param chartValues NSArray main data for chart pie
@param animation BOOL flag present with animation
@param duration float Duration of animation.
@param duration double Duration of animation.
@param options Options for animation.
@code
[_chart setChartValues:@[
Expand All @@ -205,12 +205,13 @@ typedef CGPoint (^VBLabelBlock)(CALayer*layer, NSInteger index);
options:VBPieChartAnimationDefault];
@endcode
*/
- (void) setChartValues:(NSArray *)chartValues animation:(BOOL)animation duration:(float)duration options:(VBPieChartAnimationOptions)options;
- (void) setChartValues:(NSArray *)chartValues animation:(BOOL)animation duration:(double)duration options:(VBPieChartAnimationOptions)options;

@end


@interface VBPieChart (_deprecated)
// to enbale interaction with chart. Deprecated because useless and can be done in another way.
@property (nonatomic) BOOL enableInteractive DEPRECATED_ATTRIBUTE;
@property (nonatomic, strong) UIColor *strokeColor DEPRECATED_MSG_ATTRIBUTE("Use strokeColor parameter for value");
@property (nonatomic) BOOL enableStrokeColor DEPRECATED_MSG_ATTRIBUTE("Use strokeColor parameter for value");
Expand Down
33 changes: 21 additions & 12 deletions VBPieChart/Classes/VBPieChart.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,33 @@ @interface VBPieChart () {
__strong NSMutableArray *_chartValues;
}
@property (nonatomic, strong) NSMutableArray *chartsData;
@property (nonatomic) float radius;
@property (nonatomic) float holeRadius;
@property (nonatomic) double radius;
@property (nonatomic) double holeRadius;
@property (nonatomic, weak) VBPiePiece *hitLayer;

@property (nonatomic) BOOL presentWithAnimation;
@property (nonatomic) VBPieChartAnimationOptions animationOptions;
@property (nonatomic) float animationDuration;
@property (nonatomic) double animationDuration;

@property (nonatomic, strong) NSMutableArray *pieceArray;

@end

@interface VBPiePiece ()
- (void) _animateToAngle:(float)angle startAngle:(float)startAngle;

// setup piece Angle (then will be calcuated length) and Start Angle.
- (void) pieceAngle:(double)angle start:(double)startAngle;

// animate to accent position
- (BOOL) animateToAccent:(double)accentPrecent;

// animations methods
- (void) _animateToAngle:(double)angle startAngle:(double)startAngle;
- (void) _animate;
- (void) setAnimationOptions:(VBPieChartAnimationOptions)options;
- (void) setAnimationDuration:(float)duration;
- (void) setAnimationDuration:(double)duration;

// labels control methods
- (void) setLabelsPosition:(VBLabelsPosition)labelsPosition;
- (void) setLabelBlock:(VBLabelBlock)labelBlock;
- (void) setLabelColor:(UIColor *)labelColor;
Expand Down Expand Up @@ -229,7 +238,7 @@ - (void) _refreshCharts {

double fullValue = 0;
for (VBPiePieceData *data in _chartsData) {
fullValue += fabsf([data.value floatValue]);
fullValue += fabs([data.value doubleValue]);
}

CGFloat onePrecent = fullValue*0.01;
Expand Down Expand Up @@ -301,7 +310,7 @@ - (double) _recreateChartsData {
[_chartsData addObject:data];
}

fullValue += fabsf([data.value floatValue]);
fullValue += fabs([data.value doubleValue]);
index++;
}

Expand Down Expand Up @@ -344,9 +353,9 @@ - (void) _updateCharts {

[piece setLabelsPosition:_labelsPosition];
[piece setLabelBlock:_labelBlock];
[piece setValue:pieceValuePrecents];
[piece setInnerRadius:_radius];
[piece setOuterRadius:_holeRadius];
piece->_value = pieceValuePrecents;
piece->_innerRadius = _radius;
piece->_outerRadius = _holeRadius;

[piece setData:data];

Expand Down Expand Up @@ -418,7 +427,7 @@ - (void) setChartValues:(NSArray *)chartValues animation:(BOOL)animation options
[self setChartValues:chartValues animation:animation duration:0.6 options:options];
}

- (void) setChartValues:(NSArray *)chartValues animation:(BOOL)animation duration:(float)duration options:(VBPieChartAnimationOptions)options {
- (void) setChartValues:(NSArray *)chartValues animation:(BOOL)animation duration:(double)duration options:(VBPieChartAnimationOptions)options {
_presentWithAnimation = animation;
_animationOptions = options;
_animationDuration = duration;
Expand Down Expand Up @@ -454,7 +463,7 @@ - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// delta.y = (p1.y - p2.y);
//
// if ([_hitLayer isKindOfClass:[VBPiePiece class]]) {
// float d = _hitLayer.accentPrecent+((-delta.x+delta.y)/2/_radius);
// double d = _hitLayer.accentPrecent+((-delta.x+delta.y)/2/_radius);
// d = MIN(MAX(0, d), _maxAccentPrecent);
//
// [_hitLayer setAccentPrecent:d];
Expand Down
57 changes: 39 additions & 18 deletions VBPieChart/Classes/VBPiePiece.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,60 @@

#import <QuartzCore/QuartzCore.h>

@interface VBPiePiece : CAShapeLayer
/*!
Private class
Structure that represent one piece of Pie Chart.
*/
@interface VBPiePiece : CAShapeLayer {
@package
double _value;
double _innerRadius;
double _outerRadius;
}


/*!
Radius of pie chart.
*/
@property (nonatomic, readonly) double innerRadius;

/*!
Radius of hole in pie chart.
*/
@property (nonatomic, readonly) double outerRadius;

@property (nonatomic) float innerRadius;
@property (nonatomic) float outerRadius;
/*!
Value that represent size of piece. Set from parent VBPieChart instance.
*/
@property (nonatomic, readonly) double value;

@property (nonatomic) double value;
@property (nonatomic, strong) NSString *pieceName;
/*!
Name will be set from chartValues of VBPieChart instance or value of current instance.
*/
@property (nonatomic, strong, readonly) NSString *pieceName;

/*
/*!
Actual angle of segment
*/
@property (nonatomic, readonly) float angle;
@property (nonatomic, readonly) double angle;

/*
/*!
Start angle for segment
*/
@property (nonatomic, readonly) float startAngle;
@property (nonatomic, readonly) double startAngle;

// Default is NO
/*!
Flag that say if piece can be selected.
Default is NO
*/
@property (nonatomic, readonly) BOOL accent;

// vector of accent, used in case user touched piece
@property (nonatomic, readonly) CGPoint accentVector;

// Default is 0.1 (i.e. 10%) of innerRadius
@property (nonatomic) float accentPrecent;

// Value in range 0..1
- (BOOL) animateToAccent:(float)accentPrecent;


// Values in radians
- (void) pieceAngle:(float)angle start:(float)startAngle;
@property (nonatomic, readonly) double accentPrecent;


@end
Loading

0 comments on commit 2c4f3af

Please sign in to comment.