KLineChart
KLineChart copied to clipboard
[Bug] overlay with point in the future does not saving right
Version
9.5.9
Steps to Reproduce
- Draw segment or any 2 point overlays with second point beyond last candle (future)
- 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
https://github.com/liihuu/KLineChart/assets/70148117/bb9f8c49-bdc2-44cf-af43-7414f05d5cba
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
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
}
}
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.
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
But its not a solution for the problem. If library can't handle it should force it by default.
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)