From e40ee5a1ee3edc93ae6de5dc718de679792155d6 Mon Sep 17 00:00:00 2001 From: Edward Dewhurst Date: Tue, 2 Nov 2021 10:47:01 +0000 Subject: [PATCH] Copy markers left of first changed index --- src/model/series.ts | 6 +++-- .../series-markers/set-series-data.js | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/e2e/graphics/test-cases/series-markers/set-series-data.js diff --git a/src/model/series.ts b/src/model/series.ts index 8ba2c14b69..87ee402a25 100644 --- a/src/model/series.ts +++ b/src/model/series.ts @@ -576,14 +576,16 @@ export class Series extends PriceDataSource i return; } - const indexedMarkers = []; - const firstDataIndex = ensureNotNull(this._data.firstIndex()); let startIndex = this._indexedMarkers.findIndex((m: InternalSeriesMarker) => m.time >= firstChangedPointIndex); if (startIndex === -1) { startIndex = 0; } + // We can copy marks with a time point index < firstChangedPointIndex because we know they have not changed. + const indexedMarkers = this._indexedMarkers.slice(0, startIndex); + const firstDataIndex = ensureNotNull(this._data.firstIndex()); + for (let index = startIndex; index < this._markers.length; index++) { const marker = this._markers[index]; // the first find index on the time scale (across all series) diff --git a/tests/e2e/graphics/test-cases/series-markers/set-series-data.js b/tests/e2e/graphics/test-cases/series-markers/set-series-data.js new file mode 100644 index 0000000000..ac814ea532 --- /dev/null +++ b/tests/e2e/graphics/test-cases/series-markers/set-series-data.js @@ -0,0 +1,27 @@ +function runTestCase(container) { + const chart = LightweightCharts.createChart(container); + + const candlestickSeries = chart.addCandlestickSeries(); + + candlestickSeries.setData([ + { time: '2021-10-01', open: 100, high: 110, low: 100, close: 110 }, + { time: '2021-10-02', open: 110, high: 110, low: 100, close: 100 }, + { time: '2021-10-03', open: 100, high: 110, low: 100, close: 110 }, + { time: '2021-10-04', open: 120, high: 130, low: 120, close: 125 }, + ]); + + candlestickSeries.setMarkers([ + { time: '2021-10-01', position: 'aboveBar', shape: 'circle' }, + { time: '2021-10-02', position: 'aboveBar', shape: 'circle' }, + { time: '2021-10-03', position: 'aboveBar', shape: 'circle' }, + { time: '2021-10-04', position: 'aboveBar', shape: 'circle' }, + ]); + + candlestickSeries.setData([ + { time: '2021-10-01', open: 100, high: 110, low: 100, close: 110 }, + { time: '2021-10-02', open: 110, high: 110, low: 100, close: 100 }, + { time: '2021-10-04', open: 120, high: 130, low: 120, close: 125 }, + ]); + + chart.timeScale().fitContent(); +}