forked from core-plot/core-plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPTGridLineGroup.m
More file actions
145 lines (111 loc) · 3.16 KB
/
CPTGridLineGroup.m
File metadata and controls
145 lines (111 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#import "CPTGridLineGroup.h"
#import "CPTAxis.h"
#import "CPTAxisSet.h"
#import "CPTPlotArea.h"
/** @brief A group of grid line layers.
*
* When using separate axis layers, this layer serves as the common superlayer for the grid line layers.
* Otherwise, this layer handles the drawing for the grid lines. It supports mixing the two modes;
* some axes can use separate grid line layers while others are handled by the grid line group.
**/
@implementation CPTGridLineGroup
/** @property nullable CPTPlotArea *plotArea
* @brief The plot area that this grid line group belongs to.
**/
@synthesize plotArea;
/** @property BOOL major
* @brief If @YES, draw the major grid lines, else draw the minor grid lines.
**/
@synthesize major;
#pragma mark -
#pragma mark Init/Dealloc
/// @name Initialization
/// @{
/** @brief Initializes a newly allocated CPTGridLineGroup object with the provided frame rectangle.
*
* This is the designated initializer. The initialized layer will have the following properties:
* - @ref plotArea = @nil
* - @ref major = @NO
* - @ref needsDisplayOnBoundsChange = @YES
*
* @param newFrame The frame rectangle.
* @return The initialized CPTGridLineGroup object.
**/
-(nonnull instancetype)initWithFrame:(CGRect)newFrame
{
if ( (self = [super initWithFrame:newFrame]) ) {
plotArea = nil;
major = NO;
self.needsDisplayOnBoundsChange = YES;
}
return self;
}
/// @}
/// @cond
-(nonnull instancetype)initWithLayer:(nonnull id)layer
{
if ( (self = [super initWithLayer:layer]) ) {
CPTGridLineGroup *theLayer = (CPTGridLineGroup *)layer;
plotArea = theLayer->plotArea;
major = theLayer->major;
}
return self;
}
/// @endcond
#pragma mark -
#pragma mark NSCoding Methods
/// @cond
-(void)encodeWithCoder:(nonnull NSCoder *)coder
{
[super encodeWithCoder:coder];
[coder encodeConditionalObject:self.plotArea forKey:@"CPTGridLineGroup.plotArea"];
[coder encodeBool:self.major forKey:@"CPTGridLineGroup.major"];
}
-(nullable instancetype)initWithCoder:(nonnull NSCoder *)coder
{
if ( (self = [super initWithCoder:coder]) ) {
plotArea = [coder decodeObjectOfClass:[CPTPlotArea class]
forKey:@"CPTGridLineGroup.plotArea"];
major = [coder decodeBoolForKey:@"CPTGridLineGroup.major"];
}
return self;
}
/// @endcond
#pragma mark -
#pragma mark NSSecureCoding Methods
/// @cond
+(BOOL)supportsSecureCoding
{
return YES;
}
/// @endcond
#pragma mark -
#pragma mark Drawing
/// @cond
-(void)renderAsVectorInContext:(nonnull CGContextRef)context
{
if ( self.hidden ) {
return;
}
CPTPlotArea *thePlotArea = self.plotArea;
for ( CPTAxis *axis in thePlotArea.axisSet.axes ) {
if ( !axis.separateLayers ) {
[axis drawGridLinesInContext:context isMajor:self.major];
}
}
}
/// @endcond
#pragma mark -
#pragma mark Accessors
/// @cond
-(void)setPlotArea:(nullable CPTPlotArea *)newPlotArea
{
if ( newPlotArea != plotArea ) {
plotArea = newPlotArea;
if ( newPlotArea ) {
[self setNeedsDisplay];
}
}
}
/// @endcond
@end