diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java index 395be9c68f..66994f9819 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java @@ -439,7 +439,7 @@ protected void drawDescription(Canvas c) { y = position.y; } - c.drawText(mDescription.getText(), x, y, mDescPaint); + c.drawText(mDescription.text, x, y, mDescPaint); } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/Description.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/Description.java deleted file mode 100644 index 18294a3270..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/Description.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.github.mikephil.charting.components; - -import android.graphics.Paint; - -import com.github.mikephil.charting.utils.MPPointF; -import com.github.mikephil.charting.utils.Utils; - -/** - * Created by Philipp Jahoda on 17/09/16. - */ -public class Description extends ComponentBase { - - /** - * the text used in the description - */ - private String text = "Description Label"; - - /** - * the custom position of the description text - */ - private MPPointF mPosition; - - /** - * the alignment of the description text - */ - private Paint.Align mTextAlign = Paint.Align.RIGHT; - - public Description() { - super(); - - // default size - mTextSize = Utils.convertDpToPixel(8f); - } - - /** - * Sets the text to be shown as the description. - * Never set this to null as this will cause nullpointer exception when drawing with Android Canvas. - * - * @param text - */ - public void setText(String text) { - this.text = text; - } - - /** - * Returns the description text. - * - * @return - */ - public String getText() { - return text; - } - - /** - * Sets a custom position for the description text in pixels on the screen. - * - * @param x - xcoordinate - * @param y - ycoordinate - */ - public void setPosition(float x, float y) { - if (mPosition == null) { - mPosition = MPPointF.getInstance(x, y); - } else { - mPosition.x = x; - mPosition.y = y; - } - } - - /** - * Returns the customized position of the description, or null if none set. - * - * @return - */ - public MPPointF getPosition() { - return mPosition; - } - - /** - * Sets the text alignment of the description text. Default RIGHT. - * - * @param align - */ - public void setTextAlign(Paint.Align align) { - this.mTextAlign = align; - } - - /** - * Returns the text alignment of the description. - * - * @return - */ - public Paint.Align getTextAlign() { - return mTextAlign; - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/Description.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/components/Description.kt new file mode 100644 index 0000000000..e7fba481cd --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/Description.kt @@ -0,0 +1,55 @@ +package com.github.mikephil.charting.components + +import android.graphics.Paint.Align +import com.github.mikephil.charting.utils.MPPointF +import com.github.mikephil.charting.utils.Utils + +class Description : ComponentBase() { + /** + * Sets the text to be shown as the description. + * Never set this to null as this will cause nullpointer exception when drawing with Android Canvas. + * + * @param text + */ + @JvmField + var text: String? = "Description Label" + + /** + * Returns the customized position of the description, or null if none set. + * + * @return + */ + /** + * the custom position of the description text + */ + var position: MPPointF? = null + private set + + /** + * Sets the text alignment of the description text. Default RIGHT. + */ + /** + * the alignment of the description text + */ + var textAlign: Align? = Align.RIGHT + + init { + // default size + mTextSize = Utils.convertDpToPixel(8f) + } + + /** + * Sets a custom position for the description text in pixels on the screen. + * + * @param x - xcoordinate + * @param y - ycoordinate + */ + fun setPosition(x: Float, y: Float) { + if (this.position == null) { + this.position = MPPointF.getInstance(x, y) + } else { + position!!.x = x + position!!.y = y + } + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/IMarker.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/IMarker.java deleted file mode 100644 index 3b8ca43c81..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/IMarker.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.github.mikephil.charting.components; - -import android.graphics.Canvas; - -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.highlight.Highlight; -import com.github.mikephil.charting.utils.MPPointF; - -public interface IMarker { - - /** - * @return The desired (general) offset you wish the IMarker to have on the x- and y-axis. - * By returning x: -(width / 2) you will center the IMarker horizontally. - * By returning y: -(height / 2) you will center the IMarker vertically. - */ - MPPointF getOffset(); - - /** - * @return The offset for drawing at the specific `point`. This allows conditional adjusting of the Marker position. - * If you have no adjustments to make, return getOffset(). - * - * @param posX This is the X position at which the marker wants to be drawn. - * You can adjust the offset conditionally based on this argument. - * @param posY This is the X position at which the marker wants to be drawn. - * You can adjust the offset conditionally based on this argument. - */ - MPPointF getOffsetForDrawingAtPoint(float posX, float posY); - - /** - * This method enables a specified custom IMarker to update it's content every time the IMarker is redrawn. - * - * @param e The Entry the IMarker belongs to. This can also be any subclass of Entry, like BarEntry or - * CandleEntry, simply cast it at runtime. - * @param highlight The highlight object contains information about the highlighted value such as it's dataset-index, the - * selected range or stack-index (only stacked bar entries). - */ - void refreshContent(Entry e, Highlight highlight); - - /** - * Draws the IMarker on the given position on the screen with the given Canvas object. - * - * @param canvas - * @param posX - * @param posY - */ - void draw(Canvas canvas, float posX, float posY); -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/IMarker.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/components/IMarker.kt new file mode 100644 index 0000000000..d3838dcb9e --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/IMarker.kt @@ -0,0 +1,45 @@ +package com.github.mikephil.charting.components + +import android.graphics.Canvas +import com.github.mikephil.charting.data.Entry +import com.github.mikephil.charting.highlight.Highlight +import com.github.mikephil.charting.utils.MPPointF + +interface IMarker { + /** + * @return The desired (general) offset you wish the IMarker to have on the x- and y-axis. + * By returning x: -(width / 2) you will center the IMarker horizontally. + * By returning y: -(height / 2) you will center the IMarker vertically. + */ + val offset: MPPointF + + /** + * @return The offset for drawing at the specific `point`. This allows conditional adjusting of the Marker position. + * If you have no adjustments to make, return getOffset(). + * + * @param posX This is the X position at which the marker wants to be drawn. + * You can adjust the offset conditionally based on this argument. + * @param posY This is the X position at which the marker wants to be drawn. + * You can adjust the offset conditionally based on this argument. + */ + fun getOffsetForDrawingAtPoint(posX: Float, posY: Float): MPPointF? + + /** + * This method enables a specified custom IMarker to update it's content every time the IMarker is redrawn. + * + * @param entry The Entry the IMarker belongs to. This can also be any subclass of Entry, like BarEntry or + * CandleEntry, simply cast it at runtime. + * @param highlight The highlight object contains information about the highlighted value such as it's dataset-index, the + * selected range or stack-index (only stacked bar entries). + */ + fun refreshContent(entry: Entry, highlight: Highlight) + + /** + * Draws the IMarker on the given position on the screen with the given Canvas object. + * + * @param canvas + * @param posX + * @param posY + */ + fun draw(canvas: Canvas, posX: Float, posY: Float) +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerImage.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerImage.java deleted file mode 100644 index 7bd7b8e6c3..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerImage.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.github.mikephil.charting.components; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.RelativeLayout; - -import com.github.mikephil.charting.charts.Chart; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.highlight.Highlight; -import com.github.mikephil.charting.utils.FSize; -import com.github.mikephil.charting.utils.MPPointF; - -import java.lang.ref.WeakReference; - -/** - * View that can be displayed when selecting values in the chart. Extend this class to provide custom layouts for your - * markers. - * - * @author Philipp Jahoda - */ -public class MarkerImage implements IMarker { - - private Context mContext; - private Drawable mDrawable; - - private MPPointF mOffset = new MPPointF(); - private MPPointF mOffset2 = new MPPointF(); - private WeakReference mWeakChart; - - private FSize mSize = new FSize(); - private Rect mDrawableBoundsCache = new Rect(); - - /** - * Constructor. Sets up the MarkerView with a custom layout resource. - * - * @param context - * @param drawableResourceId the drawable resource to render - */ - public MarkerImage(Context context, int drawableResourceId) { - mContext = context; - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) - { - mDrawable = mContext.getResources().getDrawable(drawableResourceId, null); - } - else - { - mDrawable = mContext.getResources().getDrawable(drawableResourceId); - } - } - - public void setOffset(MPPointF offset) { - mOffset = offset; - - if (mOffset == null) { - mOffset = new MPPointF(); - } - } - - public void setOffset(float offsetX, float offsetY) { - mOffset.x = offsetX; - mOffset.y = offsetY; - } - - @Override - public MPPointF getOffset() { - return mOffset; - } - - public void setSize(FSize size) { - mSize = size; - - if (mSize == null) { - mSize = new FSize(); - } - } - - public FSize getSize() { - return mSize; - } - - public void setChartView(Chart chart) { - mWeakChart = new WeakReference<>(chart); - } - - public Chart getChartView() { - return mWeakChart == null ? null : mWeakChart.get(); - } - - @Override - public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) { - - MPPointF offset = getOffset(); - mOffset2.x = offset.x; - mOffset2.y = offset.y; - - Chart chart = getChartView(); - - float width = mSize.width; - float height = mSize.height; - - if (width == 0.f && mDrawable != null) { - width = mDrawable.getIntrinsicWidth(); - } - if (height == 0.f && mDrawable != null) { - height = mDrawable.getIntrinsicHeight(); - } - - if (posX + mOffset2.x < 0) { - mOffset2.x = - posX; - } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) { - mOffset2.x = chart.getWidth() - posX - width; - } - - if (posY + mOffset2.y < 0) { - mOffset2.y = - posY; - } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) { - mOffset2.y = chart.getHeight() - posY - height; - } - - return mOffset2; - } - - @Override - public void refreshContent(Entry e, Highlight highlight) { - - } - - @Override - public void draw(Canvas canvas, float posX, float posY) { - - if (mDrawable == null) return; - - MPPointF offset = getOffsetForDrawingAtPoint(posX, posY); - - float width = mSize.width; - float height = mSize.height; - - if (width == 0.f) { - width = mDrawable.getIntrinsicWidth(); - } - if (height == 0.f) { - height = mDrawable.getIntrinsicHeight(); - } - - mDrawable.copyBounds(mDrawableBoundsCache); - mDrawable.setBounds( - mDrawableBoundsCache.left, - mDrawableBoundsCache.top, - mDrawableBoundsCache.left + (int)width, - mDrawableBoundsCache.top + (int)height); - - int saveId = canvas.save(); - // translate to the correct position and draw - canvas.translate(posX + offset.x, posY + offset.y); - mDrawable.draw(canvas); - canvas.restoreToCount(saveId); - - mDrawable.setBounds(mDrawableBoundsCache); - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerImage.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerImage.kt new file mode 100644 index 0000000000..c8ec971c60 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerImage.kt @@ -0,0 +1,135 @@ +package com.github.mikephil.charting.components + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Rect +import android.graphics.drawable.Drawable +import android.os.Build +import com.github.mikephil.charting.charts.Chart +import com.github.mikephil.charting.data.Entry +import com.github.mikephil.charting.highlight.Highlight +import com.github.mikephil.charting.utils.FSize +import com.github.mikephil.charting.utils.MPPointF +import java.lang.ref.WeakReference + +/** + * View that can be displayed when selecting values in the chart. Extend this class to provide custom layouts for your markers. + */ +class MarkerImage(private var mContext: Context, drawableResourceId: Int) : IMarker { + private var drawable: Drawable? = null + + private var mOffset: MPPointF = MPPointF() + private val mOffset2 = MPPointF() + private var mWeakChart: WeakReference?>? = null + + private var mSize: FSize? = FSize() + private val mDrawableBoundsCache = Rect() + + /** + * Constructor. Sets up the MarkerView with a custom layout resource. + * + * @param mContext + * @param drawableResourceId the drawable resource to render + */ + init { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + drawable = mContext.resources.getDrawable(drawableResourceId, null) + } else { + drawable = mContext.resources.getDrawable(drawableResourceId) + } + } + + fun setOffset(offsetX: Float, offsetY: Float) { + mOffset.x = offsetX + mOffset.y = offsetY + } + + override var offset: MPPointF + get() = mOffset + set(offset) { + mOffset = offset + } + + var size: FSize? + get() = mSize + set(size) { + mSize = size + + if (mSize == null) { + mSize = FSize() + } + } + + var chartView: Chart<*>? + get() = if (mWeakChart == null) null else mWeakChart!!.get() + set(chart) { + mWeakChart = WeakReference?>(chart) + } + + override fun getOffsetForDrawingAtPoint(posX: Float, posY: Float): MPPointF { + val offset = offset + mOffset2.x = offset.x + mOffset2.y = offset.y + + val chart = this.chartView + + var width = mSize!!.width + var height = mSize!!.height + + if (width == 0f && drawable != null) { + width = drawable!!.intrinsicWidth.toFloat() + } + if (height == 0f && drawable != null) { + height = drawable!!.intrinsicHeight.toFloat() + } + + if (posX + mOffset2.x < 0) { + mOffset2.x = -posX + } else if (chart != null && posX + width + mOffset2.x > chart.width) { + mOffset2.x = chart.width - posX - width + } + + if (posY + mOffset2.y < 0) { + mOffset2.y = -posY + } else if (chart != null && posY + height + mOffset2.y > chart.height) { + mOffset2.y = chart.height - posY - height + } + + return mOffset2 + } + + override fun refreshContent(entry: Entry, highlight: Highlight) = Unit + + override fun draw(canvas: Canvas, posX: Float, posY: Float) { + if (drawable == null) + return + + val offset: MPPointF = getOffsetForDrawingAtPoint(posX, posY) + + var width = mSize!!.width + var height = mSize!!.height + + if (width == 0f) { + width = drawable!!.intrinsicWidth.toFloat() + } + if (height == 0f) { + height = drawable!!.intrinsicHeight.toFloat() + } + + drawable!!.copyBounds(mDrawableBoundsCache) + drawable!!.setBounds( + mDrawableBoundsCache.left, + mDrawableBoundsCache.top, + mDrawableBoundsCache.left + width.toInt(), + mDrawableBoundsCache.top + height.toInt() + ) + + val saveId = canvas.save() + // translate to the correct position and draw + canvas.translate(posX + offset.x, posY + offset.y) + drawable!!.draw(canvas) + canvas.restoreToCount(saveId) + + drawable!!.bounds = mDrawableBoundsCache + } +} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerView.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerView.java deleted file mode 100644 index 162e88e33c..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerView.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.github.mikephil.charting.components; - -import android.content.Context; -import android.graphics.Canvas; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.RelativeLayout; - -import com.github.mikephil.charting.charts.Chart; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.highlight.Highlight; -import com.github.mikephil.charting.utils.FSize; -import com.github.mikephil.charting.utils.MPPointF; - -import java.lang.ref.WeakReference; - -/** - * View that can be displayed when selecting values in the chart. Extend this class to provide custom layouts for your - * markers. - * - * @author Philipp Jahoda - */ -public class MarkerView extends RelativeLayout implements IMarker { - - private MPPointF mOffset = new MPPointF(); - private MPPointF mOffset2 = new MPPointF(); - private WeakReference mWeakChart; - - /** - * Constructor. Sets up the MarkerView with a custom layout resource. - * - * @param context - * @param layoutResource the layout resource to use for the MarkerView - */ - public MarkerView(Context context, int layoutResource) { - super(context); - setupLayoutResource(layoutResource); - } - - /** - * Sets the layout resource for a custom MarkerView. - * - * @param layoutResource - */ - private void setupLayoutResource(int layoutResource) { - - View inflated = LayoutInflater.from(getContext()).inflate(layoutResource, this); - - inflated.setLayoutParams(new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); - inflated.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); - - // measure(getWidth(), getHeight()); - inflated.layout(0, 0, inflated.getMeasuredWidth(), inflated.getMeasuredHeight()); - } - - public void setOffset(MPPointF offset) { - mOffset = offset; - - if (mOffset == null) { - mOffset = new MPPointF(); - } - } - - public void setOffset(float offsetX, float offsetY) { - mOffset.x = offsetX; - mOffset.y = offsetY; - } - - @Override - public MPPointF getOffset() { - return mOffset; - } - - public void setChartView(Chart chart) { - mWeakChart = new WeakReference<>(chart); - } - - public Chart getChartView() { - return mWeakChart == null ? null : mWeakChart.get(); - } - - @Override - public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) { - - MPPointF offset = getOffset(); - mOffset2.x = offset.x; - mOffset2.y = offset.y; - - Chart chart = getChartView(); - - float width = getWidth(); - float height = getHeight(); - - if (posX + mOffset2.x < 0) { - mOffset2.x = - posX; - } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) { - mOffset2.x = chart.getWidth() - posX - width; - } - - if (posY + mOffset2.y < 0) { - mOffset2.y = - posY; - } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) { - mOffset2.y = chart.getHeight() - posY - height; - } - - return mOffset2; - } - - @Override - public void refreshContent(Entry e, Highlight highlight) { - - measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); - layout(0, 0, getMeasuredWidth(), getMeasuredHeight()); - - } - - @Override - public void draw(Canvas canvas, float posX, float posY) { - - MPPointF offset = getOffsetForDrawingAtPoint(posX, posY); - - int saveId = canvas.save(); - // translate to the correct position and draw - canvas.translate(posX + offset.x, posY + offset.y); - draw(canvas); - canvas.restoreToCount(saveId); - } -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerView.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerView.kt new file mode 100644 index 0000000000..213a6c182c --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerView.kt @@ -0,0 +1,100 @@ +package com.github.mikephil.charting.components + +import android.content.Context +import android.graphics.Canvas +import android.view.LayoutInflater +import android.widget.RelativeLayout +import com.github.mikephil.charting.charts.Chart +import com.github.mikephil.charting.data.Entry +import com.github.mikephil.charting.highlight.Highlight +import com.github.mikephil.charting.utils.MPPointF +import java.lang.ref.WeakReference + +/** + * View that can be displayed when selecting values in the chart. Extend this class to provide custom layouts for your markers. + */ +open class MarkerView(context: Context?, layoutResource: Int) : RelativeLayout(context), IMarker { + private var mOffset: MPPointF = MPPointF() + private val mOffset2 = MPPointF() + private var mWeakChart: WeakReference?>? = null + + /** + * Constructor. Sets up the MarkerView with a custom layout resource. + * + * @param context + * @param layoutResource the layout resource to use for the MarkerView + */ + init { + setupLayoutResource(layoutResource) + } + + /** + * Sets the layout resource for a custom MarkerView. + * + * @param layoutResource + */ + private fun setupLayoutResource(layoutResource: Int) { + val inflated = LayoutInflater.from(context).inflate(layoutResource, this) + + inflated.layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) + inflated.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)) + + // measure(getWidth(), getHeight()); + inflated.layout(0, 0, inflated.measuredWidth, inflated.measuredHeight) + } + + override var offset: MPPointF + get() = mOffset + set(offset) { + mOffset = offset + } + + var chartView: Chart<*>? + get() = if (mWeakChart == null) null else mWeakChart!!.get() + set(chart) { + mWeakChart = WeakReference?>(chart) + } + + override fun getOffsetForDrawingAtPoint(posX: Float, posY: Float): MPPointF { + val offset = offset + mOffset2.x = offset.x + mOffset2.y = offset.y + + val chart = this.chartView + + val width = width.toFloat() + val height = height.toFloat() + + if (posX + mOffset2.x < 0) { + mOffset2.x = -posX + } else if (chart != null && posX + width + mOffset2.x > chart.width) { + mOffset2.x = chart.width - posX - width + } + + if (posY + mOffset2.y < 0) { + mOffset2.y = -posY + } else if (chart != null && posY + height + mOffset2.y > chart.height) { + mOffset2.y = chart.height - posY - height + } + + return mOffset2 + } + + override fun refreshContent(entry: Entry, highlight: Highlight) { + measure( + MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), + MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED) + ) + layout(0, 0, measuredWidth, measuredHeight) + } + + override fun draw(canvas: Canvas, posX: Float, posY: Float) { + val offset: MPPointF = getOffsetForDrawingAtPoint(posX, posY) + + val saveId = canvas.save() + // translate to the correct position and draw + canvas.translate(posX + offset.x, posY + offset.y) + draw(canvas) + canvas.restoreToCount(saveId) + } +} diff --git a/app/src/main/kotlin/info/appdev/chartexample/custom/MyMarkerView.kt b/app/src/main/kotlin/info/appdev/chartexample/custom/MyMarkerView.kt index ee70b0da2f..29fc5ebf22 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/custom/MyMarkerView.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/custom/MyMarkerView.kt @@ -20,17 +20,17 @@ class MyMarkerView(context: Context?, layoutResource: Int) : MarkerView(context, // runs every time the MarkerView is redrawn, can be used to update the // content (user-interface) - override fun refreshContent(e: Entry, highlight: Highlight?) { - if (e is CandleEntry) { - tvContent.text = e.high.formatNumber(0, true) + + override fun refreshContent(entry: Entry, highlight: Highlight) { + if (entry is CandleEntry) { + tvContent.text = entry.high.formatNumber(0, true) } else { - tvContent.text = e.y.formatNumber(0, true) + tvContent.text = entry.y.formatNumber(0, true) } - super.refreshContent(e, highlight) + super.refreshContent(entry, highlight) } - override fun getOffset(): MPPointF { - return MPPointF(-(width / 2).toFloat(), -height.toFloat()) - } + override var offset: MPPointF = MPPointF() + get() = MPPointF(-(width / 2).toFloat(), -height.toFloat()) } diff --git a/app/src/main/kotlin/info/appdev/chartexample/custom/RadarMarkerView.kt b/app/src/main/kotlin/info/appdev/chartexample/custom/RadarMarkerView.kt index b45c472657..f302f29cb4 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/custom/RadarMarkerView.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/custom/RadarMarkerView.kt @@ -25,13 +25,12 @@ class RadarMarkerView(context: Context, layoutResource: Int) : MarkerView(contex // runs every time the MarkerView is redrawn, can be used to update the // content (user-interface) - override fun refreshContent(e: Entry, highlight: Highlight?) { - tvContent.text = String.format("%s %%", format.format(e.y.toDouble())) + override fun refreshContent(entry: Entry, highlight: Highlight) { + tvContent.text = String.format("%s %%", format.format(entry.y.toDouble())) - super.refreshContent(e, highlight) + super.refreshContent(entry, highlight) } - override fun getOffset(): MPPointF { - return MPPointF(-(width / 2).toFloat(), (-height - 10).toFloat()) - } + override var offset: MPPointF = MPPointF() + get() = MPPointF(-(width / 2).toFloat(), (-height - 10).toFloat()) } diff --git a/app/src/main/kotlin/info/appdev/chartexample/custom/StackedBarsMarkerView.kt b/app/src/main/kotlin/info/appdev/chartexample/custom/StackedBarsMarkerView.kt index 18b23126d0..d44ec965b9 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/custom/StackedBarsMarkerView.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/custom/StackedBarsMarkerView.kt @@ -8,7 +8,6 @@ import com.github.mikephil.charting.data.BarEntry import com.github.mikephil.charting.data.Entry import com.github.mikephil.charting.highlight.Highlight import com.github.mikephil.charting.utils.MPPointF -import com.github.mikephil.charting.utils.Utils import com.github.mikephil.charting.utils.formatNumber import info.appdev.chartexample.R @@ -27,18 +26,17 @@ class StackedBarsMarkerView(context: Context?, layoutResource: Int) : MarkerView if (entry.yVals != null) { // draw the stack value - tvContent.text = entry.yVals!![highlight.stackIndex].formatNumber( 0, true) + tvContent.text = entry.yVals!![highlight.stackIndex].formatNumber(0, true) } else { - tvContent.text = entry.y.formatNumber( 0, true) + tvContent.text = entry.y.formatNumber(0, true) } } else { - tvContent.text = entry.y.formatNumber( 0, true) + tvContent.text = entry.y.formatNumber(0, true) } super.refreshContent(entry, highlight) } - override fun getOffset(): MPPointF { - return MPPointF(-(width / 2).toFloat(), -height.toFloat()) - } + override var offset: MPPointF = MPPointF() + get() = MPPointF(-(width / 2).toFloat(), -height.toFloat()) } diff --git a/app/src/main/kotlin/info/appdev/chartexample/custom/XYMarkerView.kt b/app/src/main/kotlin/info/appdev/chartexample/custom/XYMarkerView.kt index a64f768c29..8ac4279194 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/custom/XYMarkerView.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/custom/XYMarkerView.kt @@ -21,13 +21,12 @@ class XYMarkerView(context: Context?, private val xAxisValueFormatter: IAxisValu private val format: DecimalFormat = DecimalFormat("###.0") // runs every time the MarkerView is redrawn, can be used to update the content (user-interface) - override fun refreshContent(e: Entry, highlight: Highlight?) { - tvContent.text = String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(e.x, null), format.format(e.y.toDouble())) + override fun refreshContent(entry: Entry, highlight: Highlight) { + tvContent.text = String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(entry.x, null), format.format(entry.y.toDouble())) - super.refreshContent(e, highlight) + super.refreshContent(entry, highlight) } - override fun getOffset(): MPPointF { - return MPPointF(-(width / 2).toFloat(), -height.toFloat()) - } + override var offset: MPPointF = MPPointF() + get() = MPPointF(-(width / 2).toFloat(), -height.toFloat()) }