diff --git a/src/store/ChartStore.ts b/src/store/ChartStore.ts index 2b8df19f7..3bf148eba 100644 --- a/src/store/ChartStore.ts +++ b/src/store/ChartStore.ts @@ -210,7 +210,7 @@ export default class ChartStore { setPrecision (precision: Precision): this { this._precision = precision - this._indicatorStore.setSeriesPrecision(precision) + this._indicatorStore.synchronizeSeriesPrecision() return this } diff --git a/src/store/IndicatorStore.ts b/src/store/IndicatorStore.ts index b6a3cce9b..d6761d1c7 100644 --- a/src/store/IndicatorStore.ts +++ b/src/store/IndicatorStore.ts @@ -13,7 +13,6 @@ */ import type Nullable from '../common/Nullable' -import type Precision from '../common/Precision' import { isValid, isString, isArray, isNumber, isBoolean, isFunction } from '../common/utils/typeChecks' import type ChartStore from './ChartStore' @@ -123,6 +122,8 @@ export default class IndicatorStore { } const IndicatorClazz = getIndicatorClass(name)! const instance = new IndicatorClazz() + + this.synchronizeSeriesPrecision(instance) this._overrideInstance(instance, indicator) if (!isStack) { paneInstances = [] @@ -215,17 +216,31 @@ export default class IndicatorStore { return mapping } - setSeriesPrecision (precision: Precision): void { - this._instances.forEach(paneInstances => { - paneInstances.forEach(instance => { - if (instance.series === IndicatorSeries.Price) { - instance.setPrecision(precision.price, true) + synchronizeSeriesPrecision (indicator?: IndicatorImp): void { + const { price: pricePrecision, volume: volumePrecision } = this._chartStore.getPrecision() + const synchronize: ((instance: IndicatorImp) => void) = instance => { + switch (instance.series) { + case IndicatorSeries.Price: { + instance.setPrecision(pricePrecision, true) + break } - if (instance.series === IndicatorSeries.Volume) { - instance.setPrecision(precision.volume, true) + case IndicatorSeries.Volume: { + instance.setPrecision(volumePrecision, true) + break } + default: { break } + } + } + + if (isValid(indicator)) { + synchronize(indicator) + } else { + this._instances.forEach(paneInstances => { + paneInstances.forEach(instance => { + synchronize(instance) + }) }) - }) + } } async override (indicator: IndicatorCreate, paneId: Nullable): Promise<[boolean, boolean]> {