This repository was archived by the owner on Jan 15, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGraphController.m
More file actions
executable file
·420 lines (377 loc) · 11.6 KB
/
Copy pathGraphController.m
File metadata and controls
executable file
·420 lines (377 loc) · 11.6 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
//
// GraphController.m
// Eavesdrop
//
// Created by Eric Baur on 12/18/04.
// Copyright 2004 Eric Shore Baur. All rights reserved.
//
#import "GraphController.h"
@implementation GraphController
+ (void)initialize //may not need this one...
{
// [self setKeys:[NSArray arrayWithObjects:@"setContent", @"dataSet", @"selection", nil]
// triggerChangeNotificationsForDependentKey:@"content"];
}
- (instancetype)init
{
//NSLog( @"[GraphController init]" );
self = [super init];
if (self) {
independentTag = GCPacketIDTag;
dependentTag = GCDeltaTag;
chartDisplayTag = GCDeltaTag;
minY=minX=0;
maxY=maxX=1;
}
return self;
}
- (void)awakeFromNib
{
[self bind:@"conversation" toObject:conversationController
withKeyPath:@"selection.myself" options:nil ];
}
#pragma mark accessor methods
- (void)setConversation:(Conversation *)newConversation
{
//NSLog( @"[GraphController setConversation:]" );
[conversation release];
conversation = [newConversation retain];
if (conversation!=nil) {
[self refreshGraph];
[self refreshPieChart];
}
}
- (void)setIndependentTag:(GCVariableType)newTag
{
ENTRY(NSLog( @"changing independent tag from %d to %d", independentTag, newTag ));
independentTag = newTag;
[self refreshGraph];
}
- (void)setDependentTag:(GCVariableType)newTag
{
ENTRY(NSLog( @"changing dependent tag from %d to %d", dependentTag, newTag ));
dependentTag = newTag;
[self refreshGraph];
}
- (void)setChartDisplayTag:(GCVariableType)newTag
{
ENTRY(NSLog( @"changing chart display tag from %d to %d", chartDisplayTag, newTag ));
chartDisplayTag = newTag;
[self refreshPieChart];
}
- (void)setSourceTag:(int)newTag
{
ENTRY(NSLog( @"changing source tag from %d to %d", sourceTag, newTag ));
sourceTag = newTag;
[self refreshGraph];
}
- (void)setGraphType:(GCGraphType)newType
{
ENTRY(NSLog( @"changing graph type from %d to %d", graphType, newType ));
graphType = newType;
[self refreshGraph];
}
- (NSString *)identifierForTag:(GCVariableType)tag
{
switch (tag) {
case GCPacketIDTag: return GCPacketIDIdentifier; break;
case GCPacketNumberTag: return GCPacketNumberIdentifier; break;
case GCTimeTag: return GCTimeIdentifier; break;
case GCTotalSizeTag: return GCTotalSizeIdentifier; break;
case GCPayloadLengthTag:return GCPayloadLengthIdentifier; break;
case GCWindowTag: return GCWindowIdentifier; break;
case GCDeltaTag: return GCDeltaIdentifier; break;
default: return nil;
}
}
- (NSString *)stringForTag:(GCVariableType)tag
{
switch (tag) {
case GCPacketIDTag: return GCPacketIDString; break;
case GCPacketNumberTag: return GCPacketNumberString; break;
case GCTimeTag: return GCTimeString; break;
case GCTotalSizeTag: return GCTotalSizeString; break;
case GCPayloadLengthTag:return GCPayloadLengthString; break;
case GCWindowTag: return GCWindowString; break;
case GCDeltaTag: return GCDeltaString; break;
default: return nil;
}
}
- (void)refreshGraph
{
ENTRY(NSLog( @"[GraphController refresh]" ));
[dataSet release];
[dataSet2 release];
switch( sourceTag ) {
case GCAllPacketsTag:
INFO(NSLog( @"gathering data for all packets" ));
dataSet = [conversation
dataSetWithKeys:@[[self identifierForTag:dependentTag]]
independent:[self identifierForTag:independentTag]
forHost:nil
];
dataSet2 = nil;
break;
case GCClientOnlyTag:
ENTRY(NSLog( @"gathering data for client" ));
dataSet = [conversation
dataSetWithKeys:@[[self identifierForTag:dependentTag]]
independent:[self identifierForTag:independentTag]
forHost:conversation.source
];
dataSet2 = nil;
break;
case GCServerOnlyTag:
ENTRY(NSLog( @"gathering data for server" ));
dataSet = [conversation
dataSetWithKeys:@[[self identifierForTag:dependentTag]]
independent:[self identifierForTag:independentTag]
forHost:conversation.destination
];
dataSet2 = nil;
break;
case GCBothHostsTag:
ENTRY(NSLog( @"gathering data for both hosts" ));
if (graphType==GCBarGraphType) {
dataSet = [conversation
dataSetWithKeys:@[[self identifierForTag:dependentTag],@"source"]
independent:[self identifierForTag:independentTag]
forHost:nil
];
dataSet2 = nil;
} else {
dataSet = [conversation
dataSetWithKeys:@[[self identifierForTag:dependentTag]]
independent:[self identifierForTag:independentTag]
forHost:conversation.source
];
dataSet2 = [conversation
dataSetWithKeys:@[[self identifierForTag:dependentTag]]
independent:[self identifierForTag:independentTag]
forHost:conversation.destination
];
}
break;
case GCAllwFlagsTag:
ENTRY(NSLog( @"gathering data for all packets with tags" ));
dataSet = [conversation
dataSetWithKeys:@[[self identifierForTag:dependentTag], @"flagNums"]
independent:[self identifierForTag:independentTag]
forHost:nil
];
dataSet2 = nil;
break;
default:
NSLog( @"GraphController: no valid source tag set! No refresh will be performed" );
dataSet = nil;
dataSet2 = nil;
return;
}
if (dataSet.count)
[dataSet retain];
else
dataSet = nil;
if (dataSet2.count)
[dataSet2 retain];
else
dataSet2 = nil;
minX = 0;
minY = 0;
if (dataSet.maximum<dataSet2.maximum)
maxY = dataSet2.maximum * 1.1;
else
maxY = dataSet.maximum * 1.1;
if (dataSet.domainMaximum<dataSet2.domainMaximum)
maxX = dataSet2.domainMaximum;
else
maxX = dataSet.domainMaximum;
INFO(NSLog( @"\n X range: %f -> %f\n Y range: %f -> %f\n", minX, maxX, minY, maxY ));
[parentGraphView setLabel:[self stringForTag:dependentTag] forAxis:kSM2DGraph_Axis_Y_Left];
[parentGraphView setLabel:[self stringForTag:independentTag] forAxis:kSM2DGraph_Axis_X];
[parentGraphView reloadData];
[parentGraphView reloadAttributes];
}
- (void)refreshPieChart
{
NSEnumerator *en;
NSDictionary *tempDict;
NSString *client, *server;
double clientDelta = 0;
double serverDelta = 0;
[pieChartArray release];
switch (chartDisplayTag) {
case GCTotalSizeTag:
pieChartArray = @[[conversation valueForKey:@"sbytes"],
[conversation valueForKey:@"dbytes"]];
break;
case GCPayloadLengthTag:
pieChartArray = @[[NSNumber numberWithInt:conversation.clientPayload.length ],
[NSNumber numberWithInt:conversation.serverPayload.length ]];
break;
case GCDeltaTag:
en = [conversation.payloadArrayBySource objectEnumerator];
client = conversation.source;
server = conversation.destination;
while (tempDict=[en nextObject]) {
if ([tempDict[@"source"] isEqualToString:client])
clientDelta += [tempDict[@"timeDelta"] doubleValue];
else if ([tempDict[@"source"] isEqualToString:server])
serverDelta += [tempDict[@"timeDelta"] doubleValue];
}
pieChartArray = @[@(clientDelta),
@(serverDelta)];
break;
default:
pieChartArray = nil;
break;
}
[pieChartArray retain];
[parentPieChartView reloadData];
[parentPieChartView reloadAttributes];
}
#pragma mark SM2DGraphView datasource methods
- (unsigned int)numberOfLinesInTwoDGraphView:(SM2DGraphView *)inGraphView
{
switch( sourceTag ) {
case GCBothHostsTag:
if (graphType==GCBarGraphType)
return 1;
else
return 2;
break;
case GCAllPacketsTag:
case GCClientOnlyTag:
case GCServerOnlyTag:
return 1;
break;
case GCAllwFlagsTag:
return 9;
break;
default:
NSLog( @"GraphController: no valid source tag set!" );
return 0;
}
}
- (NSDictionary *)twoDGraphView:(SM2DGraphView *)inGraphView attributesForLineIndex:(unsigned int)inLineIndex
{
ENTRY(NSLog( @"getting COLOR" ));
NSColor *graphColor;
if ( inLineIndex==0 && (sourceTag==GCClientOnlyTag || sourceTag==GCBothHostsTag) ) {
graphColor = [NSColor redColor];
} else if (inLineIndex==1 || sourceTag==GCServerOnlyTag ) {
graphColor = [NSColor blueColor];
} else if ( sourceTag==GCAllwFlagsTag ) {
switch (inLineIndex) {
case 0: graphColor = [NSColor greenColor]; break;
case 1: graphColor = [NSColor yellowColor]; break;
case 2: graphColor = [NSColor brownColor]; break;
case 3: graphColor = [NSColor blueColor]; break;
case 4: graphColor = [NSColor blackColor]; break;
case 5: graphColor = [NSColor blackColor]; break;
case 6: graphColor = [NSColor magentaColor]; break;
case 7: graphColor = [NSColor redColor]; break;
default: graphColor = [NSColor grayColor];
}
} else {
graphColor = [NSColor blackColor];
}
if (graphType==GCBarGraphType) {
return @{NSForegroundColorAttributeName: graphColor,
SM2DGraphBarStyleAttributeName: @"on"};
} else if (graphType==GCScatterPlotType) {
return @{NSForegroundColorAttributeName: graphColor,
SM2DGraphLineSymbolAttributeName: @(kSM2DGraph_Symbol_FilledCircle),
SM2DGraphLineWidthAttributeName: @(kSM2DGraph_Width_None)};
} else {
return @{NSForegroundColorAttributeName: graphColor,
SM2DGraphLineSymbolAttributeName: @(kSM2DGraph_Symbol_FilledCircle)};
}
}
- (NSArray *)twoDGraphView:(SM2DGraphView *)inGraphView dataForLineIndex:(unsigned int)inLineIndex
{
ENTRY(NSLog( @"[GraphController twoDGraphView:dataForLineIndex:]" ));
if ( sourceTag!=GCAllwFlagsTag && inLineIndex==0 ) {
if (dataSet) {
return dataSet.dataPointsForCurrentIdentifier;
} else {
return nil;
}
} else if ( sourceTag!=GCAllwFlagsTag && inLineIndex==1 ) {
if (dataSet2) {
return dataSet2.dataPointsForCurrentIdentifier;
} else {
return nil;
}
} else if ( sourceTag==GCAllwFlagsTag ) {
if (dataSet) {
return [dataSet dataPointsForCurrentIdentifierWithKey:@"flagNums" equalTo:inLineIndex];
} else {
return nil;
}
}
return nil;
}
- (double)twoDGraphView:(SM2DGraphView *)inGraphView maximumValueForLineIndex:(unsigned int)inLineIndex
forAxis:(SM2DGraphAxisEnum)inAxis
{
if (inAxis==kSM2DGraph_Axis_Y_Left || inAxis==kSM2DGraph_Axis_Y_Right) {
return maxY;
} else if (inAxis==kSM2DGraph_Axis_X) {
return maxX;
} else {
return 1;
}
}
- (double)twoDGraphView:(SM2DGraphView *)inGraphView minimumValueForLineIndex:(unsigned int)inLineIndex
forAxis:(SM2DGraphAxisEnum)inAxis
{
if (inAxis==kSM2DGraph_Axis_Y_Left || inAxis==kSM2DGraph_Axis_Y_Right) {
return minY;
} else if (inAxis==kSM2DGraph_Axis_X) {
return minX;
} else {
return 0;
}
}
#pragma mark SM2DGraphView delegate methods
- (void)twoDGraphView:(SM2DGraphView *)inGraphView willDisplayBarIndex:(unsigned int)inBarIndex
forLineIndex:(unsigned int)inLineIndex withAttributes:(NSMutableDictionary *)attr
{
if ( sourceTag==GCAllwFlagsTag ) {
//do nothing, it should be the right color already... maybe
} else {
int source = [dataSet valueAtIndex:inBarIndex forKey:@"source" ];
INFO(NSLog( @"source = %d", source ));
if (graphType==GCBarGraphType) {
if (source==-1)
attr[NSForegroundColorAttributeName] = [NSColor blueColor];
else if (source==1)
attr[NSForegroundColorAttributeName] = [NSColor redColor];
else
attr[NSForegroundColorAttributeName] = [NSColor blackColor];
}
}
}
#pragma mark SMPieChartView datasource methods
- (unsigned int)numberOfSlicesInPieChartView:(SMPieChartView *)inPieChartView
{
return 2;
}
- (NSDictionary *)pieChartView:(SMPieChartView *)inPieChartView attributesForSliceIndex:(unsigned int)inSliceIndex
{
if (inSliceIndex==0) {
return @{NSBackgroundColorAttributeName: [NSColor redColor],
NSForegroundColorAttributeName: [NSColor clearColor]};
} else if (inSliceIndex==1) {
return @{NSBackgroundColorAttributeName: [NSColor blueColor],
NSForegroundColorAttributeName: [NSColor clearColor]};
} else {
return @{NSBackgroundColorAttributeName: [NSColor blackColor],
NSForegroundColorAttributeName: [NSColor clearColor]};
}
}
- (NSArray *)pieChartViewArrayOfSliceData:(SMPieChartView *)inPieChartView
{
return pieChartArray;
}
@end