Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding points or bars while scrolling leads to timescale jumps #1521

Open
devoln opened this issue Feb 21, 2024 · 1 comment
Open

Adding points or bars while scrolling leads to timescale jumps #1521

devoln opened this issue Feb 21, 2024 · 1 comment
Labels
bug Unexpected problem or unintended behavior. good first issue Good issue for first-time contributors.
Milestone

Comments

@devoln
Copy link

devoln commented Feb 21, 2024

Lightweight Charts™ Version: 4.1.3

Steps/code to reproduce:

  1. Create a HTML file with the following content.
  2. Open it
  3. Scroll the chart to the left
  4. Continue scrolling by moving mouse slowly in any direction with left mouse button pressed
  5. Watch jumps happening each 3 seconds
<html>
<body>
<script src="https://unpkg.com/lightweight-charts@4.1.3/dist/lightweight-charts.standalone.production.js"></script>
  <div id="container"></div>
  <script>
    const chart = LightweightCharts.createChart(document.getElementById('container'), {width: 800, height: 400});

    const series = chart.addLineSeries();
    let nextVal = {time: Date.parse('2023-01-01') / 1000, value: 0};

    const addVal = () => {
        nextVal.time += 86400;
        nextVal.value = Math.random();
        series.update(nextVal);
    };

    for(let i = 0; i < 500; i++) addVal();
    setInterval(() => {for(let i = 0; i < 50; i++) addVal()}, 3000)
  </script>
</body>
</html>

Actual behavior:

The timescale jumps to the right by 50 days every 3 seconds while scrolling is in process.

Expected behavior:

No jumps, just scrolling proportional to mouse movements.

Also can be reproduced in TradingView. Select the smallest possible timeframe (1m for free plans), scale the chart to make bars bigger in order to make jumps more noticeable. Then start to scroll slowly. When new candle appears, the timescale will jump to the right by one bar.

Let me know if there is a way to work around this issue. I couldn't find any. I want to append new candles while user is scrolling to the right and more candles become visible. But this makes the chart to jump by the number of added candles.
Option shiftVisibleRangeOnNewBar has no effect because it isn't applicable to this case. Both setData and update have the same behaviour.
By the way, adding new candles into the beginning (candleArray.unshift + setData) doesn't have any issue, no jumps happen in that case.

@SlicedSilver
Copy link
Contributor

Thank you for reporting this. This is something that could be improved and fixed on the library.

@SlicedSilver SlicedSilver added bug Unexpected problem or unintended behavior. good first issue Good issue for first-time contributors. labels Feb 21, 2024
@SlicedSilver SlicedSilver added this to the 5.0 milestone Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected problem or unintended behavior. good first issue Good issue for first-time contributors.
Projects
None yet
Development

No branches or pull requests

2 participants