Skip to content

Commit

Permalink
fix: rework PrependedCandlesData interface
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaZN committed Oct 5, 2023
1 parent 00b075c commit 6d97d79
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/chart/components/chart/chart-base.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ type DataPoint<T extends BaseType> = T extends 'candle' ? Candle : DataSeriesPoi
type VisualPoint<T extends BaseType> = T extends 'candle' ? VisualCandle : VisualSeriesPoint;
export interface PrependedCandlesData {
prependedCandlesWidth: number;
prependedCandlesCount: number;
preparedCandles: Candle[];
prependedCandles: Candle[];
}

/**
Expand Down
15 changes: 7 additions & 8 deletions src/chart/components/chart/chart.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -1065,7 +1064,7 @@ export class ChartModel extends ChartBaseElement {
});

return {
prepended: prepend.length,
prepended: prepend,
candles: [...prepend, ...targetCopy],
};
}
Expand Down Expand Up @@ -1111,8 +1110,8 @@ export class ChartModel extends ChartBaseElement {
}

export interface UpdateCandlesResult {
prepended: number;
appended?: number;
prepended: Candle[];
appended?: Candle[];
candles: Candle[];
}

Expand Down Expand Up @@ -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],
};
};
6 changes: 3 additions & 3 deletions src/chart/components/x_axis/x-axis.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}),
)
Expand Down

0 comments on commit 6d97d79

Please sign in to comment.