├── .DS_Store ├── Image ├── .DS_Store ├── IMG_0470.PNG ├── IMG_0473.PNG ├── IMG_0478.PNG ├── IMG_0479.PNG └── IMG_0480.PNG ├── Sample ├── .DS_Store └── LineDrawer │ ├── ImgGetter │ ├── en.lproj │ │ └── InfoPlist.strings │ ├── .DS_Store │ ├── CSChartsView │ │ ├── .DS_Store │ │ ├── Layer │ │ │ ├── CSChartsXAxisLayer.h │ │ │ ├── CSChartsMainLineLayer.h │ │ │ ├── CSChartsBackgroundLayer.h │ │ │ ├── CSChartsXAxisLayer.m │ │ │ ├── CSChartsMainLineLayer.m │ │ │ └── CSChartsBackgroundLayer.m │ │ ├── Model │ │ │ ├── CSAxisUnit.h │ │ │ ├── CSAxisUnit.m │ │ │ ├── CSChartsColorRegion.h │ │ │ ├── CSChartsMaiLine.m │ │ │ ├── CSChartsXAxis.h │ │ │ ├── CSChartsMaiLine.h │ │ │ ├── CSChartsColorRegion.m │ │ │ ├── CSChartsYAxis.m │ │ │ ├── CSChartsBackground.h │ │ │ ├── CSChartsDetailRect.h │ │ │ ├── CSChartsXAxis.m │ │ │ ├── CSChartsBackground.m │ │ │ ├── CSChartsDetailRect.m │ │ │ ├── CSCharts.m │ │ │ ├── CSChartsYAxis.h │ │ │ ├── CSChartsPoint.m │ │ │ ├── CSChartsPoint.h │ │ │ └── CSCharts.h │ │ ├── CSChartsView.h │ │ └── CSChartsView.m │ ├── AppDelegate.h │ ├── RootViewController.h │ ├── main.m │ ├── LineDrawer-Prefix.pch │ ├── Images.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── LaunchImage.launchimage │ │ │ └── Contents.json │ ├── NSString+BoundingRect.h │ ├── LineDrawer-Info.plist │ ├── NSString+BoundingRect.m │ ├── AppDelegate.m │ └── RootViewController.m │ ├── .DS_Store │ └── LineDrawer.xcodeproj │ ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcuserdata │ │ ├── CarlShen.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ └── CruiseShen.xcuserdatad │ │ │ ├── UserInterfaceState.xcuserstate │ │ │ └── WorkspaceSettings.xcsettings │ └── xcshareddata │ │ └── LineDrawer.xccheckout │ ├── xcuserdata │ ├── CruiseShen.xcuserdatad │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ │ ├── xcschememanagement.plist │ │ │ └── ImgGetter.xcscheme │ └── CarlShen.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── LineDrawer.xcscheme │ └── project.pbxproj ├── Source ├── .DS_Store ├── Layer │ ├── CSChartsXAxisLayer.h │ ├── CSChartsMainLineLayer.h │ ├── CSChartsBackgroundLayer.h │ ├── CSChartsXAxisLayer.m │ ├── CSChartsMainLineLayer.m │ └── CSChartsBackgroundLayer.m ├── Model │ ├── CSAxisUnit.h │ ├── CSAxisUnit.m │ ├── CSChartsColorRegion.h │ ├── CSChartsMaiLine.m │ ├── CSChartsXAxis.h │ ├── CSChartsMaiLine.h │ ├── CSChartsColorRegion.m │ ├── CSChartsYAxis.m │ ├── CSChartsBackground.h │ ├── CSChartsDetailRect.h │ ├── CSChartsXAxis.m │ ├── CSChartsBackground.m │ ├── CSChartsDetailRect.m │ ├── CSCharts.m │ ├── CSChartsYAxis.h │ ├── CSChartsPoint.m │ ├── CSChartsPoint.h │ └── CSCharts.h ├── NSString+BoundingRect.h ├── NSString+BoundingRect.m ├── CSChartsView.h └── CSChartsView.m ├── LICENSE ├── CSChartsView.podspec └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/.DS_Store -------------------------------------------------------------------------------- /Image/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Image/.DS_Store -------------------------------------------------------------------------------- /Sample/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Sample/.DS_Store -------------------------------------------------------------------------------- /Source/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Source/.DS_Store -------------------------------------------------------------------------------- /Image/IMG_0470.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Image/IMG_0470.PNG -------------------------------------------------------------------------------- /Image/IMG_0473.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Image/IMG_0473.PNG -------------------------------------------------------------------------------- /Image/IMG_0478.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Image/IMG_0478.PNG -------------------------------------------------------------------------------- /Image/IMG_0479.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Image/IMG_0479.PNG -------------------------------------------------------------------------------- /Image/IMG_0480.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Image/IMG_0480.PNG -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Sample/LineDrawer/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Sample/LineDrawer/.DS_Store -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Sample/LineDrawer/ImgGetter/.DS_Store -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Sample/LineDrawer/ImgGetter/CSChartsView/.DS_Store -------------------------------------------------------------------------------- /Sample/LineDrawer/LineDrawer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Sample/LineDrawer/LineDrawer.xcodeproj/project.xcworkspace/xcuserdata/CarlShen.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Sample/LineDrawer/LineDrawer.xcodeproj/project.xcworkspace/xcuserdata/CarlShen.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Sample/LineDrawer/LineDrawer.xcodeproj/project.xcworkspace/xcuserdata/CruiseShen.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skysh3n/CSChartsView/HEAD/Sample/LineDrawer/LineDrawer.xcodeproj/project.xcworkspace/xcuserdata/CruiseShen.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-2-18. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Source/Layer/CSChartsXAxisLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsXAxisLayer.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSCharts.h" 11 | 12 | @interface CSChartsXAxisLayer : CALayer 13 | @property(nonatomic,weak) CSCharts *charts; 14 | @end 15 | -------------------------------------------------------------------------------- /Source/Layer/CSChartsMainLineLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsMainLineLayer.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSCharts.h" 11 | 12 | @interface CSChartsMainLineLayer : CALayer 13 | @property(nonatomic,weak) CSCharts *charts; 14 | @end 15 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/RootViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-3. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSChartsView.h" 11 | 12 | @interface RootViewController : UIViewController 13 | @property(nonatomic,strong) CSChartsView *chartsView; 14 | @end 15 | -------------------------------------------------------------------------------- /Source/Layer/CSChartsBackgroundLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsBackgroundLayer.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSCharts.h" 11 | 12 | @interface CSChartsBackgroundLayer : CALayer 13 | 14 | @property(nonatomic,weak) CSCharts *charts; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Layer/CSChartsXAxisLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsXAxisLayer.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSCharts.h" 11 | 12 | @interface CSChartsXAxisLayer : CALayer 13 | @property(nonatomic,weak) CSCharts *charts; 14 | @end 15 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Layer/CSChartsMainLineLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsMainLineLayer.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSCharts.h" 11 | 12 | @interface CSChartsMainLineLayer : CALayer 13 | @property(nonatomic,weak) CSCharts *charts; 14 | @end 15 | -------------------------------------------------------------------------------- /Source/Model/CSAxisUnit.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSAxisUnit.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-31. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSAxisUnit : NSObject 12 | @property(nonatomic,strong) NSString *unitString; 13 | @property(nonatomic,strong) UIFont *font; 14 | @property(nonatomic,strong) UIColor *color; 15 | @end 16 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Layer/CSChartsBackgroundLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsBackgroundLayer.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSCharts.h" 11 | 12 | @interface CSChartsBackgroundLayer : CALayer 13 | 14 | @property(nonatomic,weak) CSCharts *charts; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-2-18. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Source/Model/CSAxisUnit.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSAxisUnit.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-31. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSAxisUnit.h" 10 | 11 | @implementation CSAxisUnit 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.color = [UIColor blackColor]; 15 | self.font = [UIFont boldSystemFontOfSize:9]; 16 | } 17 | return self; 18 | } 19 | @end 20 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSAxisUnit.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSAxisUnit.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-31. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSAxisUnit : NSObject 12 | @property(nonatomic,strong) NSString *unitString; 13 | @property(nonatomic,strong) UIFont *font; 14 | @property(nonatomic,strong) UIColor *color; 15 | @end 16 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/LineDrawer-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSAxisUnit.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSAxisUnit.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-31. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSAxisUnit.h" 10 | 11 | @implementation CSAxisUnit 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.color = [UIColor blackColor]; 15 | self.font = [UIFont boldSystemFontOfSize:9]; 16 | } 17 | return self; 18 | } 19 | @end 20 | -------------------------------------------------------------------------------- /Sample/LineDrawer/LineDrawer.xcodeproj/project.xcworkspace/xcuserdata/CruiseShen.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Source/Model/CSChartsColorRegion.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsColorRegion.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-11. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSChartsColorRegion : NSObject 12 | @property(nonatomic,strong) UIColor *color; 13 | @property(nonatomic) CGFloat regionRange; 14 | @end 15 | 16 | //convenient method 17 | CSChartsColorRegion *CSChartsColorRegionMake(UIColor *color,CGFloat regionRange); -------------------------------------------------------------------------------- /Source/Model/CSChartsMaiLine.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsMaiLine.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsMaiLine.h" 10 | 11 | @implementation CSChartsMaiLine 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.color = [UIColor blackColor]; 15 | self.lineWidth = 2; 16 | self.detailRect = [[CSChartsDetailRect alloc] init]; 17 | } 18 | return self; 19 | } 20 | @end 21 | -------------------------------------------------------------------------------- /Source/Model/CSChartsXAxis.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsXAxis.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSChartsXAxis : NSObject 12 | @property(nonatomic,strong) UIColor *color; 13 | @property(nonatomic,strong) NSArray *signArray; 14 | @property(nonatomic,strong) UIColor *signColor; 15 | @property(nonatomic,strong) UIFont *signFont; 16 | @property(nonatomic) CGFloat axisWidth; 17 | @end 18 | -------------------------------------------------------------------------------- /Source/Model/CSChartsMaiLine.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsMaiLine.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSChartsDetailRect.h" 11 | 12 | @interface CSChartsMaiLine : NSObject 13 | @property(nonatomic,strong) NSArray *pointArray; 14 | @property(nonatomic,strong) UIColor *color; 15 | @property(nonatomic) CGFloat lineWidth; 16 | @property(nonatomic,strong) CSChartsDetailRect *detailRect; 17 | @end 18 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsColorRegion.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsColorRegion.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-11. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSChartsColorRegion : NSObject 12 | @property(nonatomic,strong) UIColor *color; 13 | @property(nonatomic) CGFloat regionRange; 14 | @end 15 | 16 | //convenient method 17 | CSChartsColorRegion *CSChartsColorRegionMake(UIColor *color,CGFloat regionRange); -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsMaiLine.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsMaiLine.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsMaiLine.h" 10 | 11 | @implementation CSChartsMaiLine 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.color = [UIColor blackColor]; 15 | self.lineWidth = 2; 16 | self.detailRect = [[CSChartsDetailRect alloc] init]; 17 | } 18 | return self; 19 | } 20 | @end 21 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsXAxis.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsXAxis.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSChartsXAxis : NSObject 12 | @property(nonatomic,strong) UIColor *color; 13 | @property(nonatomic,strong) NSArray *signArray; 14 | @property(nonatomic,strong) UIColor *signColor; 15 | @property(nonatomic,strong) UIFont *signFont; 16 | @property(nonatomic) CGFloat axisWidth; 17 | @end 18 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsMaiLine.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsMaiLine.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSChartsDetailRect.h" 11 | 12 | @interface CSChartsMaiLine : NSObject 13 | @property(nonatomic,strong) NSArray *pointArray; 14 | @property(nonatomic,strong) UIColor *color; 15 | @property(nonatomic) CGFloat lineWidth; 16 | @property(nonatomic,strong) CSChartsDetailRect *detailRect; 17 | @end 18 | -------------------------------------------------------------------------------- /Source/Model/CSChartsColorRegion.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsColorRegion.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-11. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsColorRegion.h" 10 | 11 | @implementation CSChartsColorRegion 12 | 13 | @end 14 | 15 | CSChartsColorRegion *CSChartsColorRegionMake(UIColor *color,CGFloat regionRange){ 16 | CSChartsColorRegion *colorRegion = [[CSChartsColorRegion alloc] init]; 17 | colorRegion.color = color; 18 | colorRegion.regionRange = regionRange; 19 | return colorRegion; 20 | } -------------------------------------------------------------------------------- /Source/Model/CSChartsYAxis.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsYAxis.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsYAxis.h" 10 | 11 | @implementation CSChartsYAxis 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.color = [UIColor blackColor]; 15 | self.font = [UIFont boldSystemFontOfSize:9]; 16 | self.axisUnit = [[CSAxisUnit alloc] init]; 17 | self.signFormat = @"%0.0f"; 18 | self.isNeeded = YES; 19 | } 20 | return self; 21 | } 22 | @end 23 | -------------------------------------------------------------------------------- /Source/Model/CSChartsBackground.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsBackground.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSChartsBackground : NSObject 12 | @property(nonatomic,strong) UIColor *viceLineColor; 13 | @property(nonatomic,strong) UIColor *mainLineColor; 14 | @property(nonatomic,strong) NSArray *colorRegionArray; 15 | @property(nonatomic) BOOL isRegionSeparated; 16 | @property(nonatomic) BOOL shouldDrawHorizontalViceLines; 17 | @end 18 | -------------------------------------------------------------------------------- /Source/Model/CSChartsDetailRect.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsDetailRect.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-12. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSChartsDetailRect : NSObject 12 | @property(nonatomic) CGSize size; 13 | @property(nonatomic,strong) UIFont *font; 14 | @property(nonatomic,strong) NSString *textFormat; 15 | @property(nonatomic,strong) UIColor *color; 16 | @property(nonatomic,strong) NSString *unitString; 17 | @property(nonatomic,strong) UIFont *unitFont; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Source/NSString+BoundingRect.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+BoundingRect.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-5. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (BoundingRect) 12 | //calculate text size 13 | -(CGSize)boundingRectWithSize:(CGSize)size withTextFont:(UIFont *)font withLineSpacing:(CGFloat)lineSpacing; 14 | //transform sting to AttributedString 15 | -(NSMutableAttributedString *)attributedStringFromStingWithFont:(UIFont *)font withLineSpacing:(CGFloat)lineSpacing; 16 | @end 17 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsColorRegion.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsColorRegion.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-11. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsColorRegion.h" 10 | 11 | @implementation CSChartsColorRegion 12 | 13 | @end 14 | 15 | CSChartsColorRegion *CSChartsColorRegionMake(UIColor *color,CGFloat regionRange){ 16 | CSChartsColorRegion *colorRegion = [[CSChartsColorRegion alloc] init]; 17 | colorRegion.color = color; 18 | colorRegion.regionRange = regionRange; 19 | return colorRegion; 20 | } -------------------------------------------------------------------------------- /Source/Model/CSChartsXAxis.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsXAxis.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsXAxis.h" 10 | 11 | @implementation CSChartsXAxis 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.color = [UIColor colorWithRed:95 / 255.0 green:0 /255.0 blue:55 / 255.0 alpha:1]; 15 | self.signColor = [UIColor blackColor]; 16 | self.signFont = [UIFont boldSystemFontOfSize:10]; 17 | self.axisWidth = 2; 18 | } 19 | return self; 20 | } 21 | @end 22 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsYAxis.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsYAxis.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsYAxis.h" 10 | 11 | @implementation CSChartsYAxis 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.color = [UIColor blackColor]; 15 | self.font = [UIFont boldSystemFontOfSize:9]; 16 | self.axisUnit = [[CSAxisUnit alloc] init]; 17 | self.signFormat = @"%0.0f"; 18 | self.isNeeded = YES; 19 | } 20 | return self; 21 | } 22 | @end 23 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsBackground.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsBackground.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSChartsBackground : NSObject 12 | @property(nonatomic,strong) UIColor *viceLineColor; 13 | @property(nonatomic,strong) UIColor *mainLineColor; 14 | @property(nonatomic,strong) NSArray *colorRegionArray; 15 | @property(nonatomic) BOOL isRegionSeparated; 16 | @property(nonatomic) BOOL shouldDrawHorizontalViceLines; 17 | @end 18 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/NSString+BoundingRect.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+BoundingRect.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-5. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (BoundingRect) 12 | //calculate text size 13 | -(CGSize)boundingRectWithSize:(CGSize)size withTextFont:(UIFont *)font withLineSpacing:(CGFloat)lineSpacing; 14 | //transform sting to AttributedString 15 | -(NSMutableAttributedString *)attributedStringFromStingWithFont:(UIFont *)font withLineSpacing:(CGFloat)lineSpacing; 16 | @end 17 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Source/Model/CSChartsBackground.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsBackground.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsBackground.h" 10 | 11 | @implementation CSChartsBackground 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.viceLineColor = [UIColor lightGrayColor]; 15 | self.mainLineColor = [UIColor blackColor]; 16 | self.colorRegionArray = nil; 17 | self.isRegionSeparated = YES; 18 | self.shouldDrawHorizontalViceLines = YES; 19 | } 20 | return self; 21 | } 22 | @end 23 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsDetailRect.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsDetailRect.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-12. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSChartsDetailRect : NSObject 12 | @property(nonatomic) CGSize size; 13 | @property(nonatomic,strong) UIFont *font; 14 | @property(nonatomic,strong) NSString *textFormat; 15 | @property(nonatomic,strong) UIColor *color; 16 | @property(nonatomic,strong) NSString *unitString; 17 | @property(nonatomic,strong) UIFont *unitFont; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsXAxis.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsXAxis.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsXAxis.h" 10 | 11 | @implementation CSChartsXAxis 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.color = [UIColor colorWithRed:95 / 255.0 green:0 /255.0 blue:55 / 255.0 alpha:1]; 15 | self.signColor = [UIColor blackColor]; 16 | self.signFont = [UIFont boldSystemFontOfSize:10]; 17 | self.axisWidth = 2; 18 | } 19 | return self; 20 | } 21 | @end 22 | -------------------------------------------------------------------------------- /Source/Model/CSChartsDetailRect.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsDetailRect.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-12. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsDetailRect.h" 10 | 11 | @implementation CSChartsDetailRect 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.font = [UIFont boldSystemFontOfSize:18]; 15 | self.size = CGSizeMake(45, 25); 16 | self.color = [UIColor greenColor]; 17 | self.textFormat = @"%0.f"; 18 | self.unitString = @""; 19 | self.unitFont = [UIFont boldSystemFontOfSize:13]; 20 | } 21 | return self; 22 | } 23 | @end 24 | -------------------------------------------------------------------------------- /Sample/LineDrawer/LineDrawer.xcodeproj/xcuserdata/CruiseShen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Source/Model/CSCharts.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSCharts.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSCharts.h" 10 | 11 | @interface CSCharts(){ 12 | 13 | } 14 | 15 | @end 16 | 17 | @implementation CSCharts 18 | 19 | -(id)init{ 20 | if (self = [super init]) { 21 | self.xAxis = [[CSChartsXAxis alloc] init]; 22 | self.yAxis = [[CSChartsYAxis alloc] init]; 23 | self.background = [[CSChartsBackground alloc] init]; 24 | self.mainLine = [[CSChartsMaiLine alloc] init]; 25 | } 26 | return self; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsBackground.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsBackground.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsBackground.h" 10 | 11 | @implementation CSChartsBackground 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.viceLineColor = [UIColor lightGrayColor]; 15 | self.mainLineColor = [UIColor blackColor]; 16 | self.colorRegionArray = nil; 17 | self.isRegionSeparated = YES; 18 | self.shouldDrawHorizontalViceLines = YES; 19 | } 20 | return self; 21 | } 22 | @end 23 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsDetailRect.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsDetailRect.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-12. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsDetailRect.h" 10 | 11 | @implementation CSChartsDetailRect 12 | -(id)init{ 13 | if (self = [super init]) { 14 | self.font = [UIFont boldSystemFontOfSize:18]; 15 | self.size = CGSizeMake(45, 25); 16 | self.color = [UIColor greenColor]; 17 | self.textFormat = @"%0.f"; 18 | self.unitString = @""; 19 | self.unitFont = [UIFont boldSystemFontOfSize:13]; 20 | } 21 | return self; 22 | } 23 | @end 24 | -------------------------------------------------------------------------------- /Source/Model/CSChartsYAxis.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsYAxis.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSAxisUnit.h" 11 | 12 | @interface CSChartsYAxis : NSObject 13 | @property(nonatomic) NSInteger signAmount; 14 | @property(nonatomic) CGFloat max; 15 | @property(nonatomic) CGFloat min; 16 | @property(nonatomic,strong) UIFont *font; 17 | @property(nonatomic,strong) UIColor *color; 18 | @property(nonatomic,strong) CSAxisUnit *axisUnit; 19 | @property(nonatomic,strong) NSString *signFormat; 20 | @property(nonatomic) BOOL isNeeded; 21 | @end 22 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSCharts.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSCharts.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSCharts.h" 10 | 11 | @interface CSCharts(){ 12 | 13 | } 14 | 15 | @end 16 | 17 | @implementation CSCharts 18 | 19 | -(id)init{ 20 | if (self = [super init]) { 21 | self.xAxis = [[CSChartsXAxis alloc] init]; 22 | self.yAxis = [[CSChartsYAxis alloc] init]; 23 | self.background = [[CSChartsBackground alloc] init]; 24 | self.mainLine = [[CSChartsMaiLine alloc] init]; 25 | } 26 | return self; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Source/Model/CSChartsPoint.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsPoint.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsPoint.h" 10 | 11 | @implementation CSChartsPoint 12 | 13 | -(id)init{ 14 | if (self = [super init]) { 15 | self.shouldShowDetail = NO; 16 | self.pointStyle = CSChartsPointStyleHollow; 17 | self.color = [UIColor brownColor]; 18 | } 19 | return self; 20 | } 21 | 22 | @end 23 | 24 | CSChartsPoint *CSChartsPointMake(CGFloat x,CGFloat y){ 25 | CSChartsPoint * point = [[CSChartsPoint alloc] init]; 26 | point.x = x; 27 | point.y = y; 28 | return point; 29 | } -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsYAxis.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsYAxis.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSAxisUnit.h" 11 | 12 | @interface CSChartsYAxis : NSObject 13 | @property(nonatomic) NSInteger signAmount; 14 | @property(nonatomic) CGFloat max; 15 | @property(nonatomic) CGFloat min; 16 | @property(nonatomic,strong) UIFont *font; 17 | @property(nonatomic,strong) UIColor *color; 18 | @property(nonatomic,strong) CSAxisUnit *axisUnit; 19 | @property(nonatomic,strong) NSString *signFormat; 20 | @property(nonatomic) BOOL isNeeded; 21 | @end 22 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsPoint.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsPoint.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsPoint.h" 10 | 11 | @implementation CSChartsPoint 12 | 13 | -(id)init{ 14 | if (self = [super init]) { 15 | self.shouldShowDetail = NO; 16 | self.pointStyle = CSChartsPointStyleHollow; 17 | self.color = [UIColor brownColor]; 18 | } 19 | return self; 20 | } 21 | 22 | @end 23 | 24 | CSChartsPoint *CSChartsPointMake(CGFloat x,CGFloat y){ 25 | CSChartsPoint * point = [[CSChartsPoint alloc] init]; 26 | point.x = x; 27 | point.y = y; 28 | return point; 29 | } -------------------------------------------------------------------------------- /Sample/LineDrawer/LineDrawer.xcodeproj/xcuserdata/CarlShen.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LineDrawer.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 44F63E0718B2F59C0001398F 16 | 17 | primary 18 | 19 | 20 | 44F63E2818B2F59C0001398F 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Sample/LineDrawer/LineDrawer.xcodeproj/xcuserdata/CruiseShen.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ImgGetter.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 44F63E0718B2F59C0001398F 16 | 17 | primary 18 | 19 | 20 | 44F63E2818B2F59C0001398F 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source/Model/CSChartsPoint.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsPoint.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef enum { 12 | CSChartsPointStyleNone = -1, ///< none point 13 | CSChartsPointStyleHollow = 0, ///< hollow point 14 | CSChartsPointStyleSolid = 1, ///< solid point 15 | CSChartsPointStyleSolidWhite = 2, ///< solid white 16 | CSChartsPointStyleSolidWhiteBorder = 3 ///< solid white border 17 | } CSChartsPointStyle; 18 | 19 | 20 | @interface CSChartsPoint : NSObject 21 | 22 | @property(nonatomic) CGFloat x; 23 | @property(nonatomic) CGFloat y; 24 | @property(nonatomic) CSChartsPointStyle pointStyle; 25 | @property(nonatomic) BOOL shouldShowDetail; 26 | @property(nonatomic,strong) UIColor *color; 27 | 28 | @end 29 | 30 | //convenient method 31 | CSChartsPoint *CSChartsPointMake(CGFloat x,CGFloat y); -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSChartsPoint.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsPoint.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef enum { 12 | CSChartsPointStyleNone = -1, ///< none point 13 | CSChartsPointStyleHollow = 0, ///< hollow point 14 | CSChartsPointStyleSolid = 1, ///< solid point 15 | CSChartsPointStyleSolidWhite = 2, ///< solid white 16 | CSChartsPointStyleSolidWhiteBorder = 3 ///< solid white border 17 | } CSChartsPointStyle; 18 | 19 | 20 | @interface CSChartsPoint : NSObject 21 | 22 | @property(nonatomic) CGFloat x; 23 | @property(nonatomic) CGFloat y; 24 | @property(nonatomic) CSChartsPointStyle pointStyle; 25 | @property(nonatomic) BOOL shouldShowDetail; 26 | @property(nonatomic,strong) UIColor *color; 27 | 28 | @end 29 | 30 | //convenient method 31 | CSChartsPoint *CSChartsPointMake(CGFloat x,CGFloat y); -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | CSChartsView - Copyright (C) 2014 Carl Shen (344208651@qq.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /CSChartsView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "CSChartsView" 3 | s.version = "0.1.0" 4 | s.summary = "A light weight line graph drawing framework" 5 | s.description = "This is a light weight line graph drawing framework,it is easy to use." 6 | s.homepage = "https://github.com/sk344208651/CSChartsView" 7 | s.license = { :type => "MIT" } 8 | s.authors = { "Carl Shen" => "344208651@qq.com" } 9 | s.platform = :ios, "6.0" 10 | s.source = { :git => "https://github.com/sk344208651/CSChartsView.git", :tag => "0.1.0" } 11 | s.source_files = "Source/**/*.{h,m}" 12 | s.frameworks = "CoreGraphics", "UIKit" ,"Foundation" 13 | s.requires_arc = true 14 | s.screenshorts = ["https://raw.githubusercontent.com/sk344208651/CSChartsView/master/Image/IMG_0470.PNG","https://raw.githubusercontent.com/sk344208651/CSChartsView/master/Image/IMG_0473.PNG","https://raw.githubusercontent.com/sk344208651/CSChartsView/master/Image/IMG_0478.PNG","https://raw.githubusercontent.com/sk344208651/CSChartsView/master/Image/IMG_0479.PNG","https://raw.githubusercontent.com/sk344208651/CSChartsView/master/Image/IMG_0480.PNG"] 15 | end 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CSChartsView 2 | ============ 3 | 4 | **Introducing CSChartsView** -A light weight line graph drawing framework 5 | 6 | ## Features 7 | 8 | - iPhone and iPad support 9 | 10 | ##Requirements 11 | - Requires iOS 6.0 or later 12 | - Requires Automatic Reference Counting (ARC) 13 | 14 | ## Installation & Usage 15 | If you're using [CocoaPods](http://www.cocoapods.org), simply add `pod ‘CSChartsView’` to your Podfile. If you wish to use the **static library** check out the installation documentation 16 | 17 | ## Consulting 18 | 19 | If you need **additional support** or help **integrating** and/or **customizing** the controller for your project, feel free to get in touch ([344208651@qq.com](mailto:344208651@qq.com)). 20 | 21 | ## PreViewing 22 | ![Alt text](https://raw.githubusercontent.com/sk344208651/CSChartsView/master/Image/IMG_0470.PNG) 23 | ![Alt text](https://raw.githubusercontent.com/sk344208651/CSChartsView/master/Image/IMG_0473.PNG) 24 | ![Alt text](https://raw.githubusercontent.com/sk344208651/CSChartsView/master/Image/IMG_0478.PNG) 25 | ![Alt text](https://raw.githubusercontent.com/sk344208651/CSChartsView/master/Image/IMG_0479.PNG) 26 | ![Alt text](https://raw.githubusercontent.com/sk344208651/CSChartsView/master/Image/IMG_0480.PNG) -------------------------------------------------------------------------------- /Source/Model/CSCharts.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSCharts.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #define CSCHARTS_SPACING 5 10 | #define CSCHARTS_DETAILRECT_FROM_MAINLINE_SPACING 10 11 | #define PORT_SPACING_RATE 0.10135135135135 12 | #define TAP_GESTURE_REG_RADIUS 20 13 | #define CSCHARTS_TOP_EXTRA_SPACING 2 14 | 15 | #import 16 | #import "CSChartsXAxis.h" 17 | #import "CSChartsYAxis.h" 18 | #import "CSChartsBackground.h" 19 | #import "CSChartsMaiLine.h" 20 | 21 | @interface CSCharts : NSObject{ 22 | @public 23 | //auxiliary parameters 24 | CGPoint points[12]; 25 | } 26 | @property(nonatomic,strong) CSChartsXAxis *xAxis; 27 | @property(nonatomic,strong) CSChartsYAxis *yAxis; 28 | @property(nonatomic,strong) CSChartsBackground *background; 29 | @property(nonatomic,strong) CSChartsMaiLine *mainLine; 30 | @property(nonatomic) CGRect frame; 31 | 32 | 33 | 34 | //auxiliary parameters 35 | //@property(nonatomic,) 36 | @property(nonatomic,readonly) CGFloat bottomSpacing; 37 | @property(nonatomic,readonly) CGFloat leftSpacing; 38 | @property(nonatomic,readonly) CGFloat topSpacing; 39 | @property(nonatomic,readonly) NSInteger horizontalLineAmount; 40 | @property(nonatomic,readonly) NSInteger verticalLineAmount; 41 | @end 42 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Model/CSCharts.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSCharts.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #define CSCHARTS_SPACING 5 10 | #define CSCHARTS_DETAILRECT_FROM_MAINLINE_SPACING 10 11 | #define PORT_SPACING_RATE 0.10135135135135 12 | #define TAP_GESTURE_REG_RADIUS 20 13 | #define CSCHARTS_TOP_EXTRA_SPACING 2 14 | 15 | #import 16 | #import "CSChartsXAxis.h" 17 | #import "CSChartsYAxis.h" 18 | #import "CSChartsBackground.h" 19 | #import "CSChartsMaiLine.h" 20 | 21 | @interface CSCharts : NSObject{ 22 | @public 23 | //auxiliary parameters 24 | CGPoint points[100]; 25 | } 26 | @property(nonatomic,strong) CSChartsXAxis *xAxis; 27 | @property(nonatomic,strong) CSChartsYAxis *yAxis; 28 | @property(nonatomic,strong) CSChartsBackground *background; 29 | @property(nonatomic,strong) CSChartsMaiLine *mainLine; 30 | @property(nonatomic) CGRect frame; 31 | 32 | 33 | 34 | //auxiliary parameters 35 | //@property(nonatomic,) 36 | @property(nonatomic,readonly) CGFloat bottomSpacing; 37 | @property(nonatomic,readonly) CGFloat leftSpacing; 38 | @property(nonatomic,readonly) CGFloat topSpacing; 39 | @property(nonatomic,readonly) NSInteger horizontalLineAmount; 40 | @property(nonatomic,readonly) NSInteger verticalLineAmount; 41 | @end 42 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/LineDrawer-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | CruiseShen.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Source/NSString+BoundingRect.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+BoundingRect.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-5. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "NSString+BoundingRect.h" 10 | 11 | @implementation NSString (BoundingRect) 12 | -(NSMutableAttributedString *)attributedStringFromStingWithFont:(UIFont *)font 13 | withLineSpacing:(CGFloat)lineSpacing 14 | { 15 | NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:self attributes:@{NSFontAttributeName:font}]; 16 | 17 | NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; 18 | [paragraphStyle setLineSpacing:lineSpacing]; 19 | 20 | [attributedStr addAttribute:NSParagraphStyleAttributeName 21 | value:paragraphStyle 22 | range:NSMakeRange(0, [self length])]; 23 | return attributedStr; 24 | } 25 | 26 | -(CGSize)boundingRectWithSize:(CGSize)size 27 | withTextFont:(UIFont *)font 28 | withLineSpacing:(CGFloat)lineSpacing 29 | { 30 | NSMutableAttributedString *attributedText = [self attributedStringFromStingWithFont:font withLineSpacing:lineSpacing]; 31 | CGSize textSize = [attributedText boundingRectWithSize:size 32 | options:NSStringDrawingUsesLineFragmentOrigin 33 | context:nil].size; 34 | return textSize; 35 | } 36 | @end 37 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/NSString+BoundingRect.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+BoundingRect.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-5. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "NSString+BoundingRect.h" 10 | 11 | @implementation NSString (BoundingRect) 12 | -(NSMutableAttributedString *)attributedStringFromStingWithFont:(UIFont *)font 13 | withLineSpacing:(CGFloat)lineSpacing 14 | { 15 | NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:self attributes:@{NSFontAttributeName:font}]; 16 | 17 | NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; 18 | [paragraphStyle setLineSpacing:lineSpacing]; 19 | 20 | [attributedStr addAttribute:NSParagraphStyleAttributeName 21 | value:paragraphStyle 22 | range:NSMakeRange(0, [self length])]; 23 | return attributedStr; 24 | } 25 | 26 | -(CGSize)boundingRectWithSize:(CGSize)size 27 | withTextFont:(UIFont *)font 28 | withLineSpacing:(CGFloat)lineSpacing 29 | { 30 | NSMutableAttributedString *attributedText = [self attributedStringFromStingWithFont:font withLineSpacing:lineSpacing]; 31 | CGSize textSize = [attributedText boundingRectWithSize:size 32 | options:NSStringDrawingUsesLineFragmentOrigin 33 | context:nil].size; 34 | return textSize; 35 | } 36 | @end 37 | -------------------------------------------------------------------------------- /Sample/LineDrawer/LineDrawer.xcodeproj/project.xcworkspace/xcshareddata/LineDrawer.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 2B986CF8-2409-4B7C-A406-A208878B3CD9 9 | IDESourceControlProjectName 10 | LineDrawer 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | B0EFEF98809F096F17B59945AC4AA3F674CB63AF 14 | https://github.com/sk344208651/CSChartsView.git 15 | 16 | IDESourceControlProjectPath 17 | Sample/LineDrawer/LineDrawer.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | B0EFEF98809F096F17B59945AC4AA3F674CB63AF 21 | ../../../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/sk344208651/CSChartsView.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | B0EFEF98809F096F17B59945AC4AA3F674CB63AF 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | B0EFEF98809F096F17B59945AC4AA3F674CB63AF 36 | IDESourceControlWCCName 37 | CSChartsView 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-2-18. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "RootViewController.h" 11 | 12 | @implementation AppDelegate 13 | 14 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 15 | { 16 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 17 | self.window.rootViewController = [[RootViewController alloc] init]; 18 | self.window.backgroundColor = [UIColor whiteColor]; 19 | [self.window makeKeyAndVisible]; 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application 24 | { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 27 | } 28 | 29 | - (void)applicationDidEnterBackground:(UIApplication *)application 30 | { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | - (void)applicationWillEnterForeground:(UIApplication *)application 36 | { 37 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | - (void)applicationDidBecomeActive:(UIApplication *)application 41 | { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | - (void)applicationWillTerminate:(UIApplication *)application 46 | { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /Source/CSChartsView.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsView.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSChartsPoint.h" 11 | 12 | @protocol CSChartsViewDelegate 13 | 14 | @optional 15 | -(void)pointSelected:(NSInteger) index; 16 | -(void)leftSwipeGesturePerformed; 17 | -(void)rightSwipeGesturePerformed; 18 | -(void)pinchGesturePerformed:(UIPinchGestureRecognizer *) pinchGestureRecognizer; 19 | @end 20 | 21 | @interface CSChartsView : UIView 22 | @property(nonatomic,strong) UIColor *mainLineColor UI_APPEARANCE_SELECTOR; 23 | 24 | //delegate 25 | @property(nonatomic,weak) id delegate; 26 | 27 | //detail rect 28 | @property(nonatomic) CGSize detailRectSize UI_APPEARANCE_SELECTOR; 29 | @property(nonatomic,strong) UIFont *detailRectFont UI_APPEARANCE_SELECTOR; 30 | @property(nonatomic,strong) UIColor *detailRectColor UI_APPEARANCE_SELECTOR; 31 | @property(nonatomic,strong) NSString *detailRectTextFormat UI_APPEARANCE_SELECTOR; 32 | @property(nonatomic,strong) NSString *detailRectUnitString UI_APPEARANCE_SELECTOR; 33 | @property(nonatomic,strong) UIFont *detailRectUnitFont UI_APPEARANCE_SELECTOR; 34 | 35 | //background 36 | @property(nonatomic,strong) UIColor *backgroundViceLineColor UI_APPEARANCE_SELECTOR; 37 | @property(nonatomic,strong) UIColor *backgroundMainLineColor UI_APPEARANCE_SELECTOR; 38 | @property(nonatomic,strong) NSArray *colorRegionArray UI_APPEARANCE_SELECTOR; 39 | @property(nonatomic) BOOL isRegionSeparated UI_APPEARANCE_SELECTOR; 40 | @property(nonatomic) BOOL shouldDrawHorizontalViceLines UI_APPEARANCE_SELECTOR; 41 | 42 | //y Axis 43 | @property(nonatomic,strong) UIFont *yAxisFont UI_APPEARANCE_SELECTOR; 44 | @property(nonatomic,strong) UIColor *yAxisColor UI_APPEARANCE_SELECTOR; 45 | @property(nonatomic,strong) NSString *yAxisSignFormat UI_APPEARANCE_SELECTOR; 46 | @property(nonatomic,strong) NSString *yAxisUnitString UI_APPEARANCE_SELECTOR; 47 | @property(nonatomic,strong) UIFont *yAxisUnitFont UI_APPEARANCE_SELECTOR; 48 | @property(nonatomic,strong) UIColor *yAxisUnitColor UI_APPEARANCE_SELECTOR; 49 | @property(nonatomic) BOOL needYAxis UI_APPEARANCE_SELECTOR; 50 | 51 | //x Axis 52 | @property(nonatomic,strong) UIColor *xAxisColor UI_APPEARANCE_SELECTOR; 53 | @property(nonatomic,strong) UIColor *xAxisSignColor UI_APPEARANCE_SELECTOR; 54 | @property(nonatomic,strong) UIFont *xAxisSignFont UI_APPEARANCE_SELECTOR; 55 | 56 | //necessary property 57 | @property(nonatomic,strong) NSArray *mainLinePointArray; 58 | @property(nonatomic,strong) NSArray *xAxisSignArray; 59 | @property(nonatomic) NSInteger yAxisSignAmount; 60 | @property(nonatomic) CGFloat yAxisMax; 61 | @property(nonatomic) CGFloat yAxisMin; 62 | 63 | //refresh view 64 | -(void) refreshCSChartsView; 65 | -(void) refreshBackgroundLayer; 66 | -(void) refreshMainLineLayer; 67 | -(void) refreshXAxisLayer; 68 | 69 | @end 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/CSChartsView.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsView.h 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSChartsPoint.h" 11 | 12 | @protocol CSChartsViewDelegate 13 | 14 | @optional 15 | -(void)pointSelected:(NSInteger) index; 16 | -(void)leftSwipeGesturePerformed; 17 | -(void)rightSwipeGesturePerformed; 18 | -(void)pinchGesturePerformed:(UIPinchGestureRecognizer *) pinchGestureRecognizer; 19 | @end 20 | 21 | @interface CSChartsView : UIView 22 | @property(nonatomic,strong) UIColor *mainLineColor UI_APPEARANCE_SELECTOR; 23 | 24 | //delegate 25 | @property(nonatomic,weak) id delegate; 26 | 27 | //detail rect 28 | @property(nonatomic) CGSize detailRectSize UI_APPEARANCE_SELECTOR; 29 | @property(nonatomic,strong) UIFont *detailRectFont UI_APPEARANCE_SELECTOR; 30 | @property(nonatomic,strong) UIColor *detailRectColor UI_APPEARANCE_SELECTOR; 31 | @property(nonatomic,strong) NSString *detailRectTextFormat UI_APPEARANCE_SELECTOR; 32 | @property(nonatomic,strong) NSString *detailRectUnitString UI_APPEARANCE_SELECTOR; 33 | @property(nonatomic,strong) UIFont *detailRectUnitFont UI_APPEARANCE_SELECTOR; 34 | 35 | //background 36 | @property(nonatomic,strong) UIColor *backgroundViceLineColor UI_APPEARANCE_SELECTOR; 37 | @property(nonatomic,strong) UIColor *backgroundMainLineColor UI_APPEARANCE_SELECTOR; 38 | @property(nonatomic,strong) NSArray *colorRegionArray UI_APPEARANCE_SELECTOR; 39 | @property(nonatomic) BOOL isRegionSeparated UI_APPEARANCE_SELECTOR; 40 | @property(nonatomic) BOOL shouldDrawHorizontalViceLines UI_APPEARANCE_SELECTOR; 41 | 42 | //y Axis 43 | @property(nonatomic,strong) UIFont *yAxisFont UI_APPEARANCE_SELECTOR; 44 | @property(nonatomic,strong) UIColor *yAxisColor UI_APPEARANCE_SELECTOR; 45 | @property(nonatomic,strong) NSString *yAxisSignFormat UI_APPEARANCE_SELECTOR; 46 | @property(nonatomic,strong) NSString *yAxisUnitString UI_APPEARANCE_SELECTOR; 47 | @property(nonatomic,strong) UIFont *yAxisUnitFont UI_APPEARANCE_SELECTOR; 48 | @property(nonatomic,strong) UIColor *yAxisUnitColor UI_APPEARANCE_SELECTOR; 49 | @property(nonatomic) BOOL needYAxis UI_APPEARANCE_SELECTOR; 50 | 51 | //x Axis 52 | @property(nonatomic,strong) UIColor *xAxisColor UI_APPEARANCE_SELECTOR; 53 | @property(nonatomic,strong) UIColor *xAxisSignColor UI_APPEARANCE_SELECTOR; 54 | @property(nonatomic,strong) UIFont *xAxisSignFont UI_APPEARANCE_SELECTOR; 55 | 56 | //necessary property 57 | @property(nonatomic,strong) NSArray *mainLinePointArray; 58 | @property(nonatomic,strong) NSArray *xAxisSignArray; 59 | @property(nonatomic) NSInteger yAxisSignAmount; 60 | @property(nonatomic) CGFloat yAxisMax; 61 | @property(nonatomic) CGFloat yAxisMin; 62 | 63 | //refresh view 64 | -(void) refreshCSChartsView; 65 | -(void) refreshBackgroundLayer; 66 | -(void) refreshMainLineLayer; 67 | -(void) refreshXAxisLayer; 68 | 69 | @end 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/RootViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-3. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "RootViewController.h" 10 | #import "CSChartsColorRegion.h" 11 | 12 | @interface RootViewController (){ 13 | } 14 | 15 | @end 16 | 17 | @implementation RootViewController 18 | 19 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 20 | { 21 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 22 | if (self) { 23 | // Custom initialization 24 | } 25 | return self; 26 | } 27 | 28 | - (void)viewDidLoad 29 | { 30 | [super viewDidLoad]; 31 | self.chartsView = [[CSChartsView alloc] initWithFrame:CGRectMake(0, 135, 320, 433)]; 32 | [self.view addSubview:self.chartsView]; 33 | self.chartsView.yAxisMax = 100; 34 | self.chartsView.yAxisMin = 0; 35 | self.chartsView.yAxisSignAmount = 5; 36 | self.chartsView.yAxisSignFormat = @"%0.0f"; 37 | self.chartsView.detailRectUnitString = @"times/h"; 38 | self.chartsView.detailRectSize = CGSizeMake(80, 25); 39 | self.chartsView.xAxisSignArray = [NSArray arrayWithObjects:@"Feb 9",@"10",@"11",@"12",@"13",@"14",@"Feb 15 ", nil]; 40 | 41 | self.chartsView.delegate = self; 42 | //p0 43 | CSChartsPoint *point0 = CSChartsPointMake(-1, 40); 44 | point0.pointStyle = CSChartsPointStyleSolidWhite; 45 | point0.color = [UIColor colorWithRed:228 / 255.0 green:81 / 255.0 blue:26 / 255.0 alpha:1]; 46 | //p1 47 | CSChartsPoint *point1 = CSChartsPointMake(0, 50); 48 | point1.pointStyle = CSChartsPointStyleSolidWhite; 49 | point1.color = [UIColor colorWithRed:228 / 255.0 green:81 / 255.0 blue:26 / 255.0 alpha:1]; 50 | //p2 51 | CSChartsPoint *point2 = CSChartsPointMake(1, 22); 52 | point2.pointStyle = CSChartsPointStyleSolidWhite; 53 | point2.color = [UIColor colorWithRed:154 / 255.0 green:0 / 255.0 blue:28 / 255.0 alpha:1]; 54 | //p3 55 | CSChartsPoint *point3 = CSChartsPointMake(2, 30); 56 | point3.pointStyle = CSChartsPointStyleSolidWhite; 57 | point3.color = [UIColor colorWithRed:154 / 255.0 green:0 / 255.0 blue:28 / 255.0 alpha:1]; 58 | //p4 59 | CSChartsPoint *point4 = CSChartsPointMake(3, 0); 60 | point4.pointStyle = CSChartsPointStyleSolidWhite; 61 | point4.color = [UIColor colorWithRed:228 / 255.0 green:81 / 255.0 blue:26 / 255.0 alpha:1]; 62 | //p5 63 | CSChartsPoint *point5 = CSChartsPointMake(4, 65); 64 | point5.pointStyle = CSChartsPointStyleSolidWhite; 65 | point5.color = [UIColor colorWithRed:228 / 255.0 green:81 / 255.0 blue:26 / 255.0 alpha:1]; 66 | //p6 67 | CSChartsPoint *point6 = CSChartsPointMake(6, 100); 68 | point6.pointStyle = CSChartsPointStyleSolidWhiteBorder; 69 | point6.color = [UIColor colorWithRed:228 / 255.0 green:81 / 255.0 blue:26 / 255.0 alpha:1]; 70 | point6.shouldShowDetail = YES; 71 | 72 | self.chartsView.mainLinePointArray = [NSArray arrayWithObjects:point0,point1,point2,point3,point4,point5,point6, nil]; 73 | self.chartsView.detailRectTextFormat = @"%0.f "; 74 | self.chartsView.isRegionSeparated = NO; 75 | self.chartsView.colorRegionArray = [NSArray arrayWithObjects:CSChartsColorRegionMake([UIColor colorWithRed:211 / 255.0 green:234 / 255.0 blue:210 / 255.0 alpha:1], 40),CSChartsColorRegionMake([UIColor colorWithRed:244 / 255.0 green:250 / 255.0 blue:246 / 255.0 alpha:1], 40),nil]; 76 | } 77 | 78 | -(void)leftSwipeGesturePerformed{ 79 | NSLog(@"leftSwipeGesturePerformed"); 80 | } 81 | 82 | -(void)rightSwipeGesturePerformed{ 83 | NSLog(@"rightSwipeGesturePerformed"); 84 | } 85 | 86 | -(void)pinchGesturePerformed:(UIPinchGestureRecognizer *)pinchGestureRecognizer{ 87 | if (pinchGestureRecognizer.state == UIGestureRecognizerStateEnded) { 88 | NSLog(@"pinchGesturePerformed"); 89 | } 90 | } 91 | @end 92 | -------------------------------------------------------------------------------- /Sample/LineDrawer/LineDrawer.xcodeproj/xcuserdata/CruiseShen.xcuserdatad/xcschemes/ImgGetter.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 61 | 62 | 68 | 69 | 70 | 71 | 72 | 73 | 79 | 80 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Source/Layer/CSChartsXAxisLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsXAxisLayer.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsXAxisLayer.h" 10 | #import "NSString+BoundingRect.h" 11 | 12 | @interface CSChartsXAxisLayer (){ 13 | CGSize yAxisCharacterSize; 14 | CGSize xAxisCharacterSize; 15 | CGFloat bottomSpacing; 16 | CGFloat leftSpacing; 17 | CGFloat topSpacing; 18 | NSInteger horizontalLineAmount; 19 | CGFloat horizontalSpacing; 20 | NSUInteger verticalLineAmount; 21 | CGFloat portSpacing; 22 | CGFloat verticalSpacing; 23 | CGFloat chartsContentHeight; 24 | CGFloat yAxisMax; 25 | CGFloat yAxisMin; 26 | CGFloat xAxisYPosition; 27 | } 28 | @end 29 | 30 | @implementation CSChartsXAxisLayer 31 | -(void)drawInContext:(CGContextRef)ctx{ 32 | [self paramsPreparation]; 33 | /*********************/ 34 | /* draw X Axis lines */ 35 | /*********************/ 36 | [self drawXAxisLines:ctx]; 37 | 38 | /*********************/ 39 | /* draw X Axis signs */ 40 | /*********************/ 41 | [self drawXAxisSigns:ctx]; 42 | } 43 | 44 | #pragma mark - private 45 | #pragma mark -- draw method 46 | -(void)drawXAxisLines:(CGContextRef)ctx{ 47 | CGPoint points[2]; 48 | //set line width 49 | CGContextSetLineWidth(ctx, self.charts.xAxis.axisWidth); 50 | //set line style 51 | CGContextSetLineCap(ctx, kCGLineCapRound); 52 | //set anti alias off 53 | CGContextSetShouldAntialias(ctx, NO); 54 | //set line color 55 | CGContextSetStrokeColorWithColor(ctx, self.charts.xAxis.color.CGColor); 56 | //set the points 57 | points[0] = CGPointMake(self.charts.frame.size.width, xAxisYPosition); 58 | points[1] = CGPointMake(leftSpacing, xAxisYPosition); 59 | CGContextAddLines(ctx, points, 2); 60 | //commit draw 61 | CGContextStrokePath(ctx); 62 | } 63 | 64 | -(void)drawXAxisSigns:(CGContextRef)ctx{ 65 | UIColor *xAxisSignColor = self.charts.xAxis.signColor; 66 | UIFont *xAxisSignFont = self.charts.xAxis.signFont; 67 | CGFloat xAxisSignPosition = leftSpacing + portSpacing; 68 | 69 | //set Anti alias 70 | CGContextSetShouldAntialias(ctx, YES); 71 | 72 | CGContextSetFillColorWithColor(ctx, xAxisSignColor.CGColor); 73 | UIGraphicsPushContext(ctx); 74 | for (int i = 0; i < self.charts.xAxis.signArray.count; i ++ , xAxisSignPosition += verticalSpacing) { 75 | //draw characters 76 | NSString *drawString = [self.charts.xAxis.signArray objectAtIndex:i]; 77 | CGSize drawStringSize = [drawString boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 78 | // [drawString drawAtPoint:CGPointMake(xAxisSignPosition - drawStringSize.width / 2, xAxisYPosition + CSCHARTS_SPACING) withAttributes:attributes]; 79 | [drawString drawAtPoint:CGPointMake(xAxisSignPosition - drawStringSize.width / 2, xAxisYPosition + CSCHARTS_SPACING) withFont:xAxisSignFont]; 80 | } 81 | UIGraphicsPopContext(); 82 | } 83 | 84 | #pragma mark -- param init method 85 | -(void)paramsPreparation{ 86 | yAxisCharacterSize = [[NSString stringWithFormat:@"%0.f",self.charts.yAxis.max] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 87 | xAxisCharacterSize = [[self.charts.xAxis.signArray objectAtIndex:0] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.xAxis.signFont withLineSpacing:3]; 88 | bottomSpacing = xAxisCharacterSize.height + CSCHARTS_SPACING * 2; 89 | if (self.charts.yAxis.isNeeded) { 90 | leftSpacing = yAxisCharacterSize.width + CSCHARTS_SPACING * 2; 91 | }else{ 92 | leftSpacing = 0; 93 | } 94 | topSpacing = yAxisCharacterSize.height / 2 + CSCHARTS_TOP_EXTRA_SPACING; 95 | horizontalLineAmount = (self.charts.yAxis.signAmount - 1) * 5; 96 | horizontalSpacing = (self.charts.frame.size.height - topSpacing - bottomSpacing) / (horizontalLineAmount - 1); 97 | verticalLineAmount = self.charts.xAxis.signArray.count; 98 | portSpacing = (self.charts.frame.size.width - leftSpacing) * PORT_SPACING_RATE; 99 | 100 | verticalSpacing = (self.charts.frame.size.width - portSpacing * 2 - leftSpacing) / (verticalLineAmount - 1); 101 | yAxisMax = self.charts.yAxis.max; 102 | yAxisMin = self.charts.yAxis.min; 103 | chartsContentHeight = self.charts.frame.size.height - bottomSpacing - topSpacing; 104 | xAxisYPosition = self.charts.frame.size.height - bottomSpacing - self.charts.xAxis.axisWidth / 2; 105 | } 106 | 107 | @end 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Layer/CSChartsXAxisLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsXAxisLayer.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsXAxisLayer.h" 10 | #import "NSString+BoundingRect.h" 11 | 12 | @interface CSChartsXAxisLayer (){ 13 | CGSize yAxisCharacterSize; 14 | CGSize xAxisCharacterSize; 15 | CGFloat bottomSpacing; 16 | CGFloat leftSpacing; 17 | CGFloat topSpacing; 18 | NSInteger horizontalLineAmount; 19 | CGFloat horizontalSpacing; 20 | NSUInteger verticalLineAmount; 21 | CGFloat portSpacing; 22 | CGFloat verticalSpacing; 23 | CGFloat chartsContentHeight; 24 | CGFloat yAxisMax; 25 | CGFloat yAxisMin; 26 | CGFloat xAxisYPosition; 27 | } 28 | @end 29 | 30 | @implementation CSChartsXAxisLayer 31 | -(void)drawInContext:(CGContextRef)ctx{ 32 | [self paramsPreparation]; 33 | /*********************/ 34 | /* draw X Axis lines */ 35 | /*********************/ 36 | [self drawXAxisLines:ctx]; 37 | 38 | /*********************/ 39 | /* draw X Axis signs */ 40 | /*********************/ 41 | [self drawXAxisSigns:ctx]; 42 | } 43 | 44 | #pragma mark - private 45 | #pragma mark -- draw method 46 | -(void)drawXAxisLines:(CGContextRef)ctx{ 47 | CGPoint points[2]; 48 | //set line width 49 | CGContextSetLineWidth(ctx, self.charts.xAxis.axisWidth); 50 | //set line style 51 | CGContextSetLineCap(ctx, kCGLineCapRound); 52 | //set anti alias off 53 | CGContextSetShouldAntialias(ctx, NO); 54 | //set line color 55 | CGContextSetStrokeColorWithColor(ctx, self.charts.xAxis.color.CGColor); 56 | //set the points 57 | points[0] = CGPointMake(self.charts.frame.size.width, xAxisYPosition); 58 | points[1] = CGPointMake(leftSpacing, xAxisYPosition); 59 | CGContextAddLines(ctx, points, 2); 60 | //commit draw 61 | CGContextStrokePath(ctx); 62 | } 63 | 64 | -(void)drawXAxisSigns:(CGContextRef)ctx{ 65 | UIColor *xAxisSignColor = self.charts.xAxis.signColor; 66 | UIFont *xAxisSignFont = self.charts.xAxis.signFont; 67 | CGFloat xAxisSignPosition = leftSpacing + portSpacing; 68 | 69 | //set Anti alias 70 | CGContextSetShouldAntialias(ctx, YES); 71 | 72 | CGContextSetFillColorWithColor(ctx, xAxisSignColor.CGColor); 73 | UIGraphicsPushContext(ctx); 74 | for (int i = 0; i < self.charts.xAxis.signArray.count; i ++ , xAxisSignPosition += verticalSpacing) { 75 | //draw characters 76 | NSString *drawString = [self.charts.xAxis.signArray objectAtIndex:i]; 77 | CGSize drawStringSize = [drawString boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 78 | // [drawString drawAtPoint:CGPointMake(xAxisSignPosition - drawStringSize.width / 2, xAxisYPosition + CSCHARTS_SPACING) withAttributes:attributes]; 79 | [drawString drawAtPoint:CGPointMake(xAxisSignPosition - drawStringSize.width / 2, xAxisYPosition + CSCHARTS_SPACING) withFont:xAxisSignFont]; 80 | } 81 | UIGraphicsPopContext(); 82 | } 83 | 84 | #pragma mark -- param init method 85 | -(void)paramsPreparation{ 86 | yAxisCharacterSize = [[NSString stringWithFormat:@"%0.f",self.charts.yAxis.max] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 87 | xAxisCharacterSize = [[self.charts.xAxis.signArray objectAtIndex:0] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.xAxis.signFont withLineSpacing:3]; 88 | bottomSpacing = xAxisCharacterSize.height + CSCHARTS_SPACING * 2; 89 | if (self.charts.yAxis.isNeeded) { 90 | leftSpacing = yAxisCharacterSize.width + CSCHARTS_SPACING * 2; 91 | }else{ 92 | leftSpacing = 0; 93 | } 94 | topSpacing = yAxisCharacterSize.height / 2 + CSCHARTS_TOP_EXTRA_SPACING; 95 | horizontalLineAmount = (self.charts.yAxis.signAmount - 1) * 5; 96 | horizontalSpacing = (self.charts.frame.size.height - topSpacing - bottomSpacing) / (horizontalLineAmount - 1); 97 | verticalLineAmount = self.charts.xAxis.signArray.count; 98 | portSpacing = (self.charts.frame.size.width - leftSpacing) * PORT_SPACING_RATE; 99 | 100 | verticalSpacing = (self.charts.frame.size.width - portSpacing * 2 - leftSpacing) / (verticalLineAmount - 1); 101 | yAxisMax = self.charts.yAxis.max; 102 | yAxisMin = self.charts.yAxis.min; 103 | chartsContentHeight = self.charts.frame.size.height - bottomSpacing - topSpacing; 104 | xAxisYPosition = self.charts.frame.size.height - bottomSpacing - self.charts.xAxis.axisWidth / 2; 105 | } 106 | 107 | @end 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /Sample/LineDrawer/LineDrawer.xcodeproj/xcuserdata/CarlShen.xcuserdatad/xcschemes/LineDrawer.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 94 | 100 | 101 | 102 | 103 | 105 | 106 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /Source/Layer/CSChartsMainLineLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsMainLineLayer.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsMainLineLayer.h" 10 | #import "NSString+BoundingRect.h" 11 | #import "CSChartsPoint.h" 12 | 13 | @interface CSChartsMainLineLayer (){ 14 | CGSize yAxisCharacterSize; 15 | CGSize xAxisCharacterSize; 16 | CGFloat bottomSpacing; 17 | CGFloat leftSpacing; 18 | CGFloat topSpacing; 19 | NSInteger horizontalLineAmount; 20 | CGFloat horizontalSpacing; 21 | NSUInteger verticalLineAmount; 22 | CGFloat portSpacing; 23 | CGFloat verticalSpacing; 24 | CGFloat chartsContentHeight; 25 | CGFloat yAxisMax; 26 | CGFloat yAxisMin; 27 | } 28 | @end 29 | 30 | @implementation CSChartsMainLineLayer 31 | 32 | -(void)drawInContext:(CGContextRef)ctx{ 33 | [self paramsPreparation]; 34 | /*******************/ 35 | /* draw main lines */ 36 | /*******************/ 37 | [self drawMainLines:ctx]; 38 | 39 | /***************/ 40 | /* draw points */ 41 | /***************/ 42 | [self drawPoints:ctx]; 43 | 44 | /********************/ 45 | /* draw detail rect */ 46 | /********************/ 47 | [self drawDetailRect:ctx]; 48 | } 49 | 50 | -(void)drawDetailRect:(CGContextRef)ctx{ 51 | NSArray *pointArray = self.charts.mainLine.pointArray; 52 | for (int i = 0; i < pointArray.count; i++) { 53 | CSChartsPoint *tempPoint = [pointArray objectAtIndex:i]; 54 | if (tempPoint.shouldShowDetail) { 55 | CGFloat detailRectWidth = self.charts.mainLine.detailRect.size.width; 56 | CGFloat detailRectHeight = self.charts.mainLine.detailRect.size.height; 57 | CGPoint detailRectPoint = [self calculateDetalRectPosition:self.charts -> points[i]]; 58 | CGFloat detailRectX = detailRectPoint.x; 59 | CGFloat detailRectY = detailRectPoint.y; 60 | //draw detail rect 61 | //set line color 62 | CGContextSetFillColorWithColor(ctx, self.charts.mainLine.detailRect.color.CGColor); 63 | //set fill rect 64 | CGContextBeginPath(ctx); 65 | //set 4 points for the rect 66 | //1 67 | CGContextMoveToPoint(ctx, detailRectX, detailRectY); 68 | //2 69 | CGContextAddLineToPoint(ctx, detailRectX + detailRectWidth, detailRectY); 70 | //3 71 | CGContextAddLineToPoint(ctx, detailRectX + detailRectWidth, detailRectY + detailRectHeight); 72 | //4 73 | CGContextAddLineToPoint(ctx, detailRectX, detailRectY + detailRectHeight); 74 | 75 | CGContextClosePath(ctx); 76 | //commit draw 77 | CGContextFillPath(ctx); 78 | 79 | //draw detail rect triangle 80 | //set line color 81 | CGContextSetFillColorWithColor(ctx, self.charts.mainLine.detailRect.color.CGColor); 82 | //set fill triangle 83 | CGContextBeginPath(ctx); 84 | //set 3 points for the triangle 85 | CGFloat point1Y = detailRectY - self.charts -> points[i].y < 0 ? self.charts -> points[i].y - CSCHARTS_DETAILRECT_FROM_MAINLINE_SPACING : self.charts -> points[i].y + CSCHARTS_DETAILRECT_FROM_MAINLINE_SPACING; 86 | CGFloat point2Y = detailRectY - self.charts -> points[i].y < 0 ? detailRectY + detailRectHeight - 1 : detailRectY + 1; 87 | //1 88 | CGContextMoveToPoint(ctx, self.charts -> points[i].x, point1Y); 89 | //2 90 | CGContextAddLineToPoint(ctx, self.charts -> points[i].x - 6, point2Y); 91 | //3 92 | CGContextAddLineToPoint(ctx, self.charts -> points[i].x + 6, point2Y); 93 | 94 | CGContextClosePath(ctx); 95 | //commit draw 96 | CGContextFillPath(ctx); 97 | 98 | //draw detail text 99 | //set Anti alias 100 | CGContextSetShouldAntialias(ctx, YES); 101 | CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); 102 | UIGraphicsPushContext(ctx); 103 | 104 | NSString *drawString = [NSString stringWithFormat:self.charts.mainLine.detailRect.textFormat,tempPoint.y]; 105 | CGSize drawStringSize = [drawString boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.mainLine.detailRect.font withLineSpacing:3]; 106 | NSString *unitString = self.charts.mainLine.detailRect.unitString; 107 | CGSize unitStringSize = [unitString boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.mainLine.detailRect.unitFont withLineSpacing:3]; 108 | 109 | //draw characters 110 | [drawString drawAtPoint:CGPointMake(detailRectX + (detailRectWidth - drawStringSize.width - unitStringSize.width) / 2, detailRectY + (detailRectHeight - drawStringSize.height) / 2) withFont:self.charts.mainLine.detailRect.font]; 111 | //draw unit 112 | 113 | [unitString drawAtPoint:CGPointMake(detailRectX + (detailRectWidth - drawStringSize.width - unitStringSize.width) / 2 + drawStringSize.width, detailRectY + (detailRectHeight - unitStringSize.height) / 2 ) withFont:self.charts.mainLine.detailRect.unitFont]; 114 | UIGraphicsPopContext(); 115 | } 116 | } 117 | } 118 | 119 | -(void)drawPoints:(CGContextRef)ctx{ 120 | NSArray *pointArray = self.charts.mainLine.pointArray; 121 | for (int i = 0; i < pointArray.count; i++) { 122 | //set line width 123 | 124 | CGContextSetLineWidth(ctx, 1.8); 125 | //set line color 126 | CGContextSetStrokeColorWithColor(ctx, self.charts.mainLine.color.CGColor); 127 | //draw points 128 | CSChartsPoint *tempPoint = [pointArray objectAtIndex:i]; 129 | 130 | if (tempPoint.pointStyle == CSChartsPointStyleSolid) { 131 | //draw solid point 132 | CGContextSetFillColorWithColor(ctx, self.charts.mainLine.color.CGColor); 133 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 3, 0, 360, 0); 134 | CGContextStrokePath(ctx); 135 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 3, 0, 360, 0); 136 | CGContextFillPath(ctx); 137 | }else if(tempPoint.pointStyle == CSChartsPointStyleHollow){ 138 | //draw hollow point 139 | CGContextSetFillColorWithColor(ctx, self.charts.mainLine.color.CGColor); 140 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 3, 0, 360, 0); 141 | CGContextStrokePath(ctx); 142 | CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); 143 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 3, 0, 360, 0); 144 | CGContextFillPath(ctx); 145 | }else if(tempPoint.pointStyle == CSChartsPointStyleSolidWhite){ 146 | //draw SolidWhite point 147 | CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); 148 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 6, 0, 360, 0); 149 | CGContextFillPath(ctx); 150 | CGContextSetFillColorWithColor(ctx, tempPoint.color.CGColor); 151 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 4, 0, 360, 0); 152 | CGContextFillPath(ctx); 153 | }else if(tempPoint.pointStyle == CSChartsPointStyleSolidWhiteBorder){ 154 | //draw SolidWhiteBorder point 155 | CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); 156 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 6, 0, 360, 0); 157 | CGContextFillPath(ctx); 158 | CGContextSetFillColorWithColor(ctx, tempPoint.color.CGColor); 159 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 3, 0, 360, 0); 160 | CGContextFillPath(ctx); 161 | CGContextSetStrokeColorWithColor(ctx, tempPoint.color.CGColor); 162 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 6, 0, 360, 0); 163 | CGContextStrokePath(ctx); 164 | } 165 | } 166 | } 167 | 168 | #pragma mark - private 169 | -(CGPoint)calculateDetalRectPosition:(CGPoint) point{ 170 | CGFloat detailRectWidth = self.charts.mainLine.detailRect.size.width; 171 | CGFloat detailRectHeight = self.charts.mainLine.detailRect.size.height; 172 | CGFloat detailRectX = point.x - detailRectWidth / 2; 173 | if (detailRectX < 10) { 174 | detailRectX = 10; 175 | }else if(detailRectX + detailRectWidth > self.charts.frame.size.width - 10){ 176 | detailRectX = self.charts.frame.size.width - 2 - detailRectWidth; 177 | } 178 | CGFloat detailRectY = point.y - detailRectHeight / 3 - CSCHARTS_DETAILRECT_FROM_MAINLINE_SPACING - detailRectHeight; 179 | if (detailRectY < 0) { 180 | detailRectY = point.y + CSCHARTS_DETAILRECT_FROM_MAINLINE_SPACING + 10; 181 | } 182 | return CGPointMake(detailRectX, detailRectY); 183 | } 184 | 185 | #pragma mark -- draw method 186 | -(void)drawMainLines:(CGContextRef)ctx{ 187 | NSArray *pointArray = self.charts.mainLine.pointArray; 188 | CGFloat allLeftSpacing = portSpacing + leftSpacing; 189 | 190 | //set line width 191 | CGContextSetLineWidth(ctx, self.charts.mainLine.lineWidth); 192 | //set anti alias off 193 | CGContextSetShouldAntialias(ctx, YES); 194 | //set line color 195 | CGContextSetStrokeColorWithColor(ctx, self.charts.mainLine.color.CGColor); 196 | 197 | CSChartsPoint *curPoint; 198 | for (int i = 0; i < pointArray.count; i++ ) { 199 | curPoint = [pointArray objectAtIndex:i]; 200 | CGFloat percentOfHeight = (yAxisMax - curPoint.y) / (yAxisMax - yAxisMin); 201 | self.charts -> points[i].y = topSpacing + chartsContentHeight * percentOfHeight; 202 | self.charts -> points[i].x = allLeftSpacing + curPoint.x * verticalSpacing; 203 | } 204 | CGContextAddLines(ctx, self.charts -> points, pointArray.count); 205 | //commit draw 206 | CGContextStrokePath(ctx); 207 | } 208 | 209 | #pragma mark -- param init method 210 | -(void)paramsPreparation{ 211 | yAxisCharacterSize = [[NSString stringWithFormat:@"%0.f",self.charts.yAxis.max] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 212 | xAxisCharacterSize = [[self.charts.xAxis.signArray objectAtIndex:0] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.xAxis.signFont withLineSpacing:3]; 213 | bottomSpacing = xAxisCharacterSize.height + CSCHARTS_SPACING * 2; 214 | if (self.charts.yAxis.isNeeded) { 215 | leftSpacing = yAxisCharacterSize.width + CSCHARTS_SPACING * 2; 216 | }else{ 217 | leftSpacing = 0; 218 | } 219 | topSpacing = yAxisCharacterSize.height / 2 + CSCHARTS_TOP_EXTRA_SPACING; 220 | horizontalLineAmount = (self.charts.yAxis.signAmount - 1) * 5; 221 | horizontalSpacing = (self.charts.frame.size.height - topSpacing - bottomSpacing) / (horizontalLineAmount - 1); 222 | verticalLineAmount = self.charts.xAxis.signArray.count; 223 | portSpacing = (self.charts.frame.size.width - leftSpacing) * PORT_SPACING_RATE; 224 | 225 | verticalSpacing = (self.charts.frame.size.width - portSpacing * 2 - leftSpacing) / (verticalLineAmount - 1); 226 | yAxisMax = self.charts.yAxis.max; 227 | yAxisMin = self.charts.yAxis.min; 228 | chartsContentHeight = self.charts.frame.size.height - bottomSpacing - topSpacing; 229 | } 230 | 231 | @end 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Layer/CSChartsMainLineLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsMainLineLayer.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsMainLineLayer.h" 10 | #import "NSString+BoundingRect.h" 11 | #import "CSChartsPoint.h" 12 | 13 | @interface CSChartsMainLineLayer (){ 14 | CGSize yAxisCharacterSize; 15 | CGSize xAxisCharacterSize; 16 | CGFloat bottomSpacing; 17 | CGFloat leftSpacing; 18 | CGFloat topSpacing; 19 | NSInteger horizontalLineAmount; 20 | CGFloat horizontalSpacing; 21 | NSUInteger verticalLineAmount; 22 | CGFloat portSpacing; 23 | CGFloat verticalSpacing; 24 | CGFloat chartsContentHeight; 25 | CGFloat yAxisMax; 26 | CGFloat yAxisMin; 27 | } 28 | @end 29 | 30 | @implementation CSChartsMainLineLayer 31 | 32 | -(void)drawInContext:(CGContextRef)ctx{ 33 | [self paramsPreparation]; 34 | /*******************/ 35 | /* draw main lines */ 36 | /*******************/ 37 | [self drawMainLines:ctx]; 38 | 39 | /***************/ 40 | /* draw points */ 41 | /***************/ 42 | [self drawPoints:ctx]; 43 | 44 | /********************/ 45 | /* draw detail rect */ 46 | /********************/ 47 | [self drawDetailRect:ctx]; 48 | } 49 | 50 | -(void)drawDetailRect:(CGContextRef)ctx{ 51 | NSArray *pointArray = self.charts.mainLine.pointArray; 52 | for (int i = 0; i < pointArray.count; i++) { 53 | CSChartsPoint *tempPoint = [pointArray objectAtIndex:i]; 54 | if (tempPoint.shouldShowDetail) { 55 | CGFloat detailRectWidth = self.charts.mainLine.detailRect.size.width; 56 | CGFloat detailRectHeight = self.charts.mainLine.detailRect.size.height; 57 | CGPoint detailRectPoint = [self calculateDetalRectPosition:self.charts -> points[i]]; 58 | CGFloat detailRectX = detailRectPoint.x; 59 | CGFloat detailRectY = detailRectPoint.y; 60 | //draw detail rect 61 | //set line color 62 | CGContextSetFillColorWithColor(ctx, self.charts.mainLine.detailRect.color.CGColor); 63 | //set fill rect 64 | CGContextBeginPath(ctx); 65 | //set 4 points for the rect 66 | //1 67 | CGContextMoveToPoint(ctx, detailRectX, detailRectY); 68 | //2 69 | CGContextAddLineToPoint(ctx, detailRectX + detailRectWidth, detailRectY); 70 | //3 71 | CGContextAddLineToPoint(ctx, detailRectX + detailRectWidth, detailRectY + detailRectHeight); 72 | //4 73 | CGContextAddLineToPoint(ctx, detailRectX, detailRectY + detailRectHeight); 74 | 75 | CGContextClosePath(ctx); 76 | //commit draw 77 | CGContextFillPath(ctx); 78 | 79 | //draw detail rect triangle 80 | //set line color 81 | CGContextSetFillColorWithColor(ctx, self.charts.mainLine.detailRect.color.CGColor); 82 | //set fill triangle 83 | CGContextBeginPath(ctx); 84 | //set 3 points for the triangle 85 | CGFloat point1Y = detailRectY - self.charts -> points[i].y < 0 ? self.charts -> points[i].y - CSCHARTS_DETAILRECT_FROM_MAINLINE_SPACING : self.charts -> points[i].y + CSCHARTS_DETAILRECT_FROM_MAINLINE_SPACING; 86 | CGFloat point2Y = detailRectY - self.charts -> points[i].y < 0 ? detailRectY + detailRectHeight - 1 : detailRectY + 1; 87 | //1 88 | CGContextMoveToPoint(ctx, self.charts -> points[i].x, point1Y); 89 | //2 90 | CGContextAddLineToPoint(ctx, self.charts -> points[i].x - 6, point2Y); 91 | //3 92 | CGContextAddLineToPoint(ctx, self.charts -> points[i].x + 6, point2Y); 93 | 94 | CGContextClosePath(ctx); 95 | //commit draw 96 | CGContextFillPath(ctx); 97 | 98 | //draw detail text 99 | //set Anti alias 100 | CGContextSetShouldAntialias(ctx, YES); 101 | CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); 102 | UIGraphicsPushContext(ctx); 103 | 104 | NSString *drawString = [NSString stringWithFormat:self.charts.mainLine.detailRect.textFormat,tempPoint.y]; 105 | CGSize drawStringSize = [drawString boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.mainLine.detailRect.font withLineSpacing:3]; 106 | NSString *unitString = self.charts.mainLine.detailRect.unitString; 107 | CGSize unitStringSize = [unitString boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.mainLine.detailRect.unitFont withLineSpacing:3]; 108 | 109 | //draw characters 110 | [drawString drawAtPoint:CGPointMake(detailRectX + (detailRectWidth - drawStringSize.width - unitStringSize.width) / 2, detailRectY + (detailRectHeight - drawStringSize.height) / 2) withFont:self.charts.mainLine.detailRect.font]; 111 | //draw unit 112 | 113 | [unitString drawAtPoint:CGPointMake(detailRectX + (detailRectWidth - drawStringSize.width - unitStringSize.width) / 2 + drawStringSize.width, detailRectY + (detailRectHeight - unitStringSize.height) / 2 ) withFont:self.charts.mainLine.detailRect.unitFont]; 114 | UIGraphicsPopContext(); 115 | } 116 | } 117 | } 118 | 119 | -(void)drawPoints:(CGContextRef)ctx{ 120 | NSArray *pointArray = self.charts.mainLine.pointArray; 121 | for (int i = 0; i < pointArray.count; i++) { 122 | //set line width 123 | 124 | CGContextSetLineWidth(ctx, 1.8); 125 | //set line color 126 | CGContextSetStrokeColorWithColor(ctx, self.charts.mainLine.color.CGColor); 127 | //draw points 128 | CSChartsPoint *tempPoint = [pointArray objectAtIndex:i]; 129 | 130 | if (tempPoint.pointStyle == CSChartsPointStyleSolid) { 131 | //draw solid point 132 | CGContextSetFillColorWithColor(ctx, self.charts.mainLine.color.CGColor); 133 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 3, 0, 360, 0); 134 | CGContextStrokePath(ctx); 135 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 3, 0, 360, 0); 136 | CGContextFillPath(ctx); 137 | }else if(tempPoint.pointStyle == CSChartsPointStyleHollow){ 138 | //draw hollow point 139 | CGContextSetFillColorWithColor(ctx, self.charts.mainLine.color.CGColor); 140 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 3, 0, 360, 0); 141 | CGContextStrokePath(ctx); 142 | CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); 143 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 3, 0, 360, 0); 144 | CGContextFillPath(ctx); 145 | }else if(tempPoint.pointStyle == CSChartsPointStyleSolidWhite){ 146 | //draw SolidWhite point 147 | CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); 148 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 6, 0, 360, 0); 149 | CGContextFillPath(ctx); 150 | CGContextSetFillColorWithColor(ctx, tempPoint.color.CGColor); 151 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 4, 0, 360, 0); 152 | CGContextFillPath(ctx); 153 | }else if(tempPoint.pointStyle == CSChartsPointStyleSolidWhiteBorder){ 154 | //draw SolidWhiteBorder point 155 | CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); 156 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 6, 0, 360, 0); 157 | CGContextFillPath(ctx); 158 | CGContextSetFillColorWithColor(ctx, tempPoint.color.CGColor); 159 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 3, 0, 360, 0); 160 | CGContextFillPath(ctx); 161 | CGContextSetStrokeColorWithColor(ctx, tempPoint.color.CGColor); 162 | CGContextAddArc(ctx, self.charts -> points[i].x, self.charts -> points[i].y, 6, 0, 360, 0); 163 | CGContextStrokePath(ctx); 164 | } 165 | } 166 | } 167 | 168 | #pragma mark - private 169 | -(CGPoint)calculateDetalRectPosition:(CGPoint) point{ 170 | CGFloat detailRectWidth = self.charts.mainLine.detailRect.size.width; 171 | CGFloat detailRectHeight = self.charts.mainLine.detailRect.size.height; 172 | CGFloat detailRectX = point.x - detailRectWidth / 2; 173 | if (detailRectX < 10) { 174 | detailRectX = 10; 175 | }else if(detailRectX + detailRectWidth > self.charts.frame.size.width - 10){ 176 | detailRectX = self.charts.frame.size.width - 2 - detailRectWidth; 177 | } 178 | CGFloat detailRectY = point.y - detailRectHeight / 3 - CSCHARTS_DETAILRECT_FROM_MAINLINE_SPACING - detailRectHeight; 179 | if (detailRectY < 0) { 180 | detailRectY = point.y + CSCHARTS_DETAILRECT_FROM_MAINLINE_SPACING + 10; 181 | } 182 | return CGPointMake(detailRectX, detailRectY); 183 | } 184 | 185 | #pragma mark -- draw method 186 | -(void)drawMainLines:(CGContextRef)ctx{ 187 | NSArray *pointArray = self.charts.mainLine.pointArray; 188 | CGFloat allLeftSpacing = portSpacing + leftSpacing; 189 | 190 | //set line width 191 | CGContextSetLineWidth(ctx, self.charts.mainLine.lineWidth); 192 | //set anti alias off 193 | CGContextSetShouldAntialias(ctx, YES); 194 | //set line color 195 | CGContextSetStrokeColorWithColor(ctx, self.charts.mainLine.color.CGColor); 196 | 197 | CSChartsPoint *curPoint; 198 | for (int i = 0; i < pointArray.count; i++ ) { 199 | curPoint = [pointArray objectAtIndex:i]; 200 | CGFloat percentOfHeight = (yAxisMax - curPoint.y) / (yAxisMax - yAxisMin); 201 | self.charts -> points[i].y = topSpacing + chartsContentHeight * percentOfHeight; 202 | self.charts -> points[i].x = allLeftSpacing + curPoint.x * verticalSpacing; 203 | } 204 | CGContextAddLines(ctx, self.charts -> points, pointArray.count); 205 | //commit draw 206 | CGContextStrokePath(ctx); 207 | } 208 | 209 | #pragma mark -- param init method 210 | -(void)paramsPreparation{ 211 | yAxisCharacterSize = [[NSString stringWithFormat:@"%0.f",self.charts.yAxis.max] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 212 | xAxisCharacterSize = [[self.charts.xAxis.signArray objectAtIndex:0] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.xAxis.signFont withLineSpacing:3]; 213 | bottomSpacing = xAxisCharacterSize.height + CSCHARTS_SPACING * 2; 214 | if (self.charts.yAxis.isNeeded) { 215 | leftSpacing = yAxisCharacterSize.width + CSCHARTS_SPACING * 2; 216 | }else{ 217 | leftSpacing = 0; 218 | } 219 | topSpacing = yAxisCharacterSize.height / 2 + CSCHARTS_TOP_EXTRA_SPACING; 220 | horizontalLineAmount = (self.charts.yAxis.signAmount - 1) * 5; 221 | horizontalSpacing = (self.charts.frame.size.height - topSpacing - bottomSpacing) / (horizontalLineAmount - 1); 222 | verticalLineAmount = self.charts.xAxis.signArray.count; 223 | portSpacing = (self.charts.frame.size.width - leftSpacing) * PORT_SPACING_RATE; 224 | 225 | verticalSpacing = (self.charts.frame.size.width - portSpacing * 2 - leftSpacing) / (verticalLineAmount - 1); 226 | yAxisMax = self.charts.yAxis.max; 227 | yAxisMin = self.charts.yAxis.min; 228 | chartsContentHeight = self.charts.frame.size.height - bottomSpacing - topSpacing; 229 | } 230 | 231 | @end 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /Source/CSChartsView.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsView.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsView.h" 10 | #import "CSCharts.h" 11 | #import "CSChartsBackgroundLayer.h" 12 | #import "CSChartsMainLineLayer.h" 13 | #import "CSChartsXAxisLayer.h" 14 | 15 | @interface CSChartsView (){ 16 | CSCharts *charts; 17 | CSChartsBackgroundLayer *backgroundLayer; 18 | CSChartsMainLineLayer *mainLineLayer; 19 | CSChartsXAxisLayer *xAxisLayer; 20 | UITapGestureRecognizer *tapGestureRecognizer; 21 | } 22 | 23 | @end 24 | 25 | @implementation CSChartsView 26 | 27 | 28 | #pragma mark - life cycle methods 29 | - (id)initWithFrame:(CGRect)frame 30 | { 31 | self = [super initWithFrame:frame]; 32 | if (self) { 33 | charts = [[CSCharts alloc] init]; 34 | charts.frame = frame; 35 | 36 | backgroundLayer = [CSChartsBackgroundLayer layer]; 37 | backgroundLayer.charts = charts; 38 | backgroundLayer.frame = CGRectInset(self.layer.bounds,0,0); 39 | backgroundLayer.contentsScale = [[UIScreen mainScreen] scale]; 40 | 41 | mainLineLayer = [CSChartsMainLineLayer layer]; 42 | mainLineLayer.charts = charts; 43 | mainLineLayer.frame = CGRectInset(self.layer.bounds,0,0); 44 | mainLineLayer.contentsScale = [[UIScreen mainScreen] scale]; 45 | 46 | xAxisLayer = [CSChartsXAxisLayer layer]; 47 | xAxisLayer.charts = charts; 48 | xAxisLayer.frame = CGRectInset(self.layer.bounds,0,0); 49 | xAxisLayer.contentsScale = [[UIScreen mainScreen] scale]; 50 | 51 | [self.layer addSublayer:backgroundLayer]; 52 | [self.layer addSublayer:mainLineLayer]; 53 | [self.layer addSublayer:xAxisLayer]; 54 | 55 | //add gesture 56 | tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesturePerformed)]; 57 | [self addGestureRecognizer:tapGestureRecognizer]; 58 | [self refreshCSChartsView]; 59 | } 60 | return self; 61 | } 62 | 63 | #pragma mark - refresh methods 64 | -(void) refreshCSChartsView{ 65 | [self refreshBackgroundLayer]; 66 | [self refreshMainLineLayer]; 67 | [self refreshXAxisLayer]; 68 | } 69 | 70 | -(void) refreshBackgroundLayer{ 71 | [backgroundLayer setNeedsDisplay]; 72 | } 73 | 74 | -(void) refreshMainLineLayer{ 75 | [mainLineLayer setNeedsDisplay]; 76 | } 77 | 78 | -(void) refreshXAxisLayer{ 79 | [xAxisLayer setNeedsDisplay]; 80 | } 81 | 82 | #pragma mark - action method 83 | -(void)tapGesturePerformed{ 84 | CGPoint tapPoint = [tapGestureRecognizer locationInView:self]; 85 | NSInteger index = [self pointsIndexTapped:tapPoint]; 86 | if (index != -1) { 87 | if ([self.delegate respondsToSelector:@selector(pointSelected:)]) { 88 | [self.delegate pointSelected:index]; 89 | } 90 | } 91 | [self setPointChosen:index]; 92 | [self refreshMainLineLayer]; 93 | } 94 | 95 | #pragma mark - UIAppearance methods 96 | -(BOOL)needYAxis{ 97 | return charts.yAxis.isNeeded; 98 | } 99 | 100 | -(void)setNeedYAxis:(BOOL)needYAxis{ 101 | charts.yAxis.isNeeded = needYAxis; 102 | } 103 | 104 | -(NSString *)detailRectUnitString{ 105 | return charts.mainLine.detailRect.unitString; 106 | } 107 | 108 | -(void)setDetailRectUnitString:(NSString *)detailRectUnitString{ 109 | charts.mainLine.detailRect.unitString = detailRectUnitString; 110 | } 111 | 112 | -(UIFont *)detailRectUnitFont{ 113 | return charts.mainLine.detailRect.unitFont; 114 | } 115 | 116 | -(void)setDetailRectUnitFont:(UIFont *)detailRectUnitFont{ 117 | charts.mainLine.detailRect.unitFont = detailRectUnitFont; 118 | } 119 | 120 | -(BOOL)shouldDrawHorizontalViceLines{ 121 | return charts.background.shouldDrawHorizontalViceLines; 122 | } 123 | 124 | -(void)setShouldDrawHorizontalViceLines:(BOOL)shouldDrawHorizontalViceLines{ 125 | charts.background.shouldDrawHorizontalViceLines = shouldDrawHorizontalViceLines; 126 | } 127 | 128 | -(NSString *)yAxisSignFormat{ 129 | return charts.yAxis.signFormat; 130 | } 131 | 132 | -(void)setYAxisSignFormat:(NSString *)yAxisSignFormat{ 133 | charts.yAxis.signFormat = yAxisSignFormat; 134 | } 135 | 136 | -(NSString *)yAxisUnitString{ 137 | return charts.yAxis.axisUnit.unitString; 138 | } 139 | 140 | -(void)setYAxisUnitString:(NSString *)yAxisUnitString{ 141 | charts.yAxis.axisUnit.unitString = yAxisUnitString; 142 | } 143 | 144 | -(UIColor *)yAxisUnitColor{ 145 | return charts.yAxis.axisUnit.color; 146 | } 147 | 148 | -(void)setYAxisUnitColor:(UIColor *)yAxisUnitColor{ 149 | charts.yAxis.axisUnit.color = yAxisUnitColor; 150 | } 151 | 152 | -(UIFont *)yAxisUnitFont{ 153 | return charts.yAxis.axisUnit.font; 154 | } 155 | 156 | -(void)setYAxisUnitFont:(UIFont *)yAxisUnitFont{ 157 | charts.yAxis.axisUnit.font = yAxisUnitFont; 158 | } 159 | 160 | -(BOOL)isRegionSeparated{ 161 | return charts.background.isRegionSeparated; 162 | } 163 | 164 | -(void)setIsRegionSeparated:(BOOL)isRegionSeparated{ 165 | charts.background.isRegionSeparated = isRegionSeparated; 166 | } 167 | 168 | -(NSString *)detailRectTextFormat{ 169 | return charts.mainLine.detailRect.textFormat; 170 | } 171 | 172 | -(void)setDetailRectTextFormat:(NSString *)detailRectTextFormat{ 173 | charts.mainLine.detailRect.textFormat = detailRectTextFormat; 174 | } 175 | 176 | -(UIColor *)detailRectColor{ 177 | return charts.mainLine.detailRect.color; 178 | } 179 | 180 | -(void)setDetailRectColor:(UIColor *)detailRectColor{ 181 | charts.mainLine.detailRect.color = detailRectColor; 182 | } 183 | 184 | -(UIFont *)detailRectFont{ 185 | return charts.mainLine.detailRect.font; 186 | } 187 | 188 | -(void)setDetailRectFont:(UIFont *)detailRectFont{ 189 | charts.mainLine.detailRect.font = detailRectFont; 190 | } 191 | 192 | -(NSArray *)colorRegionArray{ 193 | return charts.background.colorRegionArray; 194 | } 195 | 196 | -(void)setColorRegionArray:(NSArray *)colorRegionArray{ 197 | charts.background.colorRegionArray = colorRegionArray; 198 | } 199 | 200 | -(UIColor *)yAxisColor{ 201 | return charts.yAxis.color; 202 | } 203 | 204 | -(void)setYAxisColor:(UIColor *)yAxisColor{ 205 | charts.yAxis.color = yAxisColor; 206 | } 207 | 208 | -(UIFont *)yAxisFont{ 209 | return charts.yAxis.font; 210 | } 211 | 212 | -(void)setYAxisFont:(UIFont *)yAxisFont{ 213 | charts.yAxis.font = yAxisFont; 214 | } 215 | 216 | -(UIColor *)backgroundMainLineColor{ 217 | return charts.background.mainLineColor; 218 | } 219 | 220 | -(void)setBackgroundMainLineColor:(UIColor *)backgroundMainLineColor{ 221 | charts.background.mainLineColor = backgroundMainLineColor; 222 | } 223 | 224 | -(UIColor *)backgroundViceLineColor{ 225 | return charts.background.viceLineColor; 226 | } 227 | 228 | -(void)setBackgroundViceLineColor:(UIColor *)backgroundViceLineColor{ 229 | charts.background.viceLineColor = backgroundViceLineColor; 230 | } 231 | 232 | -(UIColor *)mainLineColor{ 233 | return charts.mainLine.color; 234 | } 235 | 236 | -(void)setMainLineColor:(UIColor *)mainLineColor{ 237 | charts.mainLine.color = mainLineColor; 238 | } 239 | 240 | -(UIColor *)xAxisColor{ 241 | return charts.xAxis.color; 242 | } 243 | 244 | -(void)setXAxisColor:(UIColor *)xAxisColor{ 245 | charts.xAxis.color = xAxisColor; 246 | } 247 | 248 | -(UIColor *)xAxisSignColor{ 249 | return charts.xAxis.signColor; 250 | } 251 | 252 | -(void)setXAxisSignColor:(UIColor *)xAxisSignColor{ 253 | charts.xAxis.signColor = xAxisSignColor; 254 | } 255 | 256 | -(UIFont *)xAxisSignFont{ 257 | return charts.xAxis.signFont; 258 | } 259 | 260 | -(void)setXAxisSignFont:(UIFont *)xAxisSignFont{ 261 | charts.xAxis.signFont = xAxisSignFont; 262 | } 263 | 264 | -(CGSize)detailRectSize{ 265 | return charts.mainLine.detailRect.size; 266 | } 267 | 268 | -(void)setDetailRectSize:(CGSize)detailRectSize{ 269 | charts.mainLine.detailRect.size = detailRectSize; 270 | } 271 | 272 | #pragma mark - necessary property setter and getter 273 | -(CGFloat)yAxisMax{ 274 | return charts.yAxis.max; 275 | } 276 | 277 | -(void)setYAxisMax:(CGFloat)yAxisMax{ 278 | charts.yAxis.max = yAxisMax; 279 | } 280 | 281 | -(CGFloat)yAxisMin{ 282 | return charts.yAxis.min; 283 | } 284 | 285 | -(void)setYAxisMin:(CGFloat)yAxisMin{ 286 | charts.yAxis.min = yAxisMin; 287 | } 288 | 289 | -(NSInteger)yAxisSignAmount{ 290 | return charts.yAxis.signAmount; 291 | } 292 | 293 | -(void)setYAxisSignAmount:(NSInteger)yAxisSignAmount{ 294 | charts.yAxis.signAmount = yAxisSignAmount; 295 | } 296 | 297 | -(NSArray *)xAxisSignArray{ 298 | return charts.xAxis.signArray; 299 | } 300 | 301 | -(void)setXAxisSignArray:(NSArray *)xAxisSignArray{ 302 | charts.xAxis.signArray = xAxisSignArray; 303 | } 304 | 305 | -(NSArray *)mainLinePointArray{ 306 | return charts.mainLine.pointArray; 307 | } 308 | 309 | -(void)setMainLinePointArray:(NSArray *)mainLinePointArray{ 310 | charts.mainLine.pointArray = mainLinePointArray; 311 | } 312 | 313 | #pragma mark - delegate setter 314 | -(void)setDelegate:(id)delegate{ 315 | _delegate = delegate; 316 | //add gesture 317 | // UISwipeGestureRecognizer *leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self.delegate action:@selector(leftSwipeGesturePerformed)]; 318 | // leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft; 319 | // UISwipeGestureRecognizer *rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self.delegate action:@selector(rightSwipeGesturePerformed)]; 320 | // rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight; 321 | UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self.delegate action:@selector(pinchGesturePerformed:)]; 322 | // 323 | // [self addGestureRecognizer:leftSwipeGestureRecognizer]; 324 | // [self addGestureRecognizer:rightSwipeGestureRecognizer]; 325 | [self addGestureRecognizer:pinchGestureRecognizer]; 326 | } 327 | 328 | #pragma mark - private 329 | -(CGFloat)distanceBetweenPoint:(CGPoint) pointA and:(CGPoint) pointB{ 330 | return sqrt((pointA.x - pointB.x) * (pointA.x - pointB.x) + (pointA.y - pointB.y) * (pointA.y - pointB.y)); 331 | } 332 | 333 | -(NSInteger)pointsIndexTapped:(CGPoint) point{ 334 | for (int i = 0; i < charts.mainLine.pointArray.count; i++) { 335 | if ([self distanceBetweenPoint:charts->points[i] and:point] <= TAP_GESTURE_REG_RADIUS) { 336 | return i; 337 | } 338 | } 339 | return -1; 340 | } 341 | 342 | -(void)setPointChosen:(NSInteger) index{ 343 | if (index != -1) { 344 | for (int i = 0; i < charts.mainLine.pointArray.count; i++) { 345 | CSChartsPoint *point = [charts.mainLine.pointArray objectAtIndex:i]; 346 | point.shouldShowDetail = NO; 347 | point.pointStyle = CSChartsPointStyleSolidWhite; 348 | } 349 | CSChartsPoint *point = [charts.mainLine.pointArray objectAtIndex:index]; 350 | point.shouldShowDetail = YES; 351 | point.pointStyle = CSChartsPointStyleSolidWhiteBorder; 352 | } 353 | } 354 | @end 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/CSChartsView.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsView.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsView.h" 10 | #import "CSCharts.h" 11 | #import "CSChartsBackgroundLayer.h" 12 | #import "CSChartsMainLineLayer.h" 13 | #import "CSChartsXAxisLayer.h" 14 | 15 | @interface CSChartsView (){ 16 | CSCharts *charts; 17 | CSChartsBackgroundLayer *backgroundLayer; 18 | CSChartsMainLineLayer *mainLineLayer; 19 | CSChartsXAxisLayer *xAxisLayer; 20 | UITapGestureRecognizer *tapGestureRecognizer; 21 | } 22 | 23 | @end 24 | 25 | @implementation CSChartsView 26 | 27 | 28 | #pragma mark - life cycle methods 29 | - (id)initWithFrame:(CGRect)frame 30 | { 31 | self = [super initWithFrame:frame]; 32 | if (self) { 33 | charts = [[CSCharts alloc] init]; 34 | charts.frame = frame; 35 | 36 | backgroundLayer = [CSChartsBackgroundLayer layer]; 37 | backgroundLayer.charts = charts; 38 | backgroundLayer.frame = CGRectInset(self.layer.bounds,0,0); 39 | backgroundLayer.contentsScale = [[UIScreen mainScreen] scale]; 40 | 41 | mainLineLayer = [CSChartsMainLineLayer layer]; 42 | mainLineLayer.charts = charts; 43 | mainLineLayer.frame = CGRectInset(self.layer.bounds,0,0); 44 | mainLineLayer.contentsScale = [[UIScreen mainScreen] scale]; 45 | 46 | xAxisLayer = [CSChartsXAxisLayer layer]; 47 | xAxisLayer.charts = charts; 48 | xAxisLayer.frame = CGRectInset(self.layer.bounds,0,0); 49 | xAxisLayer.contentsScale = [[UIScreen mainScreen] scale]; 50 | 51 | [self.layer addSublayer:backgroundLayer]; 52 | [self.layer addSublayer:mainLineLayer]; 53 | [self.layer addSublayer:xAxisLayer]; 54 | 55 | //add gesture 56 | tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesturePerformed)]; 57 | [self addGestureRecognizer:tapGestureRecognizer]; 58 | [self refreshCSChartsView]; 59 | } 60 | return self; 61 | } 62 | 63 | #pragma mark - refresh methods 64 | -(void) refreshCSChartsView{ 65 | [self refreshBackgroundLayer]; 66 | [self refreshMainLineLayer]; 67 | [self refreshXAxisLayer]; 68 | } 69 | 70 | -(void) refreshBackgroundLayer{ 71 | [backgroundLayer setNeedsDisplay]; 72 | } 73 | 74 | -(void) refreshMainLineLayer{ 75 | [mainLineLayer setNeedsDisplay]; 76 | } 77 | 78 | -(void) refreshXAxisLayer{ 79 | [xAxisLayer setNeedsDisplay]; 80 | } 81 | 82 | #pragma mark - action method 83 | -(void)tapGesturePerformed{ 84 | CGPoint tapPoint = [tapGestureRecognizer locationInView:self]; 85 | NSInteger index = [self pointsIndexTapped:tapPoint]; 86 | if (index != -1) { 87 | if ([self.delegate respondsToSelector:@selector(pointSelected:)]) { 88 | [self.delegate pointSelected:index]; 89 | } 90 | } 91 | [self setPointChosen:index]; 92 | [self refreshMainLineLayer]; 93 | } 94 | 95 | #pragma mark - UIAppearance methods 96 | -(BOOL)needYAxis{ 97 | return charts.yAxis.isNeeded; 98 | } 99 | 100 | -(void)setNeedYAxis:(BOOL)needYAxis{ 101 | charts.yAxis.isNeeded = needYAxis; 102 | } 103 | 104 | -(NSString *)detailRectUnitString{ 105 | return charts.mainLine.detailRect.unitString; 106 | } 107 | 108 | -(void)setDetailRectUnitString:(NSString *)detailRectUnitString{ 109 | charts.mainLine.detailRect.unitString = detailRectUnitString; 110 | } 111 | 112 | -(UIFont *)detailRectUnitFont{ 113 | return charts.mainLine.detailRect.unitFont; 114 | } 115 | 116 | -(void)setDetailRectUnitFont:(UIFont *)detailRectUnitFont{ 117 | charts.mainLine.detailRect.unitFont = detailRectUnitFont; 118 | } 119 | 120 | -(BOOL)shouldDrawHorizontalViceLines{ 121 | return charts.background.shouldDrawHorizontalViceLines; 122 | } 123 | 124 | -(void)setShouldDrawHorizontalViceLines:(BOOL)shouldDrawHorizontalViceLines{ 125 | charts.background.shouldDrawHorizontalViceLines = shouldDrawHorizontalViceLines; 126 | } 127 | 128 | -(NSString *)yAxisSignFormat{ 129 | return charts.yAxis.signFormat; 130 | } 131 | 132 | -(void)setYAxisSignFormat:(NSString *)yAxisSignFormat{ 133 | charts.yAxis.signFormat = yAxisSignFormat; 134 | } 135 | 136 | -(NSString *)yAxisUnitString{ 137 | return charts.yAxis.axisUnit.unitString; 138 | } 139 | 140 | -(void)setYAxisUnitString:(NSString *)yAxisUnitString{ 141 | charts.yAxis.axisUnit.unitString = yAxisUnitString; 142 | } 143 | 144 | -(UIColor *)yAxisUnitColor{ 145 | return charts.yAxis.axisUnit.color; 146 | } 147 | 148 | -(void)setYAxisUnitColor:(UIColor *)yAxisUnitColor{ 149 | charts.yAxis.axisUnit.color = yAxisUnitColor; 150 | } 151 | 152 | -(UIFont *)yAxisUnitFont{ 153 | return charts.yAxis.axisUnit.font; 154 | } 155 | 156 | -(void)setYAxisUnitFont:(UIFont *)yAxisUnitFont{ 157 | charts.yAxis.axisUnit.font = yAxisUnitFont; 158 | } 159 | 160 | -(BOOL)isRegionSeparated{ 161 | return charts.background.isRegionSeparated; 162 | } 163 | 164 | -(void)setIsRegionSeparated:(BOOL)isRegionSeparated{ 165 | charts.background.isRegionSeparated = isRegionSeparated; 166 | } 167 | 168 | -(NSString *)detailRectTextFormat{ 169 | return charts.mainLine.detailRect.textFormat; 170 | } 171 | 172 | -(void)setDetailRectTextFormat:(NSString *)detailRectTextFormat{ 173 | charts.mainLine.detailRect.textFormat = detailRectTextFormat; 174 | } 175 | 176 | -(UIColor *)detailRectColor{ 177 | return charts.mainLine.detailRect.color; 178 | } 179 | 180 | -(void)setDetailRectColor:(UIColor *)detailRectColor{ 181 | charts.mainLine.detailRect.color = detailRectColor; 182 | } 183 | 184 | -(UIFont *)detailRectFont{ 185 | return charts.mainLine.detailRect.font; 186 | } 187 | 188 | -(void)setDetailRectFont:(UIFont *)detailRectFont{ 189 | charts.mainLine.detailRect.font = detailRectFont; 190 | } 191 | 192 | -(NSArray *)colorRegionArray{ 193 | return charts.background.colorRegionArray; 194 | } 195 | 196 | -(void)setColorRegionArray:(NSArray *)colorRegionArray{ 197 | charts.background.colorRegionArray = colorRegionArray; 198 | } 199 | 200 | -(UIColor *)yAxisColor{ 201 | return charts.yAxis.color; 202 | } 203 | 204 | -(void)setYAxisColor:(UIColor *)yAxisColor{ 205 | charts.yAxis.color = yAxisColor; 206 | } 207 | 208 | -(UIFont *)yAxisFont{ 209 | return charts.yAxis.font; 210 | } 211 | 212 | -(void)setYAxisFont:(UIFont *)yAxisFont{ 213 | charts.yAxis.font = yAxisFont; 214 | } 215 | 216 | -(UIColor *)backgroundMainLineColor{ 217 | return charts.background.mainLineColor; 218 | } 219 | 220 | -(void)setBackgroundMainLineColor:(UIColor *)backgroundMainLineColor{ 221 | charts.background.mainLineColor = backgroundMainLineColor; 222 | } 223 | 224 | -(UIColor *)backgroundViceLineColor{ 225 | return charts.background.viceLineColor; 226 | } 227 | 228 | -(void)setBackgroundViceLineColor:(UIColor *)backgroundViceLineColor{ 229 | charts.background.viceLineColor = backgroundViceLineColor; 230 | } 231 | 232 | -(UIColor *)mainLineColor{ 233 | return charts.mainLine.color; 234 | } 235 | 236 | -(void)setMainLineColor:(UIColor *)mainLineColor{ 237 | charts.mainLine.color = mainLineColor; 238 | } 239 | 240 | -(UIColor *)xAxisColor{ 241 | return charts.xAxis.color; 242 | } 243 | 244 | -(void)setXAxisColor:(UIColor *)xAxisColor{ 245 | charts.xAxis.color = xAxisColor; 246 | } 247 | 248 | -(UIColor *)xAxisSignColor{ 249 | return charts.xAxis.signColor; 250 | } 251 | 252 | -(void)setXAxisSignColor:(UIColor *)xAxisSignColor{ 253 | charts.xAxis.signColor = xAxisSignColor; 254 | } 255 | 256 | -(UIFont *)xAxisSignFont{ 257 | return charts.xAxis.signFont; 258 | } 259 | 260 | -(void)setXAxisSignFont:(UIFont *)xAxisSignFont{ 261 | charts.xAxis.signFont = xAxisSignFont; 262 | } 263 | 264 | -(CGSize)detailRectSize{ 265 | return charts.mainLine.detailRect.size; 266 | } 267 | 268 | -(void)setDetailRectSize:(CGSize)detailRectSize{ 269 | charts.mainLine.detailRect.size = detailRectSize; 270 | } 271 | 272 | #pragma mark - necessary property setter and getter 273 | -(CGFloat)yAxisMax{ 274 | return charts.yAxis.max; 275 | } 276 | 277 | -(void)setYAxisMax:(CGFloat)yAxisMax{ 278 | charts.yAxis.max = yAxisMax; 279 | } 280 | 281 | -(CGFloat)yAxisMin{ 282 | return charts.yAxis.min; 283 | } 284 | 285 | -(void)setYAxisMin:(CGFloat)yAxisMin{ 286 | charts.yAxis.min = yAxisMin; 287 | } 288 | 289 | -(NSInteger)yAxisSignAmount{ 290 | return charts.yAxis.signAmount; 291 | } 292 | 293 | -(void)setYAxisSignAmount:(NSInteger)yAxisSignAmount{ 294 | charts.yAxis.signAmount = yAxisSignAmount; 295 | } 296 | 297 | -(NSArray *)xAxisSignArray{ 298 | return charts.xAxis.signArray; 299 | } 300 | 301 | -(void)setXAxisSignArray:(NSArray *)xAxisSignArray{ 302 | charts.xAxis.signArray = xAxisSignArray; 303 | } 304 | 305 | -(NSArray *)mainLinePointArray{ 306 | return charts.mainLine.pointArray; 307 | } 308 | 309 | -(void)setMainLinePointArray:(NSArray *)mainLinePointArray{ 310 | charts.mainLine.pointArray = mainLinePointArray; 311 | } 312 | 313 | #pragma mark - delegate setter 314 | -(void)setDelegate:(id)delegate{ 315 | _delegate = delegate; 316 | //add gesture 317 | // UISwipeGestureRecognizer *leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self.delegate action:@selector(leftSwipeGesturePerformed)]; 318 | // leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft; 319 | // UISwipeGestureRecognizer *rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self.delegate action:@selector(rightSwipeGesturePerformed)]; 320 | // rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight; 321 | UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self.delegate action:@selector(pinchGesturePerformed:)]; 322 | // 323 | // [self addGestureRecognizer:leftSwipeGestureRecognizer]; 324 | // [self addGestureRecognizer:rightSwipeGestureRecognizer]; 325 | [self addGestureRecognizer:pinchGestureRecognizer]; 326 | } 327 | 328 | #pragma mark - private 329 | -(CGFloat)distanceBetweenPoint:(CGPoint) pointA and:(CGPoint) pointB{ 330 | return sqrt((pointA.x - pointB.x) * (pointA.x - pointB.x) + (pointA.y - pointB.y) * (pointA.y - pointB.y)); 331 | } 332 | 333 | -(NSInteger)pointsIndexTapped:(CGPoint) point{ 334 | for (int i = 0; i < charts.mainLine.pointArray.count; i++) { 335 | if ([self distanceBetweenPoint:charts->points[i] and:point] <= TAP_GESTURE_REG_RADIUS) { 336 | return i; 337 | } 338 | } 339 | return -1; 340 | } 341 | 342 | -(void)setPointChosen:(NSInteger) index{ 343 | if (index != -1) { 344 | for (int i = 0; i < charts.mainLine.pointArray.count; i++) { 345 | CSChartsPoint *point = [charts.mainLine.pointArray objectAtIndex:i]; 346 | point.shouldShowDetail = NO; 347 | point.pointStyle = CSChartsPointStyleSolidWhite; 348 | } 349 | CSChartsPoint *point = [charts.mainLine.pointArray objectAtIndex:index]; 350 | point.shouldShowDetail = YES; 351 | point.pointStyle = CSChartsPointStyleSolidWhiteBorder; 352 | } 353 | } 354 | @end 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | -------------------------------------------------------------------------------- /Source/Layer/CSChartsBackgroundLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsBackgroundLayer.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsBackgroundLayer.h" 10 | #import "NSString+BoundingRect.h" 11 | #import "CSChartsColorRegion.h" 12 | 13 | @interface CSChartsBackgroundLayer (){ 14 | CGSize yAxisCharacterSize; 15 | CGSize xAxisCharacterSize; 16 | CGFloat bottomSpacing; 17 | CGFloat leftSpacing; 18 | CGFloat topSpacing; 19 | NSInteger horizontalLineAmount; 20 | CGFloat horizontalSpacing; 21 | NSUInteger verticalLineAmount; 22 | CGFloat portSpacing; 23 | CGFloat verticalSpacing; 24 | UIColor *yAxisColor; 25 | UIFont *yAxisFont; 26 | CGFloat characterSpacing; 27 | CGFloat chartsContentHeight; 28 | CGFloat yAxisMax; 29 | CGFloat yAxisMin; 30 | CGFloat unitHeight; 31 | } 32 | @end 33 | 34 | @implementation CSChartsBackgroundLayer 35 | 36 | -(void)drawInContext:(CGContextRef)ctx{ 37 | [self paramsPreparation]; 38 | 39 | /******************************/ 40 | /*draw background color region*/ 41 | /******************************/ 42 | [self drawBackgroundColorRegion:ctx]; 43 | 44 | /***********************************/ 45 | /*draw background horizontal lines */ 46 | /***********************************/ 47 | [self drawBackgroundHorizontalLines:ctx]; 48 | 49 | /***********************************/ 50 | /*draw background vertical lines */ 51 | /***********************************/ 52 | [self drawBackgroundVerticalLines:ctx]; 53 | 54 | /***********************************/ 55 | /* draw background y xAis unit **/ 56 | /***********************************/ 57 | // [self drawBackgroundYXAisUnit:ctx]; 58 | 59 | /***********************************/ 60 | /* draw background y xAis signs **/ 61 | /***********************************/ 62 | if (self.charts.yAxis.isNeeded) { 63 | [self drawBackgroundYXAisSigns:ctx]; 64 | } 65 | } 66 | 67 | 68 | #pragma mark - private 69 | #pragma mark -- draw method 70 | -(void)drawBackgroundColorRegion:(CGContextRef) ctx{ 71 | CGFloat rectY = topSpacing + chartsContentHeight; 72 | NSArray *colorRegionArray = self.charts.background.colorRegionArray; 73 | for (CSChartsColorRegion *colorRegion in colorRegionArray) { 74 | if (self.charts.background.isRegionSeparated) { 75 | CGFloat rectHeight = colorRegion.regionRange / (yAxisMax - yAxisMin) * chartsContentHeight; 76 | rectY -= rectHeight; 77 | CGRect drawRect = CGRectMake(leftSpacing - 3, rectY, self.charts.frame.size.width - leftSpacing + 3, rectHeight); 78 | //draw rect back 79 | //set color 80 | CGContextSetFillColorWithColor(ctx, colorRegion.color.CGColor); 81 | //fill rect 82 | CGContextFillRect(ctx, drawRect); 83 | //commit draw 84 | CGContextStrokePath(ctx); 85 | }else{ 86 | NSArray *colors = @[ 87 | [[colorRegionArray objectAtIndex:0] color], 88 | [[colorRegionArray objectAtIndex:1] color] 89 | ]; 90 | [self drawGradientColor:ctx 91 | rect:CGRectMake(leftSpacing, topSpacing, 320 - leftSpacing, chartsContentHeight) 92 | options:kCGGradientDrawsAfterEndLocation 93 | colors:colors]; 94 | CGContextStrokePath(ctx); 95 | CGContextFillPath(ctx); 96 | } 97 | } 98 | 99 | } 100 | 101 | -(void)drawBackgroundHorizontalLines:(CGContextRef) ctx{ 102 | //set line width 103 | CGContextSetLineWidth(ctx, 0.5); 104 | //set line style 105 | CGContextSetLineCap(ctx, kCGLineCapSquare); 106 | //set anti alias off 107 | CGContextSetShouldAntialias(ctx, NO); 108 | 109 | CGPoint points[2]; 110 | CGFloat lineYPosition = topSpacing; 111 | for (int i = 0;i < horizontalLineAmount; i ++ , lineYPosition += horizontalSpacing) { 112 | //set line color 113 | if (i % 5 == 0) { 114 | UIColor *mainLineColor = self.charts.background.mainLineColor; 115 | CGContextSetStrokeColorWithColor(ctx, mainLineColor.CGColor); 116 | //set dash linez 117 | if (i != 0) { 118 | CGFloat lengths[] = {3,1}; 119 | CGContextSetLineDash(ctx, 0,lengths, 2); 120 | } 121 | //set the points 122 | points[0] = CGPointMake(self.charts.frame.size.width, lineYPosition); 123 | points[1] = CGPointMake(leftSpacing, lineYPosition); 124 | CGContextAddLines(ctx, points, 2); 125 | //commit draw 126 | CGContextStrokePath(ctx); 127 | }else if(self.charts.background.shouldDrawHorizontalViceLines){ 128 | UIColor *viceLineColor = self.charts.background.viceLineColor; 129 | CGContextSetStrokeColorWithColor(ctx, viceLineColor.CGColor); 130 | //set dash linez 131 | if (i != 0) { 132 | CGFloat lengths[] = {3,1}; 133 | CGContextSetLineDash(ctx, 0,lengths, 2); 134 | } 135 | //set the points 136 | points[0] = CGPointMake(self.charts.frame.size.width, lineYPosition); 137 | points[1] = CGPointMake(leftSpacing, lineYPosition); 138 | CGContextAddLines(ctx, points, 2); 139 | //commit draw 140 | CGContextStrokePath(ctx); 141 | } 142 | 143 | } 144 | 145 | } 146 | 147 | -(void)drawBackgroundVerticalLines:(CGContextRef) ctx{ 148 | //set LineDash mode off 149 | CGPoint points[2]; 150 | CGContextSetLineDash(ctx, 0,nil, 0); 151 | CGFloat lineXPosition = leftSpacing + portSpacing; 152 | 153 | for (int i = 0;i < verticalLineAmount; i ++ , lineXPosition += verticalSpacing) { 154 | //set line color 155 | UIColor *viceLineColor = self.charts.background.viceLineColor; 156 | CGContextSetStrokeColorWithColor(ctx, viceLineColor.CGColor); 157 | //set the points 158 | points[0] = CGPointMake(lineXPosition, topSpacing); 159 | points[1] = CGPointMake(lineXPosition, self.charts.frame.size.height - bottomSpacing); 160 | CGContextAddLines(ctx, points, 2); 161 | //commit draw 162 | CGContextStrokePath(ctx); 163 | } 164 | } 165 | 166 | -(void)drawBackgroundYXAisUnit:(CGContextRef) ctx{ 167 | // //set Anti alias 168 | // CGContextSetShouldAntialias(ctx, YES); 169 | // //set line font 170 | // NSDictionary * attributes = @{ 171 | // NSFontAttributeName: self.charts.yAxis.axisUnit.font, 172 | // NSForegroundColorAttributeName:self.charts.yAxis.axisUnit.color 173 | // }; 174 | // UIGraphicsPushContext(ctx); 175 | // CGSize axisUnitSize = [self.charts.yAxis.axisUnit.unitString boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 176 | // [self.charts.yAxis.axisUnit.unitString drawAtPoint:CGPointMake((leftSpacing - axisUnitSize.width) / 2, 0) withAttributes:attributes]; 177 | // UIGraphicsPopContext(); 178 | } 179 | 180 | -(void)drawBackgroundYXAisSigns:(CGContextRef) ctx{ 181 | //set Anti alias 182 | CGContextSetShouldAntialias(ctx, YES); 183 | //set line font 184 | CGContextSetFillColorWithColor(ctx, yAxisColor.CGColor); 185 | UIGraphicsPushContext(ctx); 186 | 187 | CGFloat drawNum = self.charts.yAxis.max; 188 | CGFloat numGap = (self.charts.yAxis.max - self.charts.yAxis.min)/(self.charts.yAxis.signAmount - 1); 189 | CGFloat characterPosition = CSCHARTS_TOP_EXTRA_SPACING; 190 | for (int i = 0; i < self.charts.yAxis.signAmount - 1; i ++ , characterPosition += characterSpacing) { 191 | //draw characters 192 | NSString *drawString = [NSString stringWithFormat:self.charts.yAxis.signFormat, drawNum]; 193 | CGSize drawStringSize = [drawString boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 194 | [drawString drawAtPoint:CGPointMake((leftSpacing - drawStringSize.width) / 2, characterPosition) withFont:yAxisFont]; 195 | drawNum -= numGap; 196 | } 197 | UIGraphicsPopContext(); 198 | } 199 | 200 | #pragma mark -- param init method 201 | -(void)paramsPreparation{ 202 | yAxisCharacterSize = [[NSString stringWithFormat:self.charts.yAxis.signFormat,self.charts.yAxis.max] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 203 | xAxisCharacterSize = [[self.charts.xAxis.signArray objectAtIndex:0] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.xAxis.signFont withLineSpacing:3]; 204 | bottomSpacing = xAxisCharacterSize.height + CSCHARTS_SPACING * 2; 205 | if (self.charts.yAxis.isNeeded) { 206 | leftSpacing = yAxisCharacterSize.width + CSCHARTS_SPACING * 2; 207 | }else{ 208 | leftSpacing = 0; 209 | } 210 | topSpacing = yAxisCharacterSize.height / 2 + CSCHARTS_TOP_EXTRA_SPACING; 211 | horizontalLineAmount = (self.charts.yAxis.signAmount - 1) * 5 + 1; 212 | horizontalSpacing = (self.charts.frame.size.height - topSpacing - bottomSpacing) / (horizontalLineAmount - 1); 213 | verticalLineAmount = self.charts.xAxis.signArray.count; 214 | portSpacing = (self.charts.frame.size.width - leftSpacing) * PORT_SPACING_RATE; 215 | 216 | verticalSpacing = (self.charts.frame.size.width - portSpacing * 2 - leftSpacing) / (verticalLineAmount - 1); 217 | yAxisColor = self.charts.yAxis.color; 218 | yAxisFont = self.charts.yAxis.font; 219 | characterSpacing = horizontalSpacing * 5; 220 | yAxisMax = self.charts.yAxis.max; 221 | yAxisMin = self.charts.yAxis.min; 222 | chartsContentHeight = self.charts.frame.size.height - bottomSpacing - topSpacing; 223 | // unitHeight = 10; 224 | } 225 | 226 | /** 227 | * (“别人写的”————Cruise Shen注)绘制背景色渐变的矩形,p_colors渐变颜色设置,集合中存储UIColor对象(创建Color时一定用三原色来创建) 228 | **/ 229 | - (void)drawGradientColor:(CGContextRef)p_context 230 | rect:(CGRect)p_clipRect 231 | options:(CGGradientDrawingOptions)p_options 232 | colors:(NSArray *)p_colors { 233 | CGContextSaveGState(p_context);// 保持住现在的context 234 | CGContextClipToRect(p_context, p_clipRect);// 截取对应的context 235 | NSUInteger colorCount = p_colors.count; 236 | int numOfComponents = 4; 237 | CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); 238 | CGFloat colorComponents[colorCount * numOfComponents]; 239 | for (int i = 0; i < colorCount; i++) { 240 | UIColor *color = p_colors[i]; 241 | CGColorRef temcolorRef = color.CGColor; 242 | const CGFloat *components = CGColorGetComponents(temcolorRef); 243 | for (int j = 0; j < numOfComponents; ++j) { 244 | colorComponents[i * numOfComponents + j] = components[j]; 245 | } 246 | } 247 | CGGradientRef gradient = CGGradientCreateWithColorComponents(rgb, colorComponents, NULL, colorCount); 248 | CGColorSpaceRelease(rgb); 249 | CGPoint startPoint = p_clipRect.origin; 250 | CGPoint endPoint = CGPointMake(CGRectGetMinX(p_clipRect), CGRectGetMaxY(p_clipRect)); 251 | CGContextDrawLinearGradient(p_context, gradient, startPoint, endPoint, p_options); 252 | CGGradientRelease(gradient); 253 | CGContextRestoreGState(p_context);// 恢复到之前的context 254 | } 255 | @end 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | -------------------------------------------------------------------------------- /Sample/LineDrawer/ImgGetter/CSChartsView/Layer/CSChartsBackgroundLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSChartsBackgroundLayer.m 3 | // ImgGetter 4 | // 5 | // Created by 沈凯 on 14-3-4. 6 | // Copyright (c) 2014年 CruiseShen. All rights reserved. 7 | // 8 | 9 | #import "CSChartsBackgroundLayer.h" 10 | #import "NSString+BoundingRect.h" 11 | #import "CSChartsColorRegion.h" 12 | 13 | @interface CSChartsBackgroundLayer (){ 14 | CGSize yAxisCharacterSize; 15 | CGSize xAxisCharacterSize; 16 | CGFloat bottomSpacing; 17 | CGFloat leftSpacing; 18 | CGFloat topSpacing; 19 | NSInteger horizontalLineAmount; 20 | CGFloat horizontalSpacing; 21 | NSUInteger verticalLineAmount; 22 | CGFloat portSpacing; 23 | CGFloat verticalSpacing; 24 | UIColor *yAxisColor; 25 | UIFont *yAxisFont; 26 | CGFloat characterSpacing; 27 | CGFloat chartsContentHeight; 28 | CGFloat yAxisMax; 29 | CGFloat yAxisMin; 30 | CGFloat unitHeight; 31 | } 32 | @end 33 | 34 | @implementation CSChartsBackgroundLayer 35 | 36 | -(void)drawInContext:(CGContextRef)ctx{ 37 | [self paramsPreparation]; 38 | 39 | /******************************/ 40 | /*draw background color region*/ 41 | /******************************/ 42 | [self drawBackgroundColorRegion:ctx]; 43 | 44 | /***********************************/ 45 | /*draw background horizontal lines */ 46 | /***********************************/ 47 | [self drawBackgroundHorizontalLines:ctx]; 48 | 49 | /***********************************/ 50 | /*draw background vertical lines */ 51 | /***********************************/ 52 | [self drawBackgroundVerticalLines:ctx]; 53 | 54 | /***********************************/ 55 | /* draw background y xAis unit **/ 56 | /***********************************/ 57 | // [self drawBackgroundYXAisUnit:ctx]; 58 | 59 | /***********************************/ 60 | /* draw background y xAis signs **/ 61 | /***********************************/ 62 | if (self.charts.yAxis.isNeeded) { 63 | [self drawBackgroundYXAisSigns:ctx]; 64 | } 65 | } 66 | 67 | 68 | #pragma mark - private 69 | #pragma mark -- draw method 70 | -(void)drawBackgroundColorRegion:(CGContextRef) ctx{ 71 | CGFloat rectY = topSpacing + chartsContentHeight; 72 | NSArray *colorRegionArray = self.charts.background.colorRegionArray; 73 | for (CSChartsColorRegion *colorRegion in colorRegionArray) { 74 | if (self.charts.background.isRegionSeparated) { 75 | CGFloat rectHeight = colorRegion.regionRange / (yAxisMax - yAxisMin) * chartsContentHeight; 76 | rectY -= rectHeight; 77 | CGRect drawRect = CGRectMake(leftSpacing - 3, rectY, self.charts.frame.size.width - leftSpacing + 3, rectHeight); 78 | //draw rect back 79 | //set color 80 | CGContextSetFillColorWithColor(ctx, colorRegion.color.CGColor); 81 | //fill rect 82 | CGContextFillRect(ctx, drawRect); 83 | //commit draw 84 | CGContextStrokePath(ctx); 85 | }else{ 86 | NSArray *colors = @[ 87 | [[colorRegionArray objectAtIndex:0] color], 88 | [[colorRegionArray objectAtIndex:1] color] 89 | ]; 90 | [self drawGradientColor:ctx 91 | rect:CGRectMake(leftSpacing, topSpacing, 320 - leftSpacing, chartsContentHeight) 92 | options:kCGGradientDrawsAfterEndLocation 93 | colors:colors]; 94 | CGContextStrokePath(ctx); 95 | CGContextFillPath(ctx); 96 | } 97 | } 98 | 99 | } 100 | 101 | -(void)drawBackgroundHorizontalLines:(CGContextRef) ctx{ 102 | //set line width 103 | CGContextSetLineWidth(ctx, 0.5); 104 | //set line style 105 | CGContextSetLineCap(ctx, kCGLineCapSquare); 106 | //set anti alias off 107 | CGContextSetShouldAntialias(ctx, NO); 108 | 109 | CGPoint points[2]; 110 | CGFloat lineYPosition = topSpacing; 111 | for (int i = 0;i < horizontalLineAmount; i ++ , lineYPosition += horizontalSpacing) { 112 | //set line color 113 | if (i % 5 == 0) { 114 | UIColor *mainLineColor = self.charts.background.mainLineColor; 115 | CGContextSetStrokeColorWithColor(ctx, mainLineColor.CGColor); 116 | //set dash linez 117 | if (i != 0) { 118 | CGFloat lengths[] = {3,1}; 119 | CGContextSetLineDash(ctx, 0,lengths, 2); 120 | } 121 | //set the points 122 | points[0] = CGPointMake(self.charts.frame.size.width, lineYPosition); 123 | points[1] = CGPointMake(leftSpacing, lineYPosition); 124 | CGContextAddLines(ctx, points, 2); 125 | //commit draw 126 | CGContextStrokePath(ctx); 127 | }else if(self.charts.background.shouldDrawHorizontalViceLines){ 128 | UIColor *viceLineColor = self.charts.background.viceLineColor; 129 | CGContextSetStrokeColorWithColor(ctx, viceLineColor.CGColor); 130 | //set dash linez 131 | if (i != 0) { 132 | CGFloat lengths[] = {3,1}; 133 | CGContextSetLineDash(ctx, 0,lengths, 2); 134 | } 135 | //set the points 136 | points[0] = CGPointMake(self.charts.frame.size.width, lineYPosition); 137 | points[1] = CGPointMake(leftSpacing, lineYPosition); 138 | CGContextAddLines(ctx, points, 2); 139 | //commit draw 140 | CGContextStrokePath(ctx); 141 | } 142 | 143 | } 144 | 145 | } 146 | 147 | -(void)drawBackgroundVerticalLines:(CGContextRef) ctx{ 148 | //set LineDash mode off 149 | CGPoint points[2]; 150 | CGContextSetLineDash(ctx, 0,nil, 0); 151 | CGFloat lineXPosition = leftSpacing + portSpacing; 152 | 153 | for (int i = 0;i < verticalLineAmount; i ++ , lineXPosition += verticalSpacing) { 154 | //set line color 155 | UIColor *viceLineColor = self.charts.background.viceLineColor; 156 | CGContextSetStrokeColorWithColor(ctx, viceLineColor.CGColor); 157 | //set the points 158 | points[0] = CGPointMake(lineXPosition, topSpacing); 159 | points[1] = CGPointMake(lineXPosition, self.charts.frame.size.height - bottomSpacing); 160 | CGContextAddLines(ctx, points, 2); 161 | //commit draw 162 | CGContextStrokePath(ctx); 163 | } 164 | } 165 | 166 | -(void)drawBackgroundYXAisUnit:(CGContextRef) ctx{ 167 | // //set Anti alias 168 | // CGContextSetShouldAntialias(ctx, YES); 169 | // //set line font 170 | // NSDictionary * attributes = @{ 171 | // NSFontAttributeName: self.charts.yAxis.axisUnit.font, 172 | // NSForegroundColorAttributeName:self.charts.yAxis.axisUnit.color 173 | // }; 174 | // UIGraphicsPushContext(ctx); 175 | // CGSize axisUnitSize = [self.charts.yAxis.axisUnit.unitString boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 176 | // [self.charts.yAxis.axisUnit.unitString drawAtPoint:CGPointMake((leftSpacing - axisUnitSize.width) / 2, 0) withAttributes:attributes]; 177 | // UIGraphicsPopContext(); 178 | } 179 | 180 | -(void)drawBackgroundYXAisSigns:(CGContextRef) ctx{ 181 | //set Anti alias 182 | CGContextSetShouldAntialias(ctx, YES); 183 | //set line font 184 | CGContextSetFillColorWithColor(ctx, yAxisColor.CGColor); 185 | UIGraphicsPushContext(ctx); 186 | 187 | CGFloat drawNum = self.charts.yAxis.max; 188 | CGFloat numGap = (self.charts.yAxis.max - self.charts.yAxis.min)/(self.charts.yAxis.signAmount - 1); 189 | CGFloat characterPosition = CSCHARTS_TOP_EXTRA_SPACING; 190 | for (int i = 0; i < self.charts.yAxis.signAmount - 1; i ++ , characterPosition += characterSpacing) { 191 | //draw characters 192 | NSString *drawString = [NSString stringWithFormat:self.charts.yAxis.signFormat, drawNum]; 193 | CGSize drawStringSize = [drawString boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 194 | [drawString drawAtPoint:CGPointMake((leftSpacing - drawStringSize.width) / 2, characterPosition) withFont:yAxisFont]; 195 | drawNum -= numGap; 196 | } 197 | UIGraphicsPopContext(); 198 | } 199 | 200 | #pragma mark -- param init method 201 | -(void)paramsPreparation{ 202 | yAxisCharacterSize = [[NSString stringWithFormat:self.charts.yAxis.signFormat,self.charts.yAxis.max] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.yAxis.font withLineSpacing:3]; 203 | xAxisCharacterSize = [[self.charts.xAxis.signArray objectAtIndex:0] boundingRectWithSize:CGSizeMake(200, 200) withTextFont:self.charts.xAxis.signFont withLineSpacing:3]; 204 | bottomSpacing = xAxisCharacterSize.height + CSCHARTS_SPACING * 2; 205 | if (self.charts.yAxis.isNeeded) { 206 | leftSpacing = yAxisCharacterSize.width + CSCHARTS_SPACING * 2; 207 | }else{ 208 | leftSpacing = 0; 209 | } 210 | topSpacing = yAxisCharacterSize.height / 2 + CSCHARTS_TOP_EXTRA_SPACING; 211 | horizontalLineAmount = (self.charts.yAxis.signAmount - 1) * 5 + 1; 212 | horizontalSpacing = (self.charts.frame.size.height - topSpacing - bottomSpacing) / (horizontalLineAmount - 1); 213 | verticalLineAmount = self.charts.xAxis.signArray.count; 214 | portSpacing = (self.charts.frame.size.width - leftSpacing) * PORT_SPACING_RATE; 215 | 216 | verticalSpacing = (self.charts.frame.size.width - portSpacing * 2 - leftSpacing) / (verticalLineAmount - 1); 217 | yAxisColor = self.charts.yAxis.color; 218 | yAxisFont = self.charts.yAxis.font; 219 | characterSpacing = horizontalSpacing * 5; 220 | yAxisMax = self.charts.yAxis.max; 221 | yAxisMin = self.charts.yAxis.min; 222 | chartsContentHeight = self.charts.frame.size.height - bottomSpacing - topSpacing; 223 | // unitHeight = 10; 224 | } 225 | 226 | /** 227 | * (“别人写的”————Cruise Shen注)绘制背景色渐变的矩形,p_colors渐变颜色设置,集合中存储UIColor对象(创建Color时一定用三原色来创建) 228 | **/ 229 | - (void)drawGradientColor:(CGContextRef)p_context 230 | rect:(CGRect)p_clipRect 231 | options:(CGGradientDrawingOptions)p_options 232 | colors:(NSArray *)p_colors { 233 | CGContextSaveGState(p_context);// 保持住现在的context 234 | CGContextClipToRect(p_context, p_clipRect);// 截取对应的context 235 | NSUInteger colorCount = p_colors.count; 236 | int numOfComponents = 4; 237 | CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); 238 | CGFloat colorComponents[colorCount * numOfComponents]; 239 | for (int i = 0; i < colorCount; i++) { 240 | UIColor *color = p_colors[i]; 241 | CGColorRef temcolorRef = color.CGColor; 242 | const CGFloat *components = CGColorGetComponents(temcolorRef); 243 | for (int j = 0; j < numOfComponents; ++j) { 244 | colorComponents[i * numOfComponents + j] = components[j]; 245 | } 246 | } 247 | CGGradientRef gradient = CGGradientCreateWithColorComponents(rgb, colorComponents, NULL, colorCount); 248 | CGColorSpaceRelease(rgb); 249 | CGPoint startPoint = p_clipRect.origin; 250 | CGPoint endPoint = CGPointMake(CGRectGetMinX(p_clipRect), CGRectGetMaxY(p_clipRect)); 251 | CGContextDrawLinearGradient(p_context, gradient, startPoint, endPoint, p_options); 252 | CGGradientRelease(gradient); 253 | CGContextRestoreGState(p_context);// 恢复到之前的context 254 | } 255 | @end 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | -------------------------------------------------------------------------------- /Sample/LineDrawer/LineDrawer.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 44309A9518C487BE00575E5D /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 44309A9418C487BE00575E5D /* RootViewController.m */; }; 11 | 444077CC191C67C70020F0A2 /* CSChartsView.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077B1191C67C70020F0A2 /* CSChartsView.m */; }; 12 | 444077CD191C67C70020F0A2 /* CSChartsBackgroundLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077B4191C67C70020F0A2 /* CSChartsBackgroundLayer.m */; }; 13 | 444077CE191C67C70020F0A2 /* CSChartsMainLineLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077B6191C67C70020F0A2 /* CSChartsMainLineLayer.m */; }; 14 | 444077CF191C67C70020F0A2 /* CSChartsXAxisLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077B8191C67C70020F0A2 /* CSChartsXAxisLayer.m */; }; 15 | 444077D0191C67C70020F0A2 /* CSAxisUnit.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077BB191C67C70020F0A2 /* CSAxisUnit.m */; }; 16 | 444077D1191C67C70020F0A2 /* CSCharts.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077BD191C67C70020F0A2 /* CSCharts.m */; }; 17 | 444077D2191C67C70020F0A2 /* CSChartsBackground.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077BF191C67C70020F0A2 /* CSChartsBackground.m */; }; 18 | 444077D3191C67C70020F0A2 /* CSChartsColorRegion.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077C1191C67C70020F0A2 /* CSChartsColorRegion.m */; }; 19 | 444077D4191C67C70020F0A2 /* CSChartsDetailRect.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077C3191C67C70020F0A2 /* CSChartsDetailRect.m */; }; 20 | 444077D5191C67C70020F0A2 /* CSChartsMaiLine.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077C5191C67C70020F0A2 /* CSChartsMaiLine.m */; }; 21 | 444077D6191C67C70020F0A2 /* CSChartsPoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077C7191C67C70020F0A2 /* CSChartsPoint.m */; }; 22 | 444077D7191C67C70020F0A2 /* CSChartsXAxis.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077C9191C67C70020F0A2 /* CSChartsXAxis.m */; }; 23 | 444077D8191C67C70020F0A2 /* CSChartsYAxis.m in Sources */ = {isa = PBXBuildFile; fileRef = 444077CB191C67C70020F0A2 /* CSChartsYAxis.m */; }; 24 | 44BDB18D18C6C4300035AA6D /* NSString+BoundingRect.m in Sources */ = {isa = PBXBuildFile; fileRef = 44BDB18C18C6C4300035AA6D /* NSString+BoundingRect.m */; }; 25 | 44F63E0C18B2F59C0001398F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 44F63E0B18B2F59C0001398F /* Foundation.framework */; }; 26 | 44F63E0E18B2F59C0001398F /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 44F63E0D18B2F59C0001398F /* CoreGraphics.framework */; }; 27 | 44F63E1018B2F59C0001398F /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 44F63E0F18B2F59C0001398F /* UIKit.framework */; }; 28 | 44F63E1618B2F59C0001398F /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 44F63E1418B2F59C0001398F /* InfoPlist.strings */; }; 29 | 44F63E1818B2F59C0001398F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 44F63E1718B2F59C0001398F /* main.m */; }; 30 | 44F63E1C18B2F59C0001398F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 44F63E1B18B2F59C0001398F /* AppDelegate.m */; }; 31 | 44F63E2418B2F59C0001398F /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 44F63E2318B2F59C0001398F /* Images.xcassets */; }; 32 | /* End PBXBuildFile section */ 33 | 34 | /* Begin PBXFileReference section */ 35 | 44309A9318C487BE00575E5D /* RootViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RootViewController.h; sourceTree = ""; }; 36 | 44309A9418C487BE00575E5D /* RootViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RootViewController.m; sourceTree = ""; }; 37 | 444077B0191C67C70020F0A2 /* CSChartsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSChartsView.h; sourceTree = ""; }; 38 | 444077B1191C67C70020F0A2 /* CSChartsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSChartsView.m; sourceTree = ""; }; 39 | 444077B3191C67C70020F0A2 /* CSChartsBackgroundLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSChartsBackgroundLayer.h; sourceTree = ""; }; 40 | 444077B4191C67C70020F0A2 /* CSChartsBackgroundLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSChartsBackgroundLayer.m; sourceTree = ""; }; 41 | 444077B5191C67C70020F0A2 /* CSChartsMainLineLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSChartsMainLineLayer.h; sourceTree = ""; }; 42 | 444077B6191C67C70020F0A2 /* CSChartsMainLineLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSChartsMainLineLayer.m; sourceTree = ""; }; 43 | 444077B7191C67C70020F0A2 /* CSChartsXAxisLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSChartsXAxisLayer.h; sourceTree = ""; }; 44 | 444077B8191C67C70020F0A2 /* CSChartsXAxisLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSChartsXAxisLayer.m; sourceTree = ""; }; 45 | 444077BA191C67C70020F0A2 /* CSAxisUnit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSAxisUnit.h; sourceTree = ""; }; 46 | 444077BB191C67C70020F0A2 /* CSAxisUnit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSAxisUnit.m; sourceTree = ""; }; 47 | 444077BC191C67C70020F0A2 /* CSCharts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSCharts.h; sourceTree = ""; }; 48 | 444077BD191C67C70020F0A2 /* CSCharts.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSCharts.m; sourceTree = ""; }; 49 | 444077BE191C67C70020F0A2 /* CSChartsBackground.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSChartsBackground.h; sourceTree = ""; }; 50 | 444077BF191C67C70020F0A2 /* CSChartsBackground.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSChartsBackground.m; sourceTree = ""; }; 51 | 444077C0191C67C70020F0A2 /* CSChartsColorRegion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSChartsColorRegion.h; sourceTree = ""; }; 52 | 444077C1191C67C70020F0A2 /* CSChartsColorRegion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSChartsColorRegion.m; sourceTree = ""; }; 53 | 444077C2191C67C70020F0A2 /* CSChartsDetailRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSChartsDetailRect.h; sourceTree = ""; }; 54 | 444077C3191C67C70020F0A2 /* CSChartsDetailRect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSChartsDetailRect.m; sourceTree = ""; }; 55 | 444077C4191C67C70020F0A2 /* CSChartsMaiLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSChartsMaiLine.h; sourceTree = ""; }; 56 | 444077C5191C67C70020F0A2 /* CSChartsMaiLine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSChartsMaiLine.m; sourceTree = ""; }; 57 | 444077C6191C67C70020F0A2 /* CSChartsPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSChartsPoint.h; sourceTree = ""; }; 58 | 444077C7191C67C70020F0A2 /* CSChartsPoint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSChartsPoint.m; sourceTree = ""; }; 59 | 444077C8191C67C70020F0A2 /* CSChartsXAxis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSChartsXAxis.h; sourceTree = ""; }; 60 | 444077C9191C67C70020F0A2 /* CSChartsXAxis.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSChartsXAxis.m; sourceTree = ""; }; 61 | 444077CA191C67C70020F0A2 /* CSChartsYAxis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSChartsYAxis.h; sourceTree = ""; }; 62 | 444077CB191C67C70020F0A2 /* CSChartsYAxis.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSChartsYAxis.m; sourceTree = ""; }; 63 | 44BDB18B18C6C4300035AA6D /* NSString+BoundingRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+BoundingRect.h"; sourceTree = ""; }; 64 | 44BDB18C18C6C4300035AA6D /* NSString+BoundingRect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+BoundingRect.m"; sourceTree = ""; }; 65 | 44F63E0818B2F59C0001398F /* LineDrawer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LineDrawer.app; sourceTree = BUILT_PRODUCTS_DIR; }; 66 | 44F63E0B18B2F59C0001398F /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 67 | 44F63E0D18B2F59C0001398F /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 68 | 44F63E0F18B2F59C0001398F /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 69 | 44F63E1318B2F59C0001398F /* LineDrawer-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "LineDrawer-Info.plist"; sourceTree = ""; }; 70 | 44F63E1518B2F59C0001398F /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 71 | 44F63E1718B2F59C0001398F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 72 | 44F63E1918B2F59C0001398F /* LineDrawer-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LineDrawer-Prefix.pch"; sourceTree = ""; }; 73 | 44F63E1A18B2F59C0001398F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 74 | 44F63E1B18B2F59C0001398F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 75 | 44F63E2318B2F59C0001398F /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 76 | /* End PBXFileReference section */ 77 | 78 | /* Begin PBXFrameworksBuildPhase section */ 79 | 44F63E0518B2F59C0001398F /* Frameworks */ = { 80 | isa = PBXFrameworksBuildPhase; 81 | buildActionMask = 2147483647; 82 | files = ( 83 | 44F63E0E18B2F59C0001398F /* CoreGraphics.framework in Frameworks */, 84 | 44F63E1018B2F59C0001398F /* UIKit.framework in Frameworks */, 85 | 44F63E0C18B2F59C0001398F /* Foundation.framework in Frameworks */, 86 | ); 87 | runOnlyForDeploymentPostprocessing = 0; 88 | }; 89 | /* End PBXFrameworksBuildPhase section */ 90 | 91 | /* Begin PBXGroup section */ 92 | 444077AF191C67C70020F0A2 /* CSChartsView */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 444077B0191C67C70020F0A2 /* CSChartsView.h */, 96 | 444077B1191C67C70020F0A2 /* CSChartsView.m */, 97 | 444077B2191C67C70020F0A2 /* Layer */, 98 | 444077B9191C67C70020F0A2 /* Model */, 99 | ); 100 | path = CSChartsView; 101 | sourceTree = ""; 102 | }; 103 | 444077B2191C67C70020F0A2 /* Layer */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | 444077B3191C67C70020F0A2 /* CSChartsBackgroundLayer.h */, 107 | 444077B4191C67C70020F0A2 /* CSChartsBackgroundLayer.m */, 108 | 444077B5191C67C70020F0A2 /* CSChartsMainLineLayer.h */, 109 | 444077B6191C67C70020F0A2 /* CSChartsMainLineLayer.m */, 110 | 444077B7191C67C70020F0A2 /* CSChartsXAxisLayer.h */, 111 | 444077B8191C67C70020F0A2 /* CSChartsXAxisLayer.m */, 112 | ); 113 | path = Layer; 114 | sourceTree = ""; 115 | }; 116 | 444077B9191C67C70020F0A2 /* Model */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 444077BA191C67C70020F0A2 /* CSAxisUnit.h */, 120 | 444077BB191C67C70020F0A2 /* CSAxisUnit.m */, 121 | 444077BC191C67C70020F0A2 /* CSCharts.h */, 122 | 444077BD191C67C70020F0A2 /* CSCharts.m */, 123 | 444077BE191C67C70020F0A2 /* CSChartsBackground.h */, 124 | 444077BF191C67C70020F0A2 /* CSChartsBackground.m */, 125 | 444077C0191C67C70020F0A2 /* CSChartsColorRegion.h */, 126 | 444077C1191C67C70020F0A2 /* CSChartsColorRegion.m */, 127 | 444077C2191C67C70020F0A2 /* CSChartsDetailRect.h */, 128 | 444077C3191C67C70020F0A2 /* CSChartsDetailRect.m */, 129 | 444077C4191C67C70020F0A2 /* CSChartsMaiLine.h */, 130 | 444077C5191C67C70020F0A2 /* CSChartsMaiLine.m */, 131 | 444077C6191C67C70020F0A2 /* CSChartsPoint.h */, 132 | 444077C7191C67C70020F0A2 /* CSChartsPoint.m */, 133 | 444077C8191C67C70020F0A2 /* CSChartsXAxis.h */, 134 | 444077C9191C67C70020F0A2 /* CSChartsXAxis.m */, 135 | 444077CA191C67C70020F0A2 /* CSChartsYAxis.h */, 136 | 444077CB191C67C70020F0A2 /* CSChartsYAxis.m */, 137 | ); 138 | path = Model; 139 | sourceTree = ""; 140 | }; 141 | 44BDB18A18C6C3F40035AA6D /* Common */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | 44BDB18B18C6C4300035AA6D /* NSString+BoundingRect.h */, 145 | 44BDB18C18C6C4300035AA6D /* NSString+BoundingRect.m */, 146 | ); 147 | name = Common; 148 | sourceTree = ""; 149 | }; 150 | 44F63DFF18B2F59C0001398F = { 151 | isa = PBXGroup; 152 | children = ( 153 | 44F63E1118B2F59C0001398F /* LineDrawer */, 154 | 44F63E0A18B2F59C0001398F /* Frameworks */, 155 | 44F63E0918B2F59C0001398F /* Products */, 156 | ); 157 | sourceTree = ""; 158 | }; 159 | 44F63E0918B2F59C0001398F /* Products */ = { 160 | isa = PBXGroup; 161 | children = ( 162 | 44F63E0818B2F59C0001398F /* LineDrawer.app */, 163 | ); 164 | name = Products; 165 | sourceTree = ""; 166 | }; 167 | 44F63E0A18B2F59C0001398F /* Frameworks */ = { 168 | isa = PBXGroup; 169 | children = ( 170 | 44F63E0B18B2F59C0001398F /* Foundation.framework */, 171 | 44F63E0D18B2F59C0001398F /* CoreGraphics.framework */, 172 | 44F63E0F18B2F59C0001398F /* UIKit.framework */, 173 | ); 174 | name = Frameworks; 175 | sourceTree = ""; 176 | }; 177 | 44F63E1118B2F59C0001398F /* LineDrawer */ = { 178 | isa = PBXGroup; 179 | children = ( 180 | 44F63E1A18B2F59C0001398F /* AppDelegate.h */, 181 | 44F63E1B18B2F59C0001398F /* AppDelegate.m */, 182 | 44309A9318C487BE00575E5D /* RootViewController.h */, 183 | 44309A9418C487BE00575E5D /* RootViewController.m */, 184 | 444077AF191C67C70020F0A2 /* CSChartsView */, 185 | 44BDB18A18C6C3F40035AA6D /* Common */, 186 | 44F63E2318B2F59C0001398F /* Images.xcassets */, 187 | 44F63E1218B2F59C0001398F /* Supporting Files */, 188 | ); 189 | name = LineDrawer; 190 | path = ImgGetter; 191 | sourceTree = ""; 192 | }; 193 | 44F63E1218B2F59C0001398F /* Supporting Files */ = { 194 | isa = PBXGroup; 195 | children = ( 196 | 44F63E1318B2F59C0001398F /* LineDrawer-Info.plist */, 197 | 44F63E1418B2F59C0001398F /* InfoPlist.strings */, 198 | 44F63E1718B2F59C0001398F /* main.m */, 199 | 44F63E1918B2F59C0001398F /* LineDrawer-Prefix.pch */, 200 | ); 201 | name = "Supporting Files"; 202 | sourceTree = ""; 203 | }; 204 | /* End PBXGroup section */ 205 | 206 | /* Begin PBXNativeTarget section */ 207 | 44F63E0718B2F59C0001398F /* LineDrawer */ = { 208 | isa = PBXNativeTarget; 209 | buildConfigurationList = 44F63E3A18B2F59C0001398F /* Build configuration list for PBXNativeTarget "LineDrawer" */; 210 | buildPhases = ( 211 | 44F63E0418B2F59C0001398F /* Sources */, 212 | 44F63E0518B2F59C0001398F /* Frameworks */, 213 | 44F63E0618B2F59C0001398F /* Resources */, 214 | ); 215 | buildRules = ( 216 | ); 217 | dependencies = ( 218 | ); 219 | name = LineDrawer; 220 | productName = ImgGetter; 221 | productReference = 44F63E0818B2F59C0001398F /* LineDrawer.app */; 222 | productType = "com.apple.product-type.application"; 223 | }; 224 | /* End PBXNativeTarget section */ 225 | 226 | /* Begin PBXProject section */ 227 | 44F63E0018B2F59C0001398F /* Project object */ = { 228 | isa = PBXProject; 229 | attributes = { 230 | CLASSPREFIX = CS; 231 | LastUpgradeCheck = 0510; 232 | ORGANIZATIONNAME = CruiseShen; 233 | TargetAttributes = { 234 | 44F63E0718B2F59C0001398F = { 235 | DevelopmentTeam = 7ZA2LA43A4; 236 | SystemCapabilities = { 237 | com.apple.DataProtection = { 238 | enabled = 0; 239 | }; 240 | com.apple.InterAppAudio = { 241 | enabled = 0; 242 | }; 243 | }; 244 | }; 245 | }; 246 | }; 247 | buildConfigurationList = 44F63E0318B2F59C0001398F /* Build configuration list for PBXProject "LineDrawer" */; 248 | compatibilityVersion = "Xcode 3.2"; 249 | developmentRegion = English; 250 | hasScannedForEncodings = 0; 251 | knownRegions = ( 252 | en, 253 | Base, 254 | ); 255 | mainGroup = 44F63DFF18B2F59C0001398F; 256 | productRefGroup = 44F63E0918B2F59C0001398F /* Products */; 257 | projectDirPath = ""; 258 | projectRoot = ""; 259 | targets = ( 260 | 44F63E0718B2F59C0001398F /* LineDrawer */, 261 | ); 262 | }; 263 | /* End PBXProject section */ 264 | 265 | /* Begin PBXResourcesBuildPhase section */ 266 | 44F63E0618B2F59C0001398F /* Resources */ = { 267 | isa = PBXResourcesBuildPhase; 268 | buildActionMask = 2147483647; 269 | files = ( 270 | 44F63E2418B2F59C0001398F /* Images.xcassets in Resources */, 271 | 44F63E1618B2F59C0001398F /* InfoPlist.strings in Resources */, 272 | ); 273 | runOnlyForDeploymentPostprocessing = 0; 274 | }; 275 | /* End PBXResourcesBuildPhase section */ 276 | 277 | /* Begin PBXSourcesBuildPhase section */ 278 | 44F63E0418B2F59C0001398F /* Sources */ = { 279 | isa = PBXSourcesBuildPhase; 280 | buildActionMask = 2147483647; 281 | files = ( 282 | 444077D4191C67C70020F0A2 /* CSChartsDetailRect.m in Sources */, 283 | 444077D0191C67C70020F0A2 /* CSAxisUnit.m in Sources */, 284 | 444077D7191C67C70020F0A2 /* CSChartsXAxis.m in Sources */, 285 | 44F63E1C18B2F59C0001398F /* AppDelegate.m in Sources */, 286 | 444077D8191C67C70020F0A2 /* CSChartsYAxis.m in Sources */, 287 | 444077D3191C67C70020F0A2 /* CSChartsColorRegion.m in Sources */, 288 | 444077D2191C67C70020F0A2 /* CSChartsBackground.m in Sources */, 289 | 44BDB18D18C6C4300035AA6D /* NSString+BoundingRect.m in Sources */, 290 | 444077D6191C67C70020F0A2 /* CSChartsPoint.m in Sources */, 291 | 444077CD191C67C70020F0A2 /* CSChartsBackgroundLayer.m in Sources */, 292 | 444077D1191C67C70020F0A2 /* CSCharts.m in Sources */, 293 | 444077CC191C67C70020F0A2 /* CSChartsView.m in Sources */, 294 | 444077CF191C67C70020F0A2 /* CSChartsXAxisLayer.m in Sources */, 295 | 444077D5191C67C70020F0A2 /* CSChartsMaiLine.m in Sources */, 296 | 44F63E1818B2F59C0001398F /* main.m in Sources */, 297 | 444077CE191C67C70020F0A2 /* CSChartsMainLineLayer.m in Sources */, 298 | 44309A9518C487BE00575E5D /* RootViewController.m in Sources */, 299 | ); 300 | runOnlyForDeploymentPostprocessing = 0; 301 | }; 302 | /* End PBXSourcesBuildPhase section */ 303 | 304 | /* Begin PBXVariantGroup section */ 305 | 44F63E1418B2F59C0001398F /* InfoPlist.strings */ = { 306 | isa = PBXVariantGroup; 307 | children = ( 308 | 44F63E1518B2F59C0001398F /* en */, 309 | ); 310 | name = InfoPlist.strings; 311 | sourceTree = ""; 312 | }; 313 | /* End PBXVariantGroup section */ 314 | 315 | /* Begin XCBuildConfiguration section */ 316 | 44F63E3818B2F59C0001398F /* Debug */ = { 317 | isa = XCBuildConfiguration; 318 | buildSettings = { 319 | ALWAYS_SEARCH_USER_PATHS = NO; 320 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 321 | CLANG_CXX_LIBRARY = "libc++"; 322 | CLANG_ENABLE_MODULES = YES; 323 | CLANG_ENABLE_OBJC_ARC = YES; 324 | CLANG_WARN_BOOL_CONVERSION = YES; 325 | CLANG_WARN_CONSTANT_CONVERSION = YES; 326 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 327 | CLANG_WARN_EMPTY_BODY = YES; 328 | CLANG_WARN_ENUM_CONVERSION = YES; 329 | CLANG_WARN_INT_CONVERSION = YES; 330 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 331 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 332 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 333 | COPY_PHASE_STRIP = NO; 334 | GCC_C_LANGUAGE_STANDARD = gnu99; 335 | GCC_DYNAMIC_NO_PIC = NO; 336 | GCC_OPTIMIZATION_LEVEL = 0; 337 | GCC_PREPROCESSOR_DEFINITIONS = ( 338 | "DEBUG=1", 339 | "$(inherited)", 340 | ); 341 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 342 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 343 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 344 | GCC_WARN_UNDECLARED_SELECTOR = YES; 345 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 346 | GCC_WARN_UNUSED_FUNCTION = YES; 347 | GCC_WARN_UNUSED_VARIABLE = YES; 348 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 349 | ONLY_ACTIVE_ARCH = YES; 350 | SDKROOT = iphoneos; 351 | }; 352 | name = Debug; 353 | }; 354 | 44F63E3918B2F59C0001398F /* Release */ = { 355 | isa = XCBuildConfiguration; 356 | buildSettings = { 357 | ALWAYS_SEARCH_USER_PATHS = NO; 358 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 359 | CLANG_CXX_LIBRARY = "libc++"; 360 | CLANG_ENABLE_MODULES = YES; 361 | CLANG_ENABLE_OBJC_ARC = YES; 362 | CLANG_WARN_BOOL_CONVERSION = YES; 363 | CLANG_WARN_CONSTANT_CONVERSION = YES; 364 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 365 | CLANG_WARN_EMPTY_BODY = YES; 366 | CLANG_WARN_ENUM_CONVERSION = YES; 367 | CLANG_WARN_INT_CONVERSION = YES; 368 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 369 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 370 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 371 | COPY_PHASE_STRIP = YES; 372 | ENABLE_NS_ASSERTIONS = NO; 373 | GCC_C_LANGUAGE_STANDARD = gnu99; 374 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 375 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 376 | GCC_WARN_UNDECLARED_SELECTOR = YES; 377 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 378 | GCC_WARN_UNUSED_FUNCTION = YES; 379 | GCC_WARN_UNUSED_VARIABLE = YES; 380 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 381 | SDKROOT = iphoneos; 382 | VALIDATE_PRODUCT = YES; 383 | }; 384 | name = Release; 385 | }; 386 | 44F63E3B18B2F59C0001398F /* Debug */ = { 387 | isa = XCBuildConfiguration; 388 | buildSettings = { 389 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 390 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 391 | CODE_SIGN_IDENTITY = "iPhone Developer"; 392 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 393 | FRAMEWORK_SEARCH_PATHS = ( 394 | "$(inherited)", 395 | "$(DEVELOPER_FRAMEWORKS_DIR)", 396 | ); 397 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 398 | GCC_PREFIX_HEADER = "ImgGetter/LineDrawer-Prefix.pch"; 399 | INFOPLIST_FILE = "ImgGetter/LineDrawer-Info.plist"; 400 | PRODUCT_NAME = LineDrawer; 401 | PROVISIONING_PROFILE = ""; 402 | WRAPPER_EXTENSION = app; 403 | }; 404 | name = Debug; 405 | }; 406 | 44F63E3C18B2F59C0001398F /* Release */ = { 407 | isa = XCBuildConfiguration; 408 | buildSettings = { 409 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 410 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 411 | CODE_SIGN_IDENTITY = "iPhone Developer"; 412 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 413 | FRAMEWORK_SEARCH_PATHS = ( 414 | "$(inherited)", 415 | "$(DEVELOPER_FRAMEWORKS_DIR)", 416 | ); 417 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 418 | GCC_PREFIX_HEADER = "ImgGetter/LineDrawer-Prefix.pch"; 419 | INFOPLIST_FILE = "ImgGetter/LineDrawer-Info.plist"; 420 | PRODUCT_NAME = LineDrawer; 421 | PROVISIONING_PROFILE = ""; 422 | WRAPPER_EXTENSION = app; 423 | }; 424 | name = Release; 425 | }; 426 | /* End XCBuildConfiguration section */ 427 | 428 | /* Begin XCConfigurationList section */ 429 | 44F63E0318B2F59C0001398F /* Build configuration list for PBXProject "LineDrawer" */ = { 430 | isa = XCConfigurationList; 431 | buildConfigurations = ( 432 | 44F63E3818B2F59C0001398F /* Debug */, 433 | 44F63E3918B2F59C0001398F /* Release */, 434 | ); 435 | defaultConfigurationIsVisible = 0; 436 | defaultConfigurationName = Release; 437 | }; 438 | 44F63E3A18B2F59C0001398F /* Build configuration list for PBXNativeTarget "LineDrawer" */ = { 439 | isa = XCConfigurationList; 440 | buildConfigurations = ( 441 | 44F63E3B18B2F59C0001398F /* Debug */, 442 | 44F63E3C18B2F59C0001398F /* Release */, 443 | ); 444 | defaultConfigurationIsVisible = 0; 445 | defaultConfigurationName = Release; 446 | }; 447 | /* End XCConfigurationList section */ 448 | }; 449 | rootObject = 44F63E0018B2F59C0001398F /* Project object */; 450 | } 451 | --------------------------------------------------------------------------------