fix(kline): 稀疏数据时让最新K线居中而非整组居中
修正居中逻辑:当K线数量少时,让最新的那根K线(最右边)显示在屏幕中央,而不是让整个K线组居中。 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f1b2ec7ede
commit
ccbea74f87
|
|
@ -583,9 +583,14 @@ class _KlineChartWidgetState extends State<KlineChartWidget> {
|
|||
final availableWidth = chartWidth - rightPadding - leftPadding;
|
||||
final totalWidth = widget.klines.length * _candleWidth;
|
||||
|
||||
// 计算左侧偏移量:当K线总宽度小于可用宽度时,将K线居中显示
|
||||
// 居中偏移 = (可用宽度 - K线总宽度) / 2
|
||||
final leftOffset = totalWidth < availableWidth ? (availableWidth - totalWidth) / 2 : 0.0;
|
||||
// 计算左侧偏移量:当K线总宽度小于可用宽度时,让最新K线(最右边)居中显示
|
||||
// 最新K线位置 = totalWidth - candleWidth/2(最后一根K线的中心点)
|
||||
// 居中偏移 = 屏幕中心 - 最新K线位置 = availableWidth/2 - (totalWidth - candleWidth/2)
|
||||
double leftOffset = 0.0;
|
||||
if (totalWidth < availableWidth) {
|
||||
// 让最新K线居中:偏移量 = 屏幕中心 - 最新K线中心位置
|
||||
leftOffset = (availableWidth / 2) - (totalWidth - _candleWidth / 2);
|
||||
}
|
||||
|
||||
// 根据滚动位置计算可见的K线范围
|
||||
final int startIndex = (_scrollX / _candleWidth).floor().clamp(0, widget.klines.length - 1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue