Fixes the use of decimals on Notification's chart
This commit is contained in:
@@ -193,6 +193,8 @@ class UserReactionsViewModel(val account: Account) : ViewModel() {
|
|||||||
val todaysReactionCount = _reactions.map { showCount(it[today()]) }.distinctUntilChanged()
|
val todaysReactionCount = _reactions.map { showCount(it[today()]) }.distinctUntilChanged()
|
||||||
val todaysZapAmount = _zaps.map { showAmountAxis(it[today()]) }.distinctUntilChanged()
|
val todaysZapAmount = _zaps.map { showAmountAxis(it[today()]) }.distinctUntilChanged()
|
||||||
|
|
||||||
|
var shouldShowDecimalsInAxis = false
|
||||||
|
|
||||||
fun formatDate(createAt: Long): String {
|
fun formatDate(createAt: Long): String {
|
||||||
return sdf.format(
|
return sdf.format(
|
||||||
Instant.ofEpochSecond(createAt)
|
Instant.ofEpochSecond(createAt)
|
||||||
@@ -334,10 +336,28 @@ class UserReactionsViewModel(val account: Account) : ViewModel() {
|
|||||||
val chartEntryModelProducer1 = ChartEntryModelProducer(listOfCountCurves).getModel()
|
val chartEntryModelProducer1 = ChartEntryModelProducer(listOfCountCurves).getModel()
|
||||||
val chartEntryModelProducer2 = ChartEntryModelProducer(listOfValueCurves).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._axisLabels.emit(listOf(6, 5, 4, 3, 2, 1, 0).map { displayAxisFormatter.format(now.minusSeconds(day * it)) })
|
||||||
this._chartModel.emit(chartEntryModelProducer1.plus(chartEntryModelProducer2))
|
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
|
var collectorJob: Job? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
+9
-3
@@ -55,6 +55,7 @@ import com.vitorpamplona.amethyst.ui.note.OneKilo
|
|||||||
import com.vitorpamplona.amethyst.ui.note.OneMega
|
import com.vitorpamplona.amethyst.ui.note.OneMega
|
||||||
import com.vitorpamplona.amethyst.ui.note.UserReactionsRow
|
import com.vitorpamplona.amethyst.ui.note.UserReactionsRow
|
||||||
import com.vitorpamplona.amethyst.ui.note.UserReactionsViewModel
|
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.note.showCount
|
||||||
import com.vitorpamplona.amethyst.ui.screen.NotificationViewModel
|
import com.vitorpamplona.amethyst.ui.screen.NotificationViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.screen.RefresheableCardView
|
import com.vitorpamplona.amethyst.ui.screen.RefresheableCardView
|
||||||
@@ -224,6 +225,7 @@ private fun ObserveAndShowChart(
|
|||||||
) {
|
) {
|
||||||
val axisModel = model.axisLabels.collectAsStateWithLifecycle()
|
val axisModel = model.axisLabels.collectAsStateWithLifecycle()
|
||||||
val chartModel by model.chartModel.collectAsStateWithLifecycle()
|
val chartModel by model.chartModel.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
chartModel?.let {
|
chartModel?.let {
|
||||||
Chart(
|
Chart(
|
||||||
chart = remember(lineChartCount, lineChartZaps) {
|
chart = remember(lineChartCount, lineChartZaps) {
|
||||||
@@ -235,7 +237,7 @@ private fun ObserveAndShowChart(
|
|||||||
),
|
),
|
||||||
endAxis = rememberEndAxis(
|
endAxis = rememberEndAxis(
|
||||||
label = axisLabelComponent(color = BitcoinOrange),
|
label = axisLabelComponent(color = BitcoinOrange),
|
||||||
valueFormatter = AmountAxisValueFormatter()
|
valueFormatter = AmountAxisValueFormatter(model.shouldShowDecimalsInAxis)
|
||||||
),
|
),
|
||||||
bottomAxis = rememberBottomAxis(
|
bottomAxis = rememberBottomAxis(
|
||||||
valueFormatter = LabelValueFormatter(axisModel)
|
valueFormatter = LabelValueFormatter(axisModel)
|
||||||
@@ -265,12 +267,16 @@ class CountAxisValueFormatter() : AxisValueFormatter<AxisPosition.Vertical.Start
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
class AmountAxisValueFormatter() : AxisValueFormatter<AxisPosition.Vertical.End> {
|
class AmountAxisValueFormatter(val showDecimals: Boolean) : AxisValueFormatter<AxisPosition.Vertical.End> {
|
||||||
override fun formatValue(
|
override fun formatValue(
|
||||||
value: Float,
|
value: Float,
|
||||||
chartValues: ChartValues
|
chartValues: ChartValues
|
||||||
): String {
|
): String {
|
||||||
return showAmountAxis(value.toBigDecimal())
|
return if (showDecimals) {
|
||||||
|
showAmount(value.toBigDecimal())
|
||||||
|
} else {
|
||||||
|
showAmountAxis(value.toBigDecimal())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user