From 20066718d04167438d18804279f27ba958c3e551 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 18 Sep 2015 11:20:35 +0100 Subject: [PATCH] Allow setting maximum y-scale factor --- Charts/Classes/Utils/ChartViewPortHandler.swift | 14 +++++++++++++- .../Classes/Demos/LineChart1ViewController.m | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Charts/Classes/Utils/ChartViewPortHandler.swift b/Charts/Classes/Utils/ChartViewPortHandler.swift index cea55d1b9b..9d2a825614 100755 --- a/Charts/Classes/Utils/ChartViewPortHandler.swift +++ b/Charts/Classes/Utils/ChartViewPortHandler.swift @@ -25,6 +25,9 @@ public class ChartViewPortHandler: NSObject private var _chartWidth = CGFloat(0.0) private var _chartHeight = CGFloat(0.0) + /** maximum scale value on the y-axis */ + private var _maxScaleY = CGFloat(1.0) + /// minimum scale value on the y-axis private var _minScaleY = CGFloat(1.0) @@ -214,7 +217,8 @@ public class ChartViewPortHandler: NSObject _scaleX = min(max(_minScaleX, matrix.a), _maxScaleX) // min scale-y is 1 - _scaleY = max(_minScaleY, matrix.d) + _scaleY = min(max(_minScaleY, matrix.d), _maxScaleY) + var width: CGFloat = 0.0 var height: CGFloat = 0.0 @@ -273,6 +277,14 @@ public class ChartViewPortHandler: NSObject limitTransAndScale(matrix: &_touchMatrix, content: _contentRect) } + + public func setMaximumScaleY(yScale: CGFloat) + { + _maxScaleY = yScale; + + limitTransAndScale(matrix: &_touchMatrix, content: _contentRect) + } + public func setMinimumScaleY(yScale: CGFloat) { var newValue = yScale diff --git a/ChartsDemo/Classes/Demos/LineChart1ViewController.m b/ChartsDemo/Classes/Demos/LineChart1ViewController.m index 6b79bd2d50..7a471cbe4a 100644 --- a/ChartsDemo/Classes/Demos/LineChart1ViewController.m +++ b/ChartsDemo/Classes/Demos/LineChart1ViewController.m @@ -90,6 +90,9 @@ - (void)viewDidLoad _chartView.rightAxis.enabled = NO; + [_chartView.viewPortHandler setMaximumScaleY: 2.f]; + [_chartView.viewPortHandler setMaximumScaleY: 2.f]; + BalloonMarker *marker = [[BalloonMarker alloc] initWithColor:[UIColor colorWithWhite:180/255. alpha:1.0] font:[UIFont systemFontOfSize:12.0] insets: UIEdgeInsetsMake(8.0, 8.0, 20.0, 8.0)]; marker.minimumSize = CGSizeMake(80.f, 40.f); _chartView.marker = marker;