-
-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Line data chart jumps during zoom #4489
Comments
I found way to fix jump bug, but in very weird way. Unfortunately, I couldn't find source of problem. Some debug show, that it seems like you occasionally stop touch and quickly start touch again, but between this actions graph for some reason jumps on some distance on x or y points. This is a fix, that works for me and adapted for your case(In my case it jumps during Y zoom). Hope it helps you. boolean isNoTouchAfterEnd;
MPPointD startScalePoint;
public MPPointD getCenterOfViewPort(){
final ViewPortHandler handler = chart.getViewPortHandler();
final float middleX = (handler.contentRight() - handler.contentLeft()) / 2 + handler.contentLeft();
final float middleY = (handler.contentTop() - handler.contentBottom()) / 2 + handler.contentBottom();
return chart.getValuesByTouchPoint(middleX, middleY, chart.getAxisLeft().getAxisDependency());
}
chart.setOnChartGestureListener(new OnChartGestureListener() {
@Override
public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
startScalePoint = getCenterOfViewPort();
isNoTouchAfterEnd = false;
}
@Override
public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
if (lastPerformedGesture.equals(ChartTouchListener.ChartGesture.X_ZOOM)) {
isNoTouchAfterEnd = true;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (isNoTouchAfterEnd)
chart.centerViewTo((float) startScalePoint.x,
(float) startScalePoint.y,
chart.getAxisLeft().getAxisDependency());
}
}, 50);
}
}
@Override
public void onChartLongPressed(MotionEvent me) {
}
@Override
public void onChartDoubleTapped(MotionEvent me) {
}
@Override
public void onChartSingleTapped(MotionEvent me) {
}
@Override
public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
}
@Override
public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
if (scaleY == 1.0f) {
startScalePoint.x = chart.getCenterOfViewPort().x;
chart.centerViewTo((float) startScalePoint.x,
(float) startScalePoint.y,
chart.getAxisLeft().getAxisDependency());
}
}
@Override
public void onChartTranslate(MotionEvent me, float dX, float dY) {
}
}); |
Thank you, @DropDrage ! I tried the provided code. It's more like a workaround. The problem is still there. I can see the chart jumps in a millisecond. But thanks for sharing. I will take it as a reference to further investigation. |
It jumps when zoom in x axis.but when zoom in y axis it works ok. |
Summary
Line data chart jumps during zoom gesture.
Please, check the provided video:
https://youtu.be/QByOeq8UmRY
I have a line chart with two datasets on X-axis. First for the time, second for data. I tried to get into the library's code to understand is it a bug or I'm doing something wrong. But couldn't sort out inner logic from first glance. So I'm looking for the hint what place in the library to look related to such behavior (as in video).
Device
The text was updated successfully, but these errors were encountered: