Skip to content

Commit 46d5ed6

Browse files
authored
Merge pull request #752 from AppDevNext/EntryGeneric
Entry is generic to have optional higher precision with Double
2 parents 5231bb7 + c3470d6 commit 46d5ed6

File tree

133 files changed

+1003
-746
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+1003
-746
lines changed

app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import info.appdev.chartexample.notimportant.DemoBase
1616
import info.appdev.charting.components.XAxis.XAxisPosition
1717
import info.appdev.charting.data.BarData
1818
import info.appdev.charting.data.BarDataSet
19-
import info.appdev.charting.data.BarEntry
19+
import info.appdev.charting.data.BarEntryFloat
2020
import info.appdev.charting.interfaces.datasets.IBarDataSet
2121
import info.appdev.charting.utils.ColorTemplate
2222

@@ -62,13 +62,13 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener {
6262
binding.tvXMax.text = binding.seekBarX.progress.toString()
6363
binding.tvYMax.text = binding.seekBarY.progress.toString()
6464

65-
val values = ArrayList<BarEntry>()
65+
val values = ArrayList<BarEntryFloat>()
6666
val sampleValues = getValues(100)
6767

6868
for (i in 0..<binding.seekBarX.progress) {
6969
val multi = (binding.seekBarY.progress + 1).toFloat()
7070
val `val` = (sampleValues[i]!!.toFloat() * multi) + multi / 3
71-
values.add(BarEntry(i.toFloat(), `val`))
71+
values.add(BarEntryFloat(i.toFloat(), `val`))
7272
}
7373

7474
val set1: BarDataSet

app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import info.appdev.charting.components.YAxis.AxisDependency
2525
import info.appdev.charting.components.YAxis.YAxisLabelPosition
2626
import info.appdev.charting.data.BarData
2727
import info.appdev.charting.data.BarDataSet
28-
import info.appdev.charting.data.BarEntry
29-
import info.appdev.charting.data.Entry
28+
import info.appdev.charting.data.BarEntryFloat
29+
import info.appdev.charting.data.EntryFloat
3030
import info.appdev.charting.formatter.IAxisValueFormatter
3131
import info.appdev.charting.highlight.Highlight
3232
import info.appdev.charting.interfaces.datasets.IBarDataSet
@@ -122,17 +122,17 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect
122122
private fun setData(count: Int, range: Float) {
123123
val start = 1f
124124

125-
val values = ArrayList<BarEntry>()
125+
val values = ArrayList<BarEntryFloat>()
126126
val sampleValues = getValues(100)
127127

128128
var i = start.toInt()
129129
while (i < start + count) {
130130
val `val` = (sampleValues[i]!!.toFloat() * (range + 1))
131131

132132
if (`val` * 100 < 25) {
133-
values.add(BarEntry(i.toFloat(), `val`, ResourcesCompat.getDrawable(resources, R.drawable.star, null)))
133+
values.add(BarEntryFloat(i.toFloat(), `val`, ResourcesCompat.getDrawable(resources, R.drawable.star, null)))
134134
} else {
135-
values.add(BarEntry(i.toFloat(), `val`))
135+
values.add(BarEntryFloat(i.toFloat(), `val`))
136136
}
137137
i++
138138
}
@@ -281,10 +281,10 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect
281281

282282
private val onValueSelectedRectF = RectF()
283283

284-
override fun onValueSelected(entry: Entry, highlight: Highlight) {
284+
override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) {
285285
val bounds = onValueSelectedRectF
286-
binding.chart1.getBarBounds(entry as BarEntry, bounds)
287-
val position = binding.chart1.getPosition(entry, AxisDependency.LEFT)
286+
binding.chart1.getBarBounds(entryFloat as BarEntryFloat, bounds)
287+
val position = binding.chart1.getPosition(entryFloat, AxisDependency.LEFT)
288288

289289
Timber.i("bounds $bounds")
290290
Timber.i("position = $position")

app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import info.appdev.charting.components.AxisBase
1919
import info.appdev.charting.components.Legend
2020
import info.appdev.charting.data.BarData
2121
import info.appdev.charting.data.BarDataSet
22-
import info.appdev.charting.data.BarEntry
23-
import info.appdev.charting.data.Entry
22+
import info.appdev.charting.data.BarEntryFloat
23+
import info.appdev.charting.data.EntryFloat
2424
import info.appdev.charting.formatter.IAxisValueFormatter
2525
import info.appdev.charting.formatter.LargeValueFormatter
2626
import info.appdev.charting.highlight.Highlight
@@ -110,19 +110,19 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar
110110
binding.tvXMax.text = String.format(Locale.ENGLISH, "%d-%d", startYear, endYear)
111111
binding.tvYMax.text = binding.seekBarY.progress.toString()
112112

113-
val values1 = ArrayList<BarEntry>()
114-
val values2 = ArrayList<BarEntry>()
115-
val values3 = ArrayList<BarEntry>()
116-
val values4 = ArrayList<BarEntry>()
113+
val values1 = ArrayList<BarEntryFloat>()
114+
val values2 = ArrayList<BarEntryFloat>()
115+
val values3 = ArrayList<BarEntryFloat>()
116+
val values4 = ArrayList<BarEntryFloat>()
117117

118118
val randomMultiplier = binding.seekBarY.progress * 100000f
119119
val sampleValues = getValues(100 + 2)
120120

121121
for (i in startYear..<endYear) {
122-
values1.add(BarEntry(i.toFloat(), (sampleValues[i - startYear]!!.toFloat() * randomMultiplier)))
123-
values2.add(BarEntry(i.toFloat(), (sampleValues[i - startYear + 1]!!.toFloat() * randomMultiplier)))
124-
values3.add(BarEntry(i.toFloat(), (sampleValues[i - startYear + 2]!!.toFloat() * randomMultiplier)))
125-
values4.add(BarEntry(i.toFloat(), (sampleValues[i - startYear]!!.toFloat() * randomMultiplier)))
122+
values1.add(BarEntryFloat(i.toFloat(), (sampleValues[i - startYear]!!.toFloat() * randomMultiplier)))
123+
values2.add(BarEntryFloat(i.toFloat(), (sampleValues[i - startYear + 1]!!.toFloat() * randomMultiplier)))
124+
values3.add(BarEntryFloat(i.toFloat(), (sampleValues[i - startYear + 2]!!.toFloat() * randomMultiplier)))
125+
values4.add(BarEntryFloat(i.toFloat(), (sampleValues[i - startYear]!!.toFloat() * randomMultiplier)))
126126
}
127127

128128
val set1: BarDataSet
@@ -247,8 +247,8 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar
247247

248248
override fun onStopTrackingTouch(seekBar: SeekBar?) = Unit
249249

250-
override fun onValueSelected(entry: Entry, highlight: Highlight) {
251-
Timber.i("Selected: $entry, dataSet: ${highlight.dataSetIndex}")
250+
override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) {
251+
Timber.i("Selected: $entryFloat, dataSet: ${highlight.dataSetIndex}")
252252
}
253253

254254
override fun onNothingSelected() = Unit

app/src/main/kotlin/info/appdev/chartexample/BarChartActivitySinus.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import info.appdev.charting.components.Legend
1717
import info.appdev.charting.components.Legend.LegendForm
1818
import info.appdev.charting.data.BarData
1919
import info.appdev.charting.data.BarDataSet
20-
import info.appdev.charting.data.BarEntry
20+
import info.appdev.charting.data.BarEntryFloat
2121
import info.appdev.charting.utils.loadBarEntriesFromAssets
2222

2323
class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener {
2424

25-
private lateinit var dataSinus: MutableList<BarEntry>
25+
private lateinit var dataSinus: MutableList<BarEntryFloat>
2626

2727
private lateinit var binding: ActivityBarchartSinusBinding
2828

@@ -87,7 +87,7 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener {
8787
}
8888

8989
private fun setData(count: Int) {
90-
val entries = ArrayList<BarEntry>()
90+
val entries = ArrayList<BarEntryFloat>()
9191

9292
for (i in 0..<count) {
9393
entries.add(dataSinus[i])

app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import info.appdev.charting.components.AxisBase
1212
import info.appdev.charting.components.XAxis.XAxisPosition
1313
import info.appdev.charting.data.BarData
1414
import info.appdev.charting.data.BarDataSet
15-
import info.appdev.charting.data.BarEntry
16-
import info.appdev.charting.data.Entry
15+
import info.appdev.charting.data.BarEntryFloat
16+
import info.appdev.charting.data.EntryFloat
1717
import info.appdev.charting.formatter.IAxisValueFormatter
1818
import info.appdev.charting.formatter.IValueFormatter
1919
import info.appdev.charting.utils.ViewPortHandler
@@ -87,15 +87,15 @@ class BarChartPositiveNegative : DemoBase() {
8787
}
8888

8989
private fun setData(dataList: MutableList<Data>) {
90-
val values = ArrayList<BarEntry>()
90+
val values = ArrayList<BarEntryFloat>()
9191
val colors: MutableList<Int> = ArrayList()
9292

9393
val green = Color.rgb(110, 190, 102)
9494
val red = Color.rgb(211, 74, 88)
9595

9696
for (i in dataList.indices) {
9797
val d = dataList[i]
98-
val entry = BarEntry(d.xValue, d.yValue)
98+
val entry = BarEntryFloat(d.xValue, d.yValue)
9999
values.add(entry)
100100

101101
// specific colors
@@ -136,7 +136,7 @@ class BarChartPositiveNegative : DemoBase() {
136136
private class ValueFormatter : IValueFormatter {
137137
private val mFormat: DecimalFormat = DecimalFormat("######.0")
138138

139-
override fun getFormattedValue(value: Float, entry: Entry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String {
139+
override fun getFormattedValue(value: Float, entryFloat: EntryFloat?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String {
140140
return mFormat.format(value.toDouble())
141141
}
142142
}

app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import info.appdev.charting.components.Legend
1919
import info.appdev.charting.components.XAxis
2020
import info.appdev.charting.data.BubbleData
2121
import info.appdev.charting.data.BubbleDataSet
22-
import info.appdev.charting.data.BubbleEntry
23-
import info.appdev.charting.data.Entry
22+
import info.appdev.charting.data.BubbleEntryFloat
23+
import info.appdev.charting.data.EntryFloat
2424
import info.appdev.charting.highlight.Highlight
2525
import info.appdev.charting.interfaces.datasets.IBubbleDataSet
2626
import info.appdev.charting.listener.OnChartValueSelectedListener
@@ -82,29 +82,29 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel
8282
binding.tvXMax.text = count.toString()
8383
binding.tvYMax.text = range.toString()
8484

85-
val values1 = ArrayList<BubbleEntry>()
86-
val values2 = ArrayList<BubbleEntry>()
87-
val values3 = ArrayList<BubbleEntry>()
85+
val values1 = ArrayList<BubbleEntryFloat>()
86+
val values2 = ArrayList<BubbleEntryFloat>()
87+
val values3 = ArrayList<BubbleEntryFloat>()
8888
val sampleValues = getValues(100)
8989

9090
for (i in 0..<count) {
9191
values1.add(
92-
BubbleEntry(
92+
BubbleEntryFloat(
9393
i.toFloat(),
9494
(sampleValues[i + 1]!! * range).toFloat(),
9595
(sampleValues[i]!!.toFloat() * range),
9696
ResourcesCompat.getDrawable(resources, R.drawable.star, null)
9797
)
9898
)
9999
values2.add(
100-
BubbleEntry(
100+
BubbleEntryFloat(
101101
i.toFloat(),
102102
(sampleValues[i + 2]!! * range).toFloat(),
103103
(sampleValues[i + 1]!!.toFloat() * range),
104104
ResourcesCompat.getDrawable(resources, R.drawable.star, null)
105105
)
106106
)
107-
values3.add(BubbleEntry(i.toFloat(), (sampleValues[i]!! * range).toFloat(), (sampleValues[i + 2]!!.toFloat() * range)))
107+
values3.add(BubbleEntryFloat(i.toFloat(), (sampleValues[i]!! * range).toFloat(), (sampleValues[i + 2]!!.toFloat() * range)))
108108
}
109109

110110
// create a dataset and give it a type
@@ -211,8 +211,8 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel
211211
saveToGallery(binding.chart1, "BubbleChartActivity")
212212
}
213213

214-
override fun onValueSelected(entry: Entry, highlight: Highlight) {
215-
Timber.i("Value: ${entry.y}, xIndex: ${entry.x}, DataSet index: ${highlight.dataSetIndex}")
214+
override fun onValueSelected(entryFloat: EntryFloat, highlight: Highlight) {
215+
Timber.i("Value: ${entryFloat.y}, xIndex: ${entryFloat.x}, DataSet index: ${highlight.dataSetIndex}")
216216
}
217217

218218
override fun onNothingSelected() = Unit

app/src/main/kotlin/info/appdev/chartexample/CandleStickChartActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import info.appdev.charting.components.XAxis.XAxisPosition
2020
import info.appdev.charting.components.YAxis.AxisDependency
2121
import info.appdev.charting.data.CandleData
2222
import info.appdev.charting.data.CandleDataSet
23-
import info.appdev.charting.data.CandleEntry
23+
import info.appdev.charting.data.CandleEntryFloat
2424

2525
class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener {
2626

@@ -74,7 +74,7 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener {
7474

7575
binding.chart1.resetTracking()
7676

77-
val values = ArrayList<CandleEntry>()
77+
val values = ArrayList<CandleEntryFloat>()
7878
val sampleValues = getValues(100)
7979

8080
for (i in 0..<progress) {
@@ -90,7 +90,7 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener {
9090
val even = i % 2 == 0
9191

9292
values.add(
93-
CandleEntry(
93+
CandleEntryFloat(
9494
i.toFloat(), `val` + high,
9595
`val` - low,
9696
if (even) `val` + open else `val` - open,

app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import info.appdev.charting.components.XAxis.XAxisPosition
1616
import info.appdev.charting.components.YAxis
1717
import info.appdev.charting.data.BarData
1818
import info.appdev.charting.data.BarDataSet
19-
import info.appdev.charting.data.BarEntry
19+
import info.appdev.charting.data.BarEntryFloat
2020
import info.appdev.charting.data.BubbleData
2121
import info.appdev.charting.data.BubbleDataSet
22-
import info.appdev.charting.data.BubbleEntry
22+
import info.appdev.charting.data.BubbleEntryFloat
2323
import info.appdev.charting.data.CandleData
2424
import info.appdev.charting.data.CandleDataSet
25-
import info.appdev.charting.data.CandleEntry
25+
import info.appdev.charting.data.CandleEntryFloat
2626
import info.appdev.charting.data.CombinedData
27-
import info.appdev.charting.data.Entry
27+
import info.appdev.charting.data.EntryFloat
2828
import info.appdev.charting.data.LineData
2929
import info.appdev.charting.data.LineDataSet
3030
import info.appdev.charting.data.ScatterData
@@ -100,9 +100,9 @@ class CombinedChartActivity : DemoBase() {
100100
private fun generateLineData(): LineData {
101101
val d = LineData()
102102

103-
val entries = ArrayList<Entry>()
103+
val entries = ArrayList<EntryFloat>()
104104

105-
for (index in 0..<sampleCount) entries.add(Entry(index + 0.5f, values[index]!!.toFloat() * 15 + 5))
105+
for (index in 0..<sampleCount) entries.add(EntryFloat(index + 0.5f, values[index]!!.toFloat() * 15 + 5))
106106

107107
val set = LineDataSet(entries, "Line DataSet")
108108
set.color = Color.rgb(240, 238, 70)
@@ -122,14 +122,14 @@ class CombinedChartActivity : DemoBase() {
122122
}
123123

124124
private fun generateBarData(): BarData {
125-
val entries1 = ArrayList<BarEntry>()
126-
val entries2 = ArrayList<BarEntry>()
125+
val entries1 = ArrayList<BarEntryFloat>()
126+
val entries2 = ArrayList<BarEntryFloat>()
127127

128128
for (index in 0..<sampleCount) {
129-
entries1.add(BarEntry(0f, values[index]!!.toFloat() * 25 + 25))
129+
entries1.add(BarEntryFloat(0f, values[index]!!.toFloat() * 25 + 25))
130130

131131
// stacked
132-
entries2.add(BarEntry(0f, floatArrayOf(values[index]!!.toFloat() * 13 + 12, values[index]!!.toFloat() * 13 + 12)))
132+
entries2.add(BarEntryFloat(0f, floatArrayOf(values[index]!!.toFloat() * 13 + 12, values[index]!!.toFloat() * 13 + 12)))
133133
}
134134

135135
val set1 = BarDataSet(entries1, "Bar 1")
@@ -162,11 +162,11 @@ class CombinedChartActivity : DemoBase() {
162162
private fun generateScatterData(): ScatterData {
163163
val d = ScatterData()
164164

165-
val entries = ArrayList<Entry>()
165+
val entries = ArrayList<EntryFloat>()
166166

167167
var index = 0f
168168
while (index < sampleCount) {
169-
entries.add(Entry(index + 0.25f, values[(index * 2).roundToInt()]!!.toFloat() * 10 + 55))
169+
entries.add(EntryFloat(index + 0.25f, values[(index * 2).roundToInt()]!!.toFloat() * 10 + 55))
170170
index += 0.5f
171171
}
172172

@@ -183,11 +183,11 @@ class CombinedChartActivity : DemoBase() {
183183
private fun generateCandleData(): CandleData {
184184
val d = CandleData()
185185

186-
val entries = ArrayList<CandleEntry>()
186+
val entries = ArrayList<CandleEntryFloat>()
187187

188188
var index = 0
189189
while (index < sampleCount) {
190-
entries.add(CandleEntry(index + 1f, 90f, 70f, 85f, 75f))
190+
entries.add(CandleEntryFloat(index + 1f, 90f, 70f, 85f, 75f))
191191
index += 2
192192
}
193193

@@ -205,12 +205,12 @@ class CombinedChartActivity : DemoBase() {
205205
private fun generateBubbleData(): BubbleData {
206206
val bd = BubbleData()
207207

208-
val entries = ArrayList<BubbleEntry>()
208+
val entries = ArrayList<BubbleEntryFloat>()
209209

210210
for (index in 0..<sampleCount) {
211211
val y = values[index]!!.toFloat() * 10 + 105
212212
val size = values[index]!!.toFloat() * 100 + 105
213-
entries.add(BubbleEntry(index + 0.5f, y, size))
213+
entries.add(BubbleEntryFloat(index + 0.5f, y, size))
214214
}
215215

216216
val set = BubbleDataSet(entries, "Bubble DataSet")

0 commit comments

Comments
 (0)