Skip to content

Commit

Permalink
fix: fix add data overlay in the wrong position when point time does …
Browse files Browse the repository at this point in the history
…not exist. #516
  • Loading branch information
liihuu committed Mar 17, 2024
1 parent debdab6 commit 61954b8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/store/ChartStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ export default class ChartStore {
async addData (data: KLineData | KLineData[], type?: LoadDataType, more?: boolean): Promise<void> {
let success = false
let adjustFlag = false

let dataLengthChange = 0
if (isArray<KLineData>(data)) {
dataLengthChange = data.length
switch (type) {
case LoadDataType.Init: {
this.clear()
Expand All @@ -239,13 +240,13 @@ export default class ChartStore {
case LoadDataType.Backward: {
this._dataList = this._dataList.concat(data)
this._backwardMore = more ?? false
adjustFlag = data.length > 0
adjustFlag = dataLengthChange > 0
break
}
case LoadDataType.Forward: {
this._dataList = data.concat(this._dataList)
this._forwardMore = more ?? false
adjustFlag = data.length > 0
adjustFlag = dataLengthChange > 0
}
}
this._loading = false
Expand All @@ -261,6 +262,7 @@ export default class ChartStore {
if (lastBarRightSideDiffBarCount < 0) {
this._timeScaleStore.setLastBarRightSideDiffBarCount(--lastBarRightSideDiffBarCount)
}
dataLengthChange = 1
success = true
adjustFlag = true
} else if (timestamp === lastDataTimestamp) {
Expand All @@ -271,6 +273,7 @@ export default class ChartStore {
}
if (success) {
try {
this._overlayStore.updatePointPosition(dataLengthChange, type)
if (adjustFlag) {
this._timeScaleStore.adjustVisibleRange()
this._tooltipStore.recalculateCrosshair(true)
Expand Down
21 changes: 21 additions & 0 deletions src/store/OverlayStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { UpdateLevel } from '../common/Updater'
import { type MouseTouchEvent } from '../common/SyntheticEvent'
import { isFunction, isValid, isString, isBoolean, isNumber, isArray } from '../common/utils/typeChecks'
import { createId } from '../common/utils/id'
import { LoadDataType } from '../common/LoadDataCallback'

import { type OverlayCreate, type OverlayRemove } from '../component/Overlay'
import type OverlayImp from '../component/Overlay'
Expand Down Expand Up @@ -420,6 +421,26 @@ export default class OverlayStore {
return this._pressedInstanceInfo
}

updatePointPosition (dataChangeLength: number, type?: LoadDataType): void {
if (dataChangeLength > 0) {
const dataList = this._chartStore.getDataList()
this._instances.forEach(overlays => {
overlays.forEach(o => {
const points = o.points
points.forEach(point => {
if (!isValid(point.timestamp) && isValid(point.dataIndex)) {
if (type === LoadDataType.Forward) {
point.dataIndex = point.dataIndex + dataChangeLength
}
const data = dataList[point.dataIndex]
point.timestamp = data?.timestamp
}
})
})
})
}
}

setHoverInstanceInfo (info: EventOverlayInfo, event: MouseTouchEvent): void {
const { instance, figureType, figureKey, figureIndex } = this._hoverInstanceInfo
if (
Expand Down

0 comments on commit 61954b8

Please sign in to comment.