Skip to content

Commit

Permalink
Merge pull request #174 from AppDevNext/BarLineChart-text-color
Browse files Browse the repository at this point in the history
Bar line chart text color
  • Loading branch information
hannesa2 committed Nov 28, 2023
2 parents 696f945 + 82e4263 commit 47d674a
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 291 deletions.
9 changes: 2 additions & 7 deletions MPChartLib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>

<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
</application> -->
android:supportsRtl="true" />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -1686,4 +1686,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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public void disableGridDashedLine() {
* @return
*/
public boolean isGridDashedLineEnabled() {
return mGridDashPathEffect == null ? false : true;
return mGridDashPathEffect != null;
}

/**
Expand Down Expand Up @@ -655,7 +655,7 @@ public void disableAxisLineDashedLine() {
* @return
*/
public boolean isAxisLineDashedLineEnabled() {
return mAxisLineDashPathEffect == null ? false : true;
return mAxisLineDashPathEffect != null;
}

/**
Expand Down Expand Up @@ -846,4 +846,14 @@ public float[] getSpecificPositions()
{
return specificPositions;
}

/**
* 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
* Default constructor.
*/
public BaseDataSet() {
mColors = new ArrayList<Integer>();
mValueColors = new ArrayList<Integer>();
mColors = new ArrayList<>();
mValueColors = new ArrayList<>();

// default color
mColors.add(Color.rgb(140, 234, 255));
Expand Down Expand Up @@ -201,7 +201,7 @@ public void setColors(int[] colors, Context c) {
*/
public void addColor(int color) {
if (mColors == null)
mColors = new ArrayList<Integer>();
mColors = new ArrayList<>();
mColors.add(color);
}

Expand Down Expand Up @@ -244,7 +244,7 @@ public void setColors(int[] colors, int alpha) {
*/
public void resetColors() {
if (mColors == null) {
mColors = new ArrayList<Integer>();
mColors = new ArrayList<>();
}
mColors.clear();
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1038,12 +1038,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);
Expand All @@ -1055,7 +1055,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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
package com.github.mikephil.charting.test;

import static junit.framework.Assert.assertEquals;

import com.github.mikephil.charting.data.filter.Approximator;

import org.junit.Test;

import static junit.framework.Assert.assertEquals;

/**
* Created by philipp on 07/06/16.
*/
public class ApproximatorTest {

@Test
public void testApproximation() {
@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);
assertEquals(24, points.length);

Approximator a = new Approximator();
Approximator a = new Approximator();

float[] reduced = a.reduceWithDouglasPeucker(points, 2);
float[] reduced = a.reduceWithDouglasPeucker(points, 2);

assertEquals(18, reduced.length);
}
assertEquals(18, reduced.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,57 @@
*/
public class BarDataTest {

@Test
public void testGroupBars() {
@Test
public void testGroupBars() {

float groupSpace = 5f;
float barSpace = 1f;
float groupSpace = 5f;
float barSpace = 1f;

List<BarEntry> values1 = new ArrayList<>();
List<BarEntry> values2 = new ArrayList<>();
List<BarEntry> values1 = new ArrayList<>();
List<BarEntry> values2 = new ArrayList<>();

for(int i = 0; i < 5; i++) {
values1.add(new BarEntry(i, 50));
values2.add(new BarEntry(i, 60));
}
for (int i = 0; i < 5; i++) {
values1.add(new BarEntry(i, 50));
values2.add(new BarEntry(i, 60));
}

BarDataSet barDataSet1 = new BarDataSet(values1, "Set1");
BarDataSet barDataSet2 = new BarDataSet(values2, "Set2");
BarDataSet barDataSet1 = new BarDataSet(values1, "Set1");
BarDataSet barDataSet2 = new BarDataSet(values2, "Set2");

BarData data = new BarData(barDataSet1, barDataSet2);
data.setBarWidth(10f);
BarData data = new BarData(barDataSet1, barDataSet2);
data.setBarWidth(10f);

float groupWidth = data.getGroupWidth(groupSpace, barSpace);
assertEquals(27f, groupWidth, 0.01f);
float groupWidth = data.getGroupWidth(groupSpace, barSpace);
assertEquals(27f, groupWidth, 0.01f);

assertEquals(0f, values1.get(0).getX(), 0.01f);
assertEquals(1f, values1.get(1).getX(), 0.01f);
assertEquals(0f, values1.get(0).getX(), 0.01f);
assertEquals(1f, values1.get(1).getX(), 0.01f);

data.groupBars(1000, groupSpace, barSpace);
data.groupBars(1000, groupSpace, barSpace);

// 1000 + 2.5 + 0.5 + 5
assertEquals(1008f, values1.get(0).getX(), 0.01f);
assertEquals(1019f, values2.get(0).getX(), 0.01f);
assertEquals(1035f, values1.get(1).getX(), 0.01f);
assertEquals(1046f, values2.get(1).getX(), 0.01f);
// 1000 + 2.5 + 0.5 + 5
assertEquals(1008f, values1.get(0).getX(), 0.01f);
assertEquals(1019f, values2.get(0).getX(), 0.01f);
assertEquals(1035f, values1.get(1).getX(), 0.01f);
assertEquals(1046f, values2.get(1).getX(), 0.01f);

data.groupBars(-1000, groupSpace, barSpace);
data.groupBars(-1000, groupSpace, barSpace);

assertEquals(-992f, values1.get(0).getX(), 0.01f);
assertEquals(-981f, values2.get(0).getX(), 0.01f);
assertEquals(-965f, values1.get(1).getX(), 0.01f);
assertEquals(-954f, values2.get(1).getX(), 0.01f);
assertEquals(-992f, values1.get(0).getX(), 0.01f);
assertEquals(-981f, values2.get(0).getX(), 0.01f);
assertEquals(-965f, values1.get(1).getX(), 0.01f);
assertEquals(-954f, values2.get(1).getX(), 0.01f);

data.setBarWidth(20f);
groupWidth = data.getGroupWidth(groupSpace, barSpace);
assertEquals(47f, groupWidth, 0.01f);
data.setBarWidth(20f);
groupWidth = data.getGroupWidth(groupSpace, barSpace);
assertEquals(47f, groupWidth, 0.01f);

data.setBarWidth(10f);
data.groupBars(-20, groupSpace, barSpace);
data.setBarWidth(10f);
data.groupBars(-20, groupSpace, barSpace);

assertEquals(-12f, values1.get(0).getX(), 0.01f);
assertEquals(-1f, values2.get(0).getX(), 0.01f);
assertEquals(15f, values1.get(1).getX(), 0.01f);
assertEquals(26f, values2.get(1).getX(), 0.01f);
}
assertEquals(-12f, values1.get(0).getX(), 0.01f);
assertEquals(-1f, values2.get(0).getX(), 0.01f);
assertEquals(15f, values1.get(1).getX(), 0.01f);
assertEquals(26f, values2.get(1).getX(), 0.01f);
}
}
Loading

0 comments on commit 47d674a

Please sign in to comment.