Skip to content

Commit dae7308

Browse files
committed
Kotlin IScatterDataSet
1 parent 66d1574 commit dae7308

12 files changed

Lines changed: 66 additions & 85 deletions

File tree

MPChartLib/src/main/java/com/github/mikephil/charting/data/DataSet.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ abstract class DataSet<T : Entry>(
176176
}
177177

178178
/**
179-
* Returns a simple string representation of the DataSet with the type and
180-
* the number of Entries.
179+
* Returns a simple string representation of the DataSet with the type and the number of Entries.
181180
*/
182181
fun toSimpleString() = "DataSet, label: $label, entries: ${mEntries!!.size}"
183182

MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterDataSet.kt

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import com.github.mikephil.charting.utils.ColorTemplate
1414

1515
open class ScatterDataSet(yVals: MutableList<Entry>?, label: String = "") : LineScatterCandleRadarDataSet<Entry>(yVals, label), IScatterDataSet {
1616
/**
17-
* the size the scattershape will have, in density pixels
17+
* the size the scatterShape will have, in density pixels
1818
*/
1919
private var shapeSize = 15f
2020

@@ -56,18 +56,6 @@ open class ScatterDataSet(yVals: MutableList<Entry>?, label: String = "") : Line
5656
scatterDataSet.mScatterShapeHoleColor = mScatterShapeHoleColor
5757
}
5858

59-
/**
60-
* Sets the size in density pixels the drawn scattershape will have. This
61-
* only applies for non custom shapes.
62-
*/
63-
fun setScatterShapeSize(size: Float) {
64-
shapeSize = size
65-
}
66-
67-
override fun getScatterShapeSize(): Float {
68-
return shapeSize
69-
}
70-
7159
/**
7260
* Sets the ScatterShape this DataSet should be drawn with. This will search for an available IShapeRenderer and set this
7361
* renderer for the DataSet.
@@ -77,39 +65,34 @@ open class ScatterDataSet(yVals: MutableList<Entry>?, label: String = "") : Line
7765
}
7866

7967
/**
80-
* Sets a new IShapeRenderer responsible for drawing this DataSet.
81-
* This can also be used to set a custom IShapeRenderer aside from the default ones.
82-
*/
83-
fun setShapeRenderer(shape: IShapeRenderer?) {
84-
mShapeRenderer = shape
85-
}
86-
87-
override fun getShapeRenderer(): IShapeRenderer? {
88-
return mShapeRenderer
89-
}
90-
91-
/**
92-
* Sets the radius of the hole in the shape (applies to Square, Circle and Triangle)
93-
* Set this to <= 0 to remove holes.
68+
* Sets the size in density pixels the drawn scatterShape will have. This
69+
* only applies for non custom shapes.
9470
*/
95-
fun setScatterShapeHoleRadius(holeRadius: Float) {
96-
mScatterShapeHoleRadius = holeRadius
97-
}
98-
99-
override fun getScatterShapeHoleRadius(): Float {
100-
return mScatterShapeHoleRadius
101-
}
71+
override var scatterShapeSize: Float
72+
get() = shapeSize
73+
set(value) {
74+
shapeSize = value
75+
}
76+
override var scatterShapeHoleRadius: Float
77+
get() = mScatterShapeHoleRadius
78+
set(value) {
79+
mScatterShapeHoleRadius = value
80+
}
81+
override var scatterShapeHoleColor: Int
82+
get() = mScatterShapeHoleColor
83+
set(value) {
84+
mScatterShapeHoleColor = value
85+
}
10286

10387
/**
104-
* Sets the color for the hole in the shape.
88+
* Sets a new IShapeRenderer responsible for drawing this DataSet.
89+
* This can also be used to set a custom IShapeRenderer aside from the default ones.
10590
*/
106-
fun setScatterShapeHoleColor(holeColor: Int) {
107-
mScatterShapeHoleColor = holeColor
108-
}
109-
110-
override fun getScatterShapeHoleColor(): Int {
111-
return mScatterShapeHoleColor
112-
}
91+
override var shapeRenderer: IShapeRenderer?
92+
get() = mShapeRenderer
93+
set(value) {
94+
mShapeRenderer = value
95+
}
11396

11497
companion object {
11598
fun getRendererForShape(shape: ScatterShape): IShapeRenderer? {

MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IScatterDataSet.java

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.github.mikephil.charting.interfaces.datasets
2+
3+
import com.github.mikephil.charting.data.Entry
4+
import com.github.mikephil.charting.renderer.scatter.IShapeRenderer
5+
6+
interface IScatterDataSet : ILineScatterCandleRadarDataSet<Entry> {
7+
/**
8+
* the currently set scatter shape size
9+
*/
10+
val scatterShapeSize: Float
11+
12+
/**
13+
* radius of the hole in the shape
14+
*/
15+
val scatterShapeHoleRadius: Float
16+
17+
/**
18+
* the color for the hole in the shape
19+
*/
20+
val scatterShapeHoleColor: Int
21+
22+
/**
23+
* the IShapeRenderer responsible for rendering this DataSet.
24+
*/
25+
val shapeRenderer: IShapeRenderer?
26+
}

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/ChevronDownShapeRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ChevronDownShapeRenderer : IShapeRenderer {
1111
canvas: Canvas, dataSet: IScatterDataSet, viewPortHandler: ViewPortHandler?,
1212
posX: Float, posY: Float, renderPaint: Paint
1313
) {
14-
val shapeHalf = dataSet.getScatterShapeSize().convertDpToPixel() / 2f
14+
val shapeHalf = dataSet.scatterShapeSize.convertDpToPixel() / 2f
1515

1616
renderPaint.style = Paint.Style.STROKE
1717
renderPaint.strokeWidth = 1f.convertDpToPixel()

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/ChevronUpShapeRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ChevronUpShapeRenderer : IShapeRenderer {
1111
canvas: Canvas, dataSet: IScatterDataSet, viewPortHandler: ViewPortHandler?,
1212
posX: Float, posY: Float, renderPaint: Paint
1313
) {
14-
val shapeHalf = dataSet.getScatterShapeSize().convertDpToPixel() / 2f
14+
val shapeHalf = dataSet.scatterShapeSize.convertDpToPixel() / 2f
1515

1616
renderPaint.style = Paint.Style.STROKE
1717
renderPaint.strokeWidth = 1f.convertDpToPixel()

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/CircleShapeRenderer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ class CircleShapeRenderer : IShapeRenderer {
1212
canvas: Canvas, dataSet: IScatterDataSet, viewPortHandler: ViewPortHandler?,
1313
posX: Float, posY: Float, renderPaint: Paint
1414
) {
15-
val shapeSize = dataSet.getScatterShapeSize().convertDpToPixel()
15+
val shapeSize = dataSet.scatterShapeSize.convertDpToPixel()
1616
val shapeHalf = shapeSize / 2f
17-
val shapeHoleSizeHalf = dataSet.getScatterShapeHoleRadius().convertDpToPixel()
17+
val shapeHoleSizeHalf = dataSet.scatterShapeHoleRadius.convertDpToPixel()
1818
val shapeHoleSize = shapeHoleSizeHalf * 2f
1919
val shapeStrokeSize = (shapeSize - shapeHoleSize) / 2f
2020
val shapeStrokeSizeHalf = shapeStrokeSize / 2f
2121

22-
val shapeHoleColor = dataSet.getScatterShapeHoleColor()
22+
val shapeHoleColor = dataSet.scatterShapeHoleColor
2323

2424
if (shapeSize > 0.0) {
2525
renderPaint.style = Paint.Style.STROKE

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/CrossShapeRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CrossShapeRenderer : IShapeRenderer {
1111
canvas: Canvas, dataSet: IScatterDataSet, viewPortHandler: ViewPortHandler?,
1212
posX: Float, posY: Float, renderPaint: Paint
1313
) {
14-
val shapeHalf = dataSet.getScatterShapeSize().convertDpToPixel() / 2f
14+
val shapeHalf = dataSet.scatterShapeSize.convertDpToPixel() / 2f
1515

1616
renderPaint.style = Paint.Style.STROKE
1717
renderPaint.strokeWidth = 1f.convertDpToPixel()

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/SquareShapeRenderer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ class SquareShapeRenderer : IShapeRenderer {
1212
canvas: Canvas, dataSet: IScatterDataSet, viewPortHandler: ViewPortHandler?,
1313
posX: Float, posY: Float, renderPaint: Paint
1414
) {
15-
val shapeSize = dataSet.getScatterShapeSize().convertDpToPixel()
15+
val shapeSize = dataSet.scatterShapeSize.convertDpToPixel()
1616
val shapeHalf = shapeSize / 2f
17-
val shapeHoleSizeHalf = dataSet.getScatterShapeHoleRadius().convertDpToPixel()
17+
val shapeHoleSizeHalf = dataSet.scatterShapeHoleRadius.convertDpToPixel()
1818
val shapeHoleSize = shapeHoleSizeHalf * 2f
1919
val shapeStrokeSize = (shapeSize - shapeHoleSize) / 2f
2020
val shapeStrokeSizeHalf = shapeStrokeSize / 2f
2121

22-
val shapeHoleColor = dataSet.getScatterShapeHoleColor()
22+
val shapeHoleColor = dataSet.scatterShapeHoleColor
2323

2424
if (shapeSize > 0.0) {
2525
renderPaint.style = Paint.Style.STROKE

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/TriangleShapeRenderer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ open class TriangleShapeRenderer : IShapeRenderer {
1515
canvas: Canvas, dataSet: IScatterDataSet, viewPortHandler: ViewPortHandler?,
1616
posX: Float, posY: Float, renderPaint: Paint
1717
) {
18-
val shapeSize = dataSet.getScatterShapeSize().convertDpToPixel()
18+
val shapeSize = dataSet.scatterShapeSize.convertDpToPixel()
1919
val shapeHalf = shapeSize / 2f
20-
val shapeHoleSizeHalf = dataSet.getScatterShapeHoleRadius().convertDpToPixel()
20+
val shapeHoleSizeHalf = dataSet.scatterShapeHoleRadius.convertDpToPixel()
2121
val shapeHoleSize = shapeHoleSizeHalf * 2f
2222
val shapeStrokeSize = (shapeSize - shapeHoleSize) / 2f
2323

24-
val shapeHoleColor = dataSet.getScatterShapeHoleColor()
24+
val shapeHoleColor = dataSet.scatterShapeHoleColor
2525

2626
renderPaint.style = Paint.Style.FILL
2727

0 commit comments

Comments
 (0)