Skip to content

Commit

Permalink
优化缩放体验
Browse files Browse the repository at this point in the history
  • Loading branch information
donglua committed Nov 12, 2021
1 parent 8a289c1 commit d85e5a8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions chart/src/main/java/cn/jingzhuan/lib/chart2/base/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public abstract class Chart extends BitmapCachedChart {
* @see #zoomIn()
* @see #zoomOut()
*/
private static final float ZOOM_AMOUNT = 0.25f;
private static final float ZOOM_AMOUNT = 0.2f;

private Point mSurfaceSizeBuffer = new Point();
private final Point mSurfaceSizeBuffer = new Point();


// Edge effect / overscroll tracking objects.
Expand Down Expand Up @@ -222,6 +222,7 @@ private boolean hitTest(float x, float y, PointF dest) {
if (!mContentRect.contains((int) x, (int) y)) {
return false;
}

dest.set(mCurrentViewport.left
+ mCurrentViewport.width()
* (x - mContentRect.left) / mContentRect.width(),
Expand Down Expand Up @@ -316,6 +317,7 @@ else if (zoomOut)
mCurrentViewport.constrainViewport();
triggerViewportChange();
lastSpanX = spanX;

return true;
}
};
Expand All @@ -335,6 +337,7 @@ public boolean onDown(MotionEvent e) {
releaseEdgeEffects();
mScrollerStartViewport.set(mCurrentViewport);
mScroller.forceFinished(true);

postInvalidateOnAnimation();

return true;
Expand Down Expand Up @@ -446,6 +449,8 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
};

protected void triggerViewportChange() {
postInvalidateOnAnimation();

if (mInternalViewportChangeListener != null) {
mInternalViewportChangeListener.onViewportChange(mCurrentViewport);
}
Expand All @@ -460,7 +465,6 @@ protected void triggerViewportChange() {
}
}
}
postInvalidateOnAnimation();
}

private void fling(int velocityX) {
Expand Down

0 comments on commit d85e5a8

Please sign in to comment.