Skip to content

Commit 148f823

Browse files
committed
Add x to BaseEntry
1 parent 76cebbb commit 148f823

File tree

3 files changed

+64
-61
lines changed

3 files changed

+64
-61
lines changed

chartLib/src/main/kotlin/info/appdev/charting/data/BaseEntry.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import android.graphics.drawable.Drawable
44

55
abstract class BaseEntry<T> where T : Number, T : Comparable<T> {
66

7+
protected lateinit var xBase: T
8+
open var x: T
9+
get() = xBase
10+
set(value) {
11+
xBase = value
12+
}
13+
714
protected lateinit var yBase: T
815
open var y: T
916
get() = yBase
@@ -21,6 +28,11 @@ abstract class BaseEntry<T> where T : Number, T : Comparable<T> {
2128
this.yBase = y
2229
}
2330

31+
constructor(x: T, y: T) {
32+
this.xBase = x
33+
this.yBase = y
34+
}
35+
2436
constructor(y: T, data: Any?) : this(y) {
2537
this.data = data
2638
}
@@ -29,7 +41,20 @@ abstract class BaseEntry<T> where T : Number, T : Comparable<T> {
2941
this.icon = icon
3042
}
3143

32-
constructor(y: T, icon: Drawable?, data: Any?) : this(y) {
44+
constructor(y: T, icon: Drawable?, data: Any?) : this(y = y) {
45+
this.icon = icon
46+
this.data = data
47+
}
48+
49+
constructor(x: T, y: T, data: Any?) : this(x = x, y = y) {
50+
this.data = data
51+
}
52+
53+
constructor(x: T, y: T, icon: Drawable?) : this(x = x, y = y) {
54+
this.icon = icon
55+
}
56+
57+
constructor(x: T, y: T, icon: Drawable?, data: Any?) : this(x = x, y = y) {
3358
this.icon = icon
3459
this.data = data
3560
}

chartLib/src/main/kotlin/info/appdev/charting/data/EntryDouble.kt

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,53 @@ import kotlin.math.abs
1111

1212
open class EntryDouble : BaseEntry<Double>, Parcelable, Serializable {
1313

14-
private var _x: Double = 0.0
15-
open var x: Double
16-
get() = _x
17-
set(value) {
18-
_x = value
19-
}
20-
2114
constructor()
2215

2316
/**
24-
* A Entry represents one single entry in the chart.
17+
* An Entry represents one single entry in the chart.
2518
*
2619
* @param x the x value
2720
* @param y the y value (the actual value of the entry)
2821
*/
29-
constructor(x: Double, y: Double) : super(y) {
30-
this._x = x
31-
}
22+
constructor(x: Double, y: Double) : super(x = x, y = y)
3223

3324
/**
34-
* A Entry represents one single entry in the chart.
25+
* An Entry represents one single entry in the chart.
3526
*
3627
* @param x the x value
3728
* @param y the y value (the actual value of the entry)
3829
* @param data Spot for additional data this Entry represents.
3930
*/
40-
constructor(x: Double, y: Double, data: Any?) : super(y, data) {
41-
this._x = x
42-
}
31+
constructor(x: Double, y: Double, data: Any?) : super(x = x, y = y, data = data)
4332

4433
/**
45-
* A Entry represents one single entry in the chart.
34+
* An Entry represents one single entry in the chart.
4635
*
4736
* @param x the x value
4837
* @param y the y value (the actual value of the entry)
4938
* @param icon icon image
5039
*/
51-
constructor(x: Double, y: Double, icon: Drawable?) : super(y, icon) {
52-
this._x = x
53-
}
40+
constructor(x: Double, y: Double, icon: Drawable?) : super(x = x, y = y, icon = icon)
5441

5542
/**
56-
* A Entry represents one single entry in the chart.
43+
* An Entry represents one single entry in the chart.
5744
*
5845
* @param x the x value
5946
* @param y the y value (the actual value of the entry)
6047
* @param icon icon image
6148
* @param data Spot for additional data this Entry represents.
6249
*/
63-
constructor(x: Double, y: Double, icon: Drawable?, data: Any?) : super(y, icon, data) {
64-
this._x = x
65-
}
50+
constructor(x: Double, y: Double, icon: Drawable?, data: Any?) : super(x = x, y = y, icon = icon, data = data)
6651

6752
/**
6853
* returns an exact copy of the entry
6954
*/
7055
open fun copy(): EntryDouble {
71-
val e = EntryDouble(x, y, data)
56+
val e = EntryDouble(
57+
x = x,
58+
y = y,
59+
data = data
60+
)
7261
return e
7362
}
7463

@@ -77,17 +66,17 @@ open class EntryDouble : BaseEntry<Double>, Parcelable, Serializable {
7766
* are equal in those points, false if not. Does not check by hash-code like
7867
* it's done by the "equals" method.
7968
*/
80-
fun equalTo(e: EntryDouble?): Boolean {
81-
if (e == null)
69+
fun equalTo(entryDouble: EntryDouble?): Boolean {
70+
if (entryDouble == null)
8271
return false
8372

84-
if (e.data !== this.data)
73+
if (entryDouble.data !== this.data)
8574
return false
8675

87-
if (abs((e.x - this.x)) > Utils.DOUBLE_EPSILON)
76+
if (abs((entryDouble.x - this.x)) > Utils.DOUBLE_EPSILON)
8877
return false
8978

90-
if (abs((e.y - this.y)) > Utils.DOUBLE_EPSILON)
79+
if (abs((entryDouble.y - this.y)) > Utils.DOUBLE_EPSILON)
9180
return false
9281

9382
return true
@@ -124,7 +113,7 @@ open class EntryDouble : BaseEntry<Double>, Parcelable, Serializable {
124113
}
125114

126115
protected constructor(`in`: Parcel) {
127-
this._x = `in`.readDouble()
116+
this.x = `in`.readDouble()
128117
this.yBase = `in`.readDouble()
129118
if (`in`.readInt() == 1) {
130119
this.data = if (Build.VERSION.SDK_INT >= 33) {

chartLib/src/main/kotlin/info/appdev/charting/data/EntryFloat.kt

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,53 @@ import kotlin.math.abs
1515
*/
1616
open class EntryFloat : BaseEntry<Float>, Parcelable, Serializable {
1717

18-
private var _x: Float = 0f
19-
open var x: Float
20-
get() = _x
21-
set(value) {
22-
_x = value
23-
}
24-
2518
constructor()
2619

2720
/**
28-
* A EntryFloat represents one single entry in the chart.
21+
* An EntryFloat represents one single entry in the chart.
2922
*
3023
* @param x the x value
3124
* @param y the y value (the actual value of the entry)
3225
*/
33-
constructor(x: Float, y: Float) : super(y) {
34-
this._x = x
35-
}
26+
constructor(x: Float, y: Float) : super(x = x, y = y)
3627

3728
/**
38-
* A EntryFloat represents one single entry in the chart.
29+
* An EntryFloat represents one single entry in the chart.
3930
*
4031
* @param x the x value
4132
* @param y the y value (the actual value of the entry)
4233
* @param data Spot for additional data this Entry represents.
4334
*/
44-
constructor(x: Float, y: Float, data: Any?) : super(y, data) {
45-
this._x = x
46-
}
35+
constructor(x: Float, y: Float, data: Any?) : super(x = x, y = y, data = data)
4736

4837
/**
49-
* A EntryFloat represents one single entry in the chart.
38+
* An EntryFloat represents one single entry in the chart.
5039
*
5140
* @param x the x value
5241
* @param y the y value (the actual value of the entry)
5342
* @param icon icon image
5443
*/
55-
constructor(x: Float, y: Float, icon: Drawable?) : super(y, icon) {
56-
this._x = x
57-
}
44+
constructor(x: Float, y: Float, icon: Drawable?) : super(x = x, y = y, icon = icon)
5845

5946
/**
60-
* A EntryFloat represents one single entry in the chart.
47+
* An EntryFloat represents one single entry in the chart.
6148
*
6249
* @param x the x value
6350
* @param y the y value (the actual value of the entry)
6451
* @param icon icon image
6552
* @param data Spot for additional data this EntryFloat represents.
6653
*/
67-
constructor(x: Float, y: Float, icon: Drawable?, data: Any?) : super(y, icon, data) {
68-
this._x = x
69-
}
54+
constructor(x: Float, y: Float, icon: Drawable?, data: Any?) : super(x = x, y = y, icon = icon, data = data)
7055

7156
/**
7257
* returns an exact copy of the entry
7358
*/
7459
open fun copy(): EntryFloat {
75-
val e = EntryFloat(x, y, data)
60+
val e = EntryFloat(
61+
x = x,
62+
y = y,
63+
data = data
64+
)
7665
return e
7766
}
7867

@@ -81,17 +70,17 @@ open class EntryFloat : BaseEntry<Float>, Parcelable, Serializable {
8170
* are equal in those points, false if not. Does not check by hash-code like
8271
* it's done by the "equals" method.
8372
*/
84-
fun equalTo(e: EntryFloat?): Boolean {
85-
if (e == null)
73+
fun equalTo(entryFloat: EntryFloat?): Boolean {
74+
if (entryFloat == null)
8675
return false
8776

88-
if (e.data !== this.data)
77+
if (entryFloat.data !== this.data)
8978
return false
9079

91-
if (abs((e.x - this.x).toDouble()) > Utils.FLOAT_EPSILON)
80+
if (abs((entryFloat.x - this.x).toDouble()) > Utils.FLOAT_EPSILON)
9281
return false
9382

94-
if (abs((e.y - this.y).toDouble()) > Utils.FLOAT_EPSILON)
83+
if (abs((entryFloat.y - this.y).toDouble()) > Utils.FLOAT_EPSILON)
9584
return false
9685

9786
return true
@@ -128,7 +117,7 @@ open class EntryFloat : BaseEntry<Float>, Parcelable, Serializable {
128117
}
129118

130119
protected constructor(`in`: Parcel) {
131-
this._x = `in`.readFloat()
120+
this.x = `in`.readFloat()
132121
this.yBase = `in`.readFloat()
133122
if (`in`.readInt() == 1) {
134123
this.data = if (Build.VERSION.SDK_INT >= 33) {

0 commit comments

Comments
 (0)