Skip to content

Commit

Permalink
Add method priceLines in ISeriesAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
signatenkov committed Nov 21, 2024
1 parent 40c8cc5 commit 580ae8e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/api/iseries-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ export interface ISeriesApi<
*/
removePriceLine(line: IPriceLine): void;

/**
* Returns an array of price lines.
*/
priceLines(): IPriceLine[];

/**
* Return current series type.
*
Expand Down
4 changes: 4 additions & 0 deletions src/api/series-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ export class SeriesApi<
this._series.removePriceLine((line as PriceLine).priceLine());
}

public priceLines(): IPriceLine[] {
return this._series.priceLines();
}

public seriesType(): TSeriesType {
return this._series.seriesType();
}
Expand Down
4 changes: 4 additions & 0 deletions src/model/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ export class Series<T extends SeriesType> extends PriceDataSource implements IDe
this.model().updateSource(this);
}

public priceLines(): CustomPriceLine[] {
return this._customPriceLines.slice();
}

public seriesType(): T {
return this._seriesType;
}
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/graphics/test-cases/series/price-lines-remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ function runTestCase(container) {
const series = chart.addSeries(LightweightCharts.LineSeries);
series.setData(generateData());

const line1 = series.createPriceLine({ price: 10 });
const line2 = series.createPriceLine({ price: 20 });
series.createPriceLine({ price: 10 });
series.createPriceLine({ price: 20 });

return new Promise(resolve => {
setTimeout(() => {
const [line1, line2] = series.priceLines();
series.removePriceLine(line2);
series.removePriceLine(line1);
resolve();
Expand Down

0 comments on commit 580ae8e

Please sign in to comment.