CorePlot学习一
阅读这篇国外文章手记而已 原文地址:https://github.com/core-plot/core-plot/wiki/High-Level-Design-Overview首先,我们先看一下我们绘制图表是的区域划分:这个图标的学习很有必要,在以后的编程中,你会有深刻体会,各个区域的划分,和名称2 再来看看这个CorePlot开源图形库的类的层次结构 ,便于我们源码的理解
阅读这篇国外文章手记而已 原文地址:https://github.com/core-plot/core-plot/wiki/High-Level-Design-Overview
强烈推荐阅读该博客:http://blog.csdn.net/kmyhy/article/details/7819661
首先,我们先看一下我们绘制图表是的区域划分:
这个图标的学习很有必要,在以后的编程中,你会有深刻体会,各个区域的划分,和名称
2 再来看看这个CorePlot开源图形库的类的层次结构 ,便于我们源码的理解
3 再来看一下他的成员对象和各个层的树形结构
4 图表视图的动画层分析
UIView的核心动画层,CALayer并不适合产生高质量的矢量图形,并且它也不支持事件处理,因此,Core Plot layers继承于CPTLayer
,而CPTLayer
是CALayer的子类,只不过做了扩展。CPTLayer
包含绘图方法,可以绘制高质量的矢量图形,并且能够处理事件
绘图方法包括如下:
-(void)renderAsVectorInContext:(CGContextRef)context;
-(void)recursivelyRenderInContext:(CGContextRef)context;
-(NSData *)dataForPDFRepresentationOfLayer;
当我们绘制矢量图形时,就不用重写(override)-
drawInContext
:方法,而是只需重写-
renderAsVectorInContext
:方法即可把图形会知道窗口。
5
Graphs 分析
CPTGraph
是Core Plot的核心类,在coreplot中graph就是整个图表,包括:坐标轴,标签,标题,以及多个图表元素。
看一下该类的定义:
@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; //我目前认为是PlotArea的原点
@property (nonatomic, readwrite, retain) CPTAxisSet *axisSet; //坐标轴设置
@property (nonatomic, readwrite, retain) CPTPlotAreaFrame *plotAreaFrame; //PlotArea的fram
@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
CPTXYGraph
creates an instance of
CPTXYAxisSet
, and
CPTXYPlotSpace
6 Plot Area
这个事我们图表显示的区域,该区域被坐标轴限制在一定方位内,可以显示栅格在该区域,每个图表视图只能有一个图标区域,
7 Plot Spaces
我这里想称Plot space为图表元素原型,比如说柱状图,他有更多个柱元素组成,其中的一个就是元素原型。这时个人理解
而Plot Spaces就是元素原型和坐标系的映射关系集合,
一个PLot space 元素原型会知道图表上,必须要实现以下方法:完成数据和坐标空间的转换
-(CGPoint)plotAreaViewPointForPlotPoint:(NSDecimal *)plotPoint;
-(CGPoint)plotAreaViewPointForDoublePrecisionPlotPoint:(double *)plotPoint;
-(void)plotPoint:(NSDecimal *)plotPoint forPlotAreaViewPoint:(CGPoint)point;
-(void)doublePrecisionPlotPoint:(double *)plotPoint forPlotAreaViewPoint:(CGPoint)point;
一个graph可以包含多个原型单元的,只不过我们一般常用地就是一个而已。
8 Plots
Plot就是一个数据在图表中的表现形式,比如条形,柱状型等,
CPTPlot的dataSource
方法
@protocol CPTPlotDataSource <NSObject>
-(NSUInteger)numberOfRecords;
@optional
// Implement one of the following
-(NSArray *)numbersForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange;
-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index;
@end
9 Axes
坐标轴CPTAxis
和CPTPlotSpace
有密切关系,CPTXYAxisSet
包含多个CPTAxis
,CPTAxis
中的标签元素可以自定义的。
10 动画
更多推荐
所有评论(0)