Showing
2 changed files
with
105 additions
and
0 deletions
PNChart/PNScatterChartData.h
0 → 100644
| 1 | +// | ||
| 2 | +// PNScatterChartData.h | ||
| 3 | +// PNChartDemo | ||
| 4 | +// | ||
| 5 | +// Created by Alireza Arabi on 12/4/14. | ||
| 6 | +// Copyright (c) 2014 kevinzhow. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import <Foundation/Foundation.h> | ||
| 10 | + | ||
| 11 | +typedef NS_ENUM(NSUInteger, PNScatterChartPointStyle) { | ||
| 12 | + PNScatterChartPointStyleCircle = 0, | ||
| 13 | + PNScatterChartPointStyleSquare = 1, | ||
| 14 | +}; | ||
| 15 | + | ||
| 16 | +@class PNScatterChartDataItem; | ||
| 17 | + | ||
| 18 | +typedef PNScatterChartDataItem *(^LCScatterChartDataGetter)(NSUInteger item); | ||
| 19 | + | ||
| 20 | +@interface PNScatterChartData : NSObject | ||
| 21 | + | ||
| 22 | +@property (strong) UIColor *fillColor; | ||
| 23 | +@property (strong) UIColor *strokeColor; | ||
| 24 | + | ||
| 25 | +@property NSUInteger itemCount; | ||
| 26 | +@property (copy) LCScatterChartDataGetter getData; | ||
| 27 | + | ||
| 28 | +@property (nonatomic, assign) PNScatterChartPointStyle inflexionPointStyle; | ||
| 29 | + | ||
| 30 | +/** | ||
| 31 | + * If PNLineChartPointStyle is circle, this returns the circle's diameter. | ||
| 32 | + * If PNLineChartPointStyle is square, each point is a square with each side equal in length to this value. | ||
| 33 | + */ | ||
| 34 | +@property (nonatomic, assign) CGFloat size; | ||
| 35 | + | ||
| 36 | + | ||
| 37 | +@end |
PNChart/PNScatterChartData.m
0 → 100644
| 1 | +// | ||
| 2 | +// PNScatterChartData.m | ||
| 3 | +// PNChartDemo | ||
| 4 | +// | ||
| 5 | +// Created by Alireza Arabi on 12/4/14. | ||
| 6 | +// Copyright (c) 2014 kevinzhow. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import "PNScatterChartData.h" | ||
| 10 | + | ||
| 11 | +@implementation PNScatterChartData | ||
| 12 | + | ||
| 13 | +- (id)init | ||
| 14 | +{ | ||
| 15 | + self = [super init]; | ||
| 16 | + if (self) { | ||
| 17 | + [self setDefaultValues]; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + return self; | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +- (void)setDefaultValues | ||
| 24 | +{ | ||
| 25 | + _inflexionPointStyle = PNScatterChartPointStyleCircle; | ||
| 26 | + _fillColor = [UIColor grayColor]; | ||
| 27 | + _strokeColor = [UIColor blackColor]; | ||
| 28 | + _size = 10 ; | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +- (CAShapeLayer*) drawingPoints | ||
| 32 | +{ | ||
| 33 | + if (_inflexionPointStyle == PNScatterChartPointStyleCircle) { | ||
| 34 | + float radius = _size; | ||
| 35 | + CAShapeLayer *circle = [CAShapeLayer layer]; | ||
| 36 | + // Make a circular shape | ||
| 37 | + circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) | ||
| 38 | + cornerRadius:radius].CGPath; | ||
| 39 | + // Configure the apperence of the circle | ||
| 40 | + circle.fillColor = [_fillColor CGColor]; | ||
| 41 | + circle.strokeColor = [_strokeColor CGColor]; | ||
| 42 | + circle.lineWidth = 1; | ||
| 43 | + | ||
| 44 | + // Add to parent layer | ||
| 45 | + return circle; | ||
| 46 | + } | ||
| 47 | + else if (_inflexionPointStyle == PNScatterChartPointStyleSquare) { | ||
| 48 | + float side = _size; | ||
| 49 | + CAShapeLayer *square = [CAShapeLayer layer]; | ||
| 50 | + // Make a circular shape | ||
| 51 | + square.path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, side, side)].CGPath ; | ||
| 52 | + // Configure the apperence of the circle | ||
| 53 | + square.fillColor = [_fillColor CGColor]; | ||
| 54 | + square.strokeColor = [_strokeColor CGColor]; | ||
| 55 | + square.lineWidth = 1; | ||
| 56 | + | ||
| 57 | + // Add to parent layer | ||
| 58 | + return square; | ||
| 59 | + | ||
| 60 | + } | ||
| 61 | + else { | ||
| 62 | + // you cann add your own scatter chart poin here | ||
| 63 | + } | ||
| 64 | + return nil ; | ||
| 65 | + | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +@end |
-
Please register or login to post a comment