Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refined look of trend sparklines

Percentage is now displayed next to the graph and the area below
the line is filled with light gray.
The percentage is displayed in black if the latest daily/weekly
report is yesterday's/last week's. Otherwise, it's gray.

Also fixed some warnings by replacing deprecated methods.
  • Loading branch information...
commit 49cf94138d31b32be78a640220c2052eb1ee933c 1 parent 7baa5c8
Ole Zorn authored
View
4 Classes/CountryCell.m
@@ -39,7 +39,7 @@ @implementation CountryCell
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
{
- if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
+ if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
UIColor *calendarBackgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
UIView *calendarBackgroundView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,45,44)] autorelease];
calendarBackgroundView.backgroundColor = calendarBackgroundColor;
@@ -69,7 +69,7 @@ - (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
graphLabel.textColor = [UIColor whiteColor];
graphLabel.text = @"## %";
- UIView *graphBackground = [[UIView alloc] initWithFrame:CGRectMake(160, 4, 130, 21)];
+ UIView *graphBackground = [[[UIView alloc] initWithFrame:CGRectMake(160, 4, 130, 21)] autorelease];
graphBackground.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1.0];
self.graphColor = [UIColor colorWithRed:0.54 green:0.61 blue:0.67 alpha:1.0];
View
2  Classes/CurrencyManager.m
@@ -226,7 +226,7 @@ - (void)refreshExchangeRates
}
[urlString appendString:@"&f=nl1"];
- NSString *csv = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
+ NSString *csv = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] usedEncoding:NULL error:NULL];
if (!csv) {
//NSLog(@"URL could not be retrieved");
[self performSelectorOnMainThread:@selector(refreshFailed) withObject:nil waitUntilDone:YES];
View
2  Classes/DayCell.m
@@ -38,7 +38,7 @@ @implementation DayCell
@synthesize graphColor;
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
- if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
+ if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
UIColor *calendarBackgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
UIView *calendarBackgroundView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,45,44)] autorelease];
calendarBackgroundView.backgroundColor = calendarBackgroundColor;
View
2  Classes/EntryCell.m
@@ -37,7 +37,7 @@ @implementation EntryCell
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
{
- if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
+ if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
iconView = [[[UIImageView alloc] initWithFrame:CGRectMake(6,6,32,32)] autorelease];
descriptionLabel = [[[UILabel alloc] initWithFrame:CGRectMake(45, 0, 270, 44)] autorelease];
descriptionLabel.font = [UIFont systemFontOfSize:15.0];
View
4 Classes/ProductCell.m
@@ -37,7 +37,7 @@ @implementation ProductCell
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
{
- if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
+ if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
UIColor *calendarBackgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
UIView *calendarBackgroundView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,45,44)] autorelease];
calendarBackgroundView.backgroundColor = calendarBackgroundColor;
@@ -67,7 +67,7 @@ - (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
self.graphColor = [UIColor colorWithRed:0.54 green:0.61 blue:0.67 alpha:1.0];
- UIView *graphBackground = [[UIView alloc] initWithFrame:CGRectMake(160, 4, 130, 21)];
+ UIView *graphBackground = [[[UIView alloc] initWithFrame:CGRectMake(160, 4, 130, 21)] autorelease];
graphBackground.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1.0];
graphView = [[[UIView alloc] initWithFrame:CGRectMake(160, 4, 130, 21)] autorelease];
View
62 Classes/RootViewController.m
@@ -109,7 +109,7 @@ - (void)refreshDailyTrend
- (UIImage *)sparklineForReports:(NSArray *)days
{
- UIGraphicsBeginImageContext(CGSizeMake(100, 25));
+ UIGraphicsBeginImageContext(CGSizeMake(120, 30));
CGContextRef c = UIGraphicsGetCurrentContext();
NSSortDescriptor *dateSorter = [[[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO] autorelease];
@@ -117,6 +117,18 @@ - (UIImage *)sparklineForReports:(NSArray *)days
if ([sortedDays count] > 7) {
sortedDays = [sortedDays subarrayWithRange:NSMakeRange(0, 7)];
}
+ BOOL reportIsLatest = NO;
+ if ([sortedDays count] > 0) {
+ Day *lastDay = [sortedDays objectAtIndex:0];
+ NSTimeInterval reportAge = [[NSDate date] timeIntervalSince1970] - [lastDay.date timeIntervalSince1970];
+ if (!lastDay.isWeek && reportAge < 172800) { //48 hours
+ reportIsLatest = YES;
+ }
+ else if (lastDay.isWeek && reportAge < 1209600) { //14 days
+ reportIsLatest = YES;
+ }
+ }
+
int maxUnitSales = 0;
NSMutableArray *unitSales = [NSMutableArray array];
for (Day *d in [sortedDays reverseObjectEnumerator]) {
@@ -126,35 +138,59 @@ - (UIImage *)sparklineForReports:(NSArray *)days
[unitSales addObject:[NSNumber numberWithInt:units]];
}
[[UIColor grayColor] set];
- float maxY = 20.0;
- float minY = 2.0;
+ float maxY = 27.0;
+ float minY = 3.0;
float minX = 2.0;
- float maxX = 95.0;
+ float maxX = 75.0;
int i = 0;
float prevX = 0.0;
float prevY = 0.0;
+ CGMutablePathRef path = CGPathCreateMutable();
+
CGContextBeginPath(c);
- CGContextSetLineWidth(c, 2.0);
- CGContextSetLineJoin(c, kCGLineJoinRound);
- CGContextSetLineCap(c, kCGLineCapRound);
for (NSNumber *sales in unitSales) {
float r = [sales floatValue];
float y = maxY - ((r / maxUnitSales) * (maxY - minY));
float x = minX + ((maxX - minX) / ([unitSales count] - 1)) * i;
if (prevX == 0.0) {
- CGContextMoveToPoint(c, x, y);
+ CGPathMoveToPoint(path, NULL, x, y);
}
else {
- CGContextAddLineToPoint(c, x, y);
+ CGPathAddLineToPoint(path, NULL, x, y);
}
prevX = x;
prevY = y;
i++;
}
- CGContextDrawPath(c, kCGPathStroke);
-
- [[UIColor colorWithRed:0.84 green:0.11 blue:0.06 alpha:1.0] set];
- CGContextFillEllipseInRect(c, CGRectMake(prevX-2, prevY-2, 4, 4));
+ if ([unitSales count] > 1) {
+ CGContextSetLineWidth(c, 1.0);
+ CGContextSetLineJoin(c, kCGLineJoinRound);
+ CGContextSetLineCap(c, kCGLineCapRound);
+
+ CGMutablePathRef fillPath = CGPathCreateMutableCopy(path);
+ CGPathAddLineToPoint(fillPath, NULL, prevX, maxY);
+ CGPathAddLineToPoint(fillPath, NULL, minX, maxY);
+ [[UIColor colorWithWhite:0.95 alpha:1.0] set];
+ CGContextAddPath(c, fillPath);
+ CGContextFillPath(c);
+ CGPathRelease(fillPath);
+
+ [[UIColor grayColor] set];
+ CGContextAddPath(c, path);
+ CGContextStrokePath(c);
+
+ [[UIColor colorWithRed:0.84 green:0.11 blue:0.06 alpha:1.0] set];
+ CGContextFillEllipseInRect(c, CGRectMake(prevX-2.5, prevY-2.5, 5, 5));
+
+ NSNumber *lastDayUnits = [unitSales lastObject];
+ NSNumber *lastButOneDayUnits = [unitSales objectAtIndex:[unitSales count]-2];
+ float percentage = ([lastDayUnits floatValue] - [lastButOneDayUnits floatValue]) / [lastButOneDayUnits floatValue];
+ int roundedPercent = (int)(percentage * 100.0);
+ NSString *percentString = (roundedPercent < 0) ? [NSString stringWithFormat:@"%i%%", roundedPercent] : [NSString stringWithFormat:@"+%i%%", roundedPercent];
+ [(reportIsLatest) ? ([UIColor blackColor]) : ([UIColor darkGrayColor]) set];
+ [percentString drawInRect:CGRectMake(80, 7, 40, 15) withFont:[UIFont boldSystemFontOfSize:12.0]];
+ }
+ CGPathRelease(path);
UIImage *trendImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
View
2  Classes/WeekCell.m
@@ -38,7 +38,7 @@ @implementation WeekCell
@synthesize graphColor;
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
- if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
+ if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
UIColor *calendarBackgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
UIView *calendarBackgroundView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,45,44)] autorelease];
calendarBackgroundView.backgroundColor = calendarBackgroundColor;
Please sign in to comment.
Something went wrong with that request. Please try again.