mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-29 11:11:44 +01:00
Fixes the use of decimals on Notification's chart
This commit is contained in:
parent
c606212043
commit
75dc55858c
@ -193,6 +193,8 @@ class UserReactionsViewModel(val account: Account) : ViewModel() {
|
||||
val todaysReactionCount = _reactions.map { showCount(it[today()]) }.distinctUntilChanged()
|
||||
val todaysZapAmount = _zaps.map { showAmountAxis(it[today()]) }.distinctUntilChanged()
|
||||
|
||||
var shouldShowDecimalsInAxis = false
|
||||
|
||||
fun formatDate(createAt: Long): String {
|
||||
return sdf.format(
|
||||
Instant.ofEpochSecond(createAt)
|
||||
@ -334,10 +336,28 @@ class UserReactionsViewModel(val account: Account) : ViewModel() {
|
||||
val chartEntryModelProducer1 = ChartEntryModelProducer(listOfCountCurves).getModel()
|
||||
val chartEntryModelProducer2 = ChartEntryModelProducer(listOfValueCurves).getModel()
|
||||
|
||||
this.shouldShowDecimalsInAxis = shouldShowDecimals(chartEntryModelProducer2.minY, chartEntryModelProducer2.maxY)
|
||||
|
||||
this._axisLabels.emit(listOf(6, 5, 4, 3, 2, 1, 0).map { displayAxisFormatter.format(now.minusSeconds(day * it)) })
|
||||
this._chartModel.emit(chartEntryModelProducer1.plus(chartEntryModelProducer2))
|
||||
}
|
||||
|
||||
// determine if the min max are so close that they render to the same number.
|
||||
fun shouldShowDecimals(min: Float, max: Float): Boolean {
|
||||
val step = (max - min) / 8
|
||||
|
||||
var previous = showAmountAxis(min.toBigDecimal())
|
||||
for (i in 1..7) {
|
||||
val current = showAmountAxis((min + (i * step)).toBigDecimal())
|
||||
if (previous == current) {
|
||||
return true
|
||||
}
|
||||
previous = current
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
var collectorJob: Job? = null
|
||||
|
||||
init {
|
||||
|
@ -55,6 +55,7 @@ import com.vitorpamplona.amethyst.ui.note.OneKilo
|
||||
import com.vitorpamplona.amethyst.ui.note.OneMega
|
||||
import com.vitorpamplona.amethyst.ui.note.UserReactionsRow
|
||||
import com.vitorpamplona.amethyst.ui.note.UserReactionsViewModel
|
||||
import com.vitorpamplona.amethyst.ui.note.showAmount
|
||||
import com.vitorpamplona.amethyst.ui.note.showCount
|
||||
import com.vitorpamplona.amethyst.ui.screen.NotificationViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.RefresheableCardView
|
||||
@ -224,6 +225,7 @@ private fun ObserveAndShowChart(
|
||||
) {
|
||||
val axisModel = model.axisLabels.collectAsStateWithLifecycle()
|
||||
val chartModel by model.chartModel.collectAsStateWithLifecycle()
|
||||
|
||||
chartModel?.let {
|
||||
Chart(
|
||||
chart = remember(lineChartCount, lineChartZaps) {
|
||||
@ -235,7 +237,7 @@ private fun ObserveAndShowChart(
|
||||
),
|
||||
endAxis = rememberEndAxis(
|
||||
label = axisLabelComponent(color = BitcoinOrange),
|
||||
valueFormatter = AmountAxisValueFormatter()
|
||||
valueFormatter = AmountAxisValueFormatter(model.shouldShowDecimalsInAxis)
|
||||
),
|
||||
bottomAxis = rememberBottomAxis(
|
||||
valueFormatter = LabelValueFormatter(axisModel)
|
||||
@ -265,12 +267,16 @@ class CountAxisValueFormatter() : AxisValueFormatter<AxisPosition.Vertical.Start
|
||||
}
|
||||
|
||||
@Stable
|
||||
class AmountAxisValueFormatter() : AxisValueFormatter<AxisPosition.Vertical.End> {
|
||||
class AmountAxisValueFormatter(val showDecimals: Boolean) : AxisValueFormatter<AxisPosition.Vertical.End> {
|
||||
override fun formatValue(
|
||||
value: Float,
|
||||
chartValues: ChartValues
|
||||
): String {
|
||||
return showAmountAxis(value.toBigDecimal())
|
||||
return if (showDecimals) {
|
||||
showAmount(value.toBigDecimal())
|
||||
} else {
|
||||
showAmountAxis(value.toBigDecimal())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user