1 2 package com.github.mikephil.charting.data; 3 4 import android.annotation.TargetApi; 5 import android.graphics.Color; 6 import android.graphics.drawable.Drawable; 7 8 import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet; 9 import com.github.mikephil.charting.utils.Utils; 10 11 import java.util.List; 12 13 /** 14 * Base dataset for line and radar DataSets. 15 * 16 * @author Philipp Jahoda 17 */ 18 public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandleRadarDataSet<T> implements ILineRadarDataSet<T> { 19 20 // TODO: Move to using `Fill` class 21 /** 22 * the color that is used for filling the line surface 23 */ 24 private int mFillColor = Color.rgb(140, 234, 255); 25 26 /** 27 * the drawable to be used for filling the line surface 28 */ 29 protected Drawable mFillDrawable; 30 31 /** 32 * transparency used for filling line surface 33 */ 34 private int mFillAlpha = 85; 35 36 /** 37 * the width of the drawn data lines 38 */ 39 private float mLineWidth = 2.5f; 40 41 /** 42 * if true, the data will also be drawn filled 43 */ 44 private boolean mDrawFilled = false; 45 46 LineRadarDataSet(List<T> yVals, String label)47 public LineRadarDataSet(List<T> yVals, String label) { 48 super(yVals, label); 49 } 50 51 @Override getFillColor()52 public int getFillColor() { 53 return mFillColor; 54 } 55 56 /** 57 * Sets the color that is used for filling the area below the line. 58 * Resets an eventually set "fillDrawable". 59 * 60 * @param color 61 */ setFillColor(int color)62 public void setFillColor(int color) { 63 mFillColor = color; 64 mFillDrawable = null; 65 } 66 67 @Override getFillDrawable()68 public Drawable getFillDrawable() { 69 return mFillDrawable; 70 } 71 72 /** 73 * Sets the drawable to be used to fill the area below the line. 74 * 75 * @param drawable 76 */ 77 @TargetApi(18) setFillDrawable(Drawable drawable)78 public void setFillDrawable(Drawable drawable) { 79 this.mFillDrawable = drawable; 80 } 81 82 @Override getFillAlpha()83 public int getFillAlpha() { 84 return mFillAlpha; 85 } 86 87 /** 88 * sets the alpha value (transparency) that is used for filling the line 89 * surface (0-255), default: 85 90 * 91 * @param alpha 92 */ setFillAlpha(int alpha)93 public void setFillAlpha(int alpha) { 94 mFillAlpha = alpha; 95 } 96 97 /** 98 * set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE: 99 * thinner line == better performance, thicker line == worse performance 100 * 101 * @param width 102 */ setLineWidth(float width)103 public void setLineWidth(float width) { 104 105 if (width < 0.0f) 106 width = 0.0f; 107 if (width > 10.0f) 108 width = 10.0f; 109 mLineWidth = Utils.convertDpToPixel(width); 110 } 111 112 @Override getLineWidth()113 public float getLineWidth() { 114 return mLineWidth; 115 } 116 117 @Override setDrawFilled(boolean filled)118 public void setDrawFilled(boolean filled) { 119 mDrawFilled = filled; 120 } 121 122 @Override isDrawFilledEnabled()123 public boolean isDrawFilledEnabled() { 124 return mDrawFilled; 125 } 126 copy(LineRadarDataSet lineRadarDataSet)127 protected void copy(LineRadarDataSet lineRadarDataSet) { 128 super.copy(lineRadarDataSet); 129 lineRadarDataSet.mDrawFilled = mDrawFilled; 130 lineRadarDataSet.mFillAlpha = mFillAlpha; 131 lineRadarDataSet.mFillColor = mFillColor; 132 lineRadarDataSet.mFillDrawable = mFillDrawable; 133 lineRadarDataSet.mLineWidth = mLineWidth; 134 } 135 } 136