-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFLRadialItem.m
115 lines (95 loc) · 2.71 KB
/
FLRadialItem.m
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* Copyright (C) 1996 Dave Vasilevsky
* This file is licensed under the GNU General Public License,
* see the file Copying.txt for details. */
#import "FLRadialItem.h"
#import "FLRadialPainter.h"
@implementation FLRadialItem
- (id) initWithItem: (id)item
dataSource: (id)dataSource
weight: (float)weight
startAngle: (float)a1
endAngle: (float)a2
level: (int)level
{
if (self = [super init]) {
m_item = item;
m_dataSource = dataSource;
m_weight = weight;
m_startAngle = a1;
m_endAngle = a2;
m_level = level;
}
return self;
}
- (id) item
{
return m_item;
}
- (float) weight
{
return m_weight;
}
- (float) startAngle
{
return m_startAngle;
}
- (float) endAngle
{
return m_endAngle;
}
- (int) level
{
return m_level;
}
- (float) midAngle
{
return ([self startAngle] + [self endAngle]) / 2.0;
}
- (float) angleSpan
{
return [self endAngle] - [self startAngle];
}
- (NSArray *) children;
{
if ([self weight] == 0.0) {
return [NSArray array];
}
float curAngle = [self startAngle];
float anglePerWeight = [self angleSpan] / [self weight];
id item = [self item];
int m = [m_dataSource numberOfChildrenOfItem: item];
NSMutableArray *children = [NSMutableArray arrayWithCapacity: m];
int i;
for (i = 0; i < m; ++i) {
id sub = [m_dataSource child: i ofItem: item];
float subw = [m_dataSource weightOfItem: sub];
float subAngle = anglePerWeight * subw;
float nextAngle = curAngle + subAngle;
id child = [[FLRadialItem alloc] initWithItem: sub
dataSource: m_dataSource
weight: subw
startAngle: curAngle
endAngle: nextAngle
level: [self level] + 1];
[children addObject: child];
[child release];
curAngle = nextAngle;
}
return children;
}
- (NSEnumerator *)childEnumerator
{
return [[self children] objectEnumerator];
}
+ (FLRadialItem *) rootItemWithDataSource: (id)dataSource
{
float weight = [dataSource weightOfItem: nil];
FLRadialItem *ri = [[FLRadialItem alloc] initWithItem: nil
dataSource: dataSource
weight: weight
startAngle: 0
endAngle: 360
level: -1];
return [ri autorelease];
}
@end