Gianmaria Dal Maistro

Merge branch 'master' of github.com:jerrygdm/PNChart into HideValues-PieChart

Conflicts:
	PNChart/PNPieChart.h
	PNChart/PNPieChart.m
... ... @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#
s.name = "PNChart"
s.version = "0.8.5"
s.version = "0.8.6"
s.summary = "A simple and beautiful chart lib with animation used in Piner for iOS"
s.description = <<-DESC
... ... @@ -90,7 +90,7 @@ Pod::Spec.new do |s|
# Supports git, hg, bzr, svn and HTTP.
#
s.source = { :git => "https://github.com/kevinzhow/PNChart.git", :tag => "0.8.5" }
s.source = { :git => "https://github.com/kevinzhow/PNChart.git", :tag => s.version }
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
... ...
... ... @@ -26,6 +26,9 @@
@property (nonatomic) CAShapeLayer *gradeLayer;
@property (nonatomic) CATextLayer* textLayer;
/** Text color for all bars in the chart. */
@property (nonatomic) UIColor * labelTextColor;
@property (nonatomic, assign) BOOL isNegative; //!< 是否是负数
@property (nonatomic, assign) BOOL isShowNumber; //!< 是否显示numbers
@end
... ...
... ... @@ -181,7 +181,7 @@
_textLayer = [[CATextLayer alloc]init];
[_textLayer setString:@"0"];
[_textLayer setAlignmentMode:kCAAlignmentCenter];
[_textLayer setForegroundColor:[[UIColor colorWithRed:178/255.0 green:178/255. blue:178/255.0 alpha:1.0] CGColor]];
[_textLayer setForegroundColor:[_labelTextColor CGColor]];
_textLayer.hidden = YES;
}
... ... @@ -189,6 +189,11 @@
return _textLayer;
}
- (void) setLabelTextColor:(UIColor *)labelTextColor {
_labelTextColor = labelTextColor;
[_textLayer setForegroundColor:[_labelTextColor CGColor]];
}
-(void)setGradeFrame:(CGFloat)grade startPosY:(CGFloat)startPosY
{
CGFloat textheigt = self.bounds.size.height*self.grade;
... ...
... ... @@ -52,7 +52,10 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
/** Suffix to y label values, none if unset. */
@property (nonatomic) NSString *yLabelSuffix;
@property (nonatomic) CGFloat chartMargin;
@property (nonatomic) CGFloat chartMarginLeft;
@property (nonatomic) CGFloat chartMarginRight;
@property (nonatomic) CGFloat chartMarginTop;
@property (nonatomic) CGFloat chartMarginBottom;
/** Controls whether labels should be displayed. */
@property (nonatomic) BOOL showLabel;
... ... @@ -60,6 +63,8 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
/** Controls whether the chart border line should be displayed. */
@property (nonatomic) BOOL showChartBorder;
@property (nonatomic) UIColor *chartBorderColor;
/** Controls whether the chart Horizontal separator should be displayed. */
@property (nonatomic, assign) BOOL showLevelLine;
... ...
This diff is collapsed. Click to expand it.
... ... @@ -13,7 +13,9 @@
typedef NS_ENUM (NSUInteger, PNChartFormatType) {
PNChartFormatTypePercent,
PNChartFormatTypeDollar,
PNChartFormatTypeNone
PNChartFormatTypeNone,
PNChartFormatTypeDecimal,
PNChartFormatTypeDecimalTwoPlaces,
};
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
... ...
... ... @@ -46,7 +46,7 @@
current:current
clockwise:clockwise
shadow:shadow
shadowColor:PNGreen
shadowColor:backgroundShadowColor
displayCountingLabel:displayCountingLabel
overrideLineWidth:@8.0f];
... ... @@ -131,6 +131,12 @@ displayCountingLabel:(BOOL)displayCountingLabel
case PNChartFormatTypeDollar:
format = @"$%d";
break;
case PNChartFormatTypeDecimal:
format = @"%.1f";
break;
case PNChartFormatTypeDecimalTwoPlaces:
format = @"%.2f";
break;
case PNChartFormatTypeNone:
default:
format = @"%d";
... ...
... ... @@ -45,11 +45,14 @@
@property (nonatomic) UIColor *yLabelColor;
@property (nonatomic) CGFloat chartCavanHeight;
@property (nonatomic) CGFloat chartCavanWidth;
@property (nonatomic) CGFloat chartMargin;
@property (nonatomic) BOOL showLabel;
@property (nonatomic) BOOL showGenYLabels;
@property (nonatomic) BOOL thousandsSeparator;
@property (nonatomic) CGFloat chartMarginLeft;
@property (nonatomic) CGFloat chartMarginRight;
@property (nonatomic) CGFloat chartMarginTop;
@property (nonatomic) CGFloat chartMarginBottom;
/**
* Controls whether to show the coordinate axis. Default is NO.
... ...
This diff is collapsed. Click to expand it.
... ... @@ -25,6 +25,11 @@ typedef PNLineChartDataItem *(^LCLineChartDataGetter)(NSUInteger item);
@property (copy) LCLineChartDataGetter getData;
@property (strong, nonatomic) NSString *dataTitle;
@property (nonatomic) BOOL showPointLabel;
@property (nonatomic) UIColor *pointLabelColor;
@property (nonatomic) UIFont *pointLabelFont;
@property (nonatomic) NSString *pointLabelFormat;
@property (nonatomic, assign) PNLineChartPointStyle inflexionPointStyle;
/**
... ...
... ... @@ -23,6 +23,9 @@
_inflexionPointWidth = 6.f;
_lineWidth = 2.f;
_alpha = 1.f;
_showPointLabel = NO;
_pointLabelColor = [UIColor blackColor];
_pointLabelFormat = @"%1.f";
}
@end
... ...
... ... @@ -9,7 +9,9 @@
@interface PNLineChartDataItem : NSObject
+ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y;
+ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y andRawY:(CGFloat)rawY;
@property (readonly) CGFloat y; // should be within the y range
@property (readonly) CGFloat rawY; // this is the raw value, used for point label.
@end
... ...
... ... @@ -7,9 +7,10 @@
@interface PNLineChartDataItem ()
- (id)initWithY:(CGFloat)y;
- (id)initWithY:(CGFloat)y andRawY:(CGFloat)rawY;
@property (readwrite) CGFloat y; // should be within the y range
@property (readwrite) CGFloat y; // should be within the y range
@property (readwrite) CGFloat rawY; // this is the raw value, used for point label.
@end
... ... @@ -17,13 +18,18 @@
+ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y
{
return [[PNLineChartDataItem alloc] initWithY:y];
return [[PNLineChartDataItem alloc] initWithY:y andRawY:y];
}
- (id)initWithY:(CGFloat)y
+ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y andRawY:(CGFloat)rawY {
return [[PNLineChartDataItem alloc] initWithY:y andRawY:rawY];
}
- (id)initWithY:(CGFloat)y andRawY:(CGFloat)rawY
{
if ((self = [super init])) {
self.y = y;
self.rawY = rawY;
}
return self;
... ...
... ... @@ -32,9 +32,6 @@
/** Default is 1.0. */
@property (nonatomic) NSTimeInterval duration;
/** show only tiles, not values or percentage */
@property (nonatomic) BOOL hideValues;
/** Show only values, this is useful when legend is present */
@property (nonatomic) BOOL showOnlyValues;
... ... @@ -47,11 +44,29 @@
/** Default YES. */
@property (nonatomic) BOOL shouldHighlightSectorOnTouch;
/** Current outer radius. Override recompute() to change this. **/
@property (nonatomic) CGFloat outerCircleRadius;
/** Current inner radius. Override recompute() to change this. **/
@property (nonatomic) CGFloat innerCircleRadius;
@property (nonatomic, weak) id<PNChartDelegate> delegate;
/** Update chart items. Does not update chart itself. */
- (void)updateChartData:(NSArray *)data;
/** Multiple selection */
@property (nonatomic, assign) BOOL enableMultipleSelection;
/** show only tiles, not values or percentage */
@property (nonatomic) BOOL hideValues;
- (void)strokeChart;
- (void)recompute;
<<<<<<< Updated upstream
@end
=======
@end
>>>>>>> Stashed changes
... ...
... ... @@ -15,14 +15,13 @@
@property (nonatomic) NSArray *items;
@property (nonatomic) NSArray *endPercentages;
@property (nonatomic) CGFloat outerCircleRadius;
@property (nonatomic) CGFloat innerCircleRadius;
@property (nonatomic) UIView *contentView;
@property (nonatomic) CAShapeLayer *pieLayer;
@property (nonatomic) NSMutableArray *descriptionLabels;
@property (strong, nonatomic) CAShapeLayer *sectorHighlight;
@property (nonatomic, strong) NSMutableDictionary *selectedItems;
- (void)loadDefault;
- (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index;
... ... @@ -48,9 +47,9 @@
self = [self initWithFrame:frame];
if(self){
_items = [NSArray arrayWithArray:items];
_selectedItems = [NSMutableDictionary dictionary];
_outerCircleRadius = CGRectGetWidth(self.bounds) / 2;
_innerCircleRadius = CGRectGetWidth(self.bounds) / 6;
_descriptionTextColor = [UIColor whiteColor];
_descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:18.0];
_descriptionTextShadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
... ... @@ -88,12 +87,20 @@
_pieLayer = [CAShapeLayer layer];
[_contentView.layer addSublayer:_pieLayer];
}
/** Override this to change how inner attributes are computed. **/
- (void)recompute {
self.outerCircleRadius = CGRectGetWidth(self.bounds) / 2;
self.innerCircleRadius = CGRectGetWidth(self.bounds) / 6;
}
#pragma mark -
- (void)strokeChart{
[self loadDefault];
[self recompute];
PNPieChartDataItem *currentItem;
for (int i = 0; i < _items.count; i++) {
... ... @@ -174,6 +181,10 @@
return descriptionLabel;
}
- (void)updateChartData:(NSArray *)items {
self.items = items;
}
- (PNPieChartDataItem *)dataItemForIndex:(NSUInteger)index{
return self.items[index];
}
... ... @@ -284,15 +295,17 @@
while (percentage > [self endPercentageForItemAtIndex:index]) {
index ++;
}
if ([self.delegate respondsToSelector:@selector(userClickedOnPieIndexItem:)]) {
[self.delegate userClickedOnPieIndexItem:index];
}
if (self.shouldHighlightSectorOnTouch) {
if (self.sectorHighlight) {
[self.sectorHighlight removeFromSuperlayer];
if (self.shouldHighlightSectorOnTouch)
{
if (!self.enableMultipleSelection)
{
if (self.sectorHighlight)
[self.sectorHighlight removeFromSuperlayer];
}
PNPieChartDataItem *currentItem = [self dataItemForIndex:index];
... ... @@ -305,13 +318,33 @@
CGFloat startPercnetage = [self startPercentageForItemAtIndex:index];
CGFloat endPercentage = [self endPercentageForItemAtIndex:index];
self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5
self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5
borderWidth:10
fillColor:[UIColor clearColor]
borderColor:newColor
startPercentage:startPercnetage
endPercentage:endPercentage];
[_contentView.layer addSublayer:self.sectorHighlight];
if (self.enableMultipleSelection)
{
NSString *dictIndex = [NSString stringWithFormat:@"%d", index];
CAShapeLayer *indexShape = [self.selectedItems valueForKey:dictIndex];
if (indexShape)
{
[indexShape removeFromSuperlayer];
[self.selectedItems removeObjectForKey:dictIndex];
}
else
{
[self.selectedItems setObject:self.sectorHighlight forKey:dictIndex];
[_contentView.layer addSublayer:self.sectorHighlight];
}
}
else
{
[_contentView.layer addSublayer:self.sectorHighlight];
}
}
}
... ... @@ -402,7 +435,7 @@
x += self.legendStyle == PNLegendItemStyleStacked ? 0 : labelsize.width + beforeLabel;
y += self.legendStyle == PNLegendItemStyleStacked ? labelsize.height : 0;
totalHeight = self.legendStyle == PNLegendItemStyleSerial ? fmaxf(totalHeight, rowMaxHeight + y) : totalHeight + labelsize.height;
[legendViews addObject:label];
counter ++;
... ... @@ -427,7 +460,7 @@
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddArc(context, size/2, size/ 2, size/2, 0, M_PI*2, YES);
//Set some fill color
CGContextSetFillColorWithColor(context, color.CGColor);
... ... @@ -448,4 +481,11 @@
[squareImageView setFrame:CGRectMake(originX, originY, size, size)];
return squareImageView;
}
/* Redraw the chart on autolayout */
-(void)layoutSubviews {
[super layoutSubviews];
[self strokeChart];
}
@end
... ...
<?xml version='1.0' encoding='UTF-8'?><Workspace version='1.0'><FileRef location='group:PNChartDemo.xcodeproj'/><FileRef location='group:Pods/Pods.xcodeproj'/></Workspace>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:PNChartDemo.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>
... ...
This diff is collapsed. Click to expand it.
... ... @@ -25,12 +25,13 @@
@property (weak, nonatomic) IBOutlet UIButton *changeValueButton;
@property (weak, nonatomic) IBOutlet UISwitch *leftSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *centerSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *rightSwitch;
@property (weak, nonatomic) IBOutlet UILabel *leftLabel;
@property (weak, nonatomic) IBOutlet UILabel *rightLabel;
- (IBAction)rightSwitchChanged:(id)sender;
- (IBAction)leftSwitchChanged:(id)sender;
- (IBAction)rightSwitchChanged:(id)sender;
@end
... ...
... ... @@ -91,20 +91,34 @@
}
else if ([self.title isEqualToString:@"Bar Chart"])
{
static NSNumberFormatter *barChartFormatter;
if (!barChartFormatter){
barChartFormatter = [[NSNumberFormatter alloc] init];
barChartFormatter.numberStyle = NSNumberFormatterCurrencyStyle;
barChartFormatter.allowsFloats = NO;
barChartFormatter.maximumFractionDigits = 0;
}
self.titleLabel.text = @"Bar Chart";
self.barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
// self.barChart.showLabel = NO;
self.barChart.backgroundColor = [UIColor clearColor];
self.barChart.yLabelFormatter = ^(CGFloat yValue){
CGFloat yValueParsed = yValue;
NSString * labelText = [NSString stringWithFormat:@"%0.f",yValueParsed];
return labelText;
return [barChartFormatter stringFromNumber:[NSNumber numberWithFloat:yValue]];
};
self.barChart.yChartLabelWidth = 20.0;
self.barChart.chartMarginLeft = 30.0;
self.barChart.chartMarginRight = 10.0;
self.barChart.chartMarginTop = 5.0;
self.barChart.chartMarginBottom = 10.0;
self.barChart.labelMarginTop = 5.0;
self.barChart.showChartBorder = YES;
[self.barChart setXLabels:@[@"2",@"3",@"4",@"5",@"2",@"3",@"4",@"5"]];
// self.barChart.yLabels = @[@-10,@0,@10];
// [self.barChart setYValues:@[@10000.0,@30000.0,@10000.0,@100000.0,@500000.0,@1000000.0,@1150000.0,@2150000.0]];
[self.barChart setYValues:@[@10.82,@1.88,@6.96,@33.93,@10.82,@1.88,@6.96,@33.93]];
[self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNGreen,PNRed,PNGreen]];
self.barChart.isGradientShow = NO;
... ... @@ -344,6 +358,15 @@
}
}
- (IBAction)centerSwitchChanged:(id)sender
{
if (self.pieChart)
{
[self.pieChart setEnableMultipleSelection:self.centerSwitch.on];
[self.pieChart strokeChart];
}
}
- (IBAction)leftSwitchChanged:(id)sender {
if ([self.title isEqualToString:@"Pie Chart"]){
UISwitch *showRelative = (UISwitch*) sender;
... ...
PODS:
- Expecta (0.4.2)
- Expecta (1.0.2)
- UICountingLabel (1.2.0)
DEPENDENCIES:
... ... @@ -7,7 +7,7 @@ DEPENDENCIES:
- UICountingLabel (~> 1.2.0)
SPEC CHECKSUMS:
Expecta: 78b4e8b0c8291fa4524d7f74016b6065c2e391ec
Expecta: 54e8a3530add08f4f0208c111355eda7cde74a53
UICountingLabel: 1db4e7d023e1762171eb226d6dff47a7a84f27aa
COCOAPODS: 0.38.2
... ...
... ... @@ -10,7 +10,10 @@ A simple and beautiful chart lib with **animation** used in [Piner](https://itun
## Requirements
PNChart works on iOS 6.0 (Begin with 0.8.2 supports iOS 8 and Later only, if you are working with iOS 6 and iOS 7, use 0.8.1 instead.) and later version and is compatible with ARC projects. It depends on the following Apple frameworks, which should already be included with most Xcode templates:
PNChart works on iOS 7.0+ and is compatible with ARC projects.
If you need support for iOS 6, use PNChart <= 0.8.1. Note that 0.8.2 supports iOS 8.0+ only, 0.8.3 and newer supports iOS 7.0+.
It depends on the following Apple frameworks, which should already be included with most Xcode templates:
* Foundation.framework
* UIKit.framework
... ...