Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting maximum y-scale factor #388

Merged
merged 1 commit into from
Sep 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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