Skip to content

Commit eae9773

Browse files
committed
Merge branch 'fill'
* fill: Implement a more generic Fill class instead of GradientColor
2 parents 351e341 + c0e7f56 commit eae9773

File tree

10 files changed

+514
-127
lines changed

10 files changed

+514
-127
lines changed

MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
3333
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
3434
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
35-
import com.github.mikephil.charting.model.GradientColor;
35+
import com.github.mikephil.charting.utils.Fill;
3636
import com.github.mikephil.charting.utils.MPPointF;
3737
import com.xxmassdeveloper.mpchartexample.custom.DayAxisValueFormatter;
3838
import com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter;
@@ -164,12 +164,6 @@ private void setData(int count, float range) {
164164

165165
set1.setDrawIcons(false);
166166

167-
// set1.setColors(ColorTemplate.MATERIAL_COLORS);
168-
169-
/*int startColor = ContextCompat.getColor(this, android.R.color.holo_blue_dark);
170-
int endColor = ContextCompat.getColor(this, android.R.color.holo_blue_bright);
171-
set1.setGradientColor(startColor, endColor);*/
172-
173167
int startColor1 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
174168
int startColor2 = ContextCompat.getColor(this, android.R.color.holo_blue_light);
175169
int startColor3 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
@@ -181,14 +175,14 @@ private void setData(int count, float range) {
181175
int endColor4 = ContextCompat.getColor(this, android.R.color.holo_red_dark);
182176
int endColor5 = ContextCompat.getColor(this, android.R.color.holo_orange_dark);
183177

184-
List<GradientColor> gradientColors = new ArrayList<>();
185-
gradientColors.add(new GradientColor(startColor1, endColor1));
186-
gradientColors.add(new GradientColor(startColor2, endColor2));
187-
gradientColors.add(new GradientColor(startColor3, endColor3));
188-
gradientColors.add(new GradientColor(startColor4, endColor4));
189-
gradientColors.add(new GradientColor(startColor5, endColor5));
178+
List<Fill> gradientFills = new ArrayList<>();
179+
gradientFills.add(new Fill(startColor1, endColor1));
180+
gradientFills.add(new Fill(startColor2, endColor2));
181+
gradientFills.add(new Fill(startColor3, endColor3));
182+
gradientFills.add(new Fill(startColor4, endColor4));
183+
gradientFills.add(new Fill(startColor5, endColor5));
190184

191-
set1.setGradientColors(gradientColors);
185+
set1.setFills(gradientFills);
192186

193187
ArrayList<IBarDataSet> dataSets = new ArrayList<>();
194188
dataSets.add(set1);

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.graphics.Color;
55

66
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
7+
import com.github.mikephil.charting.utils.Fill;
78

89
import java.util.ArrayList;
910
import java.util.List;
@@ -40,6 +41,8 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> impl
4041
*/
4142
private String[] mStackLabels = new String[]{};
4243

44+
protected List<Fill> mFills = null;
45+
4346
public BarDataSet(List<BarEntry> yVals, String label) {
4447
super(yVals, label);
4548

@@ -69,6 +72,67 @@ protected void copy(BarDataSet barDataSet) {
6972
barDataSet.mHighLightAlpha = mHighLightAlpha;
7073
}
7174

75+
@Override
76+
public List<Fill> getFills() {
77+
return mFills;
78+
}
79+
80+
@Override
81+
public Fill getFill(int index) {
82+
return mFills.get(index % mFills.size());
83+
}
84+
85+
/**
86+
* This method is deprecated.
87+
* Use getFills() instead.
88+
*/
89+
@Deprecated
90+
public List<Fill> getGradients() {
91+
return mFills;
92+
}
93+
94+
/**
95+
* This method is deprecated.
96+
* Use getFill(...) instead.
97+
*
98+
* @param index
99+
*/
100+
@Deprecated
101+
public Fill getGradient(int index) {
102+
return getFill(index);
103+
}
104+
105+
/**
106+
* Sets the start and end color for gradient color, ONLY color that should be used for this DataSet.
107+
*
108+
* @param startColor
109+
* @param endColor
110+
*/
111+
public void setGradientColor(int startColor, int endColor) {
112+
mFills.clear();
113+
mFills.add(new Fill(startColor, endColor));
114+
}
115+
116+
/**
117+
* This method is deprecated.
118+
* Use setFills(...) instead.
119+
*
120+
* @param gradientColors
121+
*/
122+
@Deprecated
123+
public void setGradientColors(List<Fill> gradientColors) {
124+
this.mFills = gradientColors;
125+
}
126+
127+
/**
128+
* Sets the fills for the bars in this dataset.
129+
*
130+
* @param fills
131+
*/
132+
public void setFills(List<Fill> fills) {
133+
this.mFills = fills;
134+
}
135+
72136
/**
73137
* Calculates the total number of entries this DataSet represents, including
74138
* stacks. All values belonging to a stack are calculated separately.

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.github.mikephil.charting.components.YAxis;
1010
import com.github.mikephil.charting.formatter.ValueFormatter;
1111
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
12-
import com.github.mikephil.charting.model.GradientColor;
1312
import com.github.mikephil.charting.utils.ColorTemplate;
1413
import com.github.mikephil.charting.utils.MPPointF;
1514
import com.github.mikephil.charting.utils.Utils;
@@ -29,10 +28,6 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
2928
*/
3029
protected List<Integer> mColors = null;
3130

32-
protected GradientColor mGradientColor = null;
33-
34-
protected List<GradientColor> mGradientColors = null;
35-
3631
/**
3732
* List representing all colors that are used for drawing the actual values for this DataSet
3833
*/
@@ -146,21 +141,6 @@ public int getColor(int index) {
146141
return mColors.get(index % mColors.size());
147142
}
148143

149-
@Override
150-
public GradientColor getGradientColor() {
151-
return mGradientColor;
152-
}
153-
154-
@Override
155-
public List<GradientColor> getGradientColors() {
156-
return mGradientColors;
157-
}
158-
159-
@Override
160-
public GradientColor getGradientColor(int index) {
161-
return mGradientColors.get(index % mGradientColors.size());
162-
}
163-
164144
/**
165145
* ###### ###### COLOR SETTING RELATED METHODS ##### ######
166146
*/
@@ -236,25 +216,6 @@ public void setColor(int color) {
236216
mColors.add(color);
237217
}
238218

239-
/**
240-
* Sets the start and end color for gradient color, ONLY color that should be used for this DataSet.
241-
*
242-
* @param startColor
243-
* @param endColor
244-
*/
245-
public void setGradientColor(int startColor, int endColor) {
246-
mGradientColor = new GradientColor(startColor, endColor);
247-
}
248-
249-
/**
250-
* Sets the start and end color for gradient colors, ONLY color that should be used for this DataSet.
251-
*
252-
* @param gradientColors
253-
*/
254-
public void setGradientColors(List<GradientColor> gradientColors) {
255-
this.mGradientColors = gradientColors;
256-
}
257-
258219
/**
259220
* Sets a color with a specific alpha value.
260221
*
@@ -534,8 +495,6 @@ protected void copy(BaseDataSet baseDataSet) {
534495
baseDataSet.mFormLineDashEffect = mFormLineDashEffect;
535496
baseDataSet.mFormLineWidth = mFormLineWidth;
536497
baseDataSet.mFormSize = mFormSize;
537-
baseDataSet.mGradientColor = mGradientColor;
538-
baseDataSet.mGradientColors = mGradientColors;
539498
baseDataSet.mHighlightEnabled = mHighlightEnabled;
540499
baseDataSet.mIconsOffset = mIconsOffset;
541500
baseDataSet.mValueColors = mValueColors;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandleRadarDataSet<T> implements ILineRadarDataSet<T> {
1919

20+
// TODO: Move to using `Fill` class
2021
/**
2122
* the color that is used for filling the line surface
2223
*/

MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarDataSet.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package com.github.mikephil.charting.interfaces.datasets;
22

33
import com.github.mikephil.charting.data.BarEntry;
4+
import com.github.mikephil.charting.utils.Fill;
5+
6+
import java.util.List;
47

58
/**
69
* Created by philipp on 21/10/15.
710
*/
811
public interface IBarDataSet extends IBarLineScatterCandleBubbleDataSet<BarEntry> {
912

13+
List<Fill> getFills();
14+
15+
Fill getFill(int index);
16+
1017
/**
1118
* Returns true if this DataSet is stacked (stacksize > 1) or not.
1219
*

MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.github.mikephil.charting.data.Entry;
1010
import com.github.mikephil.charting.formatter.ValueFormatter;
1111
import com.github.mikephil.charting.utils.MPPointF;
12-
import com.github.mikephil.charting.model.GradientColor;
1312

1413
import java.util.List;
1514

@@ -285,28 +284,6 @@ public interface IDataSet<T extends Entry> {
285284
*/
286285
int getColor();
287286

288-
/**
289-
* Returns the Gradient color model
290-
*
291-
* @return
292-
*/
293-
GradientColor getGradientColor();
294-
295-
/**
296-
* Returns the Gradient colors
297-
*
298-
* @return
299-
*/
300-
List<GradientColor> getGradientColors();
301-
302-
/**
303-
* Returns the Gradient colors
304-
*
305-
* @param index
306-
* @return
307-
*/
308-
GradientColor getGradientColor(int index);
309-
310287
/**
311288
* Returns the color at the given index of the DataSet's color array.
312289
* Performs a IndexOutOfBounds check by modulus.
Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,69 @@
11
package com.github.mikephil.charting.model;
22

3-
public class GradientColor {
3+
import com.github.mikephil.charting.utils.Fill;
44

5-
private int startColor;
6-
private int endColor;
7-
8-
public GradientColor(int startColor, int endColor) {
9-
this.startColor = startColor;
10-
this.endColor = endColor;
5+
/**
6+
* Deprecated. Use `Fill`
7+
*/
8+
@Deprecated
9+
public class GradientColor extends Fill
10+
{
11+
/**
12+
* Deprecated. Use `Fill.getGradientColors()`
13+
*/
14+
@Deprecated
15+
public int getStartColor()
16+
{
17+
return getGradientColors()[0];
1118
}
1219

13-
public int getStartColor() {
14-
return startColor;
20+
/**
21+
* Deprecated. Use `Fill.setGradientColors(...)`
22+
*/
23+
@Deprecated
24+
public void setStartColor(int startColor)
25+
{
26+
if (getGradientColors() == null || getGradientColors().length != 2)
27+
{
28+
setGradientColors(new int[]{
29+
startColor,
30+
getGradientColors() != null && getGradientColors().length > 1
31+
? getGradientColors()[1]
32+
: 0
33+
});
34+
} else
35+
{
36+
getGradientColors()[0] = startColor;
37+
}
1538
}
1639

17-
public void setStartColor(int startColor) {
18-
this.startColor = startColor;
40+
/**
41+
* Deprecated. Use `Fill.getGradientColors()`
42+
*/
43+
@Deprecated
44+
public int getEndColor()
45+
{
46+
return getGradientColors()[1];
1947
}
2048

21-
public int getEndColor() {
22-
return endColor;
49+
/**
50+
* Deprecated. Use `Fill.setGradientColors(...)`
51+
*/
52+
@Deprecated
53+
public void setEndColor(int endColor)
54+
{
55+
if (getGradientColors() == null || getGradientColors().length != 2)
56+
{
57+
setGradientColors(new int[]{
58+
getGradientColors() != null && getGradientColors().length > 0
59+
? getGradientColors()[0]
60+
: 0,
61+
endColor
62+
});
63+
} else
64+
{
65+
getGradientColors()[1] = endColor;
66+
}
2367
}
2468

25-
public void setEndColor(int endColor) {
26-
this.endColor = endColor;
27-
}
2869
}

0 commit comments

Comments
 (0)