Skip to content

Commit ceca160

Browse files
committed
TimeBar Float
XAxis label rotation
1 parent 18aa58a commit ceca160

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ class TimeBarActivity : DemoBase(), OnSeekBarChangeListener {
101101

102102
private fun setData(count: Int) {
103103
val barWidth = 9f
104-
val spaceForBar = 10.0
105-
val values = ArrayList<BarEntryDouble>()
104+
val spaceForBar = 10.0f
105+
val values = ArrayList<BarEntryFloat>()
106106
val sampleValues = getValues(100).map { (it!! * 100).toInt() }
107107

108-
var previousTimeOffset = 0.0 //TIME_OFFSET.toDouble()
108+
var previousTimeOffset = 0f //TIME_OFFSET.toFloat()
109109
for (i in 0..<count) {
110110
Timber.d("add ${sampleValues[i]}s to $previousTimeOffset")
111111
val yValue = sampleValues[i] + previousTimeOffset
112-
val value = BarEntryDouble(
112+
val value = BarEntryFloat(
113113
x = i * spaceForBar,
114-
vals = doubleArrayOf(previousTimeOffset, yValue),
114+
vals = floatArrayOf(previousTimeOffset, yValue),
115115
icon = ResourcesCompat.getDrawable(resources, R.drawable.star, null)
116116
)
117117
values.add(value)
Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package info.appdev.chartexample.formatter
22

3-
import info.appdev.charting.data.BarEntryDouble
43
import info.appdev.charting.data.BarEntryFloat
54
import info.appdev.charting.data.EntryFloat
65
import info.appdev.charting.formatter.IValueFormatter
@@ -14,24 +13,12 @@ class UnixTimeValueFormatter(val format: String = "yyyy-MM-dd'T'HH:mm:ss'Z'") :
1413

1514
// For bar/line values
1615
override fun getFormattedValue(value: Float, entryFloat: EntryFloat?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String {
17-
return when (entryFloat) {
18-
is BarEntryDouble if entryFloat.yValsDouble != null -> {
19-
// High-precision double path
20-
val vals = entryFloat.yValsDouble!!
21-
val start = simpleDateFormat.format(vals.first().toLong())
22-
val end = simpleDateFormat.format(vals.last().toLong())
23-
"$start - $end"
24-
}
25-
26-
is BarEntryFloat if entryFloat.yVals != null -> {
27-
// Float path
28-
val vals = entryFloat.yVals!!
29-
val start = simpleDateFormat.format(vals.first().toLong())
30-
val end = simpleDateFormat.format(vals.last().toLong())
31-
"$start - $end"
32-
}
33-
34-
else -> simpleDateFormat.format(value.toLong())
16+
return if (entryFloat is BarEntryFloat) {
17+
simpleDateFormat.format(entryFloat.yVals?.get(0)!!.toLong()) +
18+
" - " +
19+
simpleDateFormat.format(entryFloat.yVals?.get(entryFloat.yVals?.size!! - 1)!!.toLong())
3520
}
21+
else
22+
simpleDateFormat.format(value.toLong())
3623
}
3724
}

0 commit comments

Comments
 (0)