Skip to content

Commit ffaa91f

Browse files
committed
Kotlin components
1 parent 8f8e2ae commit ffaa91f

File tree

8 files changed

+70
-76
lines changed

8 files changed

+70
-76
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/components/IMarker.java

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.github.mikephil.charting.components
2+
3+
import android.graphics.Canvas
4+
import com.github.mikephil.charting.data.Entry
5+
import com.github.mikephil.charting.highlight.Highlight
6+
import com.github.mikephil.charting.utils.MPPointF
7+
8+
interface IMarker {
9+
/**
10+
* @return The desired (general) offset you wish the IMarker to have on the x- and y-axis.
11+
* By returning x: -(width / 2) you will center the IMarker horizontally.
12+
* By returning y: -(height / 2) you will center the IMarker vertically.
13+
*/
14+
val offset: MPPointF
15+
16+
/**
17+
* @return The offset for drawing at the specific `point`. This allows conditional adjusting of the Marker position.
18+
* If you have no adjustments to make, return getOffset().
19+
*
20+
* @param posX This is the X position at which the marker wants to be drawn.
21+
* You can adjust the offset conditionally based on this argument.
22+
* @param posY This is the X position at which the marker wants to be drawn.
23+
* You can adjust the offset conditionally based on this argument.
24+
*/
25+
fun getOffsetForDrawingAtPoint(posX: Float, posY: Float): MPPointF?
26+
27+
/**
28+
* This method enables a specified custom IMarker to update it's content every time the IMarker is redrawn.
29+
*
30+
* @param entry The Entry the IMarker belongs to. This can also be any subclass of Entry, like BarEntry or
31+
* CandleEntry, simply cast it at runtime.
32+
* @param highlight The highlight object contains information about the highlighted value such as it's dataset-index, the
33+
* selected range or stack-index (only stacked bar entries).
34+
*/
35+
fun refreshContent(entry: Entry, highlight: Highlight)
36+
37+
/**
38+
* Draws the IMarker on the given position on the screen with the given Canvas object.
39+
*
40+
* @param canvas
41+
* @param posX
42+
* @param posY
43+
*/
44+
fun draw(canvas: Canvas, posX: Float, posY: Float)
45+
}

MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerImage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {
128128
}
129129

130130
@Override
131-
public void refreshContent(Entry e, Highlight highlight) {
131+
public void refreshContent(Entry entry, Highlight highlight) {
132132

133133
}
134134

MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {
107107
}
108108

109109
@Override
110-
public void refreshContent(Entry e, Highlight highlight) {
110+
public void refreshContent(Entry entry, Highlight highlight) {
111111

112112
measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
113113
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

app/src/main/kotlin/info/appdev/chartexample/custom/MyMarkerView.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ class MyMarkerView(context: Context?, layoutResource: Int) : MarkerView(context,
2020

2121
// runs every time the MarkerView is redrawn, can be used to update the
2222
// content (user-interface)
23-
override fun refreshContent(e: Entry, highlight: Highlight?) {
24-
if (e is CandleEntry) {
25-
tvContent.text = e.high.formatNumber(0, true)
23+
24+
override fun refreshContent(entry: Entry, highlight: Highlight) {
25+
if (entry is CandleEntry) {
26+
tvContent.text = entry.high.formatNumber(0, true)
2627
} else {
27-
tvContent.text = e.y.formatNumber(0, true)
28+
tvContent.text = entry.y.formatNumber(0, true)
2829
}
2930

30-
super.refreshContent(e, highlight)
31+
super.refreshContent(entry, highlight)
3132
}
3233

33-
override fun getOffset(): MPPointF {
34-
return MPPointF(-(width / 2).toFloat(), -height.toFloat())
35-
}
34+
override val offset: MPPointF
35+
get() = MPPointF(-(width / 2).toFloat(), -height.toFloat())
3636
}

app/src/main/kotlin/info/appdev/chartexample/custom/RadarMarkerView.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ class RadarMarkerView(context: Context, layoutResource: Int) : MarkerView(contex
2525

2626
// runs every time the MarkerView is redrawn, can be used to update the
2727
// content (user-interface)
28-
override fun refreshContent(e: Entry, highlight: Highlight?) {
29-
tvContent.text = String.format("%s %%", format.format(e.y.toDouble()))
28+
override fun refreshContent(entry: Entry, highlight: Highlight) {
29+
tvContent.text = String.format("%s %%", format.format(entry.y.toDouble()))
3030

31-
super.refreshContent(e, highlight)
31+
super.refreshContent(entry, highlight)
3232
}
3333

34-
override fun getOffset(): MPPointF {
35-
return MPPointF(-(width / 2).toFloat(), (-height - 10).toFloat())
36-
}
34+
override val offset: MPPointF
35+
get() = MPPointF(-(width / 2).toFloat(), (-height - 10).toFloat())
3736
}

app/src/main/kotlin/info/appdev/chartexample/custom/StackedBarsMarkerView.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import com.github.mikephil.charting.data.BarEntry
88
import com.github.mikephil.charting.data.Entry
99
import com.github.mikephil.charting.highlight.Highlight
1010
import com.github.mikephil.charting.utils.MPPointF
11-
import com.github.mikephil.charting.utils.Utils
1211
import com.github.mikephil.charting.utils.formatNumber
1312
import info.appdev.chartexample.R
1413

@@ -27,18 +26,17 @@ class StackedBarsMarkerView(context: Context?, layoutResource: Int) : MarkerView
2726

2827
if (entry.yVals != null) {
2928
// draw the stack value
30-
tvContent.text = entry.yVals!![highlight.stackIndex].formatNumber( 0, true)
29+
tvContent.text = entry.yVals!![highlight.stackIndex].formatNumber(0, true)
3130
} else {
32-
tvContent.text = entry.y.formatNumber( 0, true)
31+
tvContent.text = entry.y.formatNumber(0, true)
3332
}
3433
} else {
35-
tvContent.text = entry.y.formatNumber( 0, true)
34+
tvContent.text = entry.y.formatNumber(0, true)
3635
}
3736

3837
super.refreshContent(entry, highlight)
3938
}
4039

41-
override fun getOffset(): MPPointF {
42-
return MPPointF(-(width / 2).toFloat(), -height.toFloat())
43-
}
40+
override val offset: MPPointF
41+
get() = MPPointF(-(width / 2).toFloat(), -height.toFloat())
4442
}

app/src/main/kotlin/info/appdev/chartexample/custom/XYMarkerView.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ class XYMarkerView(context: Context?, private val xAxisValueFormatter: IAxisValu
2121
private val format: DecimalFormat = DecimalFormat("###.0")
2222

2323
// runs every time the MarkerView is redrawn, can be used to update the content (user-interface)
24-
override fun refreshContent(e: Entry, highlight: Highlight?) {
25-
tvContent.text = String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(e.x, null), format.format(e.y.toDouble()))
24+
override fun refreshContent(entry: Entry, highlight: Highlight) {
25+
tvContent.text = String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(entry.x, null), format.format(entry.y.toDouble()))
2626

27-
super.refreshContent(e, highlight)
27+
super.refreshContent(entry, highlight)
2828
}
2929

30-
override fun getOffset(): MPPointF {
31-
return MPPointF(-(width / 2).toFloat(), -height.toFloat())
32-
}
30+
override val offset: MPPointF
31+
get() = MPPointF(-(width / 2).toFloat(), -height.toFloat())
3332
}

0 commit comments

Comments
 (0)