Skip to content
This repository
Browse code

move all layers out from view class.

  • Loading branch information...
commit 867eea0032255aee39f7cf3792c6052e7caaf828 1 parent af28643
pyanfield authored March 20, 2012
40  WSCharts.xcodeproj/project.pbxproj
@@ -23,6 +23,10 @@
23 23
 		9026093514E29B13007779D9 /* WSPieChartWithMotionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9026093414E29B13007779D9 /* WSPieChartWithMotionView.m */; };
24 24
 		902D3212150749E000D9CA06 /* WSAreaChartView.m in Sources */ = {isa = PBXBuildFile; fileRef = 902D3211150749E000D9CA06 /* WSAreaChartView.m */; };
25 25
 		902FF3C714FE203700A5DD5A /* WSLegendLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 902FF3C614FE203600A5DD5A /* WSLegendLayer.m */; };
  26
+		9034049615187F950080CD54 /* WSLineLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9034049515187F950080CD54 /* WSLineLayer.m */; };
  27
+		90340499151880880080CD54 /* WSAreaLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 90340498151880880080CD54 /* WSAreaLayer.m */; };
  28
+		9034049C151881520080CD54 /* WSScatterLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9034049B151881520080CD54 /* WSScatterLayer.m */; };
  29
+		9034049F151882B20080CD54 /* WSColumnLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9034049E151882B20080CD54 /* WSColumnLayer.m */; };
26 30
 		9044CA01151761C4005E2547 /* WSComboChartView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9044CA00151761C4005E2547 /* WSComboChartView.m */; };
27 31
 		90653E2D15089E2C00ECE29D /* WSBaseChartView.m in Sources */ = {isa = PBXBuildFile; fileRef = 90653E2C15089E2C00ECE29D /* WSBaseChartView.m */; };
28 32
 		906F683E14E0157E00E0D9CF /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 906F683C14E0157E00E0D9CF /* LICENSE */; };
@@ -62,6 +66,14 @@
62 66
 		902D3211150749E000D9CA06 /* WSAreaChartView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WSAreaChartView.m; sourceTree = "<group>"; };
63 67
 		902FF3C514FE203600A5DD5A /* WSLegendLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WSLegendLayer.h; sourceTree = "<group>"; };
64 68
 		902FF3C614FE203600A5DD5A /* WSLegendLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WSLegendLayer.m; sourceTree = "<group>"; };
  69
+		9034049415187F950080CD54 /* WSLineLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WSLineLayer.h; sourceTree = "<group>"; };
  70
+		9034049515187F950080CD54 /* WSLineLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WSLineLayer.m; sourceTree = "<group>"; };
  71
+		90340497151880880080CD54 /* WSAreaLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WSAreaLayer.h; sourceTree = "<group>"; };
  72
+		90340498151880880080CD54 /* WSAreaLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WSAreaLayer.m; sourceTree = "<group>"; };
  73
+		9034049A151881520080CD54 /* WSScatterLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WSScatterLayer.h; sourceTree = "<group>"; };
  74
+		9034049B151881520080CD54 /* WSScatterLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WSScatterLayer.m; sourceTree = "<group>"; };
  75
+		9034049D151882B20080CD54 /* WSColumnLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WSColumnLayer.h; sourceTree = "<group>"; };
  76
+		9034049E151882B20080CD54 /* WSColumnLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WSColumnLayer.m; sourceTree = "<group>"; };
65 77
 		9044C9FF151761C4005E2547 /* WSComboChartView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WSComboChartView.h; sourceTree = "<group>"; };
66 78
 		9044CA00151761C4005E2547 /* WSComboChartView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WSComboChartView.m; sourceTree = "<group>"; };
67 79
 		90653E2B15089E2C00ECE29D /* WSBaseChartView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WSBaseChartView.h; sourceTree = "<group>"; };
@@ -184,6 +196,25 @@
184 196
 			name = ColumnChart;
185 197
 			sourceTree = "<group>";
186 198
 		};
  199
+		9034049215187F4B0080CD54 /* Chart Layers */ = {
  200
+			isa = PBXGroup;
  201
+			children = (
  202
+				902FF3C514FE203600A5DD5A /* WSLegendLayer.h */,
  203
+				902FF3C614FE203600A5DD5A /* WSLegendLayer.m */,
  204
+				9005531615049FDF00BC7CD4 /* WSCoordinateLayer.h */,
  205
+				9005531715049FDF00BC7CD4 /* WSCoordinateLayer.m */,
  206
+				9034049415187F950080CD54 /* WSLineLayer.h */,
  207
+				9034049515187F950080CD54 /* WSLineLayer.m */,
  208
+				90340497151880880080CD54 /* WSAreaLayer.h */,
  209
+				90340498151880880080CD54 /* WSAreaLayer.m */,
  210
+				9034049A151881520080CD54 /* WSScatterLayer.h */,
  211
+				9034049B151881520080CD54 /* WSScatterLayer.m */,
  212
+				9034049D151882B20080CD54 /* WSColumnLayer.h */,
  213
+				9034049E151882B20080CD54 /* WSColumnLayer.m */,
  214
+			);
  215
+			name = "Chart Layers";
  216
+			sourceTree = "<group>";
  217
+		};
187 218
 		9044C9FD1517619E005E2547 /* Combo Chart */ = {
188 219
 			isa = PBXGroup;
189 220
 			children = (
@@ -196,10 +227,6 @@
196 227
 		9062D4331504B2FC0000809F /* Global */ = {
197 228
 			isa = PBXGroup;
198 229
 			children = (
199  
-				902FF3C514FE203600A5DD5A /* WSLegendLayer.h */,
200  
-				902FF3C614FE203600A5DD5A /* WSLegendLayer.m */,
201  
-				9005531615049FDF00BC7CD4 /* WSCoordinateLayer.h */,
202  
-				9005531715049FDF00BC7CD4 /* WSCoordinateLayer.m */,
203 230
 				900553201504ADD800BC7CD4 /* WSGlobalCore.h */,
204 231
 				900553211504ADD800BC7CD4 /* WSGlobalCore.m */,
205 232
 				90653E2B15089E2C00ECE29D /* WSBaseChartView.h */,
@@ -232,6 +259,7 @@
232 259
 		90CAF43A14DA7B6C00928735 /* charts */ = {
233 260
 			isa = PBXGroup;
234 261
 			children = (
  262
+				9034049215187F4B0080CD54 /* Chart Layers */,
235 263
 				9044C9FD1517619E005E2547 /* Combo Chart */,
236 264
 				90936B621509E3AC0021AF14 /* Scatter Chart */,
237 265
 				902D320E1507494E00D9CA06 /* Area Chart */,
@@ -324,6 +352,10 @@
324 352
 				90936B601509E3A80021AF14 /* WSScatterChartView.m in Sources */,
325 353
 				907C7AE0150F3DDB00656860 /* WSChartObject.m in Sources */,
326 354
 				9044CA01151761C4005E2547 /* WSComboChartView.m in Sources */,
  355
+				9034049615187F950080CD54 /* WSLineLayer.m in Sources */,
  356
+				90340499151880880080CD54 /* WSAreaLayer.m in Sources */,
  357
+				9034049C151881520080CD54 /* WSScatterLayer.m in Sources */,
  358
+				9034049F151882B20080CD54 /* WSColumnLayer.m in Sources */,
327 359
 			);
328 360
 			runOnlyForDeploymentPostprocessing = 0;
329 361
 		};
52  WSCharts/WSAreaChartView.m
@@ -21,58 +21,8 @@ this software and associated documentation files (the "Software"), to deal in
21 21
  */
22 22
 
23 23
 #import "WSAreaChartView.h"
  24
+#import "WSAreaLayer.h"
24 25
 
25  
-#pragma mark - WSAreaLayer
26  
-
27  
-@interface WSAreaLayer:CAShapeLayer
28  
-
29  
-@property (nonatomic, strong) NSArray* points;
30  
-@property (nonatomic) CGFloat rowWidth;
31  
-@property (nonatomic, strong) UIColor *color;
32  
-@property (nonatomic) CGPoint originalPoint;
33  
-
34  
-@end
35  
-
36  
-@implementation WSAreaLayer
37  
-
38  
-@synthesize points = _points;
39  
-@synthesize rowWidth = _rowWidth;
40  
-@synthesize color = _color;
41  
-@synthesize originalPoint = _originalPoint;
42  
-
43  
-- (id)init
44  
-{
45  
-    self = [super init];
46  
-    return self;
47  
-}
48  
-
49  
-- (void)drawInContext:(CGContextRef)ctx
50  
-{   
51  
-    size_t count = [self.points count];
52  
-    CGPoint p[count];
53  
-    for (int i=0; i<count; i++) {
54  
-        CGPoint point = [[self.points objectAtIndex:i] CGPointValue];
55  
-        p[i] = point;
56  
-    }
57  
-    CGMutablePathRef path = CGPathCreateMutable();
58  
-    CGPathAddLines(path, NULL, p, count);
59  
-    CGPoint point = [[self.points lastObject] CGPointValue];
60  
-    CGPathAddLineToPoint(path, NULL, point.x, self.originalPoint.y);
61  
-    CGPathAddLineToPoint(path, NULL, self.originalPoint.x, self.originalPoint.y);
62  
-    CGPathCloseSubpath(path);
63  
-    CGContextSetStrokeColorWithColor(ctx, self.color.CGColor);
64  
-    CGContextSetLineWidth(ctx, 2.0);
65  
-    UIColor *fillColor = CreateAlphaColor(self.color, 0.3);
66  
-    CGContextSetFillColorWithColor(ctx, fillColor.CGColor);
67  
-    CGContextAddPath(ctx, path);
68  
-    CGContextDrawPath(ctx, kCGPathFillStroke);
69  
-    CGPathRelease(path);
70  
-}
71  
-
72  
-@end
73  
-
74  
-
75  
-#pragma mark - WSAreaChartView
76 26
 
77 27
 @implementation WSAreaChartView
78 28
 
32  WSCharts/WSAreaLayer.h
... ...
@@ -0,0 +1,32 @@
  1
+/*
  2
+ Copyright (C) 2012, pyanfield  - pyanfield@gmail.com
  3
+ 
  4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
  5
+ this software and associated documentation files (the "Software"), to deal in
  6
+ the Software without restriction, including without limitation the rights to
  7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8
+ of the Software, and to permit persons to whom the Software is furnished to do
  9
+ so, subject to the following conditions:
  10
+ 
  11
+ The above copyright notice and this permission notice shall be included in all
  12
+ copies or substantial portions of the Software.
  13
+ 
  14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20
+ SOFTWARE.
  21
+ */
  22
+
  23
+#import <QuartzCore/QuartzCore.h>
  24
+
  25
+@interface WSAreaLayer:CAShapeLayer
  26
+
  27
+@property (nonatomic, strong) NSArray* points;
  28
+@property (nonatomic) CGFloat rowWidth;
  29
+@property (nonatomic, strong) UIColor *color;
  30
+@property (nonatomic) CGPoint originalPoint;
  31
+
  32
+@end
63  WSCharts/WSAreaLayer.m
... ...
@@ -0,0 +1,63 @@
  1
+/*
  2
+ Copyright (C) 2012, pyanfield  - pyanfield@gmail.com
  3
+ 
  4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
  5
+ this software and associated documentation files (the "Software"), to deal in
  6
+ the Software without restriction, including without limitation the rights to
  7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8
+ of the Software, and to permit persons to whom the Software is furnished to do
  9
+ so, subject to the following conditions:
  10
+ 
  11
+ The above copyright notice and this permission notice shall be included in all
  12
+ copies or substantial portions of the Software.
  13
+ 
  14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20
+ SOFTWARE.
  21
+ */
  22
+
  23
+#import "WSAreaLayer.h"
  24
+#import "WSGlobalCore.h"
  25
+
  26
+@implementation WSAreaLayer
  27
+
  28
+@synthesize points = _points;
  29
+@synthesize rowWidth = _rowWidth;
  30
+@synthesize color = _color;
  31
+@synthesize originalPoint = _originalPoint;
  32
+
  33
+- (id)init
  34
+{
  35
+    self = [super init];
  36
+    return self;
  37
+}
  38
+
  39
+- (void)drawInContext:(CGContextRef)ctx
  40
+{   
  41
+    size_t count = [self.points count];
  42
+    CGPoint p[count];
  43
+    for (int i=0; i<count; i++) {
  44
+        CGPoint point = [[self.points objectAtIndex:i] CGPointValue];
  45
+        p[i] = point;
  46
+    }
  47
+    CGMutablePathRef path = CGPathCreateMutable();
  48
+    CGPathAddLines(path, NULL, p, count);
  49
+    CGPoint point = [[self.points lastObject] CGPointValue];
  50
+    CGPathAddLineToPoint(path, NULL, point.x, self.originalPoint.y);
  51
+    CGPathAddLineToPoint(path, NULL, self.originalPoint.x, self.originalPoint.y);
  52
+    CGPathCloseSubpath(path);
  53
+    CGContextSetStrokeColorWithColor(ctx, self.color.CGColor);
  54
+    CGContextSetLineWidth(ctx, 2.0);
  55
+    UIColor *fillColor = CreateAlphaColor(self.color, 0.3);
  56
+    CGContextSetFillColorWithColor(ctx, fillColor.CGColor);
  57
+    CGContextAddPath(ctx, path);
  58
+    CGContextDrawPath(ctx, kCGPathFillStroke);
  59
+    CGPathRelease(path);
  60
+}
  61
+
  62
+@end
  63
+
93  WSCharts/WSColumnChartView.m
@@ -21,99 +21,8 @@ this software and associated documentation files (the "Software"), to deal in
21 21
  */
22 22
 
23 23
 #import "WSColumnChartView.h"
  24
+#import "WSColumnLayer.h"
24 25
 
25  
-#define ANGLE_DEFAULT M_PI/4.0
26  
-#define DISTANCE_DEFAULT 15.0
27  
-
28  
-#pragma mark - WSColumnLayer
29  
-
30  
-@interface WSColumnLayer:CAShapeLayer
31  
-
32  
-@property (nonatomic) CGPoint xStartPoint;
33  
-@property (nonatomic) CGFloat yValue;
34  
-@property (nonatomic) CGFloat columnWidth;
35  
-@property (nonatomic, strong) UIColor *color;
36  
-
37  
-@end
38  
-
39  
-@implementation WSColumnLayer
40  
-
41  
-@synthesize xStartPoint = _xStartPoint;
42  
-@synthesize yValue = _yValue;
43  
-@synthesize columnWidth = _columnWidth;
44  
-@synthesize color = _color;
45  
-
46  
-- (id)init
47  
-{
48  
-    self = [super init];
49  
-    return self;
50  
-}
51  
-
52  
-- (void)drawInContext:(CGContextRef)ctx
53  
-{
54  
-    NSDictionary *colors = ConstructBrightAndDarkColors(self.color);
55  
-    CGPoint topLeftFront ,topLeftBack,topRightFront,topRightBack , bottomRightBack ,bottomRightFront;
56  
-    if (self.yValue>=0.0) {
57  
-        topLeftFront = CGPointMake(self.xStartPoint.x, self.xStartPoint.y-self.yValue);
58  
-        topLeftBack = CreateEndPoint(topLeftFront, ANGLE_DEFAULT,DISTANCE_DEFAULT);
59  
-        topRightFront = CGPointMake(self.xStartPoint.x+self.columnWidth, self.xStartPoint.y-self.yValue);
60  
-        topRightBack = CreateEndPoint(topRightFront, ANGLE_DEFAULT, DISTANCE_DEFAULT);
61  
-        bottomRightBack = CGPointMake(topRightBack.x, topRightBack.y+self.yValue);
62  
-        bottomRightFront = CGPointMake(topRightFront.x, self.xStartPoint.y);
63  
-    }else
64  
-    {
65  
-        topLeftFront = self.xStartPoint;
66  
-        topLeftBack = CreateEndPoint(topLeftFront, ANGLE_DEFAULT, DISTANCE_DEFAULT);
67  
-        topRightFront = CGPointMake(self.xStartPoint.x+self.columnWidth, self.xStartPoint.y);
68  
-        topRightBack = CreateEndPoint(topRightFront, ANGLE_DEFAULT, DISTANCE_DEFAULT);
69  
-        bottomRightBack = CGPointMake(topRightBack.x, topRightBack.y-self.yValue);
70  
-        bottomRightFront = CGPointMake(topRightFront.x, topLeftFront.y-self.yValue);
71  
-    }
72  
-
73  
-    
74  
-    // front side
75  
-    CGMutablePathRef path = CGPathCreateMutable();
76  
-    CGPathAddRect(path, NULL, CGRectMake(topLeftFront.x,topLeftFront.y, self.columnWidth,fabsf(self.yValue)));
77  
-    UIColor *normalColor = [colors objectForKey:@"normalColor"];
78  
-    CGContextSetFillColorWithColor(ctx, normalColor.CGColor);
79  
-    CGContextSetLineWidth(ctx, 1.0);
80  
-    CGContextAddPath(ctx, path);
81  
-    CGContextDrawPath(ctx, kCGPathFill);
82  
-    CGPathRelease(path);
83  
-
84  
-    
85  
-    // top side
86  
-    CGMutablePathRef topPath = CGPathCreateMutable();
87  
-    CGPathMoveToPoint(topPath, NULL, topLeftFront.x,topLeftFront.y);
88  
-    CGPathAddLineToPoint(topPath, NULL, topLeftBack.x,topLeftBack.y);
89  
-    CGPathAddLineToPoint(topPath, NULL, topRightBack.x, topRightBack.y);
90  
-    CGPathAddLineToPoint(topPath, NULL,topRightFront.x,topRightFront.y);
91  
-    CGPathCloseSubpath(topPath);
92  
-    UIColor *brightColor = [colors objectForKey:@"brightColor"];
93  
-    CGContextSetFillColorWithColor(ctx, brightColor.CGColor);
94  
-    CGContextSetLineWidth(ctx, 1.0);
95  
-    CGContextAddPath(ctx, topPath);
96  
-    CGContextDrawPath(ctx, kCGPathFill);
97  
-    CGPathRelease(topPath);
98  
-    
99  
-    // right side
100  
-    CGMutablePathRef rightPath = CGPathCreateMutable();
101  
-    CGPathMoveToPoint(rightPath, NULL, topRightBack.x,topRightBack.y);
102  
-    CGPathAddLineToPoint(rightPath, NULL, bottomRightBack.x, bottomRightBack.y);
103  
-    CGPathAddLineToPoint(rightPath, NULL, bottomRightFront.x, bottomRightFront.y);
104  
-    CGPathAddLineToPoint(rightPath, NULL, topRightFront.x, topRightFront.y);
105  
-    CGPathCloseSubpath(rightPath);
106  
-    UIColor *darkColor = [colors objectForKey:@"darkColor"];
107  
-    CGContextSetFillColorWithColor(ctx, darkColor.CGColor);
108  
-    CGContextSetLineWidth(ctx, 1.0);
109  
-    CGContextAddPath(ctx, rightPath);
110  
-    CGContextDrawPath(ctx, kCGPathFill);
111  
-    CGPathRelease(rightPath);
112  
-}
113  
-
114  
-@end
115  
-
116  
-#pragma mark - WSColumnChartView
117 26
 
118 27
 @interface WSColumnChartView()
119 28
 
36  WSCharts/WSColumnLayer.h
... ...
@@ -0,0 +1,36 @@
  1
+/*
  2
+ Copyright (C) 2012, pyanfield  - pyanfield@gmail.com
  3
+ 
  4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
  5
+ this software and associated documentation files (the "Software"), to deal in
  6
+ the Software without restriction, including without limitation the rights to
  7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8
+ of the Software, and to permit persons to whom the Software is furnished to do
  9
+ so, subject to the following conditions:
  10
+ 
  11
+ The above copyright notice and this permission notice shall be included in all
  12
+ copies or substantial portions of the Software.
  13
+ 
  14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20
+ SOFTWARE.
  21
+ */
  22
+
  23
+#import <QuartzCore/QuartzCore.h>
  24
+
  25
+#define ANGLE_DEFAULT M_PI/4.0
  26
+#define DISTANCE_DEFAULT 15.0
  27
+
  28
+@interface WSColumnLayer:CAShapeLayer
  29
+
  30
+@property (nonatomic) CGPoint xStartPoint;
  31
+@property (nonatomic) CGFloat yValue;
  32
+@property (nonatomic) CGFloat columnWidth;
  33
+@property (nonatomic, strong) UIColor *color;
  34
+
  35
+@end
  36
+
102  WSCharts/WSColumnLayer.m
... ...
@@ -0,0 +1,102 @@
  1
+/*
  2
+ Copyright (C) 2012, pyanfield  - pyanfield@gmail.com
  3
+ 
  4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
  5
+ this software and associated documentation files (the "Software"), to deal in
  6
+ the Software without restriction, including without limitation the rights to
  7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8
+ of the Software, and to permit persons to whom the Software is furnished to do
  9
+ so, subject to the following conditions:
  10
+ 
  11
+ The above copyright notice and this permission notice shall be included in all
  12
+ copies or substantial portions of the Software.
  13
+ 
  14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20
+ SOFTWARE.
  21
+ */
  22
+
  23
+#import "WSColumnLayer.h"
  24
+#import "WSGlobalCore.h"
  25
+
  26
+@implementation WSColumnLayer
  27
+
  28
+@synthesize xStartPoint = _xStartPoint;
  29
+@synthesize yValue = _yValue;
  30
+@synthesize columnWidth = _columnWidth;
  31
+@synthesize color = _color;
  32
+
  33
+- (id)init
  34
+{
  35
+    self = [super init];
  36
+    return self;
  37
+}
  38
+
  39
+- (void)drawInContext:(CGContextRef)ctx
  40
+{
  41
+    NSDictionary *colors = ConstructBrightAndDarkColors(self.color);
  42
+    CGPoint topLeftFront ,topLeftBack,topRightFront,topRightBack , bottomRightBack ,bottomRightFront;
  43
+    if (self.yValue>=0.0) {
  44
+        topLeftFront = CGPointMake(self.xStartPoint.x, self.xStartPoint.y-self.yValue);
  45
+        topLeftBack = CreateEndPoint(topLeftFront, ANGLE_DEFAULT,DISTANCE_DEFAULT);
  46
+        topRightFront = CGPointMake(self.xStartPoint.x+self.columnWidth, self.xStartPoint.y-self.yValue);
  47
+        topRightBack = CreateEndPoint(topRightFront, ANGLE_DEFAULT, DISTANCE_DEFAULT);
  48
+        bottomRightBack = CGPointMake(topRightBack.x, topRightBack.y+self.yValue);
  49
+        bottomRightFront = CGPointMake(topRightFront.x, self.xStartPoint.y);
  50
+    }else
  51
+    {
  52
+        topLeftFront = self.xStartPoint;
  53
+        topLeftBack = CreateEndPoint(topLeftFront, ANGLE_DEFAULT, DISTANCE_DEFAULT);
  54
+        topRightFront = CGPointMake(self.xStartPoint.x+self.columnWidth, self.xStartPoint.y);
  55
+        topRightBack = CreateEndPoint(topRightFront, ANGLE_DEFAULT, DISTANCE_DEFAULT);
  56
+        bottomRightBack = CGPointMake(topRightBack.x, topRightBack.y-self.yValue);
  57
+        bottomRightFront = CGPointMake(topRightFront.x, topLeftFront.y-self.yValue);
  58
+    }
  59
+    
  60
+    
  61
+    // front side
  62
+    CGMutablePathRef path = CGPathCreateMutable();
  63
+    CGPathAddRect(path, NULL, CGRectMake(topLeftFront.x,topLeftFront.y, self.columnWidth,fabsf(self.yValue)));
  64
+    UIColor *normalColor = [colors objectForKey:@"normalColor"];
  65
+    CGContextSetFillColorWithColor(ctx, normalColor.CGColor);
  66
+    CGContextSetLineWidth(ctx, 1.0);
  67
+    CGContextAddPath(ctx, path);
  68
+    CGContextDrawPath(ctx, kCGPathFill);
  69
+    CGPathRelease(path);
  70
+    
  71
+    
  72
+    // top side
  73
+    CGMutablePathRef topPath = CGPathCreateMutable();
  74
+    CGPathMoveToPoint(topPath, NULL, topLeftFront.x,topLeftFront.y);
  75
+    CGPathAddLineToPoint(topPath, NULL, topLeftBack.x,topLeftBack.y);
  76
+    CGPathAddLineToPoint(topPath, NULL, topRightBack.x, topRightBack.y);
  77
+    CGPathAddLineToPoint(topPath, NULL,topRightFront.x,topRightFront.y);
  78
+    CGPathCloseSubpath(topPath);
  79
+    UIColor *brightColor = [colors objectForKey:@"brightColor"];
  80
+    CGContextSetFillColorWithColor(ctx, brightColor.CGColor);
  81
+    CGContextSetLineWidth(ctx, 1.0);
  82
+    CGContextAddPath(ctx, topPath);
  83
+    CGContextDrawPath(ctx, kCGPathFill);
  84
+    CGPathRelease(topPath);
  85
+    
  86
+    // right side
  87
+    CGMutablePathRef rightPath = CGPathCreateMutable();
  88
+    CGPathMoveToPoint(rightPath, NULL, topRightBack.x,topRightBack.y);
  89
+    CGPathAddLineToPoint(rightPath, NULL, bottomRightBack.x, bottomRightBack.y);
  90
+    CGPathAddLineToPoint(rightPath, NULL, bottomRightFront.x, bottomRightFront.y);
  91
+    CGPathAddLineToPoint(rightPath, NULL, topRightFront.x, topRightFront.y);
  92
+    CGPathCloseSubpath(rightPath);
  93
+    UIColor *darkColor = [colors objectForKey:@"darkColor"];
  94
+    CGContextSetFillColorWithColor(ctx, darkColor.CGColor);
  95
+    CGContextSetLineWidth(ctx, 1.0);
  96
+    CGContextAddPath(ctx, rightPath);
  97
+    CGContextDrawPath(ctx, kCGPathFill);
  98
+    CGPathRelease(rightPath);
  99
+}
  100
+
  101
+@end
  102
+
46  WSCharts/WSLineChartView.m
@@ -21,51 +21,7 @@ this software and associated documentation files (the "Software"), to deal in
21 21
  */
22 22
 
23 23
 #import "WSLineChartView.h"
24  
-
25  
-#pragma mark - WSLineLayer
26  
-
27  
-@interface WSLineLayer:CAShapeLayer
28  
-
29  
-@property (nonatomic, strong) NSArray* points;
30  
-@property (nonatomic) CGFloat rowWidth;
31  
-@property (nonatomic, strong) UIColor *color;
32  
-
33  
-@end
34  
-
35  
-@implementation WSLineLayer
36  
-
37  
-@synthesize points = _points;
38  
-@synthesize rowWidth = _rowWidth;
39  
-@synthesize color = _color;
40  
-
41  
-
42  
-- (id)init
43  
-{
44  
-    self = [super init];
45  
-    return self;
46  
-}
47  
-
48  
-- (void)drawInContext:(CGContextRef)ctx
49  
-{   
50  
-    size_t count = [self.points count];
51  
-    CGPoint p[count];
52  
-    for (int i=0; i<count; i++) {
53  
-        CGPoint point = [[self.points objectAtIndex:i] CGPointValue];
54  
-        p[i] = point;
55  
-    }
56  
-    CGMutablePathRef path = CGPathCreateMutable();
57  
-    CGPathAddLines(path, NULL, p, count);
58  
-    CGContextSetStrokeColorWithColor(ctx, self.color.CGColor);
59  
-    CGContextSetLineWidth(ctx, 2.0);
60  
-    CGContextAddPath(ctx, path);
61  
-    CGContextDrawPath(ctx, kCGPathStroke);
62  
-    CGPathRelease(path);
63  
-}
64  
-
65  
-@end
66  
-
67  
-
68  
-#pragma mark - WSLineChartView
  24
+#import "WSLineLayer.h"
69 25
 
70 26
 @implementation WSLineChartView
71 27
 
34  WSCharts/WSLineLayer.h
... ...
@@ -0,0 +1,34 @@
  1
+/*
  2
+ Copyright (C) 2012, pyanfield  - pyanfield@gmail.com
  3
+ 
  4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
  5
+ this software and associated documentation files (the "Software"), to deal in
  6
+ the Software without restriction, including without limitation the rights to
  7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8
+ of the Software, and to permit persons to whom the Software is furnished to do
  9
+ so, subject to the following conditions:
  10
+ 
  11
+ The above copyright notice and this permission notice shall be included in all
  12
+ copies or substantial portions of the Software.
  13
+ 
  14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20
+ SOFTWARE.
  21
+ */
  22
+
  23
+#import <QuartzCore/QuartzCore.h>
  24
+
  25
+
  26
+@interface WSLineLayer:CAShapeLayer
  27
+
  28
+@property (nonatomic, strong) NSArray* points;
  29
+@property (nonatomic) CGFloat rowWidth;
  30
+@property (nonatomic, strong) UIColor *color;
  31
+
  32
+@end
  33
+
  34
+
55  WSCharts/WSLineLayer.m
... ...
@@ -0,0 +1,55 @@
  1
+/*
  2
+ Copyright (C) 2012, pyanfield  - pyanfield@gmail.com
  3
+ 
  4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
  5
+ this software and associated documentation files (the "Software"), to deal in
  6
+ the Software without restriction, including without limitation the rights to
  7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8
+ of the Software, and to permit persons to whom the Software is furnished to do
  9
+ so, subject to the following conditions:
  10
+ 
  11
+ The above copyright notice and this permission notice shall be included in all
  12
+ copies or substantial portions of the Software.
  13
+ 
  14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20
+ SOFTWARE.
  21
+ */
  22
+
  23
+#import "WSLineLayer.h"
  24
+
  25
+@implementation WSLineLayer
  26
+
  27
+@synthesize points = _points;
  28
+@synthesize rowWidth = _rowWidth;
  29
+@synthesize color = _color;
  30
+
  31
+
  32
+- (id)init
  33
+{
  34
+    self = [super init];
  35
+    return self;
  36
+}
  37
+
  38
+- (void)drawInContext:(CGContextRef)ctx
  39
+{   
  40
+    size_t count = [self.points count];
  41
+    CGPoint p[count];
  42
+    for (int i=0; i<count; i++) {
  43
+        CGPoint point = [[self.points objectAtIndex:i] CGPointValue];
  44
+        p[i] = point;
  45
+    }
  46
+    CGMutablePathRef path = CGPathCreateMutable();
  47
+    CGPathAddLines(path, NULL, p, count);
  48
+    CGContextSetStrokeColorWithColor(ctx, self.color.CGColor);
  49
+    CGContextSetLineWidth(ctx, 2.0);
  50
+    CGContextAddPath(ctx, path);
  51
+    CGContextDrawPath(ctx, kCGPathStroke);
  52
+    CGPathRelease(path);
  53
+}
  54
+
  55
+@end
71  WSCharts/WSScatterChartView.m
@@ -21,73 +21,7 @@ this software and associated documentation files (the "Software"), to deal in
21 21
  */
22 22
 
23 23
 #import "WSScatterChartView.h"
24  
-
25  
-#define RADIUS 5.0
26  
-
27  
-#pragma mark - WSScatterLayer
28  
-
29  
-@interface WSScatterLayer : CAShapeLayer
30  
-
31  
-@property (nonatomic, strong) UIColor *color;
32  
-@property (nonatomic, strong) NSMutableArray *points;
33  
-@property (nonatomic, strong) NSMutableArray *radiusArr;
34  
-/*
35  
- Can set the circle's radius.
36  
- */
37  
-@property (nonatomic) BOOL enableChangeRadius;
38  
-
39  
-@end
40  
-
41  
-
42  
-
43  
-@implementation WSScatterLayer
44  
-
45  
-@synthesize color = _color;
46  
-@synthesize points = _points;
47  
-@synthesize radiusArr = _radiusArr;
48  
-@synthesize enableChangeRadius = _enableChangeRadius;
49  
-
50  
-- (id)init
51  
-{
52  
-    return [super init];
53  
-}
54  
-
55  
-- (void)drawInContext:(CGContextRef)ctx
56  
-{
57  
-    int count = [self.points count];
58  
-    if (self.enableChangeRadius) {
59  
-        for (int i=0; i<count; i++) {
60  
-            CGPoint point = [[self.points objectAtIndex:i] CGPointValue];
61  
-            CGMutablePathRef path = CGPathCreateMutable();
62  
-            CGFloat r = [[self.radiusArr objectAtIndex:i] floatValue];
63  
-            CGRect rect = CGRectMake(point.x-r, point.y-r, 2*r, 2*r);
64  
-            CGPathAddEllipseInRect(path, NULL, rect);
65  
-            UIColor *fillColor = CreateAlphaColor(self.color, 0.5);
66  
-            CGContextSetFillColorWithColor(ctx, fillColor.CGColor);
67  
-            CGContextSetLineWidth(ctx, 2.0);
68  
-            CGContextAddPath(ctx, path);
69  
-            CGContextDrawPath(ctx, kCGPathFill);
70  
-            CGPathRelease(path);
71  
-        }
72  
-    }else{
73  
-        for (int i=0; i<count; i++) {
74  
-            CGPoint point = [[self.points objectAtIndex:i] CGPointValue];
75  
-            CGMutablePathRef path = CGPathCreateMutable();
76  
-            CGRect rect = CGRectMake(point.x-RADIUS, point.y-RADIUS, 2*RADIUS, 2*RADIUS);
77  
-            CGPathAddEllipseInRect(path, NULL, rect);
78  
-            UIColor *fillColor = CreateAlphaColor(self.color, 0.5);
79  
-            CGContextSetFillColorWithColor(ctx, fillColor.CGColor);
80  
-            CGContextSetLineWidth(ctx, 2.0);
81  
-            CGContextAddPath(ctx, path);
82  
-            CGContextDrawPath(ctx, kCGPathFill);
83  
-            CGPathRelease(path);
84  
-        }
85  
-    }
86  
-}
87  
-
88  
-@end
89  
-
90  
-#pragma mark - WSScatterChartView
  24
+#import "WSScatterLayer.h"
91 25
 
92 26
 @implementation WSScatterChartView
93 27
 
@@ -139,7 +73,8 @@ - (void)createCoordinateLayer
139 73
     xyAxesLayer.xAxisLength = xAxisLength;
140 74
     xyAxesLayer.originalPoint = self.coordinateOriginalPoint;
141 75
     xyAxesLayer.xMarkTitlePosition = WSAtPoint;
142  
-    
  76
+    xyAxesLayer.xAxisName = self.xAxisName;
  77
+    xyAxesLayer.yAxisName = self.yAxisName;
143 78
     xyAxesLayer.showBorder = YES;
144 79
     [xyAxesLayer setNeedsDisplay];
145 80
 }
37  WSCharts/WSScatterLayer.h
... ...
@@ -0,0 +1,37 @@
  1
+/*
  2
+ Copyright (C) 2012, pyanfield  - pyanfield@gmail.com
  3
+ 
  4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
  5
+ this software and associated documentation files (the "Software"), to deal in
  6
+ the Software without restriction, including without limitation the rights to
  7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8
+ of the Software, and to permit persons to whom the Software is furnished to do
  9
+ so, subject to the following conditions:
  10
+ 
  11
+ The above copyright notice and this permission notice shall be included in all
  12
+ copies or substantial portions of the Software.
  13
+ 
  14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20
+ SOFTWARE.
  21
+ */
  22
+
  23
+#import <QuartzCore/QuartzCore.h>
  24
+
  25
+
  26
+@interface WSScatterLayer : CAShapeLayer
  27
+
  28
+@property (nonatomic, strong) UIColor *color;
  29
+@property (nonatomic, strong) NSMutableArray *points;
  30
+@property (nonatomic, strong) NSMutableArray *radiusArr;
  31
+/*
  32
+ Can set the circle's radius.
  33
+ */
  34
+@property (nonatomic) BOOL enableChangeRadius;
  35
+
  36
+@end
  37
+
73  WSCharts/WSScatterLayer.m
... ...
@@ -0,0 +1,73 @@
  1
+/*
  2
+ Copyright (C) 2012, pyanfield  - pyanfield@gmail.com
  3
+ 
  4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
  5
+ this software and associated documentation files (the "Software"), to deal in
  6
+ the Software without restriction, including without limitation the rights to
  7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8
+ of the Software, and to permit persons to whom the Software is furnished to do
  9
+ so, subject to the following conditions:
  10
+ 
  11
+ The above copyright notice and this permission notice shall be included in all
  12
+ copies or substantial portions of the Software.
  13
+ 
  14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20
+ SOFTWARE.
  21
+ */
  22
+
  23
+#import "WSScatterLayer.h"
  24
+#import "WSGlobalCore.h"
  25
+
  26
+#define RADIUS 5.0
  27
+
  28
+@implementation WSScatterLayer
  29
+
  30
+@synthesize color = _color;
  31
+@synthesize points = _points;
  32
+@synthesize radiusArr = _radiusArr;
  33
+@synthesize enableChangeRadius = _enableChangeRadius;
  34
+
  35
+- (id)init
  36
+{
  37
+    return [super init];
  38
+}
  39
+
  40
+- (void)drawInContext:(CGContextRef)ctx
  41
+{
  42
+    int count = [self.points count];
  43
+    if (self.enableChangeRadius) {
  44
+        for (int i=0; i<count; i++) {
  45
+            CGPoint point = [[self.points objectAtIndex:i] CGPointValue];
  46
+            CGMutablePathRef path = CGPathCreateMutable();
  47
+            CGFloat r = [[self.radiusArr objectAtIndex:i] floatValue];
  48
+            CGRect rect = CGRectMake(point.x-r, point.y-r, 2*r, 2*r);
  49
+            CGPathAddEllipseInRect(path, NULL, rect);
  50
+            UIColor *fillColor = CreateAlphaColor(self.color, 0.5);
  51
+            CGContextSetFillColorWithColor(ctx, fillColor.CGColor);
  52
+            CGContextSetLineWidth(ctx, 2.0);
  53
+            CGContextAddPath(ctx, path);
  54
+            CGContextDrawPath(ctx, kCGPathFill);
  55
+            CGPathRelease(path);
  56
+        }
  57
+    }else{
  58
+        for (int i=0; i<count; i++) {
  59
+            CGPoint point = [[self.points objectAtIndex:i] CGPointValue];
  60
+            CGMutablePathRef path = CGPathCreateMutable();
  61
+            CGRect rect = CGRectMake(point.x-RADIUS, point.y-RADIUS, 2*RADIUS, 2*RADIUS);
  62
+            CGPathAddEllipseInRect(path, NULL, rect);
  63
+            UIColor *fillColor = CreateAlphaColor(self.color, 0.5);
  64
+            CGContextSetFillColorWithColor(ctx, fillColor.CGColor);
  65
+            CGContextSetLineWidth(ctx, 2.0);
  66
+            CGContextAddPath(ctx, path);
  67
+            CGContextDrawPath(ctx, kCGPathFill);
  68
+            CGPathRelease(path);
  69
+        }
  70
+    }
  71
+}
  72
+
  73
+@end

0 notes on commit 867eea0

Please sign in to comment.
Something went wrong with that request. Please try again.