Source

CS193P Assignment 1 / Calculator / GraphingViewController.m

Full commit
//
//  GraphingViewController.m
//  Calculator
//
//  Created by Jay Yu on 21/07/12.
//  Copyright (c) 2012 JayYu.com. All rights reserved.
//

#import "GraphingViewController.h"
#import "GraphingView.h"
#import "CalculatorBrain.h"

@interface GraphingViewController ()
@property (nonatomic, strong) id program;
@property (nonatomic, strong) NSDictionary *variables;
@property (readonly) NSString *title;

@end

@implementation GraphingViewController
@synthesize graphingView = _graphingView;
@synthesize program = _program;
@synthesize variables = _variables;

- (NSString *)title
{
    return [CalculatorBrain descriptionOfProgram:self.program];
}

- (void)setGraphingView:(GraphingView *)graphingView
{
    _graphingView = graphingView;
    self.graphingView.dataSource = self;

    // enable pinch gestures in the FaceView using its pinch: handler
    [self.graphingView addGestureRecognizer:[[UIPinchGestureRecognizer alloc] initWithTarget:self.graphingView action:@selector(pinch:)]];
}

- (void)setup
{
    
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

- (void)initProgram:(id)program
{
    self.program = program; 
}

- (double)yAxisValue:(GraphingView *)sender atXAxis:(double)xAxis
{
    NSDictionary *vars = [NSDictionary dictionaryWithObjectsAndKeys:
                          [NSNumber numberWithDouble:xAxis], @"x", nil];
    
    double yAxis = [CalculatorBrain runProgram:self.program usingVariableValues:vars];
    NSLog(@"yAxis: x axis: %f, y axis: %f", xAxis, yAxis);
    
    return yAxis;
    
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [self setGraphingView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

@end