@@ -58,15 +58,32 @@ sealed interface AggregationType {
5858 val withCurrent = points + MarketCapPoint (x = now, y = currentValue)
5959 val sorted = withCurrent.sortedBy { it.x }
6060
61+ // Find the first real data point (non-zero timestamp)
62+ // Instead of checking for x == 0, check if there's a gap at the start
63+ val firstRealPoint = sorted.firstOrNull { it.x >= startTime && it.y > 0.0 }
64+ ? : sorted.firstOrNull { it.x > 0 }
65+
66+ // Build the effective point list: if data starts after startTime,
67+ // anchor zeros from startTime up to the first real point
68+ val effective = if (firstRealPoint != null && firstRealPoint.x > startTime) {
69+ val zeroAnchors = listOf (
70+ MarketCapPoint (x = startTime, y = 0.0 ),
71+ MarketCapPoint (x = firstRealPoint.x - 1 , y = 0.0 ),
72+ )
73+ zeroAnchors + sorted.filter { it.x > 0 }
74+ } else {
75+ sorted
76+ }
77+
6178 // Select visually significant points using LTTB
6279 val selected = when {
63- sorted .size <= targetPoints -> sorted
80+ effective .size <= targetPoints -> effective
6481 targetPoints < 3 -> listOfNotNull(
65- sorted .firstOrNull(),
66- sorted .lastOrNull()
82+ effective .firstOrNull(),
83+ effective .lastOrNull()
6784 ).distinct()
6885
69- else -> selectPoints(sorted , targetPoints)
86+ else -> selectPoints(effective , targetPoints)
7087 }
7188
7289 // Interpolate to evenly-spaced timestamps
0 commit comments