     }
     
     @objc func onPan(sender: UIPanGestureRecognizer) {
+        
+        guard let chartSettings = chart?.settings else {return}
+        
+        func finalPanDelta(deltaX deltaX: CGFloat, deltaY: CGFloat) -> (deltaX: CGFloat, deltaY: CGFloat) {
+            switch chartSettings.zoomPanGestureMode {
+            case .OnlyX: return (deltaX, 0)
+            case .OnlyY: return (0, deltaY)
+            case .Max:
+                if isPanningX == nil {
+                    isPanningX = abs(deltaX) > abs(deltaY)
+                }
+                return isPanningX! ? (deltaX, 0) : (0, deltaY)
+            case .Both: return (deltaX, deltaY)
+            }
+        }
         
         switch sender.state {
             
         case .Began:
             lastPanTranslation = nil
+            isPanningX = nil
             
         case .Changed:
             

    
    public var maxZoomY: CGFloat?
    
    public init() {}
}

public protocol ChartDelegate {

    @objc func onPinch(sender: UIPinchGestureRecognizer) {
        
        guard sender.numberOfTouches() > 1 else {return}
        guard let chartSettings = chart?.settings else {return}
        
        let center = sender.locationInView(self)
        
        let x = abs(sender.locationInView(self).x - sender.locationOfTouch(1, inView: self).x)
        let y = abs(sender.locationInView(self).y - sender.locationOfTouch(1, inView: self).y)
        
        let (deltaX, deltaY): (CGFloat, CGFloat) = {
            switch chartSettings.zoomPanGestureMode {
            case .OnlyX: return (sender.scale, 1)
            case .OnlyY: return (1, sender.scale)
            case .Max: return x > y ? (sender.scale, 1) : (1, sender.scale)
            case .Both:
                // calculate scale x and scale y
                let (absMax, absMin) = x > y ? (abs(x), abs(y)) : (abs(y), abs(x))
                let minScale = (absMin * (sender.scale - 1) / absMax) + 1
                return x > y ? (sender.scale, minScale) : (minScale, sender.scale)
            }
        }()
        
        chart?.zoom(deltaX: deltaX, deltaY: deltaY, centerX: center.x, centerY: center.y, isGesture: true)
        
