diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/LineChart.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/LineChart.kt index ee0119848..3cefc5ee6 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/LineChart.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/LineChart.kt @@ -39,13 +39,13 @@ open class LineChart : BarLineChartBase, LineDataProvider { // Min and max values... val yAxisValueFormatter = axisLeft.valueFormatter - val minVal = yAxisValueFormatter.getFormattedValue(lineData.yMin, null) - val maxVal = yAxisValueFormatter.getFormattedValue(lineData.yMax, null) + val minVal = yAxisValueFormatter?.getFormattedValue(lineData.yMin, null) + val maxVal = yAxisValueFormatter?.getFormattedValue(lineData.yMax, null) // Data range... val xAxisValueFormatter = xAxis.valueFormatter - val minRange = xAxisValueFormatter.getFormattedValue(lineData.xMin, null) - val maxRange = xAxisValueFormatter.getFormattedValue(lineData.xMax, null) + val minRange = xAxisValueFormatter?.getFormattedValue(lineData.xMin, null) + val maxRange = xAxisValueFormatter?.getFormattedValue(lineData.xMax, null) val entries = if (numberOfPoints == 1) "entry" else "entries" return String.format( Locale.getDefault(), "The line chart has %d %s. " + diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitLine.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitLine.java index d044024ce..794896992 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitLine.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitLine.java @@ -16,7 +16,7 @@ public class LimitLine extends ComponentBase { /** limit / maximum (the y-value or xIndex) */ - private float mLimit; + private final float mLimit; /** the width of the limit line */ private float mLineWidth = 2f; @@ -130,7 +130,7 @@ public void disableDashedLine() { * disabled */ public boolean isDashedLineEnabled() { - return mDashPathEffect == null ? false : true; + return mDashPathEffect != null; } /** diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitRange.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitRange.java index 046bab334..55a98a3cc 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitRange.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitRange.java @@ -39,7 +39,7 @@ public float getHigh() { /** * limit / maximum (the y-value or xIndex) */ - private Range mLimit; + private final Range mLimit; /** * the width of the limit line @@ -182,7 +182,7 @@ public void disableDashedLine() { * disabled */ public boolean isDashedLineEnabled() { - return mDashPathEffect == null ? false : true; + return mDashPathEffect != null; } /** diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java index 4213547d1..d8a04ea86 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java @@ -19,406 +19,408 @@ */ public class YAxis extends AxisBase { - /** - * indicates if the bottom y-label entry is drawn or not - */ - private final boolean mDrawBottomYLabelEntry = true; - - /** - * indicates if the top y-label entry is drawn or not - */ - private boolean mDrawTopYLabelEntry = true; - - /** - * flag that indicates if the axis is inverted or not - */ - protected boolean mInverted = false; - - /** - * flag that indicates if the zero-line should be drawn regardless of other grid lines - */ - protected boolean mDrawZeroLine = false; - - /** - * flag indicating that auto scale min restriction should be used - */ - private boolean mUseAutoScaleRestrictionMin = false; - - /** - * flag indicating that auto scale max restriction should be used - */ - private boolean mUseAutoScaleRestrictionMax = false; - - /** - * Color of the zero line - */ - protected int mZeroLineColor = Color.GRAY; - - /** - * Width of the zero line in pixels - */ - protected float mZeroLineWidth = 1f; - - /** - * axis space from the largest value to the top in percent of the total axis range - */ - protected float mSpacePercentTop = 10f; - - /** - * axis space from the smallest value to the bottom in percent of the total axis range - */ - protected float mSpacePercentBottom = 10f; - - /** - * the position of the y-labels relative to the chart - */ - private YAxisLabelPosition mPosition = YAxisLabelPosition.OUTSIDE_CHART; - - /** - * the horizontal offset of the y-label - */ - private float mXLabelOffset = 0.0f; - - /** - * enum for the position of the y-labels relative to the chart - */ - public enum YAxisLabelPosition { - OUTSIDE_CHART, INSIDE_CHART - } - - /** - * the side this axis object represents - */ - private final AxisDependency mAxisDependency; - - /** - * the minimum width that the axis should take (in dp). - *

- * default: 0.0 - */ - protected float mMinWidth = 0.f; - - /** - * the maximum width that the axis can take (in dp). - * use Inifinity for disabling the maximum - * default: Float.POSITIVE_INFINITY (no maximum specified) - */ - protected float mMaxWidth = Float.POSITIVE_INFINITY; - - /** - * Enum that specifies the axis a DataSet should be plotted against, either LEFT or RIGHT. - * - * @author Philipp Jahoda - */ - public enum AxisDependency { - LEFT, RIGHT - } - - public YAxis() { - super(); - - // default left - this.mAxisDependency = AxisDependency.LEFT; - this.mYOffset = 0f; - } - - public YAxis(AxisDependency position) { - super(); - this.mAxisDependency = position; - this.mYOffset = 0f; - } - - public AxisDependency getAxisDependency() { - return mAxisDependency; - } - - /** - * @return the minimum width that the axis should take (in dp). - */ - public float getMinWidth() { - return mMinWidth; - } - - /** - * Sets the minimum width that the axis should take (in dp). - */ - public void setMinWidth(float minWidth) { - mMinWidth = minWidth; - } - - /** - * @return the maximum width that the axis can take (in dp). - */ - public float getMaxWidth() { - return mMaxWidth; - } - - /** - * Sets the maximum width that the axis can take (in dp). - */ - public void setMaxWidth(float maxWidth) { - mMaxWidth = maxWidth; - } - - /** - * returns the position of the y-labels - */ - public YAxisLabelPosition getLabelPosition() { - return mPosition; - } - - /** - * sets the position of the y-labels - */ - public void setPosition(YAxisLabelPosition pos) { - mPosition = pos; - } - - /** - * returns the horizontal offset of the y-label - */ - public float getLabelXOffset() { - return mXLabelOffset; - } - - /** - * sets the horizontal offset of the y-label - */ - public void setLabelXOffset(float xOffset) { - mXLabelOffset = xOffset; - } - - /** - * returns true if drawing the top y-axis label entry is enabled - */ - public boolean isDrawTopYLabelEntryEnabled() { - return mDrawTopYLabelEntry; - } - - /** - * returns true if drawing the bottom y-axis label entry is enabled - */ - public boolean isDrawBottomYLabelEntryEnabled() { - return mDrawBottomYLabelEntry; - } - - /** - * set this to true to enable drawing the top y-label entry. Disabling this can be helpful - * when the top y-label and - * left x-label interfere with each other. default: true - */ - public void setDrawTopYLabelEntry(boolean enabled) { - mDrawTopYLabelEntry = enabled; - } - - /** - * If this is set to true, the y-axis is inverted which means that low values are on top of - * the chart, high values - * on bottom. - */ - public void setInverted(boolean enabled) { - mInverted = enabled; - } - - /** - * If this returns true, the y-axis is inverted. - */ - public boolean isInverted() { - return mInverted; - } - - /** - * This method is deprecated. - * Use setAxisMinimum(...) / setAxisMaximum(...) instead. - */ - @Deprecated - public void setStartAtZero(boolean startAtZero) { - if (startAtZero) { - setAxisMinimum(0f); - } else { - resetAxisMinimum(); - } - } - - /** - * Sets the top axis space in percent of the full range. Default 10f - */ - public void setSpaceTop(float percent) { - mSpacePercentTop = percent; - } - - /** - * Returns the top axis space in percent of the full range. Default 10f - */ - public float getSpaceTop() { - return mSpacePercentTop; - } - - /** - * Sets the bottom axis space in percent of the full range. Default 10f - */ - public void setSpaceBottom(float percent) { - mSpacePercentBottom = percent; - } - - /** - * Returns the bottom axis space in percent of the full range. Default 10f - */ - public float getSpaceBottom() { - return mSpacePercentBottom; - } - - public boolean isDrawZeroLineEnabled() { - return mDrawZeroLine; - } - - /** - * Set this to true to draw the zero-line regardless of weather other - * grid-lines are enabled or not. Default: false - */ - public void setDrawZeroLine(boolean mDrawZeroLine) { - this.mDrawZeroLine = mDrawZeroLine; - } - - public int getZeroLineColor() { - return mZeroLineColor; - } - - /** - * Sets the color of the zero line - */ - public void setZeroLineColor(int color) { - mZeroLineColor = color; - } - - public float getZeroLineWidth() { - return mZeroLineWidth; - } - - /** - * Sets the width of the zero line in dp - */ - public void setZeroLineWidth(float width) { - this.mZeroLineWidth = UtilsKtKt.convertDpToPixel(width); - } - - /** - * This is for normal (not horizontal) charts horizontal spacing. - */ - public float getRequiredWidthSpace(Paint p) { - - p.setTextSize(mTextSize); - - String label = getLongestLabel(p); - float width = (float) Utils.calcTextWidth(p, label) + getXOffset() * 2f; - - float minWidth = getMinWidth(); - float maxWidth = getMaxWidth(); - - if (minWidth > 0.f) { - minWidth = UtilsKtKt.convertDpToPixel(minWidth); - } - - if (maxWidth > 0.f && maxWidth != Float.POSITIVE_INFINITY) { - maxWidth = UtilsKtKt.convertDpToPixel(maxWidth); - } - - width = Math.max(minWidth, Math.min(width, maxWidth > 0.0 ? maxWidth : width)); - - return width; - } - - /** - * This is for HorizontalBarChart vertical spacing. - */ - public float getRequiredHeightSpace(Paint p) { - - p.setTextSize(mTextSize); - - String label = getLongestLabel(p); - return (float) Utils.calcTextHeight(p, label) + getYOffset() * 2f; - } - - /** - * Returns true if this axis needs horizontal offset, false if no offset is needed. - */ - public boolean needsOffset() { - if (isEnabled() && isDrawLabelsEnabled() && getLabelPosition() == YAxisLabelPosition - .OUTSIDE_CHART) { - return true; - } else { - return false; - } - } - - /** - * Returns true if autoscale restriction for axis min value is enabled - */ - @Deprecated - public boolean isUseAutoScaleMinRestriction() { - return mUseAutoScaleRestrictionMin; - } - - /** - * Sets autoscale restriction for axis min value as enabled/disabled - */ - @Deprecated - public void setUseAutoScaleMinRestriction(boolean isEnabled) { - mUseAutoScaleRestrictionMin = isEnabled; - } - - /** - * Returns true if autoscale restriction for axis max value is enabled - */ - @Deprecated - public boolean isUseAutoScaleMaxRestriction() { - return mUseAutoScaleRestrictionMax; - } - - /** - * Sets autoscale restriction for axis max value as enabled/disabled - */ - @Deprecated - public void setUseAutoScaleMaxRestriction(boolean isEnabled) { - mUseAutoScaleRestrictionMax = isEnabled; - } - - - @Override - public void calculate(float dataMin, float dataMax) { - - float min = dataMin; - float max = dataMax; - - // Make sure max is greater than min - // Discussion: https://github.com/danielgindi/Charts/pull/3650#discussion_r221409991 - if (min > max) { - if (mCustomAxisMax && mCustomAxisMin) { - float t = min; - min = max; - max = t; - } else if (mCustomAxisMax) { - min = max < 0f ? max * 1.5f : max * 0.5f; - } else if (mCustomAxisMin) { - max = min < 0f ? min * 0.5f : min * 1.5f; - } - } - - float range = Math.abs(max - min); - - // in case all values are equal - if (range == 0f) { - max = max + 1f; - min = min - 1f; - } - - // recalculate - range = Math.abs(max - min); - - // calc extra spacing - this.mAxisMinimum = mCustomAxisMin ? this.mAxisMinimum : min - (range / 100f) * getSpaceBottom(); - this.mAxisMaximum = mCustomAxisMax ? this.mAxisMaximum : max + (range / 100f) * getSpaceTop(); - - this.mAxisRange = Math.abs(this.mAxisMinimum - this.mAxisMaximum); - } + /** + * indicates if the bottom y-label entry is drawn or not + */ + private final boolean mDrawBottomYLabelEntry = true; + + /** + * indicates if the top y-label entry is drawn or not + */ + private boolean mDrawTopYLabelEntry = true; + + /** + * flag that indicates if the axis is inverted or not + */ + protected boolean mInverted = false; + + /** + * flag that indicates if the zero-line should be drawn regardless of other grid lines + */ + protected boolean mDrawZeroLine = false; + + /** + * flag indicating that auto scale min restriction should be used + */ + private boolean mUseAutoScaleRestrictionMin = false; + + /** + * flag indicating that auto scale max restriction should be used + */ + private boolean mUseAutoScaleRestrictionMax = false; + + /** + * Color of the zero line + */ + protected int mZeroLineColor = Color.GRAY; + + /** + * Width of the zero line in pixels + */ + protected float mZeroLineWidth = 1f; + + /** + * axis space from the largest value to the top in percent of the total axis range + */ + protected float mSpacePercentTop = 10f; + + /** + * axis space from the smallest value to the bottom in percent of the total axis range + */ + protected float mSpacePercentBottom = 10f; + + /** + * the position of the y-labels relative to the chart + */ + private YAxisLabelPosition mPosition = YAxisLabelPosition.OUTSIDE_CHART; + + /** + * the horizontal offset of the y-label + */ + private float mXLabelOffset = 0.0f; + + /** + * enum for the position of the y-labels relative to the chart + */ + public enum YAxisLabelPosition { + OUTSIDE_CHART, INSIDE_CHART + } + + /** + * the side this axis object represents + */ + private final AxisDependency mAxisDependency; + + /** + * the minimum width that the axis should take (in dp). + *

+ * default: 0.0 + */ + protected float mMinWidth = 0.f; + + /** + * the maximum width that the axis can take (in dp). + * use Inifinity for disabling the maximum + * default: Float.POSITIVE_INFINITY (no maximum specified) + */ + protected float mMaxWidth = Float.POSITIVE_INFINITY; + + /** + * Enum that specifies the axis a DataSet should be plotted against, either LEFT or RIGHT. + * + * @author Philipp Jahoda + */ + public enum AxisDependency { + LEFT, RIGHT + } + + public YAxis() { + super(); + + // default left + this.mAxisDependency = AxisDependency.LEFT; + this.mYOffset = 0f; + } + + public YAxis(AxisDependency position) { + super(); + this.mAxisDependency = position; + this.mYOffset = 0f; + } + + public AxisDependency getAxisDependency() { + return mAxisDependency; + } + + /** + * @return the minimum width that the axis should take (in dp). + */ + public float getMinWidth() { + return mMinWidth; + } + + /** + * Sets the minimum width that the axis should take (in dp). + */ + public void setMinWidth(float minWidth) { + mMinWidth = minWidth; + } + + /** + * @return the maximum width that the axis can take (in dp). + */ + public float getMaxWidth() { + return mMaxWidth; + } + + /** + * Sets the maximum width that the axis can take (in dp). + */ + public void setMaxWidth(float maxWidth) { + mMaxWidth = maxWidth; + } + + /** + * returns the position of the y-labels + */ + public YAxisLabelPosition getLabelPosition() { + return mPosition; + } + + /** + * sets the position of the y-labels + */ + public void setPosition(YAxisLabelPosition pos) { + mPosition = pos; + } + + /** + * returns the horizontal offset of the y-label + */ + public float getLabelXOffset() { + return mXLabelOffset; + } + + /** + * sets the horizontal offset of the y-label + */ + public void setLabelXOffset(float xOffset) { + mXLabelOffset = xOffset; + } + + /** + * returns true if drawing the top y-axis label entry is enabled + */ + public boolean isDrawTopYLabelEntryEnabled() { + return mDrawTopYLabelEntry; + } + + /** + * returns true if drawing the bottom y-axis label entry is enabled + */ + public boolean isDrawBottomYLabelEntryEnabled() { + return mDrawBottomYLabelEntry; + } + + /** + * set this to true to enable drawing the top y-label entry. Disabling this can be helpful + * when the top y-label and + * left x-label interfere with each other. default: true + */ + public void setDrawTopYLabelEntry(boolean enabled) { + mDrawTopYLabelEntry = enabled; + } + + /** + * If this is set to true, the y-axis is inverted which means that low values are on top of + * the chart, high values + * on bottom. + */ + public void setInverted(boolean enabled) { + mInverted = enabled; + } + + /** + * If this returns true, the y-axis is inverted. + */ + public boolean isInverted() { + return mInverted; + } + + /** + * This method is deprecated. + * Use setAxisMinimum(...) / setAxisMaximum(...) instead. + */ + @Deprecated + public void setStartAtZero(boolean startAtZero) { + if (startAtZero) + setAxisMinimum(0f); + else + resetAxisMinimum(); + } + + /** + * Sets the top axis space in percent of the full range. Default 10f + */ + public void setSpaceTop(float percent) { + mSpacePercentTop = percent; + } + + /** + * Returns the top axis space in percent of the full range. Default 10f + */ + public float getSpaceTop() { + return mSpacePercentTop; + } + + /** + * Sets the bottom axis space in percent of the full range. Default 10f + */ + public void setSpaceBottom(float percent) { + mSpacePercentBottom = percent; + } + + /** + * Returns the bottom axis space in percent of the full range. Default 10f + */ + public float getSpaceBottom() { + return mSpacePercentBottom; + } + + public boolean isDrawZeroLineEnabled() { + return mDrawZeroLine; + } + + /** + * Set this to true to draw the zero-line regardless of weather other + * grid-lines are enabled or not. Default: false + */ + public void setDrawZeroLine(boolean mDrawZeroLine) { + this.mDrawZeroLine = mDrawZeroLine; + } + + public int getZeroLineColor() { + return mZeroLineColor; + } + + /** + * Sets the color of the zero line + */ + public void setZeroLineColor(int color) { + mZeroLineColor = color; + } + + public float getZeroLineWidth() { + return mZeroLineWidth; + } + + /** + * Sets the width of the zero line in dp + */ + public void setZeroLineWidth(float width) { + this.mZeroLineWidth = UtilsKtKt.convertDpToPixel(width); + } + + /** + * This is for normal (not horizontal) charts horizontal spacing. + */ + public float getRequiredWidthSpace(Paint p) { + + p.setTextSize(mTextSize); + + String label = getLongestLabel(p); + float width = (float) Utils.calcTextWidth(p, label) + getXOffset() * 2f; + + float minWidth = getMinWidth(); + float maxWidth = getMaxWidth(); + + if (minWidth > 0.f) + minWidth = UtilsKtKt.convertDpToPixel(minWidth); + + if (maxWidth > 0.f && maxWidth != Float.POSITIVE_INFINITY) + maxWidth = UtilsKtKt.convertDpToPixel(maxWidth); + + width = Math.max(minWidth, Math.min(width, maxWidth > 0.0 ? maxWidth : width)); + + return width; + } + + /** + * This is for HorizontalBarChart vertical spacing. + */ + public float getRequiredHeightSpace(Paint p) { + + p.setTextSize(mTextSize); + + String label = getLongestLabel(p); + return (float) Utils.calcTextHeight(p, label) + getYOffset() * 2f; + } + + /** + * Returns true if this axis needs horizontal offset, false if no offset is needed. + */ + public boolean needsOffset() { + if (isEnabled() && isDrawLabelsEnabled() && getLabelPosition() == YAxisLabelPosition + .OUTSIDE_CHART) + return true; + else + return false; + } + + /** + * Returns true if autoscale restriction for axis min value is enabled + */ + @Deprecated + public boolean isUseAutoScaleMinRestriction( ) { + return mUseAutoScaleRestrictionMin; + } + + /** + * Sets autoscale restriction for axis min value as enabled/disabled + */ + @Deprecated + public void setUseAutoScaleMinRestriction( boolean isEnabled ) { + mUseAutoScaleRestrictionMin = isEnabled; + } + + /** + * Returns true if autoscale restriction for axis max value is enabled + */ + @Deprecated + public boolean isUseAutoScaleMaxRestriction() { + return mUseAutoScaleRestrictionMax; + } + + /** + * Sets autoscale restriction for axis max value as enabled/disabled + */ + @Deprecated + public void setUseAutoScaleMaxRestriction( boolean isEnabled ) { + mUseAutoScaleRestrictionMax = isEnabled; + } + + + @Override + public void calculate(float dataMin, float dataMax) { + + float min = dataMin; + float max = dataMax; + + // Make sure max is greater than min + // Discussion: https://github.com/danielgindi/Charts/pull/3650#discussion_r221409991 + if (min > max) + { + if (isAxisMaxCustom() && isAxisMinCustom()) + { + float t = min; + min = max; + max = t; + } + else if (isAxisMaxCustom()) + { + min = max < 0f ? max * 1.5f : max * 0.5f; + } + else if (isAxisMinCustom()) + { + max = min < 0f ? min * 0.5f : min * 1.5f; + } + } + + float range = Math.abs(max - min); + + // in case all values are equal + if (range == 0f) { + max = max + 1f; + min = min - 1f; + } + + // recalculate + range = Math.abs(max - min); + + // calc extra spacing + this.mAxisMinimum = isAxisMinCustom() ? this.mAxisMinimum : min - (range / 100f) * getSpaceBottom(); + this.mAxisMaximum = isAxisMaxCustom() ? this.mAxisMaximum : max + (range / 100f) * getSpaceTop(); + + this.mAxisRange = Math.abs(this.mAxisMinimum - this.mAxisMaximum); + } } 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 index b40048cd3..9f8eb2546 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.kt @@ -59,6 +59,9 @@ abstract class BaseDataSet() : IDataSet { private var mFormSize = Float.NaN private var mFormLineWidth = Float.NaN private var mFormLineDashEffect: DashPathEffect? = null + private var mIsVisible = true + private var mIsDrawValues = true + private var mIsDrawIcons = true /** * if true, y-values are drawn on the chart @@ -105,24 +108,61 @@ abstract class BaseDataSet() : IDataSet { calcMinMax() } - override fun getColors(): List { - return mColors + /** + * Sets a color with a specific alpha value. + * + * @param color + * @param alpha from 0-255 + */ + fun setColor(color: Int, alpha: Int) { + mColors.clear() + mColors.add(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))) } - val valueColors: List - get() = mValueColors + override var color: Int + get() = mColors[0] + set(value) { + mColors.clear() + mColors.add(value) + } - override fun getColor(): Int { - return mColors[0] - } + override val colors: MutableList + get() = mColors override fun getColorByIndex(index: Int): Int { return mColors[index % mColors.size] } - /** - * ###### ###### COLOR SETTING RELATED METHODS ##### ###### - */ + override var formLineDashEffect: DashPathEffect? + get() = mFormLineDashEffect + set(value) { + mFormLineDashEffect = value + } + + override var isDrawValues: Boolean + get() = mIsDrawValues + set(value) { + mIsDrawValues = value + } + + override var isDrawIcons: Boolean + get() = mIsDrawIcons + set(value) { + mIsDrawIcons = value + } + + override var iconsOffset: MPPointF + get() = mIconsOffset + set(value) { + mIconsOffset = value + } + + override var formLineWidth: Float + get() = mFormLineWidth + set(value) { + mFormLineWidth = value + } + /** * 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 @@ -176,27 +216,6 @@ abstract class BaseDataSet() : IDataSet { 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. * @@ -217,149 +236,83 @@ abstract class BaseDataSet() : IDataSet { 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 var label: String? + get() = mLabel + set(value) { + if (value != null) { + mLabel = value + } + } + override var axisDependency: AxisDependency + get() = mAxisDependency + set(value) { + mAxisDependency = value + } - override fun setValueFormatter(f: IValueFormatter?) { - if (f == null) return - else mValueFormatter = f - } + override var isHighlightEnabled: Boolean + get() = mHighlightEnabled + set(value) { + mHighlightEnabled = value + } - override fun getValueFormatter(): IValueFormatter { - if (needsFormatter()) return Utils.getDefaultValueFormatter() - return mValueFormatter!! - } + override var valueFormatter: IValueFormatter + get() = if (needsFormatter()) + Utils.getDefaultValueFormatter() + else + mValueFormatter!! + set(value) { + mValueFormatter = value + } 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 = size.convertDpToPixel() + override fun setSingleValueTextColor(value: Int) { + mValueColors.clear() + mValueColors.add(value) } - override fun getValueTextColor(): Int { - return mValueColors[0] - } + override var valueTextColors: MutableList + get() = mValueColors + set(value) { + mValueColors = value + } 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 isDrawValues(): Boolean { - return mDrawValues - } - - override fun setDrawIcons(enabled: Boolean) { - mDrawIcons = enabled - } - - override fun isDrawIcons(): 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 var valueTypeface: Typeface? + get() = mValueTypeface + set(value) { + mValueTypeface = value + } - override fun isVisible(): Boolean { - return mVisible - } + override var valueTextSize: Float + get() = mValueTextSize + set(value) { + mValueTextSize = value.convertDpToPixel() + } - override fun getAxisDependency(): AxisDependency { - return mAxisDependency - } + override var form: LegendForm + get() = mForm + set(value) { + mForm = value + } - override fun setAxisDependency(dependency: AxisDependency) { - mAxisDependency = dependency - } + override var formSize: Float + get() = mFormSize + set(value) { + mFormSize = value + } + override var isVisible: Boolean + get() = mIsVisible + set(value) { + mIsVisible = value + } - /** - * ###### ###### DATA RELATED METHODS ###### ###### - */ override fun getIndexInEntries(xIndex: Int): Int { for (i in 0..() : IDataSet { override fun removeFirst(): Boolean { if (entryCount > 0) { val entry = getEntryForIndex(0) - return removeEntry(entry) + return if (entry != null) removeEntry(entry) else false } else return false } override fun removeLast(): Boolean { if (entryCount > 0) { - val e = getEntryForIndex(entryCount - 1) - return removeEntry(e) + val entry = getEntryForIndex(entryCount - 1) + return if (entry != null) removeEntry(entry) else false } else return false } override fun removeEntryByXValue(xValue: Float): Boolean { - val e = getEntryForXValue(xValue, Float.NaN) - return removeEntry(e) + val entry = getEntryForXValue(xValue, Float.NaN) + return if (entry != null) removeEntry(entry) else false } override fun removeEntry(index: Int): Boolean { - val e = getEntryForIndex(index) - return removeEntry(e) + val entry = getEntryForIndex(index) + return if (entry != null) removeEntry(entry) else false } - override fun contains(e: T): Boolean { + override fun contains(entry: T): Boolean { for (i in 0..() : IDataSet { baseDataSet.mDrawValues = mDrawValues baseDataSet.mForm = mForm baseDataSet.mFormLineDashEffect = mFormLineDashEffect - baseDataSet.mFormLineWidth = mFormLineWidth + baseDataSet.formLineWidth = formLineWidth baseDataSet.mFormSize = mFormSize baseDataSet.mHighlightEnabled = mHighlightEnabled baseDataSet.mIconsOffset = mIconsOffset diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/ChartData.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/ChartData.java index 58639fb9e..b011b0b14 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/ChartData.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/ChartData.java @@ -67,15 +67,15 @@ public ChartData() { /** * Constructor taking single or multiple DataSet objects. */ - public ChartData(T... dataSets) { - mDataSets = arrayToList(dataSets); - notifyDataChanged(); - } + public ChartData(T... dataSets) { + mDataSets = arrayToList(dataSets); + notifyDataChanged(); + } /** * Created because Arrays.asList(...) does not support modification. */ - private List arrayToList(T[] array) { + private List arrayToList(T[] array) { List list = new ArrayList<>(); @@ -199,15 +199,15 @@ public int getDataSetCount() { /** * Returns the smallest y-value the data object contains. */ - public float getYMin() { - return mYMin; - } + public float getYMin() { + return mYMin; + } /** * Returns the minimum y-value for the specified axis. */ - public float getYMin(AxisDependency axis) { - if (axis == AxisDependency.LEFT) { + public float getYMin(AxisDependency axis) { + if (axis == AxisDependency.LEFT) { if (mLeftAxisMin == Float.MAX_VALUE) { return mRightAxisMin; @@ -226,15 +226,15 @@ public float getYMin(AxisDependency axis) { /** * Returns the greatest y-value the data object contains. */ - public float getYMax() { - return mYMax; - } + public float getYMax() { + return mYMax; + } /** * Returns the maximum y-value for the specified axis. */ - public float getYMax(AxisDependency axis) { - if (axis == AxisDependency.LEFT) { + public float getYMax(AxisDependency axis) { + if (axis == AxisDependency.LEFT) { if (mLeftAxisMax == -Float.MAX_VALUE) { return mRightAxisMax; @@ -253,23 +253,23 @@ public float getYMax(AxisDependency axis) { /** * Returns the minimum x-value this data object contains. */ - public float getXMin() { - return mXMin; - } + public float getXMin() { + return mXMin; + } /** * Returns the maximum x-value this data object contains. */ - public float getXMax() { - return mXMax; - } + public float getXMax() { + return mXMax; + } /** * Returns all DataSet objects this ChartData object holds. */ - public List getDataSets() { - return mDataSets; - } + public List getDataSets() { + return mDataSets; + } /** * Retrieve the index of a DataSet with a specific label from the ChartData. @@ -303,7 +303,7 @@ protected int getDataSetIndexByLabel(List dataSets, String label, /** * Returns the labels of all DataSets as a string array. */ - public String[] getDataSetLabels() { + public String[] getDataSetLabels() { String[] types = new String[mDataSets.size()]; @@ -316,7 +316,6 @@ public String[] getDataSetLabels() { /** * Get the Entry for a corresponding highlight object - * * @return the entry that is highlighted */ public Entry getEntryForHighlight(Highlight highlight) { @@ -332,7 +331,7 @@ public Entry getEntryForHighlight(Highlight highlight) { * sensitive or not. IMPORTANT: This method does calculations at runtime. * Use with care in performance critical situations. */ - public T getDataSetByLabel(String label, boolean ignorecase) { + public T getDataSetByLabel(String label, boolean ignorecase) { int index = getDataSetIndexByLabel(mDataSets, label, ignorecase); @@ -355,7 +354,7 @@ public T getDataSetByIndex(int index) { /** * Adds a DataSet dynamically. */ - public void addDataSet(T d) { + public void addDataSet(T d) { if (d == null) { return; @@ -371,7 +370,7 @@ public void addDataSet(T d) { * minimum and maximum values. Returns true if a DataSet was removed, false * if no DataSet could be removed. */ - public boolean removeDataSet(T d) { + public boolean removeDataSet(T d) { if (d == null) { return false; @@ -392,7 +391,7 @@ public boolean removeDataSet(T d) { * object. Also recalculates all minimum and maximum values. Returns true if * a DataSet was removed, false if no DataSet could be removed. */ - public boolean removeDataSet(int index) { + public boolean removeDataSet(int index) { if (index >= mDataSets.size() || index < 0) { return false; @@ -406,7 +405,7 @@ public boolean removeDataSet(int index) { * Adds an Entry to the DataSet at the specified index. * Entries are added to the end of the list. */ - public void addEntry(Entry e, int dataSetIndex) { + public void addEntry(Entry e, int dataSetIndex) { if (mDataSets.size() > dataSetIndex && dataSetIndex >= 0) { @@ -426,7 +425,7 @@ public void addEntry(Entry e, int dataSetIndex) { /** * Adjusts the current minimum and maximum values based on the provided Entry object. */ - protected void calcMinMax(Entry e, AxisDependency axis) { + protected void calcMinMax(Entry e, AxisDependency axis) { if (mYMax < e.getY()) { mYMax = e.getY(); @@ -463,7 +462,7 @@ protected void calcMinMax(Entry e, AxisDependency axis) { /** * Adjusts the minimum and maximum values based on the given DataSet. */ - protected void calcMinMax(T d) { + protected void calcMinMax(T d) { if (mYMax < d.getYMax()) { mYMax = d.getYMax(); @@ -500,7 +499,7 @@ protected void calcMinMax(T d) { /** * Removes the given Entry object from the DataSet at the specified index. */ - public boolean removeEntry(Entry e, int dataSetIndex) { + public boolean removeEntry(Entry e, int dataSetIndex) { // entry null, outofbounds if (e == null || dataSetIndex >= mDataSets.size()) { @@ -528,7 +527,7 @@ public boolean removeEntry(Entry e, int dataSetIndex) { * specified index. Returns true if an Entry was removed, false if no Entry * was found that meets the specified requirements. */ - public boolean removeEntry(float xValue, int dataSetIndex) { + public boolean removeEntry(float xValue, int dataSetIndex) { if (dataSetIndex >= mDataSets.size()) { return false; @@ -548,7 +547,7 @@ public boolean removeEntry(float xValue, int dataSetIndex) { * Returns the DataSet that contains the provided Entry, or null, if no * DataSet contains this Entry. */ - public T getDataSetForEntry(Entry e) { + public T getDataSetForEntry(Entry e) { if (e == null) { return null; @@ -572,7 +571,7 @@ public T getDataSetForEntry(Entry e) { * Returns all colors used across all DataSet objects this object * represents. */ - public int[] getColors() { + public int[] getColors() { if (mDataSets == null) { return null; @@ -603,17 +602,17 @@ public int[] getColors() { /** * Returns the index of the provided DataSet in the DataSet array of this data object, or -1 if it does not exist. */ - public int getIndexOfDataSet(T dataSet) { - return mDataSets.indexOf(dataSet); - } + public int getIndexOfDataSet(T dataSet) { + return mDataSets.indexOf(dataSet); + } /** * Returns the first DataSet from the datasets-array that has it's dependency on the left axis. * Returns null if no DataSet with left dependency could be found. */ - protected T getFirstLeft(List sets) { - for (T dataSet : sets) { - if (dataSet.getAxisDependency() == AxisDependency.LEFT) { + protected T getFirstLeft(List sets) { + for (T dataSet : sets) { + if (dataSet.getAxisDependency() == AxisDependency.LEFT){ return dataSet; } } @@ -624,9 +623,9 @@ protected T getFirstLeft(List sets) { * Returns the first DataSet from the datasets-array that has it's dependency on the right axis. * Returns null if no DataSet with right dependency could be found. */ - public T getFirstRight(List sets) { - for (T dataSet : sets) { - if (dataSet.getAxisDependency() == AxisDependency.RIGHT) { + public T getFirstRight(List sets) { + for (T dataSet : sets) { + if (dataSet.getAxisDependency() == AxisDependency.RIGHT){ return dataSet; } } @@ -646,51 +645,51 @@ public void setValueFormatter(IValueFormatter f) { * Sets the color of the value-text (color in which the value-labels are * drawn) for all DataSets this data object contains. */ - public void setValueTextColor(int color) { - for (IDataSet set : mDataSets) { - set.setValueTextColor(color); - } - } + public void setValueTextColor(int color) { + for (IDataSet set : mDataSets) { + set.setSingleValueTextColor(color); + } + } /** * Sets the same list of value-colors for all DataSets this * data object contains. */ - public void setValueTextColors(List colors) { - for (IDataSet set : mDataSets) { - set.setValueTextColors(colors); - } - } + public void setValueTextColors(List colors) { + for (IDataSet set : mDataSets) { + set.setValueTextColors(colors); + } + } /** * Sets the Typeface for all value-labels for all DataSets this data object * contains. */ - public void setValueTypeface(Typeface tf) { - for (IDataSet set : mDataSets) { - set.setValueTypeface(tf); - } - } + public void setValueTypeface(Typeface tf) { + for (IDataSet set : mDataSets) { + set.setValueTypeface(tf); + } + } /** * Sets the size (in dp) of the value-text for all DataSets this data object * contains. */ - public void setValueTextSize(float size) { - for (IDataSet set : mDataSets) { - set.setValueTextSize(size); - } - } + public void setValueTextSize(float size) { + for (IDataSet set : mDataSets) { + set.setValueTextSize(size); + } + } /** * Enables / disables drawing values (value-text) for all DataSets this data * object contains. */ - public void setDrawValues(boolean enabled) { - for (IDataSet set : mDataSets) { - set.setDrawValues(enabled); - } - } + public void setDrawValues(boolean enabled) { + for (IDataSet set : mDataSets) { + set.setDrawValues(enabled); + } + } /** * Enables / disables highlighting values for all DataSets this data object @@ -706,9 +705,9 @@ public void setHighlightEnabled(boolean enabled) { /** * Returns true if highlighting of all underlying values is enabled, false if not. */ - public boolean isHighlightEnabled() { - for (IDataSet set : mDataSets) { - if (!set.isHighlightEnabled()) { + public boolean isHighlightEnabled() { + for (IDataSet set : mDataSets) { + if (!set.isHighlightEnabled()){ return false; } } @@ -730,7 +729,7 @@ public void clearValues() { * Checks if this data object contains the specified DataSet. Returns true * if so, false if not. */ - public boolean contains(T dataSet) { + public boolean contains(T dataSet) { for (T set : mDataSets) { if (set.equals(dataSet)) { @@ -744,7 +743,7 @@ public boolean contains(T dataSet) { /** * Returns the total entry count across all DataSet objects this data object contains. */ - public int getEntryCount() { + public int getEntryCount() { int count = 0; for (T set : mDataSets) { @@ -757,7 +756,7 @@ public int getEntryCount() { /** * Returns the DataSet object with the maximum number of entries or null if there are no DataSets. */ - public T getMaxEntryCountSet() { + public T getMaxEntryCountSet() { if (mDataSets == null || mDataSets.isEmpty()) { return null; diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.java index 6e6821bee..daf33dbf0 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.java @@ -1,10 +1,14 @@ package com.github.mikephil.charting.data; +import android.util.Log; + import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import androidx.annotation.NonNull; + /** * The DataSet class represents one group or type of entries (Entry) in the * Chart that belong together. It is designed to logically separate different @@ -46,6 +50,7 @@ public abstract class DataSet extends BaseDataSet implements * label that describes the DataSet can be specified. The label can also be * used to retrieve the DataSet from a ChartData object. */ + public DataSet(List entries, String label) { super(label); this.mEntries = entries; @@ -100,6 +105,7 @@ public void calcMinMaxY(float fromX, float toX) { /** * Updates the min and max x and y value of this DataSet based on the given Entry. */ + protected void calcMinMax(T entry) { if (entry == null) { @@ -141,6 +147,7 @@ public int getEntryCount() { * This method is deprecated. * Use getEntries() instead. */ + @Deprecated public List getValues() { return mEntries; @@ -149,6 +156,7 @@ public List getValues() { /** * Returns the array of entries that this DataSet represents. */ + public List getEntries() { return mEntries; } @@ -157,6 +165,7 @@ public List getEntries() { * This method is deprecated. * Use setEntries(...) instead. */ + @Deprecated public void setValues(List values) { setEntries(values); @@ -165,6 +174,7 @@ public void setValues(List values) { /** * Sets the array of entries that this DataSet represents, and calls notifyDataSetChanged() */ + public void setEntries(List entries) { mEntries = entries; notifyDataSetChanged(); @@ -173,18 +183,21 @@ public void setEntries(List entries) { /** * Provides an exact copy of the DataSet this method is used on. */ + public abstract DataSet copy(); + protected void copy(DataSet dataSet) { super.copy(dataSet); } + @NonNull @Override public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append(toSimpleString()); for (int i = 0; i < mEntries.size(); i++) { - buffer.append(mEntries.get(i).toString()).append(" "); + buffer.append(mEntries.get(i).toString() ).append( " "); } return buffer.toString(); } @@ -193,6 +206,7 @@ public String toString() { * Returns a simple string representation of the DataSet with the type and * the number of Entries. */ + public String toSimpleString() { return "DataSet, label: " + (getLabel() == null ? "" : getLabel()) + @@ -222,11 +236,11 @@ public float getXMax() { } @Override - public void addEntryOrdered(T entry) { + public void addEntryOrdered(@NonNull T entry) { if (mEntries == null) { - mEntries = new ArrayList<>(); - } + mEntries = new ArrayList<>(); + } calcMinMax(entry); @@ -245,7 +259,7 @@ public void clear() { } @Override - public boolean addEntry(T entry) { + public boolean addEntry(@NonNull T entry) { List values = getEntries(); if (values == null) { values = new ArrayList<>(); @@ -258,11 +272,10 @@ public boolean addEntry(T entry) { } @Override - public boolean removeEntry(T entry) { + public boolean removeEntry(@NonNull T entry) { - if (mEntries == null) { - return false; - } + if (mEntries == null) + return false; // remove the entry boolean removed = mEntries.remove(entry); @@ -275,7 +288,7 @@ public boolean removeEntry(T entry) { } @Override - public int getEntryIndex(Entry entry) { + public int getEntryIndex(@NonNull Entry entry) { return mEntries.indexOf(entry); } @@ -297,9 +310,10 @@ public T getEntryForXValue(float xValue, float closestToY) { @Override public T getEntryForIndex(int index) { if (index < 0) { + Log.e("DataSet", "index " + index + " is < 0 for getEntryForIndex"); return null; - } - if (index >= mEntries.size()) { + } else if (index >= mEntries.size()) { + Log.e("DataSet", "index " + index + "/" + mEntries.size() + " is out of range for getEntryForIndex"); return null; } return mEntries.get(index); 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 379d942e4..a20e0a2e8 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 @@ -6,12 +6,15 @@ import android.graphics.DashPathEffect; import android.util.Log; +import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.formatter.DefaultFillFormatter; import com.github.mikephil.charting.formatter.IFillFormatter; import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; import com.github.mikephil.charting.utils.ColorTemplate; import com.github.mikephil.charting.utils.UtilsKtKt; +import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; import java.util.List; @@ -223,7 +226,7 @@ public void disableDashedLine() { @Override public boolean isDashedLineEnabled() { - return mDashPathEffect == null ? false : true; + return mDashPathEffect != null; } @Override diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/ChartHighlighter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/ChartHighlighter.java index cc1aa5624..e622a43b3 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/ChartHighlighter.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/ChartHighlighter.java @@ -25,7 +25,7 @@ public class ChartHighlighter /** * buffer for storing previously highlighted values */ - protected List mHighlightBuffer = new ArrayList(); + protected List mHighlightBuffer = new ArrayList<>(); public ChartHighlighter(T chart) { this.mChart = chart; 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 index b89406425..b4f773ab4 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/Highlight.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/Highlight.kt @@ -17,7 +17,6 @@ class Highlight : Serializable { * the y-value of the highlighted value */ var y: Float = Float.NaN - private set /** * the x-pixel of the highlight 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 index 362cdf0dd..a1ecb565c 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieHighlighter.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieHighlighter.kt @@ -4,11 +4,14 @@ 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 + override fun getClosestHighlight(index: Int, x: Float, y: Float): Highlight? { + val pieDataSet = mChart!!.data!!.dataSet - val entry: Entry = set.getEntryForIndex(index) + val entry: Entry? = pieDataSet.getEntryForIndex(index) - return Highlight(index.toFloat(), entry.y, x, y, 0, set.axisDependency) + entry?.let { + return Highlight(index.toFloat(), entry.y, x, y, 0, pieDataSet.axisDependency) + } + return null } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.kt similarity index 64% rename from MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.java rename to MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.kt index 748afea41..25affa43d 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.kt @@ -1,55 +1,51 @@ -package com.github.mikephil.charting.interfaces.datasets; +package com.github.mikephil.charting.interfaces.datasets -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.data.DataSet; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.formatter.IValueFormatter; -import com.github.mikephil.charting.utils.MPPointF; - -import java.util.List; - -public interface IDataSet { +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.data.DataSet +import com.github.mikephil.charting.data.Entry +import com.github.mikephil.charting.formatter.IValueFormatter +import com.github.mikephil.charting.utils.MPPointF +interface IDataSet { /** * returns the minimum y-value this DataSet holds */ - float getYMin(); + val yMin: Float /** * returns the maximum y-value this DataSet holds */ - float getYMax(); + val yMax: Float /** * returns the minimum x-value this DataSet holds */ - float getXMin(); + val xMin: Float /** * returns the maximum x-value this DataSet holds */ - float getXMax(); + val xMax: Float /** * Returns the number of y-values this DataSet represents -> the size of the y-values array - * -> yvals.size() + * -> yVals.size() */ - int getEntryCount(); + val entryCount: Int /** * Calculates the minimum and maximum x and y values (mXMin, mXMax, mYMin, mYMax). */ - void calcMinMax(); + fun calcMinMax() /** * Calculates the min and max y-values from the Entry closest to the given fromX to the Entry closest to the given toX value. * This is only needed for the autoScaleMinMax feature. */ - void calcMinMaxY(float fromX, float toX); + fun calcMinMaxY(fromX: Float, toX: Float) /** * Returns the first Entry object found at the given x-value with binary @@ -62,9 +58,9 @@ public interface IDataSet { * @param xValue the x-value * @param closestToY If there are multiple y-values for the specified x-value, * @param rounding determine whether to round up/down/closest - * if there is no Entry matching the provided x-value + * if there is no Entry matching the provided x-value */ - T getEntryForXValue(float xValue, float closestToY, DataSet.Rounding rounding); + fun getEntryForXValue(xValue: Float, closestToY: Float, rounding: DataSet.Rounding?): T? /** * Returns the first Entry object found at the given x-value with binary @@ -77,7 +73,7 @@ public interface IDataSet { * @param xValue the x-value * @param closestToY If there are multiple y-values for the specified x-value, */ - T getEntryForXValue(float xValue, float closestToY); + fun getEntryForXValue(xValue: Float, closestToY: Float): T? /** * Returns all Entry objects found at the given x-value with binary @@ -85,12 +81,12 @@ public interface IDataSet { * INFORMATION: This method does calculations at runtime. Do * not over-use in performance critical situations. */ - List getEntriesForXValue(float xValue); + fun getEntriesForXValue(xValue: Float): MutableList? /** * Returns the Entry object found at the given index (NOT xIndex) in the values array. */ - T getEntryForIndex(int index); + fun getEntryForIndex(index: Int): T? /** * Returns the first Entry index found at the given x-value with binary @@ -103,16 +99,15 @@ public interface IDataSet { * @param xValue the x-value * @param closestToY If there are multiple y-values for the specified x-value, * @param rounding determine whether to round up/down/closest - * if there is no Entry matching the provided x-value + * if there is no Entry matching the provided x-value */ - int getEntryIndex(float xValue, float closestToY, DataSet.Rounding rounding); + fun getEntryIndex(xValue: Float, closestToY: Float, rounding: DataSet.Rounding?): Int /** * Returns the position of the provided entry in the DataSets Entry array. * Returns -1 if doesn't exist. */ - int getEntryIndex(T entry); - + fun getEntryIndex(e: T): Int /** * This method returns the actual @@ -120,7 +115,7 @@ public interface IDataSet { * calculations at runtime, do not over-use in performance critical * situations. */ - int getIndexInEntries(int xIndex); + fun getIndexInEntries(xIndex: Int): Int /** * Adds an Entry to the DataSet dynamically. @@ -128,7 +123,7 @@ public interface IDataSet { * This will also recalculate the current minimum and maximum * values of the DataSet and the value-sum. */ - boolean addEntry(T entry); + fun addEntry(entry: T): Boolean /** @@ -137,19 +132,19 @@ public interface IDataSet { * This will also recalculate the current minimum and maximum * values of the DataSet and the value-sum. */ - void addEntryOrdered(T entry); + fun addEntryOrdered(entry: T) /** * Removes the first Entry (at index 0) of this DataSet from the entries array. * Returns true if successful, false if not. */ - boolean removeFirst(); + fun removeFirst(): Boolean /** * Removes the last Entry (at index size-1) of this DataSet from the entries array. * Returns true if successful, false if not. */ - boolean removeLast(); + fun removeLast(): Boolean /** * Removes an Entry from the DataSets entries array. This will also @@ -157,80 +152,64 @@ public interface IDataSet { * value-sum. Returns true if an Entry was removed, false if no Entry could * be removed. */ - boolean removeEntry(T entry); + fun removeEntry(entry: T): Boolean /** * Removes the Entry object closest to the given x-value from the DataSet. * Returns true if an Entry was removed, false if no Entry could be removed. */ - boolean removeEntryByXValue(float xValue); + fun removeEntryByXValue(xValue: Float): Boolean /** * Removes the Entry object at the given index in the values array from the DataSet. * Returns true if an Entry was removed, false if no Entry could be removed. */ - boolean removeEntry(int index); + fun removeEntry(index: Int): Boolean /** * Checks if this DataSet contains the specified Entry. Returns true if so, * false if not. NOTE: Performance is pretty bad on this one, do not * over-use in performance critical situations. */ - boolean contains(T entry); + fun contains(entry: T): Boolean /** * Removes all values from this DataSet and does all necessary recalculations. */ - void clear(); - - /** - * Returns the label string that describes the DataSet. - */ - String getLabel(); + fun clear() /** * Sets the label string that describes the DataSet. */ - void setLabel(String label); - - /** - * Returns the axis this DataSet should be plotted against. - */ - YAxis.AxisDependency getAxisDependency(); + var label: String? /** - * Set the y-axis this DataSet should be plotted against (either LEFT or RIGHT). - * Default: LEFT + * Set the y-axis this DataSet should be plotted against (either LEFT or RIGHT). Default: LEFT */ - void setAxisDependency(YAxis.AxisDependency dependency); + var axisDependency: YAxis.AxisDependency /** * returns all the colors that are set for this DataSet */ - List getColors(); + val colors: MutableList /** * Returns the first color (index 0) of the colors-array this DataSet * contains. This is only used for performance reasons when only one color is in the colors array (size == 1) */ - int getColor(); + var color: Int /** * Returns the color at the given index of the DataSet's color array. * Performs a IndexOutOfBounds check by modulus. */ - int getColorByIndex(int index); - - /** - * returns true if highlighting of values is enabled, false if not - */ - boolean isHighlightEnabled(); + fun getColorByIndex(index: Int): Int /** * If set to true, value highlighting is enabled which means that values can * be highlighted programmatically or by touch gesture. */ - void setHighlightEnabled(boolean enabled); + var isHighlightEnabled: Boolean /** * Sets the formatter to be used for drawing the values inside the chart. If @@ -239,132 +218,79 @@ public interface IDataSet { * the chart. Use chart.getDefaultValueFormatter() to use the formatter * calculated by the chart. */ - void setValueFormatter(IValueFormatter f); - - /** - * Returns the formatter used for drawing the values inside the chart. - */ - IValueFormatter getValueFormatter(); + var valueFormatter: IValueFormatter /** * Returns true if the valueFormatter object of this DataSet is null. */ - boolean needsFormatter(); + fun needsFormatter(): Boolean + fun setSingleValueTextColor(value: Int) /** * Sets the color the value-labels of this DataSet should have. */ - void setValueTextColor(int color); + fun getValueTextColor(index: Int): Int - /** - * Sets a list of colors to be used as the colors for the drawn values. - */ - void setValueTextColors(List colors); + var valueTextColors: MutableList /** * Sets a Typeface for the value-labels of this DataSet. */ - void setValueTypeface(Typeface tf); + var valueTypeface: Typeface? /** * Sets the text-size of the value-labels of this DataSet in dp. */ - void setValueTextSize(float size); - - /** - * Returns only the first color of all colors that are set to be used for the values. - */ - int getValueTextColor(); - - /** - * Returns the color at the specified index that is used for drawing the values inside the chart. - * Uses modulus internally. - */ - int getValueTextColor(int index); - - /** - * Returns the typeface that is used for drawing the values inside the chart - */ - Typeface getValueTypeface(); - - /** - * Returns the text size that is used for drawing the values inside the chart - */ - float getValueTextSize(); + var valueTextSize: Float /** * The form to draw for this dataset in the legend. - *

+ * * Return `DEFAULT` to use the default legend form. */ - Legend.LegendForm getForm(); + val form: Legend.LegendForm /** * The form size to draw for this dataset in the legend. - *

+ * * Return `Float.NaN` to use the default legend form size. */ - float getFormSize(); + val formSize: Float /** * The line width for drawing the form of this dataset in the legend - *

+ * * Return `Float.NaN` to use the default legend form line width. */ - float getFormLineWidth(); + var formLineWidth: Float /** * The line dash path effect used for shapes that consist of lines. - *

+ * * Return `null` to use the default legend form line dash effect. */ - DashPathEffect getFormLineDashEffect(); - - /** - * set this to true to draw y-values on the chart. - * NOTE (for bar and line charts): if `maxVisibleCount` is reached, no values will be drawn even - * if this is enabled - */ - void setDrawValues(boolean enabled); + val formLineDashEffect: DashPathEffect? /** * Returns true if y-value drawing is enabled, false if not */ - boolean isDrawValues(); - - /** - * Set this to true to draw y-icons on the chart. - * NOTE (for bar and line charts): if `maxVisibleCount` is reached, no icons will be drawn even - * if this is enabled - */ - void setDrawIcons(boolean enabled); + var isDrawValues: Boolean /** * Returns true if y-icon drawing is enabled, false if not */ - boolean isDrawIcons(); + var isDrawIcons: Boolean /** * Offset of icons drawn on the chart. * For all charts except Pie and Radar it will be ordinary (x offset,y offset). * For Pie and Radar chart it will be (y offset, distance from center offset); so if you want icon to be rendered under value, you should increase X component of CGPoint, and if you want icon to be rendered closet to center, you should decrease height component of CGPoint. */ - void setIconsOffset(MPPointF offset); - - /** - * Get the offset for drawing icons. - */ - MPPointF getIconsOffset(); + var iconsOffset: MPPointF /** * Set the visibility of this DataSet. If not visible, the DataSet will not * be drawn to the chart upon refreshing it. */ - void setVisible(boolean visible); - - /** - * Returns true if this DataSet is visible inside the chart, or false if it - * is currently hidden. - */ - boolean isVisible(); + var isVisible: Boolean } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.kt similarity index 63% rename from MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.java rename to MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.kt index 8ac63e1db..50b153e3f 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.kt @@ -1,39 +1,34 @@ -package com.github.mikephil.charting.interfaces.datasets; +package com.github.mikephil.charting.interfaces.datasets -import android.graphics.drawable.Drawable; - -import com.github.mikephil.charting.data.Entry; - -/** - * Created by Philipp Jahoda on 21/10/15. - */ -public interface ILineRadarDataSet extends ILineScatterCandleRadarDataSet { +import android.graphics.drawable.Drawable +import com.github.mikephil.charting.data.Entry +interface ILineRadarDataSet : ILineScatterCandleRadarDataSet { /** * Returns the color that is used for filling the line surface area. */ - int getFillColor(); + val fillColor: Int /** * Returns the drawable used for filling the area below the line. */ - Drawable getFillDrawable(); + val fillDrawable: Drawable? /** * Returns the alpha value that is used for filling the line surface, * default: 85 */ - int getFillAlpha(); + val fillAlpha: Int /** * Returns the stroke-width of the drawn line */ - float getLineWidth(); + val lineWidth: Float /** * Returns true if filled drawing is enabled, false if not */ - boolean isDrawFilledEnabled(); + val isDrawFilledEnabled: Boolean /** * Set to true if the DataSet should be drawn filled (surface), and not just @@ -42,5 +37,5 @@ public interface ILineRadarDataSet extends ILineScatterCandleRa * For devices with API level < 18 (Android 4.3), hardware acceleration of the chart should * be turned off. Default: false */ - void setDrawFilled(boolean enabled); + fun setDrawFilled(enabled: Boolean) } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.kt index 3a6e9db9d..9f33e863c 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.kt @@ -126,15 +126,16 @@ open class BarChartRenderer( var i = 0 val count = min((ceil(((dataSet.entryCount).toFloat() * phaseX).toDouble())).toInt().toDouble(), dataSet.entryCount.toDouble()).toInt() while (i < count) { - val e = dataSet.getEntryForIndex(i) + val barEntry = dataSet.getEntryForIndex(i) - x = e.x + barEntry?.let { + x = barEntry.x - barShadowRectBuffer.left = x - barWidthHalf - barShadowRectBuffer.right = x + barWidthHalf - - trans!!.rectValueToPixel(barShadowRectBuffer) + barShadowRectBuffer.left = x - barWidthHalf + barShadowRectBuffer.right = x + barWidthHalf + trans!!.rectValueToPixel(barShadowRectBuffer) + } if (!viewPortHandler.isInBoundsLeft(barShadowRectBuffer.right)) { i++ continue @@ -311,82 +312,23 @@ open class BarChartRenderer( continue } - val entry = dataSet.getEntryForIndex(j / 4) - val `val` = entry.y - - if (dataSet.isDrawValues) { - drawValue( - canvas, dataSet.valueFormatter, `val`, entry, i, x, - if (`val` >= 0) (buffer.buffer[j + 1] + posOffset) else (buffer.buffer[j + 3] + negOffset), - dataSet.getValueTextColor(j / 4) - ) - } - - if (entry.icon != null && dataSet.isDrawIcons) { - val icon = entry.icon - - var px = x - var py = if (`val` >= 0) (buffer.buffer[j + 1] + posOffset) else (buffer.buffer[j + 3] + negOffset) - - px += iconsOffset.x - py += iconsOffset.y - - icon?.let { - Utils.drawImage( - canvas, - it, - px.toInt(), - py.toInt() - ) - } - } - j += 4 - } - - // if we have stacks - } else { - val trans = chart.getTransformer(dataSet.axisDependency) - - var bufferIndex = 0 - var index = 0 - - while (index < dataSet.entryCount * animator.phaseX) { - val entry = dataSet.getEntryForIndex(index) - - val vals = entry.yVals - val x = (buffer!!.buffer[bufferIndex] + buffer.buffer[bufferIndex + 2]) / 2f - - val color = dataSet.getValueTextColor(index) - - // we still draw stacked bars, but there is one - // non-stacked - // in between - if (vals == null) { - if (!viewPortHandler.isInBoundsRight(x)) { - break - } - - if (!viewPortHandler.isInBoundsY(buffer.buffer[bufferIndex + 1]) - || !viewPortHandler.isInBoundsLeft(x) - ) { - continue - } + val barEntry = dataSet.getEntryForIndex(j / 4) + barEntry?.let { + val value = barEntry.y if (dataSet.isDrawValues) { drawValue( - canvas, dataSet.valueFormatter, entry.y, entry, i, x, - buffer.buffer[bufferIndex + 1] + - (if (entry.y >= 0) posOffset else negOffset), - color + canvas, dataSet.valueFormatter, value, barEntry, i, x, + if (value >= 0) (buffer.buffer[j + 1] + posOffset) else (buffer.buffer[j + 3] + negOffset), + dataSet.getValueTextColor(j / 4) ) } - if (entry.icon != null && dataSet.isDrawIcons) { - val icon = entry.icon + if (barEntry.icon != null && dataSet.isDrawIcons) { + val icon = barEntry.icon var px = x - var py = buffer.buffer[bufferIndex + 1] + - (if (entry.y >= 0) posOffset else negOffset) + var py = if (value >= 0) (buffer.buffer[j + 1] + posOffset) else (buffer.buffer[j + 3] + negOffset) px += iconsOffset.x py += iconsOffset.y @@ -400,90 +342,151 @@ open class BarChartRenderer( ) } } + } + j += 4 + } - // draw stack values - } else { - val transformed = FloatArray(vals.size * 2) - - var posY = 0f - var negY = -entry.negativeSum - - run { - var k = 0 - var idx = 0 - while (k < transformed.size) { - val value = vals[idx] - val y: Float - - if (value == 0.0f && (posY == 0.0f || negY == 0.0f)) { - // Take care of the situation of a 0.0 value, which overlaps a non-zero bar - y = value - } else if (value >= 0.0f) { - posY += value - y = posY - } else { - y = negY - negY -= value - } - - transformed[k + 1] = y * phaseY - k += 2 - idx++ - } - } - - trans!!.pointValuesToPixel(transformed) + // if we have stacks + } else { + val trans = chart.getTransformer(dataSet.axisDependency) - var k = 0 - while (k < transformed.size) { - val `val` = vals[k / 2] - val drawBelow = - (`val` == 0.0f && negY == 0.0f && posY > 0.0f) || - `val` < 0.0f - val y = (transformed[k + 1] - + (if (drawBelow) negOffset else posOffset)) + var bufferIndex = 0 + var index = 0 + while (index < dataSet.entryCount * animator.phaseX) { + val barEntry = dataSet.getEntryForIndex(index) + barEntry?.let { + val vals = barEntry.yVals + val x = (buffer!!.buffer[bufferIndex] + buffer.buffer[bufferIndex + 2]) / 2f + val color = dataSet.getValueTextColor(index) + + // we still draw stacked bars, but there is one + // non-stacked + // in between + if (vals == null) { if (!viewPortHandler.isInBoundsRight(x)) { break } - if (!viewPortHandler.isInBoundsY(y) + if (!viewPortHandler.isInBoundsY(buffer.buffer[bufferIndex + 1]) || !viewPortHandler.isInBoundsLeft(x) ) { - k += 2 continue } if (dataSet.isDrawValues) { drawValue( - canvas, - dataSet.valueFormatter, - vals[k / 2], - entry, - i, - x, - y, + canvas, dataSet.valueFormatter, barEntry.y, barEntry, i, x, + buffer.buffer[bufferIndex + 1] + (if (barEntry.y >= 0) + posOffset else negOffset), color ) } - if (entry.icon != null && dataSet.isDrawIcons) { - val icon = entry.icon + if (barEntry.icon != null && dataSet.isDrawIcons) { + val icon = barEntry.icon + + var px = x + var py = buffer.buffer[bufferIndex + 1] + + (if (barEntry.y >= 0) posOffset else negOffset) + + px += iconsOffset.x + py += iconsOffset.y icon?.let { Utils.drawImage( canvas, it, - (x + iconsOffset.x).toInt(), - (y + iconsOffset.y).toInt() + px.toInt(), + py.toInt() ) } } - k += 2 + + // draw stack values + } else { + val transformed = FloatArray(vals.size * 2) + + var posY = 0f + var negY = -barEntry.negativeSum + + run { + var k = 0 + var idx = 0 + while (k < transformed.size) { + val value = vals[idx] + val y: Float + + if (value == 0.0f && (posY == 0.0f || negY == 0.0f)) { + // Take care of the situation of a 0.0 value, which overlaps a non-zero bar + y = value + } else if (value >= 0.0f) { + posY += value + y = posY + } else { + y = negY + negY -= value + } + + transformed[k + 1] = y * phaseY + k += 2 + idx++ + } + } + + trans!!.pointValuesToPixel(transformed) + + var k = 0 + while (k < transformed.size) { + val `val` = vals[k / 2] + val drawBelow = + (`val` == 0.0f && negY == 0.0f && posY > 0.0f) || + `val` < 0.0f + val y = (transformed[k + 1] + + (if (drawBelow) negOffset else posOffset)) + + if (!viewPortHandler.isInBoundsRight(x)) { + break + } + + if (!viewPortHandler.isInBoundsY(y) + || !viewPortHandler.isInBoundsLeft(x) + ) { + k += 2 + continue + } + + if (dataSet.isDrawValues) { + drawValue( + canvas, + dataSet.valueFormatter, + vals[k / 2], + barEntry, + i, + x, + y, + color + ) + } + + if (barEntry.icon != null && dataSet.isDrawIcons) { + val icon = barEntry.icon + + icon?.let { + Utils.drawImage( + canvas, + it, + (x + iconsOffset.x).toInt(), + (y + iconsOffset.y).toInt() + ) + } + } + k += 2 + } } - } - bufferIndex = if (vals == null) bufferIndex + 4 else bufferIndex + 4 * vals.size + bufferIndex = if (vals == null) bufferIndex + 4 else bufferIndex + 4 * vals.size + } index++ } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarLineScatterCandleBubbleRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarLineScatterCandleBubbleRenderer.kt index 6ba1846c1..e8e3ea537 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarLineScatterCandleBubbleRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarLineScatterCandleBubbleRenderer.kt @@ -20,7 +20,7 @@ abstract class BarLineScatterCandleBubbleRenderer(animator: ChartAnimator, viewP * Returns true if the DataSet values should be drawn, false if not. */ protected fun shouldDrawValues(set: IDataSet<*>): Boolean { - return set.isVisible() && (set.isDrawValues() || set.isDrawIcons()) + return set.isVisible && (set.isDrawValues || set.isDrawIcons) } /** @@ -29,7 +29,7 @@ abstract class BarLineScatterCandleBubbleRenderer(animator: ChartAnimator, viewP protected fun isInBoundsX(entry: T, set: IBarLineScatterCandleBubbleDataSet): Boolean { val entryIndex = set.getEntryIndex(entry).toFloat() - return if (entryIndex >= set.getEntryCount() * animator.phaseX) { + return if (entryIndex >= set.entryCount * animator.phaseX) { false } else { true diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.kt index cba3558e7..efecf4f61 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.kt @@ -65,26 +65,27 @@ open class BubbleChartRenderer( val referenceSize = min(maxBubbleHeight.toDouble(), maxBubbleWidth.toDouble()).toFloat() for (j in xBounds.min..xBounds.range + xBounds.min) { - val entry = dataSet.getEntryForIndex(j) + val bubbleEntry = dataSet.getEntryForIndex(j) + bubbleEntry?.let { + pointBuffer[0] = it.x + pointBuffer[1] = (it.y) * phaseY + trans.pointValuesToPixel(pointBuffer) - pointBuffer[0] = entry.x - pointBuffer[1] = (entry.y) * phaseY - trans.pointValuesToPixel(pointBuffer) + val shapeHalf = getShapeSize(it.size, dataSet.maxSize, referenceSize, normalizeSize) / 2f - val shapeHalf = getShapeSize(entry.size, dataSet.maxSize, referenceSize, normalizeSize) / 2f + if (!viewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf) + || !viewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf) + ) continue - if (!viewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf) - || !viewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf) - ) continue + if (!viewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf)) continue - if (!viewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf)) continue - - if (!viewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf)) break + if (!viewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf)) break - val color = dataSet.getColorByIndex(j) + val color = dataSet.getColorByIndex(j) - paintRender.color = color - canvas.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, paintRender) + paintRender.color = color + canvas.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, paintRender) + } } } @@ -144,26 +145,27 @@ open class BubbleChartRenderer( continue } - val entry = dataSet.getEntryForIndex(j / 2 + xBounds.min) - - if (dataSet.isDrawValues) { - drawValue( - canvas, dataSet.valueFormatter, entry.size, entry, i, x, - y + (0.5f * lineHeight), valueTextColor - ) - } - - if (entry.icon != null && dataSet.isDrawIcons) { - val icon = entry.icon - - icon?.let { - Utils.drawImage( - canvas, - it, - (x + iconsOffset.x).toInt(), - (y + iconsOffset.y).toInt() + val bubbleEntry = dataSet.getEntryForIndex(j / 2 + xBounds.min) + bubbleEntry?.let { + if (dataSet.isDrawValues) { + drawValue( + canvas, dataSet.valueFormatter, bubbleEntry.size, bubbleEntry, i, x, + y + (0.5f * lineHeight), valueTextColor ) } + + if (bubbleEntry.icon != null && dataSet.isDrawIcons) { + val icon = bubbleEntry.icon + + icon?.let { + Utils.drawImage( + canvas, + it, + (x + iconsOffset.x).toInt(), + (y + iconsOffset.y).toInt() + ) + } + } } j += 2 } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.kt index a55cac95f..df7f97536 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.kt @@ -248,7 +248,7 @@ open class CandleStickChartRenderer( continue } - val entry = dataSet.getEntryForIndex(j / 2 + xBounds.min) + val entry = dataSet.getEntryForIndex(j / 2 + xBounds.min)!! if (dataSet.isDrawValues) { drawValue( @@ -259,8 +259,7 @@ open class CandleStickChartRenderer( i, x, y - yOffset, - dataSet - .getValueTextColor(j / 2) + dataSet.getValueTextColor(j / 2) ) } @@ -294,20 +293,21 @@ open class CandleStickChartRenderer( if (set == null || !set.isHighlightEnabled) continue - val e = set.getEntryForXValue(high.x, high.y) + val candleEntry = set.getEntryForXValue(high.x, high.y) - if (!isInBoundsX(e, set)) continue - - val lowValue = e.low * animator.phaseY - val highValue = e.high * animator.phaseY - val y = (lowValue + highValue) / 2f - - val pix = dataProvider.getTransformer(set.axisDependency)!!.getPixelForValues(e.x, y) + candleEntry?.let { + if (!isInBoundsX(candleEntry, set)) + continue + val lowValue = it.low * animator.phaseY + val highValue = it.high * animator.phaseY + val y = (lowValue + highValue) / 2f + val pix = dataProvider.getTransformer(set.axisDependency)!!.getPixelForValues(it.x, y) - high.setDraw(pix.x.toFloat(), pix.y.toFloat()) + high.setDraw(pix.x.toFloat(), pix.y.toFloat()) - // draw the lines - drawHighlightLines(canvas, pix.x.toFloat(), pix.y.toFloat(), set) + // draw the lines + drawHighlightLines(canvas, pix.x.toFloat(), pix.y.toFloat(), set) + } } } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.kt index 40824b961..fe0b27469 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.kt @@ -70,28 +70,29 @@ open class HorizontalBarChartRenderer( val count = min((ceil(((dataSet.entryCount).toFloat() * phaseX).toDouble())).toInt().toDouble(), dataSet.entryCount.toDouble()).toInt() while (i < count ) { - val e = dataSet.getEntryForIndex(i) + val barEntry = dataSet.getEntryForIndex(i) + barEntry?.let { + x = it.x - x = e.x + mBarShadowRectBuffer.top = x - barWidthHalf + mBarShadowRectBuffer.bottom = x + barWidthHalf - mBarShadowRectBuffer.top = x - barWidthHalf - mBarShadowRectBuffer.bottom = x + barWidthHalf + trans!!.rectValueToPixel(mBarShadowRectBuffer) - trans!!.rectValueToPixel(mBarShadowRectBuffer) - - if (!viewPortHandler.isInBoundsTop(mBarShadowRectBuffer.bottom)) { - i++ - continue - } + if (!viewPortHandler.isInBoundsTop(mBarShadowRectBuffer.bottom)) { + i++ + continue + } - if (!viewPortHandler.isInBoundsBottom(mBarShadowRectBuffer.top)) { - break - } + if (!viewPortHandler.isInBoundsBottom(mBarShadowRectBuffer.top)) { + break + } - mBarShadowRectBuffer.left = viewPortHandler.contentLeft() - mBarShadowRectBuffer.right = viewPortHandler.contentRight() + mBarShadowRectBuffer.left = viewPortHandler.contentLeft() + mBarShadowRectBuffer.right = viewPortHandler.contentRight() - canvas.drawRect(mBarShadowRectBuffer, shadowPaint) + canvas.drawRect(mBarShadowRectBuffer, shadowPaint) + } i++ } } @@ -219,91 +220,15 @@ open class HorizontalBarChartRenderer( continue } - val entry = dataSet.getEntryForIndex(j / 4) - val valueY = entry.y - val formattedValue = formatter.getFormattedValue(valueY, entry, i, viewPortHandler) - - // calculate the correct offset depending on the draw position of the value - val valueTextWidth = Utils.calcTextWidth(paintValues, formattedValue).toFloat() - posOffset = (if (drawValueAboveBar) valueOffsetPlus else -(valueTextWidth + valueOffsetPlus)) - negOffset = ((if (drawValueAboveBar) -(valueTextWidth + valueOffsetPlus) else valueOffsetPlus) - - (buffer.buffer[j + 2] - buffer.buffer[j])) - - if (isInverted) { - posOffset = -posOffset - valueTextWidth - negOffset = -negOffset - valueTextWidth - } - - if (dataSet.isDrawValues) { - drawValue( - canvas, - formattedValue!!, - buffer.buffer[j + 2] + (if (valueY >= 0) posOffset else negOffset), - y + halfTextHeight, - dataSet.getValueTextColor(j / 2) - ) - } - - if (entry.icon != null && dataSet.isDrawIcons) { - val icon = entry.icon - - var px = buffer.buffer[j + 2] + (if (valueY >= 0) posOffset else negOffset) - var py = y - - px += iconsOffset.x - py += iconsOffset.y - - icon?.let { - Utils.drawImage( - canvas, - it, - px.toInt(), - py.toInt() - ) - } - } - j += 4 - } - - // if each value of a potential stack should be drawn - } else { - val trans = chart.getTransformer(dataSet.axisDependency) - - var bufferIndex = 0 - var index = 0 - - while (index < dataSet.entryCount * animator.phaseX) { - val entry = dataSet.getEntryForIndex(index) - - val color = dataSet.getValueTextColor(index) - val vals = entry.yVals - - // we still draw stacked bars, but there is one - // non-stacked - // in between - if (vals == null) { - if (!viewPortHandler.isInBoundsTop(buffer.buffer[bufferIndex + 1])) { - break - } - - if (!viewPortHandler.isInBoundsX(buffer.buffer[bufferIndex])) { - continue - } - - if (!viewPortHandler.isInBoundsBottom(buffer.buffer[bufferIndex + 1])) { - continue - } - - val valueY = entry.y - val formattedValue = formatter.getFormattedValue( - valueY, - entry, i, viewPortHandler - ) - + val barEntry = dataSet.getEntryForIndex(j / 4) + barEntry?.let { + val valueY = barEntry.y + val formattedValue = formatter.getFormattedValue(valueY, barEntry, i, viewPortHandler) // calculate the correct offset depending on the draw position of the value val valueTextWidth = Utils.calcTextWidth(paintValues, formattedValue).toFloat() posOffset = (if (drawValueAboveBar) valueOffsetPlus else -(valueTextWidth + valueOffsetPlus)) - negOffset = (if (drawValueAboveBar) -(valueTextWidth + valueOffsetPlus) else valueOffsetPlus) + negOffset = ((if (drawValueAboveBar) -(valueTextWidth + valueOffsetPlus) else valueOffsetPlus) + - (buffer.buffer[j + 2] - buffer.buffer[j])) if (isInverted) { posOffset = -posOffset - valueTextWidth @@ -312,19 +237,19 @@ open class HorizontalBarChartRenderer( if (dataSet.isDrawValues) { drawValue( - canvas, formattedValue!!, - buffer.buffer[bufferIndex + 2] - + (if (entry.y >= 0) posOffset else negOffset), - buffer.buffer[bufferIndex + 1] + halfTextHeight, color + canvas, + formattedValue!!, + buffer.buffer[j + 2] + (if (valueY >= 0) posOffset else negOffset), + y + halfTextHeight, + dataSet.getValueTextColor(j / 2) ) } - if (entry.icon != null && dataSet.isDrawIcons) { - val icon = entry.icon + if (barEntry.icon != null && dataSet.isDrawIcons) { + val icon = barEntry.icon - var px = (buffer.buffer[bufferIndex + 2] - + (if (entry.y >= 0) posOffset else negOffset)) - var py = buffer.buffer[bufferIndex + 1] + var px = buffer.buffer[j + 2] + (if (valueY >= 0) posOffset else negOffset) + var py = y px += iconsOffset.x py += iconsOffset.y @@ -338,44 +263,42 @@ open class HorizontalBarChartRenderer( ) } } - } else { - val transformed = FloatArray(vals.size * 2) + } + j += 4 + } - var posY = 0f - var negY = -entry.negativeSum + // if each value of a potential stack should be drawn + } else { + val trans = chart.getTransformer(dataSet.axisDependency) - run { - var k = 0 - var idx = 0 - while (k < transformed.size) { - val value = vals[idx] - val y: Float - - if (value == 0.0f && (posY == 0.0f || negY == 0.0f)) { - // Take care of the situation of a 0.0 value, which overlaps a non-zero bar - y = value - } else if (value >= 0.0f) { - posY += value - y = posY - } else { - y = negY - negY -= value - } + var bufferIndex = 0 + var index = 0 - transformed[k] = y * phaseY - k += 2 - idx++ + while (index < dataSet.entryCount * animator.phaseX) { + val barEntry = dataSet.getEntryForIndex(index) + barEntry?.let { + val color = dataSet.getValueTextColor(index) + val vals = it.yVals + + // we still draw stacked bars, but there is one + // non-stacked + // in between + if (vals == null) { + if (!viewPortHandler.isInBoundsTop(buffer.buffer[bufferIndex + 1])) { + break } - } - trans!!.pointValuesToPixel(transformed) + if (!viewPortHandler.isInBoundsX(buffer.buffer[bufferIndex])) { + continue + } + + if (!viewPortHandler.isInBoundsBottom(buffer.buffer[bufferIndex + 1])) { + continue + } - var k = 0 - while (k < transformed.size) { - val valueY = vals[k / 2] val formattedValue = formatter.getFormattedValue( - valueY, - entry, i, viewPortHandler + it.y, + it, i, viewPortHandler ) // calculate the correct offset depending on the draw position of the value @@ -388,49 +311,125 @@ open class HorizontalBarChartRenderer( negOffset = -negOffset - valueTextWidth } - val drawBelow = - (valueY == 0.0f && negY == 0.0f && posY > 0.0f) || - valueY < 0.0f - - val x = (transformed[k] - + (if (drawBelow) negOffset else posOffset)) - val y = (buffer.buffer[bufferIndex + 1] + buffer.buffer[bufferIndex + 3]) / 2f - - if (!viewPortHandler.isInBoundsTop(y)) { - break - } - - if (!viewPortHandler.isInBoundsX(x)) { - k += 2 - continue + if (dataSet.isDrawValues) { + drawValue( + canvas, formattedValue!!, + buffer.buffer[bufferIndex + 2] + + (if (it.y >= 0) posOffset else negOffset), + buffer.buffer[bufferIndex + 1] + halfTextHeight, color + ) } - if (!viewPortHandler.isInBoundsBottom(y)) { - k += 2 - continue - } + if (it.icon != null && dataSet.isDrawIcons) { + val icon = it.icon - if (dataSet.isDrawValues) { - drawValue(canvas, formattedValue!!, x, y + halfTextHeight, color) - } + var px = (buffer.buffer[bufferIndex + 2] + + (if (it.y >= 0) posOffset else negOffset)) + var py = buffer.buffer[bufferIndex + 1] - if (entry.icon != null && dataSet.isDrawIcons) { - val icon = entry.icon + px += iconsOffset.x + py += iconsOffset.y - icon?.let { + icon?.let { myIcon -> Utils.drawImage( canvas, - it, - (x + iconsOffset.x).toInt(), - (y + iconsOffset.y).toInt() + myIcon, + px.toInt(), + py.toInt() ) } } - k += 2 + } else { + val transformed = FloatArray(vals.size * 2) + + var posY = 0f + var negY = -it.negativeSum + + run { + var k = 0 + var idx = 0 + while (k < transformed.size) { + val value = vals[idx] + val y: Float + + if (value == 0.0f && (posY == 0.0f || negY == 0.0f)) { + // Take care of the situation of a 0.0 value, which overlaps a non-zero bar + y = value + } else if (value >= 0.0f) { + posY += value + y = posY + } else { + y = negY + negY -= value + } + + transformed[k] = y * phaseY + k += 2 + idx++ + } + } + + trans!!.pointValuesToPixel(transformed) + + var k = 0 + while (k < transformed.size) { + val valueY = vals[k / 2] + val formattedValue = formatter.getFormattedValue( + valueY, + it, i, viewPortHandler + ) + + // calculate the correct offset depending on the draw position of the value + val valueTextWidth = Utils.calcTextWidth(paintValues, formattedValue).toFloat() + posOffset = (if (drawValueAboveBar) valueOffsetPlus else -(valueTextWidth + valueOffsetPlus)) + negOffset = (if (drawValueAboveBar) -(valueTextWidth + valueOffsetPlus) else valueOffsetPlus) + + if (isInverted) { + posOffset = -posOffset - valueTextWidth + negOffset = -negOffset - valueTextWidth + } + + val drawBelow = (valueY == 0.0f && negY == 0.0f && posY > 0.0f) || valueY < 0.0f + + val x = (transformed[k] + (if (drawBelow) negOffset else posOffset)) + val y = (buffer.buffer[bufferIndex + 1] + buffer.buffer[bufferIndex + 3]) / 2f + + if (!viewPortHandler.isInBoundsTop(y)) { + break + } + + if (!viewPortHandler.isInBoundsX(x)) { + k += 2 + continue + } + + if (!viewPortHandler.isInBoundsBottom(y)) { + k += 2 + continue + } + + if (dataSet.isDrawValues) { + drawValue(canvas, formattedValue!!, x, y + halfTextHeight, color) + } + + if (it.icon != null && dataSet.isDrawIcons) { + val icon = it.icon + + icon?.let { myIcon -> + Utils.drawImage( + canvas, + myIcon, + (x + iconsOffset.x).toInt(), + (y + iconsOffset.y).toInt() + ) + } + } + k += 2 + } } - } - bufferIndex = if (vals == null) bufferIndex + 4 else bufferIndex + 4 * vals.size + bufferIndex = if (vals == null) bufferIndex + 4 else bufferIndex + 4 * vals.size + } index++ } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LegendRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LegendRenderer.kt index 690590de2..ac0b65448 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LegendRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LegendRenderer.kt @@ -52,7 +52,6 @@ open class LegendRenderer( val clrs = dataSet.colors val entryCount = dataSet.entryCount - // if we have a barchart with stacked bars if (dataSet is IBarDataSet && dataSet.isStacked) { val sLabels = dataSet.stackLabels @@ -71,10 +70,10 @@ open class LegendRenderer( computedEntries.add( LegendEntry( label, - dataSet.getForm(), - dataSet.getFormSize(), - dataSet.getFormLineWidth(), - dataSet.getFormLineDashEffect(), + dataSet.form, + dataSet.formSize, + dataSet.formLineWidth, + dataSet.formLineDashEffect, clrs[j] ) ) @@ -84,7 +83,7 @@ open class LegendRenderer( // add the legend description label computedEntries.add( LegendEntry( - dataSet.getLabel(), + dataSet.label, LegendForm.NONE, Float.NaN, Float.NaN, @@ -97,16 +96,18 @@ open class LegendRenderer( var j = 0 while (j < clrs.size && j < entryCount) { - computedEntries.add( - LegendEntry( - dataSet.getEntryForIndex(j).label, - dataSet.getForm(), - dataSet.getFormSize(), - dataSet.getFormLineWidth(), - dataSet.getFormLineDashEffect(), - clrs[j] + dataSet.getEntryForIndex(j)?.let { pieEntry -> + computedEntries.add( + LegendEntry( + pieEntry.label, + dataSet.form, + dataSet.formSize, + dataSet.formLineWidth, + dataSet.formLineDashEffect, + clrs[j] + ) ) - ) + } j++ } @@ -114,7 +115,7 @@ open class LegendRenderer( // add the legend description label computedEntries.add( LegendEntry( - dataSet.getLabel(), + dataSet.label, LegendForm.NONE, Float.NaN, Float.NaN, @@ -132,21 +133,21 @@ open class LegendRenderer( computedEntries.add( LegendEntry( null, - dataSet.getForm(), - dataSet.getFormSize(), - dataSet.getFormLineWidth(), - dataSet.getFormLineDashEffect(), + dataSet.form, + dataSet.formSize, + dataSet.formLineWidth, + dataSet.formLineDashEffect, decreasingColor ) ) computedEntries.add( LegendEntry( - dataSet.getLabel(), - dataSet.getForm(), - dataSet.getFormSize(), - dataSet.getFormLineWidth(), - dataSet.getFormLineDashEffect(), + dataSet.label, + dataSet.form, + dataSet.formSize, + dataSet.formLineWidth, + dataSet.formLineDashEffect, increasingColor ) ) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.kt index df08462c9..8122c5b61 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.kt @@ -110,7 +110,7 @@ open class LineChartRenderer( cubicPath.reset() if (xBounds.range >= 1) { - var prev = dataSet.getEntryForIndex(xBounds.min) + var prev = dataSet.getEntryForIndex(xBounds.min)!! var cur = prev // let the spline start @@ -118,7 +118,7 @@ open class LineChartRenderer( for (j in xBounds.min + 1..xBounds.range + xBounds.min) { prev = cur - cur = dataSet.getEntryForIndex(j) + cur = dataSet.getEntryForIndex(j)!! val cpx = ((prev.x) + (cur.x - prev.x) / 2.0f) @@ -190,7 +190,7 @@ open class LineChartRenderer( cur = if (nextIndex == j) next else dataSet.getEntryForIndex(j) nextIndex = if (j + 1 < dataSet.entryCount) j + 1 else j - next = dataSet.getEntryForIndex(nextIndex) + next = dataSet.getEntryForIndex(nextIndex)!! prevDx = (cur!!.x - prevPrev!!.x) * intensity prevDy = (cur.y - prevPrev.y) * intensity @@ -227,8 +227,12 @@ open class LineChartRenderer( protected fun drawCubicFill(canvas: Canvas, dataSet: ILineDataSet, spline: Path, trans: Transformer, bounds: XBounds) { val fillMin = dataSet.fillFormatter.getFillLinePosition(dataSet, dataProvider) - spline.lineTo(dataSet.getEntryForIndex(bounds.min + bounds.range).x, fillMin) - spline.lineTo(dataSet.getEntryForIndex(bounds.min).x, fillMin) + dataSet.getEntryForIndex(bounds.min + bounds.range)?.let { + spline.lineTo(it.x, fillMin) + } + dataSet.getEntryForIndex(bounds.min)?.let { + spline.lineTo(it.x, fillMin) + } spline.close() trans.pathValueToPixel(spline) @@ -270,113 +274,113 @@ open class LineChartRenderer( } // more than 1 color - if (dataSet.colors.size > 1) { - val numberOfFloats = pointsPerEntryPair * 2 + if (dataSet.colors.size > 1) { + val numberOfFloats = pointsPerEntryPair * 2 - if (lineBuffer.size <= numberOfFloats) - lineBuffer = FloatArray(numberOfFloats * 2) + if (lineBuffer.size <= numberOfFloats) + lineBuffer = FloatArray(numberOfFloats * 2) - val max = xBounds.min + xBounds.range + val max = xBounds.min + xBounds.range - for (j in xBounds.min.. 0) { - trans!!.pointValuesToPixel(lineBuffer) + if (j > 0) { + trans!!.pointValuesToPixel(lineBuffer) - val size = (max(((xBounds.range + 1) * pointsPerEntryPair).toDouble(), pointsPerEntryPair.toDouble()) * 2).toInt() + val size = (max(((xBounds.range + 1) * pointsPerEntryPair).toDouble(), pointsPerEntryPair.toDouble()) * 2).toInt() - paintRender.color = dataSet.color + paintRender.color = dataSet.color - canvas!!.drawLines(lineBuffer, 0, size, paintRender) + canvas!!.drawLines(lineBuffer, 0, size, paintRender) + } } - } } paintRender.pathEffect = null @@ -450,37 +454,36 @@ open class LineChartRenderer( val phaseY = animator.phaseY val isDrawSteppedEnabled = dataSet.lineMode == LineDataSet.Mode.STEPPED - val filled = outputPath - filled.reset() + outputPath.reset() - val entry = dataSet.getEntryForIndex(startIndex) + dataSet.getEntryForIndex(startIndex)?.let { entry -> - filled.moveTo(entry.x, fillMin) - filled.lineTo(entry.x, entry.y * phaseY) + outputPath.moveTo(entry.x, fillMin) + outputPath.lineTo(entry.x, entry.y * phaseY) - // create a new path - var currentEntry: Entry? = null - var previousEntry = entry - for (x in startIndex + 1..endIndex) { - currentEntry = dataSet.getEntryForIndex(x) + // create a new path + var currentEntry: Entry? = null + var previousEntry = entry + for (x in startIndex + 1..endIndex) { + currentEntry = dataSet.getEntryForIndex(x) - if (currentEntry != null) { - if (isDrawSteppedEnabled) { - filled.lineTo(currentEntry.x, previousEntry.y * phaseY) - } + if (currentEntry != null) { + if (isDrawSteppedEnabled) { + outputPath.lineTo(currentEntry.x, previousEntry.y * phaseY) + } - filled.lineTo(currentEntry.x, currentEntry.y * phaseY) + outputPath.lineTo(currentEntry.x, currentEntry.y * phaseY) - previousEntry = currentEntry + previousEntry = currentEntry + } } - } - // close up - if (currentEntry != null) { - filled.lineTo(currentEntry.x, fillMin) + // close up + if (currentEntry != null) { + outputPath.lineTo(currentEntry.x, fillMin) + } } - - filled.close() + outputPath.close() } override fun drawValues(canvas: Canvas) { @@ -655,19 +658,19 @@ open class LineChartRenderer( if (set == null || !set.isHighlightEnabled) continue - val e = set.getEntryForXValue(high.x, high.y) + set.getEntryForXValue(high.x, high.y)?.let { entry -> - if (!isInBoundsX(e, set)) continue - - val pix = dataProvider.getTransformer(set.axisDependency)!!.getPixelForValues( - e.x, e.y * animator - .phaseY - ) + if (!isInBoundsX(entry, set)) + continue - high.setDraw(pix.x.toFloat(), pix.y.toFloat()) + val pix = dataProvider.getTransformer(set.axisDependency)!!.getPixelForValues( + entry.x, entry.y * animator.phaseY + ) - // draw the lines - drawHighlightLines(canvas, pix.x.toFloat(), pix.y.toFloat(), set) + high.setDraw(pix.x.toFloat(), pix.y.toFloat()) + // draw the lines + drawHighlightLines(canvas, pix.x.toFloat(), pix.y.toFloat(), set) + } } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.kt index b04389ad1..38027684f 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.kt @@ -14,7 +14,6 @@ import androidx.core.graphics.createBitmap import androidx.core.graphics.withSave import com.github.mikephil.charting.animation.ChartAnimator import com.github.mikephil.charting.charts.PieChart -import com.github.mikephil.charting.data.Entry import com.github.mikephil.charting.data.PieDataSet.ValuePosition import com.github.mikephil.charting.highlight.Highlight import com.github.mikephil.charting.interfaces.datasets.IPieDataSet @@ -195,7 +194,7 @@ open class PieChartRenderer( var visibleAngleCount = 0 for (j in 0.. Utils.FLOAT_EPSILON) { + if (abs(dataSet.getEntryForIndex(j)!!.y.toDouble()) > Utils.FLOAT_EPSILON) { visibleAngleCount++ } } @@ -211,14 +210,14 @@ open class PieChartRenderer( val sliceAngle = drawAngles[j] var innerRadius = userInnerRadius - val e: Entry = dataSet.getEntryForIndex(j) + dataSet.getEntryForIndex(j)?.let { pieEntry -> - // draw only if the value is greater than zero - if (!(abs(e.y.toDouble()) > Utils.FLOAT_EPSILON)) { - angle += sliceAngle * phaseX - continue + // draw only if the value is greater than zero + if (!(abs(pieEntry.y.toDouble()) > Utils.FLOAT_EPSILON)) { + angle += sliceAngle * phaseX + continue + } } - // Don't draw if it's highlighted, unless the chart uses rounded slices if (dataSet.isHighlightEnabled && chart.needsHighlight(j) && !drawRoundedSlices) { angle += sliceAngle * phaseX @@ -310,16 +309,15 @@ open class PieChartRenderer( if (accountForSliceSpacing) { val angleMiddle = startAngleOuter + sweepAngleOuter / 2f - val sliceSpaceOffset = - calculateMinimumRadiusForSpacedSlice( - center, - radius, - sliceAngle * phaseY, - arcStartPointX, - arcStartPointY, - startAngleOuter, - sweepAngleOuter - ) + val sliceSpaceOffset = calculateMinimumRadiusForSpacedSlice( + center, + radius, + sliceAngle * phaseY, + arcStartPointX, + arcStartPointY, + startAngleOuter, + sweepAngleOuter + ) val arcEndPointX = center.x + sliceSpaceOffset * cos((angleMiddle * Utils.FDEG2RAD).toDouble()).toFloat() val arcEndPointY = center.y + sliceSpaceOffset * sin((angleMiddle * Utils.FDEG2RAD).toDouble()).toFloat() @@ -427,182 +425,157 @@ open class PieChartRenderer( iconsOffset.y = iconsOffset.y.convertDpToPixel() for (j in 0.. - angle = if (xIndex == 0) 0f - else absoluteAngles[xIndex - 1] * phaseX + angle = if (xIndex == 0) 0f + else absoluteAngles[xIndex - 1] * phaseX - val sliceAngle = drawAngles[xIndex] - val sliceSpaceMiddleAngle = sliceSpace / (Utils.FDEG2RAD * labelRadius) + val sliceAngle = drawAngles[xIndex] + val sliceSpaceMiddleAngle = sliceSpace / (Utils.FDEG2RAD * labelRadius) - // offset needed to center the drawn text in the slice - val angleOffset = (sliceAngle - sliceSpaceMiddleAngle / 2f) / 2f + // offset needed to center the drawn text in the slice + val angleOffset = (sliceAngle - sliceSpaceMiddleAngle / 2f) / 2f - angle += angleOffset + angle += angleOffset - val transformedAngle = rotationAngle + angle * phaseY + val transformedAngle = rotationAngle + angle * phaseY - val value = if (chart.isUsePercentValuesEnabled) (entry.y - / yValueSum * 100f) else entry.y - val entryLabel = entry.label + val value = if (chart.isUsePercentValuesEnabled) (entry.y / yValueSum * 100f) else entry.y + val entryLabel = entry.label - val sliceXBase = cos((transformedAngle * Utils.FDEG2RAD).toDouble()).toFloat() - val sliceYBase = sin((transformedAngle * Utils.FDEG2RAD).toDouble()).toFloat() + val sliceXBase = cos((transformedAngle * Utils.FDEG2RAD).toDouble()).toFloat() + val sliceYBase = sin((transformedAngle * Utils.FDEG2RAD).toDouble()).toFloat() - val drawXOutside = drawEntryLabels && - xValuePosition == ValuePosition.OUTSIDE_SLICE - val drawYOutside = drawValues && - yValuePosition == ValuePosition.OUTSIDE_SLICE - val drawXInside = drawEntryLabels && - xValuePosition == ValuePosition.INSIDE_SLICE - val drawYInside = drawValues && - yValuePosition == ValuePosition.INSIDE_SLICE + val drawXOutside = drawEntryLabels && xValuePosition == ValuePosition.OUTSIDE_SLICE + val drawYOutside = drawValues && yValuePosition == ValuePosition.OUTSIDE_SLICE + val drawXInside = drawEntryLabels && xValuePosition == ValuePosition.INSIDE_SLICE + val drawYInside = drawValues && yValuePosition == ValuePosition.INSIDE_SLICE - if (drawXOutside || drawYOutside) { - val valueLineLength1 = dataSet.valueLinePart1Length - val valueLineLength2 = dataSet.valueLinePart2Length - val valueLinePart1OffsetPercentage = dataSet.valueLinePart1OffsetPercentage / 100f + if (drawXOutside || drawYOutside) { + val valueLineLength1 = dataSet.valueLinePart1Length + val valueLineLength2 = dataSet.valueLinePart2Length + val valueLinePart1OffsetPercentage = dataSet.valueLinePart1OffsetPercentage / 100f - val pt2x: Float - val pt2y: Float - val labelPtx: Float - val labelPty: Float + val pt2x: Float + val pt2y: Float + val labelPtx: Float + val labelPty: Float - val line1Radius = if (chart.isDrawHoleEnabled) ((radius - (radius * holeRadiusPercent)) - * valueLinePart1OffsetPercentage - + (radius * holeRadiusPercent)) - else radius * valueLinePart1OffsetPercentage + val line1Radius = + if (chart.isDrawHoleEnabled) ((radius - (radius * holeRadiusPercent)) * valueLinePart1OffsetPercentage + (radius * holeRadiusPercent)) + else radius * valueLinePart1OffsetPercentage - val polyline2Width = if (dataSet.isValueLineVariableLength) - labelRadius * valueLineLength2 * abs( + val polyline2Width = if (dataSet.isValueLineVariableLength) labelRadius * valueLineLength2 * abs( sin( (transformedAngle * Utils.FDEG2RAD).toDouble() ) ).toFloat() - else - labelRadius * valueLineLength2 + else labelRadius * valueLineLength2 - val pt0x = line1Radius * sliceXBase + center.x - val pt0y = line1Radius * sliceYBase + center.y + val pt0x = line1Radius * sliceXBase + center.x + val pt0y = line1Radius * sliceYBase + center.y - val pt1x = labelRadius * (1 + valueLineLength1) * sliceXBase + center.x - val pt1y = labelRadius * (1 + valueLineLength1) * sliceYBase + center.y + val pt1x = labelRadius * (1 + valueLineLength1) * sliceXBase + center.x + val pt1y = labelRadius * (1 + valueLineLength1) * sliceYBase + center.y - if (transformedAngle % 360.0 in 90.0..270.0) { - pt2x = pt1x - polyline2Width - pt2y = pt1y + if (transformedAngle % 360.0 in 90.0..270.0) { + pt2x = pt1x - polyline2Width + pt2y = pt1y - paintValues.textAlign = Align.RIGHT + paintValues.textAlign = Align.RIGHT - if (drawXOutside) paintEntryLabels.textAlign = Align.RIGHT + if (drawXOutside) paintEntryLabels.textAlign = Align.RIGHT - labelPtx = pt2x - offset - labelPty = pt2y - } else { - pt2x = pt1x + polyline2Width - pt2y = pt1y - paintValues.textAlign = Align.LEFT + labelPtx = pt2x - offset + labelPty = pt2y + } else { + pt2x = pt1x + polyline2Width + pt2y = pt1y + paintValues.textAlign = Align.LEFT - if (drawXOutside) paintEntryLabels.textAlign = Align.LEFT + if (drawXOutside) paintEntryLabels.textAlign = Align.LEFT - labelPtx = pt2x + offset - labelPty = pt2y - } + labelPtx = pt2x + offset + labelPty = pt2y + } - var lineColor = ColorTemplate.COLOR_NONE + var lineColor = ColorTemplate.COLOR_NONE - if (isUseValueColorForLineEnabled) lineColor = dataSet.getColorByIndex(j) - else if (valueLineColor != ColorTemplate.COLOR_NONE) lineColor = valueLineColor + if (isUseValueColorForLineEnabled) lineColor = dataSet.getColorByIndex(j) + else if (valueLineColor != ColorTemplate.COLOR_NONE) lineColor = valueLineColor - if (lineColor != ColorTemplate.COLOR_NONE) { - valueLinePaint.color = lineColor - drawLine(pt0x, pt0y, pt1x, pt1y, valueLinePaint) - drawLine(pt1x, pt1y, pt2x, pt2y, valueLinePaint) - } + if (lineColor != ColorTemplate.COLOR_NONE) { + valueLinePaint.color = lineColor + drawLine(pt0x, pt0y, pt1x, pt1y, valueLinePaint) + drawLine(pt1x, pt1y, pt2x, pt2y, valueLinePaint) + } - // draw everything, depending on settings - if (drawXOutside && drawYOutside) { - drawValue( - this, - formatter, - value, - entry, - 0, - labelPtx, - labelPty, - dataSet.getValueTextColor(j) - ) + // draw everything, depending on settings + if (drawXOutside && drawYOutside) { + drawValue( + this, formatter, value, entry, 0, labelPtx, labelPty, dataSet.getValueTextColor(j) + ) - if (j < data.entryCount && entryLabel != null) { - drawEntryLabel(this, entryLabel, labelPtx, labelPty + lineHeight) - } - } else if (drawXOutside) { - if (j < data.entryCount && entryLabel != null) { - drawEntryLabel(this, entryLabel, labelPtx, labelPty + lineHeight / 2f) + if (j < data.entryCount && entryLabel != null) { + drawEntryLabel(this, entryLabel, labelPtx, labelPty + lineHeight) + } + } else if (drawXOutside) { + if (j < data.entryCount && entryLabel != null) { + drawEntryLabel(this, entryLabel, labelPtx, labelPty + lineHeight / 2f) + } + } else if (drawYOutside) { + drawValue( + this, + formatter, + value, + entry, + 0, + labelPtx, + labelPty + lineHeight / 2f, + dataSet.getValueTextColor(j) + ) } - } else if (drawYOutside) { - drawValue( - this, - formatter, - value, - entry, - 0, - labelPtx, - labelPty + lineHeight / 2f, - dataSet.getValueTextColor(j) - ) } - } - if (drawXInside || drawYInside) { - // calculate the text position - val x = labelRadius * sliceXBase + center.x - val y = labelRadius * sliceYBase + center.y - - paintValues.textAlign = Align.CENTER - - // draw everything, depending on settings - if (drawXInside && drawYInside) { - drawValue( - this, - formatter, - value, - entry, - 0, - x, - y, - dataSet.getValueTextColor(j) + + if (drawXInside || drawYInside) { + // calculate the text position + val x = labelRadius * sliceXBase + center.x + val y = labelRadius * sliceYBase + center.y + + paintValues.textAlign = Align.CENTER + + // draw everything, depending on settings + if (drawXInside && drawYInside) { + drawValue(this, formatter, value, entry, 0, x, y, dataSet.getValueTextColor(j) ) - if (j < data.entryCount && entryLabel != null) { - drawEntryLabel(this, entryLabel, x, y + lineHeight) - } - } else if (drawXInside) { - if (j < data.entryCount && entryLabel != null) { - drawEntryLabel(this, entryLabel, x, y + lineHeight / 2f) + if (j < data.entryCount && entryLabel != null) { + drawEntryLabel(this, entryLabel, x, y + lineHeight) + } + } else if (drawXInside) { + if (j < data.entryCount && entryLabel != null) { + drawEntryLabel(this, entryLabel, x, y + lineHeight / 2f) + } + } else if (drawYInside) { + drawValue(this, formatter, value, entry, 0, x, y + lineHeight / 2f, dataSet.getValueTextColor(j)) } - } else if (drawYInside) { - drawValue(this, formatter, value, entry, 0, x, y + lineHeight / 2f, dataSet.getValueTextColor(j)) } - } - if (entry.icon != null && dataSet.isDrawIcons) { - val icon = entry.icon + if (entry.icon != null && dataSet.isDrawIcons) { + val icon = entry.icon - val x = (labelRadius + iconsOffset.y) * sliceXBase + center.x - var y = (labelRadius + iconsOffset.y) * sliceYBase + center.y - y += iconsOffset.x + val x = (labelRadius + iconsOffset.y) * sliceXBase + center.x + var y = (labelRadius + iconsOffset.y) * sliceYBase + center.y + y += iconsOffset.x - icon?.let { - Utils.drawImage( - this, - it, - x.toInt(), - y.toInt() - ) + icon?.let { + Utils.drawImage( + this, it, x.toInt(), y.toInt() + ) + } } } - xIndex++ } @@ -642,9 +615,7 @@ open class PieChartRenderer( } // only draw the circle if it can be seen (not covered by the hole) - if (Color.alpha(paintTransparentCircle.color) > 0 && - chart.transparentCircleRadius > chart.holeRadius - ) { + if (Color.alpha(paintTransparentCircle.color) > 0 && chart.transparentCircleRadius > chart.holeRadius) { val alpha = paintTransparentCircle.alpha val secondHoleRadius = radius * (chart.transparentCircleRadius / 100) @@ -679,10 +650,8 @@ open class PieChartRenderer( val x = center.x + offset.x val y = center.y + offset.y - val innerRadius = if (chart.isDrawHoleEnabled && !chart.isDrawSlicesUnderHoleEnabled) - chart.radius * (chart.holeRadius / 100f) - else - chart.radius + val innerRadius = if (chart.isDrawHoleEnabled && !chart.isDrawSlicesUnderHoleEnabled) chart.radius * (chart.holeRadius / 100f) + else chart.radius val holeRect = rectBuffer[0] holeRect.left = x - innerRadius @@ -695,8 +664,7 @@ open class PieChartRenderer( val radiusPercent = chart.centerTextRadiusPercent / 100f if (radiusPercent > 0.0) { boundingRect.inset( - (boundingRect.width() - boundingRect.width() * radiusPercent) / 2f, - (boundingRect.height() - boundingRect.height() * radiusPercent) / 2f + (boundingRect.width() - boundingRect.width() * radiusPercent) / 2f, (boundingRect.height() - boundingRect.height() * radiusPercent) / 2f ) } @@ -710,10 +678,7 @@ open class PieChartRenderer( // If width is 0, it will crash. Always have a minimum of 1 centerTextLayout = StaticLayout( - centerText, 0, centerText.length, - paintCenterText, - max(ceil(width.toDouble()), 1.0).toInt(), - Layout.Alignment.ALIGN_CENTER, 1f, 0f, false + centerText, 0, centerText.length, paintCenterText, max(ceil(width.toDouble()), 1.0).toInt(), Layout.Alignment.ALIGN_CENTER, 1f, 0f, false ) } @@ -769,8 +734,7 @@ open class PieChartRenderer( roundedCornerPaint.isAntiAlias = true } - override fun drawHighlighted(canvas: Canvas, indices: Array) { - /* Skip entirely if using rounded circle slices, because it doesn't make sense to highlight in this way. + override fun drawHighlighted(canvas: Canvas, indices: Array) {/* Skip entirely if using rounded circle slices, because it doesn't make sense to highlight in this way. * TODO: add support for changing slice color with highlighting rather than only shifting the slice */ @@ -810,7 +774,7 @@ open class PieChartRenderer( var visibleAngleCount = 0 for (j in 0.. Utils.FLOAT_EPSILON)) { + if ((abs(set.getEntryForIndex(j)!!.y.toDouble()) > Utils.FLOAT_EPSILON)) { visibleAngleCount++ } } @@ -866,24 +830,21 @@ open class PieChartRenderer( var sliceSpaceRadius = 0f if (accountForSliceSpacing) { - sliceSpaceRadius = - calculateMinimumRadiusForSpacedSlice( - center, - radius, - sliceAngle * phaseY, - center.x + radius * cos((startAngleOuter * Utils.FDEG2RAD).toDouble()).toFloat(), - center.y + radius * sin((startAngleOuter * Utils.FDEG2RAD).toDouble()).toFloat(), - startAngleOuter, - sweepAngleOuter - ) + sliceSpaceRadius = calculateMinimumRadiusForSpacedSlice( + center, + radius, + sliceAngle * phaseY, + center.x + radius * cos((startAngleOuter * Utils.FDEG2RAD).toDouble()).toFloat(), + center.y + radius * sin((startAngleOuter * Utils.FDEG2RAD).toDouble()).toFloat(), + startAngleOuter, + sweepAngleOuter + ) } // API < 21 does not receive floats in addArc, but a RectF mInnerRectBuffer[center.x - innerRadius, center.y - innerRadius, center.x + innerRadius] = center.y + innerRadius - if (drawInnerArc && - (innerRadius > 0f || accountForSliceSpacing) - ) { + if (drawInnerArc && (innerRadius > 0f || accountForSliceSpacing)) { if (accountForSliceSpacing) { var minSpacedRadius = sliceSpaceRadius @@ -916,19 +877,15 @@ open class PieChartRenderer( if (accountForSliceSpacing) { val angleMiddle = startAngleOuter + sweepAngleOuter / 2f - val arcEndPointX = center.x + - sliceSpaceRadius * cos((angleMiddle * Utils.FDEG2RAD).toDouble()).toFloat() - val arcEndPointY = center.y + - sliceSpaceRadius * sin((angleMiddle * Utils.FDEG2RAD).toDouble()).toFloat() + val arcEndPointX = center.x + sliceSpaceRadius * cos((angleMiddle * Utils.FDEG2RAD).toDouble()).toFloat() + val arcEndPointY = center.y + sliceSpaceRadius * sin((angleMiddle * Utils.FDEG2RAD).toDouble()).toFloat() mPathBuffer.lineTo( - arcEndPointX, - arcEndPointY + arcEndPointX, arcEndPointY ) } else { mPathBuffer.lineTo( - center.x, - center.y + center.x, center.y ) } } @@ -967,23 +924,20 @@ open class PieChartRenderer( for (j in 0.. - // draw only if the value is greater than zero - if ((abs(e.y.toDouble()) > Utils.FLOAT_EPSILON)) { - val v = Math.toRadians( - ((angle + sliceAngle) - * phaseY).toDouble() - ) - val x = ((r - circleRadius) - * cos(v) + center.x).toFloat() - val y = ((r - circleRadius) - * sin(v) + center.y).toFloat() + // draw only if the value is greater than zero + if ((abs(entry.y.toDouble()) > Utils.FLOAT_EPSILON)) { + val v = Math.toRadians( + ((angle + sliceAngle) * phaseY).toDouble() + ) + val x = ((r - circleRadius) * cos(v) + center.x).toFloat() + val y = ((r - circleRadius) * sin(v) + center.y).toFloat() - paintRender.color = dataSet.getColorByIndex(j) - bitmapCanvas!!.drawCircle(x, y, circleRadius, paintRender) + paintRender.color = dataSet.getColorByIndex(j) + bitmapCanvas!!.drawCircle(x, y, circleRadius, paintRender) + } } - angle += sliceAngle * phaseX } MPPointF.recycleInstance(center) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.kt index e6196aa1c..743b7ea9b 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.kt @@ -25,8 +25,8 @@ open class RadarChartRenderer( private val paint = Paint(Paint.ANTI_ALIAS_FLAG) private val previousPath = Path() - private val innerArea = Path() - private val temp = Path() + private val innerAreaPath = Path() + private val tempPath = Path() override fun initBuffers() = Unit @@ -72,14 +72,14 @@ open class RadarChartRenderer( for (j in 0.. + Utils.getPosition( + center, + (e.y - chart.yChartMin) * factor * phaseY, + sliceAngle * j * phaseX + chart.rotationAngle, pOut + ) + } if (java.lang.Float.isNaN(pOut.x)) continue if (!hasMovedToPoint) { @@ -147,48 +147,49 @@ open class RadarChartRenderer( iconsOffset.y = iconsOffset.y.convertDpToPixel() for (j in 0.. Utils.getPosition( center, - (entry.y) * factor * phaseY + iconsOffset.y, + (entry.y - chart.yChartMin) * factor * phaseY, sliceAngle * j * phaseX + chart.rotationAngle, - pIcon + pOut ) - pIcon.y += iconsOffset.x - - icon?.let { - Utils.drawImage( + if (dataSet.isDrawValues) { + drawValue( canvas, - it, - pIcon.x.toInt(), - pIcon.y.toInt() + dataSet.valueFormatter, + entry.y, + entry, + i, + pOut.x, + pOut.y - yOffset, + dataSet.getValueTextColor(j) ) } + + if (entry.icon != null && dataSet.isDrawIcons) { + val icon = entry.icon + + Utils.getPosition( + center, + (entry.y) * factor * phaseY + iconsOffset.y, + sliceAngle * j * phaseX + chart.rotationAngle, + pIcon + ) + + pIcon.y += iconsOffset.x + + icon?.let { + Utils.drawImage( + canvas, + it, + pIcon.x.toInt(), + pIcon.y.toInt() + ) + } + } } } @@ -248,7 +249,7 @@ open class RadarChartRenderer( val p2out = MPPointF.getInstance(0f, 0f) for (j in 0.. + high.y = radarEntry.y - val y = (radarEntry.y - chart.yChartMin) + if (!isInBoundsX(radarEntry, set)) continue - Utils.getPosition( - center, - y * factor * animator.phaseY, - sliceAngle * high.x * animator.phaseX + chart.rotationAngle, - pOut - ) + val y = (radarEntry.y - chart.yChartMin) + Utils.getPosition( + center, + y * factor * animator.phaseY, + sliceAngle * high.x * animator.phaseX + chart.rotationAngle, + pOut + ) + } high.setDraw(pOut.x, pOut.y) // draw the lines diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RoundedBarChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RoundedBarChartRenderer.kt index e61feac82..6803e7044 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RoundedBarChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RoundedBarChartRenderer.kt @@ -54,10 +54,11 @@ class RoundedBarChartRenderer(chart: BarDataProvider, animator: ChartAnimator, v var i = 0 val count = min((dataSet.entryCount.toFloat() * phaseX).toDouble().toInt().toDouble(), dataSet.entryCount.toDouble()) while (i < count) { - val e = dataSet.getEntryForIndex(i) - x = e.x - mBarShadowRectBuffer.left = x - barWidthHalf - mBarShadowRectBuffer.right = x + barWidthHalf + dataSet.getEntryForIndex(i)?.let { barEntry -> + x = barEntry.x + mBarShadowRectBuffer.left = x - barWidthHalf + mBarShadowRectBuffer.right = x + barWidthHalf + } trans!!.rectValueToPixel(mBarShadowRectBuffer) if (!viewPortHandler.isInBoundsLeft(mBarShadowRectBuffer.right)) { i++ @@ -88,76 +89,92 @@ class RoundedBarChartRenderer(chart: BarDataProvider, animator: ChartAnimator, v trans!!.pointValuesToPixel(buffer.buffer) // if multiple colors has been assigned to Bar Chart - if (dataSet.colors.size > 1) { - var j = 0 - while (j < buffer.size()) { - if (!viewPortHandler.isInBoundsLeft(buffer.buffer[j + 2])) { - j += 4 - continue - } + dataSet.colors?.let { + if (it.size > 1) { + var j = 0 + while (j < buffer.size()) { + if (!viewPortHandler.isInBoundsLeft(buffer.buffer[j + 2])) { + j += 4 + continue + } - if (!viewPortHandler.isInBoundsRight(buffer.buffer[j])) { - break - } + if (!viewPortHandler.isInBoundsRight(buffer.buffer[j])) { + break + } - if (chart.isDrawBarShadowEnabled) { - if (roundedShadowRadius > 0) { - canvas.drawRoundRect( - RectF( + if (chart.isDrawBarShadowEnabled) { + if (roundedShadowRadius > 0) { + canvas.drawRoundRect( + RectF( + buffer.buffer[j], viewPortHandler.contentTop(), + buffer.buffer[j + 2], + viewPortHandler.contentBottom() + ), roundedShadowRadius, roundedShadowRadius, shadowPaint + ) + } else { + canvas.drawRect( buffer.buffer[j], viewPortHandler.contentTop(), buffer.buffer[j + 2], - viewPortHandler.contentBottom() - ), roundedShadowRadius, roundedShadowRadius, shadowPaint + viewPortHandler.contentBottom(), shadowPaint + ) + } + } + + // Set the color for the currently drawn value. If the index + paintRender.color = dataSet.getColorByIndex(j / 4) + + if (roundedPositiveDataSetRadius > 0) { + canvas.drawRoundRect( + RectF( + buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], + buffer.buffer[j + 3] + ), roundedPositiveDataSetRadius, roundedPositiveDataSetRadius, paintRender ) } else { canvas.drawRect( - buffer.buffer[j], viewPortHandler.contentTop(), - buffer.buffer[j + 2], - viewPortHandler.contentBottom(), shadowPaint + buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], + buffer.buffer[j + 3], paintRender ) } + j += 4 } + } else { + paintRender.color = dataSet.color - // Set the color for the currently drawn value. If the index - paintRender.color = dataSet.getColorByIndex(j / 4) - - if (roundedPositiveDataSetRadius > 0) { - canvas.drawRoundRect( - RectF( - buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], - buffer.buffer[j + 3] - ), roundedPositiveDataSetRadius, roundedPositiveDataSetRadius, paintRender - ) - } else { - canvas.drawRect( - buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], - buffer.buffer[j + 3], paintRender - ) - } - j += 4 - } - } else { - paintRender.color = dataSet.color + var j = 0 + while (j < buffer.size()) { + if (!viewPortHandler.isInBoundsLeft(buffer.buffer[j + 2])) { + j += 4 + continue + } - var j = 0 - while (j < buffer.size()) { - if (!viewPortHandler.isInBoundsLeft(buffer.buffer[j + 2])) { - j += 4 - continue - } + if (!viewPortHandler.isInBoundsRight(buffer.buffer[j])) { + break + } - if (!viewPortHandler.isInBoundsRight(buffer.buffer[j])) { - break - } + if (chart.isDrawBarShadowEnabled) { + if (roundedShadowRadius > 0) { + canvas.drawRoundRect( + RectF( + buffer.buffer[j], viewPortHandler.contentTop(), + buffer.buffer[j + 2], + viewPortHandler.contentBottom() + ), roundedShadowRadius, roundedShadowRadius, shadowPaint + ) + } else { + canvas.drawRect( + buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], + buffer.buffer[j + 3], paintRender + ) + } + } - if (chart.isDrawBarShadowEnabled) { - if (roundedShadowRadius > 0) { + if (roundedPositiveDataSetRadius > 0) { canvas.drawRoundRect( RectF( - buffer.buffer[j], viewPortHandler.contentTop(), - buffer.buffer[j + 2], - viewPortHandler.contentBottom() - ), roundedShadowRadius, roundedShadowRadius, shadowPaint + buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], + buffer.buffer[j + 3] + ), roundedPositiveDataSetRadius, roundedPositiveDataSetRadius, paintRender ) } else { canvas.drawRect( @@ -165,22 +182,8 @@ class RoundedBarChartRenderer(chart: BarDataProvider, animator: ChartAnimator, v buffer.buffer[j + 3], paintRender ) } + j += 4 } - - if (roundedPositiveDataSetRadius > 0) { - canvas.drawRoundRect( - RectF( - buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], - buffer.buffer[j + 3] - ), roundedPositiveDataSetRadius, roundedPositiveDataSetRadius, paintRender - ) - } else { - canvas.drawRect( - buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], - buffer.buffer[j + 3], paintRender - ) - } - j += 4 } } @@ -229,30 +232,31 @@ class RoundedBarChartRenderer(chart: BarDataProvider, animator: ChartAnimator, v ) ) + dataSet.getEntryForIndex(j / 4)?.let { barEntry -> - if ((dataSet.getEntryForIndex(j / 4).y < 0 && roundedNegativeDataSetRadius > 0)) { - val path2 = roundRect( - RectF( - buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], - buffer.buffer[j + 3] - ), roundedNegativeDataSetRadius, roundedNegativeDataSetRadius, true, true, true, true - ) - canvas.drawPath(path2, paintRender) - } else if ((dataSet.getEntryForIndex(j / 4).y > 0 && roundedPositiveDataSetRadius > 0)) { - val path2 = roundRect( - RectF( + if ((barEntry.y < 0 && roundedNegativeDataSetRadius > 0)) { + val path2 = roundRect( + RectF( + buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], + buffer.buffer[j + 3] + ), roundedNegativeDataSetRadius, roundedNegativeDataSetRadius, true, true, true, true + ) + canvas.drawPath(path2, paintRender) + } else if ((barEntry.y > 0 && roundedPositiveDataSetRadius > 0)) { + val path2 = roundRect( + RectF( + buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], + buffer.buffer[j + 3] + ), roundedPositiveDataSetRadius, roundedPositiveDataSetRadius, true, true, true, true + ) + canvas.drawPath(path2, paintRender) + } else { + canvas.drawRect( buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], - buffer.buffer[j + 3] - ), roundedPositiveDataSetRadius, roundedPositiveDataSetRadius, true, true, true, true - ) - canvas.drawPath(path2, paintRender) - } else { - canvas.drawRect( - buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], - buffer.buffer[j + 3], paintRender - ) + buffer.buffer[j + 3], paintRender + ) + } } - j += 4 } } @@ -267,49 +271,50 @@ class RoundedBarChartRenderer(chart: BarDataProvider, animator: ChartAnimator, v continue } - val barEntry = set.getEntryForXValue(high.x, high.y) + set.getEntryForXValue(high.x, high.y)?.let { barEntry -> - if (!isInBoundsX(barEntry, set)) { - continue - } + if (!isInBoundsX(barEntry, set)) { + continue + } - val trans = chart.getTransformer(set.axisDependency) + val trans = chart.getTransformer(set.axisDependency) - paintHighlight.color = set.highLightColor - paintHighlight.alpha = set.highLightAlpha + paintHighlight.color = set.highLightColor + paintHighlight.alpha = set.highLightAlpha - val isStack = high.stackIndex >= 0 && barEntry.isStacked + val isStack = high.stackIndex >= 0 && barEntry.isStacked - val y1: Float - val y2: Float + val y1: Float + val y2: Float - if (isStack) { - if (chart.isHighlightFullBarEnabled) { - y1 = barEntry.positiveSum - y2 = -barEntry.negativeSum - } else { - val range = barEntry.ranges[high.stackIndex] + if (isStack) { + if (chart.isHighlightFullBarEnabled) { + y1 = barEntry.positiveSum + y2 = -barEntry.negativeSum + } else { + val range = barEntry.ranges[high.stackIndex] - y1 = range?.from ?: 0f - y2 = range?.to ?: 0f + y1 = range?.from ?: 0f + y2 = range?.to ?: 0f + } + } else { + y1 = barEntry.y + y2 = 0f } - } else { - y1 = barEntry.y - y2 = 0f - } - prepareBarHighlight(barEntry.x, y1, y2, barData.barWidth / 2f, trans!!) + prepareBarHighlight(barEntry.x, y1, y2, barData.barWidth / 2f, trans!!) - setHighlightDrawPos(high, barRect) + setHighlightDrawPos(high, barRect) - val path2 = roundRect( - RectF( - barRect.left, barRect.top, barRect.right, - barRect.bottom - ), mRadius, mRadius, true, true, true, true - ) + val path2 = roundRect( + RectF( + barRect.left, barRect.top, barRect.right, + barRect.bottom + ), mRadius, mRadius, true, true, true, true + ) - canvas.drawPath(path2, paintHighlight) + canvas.drawPath(path2, paintHighlight) + } } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RoundedHorizontalBarChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RoundedHorizontalBarChartRenderer.kt index 1b7a77bd8..b1b28f364 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RoundedHorizontalBarChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RoundedHorizontalBarChartRenderer.kt @@ -56,10 +56,11 @@ class RoundedHorizontalBarChartRenderer(chart: BarDataProvider, animator: ChartA var i = 0 val count = min((dataSet.entryCount.toFloat() * phaseX).toDouble().toInt().toDouble(), dataSet.entryCount.toDouble()) while (i < count) { - val e = dataSet.getEntryForIndex(i) - x = e.x - mBarShadowRectBuffer.top = x - barWidthHalf - mBarShadowRectBuffer.bottom = x + barWidthHalf + dataSet.getEntryForIndex(i)?.let { barEntry -> + x = barEntry.x + mBarShadowRectBuffer.top = x - barWidthHalf + mBarShadowRectBuffer.bottom = x + barWidthHalf + } trans!!.rectValueToPixel(mBarShadowRectBuffer) if (!viewPortHandler.isInBoundsTop(mBarShadowRectBuffer.bottom)) { i++ @@ -205,27 +206,29 @@ class RoundedHorizontalBarChartRenderer(chart: BarDataProvider, animator: ChartA paintRender.color = dataSet.getColorByIndex(j / 4) } - if ((dataSet.getEntryForIndex(j / 4).y < 0 && roundedNegativeDataSetRadius > 0)) { - val path2 = roundRect( - RectF( - buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], - buffer.buffer[j + 3] - ), roundedNegativeDataSetRadius, roundedNegativeDataSetRadius, true, true, true, true - ) - canvas.drawPath(path2, paintRender) - } else if ((dataSet.getEntryForIndex(j / 4).y > 0 && roundedPositiveDataSetRadius > 0)) { - val path2 = roundRect( - RectF( + dataSet.getEntryForIndex(j / 4)?.let { barEntry -> + if ((barEntry.y < 0 && roundedNegativeDataSetRadius > 0)) { + val path2 = roundRect( + RectF( + buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], + buffer.buffer[j + 3] + ), roundedNegativeDataSetRadius, roundedNegativeDataSetRadius, true, true, true, true + ) + canvas.drawPath(path2, paintRender) + } else if ((barEntry.y > 0 && roundedPositiveDataSetRadius > 0)) { + val path2 = roundRect( + RectF( + buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], + buffer.buffer[j + 3] + ), roundedPositiveDataSetRadius, roundedPositiveDataSetRadius, true, true, true, true + ) + canvas.drawPath(path2, paintRender) + } else { + canvas.drawRect( buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], - buffer.buffer[j + 3] - ), roundedPositiveDataSetRadius, roundedPositiveDataSetRadius, true, true, true, true - ) - canvas.drawPath(path2, paintRender) - } else { - canvas.drawRect( - buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], - buffer.buffer[j + 3], paintRender - ) + buffer.buffer[j + 3], paintRender + ) + } } j += 4 } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.kt index 62f3f2bcc..c62c65168 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.kt @@ -50,25 +50,26 @@ open class ScatterChartRenderer(@JvmField var dataProvider: ScatterDataProvider, ).toInt() for (i in 0.. - pixelBuffer[0] = entry.x - pixelBuffer[1] = entry.y * phaseY + pixelBuffer[0] = entry.x + pixelBuffer[1] = entry.y * phaseY - trans!!.pointValuesToPixel(pixelBuffer) + trans!!.pointValuesToPixel(pixelBuffer) - if (!viewPortHandler.isInBoundsRight(pixelBuffer[0])) - break + if (!viewPortHandler.isInBoundsRight(pixelBuffer[0])) + break - if (!viewPortHandler.isInBoundsLeft(pixelBuffer[0]) || !viewPortHandler.isInBoundsY(pixelBuffer[1]) - ) continue + if (!viewPortHandler.isInBoundsLeft(pixelBuffer[0]) || !viewPortHandler.isInBoundsY(pixelBuffer[1])) + continue - paintRender.color = dataSet.getColorByIndex(i / 2) - renderer.renderShape( - canvas, dataSet, this.viewPortHandler, - pixelBuffer[0], pixelBuffer[1], - paintRender - ) + paintRender.color = dataSet.getColorByIndex(i / 2) + renderer.renderShape( + canvas, dataSet, this.viewPortHandler, + pixelBuffer[0], pixelBuffer[1], + paintRender + ) + } } } @@ -104,7 +105,8 @@ open class ScatterChartRenderer(@JvmField var dataProvider: ScatterDataProvider, var j = 0 while (j < positions.size) { - if (!viewPortHandler.isInBoundsRight(positions[j])) break + if (!viewPortHandler.isInBoundsRight(positions[j])) + break // make sure the lines don't do shitty things outside bounds if ((!viewPortHandler.isInBoundsLeft(positions[j]) @@ -114,32 +116,33 @@ open class ScatterChartRenderer(@JvmField var dataProvider: ScatterDataProvider, continue } - val entry = dataSet.getEntryForIndex(j / 2 + xBounds.min) - - if (dataSet.isDrawValues) { - drawValue( - canvas, - dataSet.valueFormatter, - entry.y, - entry, - i, - positions[j], - positions[j + 1] - shapeSize, - dataSet.getValueTextColor(j / 2 + xBounds.min) - ) - } - - if (entry.icon != null && dataSet.isDrawIcons) { - val icon = entry.icon + dataSet.getEntryForIndex(j / 2 + xBounds.min)?.let { entry -> - icon?.let { - Utils.drawImage( + if (dataSet.isDrawValues) { + drawValue( canvas, - it, - (positions[j] + iconsOffset.x).toInt(), - (positions[j + 1] + iconsOffset.y).toInt() + dataSet.valueFormatter, + entry.y, + entry, + i, + positions[j], + positions[j + 1] - shapeSize, + dataSet.getValueTextColor(j / 2 + xBounds.min) ) } + + if (entry.icon != null && dataSet.isDrawIcons) { + val icon = entry.icon + + icon?.let { + Utils.drawImage( + canvas, + it, + (positions[j] + iconsOffset.x).toInt(), + (positions[j + 1] + iconsOffset.y).toInt() + ) + } + } } j += 2 } @@ -160,19 +163,20 @@ open class ScatterChartRenderer(@JvmField var dataProvider: ScatterDataProvider, if (set == null || !set.isHighlightEnabled) continue - val entry = set.getEntryForXValue(high.x, high.y) + set.getEntryForXValue(high.x, high.y)?.let { entry -> - if (!isInBoundsX(entry, set)) continue + if (!isInBoundsX(entry, set)) continue - val pix = dataProvider.getTransformer(set.axisDependency)!!.getPixelForValues( - entry.x, entry.y * animator - .phaseY - ) + val pix = dataProvider.getTransformer(set.axisDependency)!!.getPixelForValues( + entry.x, entry.y * animator + .phaseY + ) - high.setDraw(pix.x.toFloat(), pix.y.toFloat()) + high.setDraw(pix.x.toFloat(), pix.y.toFloat()) - // draw the lines - drawHighlightLines(canvas, pix.x.toFloat(), pix.y.toFloat(), set) + // draw the lines + drawHighlightLines(canvas, pix.x.toFloat(), pix.y.toFloat(), set) + } } } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.kt index 78a758264..13c2408c4 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.kt @@ -162,15 +162,15 @@ open class XAxisRenderer( val labelRotationAngleDegrees = xAxis.labelRotationAngle val centeringEnabled = xAxis.isCenterAxisLabelsEnabled - val positions: FloatArray + var positions: FloatArray if (xAxis.isShowSpecificPositions) { - positions = FloatArray(xAxis.specificPositions.size * 2) - var i = 0 - while (i < positions.size) { - positions[i] = xAxis.specificPositions[i / 2] - i += 2 - } + positions = FloatArray(xAxis.specificPositions.size * 2) + var i = 0 + while (i < positions.size) { + positions[i] = xAxis.specificPositions[i / 2] + i += 2 + } } else { positions = FloatArray(xAxis.mEntryCount * 2) var i = 0 @@ -340,29 +340,29 @@ open class XAxisRenderer( override fun renderLimitLines(canvas: Canvas) { val limitLines = xAxis.limitLines - if (limitLines == null || limitLines.isEmpty()) return + if (limitLines.isEmpty()) return val position = mRenderLimitLinesBuffer position[0] = 0f position[1] = 0f for (i in limitLines.indices) { - val l = limitLines[i] + val limitLine = limitLines[i]!! - if (!l.isEnabled) continue + if (!limitLine.isEnabled) continue canvas.withSave { mLimitLineClippingRect.set(viewPortHandler.contentRect) - mLimitLineClippingRect.inset(-l.lineWidth, 0f) + mLimitLineClippingRect.inset(-limitLine.lineWidth, 0f) canvas.clipRect(mLimitLineClippingRect) - position[0] = l.limit + position[0] = limitLine.limit position[1] = 0f transformer!!.pointValuesToPixel(position) - renderLimitLineLine(canvas, l, position) - renderLimitLineLabel(canvas, l, position, 2f + l.yOffset) + renderLimitLineLine(canvas, limitLine, position) + renderLimitLineLabel(canvas, limitLine, position, 2f + limitLine.yOffset) } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.kt index 726adb054..e47e637cc 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.kt @@ -205,7 +205,7 @@ open class XAxisRendererHorizontalBarChart( override fun renderLimitLines(canvas: Canvas) { val limitLines = xAxis.limitLines - if (limitLines == null || limitLines.isEmpty()) return + if (limitLines.isEmpty()) return val pts = mRenderLimitLinesBuffer pts[0] = 0f @@ -215,21 +215,21 @@ open class XAxisRendererHorizontalBarChart( limitLinePath.reset() for (i in limitLines.indices) { - val l = limitLines[i] + val limitLine = limitLines[i]!! - if (!l.isEnabled) continue + if (!limitLine.isEnabled) continue canvas.withSave { mLimitLineClippingRect.set(viewPortHandler.contentRect) - mLimitLineClippingRect.inset(0f, -l.lineWidth) + mLimitLineClippingRect.inset(0f, -limitLine.lineWidth) canvas.clipRect(mLimitLineClippingRect) limitLinePaint.style = Paint.Style.STROKE - limitLinePaint.color = l.lineColor - limitLinePaint.strokeWidth = l.lineWidth - limitLinePaint.pathEffect = l.dashPathEffect + limitLinePaint.color = limitLine.lineColor + limitLinePaint.strokeWidth = limitLine.lineWidth + limitLinePaint.pathEffect = limitLine.dashPathEffect - pts[1] = l.limit + pts[1] = limitLine.limit transformer!!.pointValuesToPixel(pts) @@ -240,21 +240,21 @@ open class XAxisRendererHorizontalBarChart( limitLinePath.reset() // c.drawLines(pts, mLimitLinePaint); - val label = l.label + val label = limitLine.label // if drawing the limit-value label is enabled if (label != null && label != "") { - limitLinePaint.style = l.textStyle + limitLinePaint.style = limitLine.textStyle limitLinePaint.pathEffect = null - limitLinePaint.color = l.textColor + limitLinePaint.color = limitLine.textColor limitLinePaint.strokeWidth = 0.5f - limitLinePaint.textSize = l.textSize + limitLinePaint.textSize = limitLine.textSize val labelLineHeight = Utils.calcTextHeight(limitLinePaint, label).toFloat() - val xOffset = 4f.convertDpToPixel() + l.xOffset - val yOffset = l.lineWidth + labelLineHeight + l.yOffset + val xOffset = 4f.convertDpToPixel() + limitLine.xOffset + val yOffset = limitLine.lineWidth + labelLineHeight + limitLine.yOffset - val position = l.labelPosition + val position = limitLine.labelPosition when (position) { LimitLabelPosition.RIGHT_TOP -> { diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRenderer.kt index 66505c0b1..49792a15e 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRenderer.kt @@ -269,7 +269,7 @@ open class YAxisRenderer(viewPortHandler: ViewPortHandler, @JvmField protected v */ override fun renderLimitLines(canvas: Canvas) { val limitLines = yAxis.limitLines - if (limitLines != null && limitLines.isNotEmpty()) { + if (limitLines.isNotEmpty()) { val pts = renderLimitLinesBuffer pts[0] = 0f pts[1] = 0f @@ -277,7 +277,7 @@ open class YAxisRenderer(viewPortHandler: ViewPortHandler, @JvmField protected v limitLinePath.reset() for (i in limitLines.indices) { - val limitLine = limitLines[i] + val limitLine = limitLines[i]!! if (!limitLine.isEnabled) continue @@ -362,7 +362,7 @@ open class YAxisRenderer(viewPortHandler: ViewPortHandler, @JvmField protected v // Now the ranges val limitRanges = yAxis.limitRanges - if (limitRanges != null && limitRanges.isNotEmpty()) { + if (limitRanges.isNotEmpty()) { val ptsr = FloatArray(2) ptsr[0] = 0f ptsr[1] = 0f @@ -375,7 +375,7 @@ open class YAxisRenderer(viewPortHandler: ViewPortHandler, @JvmField protected v limitRangePathFill.reset() for (limitRangeIndex in limitRanges.indices) { - val limitRange = limitRanges[limitRangeIndex] + val limitRange = limitRanges[limitRangeIndex]!! if (!limitRange.isEnabled) continue diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererHorizontalBarChart.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererHorizontalBarChart.kt index 87bc5b299..f439de821 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererHorizontalBarChart.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererHorizontalBarChart.kt @@ -69,7 +69,7 @@ open class YAxisRendererHorizontalBarChart( val positions = transformedPositions - paintAxisLabels.setTypeface(yAxis.typeface) + paintAxisLabels.typeface = yAxis.typeface paintAxisLabels.textSize = yAxis.textSize paintAxisLabels.color = yAxis.textColor paintAxisLabels.textAlign = Align.CENTER @@ -125,7 +125,7 @@ open class YAxisRendererHorizontalBarChart( * @param positions */ override fun drawYLabels(canvas: Canvas, fixedPosition: Float, positions: FloatArray, offset: Float) { - paintAxisLabels.setTypeface(yAxis.typeface) + paintAxisLabels.typeface = yAxis.typeface paintAxisLabels.textSize = yAxis.textSize paintAxisLabels.color = yAxis.textColor @@ -140,12 +140,14 @@ open class YAxisRendererHorizontalBarChart( for (i in from.. { diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererRadarChart.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererRadarChart.kt index 007f98878..b7bb0ce51 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererRadarChart.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererRadarChart.kt @@ -162,14 +162,14 @@ class YAxisRendererRadarChart(viewPortHandler: ViewPortHandler, yAxis: YAxis, pr val label = yAxis.getFormattedLabel(j) - canvas.drawText(label, pOut.x + xOffset, pOut.y, paintAxisLabels) + label?.let { canvas.drawText(it, pOut.x + xOffset, pOut.y, paintAxisLabels) } } MPPointF.recycleInstance(center) MPPointF.recycleInstance(pOut) } override fun renderLimitLines(canvas: Canvas) { - val limitLines = yAxis.limitLines ?: return + val limitLines = yAxis.limitLines val sliceAngle = chart.sliceAngle @@ -180,15 +180,15 @@ class YAxisRendererRadarChart(viewPortHandler: ViewPortHandler, yAxis: YAxis, pr val center = chart.centerOffsets val pOut = MPPointF.getInstance(0f, 0f) for (i in limitLines.indices) { - val l = limitLines[i] + val limitLine = limitLines[i]!! - if (!l.isEnabled) continue + if (!limitLine.isEnabled) continue - limitLinePaint.color = l.lineColor - limitLinePaint.pathEffect = l.dashPathEffect - limitLinePaint.strokeWidth = l.lineWidth + limitLinePaint.color = limitLine.lineColor + limitLinePaint.pathEffect = limitLine.dashPathEffect + limitLinePaint.strokeWidth = limitLine.lineWidth - val r = (l.limit - chart.yChartMin) * factor + val r = (limitLine.limit - chart.yChartMin) * factor val limitPath = renderLimitLinesPathBuffer limitPath.reset() diff --git a/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/DataSetTest.kt b/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/DataSetTest.kt index b5db37fc2..c89fb1054 100644 --- a/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/DataSetTest.kt +++ b/MPChartLib/src/test/kotlin/com/github/mikephil/charting/test/DataSetTest.kt @@ -64,49 +64,49 @@ class DataSetTest { Assert.assertEquals(1f, set.yMin, 0.01f) Assert.assertEquals(10f, set.yMax, 0.01f) - Assert.assertEquals(5f, set.getEntryForIndex(0).x, 0.01f) - Assert.assertEquals(1f, set.getEntryForIndex(0).y, 0.01f) + Assert.assertEquals(5f, set.getEntryForIndex(0)!!.x, 0.01f) + Assert.assertEquals(1f, set.getEntryForIndex(0)!!.y, 0.01f) set.addEntryOrdered(Entry(20f, 50f)) Assert.assertEquals(5, set.entryCount) - Assert.assertEquals(20f, set.getEntryForIndex(3).x, 0.01f) - Assert.assertEquals(50f, set.getEntryForIndex(3).y, 0.01f) + Assert.assertEquals(20f, set.getEntryForIndex(3)!!.x, 0.01f) + Assert.assertEquals(50f, set.getEntryForIndex(3)!!.y, 0.01f) Assert.assertTrue(set.removeEntry(3)) Assert.assertEquals(4, set.entryCount) - Assert.assertEquals(21f, set.getEntryForIndex(3).x, 0.01f) - Assert.assertEquals(5f, set.getEntryForIndex(3).y, 0.01f) + Assert.assertEquals(21f, set.getEntryForIndex(3)!!.x, 0.01f) + Assert.assertEquals(5f, set.getEntryForIndex(3)!!.y, 0.01f) - Assert.assertEquals(5f, set.getEntryForIndex(0).x, 0.01f) - Assert.assertEquals(1f, set.getEntryForIndex(0).y, 0.01f) + Assert.assertEquals(5f, set.getEntryForIndex(0)!!.x, 0.01f) + Assert.assertEquals(1f, set.getEntryForIndex(0)!!.y, 0.01f) Assert.assertTrue(set.removeFirst()) Assert.assertEquals(3, set.entryCount) - Assert.assertEquals(10f, set.getEntryForIndex(0).x, 0.01f) - Assert.assertEquals(10f, set.getEntryForIndex(0).y, 0.01f) + Assert.assertEquals(10f, set.getEntryForIndex(0)!!.x, 0.01f) + Assert.assertEquals(10f, set.getEntryForIndex(0)!!.y, 0.01f) set.addEntryOrdered(Entry(15f, 3f)) Assert.assertEquals(4, set.entryCount) - Assert.assertEquals(15f, set.getEntryForIndex(1).x, 0.01f) - Assert.assertEquals(3f, set.getEntryForIndex(1).y, 0.01f) + Assert.assertEquals(15f, set.getEntryForIndex(1)!!.x, 0.01f) + Assert.assertEquals(3f, set.getEntryForIndex(1)!!.y, 0.01f) - Assert.assertEquals(21f, set.getEntryForIndex(3).x, 0.01f) - Assert.assertEquals(5f, set.getEntryForIndex(3).y, 0.01f) + Assert.assertEquals(21f, set.getEntryForIndex(3)!!.x, 0.01f) + Assert.assertEquals(5f, set.getEntryForIndex(3)!!.y, 0.01f) Assert.assertTrue(set.removeLast()) Assert.assertEquals(3, set.entryCount) - Assert.assertEquals(15f, set.getEntryForIndex(2).x, 0.01f) - Assert.assertEquals(2f, set.getEntryForIndex(2).y, 0.01f) + Assert.assertEquals(15f, set.getEntryForIndex(2)!!.x, 0.01f) + Assert.assertEquals(2f, set.getEntryForIndex(2)!!.y, 0.01f) Assert.assertTrue(set.removeLast()) @@ -116,8 +116,8 @@ class DataSetTest { Assert.assertEquals(1, set.entryCount) - Assert.assertEquals(10f, set.getEntryForIndex(0).x, 0.01f) - Assert.assertEquals(10f, set.getEntryForIndex(0).y, 0.01f) + Assert.assertEquals(10f, set.getEntryForIndex(0)!!.x, 0.01f) + Assert.assertEquals(10f, set.getEntryForIndex(0)!!.y, 0.01f) Assert.assertTrue(set.removeLast()) @@ -137,31 +137,31 @@ class DataSetTest { val set = ScatterDataSet(entries, "") var closest = set.getEntryForXValue(17f, Float.NaN, DataSet.Rounding.CLOSEST) - Assert.assertEquals(15f, closest.x, 0.01f) + Assert.assertEquals(15f, closest!!.x, 0.01f) Assert.assertEquals(5f, closest.y, 0.01f) closest = set.getEntryForXValue(17f, Float.NaN, DataSet.Rounding.DOWN) - Assert.assertEquals(15f, closest.x, 0.01f) + Assert.assertEquals(15f, closest!!.x, 0.01f) Assert.assertEquals(5f, closest.y, 0.01f) closest = set.getEntryForXValue(15f, Float.NaN, DataSet.Rounding.DOWN) - Assert.assertEquals(15f, closest.x, 0.01f) + Assert.assertEquals(15f, closest!!.x, 0.01f) Assert.assertEquals(5f, closest.y, 0.01f) closest = set.getEntryForXValue(14f, Float.NaN, DataSet.Rounding.DOWN) - Assert.assertEquals(10f, closest.x, 0.01f) + Assert.assertEquals(10f, closest!!.x, 0.01f) Assert.assertEquals(10f, closest.y, 0.01f) closest = set.getEntryForXValue(17f, Float.NaN, DataSet.Rounding.UP) - Assert.assertEquals(21f, closest.x, 0.01f) + Assert.assertEquals(21f, closest!!.x, 0.01f) Assert.assertEquals(5f, closest.y, 0.01f) closest = set.getEntryForXValue(21f, Float.NaN, DataSet.Rounding.UP) - Assert.assertEquals(21f, closest.x, 0.01f) + Assert.assertEquals(21f, closest!!.x, 0.01f) Assert.assertEquals(5f, closest.y, 0.01f) closest = set.getEntryForXValue(21f, Float.NaN, DataSet.Rounding.CLOSEST) - Assert.assertEquals(21f, closest.x, 0.01f) + Assert.assertEquals(21f, closest!!.x, 0.01f) Assert.assertEquals(5f, closest.y, 0.01f) } @@ -186,39 +186,39 @@ class DataSetTest { val set = ScatterDataSet(values, "") var closest = set.getEntryForXValue(0f, Float.NaN, DataSet.Rounding.CLOSEST) - Assert.assertEquals(0f, closest.x, 0.01f) + Assert.assertEquals(0f, closest!!.x, 0.01f) Assert.assertEquals(10f, closest.y, 0.01f) closest = set.getEntryForXValue(5f, Float.NaN, DataSet.Rounding.CLOSEST) - Assert.assertEquals(5f, closest.x, 0.01f) + Assert.assertEquals(5f, closest!!.x, 0.01f) Assert.assertEquals(80f, closest.y, 0.01f) closest = set.getEntryForXValue(5.4f, Float.NaN, DataSet.Rounding.CLOSEST) - Assert.assertEquals(5f, closest.x, 0.01f) + Assert.assertEquals(5f, closest!!.x, 0.01f) Assert.assertEquals(80f, closest.y, 0.01f) closest = set.getEntryForXValue(4.6f, Float.NaN, DataSet.Rounding.CLOSEST) - Assert.assertEquals(5f, closest.x, 0.01f) + Assert.assertEquals(5f, closest!!.x, 0.01f) Assert.assertEquals(80f, closest.y, 0.01f) closest = set.getEntryForXValue(7f, Float.NaN, DataSet.Rounding.CLOSEST) - Assert.assertEquals(7f, closest.x, 0.01f) + Assert.assertEquals(7f, closest!!.x, 0.01f) Assert.assertEquals(100f, closest.y, 0.01f) closest = set.getEntryForXValue(4f, Float.NaN, DataSet.Rounding.CLOSEST) - Assert.assertEquals(4f, closest.x, 0.01f) + Assert.assertEquals(4f, closest!!.x, 0.01f) Assert.assertEquals(60f, closest.y, 0.01f) var entries = set.getEntriesForXValue(4f) - Assert.assertEquals(2, entries.size) - Assert.assertEquals(60f, entries[0].y, 0.01f) - Assert.assertEquals(70f, entries[1].y, 0.01f) + Assert.assertEquals(2, entries!!.size) + Assert.assertEquals(60f, entries[0]!!.y, 0.01f) + Assert.assertEquals(70f, entries[1]!!.y, 0.01f) entries = set.getEntriesForXValue(3.5f) - Assert.assertEquals(0, entries.size) + Assert.assertEquals(0, entries!!.size) entries = set.getEntriesForXValue(2f) - Assert.assertEquals(1, entries.size) - Assert.assertEquals(30f, entries[0].y, 0.01f) + Assert.assertEquals(1, entries!!.size) + Assert.assertEquals(30f, entries[0]!!.y, 0.01f) } } diff --git a/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt index aa8c83b9b..b7844bc4f 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt @@ -96,7 +96,7 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener { } else { set1 = BarDataSet(values, "Data Set") set1.setColors(*ColorTemplate.VORDIPLOM_COLORS) - set1.setDrawValues(false) + set1.isDrawValues = false val dataSets = ArrayList() dataSets.add(set1) @@ -124,9 +124,10 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } + chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt index d5f77a0c1..3e9b76dcd 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt @@ -81,8 +81,8 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect xAxis.position = XAxisPosition.BOTTOM xAxis.typeface = tfLight xAxis.setDrawGridLines(false) - xAxis.setGranularity(1f) // only intervals of 1 day - xAxis.setLabelCount(7) + xAxis.granularity = 1f // only intervals of 1 day + xAxis.labelCount = 7 xAxis.valueFormatter = xAxisFormatter val custom: IAxisValueFormatter = MyAxisValueFormatter() @@ -93,7 +93,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect leftAxis.valueFormatter = custom leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART) leftAxis.spaceTop = 15f - leftAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + leftAxis.axisMinimum = 0f// this replaces setStartAtZero(true) val rightAxis = chart!!.axisRight rightAxis.setDrawGridLines(false) @@ -101,7 +101,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect rightAxis.setLabelCount(8, false) rightAxis.valueFormatter = custom rightAxis.spaceTop = 15f - rightAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + rightAxis.axisMinimum = 0f// this replaces setStartAtZero(true) val l = chart!!.legend l.verticalAlignment = Legend.LegendVerticalAlignment.BOTTOM @@ -154,7 +154,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect } else { set1 = BarDataSet(values, "The year 2017") - set1.setDrawIcons(false) + set1.isDrawIcons = false val startColor1 = ContextCompat.getColor(this, android.R.color.holo_orange_light) val startColor2 = ContextCompat.getColor(this, android.R.color.holo_blue_light) @@ -202,15 +202,16 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } + chart!!.invalidate() } R.id.actionToggleIcons -> { for (set in chart!!.data!!.dataSets) - set.setDrawIcons(!set.isDrawIcons()) + set.isDrawIcons = !set.isDrawIcons chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt index 720c534f6..d13fc3bf1 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt @@ -86,7 +86,7 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar val xAxis = chart!!.xAxis xAxis.typeface = tfLight - xAxis.setGranularity(1f) + xAxis.granularity = 1f xAxis.setCenterAxisLabels(true) xAxis.valueFormatter = object : IAxisValueFormatter { override fun getFormattedValue(value: Float, axis: AxisBase?): String { @@ -99,7 +99,7 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar leftAxis.valueFormatter = LargeValueFormatter() leftAxis.setDrawGridLines(false) leftAxis.spaceTop = 35f - leftAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + leftAxis.axisMinimum = 0f // this replaces setStartAtZero(true) chart!!.axisRight.isEnabled = false } @@ -151,13 +151,13 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar } else { // create 4 DataSets set1 = BarDataSet(values1, "Company A") - set1.setColor(Color.rgb(104, 241, 175)) + set1.color = Color.rgb(104, 241, 175) set2 = BarDataSet(values2, "Company B") - set2.setColor(Color.rgb(164, 228, 251)) + set2.color = Color.rgb(164, 228, 251) set3 = BarDataSet(values3, "Company C") - set3.setColor(Color.rgb(242, 247, 158)) + set3.color = Color.rgb(242, 247, 158) set4 = BarDataSet(values4, "Company D") - set4.setColor(Color.rgb(255, 102, 0)) + set4.color = Color.rgb(255, 102, 0) val data = BarData(set1, set2, set3, set4) data.setValueFormatter(LargeValueFormatter()) @@ -170,10 +170,10 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar chart!!.barData.barWidth = barWidth // restrict the x-axis range - chart!!.xAxis.setAxisMinimum(startYear.toFloat()) + chart!!.xAxis.axisMinimum = startYear.toFloat() // barData.getGroupWith(...) is a helper that calculates the width each group needs based on the provided parameters - chart!!.xAxis.setAxisMaximum(startYear + chart!!.barData.getGroupWidth(groupSpace, barSpace) * groupCount) + chart!!.xAxis.axisMaximum = startYear + chart!!.barData.getGroupWidth(groupSpace, barSpace) * groupCount chart!!.groupBars(startYear.toFloat(), groupSpace, barSpace) chart!!.invalidate() } @@ -193,9 +193,10 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } + chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivitySinus.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivitySinus.kt index 1365320fe..098a5190c 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivitySinus.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivitySinus.kt @@ -57,18 +57,18 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener { val leftAxis = binding.chart1.axisLeft leftAxis.typeface = tfLight leftAxis.setLabelCount(6, false) - leftAxis.setAxisMinimum(-2.5f) - leftAxis.setAxisMaximum(2.5f) + leftAxis.axisMinimum = -2.5f + leftAxis.axisMaximum = 2.5f leftAxis.isGranularityEnabled = true - leftAxis.setGranularity(0.1f) + leftAxis.granularity = 0.1f val rightAxis = binding.chart1.axisRight rightAxis.setDrawGridLines(false) rightAxis.typeface = tfLight rightAxis.setLabelCount(6, false) - rightAxis.setAxisMinimum(-2.5f) - rightAxis.setAxisMaximum(2.5f) - rightAxis.setGranularity(0.1f) + rightAxis.axisMinimum = -2.5f + rightAxis.axisMaximum = 2.5f + rightAxis.granularity = 0.1f binding.seekbarValues.setOnSeekBarChangeListener(this) binding.seekbarValues.progress = 150 // set data @@ -105,7 +105,7 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener { binding.chart1.notifyDataSetChanged() } else { set = BarDataSet(entries, "Sinus Function") - set.setColor(Color.BLUE) + set.color = Color.BLUE } val data = BarData(set) @@ -131,9 +131,10 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleValues -> { - binding.chart1.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + binding.chart1.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } + binding.chart1.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt index bc39b003f..a4d4fa00b 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt @@ -52,9 +52,9 @@ class BarChartPositiveNegative : DemoBase() { xAxis.setDrawAxisLine(false) xAxis.textColor = Color.LTGRAY xAxis.textSize = 13f - xAxis.setLabelCount(5) + xAxis.labelCount = 5 xAxis.setCenterAxisLabels(true) - xAxis.setGranularity(1f) + xAxis.granularity = 1f val left = chart!!.axisLeft left.setDrawLabels(false) @@ -114,7 +114,7 @@ class BarChartPositiveNegative : DemoBase() { } else { set = BarDataSet(values, "Values") set.setColors(colors) - set.setValueTextColors(colors) + set.valueTextColors = colors val data = BarData(set) data.setValueTextSize(13f) diff --git a/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt index fc738ce75..647e067c2 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt @@ -122,19 +122,19 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel // create a dataset and give it a type val set1 = BubbleDataSet(values1, "DS 1") - set1.setDrawIcons(false) + set1.isDrawIcons = false set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130) - set1.setDrawValues(true) + set1.isDrawValues = true val set2 = BubbleDataSet(values2, "DS 2") - set2.setDrawIcons(false) - set2.setIconsOffset(MPPointF(0f, 15f)) + set2.isDrawIcons = false + set2.iconsOffset = MPPointF(0f, 15f) set2.setColor(ColorTemplate.COLORFUL_COLORS[1], 130) - set2.setDrawValues(true) + set2.isDrawValues = true val set3 = BubbleDataSet(values3, "DS 3") set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130) - set3.setDrawValues(true) + set3.isDrawValues = true val dataSets = ArrayList() dataSets.add(set1) // add the data sets @@ -167,15 +167,15 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } chart!!.invalidate() } R.id.actionToggleIcons -> { - for (set in chart!!.data!!.dataSets) set.setDrawIcons(!set.isDrawIcons()) - + for (set in chart!!.data!!.dataSets) + set.isDrawIcons = !set.isDrawIcons chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/CandleStickChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CandleStickChartActivity.kt index ab223c24c..c90c8fd07 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CandleStickChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CandleStickChartActivity.kt @@ -13,6 +13,7 @@ import android.widget.SeekBar.OnSeekBarChangeListener import android.widget.TextView import androidx.core.content.ContextCompat import androidx.core.content.res.ResourcesCompat +import androidx.core.net.toUri import com.github.mikephil.charting.charts.CandleStickChart import com.github.mikephil.charting.components.XAxis.XAxisPosition import com.github.mikephil.charting.components.YAxis.AxisDependency @@ -21,7 +22,6 @@ import com.github.mikephil.charting.data.CandleDataSet import com.github.mikephil.charting.data.CandleEntry import info.appdev.chartexample.DataTools.Companion.getValues import info.appdev.chartexample.notimportant.DemoBase -import androidx.core.net.toUri class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener { private var chart: CandleStickChart? = null @@ -115,7 +115,7 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener { val set1 = CandleDataSet(values, "Data Set") - set1.setDrawIcons(false) + set1.isDrawIcons = false set1.axisDependency = AxisDependency.LEFT // set1.setColor(Color.rgb(80, 80, 80)); set1.shadowColor = Color.DKGRAY @@ -148,15 +148,15 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } chart!!.invalidate() } R.id.actionToggleIcons -> { - for (set in chart!!.data!!.dataSets) set.setDrawIcons(!set.isDrawIcons()) - + for (set in chart!!.data!!.dataSets) + set.isDrawIcons = !set.isDrawIcons chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt index 0b7916e61..70cf25de2 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt @@ -5,6 +5,7 @@ import android.graphics.Color import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.core.net.toUri import com.github.mikephil.charting.charts.CombinedChart import com.github.mikephil.charting.charts.CombinedChart.DrawOrder import com.github.mikephil.charting.components.AxisBase @@ -30,7 +31,6 @@ import com.github.mikephil.charting.formatter.IAxisValueFormatter import com.github.mikephil.charting.utils.ColorTemplate import info.appdev.chartexample.DataTools.Companion.getValues import info.appdev.chartexample.notimportant.DemoBase -import androidx.core.net.toUri import kotlin.math.roundToInt class CombinedChartActivity : DemoBase() { @@ -65,16 +65,16 @@ class CombinedChartActivity : DemoBase() { val rightAxis = chart!!.axisRight rightAxis.setDrawGridLines(false) - rightAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + rightAxis.axisMinimum = 0f // this replaces setStartAtZero(true) val leftAxis = chart!!.axisLeft leftAxis.setDrawGridLines(false) - leftAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + leftAxis.axisMinimum = 0f // this replaces setStartAtZero(true) val xAxis = chart!!.xAxis xAxis.position = XAxisPosition.BOTH_SIDED - xAxis.setAxisMinimum(0f) - xAxis.setGranularity(1f) + xAxis.axisMinimum = 0f + xAxis.granularity = 1f xAxis.valueFormatter = object : IAxisValueFormatter { override fun getFormattedValue(value: Float, axis: AxisBase?): String { return months[value.toInt() % months.size] @@ -90,7 +90,7 @@ class CombinedChartActivity : DemoBase() { data.setData(generateCandleData()) data.setValueTypeface(tfLight) - xAxis.setAxisMaximum(data.xMax + 0.25f) + xAxis.axisMaximum = data.xMax + 0.25f chart!!.setData(data) chart!!.invalidate() @@ -104,7 +104,7 @@ class CombinedChartActivity : DemoBase() { for (index in 0.. { - for (set in chart!!.data!!.dataSets) { - if (set is LineDataSet) set.isDrawValues = !set.isDrawValues + chart!!.data!!.dataSets.forEach { + if (it is LineDataSet) + it.isDrawValues = !it.isDrawValues } - chart!!.invalidate() } R.id.actionToggleBarValues -> { - for (set in chart!!.data!!.dataSets) { - if (set is BarDataSet) set.isDrawValues = !set.isDrawValues + chart!!.data!!.dataSets.forEach { + if (it is BarDataSet) + it.isDrawValues = !it.isDrawValues } chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt index 206e38543..95d355229 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CubicLineChartActivity.kt @@ -115,13 +115,13 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { set1.cubicIntensity = 0.2f set1.setDrawFilled(true) set1.setDrawCircles(false) - set1.lineWidth = 1.8f + set1.setLineWidth(1.8f) set1.circleRadius = 4f set1.setCircleColor(Color.WHITE) set1.setHighLightColor(Color.rgb(244, 117, 117)) set1.color = Color.WHITE - set1.fillColor = Color.WHITE - set1.fillAlpha = 100 + set1.setFillColor(Color.WHITE) + set1.setFillAlpha(100) set1.setDrawHorizontalHighlightIndicator(false) set1.fillFormatter = object : IFillFormatter { override fun getFillLinePosition(dataSet: ILineDataSet?, dataProvider: LineDataProvider?): Float { @@ -154,8 +154,8 @@ class CubicLineChartActivity : DemoBase(), OnSeekBarChangeListener { } R.id.actionToggleValues -> { - binding.chart1.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + binding.chart1.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } binding.chart1.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt b/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt index 3b910dd41..e5cd57ff6 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DataTools.kt @@ -176,7 +176,7 @@ class DataTools { ) { // create a dataset and give it a type val lineDataSet01 = LineDataSet(values, "DataSet 1") - lineDataSet01.setDrawIcons(false) + lineDataSet01.isDrawIcons = false // draw dashed line lineDataSet01.enableDashedLine(10f, 5f, 0f) @@ -186,7 +186,7 @@ class DataTools { lineDataSet01.setCircleColor(Color.BLACK) // line thickness and point size - lineDataSet01.lineWidth = 1f + lineDataSet01.setLineWidth(1f) lineDataSet01.circleRadius = 3f // draw points as solid circles @@ -194,7 +194,7 @@ class DataTools { // customize legend entry lineDataSet01.formLineWidth = 1f - lineDataSet01.setFormLineDashEffect(DashPathEffect(floatArrayOf(10f, 5f), 0f)) + lineDataSet01.formLineDashEffect = DashPathEffect(floatArrayOf(10f, 5f), 0f) lineDataSet01.formSize = 15f // text size of values @@ -215,9 +215,9 @@ class DataTools { if (getSDKInt() >= 18) { // drawables only supported on api level 18 and above val drawable = ContextCompat.getDrawable(context, R.drawable.fade_blue) - lineDataSet01.fillDrawable = drawable + lineDataSet01.setFillDrawable(drawable) } else { - lineDataSet01.fillColor = Color.BLACK + lineDataSet01.setFillColor(Color.BLACK) } val dataSets = ArrayList() dataSets.add(lineDataSet01) // add the data sets diff --git a/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt index b72aa9a55..e44eddcdc 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DrawChartActivity.kt @@ -62,7 +62,7 @@ class DrawChartActivity : DemoBase(), OnChartValueSelectedListener, OnDrawListen // create a dataset and give it a type (0) val set1 = LineDataSet(values, "DataSet") - set1.lineWidth = 3f + set1.setLineWidth(3f) set1.circleRadius = 5f // create a data object with the data sets @@ -79,8 +79,8 @@ class DrawChartActivity : DemoBase(), OnChartValueSelectedListener, OnDrawListen override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.actionToggleValues -> { - binding.chart1.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + binding.chart1.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } binding.chart1.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt index 59697db8c..0beccbf3d 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt @@ -61,11 +61,11 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { val lastDataSetIndex = data.getDataSetCount() - 1 // add data only to the last val lastSet = data.getDataSetByIndex(lastDataSetIndex) - val cycleValue = (lastSet.getEntryCount() % 100.0).toInt() + val cycleValue = (lastSet.entryCount % 100.0).toInt() val value = (sampleValues[cycleValue]!!.toFloat() * 50) + 50f * (lastDataSetIndex + 1) - data.addEntry(Entry(lastSet.getEntryCount().toFloat(), value), lastDataSetIndex) + data.addEntry(Entry(lastSet.entryCount.toFloat(), value), lastDataSetIndex) data.notifyDataChanged() // let the chart know it's data has changed @@ -85,7 +85,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { val set = data.getDataSetByIndex(0) if (set != null) { - val e = set.getEntryForXValue((set.getEntryCount() - 1).toFloat(), Float.NaN) + val e = set.getEntryForXValue((set.entryCount - 1).toFloat(), Float.NaN) data.removeEntry(e, 0) // or remove by index @@ -104,7 +104,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { chart!!.setData(LineData()) } else { val count = (data.getDataSetCount() + 1) - val amount = data.getDataSetByIndex(0).getEntryCount() + val amount = data.getDataSetByIndex(0).entryCount val values = ArrayList() @@ -120,11 +120,11 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { val color = colors[count % colors.size] - set.setColor(color) + set.color = color set.setCircleColor(color) set.setHighLightColor(color) set.valueTextSize = 10f - set.setValueTextColor(color) + set.setSingleValueTextColor(color) data.addDataSet(set) data.notifyDataChanged() @@ -148,7 +148,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { val set = LineDataSet(null, "DataSet 1") set.setLineWidth(2.5f) set.circleRadius = 4.5f - set.setColor(Color.rgb(240, 99, 99)) + set.color = Color.rgb(240, 99, 99) set.setCircleColor(Color.rgb(240, 99, 99)) set.setHighLightColor(Color.rgb(190, 190, 190)) set.axisDependency = AxisDependency.LEFT diff --git a/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt index 1c8f2c325..a0bb5b796 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/FilledLineActivity.kt @@ -54,8 +54,8 @@ class FilledLineActivity : DemoBase() { xAxis.isEnabled = false val leftAxis = binding.chart1.axisLeft - leftAxis.setAxisMaximum(900f) - leftAxis.setAxisMinimum(-250f) + leftAxis.axisMaximum = 900f + leftAxis.axisMinimum = -250f leftAxis.setDrawAxisLine(false) leftAxis.setDrawZeroLine(false) leftAxis.setDrawGridLines(false) @@ -101,11 +101,11 @@ class FilledLineActivity : DemoBase() { set1 = LineDataSet(valuesArray1, "DataSet 1") set1.axisDependency = YAxis.AxisDependency.LEFT - set1.setColor(Color.rgb(255, 241, 46)) + set1.color = Color.rgb(255, 241, 46) set1.setDrawCircles(false) set1.setLineWidth(2f) set1.circleRadius = 3f - set1.fillAlpha = 255 + set1.setFillAlpha(255) set1.setDrawFilled(true) set1.setFillColor(Color.WHITE) set1.setHighLightColor(Color.rgb(244, 117, 117)) @@ -121,11 +121,11 @@ class FilledLineActivity : DemoBase() { // create a dataset and give it a type set2 = LineDataSet(valuesArray2, "DataSet 2") set2.axisDependency = YAxis.AxisDependency.LEFT - set2.setColor(Color.rgb(255, 241, 46)) + set2.color = Color.rgb(255, 241, 46) set2.setDrawCircles(false) set2.setLineWidth(2f) set2.circleRadius = 3f - set2.fillAlpha = 255 + set2.setFillAlpha(255) set2.setDrawFilled(true) set2.setFillColor(Color.WHITE) set2.setDrawCircleHole(false) diff --git a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt index 25a8e6ea6..fa0ec6fcc 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarChartActivity.kt @@ -65,20 +65,20 @@ class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartV xl.typeface = tfLight xl.setDrawAxisLine(true) xl.setDrawGridLines(false) - xl.setGranularity(10f) + xl.granularity = 10f val yl = binding.chart1.axisLeft yl.typeface = tfLight yl.setDrawAxisLine(true) yl.setDrawGridLines(true) - yl.setAxisMinimum(0f) // this replaces setStartAtZero(true) + yl.axisMinimum = 0f // this replaces setStartAtZero(true) // yl.setInverted(true); val yr = binding.chart1.axisRight yr.typeface = tfLight yr.setDrawAxisLine(true) yr.setDrawGridLines(false) - yr.setAxisMinimum(0f) // this replaces setStartAtZero(true) + yr.axisMinimum = 0f // this replaces setStartAtZero(true) // yr.setInverted(true); binding.chart1.setFitBars(true) @@ -125,7 +125,7 @@ class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartV } else { set1 = BarDataSet(values, "DataSet 1") - set1.setDrawIcons(false) + set1.isDrawIcons = false val dataSets = ArrayList() dataSets.add(set1) @@ -153,8 +153,8 @@ class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartV } R.id.actionToggleValues -> { - binding.chart1.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + binding.chart1.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } binding.chart1.invalidate() } @@ -164,7 +164,7 @@ class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartV .dataSets for (iSet in sets) { - iSet.setDrawIcons(!iSet.isDrawIcons()) + iSet.isDrawIcons = !iSet.isDrawIcons } binding.chart1.invalidate() @@ -242,7 +242,7 @@ class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartV val position = binding.chart1.getPosition( entry, binding.chart1.data!!.getDataSetByIndex(highlight.dataSetIndex) - .getAxisDependency() + .axisDependency ) Timber.i(bounds.toString()) diff --git a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt index f7a911c1d..bbf03ba39 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt @@ -74,7 +74,7 @@ class HorizontalBarNegativeChartActivity : DemoBase(), OnSeekBarChangeListener, xl.typeface = tfLight xl.setDrawAxisLine(true) xl.setDrawGridLines(false) - xl.setGranularity(10f) + xl.granularity = 10f val yl = chart!!.axisLeft yl.typeface = tfLight @@ -132,7 +132,7 @@ class HorizontalBarNegativeChartActivity : DemoBase(), OnSeekBarChangeListener, } else { set1 = BarDataSet(values, "DataSet 1") - set1.setDrawIcons(false) + set1.isDrawIcons = false val dataSets = ArrayList() dataSets.add(set1) @@ -161,15 +161,14 @@ class HorizontalBarNegativeChartActivity : DemoBase(), OnSeekBarChangeListener, R.id.actionToggleValues -> { chart!!.data!!.dataSets.forEach { - it.setDrawValues(!it.isDrawValues()) + it.isDrawValues = !it.isDrawValues } - chart!!.invalidate() } R.id.actionToggleIcons -> { chart!!.data!!.dataSets.forEach { iSet -> - iSet.setDrawIcons(!iSet.isDrawIcons()) + iSet.isDrawIcons = !iSet.isDrawIcons } chart!!.invalidate() @@ -247,7 +246,7 @@ class HorizontalBarNegativeChartActivity : DemoBase(), OnSeekBarChangeListener, val position = chart!!.getPosition( entry, chart!!.data!!.getDataSetByIndex(highlight.dataSetIndex) - .getAxisDependency() + .axisDependency ) Timber.i("bounds $bounds") diff --git a/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt index d5ac319f5..8c3a5e8f7 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt @@ -73,11 +73,11 @@ class InvertedLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa val xl = chart!!.xAxis xl.setAvoidFirstLastClipping(true) - xl.setAxisMinimum(0f) + xl.axisMinimum = 0f val leftAxis = chart!!.axisLeft leftAxis.isInverted = true - leftAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + leftAxis.axisMinimum = 0f // this replaces setStartAtZero(true) val rightAxis = chart!!.axisRight rightAxis.isEnabled = false @@ -143,8 +143,8 @@ class InvertedLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { iSet -> - iSet.setDrawValues(!iSet.isDrawValues) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt index 12696e307..b22287dd1 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivity.kt @@ -155,14 +155,14 @@ class LineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelec R.id.actionToggleValues -> { binding.chart1.data?.dataSets?.forEach { set -> - set.setDrawValues(!set.isDrawValues) + set.isDrawValues = !set.isDrawValues } binding.chart1.invalidate() } R.id.actionToggleIcons -> { binding.chart1.data?.dataSets?.forEach { set -> - set.setDrawIcons(!set.isDrawIcons) + set.isDrawIcons = !set.isDrawIcons binding.chart1.invalidate() } } @@ -259,8 +259,8 @@ class LineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelec override fun onStopTrackingTouch(seekBar: SeekBar) {} override fun onValueSelected(entry: Entry, highlight: Highlight) { Timber.i(entry.toString()) - Timber.i("LOW HIGH low: ${binding.chart1.lowestVisibleX}, high: ${binding.chart1.highestVisibleX}") - Timber.i("MIN MAX xMin: ${binding.chart1.xChartMin}, xMax: ${binding.chart1.xChartMax}, yMin: ${binding.chart1.yChartMin}, yMax: ${binding.chart1.yChartMax}") + Timber.i("LOW HIGH low:${binding.chart1.lowestVisibleX}, high:${binding.chart1.highestVisibleX}") + Timber.i("MIN MAX xMin:${binding.chart1.xChartMin}, xMax:${binding.chart1.xChartMax}, yMin:${binding.chart1.yChartMin}, yMax:${binding.chart1.yChartMax}") } override fun onNothingSelected() = Unit diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt index b82ec807b..66b84d351 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartActivityColored.kt @@ -108,10 +108,10 @@ class LineChartActivityColored : DemoBase() { set1.setLineWidth(1.75f) set1.circleRadius = 5f set1.circleHoleRadius = 2.5f - set1.setColor(Color.WHITE) + set1.color = Color.WHITE set1.setCircleColor(Color.WHITE) set1.setHighLightColor(Color.WHITE) - set1.setDrawValues(false) + set1.isDrawValues = false // create a data object with the data sets return LineData(set1) diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt index c283d62db..c84127501 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt @@ -105,16 +105,16 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa val leftAxis = chart!!.axisLeft leftAxis.typeface = tfLight leftAxis.textColor = ColorTemplate.getHoloBlue() - leftAxis.setAxisMaximum(200f) - leftAxis.setAxisMinimum(0f) + leftAxis.axisMaximum = 200f + leftAxis.axisMinimum = 0f leftAxis.setDrawGridLines(true) leftAxis.isGranularityEnabled = true val rightAxis = chart!!.axisRight rightAxis.typeface = tfLight rightAxis.textColor = Color.MAGENTA - rightAxis.setAxisMaximum(900f) - rightAxis.setAxisMinimum(-200f) + rightAxis.axisMaximum = 900f + rightAxis.axisMinimum = -200f rightAxis.setDrawGridLines(false) rightAxis.setDrawZeroLine(false) rightAxis.isGranularityEnabled = false @@ -163,11 +163,11 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa set1 = LineDataSet(values1, "DataSet 1") set1.axisDependency = AxisDependency.LEFT - set1.setColor(ColorTemplate.getHoloBlue()) + set1.color = ColorTemplate.getHoloBlue() set1.setCircleColor(Color.WHITE) set1.setLineWidth(2f) set1.circleRadius = 3f - set1.fillAlpha = 65 + set1.setFillAlpha(65) set1.setFillColor(ColorTemplate.getHoloBlue()) set1.setHighLightColor(Color.rgb(244, 117, 117)) set1.setDrawCircleHole(false) @@ -180,11 +180,11 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa // create a dataset and give it a type set2 = LineDataSet(values2, "DataSet 2") set2.axisDependency = AxisDependency.RIGHT - set2.setColor(Color.MAGENTA) + set2.color = Color.MAGENTA set2.setCircleColor(Color.WHITE) set2.setLineWidth(2f) set2.circleRadius = 3f - set2.fillAlpha = 65 + set2.setFillAlpha(65) set2.setFillColor(Color.BLUE) set2.setDrawCircleHole(false) set2.setHighLightColor(Color.rgb(244, 117, 117)) @@ -192,11 +192,11 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa //set2.setFillFormatter(new MyFillFormatter(900f)); set3 = LineDataSet(values3, "DataSet 3") set3.axisDependency = AxisDependency.RIGHT - set3.setColor(Color.YELLOW) + set3.color = Color.YELLOW set3.setCircleColor(Color.WHITE) set3.setLineWidth(2f) set3.circleRadius = 3f - set3.fillAlpha = 65 + set3.setFillAlpha(65) set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200)) set3.setDrawCircleHole(false) set3.setHighLightColor(Color.rgb(244, 117, 117)) @@ -227,7 +227,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa R.id.actionToggleValues -> { chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues) + set.isDrawValues = !set.isDrawValues } chart!!.invalidate() } @@ -348,7 +348,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa chart!!.centerViewToAnimated( entry.x, entry.y, chart!!.data!!.getDataSetByIndex(highlight.dataSetIndex) - .getAxisDependency(), 500 + .axisDependency, 500 ) //chart.zoomAndCenterAnimated(2.5f, 2.5f, e.getX(), e.getY(), chart.getData().getDataSetByIndex(dataSetIndex) // .getAxisDependency(), 1000); diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt index b4f9f3117..84c1c194c 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt @@ -13,7 +13,6 @@ import android.widget.TextView import androidx.core.content.ContextCompat import androidx.core.net.toUri import com.github.mikephil.charting.charts.LineChart -import com.github.mikephil.charting.components.AxisBase import com.github.mikephil.charting.components.XAxis import com.github.mikephil.charting.components.YAxis import com.github.mikephil.charting.components.YAxis.AxisDependency @@ -28,6 +27,7 @@ import java.text.SimpleDateFormat import java.util.Date import java.util.Locale import java.util.concurrent.TimeUnit +import com.github.mikephil.charting.components.AxisBase import kotlin.math.roundToInt class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { @@ -79,7 +79,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { xAxis.setDrawGridLines(true) xAxis.textColor = Color.rgb(255, 192, 56) xAxis.setCenterAxisLabels(true) - xAxis.setGranularity(1f) // one hour + xAxis.granularity = 1f // one hour xAxis.valueFormatter = object : IAxisValueFormatter { private val mFormat = SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH) @@ -95,8 +95,8 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { leftAxis.textColor = ColorTemplate.getHoloBlue() leftAxis.setDrawGridLines(true) leftAxis.isGranularityEnabled = true - leftAxis.setAxisMinimum(0f) - leftAxis.setAxisMaximum(170f) + leftAxis.axisMinimum = 0f + leftAxis.axisMaximum = 170f leftAxis.yOffset = -9f leftAxis.textColor = Color.rgb(255, 192, 56) @@ -130,12 +130,12 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { // create a dataset and give it a type val set1 = LineDataSet(values, "DataSet 1") set1.axisDependency = AxisDependency.LEFT - set1.setColor(ColorTemplate.getHoloBlue()) - set1.setValueTextColor(ColorTemplate.getHoloBlue()) + set1.color = ColorTemplate.getHoloBlue() + set1.setSingleValueTextColor(ColorTemplate.getHoloBlue()) set1.setLineWidth(1.5f) set1.setDrawCircles(false) - set1.setDrawValues(false) - set1.fillAlpha = 65 + set1.isDrawValues = false + set1.setFillAlpha(65) set1.setFillColor(ColorTemplate.getHoloBlue()) set1.setHighLightColor(Color.rgb(244, 117, 117)) set1.setDrawCircleHole(false) @@ -165,7 +165,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { R.id.actionToggleValues -> { chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues) + set.isDrawValues = !set.isDrawValues } chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt index ad7e25ee7..bed10a705 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt @@ -92,7 +92,7 @@ class ListViewMultiChartActivity : DemoBase() { d1.setLineWidth(2.5f) d1.circleRadius = 4.5f d1.setHighLightColor(Color.rgb(244, 117, 117)) - d1.setDrawValues(false) + d1.isDrawValues = false val values2 = ArrayList() @@ -104,9 +104,9 @@ class ListViewMultiChartActivity : DemoBase() { d2.setLineWidth(2.5f) d2.circleRadius = 4.5f d2.setHighLightColor(Color.rgb(244, 117, 117)) - d2.setColor(ColorTemplate.VORDIPLOM_COLORS[0]) + d2.color = ColorTemplate.VORDIPLOM_COLORS[0] d2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]) - d2.setDrawValues(false) + d2.isDrawValues = false val sets = ArrayList() sets.add(d1) diff --git a/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt index 55000ecd4..60c6dcf18 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/MultiLineChartActivity.kt @@ -100,7 +100,7 @@ class MultiLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartGestu lineDataSet.circleRadius = 4f val color = colors[datasetNumber % colors.size] - lineDataSet.setColor(color) + lineDataSet.color = color lineDataSet.setCircleColor(color) dataSets.add(lineDataSet) } @@ -132,7 +132,7 @@ class MultiLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartGestu R.id.actionToggleValues -> { binding.chart1.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues) + set.isDrawValues = !set.isDrawValues } binding.chart1.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt b/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt index e7e67eeb2..9e25a8804 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt @@ -68,9 +68,9 @@ class PerformanceLineChart : DemoBase(), OnSeekBarChangeListener { // create a dataset and give it a type val set1 = LineDataSet(values, "DataSet 1") - set1.setColor(Color.BLACK) + set1.color = Color.BLACK set1.setLineWidth(0.5f) - set1.setDrawValues(false) + set1.isDrawValues = false set1.setDrawCircles(false) set1.lineMode = LineDataSet.Mode.LINEAR set1.setDrawFilled(false) diff --git a/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt index 5daa7a6f1..0335813fe 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt @@ -125,10 +125,10 @@ class PieChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect val dataSet = PieDataSet(entries, "Election Results") - dataSet.setDrawIcons(false) + dataSet.isDrawIcons = false dataSet.setSliceSpace(3f) - dataSet.setIconsOffset(MPPointF(0f, 40f)) + dataSet.iconsOffset = MPPointF(0f, 40f) dataSet.selectionShift = 5f // add a lot of colors @@ -177,14 +177,15 @@ class PieChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } chart!!.invalidate() } R.id.actionToggleIcons -> { - for (set in chart!!.data!!.getDataSets()) set.setDrawIcons(!set.isDrawIcons()) + for (set in chart!!.data!!.getDataSets()) + set.isDrawIcons = !set.isDrawIcons chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt index 1ac4fb936..80709c717 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt @@ -127,10 +127,10 @@ class PieChartRoundedActivity : DemoBase(), OnSeekBarChangeListener, OnChartValu val dataSet = PieDataSet(entries, "Election Results") - dataSet.setDrawIcons(false) + dataSet.isDrawIcons = false dataSet.setSliceSpace(3f) - dataSet.setIconsOffset(MPPointF(0f, 40f)) + dataSet.iconsOffset = MPPointF(0f, 40f) dataSet.selectionShift = 5f // add a lot of colors @@ -182,14 +182,15 @@ class PieChartRoundedActivity : DemoBase(), OnSeekBarChangeListener, OnChartValu } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } chart!!.invalidate() } R.id.actionToggleIcons -> { - for (set in chart!!.data!!.getDataSets()) set.setDrawIcons(!set.isDrawIcons()) + for (set in chart!!.data!!.getDataSets()) + set.isDrawIcons = !set.isDrawIcons chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt index 84f3d9682..a9d1b1fae 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt @@ -171,8 +171,8 @@ class PiePolylineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVal } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt index b63e6c7e1..a5f5d25e6 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt @@ -69,8 +69,8 @@ class RadarChartActivity : DemoBase() { yAxis.typeface = tfLight yAxis.setLabelCount(5, false) yAxis.textSize = 9f - yAxis.setAxisMinimum(0f) - yAxis.setAxisMaximum(80f) + yAxis.axisMinimum = 0f + yAxis.axisMaximum = 80f yAxis.setDrawLabels(false) val l = chart!!.legend @@ -104,19 +104,19 @@ class RadarChartActivity : DemoBase() { } val set1 = RadarDataSet(entries1, "Last Week") - set1.setColor(Color.rgb(103, 110, 129)) + set1.color = Color.rgb(103, 110, 129) set1.setFillColor(Color.rgb(103, 110, 129)) set1.setDrawFilled(true) - set1.fillAlpha = 180 + set1.setFillAlpha(180) set1.setLineWidth(2f) set1.isDrawHighlightCircleEnabled = true set1.setDrawHighlightIndicators(false) val set2 = RadarDataSet(entries2, "This Week") - set2.setColor(Color.rgb(121, 162, 175)) + set2.color = Color.rgb(121, 162, 175) set2.setFillColor(Color.rgb(121, 162, 175)) set2.setDrawFilled(true) - set2.fillAlpha = 180 + set2.setFillAlpha(180) set2.setLineWidth(2f) set2.isDrawHighlightCircleEnabled = true set2.setDrawHighlightIndicators(false) @@ -156,9 +156,10 @@ class RadarChartActivity : DemoBase() { } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } + chart!!.invalidate() } @@ -176,7 +177,7 @@ class RadarChartActivity : DemoBase() { R.id.actionToggleFilled -> { chart!!.data!!.dataSets.forEach { set -> - set.setDrawFilled(!set.isDrawFilledEnabled()) + set.setDrawFilled(!set.isDrawFilledEnabled) } chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt index 7ecaa1583..dcbbbe1a0 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt @@ -75,8 +75,8 @@ class RealtimeLineChartActivity : DemoBase(), OnChartValueSelectedListener { val leftAxis = chart!!.axisLeft leftAxis.typeface = tfLight leftAxis.textColor = Color.WHITE - leftAxis.setAxisMaximum(100f) - leftAxis.setAxisMinimum(0f) + leftAxis.axisMaximum = 100f + leftAxis.axisMinimum = 0f leftAxis.setDrawGridLines(true) val rightAxis = chart!!.axisRight @@ -95,8 +95,8 @@ class RealtimeLineChartActivity : DemoBase(), OnChartValueSelectedListener { data.addDataSet(set) } - val cycleValue = (set.getEntryCount() % 100.0).toInt() - data.addEntry(Entry(set.getEntryCount().toFloat(), (sampleValues[cycleValue]!!.toFloat() * 40) + 30f), 0) + val cycleValue = (set.entryCount % 100.0).toInt() + data.addEntry(Entry(set.entryCount.toFloat(), (sampleValues[cycleValue]!!.toFloat() * 40) + 30f), 0) data.notifyDataChanged() // let the chart know it's data has changed @@ -119,14 +119,14 @@ class RealtimeLineChartActivity : DemoBase(), OnChartValueSelectedListener { private fun createSet(): LineDataSet { val set = LineDataSet(null, "Dynamic Data") set.axisDependency = AxisDependency.LEFT - set.setColor(ColorTemplate.getHoloBlue()) + set.color = ColorTemplate.getHoloBlue() set.setCircleColor(Color.WHITE) set.setLineWidth(2f) set.circleRadius = 4f - set.fillAlpha = 65 + set.setFillAlpha(65) set.setFillColor(ColorTemplate.getHoloBlue()) set.setHighLightColor(Color.rgb(244, 117, 117)) - set.setValueTextColor(Color.WHITE) + set.setSingleValueTextColor(Color.WHITE) set.valueTextSize = 9f set.isDrawValues = false return set diff --git a/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt index 9fdb34292..5b14544c5 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt @@ -73,7 +73,7 @@ class ScatterChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSe val yl = chart!!.axisLeft yl.typeface = tfLight - yl.setAxisMinimum(0f) // this replaces setStartAtZero(true) + yl.axisMinimum = 0f // this replaces setStartAtZero(true) chart!!.axisRight.isEnabled = false @@ -109,15 +109,15 @@ class ScatterChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSe // create a dataset and give it a type val set1 = ScatterDataSet(values1, "DS 1") set1.setScatterShape(ScatterChart.ScatterShape.SQUARE) - set1.setColor(ColorTemplate.COLORFUL_COLORS[0]) + set1.color = ColorTemplate.COLORFUL_COLORS[0] val set2 = ScatterDataSet(values2, "DS 2") set2.setScatterShape(ScatterChart.ScatterShape.CIRCLE) set2.scatterShapeHoleColor = ColorTemplate.COLORFUL_COLORS[3] set2.scatterShapeHoleRadius = 3f - set2.setColor(ColorTemplate.COLORFUL_COLORS[1]) + set2.color = ColorTemplate.COLORFUL_COLORS[1] val set3 = ScatterDataSet(values3, "DS 3") set3.shapeRenderer = CustomScatterShapeRenderer() - set3.setColor(ColorTemplate.COLORFUL_COLORS[2]) + set3.color = ColorTemplate.COLORFUL_COLORS[2] set1.scatterShapeSize = 8f set2.scatterShapeSize = 8f @@ -151,7 +151,7 @@ class ScatterChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSe R.id.actionToggleValues -> { chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues) + set.isDrawValues = !set.isDrawValues } chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt index a4abe359a..b928f6b85 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/SpecificPositionsLineChartActivity.kt @@ -138,8 +138,8 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.actionToggleValues -> { - mChart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + mChart!!.data?.dataSets?.forEach { + it.isDrawValues = !it.isDrawValues } mChart!!.invalidate() } @@ -264,20 +264,20 @@ class SpecificPositionsLineChartActivity : DemoBase(), OnSeekBarChangeListener, set11.enableDashedHighlightLine(10f, 5f, 0f) set11.color = Color.BLACK set11.setCircleColor(Color.BLACK) - set11.lineWidth = 1f + set11.setLineWidth(1f) set11.circleRadius = 3f set11.setDrawCircleHole(false) set11.valueTextSize = 9f set11.setDrawFilled(true) set11.formLineWidth = 1f - set11.setFormLineDashEffect(DashPathEffect(floatArrayOf(10f, 5f), 0f)) + set11.formLineDashEffect = DashPathEffect(floatArrayOf(10f, 5f), 0f) set11.formSize = 15f if (getSDKInt() >= 18) { // fill drawable only supported on api level 18 and above val drawable = ContextCompat.getDrawable(this, R.drawable.fade_blue) - set11.fillDrawable = drawable + set11.setFillDrawable(drawable) } else { - set11.fillColor = Color.BLACK + set11.setFillColor(Color.BLACK) } val dataSets = ArrayList() dataSets.add(set11) // add the datasets diff --git a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt index d7a26de15..e883cb741 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt @@ -71,7 +71,7 @@ class StackedBarActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSele // change the position of the y-labels val leftAxis = chart!!.axisLeft leftAxis.valueFormatter = MyAxisValueFormatter() - leftAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + leftAxis.axisMinimum = 0f // this replaces setStartAtZero(true) chart!!.axisRight.isEnabled = false val xLabels = chart!!.xAxis @@ -128,7 +128,7 @@ class StackedBarActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSele chart!!.notifyDataSetChanged() } else { set1 = BarDataSet(values, "Statistics Vienna 2014") - set1.setDrawIcons(false) + set1.isDrawIcons = false set1.setColors(*this.colors) set1.stackLabels = arrayOf("Births", "Divorces", "Marriages") @@ -160,15 +160,15 @@ class StackedBarActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSele } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } chart!!.invalidate() } R.id.actionToggleIcons -> { chart!!.data!!.dataSets.forEach { set -> - set.setDrawIcons(!set.isDrawIcons) + set.isDrawIcons = !set.isDrawIcons } chart!!.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt index 0abce05f3..bdf5500cf 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt @@ -49,8 +49,8 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { chart!!.isHighlightFullBarEnabled = false chart!!.axisLeft.isEnabled = false - chart!!.axisRight.setAxisMaximum(25f) - chart!!.axisRight.setAxisMinimum(-25f) + chart!!.axisRight.axisMaximum = 25f + chart!!.axisRight.axisMinimum = -25f chart!!.axisRight.setDrawGridLines(false) chart!!.axisRight.setDrawZeroLine(true) chart!!.axisRight.setLabelCount(7, false) @@ -62,11 +62,11 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { xAxis.setDrawGridLines(false) xAxis.setDrawAxisLine(false) xAxis.textSize = 9f - xAxis.setAxisMinimum(0f) - xAxis.setAxisMaximum(110f) + xAxis.axisMinimum = 0f + xAxis.axisMaximum = 110f xAxis.setCenterAxisLabels(true) - xAxis.setLabelCount(12) - xAxis.setGranularity(10f) + xAxis.labelCount = 12 + xAxis.granularity = 10f xAxis.valueFormatter = object : IAxisValueFormatter { private val format = DecimalFormat("###") @@ -100,8 +100,8 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { values.add(BarEntry(105f, floatArrayOf(-1f, 2f))) val set = BarDataSet(values, "Age Distribution") - set.setDrawIcons(false) - set.setValueFormatter(CustomFormatter()) + set.isDrawIcons = false + set.valueFormatter = CustomFormatter() set.valueTextSize = 7f set.axisDependency = YAxis.AxisDependency.RIGHT set.setColors(Color.rgb(67, 67, 72), Color.rgb(124, 181, 236)) @@ -128,15 +128,15 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { } R.id.actionToggleValues -> { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } chart!!.invalidate() } R.id.actionToggleIcons -> { chart!!.data!!.dataSets.forEach { set -> - set.setDrawIcons(!set.isDrawIcons) + set.isDrawIcons = !set.isDrawIcons } chart!!.invalidate() diff --git a/app/src/main/kotlin/info/appdev/chartexample/compose/HorizontalBarComposeActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/compose/HorizontalBarComposeActivity.kt index 8630a41b7..3c85915bc 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/compose/HorizontalBarComposeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/compose/HorizontalBarComposeActivity.kt @@ -359,7 +359,7 @@ class HorizontalBarComposeActivity : DemoBaseCompose() { localChart.notifyDataSetChanged() } else { set1 = BarDataSet(values, "DataSet 1") - set1.setDrawIcons(false) + set1.isDrawIcons = false val dataSets = ArrayList() dataSets.add(set1) @@ -377,8 +377,8 @@ class HorizontalBarComposeActivity : DemoBaseCompose() { private fun toggleValues() { chart?.let { - chart!!.data!!.dataSets.forEach { set -> - set.setDrawValues(!set.isDrawValues()) + chart!!.data!!.dataSets.forEach { + it.isDrawValues = !it.isDrawValues } it.invalidate() } @@ -388,7 +388,7 @@ class HorizontalBarComposeActivity : DemoBaseCompose() { chart?.let { val sets = it.data?.dataSets ?: return for (iSet in sets) { - iSet.setDrawIcons(!iSet.isDrawIcons) + iSet.isDrawIcons = !iSet.isDrawIcons } it.invalidate() } diff --git a/app/src/main/kotlin/info/appdev/chartexample/fragments/BarChartFrag.kt b/app/src/main/kotlin/info/appdev/chartexample/fragments/BarChartFrag.kt index b27b03e8d..67e7cfa73 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/fragments/BarChartFrag.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/fragments/BarChartFrag.kt @@ -42,7 +42,7 @@ class BarChartFrag : SimpleFragment(), OnChartGestureListener { val leftAxis = chart!!.axisLeft leftAxis.typeface = tf - leftAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + leftAxis.axisMinimum = 0f // this replaces setStartAtZero(true) chart!!.axisRight.isEnabled = false diff --git a/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt b/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt index 87d5728b6..740880e69 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/fragments/SimpleFragment.kt @@ -99,7 +99,7 @@ abstract class SimpleFragment : Fragment() { val ds1 = PieDataSet(entries1, "Quarterly Revenues 2015") ds1.setColors(*ColorTemplate.VORDIPLOM_COLORS) ds1.setSliceSpace(2f) - ds1.setValueTextColor(Color.WHITE) + ds1.setSingleValueTextColor(Color.WHITE) ds1.valueTextSize = 12f val d = PieData(ds1) @@ -119,8 +119,8 @@ abstract class SimpleFragment : Fragment() { ds1.setDrawCircles(false) ds2.setDrawCircles(false) - ds1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]) - ds2.setColor(ColorTemplate.VORDIPLOM_COLORS[1]) + ds1.color = ColorTemplate.VORDIPLOM_COLORS[0] + ds2.color = ColorTemplate.VORDIPLOM_COLORS[1] // load DataSets from files in assets folder sets.add(ds1) @@ -144,10 +144,10 @@ abstract class SimpleFragment : Fragment() { val ds4 = LineDataSet(FileUtils.loadEntriesFromAssets(requireContext().assets, "three.txt"), "O(n\u00B3)") - ds1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]) - ds2.setColor(ColorTemplate.VORDIPLOM_COLORS[1]) - ds3.setColor(ColorTemplate.VORDIPLOM_COLORS[2]) - ds4.setColor(ColorTemplate.VORDIPLOM_COLORS[3]) + ds1.color = ColorTemplate.VORDIPLOM_COLORS[0] + ds2.color = ColorTemplate.VORDIPLOM_COLORS[1] + ds3.color = ColorTemplate.VORDIPLOM_COLORS[2] + ds4.color = ColorTemplate.VORDIPLOM_COLORS[3] ds1.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]) ds2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[1]) diff --git a/app/src/main/kotlin/info/appdev/chartexample/fragments/SineCosineFragment.kt b/app/src/main/kotlin/info/appdev/chartexample/fragments/SineCosineFragment.kt index 98064fa25..3ef3f7bb6 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/fragments/SineCosineFragment.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/fragments/SineCosineFragment.kt @@ -31,8 +31,8 @@ class SineCosineFragment : SimpleFragment() { val leftAxis = chart!!.axisLeft leftAxis.typeface = tf - leftAxis.setAxisMaximum(1.2f) - leftAxis.setAxisMinimum(-1.2f) + leftAxis.axisMaximum = 1.2f + leftAxis.axisMinimum = -1.2f chart!!.axisRight.isEnabled = false diff --git a/app/src/main/kotlin/info/appdev/chartexample/listviewitems/BarChartItem.kt b/app/src/main/kotlin/info/appdev/chartexample/listviewitems/BarChartItem.kt index 675b03336..2e0811c17 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/listviewitems/BarChartItem.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/listviewitems/BarChartItem.kt @@ -50,13 +50,13 @@ class BarChartItem(cd: ChartData<*>, c: Context) : ChartItem(cd) { leftAxis.typeface = typeface leftAxis.setLabelCount(5, false) leftAxis.spaceTop = 20f - leftAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + leftAxis.axisMinimum = 0f // this replaces setStartAtZero(true) val rightAxis = holder.chart!!.axisRight rightAxis.typeface = typeface rightAxis.setLabelCount(5, false) rightAxis.spaceTop = 20f - rightAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + rightAxis.axisMinimum = 0f // this replaces setStartAtZero(true) chartData.setValueTypeface(typeface) diff --git a/app/src/main/kotlin/info/appdev/chartexample/listviewitems/LineChartItem.kt b/app/src/main/kotlin/info/appdev/chartexample/listviewitems/LineChartItem.kt index 2ed37997e..74a71fa04 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/listviewitems/LineChartItem.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/listviewitems/LineChartItem.kt @@ -49,13 +49,13 @@ class LineChartItem(cd: ChartData<*>, c: Context) : ChartItem(cd) { val leftAxis = holder.chart!!.axisLeft leftAxis.typeface = typeface leftAxis.setLabelCount(5, false) - leftAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + leftAxis.axisMinimum = 0f // this replaces setStartAtZero(true) val rightAxis = holder.chart!!.axisRight rightAxis.typeface = typeface rightAxis.setLabelCount(5, false) rightAxis.setDrawGridLines(false) - rightAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true) + rightAxis.axisMinimum = 0f // this replaces setStartAtZero(true) // set data holder.chart!!.setData(chartData as LineData?)