Skip to content
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

Open
dGorod opened this issue Apr 8, 2019 · 3 comments
Open

Line data chart jumps during zoom #4489

dGorod opened this issue Apr 8, 2019 · 3 comments

Comments

@dGorod
Copy link

dGorod commented Apr 8, 2019

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

  • Device: emulator, Sony Xperia X
  • Android Version: 8.0
  • Library Version: 3.1.0
@DropDrage
Copy link

DropDrage commented Jun 30, 2019

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) {
            }
    });

@dGorod
Copy link
Author

dGorod commented Jul 16, 2019

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.

@QaisBaig
Copy link

QaisBaig commented Oct 1, 2021

It jumps when zoom in x axis.but when zoom in y axis it works ok.
Have you find solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants