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

[Bug] Overlay that extends the last data point will be positioned wrong if new data are appended #516

Open
char101 opened this issue Dec 11, 2023 · 12 comments

Comments

@char101
Copy link

char101 commented Dec 11, 2023

Version

latest

Steps to Reproduce

  1. Create a segment overlay extending past the last data point
  2. Add new data by scrolling to the left
  3. Scroll back to the right

Current Behavior

Right point of overlay is misplaced.

Expected Behavior

Right point position is retained.

Environment

- OS:
- Browser:
- Framework:

Any additional comments?

When adding new data, dataIndex points in overlays that do not have a timestamp need to be updated with the new data length.

@jinusean
Copy link

jinusean commented Dec 15, 2023

You have to create the overlay using timestamp instead of dataIndex.

Or update the overlay instance after new (historical) data is loaded.

@char101
Copy link
Author

char101 commented Dec 15, 2023

I obviously write the overlay is past the last data point. When an overlay is stretched past the last data point, the point values does not contain a timestamp key, because there is no timestamp.

@sazanof
Copy link

sazanof commented Mar 14, 2024

14.03.2024.15.22.06.webm

I join the question. If you do not specify the dataIndex, in the point structure, then the point is added to the beginning.

The offset occurs because the initial index also changes during dynamic loading of data. Thus, if I load 300 candlesticks each time I scroll to the left, the index of the point does not change and it probably needs to be changed manually.

Is it possible to use timestamp instead of dataIndex or how to updat? How would you recommend updating the dataIndex in this case?

@char101
Copy link
Author

char101 commented Mar 14, 2024

An easy way is to store the dataIndex without timestamp as negative value, thus -1 means the last dataIndex.

@liihuu
Copy link
Member

liihuu commented Mar 14, 2024

Explain why the overlay can only be drawn to future time using dataIndex instead of timestamp.

Currently, the chart does not have periods and trading sessions, but is rendered based on data, so it is impossible to determine an accurate time in the future.

@char101
Copy link
Author

char101 commented Mar 14, 2024

Which is why in Chart.updateData you need to update dataIndex of overlay coordinates that have no timestamp because the dataIndex has been shifted.

@sazanof
Copy link

sazanof commented Mar 14, 2024

The problem also arises when overlapping existing candles (with timestamp). An example is in the video.

14.03.2024.16.42.28.webm

I can not use Chart.updateData in setLoadDataCallback, because I got candles recurcievly loading and browser freezes

Code, that I use to load historical data:

this.chart.setLoadDataCallback(async data => {
                this.fromCandle = data
                setTimeout(async () => {
                    if (data.type === 'forward') {
                        const candles = await this.getCandles()
                        data.callback(candles, true)
                    } else {
                        data.callback([], true)
                    }
                }, 500)
            })

If you do not call the method data.callback(candles, true), then the next loading of candles will not work

Also I received websockets message to add candles to to front of chart

Echo.private(`candles.sync.${this.value.security.id}.${this.tf}`)
            .listen('CandlesSyncCompleteEvent', (e) => {
                const candles = e.candles.map(c => {
                    c.timestamp = formatDate(c.timestamp)
                    console.log(c, new Date(c.timestamp))
                    this.chart.updateData(c)
                    this.candles.push(c)
                    return c
                })
            })

17-00
image
17-01
image
After reloading page
image

I tried:
points: [{"value": 91993.04878472222, "dataIndex": 300, "timestamp": "2024-03-14 16:41"}]
or
points: [{"value": 91993.04878472222, "dataIndex": 300, "timestamp": 1710434460000}]
or
dataIndex:0 or (-1)

but the overlay sets incorrectly. What did I miss?

@sazanof
Copy link

sazanof commented Mar 14, 2024

It seems that a bug has been found on my side. In my case, I don't have to save dataIndex to DB and everywhere to use milliseconds format of timestamp!

@liihuu
Copy link
Member

liihuu commented Mar 17, 2024

Which is why in Chart.updateData you need to update dataIndex of overlay coordinates that have no timestamp because the dataIndex has been shifted.

Yes, I am trying to fix it.

@char101
Copy link
Author

char101 commented Mar 18, 2024

There is also the problem of restoring an overlay (from database) where coordinates contains only dataIndex. In this case using a relative offset is better because it can be persisted.

For example:

// 3 bars after 1710753641000
{timestamp: 1710753641000, offset: 3}

// 3 bars before 1710753641000
{timestamp: 1710753641000, offset: -3}

@liihuu
Copy link
Member

liihuu commented Dec 19, 2024

This problem has been completely solved. In v10, the overlay only uses the timestamp to control its position.

@liihuu
Copy link
Member

liihuu commented Dec 19, 2024

#459

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants