diff --git a/MPChartLib/build.gradle b/MPChartLib/build.gradle index b82f42add0..cfe239980b 100644 --- a/MPChartLib/build.gradle +++ b/MPChartLib/build.gradle @@ -47,6 +47,7 @@ android { dependencies { implementation 'androidx.annotation:annotation:1.9.1' + implementation 'androidx.core:core:1.16.0' testImplementation 'junit:junit:4.13.2' } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarDataSet.java index e65638805b..3f2c66dbe3 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarDataSet.java @@ -64,7 +64,7 @@ public DataSet copy() { } protected void copy(BarDataSet barDataSet) { - super.copy(barDataSet); + super.copy((BaseDataSet) barDataSet); barDataSet.mStackSize = mStackSize; barDataSet.mBarShadowColor = mBarShadowColor; barDataSet.mBarBorderWidth = mBarBorderWidth; diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java index eab6dccc55..fc8cc36e06 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java @@ -42,7 +42,7 @@ public int getHighLightColor() { } protected void copy(BarLineScatterCandleBubbleDataSet barLineScatterCandleBubbleDataSet) { - super.copy(barLineScatterCandleBubbleDataSet); + super.copy((BaseDataSet) barLineScatterCandleBubbleDataSet); barLineScatterCandleBubbleDataSet.mHighLightColor = mHighLightColor; } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java deleted file mode 100644 index b2b3798b6c..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java +++ /dev/null @@ -1,505 +0,0 @@ -package com.github.mikephil.charting.data; - -import android.content.Context; -import android.graphics.Color; -import android.graphics.DashPathEffect; -import android.graphics.Typeface; - -import com.github.mikephil.charting.components.Legend; -import com.github.mikephil.charting.components.YAxis; -import com.github.mikephil.charting.formatter.IValueFormatter; -import com.github.mikephil.charting.interfaces.datasets.IDataSet; -import com.github.mikephil.charting.utils.ColorTemplate; -import com.github.mikephil.charting.utils.MPPointF; -import com.github.mikephil.charting.utils.Utils; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by Philipp Jahoda on 21/10/15. - * This is the base dataset of all DataSets. It's purpose is to implement critical methods - * provided by the IDataSet interface. - */ -public abstract class BaseDataSet implements IDataSet { - - /** - * List representing all colors that are used for this DataSet - */ - protected List mColors = null; - - /** - * List representing all colors that are used for drawing the actual values for this DataSet - */ - protected List mValueColors = null; - - /** - * label that describes the DataSet or the data the DataSet represents - */ - private String mLabel = "DataSet"; - - /** - * this specifies which axis this DataSet should be plotted against - */ - protected YAxis.AxisDependency mAxisDependency = YAxis.AxisDependency.LEFT; - - /** - * if true, value highlightning is enabled - */ - protected boolean mHighlightEnabled = true; - - /** - * custom formatter that is used instead of the auto-formatter if set - */ - protected transient IValueFormatter mValueFormatter; - - /** - * the typeface used for the value text - */ - protected Typeface mValueTypeface; - - private Legend.LegendForm mForm = Legend.LegendForm.DEFAULT; - private float mFormSize = Float.NaN; - private float mFormLineWidth = Float.NaN; - private DashPathEffect mFormLineDashEffect = null; - - /** - * if true, y-values are drawn on the chart - */ - protected boolean mDrawValues = true; - - /** - * if true, y-icons are drawn on the chart - */ - protected boolean mDrawIcons = true; - - /** - * the offset for drawing icons (in dp) - */ - protected MPPointF mIconsOffset = new MPPointF(); - - /** - * the size of the value-text labels - */ - protected float mValueTextSize = 17f; - - /** - * flag that indicates if the DataSet is visible or not - */ - protected boolean mVisible = true; - - /** - * Default constructor. - */ - public BaseDataSet() { - mColors = new ArrayList<>(); - mValueColors = new ArrayList<>(); - - // default color - mColors.add(Color.rgb(140, 234, 255)); - mValueColors.add(Color.BLACK); - } - - /** - * Constructor with label. - * - * @param label - */ - public BaseDataSet(String label) { - this(); - this.mLabel = label; - } - - /** - * Use this method to tell the data set that the underlying data has changed. - */ - public void notifyDataSetChanged() { - calcMinMax(); - } - - - /** - * ###### ###### COLOR GETTING RELATED METHODS ##### ###### - */ - - @Override - public List getColors() { - return mColors; - } - - public List getValueColors() { - return mValueColors; - } - - @Override - public int getColor() { - return mColors.get(0); - } - - @Override - public int getColor(int index) { - return mColors.get(index % mColors.size()); - } - - /** - * ###### ###### COLOR SETTING RELATED METHODS ##### ###### - */ - - /** - * Sets the colors that should be used fore this DataSet. Colors are reused - * as soon as the number of Entries the DataSet represents is higher than - * the size of the colors array. If you are using colors from the resources, - * make sure that the colors are already prepared (by calling - * getResources().getColor(...)) before adding them to the DataSet. - * - * @param colors - */ - public void setColors(List colors) { - this.mColors = colors; - } - - /** - * Sets the colors that should be used fore this DataSet. Colors are reused - * as soon as the number of Entries the DataSet represents is higher than - * the size of the colors array. If you are using colors from the resources, - * make sure that the colors are already prepared (by calling - * getResources().getColor(...)) before adding them to the DataSet. - * - * @param colors - */ - public void setColors(int... colors) { - this.mColors = ColorTemplate.createColors(colors); - } - - /** - * Sets the colors that should be used fore this DataSet. Colors are reused - * as soon as the number of Entries the DataSet represents is higher than - * the size of the colors array. You can use - * "new int[] { R.color.red, R.color.green, ... }" to provide colors for - * this method. Internally, the colors are resolved using - * getResources().getColor(...) - * - * @param colors - */ - public void setColors(int[] colors, Context c) { - - if (mColors == null) { - mColors = new ArrayList<>(); - } - - mColors.clear(); - - for (int color : colors) { - mColors.add(c.getResources().getColor(color)); - } - } - - /** - * Adds a new color to the colors array of the DataSet. - * - * @param color - */ - public void addColor(int color) { - if (mColors == null) - mColors = new ArrayList<>(); - mColors.add(color); - } - - /** - * Sets the one and ONLY color that should be used for this DataSet. - * Internally, this recreates the colors array and adds the specified color. - * - * @param color - */ - public void setColor(int color) { - resetColors(); - mColors.add(color); - } - - /** - * Sets a color with a specific alpha value. - * - * @param color - * @param alpha from 0-255 - */ - public void setColor(int color, int alpha) { - setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))); - } - - /** - * Sets colors with a specific alpha value. - * - * @param colors - * @param alpha - */ - public void setColors(int[] colors, int alpha) { - resetColors(); - for (int color : colors) { - addColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))); - } - } - - /** - * Resets all colors of this DataSet and recreates the colors array. - */ - public void resetColors() { - if (mColors == null) { - mColors = new ArrayList<>(); - } - mColors.clear(); - } - - /** - * ###### ###### OTHER STYLING RELATED METHODS ##### ###### - */ - - @Override - public void setLabel(String label) { - mLabel = label; - } - - @Override - public String getLabel() { - return mLabel; - } - - @Override - public void setHighlightEnabled(boolean enabled) { - mHighlightEnabled = enabled; - } - - @Override - public boolean isHighlightEnabled() { - return mHighlightEnabled; - } - - @Override - public void setValueFormatter(IValueFormatter f) { - - if (f == null) - return; - else - mValueFormatter = f; - } - - @Override - public IValueFormatter getValueFormatter() { - if (needsFormatter()) - return Utils.getDefaultValueFormatter(); - return mValueFormatter; - } - - @Override - public boolean needsFormatter() { - return mValueFormatter == null; - } - - @Override - public void setValueTextColor(int color) { - mValueColors.clear(); - mValueColors.add(color); - } - - @Override - public void setValueTextColors(List colors) { - mValueColors = colors; - } - - @Override - public void setValueTypeface(Typeface tf) { - mValueTypeface = tf; - } - - @Override - public void setValueTextSize(float size) { - mValueTextSize = Utils.convertDpToPixel(size); - } - - @Override - public int getValueTextColor() { - return mValueColors.get(0); - } - - @Override - public int getValueTextColor(int index) { - return mValueColors.get(index % mValueColors.size()); - } - - @Override - public Typeface getValueTypeface() { - return mValueTypeface; - } - - @Override - public float getValueTextSize() { - return mValueTextSize; - } - - public void setForm(Legend.LegendForm form) { - mForm = form; - } - - @Override - public Legend.LegendForm getForm() { - return mForm; - } - - public void setFormSize(float formSize) { - mFormSize = formSize; - } - - @Override - public float getFormSize() { - return mFormSize; - } - - public void setFormLineWidth(float formLineWidth) { - mFormLineWidth = formLineWidth; - } - - @Override - public float getFormLineWidth() { - return mFormLineWidth; - } - - public void setFormLineDashEffect(DashPathEffect dashPathEffect) { - mFormLineDashEffect = dashPathEffect; - } - - @Override - public DashPathEffect getFormLineDashEffect() { - return mFormLineDashEffect; - } - - @Override - public void setDrawValues(boolean enabled) { - this.mDrawValues = enabled; - } - - @Override - public boolean isDrawValuesEnabled() { - return mDrawValues; - } - - @Override - public void setDrawIcons(boolean enabled) { - mDrawIcons = enabled; - } - - @Override - public boolean isDrawIconsEnabled() { - return mDrawIcons; - } - - @Override - public void setIconsOffset(MPPointF offsetDp) { - - mIconsOffset.x = offsetDp.x; - mIconsOffset.y = offsetDp.y; - } - - @Override - public MPPointF getIconsOffset() { - return mIconsOffset; - } - - @Override - public void setVisible(boolean visible) { - mVisible = visible; - } - - @Override - public boolean isVisible() { - return mVisible; - } - - @Override - public YAxis.AxisDependency getAxisDependency() { - return mAxisDependency; - } - - @Override - public void setAxisDependency(YAxis.AxisDependency dependency) { - mAxisDependency = dependency; - } - - - /** - * ###### ###### DATA RELATED METHODS ###### ###### - */ - - @Override - public int getIndexInEntries(int xIndex) { - - for (int i = 0; i < getEntryCount(); i++) { - if (xIndex == getEntryForIndex(i).getX()) - return i; - } - - return -1; - } - - @Override - public boolean removeFirst() { - - if (getEntryCount() > 0) { - - T entry = getEntryForIndex(0); - return removeEntry(entry); - } else - return false; - } - - @Override - public boolean removeLast() { - - if (getEntryCount() > 0) { - - T e = getEntryForIndex(getEntryCount() - 1); - return removeEntry(e); - } else - return false; - } - - @Override - public boolean removeEntryByXValue(float xValue) { - - T e = getEntryForXValue(xValue, Float.NaN); - return removeEntry(e); - } - - @Override - public boolean removeEntry(int index) { - - T e = getEntryForIndex(index); - return removeEntry(e); - } - - @Override - public boolean contains(T e) { - - for (int i = 0; i < getEntryCount(); i++) { - if (getEntryForIndex(i).equals(e)) - return true; - } - - 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.mHighlightEnabled = mHighlightEnabled; - baseDataSet.mIconsOffset = mIconsOffset; - baseDataSet.mValueColors = mValueColors; - baseDataSet.mValueFormatter = mValueFormatter; - baseDataSet.mValueTextSize = mValueTextSize; - baseDataSet.mVisible = mVisible; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.kt new file mode 100644 index 0000000000..dd37ddb55c --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.kt @@ -0,0 +1,426 @@ +package com.github.mikephil.charting.data + +import android.content.Context +import android.graphics.Color +import android.graphics.DashPathEffect +import android.graphics.Typeface +import androidx.core.content.ContextCompat +import com.github.mikephil.charting.components.Legend.LegendForm +import com.github.mikephil.charting.components.YAxis.AxisDependency +import com.github.mikephil.charting.formatter.IValueFormatter +import com.github.mikephil.charting.interfaces.datasets.IDataSet +import com.github.mikephil.charting.utils.ColorTemplate +import com.github.mikephil.charting.utils.MPPointF +import com.github.mikephil.charting.utils.Utils + +/** + * This is the base dataset of all DataSets. It's purpose is to implement critical methods + * provided by the IDataSet interface. + */ +abstract class BaseDataSet() : IDataSet { + /** + * List representing all colors that are used for this DataSet + */ + protected var mColors: MutableList + + /** + * List representing all colors that are used for drawing the actual values for this DataSet + */ + protected var mValueColors: MutableList + + /** + * label that describes the DataSet or the data the DataSet represents + */ + private var mLabel = "DataSet" + + /** + * this specifies which axis this DataSet should be plotted against + */ + protected var mAxisDependency: AxisDependency = AxisDependency.LEFT + + /** + * if true, value highlightning is enabled + */ + protected var mHighlightEnabled: Boolean = true + + /** + * custom formatter that is used instead of the auto-formatter if set + */ + @Transient + protected var mValueFormatter: IValueFormatter? = null + + /** + * the typeface used for the value text + */ + protected var mValueTypeface: Typeface? = null + + private var mForm = LegendForm.DEFAULT + private var mFormSize = Float.NaN + private var mFormLineWidth = Float.NaN + private var mFormLineDashEffect: DashPathEffect? = null + + /** + * if true, y-values are drawn on the chart + */ + protected var mDrawValues: Boolean = true + + /** + * if true, y-icons are drawn on the chart + */ + protected var mDrawIcons: Boolean = true + + /** + * the offset for drawing icons (in dp) + */ + protected var mIconsOffset: MPPointF = MPPointF() + + /** + * the size of the value-text labels + */ + protected var mValueTextSize: Float = 17f + + /** + * flag that indicates if the DataSet is visible or not + */ + protected var mVisible: Boolean = true + + /** + * Default constructor. + */ + init { + mColors = ArrayList() + mValueColors = ArrayList() + + // default color + mColors.add(Color.rgb(140, 234, 255)) + mValueColors.add(Color.BLACK) + } + + /** + * Constructor with label. + * + * @param label + */ + constructor(label: String) : this() { + this.mLabel = label + } + + /** + * Use this method to tell the data set that the underlying data has changed. + */ + fun notifyDataSetChanged() { + calcMinMax() + } + + override fun getColors(): List { + return mColors + } + + val valueColors: List + get() = mValueColors + + override fun getColor(): Int { + return mColors[0] + } + + override fun getColor(index: Int): Int { + return mColors[index % mColors.size] + } + + /** + * ###### ###### COLOR SETTING RELATED METHODS ##### ###### + */ + /** + * Sets the colors that should be used fore this DataSet. Colors are reused + * as soon as the number of Entries the DataSet represents is higher than + * the size of the colors array. If you are using colors from the resources, + * make sure that the colors are already prepared (by calling + * ContextCompat.getColor(context,..) before adding them to the DataSet. + * + * @param colors + */ + fun setColors(colors: MutableList) { + this.mColors = colors + } + + /** + * Sets the colors that should be used fore this DataSet. Colors are reused + * as soon as the number of Entries the DataSet represents is higher than + * the size of the colors array. If you are using colors from the resources, + * make sure that the colors are already prepared (by calling + * ContextCompat.getColor(context,...)) before adding them to the DataSet. + * + * @param colors + */ + fun setColors(vararg colors: Int) { + this.mColors = ColorTemplate.createColors(colors) + } + + /** + * Sets the colors that should be used fore this DataSet. Colors are reused + * as soon as the number of Entries the DataSet represents is higher than + * the size of the colors array. You can use + * "new int[] { R.color.red, R.color.green, ... }" to provide colors for + * this method. Internally, the colors are resolved using + * ContextCompat.getColor(context,...) + * + * @param colors + */ + fun setColors(colors: IntArray, context: Context) { + mColors.clear() + + for (color in colors) { + mColors.add(ContextCompat.getColor(context, color)) + } + } + + /** + * Adds a new color to the colors array of the DataSet. + * + * @param color + */ + fun addColor(color: Int) { + mColors.add(color) + } + + /** + * Sets the one and ONLY color that should be used for this DataSet. + * Internally, this recreates the colors array and adds the specified color. + * + * @param color + */ + fun setColor(color: Int) { + resetColors() + mColors.add(color) + } + + /** + * Sets a color with a specific alpha value. + * + * @param color + * @param alpha from 0-255 + */ + fun setColor(color: Int, alpha: Int) { + setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))) + } + + /** + * Sets colors with a specific alpha value. + * + * @param colors + * @param alpha + */ + fun setColors(colors: IntArray, alpha: Int) { + resetColors() + for (color in colors) { + addColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))) + } + } + + /** + * Resets all colors of this DataSet and recreates the colors array. + */ + fun resetColors() { + mColors.clear() + } + + /** + * ###### ###### OTHER STYLING RELATED METHODS ##### ###### + */ + override fun setLabel(label: String) { + mLabel = label + } + + override fun getLabel(): String { + return mLabel + } + + override fun setHighlightEnabled(enabled: Boolean) { + mHighlightEnabled = enabled + } + + override fun isHighlightEnabled(): Boolean { + return mHighlightEnabled + } + + override fun setValueFormatter(f: IValueFormatter?) { + if (f == null) return + else mValueFormatter = f + } + + override fun getValueFormatter(): IValueFormatter { + if (needsFormatter()) return Utils.getDefaultValueFormatter() + return mValueFormatter!! + } + + override fun needsFormatter(): Boolean { + return mValueFormatter == null + } + + override fun setValueTextColor(color: Int) { + mValueColors.clear() + mValueColors.add(color) + } + + override fun setValueTextColors(colors: MutableList) { + mValueColors = colors + } + + override fun setValueTypeface(tf: Typeface?) { + mValueTypeface = tf + } + + override fun setValueTextSize(size: Float) { + mValueTextSize = Utils.convertDpToPixel(size) + } + + override fun getValueTextColor(): Int { + return mValueColors[0] + } + + override fun getValueTextColor(index: Int): Int { + return mValueColors[index % mValueColors.size] + } + + override fun getValueTypeface(): Typeface? { + return mValueTypeface + } + + override fun getValueTextSize(): Float { + return mValueTextSize + } + + fun setForm(form: LegendForm) { + mForm = form + } + + override fun getForm(): LegendForm { + return mForm + } + + fun setFormSize(formSize: Float) { + mFormSize = formSize + } + + override fun getFormSize(): Float { + return mFormSize + } + + fun setFormLineWidth(formLineWidth: Float) { + mFormLineWidth = formLineWidth + } + + override fun getFormLineWidth(): Float { + return mFormLineWidth + } + + fun setFormLineDashEffect(dashPathEffect: DashPathEffect?) { + mFormLineDashEffect = dashPathEffect + } + + override fun getFormLineDashEffect(): DashPathEffect? { + return mFormLineDashEffect + } + + override fun setDrawValues(enabled: Boolean) { + this.mDrawValues = enabled + } + + override fun isDrawValuesEnabled(): Boolean { + return mDrawValues + } + + override fun setDrawIcons(enabled: Boolean) { + mDrawIcons = enabled + } + + override fun isDrawIconsEnabled(): Boolean { + return mDrawIcons + } + + override fun setIconsOffset(offsetDp: MPPointF) { + mIconsOffset.x = offsetDp.x + mIconsOffset.y = offsetDp.y + } + + override fun getIconsOffset(): MPPointF { + return mIconsOffset + } + + override fun setVisible(visible: Boolean) { + mVisible = visible + } + + override fun isVisible(): Boolean { + return mVisible + } + + override fun getAxisDependency(): AxisDependency { + return mAxisDependency + } + + override fun setAxisDependency(dependency: AxisDependency) { + mAxisDependency = dependency + } + + + /** + * ###### ###### DATA RELATED METHODS ###### ###### + */ + override fun getIndexInEntries(xIndex: Int): Int { + for (i in 0.. 0) { + val entry = getEntryForIndex(0) + return removeEntry(entry) + } else return false + } + + override fun removeLast(): Boolean { + if (entryCount > 0) { + val e = getEntryForIndex(entryCount - 1) + return removeEntry(e) + } else return false + } + + override fun removeEntryByXValue(xValue: Float): Boolean { + val e = getEntryForXValue(xValue, Float.NaN) + return removeEntry(e) + } + + override fun removeEntry(index: Int): Boolean { + val e = getEntryForIndex(index) + return removeEntry(e) + } + + override fun contains(e: T): Boolean { + for (i in 0..) { + 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.mHighlightEnabled = mHighlightEnabled + baseDataSet.mIconsOffset = mIconsOffset + baseDataSet.mValueColors = mValueColors + baseDataSet.mValueFormatter = mValueFormatter + baseDataSet.mValueTextSize = mValueTextSize + baseDataSet.mVisible = mVisible + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.java index dcd5b76cea..a9a016bcad 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleDataSet.java @@ -89,7 +89,7 @@ public DataSet copy() { } protected void copy(CandleDataSet candleDataSet) { - super.copy(candleDataSet); + super.copy((BaseDataSet) candleDataSet); candleDataSet.mShadowWidth = mShadowWidth; candleDataSet.mShowCandleBar = mShowCandleBar; candleDataSet.mBarSpace = mBarSpace; diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.java index 10d1837ecd..6590d5800e 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.java @@ -94,7 +94,7 @@ public DataSet copy() { } protected void copy(LineDataSet lineDataSet) { - super.copy(lineDataSet); + super.copy((BaseDataSet) lineDataSet); lineDataSet.mCircleColors = mCircleColors; lineDataSet.mCircleHoleColor = mCircleHoleColor; lineDataSet.mCircleHoleRadius = mCircleHoleRadius; diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.java index b4347e4647..df422666e3 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineRadarDataSet.java @@ -125,7 +125,7 @@ public boolean isDrawFilledEnabled() { } protected void copy(LineRadarDataSet lineRadarDataSet) { - super.copy(lineRadarDataSet); + super.copy((BaseDataSet) lineRadarDataSet); lineRadarDataSet.mDrawFilled = mDrawFilled; lineRadarDataSet.mFillAlpha = mFillAlpha; lineRadarDataSet.mFillColor = mFillColor; diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.java index d4618d809e..151294630d 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.java @@ -111,7 +111,7 @@ public DashPathEffect getDashPathEffectHighlight() { } protected void copy(LineScatterCandleRadarDataSet lineScatterCandleRadarDataSet) { - super.copy(lineScatterCandleRadarDataSet); + super.copy((BaseDataSet) lineScatterCandleRadarDataSet); lineScatterCandleRadarDataSet.mDrawHorizontalHighlightIndicator = mDrawHorizontalHighlightIndicator; lineScatterCandleRadarDataSet.mDrawVerticalHighlightIndicator = mDrawVerticalHighlightIndicator; lineScatterCandleRadarDataSet.mHighlightLineWidth = mHighlightLineWidth; diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java index e446b0bbaf..0497985a0c 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java @@ -50,7 +50,7 @@ public DataSet copy() { } protected void copy(PieDataSet pieDataSet) { - super.copy(pieDataSet); + super.copy((BaseDataSet) pieDataSet); } @Override diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.java index 8a9740b6b5..a01604b8c3 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.java @@ -111,7 +111,7 @@ public DataSet copy() { } protected void copy(RadarDataSet radarDataSet) { - super.copy(radarDataSet); + super.copy((BaseDataSet) radarDataSet); radarDataSet.mDrawHighlightCircleEnabled = mDrawHighlightCircleEnabled; radarDataSet.mHighlightCircleFillColor = mHighlightCircleFillColor; radarDataSet.mHighlightCircleInnerRadius = mHighlightCircleInnerRadius; diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.java index 85ed808160..95b2e1ff05 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.java @@ -57,7 +57,7 @@ public DataSet copy() { } protected void copy(ScatterDataSet scatterDataSet) { - super.copy(scatterDataSet); + super.copy((BaseDataSet) scatterDataSet); scatterDataSet.mShapeSize = mShapeSize; scatterDataSet.mShapeRenderer = mShapeRenderer; scatterDataSet.mScatterShapeHoleRadius = mScatterShapeHoleRadius; diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/Highlight.java b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/Highlight.java deleted file mode 100644 index f61b13ba0c..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/Highlight.java +++ /dev/null @@ -1,245 +0,0 @@ - -package com.github.mikephil.charting.highlight; - -import com.github.mikephil.charting.components.YAxis; - -import java.io.Serializable; - -/** - * Contains information needed to determine the highlighted value. - * - * @author Philipp Jahoda - */ -public class Highlight implements Serializable { - - /** - * the x-value of the highlighted value - */ - private float mX = Float.NaN; - - /** - * the y-value of the highlighted value - */ - private float mY = Float.NaN; - - /** - * the x-pixel of the highlight - */ - private float mXPx; - - /** - * the y-pixel of the highlight - */ - private float mYPx; - - /** - * the index of the data object - in case it refers to more than one - */ - private int mDataIndex = -1; - - /** - * the index of the dataset the highlighted value is in - */ - private int mDataSetIndex; - - /** - * index which value of a stacked bar entry is highlighted, default -1 - */ - private int mStackIndex = -1; - - /** - * the axis the highlighted value belongs to - */ - private YAxis.AxisDependency axis; - - /** - * the x-position (pixels) on which this highlight object was last drawn - */ - private float mDrawX; - - /** - * the y-position (pixels) on which this highlight object was last drawn - */ - private float mDrawY; - - public Highlight(float x, float y, int dataSetIndex, int dataIndex) { - this.mX = x; - this.mY = y; - this.mDataSetIndex = dataSetIndex; - this.mDataIndex = dataIndex; - } - - public Highlight(float x, float y, int dataSetIndex) { - this.mX = x; - this.mY = y; - this.mDataSetIndex = dataSetIndex; - this.mDataIndex = -1; - } - - public Highlight(float x, int dataSetIndex, int stackIndex) { - this(x, Float.NaN, dataSetIndex); - this.mStackIndex = stackIndex; - } - - /** - * constructor - * - * @param x the x-value of the highlighted value - * @param y the y-value of the highlighted value - * @param dataSetIndex the index of the DataSet the highlighted value belongs to - */ - public Highlight(float x, float y, float xPx, float yPx, int dataSetIndex, YAxis.AxisDependency axis) { - this.mX = x; - this.mY = y; - this.mXPx = xPx; - this.mYPx = yPx; - this.mDataSetIndex = dataSetIndex; - this.axis = axis; - } - - /** - * Constructor, only used for stacked-barchart. - * - * @param x the index of the highlighted value on the x-axis - * @param y the y-value of the highlighted value - * @param dataSetIndex the index of the DataSet the highlighted value belongs to - * @param stackIndex references which value of a stacked-bar entry has been - * selected - */ - public Highlight(float x, float y, float xPx, float yPx, int dataSetIndex, int stackIndex, YAxis.AxisDependency axis) { - this(x, y, xPx, yPx, dataSetIndex, axis); - this.mStackIndex = stackIndex; - } - - /** - * returns the x-value of the highlighted value - * - * @return - */ - public float getX() { - return mX; - } - - /** - * returns the y-value of the highlighted value - * - * @return - */ - public float getY() { - return mY; - } - - /** - * returns the x-position of the highlight in pixels - */ - public float getXPx() { - return mXPx; - } - - /** - * returns the y-position of the highlight in pixels - */ - public float getYPx() { - return mYPx; - } - - /** - * the index of the data object - in case it refers to more than one - * - * @return - */ - public int getDataIndex() { - return mDataIndex; - } - - public void setDataIndex(int mDataIndex) { - this.mDataIndex = mDataIndex; - } - - /** - * returns the index of the DataSet the highlighted value is in - * - * @return - */ - public int getDataSetIndex() { - return mDataSetIndex; - } - - /** - * Only needed if a stacked-barchart entry was highlighted. References the - * selected value within the stacked-entry. - * - * @return - */ - public int getStackIndex() { - return mStackIndex; - } - - public boolean isStacked() { - return mStackIndex >= 0; - } - - /** - * Returns the axis the highlighted value belongs to. - * - * @return - */ - public YAxis.AxisDependency getAxis() { - return axis; - } - - /** - * Sets the x- and y-position (pixels) where this highlight was last drawn. - * - * @param x - * @param y - */ - public void setDraw(float x, float y) { - this.mDrawX = x; - this.mDrawY = y; - } - - /** - * Returns the x-position in pixels where this highlight object was last drawn. - * - * @return - */ - public float getDrawX() { - return mDrawX; - } - - /** - * Returns the y-position in pixels where this highlight object was last drawn. - * - * @return - */ - public float getDrawY() { - return mDrawY; - } - - /** - * Returns true if this highlight object is equal to the other (compares - * xIndex and dataSetIndex) - * - * @param h - * @return - */ - public boolean equalTo(Highlight h) { - - if (h == null) - return false; - else { - if (this.mDataSetIndex == h.mDataSetIndex && this.mX == h.mX - && this.mStackIndex == h.mStackIndex && this.mDataIndex == h.mDataIndex) - return true; - else - return false; - } - } - - @Override - public String toString() { - return "Highlight, x: " + mX + ", y: " + mY + ", dataSetIndex: " + mDataSetIndex - + ", stackIndex (only stacked barentry): " + mStackIndex; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/Highlight.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/Highlight.kt new file mode 100644 index 0000000000..b89406425a --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/Highlight.kt @@ -0,0 +1,153 @@ +package com.github.mikephil.charting.highlight + +import com.github.mikephil.charting.components.YAxis.AxisDependency +import java.io.Serializable + +/** + * Contains information needed to determine the highlighted value. + */ +class Highlight : Serializable { + /** + * the x-value of the highlighted value + */ + var x: Float = Float.NaN + private set + + /** + * the y-value of the highlighted value + */ + var y: Float = Float.NaN + private set + + /** + * the x-pixel of the highlight + */ + var xPx: Float = 0f + private set + + /** + * the y-pixel of the highlight + */ + var yPx: Float = 0f + private set + + /** + * the index of the data object - in case it refers to more than one + */ + var dataIndex: Int = -1 + + /** + * the index of the dataset the highlighted value is in + */ + val dataSetIndex: Int + + /** + * index which value of a stacked bar entry is highlighted, default -1 + */ + var stackIndex: Int = -1 + private set + + /** + * the axis the highlighted value belongs to + */ + var axis: AxisDependency? = null + private set + + /** + * the x-position (pixels) on which this highlight object was last drawn + */ + var drawX: Float = 0f + private set + + /** + * the y-position (pixels) on which this highlight object was last drawn + */ + var drawY: Float = 0f + private set + + constructor(x: Float, y: Float, dataSetIndex: Int, dataIndex: Int) { + this.x = x + this.y = y + this.dataSetIndex = dataSetIndex + this.dataIndex = dataIndex + } + + constructor(x: Float, y: Float, dataSetIndex: Int) { + this.x = x + this.y = y + this.dataSetIndex = dataSetIndex + this.dataIndex = -1 + } + + constructor(x: Float, dataSetIndex: Int, stackIndex: Int) : this(x, Float.NaN, dataSetIndex) { + this.stackIndex = stackIndex + } + + /** + * constructor + * + * @param x the x-value of the highlighted value + * @param y the y-value of the highlighted value + * @param dataSetIndex the index of the DataSet the highlighted value belongs to + */ + constructor(x: Float, y: Float, xPx: Float, yPx: Float, dataSetIndex: Int, axis: AxisDependency?) { + this.x = x + this.y = y + this.xPx = xPx + this.yPx = yPx + this.dataSetIndex = dataSetIndex + this.axis = axis + } + + /** + * Constructor, only used for stacked-barchart. + * + * @param x the index of the highlighted value on the x-axis + * @param y the y-value of the highlighted value + * @param dataSetIndex the index of the DataSet the highlighted value belongs to + * @param stackIndex references which value of a stacked-bar entry has been + * selected + */ + constructor(x: Float, y: Float, xPx: Float, yPx: Float, dataSetIndex: Int, stackIndex: Int, axis: AxisDependency?) : this( + x, + y, + xPx, + yPx, + dataSetIndex, + axis + ) { + this.stackIndex = stackIndex + } + + val isStacked: Boolean + get() = stackIndex >= 0 + + /** + * Sets the x- and y-position (pixels) where this highlight was last drawn. + * + * @param x + * @param y + */ + fun setDraw(x: Float, y: Float) { + this.drawX = x + this.drawY = y + } + + /** + * Returns true if this highlight object is equal to the other (compares + * xIndex and dataSetIndex) + * + * @param h + * @return + */ + fun equalTo(h: Highlight?): Boolean { + return if (h == null) + false + else + this.dataSetIndex == h.dataSetIndex && this.x == h.x && this.stackIndex == h.stackIndex && this.dataIndex == h.dataIndex + } + + override fun toString(): String { + return "Highlight, x:$x y:$y dataSetIndex:$dataSetIndex stackIndex (only stacked barentry): $stackIndex" + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieHighlighter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieHighlighter.java deleted file mode 100644 index b4c5a1b24b..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieHighlighter.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.mikephil.charting.highlight; - -import com.github.mikephil.charting.charts.PieChart; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.interfaces.datasets.IPieDataSet; - -/** - * Created by philipp on 12/06/16. - */ -public class PieHighlighter extends PieRadarHighlighter { - - public PieHighlighter(PieChart chart) { - super(chart); - } - - @Override - protected Highlight getClosestHighlight(int index, float x, float y) { - - IPieDataSet set = mChart.getData().getDataSet(); - - final Entry entry = set.getEntryForIndex(index); - - return new Highlight(index, entry.getY(), x, y, 0, set.getAxisDependency()); - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieHighlighter.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieHighlighter.kt new file mode 100644 index 0000000000..362cdf0dd9 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieHighlighter.kt @@ -0,0 +1,14 @@ +package com.github.mikephil.charting.highlight + +import com.github.mikephil.charting.charts.PieChart +import com.github.mikephil.charting.data.Entry + +class PieHighlighter(chart: PieChart) : PieRadarHighlighter(chart) { + override fun getClosestHighlight(index: Int, x: Float, y: Float): Highlight { + val set = mChart!!.data!!.dataSet + + val entry: Entry = set.getEntryForIndex(index) + + return Highlight(index.toFloat(), entry.y, x, y, 0, set.axisDependency) + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieRadarHighlighter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieRadarHighlighter.java index a19906d75c..4e58b761d4 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieRadarHighlighter.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieRadarHighlighter.java @@ -9,58 +9,57 @@ /** * Created by philipp on 12/06/16. */ -public abstract class PieRadarHighlighter implements IHighlighter -{ +public abstract class PieRadarHighlighter implements IHighlighter { - protected T mChart; + protected T mChart; - /** - * buffer for storing previously highlighted values - */ - protected List mHighlightBuffer = new ArrayList(); + /** + * buffer for storing previously highlighted values + */ + protected List mHighlightBuffer = new ArrayList(); - public PieRadarHighlighter(T chart) { - this.mChart = chart; - } + public PieRadarHighlighter(T chart) { + this.mChart = chart; + } - @Override - public Highlight getHighlight(float x, float y) { + @Override + public Highlight getHighlight(float x, float y) { - float touchDistanceToCenter = mChart.distanceToCenter(x, y); + float touchDistanceToCenter = mChart.distanceToCenter(x, y); - // check if a slice was touched - if (touchDistanceToCenter > mChart.getRadius()) { + // check if a slice was touched + if (touchDistanceToCenter > mChart.getRadius()) { - // if no slice was touched, highlight nothing - return null; + // if no slice was touched, highlight nothing + return null; - } else { + } else { - float angle = mChart.getAngleForPoint(x, y); + float angle = mChart.getAngleForPoint(x, y); - if (mChart instanceof PieChart) { - angle /= mChart.getAnimator().getPhaseY(); - } + if (mChart instanceof PieChart) { + angle /= mChart.getAnimator().getPhaseY(); + } - int index = mChart.getIndexForAngle(angle); + int index = mChart.getIndexForAngle(angle); - // check if the index could be found - if (index < 0 || index >= mChart.getData().getMaxEntryCountSet().getEntryCount()) { - return null; + // check if the index could be found + if (index < 0 || index >= mChart.getData().getMaxEntryCountSet().getEntryCount()) { + return null; - } else { - return getClosestHighlight(index, x, y); - } - } - } + } else { + return getClosestHighlight(index, x, y); + } + } + } - /** - * Returns the closest Highlight object of the given objects based on the touch position inside the chart. - * - * @param index - * @param x - * @param y - * @return - */ - protected abstract Highlight getClosestHighlight(int index, float x, float y); + /** + * Returns the closest Highlight object of the given objects based on the touch position inside the chart. + * + * @param index + * @param x + * @param y + * @return + */ + protected abstract Highlight getClosestHighlight(int index, float x, float y); } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.java deleted file mode 100644 index 0f9454b2cd..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.mikephil.charting.interfaces.datasets; - -import com.github.mikephil.charting.data.Entry; - -/** - * Created by philipp on 21/10/15. - */ -public interface IBarLineScatterCandleBubbleDataSet extends IDataSet { - - /** - * Returns the color that is used for drawing the highlight indicators. - * - * @return - */ - int getHighLightColor(); -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt new file mode 100644 index 0000000000..75318c3a81 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.kt @@ -0,0 +1,8 @@ +package com.github.mikephil.charting.interfaces.datasets + +import com.github.mikephil.charting.data.Entry + +interface IBarLineScatterCandleBubbleDataSet : IDataSet { + + val highLightColor: Int +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.kt index 4d854cc7fd..c18906be97 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.kt @@ -24,11 +24,11 @@ import kotlin.math.sqrt */ @Suppress("MemberVisibilityCanBePrivate") class BarLineChartTouchListener( - chart: BarLineChartBase?>?>, + chart: BarLineChartBase?>?>, touchMatrix: Matrix, dragTriggerDistance: Float ) : - ChartTouchListener?>?>?>(chart) { + ChartTouchListener?>?>?>(chart) { /** * returns the matrix object the listener holds * diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.kt index 9d79a70b54..e53b28f7b0 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.kt @@ -269,7 +269,7 @@ abstract class AxisRenderer( /** * Sets the text color to use for the labels. Make sure to use - * getResources().getColor(...) when using a color from the resources. + * ContextCompat.getColor(context,...) when using a color from the resources. * * @param color */