Repository navigation
Expand file tree
/
Copy pathCPTAxisTitle.m
More file actions
95 lines (75 loc) · 2.15 KB
/
Copy pathCPTAxisTitle.m
File metadata and controls
95 lines (75 loc) · 2.15 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
#import "CPTAxisTitle.h"
#import "CPTLayer.h"
#import "CPTUtilities.h"
#import <tgmath.h>
/** @brief An axis title.
*
* The title can be text-based or can be the content of any CPTLayer provided by the user.
**/
@implementation CPTAxisTitle
#pragma mark -
#pragma mark Init/Dealloc
/// @cond
-(nonnull instancetype)initWithContentLayer:(nonnull CPTLayer *)layer
{
if ( layer ) {
if ((self = [super initWithContentLayer:layer])) {
self.rotation = CPTNAN;
}
}
else {
self = nil;
}
return self;
}
/// @endcond
#pragma mark -
#pragma mark Label comparison
/// @name Comparison
/// @{
/** @brief Returns a boolean value that indicates whether the received is equal to the given object.
* Axis titles are equal if they have the same @ref tickLocation, @ref rotation, and @ref contentLayer.
* @param object The object to be compared with the receiver.
* @return @YES if @par{object} is equal to the receiver, @NO otherwise.
**/
-(BOOL)isEqual:(nullable id)object
{
if ( self == object ) {
return YES;
}
else if ( [object isKindOfClass:[self class]] ) {
CPTAxisTitle *otherTitle = object;
if ((self.rotation != otherTitle.rotation) || (self.offset != otherTitle.offset)) {
return NO;
}
if ( ![self.contentLayer isEqual:otherTitle] ) {
return NO;
}
NSNumber *location = ((CPTAxisLabel *)object).tickLocation;
if ( location ) {
return [self.tickLocation isEqualToNumber:location];
}
else {
return NO;
}
}
else {
return NO;
}
}
/// @}
/// @cond
-(NSUInteger)hash
{
NSUInteger hashValue = 0;
// Equal objects must hash the same.
double tickLocationAsDouble = self.tickLocation.doubleValue;
if ( !isnan(tickLocationAsDouble)) {
hashValue = (NSUInteger)lrint(fmod(ABS(tickLocationAsDouble), (double)NSUIntegerMax));
}
hashValue += (NSUInteger)lrint(fmod(ABS(self.rotation), (double)NSUIntegerMax));
hashValue += (NSUInteger)lrint(fmod(ABS(self.offset), (double)NSUIntegerMax));
return hashValue;
}
/// @endcond
@end