Updated on 2026-08-14
This commit is contained in:
parent
7b7cece46f
commit
4f7e182285
5 changed files with 26 additions and 14 deletions
|
|
@ -0,0 +1,13 @@
|
|||
package com.tangem.common.ui.charts.state
|
||||
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
fun MarketChartData.Data.sorted(): MarketChartData.Data {
|
||||
val points = this.x.zip(this.y).sortedBy { it.first }
|
||||
val (x, y) = points.unzip()
|
||||
|
||||
return MarketChartData.Data(
|
||||
x = x.toImmutableList(),
|
||||
y = y.toImmutableList(),
|
||||
)
|
||||
}
|
||||
|
|
@ -22,11 +22,6 @@ class PriceAndTimePointValuesConverter(
|
|||
private val formatYValuesCache = mutableMapOf<Double, BigDecimal>()
|
||||
private val formatXValuesCache = mutableMapOf<Double, BigDecimal>()
|
||||
|
||||
private data class Point(
|
||||
val x: BigDecimal,
|
||||
val y: BigDecimal,
|
||||
)
|
||||
|
||||
override fun convert(data: MarketChartData.Data): MarketChartRawData {
|
||||
formatYValuesCache.clear()
|
||||
formatXValuesCache.clear()
|
||||
|
|
@ -38,10 +33,8 @@ class PriceAndTimePointValuesConverter(
|
|||
)
|
||||
minMaxCache = cache
|
||||
|
||||
val points = data.x.zip(data.y) { x, y -> Point(x, y) }.sortedBy { it.x }
|
||||
|
||||
val normY = points.map { it.y }.normalizeToDouble(min = cache.minY, max = cache.maxY)
|
||||
val normX = points.map { it.x }.normalizeTime(min = cache.minX, max = cache.maxX)
|
||||
val normY = data.y.normalizeToDouble(min = cache.minY, max = cache.maxY)
|
||||
val normX = data.x.normalizeTime(min = cache.minX, max = cache.maxX)
|
||||
|
||||
return if (normX.size > MAX_POINTS) {
|
||||
LTThreeBuckets
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import arrow.core.getOrElse
|
|||
import com.tangem.common.ui.charts.state.MarketChartData
|
||||
import com.tangem.common.ui.charts.state.MarketChartDataProducer
|
||||
import com.tangem.common.ui.charts.state.MarketChartLook
|
||||
import com.tangem.common.ui.charts.state.sorted
|
||||
import com.tangem.core.decompose.di.ComponentScoped
|
||||
import com.tangem.core.decompose.model.Model
|
||||
import com.tangem.core.decompose.model.ParamsContainer
|
||||
|
|
@ -237,9 +238,9 @@ internal class MarketsTokenDetailsModel @Inject constructor(
|
|||
chart.onRight {
|
||||
chartDataProducer.runTransactionSuspend {
|
||||
chartData = MarketChartData.Data(
|
||||
x = it.timeStamps.map { it.toBigDecimal() }.toImmutableList(),
|
||||
y = it.priceY.toImmutableList(),
|
||||
)
|
||||
x = it.timeStamps.map { it.toBigDecimal() }.toImmutableList(),
|
||||
).sorted()
|
||||
|
||||
updateLook {
|
||||
it.copy(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import arrow.core.getOrElse
|
|||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.common.ui.charts.state.MarketChartData
|
||||
import com.tangem.common.ui.charts.state.converter.PriceAndTimePointValuesConverter
|
||||
import com.tangem.common.ui.charts.state.sorted
|
||||
import com.tangem.core.decompose.di.ComponentScoped
|
||||
import com.tangem.core.decompose.model.Model
|
||||
import com.tangem.core.decompose.model.ParamsContainer
|
||||
|
|
@ -105,13 +106,16 @@ internal class TokenMarketBlockModel @Inject constructor(
|
|||
)
|
||||
|
||||
result.onRight { res ->
|
||||
// wait until quotes are loaded
|
||||
state.first { it.currentPrice != null }
|
||||
|
||||
state.update { stateToUpdate ->
|
||||
stateToUpdate.copy(
|
||||
chartData = priceAndTimePointValuesConverter.convert(
|
||||
MarketChartData.Data(
|
||||
y = res.priceY.toImmutableList(),
|
||||
x = res.timeStamps.sorted().map { it.toBigDecimal() }.toImmutableList(),
|
||||
),
|
||||
x = res.timeStamps.map { it.toBigDecimal() }.toImmutableList(),
|
||||
).sorted(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.tangem.features.markets.tokenlist.impl.model.converters
|
|||
import com.tangem.common.ui.charts.state.converter.PriceAndTimePointValuesConverter
|
||||
import com.tangem.common.ui.charts.state.MarketChartData
|
||||
import com.tangem.common.ui.charts.state.MarketChartRawData
|
||||
import com.tangem.common.ui.charts.state.sorted
|
||||
import com.tangem.core.ui.components.marketprice.PriceChangeType
|
||||
import com.tangem.core.ui.utils.BigDecimalFormatter
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
|
|
@ -115,7 +116,7 @@ internal class MarketsTokenItemConverter(
|
|||
MarketChartData.Data(
|
||||
y = ct.priceY.toImmutableList(),
|
||||
x = ct.timeStamps.map { it.toBigDecimal() }.toImmutableList(),
|
||||
),
|
||||
).sorted(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue