GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — High Level Design Overview High Level Design Overview
eskroch edited this page
This document describes the main classes of Core Plot and how they work together. Before delving into the classes that make up Core Plot, it is worth considering the design goals of the framework. Core Plot has been developed to run on both Mac OS X and iOS. This places some restrictions on the technologies that can be used: AppKit drawing is not possible, and view classes like It's not all bad news, because utilizing Core Animation also opens up a whole range of possibilities for introducing "eye-candy". Graphs can be animated, with transitions and effects. The objective is to have Core Plot be capable of not only producing publication quality still images, but also stunning graphical effects and interactivity. Another objective that is influential in the design of Core Plot is that it should behave as much as possible from a developer's perspective as a built-in framework. Design patterns and technologies used in Apple's own frameworks, such as the data source pattern, delegation, and bindings, are all supported in Core Plot. This diagram shows a standard bar graph with two data sets plotted. Below, the chart has been annotated to show the various components of the the chart, and the naming scheme used in Core Plot to identify them. This standard UML class diagram gives a static view of the main classes in the framework. The cardinality of relationships is given by a label, with a This diagram shows run time relationships between objects (right) together with layers in the Core Animation layer tree (left). Color coding shows the correspondence between objects and their corresponding layers. Core Animation's layer class, The drawing methods include: -(void)renderAsVectorInContext:(CGContextRef)context; -(void)recursivelyRenderInContext:(CGContextRef)context; -(NSData *)dataForPDFRepresentationOfLayer; When subclassing The central class of Core Plot is A graph class is fundamentally a factory: It is responsible for creating the various objects that make up the graphic, and for setting up the appropriate relationships. The @interface CPTGraph : CPTBorderedLayer @property (nonatomic, readwrite, copy) NSString *title; @property (nonatomic, readwrite, copy) CPTTextStyle *titleTextStyle; @property (nonatomic, readwrite, assign) CGPoint titleDisplacement; @property (nonatomic, readwrite, assign) CPTRectAnchor titlePlotAreaFrameAnchor; @property (nonatomic, readwrite, retain) CPTAxisSet *axisSet; @property (nonatomic, readwrite, retain) CPTPlotAreaFrame *plotAreaFrame; @property (nonatomic, readonly, retain) CPTPlotSpace *defaultPlotSpace; @property (nonatomic, readwrite, retain) NSArray *topDownLayerOrder; @property (nonatomic, readwrite, retain) CPTLegend *legend; @property (nonatomic, readwrite, assign) CPTRectAnchor legendAnchor; @property (nonatomic, readwrite, assign) CGPoint legendDisplacement; -(void)reloadData; -(void)reloadDataIfNeeded; -(NSArray *)allPlots; -(CPTPlot *)plotAtIndex:(NSUInteger)index; -(CPTPlot *)plotWithIdentifier:(id <NSCopying>)identifier; -(void)addPlot:(CPTPlot *)plot; -(void)addPlot:(CPTPlot *)plot toPlotSpace:(CPTPlotSpace *)space; -(void)removePlot:(CPTPlot *)plot; -(void)removePlotWithIdentifier:(id <NSCopying>)identifier; -(void)insertPlot:(CPTPlot *)plot atIndex:(NSUInteger)index; -(void)insertPlot:(CPTPlot *)plot atIndex:(NSUInteger)index intoPlotSpace:(CPTPlotSpace *)space; -(NSArray *)allPlotSpaces; -(CPTPlotSpace *)plotSpaceAtIndex:(NSUInteger)index; -(CPTPlotSpace *)plotSpaceWithIdentifier:(id <NSCopying>)identifier; -(void)addPlotSpace:(CPTPlotSpace *)space; -(void)removePlotSpace:(CPTPlotSpace *)plotSpace; -(void)applyTheme:(CPTTheme *)theme; @end
The plot area is that part of a graph where data is plotted. It is typically bordered by axes, and grid lines may also appear in the plot area. There is only one plot area for each graph, and it is represented by the class Plot spaces define the mapping between the coordinate space, in which a set of data exists, and the drawing space inside the plot area. For example, if you were to plot the speed of a train versus time, the data space would have time along the horizontal axis, and speed on the vertical axis. The data space may range from 0 to 150 km/hr for the speed, and 0 to 180 minutes for the time. The drawing space, on the other hand, is dictated by the bounds of the plot area. A plot space, represented by a descendant of the It is tempting to use the built in support for affine transformations to perform the mapping between the data and drawing spaces, but this would be very limiting, because the mapping does not have to be linear. For example, it is not uncommon to use a logarithmic scale for the data space. To facilitate as wide a range of data sets as possible, values in the data space can be stored internally as A -(CGPoint)plotAreaViewPointForPlotPoint:(NSDecimal *)plotPoint; -(CGPoint)plotAreaViewPointForDoublePrecisionPlotPoint:(double *)plotPoint; -(void)plotPoint:(NSDecimal *)plotPoint forPlotAreaViewPoint:(CGPoint)point; -(void)doublePrecisionPlotPoint:(double *)plotPoint forPlotAreaViewPoint:(CGPoint)point; Data coordinates—represented here by the "plot point"—are passed as an C array of Whenever an object needs to perform the transform from data to drawing coordinates, or vice versa, it should query the plot space to which it corresponds. For example, instances of It is important to realize that a single graph may contain multiple plots, and that these plots may be plotted on different scales. For example, one plot may need to be drawn with a logarithmic scale, and a separate plot may be drawn on a linear scale. There is nothing to prevent both plots appearing in a single graph. For this reason, a single A particular representation of data in a graph is known as a "plot". For example, data could be shown as a line or scatter plot, with a symbol at each data point. The same data could be represented by a bar plot/histogram. A graph can have multiple plots. Each plot can derive from a single data set, or different data sets: they are completely independent of one another. Although it may not seem like it at first glance, a plot is analogous to a table view. For example, to present a simple line plot of the speed of a train versus time, you need a value for the speed at different points in time. This data could be stored in two columns of a table view, or represented as a scatter plot. In effect, the plot and the table view are just different views of the same model data. What this means is that the same design patterns used to populate table views with data can be used to provide data to plots. In particular, you can either use the data source design pattern, or you can use bindings. To provide a plot with data using the data source approach, you set the @protocol CPTPlotDataSource <NSObject> -(NSUInteger)numberOfRecords; @optional // Implement one of the following -(NSArray *)numbersForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange; -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index; @end You can think of the field as being analogous to a column identifier in a table view, and the record index being analogous to the row index. Each type of plot has a fixed number of fields. For example, a scatter plot has two: the value of for the horizontal axis (x) and the value for the vertical axis (y). An enumeration in the typedef enum _CPTScatterPlotField { CPTScatterPlotFieldX, CPTScatterPlotFieldY } CPTScatterPlotField; A record is analogous to the row of a table view. For a scatter plot, it corresponds to a single point on the graph. Plot classes not only support the data source design pattern, but also Cocoa bindings, as a means of supplying data. This is again very similar to the approach taken with table views: each field of the plot—analogous to a table column—gets bound to a key path via an CPTGraph *graph = ...; CPTScatterPlot *boundLinePlot = [[[CPTScatterPlot alloc] initWithFrame:CGRectZero] autorelease]; boundLinePlot.identifier = @"Bindings Plot"; boundLinePlot.dataLineStyle.lineWidth = 2.f; [graph addPlot:boundLinePlot]; [boundLinePlot bind:CPTScatterPlotBindingXValues toObject:self withKeyPath:@"arrangedObjects.x" options:nil]; [boundLinePlot bind:CPTScatterPlotBindingYValues toObject:self withKeyPath:@"arrangedObjects.y" options:nil]; The superclass of all plot classes is A plot object has a close relationship to the Axes describe the scale of the plotting coordinate space to the viewer. A basic graph will have just two axes, one for the horizontal direction (x) and one for the vertical direction (y), but this is not a constraint in Core Plot—you can add as many axes as you like. Axes can appear at the sides of the plot area, but also on top of it. Axes can have different scales, and can include major and/or minor ticks, as well as labels and a title. Each axis on a graph is represented by an object of class descendant from A graph can have multiple axes, but all axes get grouped together in a single Axis labels are usually textual, but there is support in Core Plot for custom labels: any Core Animation layer can be used as an axis label by wrapping it in an instance of the A unique aspect of Core Plot is the integration of animation, which facilitates dynamic effects and interactivity. The Core Animation framework provides the mechanisms for positioning and transforming layers in time. In general you can access layers directly to apply animation. Be aware that transforming some layers, such as plots or the plot area, could invalidate the correspondence of data and axes. Clone this wiki locally |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |