Skip to content

Commit 05566f3

Browse files
authored
Merge pull request #683 from AppDevNext/Revert
Revert EntryDouble and FixHighlightInCombinedChart
2 parents f05c0ec + 0aecddf commit 05566f3

23 files changed

Lines changed: 92 additions & 227 deletions

chartLib/src/main/kotlin/info/appdev/charting/charts/BarChart.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ open class BarChart : BarLineChartBase<BarData>, BarDataProvider {
5959

6060
dataRenderer = BarChartRenderer(this, mAnimator, viewPortHandler, mDrawRoundedBars, mRoundedBarRadius)
6161

62-
highlighter = BarHighlighter(this)
62+
setHighlighter(BarHighlighter(this))
6363

6464
xAxis.spaceMin = 0.5f
6565
xAxis.spaceMax = 0.5f

chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ abstract class BarLineChartBase<T : BarLineScatterCandleBubbleData<IBarLineScatt
187187

188188
xAxisRenderer = XAxisRenderer(viewPortHandler, mXAxis, mLeftAxisTransformer)
189189

190-
if (highlighter == null) // otherwise it overwrites highlighter from successors
191-
highlighter = ChartHighlighter(this)
190+
setHighlighter(ChartHighlighter(this))
192191

193192
chartTouchListener = BarLineChartTouchListener(this, viewPortHandler.matrixTouch, 3f)
194193

chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import info.appdev.charting.data.ChartData
2626
import info.appdev.charting.data.Entry
2727
import info.appdev.charting.formatter.DefaultValueFormatter
2828
import info.appdev.charting.formatter.IValueFormatter
29+
import info.appdev.charting.highlight.ChartHighlighter
2930
import info.appdev.charting.highlight.Highlight
3031
import info.appdev.charting.highlight.IHighlighter
3132
import info.appdev.charting.interfaces.dataprovider.base.IBaseProvider
@@ -151,6 +152,7 @@ abstract class Chart<T : ChartData<out IDataSet<out Entry>>> : ViewGroup, IBaseP
151152
protected var dataRenderer: DataRenderer? = null
152153

153154
var highlighter: IHighlighter? = null
155+
protected set
154156

155157
/**
156158
* Returns the ViewPortHandler of the chart that is responsible for the
@@ -1044,6 +1046,10 @@ abstract class Chart<T : ChartData<out IDataSet<out Entry>>> : ViewGroup, IBaseP
10441046
/**
10451047
* Returns a recyclable PointF instance.
10461048
*/
1049+
fun setHighlighter(highlighter: ChartHighlighter<*>?) {
1050+
this.highlighter = highlighter
1051+
}
1052+
10471053
override val centerOfView: PointF
10481054
get() = this.center
10491055

chartLib/src/main/kotlin/info/appdev/charting/charts/CombinedChart.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ open class CombinedChart : BarLineChartBase<CombinedData>, CombinedDataProvider
372372
get() = this@CombinedChart.candleData
373373
}
374374

375-
highlighter = CombinedHighlighter(this, barDataProvider)
375+
setHighlighter(CombinedHighlighter(this, barDataProvider))
376376

377377
// Old default behaviour
378378
this@CombinedChart.isHighlightFullBar = true

chartLib/src/main/kotlin/info/appdev/charting/charts/HorizontalBarChart.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ open class HorizontalBarChart : BarChart {
4444
mRightAxisTransformer = TransformerHorizontalBarChart(viewPortHandler)
4545

4646
dataRenderer = HorizontalBarChartRenderer(this, mAnimator, viewPortHandler)
47-
highlighter = HorizontalBarHighlighter(this)
47+
setHighlighter(HorizontalBarHighlighter(this))
4848

4949
axisRendererLeft = YAxisRendererHorizontalBarChart(viewPortHandler, mAxisLeft, mLeftAxisTransformer)
5050
axisRendererRight = YAxisRendererHorizontalBarChart(viewPortHandler, mAxisRight, mRightAxisTransformer)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataS
77
/**
88
* Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart.
99
*/
10-
abstract class BarLineScatterCandleBubbleDataSet<T : BaseEntry<Float>>(yVals: MutableList<T>, label: String) :
10+
abstract class BarLineScatterCandleBubbleDataSet<T : Entry>(yVals: MutableList<T>, label: String) :
1111
DataSet<T>(yVals, label), IBarLineScatterCandleBubbleDataSet<T> {
1212
/**
1313
* Sets the color that is used for drawing the highlight indicators.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import info.appdev.charting.utils.convertDpToPixel
1919
* This is the base dataset of all DataSets. It's purpose is to implement critical methods
2020
* provided by the IDataSet interface.
2121
*/
22-
abstract class BaseDataSet<T : BaseEntry<Float>>() : IDataSet<T> {
22+
abstract class BaseDataSet<T : Entry>() : IDataSet<T> {
2323
/**
2424
* List representing all colors that are used for this DataSet
2525
*/

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

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,34 @@ package info.appdev.charting.data
22

33
import android.graphics.drawable.Drawable
44

5-
abstract class BaseEntry<T> where T : Number, T : Comparable<T> {
5+
abstract class BaseEntry {
66

7-
protected var yBase: T? = null
8-
protected var xBase: T? = null
9-
10-
open var y: T
11-
get() = yBase ?: throw IllegalStateException("y not initialized")
7+
protected var yBase: Float = 0f
8+
open var y: Float
9+
get() = yBase
1210
set(value) {
1311
yBase = value
1412
}
1513

16-
open var x: T
17-
get() = xBase ?: throw IllegalStateException("x not initialized")
18-
set(value) {
19-
xBase = value
20-
}
21-
2214
var data: Any? = null
2315

2416
var icon: Drawable? = null
2517

2618
constructor()
2719

28-
constructor(y: T) {
29-
this.yBase = y
30-
}
31-
32-
constructor(y: T, data: Any?) : this(y) {
33-
this.data = data
34-
}
35-
36-
constructor(y: T, icon: Drawable?) : this(y) {
37-
this.icon = icon
38-
}
39-
40-
constructor(y: T, icon: Drawable?, data: Any?) : this(y) {
41-
this.icon = icon
42-
this.data = data
43-
}
44-
45-
/**
46-
* A Entry represents one single entry in the chart.
47-
*
48-
* @param x the x value
49-
* @param y the y value (the actual value of the entry)
50-
*/
51-
constructor(x: T, y: T) {
52-
this.xBase = x
20+
constructor(y: Float) {
5321
this.yBase = y
5422
}
5523

56-
/**
57-
* A Entry represents one single entry in the chart.
58-
*
59-
* @param x the x value
60-
* @param y the y value (the actual value of the entry)
61-
* @param data Spot for additional data this Entry represents.
62-
*/
63-
constructor(x: T, y: T, data: Any?) {
64-
this.xBase = x
65-
this.yBase = y
24+
constructor(y: Float, data: Any?) : this(y) {
6625
this.data = data
6726
}
6827

69-
/**
70-
* A Entry represents one single entry in the chart.
71-
*
72-
* @param x the x value
73-
* @param y the y value (the actual value of the entry)
74-
* @param icon icon image
75-
*/
76-
constructor(x: T, y: T, icon: Drawable?) {
77-
this.xBase = x
78-
this.yBase = y
28+
constructor(y: Float, icon: Drawable?) : this(y) {
7929
this.icon = icon
8030
}
8131

82-
/**
83-
* A Entry represents one single entry in the chart.
84-
*
85-
* @param x the x value
86-
* @param y the y value (the actual value of the entry)
87-
* @param icon icon image
88-
* @param data Spot for additional data this Entry represents.
89-
*/
90-
constructor(x: T, y: T, icon: Drawable?, data: Any?) {
91-
this.xBase = x
92-
this.yBase = y
32+
constructor(y: Float, icon: Drawable?, data: Any?) : this(y) {
9333
this.icon = icon
9434
this.data = data
9535
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ abstract class ChartData<T : IDataSet<out Entry>> : Serializable {
446446
}
447447

448448
val dataSet: IDataSet<*> = dataSets[dataSetIndex]
449-
val entry = dataSet.getEntryForXValue(xValue, Float.NaN) as? Entry ?: return false
449+
val entry: Entry = dataSet.getEntryForXValue(xValue, Float.NaN) ?: return false
450450

451451
return removeEntry(entry, dataSetIndex)
452452
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlin.math.abs
1010
* groups of values inside the Chart (e.g. the values for a specific line in the
1111
* LineChart, or the values of a specific group of bars in the BarChart).
1212
*/
13-
abstract class DataSet<T : BaseEntry<Float>>(
13+
abstract class DataSet<T : Entry>(
1414
protected var mEntries: MutableList<T>,
1515
label: String = ""
1616
) : BaseDataSet<T>(label), Serializable {
@@ -219,9 +219,9 @@ abstract class DataSet<T : BaseEntry<Float>>(
219219
while (low < high) {
220220
val m = low + (high - low) / 2
221221

222-
val currentEntry: T = mEntries[m]
222+
val currentEntry: Entry = mEntries[m]
223223

224-
val nextEntry: T = mEntries[m + 1]
224+
val nextEntry: Entry = mEntries[m + 1]
225225

226226
val d1 = currentEntry.x - xValue
227227
val d2 = nextEntry.x - xValue
@@ -251,7 +251,7 @@ abstract class DataSet<T : BaseEntry<Float>>(
251251
closest = high
252252
}
253253

254-
val closestEntry: T = mEntries[closest]
254+
val closestEntry: Entry = mEntries[closest]
255255
val closestXValue = closestEntry.x
256256
if (rounding == Rounding.UP) {
257257
// If rounding up, and found x-value is lower than specified x, and we can go upper...

0 commit comments

Comments
 (0)