ZoomJob.java
2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.github.mikephil.charting.jobs;
import android.graphics.Matrix;
import android.view.View;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.utils.ObjectPool;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Created by Philipp Jahoda on 19/02/16.
*/
public class ZoomJob extends ViewPortJob {
private static ObjectPool<ZoomJob> pool;
static {
pool = ObjectPool.create(1, new ZoomJob(null, 0, 0, 0, 0, null, null, null));
pool.setReplenishPercentage(0.5f);
}
public static ZoomJob getInstance(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue,
Transformer trans, YAxis.AxisDependency axis, View v) {
ZoomJob result = pool.get();
result.xValue = xValue;
result.yValue = yValue;
result.scaleX = scaleX;
result.scaleY = scaleY;
result.mViewPortHandler = viewPortHandler;
result.mTrans = trans;
result.axisDependency = axis;
result.view = v;
return result;
}
public static void recycleInstance(ZoomJob instance) {
pool.recycle(instance);
}
protected float scaleX;
protected float scaleY;
protected YAxis.AxisDependency axisDependency;
public ZoomJob(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue, Transformer trans,
YAxis.AxisDependency axis, View v) {
super(viewPortHandler, xValue, yValue, trans, v);
this.scaleX = scaleX;
this.scaleY = scaleY;
this.axisDependency = axis;
}
protected Matrix mRunMatrixBuffer = new Matrix();
@Override
public void run() {
Matrix save = mRunMatrixBuffer;
mViewPortHandler.zoom(scaleX, scaleY, save);
mViewPortHandler.refresh(save, view, false);
float yValsInView = ((BarLineChartBase) view).getAxis(axisDependency).mAxisRange / mViewPortHandler.getScaleY();
float xValsInView = ((BarLineChartBase) view).getXAxis().mAxisRange / mViewPortHandler.getScaleX();
pts[0] = xValue - xValsInView / 2f;
pts[1] = yValue + yValsInView / 2f;
mTrans.pointValuesToPixel(pts);
mViewPortHandler.translate(pts, save);
mViewPortHandler.refresh(save, view, false);
((BarLineChartBase) view).calculateOffsets();
view.postInvalidate();
recycleInstance(this);
}
@Override
protected ObjectPool.Poolable instantiate() {
return new ZoomJob(null, 0, 0, 0, 0, null, null, null);
}
}