Graph Kit Reference
Graph Kit Reference
Reference Guide
September 2005
Table of Contents
Table of Contents
Chapter 1 Introduction
Overview 7
Architecture 7
Chapter 2 GRChartView
GRChartView 10
defaultProperties 13
defaultPropertyForKey: 13
setDefaultProperty:ForKey: 13
setDefaultProperties: 14
propertyForKey: 14
setProperty:forKey: 14
setProperties: 14
setDataSource: 14
dataSource 14
reloadData 14
setDelegate: 15
delegate 15
setAxes: 15
axes 15
setTag: 15
tag 15
dataSets 15
addDataSet:loadData: 16
addDataSets:loadData: 16
moveDataSetAtIndex:toIndex: 16
removeDataSet: 16
removeDataSetAtIndex: 16
removeAllDataSets 16
numberOfDataSets 16
numberOfDataSetsOfKindOfClass: 16
indexOfDataSet: 17
classIndexOfDataSet: 17
dataSetOfKindOfClass: 17
Chapter 1
Introduction
Overview
GraphKit is a Cocoa framework for programmatically creating 2D line, area, column
and pie charts using the Quartz graphics layer of MacOS X. GraphKit’s basis in
Quartz makes it extremely simple to export GraphKit charts as PDF, TIFF, or other
popular data formats for use in the real world. The main design points of GraphKit
are:
GraphKit is intended for use in Cocoa programs. This document assumes that the
reader is at least somewhat familiar with the Objective-C programming language.
Architecture
Figure 1-1 diagrams the architecture of a GraphKit chart. At its highest level, a
GraphKit chart consists of an instance of the GRChartView class. The GRChartView
class manages an arbitrary number of datasets (instances of GRDataSet and its
subclasses) and controls when and how they will be drawn. In GraphKit, a dataset is
a single, related series of data points to be plotted in the same color, line style, etc.
In the case of a line chart, for example, a single continuous line represents a dataset.
GRDataSet and its subclasses (GRLineDataSet, GRAreaDataSet, GRColumnDataSet,
and GRPieDataSet) are used to contain datasets in GraphKit. A GRChartView can
display its datasets either overlayed on top of one another or tiled (vertically or
horizontally) such that each dataset is displayed on its own set of axes. When in
overlayed display mode, the datasets can be displayed independently or
cumulatively such that each dataset element is drawn with its values stacked on the
corresponding element of previously drawn datasets (total value or fraction of the
total). Each set of axes is represented by an instance of GRAxes or its subclasses
(GRXYAxes, GRPieAxes). The GRAxes classes are responsible for managing the scale
and range of datasets as well as drawing any necessary ticks, grid lines, titles, or
legends. There is an instance of the GRAxes class associated with the GRChartView
as well as with each GRDataSet contained in the chart view. In overlayed mode, the
GRChartView’s GRAxes is used. In tiled mode, the GRAxes of each GRDataSet is
used.
10
8 Properties 10
7 8
6
7
6
Properties
5 5
4
4
3
3 2
1
2
0
1 2 3 4 5
1
0
1 2 3 4 5 GRAxes
GRChartView
10
Properties Properties
8
0
1 2 3 4 5
GRDataSet GRAxes
10
Properties Properties
8
0
1 2 3 4 5
GRDataSet GRAxes
Figure 1-1. GraphKit Framework Architecture
Associated with every object in the GraphKit hierarchy is a properties dictionary.
Each properties dictionary contains key-value pairs that are initialized to a default set
of entries when a GraphKit object is created. Default properties for a class can be
read or modified one at a time with the +getDefaultPropertyForKey:
and +setDefaultProperty:ForKey: methods respectively. The entire
default properties dictionary for a class can be retrieved with
+defaultProperties or replaced with
+setDefaultProperties:. Instance properties are read with the –
propertyForKey: and modified with the –setProperty:ForKey:
method. These methods are available in every GraphKit class, although the keys and
values for each of class necessarily differ. Keys are verified by the set property
methods to be appropriate for the class or instance being modified.
If you have used ApplicationKit’s NSTableView class, then many of the concepts
used by GraphKit charts will be familiar to you. Like an NSTableView, a GraphKit
chart object uses a datasource to ask for the number of datasets, datapoints and
values to plot. Also similar to many other AppKit classes, GraphKit utilizes the
concept of a “delegate” to optionally customize the behavior of its charts.
Chapter 2
GRChartView
GRChartView
Inherits from:
NSView : NSResponder : NSObject
Conforms to:
NSCoding (NSResponder)
NSObject (NSObject)
Declared in:
GraphKit/GRChartView.h
Class Description
A GRChartView class manages an arbitrary number of datasets and controls when and
how they will be drawn to the screen.
Properties
Key Description
GRChartFrameColor The color (NSColor) used to draw all grid lines, ticks,
etc.
GRChartOverlayLayout
GRChartVerticalTileLayout
GRChartHorizontalTileLayout
GRChartIndependentOverlay
GRChartStackedValueOverlay
GRChartStackedFractionOverlay
GRChartNoBorder
GRChartLineBorder
GRChartBezelBorder
GRChartGrooveBorder
Method Types
Manipulating default properties
+ defaultProperties
+ defaultPropertyForKey:
+ setDefaultProperty:forKey:
+ setDefaultProperties:
Manipulating properties
- propertyForKey:
- setProperty:forKey:
- setProperties:
Setting the data source
- setDataSource:
- dataSource
- reloadData
Setting the delegate
- setDelegate:
- delegate
Retrieving the axes
- setAxes:
- axes
Setting the tag
- setTag:
- tag
Manipulating datasets
- dataSets
- addDataSet:loadData:
- addDataSets:loadData:
- moveDataSetAtIndex:toIndex:
- removeDataSet:
- removeDataSetAtIndex:
- removeAllDataSets
- numberOfDataSets
- numberOfDataSetsOfKindOfClass:
- indexOfDataSet:
- classIndexOfDataSet:
- dataSetOfKindOfClass:atClassIndex:
Zooming
- autoscale
- zoomInRect:
- zoomOut
- zoomIn:
- zoomOut:
- scrollView
Scrolling
- centerSelection
- leftJustifySelection
- rightJustifySelection
Layout
- canvasRect
- plotRect
- canvasRectForDataSetAtIndex:
- computeLayout
- setNeedsLayout:
- needsLayout
For delegates
- canvasRectForDataSetAtIndex:
Class Methods
defaultProperties
+(NSDictionary *) defaultProperties
Returns a copy of the default GRChartView class properties dictionary.
defaultPropertyForKey:
+(id) defaultPropertyForKey:(NSString *)key
Returns the default property value associated with key or nil if the GRChartView class default
properties dictionary does not contain key.
setDefaultProperty:ForKey:
+(BOOL) setDefaultProperty:(id)p forKey:(NSString *)key
Sets the property value p for key in the GRChartView class default properties dictionary. Returns YES
upon success or NO in the case of an illegal key.
setDefaultProperties:
+(void) setDefaultProperties:(NSDictionary *)pd
Replace the GRChartView class default properties dictionary with pd.
Instance Methods
propertyForKey:
-(id) propertyForKey:(NSString *)key
Returns the property value associated with key or nil if the properties dictionary does not contain
key.
setProperty:forKey:
-(BOOL) setProperty:(id)p forKey:(NSString *)key
Sets the property value p for key in the properties dictionary. Returns YES upon success or NO in the
case of an illegal key.
setProperties:
-(void) setProperties:(NSDictionary *)pd
Replace the GRChartView instance properties dictionary with pd.
setDataSource:
-(void) setDataSource:(id)anObject
Sets the receiver's data source to anObject. anObject should implement the appropriate methods of
the GRChartDataSource informal protocol.
This method raises an NSInternalInconsistencyException if anObject
doesn't respond to either chart:numElementsInDataSet: or chart:dataset:yValueAtIndex:.
dataSource
-(id) dataSource
Returns the object that provides the data displayed by the receiver. See the GRChartDataSource
informal protocol specification for more information.
See Also: - setDataSource:
reloadData
- (void)reloadData
Marks the receiver as needing redisplay, so it will instruct each dataset to reload the new data and
then redraw the datasets.
setDelegate:
-(void) setDelegate:(id)anObject
Sets the receiver's delegate to anObject.
See Also: - delegate
delegate
-(id) delegate
Returns the receiver's delegate.
See Also: - setDelegate:
setAxes:
-(void) setAxes:(GRAxes *)axes
Sets the receiver's axes to axes. The GRChartView’s axes are used in overlay mode. If the axes of the
first GRDataSet to be added to a chart does not match those of the GRChartView, the GRChartView’s
axes are recreated based on the dataset’s axes type. This is done in order to ensure compatibility
between the chart’s axes (used for overlay) and its datasets.
See Also: - axes
axes
-(GRAxes *) axes
Returns the receiver's axes. The GRChartView’s axes are used in overlay mode. There is no
corresponding setAxes: method because the GRChartView’s axes are instantiated automatically when
the first GRDataSet is added to the chart (the same class as the axes of this first dataset). This is done
in order to ensure compatibility between the chart’s axes (used for overlay) and its datasets.
setTag:
-(void) setTag:(int)aTag
Sets the receiver's tag to aTag, an integer that you can use to identify view objects in your application.
tag
-(int) tag
Returns the receiver's tag, an integer that you can use to identify view objects in your application.
See Also: - setTag:
dataSets
-(NSArray *) dataSets
Returns an array containing all of the GRDataSets in the receiver.
addDataSet:loadData:
-(void) addDataSet:(GRDataSet *)aDataSet
loadData:(BOOL)load
Adds aDataSet as the last dataset of the receiver. If aDataSet is the first dataset to be added, the
correct GRAxes class will be automatically allocated. If load is YES, the data are reloaded, and the
GRChartView is redrawn.
See Also: - removeDataSet:
addDataSets:loadData:
-(void) addDataSets:(NSArray *)arr loadData:(BOOL)loadData
Adds all of the datasets in arr as the last datasets of the receiver (same order as array). If loadData is
YES, the data are reloaded, and the GRChartView is redrawn.
See Also: - removeDataSet:
moveDataSetAtIndex:toIndex:
-(void)moveDataSetAtIndex:(int)oldIndex
toIndex:(int)newIndex
Moves the dataset at oldIndex to newIndex.
removeDataSet:
-(void) removeDataSet:(GRDataSet *)aDataSet
Removes aDataSet from the receiver.
See Also: - addDataSet:
removeDataSetAtIndex:
-(void) removeDataSetAtIndex:(int)index
Removes dataset at index index from the receiver.
removeAllDataSets
-(void) removeAllDataSets
Removes all datasets from the receiver.
numberOfDataSets
-(int) numberOfDataSets
Returns the number of datasets in the receiver.
numberOfDataSetsOfKindOfClass:
-(int) numberOfDataSetsOfKindOfClass:(Class)aClass
Returns the number of GRDataSets in the receiver that are a member of aClass or its subclasses.
indexOfDataSet:
-(void) indexOfDataSet:(GRDataSet *)aDataSet
Returns index of aDataSet.
classIndexOfDataSet:
-(int) classIndexOfDataSet:(GRDataSet *)aDataSet
Returns index of aDataSet for all classes of the same class or subclasses of aDataSet.
dataSetOfKindOfClass:
-(GRDataSet *) dataSetOfKindOfClass:(Class)aClass
atClassIndex:(int)index
Returns the GRDataSet in the receiver that are a member of aClass or its subclasses at the specified
index.
autoscale
-(BOOL) autoscale
zoomInRect:
-(BOOL) zoomInRect:(NSRect)zoomRect
Returns NO if all the associated GRDataSets could not zoom to the given rectangle
zoomOut
-(BOOL) zoomOut
Returns NO if the receiver could not return to its normal zoom.
zoomIn:
-(IBAction) zoomIn:(id)sender
Action that zooms in the receiver by 20%.
zoomOut:
-(IBAction) zoomOut:(id)sender
Action that calls zoomOut.
scrollView
-(NSScrollView *) scrollView
Returns the NSScrollView associated with the receiver.
centerSelection
-(void) centerSelection
Causes the axes to center the selection.
leftJustifySelection
-(void) leftJustifySelection
Causes the axes to left justify the selection.
rightJustifySelection
-(void) rightJustifySelection
Causes the azes to right justify the selection.
canvasRect
-(NSRect) canvasRect
Returns the NSRect upon which the chart is drawn.
plotRect
-(NSRect) plotRect
Returns the NSRect upon which the plot itself is drawn.
canvasRectForDataSetAtIndex:
-(NSRect) canvasRectForDataSetAtIndex:(int)dataSetIndex
Returns the canvas rectangle (bounds) of the dataset at index dataSetIndex.
computeLayout
-(BOOL) computeLayout
Returns YES if the chart layout was succesully recomputed.
setNeedsLayout:
-(void) setNeedsLayout:(BOOL)b
Mark the receiver as needing to recompute its layout
needsLayout
-(BOOL) needsLayout
Returns YES if the receiver needs to recompute its layout.
datasets can be smaller or larger than the rest). The total of fractions for all datasets must add up to
1.0.
Chapter 3
GRDataSet
GRDataSet
Inherits from:
NSObject
Conforms to:
NSObject (NSObject)
Declared in:
GraphKit/GRDataSet.h
Class Description
A GRDataSet object manages and draws a set of related datapoints. The datapoints
supplied by the data source are cached internally for efficiency. The GRDataSet class is
an abstract class; it does not define how datapoints are to be cached or drawn. Subclasses
of the GRDataSet class (GRLineDataSet, GRAreaDataSet, GRColumnDataSet,
GRPieDataSet) implement specific caching and drawing methods.
Properties
Key Description
GRDataSetSumValue (NSNumber)
Method Types
Manipulating default properties
+ defaultProperties
+ defaultPropertyForKey:
+ setDefaultProperty:forKey:
+ setDefaultProperties:
+ defaultColors
+ setDefaultColors:
+ axesClass
Manipulating properties
- propertyForKey:
- setProperty:forKey:
- setProperties:
Creating a dataset
- initWithOwnerChart:
- chart
Setting the data source
- setDataSource:
- dataSource
Loading data
- reloadData
- numberOfElements
Setting the delegate
- setDelegate:
- delegate
Setting the identifier
- setIdentifier:
- identifier
Setting the axes
- setAxes:
- axes
Drawing
- drawLegendSampleInRect:
- drawDataSetRect:
Selection
- selectedRange
- setSelectedRange:
- clearSelectedRange
- selectPrevious
- selectNext
Class Methods
defaultProperties
+(NSDictionary *) defaultProperties
Returns a copy of the default GRDataSet class properties dictionary.
defaultPropertyForKey:
+(id) defaultPropertyForKey:(NSString *)key
Returns the default property value associated with key or nil if the GRDataSet class default properties
dictionary does not contain key.
setDefaultProperty:forKey:
+(BOOL) setDefaultProperty:(id)p forKey:(NSString *)key
Sets the property value p for key in the GRDataSet class default properties dictionary. Returns YES
upon success or NO in the case of an illegal key.
setDefaultProperties:
+(void) setDefaultProperties:(NSDictionary *)aDictionary
Replace the GRDataSet class default properties dictionary with aDictionary.
defaultColors
+(NSArray *) defaultColors
Returns a copy of the default GRDataSet class colors dictionary.
setDefaultColors:
+(void) setDefaultColors:(NSArray *)anArray
Replace the GRDataSet class default colors dictionary with anArray.
axesClass
+(Class) axesClass
Returns the class of the preferred GRAxes subclass. For example, if the dataset requires a GRXYAxes
class, it should return [GRXYAxes class]. This method is used by initializer methods to allocate the
correct type of axes as well as ensure that incompatible GRDataSets are not mixed.
Instance Methods
propertyForKey:
-(id) propertyForKey:(NSString *)key
Returns the property value associated with key or nil if the properties dictionary does not contain
key.
setProperty:forKey:
-(BOOL) setProperty:(id)p forKey:(NSString *)key
Sets the property value p for key in the properties dictionary. Returns YES upon success or NO in the
case of an illegal key.
setProperties:
+(void) setProperties:(NSDictionary *)aDictionary
Replace the GRDataSet instance properties dictionary with aDictionary.
initWithOwnerChart:
-(id) initWithOwnerChart:(GRChartView *)aChartView
Initializes a newly created GRDataSet with aChartView as its owner. This method is the designated
initializer for the GRDataSet class. Returns self.
chart
-(GRChartView *) chart
Returns the owner chart.
setDataSource:
-(void) setDataSource:(id)anObject
Sets the receiver's data source to anObject. anObject should implement the appropriate methods of
the GRChartDataSource informal protocol.
This method raises an NSInternalInconsistencyException if anObject
doesn't respond to either chart:numElementsInDataSet: or chart:dataset:yValueAtIndex:.
dataSource
-(id) dataSource
Returns the object that provides the data displayed by the receiver. See the GRChartDataSource
informal protocol specification for more information.
See Also: - setDataSource:
reloadData
- (void)reloadData
Marks the receiver as needing redisplay, so it will instruct each dataset to reload the new data and
then redraw the datasets.
numberOfElements
-(int) numberOfElements
Returns the number of datapoints (elements) in the dataset.
setDelegate:
-(void) setDelegate:(id)anObject
Sets the receiver's delegate to anObject.
See Also: - delegate
delegate
-(id) delegate
Returns the receiver's delegate.
See Also: - setDelegate:
setIdentifier:
-(void) setIdentifier:(id)anObject
Sets the receiver's identifier to anObject. This object is used by the data source to identify the
attribute corresponding to the GRDataSet.
identifier
-(id) identifier
Returns the object used by the data source to identify the attribute corresponding to the receiver.
See Also: - setIdentifier:
setAxes:
-(void) setAxes:(GRAxes *)axes
Sets the receiver's axes to axes. The GRDataSet’s axes are used in tile mode. If the GRDataSet is the
first one to be added to a chart, the GRChartView’s axes are generated based on its axes type. This is
done in order to ensure compatibility between the chart’s axes (used for overlay) and its datasets.
See Also: - axes
axes
-(GRAxes *) axes
Returns the receiver's axes. The GRDataSet’s axes are used in tile mode.
drawLegendSampleInRect:
-(void) drawLegendSampleInRect:(NSRect)aRect
Draws a sample of the dataset’s plotting method (color, line width, etc.) inside of aRect. This is used
when drawing the legend.
drawDataSetRect:
-(void) drawDataSetRect:(NSRect)aRect
Called to draw the dataset’s datapoints inside of aRect as specified by the current GRAxes.
selectedRange
-(NSRange) selectedRange
Returns the range of selected datapoint indices.
setSelectedRange:
-(BOOL) setSelectedRange:(NSRange)r
Sets the dataset’s range of selected datapoint indices to [[Link]..[Link]+[Link]). Returns NO
if the supplied range is not valid for the dataset.
clearSelectedRange
-(void) clearSelectedRange
Clears the range of selected datapoint indices.
selectPrevious
-(BOOL) selectPrevious
Slides the dataset’ range of previously selected datapoint indices down by one place. Returns NO if
the range is already at the start of the dataset, or if the selected range only includes one datapoint.
selectNext
-(BOOL) selectNext
Slides the dataset’ range of previously selected datapoint indices up by one place. Returns NO if the
range is already at the end of the dataset, or if the selected range only includes one datapoint
GRDataSetDataSource
Adopted By:
NSObject
Declared in:
GraphKit/GRDataSet.h
Protocol Description
The GRDataSetDataSource informal protocol declares the methods that a GRDataSet
uses to access the contents of its data source object.
Method Types
GettingValues
- chart:numElementsForDataSet:
- chart:colorForDataSet:element:
- chart:calloutForDataSet:element:
Instance Methods
chart:numElementsForDataSet:
-(int) chart:(GRChartView *)aChart
numElementsForDataSet:(GRDataSet *)aDataSet;
Returns the number of datapoints managed for aDataSet in aChart by the data source object. A
GRDataSet uses this method to determine how many datapoints it should retain and display.
chart:colorForDataSet:element:
-(NSColor *) chart:(GRChartView *)aChart
colorForDataSet:(GRDataSet *)aDataSet element:(int)index
Returns the color (NSColor) of the element at position index in aDataSet.
chart:calloutForDataSet:element:
-(NSString *) chart:(GRChartView *)aChart
calloutForDataSet:(GRDataSet *)aDataSet element:(int)index
Returns the callout (NSString) of the element at position index in aDataSet.
GRXYDataSet
Inherits from:
GRDataSet: NSObject
Conforms to:
NSObject (NSObject)
Declared in:
GraphKit/GRXYDataSet.h
Class Description
The GRXYDataSet class is a subclass of GRDataSet used to manage all of the common
properties of datasets plotted on GRXYAxes. The GRXYDataSet class is an abstract
class; it does not define how datapoints are to be cached or drawn. Subclasses of the
GRXYDataSet class (GRLineDataSet, GRAreaDataSet, GRColumnDataSet) implement
specific caching and drawing methods.
Properties
Key Description
Method Types
Loading data
- xIntervalAtIndex:
- yValueAtIndex:
- indexOfXvalue:yValue:exactMatch:
Instance Methods
xIntervalAtIndex:
-(GRInterval) xIntervalAtIndex:(int)index
Returns the x interval of the datapoint at index. Raises an NSInvalidArgumentException and returns
(0.0, 0.0) if the index is out of range.
yValueAtIndex:
-(double) yValueAtIndex:(int)index
Returns the y value of the datapoint at index. Raises an NSInvalidArgumentException and returns 0.0
if the index is out of range.
indexOfXvalue:yValue:exactMatch:
-(int) indexOfXvalue:(double)x yValue:(double)y
exactMatch:(BOOL)exact
Not implemented in the abstract class, returns -1.
GRXYDataSetDataSource
Adopted By:
NSObject (informal protocol)
Declared in:
GraphKit/GRXYDataSet.h
Protocol Description
The GRXYDataSetDataSource informal protocol declares the methods that a
GRXYDataSet uses to access the contents of its data source object.
Method Types
GettingValues
- chart:yValueForDataSet:element:
- chart:xIntervalForDataSet:element:
Instance Methods
chart:yValueForDataSet:element:
-(double) chart:(GRChartView *)aChart
yValueForDataSet:(GRDataSet *)aDataSet element:(int)index
Returns the y value at index index of the datapoint managed for aDataSet in aChart by the data
source object.
chart:xIntervalForDataSet:element:
-(GRInterval) chart:(GRChartView *)aChart
xIntervalForDataSet:(GRDataSet *)aDataSet
element:(int)index
Returns the x interval (begin, end) at index index of the datapoint managed for aDataSet in aChart
by the data source object. This function is optional.
GRAreaDataSet
Inherits from:
GRXYDataSet: GRDataSet: NSObject
Conforms to:
NSObject (NSObject)
Declared in:
GraphKit/GRAreaDataSet.h
Class Description
The GRAreaDataSet class is a subclass of GRXYDataSet used to manage and draw a
dataset as an area chart.
GRLineDataSet
Inherits from:
GRXYDataSet: GRDataSet: NSObject
Conforms to:
NSObject (NSObject)
Declared in:
GraphKit/GRLineDataSet.h
Class Description
The GRLineDataSet class is a subclass of GRXYDataSet used to manage and draw a
dataset as line chart.
Properties
Key Description
GRLineDataSetPlotStroke
GRLineDataSetPlotFill
Method Types
Loading data
+ defaultMarkers
+ setDefaultMarkers:
Class Methods
defaultMarkers
+(NSArray *) defaultMarkers
Returns a copy of the default GRLineDataSet class markers dictionary.
setDefaultMarkers:
+(void) setDefaultMarkers:(NSArray *)anArray
Replace the GRLineDataSet class default markers dictionary with anArray.
GRColumnDataSet
Inherits from:
GRXYDataSet: GRDataSet: NSObject
Conforms to:
NSObject (NSObject)
Declared in:
GraphKit/GRColumnDataSet.h
Class Description
The GRColumnDataSet class is a subclass of GRXYDataSet used to manage and draw a
dataset as a column (vertical bar) chart.
Properties
Key Description
GRPieDataSet
Inherits from:
GRDataSet: NSObject
Conforms to:
NSObject (NSObject)
Declared in:
GraphKit/GRPieDataSet.h
Class Description
The GRPieDataSet class is a subclass of GRDataSet used to manage and draw a dataset
as a pie chart.
Properties
Key Description
GRDataSetPieStartAngle The angle at which pie wedges will start being drawn
clockwise.
Method Types
Drawing
- drawLegendSampleInRect:forWedgeIndex;
Loading data
- indexOfAngle:
Instance Methods
drawLegendSampleInRect:forWedgeIndex:
-(void) drawLegendSampleInRect:(NSRect)aRect
forWedgeIndex:(int)index
Draws a sample of the dataset’s plotting method (color, line width, ...) inside of aRect for the wedge
at index. This is used when drawing the legend.
indexOfAngle:
-(int) indexOfAngle:(double)a
Returns the index of the datapoint (element) that contains the angle a. This is used internally for
datapoint selection with the mouse.
GRPieDataSetDataSource
Adopted By:
NSObject (informal protocol)
Declared in:
GraphKit/GRPieDataSet.h
Protocol Description
The GRPieDataSetDataSource informal protocol declares the methods that a
GRPieDataSet uses to access the contents of its data source object.
Method Types
GettingValues
- chart:yValueForDataSet:element:
Instance Methods
chart:yValueForDataSet:element:
-(double) chart:(GRChartView *)aChart
yValueForDataSet:(GRDataSet *)aDataSet element:(int)index
Returns the y value at index index of the datapoint managed for aDataSet in aChart by the data
source object.
Chapter 4
GRAxes
GRAxes
Inherits from:
NSObject
Conforms to:
NSObject (NSObject)
Declared in:
GraphKit/GRAxes.h
Class Description
The GRAxes class is responsible for determining the scale and range of values to be
plotted as well as drawing any necessary ticks, grid lines, titles, or legends. There is an
instance of the GRAxes class associated with the GRChartView as well as with each
GRDataSet contained in the chart view. In overlayed mode, the GRChartView’s GRAxes
is used. In tiled mode, the GRAxes of each GRDataSet is used.
Properties
Key Description
GRAxesFixedXPlotMin
GRAcesFixedXPlotMax
GRAcesFixedYPlotMin
GRAcesFixedYPlotMax
GRAxesNoBorder
GRAxesLineBorder
GRAxesBezelBorder
GRAxesGrooveBorder
GRAxesLegendTopPosition
GRAxesLegendBottomPosition
GRAxesLegendLeftPosition
GRAxesLegendRightPosition
GRAxesLegendNoBorder
GRAxesLegendLineBorder
GRAxesLegendBezelBorder
GRAxesLegendGrooveBorder
Method Types
Manipulating default properties
+ defaultProperties
+ defaultPropertyForKey:
+ setDefaultProperty:forKey:
+ setDefaultProperties:
Manipulating properties
- propertyForKey:
- setProperty:forKey:
- setProperties:
Creating a dataset
- initWithOwner:
- owner
- chart
Setting the delegate
- setDelegate:
- delegate
Setting the identifier
- setIdentifier:
- identifier
Selection
- deselectAllPoints
- selectPoint:byExtendingSelection:
- clickPoint:
Value/Location Conversions
- xPixelValue
- yPixelValue
- xValueAtPoint:
- yValueAtPoint:
- locationForXValue:yValue:
Layout
- canvasRect
- setCanvasRect:
- plotRect
- setPlotRect:
- legendRect
- computeLayout
- setNeedsLayout:
- needsLayout
Drawing
- drawLegendRect:
- drawGridRect:
- drawAxesRect:
Class Methods
defaultProperties
+(NSDictionary *) defaultProperties
Returns a copy of the default GRAxes class properties dictionary.
defaultPropertyForKey:
+(id) defaultPropertyForKey:(NSString *)key
Returns the default property value associated with key or nil if the GRAxes class default properties
dictionary does not contain key.
setDefaultProperty:ForKey:
+(BOOL) setDefaultProperty:(id)p forKey:(NSString *)key
Sets the property value p for key in the GRAxes class default properties dictionary. Returns YES upon
success or NO in the case of an illegal key.
setDefaultProperties:
+(void) setDefaultProperties:(NSDictionary *)aDictionary
Replace the GRAxes class default properties dictionary with aDictionary.
Instance Methods
propertyForKey:
-(id) propertyForKey:(NSString *)key
Returns the property value associated with key or nil if the properties dictionary does not contain
key.
setProperty:forKey:
-(BOOL) setProperty:(id)p forKey:(NSString *)key
Sets the property value p for key in the properties dictionary. Returns YES upon success or NO in the
case of an illegal key.
setProperties:
-(void) setProperties:(NSDict *)aDict
Replace the GRAxes class properties dictionary with aDict.
initWithOwner:
-(id) initWithOwner:(id)anObject
owner
-(id) owner
chart
-(GRChartView *) chart
setDelegate:
-(void) setDelegate:(id)anObject
Sets the receiver's delegate to anObject.
delegate
-(id) delegate
Returns the receiver’s delegate.
setIdentifier:
-(void) setIdentifier:(id)anObject
Sets the receiver's identifier to anObject. This object is used by the data source and delegate to
identify the attribute corresponding to the GRAxes.
identifier
-(id) identifier
Returns the object used by the data source and delegate to identify the attribute corresponding to the
receiver.
deselectAllPoints
-(BOOL) deselectAllPoints
Sets the selected range for each dataset drawn on the axes to be [0,0) or no selection. Not
implemented in the abstract class.
selectPoint:byExtendingSelection:
-(BOOL) selectPoint:(NSPoint)aPoint
byExtendingSelection:(BOOL)extend
The datapoint index of the point aPoint is converted to the nearest datapoint in each GRDataSet
drawn on the axes and set as the respective selected range. If multiple selection is enabled and
extend is true, each dataset’s current selected range will be extended to include the new selected
point. Returns YES if aPoint was a valid point contained within the receiver’s bounds. If the point
aPoint is not within the receiver’s bounds the selected range for each dataset will be set to [0,0) or
no selection. Not Implemented in the abstract class.
clickPoint:
-(BOOL) clickPoint:(NSPoint)aPoint
Called when a point has been clicked. Not implemented in the abstract class.
xPixelValue
-(double) xPixelValue
Returns the numerical value associated with each pixel in the x direction.
yPixelValue
-(double) yPixelValue
Returns the numerical value associated with each pixel in the y direction.
xValueAtPoint:
-(double) xValueAtPoint:(NSPoint)loc
Returns the interpolated numerical value for the location loc on the x axis.
yValueAtPoint:
-(double) yValueAtPoint:(NSPoint)loc
Returns the interpolated numerical value for the location loc on the y axis.
locationForXValue:yValue:
-(NSPoint) locationForXValue:(double)x yValue:(double)y
Returns the location (NSPoint within chart) for the specified x and y values.
canvasRect
-(NSRect) canvasRect
Returns the size and position of the rectangle the axes (and it’s corresponding datasets) will be
drawn in.
setCanvasRect:
-(void) setCanvasRect:(NSRect)aRect
Resize the axes (and subsequently the datasets) to the new canvas rectangle size aRect.
plotRect
-(void) plotRect
Returns the size and position of the rectangle the axes and datasets will be drawn in.
setPlotRect
-(void) setPlotRect:(NSRect)aRect
Resizes the axes (and it’s corresponding datasets) to the new plot rectangle size aRect.
legendRect
-(NSRect) legendRect
Returns the size and position of the rectangle the legend will be drawn in.
computeLayout
-(BOOL) computeLayout
Compute the layout of the graph if needed, taking the optional legend into account automatically.
Always returns YES.
setNeedsLayout:
-(void) setNeedsLayout:(BOOL)b
Allows the graph’s layout to be recomputed with computeLayout if set to YES.
needsLayout
-(BOOL) needsLayout
Returns YES if the graph’s layout needs to be recomputed.
drawLegendRect:
-(void) drawLegendRect:(NSRect)drawRect
Draws the receiver’s legend (if any) inside the current canvas rectangle.
drawGridRect:
-(void) drawGridRect:(NSRect)drawRect
Draws the receiver’s gridlines (if any) inside the current canvas rectangle.
drawAxesRect:
-(void) drawAxesRect:(NSRect)drawRect
Draws the receiver’s axes inside the current canvas rectangle.
Returns the label string ot be used for the category at index index. This is used by the GRXYAxes
subclass for labeling axes in category mode and by the GRPieAxes for legend labels.
GRXYAxes
Inherits from:
GRAxes: NSObject
Conforms to:
NSObject (NSObject)
Declared in:
GraphKit/GRXYAxes.h
Class Description
The GRXYAxes class is a subclass of GRAxes used to determine the scale and range of
values to be plotted as well as drawing any necessary ticks, grid lines, titles, or legends.
Only dataset subclasses of the GRXYDataSet class can be plotted on GRXYAxes.
Properties
Key Description
GRAxesValueAxis
GRAxesCategoryAxis
GRAxesLinearScale
GRAxesLog10Scale
GRAxesLinearScale
GRAxesLog10Scale
GRAxesXMinSpace
GRAxesYMinSpace
Method Types
Scaling
- computeXMajorMinorUnits
- computeYMajorMinorUnits
Drawing
- drawXAxisRect:
- drawXGridRect:
- drawYAxisRect:
- drawYGridRect:
Instance Methods
computeXMajorMinorUnits
-(void) computeXMajorMinorUnits
Compute the major and minor units of the x-axis according to the canvas rectangle (bounds).
computeYMajorMinorUnits
-(void) computeYMajorMinorUnits
Compute the major and minor units of the y-axis according to the canvas rectangle (bounds).
drawXAxisRect:
-(void) drawXAxisRect:(NSRect)drawRect
Draws the receiver’s x-axis and inside the current canvas rectangle.
drawXGridRect:
-(void) drawXGridRect:(NSRect)drawRect
Draws the receiver’s x-axis gridlines (if any) inside the current canvas rectangle.
drawYAxisRect:
-(void) drawYAxisRect:(NSRect)drawRect
Draws the receiver’s y-axis and inside the current canvas rectangle.
drawYGridRect:
-(void) drawYGridRect:(NSRect)drawRect
Draws the receiver’s y-axis gridlines (if any) inside the current canvas rectangle.
chart:yLabelForAxes:value:defaultLabel:
-(NSString *) chart:(GRChartView *)aChart
yLabelForAxes:(GRXYAxes *)aAxes value:(double)val
defaultLabel:(NSString *)aString
Allows the delegate to modify or format y-axis labels. The label that would normally be used by
default for the value val is passed in as aString.
GRPieAxes
Inherits from:
GRAxes: NSObject
Conforms to:
NSObject (NSObject)
Declared in:
GraphKit/GRPieAxes.h
Class Description
The GRPieAxes class is a subclass of GRAxes used to determine the scale and range of
values to be plotted as well as drawing any necessary ticks, grid lines, titles, or legends.
Only dataset subclasses of the GRPieDataSet class can be plotted on GRPieAxes.
Chapter 5
GRGradientColor
GRGradientColor
Inherits from:
NSObject
Conforms to:
NSObject (NSObject)
Declared in:
GraphKit/GRGradientColor.h
Class Description
An GRGradientColor object represents a range of color and sometimes opacity (alpha). By sending a
fillRect: message to an GRGradientColor instance, you set the color gradient pattern for the
current drawing context. This causes subsequently drawn graphics to have the specified color
gradient pattern represented by the GRGradientColor instance.
Constants
Key Description
top.
Method Types
Creating a gradient
+gradientOfType:withColors:...
- init
- initWithColors:...
- initWithColorArray:
Modifying the colors
- addColor:
- colorCount
- colors
Modifying the gradient
- setGradientType:
- gradientType
Drawing
- fillRect:
- fillBezierPath:
- fillBezierPath:withBounds:
Class Methods
gradientOfType:withColors:...
+(id) gradientOfType:(gradient_t)aType withColors:(NSColor
*)firstColor, ...
Creates and returns a GRGradientColor representing the gradient of colors between the start color
firstColor and the end color, if present. The gradient type is specified by aType.
Instance Methods
init
-(id) init
Initializes a GRGradientColor representing a default gradient.
initWithColors:...
-(id) initWithColors:(NSColor *)aColor, ...
Initializes a GRGradientColor representing the gradient of colors between the start color aColor and
the end color, if present.
initWithColorArray:
-(id) initWithColorArray:(NSarray *)colors
Initializes a GRGradientColor representing the gradient of colors using the colors in color in their
given order.
addColor:
-(void) addColor:(NSColor *)aColor
Adds aColor to the receiver’s color array.
colorCount
-(int) colorCount
Returns the number of colors in the receivers color array.
colors
-(NSArray *) colors
Returns the receiver’s color array.
setGradientType:
-(void) setGradientType:(gradient_t)aType
Sets the receiver’s gradient fill type to be aType.
gradientType:
-(gradient_t) gradientType
Returns the receiver’s gradient fill type.
fillRect:
-(void) fillRect:(NSRect)aRect
Creates a Bezier path from the given rectangle, and uses the Bezier path to fill the receiving gradient.
fillBezierPath:
-(void) fillBezierPath:(NSBezierPath *)path
Fills the receiving gradient with the given Bezier Path.
fillBezierPath:withBounds:
-(void) fillBezierPath:(NSBezierPath *)path
withBounds:(NSRect)bounds
Fills the receiving gradient with the given Bezier path and clipping bounds.
set:
-(void) set
This function is provided for compatibility with NSColor objects. It calls set for the last color in the
array, or for black if the array is empty.
drawSwatchInRect:
-(void) drawSwatchInRect:(NSRect)aRect
This function is provided for compatibility with NSColor objects. This functions the same as
fillRect.