diff --git a/MPChartExample/AndroidManifest.xml b/MPChartExample/AndroidManifest.xml index d1ba13a5..9ac8651d 100644 --- a/MPChartExample/AndroidManifest.xml +++ b/MPChartExample/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="5" + android:versionName="1.0.5" > = 0) - yleft = Utils.calcTextWidth(mYLabelPaint, (int) mDeltaY + ".000" + mUnit); + yleft = Utils.calcTextWidth(mYLabelPaint, (int) mDeltaY + ".00" + mUnit); else - yleft = Utils.calcTextWidth(mYLabelPaint, (int) (mDeltaY * -1) + ".000" + mUnit); + yleft = Utils.calcTextWidth(mYLabelPaint, (int) (mDeltaY * -1) + ".00" + mUnit); mYLabelPaint.setTextAlign(Align.RIGHT); } else if (mYLabels.getPosition() == YLabelPosition.RIGHT) { if (mYChartMin >= 0) - yright = Utils.calcTextWidth(mYLabelPaint, (int) mDeltaY + ".000" + mUnit); + yright = Utils.calcTextWidth(mYLabelPaint, (int) mDeltaY + ".00" + mUnit); else - yright = Utils.calcTextWidth(mYLabelPaint, (int) (mDeltaY * -1) + ".000" + mUnit); + yright = Utils.calcTextWidth(mYLabelPaint, (int) (mDeltaY * -1) + ".00" + mUnit); mYLabelPaint.setTextAlign(Align.LEFT); @@ -349,9 +349,9 @@ public abstract class BarLineChartBase extends Chart { float width = 0f; if (mYChartMin >= 0) - width = Utils.calcTextWidth(mYLabelPaint, (int) mDeltaY + ".000" + mUnit); + width = Utils.calcTextWidth(mYLabelPaint, (int) mDeltaY + ".00" + mUnit); else - width = Utils.calcTextWidth(mYLabelPaint, (int) (mDeltaY * -1) + ".000" + mUnit); + width = Utils.calcTextWidth(mYLabelPaint, (int) (mDeltaY * -1) + ".00" + mUnit); yright = width; yleft = width; diff --git a/MPChartLib/src/com/github/mikephil/charting/charts/PieChart.java b/MPChartLib/src/com/github/mikephil/charting/charts/PieChart.java index 2ad64a1c..6bf6bddf 100644 --- a/MPChartLib/src/com/github/mikephil/charting/charts/PieChart.java +++ b/MPChartLib/src/com/github/mikephil/charting/charts/PieChart.java @@ -58,6 +58,9 @@ public class PieChart extends Chart { /** indicates the selection distance of a pie slice */ private float mShift = 20f; + /** the space in degrees between the chart-slices, default 0f */ + private float mSliceSpace = 0f; + /** * indicates the size of the hole in the center of the piechart, default: * radius / 2 @@ -191,7 +194,7 @@ public class PieChart extends Chart { } @Override - protected void calculateOffsets() { + protected void calculateOffsets() { if (mDrawLegend) { if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART) { @@ -386,7 +389,8 @@ public class PieChart extends Chart { // redefine the rect that contains the arc so that the // highlighted pie is not cut off - mDrawCanvas.drawArc(highlighted, angle, sliceDegrees, true, mRenderPaint); + mDrawCanvas.drawArc(highlighted, angle + mSliceSpace / 2f, sliceDegrees + - mSliceSpace / 2f, true, mRenderPaint); } } } @@ -416,7 +420,8 @@ public class PieChart extends Chart { if (!needsHighlight(entries.get(j).getXIndex(), i)) { mRenderPaint.setColor(colors.get(j % colors.size())); - mDrawCanvas.drawArc(mCircleBox, angle, newangle, true, mRenderPaint); + mDrawCanvas.drawArc(mCircleBox, angle + mSliceSpace / 2f, newangle + - mSliceSpace / 2f, true, mRenderPaint); } angle += newangle; @@ -887,6 +892,32 @@ public class PieChart extends Chart { mCenterTextPaint.setTextSize(Utils.convertDpToPixel(size)); } + /** + * sets the space that is left out between the piechart-slices, default: 0° + * --> no space, maximum 45, minimum 0 (no space) + * + * @param degrees + */ + public void setSliceSpace(float degrees) { + + if (degrees > 45) + degrees = 45f; + if (degrees < 0) + degrees = 0f; + + mSliceSpace = degrees; + } + + /** + * returns the space that is set to be between the piechart-slices, in + * degrees + * + * @return + */ + public float getSliceSpace() { + return mSliceSpace; + } + /** * sets the radius of the hole in the center of the piechart in percent of * the maximum radius (max = the radius of the whole chart), default 50% diff --git a/MPChartLib/src/com/github/mikephil/charting/listener/BarLineChartTouchListener.java b/MPChartLib/src/com/github/mikephil/charting/listener/BarLineChartTouchListener.java index a31dfbac..dcd68e90 100644 --- a/MPChartLib/src/com/github/mikephil/charting/listener/BarLineChartTouchListener.java +++ b/MPChartLib/src/com/github/mikephil/charting/listener/BarLineChartTouchListener.java @@ -379,8 +379,9 @@ public class BarLineChartTouchListener extends SimpleOnGestureListener implement Highlight h = mChart.getHighlightByTouchPoint(e.getX(), e.getY()); - if (h == null || h.equals(mLastHighlighted)) { + if (h == null || h.equalTo(mLastHighlighted)) { mChart.highlightValues(null); + mLastHighlighted = null; } else { mLastHighlighted = h; mChart.highlightValues(new Highlight[] { diff --git a/MPChartLib/src/com/github/mikephil/charting/listener/PieChartTouchListener.java b/MPChartLib/src/com/github/mikephil/charting/listener/PieChartTouchListener.java index 82be24a7..21435d40 100644 --- a/MPChartLib/src/com/github/mikephil/charting/listener/PieChartTouchListener.java +++ b/MPChartLib/src/com/github/mikephil/charting/listener/PieChartTouchListener.java @@ -1,9 +1,6 @@ package com.github.mikephil.charting.listener; -import com.github.mikephil.charting.charts.PieChart; -import com.github.mikephil.charting.utils.Highlight; - import android.graphics.Matrix; import android.graphics.PointF; import android.view.GestureDetector; @@ -12,6 +9,9 @@ import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; +import com.github.mikephil.charting.charts.PieChart; +import com.github.mikephil.charting.utils.Highlight; + public class PieChartTouchListener extends SimpleOnGestureListener implements OnTouchListener { private static final float MAX_SCALE = Float.MAX_VALUE; // 10f; @@ -78,36 +78,6 @@ public class PieChartTouchListener extends SimpleOnGestureListener implements On return matrix; } - // @Override - // public boolean onDoubleTap(MotionEvent e) { - // - // float[] values = new float[9]; - // matrix.getValues(values); - // float sX = values[Matrix.MSCALE_X]; - // float minScale = minScale(); - // - // if (sX > minScale * 1.5f) { - // matrix.postScale(0.5f, 0.5f, e.getX(), e.getY()); - // } else { - // matrix.postScale(2, 2, e.getX(), e.getY()); - // } - // limitScale(); - // limitPan(); - // ctx.update(); - // - // return true; - // } - -// @Override -// public boolean onSingleTapConfirmed(MotionEvent e) { -// -// PointF pointF = calcImagePosition(start); -// -// -// -// return super.onSingleTapConfirmed(e); -// } - @Override public void onLongPress(MotionEvent arg0) { if (mode == NONE) { @@ -120,6 +90,9 @@ public class PieChartTouchListener extends SimpleOnGestureListener implements On public boolean onSingleTapConfirmed(MotionEvent e) { return true; } + + /** reference to the last highlighted object */ + private Highlight mLastHighlight = null; @Override public boolean onSingleTapUp(MotionEvent e) { @@ -130,15 +103,24 @@ public class PieChartTouchListener extends SimpleOnGestureListener implements On if(distance < mChart.getRadius() / 2 || distance > mChart.getRadius()) { // if no slice was touched, highlight nothing - mChart.highlightValues(null); + mChart.highlightValues(null); + mLastHighlight = null; } else { int index = mChart.getIndexForAngle(mChart.getAngleForPoint(e.getX(), e.getY())); int dataSetIndex = mChart.getDataSetIndexForIndex(index); - - if(dataSetIndex == -1) mChart.highlightValues(null); - mChart.highlightValues(new Highlight[] { new Highlight(index, dataSetIndex) }); + Highlight h = new Highlight(index, dataSetIndex); + + if(h.equalTo(mLastHighlight)) { + + mChart.highlightValues(null); + mLastHighlight = null; + } else { + + mChart.highlightValues(new Highlight[] { h }); + mLastHighlight = h; + } } return true; diff --git a/MPChartLib/src/com/github/mikephil/charting/utils/Highlight.java b/MPChartLib/src/com/github/mikephil/charting/utils/Highlight.java index 9306929a..75a7559e 100644 --- a/MPChartLib/src/com/github/mikephil/charting/utils/Highlight.java +++ b/MPChartLib/src/com/github/mikephil/charting/utils/Highlight.java @@ -1,3 +1,4 @@ + package com.github.mikephil.charting.utils; /** @@ -7,53 +8,56 @@ package com.github.mikephil.charting.utils; */ public class Highlight { - /** the x-index of the highlighted value */ - private int mXIndex; + /** the x-index of the highlighted value */ + private int mXIndex; - /** the index of the dataset the highlighted value is in */ - private int mDataSetIndex; + /** the index of the dataset the highlighted value is in */ + private int mDataSetIndex; - /** - * constructor - * - * @param x - * the index of the highlighted value on the x-axis - * @param dataSet - * the index of the DataSet the highlighted value belongs to - */ - public Highlight(int x, int dataSet) { - this.mXIndex = x; - this.mDataSetIndex = dataSet; - } + /** + * constructor + * + * @param x the index of the highlighted value on the x-axis + * @param dataSet the index of the DataSet the highlighted value belongs to + */ + public Highlight(int x, int dataSet) { + this.mXIndex = x; + this.mDataSetIndex = dataSet; + } - /** - * returns the index of the DataSet the highlighted value is in - * - * @return - */ - public int getDataSetIndex() { - return mDataSetIndex; - } + /** + * returns the index of the DataSet the highlighted value is in + * + * @return + */ + public int getDataSetIndex() { + return mDataSetIndex; + } - /** - * returns the index of the highlighted value on the x-axis - * - * @return - */ - public int getXIndex() { - return mXIndex; - } + /** + * returns the index of the highlighted value on the x-axis + * + * @return + */ + public int getXIndex() { + return mXIndex; + } - @Override - public boolean equals(Object o) { - if (this != null && o != null) { - if (o instanceof Highlight) { - Highlight other = (Highlight) o; - if (mXIndex == other.mXIndex && mDataSetIndex == other.mDataSetIndex) { - return true; - } - } - } - return false; - } + /** + * returns true if this highlight object is equal to the other + * + * @param h + * @return + */ + public boolean equalTo(Highlight h) { + + if (h == null) + return false; + else { + if (this.mDataSetIndex == h.mDataSetIndex && this.mXIndex == h.mXIndex) + return true; + else + return false; + } + } } diff --git a/screenshots/piechart_holeradius_space.png b/screenshots/piechart_holeradius_space.png new file mode 100644 index 00000000..204c9c93 Binary files /dev/null and b/screenshots/piechart_holeradius_space.png differ