             context.addPath(path)
             context.strokePath()
         }
-        func drawLine(start: CGPoint, end: CGPoint, color: CGColor, width: CGFloat) {
-            context.move(to: start)
-            context.addLine(to: end)
-            context.setLineWidth(width)
-            context.setStrokeColor(color)
-            context.strokePath()
-        }
         
         context.setFillColor(UIColor.white.cgColor)
         context.fill(self.bounds)

            path.move(to: CGPoint(x: drawingX, y: 0))
            path.addLine(to: CGPoint(x: drawingX, y: maxY))
        }
        // Add the horizontal axis lines
        for y in Int(ceil(bottomRight.y))...Int(floor(topLeft.y)) {
            let drawingY = CGPoint(x: 0, y: y).applying(graphingToDrawing).y

        } else {
            selectedY = nil
        }
        
        if let selectedX = selectedX, let selectedY = selectedY {
            let drawingToGraphing = gridLineView.transformFromDrawingToGraphing()
            let graphingToDrawing = drawingToGraphing.inverted()
            
            let drawingPoint = CGPoint(x: selectedX, y: selectedY).applying(graphingToDrawing)
            
            let clampedY = drawingPoint.y.clamp(lower: self.bounds.minY, upper: self.bounds.maxY)
            
            let selectedPointRadius: CGFloat = 7
            let ellipseRect = CGRect(x: drawingPoint.x, y: clampedY, width: 0, height: 0).insetBy(dx: -selectedPointRadius, dy: -selectedPointRadius)
            
            self.selectedPointLayer.path = CGPath(ellipseIn: ellipseRect, transform: nil)
        } else {
            self.selectedPointLayer.path = nil
        }
    }
    
    static let xColor = UIColor.multiplierInputColor()
    static let yColor = UIColor.adderInputColor()
    
    func update(currentStates: [Connector: ConnectorState], resolver: InputResolver) {
        
        let drawingToGraphing = gridLineView.transformFromDrawingToGraphing()
        var graphingToDrawing = drawingToGraphing.inverted()

        var lastPoint: CGPoint?
        let functionLine = CGMutablePath()
        self.functionLayer.path = nil
        
        // For each X in our bounds, figure out the Y and add the resulting graphPoint to the line
        let xVariable = "x"
        let resolvedContext = resolver([self.xConnector: 5], [self.xConnector: xVariable])
        guard let yExpression = resolvedContext.connectorValues[self.yConnector]?.Expression else {
            return
        }
        
        for drawingX in 0...Int(self.bounds.size.width) {
            let graphX = CGPoint(x: drawingX, y: 0).applying(drawingToGraphing).x
            
            var graphYNumber: NSNumber?
            graphYNumber = try? resolvedContext.mathEvaluator.evaluateExpression(yExpression, withSubstitutions:
                [ xVariable : constantExpression(number: Double(graphX)) ])
            
            guard let graphY = graphYNumber as? Double, graphY.isFinite else {
                lastPoint = nil
                continue
            }

            let newPoint = CGPoint(x: graphX, y: CGFloat(graphY)).applying(graphingToDrawing)
            let maxDrawableMagnitude: CGFloat = 10000
            guard newPoint.x.isFinite && newPoint.y.isFinite,
                abs(newPoint.x) < maxDrawableMagnitude && abs(newPoint.y) < maxDrawableMagnitude else {
                    lastPoint = nil
                    continue
            }
            
            if lastPoint == nil {
                functionLine.move(to: newPoint)
            } else {
                functionLine.addLine(to: newPoint)
            }
            lastPoint = newPoint
        }
        self.functionLayer.path = functionLine
    }
    
    func valuesForTap(at point: CGPoint) -> [Connector: Double] {
        let poinInside = point - self.frame.origin
        let graphPoint = poinInside.applying(gridLineView.transformFromDrawingToGraphing())
        
        return [xConnector: Double(graphPoint.x)]
    }
    
    func contains(_ point: CGPoint) -> Bool {
        return self.frame.contains(point)
    }
}

class GridLineView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.isOpaque = true
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.isOpaque = true
    }
    
    let scale: CGFloat = 1 / 16 // This is the scale from drawing to graphing
