From 0b66795de12c3510c8623251ba29a46259bfc76f Mon Sep 17 00:00:00 2001 From: Anton Vorobev Date: Fri, 29 Dec 2023 12:54:23 +0300 Subject: [PATCH 1/7] fix: recalculate candle idx --- src/chart/drawers/chart-type-drawers/line.drawer.ts | 4 +++- src/chart/model/data-series.model.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/chart/drawers/chart-type-drawers/line.drawer.ts b/src/chart/drawers/chart-type-drawers/line.drawer.ts index 4021f7a9..19c15837 100644 --- a/src/chart/drawers/chart-type-drawers/line.drawer.ts +++ b/src/chart/drawers/chart-type-drawers/line.drawer.ts @@ -30,7 +30,9 @@ export class LineDrawer implements SeriesDrawer { if (drawerConfig.singleColor) { ctx.strokeStyle = drawerConfig.singleColor; } - for (let i = 1; i < visualCandles.length; i++) { + // start Idx is 2 because we shouldn't use the first viewport candle, otherwise the line would be out of canvas + // end Idx is length -1 for the same reason, don't use last candle, to correctly display on the right + for (let i = 2; i < visualCandles.length - 1; i++) { const prev = visualCandles[i - 1]; const vc = visualCandles[i]; const direction = vc.name; diff --git a/src/chart/model/data-series.model.ts b/src/chart/model/data-series.model.ts index c0eaf592..54177841 100644 --- a/src/chart/model/data-series.model.ts +++ b/src/chart/model/data-series.model.ts @@ -247,8 +247,8 @@ export class DataSeriesModel< * @returns {DataSeriesViewportIndexes} An object containing the calculated start and end indexes of the data viewport. */ public calculateDataViewportIndexes(xStart: Unit, xEnd: Unit): DataSeriesViewportIndexes { - const dataIdxStart = binarySearch(this.visualPoints, xStart, i => i.centerUnit).index; - const dataIdxEnd = binarySearch(this.visualPoints, xEnd, i => i.centerUnit).index; + const dataIdxStart = binarySearch(this.visualPoints, Math.ceil(xStart), i => i.centerUnit).index; + const dataIdxEnd = binarySearch(this.visualPoints, Math.ceil(xEnd), i => i.centerUnit).index; return { dataIdxStart, dataIdxEnd, From cc9819a9de20ae27784d422dd396fa483cf9c51d Mon Sep 17 00:00:00 2001 From: Anton Vorobev Date: Fri, 29 Dec 2023 13:44:10 +0300 Subject: [PATCH 2/7] fix: recalculate candle idx --- .../drawers/chart-type-drawers/line.drawer.ts | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/src/chart/drawers/chart-type-drawers/line.drawer.ts b/src/chart/drawers/chart-type-drawers/line.drawer.ts index 19c15837..8d8209ef 100644 --- a/src/chart/drawers/chart-type-drawers/line.drawer.ts +++ b/src/chart/drawers/chart-type-drawers/line.drawer.ts @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import { ChartConfigComponentsChart } from '../../chart.config'; +import { ChartConfigComponentsChart, LineStyleTheme } from '../../chart.config'; import { CandleSeriesModel } from '../../model/candle-series.model'; import VisualCandle from '../../model/visual-candle'; import { ChartDrawerConfig, SeriesDrawer, setLineWidth } from '../data-series.drawer'; @@ -30,26 +30,49 @@ export class LineDrawer implements SeriesDrawer { if (drawerConfig.singleColor) { ctx.strokeStyle = drawerConfig.singleColor; } + + if (candleSeries.dataIdxStart === 0) { + const prev = visualCandles[0]; + const vc = visualCandles[1]; + this.drawCandleLine(ctx, prev, vc, drawerConfig, lineTheme, candleSeries); + } // start Idx is 2 because we shouldn't use the first viewport candle, otherwise the line would be out of canvas // end Idx is length -1 for the same reason, don't use last candle, to correctly display on the right + // edge candles lines (first and last ones) are drawn only if they are in viewport for (let i = 2; i < visualCandles.length - 1; i++) { - const prev = visualCandles[i - 1]; - const vc = visualCandles[i]; - const direction = vc.name; - if (!drawerConfig.singleColor) { - ctx.strokeStyle = lineTheme[`${direction}Color`]; - } - const prevX = candleSeries.view.toX(prev.centerUnit); - const prevY = candleSeries.view.toY(prev.close); - const x = candleSeries.view.toX(vc.centerUnit); - const y = candleSeries.view.toY(vc.close); - - ctx.beginPath(); - ctx.moveTo(prevX, prevY); - ctx.lineTo(x, y); + this.drawCandleLine(ctx, visualCandles[i - 1], visualCandles[i], drawerConfig, lineTheme, candleSeries); + } + if (candleSeries.dataPoints.length - 1 === candleSeries.dataIdxEnd) { + const prev = visualCandles[visualCandles.length - 2]; + const vc = visualCandles[visualCandles.length - 1]; + this.drawCandleLine(ctx, prev, vc, drawerConfig, lineTheme, candleSeries); + } + } + } - ctx.stroke(); + drawCandleLine( + ctx: CanvasRenderingContext2D, + prev: VisualCandle, + vc: VisualCandle, + drawerConfig: ChartDrawerConfig, + lineTheme: LineStyleTheme, + candleSeries: CandleSeriesModel, + ) { + if (prev && vc) { + const direction = vc.name; + if (!drawerConfig.singleColor) { + ctx.strokeStyle = lineTheme[`${direction}Color`]; } + const prevX = candleSeries.view.toX(prev.centerUnit); + const prevY = candleSeries.view.toY(prev.close); + const x = candleSeries.view.toX(vc.centerUnit); + const y = candleSeries.view.toY(vc.close); + + ctx.beginPath(); + ctx.moveTo(prevX, prevY); + ctx.lineTo(x, y); + + ctx.stroke(); } } } From 64103784b3eca75571f5a03f878a9fcd8a77873f Mon Sep 17 00:00:00 2001 From: Anton Vorobev Date: Fri, 29 Dec 2023 16:50:12 +0300 Subject: [PATCH 3/7] fix: recalculate candle idx --- src/chart/components/chart/chart.model.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/chart/components/chart/chart.model.ts b/src/chart/components/chart/chart.model.ts index 11c3162c..bf5cf035 100755 --- a/src/chart/components/chart/chart.model.ts +++ b/src/chart/components/chart/chart.model.ts @@ -802,7 +802,8 @@ export class ChartModel extends ChartBaseElement { * @returns {void} */ setTimestampRange(start: Timestamp, end: Timestamp, forceNoAnimation: boolean = true): void { - const startUnit = this.candleFromTimestamp(start).startUnit; + // Move initial viewport startUnit insignificantly to the right to make correct recalculations based on viewport candles + const startUnit = this.candleFromTimestamp(start).startUnit + 0.01; const endCandle = this.candleFromTimestamp(end); const endUnit = endCandle.startUnit + endCandle.width; return this.scale.setXScale(startUnit, endUnit, forceNoAnimation); From cbbbda67785a4ac4f0937ca2e17c65b6306847d9 Mon Sep 17 00:00:00 2001 From: Anton Vorobev Date: Fri, 29 Dec 2023 17:11:23 +0300 Subject: [PATCH 4/7] fix: recalculate candle idx --- src/chart/components/chart/chart.model.ts | 3 +-- src/chart/model/data-series.model.ts | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chart/components/chart/chart.model.ts b/src/chart/components/chart/chart.model.ts index bf5cf035..11c3162c 100755 --- a/src/chart/components/chart/chart.model.ts +++ b/src/chart/components/chart/chart.model.ts @@ -802,8 +802,7 @@ export class ChartModel extends ChartBaseElement { * @returns {void} */ setTimestampRange(start: Timestamp, end: Timestamp, forceNoAnimation: boolean = true): void { - // Move initial viewport startUnit insignificantly to the right to make correct recalculations based on viewport candles - const startUnit = this.candleFromTimestamp(start).startUnit + 0.01; + const startUnit = this.candleFromTimestamp(start).startUnit; const endCandle = this.candleFromTimestamp(end); const endUnit = endCandle.startUnit + endCandle.width; return this.scale.setXScale(startUnit, endUnit, forceNoAnimation); diff --git a/src/chart/model/data-series.model.ts b/src/chart/model/data-series.model.ts index 54177841..e26b344c 100644 --- a/src/chart/model/data-series.model.ts +++ b/src/chart/model/data-series.model.ts @@ -247,7 +247,8 @@ export class DataSeriesModel< * @returns {DataSeriesViewportIndexes} An object containing the calculated start and end indexes of the data viewport. */ public calculateDataViewportIndexes(xStart: Unit, xEnd: Unit): DataSeriesViewportIndexes { - const dataIdxStart = binarySearch(this.visualPoints, Math.ceil(xStart), i => i.centerUnit).index; + // Move initial viewport startUnit insignificantly to the right to make correct recalculations based on viewport candles + const dataIdxStart = binarySearch(this.visualPoints, Math.ceil(xStart + 0.01), i => i.centerUnit).index; const dataIdxEnd = binarySearch(this.visualPoints, Math.ceil(xEnd), i => i.centerUnit).index; return { dataIdxStart, From d4a8cf50f125ca149fca6dbd37c4730b3a8b04cf Mon Sep 17 00:00:00 2001 From: Anton Vorobev Date: Thu, 18 Jan 2024 15:11:30 +0300 Subject: [PATCH 5/7] fix: recalculate candle idx --- src/chart/components/chart/chart.component.ts | 2 +- .../drawers/chart-type-drawers/line.drawer.ts | 58 +++++-------------- .../model/candle-series-high-low.provider.ts | 6 +- src/chart/model/candle-series.model.ts | 2 +- src/chart/model/data-series.model.ts | 18 ++++-- 5 files changed, 36 insertions(+), 50 deletions(-) diff --git a/src/chart/components/chart/chart.component.ts b/src/chart/components/chart/chart.component.ts index f34a3a46..e3cedc4c 100644 --- a/src/chart/components/chart/chart.component.ts +++ b/src/chart/components/chart/chart.component.ts @@ -82,7 +82,7 @@ export class ChartComponent extends ChartBaseElement { private readonly backgroundDrawer: BackgroundDrawer; private readonly _dataSeriesDrawers: Record = {}; private readonly dataSeriesDrawer: DataSeriesDrawer; - private backgroundDrawerPredicateSubject= new BehaviorSubject(true); + private backgroundDrawerPredicateSubject = new BehaviorSubject(true); constructor( public readonly chartModel: ChartModel, diff --git a/src/chart/drawers/chart-type-drawers/line.drawer.ts b/src/chart/drawers/chart-type-drawers/line.drawer.ts index 8d8209ef..d7efbbdd 100644 --- a/src/chart/drawers/chart-type-drawers/line.drawer.ts +++ b/src/chart/drawers/chart-type-drawers/line.drawer.ts @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import { ChartConfigComponentsChart, LineStyleTheme } from '../../chart.config'; +import { ChartConfigComponentsChart } from '../../chart.config'; import { CandleSeriesModel } from '../../model/candle-series.model'; import VisualCandle from '../../model/visual-candle'; import { ChartDrawerConfig, SeriesDrawer, setLineWidth } from '../data-series.drawer'; @@ -30,49 +30,23 @@ export class LineDrawer implements SeriesDrawer { if (drawerConfig.singleColor) { ctx.strokeStyle = drawerConfig.singleColor; } - - if (candleSeries.dataIdxStart === 0) { - const prev = visualCandles[0]; - const vc = visualCandles[1]; - this.drawCandleLine(ctx, prev, vc, drawerConfig, lineTheme, candleSeries); - } - // start Idx is 2 because we shouldn't use the first viewport candle, otherwise the line would be out of canvas - // end Idx is length -1 for the same reason, don't use last candle, to correctly display on the right - // edge candles lines (first and last ones) are drawn only if they are in viewport - for (let i = 2; i < visualCandles.length - 1; i++) { - this.drawCandleLine(ctx, visualCandles[i - 1], visualCandles[i], drawerConfig, lineTheme, candleSeries); - } - if (candleSeries.dataPoints.length - 1 === candleSeries.dataIdxEnd) { - const prev = visualCandles[visualCandles.length - 2]; - const vc = visualCandles[visualCandles.length - 1]; - this.drawCandleLine(ctx, prev, vc, drawerConfig, lineTheme, candleSeries); - } - } - } + for (let i = 1; i < visualCandles.length; i++) { + const prev = visualCandles[i - 1]; + const vc = visualCandles[i]; + const direction = vc.name; + if (!drawerConfig.singleColor) { + ctx.strokeStyle = lineTheme[`${direction}Color`]; + } + const prevX = candleSeries.view.toX(prev.centerUnit); + const prevY = candleSeries.view.toY(prev.close); + const x = candleSeries.view.toX(vc.centerUnit); + const y = candleSeries.view.toY(vc.close); - drawCandleLine( - ctx: CanvasRenderingContext2D, - prev: VisualCandle, - vc: VisualCandle, - drawerConfig: ChartDrawerConfig, - lineTheme: LineStyleTheme, - candleSeries: CandleSeriesModel, - ) { - if (prev && vc) { - const direction = vc.name; - if (!drawerConfig.singleColor) { - ctx.strokeStyle = lineTheme[`${direction}Color`]; + ctx.beginPath(); + ctx.moveTo(prevX, prevY); + ctx.lineTo(x, y); + ctx.stroke(); } - const prevX = candleSeries.view.toX(prev.centerUnit); - const prevY = candleSeries.view.toY(prev.close); - const x = candleSeries.view.toX(vc.centerUnit); - const y = candleSeries.view.toY(vc.close); - - ctx.beginPath(); - ctx.moveTo(prevX, prevY); - ctx.lineTo(x, y); - - ctx.stroke(); } } } diff --git a/src/chart/model/candle-series-high-low.provider.ts b/src/chart/model/candle-series-high-low.provider.ts index 7b684bed..b963bc9c 100644 --- a/src/chart/model/candle-series-high-low.provider.ts +++ b/src/chart/model/candle-series-high-low.provider.ts @@ -20,7 +20,11 @@ export const createCandleSeriesHighLowProvider = (candleSeriesModel: CandleSerie calculateHighLow: (state: ViewportModelState | undefined) => { const xStart = state ? state.xStart : candleSeriesModel.scale.xStart; const xEnd = state ? state.xEnd : candleSeriesModel.scale.xEnd; - const { dataIdxStart, dataIdxEnd } = candleSeriesModel.calculateDataViewportIndexes(xStart, xEnd); + const { dataIdxStart, dataIdxEnd } = candleSeriesModel.calculateDataViewportIndexes( + xStart, + xEnd, + (i: VisualCandle) => i.startUnit, + ); // +1 because dataIdxEnd candle should be included in the result const visualCandles = candleSeriesModel.visualPoints.slice(dataIdxStart, dataIdxEnd + 1); const highLowWithIndex = calculateCandlesHighLow(visualCandles); diff --git a/src/chart/model/candle-series.model.ts b/src/chart/model/candle-series.model.ts index 16632b16..eb66475e 100644 --- a/src/chart/model/candle-series.model.ts +++ b/src/chart/model/candle-series.model.ts @@ -90,7 +90,7 @@ export class CandleSeriesModel extends DataSeriesModel { * @returns {void} */ recalculateDataViewportIndexes(xStart = this.scale.xStart, xEnd = this.scale.xEnd) { - super.recalculateDataViewportIndexes(xStart, xEnd); + super.recalculateDataViewportIndexes(xStart, xEnd, (i: VisualCandle) => i.startUnit); this.recalculateZippedHighLow(); this.eventBus.fireDraw(); } diff --git a/src/chart/model/data-series.model.ts b/src/chart/model/data-series.model.ts index e26b344c..d8c7ef6d 100644 --- a/src/chart/model/data-series.model.ts +++ b/src/chart/model/data-series.model.ts @@ -232,8 +232,12 @@ export class DataSeriesModel< * @param {number} [xStart=this.scale.xStart] - The start value of the viewport on the x-axis. Defaults to the current xStart value of the scale model. * @param {number} [xEnd=this.scale.xEnd] - The end value of the viewport on the x-axis. Defaults to the current xEnd value of the scale model. */ - public recalculateDataViewportIndexes(xStart = this.scale.xStart, xEnd = this.scale.xEnd) { - const { dataIdxStart, dataIdxEnd } = this.calculateDataViewportIndexes(xStart, xEnd); + public recalculateDataViewportIndexes( + xStart = this.scale.xStart, + xEnd = this.scale.xEnd, + getter = (i: V) => i.centerUnit, + ) { + const { dataIdxStart, dataIdxEnd } = this.calculateDataViewportIndexes(xStart, xEnd, getter); this.dataIdxStart = dataIdxStart; this.dataIdxEnd = dataIdxEnd; } @@ -246,10 +250,14 @@ export class DataSeriesModel< * @param {Unit} xEnd - The end value of the viewport on the x-axis. * @returns {DataSeriesViewportIndexes} An object containing the calculated start and end indexes of the data viewport. */ - public calculateDataViewportIndexes(xStart: Unit, xEnd: Unit): DataSeriesViewportIndexes { + public calculateDataViewportIndexes( + xStart: Unit, + xEnd: Unit, + getter = (i: V) => i.centerUnit, + ): DataSeriesViewportIndexes { // Move initial viewport startUnit insignificantly to the right to make correct recalculations based on viewport candles - const dataIdxStart = binarySearch(this.visualPoints, Math.ceil(xStart + 0.01), i => i.centerUnit).index; - const dataIdxEnd = binarySearch(this.visualPoints, Math.ceil(xEnd), i => i.centerUnit).index; + const dataIdxStart = binarySearch(this.visualPoints, xStart, getter).index; + const dataIdxEnd = binarySearch(this.visualPoints, xEnd, getter).index; return { dataIdxStart, dataIdxEnd, From 3cb6a92396c9c42ca26c57e9e0f1271b61e2295b Mon Sep 17 00:00:00 2001 From: Anton Vorobev Date: Thu, 18 Jan 2024 15:12:57 +0300 Subject: [PATCH 6/7] fix: recalculate candle idx --- src/chart/model/data-series.model.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/chart/model/data-series.model.ts b/src/chart/model/data-series.model.ts index d8c7ef6d..e8252e40 100644 --- a/src/chart/model/data-series.model.ts +++ b/src/chart/model/data-series.model.ts @@ -255,7 +255,6 @@ export class DataSeriesModel< xEnd: Unit, getter = (i: V) => i.centerUnit, ): DataSeriesViewportIndexes { - // Move initial viewport startUnit insignificantly to the right to make correct recalculations based on viewport candles const dataIdxStart = binarySearch(this.visualPoints, xStart, getter).index; const dataIdxEnd = binarySearch(this.visualPoints, xEnd, getter).index; return { From 2167549724c051d5e40238cb52d58351cc2ba675 Mon Sep 17 00:00:00 2001 From: Denis Travin Date: Thu, 8 Feb 2024 17:07:48 +0500 Subject: [PATCH 7/7] fix: refactored indexes recalculation for CandleSeriesModel --- .../model/candle-series-high-low.provider.ts | 6 +--- src/chart/model/candle-series.model.ts | 30 ++++++++++++++++--- src/chart/model/data-series.model.ts | 24 +++++++-------- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/chart/model/candle-series-high-low.provider.ts b/src/chart/model/candle-series-high-low.provider.ts index b963bc9c..7b684bed 100644 --- a/src/chart/model/candle-series-high-low.provider.ts +++ b/src/chart/model/candle-series-high-low.provider.ts @@ -20,11 +20,7 @@ export const createCandleSeriesHighLowProvider = (candleSeriesModel: CandleSerie calculateHighLow: (state: ViewportModelState | undefined) => { const xStart = state ? state.xStart : candleSeriesModel.scale.xStart; const xEnd = state ? state.xEnd : candleSeriesModel.scale.xEnd; - const { dataIdxStart, dataIdxEnd } = candleSeriesModel.calculateDataViewportIndexes( - xStart, - xEnd, - (i: VisualCandle) => i.startUnit, - ); + const { dataIdxStart, dataIdxEnd } = candleSeriesModel.calculateDataViewportIndexes(xStart, xEnd); // +1 because dataIdxEnd candle should be included in the result const visualCandles = candleSeriesModel.visualPoints.slice(dataIdxStart, dataIdxEnd + 1); const highLowWithIndex = calculateCandlesHighLow(visualCandles); diff --git a/src/chart/model/candle-series.model.ts b/src/chart/model/candle-series.model.ts index eb66475e..7800687f 100644 --- a/src/chart/model/candle-series.model.ts +++ b/src/chart/model/candle-series.model.ts @@ -11,14 +11,14 @@ import { ChartInstrument } from '../components/chart/chart.component'; import { CandleWidthCalculator, VisualCandleCalculator } from '../components/chart/chart.model'; import { YExtentComponent } from '../components/pane/extent/y-extent-component'; import EventBus from '../events/event-bus'; -import { lastOf } from '../utils/array.utils'; +import { binarySearch, lastOf } from '../utils/array.utils'; import { merge } from '../utils/merge.utils'; import { DeepPartial } from '../utils/object.utils'; import { PriceIncrementsUtils } from '../utils/price-increments.utils'; import { calculateCandlesHighLow, createCandleSeriesHighLowProvider } from './candle-series-high-low.provider'; import { BASIC_CANDLE_WIDTH, Candle, nameDirection } from './candle.model'; import { DataSeriesType } from './data-series.config'; -import { DataSeriesModel } from './data-series.model'; +import { DataSeriesModel, DataSeriesViewportIndexes } from './data-series.model'; import { HighLowWithIndex, ScaleModel, getDefaultHighLowWithIndex } from './scale.model'; import { Unit } from './scaling/viewport.model'; import VisualCandle from './visual-candle'; @@ -90,11 +90,31 @@ export class CandleSeriesModel extends DataSeriesModel { * @returns {void} */ recalculateDataViewportIndexes(xStart = this.scale.xStart, xEnd = this.scale.xEnd) { - super.recalculateDataViewportIndexes(xStart, xEnd, (i: VisualCandle) => i.startUnit); + const { dataIdxStart, dataIdxEnd } = this.calculateDataViewportIndexes(xStart, xEnd); + this.dataIdxStart = dataIdxStart; + this.dataIdxEnd = dataIdxEnd; + this.recalculateZippedHighLow(); this.eventBus.fireDraw(); } + /** + * Calculates and returns the indexes of the start and end points of the data viewport, + * based on the given start and end units on the x-axis. + * + * @param {Unit} xStart - The start value of the viewport on the x-axis. + * @param {Unit} xEnd - The end value of the viewport on the x-axis. + * @returns {DataSeriesViewportIndexes} An object containing the calculated start and end indexes of the data viewport. + */ + public calculateDataViewportIndexes(xStart: Unit, xEnd: Unit): DataSeriesViewportIndexes { + const dataIdxStart = binarySearch(this.visualPoints, xStart, (it: VisualCandle) => it.startUnit).index; + const dataIdxEnd = binarySearch(this.visualPoints, xEnd, (it: VisualCandle) => it.startUnit).index; + return { + dataIdxStart, + dataIdxEnd, + }; + } + /** * Calculates the price movement of the last candle by comparing the open and close prices. * Sets the lastPriceMovement property of the instance with the name of the direction of the price movement. @@ -210,7 +230,9 @@ export class CandleSeriesModel extends DataSeriesModel { // x - middle of candle const x = accumulatedWidth + width / 2; const transformer = this.candlesTransformersByChartType[type] ?? defaultCandleTransformer; - visualCandles.push(transformer(candle, { x, width, prevCandle, activeCandle: this.activeCandle }, visualCandles[i - 1])); + visualCandles.push( + transformer(candle, { x, width, prevCandle, activeCandle: this.activeCandle }, visualCandles[i - 1]), + ); accumulatedWidth += width; } return visualCandles; diff --git a/src/chart/model/data-series.model.ts b/src/chart/model/data-series.model.ts index e8252e40..6fb80edb 100644 --- a/src/chart/model/data-series.model.ts +++ b/src/chart/model/data-series.model.ts @@ -147,7 +147,11 @@ export class DataSeriesModel< protected doActivate(): void { this.addRxSubscription(this.scale.xChanged.subscribe(() => this.recalculateDataViewportIndexes())); - this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(() => { this.recalculateVisualPoints(); })); + this.addRxSubscription( + this.scale.scaleInversedSubject.subscribe(() => { + this.recalculateVisualPoints(); + }), + ); } /** @@ -232,12 +236,8 @@ export class DataSeriesModel< * @param {number} [xStart=this.scale.xStart] - The start value of the viewport on the x-axis. Defaults to the current xStart value of the scale model. * @param {number} [xEnd=this.scale.xEnd] - The end value of the viewport on the x-axis. Defaults to the current xEnd value of the scale model. */ - public recalculateDataViewportIndexes( - xStart = this.scale.xStart, - xEnd = this.scale.xEnd, - getter = (i: V) => i.centerUnit, - ) { - const { dataIdxStart, dataIdxEnd } = this.calculateDataViewportIndexes(xStart, xEnd, getter); + public recalculateDataViewportIndexes(xStart = this.scale.xStart, xEnd = this.scale.xEnd) { + const { dataIdxStart, dataIdxEnd } = this.calculateDataViewportIndexes(xStart, xEnd); this.dataIdxStart = dataIdxStart; this.dataIdxEnd = dataIdxEnd; } @@ -250,13 +250,9 @@ export class DataSeriesModel< * @param {Unit} xEnd - The end value of the viewport on the x-axis. * @returns {DataSeriesViewportIndexes} An object containing the calculated start and end indexes of the data viewport. */ - public calculateDataViewportIndexes( - xStart: Unit, - xEnd: Unit, - getter = (i: V) => i.centerUnit, - ): DataSeriesViewportIndexes { - const dataIdxStart = binarySearch(this.visualPoints, xStart, getter).index; - const dataIdxEnd = binarySearch(this.visualPoints, xEnd, getter).index; + public calculateDataViewportIndexes(xStart: Unit, xEnd: Unit): DataSeriesViewportIndexes { + const dataIdxStart = binarySearch(this.visualPoints, xStart, (i: V) => i.centerUnit).index; + const dataIdxEnd = binarySearch(this.visualPoints, xEnd, (i: V) => i.centerUnit).index; return { dataIdxStart, dataIdxEnd,