forked from core-plot/core-plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPTAxis.m
More file actions
3297 lines (2795 loc) · 120 KB
/
Copy pathCPTAxis.m
File metadata and controls
3297 lines (2795 loc) · 120 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
247
248
249
250
251
252
253
254
255
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#import "CPTAxis.h"
#import "CPTAxisLabelGroup.h"
#import "CPTAxisSet.h"
#import "CPTAxisTitle.h"
#import "CPTColor.h"
#import "CPTExceptions.h"
#import "CPTGradient.h"
#import "CPTGridLineGroup.h"
#import "CPTGridLines.h"
#import "CPTImage.h"
#import "CPTLineCap.h"
#import "CPTLineStyle.h"
#import "CPTMutablePlotRange.h"
#import "CPTPlotArea.h"
#import "CPTPlotSpace.h"
#import "CPTShadow.h"
#import "CPTTextLayer.h"
#import "CPTUtilities.h"
#import "NSCoderExtensions.h"
/** @defgroup axisAnimation Axes
* @brief Axis properties that can be animated using Core Animation.
* @if MacOnly
* @since Custom layer property animation is supported on macOS 10.6 and later.
* @endif
* @ingroup animation
**/
/// @cond
@interface CPTAxis()
@property (nonatomic, readwrite, assign) BOOL needsRelabel;
@property (nonatomic, readwrite, cpt_weak_property, nullable) CPTGridLines *minorGridLines;
@property (nonatomic, readwrite, cpt_weak_property, nullable) CPTGridLines *majorGridLines;
@property (nonatomic, readwrite, cpt_weak_property, nullable) CPTAxisLabel *pointingDeviceDownLabel;
@property (nonatomic, readwrite, cpt_weak_property, nullable) CPTAxisLabel *pointingDeviceDownTickLabel;
@property (nonatomic, readwrite, assign) BOOL labelFormatterChanged;
@property (nonatomic, readwrite, assign) BOOL minorLabelFormatterChanged;
@property (nonatomic, readwrite, strong, nullable) CPTMutableLimitBandArray *mutableBackgroundLimitBands;
@property (nonatomic, readonly) CGFloat tickOffset;
@property (nonatomic, readwrite, assign) BOOL inTitleUpdate;
@property (nonatomic, readwrite, assign) BOOL labelsUpdated;
-(void)generateFixedIntervalMajorTickLocations:(CPTNumberSet *__nonnull __autoreleasing *)newMajorLocations minorTickLocations:(CPTNumberSet *__nonnull __autoreleasing *)newMinorLocations;
-(void)autoGenerateMajorTickLocations:(CPTNumberSet *__nonnull __autoreleasing *)newMajorLocations minorTickLocations:(CPTNumberSet *__nonnull __autoreleasing *)newMinorLocations;
-(void)generateEqualMajorTickLocations:(CPTNumberSet *__nonnull __autoreleasing *)newMajorLocations minorTickLocations:(CPTNumberSet *__nonnull __autoreleasing *)newMinorLocations;
-(nullable CPTNumberSet *)filteredTickLocations:(nullable CPTNumberSet *)allLocations;
-(void)updateAxisLabelsAtLocations:(nullable CPTNumberSet *)locations inRange:(nullable CPTPlotRange *)labeledRange useMajorAxisLabels:(BOOL)useMajorAxisLabels;
-(void)updateCustomTickLabels;
-(void)updateMajorTickLabelOffsets;
-(void)updateMinorTickLabelOffsets;
NSDecimal CPTNiceNum(NSDecimal x);
NSDecimal CPTNiceLength(NSDecimal length);
@end
/// @endcond
#pragma mark -
/**
* @brief An abstract axis class.
*
* The figure below illustrates the relationship between the three plot range properties. If all are
* @nil, the axis and grid lines will extend the full width of the plot area.
* @image html "axis ranges.png" "Axis Ranges"
* @see See @ref axisAnimation "Axes" for a list of animatable properties.
**/
@implementation CPTAxis
// Axis
/** @property nullable CPTLineStyle *axisLineStyle
* @brief The line style for the axis line.
* If @nil, the line is not drawn.
**/
@synthesize axisLineStyle;
/** @property CPTCoordinate coordinate
* @brief The axis coordinate.
**/
@synthesize coordinate;
/** @property nonnull NSNumber *labelingOrigin
* @brief The origin used for axis labels.
* The default value is @num{0}. It is only used when the axis labeling
* policy is #CPTAxisLabelingPolicyFixedInterval. The origin is
* a reference point used to being labeling. Labels are added
* at the origin, as well as at fixed intervals above and below
* the origin.
**/
@synthesize labelingOrigin;
/** @property CPTSign tickDirection
* @brief The tick direction.
* The direction is given as the sign that ticks extend along
* the axis (e.g., positive or negative).
**/
@synthesize tickDirection;
/** @property nullable CPTPlotRange *visibleRange
* @brief The plot range over which the axis and ticks are visible.
* Use this to restrict an axis and its grid lines to less than the full plot area width.
* Use the @ref visibleAxisRange to specify a separate range for the axis line, if needed.
* Set to @nil for no restriction.
**/
@synthesize visibleRange;
/** @property nullable CPTPlotRange *visibleAxisRange;
* @brief The plot range over which the axis itself is visible.
* Use this to restrict an axis line to less than the full plot area width. This range is independent
* of the @ref visibleRange and overrides it for the axis line and line cap.
* Set to @nil to use the @ref visibleRange instead.
**/
@synthesize visibleAxisRange;
/** @property nullable CPTLineCap *axisLineCapMin
* @brief The line cap for the end of the axis line with the minimum value.
* @see axisLineCapMax
**/
@synthesize axisLineCapMin;
/** @property nullable CPTLineCap *axisLineCapMax
* @brief The line cap for the end of the axis line with the maximum value.
* @see axisLineCapMin
**/
@synthesize axisLineCapMax;
// Title
/** @property nullable CPTTextStyle *titleTextStyle
* @brief The text style used to draw the axis title text.
*
* Assigning a new value to this property also sets the value of the @ref attributedTitle property to @nil.
**/
@synthesize titleTextStyle;
/** @property nullable CPTAxisTitle *axisTitle
* @brief The axis title.
* If @nil, no title is drawn.
**/
@synthesize axisTitle;
/** @property CGFloat titleOffset
* @brief The offset distance between the axis title and the axis line.
* @ingroup axisAnimation
**/
@synthesize titleOffset;
/** @property nullable NSString *title
* @brief A convenience property for setting the text title of the axis.
*
* Assigning a new value to this property also sets the value of the @ref attributedTitle property to @nil.
**/
@synthesize title;
/** @property nullable NSAttributedString *attributedTitle
* @brief A convenience property for setting the styled text title of the axis.
*
* Assigning a new value to this property also sets the value of the @ref title property to the
* same string without formatting information. It also replaces the @ref titleTextStyle with
* a style matching the first position (location @num{0}) of the styled title.
* Default is @nil.
**/
@synthesize attributedTitle;
/** @property CGFloat titleRotation
* @brief The rotation angle of the axis title in radians.
* If @NAN (the default), the title will be parallel to the axis.
* @ingroup axisAnimation
**/
@synthesize titleRotation;
/** @property CPTSign titleDirection
* @brief The offset direction for the axis title.
* The direction is given as the sign that ticks extend along
* the axis (e.g., positive or negative). If the title direction
* is #CPTSignNone (the default), the title is offset in the
* direction indicated by the @ref tickDirection.
**/
@synthesize titleDirection;
/** @property nullable NSNumber *titleLocation
* @brief The position along the axis where the axis title should be centered.
* If @NAN (the default), the @ref defaultTitleLocation will be used.
**/
@synthesize titleLocation;
/** @property nonnull NSNumber *defaultTitleLocation
* @brief The position along the axis where the axis title should be centered
* if @ref titleLocation is @NAN.
**/
@dynamic defaultTitleLocation;
// Plot space
/** @property nullable CPTPlotSpace *plotSpace
* @brief The plot space for the axis.
**/
@synthesize plotSpace;
// Labels
/** @property CPTAxisLabelingPolicy labelingPolicy
* @brief The axis labeling policy.
**/
@synthesize labelingPolicy;
/** @property CGFloat labelOffset
* @brief The offset distance between the tick marks and labels.
* @ingroup axisAnimation
**/
@synthesize labelOffset;
/** @property CGFloat minorTickLabelOffset
* @brief The offset distance between the minor tick marks and labels.
* @ingroup axisAnimation
**/
@synthesize minorTickLabelOffset;
/** @property CGFloat labelRotation
* @brief The rotation of the axis labels in radians.
* Set this property to @num{π/2} to have labels read up the screen, for example.
* @ingroup axisAnimation
**/
@synthesize labelRotation;
/** @property CGFloat minorTickLabelRotation
* @brief The rotation of the axis minor tick labels in radians.
* Set this property to @num{π/2} to have labels read up the screen, for example.
* @ingroup axisAnimation
**/
@synthesize minorTickLabelRotation;
/** @property CPTAlignment labelAlignment
* @brief The alignment of the axis label with respect to the tick mark.
**/
@synthesize labelAlignment;
/** @property CPTAlignment minorTickLabelAlignment
* @brief The alignment of the axis label with respect to the tick mark.
**/
@synthesize minorTickLabelAlignment;
/** @property nullable CPTTextStyle *labelTextStyle
* @brief The text style used to draw the label text.
**/
@synthesize labelTextStyle;
/** @property nullable CPTTextStyle *minorTickLabelTextStyle
* @brief The text style used to draw the label text of minor tick labels.
**/
@synthesize minorTickLabelTextStyle;
/** @property CPTSign tickLabelDirection
* @brief The offset direction for major tick labels.
* The direction is given as the sign that ticks extend along
* the axis (e.g., positive or negative). If the label direction
* is #CPTSignNone (the default), the labels are offset in the
* direction indicated by the @ref tickDirection.
**/
@synthesize tickLabelDirection;
/** @property CPTSign minorTickLabelDirection
* @brief The offset direction for minor tick labels.
* The direction is given as the sign that ticks extend along
* the axis (e.g., positive or negative). If the label direction
* is #CPTSignNone (the default), the labels are offset in the
* direction indicated by the @ref tickDirection.
**/
@synthesize minorTickLabelDirection;
/** @property nullable NSFormatter *labelFormatter
* @brief The number formatter used to format the label text.
* If you need a non-numerical label, such as a date, you can use a formatter than turns
* the numerical plot coordinate into a string (e.g., @quote{Jan 10, 2010}).
* The CPTCalendarFormatter and CPTTimeFormatter classes are useful for this purpose.
**/
@synthesize labelFormatter;
/** @property nullable NSFormatter *minorTickLabelFormatter
* @brief The number formatter used to format the label text of minor ticks.
* If you need a non-numerical label, such as a date, you can use a formatter than turns
* the numerical plot coordinate into a string (e.g., @quote{Jan 10, 2010}).
* The CPTCalendarFormatter and CPTTimeFormatter classes are useful for this purpose.
**/
@synthesize minorTickLabelFormatter;
@synthesize labelFormatterChanged;
@synthesize minorLabelFormatterChanged;
@dynamic tickOffset;
/** @property nullable CPTAxisLabelSet *axisLabels
* @brief The set of axis labels.
**/
@synthesize axisLabels;
/** @property nullable CPTAxisLabelSet *minorTickAxisLabels
* @brief The set of minor tick axis labels.
**/
@synthesize minorTickAxisLabels;
/** @property BOOL needsRelabel
* @brief If @YES, the axis needs to be relabeled before the layer content is drawn.
**/
@synthesize needsRelabel;
/** @property nullable CPTPlotRangeArray *labelExclusionRanges
* @brief An array of CPTPlotRange objects. Any tick marks and labels falling inside any of the ranges in the array will not be drawn.
**/
@synthesize labelExclusionRanges;
/** @property nullable CPTShadow *labelShadow
* @brief The shadow applied to each axis label.
**/
@synthesize labelShadow;
/** @property nullable CPTShadow *minorTickLabelShadow
* @brief The shadow applied to each minor tick axis label.
**/
@synthesize minorTickLabelShadow;
// Major ticks
/** @property nullable NSNumber *majorIntervalLength
* @brief The distance between major tick marks expressed in data coordinates.
**/
@synthesize majorIntervalLength;
/** @property nullable CPTLineStyle *majorTickLineStyle
* @brief The line style for the major tick marks.
* If @nil, the major ticks are not drawn.
**/
@synthesize majorTickLineStyle;
/** @property CGFloat majorTickLength
* @brief The length of the major tick marks.
**/
@synthesize majorTickLength;
/** @property nullable CPTNumberSet *majorTickLocations
* @brief A set of axis coordinates for all major tick marks.
**/
@synthesize majorTickLocations;
/** @property NSUInteger preferredNumberOfMajorTicks
* @brief The number of ticks that should be targeted when auto-generating positions.
* This property only applies when the #CPTAxisLabelingPolicyAutomatic or
* #CPTAxisLabelingPolicyEqualDivisions policies are in use.
* If zero (@num{0}) (the default), Core Plot will choose a reasonable number of ticks.
**/
@synthesize preferredNumberOfMajorTicks;
// Minor ticks
/** @property NSUInteger minorTicksPerInterval
* @brief The number of minor tick marks drawn in each major tick interval.
**/
@synthesize minorTicksPerInterval;
/** @property nullable CPTLineStyle *minorTickLineStyle
* @brief The line style for the minor tick marks.
* If @nil, the minor ticks are not drawn.
**/
@synthesize minorTickLineStyle;
/** @property CGFloat minorTickLength
* @brief The length of the minor tick marks.
**/
@synthesize minorTickLength;
/** @property nullable CPTNumberSet *minorTickLocations
* @brief A set of axis coordinates for all minor tick marks.
**/
@synthesize minorTickLocations;
// Grid Lines
/** @property nullable CPTLineStyle *majorGridLineStyle
* @brief The line style for the major grid lines.
* If @nil, the major grid lines are not drawn.
**/
@synthesize majorGridLineStyle;
/** @property nullable CPTLineStyle *minorGridLineStyle
* @brief The line style for the minor grid lines.
* If @nil, the minor grid lines are not drawn.
**/
@synthesize minorGridLineStyle;
/** @property nullable CPTPlotRange *CPTPlotRange *gridLinesRange
* @brief The plot range over which the grid lines are visible.
* Note that this range applies to the orthogonal coordinate, not
* the axis coordinate itself.
* Set to @nil for no restriction.
**/
@synthesize gridLinesRange;
// Background Bands
/** @property nullable CPTFillArray *alternatingBandFills
* @brief An array of two or more fills to be drawn between successive major tick marks.
*
* When initializing the fills, provide an NSArray containing any combination of CPTFill,
* CPTColor, CPTGradient, and/or CPTImage objects. Blank (transparent) bands can be created
* by using an NSNull object in place of some of the CPTFill objects.
**/
@synthesize alternatingBandFills;
/** @property nullable NSNumber *alternatingBandAnchor
* @brief The starting location of the first band fill.
*
* If @nil (the default), the first fill is drawn between the bottom left corner of the plot area
* and the first major tick location inside the plot area. If the anchor falls between two
* major tick locations, the first band fill wiil be drawn between those locations.
**/
@synthesize alternatingBandAnchor;
/** @property nullable CPTLimitBandArray *backgroundLimitBands
* @brief An array of CPTLimitBand objects.
*
* The limit bands are drawn on top of the alternating band fills.
**/
@dynamic backgroundLimitBands;
@synthesize mutableBackgroundLimitBands;
// Layers
/** @property BOOL separateLayers
* @brief Use separate layers for drawing grid lines?
*
* If @NO, the default, the major and minor grid lines are drawn in layers shared with other axes.
* If @YES, the grid lines are drawn in their own layers.
**/
@synthesize separateLayers;
/** @property nullable CPTPlotArea *plotArea
* @brief The plot area that the axis belongs to.
**/
@synthesize plotArea;
/** @property nullable CPTGridLines *minorGridLines
* @brief The layer that draws the minor grid lines.
**/
@synthesize minorGridLines;
/** @property nullable CPTGridLines *majorGridLines
* @brief The layer that draws the major grid lines.
**/
@synthesize majorGridLines;
/** @property nullable CPTAxisSet *axisSet
* @brief The axis set that the axis belongs to.
**/
@dynamic axisSet;
/** @internal
* @property nullable CPTAxisLabel *pointingDeviceDownLabel
* @brief The label that was selected on the pointing device down event.
**/
@synthesize pointingDeviceDownLabel;
/** @internal
* @property nullable CPTAxisLabel *pointingDeviceDownTickLabel
* @brief The tick label that was selected on the pointing device down event.
**/
@synthesize pointingDeviceDownTickLabel;
@synthesize inTitleUpdate;
@synthesize labelsUpdated;
#pragma mark -
#pragma mark Init/Dealloc
/// @name Initialization
/// @{
/** @brief Initializes a newly allocated CPTAxis object with the provided frame rectangle.
*
* This is the designated initializer. The initialized layer will have the following properties:
* - @ref plotSpace = @nil
* - @ref majorTickLocations = empty set
* - @ref minorTickLocations = empty set
* - @ref preferredNumberOfMajorTicks = @num{0}
* - @ref minorTickLength = @num{3.0}
* - @ref majorTickLength = @num{5.0}
* - @ref labelOffset = @num{2.0}
* - @ref minorTickLabelOffset = @num{2.0}
* - @ref labelRotation= @num{0.0}
* - @ref minorTickLabelRotation= @num{0.0}
* - @ref labelAlignment = #CPTAlignmentCenter
* - @ref minorTickLabelAlignment = #CPTAlignmentCenter
* - @ref title = @nil
* - @ref attributedTitle = @nil
* - @ref titleOffset = @num{30.0}
* - @ref axisLineStyle = default line style
* - @ref majorTickLineStyle = default line style
* - @ref minorTickLineStyle = default line style
* - @ref tickLabelDirection = #CPTSignNone
* - @ref minorTickLabelDirection = #CPTSignNone
* - @ref majorGridLineStyle = @nil
* - @ref minorGridLineStyle= @nil
* - @ref axisLineCapMin = @nil
* - @ref axisLineCapMax = @nil
* - @ref labelingOrigin = @num{0}
* - @ref majorIntervalLength = @num{1}
* - @ref minorTicksPerInterval = @num{1}
* - @ref coordinate = #CPTCoordinateX
* - @ref labelingPolicy = #CPTAxisLabelingPolicyFixedInterval
* - @ref labelTextStyle = default text style
* - @ref labelFormatter = number formatter that displays one fraction digit and at least one integer digit
* - @ref minorTickLabelTextStyle = default text style
* - @ref minorTickLabelFormatter = @nil
* - @ref axisLabels = empty set
* - @ref minorTickAxisLabels = empty set
* - @ref tickDirection = #CPTSignNone
* - @ref axisTitle = @nil
* - @ref titleTextStyle = default text style
* - @ref titleRotation = @NAN
* - @ref titleDirection = #CPTSignNone
* - @ref titleLocation = @NAN
* - @ref needsRelabel = @YES
* - @ref labelExclusionRanges = @nil
* - @ref plotArea = @nil
* - @ref separateLayers = @NO
* - @ref labelShadow = @nil
* - @ref minorTickLabelShadow = @nil
* - @ref alternatingBandFills = @nil
* - @ref alternatingBandAnchor = @nil
* - @ref minorGridLines = @nil
* - @ref majorGridLines = @nil
* - @ref needsDisplayOnBoundsChange = @YES
*
* @param newFrame The frame rectangle.
* @return The initialized CPTAxis object.
**/
-(nonnull instancetype)initWithFrame:(CGRect)newFrame
{
if ((self = [super initWithFrame:newFrame])) {
plotSpace = nil;
majorTickLocations = [NSSet set];
minorTickLocations = [NSSet set];
preferredNumberOfMajorTicks = 0;
minorTickLength = CPTFloat(3.0);
majorTickLength = CPTFloat(5.0);
labelOffset = CPTFloat(2.0);
minorTickLabelOffset = CPTFloat(2.0);
labelRotation = CPTFloat(0.0);
minorTickLabelRotation = CPTFloat(0.0);
labelAlignment = CPTAlignmentCenter;
minorTickLabelAlignment = CPTAlignmentCenter;
title = nil;
attributedTitle = nil;
titleOffset = CPTFloat(30.0);
axisLineStyle = [[CPTLineStyle alloc] init];
majorTickLineStyle = [[CPTLineStyle alloc] init];
minorTickLineStyle = [[CPTLineStyle alloc] init];
tickLabelDirection = CPTSignNone;
minorTickLabelDirection = CPTSignNone;
majorGridLineStyle = nil;
minorGridLineStyle = nil;
axisLineCapMin = nil;
axisLineCapMax = nil;
labelingOrigin = @0.0;
majorIntervalLength = @1.0;
minorTicksPerInterval = 1;
coordinate = CPTCoordinateX;
labelingPolicy = CPTAxisLabelingPolicyFixedInterval;
labelTextStyle = [[CPTTextStyle alloc] init];
NSNumberFormatter *newFormatter = [[NSNumberFormatter alloc] init];
newFormatter.minimumIntegerDigits = 1;
newFormatter.maximumFractionDigits = 1;
newFormatter.minimumFractionDigits = 1;
labelFormatter = newFormatter;
minorTickLabelTextStyle = [[CPTTextStyle alloc] init];
minorTickLabelFormatter = nil;
labelFormatterChanged = YES;
minorLabelFormatterChanged = NO;
axisLabels = [NSSet set];
minorTickAxisLabels = [NSSet set];
tickDirection = CPTSignNone;
axisTitle = nil;
titleTextStyle = [[CPTTextStyle alloc] init];
titleRotation = CPTNAN;
titleLocation = @(NAN);
needsRelabel = YES;
labelExclusionRanges = nil;
plotArea = nil;
separateLayers = NO;
labelShadow = nil;
minorTickLabelShadow = nil;
visibleRange = nil;
visibleAxisRange = nil;
gridLinesRange = nil;
alternatingBandFills = nil;
alternatingBandAnchor = nil;
mutableBackgroundLimitBands = nil;
minorGridLines = nil;
majorGridLines = nil;
pointingDeviceDownLabel = nil;
pointingDeviceDownTickLabel = nil;
inTitleUpdate = NO;
labelsUpdated = NO;
self.needsDisplayOnBoundsChange = YES;
}
return self;
}
/// @}
/// @cond
-(nonnull instancetype)initWithLayer:(nonnull id)layer
{
if ((self = [super initWithLayer:layer])) {
CPTAxis *theLayer = (CPTAxis *)layer;
plotSpace = theLayer->plotSpace;
majorTickLocations = theLayer->majorTickLocations;
minorTickLocations = theLayer->minorTickLocations;
preferredNumberOfMajorTicks = theLayer->preferredNumberOfMajorTicks;
minorTickLength = theLayer->minorTickLength;
majorTickLength = theLayer->majorTickLength;
labelOffset = theLayer->labelOffset;
minorTickLabelOffset = theLayer->labelOffset;
labelRotation = theLayer->labelRotation;
minorTickLabelRotation = theLayer->labelRotation;
labelAlignment = theLayer->labelAlignment;
minorTickLabelAlignment = theLayer->labelAlignment;
title = theLayer->title;
attributedTitle = theLayer->attributedTitle;
titleOffset = theLayer->titleOffset;
axisLineStyle = theLayer->axisLineStyle;
majorTickLineStyle = theLayer->majorTickLineStyle;
minorTickLineStyle = theLayer->minorTickLineStyle;
tickLabelDirection = theLayer->tickLabelDirection;
minorTickLabelDirection = theLayer->minorTickLabelDirection;
majorGridLineStyle = theLayer->majorGridLineStyle;
minorGridLineStyle = theLayer->minorGridLineStyle;
axisLineCapMin = theLayer->axisLineCapMin;
axisLineCapMax = theLayer->axisLineCapMax;
labelingOrigin = theLayer->labelingOrigin;
majorIntervalLength = theLayer->majorIntervalLength;
minorTicksPerInterval = theLayer->minorTicksPerInterval;
coordinate = theLayer->coordinate;
labelingPolicy = theLayer->labelingPolicy;
labelFormatter = theLayer->labelFormatter;
minorTickLabelFormatter = theLayer->minorTickLabelFormatter;
axisLabels = theLayer->axisLabels;
minorTickAxisLabels = theLayer->minorTickAxisLabels;
tickDirection = theLayer->tickDirection;
labelTextStyle = theLayer->labelTextStyle;
minorTickLabelTextStyle = theLayer->minorTickLabelTextStyle;
axisTitle = theLayer->axisTitle;
titleTextStyle = theLayer->titleTextStyle;
titleRotation = theLayer->titleRotation;
titleDirection = theLayer->titleDirection;
titleLocation = theLayer->titleLocation;
needsRelabel = theLayer->needsRelabel;
labelExclusionRanges = theLayer->labelExclusionRanges;
plotArea = theLayer->plotArea;
separateLayers = theLayer->separateLayers;
labelShadow = theLayer->labelShadow;
minorTickLabelShadow = theLayer->minorTickLabelShadow;
visibleRange = theLayer->visibleRange;
visibleAxisRange = theLayer->visibleAxisRange;
gridLinesRange = theLayer->gridLinesRange;
alternatingBandFills = theLayer->alternatingBandFills;
alternatingBandAnchor = theLayer->alternatingBandAnchor;
mutableBackgroundLimitBands = theLayer->mutableBackgroundLimitBands;
minorGridLines = theLayer->minorGridLines;
majorGridLines = theLayer->majorGridLines;
pointingDeviceDownLabel = theLayer->pointingDeviceDownLabel;
pointingDeviceDownTickLabel = theLayer->pointingDeviceDownTickLabel;
inTitleUpdate = theLayer->inTitleUpdate;
labelsUpdated = theLayer->labelsUpdated;
}
return self;
}
-(void)dealloc
{
plotArea = nil;
minorGridLines = nil;
majorGridLines = nil;
for ( CPTAxisLabel *label in axisLabels ) {
[label.contentLayer removeFromSuperlayer];
}
[axisTitle.contentLayer removeFromSuperlayer];
}
/// @endcond
#pragma mark -
#pragma mark NSCoding Methods
/// @cond
-(void)encodeWithCoder:(nonnull NSCoder *)coder
{
[super encodeWithCoder:coder];
[coder encodeInteger:self.coordinate forKey:@"CPTAxis.coordinate"];
[coder encodeObject:self.plotSpace forKey:@"CPTAxis.plotSpace"];
[coder encodeObject:self.majorTickLocations forKey:@"CPTAxis.majorTickLocations"];
[coder encodeObject:self.minorTickLocations forKey:@"CPTAxis.minorTickLocations"];
[coder encodeCGFloat:self.majorTickLength forKey:@"CPTAxis.majorTickLength"];
[coder encodeCGFloat:self.minorTickLength forKey:@"CPTAxis.minorTickLength"];
[coder encodeCGFloat:self.labelOffset forKey:@"CPTAxis.labelOffset"];
[coder encodeCGFloat:self.minorTickLabelOffset forKey:@"CPTAxis.minorTickLabelOffset"];
[coder encodeCGFloat:self.labelRotation forKey:@"CPTAxis.labelRotation"];
[coder encodeCGFloat:self.minorTickLabelRotation forKey:@"CPTAxis.minorTickLabelRotation"];
[coder encodeInteger:self.labelAlignment forKey:@"CPTAxis.labelAlignment"];
[coder encodeInteger:self.minorTickLabelAlignment forKey:@"CPTAxis.minorTickLabelAlignment"];
[coder encodeObject:self.axisLineStyle forKey:@"CPTAxis.axisLineStyle"];
[coder encodeObject:self.majorTickLineStyle forKey:@"CPTAxis.majorTickLineStyle"];
[coder encodeObject:self.minorTickLineStyle forKey:@"CPTAxis.minorTickLineStyle"];
[coder encodeInteger:self.tickLabelDirection forKey:@"CPTAxis.tickLabelDirection"];
[coder encodeInteger:self.minorTickLabelDirection forKey:@"CPTAxis.minorTickLabelDirection"];
[coder encodeObject:self.majorGridLineStyle forKey:@"CPTAxis.majorGridLineStyle"];
[coder encodeObject:self.minorGridLineStyle forKey:@"CPTAxis.minorGridLineStyle"];
[coder encodeObject:self.axisLineCapMin forKey:@"CPTAxis.axisLineCapMin"];
[coder encodeObject:self.axisLineCapMax forKey:@"CPTAxis.axisLineCapMax"];
[coder encodeObject:self.labelingOrigin forKey:@"CPTAxis.labelingOrigin"];
[coder encodeObject:self.majorIntervalLength forKey:@"CPTAxis.majorIntervalLength"];
[coder encodeInteger:(NSInteger)self.minorTicksPerInterval forKey:@"CPTAxis.minorTicksPerInterval"];
[coder encodeInteger:(NSInteger)self.preferredNumberOfMajorTicks forKey:@"CPTAxis.preferredNumberOfMajorTicks"];
[coder encodeInteger:self.labelingPolicy forKey:@"CPTAxis.labelingPolicy"];
[coder encodeObject:self.labelTextStyle forKey:@"CPTAxis.labelTextStyle"];
[coder encodeObject:self.minorTickLabelTextStyle forKey:@"CPTAxis.minorTickLabelTextStyle"];
[coder encodeObject:self.titleTextStyle forKey:@"CPTAxis.titleTextStyle"];
[coder encodeObject:self.labelFormatter forKey:@"CPTAxis.labelFormatter"];
[coder encodeObject:self.minorTickLabelFormatter forKey:@"CPTAxis.minorTickLabelFormatter"];
[coder encodeBool:self.labelFormatterChanged forKey:@"CPTAxis.labelFormatterChanged"];
[coder encodeBool:self.minorLabelFormatterChanged forKey:@"CPTAxis.minorLabelFormatterChanged"];
[coder encodeObject:self.axisLabels forKey:@"CPTAxis.axisLabels"];
[coder encodeObject:self.minorTickAxisLabels forKey:@"CPTAxis.minorTickAxisLabels"];
[coder encodeObject:self.axisTitle forKey:@"CPTAxis.axisTitle"];
[coder encodeObject:self.title forKey:@"CPTAxis.title"];
[coder encodeObject:self.attributedTitle forKey:@"CPTAxis.attributedTitle"];
[coder encodeCGFloat:self.titleOffset forKey:@"CPTAxis.titleOffset"];
[coder encodeCGFloat:self.titleRotation forKey:@"CPTAxis.titleRotation"];
[coder encodeInteger:self.titleDirection forKey:@"CPTAxis.titleDirection"];
[coder encodeObject:self.titleLocation forKey:@"CPTAxis.titleLocation"];
[coder encodeInteger:self.tickDirection forKey:@"CPTAxis.tickDirection"];
[coder encodeBool:self.needsRelabel forKey:@"CPTAxis.needsRelabel"];
[coder encodeObject:self.labelExclusionRanges forKey:@"CPTAxis.labelExclusionRanges"];
[coder encodeObject:self.visibleRange forKey:@"CPTAxis.visibleRange"];
[coder encodeObject:self.visibleAxisRange forKey:@"CPTAxis.visibleAxisRange"];
[coder encodeObject:self.gridLinesRange forKey:@"CPTAxis.gridLinesRange"];
[coder encodeObject:self.alternatingBandFills forKey:@"CPTAxis.alternatingBandFills"];
[coder encodeObject:self.alternatingBandAnchor forKey:@"CPTAxis.alternatingBandAnchor"];
[coder encodeObject:self.mutableBackgroundLimitBands forKey:@"CPTAxis.mutableBackgroundLimitBands"];
[coder encodeBool:self.separateLayers forKey:@"CPTAxis.separateLayers"];
[coder encodeObject:self.labelShadow forKey:@"CPTAxis.labelShadow"];
[coder encodeObject:self.minorTickLabelShadow forKey:@"CPTAxis.minorTickLabelShadow"];
[coder encodeConditionalObject:self.plotArea forKey:@"CPTAxis.plotArea"];
[coder encodeConditionalObject:self.minorGridLines forKey:@"CPTAxis.minorGridLines"];
[coder encodeConditionalObject:self.majorGridLines forKey:@"CPTAxis.majorGridLines"];
// No need to archive these properties:
// pointingDeviceDownLabel
// pointingDeviceDownTickLabel
// inTitleUpdate
// labelsUpdated
}
-(nullable instancetype)initWithCoder:(nonnull NSCoder *)coder
{
if ((self = [super initWithCoder:coder])) {
coordinate = (CPTCoordinate)[coder decodeIntegerForKey:@"CPTAxis.coordinate"];
plotSpace = [coder decodeObjectOfClass:[CPTPlotSpace class]
forKey:@"CPTAxis.plotSpace"];
majorTickLocations = [coder decodeObjectOfClasses:[NSSet setWithArray:@[[NSSet class], [NSNumber class]]]
forKey:@"CPTAxis.majorTickLocations"];
minorTickLocations = [coder decodeObjectOfClasses:[NSSet setWithArray:@[[NSSet class], [NSNumber class]]]
forKey:@"CPTAxis.minorTickLocations"];
majorTickLength = [coder decodeCGFloatForKey:@"CPTAxis.majorTickLength"];
minorTickLength = [coder decodeCGFloatForKey:@"CPTAxis.minorTickLength"];
labelOffset = [coder decodeCGFloatForKey:@"CPTAxis.labelOffset"];
minorTickLabelOffset = [coder decodeCGFloatForKey:@"CPTAxis.minorTickLabelOffset"];
labelRotation = [coder decodeCGFloatForKey:@"CPTAxis.labelRotation"];
minorTickLabelRotation = [coder decodeCGFloatForKey:@"CPTAxis.minorTickLabelRotation"];
labelAlignment = (CPTAlignment)[coder decodeIntegerForKey:@"CPTAxis.labelAlignment"];
minorTickLabelAlignment = (CPTAlignment)[coder decodeIntegerForKey:@"CPTAxis.minorTickLabelAlignment"];
axisLineStyle = [[coder decodeObjectOfClass:[CPTLineStyle class]
forKey:@"CPTAxis.axisLineStyle"] copy];
majorTickLineStyle = [[coder decodeObjectOfClass:[CPTLineStyle class]
forKey:@"CPTAxis.majorTickLineStyle"] copy];
minorTickLineStyle = [[coder decodeObjectOfClass:[CPTLineStyle class]
forKey:@"CPTAxis.minorTickLineStyle"] copy];
tickLabelDirection = (CPTSign)[coder decodeIntegerForKey:@"CPTAxis.tickLabelDirection"];
minorTickLabelDirection = (CPTSign)[coder decodeIntegerForKey:@"CPTAxis.minorTickLabelDirection"];
majorGridLineStyle = [[coder decodeObjectOfClass:[CPTLineStyle class]
forKey:@"CPTAxis.majorGridLineStyle"] copy];
minorGridLineStyle = [[coder decodeObjectOfClass:[CPTLineStyle class]
forKey:@"CPTAxis.minorGridLineStyle"] copy];
axisLineCapMin = [[coder decodeObjectOfClass:[CPTLineCap class]
forKey:@"CPTAxis.axisLineCapMin"] copy];
axisLineCapMax = [[coder decodeObjectOfClass:[CPTLineCap class]
forKey:@"CPTAxis.axisLineCapMax"] copy];
NSNumber *origin = [coder decodeObjectOfClass:[NSNumber class]
forKey:@"CPTAxis.labelingOrigin"];
labelingOrigin = origin ? origin : @0.0;
majorIntervalLength = [coder decodeObjectOfClass:[NSNumber class]
forKey:@"CPTAxis.majorIntervalLength"];
minorTicksPerInterval = (NSUInteger)[coder decodeIntegerForKey:@"CPTAxis.minorTicksPerInterval"];
preferredNumberOfMajorTicks = (NSUInteger)[coder decodeIntegerForKey:@"CPTAxis.preferredNumberOfMajorTicks"];
labelingPolicy = (CPTAxisLabelingPolicy)[coder decodeIntegerForKey:@"CPTAxis.labelingPolicy"];
labelTextStyle = [[coder decodeObjectOfClass:[CPTTextStyle class]
forKey:@"CPTAxis.labelTextStyle"] copy];
minorTickLabelTextStyle = [[coder decodeObjectOfClass:[CPTTextStyle class]
forKey:@"CPTAxis.minorTickLabelTextStyle"] copy];
titleTextStyle = [[coder decodeObjectOfClass:[CPTTextStyle class]
forKey:@"CPTAxis.titleTextStyle"] copy];
labelFormatter = [coder decodeObjectOfClass:[NSFormatter class]
forKey:@"CPTAxis.labelFormatter"];
minorTickLabelFormatter = [coder decodeObjectOfClass:[NSFormatter class]
forKey:@"CPTAxis.minorTickLabelFormatter"];
labelFormatterChanged = [coder decodeBoolForKey:@"CPTAxis.labelFormatterChanged"];
minorLabelFormatterChanged = [coder decodeBoolForKey:@"CPTAxis.minorLabelFormatterChanged"];
axisLabels = [coder decodeObjectOfClasses:[NSSet setWithArray:@[[NSSet class], [CPTAxisLabel class]]]
forKey:@"CPTAxis.axisLabels"];
minorTickAxisLabels = [coder decodeObjectOfClasses:[NSSet setWithArray:@[[NSSet class], [CPTAxisLabel class]]]
forKey:@"CPTAxis.minorTickAxisLabels"];
axisTitle = [coder decodeObjectOfClass:[NSString class]
forKey:@"CPTAxis.axisTitle"];
title = [[coder decodeObjectOfClass:[NSString class]
forKey:@"CPTAxis.title"] copy];
attributedTitle = [[coder decodeObjectOfClass:[NSAttributedString class]
forKey:@"CPTAxis.attributedTitle"] copy];
titleOffset = [coder decodeCGFloatForKey:@"CPTAxis.titleOffset"];
titleRotation = [coder decodeCGFloatForKey:@"CPTAxis.titleRotation"];
titleDirection = (CPTSign)[coder decodeIntegerForKey:@"CPTAxis.titleDirection"];
titleLocation = [coder decodeObjectOfClass:[NSNumber class]
forKey:@"CPTAxis.titleLocation"];
tickDirection = (CPTSign)[coder decodeIntegerForKey:@"CPTAxis.tickDirection"];
needsRelabel = [coder decodeBoolForKey:@"CPTAxis.needsRelabel"];
labelExclusionRanges = [coder decodeObjectOfClasses:[NSSet setWithArray:@[[NSArray class], [CPTPlotRange class]]]
forKey:@"CPTAxis.labelExclusionRanges"];
visibleRange = [[coder decodeObjectOfClass:[CPTPlotRange class]
forKey:@"CPTAxis.visibleRange"] copy];
visibleAxisRange = [[coder decodeObjectOfClass:[CPTPlotRange class]
forKey:@"CPTAxis.visibleAxisRange"] copy];
gridLinesRange = [[coder decodeObjectOfClass:[CPTPlotRange class]
forKey:@"CPTAxis.gridLinesRange"] copy];
alternatingBandFills = [[coder decodeObjectOfClasses:[NSSet setWithArray:@[[NSArray class], [CPTFill class]]]
forKey:@"CPTAxis.alternatingBandFills"] copy];
alternatingBandAnchor = [coder decodeObjectOfClass:[NSNumber class]
forKey:@"CPTAxis.alternatingBandAnchor"];
mutableBackgroundLimitBands = [[coder decodeObjectOfClasses:[NSSet setWithArray:@[[NSArray class], [CPTLimitBand class]]]
forKey:@"CPTAxis.mutableBackgroundLimitBands"] mutableCopy];
separateLayers = [coder decodeBoolForKey:@"CPTAxis.separateLayers"];
labelShadow = [coder decodeObjectOfClass:[CPTShadow class]
forKey:@"CPTAxis.labelShadow"];
minorTickLabelShadow = [coder decodeObjectOfClass:[CPTShadow class]
forKey:@"CPTAxis.minorTickLabelShadow"];
plotArea = [coder decodeObjectOfClass:[CPTPlotArea class]
forKey:@"CPTAxis.plotArea"];
minorGridLines = [coder decodeObjectOfClass:[CPTGridLines class]
forKey:@"CPTAxis.minorGridLines"];
majorGridLines = [coder decodeObjectOfClass:[CPTGridLines class]
forKey:@"CPTAxis.majorGridLines"];
pointingDeviceDownLabel = nil;
pointingDeviceDownTickLabel = nil;
inTitleUpdate = NO;
labelsUpdated = NO;
}
return self;
}
/// @endcond
#pragma mark -
#pragma mark NSSecureCoding Methods
/// @cond
+(BOOL)supportsSecureCoding
{
return YES;
}
/// @endcond
#pragma mark -
#pragma mark Animation
/// @cond
+(BOOL)needsDisplayForKey:(nonnull NSString *)aKey
{
static NSSet<NSString *> *keys = nil;
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
keys = [NSSet setWithArray:@[@"titleOffset",
@"titleRotation",
@"labelOffset",
@"minorTickLabelOffset",
@"labelRotation",
@"minorTickLabelRotation"]];
});
if ( [keys containsObject:aKey] ) {
return YES;
}
else {
return [super needsDisplayForKey:aKey];
}
}
/// @endcond
#pragma mark -
#pragma mark Ticks
/// @cond
/**
* @internal
* @brief Generate major and minor tick locations using the fixed interval labeling policy.
* @param newMajorLocations A new NSSet containing the major tick locations.
* @param newMinorLocations A new NSSet containing the minor tick locations.
*/
-(void)generateFixedIntervalMajorTickLocations:(CPTNumberSet *__autoreleasing *)newMajorLocations minorTickLocations:(CPTNumberSet *__autoreleasing *)newMinorLocations
{
CPTMutableNumberSet *majorLocations = [NSMutableSet set];
CPTMutableNumberSet *minorLocations = [NSMutableSet set];
NSDecimal zero = CPTDecimalFromInteger(0);
NSDecimal majorInterval = self.majorIntervalLength.decimalValue;
if ( CPTDecimalGreaterThan(majorInterval, zero)) {
CPTMutablePlotRange *range = [[self.plotSpace plotRangeForCoordinate:self.coordinate] mutableCopy];
if ( range ) {
CPTPlotRange *theVisibleRange = self.visibleRange;
if ( theVisibleRange ) {
[range intersectionPlotRange:theVisibleRange];
}
NSDecimal rangeMin = range.minLimitDecimal;
NSDecimal rangeMax = range.maxLimitDecimal;
NSDecimal minorInterval;
NSUInteger minorTickCount = self.minorTicksPerInterval;
if ( minorTickCount > 0 ) {
minorInterval = CPTDecimalDivide(majorInterval, CPTDecimalFromUnsignedInteger(minorTickCount + 1));
}
else {
minorInterval = zero;
}
// Set starting coord--should be the smallest value >= rangeMin that is a whole multiple of majorInterval away from the labelingOrigin
NSDecimal origin = self.labelingOrigin.decimalValue;
NSDecimal coord = CPTDecimalDivide(CPTDecimalSubtract(rangeMin, origin), majorInterval);
NSDecimalRound(&coord, &coord, 0, NSRoundUp);
coord = CPTDecimalAdd(CPTDecimalMultiply(coord, majorInterval), origin);
// Set minor ticks between the starting point and rangeMin
if ( minorTickCount > 0 ) {
NSDecimal minorCoord = CPTDecimalSubtract(coord, minorInterval);
for ( NSUInteger minorTickIndex = 0; minorTickIndex < minorTickCount; minorTickIndex++ ) {
if ( CPTDecimalLessThan(minorCoord, rangeMin)) {
break;
}
[minorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:minorCoord]];
minorCoord = CPTDecimalSubtract(minorCoord, minorInterval);
}
}
// Set tick locations
while ( CPTDecimalLessThanOrEqualTo(coord, rangeMax)) {
// Major tick
[majorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:coord]];
// Minor ticks
if ( minorTickCount > 0 ) {
NSDecimal minorCoord = CPTDecimalAdd(coord, minorInterval);
for ( NSUInteger minorTickIndex = 0; minorTickIndex < minorTickCount; minorTickIndex++ ) {
if ( CPTDecimalGreaterThan(minorCoord, rangeMax)) {
break;
}
[minorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:minorCoord]];
minorCoord = CPTDecimalAdd(minorCoord, minorInterval);
}
}
coord = CPTDecimalAdd(coord, majorInterval);