forked from core-plot/core-plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPTAxisSet.m
More file actions
246 lines (203 loc) · 5.81 KB
/
CPTAxisSet.m
File metadata and controls
246 lines (203 loc) · 5.81 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#import "CPTAxisSet.h"
#import "CPTAxis.h"
#import "CPTGraph.h"
#import "CPTLineStyle.h"
#import "CPTPlotArea.h"
/**
* @brief A container layer for the set of axes for a graph.
**/
@implementation CPTAxisSet
/** @property NSArray *axes
* @brief The axes in the axis set.
**/
@synthesize axes;
/** @property CPTLineStyle *borderLineStyle
* @brief The line style for the layer border.
* If @nil, the border is not drawn.
**/
@synthesize borderLineStyle;
#pragma mark -
#pragma mark Init/Dealloc
/// @name Initialization
/// @{
/** @brief Initializes a newly allocated CPTAxisSet object with the provided frame rectangle.
*
* This is the designated initializer. The initialized layer will have the following properties:
* - @ref axes = empty array
* - @ref borderLineStyle = @nil
* - @ref needsDisplayOnBoundsChange = @YES
*
* @param newFrame The frame rectangle.
* @return The initialized CPTAxisSet object.
**/
-(instancetype)initWithFrame:(CGRect)newFrame
{
if ( (self = [super initWithFrame:newFrame]) ) {
axes = @[];
borderLineStyle = nil;
self.needsDisplayOnBoundsChange = YES;
}
return self;
}
/// @}
/// @cond
-(instancetype)initWithLayer:(id)layer
{
if ( (self = [super initWithLayer:layer]) ) {
CPTAxisSet *theLayer = (CPTAxisSet *)layer;
axes = theLayer->axes;
borderLineStyle = theLayer->borderLineStyle;
}
return self;
}
/// @endcond
#pragma mark -
#pragma mark NSCoding Methods
/// @cond
-(void)encodeWithCoder:(NSCoder *)coder
{
[super encodeWithCoder:coder];
[coder encodeObject:self.axes forKey:@"CPTAxisSet.axes"];
[coder encodeObject:self.borderLineStyle forKey:@"CPTAxisSet.borderLineStyle"];
}
-(instancetype)initWithCoder:(NSCoder *)coder
{
if ( (self = [super initWithCoder:coder]) ) {
axes = [[coder decodeObjectForKey:@"CPTAxisSet.axes"] copy];
borderLineStyle = [[coder decodeObjectForKey:@"CPTAxisSet.borderLineStyle"] copy];
}
return self;
}
/// @endcond
#pragma mark -
#pragma mark Drawing
/// @cond
-(void)display
{
if ( self.borderLineStyle ) {
[super display];
}
}
/// @endcond
#pragma mark -
#pragma mark Labeling
/**
* @brief Updates the axis labels for each axis in the axis set.
**/
-(void)relabelAxes
{
NSArray *theAxes = self.axes;
[theAxes makeObjectsPerformSelector:@selector(setNeedsLayout)];
[theAxes makeObjectsPerformSelector:@selector(setNeedsRelabel)];
}
#pragma mark -
#pragma mark Axes
/**
* @brief Returns the first, second, third, etc. axis with the given coordinate value.
*
* For example, to find the second x-axis, use a @par{coordinate} of #CPTCoordinateX
* and @par{idx} of @num{1}.
*
* @param coordinate The axis coordinate.
* @param idx The zero-based index.
* @return The axis matching the given coordinate and index, or @nil if no match is found.
**/
-(CPTAxis *)axisForCoordinate:(CPTCoordinate)coordinate atIndex:(NSUInteger)idx
{
CPTAxis *foundAxis = nil;
NSUInteger count = 0;
for ( CPTAxis *axis in self.axes ) {
if ( axis.coordinate == coordinate ) {
if ( count == idx ) {
foundAxis = axis;
break;
}
else {
count++;
}
}
}
return foundAxis;
}
#pragma mark -
#pragma mark Responder Chain and User interaction
/// @name User Interaction
/// @{
/**
* @brief Informs the receiver that the user has
* @if MacOnly pressed the mouse button. @endif
* @if iOSOnly started touching the screen. @endif
*
*
* The event will be passed to each axis belonging to the receiver in turn. This method
* returns @YES if any of its axes handle the event.
*
* @param event The OS event.
* @param interactionPoint The coordinates of the interaction.
* @return Whether the event was handled or not.
**/
-(BOOL)pointingDeviceDownEvent:(CPTNativeEvent *)event atPoint:(CGPoint)interactionPoint
{
for ( CPTAxis *axis in self.axes ) {
if ( [axis pointingDeviceDownEvent:event atPoint:interactionPoint] ) {
return YES;
}
}
return [super pointingDeviceDownEvent:event atPoint:interactionPoint];
}
/**
* @brief Informs the receiver that the user has
* @if MacOnly released the mouse button. @endif
* @if iOSOnly ended touching the screen. @endif
*
*
* The event will be passed to each axis belonging to the receiver in turn. This method
* returns @YES if any of its axes handle the event.
*
* @param event The OS event.
* @param interactionPoint The coordinates of the interaction.
* @return Whether the event was handled or not.
**/
-(BOOL)pointingDeviceUpEvent:(CPTNativeEvent *)event atPoint:(CGPoint)interactionPoint
{
for ( CPTAxis *axis in self.axes ) {
if ( [axis pointingDeviceUpEvent:event atPoint:interactionPoint] ) {
return YES;
}
}
return [super pointingDeviceUpEvent:event atPoint:interactionPoint];
}
/// @}
#pragma mark -
#pragma mark Accessors
/// @cond
-(void)setAxes:(NSArray *)newAxes
{
if ( newAxes != axes ) {
for ( CPTAxis *axis in axes ) {
[axis removeFromSuperlayer];
axis.plotArea = nil;
axis.graph = nil;
}
axes = newAxes;
CPTPlotArea *plotArea = (CPTPlotArea *)self.superlayer;
CPTGraph *theGraph = plotArea.graph;
for ( CPTAxis *axis in axes ) {
[self addSublayer:axis];
axis.plotArea = plotArea;
axis.graph = theGraph;
}
[self setNeedsLayout];
[self setNeedsDisplay];
}
}
-(void)setBorderLineStyle:(CPTLineStyle *)newLineStyle
{
if ( newLineStyle != borderLineStyle ) {
borderLineStyle = [newLineStyle copy];
[self setNeedsLayout];
[self setNeedsDisplay];
}
}
/// @endcond
@end