Hi,

I have a few hundred points which I'm trying to draw as a scatter
plot. The origin of my plot (0,0) is in the center of my canvas where
my crosshairs are. My values in this case are no larger than 0.998 and
no less than -0.932. Though the values can always change so I'm trying
to scale my graph according the whatever values are read in.

And that's where I'm having a problem, can someone look this over and
help with my scaling? I'm trying to draw circles at each point on my
view. So if my values are between -1.0 and 1.0, then my view
boundaries should be between -1 and 1, and if I had values of -1233.0
and 2321.0, then my view boundaries should be proportional.

After looking at this a bit more, I think I may have more wrong than
scaling. But I can't figure it out.

- (void) drawRect:(NSRect) rect
{
        NSRect bounds = [self bounds];

        [[NSColor blackColor] setFill];
        [NSBezierPath fillRect:bounds];

        [self drawScatterPlotAxes];
        [self drawScatter];     
        
        return;
}


- (void) drawScatter
{
        NSRect bounds = [self bounds];

        float xFactor = (bounds.size.width * 0.5) / maxXValue;
        float yFactor = (bounds.size.height * 0.5) / maxYValue;
        
        NSBezierPath *copyPath = [circlePath copy];
        
        NSAffineTransform *xform = [NSAffineTransform transform];

        // goto center of screen where 0,0 is located to start drawing.
        [xform translateXBy:(bounds.size.width * 0.50)
                                        yBy:(bounds.size.height * 0.50)];
        [xform scaleXBy:(xFactor / 2) yBy:(yFactor / 2)];
        
        [copyPath transformUsingAffineTransform:xform];
        
        [[NSColor yellowColor] setStroke];
        
        [copyPath stroke];
        
        return;
}


- (void) addCoord:(double) xval yCoord:(double) yval
{       
        NSRect rect = NSMakeRect(xval, yval, 3, 3);
        
        [circlePath appendBezierPathWithOvalInRect:rect];
}
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to