Skip to content

Commit 47d674a

Browse files
authored
Merge pull request #174 from AppDevNext/BarLineChart-text-color
Bar line chart text color
2 parents 696f945 + 82e4263 commit 47d674a

File tree

9 files changed

+305
-291
lines changed

9 files changed

+305
-291
lines changed
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest>
3-
4-
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
53

64
<application
75
android:allowBackup="true"
8-
android:icon="@drawable/ic_launcher"
9-
android:label="@string/app_name"
10-
android:theme="@style/AppTheme" >
11-
</application> -->
6+
android:supportsRtl="true" />
127

138
</manifest>

MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,4 +1686,16 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
16861686
mViewPortHandler.refresh(mViewPortHandler.getMatrixTouch(), this, true);
16871687
}
16881688
}
1689+
1690+
/**
1691+
* Sets the text color to use for the labels. Make sure to use
1692+
* getResources().getColor(...) when using a color from the resources.
1693+
*
1694+
* @param color
1695+
*/
1696+
public void setTextColor(int color) {
1697+
mAxisRendererLeft.setTextColor(color);
1698+
mAxisRendererRight.setTextColor(color);
1699+
mXAxisRenderer.setTextColor(color);
1700+
}
16891701
}

MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ public void disableGridDashedLine() {
603603
* @return
604604
*/
605605
public boolean isGridDashedLineEnabled() {
606-
return mGridDashPathEffect == null ? false : true;
606+
return mGridDashPathEffect != null;
607607
}
608608

609609
/**
@@ -655,7 +655,7 @@ public void disableAxisLineDashedLine() {
655655
* @return
656656
*/
657657
public boolean isAxisLineDashedLineEnabled() {
658-
return mAxisLineDashPathEffect == null ? false : true;
658+
return mAxisLineDashPathEffect != null;
659659
}
660660

661661
/**
@@ -846,4 +846,14 @@ public float[] getSpecificPositions()
846846
{
847847
return specificPositions;
848848
}
849+
850+
/**
851+
* Sets the text color to use for the labels. Make sure to use
852+
* getResources().getColor(...) when using a color from the resources.
853+
*
854+
* @param color
855+
*/
856+
public void setTextColor(int color) {
857+
mTextColor = color;
858+
}
849859
}

MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
9292
* Default constructor.
9393
*/
9494
public BaseDataSet() {
95-
mColors = new ArrayList<Integer>();
96-
mValueColors = new ArrayList<Integer>();
95+
mColors = new ArrayList<>();
96+
mValueColors = new ArrayList<>();
9797

9898
// default color
9999
mColors.add(Color.rgb(140, 234, 255));
@@ -201,7 +201,7 @@ public void setColors(int[] colors, Context c) {
201201
*/
202202
public void addColor(int color) {
203203
if (mColors == null)
204-
mColors = new ArrayList<Integer>();
204+
mColors = new ArrayList<>();
205205
mColors.add(color);
206206
}
207207

@@ -244,7 +244,7 @@ public void setColors(int[] colors, int alpha) {
244244
*/
245245
public void resetColors() {
246246
if (mColors == null) {
247-
mColors = new ArrayList<Integer>();
247+
mColors = new ArrayList<>();
248248
}
249249
mColors.clear();
250250
}
@@ -499,7 +499,6 @@ protected void copy(BaseDataSet baseDataSet) {
499499
baseDataSet.mIconsOffset = mIconsOffset;
500500
baseDataSet.mValueColors = mValueColors;
501501
baseDataSet.mValueFormatter = mValueFormatter;
502-
baseDataSet.mValueColors = mValueColors;
503502
baseDataSet.mValueTextSize = mValueTextSize;
504503
baseDataSet.mVisible = mVisible;
505504
}

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,14 @@ else if (last == first && n == 0) {
290290
* @param c
291291
*/
292292
public abstract void renderLimitLines(Canvas c);
293+
294+
/**
295+
* Sets the text color to use for the labels. Make sure to use
296+
* getResources().getColor(...) when using a color from the resources.
297+
*
298+
* @param color
299+
*/
300+
public void setTextColor(int color) {
301+
mAxis.setTextColor(color);
302+
}
293303
}

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,12 @@ protected void drawRoundedSlices(Canvas c) {
10381038
// draw only if the value is greater than zero
10391039
if ((Math.abs(e.getY()) > Utils.FLOAT_EPSILON)) {
10401040

1041+
double v = Math.toRadians((angle + sliceAngle)
1042+
* phaseY);
10411043
float x = (float) ((r - circleRadius)
1042-
* Math.cos(Math.toRadians((angle + sliceAngle)
1043-
* phaseY)) + center.x);
1044+
* Math.cos(v) + center.x);
10441045
float y = (float) ((r - circleRadius)
1045-
* Math.sin(Math.toRadians((angle + sliceAngle)
1046-
* phaseY)) + center.y);
1046+
* Math.sin(v) + center.y);
10471047

10481048
mRenderPaint.setColor(dataSet.getColor(j));
10491049
mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint);
@@ -1055,7 +1055,7 @@ protected void drawRoundedSlices(Canvas c) {
10551055
}
10561056

10571057
/**
1058-
* Releases the drawing bitmap. This should be called when {@link LineChart#onDetachedFromWindow()}.
1058+
* Releases the drawing bitmap. This should be called when .
10591059
*/
10601060
public void releaseBitmap() {
10611061
if (mBitmapCanvas != null) {
Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,27 @@
11
package com.github.mikephil.charting.test;
22

3+
import static junit.framework.Assert.assertEquals;
4+
35
import com.github.mikephil.charting.data.filter.Approximator;
46

57
import org.junit.Test;
68

7-
import static junit.framework.Assert.assertEquals;
8-
99
/**
1010
* Created by philipp on 07/06/16.
1111
*/
1212
public class ApproximatorTest {
1313

14-
@Test
15-
public void testApproximation() {
14+
@Test
15+
public void testApproximation() {
1616

17-
float[] points = new float[]{
18-
10, 20,
19-
20, 30,
20-
25, 25,
21-
30, 28,
22-
31, 31,
23-
33, 33,
24-
40, 40,
25-
44, 40,
26-
48, 23,
27-
50, 20,
28-
55, 20,
29-
60, 25};
17+
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};
3018

31-
assertEquals(24, points.length);
19+
assertEquals(24, points.length);
3220

33-
Approximator a = new Approximator();
21+
Approximator a = new Approximator();
3422

35-
float[] reduced = a.reduceWithDouglasPeucker(points, 2);
23+
float[] reduced = a.reduceWithDouglasPeucker(points, 2);
3624

37-
assertEquals(18, reduced.length);
38-
}
25+
assertEquals(18, reduced.length);
26+
}
3927
}

MPChartLib/src/test/java/com/github/mikephil/charting/test/BarDataTest.java

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,57 @@
1616
*/
1717
public class BarDataTest {
1818

19-
@Test
20-
public void testGroupBars() {
19+
@Test
20+
public void testGroupBars() {
2121

22-
float groupSpace = 5f;
23-
float barSpace = 1f;
22+
float groupSpace = 5f;
23+
float barSpace = 1f;
2424

25-
List<BarEntry> values1 = new ArrayList<>();
26-
List<BarEntry> values2 = new ArrayList<>();
25+
List<BarEntry> values1 = new ArrayList<>();
26+
List<BarEntry> values2 = new ArrayList<>();
2727

28-
for(int i = 0; i < 5; i++) {
29-
values1.add(new BarEntry(i, 50));
30-
values2.add(new BarEntry(i, 60));
31-
}
28+
for (int i = 0; i < 5; i++) {
29+
values1.add(new BarEntry(i, 50));
30+
values2.add(new BarEntry(i, 60));
31+
}
3232

33-
BarDataSet barDataSet1 = new BarDataSet(values1, "Set1");
34-
BarDataSet barDataSet2 = new BarDataSet(values2, "Set2");
33+
BarDataSet barDataSet1 = new BarDataSet(values1, "Set1");
34+
BarDataSet barDataSet2 = new BarDataSet(values2, "Set2");
3535

36-
BarData data = new BarData(barDataSet1, barDataSet2);
37-
data.setBarWidth(10f);
36+
BarData data = new BarData(barDataSet1, barDataSet2);
37+
data.setBarWidth(10f);
3838

39-
float groupWidth = data.getGroupWidth(groupSpace, barSpace);
40-
assertEquals(27f, groupWidth, 0.01f);
39+
float groupWidth = data.getGroupWidth(groupSpace, barSpace);
40+
assertEquals(27f, groupWidth, 0.01f);
4141

42-
assertEquals(0f, values1.get(0).getX(), 0.01f);
43-
assertEquals(1f, values1.get(1).getX(), 0.01f);
42+
assertEquals(0f, values1.get(0).getX(), 0.01f);
43+
assertEquals(1f, values1.get(1).getX(), 0.01f);
4444

45-
data.groupBars(1000, groupSpace, barSpace);
45+
data.groupBars(1000, groupSpace, barSpace);
4646

47-
// 1000 + 2.5 + 0.5 + 5
48-
assertEquals(1008f, values1.get(0).getX(), 0.01f);
49-
assertEquals(1019f, values2.get(0).getX(), 0.01f);
50-
assertEquals(1035f, values1.get(1).getX(), 0.01f);
51-
assertEquals(1046f, values2.get(1).getX(), 0.01f);
47+
// 1000 + 2.5 + 0.5 + 5
48+
assertEquals(1008f, values1.get(0).getX(), 0.01f);
49+
assertEquals(1019f, values2.get(0).getX(), 0.01f);
50+
assertEquals(1035f, values1.get(1).getX(), 0.01f);
51+
assertEquals(1046f, values2.get(1).getX(), 0.01f);
5252

53-
data.groupBars(-1000, groupSpace, barSpace);
53+
data.groupBars(-1000, groupSpace, barSpace);
5454

55-
assertEquals(-992f, values1.get(0).getX(), 0.01f);
56-
assertEquals(-981f, values2.get(0).getX(), 0.01f);
57-
assertEquals(-965f, values1.get(1).getX(), 0.01f);
58-
assertEquals(-954f, values2.get(1).getX(), 0.01f);
55+
assertEquals(-992f, values1.get(0).getX(), 0.01f);
56+
assertEquals(-981f, values2.get(0).getX(), 0.01f);
57+
assertEquals(-965f, values1.get(1).getX(), 0.01f);
58+
assertEquals(-954f, values2.get(1).getX(), 0.01f);
5959

60-
data.setBarWidth(20f);
61-
groupWidth = data.getGroupWidth(groupSpace, barSpace);
62-
assertEquals(47f, groupWidth, 0.01f);
60+
data.setBarWidth(20f);
61+
groupWidth = data.getGroupWidth(groupSpace, barSpace);
62+
assertEquals(47f, groupWidth, 0.01f);
6363

64-
data.setBarWidth(10f);
65-
data.groupBars(-20, groupSpace, barSpace);
64+
data.setBarWidth(10f);
65+
data.groupBars(-20, groupSpace, barSpace);
6666

67-
assertEquals(-12f, values1.get(0).getX(), 0.01f);
68-
assertEquals(-1f, values2.get(0).getX(), 0.01f);
69-
assertEquals(15f, values1.get(1).getX(), 0.01f);
70-
assertEquals(26f, values2.get(1).getX(), 0.01f);
71-
}
67+
assertEquals(-12f, values1.get(0).getX(), 0.01f);
68+
assertEquals(-1f, values2.get(0).getX(), 0.01f);
69+
assertEquals(15f, values1.get(1).getX(), 0.01f);
70+
assertEquals(26f, values2.get(1).getX(), 0.01f);
71+
}
7272
}

0 commit comments

Comments
 (0)