MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

zoomAndCenterAnimated not centering on x value

Open a-bresler opened this issue 6 years ago • 7 comments

I'm trying to use the method zoomAndCenterAnimated on a line graph, but the result I get, no matter the x-value entered, is the graph zooming and centering on the very first data point.

I've tried implementing on the sample project with a simple y = x straight line graph and no matter which x;y value I choose to center on it still zooms in and centers on the first data point.

a-bresler avatar Dec 05 '18 09:12 a-bresler

I got same issue, any work around?

fullmoon6661 avatar Feb 17 '19 14:02 fullmoon6661

It happens to me as well, on the latest release of the library. Always zooms in at the first data point on the X axis.

lpbas avatar Jun 11 '19 13:06 lpbas

I did figure it out but never posted a solution.

In AnimatedZoomJob.getInstance(...) the zoomCenter variables are never set. The parameters are passed but nothing is done to it.

If @PhilJay wants I can fork and push a request, but here's the fixed method so long:

public static AnimatedZoomJob getInstance(ViewPortHandler viewPortHandler, View v, Transformer trans, YAxis axis, float xAxisRange, float scaleX, float scaleY, float xOrigin, float yOrigin, float zoomCenterX, float zoomCenterY, float zoomOriginX, float zoomOriginY, long duration) 
{

        AnimatedZoomJob result = pool.get();
        result.mViewPortHandler = viewPortHandler;
        result.xValue = scaleX;
        result.yValue = scaleY;
        result.mTrans = trans;
        result.view = v;
        result.xOrigin = xOrigin;
        result.yOrigin = yOrigin;
        result.yAxis = axis;
        result.xAxisRange = xAxisRange;
        result.resetAnimator();
        result.animator.setDuration(duration);
        result.zoomCenterX = zoomCenterX;
        result.zoomCenterY = zoomCenterY;
        result.zoomOriginX = zoomOriginX;
        result.zoomOriginY = zoomOriginY;
        return result;
    }

a-bresler avatar Jun 11 '19 14:06 a-bresler

Thanks for posting the fix here!

He hasn't merged any pull requests for the past 2 months, but I'm sure he will do so when he finds the time. Plus all of us will appreciate if you do!

lpbas avatar Jun 11 '19 15:06 lpbas

I've encountering the same issue, is the fix closed with merge?

ghost avatar Nov 16 '21 17:11 ghost

Five years later and still the same issue. I created a PR with the fix @a-bresler suggested. Hopefully it gets merged.

SimonJackler avatar Dec 18 '23 14:12 SimonJackler

Five years later and still the same issue. I created a PR with the fix @a-bresler suggested. Hopefully it gets merged.

While you wait for a merge (the last was 3 years ago), I merged it here already

hannesa2 avatar Feb 01 '24 09:02 hannesa2