Skip to content

Commit 7abc9cd

Browse files
RobertZagorskiRobert Zagorski
authored andcommitted
Update and reorganise copy data sets methods (Fix for #1604).
Copying class properties is always done in protected copy method.
1 parent 9583a18 commit 7abc9cd

File tree

13 files changed

+238
-190
lines changed

13 files changed

+238
-190
lines changed

MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {
5353

5454
private void setupChart(LineChart chart, LineData data, int color) {
5555

56-
((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(color);
56+
((LineDataSet) data.getDataSetByIndex(0)).setCircleHoleColor(color);
5757

5858
// no description text
5959
chart.getDescription().setEnabled(false);

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,24 @@ public BarDataSet(List<BarEntry> yVals, String label) {
5353

5454
@Override
5555
public DataSet<BarEntry> copy() {
56-
57-
List<BarEntry> yVals = new ArrayList<BarEntry>();
58-
yVals.clear();
59-
56+
List<BarEntry> entries = new ArrayList<BarEntry>();
6057
for (int i = 0; i < mValues.size(); i++) {
61-
yVals.add(mValues.get(i).copy());
58+
entries.add(mValues.get(i).copy());
6259
}
63-
64-
BarDataSet copied = new BarDataSet(yVals, getLabel());
65-
copied.mColors = mColors;
66-
copied.mStackSize = mStackSize;
67-
copied.mBarShadowColor = mBarShadowColor;
68-
copied.mStackLabels = mStackLabels;
69-
copied.mHighLightColor = mHighLightColor;
70-
copied.mHighLightAlpha = mHighLightAlpha;
71-
60+
BarDataSet copied = new BarDataSet(entries, getLabel());
61+
copy(copied);
7262
return copied;
7363
}
7464

65+
protected void copy(BarDataSet barDataSet) {
66+
super.copy(barDataSet);
67+
barDataSet.mStackSize = mStackSize;
68+
barDataSet.mBarShadowColor = mBarShadowColor;
69+
barDataSet.mBarBorderWidth = mBarBorderWidth;
70+
barDataSet.mStackLabels = mStackLabels;
71+
barDataSet.mHighLightAlpha = mHighLightAlpha;
72+
}
73+
7574
/**
7675
* Calculates the total number of entries this DataSet represents, including
7776
* stacks. All values belonging to a stack are calculated separately.

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99

1010
/**
1111
* Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart.
12-
*
12+
*
1313
* @author Philipp Jahoda
1414
*/
15-
public abstract class BarLineScatterCandleBubbleDataSet<T extends Entry> extends DataSet<T> implements IBarLineScatterCandleBubbleDataSet<T> {
15+
public abstract class BarLineScatterCandleBubbleDataSet<T extends Entry>
16+
extends DataSet<T>
17+
implements IBarLineScatterCandleBubbleDataSet<T> {
1618

17-
/** default highlight color */
19+
/**
20+
* default highlight color
21+
*/
1822
protected int mHighLightColor = Color.rgb(255, 187, 115);
1923

2024
public BarLineScatterCandleBubbleDataSet(List<T> yVals, String label) {
@@ -25,7 +29,7 @@ public BarLineScatterCandleBubbleDataSet(List<T> yVals, String label) {
2529
* Sets the color that is used for drawing the highlight indicators. Dont
2630
* forget to resolve the color using getResources().getColor(...) or
2731
* Color.rgb(...).
28-
*
32+
*
2933
* @param color
3034
*/
3135
public void setHighLightColor(int color) {
@@ -36,4 +40,9 @@ public void setHighLightColor(int color) {
3640
public int getHighLightColor() {
3741
return mHighLightColor;
3842
}
43+
44+
protected void copy(BarLineScatterCandleBubbleDataSet barLineScatterCandleBubbleDataSet) {
45+
super.copy(barLineScatterCandleBubbleDataSet);
46+
barLineScatterCandleBubbleDataSet.mHighLightColor = mHighLightColor;
47+
}
3948
}

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

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77

88
import com.github.mikephil.charting.components.Legend;
99
import com.github.mikephil.charting.components.YAxis;
10-
import com.github.mikephil.charting.formatter.DefaultValueFormatter;
1110
import com.github.mikephil.charting.formatter.IValueFormatter;
1211
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
12+
import com.github.mikephil.charting.model.GradientColor;
1313
import com.github.mikephil.charting.utils.ColorTemplate;
1414
import com.github.mikephil.charting.utils.MPPointF;
1515
import com.github.mikephil.charting.utils.Utils;
16-
import com.github.mikephil.charting.model.GradientColor;
1716

18-
import java.lang.annotation.Documented;
19-
import java.lang.annotation.Inherited;
2017
import java.util.ArrayList;
2118
import java.util.List;
2219

@@ -32,9 +29,9 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
3229
*/
3330
protected List<Integer> mColors = null;
3431

35-
protected GradientColor gradientColor = null;
32+
protected GradientColor mGradientColor = null;
3633

37-
protected List<GradientColor> gradientColors = null;
34+
protected List<GradientColor> mGradientColors = null;
3835

3936
/**
4037
* List representing all colors that are used for drawing the actual values for this DataSet
@@ -151,17 +148,17 @@ public int getColor(int index) {
151148

152149
@Override
153150
public GradientColor getGradientColor() {
154-
return gradientColor;
151+
return mGradientColor;
155152
}
156153

157154
@Override
158155
public List<GradientColor> getGradientColors() {
159-
return gradientColors;
156+
return mGradientColors;
160157
}
161158

162159
@Override
163160
public GradientColor getGradientColor(int index) {
164-
return gradientColors.get(index % gradientColors.size());
161+
return mGradientColors.get(index % mGradientColors.size());
165162
}
166163

167164
/**
@@ -206,7 +203,7 @@ public void setColors(int... colors) {
206203
*/
207204
public void setColors(int[] colors, Context c) {
208205

209-
if(mColors == null){
206+
if (mColors == null) {
210207
mColors = new ArrayList<>();
211208
}
212209

@@ -246,7 +243,7 @@ public void setColor(int color) {
246243
* @param endColor
247244
*/
248245
public void setGradientColor(int startColor, int endColor) {
249-
gradientColor = new GradientColor(startColor, endColor);
246+
mGradientColor = new GradientColor(startColor, endColor);
250247
}
251248

252249
/**
@@ -255,7 +252,7 @@ public void setGradientColor(int startColor, int endColor) {
255252
* @param gradientColors
256253
*/
257254
public void setGradientColors(List<GradientColor> gradientColors) {
258-
this.gradientColors = gradientColors;
255+
this.mGradientColors = gradientColors;
259256
}
260257

261258
/**
@@ -285,7 +282,7 @@ public void setColors(int[] colors, int alpha) {
285282
* Resets all colors of this DataSet and recreates the colors array.
286283
*/
287284
public void resetColors() {
288-
if(mColors == null) {
285+
if (mColors == null) {
289286
mColors = new ArrayList<Integer>();
290287
}
291288
mColors.clear();
@@ -527,4 +524,24 @@ public boolean contains(T e) {
527524

528525
return false;
529526
}
527+
528+
protected void copy(BaseDataSet baseDataSet) {
529+
baseDataSet.mAxisDependency = mAxisDependency;
530+
baseDataSet.mColors = mColors;
531+
baseDataSet.mDrawIcons = mDrawIcons;
532+
baseDataSet.mDrawValues = mDrawValues;
533+
baseDataSet.mForm = mForm;
534+
baseDataSet.mFormLineDashEffect = mFormLineDashEffect;
535+
baseDataSet.mFormLineWidth = mFormLineWidth;
536+
baseDataSet.mFormSize = mFormSize;
537+
baseDataSet.mGradientColor = mGradientColor;
538+
baseDataSet.mGradientColors = mGradientColors;
539+
baseDataSet.mHighlightEnabled = mHighlightEnabled;
540+
baseDataSet.mIconsOffset = mIconsOffset;
541+
baseDataSet.mValueColors = mValueColors;
542+
baseDataSet.mValueFormatter = mValueFormatter;
543+
baseDataSet.mValueColors = mValueColors;
544+
baseDataSet.mValueTextSize = mValueTextSize;
545+
baseDataSet.mVisible = mVisible;
546+
}
530547
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ protected void calcMinMax(BubbleEntry e) {
4141

4242
@Override
4343
public DataSet<BubbleEntry> copy() {
44-
45-
List<BubbleEntry> yVals = new ArrayList<BubbleEntry>();
46-
44+
List<BubbleEntry> entries = new ArrayList<BubbleEntry>();
4745
for (int i = 0; i < mValues.size(); i++) {
48-
yVals.add(mValues.get(i).copy());
46+
entries.add(mValues.get(i).copy());
4947
}
50-
51-
BubbleDataSet copied = new BubbleDataSet(yVals, getLabel());
52-
copied.mColors = mColors;
53-
copied.mHighLightColor = mHighLightColor;
54-
48+
BubbleDataSet copied = new BubbleDataSet(entries, getLabel());
49+
copy(copied);
5550
return copied;
5651
}
5752

53+
protected void copy(BubbleDataSet bubbleDataSet) {
54+
bubbleDataSet.mHighlightCircleWidth = mHighlightCircleWidth;
55+
bubbleDataSet.mNormalizeSize = mNormalizeSize;
56+
}
57+
5858
@Override
5959
public float getMaxSize() {
6060
return mMaxSize;

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,30 @@ public CandleDataSet(List<CandleEntry> yVals, String label) {
7979

8080
@Override
8181
public DataSet<CandleEntry> copy() {
82-
83-
List<CandleEntry> yVals = new ArrayList<CandleEntry>();
84-
yVals.clear();
85-
82+
List<CandleEntry> entries = new ArrayList<CandleEntry>();
8683
for (int i = 0; i < mValues.size(); i++) {
87-
yVals.add(mValues.get(i).copy());
84+
entries.add(mValues.get(i).copy());
8885
}
89-
90-
CandleDataSet copied = new CandleDataSet(yVals, getLabel());
91-
copied.mColors = mColors;
92-
copied.mShadowWidth = mShadowWidth;
93-
copied.mShowCandleBar = mShowCandleBar;
94-
copied.mBarSpace = mBarSpace;
95-
copied.mHighLightColor = mHighLightColor;
96-
copied.mIncreasingPaintStyle = mIncreasingPaintStyle;
97-
copied.mDecreasingPaintStyle = mDecreasingPaintStyle;
98-
copied.mShadowColor = mShadowColor;
99-
86+
CandleDataSet copied = new CandleDataSet(entries, getLabel());
87+
copy(copied);
10088
return copied;
10189
}
10290

91+
protected void copy(CandleDataSet candleDataSet) {
92+
super.copy(candleDataSet);
93+
candleDataSet.mShadowWidth = mShadowWidth;
94+
candleDataSet.mShowCandleBar = mShowCandleBar;
95+
candleDataSet.mBarSpace = mBarSpace;
96+
candleDataSet.mShadowColorSameAsCandle = mShadowColorSameAsCandle;
97+
candleDataSet.mHighLightColor = mHighLightColor;
98+
candleDataSet.mIncreasingPaintStyle = mIncreasingPaintStyle;
99+
candleDataSet.mDecreasingPaintStyle = mDecreasingPaintStyle;
100+
candleDataSet.mNeutralColor = mNeutralColor;
101+
candleDataSet.mIncreasingColor = mIncreasingColor;
102+
candleDataSet.mDecreasingColor = mDecreasingColor;
103+
candleDataSet.mShadowColor = mShadowColor;
104+
}
105+
103106
@Override
104107
protected void calcMinMax(CandleEntry e) {
105108

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ public void setValues(List<T> values) {
157157
*/
158158
public abstract DataSet<T> copy();
159159

160+
/**
161+
*
162+
* @param dataSet
163+
*/
164+
protected void copy(DataSet dataSet) {
165+
super.copy(dataSet);
166+
}
167+
160168
@Override
161169
public String toString() {
162170
StringBuffer buffer = new StringBuffer();

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet
3030
/**
3131
* the color of the inner circles
3232
*/
33-
private int mCircleColorHole = Color.WHITE;
33+
private int mCircleHoleColor = Color.WHITE;
3434

3535
/**
3636
* the radius of the circle-shaped value indicators
@@ -84,27 +84,29 @@ public LineDataSet(List<Entry> yVals, String label) {
8484

8585
@Override
8686
public DataSet<Entry> copy() {
87-
88-
List<Entry> yVals = new ArrayList<Entry>();
89-
87+
List<Entry> entries = new ArrayList<Entry>();
9088
for (int i = 0; i < mValues.size(); i++) {
91-
yVals.add(mValues.get(i).copy());
89+
entries.add(mValues.get(i).copy());
9290
}
93-
94-
LineDataSet copied = new LineDataSet(yVals, getLabel());
95-
copied.mMode = mMode;
96-
copied.mColors = mColors;
97-
copied.mCircleRadius = mCircleRadius;
98-
copied.mCircleHoleRadius = mCircleHoleRadius;
99-
copied.mCircleColors = mCircleColors;
100-
copied.mDashPathEffect = mDashPathEffect;
101-
copied.mDrawCircles = mDrawCircles;
102-
copied.mDrawCircleHole = mDrawCircleHole;
103-
copied.mHighLightColor = mHighLightColor;
104-
91+
LineDataSet copied = new LineDataSet(entries, getLabel());
92+
copy(copied);
10593
return copied;
10694
}
10795

96+
protected void copy(LineDataSet lineDataSet) {
97+
super.copy(lineDataSet);
98+
lineDataSet.mCircleColors = mCircleColors;
99+
lineDataSet.mCircleHoleColor = mCircleHoleColor;
100+
lineDataSet.mCircleHoleRadius = mCircleHoleRadius;
101+
lineDataSet.mCircleRadius = mCircleRadius;
102+
lineDataSet.mCubicIntensity = mCubicIntensity;
103+
lineDataSet.mDashPathEffect = mDashPathEffect;
104+
lineDataSet.mDrawCircleHole = mDrawCircleHole;
105+
lineDataSet.mDrawCircles = mDrawCircleHole;
106+
lineDataSet.mFillFormatter = mFillFormatter;
107+
lineDataSet.mMode = mMode;
108+
}
109+
108110
/**
109111
* Returns the drawing mode for this line dataset
110112
*
@@ -364,13 +366,13 @@ public void resetCircleColors() {
364366
*
365367
* @param color
366368
*/
367-
public void setCircleColorHole(int color) {
368-
mCircleColorHole = color;
369+
public void setCircleHoleColor(int color) {
370+
mCircleHoleColor = color;
369371
}
370372

371373
@Override
372374
public int getCircleHoleColor() {
373-
return mCircleColorHole;
375+
return mCircleHoleColor;
374376
}
375377

376378
/**

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,13 @@ public void setDrawFilled(boolean filled) {
122122
public boolean isDrawFilledEnabled() {
123123
return mDrawFilled;
124124
}
125+
126+
protected void copy(LineRadarDataSet lineRadarDataSet) {
127+
super.copy(lineRadarDataSet);
128+
lineRadarDataSet.mDrawFilled = mDrawFilled;
129+
lineRadarDataSet.mFillAlpha = mFillAlpha;
130+
lineRadarDataSet.mFillColor = mFillColor;
131+
lineRadarDataSet.mFillDrawable = mFillDrawable;
132+
lineRadarDataSet.mLineWidth = mLineWidth;
133+
}
125134
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,12 @@ public boolean isDashedHighlightLineEnabled() {
109109
public DashPathEffect getDashPathEffectHighlight() {
110110
return mHighlightDashPathEffect;
111111
}
112+
113+
protected void copy(LineScatterCandleRadarDataSet lineScatterCandleRadarDataSet) {
114+
super.copy(lineScatterCandleRadarDataSet);
115+
lineScatterCandleRadarDataSet.mDrawHorizontalHighlightIndicator = mDrawHorizontalHighlightIndicator;
116+
lineScatterCandleRadarDataSet.mDrawVerticalHighlightIndicator = mDrawVerticalHighlightIndicator;
117+
lineScatterCandleRadarDataSet.mHighlightLineWidth = mHighlightLineWidth;
118+
lineScatterCandleRadarDataSet.mHighlightDashPathEffect = mHighlightDashPathEffect;
119+
}
112120
}

0 commit comments

Comments
 (0)