Core Plot (macOS)
Cocoa plotting framework for macOS, iOS, and tvOS
CPTPlot.h
Go to the documentation of this file.
2 #import "CPTDefinitions.h"
3 #import "CPTNumericDataType.h"
4 
6 
7 @class CPTLegend;
9 @class CPTNumericData;
10 @class CPTPlot;
11 @class CPTPlotArea;
12 @class CPTPlotSpace;
14 @class CPTPlotRange;
15 @class CPTTextStyle;
16 
21 
24 extern CPTPlotBinding __nonnull const CPTPlotBindingDataLabels;
26 
30 typedef NS_ENUM (NSInteger, CPTPlotCachePrecision) {
34 };
35 
40 
45 
46 #pragma mark -
47 
52 
55 
60 -(NSUInteger)numberOfRecordsForPlot:(nonnull CPTPlot *)plot;
61 
62 @optional
63 
77 -(nullable NSArray *)numbersForPlot:(nonnull CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange;
78 
92 -(nullable id)numberForPlot:(nonnull CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx;
93 
101 -(nullable double *)doublesForPlot:(nonnull CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange NS_RETURNS_INNER_POINTER;
102 
110 -(double)doubleForPlot:(nonnull CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx;
111 
119 -(nullable CPTNumericData *)dataForPlot:(nonnull CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange;
120 
135 -(nullable CPTNumericData *)dataForPlot:(nonnull CPTPlot *)plot recordIndexRange:(NSRange)indexRange;
136 
138 
141 
147 -(nullable CPTLayerArray *)dataLabelsForPlot:(nonnull CPTPlot *)plot recordIndexRange:(NSRange)indexRange;
148 
159 -(nullable CPTLayer *)dataLabelForPlot:(nonnull CPTPlot *)plot recordIndex:(NSUInteger)idx;
160 
162 
163 @end
164 
165 #pragma mark -
166 
171 
172 @optional
173 
176 
185 -(void)plot:(nonnull CPTPlot *)plot dataLabelWasSelectedAtRecordIndex:(NSUInteger)idx;
186 
196 -(void)plot:(nonnull CPTPlot *)plot dataLabelWasSelectedAtRecordIndex:(NSUInteger)idx withEvent:(nonnull CPTNativeEvent *)event;
197 
206 -(void)plot:(nonnull CPTPlot *)plot dataLabelTouchDownAtRecordIndex:(NSUInteger)idx;
207 
217 -(void)plot:(nonnull CPTPlot *)plot dataLabelTouchDownAtRecordIndex:(NSUInteger)idx withEvent:(nonnull CPTNativeEvent *)event;
218 
227 -(void)plot:(nonnull CPTPlot *)plot dataLabelTouchUpAtRecordIndex:(NSUInteger)idx;
228 
238 -(void)plot:(nonnull CPTPlot *)plot dataLabelTouchUpAtRecordIndex:(NSUInteger)idx withEvent:(nonnull CPTNativeEvent *)event;
239 
241 
244 
249 -(void)didFinishDrawing:(nonnull CPTPlot *)plot;
250 
252 
253 @end
254 
255 #pragma mark -
256 
258 
261 @property (nonatomic, readwrite, cpt_weak_property, nullable) id<CPTPlotDataSource> dataSource;
263 
266 @property (nonatomic, readwrite, copy, nullable) NSString *title;
267 @property (nonatomic, readwrite, copy, nullable) NSAttributedString *attributedTitle;
269 
272 @property (nonatomic, readwrite, strong, nullable) CPTPlotSpace *plotSpace;
274 
277 @property (nonatomic, readonly, nullable) CPTPlotArea *plotArea;
279 
282 @property (nonatomic, readonly) BOOL dataNeedsReloading;
284 
287 @property (nonatomic, readonly) NSUInteger cachedDataCount;
288 @property (nonatomic, readonly) BOOL doublePrecisionCache;
289 @property (nonatomic, readwrite, assign) CPTPlotCachePrecision cachePrecision;
290 @property (nonatomic, readonly) CPTNumericDataType doubleDataType;
291 @property (nonatomic, readonly) CPTNumericDataType decimalDataType;
293 
296 @property (nonatomic, readonly) BOOL needsRelabel;
297 @property (nonatomic, readwrite, assign) BOOL adjustLabelAnchors;
298 @property (nonatomic, readwrite, assign) BOOL showLabels;
299 @property (nonatomic, readwrite, assign) CGFloat labelOffset;
300 @property (nonatomic, readwrite, assign) CGFloat labelRotation;
301 @property (nonatomic, readwrite, assign) NSUInteger labelField;
302 @property (nonatomic, readwrite, copy, nullable) CPTTextStyle *labelTextStyle;
303 @property (nonatomic, readwrite, strong, nullable) NSFormatter *labelFormatter;
304 @property (nonatomic, readwrite, strong, nullable) CPTShadow *labelShadow;
306 
309 @property (nonatomic, readwrite, assign) BOOL alignsPointsToPixels;
311 
314 @property (nonatomic, readwrite, assign) BOOL drawLegendSwatchDecoration;
316 
319 -(void)setNeedsRelabel;
320 -(void)relabel;
321 -(void)relabelIndexRange:(NSRange)indexRange;
323 -(void)reloadDataLabels;
324 -(void)reloadDataLabelsInIndexRange:(NSRange)indexRange;
326 
329 -(void)setDataNeedsReloading;
330 -(void)reloadData;
331 -(void)reloadDataIfNeeded;
332 -(void)reloadDataInIndexRange:(NSRange)indexRange;
333 -(void)insertDataAtIndex:(NSUInteger)idx numberOfRecords:(NSUInteger)numberOfRecords;
334 -(void)deleteDataInIndexRange:(NSRange)indexRange;
335 -(void) reloadPlotData NS_SWIFT_NAME(CPTPlot.reloadPlotData());
336 
337 -(void)reloadPlotDataInIndexRange:(NSRange) indexRange NS_SWIFT_NAME(CPTPlot.reloadPlotData(inIndexRange:));
338 
340 
343 +(nonnull id)nilData;
344 -(nullable id)numbersFromDataSourceForField:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange;
345 -(BOOL)loadNumbersForAllFieldsFromDataSourceInRecordIndexRange:(NSRange)indexRange;
347 
350 -(nullable CPTMutableNumericData *)cachedNumbersForField:(NSUInteger)fieldEnum;
351 -(nullable NSNumber *)cachedNumberForField:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx;
352 -(double)cachedDoubleForField:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx;
353 -(NSDecimal)cachedDecimalForField:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx;
354 -(nullable NSArray *)cachedArrayForKey:(nonnull NSString *)key;
355 -(nullable id)cachedValueForKey:(nonnull NSString *)key recordIndex:(NSUInteger)idx;
356 
357 -(void)cacheNumbers:(nullable id)numbers forField:(NSUInteger)fieldEnum;
358 -(void)cacheNumbers:(nullable id)numbers forField:(NSUInteger)fieldEnum atRecordIndex:(NSUInteger)idx;
359 -(void)cacheArray:(nullable NSArray *)array forKey:(nonnull NSString *)key;
360 -(void)cacheArray:(nullable NSArray *)array forKey:(nonnull NSString *)key atRecordIndex:(NSUInteger)idx;
362 
365 -(nullable CPTPlotRange *)plotRangeForField:(NSUInteger)fieldEnum;
366 -(nullable CPTPlotRange *)plotRangeForCoordinate:(CPTCoordinate)coord;
367 -(nullable CPTPlotRange *)plotRangeEnclosingField:(NSUInteger)fieldEnum;
368 -(nullable CPTPlotRange *)plotRangeEnclosingCoordinate:(CPTCoordinate)coord;
370 
374 -(nullable NSString *)titleForLegendEntryAtIndex:(NSUInteger)idx;
375 -(nullable NSAttributedString *)attributedTitleForLegendEntryAtIndex:(NSUInteger)idx;
376 -(void)drawSwatchForLegend:(nonnull CPTLegend *)legend atIndex:(NSUInteger)idx inRect:(CGRect)rect inContext:(nonnull CGContextRef)context;
378 
379 @end
380 
381 #pragma mark -
382 
387 
391 -(nonnull CPTNumberArray *)fieldIdentifiers;
392 -(nonnull CPTNumberArray *)fieldIdentifiersForCoordinate:(CPTCoordinate)coord;
393 -(CPTCoordinate)coordinateForFieldIdentifier:(NSUInteger)field;
395 
398 -(void)positionLabelAnnotation:(nonnull CPTPlotSpaceAnnotation *)label forIndex:(NSUInteger)idx;
400 
403 -(NSUInteger)dataIndexFromInteractionPoint:(CGPoint)point;
405 
406 @end
-[CPTPlot setNeedsRelabel]
void setNeedsRelabel()
Marks the receiver as needing to update all data labels before the content is next drawn.
Definition: CPTPlot.m:1595
CPTPlot::alignsPointsToPixels
BOOL alignsPointsToPixels
If YES (the default), all plot points will be aligned to device pixels when drawing.
Definition: CPTPlot.h:309
CPTShadow
Immutable wrapper for various shadow drawing properties.
Definition: CPTShadow.h:3
CPTNumericDataType
Structure that describes the encoding of numeric data samples.
Definition: CPTNumericDataType.h:27
CPTPlot::showLabels
BOOL showLabels
Set to NO to override all other label settings and hide the data labels. Defaults to YES.
Definition: CPTPlot.h:298
CPTPlotBindingDataLabels
CPTPlotBinding __nonnull const CPTPlotBindingDataLabels
Plot data labels.
Definition: CPTPlot.m:47
-[CPTPlot reloadDataIfNeeded]
void reloadDataIfNeeded()
Reload plot data from the data source only if the data cache is out of date.
Definition: CPTPlot.m:578
NSArray
CPTPlotArray
NSArray< __kindof CPTPlot * > CPTPlotArray
An array of plots.
Definition: CPTPlot.h:39
CPTPlotSpaceAnnotation
Positions a content layer relative to some anchor point in a plot space.
Definition: CPTPlotSpaceAnnotation.h:6
CPTPlotDataSource-p
A plot data source.
Definition: CPTPlot.h:51
CPTPlot::labelTextStyle
CPTTextStyle * labelTextStyle
The text style used to draw the data labels. Set this property to nil to hide the data labels.
Definition: CPTPlot.h:302
CPTPlot::labelFormatter
NSFormatter * labelFormatter
The number formatter used to format the data labels. Set this property to nil to hide the data labels...
Definition: CPTPlot.h:303
-[CPTPlot reloadPlotData]
void reloadPlotData()
Reload all plot data from the data source immediately.
Definition: CPTPlot.m:694
CPTPlot::plotSpace
CPTPlotSpace * plotSpace
The plot space for the plot.
Definition: CPTPlot.h:272
NSRange
typedef NSRange
CPTNumericDataType.h
CPTPlotRange
Defines an immutable range of plot data.
Definition: CPTPlotRange.h:27
CGPoint
typedef CGPoint
NSUInteger
typedef NSUInteger
CPTPlotSpace
Defines the coordinate system of a plot.
Definition: CPTPlotSpace.h:178
CPTPlot::dataSource
id< CPTPlotDataSource > dataSource
The data source for the plot.
Definition: CPTPlot.h:261
CPTTextStyle
Immutable wrapper for various text style properties.
Definition: CPTTextStyle.h:18
CPTPlot::adjustLabelAnchors
BOOL adjustLabelAnchors
If YES, data labels anchor points are adjusted automatically when the labels are positioned....
Definition: CPTPlot.h:297
CPTPlotCachePrecisionDecimal
@ CPTPlotCachePrecisionDecimal
All cached data will be converted to NSDecimal.
Definition: CPTPlot.h:33
CPTPlot::title
NSString * title
The title of the plot displayed in the legend.
Definition: CPTPlot.h:266
CPTPlot(AbstractMethods)
CPTPlot abstract methods—must be overridden by subclasses.
Definition: CPTPlot.h:386
-[CPTPlot numberOfLegendEntries]
NSUInteger numberOfLegendEntries()
The number of legend entries provided by this plot.
Definition: CPTPlot.m:1796
CPTAnnotationHostLayer
A container layer for annotations.
Definition: CPTAnnotationHostLayer.h:5
-[NSObject copy]
id copy
CPTLayerDelegate-p
Layer delegate.
Definition: CPTLayer.h:76
NSAttributedString
CPTPlot::labelField
NSUInteger labelField
The plot field identifier of the data field used to generate automatic labels.
Definition: CPTPlot.h:301
CPTMutableNumericData
An annotated NSMutableData type.
Definition: CPTMutableNumericData.h:5
CPTPlotCachePrecisionDouble
@ CPTPlotCachePrecisionDouble
All cached data will be converted to double precision.
Definition: CPTPlot.h:32
CPTPlot::doubleDataType
CPTNumericDataType doubleDataType
The CPTNumericDataType used to cache plot data as double.
Definition: CPTPlot.h:290
BOOL
typedef BOOL
-[CPTPlot(AbstractMethods) numberOfFields]
NSUInteger numberOfFields()
Number of fields in a plot data record.
Definition: CPTPlot.m:2259
CGContextRef
typedef CGContextRef
-[CPTPlot(AbstractMethods) fieldIdentifiers]
nonnull CPTNumberArray * fieldIdentifiers()
Identifiers (enum values) identifying the fields.
Definition: CPTPlot.m:2267
CPTPlot::cachePrecision
CPTPlotCachePrecision cachePrecision
The numeric precision used to cache the plot data and perform all plot calculations....
Definition: CPTPlot.h:289
CPTLayer
Base class for all Core Animation layers in Core Plot.
Definition: CPTLayer.h:83
CPTPlot::attributedTitle
NSAttributedString * attributedTitle
The styled title of the plot displayed in the legend.
Definition: CPTPlot.h:267
CPTDefinitions.h
CPTAnnotationHostLayer.h
CPTPlot::decimalDataType
CPTNumericDataType decimalDataType
The CPTNumericDataType used to cache plot data as NSDecimal.
Definition: CPTPlot.h:291
CPTMutablePlotArray
NSMutableArray< __kindof CPTPlot * > CPTMutablePlotArray
A mutable array of plots.
Definition: CPTPlot.h:44
CPTLegend
A graph legend.
Definition: CPTLegend.h:185
CPTPlotCachePrecision
CPTPlotCachePrecision
Enumeration of cache precisions.
Definition: CPTPlot.h:30
CPTPlot::labelShadow
CPTShadow * labelShadow
The shadow applied to each data label.
Definition: CPTPlot.h:304
CPTNumericData
An annotated NSData type.
Definition: CPTNumericData.h:4
CPTCoordinate
CPTCoordinate
Enumeration of axis coordinates.
Definition: CPTDefinitions.h:164
CPTPlot::doublePrecisionCache
BOOL doublePrecisionCache
If YES, the cache holds data of type double, otherwise it holds NSDecimal.
Definition: CPTPlot.h:288
CPTPlot
An abstract plot class.
Definition: CPTPlot.h:258
CPTPlot::dataNeedsReloading
BOOL dataNeedsReloading
If YES, the plot data will be reloaded from the data source before the layer content is drawn.
Definition: CPTPlot.h:282
CPTPlot::needsRelabel
BOOL needsRelabel
If YES, the plot needs to be relabeled before the layer content is drawn.
Definition: CPTPlot.h:296
cpt_swift_struct
#define cpt_swift_struct
Marks a type definition to be imported into Swift as a structure.
Definition: CPTDefinitions.h:73
CPTPlotArea
A layer representing the actual plotting area of a graph.
Definition: CPTPlotArea.h:76
NSString
-[CPTPlot repositionAllLabelAnnotations]
void repositionAllLabelAnnotations()
Repositions all existing label annotations.
Definition: CPTPlot.m:1775
CPTPlot::labelOffset
CGFloat labelOffset
The distance that labels should be offset from their anchor points. The direction of the offset is de...
Definition: CPTPlot.h:299
cpt_weak_property
#define cpt_weak_property
A custom definition for automatic reference counting (ARC) weak properties that falls back to assign ...
Definition: CPTDefinitions.h:32
-[CPTPlot reloadData]
void reloadData()
Reload all plot data, labels, and plot-specific information from the data source immediately.
Definition: CPTPlot.m:567
CPTPlotCachePrecisionAuto
@ CPTPlotCachePrecisionAuto
Cache precision is determined automatically from the data. All cached data will be converted to match...
Definition: CPTPlot.h:31
CPTPlotDelegate-p
Plot delegate.
Definition: CPTPlot.h:170
CPTPlot::plotArea
CPTPlotArea * plotArea
The plot area for the plot.
Definition: CPTPlot.h:277
CGRect
typedef CGRect
id
typedef id
NSDecimal
typedef NSDecimal
-[CPTPlot reloadDataLabels]
void reloadDataLabels()
Reload all data labels from the data source immediately.
Definition: CPTPlot.m:716
-[CPTPlot setDataNeedsReloading]
void setDataNeedsReloading()
Marks the receiver as needing the data source reloaded before the content is next drawn.
Definition: CPTPlot.m:559
-[CPTPlot relabel]
void relabel()
Updates the data labels in the labelIndexRange.
Definition: CPTPlot.m:1604
+[CPTPlot nilData]
nonnull id nilData()
A unique marker object used in collections to indicate that the datasource returned nil.
Definition: CPTPlot.m:761
CPTPlot::cachedDataCount
NSUInteger cachedDataCount
The number of data points stored in the cache.
Definition: CPTPlot.h:287
CPTPlot::labelRotation
CGFloat labelRotation
The rotation of the data labels in radians. Set this property to π/2 to have labels read up the scree...
Definition: CPTPlot.h:300
CPTPlot::drawLegendSwatchDecoration
BOOL drawLegendSwatchDecoration
If YES (the default), additional plot-specific decorations, symbols, and/or colors will be drawn on t...
Definition: CPTPlot.h:314