@Override protected Highlight getClosestHighlight(int index, float x, float y) { IPieDataSet set = mChart.getData().getDataSet(); final Entry entry = set.getEntryForIndex(index); return new Highlight(index, entry.getY(), x, y, 0, set.getAxisDependency()); } }
final boolean drawValues = dataSet.isDrawValuesEnabled(); final PieDataSet.ValuePosition xValuePosition = dataSet.getXValuePosition(); final PieDataSet.ValuePosition yValuePosition = dataSet.getYValuePosition(); ValueFormatter formatter = dataSet.getValueFormatter(); int entryCount = dataSet.getEntryCount(); mValueLinePaint.setColor(dataSet.getValueLineColor()); mValueLinePaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getValueLineWidth())); MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset()); iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x); iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y); PieEntry entry = dataSet.getEntryForIndex(j); final float valueLineLength1 = dataSet.getValueLinePart1Length(); final float valueLineLength2 = dataSet.getValueLinePart2Length(); final float valueLinePart1OffsetPercentage = dataSet.getValueLinePart1OffsetPercentage() / 100.f; final float polyline2Width = dataSet.isValueLineVariableLength() ? labelRadius * valueLineLength2 * (float) Math.abs(Math.sin( transformedAngle * Utils.FDEG2RAD)) if (dataSet.getValueLineColor() != ColorTemplate.COLOR_NONE) { if (dataSet.isUsingSliceColorAsValueLineColor()) {
/** * Returns the index of the DataSet this x-index belongs to. * * @param xIndex * @return */ public int getDataSetIndexForIndex(int xIndex) { List<IPieDataSet> dataSets = mData.getDataSets(); for (int i = 0; i < dataSets.size(); i++) { if (dataSets.get(i).getEntryForXValue(xIndex, Float.NaN) != null) return i; } return -1; }
/** * Calculates the sliceSpace to use based on visible values and their size compared to the set sliceSpace. * * @param dataSet * @return */ protected float getSliceSpace(IPieDataSet dataSet) { if (!dataSet.isAutomaticallyDisableSliceSpacingEnabled()) return dataSet.getSliceSpace(); float spaceSizeRatio = dataSet.getSliceSpace() / mViewPortHandler.getSmallestContentExtension(); float minValueRatio = dataSet.getYMin() / mChart.getData().getYValueSum() * 2; float sliceSpace = spaceSizeRatio > minValueRatio ? 0f : dataSet.getSliceSpace(); return sliceSpace; }
/** * Returns the sum of all values in this PieData object. * * @return */ public float getYValueSum() { float sum = 0; for (int i = 0; i < getDataSet().getEntryCount(); i++) sum += getDataSet().getEntryForIndex(i).getY(); return sum; } }
.getDataSetIndex()); if (set == null || !set.isHighlightEnabled()) continue; final int entryCount = set.getEntryCount(); int visibleAngleCount = 0; for (int j = 0; j < entryCount; j++) { if ((Math.abs(set.getEntryForIndex(j).getY()) > Utils.FLOAT_EPSILON)) { visibleAngleCount++; angle = absoluteAngles[index - 1] * phaseX; final float sliceSpace = visibleAngleCount <= 1 ? 0.f : set.getSliceSpace(); float shift = set.getSelectionShift(); final float highlightedRadius = radius + shift; highlightedCircleBox.set(mChart.getCircleBox()); mRenderPaint.setColor(set.getColor(index));
if (!dataSet.isVisible()) return; float angle = mChart.getRotationAngle(); for (int j = 0; j < dataSet.getEntryCount(); j++) { Entry e = dataSet.getEntryForIndex(j); mRenderPaint.setColor(dataSet.getColor(j)); mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint);
final int entryCount = dataSet.getEntryCount(); final float[] drawAngles = mChart.getDrawAngles(); final MPPointF center = mChart.getCenterCircleBox(); for (int j = 0; j < entryCount; j++) { if ((Math.abs(dataSet.getEntryForIndex(j).getY()) > Utils.FLOAT_EPSILON)) { visibleAngleCount++; float innerRadius = userInnerRadius; Entry e = dataSet.getEntryForIndex(j); mRenderPaint.setColor(dataSet.getColor(j));
@Override public void drawData(Canvas c) { int width = (int) mViewPortHandler.getChartWidth(); int height = (int) mViewPortHandler.getChartHeight(); Bitmap drawBitmap = mDrawBitmap == null ? null : mDrawBitmap.get(); if (drawBitmap == null || (drawBitmap.getWidth() != width) || (drawBitmap.getHeight() != height)) { if (width > 0 && height > 0) { drawBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); mDrawBitmap = new WeakReference<>(drawBitmap); mBitmapCanvas = new Canvas(drawBitmap); } else return; } drawBitmap.eraseColor(Color.TRANSPARENT); PieData pieData = mChart.getData(); for (IPieDataSet set : pieData.getDataSets()) { if (set.isVisible() && set.getEntryCount() > 0) drawDataSet(c, set); } }
pds.getEntryForIndex(j).getLabel(), dataSet.getForm(), dataSet.getFormSize(), if (pds.getLabel() != null) {
@Override public Entry getEntryForHighlight(Highlight highlight) { return getDataSet().getEntryForIndex((int) highlight.getX()); }
@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); }
.getDataSetIndex()); if (set == null || !set.isHighlightEnabled()) continue; final int entryCount = set.getEntryCount(); int visibleAngleCount = 0; for (int j = 0; j < entryCount; j++) { if ((Math.abs(set.getEntryForIndex(j).getY()) > Utils.FLOAT_EPSILON)) { visibleAngleCount++; angle = absoluteAngles[index - 1] * phaseX; final float sliceSpace = visibleAngleCount <= 1 ? 0.f : set.getSliceSpace(); float shift = set.getSelectionShift(); final float highlightedRadius = radius + shift; highlightedCircleBox.set(mChart.getCircleBox()); mRenderPaint.setColor(set.getColor(index));
if (!dataSet.isVisible()) return; float angle = mChart.getRotationAngle(); for (int j = 0; j < dataSet.getEntryCount(); j++) { Entry e = dataSet.getEntryForIndex(j); mRenderPaint.setColor(dataSet.getColor(j)); mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint);
/** * Calculates the sliceSpace to use based on visible values and their size compared to the set sliceSpace. * * @param dataSet * @return */ protected float getSliceSpace(IPieDataSet dataSet) { if (!dataSet.isAutomaticallyDisableSliceSpacingEnabled()) return dataSet.getSliceSpace(); float spaceSizeRatio = dataSet.getSliceSpace() / mViewPortHandler.getSmallestContentExtension(); float minValueRatio = dataSet.getYMin() / mChart.getData().getYValueSum() * 2; float sliceSpace = spaceSizeRatio > minValueRatio ? 0f : dataSet.getSliceSpace(); return sliceSpace; }
final int entryCount = dataSet.getEntryCount(); final float[] drawAngles = mChart.getDrawAngles(); final MPPointF center = mChart.getCenterCircleBox(); for (int j = 0; j < entryCount; j++) { if ((Math.abs(dataSet.getEntryForIndex(j).getY()) > Utils.FLOAT_EPSILON)) { visibleAngleCount++; float innerRadius = userInnerRadius; Entry e = dataSet.getEntryForIndex(j); mRenderPaint.setColor(dataSet.getColor(j));
for (int j = 0; j < set.getEntryCount(); j++) { float drawAngle = calcAngle(Math.abs(set.getEntryForIndex(j).getY()), yValueSum);
@Override public void drawData(Canvas c) { int width = (int) mViewPortHandler.getChartWidth(); int height = (int) mViewPortHandler.getChartHeight(); if (mDrawBitmap == null || (mDrawBitmap.get().getWidth() != width) || (mDrawBitmap.get().getHeight() != height)) { if (width > 0 && height > 0) { mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444)); mBitmapCanvas = new Canvas(mDrawBitmap.get()); } else return; } mDrawBitmap.get().eraseColor(Color.TRANSPARENT); PieData pieData = mChart.getData(); for (IPieDataSet set : pieData.getDataSets()) { if (set.isVisible() && set.getEntryCount() > 0) drawDataSet(c, set); } }
pds.getEntryForIndex(j).getLabel(), dataSet.getForm(), dataSet.getFormSize(), if (pds.getLabel() != null) {