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
PhilJay committed Sep 15, 2015
1 parent 2e6bfeb commit ba15207
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ protected void onCreate(Bundle savedInstanceState) {

mChart.getAxisRight().setEnabled(false);

mChart.getViewPortHandler().setMaximumScaleY(2f);
mChart.getViewPortHandler().setMaximumScaleX(2f);

// add data
setData(45, 100);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class ViewPortHandler {
/** minimum scale value on the y-axis */
private float mMinScaleY = 1f;

/** maximum scale value on the y-axis */
private float mMaxScaleY = Float.MAX_VALUE;

/** minimum scale value on the x-axis */
private float mMinScaleX = 1f;

Expand Down Expand Up @@ -285,7 +288,7 @@ public void limitTransAndScale(Matrix matrix, RectF content) {
mScaleX = Math.min(Math.max(mMinScaleX, curScaleX), mMaxScaleX);

// min scale-y is 1f
mScaleY = Math.max(mMinScaleY, curScaleY);
mScaleY = Math.min(Math.max(mMinScaleY, curScaleY), mMaxScaleY);

float width = 0f;
float height = 0f;
Expand All @@ -307,10 +310,6 @@ public void limitTransAndScale(Matrix matrix, RectF content) {
float newTransY = Math.max(Math.min(curTransY, maxTransY + mTransOffsetY), -mTransOffsetY);
mTransY = newTransY;

// if(curScaleY < mMinScaleY) {
// newTransY = (height * (mScaleY - 1f)) / 2f;
// }

vals[Matrix.MTRANS_X] = newTransX;
vals[Matrix.MSCALE_X] = mScaleX;

Expand Down Expand Up @@ -358,6 +357,13 @@ public void setMinimumScaleY(float yScale) {
limitTransAndScale(mMatrixTouch, mContentRect);
}

public void setMaximumScaleY(float yScale) {

mMaxScaleY = yScale;

limitTransAndScale(mMatrixTouch, mContentRect);
}

/**
* Returns the charts-touch matrix used for translation and scale on touch.
*
Expand Down

0 comments on commit ba15207

Please sign in to comment.