@@ -60,12 +60,16 @@ sealed interface AggregationType {
6060
6161 // Find the first real data point (non-zero timestamp)
6262 // 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 }
63+ val firstRealPoint = sorted.firstOrNull { it.x > 0 }
6564
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) {
65+ val duration = now - startTime
66+ val gapThreshold = duration * 0.05 // 5% of the period
67+
68+ val effective = if (
69+ firstRealPoint != null &&
70+ firstRealPoint.x > startTime &&
71+ (firstRealPoint.x - startTime) > gapThreshold
72+ ) {
6973 val zeroAnchors = listOf (
7074 MarketCapPoint (x = startTime, y = 0.0 ),
7175 MarketCapPoint (x = firstRealPoint.x - 1 , y = 0.0 ),
@@ -87,7 +91,6 @@ sealed interface AggregationType {
8791 }
8892
8993 // Interpolate to evenly-spaced timestamps
90- val duration = now - startTime
9194 val intervalMs = (duration / targetPoints).coerceAtLeast(1 )
9295
9396 return (0 until targetPoints).map { bucket ->
0 commit comments