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

Adding a minimum parameter to setVisibleXRange #115

Closed
dorsoft opened this issue May 28, 2015 · 4 comments
Closed

Adding a minimum parameter to setVisibleXRange #115

dorsoft opened this issue May 28, 2015 · 4 comments
Labels

Comments

@dorsoft
Copy link

dorsoft commented May 28, 2015

I'm working on a financial app and it is critical to limit the pinch gesture zoom in.
I've managed to implement this feature, could you please add it to the master branch ?

My implementation:

  1. Add the following to BarLineChartViewBase
    public func setVisibleXRange(xMinRange: CGFloat, xMaxRange: CGFloat)
    {
    var maxScale = _deltaX / (xMinRange);
    var minScale = _deltaX / (xMaxRange);
    _viewPortHandler.setScaleXRange(minScale, maxScaleX: maxScale);
    }
  2. Add the following to ChartViewPortHandler
    A.
    /// maximum scale value on the x-axis
    private var _maxScaleX = CGFloat(FLT_MAX);

B.
public func setScaleXRange(minScaleX: CGFloat, maxScaleX: CGFloat)
{
_maxScaleX = maxScaleX;
setMinimumScaleX(minScaleX);
}

C. Inside limitTransAndScale()
/// limits the maximum scale and X translation of the given matrix
private func limitTransAndScale(inout #matrix: CGAffineTransform, content: CGRect?)
{
// min scale-x is 1f
_scaleX = max(_minScaleX, matrix.a);

    if (_scaleX > _maxScaleX)
    {
        _scaleX = _maxScaleX;
    }

.
.

Thanks

@danielgindi
Copy link
Collaborator

You could make a PR. Just make sure that if you add another argument, the
first one will be named also as the naming of the function does not reflect
the exact meaning of the first argument.

On Thu, May 28, 2015 at 5:46 PM, Dor Alon notifications@github.com wrote:

I'm working on a financial app and it is critical to limit the pinch
gesture zoom in.
I've managed to implement this feature, could you please add it to the
master branch ?

My implementation:

Add the following to BarLineChartViewBase
public func setVisibleXRange(xMinRange: CGFloat, xMaxRange: CGFloat)
{
var maxScale = _deltaX / (xMinRange);
var minScale = _deltaX / (xMaxRange);
_viewPortHandler.setScaleXRange(minScale, maxScaleX: maxScale);
}
2.

Add the following to ChartViewPortHandler
A.
/// maximum scale value on the x-axis
private var _maxScaleX = CGFloat(FLT_MAX);

B.

public func setScaleXRange(minScaleX: CGFloat, maxScaleX: CGFloat)
{
_maxScaleX = maxScaleX;
setMinimumScaleX(minScaleX);
}

C. Inside limitTransAndScale()
/// limits the maximum scale and X translation of the given matrix
private func limitTransAndScale(inout #matrix: CGAffineTransform, content:
CGRect?)
{
// min scale-x is 1f
_scaleX = max(_minScaleX, matrix.a);

if (_scaleX > _maxScaleX)
{
    _scaleX = _maxScaleX;
}

.
.

Thanks


Reply to this email directly or view it on GitHub
#115.

@dorsoft
Copy link
Author

dorsoft commented May 31, 2015

I've created a PR

@dorsoft
Copy link
Author

dorsoft commented May 31, 2015

When trying to zoom in/out using the pinch gesture when the zoom in/out limit is reached the chart starts to pan.

I've fixed this issue in the PR, I'm not sure this is the best way to do that

@danielgindi
Copy link
Collaborator

#119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants