-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathZXReportGraphView.m
More file actions
73 lines (66 loc) · 2.54 KB
/
Copy pathZXReportGraphView.m
File metadata and controls
73 lines (66 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Name: ZXReportGraphView.m
* Project: Strongbox
* Created on: 2008-06-07
*
* Copyright (C) 2008 Pierre-Hans Corcoran
*
* --------------------------------------------------------------------------
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (version 2) as published
* by the Free Software Foundation. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have
* received a copy of the GNU General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* --------------------------------------------------------------------------
*/
#import "ZXReportGraphView.h"
#import "ZXReportSection.h"
@implementation ZXReportGraphView
- (void)drawRect:(NSRect)rect
{
float radius = rect.size.height / 2;
if(rect.size.width < rect.size.height) {
radius = rect.size.width / 2;
}
NSPoint center = NSMakePoint(radius, rect.size.height - radius);
NSBezierPath *path;
double currentAngle = 90;
id sortDesc = [NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"amount"
ascending:YES] autorelease]];
[allSections sortUsingDescriptors:sortDesc];
if ([allSections count] < 1)
{
// FIXME: Magic error message
id attr = [NSDictionary dictionaryWithObjectsAndKeys:[NSColor redColor], @"NSColor", nil];
NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"No Information Available"
attributes:attr];
NSPoint p = NSMakePoint((rect.size.width - [string size].width) / 2,rect.size.height - 20);
[string drawAtPoint:p];
[string release];
return;
}
double totalAmount = [[self valueForKeyPath:@"allSections.@sum.amount"] doubleValue];
for(ZXReportSection *section in allSections)
{
double endAngle = currentAngle - 360 * [section fractionForTotal:totalAmount];
[section.color set];
path = [NSBezierPath bezierPath];
[path moveToPoint:center];
[path appendBezierPathWithArcWithCenter:center
radius:radius
startAngle:currentAngle
endAngle:endAngle
clockwise:YES];
[path closePath];
[path fill];
[[NSColor whiteColor] set];
[path setLineWidth:0.5];
[path stroke];
currentAngle = endAngle;
}
}
@end