Skip to content

[Bug] DataLoader.getBars 立即返回数据会触发bug,自动滚动到最晚时间,然后又触发加载多次循环 #747

@davincerepo

Description

@davincerepo

版本

10.0.0-alpha8

复现步骤

操作表现:往左拖动k线,触发 DataLoader.getBars 加载的如果还没松开鼠标,会自动跳转到最后的k线,再次触发加载

必现代码
codesandbox

import { init, KLineData } from "klinecharts";

const chart = init("custom-figure-custom-overlay-chart");

chart.setSymbol({ ticker: "TestSymbol" });
chart.setPeriod({ span: 1, type: "day" });
chart.setDataLoader({
  getBars: async ({ callback }) => {
    const bars: KLineData[] = [];
    let lastClose = 1000; // 初始的收盘价
    let timestamp = Date.now(); // 初始的时间戳

    // 生成500条数据
    for (let i = 0; i < 500; i++) {
      const open = lastClose + Math.random() * 5 - 2.5; // 开盘价相对收盘价波动
      const close = open + Math.random() * 5 - 2.5; // 收盘价相对开盘价波动
      const high = Math.max(open, close) + Math.random() * 3; // 最高价
      const low = Math.min(open, close) - Math.random() * 3; // 最低价

      bars.push({
        timestamp,
        open,
        high,
        low,
        close,
      });

      lastClose = close; // 更新收盘价
      timestamp += 86400000; // 时间戳递增一天(毫秒)
    }

    // 返回数据,DataLoadMore设置为true true,表示还有数据可以加载
    callback(bars, { forward: true, backward: true });
  },
  subscribe: (params) => {},
  unsubscribe: (params) => {},
});

当前效果

操作表现:往左拖动k线,触发 DataLoader.getBars 加载的如果还没松开鼠标,会自动跳转到最后的k线,再次触发加载

预期效果

不会自动滚动

环境

- 系统: windows 10
- 浏览器: 139.0.7258.128(正式版本) (64 位)
- 框架: 不用框架可以复现

补充说明

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions