fix(kline): auto-load more history when data doesn't fill screen
- Always assume hasMoreHistory=true on initial load - Auto-trigger loadMoreHistory when klines don't fill drawable area - This ensures sparse data periods load all available history Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
84d920f98f
commit
9333cd81c3
|
|
@ -790,7 +790,8 @@
|
|||
"Bash(ssh -o ProxyJump=ceshi@103.39.231.231 ceshi@192.168.1.111 \"ls -la /home/ceshi/rwadurian/backend/\")",
|
||||
"Bash(ssh -o ProxyJump=ceshi@103.39.231.231 ceshi@192.168.1.111 \"ls -la /home/ceshi/rwadurian/backend/services/\")",
|
||||
"Bash(where:*)",
|
||||
"Bash(npx md-to-pdf:*)"
|
||||
"Bash(npx md-to-pdf:*)",
|
||||
"Bash(ssh -J ceshi@103.39.231.231 ceshi@192.168.1.111 \"curl -s ''http://localhost:3000/api/price/klines?period=1h&limit=5'' | head -500\")"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ class KlinesNotifier extends StateNotifier<KlinesState> {
|
|||
state = state.copyWith(
|
||||
klines: klines,
|
||||
isLoading: false,
|
||||
hasMoreHistory: klines.length >= 100, // 如果返回100条,可能还有更多
|
||||
hasMoreHistory: true, // 默认还有更多历史,直到加载返回空数据
|
||||
);
|
||||
_startAutoRefresh(apiPeriod);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -97,6 +97,24 @@ class _KlineChartWidgetState extends State<KlineChartWidget> {
|
|||
|
||||
// 计算滚动位置,让最新K线在屏幕中心
|
||||
_scrollToCenter();
|
||||
|
||||
// 如果数据不足以填满屏幕且还有更多历史数据,自动加载更多
|
||||
_checkAndLoadMoreIfNeeded();
|
||||
}
|
||||
|
||||
/// 检查是否需要自动加载更多历史数据
|
||||
void _checkAndLoadMoreIfNeeded() {
|
||||
if (!widget.hasMoreHistory || widget.isLoadingMore) return;
|
||||
|
||||
const leftPadding = 8.0;
|
||||
const rightPadding = 50.0;
|
||||
final drawableWidth = _chartWidth - leftPadding - rightPadding;
|
||||
final totalKlineWidth = widget.klines.length * _candleWidth;
|
||||
|
||||
// 如果K线总宽度不足以填满可绘制区域,自动加载更多历史
|
||||
if (totalKlineWidth < drawableWidth) {
|
||||
widget.onLoadMoreHistory?.call();
|
||||
}
|
||||
}
|
||||
|
||||
/// 滚动使最新 K 线在屏幕中心显示
|
||||
|
|
|
|||
Loading…
Reference in New Issue