Jump to content
  • Advertisement
Sign in to follow this  
Wizumwalt

scale scatter plot

This topic is 2886 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm drawing a scatter plot and in this case, all of my points (NSRect's) in pointsArray are float values between -1 and 1. My problem is that I can't seem to scale my view according to the values of my pointsArray. So, if my values are all between -1 and 1, my view size should show a scatter plot w/ x-axis boundaries -1 to 1, so as to show my points in proportion to the screen.

Can anyone help out w/ what I'm doing wrong here?


- (void) drawScatter
{
float xFactor = 0.0;
float yFactor = 0.0;

NSRect bounds = [self bounds];

float xabs = fabs(minXValue) + fabs(maxXValue);
float yabs = fabs(minYValue) + fabs(maxYValue);

xFactor = (bounds.size.width / 2) + (bounds.size.width * 0.10);
yFactor = (bounds.size.height / 2) + (bounds.size.height * 0.10);

// Move to origin in center of screen.
NSAffineTransform *xform = [NSAffineTransform transform];
[xform translateXBy:(bounds.size.width / 2) yBy:(bounds.size.height / 2)];

if (xFactor > yFactor) {
[xform scaleBy:(xFactor / 2)];
}
else {
[xform scaleBy:(yFactor / 2)];
}

id pp;

NSEnumerator *enumerator = [pointsArray objectEnumerator];

while (pp = [enumerator nextObject]) {
NSBezierPath *pointPath = [NSBezierPath bezierPath];
[pointPath appendBezierPathWithOvalInRect:[pp point]];
[pointPath transformUsingAffineTransform:xform];

if ([pp outputResult] > 0) {
[[NSColor redColor] setStroke];
[[NSColor whiteColor] setFill];
}
else {
[[NSColor blueColor] setStroke];
[[NSColor whiteColor] setFill];
}

[pointPath stroke];
}

return;
}

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

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

[self drawScatterPlotAxes];
[self drawScatter];
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!