Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PLEASE PLEASE HELP: bezier

PLEASE PLEASE HELP: bezier
Thread Tools
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Feb 3, 2003, 09:47 AM
 
#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
     
VEGAN  (op)
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Feb 3, 2003, 09:53 AM
 
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
     
VEGAN  (op)
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Feb 3, 2003, 09:55 AM
 
But... the graph doesn't appear
     
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Feb 3, 2003, 03:28 PM
 
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
     
VEGAN  (op)
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Feb 4, 2003, 04:38 AM
 
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
Reply With Quote
Feb 4, 2003, 02:55 PM
 
Originally posted by VEGAN:
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...

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
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:44 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2