Skip to content

Commit

Permalink
resetZoom()
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Dec 19, 2016
1 parent a934501 commit d5e5ec3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -571,17 +571,17 @@ public void computeScroll() {
* VIEWPORT
*/

protected Matrix mZoomInMatrixBuffer = new Matrix();
protected Matrix mZoomMatrixBuffer = new Matrix();

/**
* Zooms in by 1.4f, into the charts center. center.
* Zooms in by 1.4f, into the charts center.
*/
public void zoomIn() {

MPPointF center = mViewPortHandler.getContentCenter();

mViewPortHandler.zoomIn(center.x, -center.y, mZoomInMatrixBuffer);
mViewPortHandler.refresh(mZoomInMatrixBuffer, this, false);
mViewPortHandler.zoomIn(center.x, -center.y, mZoomMatrixBuffer);
mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);

MPPointF.recycleInstance(center);

Expand All @@ -592,17 +592,15 @@ public void zoomIn() {
postInvalidate();
}

protected Matrix mZoomOutMatrixBuffer = new Matrix();

/**
* Zooms out by 0.7f, from the charts center. center.
* Zooms out by 0.7f, from the charts center.
*/
public void zoomOut() {

MPPointF center = mViewPortHandler.getContentCenter();

mViewPortHandler.zoomOut(center.x, -center.y, mZoomOutMatrixBuffer);
mViewPortHandler.refresh(mZoomOutMatrixBuffer, this, false);
mViewPortHandler.zoomOut(center.x, -center.y, mZoomMatrixBuffer);
mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);

MPPointF.recycleInstance(center);

Expand All @@ -613,7 +611,20 @@ public void zoomOut() {
postInvalidate();
}

protected Matrix mZoomMatrixBuffer = new Matrix();
/**
* Zooms out to original size.
*/
public void resetZoom() {

mViewPortHandler.resetZoom(mZoomMatrixBuffer);
mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);

// Range might have changed, which means that Y-axis labels
// could have changed in size, affecting Y-axis size.
// So we need to recalculate offsets.
calculateOffsets();
postInvalidate();
}

/**
* Zooms in or out by the given scale factor. x and y are the coordinates
Expand All @@ -625,9 +636,9 @@ public void zoomOut() {
* @param y
*/
public void zoom(float scaleX, float scaleY, float x, float y) {
Matrix save = mZoomMatrixBuffer;
mViewPortHandler.zoom(scaleX, scaleY, x, -y, save);
mViewPortHandler.refresh(save, this, false);

mViewPortHandler.zoom(scaleX, scaleY, x, -y, mZoomMatrixBuffer);
mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);

// Range might have changed, which means that Y-axis labels
// could have changed in size, affecting Y-axis size.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ public void zoomOut(float x, float y, Matrix outputMatrix) {
outputMatrix.postScale(0.7f, 0.7f, x, y);
}

/**
* Zooms out to original size.
* @param outputMatrix
*/
public void resetZoom(Matrix outputMatrix) {
outputMatrix.reset();
outputMatrix.set(mMatrixTouch);
outputMatrix.postScale(1.0f, 1.0f, 0.0f, 0.0f);
}

/**
* Post-scales by the specified scale factors.
*
Expand Down

0 comments on commit d5e5ec3

Please sign in to comment.