Skip to content

Commit bdfbec1

Browse files
authored
Merge pull request #454 from AppDevNext/KotlinComponents
Kotlin components
2 parents f5c8aa8 + ab28c20 commit bdfbec1

File tree

13 files changed

+359
-466
lines changed

13 files changed

+359
-466
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ protected void drawDescription(Canvas c) {
439439
y = position.y;
440440
}
441441

442-
c.drawText(mDescription.getText(), x, y, mDescPaint);
442+
c.drawText(mDescription.text, x, y, mDescPaint);
443443
}
444444
}
445445

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

Lines changed: 0 additions & 95 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.github.mikephil.charting.components
2+
3+
import android.graphics.Paint.Align
4+
import com.github.mikephil.charting.utils.MPPointF
5+
import com.github.mikephil.charting.utils.Utils
6+
7+
class Description : ComponentBase() {
8+
/**
9+
* Sets the text to be shown as the description.
10+
* Never set this to null as this will cause nullpointer exception when drawing with Android Canvas.
11+
*
12+
* @param text
13+
*/
14+
@JvmField
15+
var text: String? = "Description Label"
16+
17+
/**
18+
* Returns the customized position of the description, or null if none set.
19+
*
20+
* @return
21+
*/
22+
/**
23+
* the custom position of the description text
24+
*/
25+
var position: MPPointF? = null
26+
private set
27+
28+
/**
29+
* Sets the text alignment of the description text. Default RIGHT.
30+
*/
31+
/**
32+
* the alignment of the description text
33+
*/
34+
var textAlign: Align? = Align.RIGHT
35+
36+
init {
37+
// default size
38+
mTextSize = Utils.convertDpToPixel(8f)
39+
}
40+
41+
/**
42+
* Sets a custom position for the description text in pixels on the screen.
43+
*
44+
* @param x - xcoordinate
45+
* @param y - ycoordinate
46+
*/
47+
fun setPosition(x: Float, y: Float) {
48+
if (this.position == null) {
49+
this.position = MPPointF.getInstance(x, y)
50+
} else {
51+
position!!.x = x
52+
position!!.y = y
53+
}
54+
}
55+
}

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+
}

0 commit comments

Comments
 (0)