mirror of
https://github.com/klinecharts/KLineChart.git
synced 2024-11-25 16:22:43 +08:00
impr: change indicator.onDataStatusChange
to indicator.onDataStateChange
This commit is contained in:
parent
19306e5e01
commit
8c658bf881
@ -118,18 +118,18 @@ export type IndicatorDrawCallback<D> = (params: IndicatorDrawParams<D>) => boole
|
||||
export type IndicatorCalcCallback<D> = (dataList: KLineData[], indicator: Indicator<D>) => Promise<D[]> | D[]
|
||||
export type IndicatorShouldUpdateCallback<D> = (prev: Indicator<D>, current: Indicator<D>) => (boolean | { calc: boolean, draw: boolean })
|
||||
|
||||
export enum IndicatorDataStatus {
|
||||
export enum IndicatorDataState {
|
||||
Loading = 'loading',
|
||||
Error = 'error',
|
||||
Ready = 'ready'
|
||||
}
|
||||
|
||||
export interface IndicatorOnDataStatusChangeParams<D> {
|
||||
status: IndicatorDataStatus
|
||||
export interface IndicatorOnDataStateChangeParams<D> {
|
||||
state: IndicatorDataState
|
||||
type: LoadDataType
|
||||
indicator: Indicator<D>
|
||||
}
|
||||
export type IndicatorOnDataStatusChangeCallback<D> = (params: IndicatorOnDataStatusChangeParams<D>) => void
|
||||
export type IndicatorOnDataStateChangeCallback<D> = (params: IndicatorOnDataStateChangeParams<D>) => void
|
||||
|
||||
export interface Indicator<D = unknown> {
|
||||
/**
|
||||
@ -228,9 +228,9 @@ export interface Indicator<D = unknown> {
|
||||
draw: Nullable<IndicatorDrawCallback<D>>
|
||||
|
||||
/**
|
||||
* Data status change
|
||||
* Data state change
|
||||
*/
|
||||
onDataStatusChange: Nullable<IndicatorOnDataStatusChangeCallback<D>>
|
||||
onDataStateChange: Nullable<IndicatorOnDataStateChangeCallback<D>>
|
||||
|
||||
/**
|
||||
* Calculation result
|
||||
@ -355,7 +355,7 @@ export default class IndicatorImp<D = unknown> implements Indicator<D> {
|
||||
createTooltipDataSource: Nullable<IndicatorCreateTooltipDataSourceCallback<D>> = null
|
||||
draw: Nullable<IndicatorDrawCallback<D>> = null
|
||||
|
||||
onDataStatusChange: Nullable<IndicatorOnDataStatusChangeCallback<D>> = null
|
||||
onDataStateChange: Nullable<IndicatorOnDataStateChangeCallback<D>> = null
|
||||
|
||||
result: D[] = []
|
||||
|
||||
|
@ -16,7 +16,7 @@ import { isValid, isString } from '../common/utils/typeChecks'
|
||||
|
||||
import type ChartStore from './ChartStore'
|
||||
|
||||
import { IndicatorDataStatus, type IndicatorCreate, type IndicatorFilter } from '../component/Indicator'
|
||||
import { IndicatorDataState, type IndicatorCreate, type IndicatorFilter } from '../component/Indicator'
|
||||
import type IndicatorImp from '../component/Indicator'
|
||||
import { IndicatorSeries } from '../component/Indicator'
|
||||
import { getIndicatorClass } from '../extension/indicator/index'
|
||||
@ -47,23 +47,23 @@ export default class IndicatorStore {
|
||||
this._scheduler.addTask({
|
||||
id: generateTaskId(paneId, indicator.name),
|
||||
handler: () => {
|
||||
indicator.onDataStatusChange?.({
|
||||
status: IndicatorDataStatus.Loading,
|
||||
indicator.onDataStateChange?.({
|
||||
state: IndicatorDataState.Loading,
|
||||
type: loadDataType,
|
||||
indicator
|
||||
})
|
||||
indicator.calcImp(this._chartStore.getDataList()).then(result => {
|
||||
if (result) {
|
||||
this._chartStore.getChart().adjustPaneViewport(false, true, true, true)
|
||||
indicator.onDataStatusChange?.({
|
||||
status: IndicatorDataStatus.Ready,
|
||||
indicator.onDataStateChange?.({
|
||||
state: IndicatorDataState.Ready,
|
||||
type: loadDataType,
|
||||
indicator
|
||||
})
|
||||
}
|
||||
}).catch(() => {
|
||||
indicator.onDataStatusChange?.({
|
||||
status: IndicatorDataStatus.Error,
|
||||
indicator.onDataStateChange?.({
|
||||
state: IndicatorDataState.Error,
|
||||
type: loadDataType,
|
||||
indicator
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user