Showing
2 changed files
with
18 additions
and
27 deletions
| @@ -23,12 +23,6 @@ | @@ -23,12 +23,6 @@ | ||
| 23 | 23 | ||
| 24 | - (void)strokeChart; | 24 | - (void)strokeChart; |
| 25 | 25 | ||
| 26 | -/** | ||
| 27 | - * This method will get the index user touched | ||
| 28 | - */ | ||
| 29 | - | ||
| 30 | -- (void)userTouchedOnPoint:(void (^)(NSInteger *pointIndex))getTouched; | ||
| 31 | - | ||
| 32 | @property(nonatomic,retain) id<PNChartDelegate> delegate; | 26 | @property(nonatomic,retain) id<PNChartDelegate> delegate; |
| 33 | 27 | ||
| 34 | @property (strong, nonatomic) NSArray * xLabels; | 28 | @property (strong, nonatomic) NSArray * xLabels; |
| @@ -41,7 +35,11 @@ | @@ -41,7 +35,11 @@ | ||
| 41 | 35 | ||
| 42 | @property (nonatomic) CGFloat xLabelWidth; | 36 | @property (nonatomic) CGFloat xLabelWidth; |
| 43 | 37 | ||
| 44 | -@property (nonatomic) int yValueMax; | 38 | +@property (nonatomic) float yValueMax; |
| 39 | + | ||
| 40 | +@property (nonatomic) float chartCavanHeight; | ||
| 41 | + | ||
| 42 | +@property (nonatomic) float xLabelHeight; | ||
| 45 | 43 | ||
| 46 | @property (nonatomic,strong) CAShapeLayer * chartLine; | 44 | @property (nonatomic,strong) CAShapeLayer * chartLine; |
| 47 | 45 |
| @@ -28,6 +28,8 @@ | @@ -28,6 +28,8 @@ | ||
| 28 | _showLabel = YES; | 28 | _showLabel = YES; |
| 29 | _pathPoints = [[NSMutableArray alloc] init]; | 29 | _pathPoints = [[NSMutableArray alloc] init]; |
| 30 | self.userInteractionEnabled = YES; | 30 | self.userInteractionEnabled = YES; |
| 31 | + _xLabelHeight = 20.0; | ||
| 32 | + _chartCavanHeight = self.frame.size.height - chartMargin * 2 - _xLabelHeight*2 ; | ||
| 31 | [self.layer addSublayer:_chartLine]; | 33 | [self.layer addSublayer:_chartLine]; |
| 32 | } | 34 | } |
| 33 | 35 | ||
| @@ -63,15 +65,13 @@ | @@ -63,15 +65,13 @@ | ||
| 63 | -(void)setYLabels:(NSArray *)yLabels | 65 | -(void)setYLabels:(NSArray *)yLabels |
| 64 | { | 66 | { |
| 65 | 67 | ||
| 66 | - | 68 | + float level = _yValueMax / 5.0; |
| 67 | - float level = _yValueMax /[yLabels count]; | ||
| 68 | 69 | ||
| 69 | NSInteger index = 0; | 70 | NSInteger index = 0; |
| 70 | NSInteger num = [yLabels count] + 1; | 71 | NSInteger num = [yLabels count] + 1; |
| 71 | while (num > 0) { | 72 | while (num > 0) { |
| 72 | - CGFloat chartCavanHeight = self.frame.size.height - chartMargin * 2 - 40.0 ; | 73 | + CGFloat levelHeight = _chartCavanHeight /5.0; |
| 73 | - CGFloat levelHeight = chartCavanHeight /5.0; | 74 | + PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0,_chartCavanHeight - index * levelHeight + (levelHeight - yLabelHeight) , 20.0, yLabelHeight)]; |
| 74 | - PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0,chartCavanHeight - index * levelHeight + (levelHeight - yLabelHeight) , 20.0, yLabelHeight)]; | ||
| 75 | [label setTextAlignment:NSTextAlignmentRight]; | 75 | [label setTextAlignment:NSTextAlignmentRight]; |
| 76 | label.text = [NSString stringWithFormat:@"%1.f",level * index]; | 76 | label.text = [NSString stringWithFormat:@"%1.f",level * index]; |
| 77 | [self addSubview:label]; | 77 | [self addSubview:label]; |
| @@ -104,12 +104,6 @@ | @@ -104,12 +104,6 @@ | ||
| 104 | _chartLine.strokeColor = [strokeColor CGColor]; | 104 | _chartLine.strokeColor = [strokeColor CGColor]; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | --(void)userTouchedOnPoint:(void (^)(NSInteger *))getTouched | ||
| 108 | -{ | ||
| 109 | - | ||
| 110 | -} | ||
| 111 | - | ||
| 112 | - | ||
| 113 | -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event | 107 | -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event |
| 114 | { | 108 | { |
| 115 | [self chechPoint:touches withEvent:event]; | 109 | [self chechPoint:touches withEvent:event]; |
| @@ -147,19 +141,18 @@ | @@ -147,19 +141,18 @@ | ||
| 147 | 141 | ||
| 148 | CGFloat firstValue = [[_yValues objectAtIndex:0] floatValue]; | 142 | CGFloat firstValue = [[_yValues objectAtIndex:0] floatValue]; |
| 149 | 143 | ||
| 150 | - CGFloat xPosition = 0; | 144 | + CGFloat xPosition = _xLabelWidth; |
| 151 | - CGFloat xLabelHeight = 20.0; | 145 | + |
| 152 | - CGFloat chartCavanHeight = self.frame.size.height - xLabelHeight*2; | 146 | + if(!_showLabel){ |
| 153 | - if(_showLabel){ | 147 | + _chartCavanHeight = self.frame.size.height - _xLabelHeight*2; |
| 154 | - chartCavanHeight = self.frame.size.height - chartMargin * 2 - xLabelHeight*2; | 148 | + xPosition = 0; |
| 155 | - xPosition = _xLabelWidth; | ||
| 156 | } | 149 | } |
| 157 | 150 | ||
| 158 | float grade = (float)firstValue / (float)_yValueMax; | 151 | float grade = (float)firstValue / (float)_yValueMax; |
| 159 | 152 | ||
| 160 | 153 | ||
| 161 | - [_progressline moveToPoint:CGPointMake( xPosition, chartCavanHeight - grade * chartCavanHeight + xLabelHeight)]; | 154 | + [_progressline moveToPoint:CGPointMake( xPosition, _chartCavanHeight - grade * _chartCavanHeight + _xLabelHeight)]; |
| 162 | - [_pathPoints addObject:[NSValue valueWithCGPoint:CGPointMake( xPosition, chartCavanHeight - grade * chartCavanHeight + xLabelHeight)]]; | 155 | + [_pathPoints addObject:[NSValue valueWithCGPoint:CGPointMake( xPosition, _chartCavanHeight - grade * _chartCavanHeight + _xLabelHeight)]]; |
| 163 | [_progressline setLineWidth:3.0]; | 156 | [_progressline setLineWidth:3.0]; |
| 164 | [_progressline setLineCapStyle:kCGLineCapRound]; | 157 | [_progressline setLineCapStyle:kCGLineCapRound]; |
| 165 | [_progressline setLineJoinStyle:kCGLineJoinRound]; | 158 | [_progressline setLineJoinStyle:kCGLineJoinRound]; |
| @@ -171,7 +164,7 @@ | @@ -171,7 +164,7 @@ | ||
| 171 | if (index != 0) { | 164 | if (index != 0) { |
| 172 | 165 | ||
| 173 | 166 | ||
| 174 | - CGPoint point = CGPointMake(index * _xLabelWidth + 30.0 + _xLabelWidth /2.0, chartCavanHeight - (grade * chartCavanHeight) + xLabelHeight); | 167 | + CGPoint point = CGPointMake(index * _xLabelWidth + 30.0 + _xLabelWidth /2.0, _chartCavanHeight - (grade * _chartCavanHeight) + _xLabelHeight); |
| 175 | [_pathPoints addObject:[NSValue valueWithCGPoint:point]]; | 168 | [_pathPoints addObject:[NSValue valueWithCGPoint:point]]; |
| 176 | [_progressline addLineToPoint:point]; | 169 | [_progressline addLineToPoint:point]; |
| 177 | [_progressline moveToPoint:point]; | 170 | [_progressline moveToPoint:point]; |
-
Please register or login to post a comment