KLineChart icon indicating copy to clipboard operation
KLineChart copied to clipboard

[Bug] overlay with point in the future does not saving right

Open oneart-dev opened this issue 1 year ago • 7 comments

Version

9.5.9

Steps to Reproduce

  1. Draw segment or any 2 point overlays with second point beyond last candle (future)
  2. Check overlay points data

Current Behavior

If check points data it will looks li that:

{
"points":[{"timestamp":1687420800000,"value":0.09349152777777778},{"value":0.1189336111111111}]}
}

It will lead to bugs if saving it and restore later

Expected Behavior

Chart should calculate timestamp based on interval and point location or do not let user to make point in the future

Environment

- OS: Macos
- Browser: any
- Framework: not related

Any additional comments?

No response

oneart-dev avatar Jun 26 '23 15:06 oneart-dev

https://github.com/liihuu/KLineChart/assets/70148117/bb9f8c49-bdc2-44cf-af43-7414f05d5cba

oneart-dev avatar Jun 26 '23 16:06 oneart-dev

Best possible fix probably will be draw invisible candles all the way to the right. Sadly "performEventMoveForDrawing" do not provide kline data at all, so it really hard to implement dirty fix to stop users from drawing beyond last candle

oneart-dev avatar Jun 26 '23 16:06 oneart-dev

I fixed it in my repo by updating it in OverlayView.ts function _coordinateToPoint:

   if (this.coordinateToPointTimestampDataIndexFlag()) {
      const xAxis = chart.getPaneById(PaneIdConstants.XAXIS)?.getAxisComponent() as Axis
      const dataIndex = xAxis.convertFromPixel(coordinate.x)
      const timestamp = timeScaleStore.dataIndexToTimestamp(dataIndex) ?? undefined
      const klines = chart.getChartStore().getDataList()
      if (timestamp === undefined) {
        const index = dataIndex < 0 ? 0 : dataIndex > klines.length - 1 ? klines.length - 1 : dataIndex
        point.timestamp = klines[index].timestamp
        point.dataIndex = index
      } else {
        point.dataIndex = dataIndex
        point.timestamp = timestamp
      }
    }

oneart-dev avatar Jun 26 '23 17:06 oneart-dev

It may not be necessary to change the source code, listen to the onDrawing of overlay, and then determine if it exceeds the boundary, forcing a reassignment of points.

liihuu avatar Aug 15 '23 17:08 liihuu

It may not be necessary to change the source code, listen to the onDrawing of overlay, and then determine if it exceeds the boundary, forcing a reassignment of points.

I noticed this too

Basttyy avatar Aug 15 '23 17:08 Basttyy

But its not a solution for the problem. If library can't handle it should force it by default.

oneart-dev avatar Aug 15 '23 18:08 oneart-dev

https://github.com/liihuu/KLineChart/assets/24972453/8dac81ab-68d2-4e09-b7cf-f8ed27ad4189

Likewise, if the starting and ending points are too far apart, the overlay remains hidden when LoadMore is not performed.

(Even if it is within Timestamp borders)

xtrmus avatar Sep 22 '23 06:09 xtrmus