Skip to content

Commit

Permalink
Allow setting maximum y-scale factor
Browse files Browse the repository at this point in the history
  • Loading branch information
david committed Sep 18, 2015
1 parent 71099b1 commit 2006671
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Charts/Classes/Utils/ChartViewPortHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions ChartsDemo/Classes/Demos/LineChart1ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2006671

Please sign in to comment.