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 deleted file mode 100644 index 7948969921..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitLine.java +++ /dev/null @@ -1,187 +0,0 @@ - -package com.github.mikephil.charting.components; - -import android.graphics.Color; -import android.graphics.DashPathEffect; -import android.graphics.Paint; -import com.github.mikephil.charting.utils.UtilsKtKt; - -/** - * The limit line is an additional feature for all Line-, Bar- and - * ScatterCharts. It allows the displaying of an additional line in the chart - * that marks a certain maximum / limit on the specified axis (x- or y-axis). - * - * @author Philipp Jahoda - */ -public class LimitLine extends ComponentBase { - - /** limit / maximum (the y-value or xIndex) */ - private final float mLimit; - - /** the width of the limit line */ - private float mLineWidth = 2f; - - /** the color of the limit line */ - private int mLineColor = Color.rgb(237, 91, 91); - - /** the style of the label text */ - private Paint.Style mTextStyle = Paint.Style.FILL_AND_STROKE; - - /** label string that is drawn next to the limit line */ - private String mLabel = ""; - - /** the path effect of this LimitLine that makes dashed lines possible */ - private DashPathEffect mDashPathEffect = null; - - /** indicates the position of the LimitLine label */ - private LimitLabelPosition mLabelPosition = LimitLabelPosition.RIGHT_TOP; - - /** enum that indicates the position of the LimitLine label */ - public enum LimitLabelPosition { - LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM - } - - /** - * Constructor with limit. - * - * @param limit - the position (the value) on the y-axis (y-value) or x-axis - * (xIndex) where this line should appear - */ - public LimitLine(float limit) { - mLimit = limit; - } - - /** - * Constructor with limit and label. - * - * @param limit - the position (the value) on the y-axis (y-value) or x-axis - * (xIndex) where this line should appear - * @param label - provide "" if no label is required - */ - public LimitLine(float limit, String label) { - mLimit = limit; - mLabel = label; - } - - /** - * Returns the limit that is set for this line. - */ - public float getLimit() { - return mLimit; - } - - /** - * set the line width of the chart (min = 0.2f, max = 12f); default 2f NOTE: - * thinner line == better performance, thicker line == worse performance - */ - public void setLineWidth(float width) { - - if (width < 0.2f) - width = 0.2f; - if (width > 12.0f) - width = 12.0f; - mLineWidth = UtilsKtKt.convertDpToPixel(width); - } - - /** - * returns the width of limit line - */ - public float getLineWidth() { - return mLineWidth; - } - - /** - * Sets the linecolor for this LimitLine. Make sure to use - * getResources().getColor(...) - */ - public void setLineColor(int color) { - mLineColor = color; - } - - /** - * Returns the color that is used for this LimitLine - */ - public int getLineColor() { - return mLineColor; - } - - /** - * Enables the line to be drawn in dashed mode, e.g. like this "- - - - - -" - * - * @param lineLength the length of the line pieces - * @param spaceLength the length of space inbetween the pieces - * @param phase offset, in degrees (normally, use 0) - */ - public void enableDashedLine(float lineLength, float spaceLength, float phase) { - mDashPathEffect = new DashPathEffect(new float[] { - lineLength, spaceLength - }, phase); - } - - /** - * Disables the line to be drawn in dashed mode. - */ - public void disableDashedLine() { - mDashPathEffect = null; - } - - /** - * Returns true if the dashed-line effect is enabled, false if not. Default: - * disabled - */ - public boolean isDashedLineEnabled() { - return mDashPathEffect != null; - } - - /** - * returns the DashPathEffect that is set for this LimitLine - */ - public DashPathEffect getDashPathEffect() { - return mDashPathEffect; - } - - /** - * Sets the color of the value-text that is drawn next to the LimitLine. - * Default: Paint.Style.FILL_AND_STROKE - */ - public void setTextStyle(Paint.Style style) { - this.mTextStyle = style; - } - - /** - * Returns the color of the value-text that is drawn next to the LimitLine. - */ - public Paint.Style getTextStyle() { - return mTextStyle; - } - - /** - * Sets the position of the LimitLine value label (either on the right or on - * the left edge of the chart). Not supported for RadarChart. - */ - public void setLabelPosition(LimitLabelPosition pos) { - mLabelPosition = pos; - } - - /** - * Returns the position of the LimitLine label (value). - */ - public LimitLabelPosition getLabelPosition() { - return mLabelPosition; - } - - /** - * Sets the label that is drawn next to the limit line. Provide "" if no - * label is required. - */ - public void setLabel(String label) { - mLabel = label; - } - - /** - * Returns the label that is drawn next to the limit line. - */ - public String getLabel() { - return mLabel; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitLine.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitLine.kt new file mode 100644 index 0000000000..7619bd2cb2 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitLine.kt @@ -0,0 +1,141 @@ +package com.github.mikephil.charting.components + +import android.graphics.Color +import android.graphics.DashPathEffect +import android.graphics.Paint +import com.github.mikephil.charting.utils.convertDpToPixel + +/** + * The limit line is an additional feature for all Line-, Bar- and + * ScatterCharts. It allows the displaying of an additional line in the chart + * that marks a certain maximum / limit on the specified axis (x- or y-axis). + */ +class LimitLine : ComponentBase { + /** + * Returns the limit that is set for this line. + */ + /** limit / maximum (the y-value or xIndex) */ + val limit: Float + + /** the width of the limit line */ + private var mLineWidth = 2f + + /** + * Returns the color that is used for this LimitLine + */ + /** + * Sets the linecolor for this LimitLine. Make sure to use + * getResources().getColor(...) + */ + /** the color of the limit line */ + var lineColor: Int = Color.rgb(237, 91, 91) + + /** + * Returns the color of the value-text that is drawn next to the LimitLine. + */ + /** + * Sets the color of the value-text that is drawn next to the LimitLine. + * Default: Paint.Style.FILL_AND_STROKE + */ + /** the style of the label text */ + var textStyle: Paint.Style? = Paint.Style.FILL_AND_STROKE + + /** + * Returns the label that is drawn next to the limit line. + */ + /** + * Sets the label that is drawn next to the limit line. Provide "" if no + * label is required. + */ + /** label string that is drawn next to the limit line */ + var label: String? = "" + + /** + * returns the DashPathEffect that is set for this LimitLine + */ + /** the path effect of this LimitLine that makes dashed lines possible */ + var dashPathEffect: DashPathEffect? = null + private set + + /** + * Returns the position of the LimitLine label (value). + */ + /** + * Sets the position of the LimitLine value label (either on the right or on + * the left edge of the chart). Not supported for RadarChart. + */ + /** indicates the position of the LimitLine label */ + var labelPosition: LimitLabelPosition? = LimitLabelPosition.RIGHT_TOP + + /** enum that indicates the position of the LimitLine label */ + enum class LimitLabelPosition { + LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM + } + + /** + * Constructor with limit. + * + * @param limit - the position (the value) on the y-axis (y-value) or x-axis + * (xIndex) where this line should appear + */ + constructor(limit: Float) { + this.limit = limit + } + + /** + * Constructor with limit and label. + * + * @param limit - the position (the value) on the y-axis (y-value) or x-axis + * (xIndex) where this line should appear + * @param label - provide "" if no label is required + */ + constructor(limit: Float, label: String?) { + this.limit = limit + this.label = label + } + + var lineWidth: Float + /** + * returns the width of limit line + */ + get() = mLineWidth + /** + * set the line width of the chart (min = 0.2f, max = 12f); default 2f NOTE: + * thinner line == better performance, thicker line == worse performance + */ + set(width) { + var width = width + if (width < 0.2f) width = 0.2f + if (width > 12.0f) width = 12.0f + mLineWidth = width.convertDpToPixel() + } + + /** + * Enables the line to be drawn in dashed mode, e.g. like this "- - - - - -" + * + * @param lineLength the length of the line pieces + * @param spaceLength the length of space inbetween the pieces + * @param phase offset, in degrees (normally, use 0) + */ + fun enableDashedLine(lineLength: Float, spaceLength: Float, phase: Float) { + this.dashPathEffect = DashPathEffect( + floatArrayOf( + lineLength, spaceLength + ), phase + ) + } + + /** + * Disables the line to be drawn in dashed mode. + */ + fun disableDashedLine() { + this.dashPathEffect = null + } + + val isDashedLineEnabled: Boolean + /** + * Returns true if the dashed-line effect is enabled, false if not. Default: + * disabled + */ + get() = this.dashPathEffect != 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 deleted file mode 100644 index 55a98a3cc0..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitRange.java +++ /dev/null @@ -1,239 +0,0 @@ - -package com.github.mikephil.charting.components; - -import android.graphics.Color; -import android.graphics.DashPathEffect; -import android.graphics.Paint; -import com.github.mikephil.charting.utils.UtilsKtKt; - -/** - * The limit line is an additional feature for all Line-, Bar- and - * ScatterCharts. It allows the displaying of an additional line in the chart - * that marks a certain maximum / limit on the specified axis (x- or y-axis). - */ -public class LimitRange extends ComponentBase { - - public static class Range { - private final float mLow; - private final float mHigh; - - Range(float r1, float r2) { - if (r1 < r2) { - mLow = r1; - mHigh = r2; - } else { - mLow = r2; - mHigh = r1; - } - } - - public float getLow() { - return mLow; - } - - public float getHigh() { - return mHigh; - } - } - - /** - * limit / maximum (the y-value or xIndex) - */ - private final Range mLimit; - - /** - * the width of the limit line - */ - private float mLineWidth = 0f; - - /** - * the color of the limit line - */ - private int mLineColor = Color.rgb(237, 91, 91); - - /** - * the color of the Range - */ - private int mRangeColor = Color.rgb(128, 128, 128); - - /** - * the style of the label text - */ - private Paint.Style mTextStyle = Paint.Style.FILL; - - /** - * label string that is drawn next to the limit line - */ - private String mLabel = ""; - - /** - * the path effect of this LimitLine that makes dashed lines possible - */ - private DashPathEffect mDashPathEffect = null; - - /** - * indicates the position of the LimitLine label - */ - private LimitLine.LimitLabelPosition mLabelPosition = LimitLine.LimitLabelPosition.RIGHT_TOP; - - /** - * Constructor with limit. - * - * @param firstLimit - the position (the value) on the y-axis (y-value) or x-axis - * (xIndex) where this line should appear - * @param secondLimit - the position (the value) on the y-axis (y-value) or x-axis - * (xIndex) where this line should appear - */ - public LimitRange(float firstLimit, float secondLimit) { - mLimit = new Range(firstLimit, secondLimit); - } - - /** - * Constructor with limit and label. - * - * @param firstLimit - the position (the value) on the y-axis (y-value) or x-axis - * (xIndex) where this line should appear - * @param secondLimit - the position (the value) on the y-axis (y-value) or x-axis - * (xIndex) where this line should appear - * @param label - provide "" if no label is required - */ - public LimitRange(float firstLimit, float secondLimit, String label) { - mLimit = new Range(firstLimit, secondLimit); - mLabel = label; - } - - /** - * Returns the limit that is set for this line. - */ - public Range getLimit() { - return mLimit; - } - - /** - * set the line width of the chart (min = 0.2f, max = 12f); default 2f NOTE: - * thinner line == better performance, thicker line == worse performance - */ - public void setLineWidth(float width) { - if (width > 12.0f) { - width = 12.0f; - } - mLineWidth = UtilsKtKt.convertDpToPixel(width); - } - - /** - * returns the width of limit line - */ - public float getLineWidth() { - return mLineWidth; - } - - /** - * Sets the linecolor for this LimitLine. Make sure to use - * getResources().getColor(...) - */ - public void setLineColor(int color) { - mLineColor = color; - } - - /** - * Sets the range color for this LimitRange. Make sure to use - * getResources().getColor(...) - */ - public void setRangeColor(int color) { - mRangeColor = color; - } - - /** - * Returns the color that is used for this LimitLine - */ - public int getLineColor() { - return mLineColor; - } - - /** - * Returns the color that is used for this LimitRange - */ - public int getRangeColor() { - return mRangeColor; - } - - /** - * Enables the line to be drawn in dashed mode, e.g. like this "- - - - - -" - * - * @param lineLength the length of the line pieces - * @param spaceLength the length of space inbetween the pieces - * @param phase offset, in degrees (normally, use 0) - */ - public void enableDashedLine(float lineLength, float spaceLength, float phase) { - mDashPathEffect = new DashPathEffect(new float[]{ - lineLength, spaceLength - }, phase); - } - - /** - * Disables the line to be drawn in dashed mode. - */ - public void disableDashedLine() { - mDashPathEffect = null; - } - - /** - * Returns true if the dashed-line effect is enabled, false if not. Default: - * disabled - */ - public boolean isDashedLineEnabled() { - return mDashPathEffect != null; - } - - /** - * returns the DashPathEffect that is set for this LimitLine - */ - public DashPathEffect getDashPathEffect() { - return mDashPathEffect; - } - - /** - * Sets the color of the value-text that is drawn next to the LimitLine. - * Default: Paint.Style.FILL_AND_STROKE - */ - public void setTextStyle(Paint.Style style) { - this.mTextStyle = style; - } - - /** - * Returns the color of the value-text that is drawn next to the LimitLine. - */ - public Paint.Style getTextStyle() { - return mTextStyle; - } - - /** - * Sets the position of the LimitLine value label (either on the right or on - * the left edge of the chart). Not supported for RadarChart. - */ - public void setLabelPosition(LimitLine.LimitLabelPosition pos) { - mLabelPosition = pos; - } - - /** - * Returns the position of the LimitLine label (value). - */ - public LimitLine.LimitLabelPosition getLabelPosition() { - return mLabelPosition; - } - - /** - * Sets the label that is drawn next to the limit line. Provide "" if no - * label is required. - */ - public void setLabel(String label) { - mLabel = label; - } - - /** - * Returns the label that is drawn next to the limit line. - */ - public String getLabel() { - return mLabel; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitRange.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitRange.kt new file mode 100644 index 0000000000..2036137e7b --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/LimitRange.kt @@ -0,0 +1,183 @@ +package com.github.mikephil.charting.components + +import android.graphics.Color +import android.graphics.DashPathEffect +import android.graphics.Paint +import com.github.mikephil.charting.components.LimitLine.LimitLabelPosition +import com.github.mikephil.charting.utils.convertDpToPixel + +/** + * The limit line is an additional feature for all Line-, Bar- and + * ScatterCharts. It allows the displaying of an additional line in the chart + * that marks a certain maximum / limit on the specified axis (x- or y-axis). + */ +class LimitRange : ComponentBase { + class Range internal constructor(r1: Float, r2: Float) { + val low: Float + val high: Float + + init { + if (r1 < r2) { + this.low = r1 + this.high = r2 + } else { + this.low = r2 + this.high = r1 + } + } + } + + /** + * Returns the limit that is set for this line. + */ + /** + * limit / maximum (the y-value or xIndex) + */ + val limit: Range + + /** + * the width of the limit line + */ + private var mLineWidth = 0f + + /** + * Returns the color that is used for this LimitLine + */ + /** + * Sets the linecolor for this LimitLine. Make sure to use + * getResources().getColor(...) + */ + /** + * the color of the limit line + */ + var lineColor: Int = Color.rgb(237, 91, 91) + + /** + * Returns the color that is used for this LimitRange + */ + /** + * Sets the range color for this LimitRange. Make sure to use + * getResources().getColor(...) + */ + /** + * the color of the Range + */ + var rangeColor: Int = Color.rgb(128, 128, 128) + + /** + * Returns the color of the value-text that is drawn next to the LimitLine. + */ + /** + * Sets the color of the value-text that is drawn next to the LimitLine. + * Default: Paint.Style.FILL_AND_STROKE + */ + /** + * the style of the label text + */ + var textStyle: Paint.Style? = Paint.Style.FILL + + /** + * Returns the label that is drawn next to the limit line. + */ + /** + * Sets the label that is drawn next to the limit line. Provide "" if no + * label is required. + */ + /** + * label string that is drawn next to the limit line + */ + var label: String? = "" + + /** + * returns the DashPathEffect that is set for this LimitLine + */ + /** + * the path effect of this LimitLine that makes dashed lines possible + */ + var dashPathEffect: DashPathEffect? = null + private set + + /** + * Returns the position of the LimitLine label (value). + */ + /** + * Sets the position of the LimitLine value label (either on the right or on + * the left edge of the chart). Not supported for RadarChart. + */ + /** + * indicates the position of the LimitLine label + */ + var labelPosition: LimitLabelPosition? = LimitLabelPosition.RIGHT_TOP + + /** + * Constructor with limit. + * + * @param firstLimit - the position (the value) on the y-axis (y-value) or x-axis + * (xIndex) where this line should appear + * @param secondLimit - the position (the value) on the y-axis (y-value) or x-axis + * (xIndex) where this line should appear + */ + constructor(firstLimit: Float, secondLimit: Float) { + this.limit = Range(firstLimit, secondLimit) + } + + /** + * Constructor with limit and label. + * + * @param firstLimit - the position (the value) on the y-axis (y-value) or x-axis + * (xIndex) where this line should appear + * @param secondLimit - the position (the value) on the y-axis (y-value) or x-axis + * (xIndex) where this line should appear + * @param label - provide "" if no label is required + */ + constructor(firstLimit: Float, secondLimit: Float, label: String?) { + this.limit = Range(firstLimit, secondLimit) + this.label = label + } + + var lineWidth: Float + /** + * returns the width of limit line + */ + get() = mLineWidth + /** + * set the line width of the chart (min = 0.2f, max = 12f); default 2f NOTE: + * thinner line == better performance, thicker line == worse performance + */ + set(width) { + var width = width + if (width > 12.0f) { + width = 12.0f + } + mLineWidth = width.convertDpToPixel() + } + + /** + * Enables the line to be drawn in dashed mode, e.g. like this "- - - - - -" + * + * @param lineLength the length of the line pieces + * @param spaceLength the length of space inbetween the pieces + * @param phase offset, in degrees (normally, use 0) + */ + fun enableDashedLine(lineLength: Float, spaceLength: Float, phase: Float) { + this.dashPathEffect = DashPathEffect( + floatArrayOf( + lineLength, spaceLength + ), phase + ) + } + + /** + * Disables the line to be drawn in dashed mode. + */ + fun disableDashedLine() { + this.dashPathEffect = null + } + + val isDashedLineEnabled: Boolean + /** + * Returns true if the dashed-line effect is enabled, false if not. Default: + * disabled + */ + get() = this.dashPathEffect != null +}