use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class RadarHighlighter method getHighlightsAtIndex.
/**
* Returns an array of Highlight objects for the given index. The Highlight
* objects give information about the value at the selected index and the
* DataSet it belongs to. INFORMATION: This method does calculations at
* runtime. Do not over-use in performance critical situations.
*
* @param index
* @return
*/
protected List<Highlight> getHighlightsAtIndex(int index) {
mHighlightBuffer.clear();
float phaseX = mChart.getAnimator().getPhaseX();
float phaseY = mChart.getAnimator().getPhaseY();
float sliceangle = mChart.getSliceAngle();
float factor = mChart.getFactor();
MPPointF pOut = MPPointF.getInstance(0, 0);
for (int i = 0; i < mChart.getData().getDataSetCount(); i++) {
IDataSet<?> dataSet = mChart.getData().getDataSetByIndex(i);
final Entry entry = dataSet.getEntryForIndex(index);
float y = (entry.getY() - mChart.getYChartMin());
Utils.getPosition(mChart.getCenterOffsets(), y * factor * phaseY, sliceangle * index * phaseX + mChart.getRotationAngle(), pOut);
mHighlightBuffer.add(new Highlight(index, entry.getY(), pOut.x, pOut.y, i, dataSet.getAxisDependency()));
}
return mHighlightBuffer;
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class XAxisRendererHorizontalBarChart method renderAxisLabels.
@Override
public void renderAxisLabels(Canvas c) {
if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
return;
float xoffset = mXAxis.getXOffset();
mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
mAxisLabelPaint.setColor(mXAxis.getTextColor());
MPPointF pointF = MPPointF.getInstance(0, 0);
if (mXAxis.getPosition() == XAxisPosition.TOP) {
pointF.x = 0.0f;
pointF.y = 0.5f;
drawLabels(c, mViewPortHandler.contentRight() + xoffset, pointF);
} else if (mXAxis.getPosition() == XAxisPosition.TOP_INSIDE) {
pointF.x = 1.0f;
pointF.y = 0.5f;
drawLabels(c, mViewPortHandler.contentRight() - xoffset, pointF);
} else if (mXAxis.getPosition() == XAxisPosition.BOTTOM) {
pointF.x = 1.0f;
pointF.y = 0.5f;
drawLabels(c, mViewPortHandler.contentLeft() - xoffset, pointF);
} else if (mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE) {
pointF.x = 1.0f;
pointF.y = 0.5f;
drawLabels(c, mViewPortHandler.contentLeft() + xoffset, pointF);
} else {
// BOTH SIDED
pointF.x = 0.0f;
pointF.y = 0.5f;
drawLabels(c, mViewPortHandler.contentRight() + xoffset, pointF);
pointF.x = 1.0f;
pointF.y = 0.5f;
drawLabels(c, mViewPortHandler.contentLeft() - xoffset, pointF);
}
MPPointF.recycleInstance(pointF);
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class XAxisRendererRadarChart method renderAxisLabels.
@Override
public void renderAxisLabels(Canvas c) {
if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
return;
final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();
final MPPointF drawLabelAnchor = MPPointF.getInstance(0.5f, 0.25f);
mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
mAxisLabelPaint.setColor(mXAxis.getTextColor());
float sliceangle = mChart.getSliceAngle();
// calculate the factor that is needed for transforming the value to
// pixels
float factor = mChart.getFactor();
MPPointF center = mChart.getCenterOffsets();
MPPointF pOut = MPPointF.getInstance(0, 0);
for (int i = 0; i < mChart.getData().getMaxEntryCountSet().getEntryCount(); i++) {
String label = mXAxis.getValueFormatter().getFormattedValue(i, mXAxis);
float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f;
Utils.getPosition(center, mChart.getYRange() * factor + mXAxis.mLabelRotatedWidth / 2f, angle, pOut);
drawLabel(c, label, pOut.x, pOut.y - mXAxis.mLabelRotatedHeight / 2.f, drawLabelAnchor, labelRotationAngleDegrees);
}
MPPointF.recycleInstance(center);
MPPointF.recycleInstance(pOut);
MPPointF.recycleInstance(drawLabelAnchor);
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class PieChart method getMarkerPosition.
@Override
protected float[] getMarkerPosition(Highlight highlight) {
MPPointF center = getCenterCircleBox();
float r = getRadius();
float off = r / 10f * 3.6f;
if (isDrawHoleEnabled()) {
off = (r - (r / 100f * getHoleRadius())) / 2f;
}
// offset to keep things inside the chart
r -= off;
float rotationAngle = getRotationAngle();
int entryIndex = (int) highlight.getX();
// offset needed to center the drawn text in the slice
float offset = mDrawAngles[entryIndex] / 2;
// calculate the text position
float x = (float) (r * Math.cos(Math.toRadians((rotationAngle + mAbsoluteAngles[entryIndex] - offset) * mAnimator.getPhaseY())) + center.x);
float y = (float) (r * Math.sin(Math.toRadians((rotationAngle + mAbsoluteAngles[entryIndex] - offset) * mAnimator.getPhaseY())) + center.y);
MPPointF.recycleInstance(center);
return new float[] { x, y };
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class YAxisRendererRadarChart method renderAxisLabels.
@Override
public void renderAxisLabels(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
return;
mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
mAxisLabelPaint.setColor(mYAxis.getTextColor());
MPPointF center = mChart.getCenterOffsets();
MPPointF pOut = MPPointF.getInstance(0, 0);
float factor = mChart.getFactor();
final int from = mYAxis.isDrawBottomYLabelEntryEnabled() ? 0 : 1;
final int to = mYAxis.isDrawTopYLabelEntryEnabled() ? mYAxis.mEntryCount : (mYAxis.mEntryCount - 1);
for (int j = from; j < to; j++) {
float r = (mYAxis.mEntries[j] - mYAxis.mAxisMinimum) * factor;
Utils.getPosition(center, r, mChart.getRotationAngle(), pOut);
String label = mYAxis.getFormattedLabel(j);
c.drawText(label, pOut.x + 10, pOut.y, mAxisLabelPaint);
}
MPPointF.recycleInstance(center);
MPPointF.recycleInstance(pOut);
}
Aggregations