I am learning cocoa from the book: building cocoa application... I have followed the instruction in chapter 16 which allows me to plot any function: display is the drawRect method below:
-(void)drawRect:(NSRect )rect
{
id obj=nil;
NSEnumerator *en;
NSSize sz;
[ [NSColor whiteColor] set];
NSRectFill(rect);
sz = [self convertSize:NSMakeSize(1,1) fromView:nil];
[NSBezierPath setDefaultLineWidth:MAX(sz.width,sz.height)];
en = [displayList objectEnumerator];
while (obj = [en nextObject]) {
if (NSIntersectsRect(rect,[obj bounds]) ) {
[obj stroke];
}
}
}
This method first initializes the background to white then determine the appropriate line width for drawing the graph and sets the current line width accordingly. This is where problem lies: If xmin=ymin, xmax=ymax that is |xmin|=|ymin| =|xmax|=|ymax| such that you have a square box then everything is ok. However If xmin=-1 xmax=1 ymin=-10 ymax=10 the width of y axis is about ten times the width of x axis... I would like the axes to always have the same size. If you would like me to send the whole program folder then you can email me at
hcrogman@yahoo.com.
Thanks