Skip to content

Commit

Permalink
add some functions that can set title and legend's frame
Browse files Browse the repository at this point in the history
  • Loading branch information
pyanfield authored and whan committed Mar 4, 2013
1 parent b08140e commit c5200e1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions WSCharts/Global/WSBaseChartView.h
Expand Up @@ -100,6 +100,10 @@
@property (nonatomic) BOOL showZeroValueOnXAxis;
//coordinate view's origianl point , that bottom left of that frame.
@property (nonatomic) CGPoint coordinateOriginalPoint;
// the chart's title's position and size
@property (nonatomic) CGRect titleFrame;
// the legend's frame
@property (nonatomic) CGRect legendFrame;


- (void)drawChart:(NSArray*)arr withColor:(NSDictionary*)dict;
Expand Down
18 changes: 15 additions & 3 deletions WSCharts/Global/WSBaseChartView.m
Expand Up @@ -67,6 +67,8 @@ @implementation WSBaseChartView
@synthesize rowDistance = _rowDistance;
@synthesize showZeroValueOnYAxis = _showZeroValueOnYAxis;
@synthesize showZeroValueOnXAxis = _showZeroValueOnXAxis;
@synthesize titleFrame = _titleFrame;
@synthesize legendFrame = _legendFrame;


- (id)initWithFrame:(CGRect)frame
Expand Down Expand Up @@ -98,6 +100,8 @@ - (id)initWithFrame:(CGRect)frame
self.showZeroValueOnXAxis = NO;
self.xAxisName = @"";
self.yAxisName = @"";
_titleFrame = CGRectZero;
_legendFrame = CGRectZero;
}
return self;
}
Expand All @@ -121,7 +125,11 @@ - (void)drawChart:(NSArray *)arr withColor:(NSDictionary *)dict
titleLayer.fontSize = TITLE_FONT_SIZE;
UIFont *helveticated = [UIFont fontWithName:@"HelveticaNeue-Bold" size:TITLE_FONT_SIZE];
CGSize size = [self.title sizeWithFont:helveticated];
titleLayer.frame = CGRectMake(COORDINATE_LEFT_GAP/2, COORDINATE_TOP_GAP/2, size.width, size.height);
if (CGRectEqualToRect(self.titleFrame, CGRectZero)) {
titleLayer.frame = CGRectMake(COORDINATE_LEFT_GAP/2, COORDINATE_TOP_GAP/2, size.width, size.height);
}else{
titleLayer.frame = self.titleFrame;
}

// add the lengedn layer
__block int flag = 0;
Expand All @@ -134,8 +142,12 @@ - (void)drawChart:(NSArray *)arr withColor:(NSDictionary *)dict
flag++;
legendWidth = legendWidth > layer.frame.size.width ? legendWidth : layer.frame.size.width;
}];
legendLayer.frame = CGRectMake(self.bounds.size.width - legendWidth - COORDINATE_LEFT_GAP, 20.0, legendWidth, self.frame.size.height);

if (CGRectEqualToRect(self.legendFrame, CGRectZero)) {
legendLayer.frame = CGRectMake(self.bounds.size.width - legendWidth - COORDINATE_LEFT_GAP, 20.0, legendWidth, self.frame.size.height);
}else{
legendLayer.frame = self.legendFrame;
}

// carefully about the adding order
[self manageAllLayersOrder];
}
Expand Down
2 changes: 2 additions & 0 deletions WSChartsDemo/WSChartsDemo/ViewController.m
Expand Up @@ -171,6 +171,8 @@ - (void)createLineChart
lineChart.rowWidth = 20.0;
lineChart.title = @"Pyanfield's Line Chart";
lineChart.showZeroValueOnYAxis = YES;
//lineChart.titleFrame = CGRectMake(0.0, 0.0, 400, 50);
//lineChart.legendFrame = CGRectMake(0.0, 0.0, 400, 400);
[lineChart drawChart:arr withColor:colorDict];
lineChart.backgroundColor = [UIColor blackColor];
[self.chartView addSubview:lineChart];
Expand Down

0 comments on commit c5200e1

Please sign in to comment.