Skip to content

Commit

Permalink
Update and reorganise copy data sets methods (Fix for PhilJay#1604).
Browse files Browse the repository at this point in the history
Copying class properties is always done in protected copy method.
  • Loading branch information
RobertZagorski authored and Robert Zagorski committed May 8, 2018
1 parent 2354f2e commit 949d155
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {

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

((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(color);
((LineDataSet) data.getDataSetByIndex(0)).setCircleHoleColor(color);

// no description text
chart.getDescription().setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,24 @@ public BarDataSet(List<BarEntry> yVals, String label) {

@Override
public DataSet<BarEntry> copy() {

List<BarEntry> yVals = new ArrayList<BarEntry>();
yVals.clear();

List<BarEntry> entries = new ArrayList<BarEntry>();
for (int i = 0; i < mValues.size(); i++) {
yVals.add(mValues.get(i).copy());
entries.add(mValues.get(i).copy());
}

BarDataSet copied = new BarDataSet(yVals, getLabel());
copied.mColors = mColors;
copied.mStackSize = mStackSize;
copied.mBarShadowColor = mBarShadowColor;
copied.mStackLabels = mStackLabels;
copied.mHighLightColor = mHighLightColor;
copied.mHighLightAlpha = mHighLightAlpha;

BarDataSet copied = new BarDataSet(entries, getLabel());
copy(copied);
return copied;
}

protected void copy(BarDataSet barDataSet) {
super.copy(barDataSet);
barDataSet.mStackSize = mStackSize;
barDataSet.mBarShadowColor = mBarShadowColor;
barDataSet.mBarBorderWidth = mBarBorderWidth;
barDataSet.mStackLabels = mStackLabels;
barDataSet.mHighLightAlpha = mHighLightAlpha;
}

/**
* Calculates the total number of entries this DataSet represents, including
* stacks. All values belonging to a stack are calculated separately.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@

/**
* Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart.
*
*
* @author Philipp Jahoda
*/
public abstract class BarLineScatterCandleBubbleDataSet<T extends Entry> extends DataSet<T> implements IBarLineScatterCandleBubbleDataSet<T> {
public abstract class BarLineScatterCandleBubbleDataSet<T extends Entry>
extends DataSet<T>
implements IBarLineScatterCandleBubbleDataSet<T> {

/** default highlight color */
/**
* default highlight color
*/
protected int mHighLightColor = Color.rgb(255, 187, 115);

public BarLineScatterCandleBubbleDataSet(List<T> yVals, String label) {
Expand All @@ -25,7 +29,7 @@ public BarLineScatterCandleBubbleDataSet(List<T> yVals, String label) {
* Sets the color that is used for drawing the highlight indicators. Dont
* forget to resolve the color using getResources().getColor(...) or
* Color.rgb(...).
*
*
* @param color
*/
public void setHighLightColor(int color) {
Expand All @@ -36,4 +40,9 @@ public void setHighLightColor(int color) {
public int getHighLightColor() {
return mHighLightColor;
}

protected void copy(BarLineScatterCandleBubbleDataSet barLineScatterCandleBubbleDataSet) {
super.copy(barLineScatterCandleBubbleDataSet);
barLineScatterCandleBubbleDataSet.mHighLightColor = mHighLightColor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@

import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.formatter.DefaultValueFormatter;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.model.GradientColor;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.model.GradientColor;

import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.util.ArrayList;
import java.util.List;

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

protected GradientColor gradientColor = null;
protected GradientColor mGradientColor = null;

protected List<GradientColor> gradientColors = null;
protected List<GradientColor> mGradientColors = null;

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

@Override
public GradientColor getGradientColor() {
return gradientColor;
return mGradientColor;
}

@Override
public List<GradientColor> getGradientColors() {
return gradientColors;
return mGradientColors;
}

@Override
public GradientColor getGradientColor(int index) {
return gradientColors.get(index % gradientColors.size());
return mGradientColors.get(index % mGradientColors.size());
}

/**
Expand Down Expand Up @@ -206,7 +203,7 @@ public void setColors(int... colors) {
*/
public void setColors(int[] colors, Context c) {

if(mColors == null){
if (mColors == null) {
mColors = new ArrayList<>();
}

Expand Down Expand Up @@ -246,7 +243,7 @@ public void setColor(int color) {
* @param endColor
*/
public void setGradientColor(int startColor, int endColor) {
gradientColor = new GradientColor(startColor, endColor);
mGradientColor = new GradientColor(startColor, endColor);
}

/**
Expand All @@ -255,7 +252,7 @@ public void setGradientColor(int startColor, int endColor) {
* @param gradientColors
*/
public void setGradientColors(List<GradientColor> gradientColors) {
this.gradientColors = gradientColors;
this.mGradientColors = gradientColors;
}

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

return false;
}

protected void copy(BaseDataSet baseDataSet) {
baseDataSet.mAxisDependency = mAxisDependency;
baseDataSet.mColors = mColors;
baseDataSet.mDrawIcons = mDrawIcons;
baseDataSet.mDrawValues = mDrawValues;
baseDataSet.mForm = mForm;
baseDataSet.mFormLineDashEffect = mFormLineDashEffect;
baseDataSet.mFormLineWidth = mFormLineWidth;
baseDataSet.mFormSize = mFormSize;
baseDataSet.mGradientColor = mGradientColor;
baseDataSet.mGradientColors = mGradientColors;
baseDataSet.mHighlightEnabled = mHighlightEnabled;
baseDataSet.mIconsOffset = mIconsOffset;
baseDataSet.mValueColors = mValueColors;
baseDataSet.mValueFormatter = mValueFormatter;
baseDataSet.mValueColors = mValueColors;
baseDataSet.mValueTextSize = mValueTextSize;
baseDataSet.mVisible = mVisible;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ protected void calcMinMax(BubbleEntry e) {

@Override
public DataSet<BubbleEntry> copy() {

List<BubbleEntry> yVals = new ArrayList<BubbleEntry>();

List<BubbleEntry> entries = new ArrayList<BubbleEntry>();
for (int i = 0; i < mValues.size(); i++) {
yVals.add(mValues.get(i).copy());
entries.add(mValues.get(i).copy());
}

BubbleDataSet copied = new BubbleDataSet(yVals, getLabel());
copied.mColors = mColors;
copied.mHighLightColor = mHighLightColor;

BubbleDataSet copied = new BubbleDataSet(entries, getLabel());
copy(copied);
return copied;
}

protected void copy(BubbleDataSet bubbleDataSet) {
bubbleDataSet.mHighlightCircleWidth = mHighlightCircleWidth;
bubbleDataSet.mNormalizeSize = mNormalizeSize;
}

@Override
public float getMaxSize() {
return mMaxSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,30 @@ public CandleDataSet(List<CandleEntry> yVals, String label) {

@Override
public DataSet<CandleEntry> copy() {

List<CandleEntry> yVals = new ArrayList<CandleEntry>();
yVals.clear();

List<CandleEntry> entries = new ArrayList<CandleEntry>();
for (int i = 0; i < mValues.size(); i++) {
yVals.add(mValues.get(i).copy());
entries.add(mValues.get(i).copy());
}

CandleDataSet copied = new CandleDataSet(yVals, getLabel());
copied.mColors = mColors;
copied.mShadowWidth = mShadowWidth;
copied.mShowCandleBar = mShowCandleBar;
copied.mBarSpace = mBarSpace;
copied.mHighLightColor = mHighLightColor;
copied.mIncreasingPaintStyle = mIncreasingPaintStyle;
copied.mDecreasingPaintStyle = mDecreasingPaintStyle;
copied.mShadowColor = mShadowColor;

CandleDataSet copied = new CandleDataSet(entries, getLabel());
copy(copied);
return copied;
}

protected void copy(CandleDataSet candleDataSet) {
super.copy(candleDataSet);
candleDataSet.mShadowWidth = mShadowWidth;
candleDataSet.mShowCandleBar = mShowCandleBar;
candleDataSet.mBarSpace = mBarSpace;
candleDataSet.mShadowColorSameAsCandle = mShadowColorSameAsCandle;
candleDataSet.mHighLightColor = mHighLightColor;
candleDataSet.mIncreasingPaintStyle = mIncreasingPaintStyle;
candleDataSet.mDecreasingPaintStyle = mDecreasingPaintStyle;
candleDataSet.mNeutralColor = mNeutralColor;
candleDataSet.mIncreasingColor = mIncreasingColor;
candleDataSet.mDecreasingColor = mDecreasingColor;
candleDataSet.mShadowColor = mShadowColor;
}

@Override
protected void calcMinMax(CandleEntry e) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ public void setValues(List<T> values) {
*/
public abstract DataSet<T> copy();

/**
*
* @param dataSet
*/
protected void copy(DataSet dataSet) {
super.copy(dataSet);
}

@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet
/**
* the color of the inner circles
*/
private int mCircleColorHole = Color.WHITE;
private int mCircleHoleColor = Color.WHITE;

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

@Override
public DataSet<Entry> copy() {

List<Entry> yVals = new ArrayList<Entry>();

List<Entry> entries = new ArrayList<Entry>();
for (int i = 0; i < mValues.size(); i++) {
yVals.add(mValues.get(i).copy());
entries.add(mValues.get(i).copy());
}

LineDataSet copied = new LineDataSet(yVals, getLabel());
copied.mMode = mMode;
copied.mColors = mColors;
copied.mCircleRadius = mCircleRadius;
copied.mCircleHoleRadius = mCircleHoleRadius;
copied.mCircleColors = mCircleColors;
copied.mDashPathEffect = mDashPathEffect;
copied.mDrawCircles = mDrawCircles;
copied.mDrawCircleHole = mDrawCircleHole;
copied.mHighLightColor = mHighLightColor;

LineDataSet copied = new LineDataSet(entries, getLabel());
copy(copied);
return copied;
}

protected void copy(LineDataSet lineDataSet) {
super.copy(lineDataSet);
lineDataSet.mCircleColors = mCircleColors;
lineDataSet.mCircleHoleColor = mCircleHoleColor;
lineDataSet.mCircleHoleRadius = mCircleHoleRadius;
lineDataSet.mCircleRadius = mCircleRadius;
lineDataSet.mCubicIntensity = mCubicIntensity;
lineDataSet.mDashPathEffect = mDashPathEffect;
lineDataSet.mDrawCircleHole = mDrawCircleHole;
lineDataSet.mDrawCircles = mDrawCircleHole;
lineDataSet.mFillFormatter = mFillFormatter;
lineDataSet.mMode = mMode;
}

/**
* Returns the drawing mode for this line dataset
*
Expand Down Expand Up @@ -364,13 +366,13 @@ public void resetCircleColors() {
*
* @param color
*/
public void setCircleColorHole(int color) {
mCircleColorHole = color;
public void setCircleHoleColor(int color) {
mCircleHoleColor = color;
}

@Override
public int getCircleHoleColor() {
return mCircleColorHole;
return mCircleHoleColor;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,13 @@ public void setDrawFilled(boolean filled) {
public boolean isDrawFilledEnabled() {
return mDrawFilled;
}

protected void copy(LineRadarDataSet lineRadarDataSet) {
super.copy(lineRadarDataSet);
lineRadarDataSet.mDrawFilled = mDrawFilled;
lineRadarDataSet.mFillAlpha = mFillAlpha;
lineRadarDataSet.mFillColor = mFillColor;
lineRadarDataSet.mFillDrawable = mFillDrawable;
lineRadarDataSet.mLineWidth = mLineWidth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,12 @@ public boolean isDashedHighlightLineEnabled() {
public DashPathEffect getDashPathEffectHighlight() {
return mHighlightDashPathEffect;
}

protected void copy(LineScatterCandleRadarDataSet lineScatterCandleRadarDataSet) {
super.copy(lineScatterCandleRadarDataSet);
lineScatterCandleRadarDataSet.mDrawHorizontalHighlightIndicator = mDrawHorizontalHighlightIndicator;
lineScatterCandleRadarDataSet.mDrawVerticalHighlightIndicator = mDrawVerticalHighlightIndicator;
lineScatterCandleRadarDataSet.mHighlightLineWidth = mHighlightLineWidth;
lineScatterCandleRadarDataSet.mHighlightDashPathEffect = mHighlightDashPathEffect;
}
}
Loading

0 comments on commit 949d155

Please sign in to comment.