From 6d97d7949881e52536d750029566f0019fb6763e Mon Sep 17 00:00:00 2001 From: Georgii Savin Date: Thu, 5 Oct 2023 17:06:47 +0300 Subject: [PATCH] fix: rework PrependedCandlesData interface --- src/chart/components/chart/chart-base.model.ts | 3 +-- src/chart/components/chart/chart.model.ts | 15 +++++++-------- src/chart/components/x_axis/x-axis.component.ts | 6 +++--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/chart/components/chart/chart-base.model.ts b/src/chart/components/chart/chart-base.model.ts index 7dc12255..0d266dc3 100644 --- a/src/chart/components/chart/chart-base.model.ts +++ b/src/chart/components/chart/chart-base.model.ts @@ -18,8 +18,7 @@ type DataPoint = T extends 'candle' ? Candle : DataSeriesPoi type VisualPoint = T extends 'candle' ? VisualCandle : VisualSeriesPoint; export interface PrependedCandlesData { prependedCandlesWidth: number; - prependedCandlesCount: number; - preparedCandles: Candle[]; + prependedCandles: Candle[]; } /** diff --git a/src/chart/components/chart/chart.model.ts b/src/chart/components/chart/chart.model.ts index 870d5bdb..74fc8a0f 100755 --- a/src/chart/components/chart/chart.model.ts +++ b/src/chart/components/chart/chart.model.ts @@ -384,13 +384,12 @@ export class ChartModel extends ChartBaseElement { // caclulate offset width for prepanded candles const prependedCandlesWidth = this.chartBaseModel.mainVisualPoints - .slice(0, updateResult.prepended) + .slice(0, updateResult.prepended.length) .reduce((acc, cur) => acc + cur.width, 0); this.scale.moveXStart(this.scale.xStart + prependedCandlesWidth); this.candlesPrependSubject.next({ prependedCandlesWidth, - prependedCandlesCount: updateResult.prepended, - preparedCandles, + prependedCandles: updateResult.prepended, }); this.chartBaseModel.recalculatePeriod(); @@ -1065,7 +1064,7 @@ export class ChartModel extends ChartBaseElement { }); return { - prepended: prepend.length, + prepended: prepend, candles: [...prepend, ...targetCopy], }; } @@ -1111,8 +1110,8 @@ export class ChartModel extends ChartBaseElement { } export interface UpdateCandlesResult { - prepended: number; - appended?: number; + prepended: Candle[]; + appended?: Candle[]; candles: Candle[]; } @@ -1161,8 +1160,8 @@ const updateCandles = (target: Candle[], update: Candle[]): UpdateCandlesResult }); return { - prepended: prepend.length, - appended: append.length, + prepended: prepend, + appended: append, candles: [...prepend, ...targetCopy, ...append], }; }; diff --git a/src/chart/components/x_axis/x-axis.component.ts b/src/chart/components/x_axis/x-axis.component.ts index dd4ddd32..076dd1b7 100644 --- a/src/chart/components/x_axis/x-axis.component.ts +++ b/src/chart/components/x_axis/x-axis.component.ts @@ -120,11 +120,11 @@ export class XAxisComponent extends ChartBaseElement { this.addRxSubscription( this.chartComponent.chartModel.candlesPrependSubject .pipe( - filter(({ prependedCandlesCount }) => prependedCandlesCount !== 0), - map(({ prependedCandlesCount }) => { + filter(({ prependedCandles }) => prependedCandles.length !== 0), + map(({ prependedCandles }) => { return this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice( 0, - prependedCandlesCount, + prependedCandles.length, ); }), )