Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- allow label formatting

  • Loading branch information...
commit 9ee9a98272bdef497c3b4c72dd18b8d89bda3029 1 parent 9b2b48a
@honcheng authored
View
3  iOSPlot/Shared/PCLineChartView.h
@@ -39,11 +39,12 @@
NSArray *points;
UIColor *colour;
BOOL shouldLabelValues;
+ NSString *labelFormat;
}
@property (nonatomic, assign) BOOL shouldLabelValues;
@property (nonatomic, retain) NSArray *points;
@property (nonatomic, retain) UIColor *colour;
-@property (nonatomic, retain) NSString *title;
+@property (nonatomic, retain) NSString *title, *labelFormat;
@end
View
22 iOSPlot/Shared/PCLineChartView.m
@@ -34,14 +34,26 @@
#import "PCLineChartView.h"
@implementation PCLineChartViewComponent
-@synthesize title, points, colour, shouldLabelValues;
+@synthesize title, points, colour, shouldLabelValues, labelFormat;
-(void) dealloc
{
+ [labelFormat release];
[points release];
[colour release];
[title release];
[super dealloc];
}
+
+- (id)init
+{
+ self = [super init];
+ if (self)
+ {
+ self.labelFormat = @"%.1f%%";
+ }
+ return self;
+}
+
@end
@implementation PCLineChartView
@@ -126,7 +138,7 @@ - (void)drawRect:(CGRect)rect
float div_width = (self.frame.size.width-2*margin)/([self.xLabels count]-1);
for (NSUInteger i=0; i<[self.xLabels count]; i++)
{
- if (i % numXIntervals == 1 ) {
+ if (i % numXIntervals == 1 || numXIntervals==1) {
int x = (int) (margin + div_width * i);
NSString *x_label = [NSString stringWithFormat:@"%@", [self.xLabels objectAtIndex:i]];
CGRect textFrame = CGRectMake(x - 100, self.frame.size.height - x_label_height, 200, x_label_height);
@@ -232,7 +244,7 @@ - (void)drawRect:(CGRect)rect
if (y1 > y_level)
{
CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f);
- NSString *perc_label = [NSString stringWithFormat:@"%.1f%%", value];
+ NSString *perc_label = [NSString stringWithFormat:[[components objectAtIndex:j] labelFormat], value];
CGRect textFrame = CGRectMake(x-25,y1, 50,20);
[perc_label drawInRect:textFrame
withFont:valueLabelFont
@@ -243,7 +255,7 @@ - (void)drawRect:(CGRect)rect
else if (y2 < y_level+20 && y2 < self.frame.size.height-top_margin-bottom_margin)
{
CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f);
- NSString *perc_label = [NSString stringWithFormat:@"%.1f%%", value];
+ NSString *perc_label = [NSString stringWithFormat:[[components objectAtIndex:j] labelFormat], value];
CGRect textFrame = CGRectMake(x-25,y2, 50,20);
[perc_label drawInRect:textFrame
withFont:valueLabelFont
@@ -254,7 +266,7 @@ - (void)drawRect:(CGRect)rect
else
{
CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f);
- NSString *perc_label = [NSString stringWithFormat:@"%.1f%%", value];
+ NSString *perc_label = [NSString stringWithFormat:[[components objectAtIndex:j] labelFormat], value];
CGRect textFrame = CGRectMake(x-50,y-10, 50,20);
[perc_label drawInRect:textFrame
withFont:valueLabelFont
Please sign in to comment.
Something went wrong with that request. Please try again.