- allow label formatting
diff --git a/iOSPlot/Shared/PCLineChartView.h b/iOSPlot/Shared/PCLineChartView.h
index 1f46df2..c529b17 100644
--- a/iOSPlot/Shared/PCLineChartView.h
+++ b/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
diff --git a/iOSPlot/Shared/PCLineChartView.m b/iOSPlot/Shared/PCLineChartView.m
index e2adfb1..fa32238 100644
--- a/iOSPlot/Shared/PCLineChartView.m
+++ b/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 @@
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 @@
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 @@
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 @@
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