Skip to content

Commit

Permalink
Copy markers left of first changed index
Browse files Browse the repository at this point in the history
  • Loading branch information
edew committed Nov 2, 2021
1 parent 08f9aa4 commit e40ee5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/model/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,16 @@ export class Series<T extends SeriesType = SeriesType> extends PriceDataSource i
return;
}

const indexedMarkers = [];
const firstDataIndex = ensureNotNull(this._data.firstIndex());
let startIndex = this._indexedMarkers.findIndex((m: InternalSeriesMarker<TimePointIndex>) => 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)
Expand Down
27 changes: 27 additions & 0 deletions tests/e2e/graphics/test-cases/series-markers/set-series-data.js
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit e40ee5a

Please sign in to comment.