 |
 |
PLEASE PLEASE HELP: bezier
|
 |
|
 |
|
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
#import "viewOfGraph.h"
@implementation viewOfGraph
int sortObjects(id aTree, id bTree,void *context)
{
if ([[aTree objectForKey:context] floatValue] < [[bTree objectForKey:context] floatValue])
{
return NSOrderedAscending;
}
else if ([[aTree objectForKey:context] floatValue] > [[bTree objectForKey:context] floatValue])
{
return NSOrderedDescending;
}
return NSOrderedSame;
}
- (void)drawRect:(NSRect)frameRect
{
if([[NSFileManager defaultManager] fileExistsAtPath:[@"~/Library/Preferences/vegan.WeightTracker.DATA.plist" stringByExpandingTildeInPath]])
{
NSPoint point0;
NSPoint point1;
int i;
bezier = [NSBezierPath bezierPath];
minMaxArray = [[[[[NSDictionary dictionaryWithContentsOfFile:[@"~/Library/Preferences/vegan.WeightTracker.DATA.plist" stringByExpandingTildeInPath]] objectForKey:@"TableView"] allValues]
sortedArrayUsingFunction: sortObjects context:@"Weight"] retain];
minMaxDate = [[NSMutableArray alloc] init];
[minMaxDate setArray:[[[[NSDictionary dictionaryWithContentsOfFile:[@"~/Library/Preferences/vegan.WeightTracker.DATA.plist" stringByExpandingTildeInPath]] objectForKey:@"TableView"] allValues] sortedArrayUsingSelector:@selector(dateValueCompar eTwo:)]];
point0.x = frameRect.origin.x;
point0.y = (frameRect.size.height * ([[[minMaxDate objectAtIndex: 0] objectForKey:@"Weight"] floatValue]) / ([[[minMaxArray objectAtIndex:([minMaxArray count] -1)] objectForKey: @"Weight"] floatValue] - [[[minMaxArray objectAtIndex:0] objectForKey: @"Weight"] floatValue]));
NSLog(@"Uus x %f", point0.x);
NSLog(@"Uus y %f", point0.y);
for(i=0; i < ([minMaxDate count]); i++)
{
point1.x = point0.x + (frameRect.size.width / ([minMaxDate count]));
point1.y = (frameRect.size.height * ([[[minMaxDate objectAtIndex: i] objectForKey:@"Weight"] floatValue]) / ([[[minMaxArray objectAtIndex:([minMaxArray count] -1)] objectForKey: @"Weight"] floatValue] - [[[minMaxArray objectAtIndex:0] objectForKey: @"Weight"] floatValue]));
[bezier moveToPoint:point0];
[bezier lineToPoint:point1];
[bezier stroke];
point0.x = point1.x;
point0.y = point1.y;
}
}
}
@end
@implementation NSDictionary (DictionaryDateSortingT)
- (NSComparisonResult)dateValueCompareTwo:(NSDiction ary *)otherDictionary
{
return [(NSDate *)[self valueForKey:@"Date"] compare:[otherDictionary valueForKey:@"Date"]];
}
@end
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
2003-02-03 16:52:15.017 WeightTracker[13875] point 0.x 0.000000
2003-02-03 16:52:15.017 WeightTracker[13875] point 0.y 2053.333252
2003-02-03 16:52:15.017 WeightTracker[13875] point 1.x 73.333336
2003-02-03 16:52:15.018 WeightTracker[13875] point 1.y 2053.333252
2003-02-03 16:52:15.018 WeightTracker[13875] point 2.x 146.666672
2003-02-03 16:52:15.018 WeightTracker[13875] point 2.y 1991.111084
2003-02-03 16:52:15.018 WeightTracker[13875] point 3.x 220.000000
2003-02-03 16:52:15.018 WeightTracker[13875] point 3.y 2022.222168
2003-02-03 16:52:15.018 WeightTracker[13875] point 4.x 293.333344
2003-02-03 16:52:15.018 WeightTracker[13875] point 4.y 2084.444336
2003-02-03 16:52:15.019 WeightTracker[13875] point 5.x 366.666687
2003-02-03 16:52:15.019 WeightTracker[13875] point 5.y 2146.666748
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status:
Offline
|
|
It would likely help to pick a color...
[[NSColor colorWithCalibratedRed: .2 green: .2 blue: 1 alpha: 1] set];
|

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
Originally posted by Detrius:
It would likely help to pick a color...
[[NSColor colorWithCalibratedRed: .2 green: .2 blue: 1 alpha: 1] set];
It's not the color. If I just connect two points it draws a line. It's that it doesn't work with the "if" loop!!!
I don't know why
Coz, I need the loop... or something to plot all the data...

|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status:
Offline
|
|
So, it's the "if" at the beginning of the function that's causing a problem, and not the "for" loop? Have you tried doing a debugger trace to see which lines are actually being executed?
Also, I'm no expert, but I noticed that you are reading files in the drawRect function. I would think that would be a bad idea. Try putting the data storage elsewhere in the class. For example, make a function to read the data in from the file and store it in the object. Do this only once, not every time the display needs to be drawn. I don't know about this, but it's possible that Cocoa will not allow you to read from the disk while you have a view locked. Even if it did, I peronally think it is not a good idea.
The displayed output doesn't seem to match the code. Where is that output coming from? It doesn't look like it's output during the drawRect function.
|

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|