diff --git a/MPChartLib/src/main/AndroidManifest.xml b/MPChartLib/src/main/AndroidManifest.xml index d75f87c7e2..aa7350cec2 100644 --- a/MPChartLib/src/main/AndroidManifest.xml +++ b/MPChartLib/src/main/AndroidManifest.xml @@ -1,13 +1,8 @@ - - - + android:supportsRtl="true" /> \ No newline at end of file diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java index 0926dff244..59504b96b9 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java @@ -1671,4 +1671,16 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { mViewPortHandler.refresh(mViewPortHandler.getMatrixTouch(), this, true); } } + + /** + * Sets the text color to use for the labels. Make sure to use + * getResources().getColor(...) when using a color from the resources. + * + * @param color + */ + public void setTextColor(int color) { + mAxisRendererLeft.setTextColor(color); + mAxisRendererRight.setTextColor(color); + mXAxisRenderer.setTextColor(color); + } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java index 5cf49ea9d1..f200a505c9 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java @@ -784,13 +784,11 @@ protected void drawMarkers(Canvas canvas) { if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight()) return; - for (int i = 0; i < mIndicesToHighlight.length; i++) { - - Highlight highlight = mIndicesToHighlight[i]; + for (Highlight highlight : mIndicesToHighlight) { IDataSet set = mData.getDataSetByIndex(highlight.getDataSetIndex()); - Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]); + Entry e = mData.getEntryForHighlight(highlight); int entryIndex = set.getEntryIndex(e); // make sure entry not null diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java index de11b3a844..8259856ab7 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java @@ -300,10 +300,9 @@ public boolean needsHighlight(int index) { if (!valuesToHighlight()) return false; - for (int i = 0; i < mIndicesToHighlight.length; i++) - - // check if the xvalue for the given dataset needs highlight - if ((int) mIndicesToHighlight[i].getX() == index) + // check if the xvalue for the given dataset needs highlight + for (Highlight highlight : mIndicesToHighlight) + if ((int) highlight.getX() == index) return true; return false; diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java index c90b4fc9b9..88cdf3855b 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java @@ -593,7 +593,7 @@ public void disableGridDashedLine() { * @return */ public boolean isGridDashedLineEnabled() { - return mGridDashPathEffect == null ? false : true; + return mGridDashPathEffect != null; } /** @@ -645,7 +645,7 @@ public void disableAxisLineDashedLine() { * @return */ public boolean isAxisLineDashedLineEnabled() { - return mAxisLineDashPathEffect == null ? false : true; + return mAxisLineDashPathEffect != null; } /** @@ -813,4 +813,14 @@ public void setSpaceMax(float mSpaceMax) { this.mSpaceMax = mSpaceMax; } + + /** + * Sets the text color to use for the labels. Make sure to use + * getResources().getColor(...) when using a color from the resources. + * + * @param color + */ + public void setTextColor(int color) { + mTextColor = color; + } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java index 7e7445cac7..b2b3798b6c 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java @@ -92,8 +92,8 @@ public abstract class BaseDataSet implements IDataSet { * Default constructor. */ public BaseDataSet() { - mColors = new ArrayList(); - mValueColors = new ArrayList(); + mColors = new ArrayList<>(); + mValueColors = new ArrayList<>(); // default color mColors.add(Color.rgb(140, 234, 255)); @@ -201,7 +201,7 @@ public void setColors(int[] colors, Context c) { */ public void addColor(int color) { if (mColors == null) - mColors = new ArrayList(); + mColors = new ArrayList<>(); mColors.add(color); } @@ -244,7 +244,7 @@ public void setColors(int[] colors, int alpha) { */ public void resetColors() { if (mColors == null) { - mColors = new ArrayList(); + mColors = new ArrayList<>(); } mColors.clear(); } @@ -499,7 +499,6 @@ protected void copy(BaseDataSet baseDataSet) { baseDataSet.mIconsOffset = mIconsOffset; baseDataSet.mValueColors = mValueColors; baseDataSet.mValueFormatter = mValueFormatter; - baseDataSet.mValueColors = mValueColors; baseDataSet.mValueTextSize = mValueTextSize; baseDataSet.mVisible = mVisible; } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java index 72ea2d17c8..a908764259 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java @@ -290,4 +290,14 @@ else if (last == first && n == 0) { * @param c */ public abstract void renderLimitLines(Canvas c); + + /** + * Sets the text color to use for the labels. Make sure to use + * getResources().getColor(...) when using a color from the resources. + * + * @param color + */ + public void setTextColor(int color) { + mAxis.setTextColor(color); + } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java index f35c775d45..dc523140d0 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java @@ -1034,12 +1034,12 @@ protected void drawRoundedSlices(Canvas c) { // draw only if the value is greater than zero if ((Math.abs(e.getY()) > Utils.FLOAT_EPSILON)) { + double v = Math.toRadians((angle + sliceAngle) + * phaseY); float x = (float) ((r - circleRadius) - * Math.cos(Math.toRadians((angle + sliceAngle) - * phaseY)) + center.x); + * Math.cos(v) + center.x); float y = (float) ((r - circleRadius) - * Math.sin(Math.toRadians((angle + sliceAngle) - * phaseY)) + center.y); + * Math.sin(v) + center.y); mRenderPaint.setColor(dataSet.getColor(j)); mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint); @@ -1051,7 +1051,7 @@ protected void drawRoundedSlices(Canvas c) { } /** - * Releases the drawing bitmap. This should be called when {@link LineChart#onDetachedFromWindow()}. + * Releases the drawing bitmap. This should be called when . */ public void releaseBitmap() { if (mBitmapCanvas != null) { diff --git a/MPChartLib/src/test/java/com/github/mikephil/charting/test/ApproximatorTest.java b/MPChartLib/src/test/java/com/github/mikephil/charting/test/ApproximatorTest.java index 784c290ceb..1f60ebe47d 100644 --- a/MPChartLib/src/test/java/com/github/mikephil/charting/test/ApproximatorTest.java +++ b/MPChartLib/src/test/java/com/github/mikephil/charting/test/ApproximatorTest.java @@ -1,15 +1,11 @@ package com.github.mikephil.charting.test; -import com.github.mikephil.charting.data.Entry; +import static junit.framework.Assert.assertEquals; + import com.github.mikephil.charting.data.filter.Approximator; import org.junit.Test; -import java.util.ArrayList; -import java.util.List; - -import static junit.framework.Assert.assertEquals; - /** * Created by philipp on 07/06/16. */ @@ -18,19 +14,7 @@ public class ApproximatorTest { @Test public void testApproximation() { - float[] points = new float[]{ - 10, 20, - 20, 30, - 25, 25, - 30, 28, - 31, 31, - 33, 33, - 40, 40, - 44, 40, - 48, 23, - 50, 20, - 55, 20, - 60, 25}; + float[] points = new float[]{10, 20, 20, 30, 25, 25, 30, 28, 31, 31, 33, 33, 40, 40, 44, 40, 48, 23, 50, 20, 55, 20, 60, 25}; assertEquals(24, points.length); diff --git a/MPChartLib/src/test/java/com/github/mikephil/charting/test/BarDataTest.java b/MPChartLib/src/test/java/com/github/mikephil/charting/test/BarDataTest.java index 99954bce27..9f9d79e843 100644 --- a/MPChartLib/src/test/java/com/github/mikephil/charting/test/BarDataTest.java +++ b/MPChartLib/src/test/java/com/github/mikephil/charting/test/BarDataTest.java @@ -5,6 +5,7 @@ import com.github.mikephil.charting.data.BarEntry; import org.junit.Test; +import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.List; @@ -25,7 +26,7 @@ public void testGroupBars() { List values1 = new ArrayList<>(); List values2 = new ArrayList<>(); - for(int i = 0; i < 5; i++) { + for (int i = 0; i < 5; i++) { values1.add(new BarEntry(i, 50)); values2.add(new BarEntry(i, 60)); } diff --git a/MPChartLib/src/test/java/com/github/mikephil/charting/test/DataSetTest.java b/MPChartLib/src/test/java/com/github/mikephil/charting/test/DataSetTest.java index 3be28d2a57..054db7f47c 100644 --- a/MPChartLib/src/test/java/com/github/mikephil/charting/test/DataSetTest.java +++ b/MPChartLib/src/test/java/com/github/mikephil/charting/test/DataSetTest.java @@ -21,7 +21,7 @@ public class DataSetTest { @Test public void testCalcMinMax() { - List entries = new ArrayList(); + List entries = new ArrayList<>(); entries.add(new Entry(10, 10)); entries.add(new Entry(15, 2)); entries.add(new Entry(21, 5)); @@ -58,7 +58,7 @@ public void testCalcMinMax() { @Test public void testAddRemoveEntry() { - List entries = new ArrayList(); + List entries = new ArrayList<>(); entries.add(new Entry(10, 10)); entries.add(new Entry(15, 2)); entries.add(new Entry(21, 5)); @@ -143,7 +143,7 @@ public void testAddRemoveEntry() { @Test public void testGetEntryForXValue() { - List entries = new ArrayList(); + List entries = new ArrayList<>(); entries.add(new Entry(10, 10)); entries.add(new Entry(15, 5)); entries.add(new Entry(21, 5)); @@ -183,7 +183,7 @@ public void testGetEntryForXValue() { public void testGetEntryForXValueWithDuplicates() { // sorted list of values (by x position) - List values = new ArrayList(); + List values = new ArrayList<>(); values.add(new Entry(0, 10)); values.add(new Entry(1, 20)); values.add(new Entry(2, 30)); diff --git a/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java b/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java index e1dbe81be9..e65fced33b 100644 --- a/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java +++ b/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java @@ -5,6 +5,8 @@ import junit.framework.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.List; @@ -12,51 +14,52 @@ /** * Created by otheruser on 6/28/16. */ +@RunWith(MockitoJUnitRunner.class) public class ObjectPoolTest { - static class TestPoolable extends ObjectPool.Poolable{ + static class TestPoolable extends ObjectPool.Poolable { private static ObjectPool pool; static { - pool = ObjectPool.create(4, new TestPoolable(0,0)); + pool = ObjectPool.create(4, new TestPoolable(0, 0)); } public int foo = 0; public int bar = 0; - protected ObjectPool.Poolable instantiate(){ - return new TestPoolable(0,0); + protected ObjectPool.Poolable instantiate() { + return new TestPoolable(0, 0); } - private TestPoolable(int foo, int bar){ + private TestPoolable(int foo, int bar) { this.foo = foo; this.bar = bar; } - public static TestPoolable getInstance(int foo, int bar){ + public static TestPoolable getInstance(int foo, int bar) { TestPoolable result = pool.get(); result.foo = foo; result.bar = bar; return result; } - public static void recycleInstance(TestPoolable instance){ + public static void recycleInstance(TestPoolable instance) { pool.recycle(instance); } - public static void recycleInstances(List instances){ + public static void recycleInstances(List instances) { pool.recycle(instances); } - public static ObjectPool getPool(){ + public static ObjectPool getPool() { return pool; } } @Test - public void testObjectPool(){ + public void testObjectPool() { int poolCapacity = TestPoolable.getPool().getPoolCapacity(); int poolCount = TestPoolable.getPool().getPoolCount(); @@ -66,7 +69,7 @@ public void testObjectPool(){ Assert.assertEquals(4, poolCapacity); Assert.assertEquals(4, poolCount); - testPoolable = TestPoolable.getInstance(6,7); + testPoolable = TestPoolable.getInstance(6, 7); Assert.assertEquals(6, testPoolable.foo); Assert.assertEquals(7, testPoolable.bar); @@ -84,7 +87,7 @@ public void testObjectPool(){ Assert.assertEquals(4, poolCount); - testPoolable = TestPoolable.getInstance(20,30); + testPoolable = TestPoolable.getInstance(20, 30); Assert.assertEquals(20, testPoolable.foo); Assert.assertEquals(30, testPoolable.bar); @@ -95,10 +98,10 @@ public void testObjectPool(){ Assert.assertEquals(4, poolCapacity); Assert.assertEquals(4, poolCount); - testPoolables.add(TestPoolable.getInstance(12,24)); - testPoolables.add(TestPoolable.getInstance(1,2)); - testPoolables.add(TestPoolable.getInstance(3,5)); - testPoolables.add(TestPoolable.getInstance(6,8)); + testPoolables.add(TestPoolable.getInstance(12, 24)); + testPoolables.add(TestPoolable.getInstance(1, 2)); + testPoolables.add(TestPoolable.getInstance(3, 5)); + testPoolables.add(TestPoolable.getInstance(6, 8)); poolCapacity = TestPoolable.getPool().getPoolCapacity(); poolCount = TestPoolable.getPool().getPoolCount(); @@ -115,11 +118,11 @@ public void testObjectPool(){ testPoolables.clear(); - testPoolables.add(TestPoolable.getInstance(12,24)); - testPoolables.add(TestPoolable.getInstance(1,2)); - testPoolables.add(TestPoolable.getInstance(3,5)); - testPoolables.add(TestPoolable.getInstance(6,8)); - testPoolables.add(TestPoolable.getInstance(8,9)); + testPoolables.add(TestPoolable.getInstance(12, 24)); + testPoolables.add(TestPoolable.getInstance(1, 2)); + testPoolables.add(TestPoolable.getInstance(3, 5)); + testPoolables.add(TestPoolable.getInstance(6, 8)); + testPoolables.add(TestPoolable.getInstance(8, 9)); Assert.assertEquals(12, testPoolables.get(0).foo); Assert.assertEquals(24, testPoolables.get(0).bar); Assert.assertEquals(1, testPoolables.get(1).foo); @@ -146,16 +149,16 @@ public void testObjectPool(){ testPoolables.clear(); - testPoolables.add(TestPoolable.getInstance(0,0)); - testPoolables.add(TestPoolable.getInstance(6,8)); - testPoolables.add(TestPoolable.getInstance(1,2)); - testPoolables.add(TestPoolable.getInstance(3,5)); - testPoolables.add(TestPoolable.getInstance(8,9)); - testPoolables.add(TestPoolable.getInstance(12,24)); - testPoolables.add(TestPoolable.getInstance(12,24)); - testPoolables.add(TestPoolable.getInstance(12,24)); - testPoolables.add(TestPoolable.getInstance(6,8)); - testPoolables.add(TestPoolable.getInstance(6,8)); + testPoolables.add(TestPoolable.getInstance(0, 0)); + testPoolables.add(TestPoolable.getInstance(6, 8)); + testPoolables.add(TestPoolable.getInstance(1, 2)); + testPoolables.add(TestPoolable.getInstance(3, 5)); + testPoolables.add(TestPoolable.getInstance(8, 9)); + testPoolables.add(TestPoolable.getInstance(12, 24)); + testPoolables.add(TestPoolable.getInstance(12, 24)); + testPoolables.add(TestPoolable.getInstance(12, 24)); + testPoolables.add(TestPoolable.getInstance(6, 8)); + testPoolables.add(TestPoolable.getInstance(6, 8)); Assert.assertEquals(0, testPoolables.get(0).foo); Assert.assertEquals(0, testPoolables.get(0).bar); Assert.assertEquals(6, testPoolables.get(1).foo); @@ -177,7 +180,7 @@ public void testObjectPool(){ Assert.assertEquals(6, testPoolables.get(9).foo); Assert.assertEquals(8, testPoolables.get(9).bar); - for(TestPoolable p : testPoolables){ + for (TestPoolable p : testPoolables) { TestPoolable.recycleInstance(p); } @@ -186,7 +189,7 @@ public void testObjectPool(){ Assert.assertEquals(16, poolCapacity); Assert.assertEquals(16, poolCount); - testPoolable = TestPoolable.getInstance(9001,9001); + testPoolable = TestPoolable.getInstance(9001, 9001); Assert.assertEquals(9001, testPoolable.foo); Assert.assertEquals(9001, testPoolable.bar); @@ -204,12 +207,12 @@ public void testObjectPool(){ Assert.assertEquals(16, poolCount); Exception e = null; - try{ + try { // expect an exception. TestPoolable.recycleInstance(testPoolable); - }catch (Exception ex){ + } catch (Exception ex) { e = ex; - }finally{ + } finally { Assert.assertEquals(e.getMessage(), true, e != null); } @@ -217,8 +220,8 @@ public void testObjectPool(){ TestPoolable.getPool().setReplenishPercentage(0.5f); int i = 16; - while(i > 0){ - testPoolables.add(TestPoolable.getInstance(0,0)); + while (i > 0) { + testPoolables.add(TestPoolable.getInstance(0, 0)); i--; } @@ -227,7 +230,7 @@ public void testObjectPool(){ Assert.assertEquals(16, poolCapacity); Assert.assertEquals(0, poolCount); - testPoolables.add(TestPoolable.getInstance(0,0)); + testPoolables.add(TestPoolable.getInstance(0, 0)); poolCapacity = TestPoolable.getPool().getPoolCapacity(); poolCount = TestPoolable.getPool().getPoolCount();