use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class PieChart method calculateOffsets.
@Override
public void calculateOffsets() {
super.calculateOffsets();
// prevent nullpointer when no data set
if (mData == null)
return;
float diameter = getDiameter();
float radius = diameter / 2f;
MPPointF c = getCenterOffsets();
float shift = mData.getDataSet().getSelectionShift();
// create the circle box that will contain the pie-chart (the bounds of
// the pie-chart)
mCircleBox.set(c.x - radius + shift, c.y - radius + shift, c.x + radius - shift, c.y + radius - shift);
MPPointF.recycleInstance(c);
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class PieRadarChartBase method getAngleForPoint.
/**
* returns the angle relative to the chart center for the given point on the
* chart in degrees. The angle is always between 0 and 360°, 0° is NORTH,
* 90° is EAST, ...
*
* @param x
* @param y
* @return
*/
public float getAngleForPoint(float x, float y) {
MPPointF c = getCenterOffsets();
double tx = x - c.x, ty = y - c.y;
double length = Math.sqrt(tx * tx + ty * ty);
double r = Math.acos(ty / length);
float angle = (float) Math.toDegrees(r);
if (x > c.x)
angle = 360f - angle;
// add 90° because chart starts EAST
angle = angle + 90f;
// neutralize overflow
if (angle > 360f)
angle = angle - 360f;
MPPointF.recycleInstance(c);
return angle;
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class PieRadarChartBase method getPosition.
/**
* Returns a recyclable MPPointF instance.
* Calculates the position around a center point, depending on the distance
* from the center, and the angle of the position around the center.
*
* @param center
* @param dist
* @param angle in degrees, converted to radians internally
* @return
*/
public MPPointF getPosition(MPPointF center, float dist, float angle) {
MPPointF p = MPPointF.getInstance(0, 0);
getPosition(center, dist, angle, p);
return p;
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class PieRadarChartBase method distanceToCenter.
/**
* Returns the distance of a certain point on the chart to the center of the
* chart.
*
* @param x
* @param y
* @return
*/
public float distanceToCenter(float x, float y) {
MPPointF c = getCenterOffsets();
float dist = 0f;
float xDist = 0f;
float yDist = 0f;
if (x > c.x) {
xDist = x - c.x;
} else {
xDist = c.x - x;
}
if (y > c.y) {
yDist = y - c.y;
} else {
yDist = c.y - y;
}
// pythagoras
dist = (float) Math.sqrt(Math.pow(xDist, 2.0) + Math.pow(yDist, 2.0));
MPPointF.recycleInstance(c);
return dist;
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class BarLineChartTouchListener method onDoubleTap.
@Override
public boolean onDoubleTap(MotionEvent e) {
mLastGesture = ChartGesture.DOUBLE_TAP;
OnChartGestureListener l = mChart.getOnChartGestureListener();
if (l != null) {
l.onChartDoubleTapped(e);
}
// check if double-tap zooming is enabled
if (mChart.isDoubleTapToZoomEnabled() && mChart.getData().getEntryCount() > 0) {
MPPointF trans = getTrans(e.getX(), e.getY());
mChart.zoom(mChart.isScaleXEnabled() ? 1.4f : 1f, mChart.isScaleYEnabled() ? 1.4f : 1f, trans.x, trans.y);
if (mChart.isLogEnabled())
Log.i("BarlineChartTouch", "Double-Tap, Zooming In, x: " + trans.x + ", y: " + trans.y);
MPPointF.recycleInstance(trans);
}
return super.onDoubleTap(e);
}
Aggregations