Skip to content

Commit

Permalink
修改touchlistener drag逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
VinsonGuo committed Sep 14, 2018
1 parent d2b6796 commit 3a139d1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData;
import com.github.mikephil.charting.data.Entry;
Expand Down Expand Up @@ -295,11 +296,6 @@ private void saveTouchStart(MotionEvent event) {
*/
private void performDrag(MotionEvent event) {

mLastGesture = ChartGesture.DRAG;

mMatrix.set(mSavedMatrix);

OnChartGestureListener l = mChart.getOnChartGestureListener();

float dX, dY;

Expand All @@ -319,11 +315,19 @@ private void performDrag(MotionEvent event) {
dY = event.getY() - mTouchStartPoint.y;
}

MPPointD point = mChart.getTransformer(YAxis.AxisDependency.LEFT).getValuesByTouchPoint(mTouchStartPoint.x, mTouchStartPoint.y);
// 如果向右滑,而且手指不在有效区域内
if (dX < 0 && point.x > mChart.getRealCount()) {
// 如果向右滑,而且最后的坐标不在有效区域内
XAxis xAxis = mChart.getXAxis();
float lastX = xAxis.mEntries[xAxis.mEntryCount - 1];
if(dX < 0 && lastX > mChart.getRealCount() - 1) {
return;
}

mLastGesture = ChartGesture.DRAG;

mMatrix.set(mSavedMatrix);

OnChartGestureListener l = mChart.getOnChartGestureListener();

mMatrix.postTranslate(dX, dY);

if (l != null)
Expand Down Expand Up @@ -396,12 +400,14 @@ private void performZoom(MotionEvent event) {
mMatrix.set(mSavedMatrix);
// 这里是自己改的
MPPointD point = mChart.getTransformer(YAxis.AxisDependency.LEFT).getValuesByTouchPoint(mTouchPointCenter.x, mTouchPointCenter.y);
if (mChart.getRealCount() > 0 && point.x > mChart.getRealCount()) {
// 手指的点不在图表的有效区域内,放大第一个
if (point.x > mChart.getRealCount()) {
mMatrix.postScale(scaleX, 1f, 0, t.y);
} else {
// 这里是原来的
mMatrix.postScale(scaleX, 1f, t.x, t.y);
}
MPPointD.recycleInstance(point);

if (l != null)
l.onChartScale(event, scaleX, 1f);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android-kline是Android平台的金融图表库,包括**分时图**和**K线
}
}
dependencies {
compile 'com.github.VinsonGuo:android-kline:1.0.5'
compile 'com.github.VinsonGuo:android-kline:1.0.6'
}
```

Expand Down

0 comments on commit 3a139d1

Please # to comment.