Skip to content

Commit

Permalink
Removed deprecated options
Browse files Browse the repository at this point in the history
Fixes #626
  • Loading branch information
timocov committed Nov 8, 2021
1 parent b58f2c3 commit f68f62a
Show file tree
Hide file tree
Showing 22 changed files with 117 additions and 175 deletions.
81 changes: 81 additions & 0 deletions docs/4.0-breaking-changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Version 4.0 breaking changes

In this document you can find the migration guide from the previous version v3 to v4.

## Exported enum `LasPriceAnimationMode` has been removed

Please use `LastPriceAnimationMode` instead.

## `scaleMargins` option has been removed from series options

Previously, you could do something like the following:

```js
const series = chart.addLineSeries({
scaleMargins: { /* options here */},
});
```

And `scaleMargins` option was applied to series' price scale as `scaleMargins` option.

Since v4 this option won't be applied to the price scale and will be just ignored (if you're using TypeScript you will get a compilation error).

To fix this, you need to apply these options to series' price scale:

```js
const series = chart.addLineSeries();

series.priceScale().applyOptions({
scaleMargins: { /* options here */},
});
```

## `backgroundColor` from `layout` options has been removed

If you want to have solid background color you need to use `background` property instead, e.g. instead of:

```js
const chart = createChart({
layout: {
backgroundColor: 'red',
},
});
```

use

```js
const chart = createChart({
layout: {
background: {
type: ColorType.Solid,
color: 'red',
},
},
});
```

## `overlay` property of series options has been removed

Please follow [the guide from v3.0 breaking changes](./3.0-breaking-changes.md#creating-overlay) where this option was deprecated.

## `priceScale` option has been removed

Please follow [the guide from v3.0 breaking changes](./3.0-breaking-changes.md#two-price-scales).

## `priceScale()` method of chart API now requires to provide price scale id

Before v4 you could write the following code:

```js
const priceScale = chart.priceScale();
```

And in `priceScale` you had a right price scale if it is visible and a left price scale otherwise.

Since v4 you have to provide an ID of price scale explicitly, e.g. if you want to get a right price scale you need to provide `'right'`:

```js
const rightPriceScale = chart.priceScale('right');
const leftPriceScale = chart.priceScale('left');
```
3 changes: 1 addition & 2 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ The following set of options can be used to adjust the price axis interface:

```js
chart.applyOptions({
priceScale: {
position: 'left',
rightPriceScale: {
mode: 2,
autoScale: false,
invertScale: true,
Expand Down
9 changes: 0 additions & 9 deletions docs/series-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Here are common parameters for every series:
|-|----|-------|-|
|`priceScaleId`|`string`|`right` if right scale is visible and `left` if not|Target price scale to bind new series to|
|`title`|`string`|`''`|You can name series when adding it to a chart. This name will be displayed on the label next to the last value label|
|`scaleMargins`|`{ top, bottom }`|`undefined`|[Margins](#scale-margins) of the price scale of series|
|`visible`|`boolean`|`true`|Visibility of series|

Example:
Expand All @@ -49,10 +48,6 @@ Example:
const lineSeries = chart.addLineSeries({
priceScaleId: 'left',
title: 'Series title example',
scaleMargins: {
top: 0.1,
bottom: 0.3,
},
});
```

Expand Down Expand Up @@ -120,10 +115,6 @@ Each value of an object is a number between 0 (0%) and 1 (100%).
```js
const lineSeries = chart.addLineSeries({
priceScaleId: 'right',
scaleMargins: {
top: 0.6,
bottom: 0.05,
},
});
```

Expand Down
69 changes: 2 additions & 67 deletions src/api/chart-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { ChartWidget, MouseEventParamsImpl, MouseEventParamsImplSupplier } from

import { ensureDefined } from '../helpers/assertions';
import { Delegate } from '../helpers/delegate';
import { warn } from '../helpers/logger';
import { clone, DeepPartial, isBoolean, merge } from '../helpers/strict-type-checks';

import { BarPrice, BarPrices } from '../model/bar';
import { ChartOptions, ChartOptionsInternal } from '../model/chart-model';
import { ColorType } from '../model/layout-options';
import { Series } from '../model/series';
import {
AreaSeriesOptions,
Expand Down Expand Up @@ -47,7 +45,7 @@ import {
seriesOptionsDefaults,
} from './options/series-options-defaults';
import { PriceScaleApi } from './price-scale-api';
import { migrateOptions, SeriesApi } from './series-api';
import { SeriesApi } from './series-api';
import { TimeScaleApi } from './time-scale-api';

function patchPriceFormat(priceFormat?: DeepPartial<PriceFormat>): void {
Expand Down Expand Up @@ -91,60 +89,8 @@ function migrateHandleScaleScrollOptions(options: DeepPartial<ChartOptions>): vo
}
}

function migratePriceScaleOptions(options: DeepPartial<ChartOptions>): void {
/* eslint-disable deprecation/deprecation */
if (options.priceScale) {
warn('"priceScale" option has been deprecated, use "leftPriceScale", "rightPriceScale" and "overlayPriceScales" instead');

options.leftPriceScale = options.leftPriceScale || {};
options.rightPriceScale = options.rightPriceScale || {};

const position = options.priceScale.position;
delete options.priceScale.position;

options.leftPriceScale = merge(options.leftPriceScale, options.priceScale);
options.rightPriceScale = merge(options.rightPriceScale, options.priceScale);

if (position === 'left') {
options.leftPriceScale.visible = true;
options.rightPriceScale.visible = false;
}
if (position === 'right') {
options.leftPriceScale.visible = false;
options.rightPriceScale.visible = true;
}
if (position === 'none') {
options.leftPriceScale.visible = false;
options.rightPriceScale.visible = false;
}
// copy defaults for overlays
options.overlayPriceScales = options.overlayPriceScales || {};
if (options.priceScale.invertScale !== undefined) {
options.overlayPriceScales.invertScale = options.priceScale.invertScale;
}
// do not migrate mode for backward compatibility
if (options.priceScale.scaleMargins !== undefined) {
options.overlayPriceScales.scaleMargins = options.priceScale.scaleMargins;
}
}
/* eslint-enable deprecation/deprecation */
}

export function migrateLayoutOptions(options: DeepPartial<ChartOptions>): void {
/* eslint-disable deprecation/deprecation */
if (!options.layout) {
return;
}
if (options.layout.backgroundColor && !options.layout.background) {
options.layout.background = { type: ColorType.Solid, color: options.layout.backgroundColor };
}
/* eslint-enable deprecation/deprecation */
}

function toInternalOptions(options: DeepPartial<ChartOptions>): DeepPartial<ChartOptionsInternal> {
migrateHandleScaleScrollOptions(options);
migratePriceScaleOptions(options);
migrateLayoutOptions(options);

return options as DeepPartial<ChartOptionsInternal>;
}
Expand Down Expand Up @@ -210,7 +156,6 @@ export class ChartApi implements IChartApi, DataUpdatesConsumer<SeriesType> {
}

public addAreaSeries(options: AreaSeriesPartialOptions = {}): ISeriesApi<'Area'> {
options = migrateOptions(options);
patchPriceFormat(options.priceFormat);

const strictOptions = merge(clone(seriesOptionsDefaults), areaStyleDefaults, options) as AreaSeriesOptions;
Expand All @@ -224,7 +169,6 @@ export class ChartApi implements IChartApi, DataUpdatesConsumer<SeriesType> {
}

public addBaselineSeries(options: BaselineSeriesPartialOptions = {}): ISeriesApi<'Baseline'> {
options = migrateOptions(options);
patchPriceFormat(options.priceFormat);

const strictOptions = merge(clone(seriesOptionsDefaults), baselineStyleDefaults, options) as BaselineSeriesOptions;
Expand All @@ -238,7 +182,6 @@ export class ChartApi implements IChartApi, DataUpdatesConsumer<SeriesType> {
}

public addBarSeries(options: BarSeriesPartialOptions = {}): ISeriesApi<'Bar'> {
options = migrateOptions(options);
patchPriceFormat(options.priceFormat);

const strictOptions = merge(clone(seriesOptionsDefaults), barStyleDefaults, options) as BarSeriesOptions;
Expand All @@ -252,7 +195,6 @@ export class ChartApi implements IChartApi, DataUpdatesConsumer<SeriesType> {
}

public addCandlestickSeries(options: CandlestickSeriesPartialOptions = {}): ISeriesApi<'Candlestick'> {
options = migrateOptions(options);
fillUpDownCandlesticksColors(options);
patchPriceFormat(options.priceFormat);

Expand All @@ -267,7 +209,6 @@ export class ChartApi implements IChartApi, DataUpdatesConsumer<SeriesType> {
}

public addHistogramSeries(options: HistogramSeriesPartialOptions = {}): ISeriesApi<'Histogram'> {
options = migrateOptions(options);
patchPriceFormat(options.priceFormat);

const strictOptions = merge(clone(seriesOptionsDefaults), histogramStyleDefaults, options) as HistogramSeriesOptions;
Expand All @@ -281,7 +222,6 @@ export class ChartApi implements IChartApi, DataUpdatesConsumer<SeriesType> {
}

public addLineSeries(options: LineSeriesPartialOptions = {}): ISeriesApi<'Line'> {
options = migrateOptions(options);
patchPriceFormat(options.priceFormat);

const strictOptions = merge(clone(seriesOptionsDefaults), lineStyleDefaults, options) as LineSeriesOptions;
Expand Down Expand Up @@ -331,12 +271,7 @@ export class ChartApi implements IChartApi, DataUpdatesConsumer<SeriesType> {
this._crosshairMovedDelegate.unsubscribe(handler);
}

public priceScale(priceScaleId?: string): IPriceScaleApi {
if (priceScaleId === undefined) {
warn('Using ChartApi.priceScale() method without arguments has been deprecated, pass valid price scale id instead');
priceScaleId = this._chartWidget.model().defaultVisiblePriceScaleId();
}

public priceScale(priceScaleId: string): IPriceScaleApi {
return new PriceScaleApi(this._chartWidget, priceScaleId);
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/ichart-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export interface IChartApi {
* @param priceScaleId - id of the price scale.
* @returns Price scale API.
*/
priceScale(priceScaleId?: string): IPriceScaleApi;
priceScale(priceScaleId: string): IPriceScaleApi;

/**
* Returns API to manipulate the time scale
Expand Down
4 changes: 2 additions & 2 deletions src/api/options/layout-options-defaults.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defaultFontFamily } from '../../helpers/make-font';

import { ColorType, LayoutOptionsInternal } from '../../model/layout-options';
import { ColorType, LayoutOptions } from '../../model/layout-options';

export const layoutOptionsDefaults: LayoutOptionsInternal = {
export const layoutOptionsDefaults: LayoutOptions = {
background: {
type: ColorType.Solid,
color: '#FFFFFF',
Expand Down
4 changes: 2 additions & 2 deletions src/api/price-scale-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ChartWidget } from '../gui/chart-widget';
import { ensureNotNull } from '../helpers/assertions';
import { DeepPartial } from '../helpers/strict-type-checks';

import { DefaultPriceScaleId, isDefaultPriceScale } from '../model/default-price-scale';
import { isDefaultPriceScale } from '../model/default-price-scale';
import { PriceScale, PriceScaleOptions } from '../model/price-scale';

import { IPriceScaleApi } from './iprice-scale-api';
Expand All @@ -30,7 +30,7 @@ export class PriceScaleApi implements IPriceScaleApi {
return 0;
}

return this._chartWidget.getPriceAxisWidth(this._priceScaleId === DefaultPriceScaleId.Left ? 'left' : 'right');
return this._chartWidget.getPriceAxisWidth(this._priceScaleId);
}

private _priceScale(): PriceScale {
Expand Down
14 changes: 2 additions & 12 deletions src/api/series-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Coordinate } from '../model/coordinate';
import { PlotRowSearchMode } from '../model/plot-list';
import { PriceLineOptions } from '../model/price-line-options';
import { RangeImpl } from '../model/range-impl';
import { Series, SeriesPartialOptionsInternal } from '../model/series';
import { Series } from '../model/series';
import { SeriesMarker } from '../model/series-markers';
import {
SeriesOptionsMap,
Expand All @@ -28,15 +28,6 @@ import { BarsInfo, ISeriesApi } from './iseries-api';
import { priceLineOptionsDefaults } from './options/price-line-options-defaults';
import { PriceLine } from './price-line-api';

export function migrateOptions<TSeriesType extends SeriesType>(options: SeriesPartialOptionsMap[TSeriesType]): SeriesPartialOptionsInternal<TSeriesType> {
// eslint-disable-next-line deprecation/deprecation
const { overlay, ...res } = options;
if (overlay) {
res.priceScaleId = '';
}
return res;
}

export class SeriesApi<TSeriesType extends SeriesType> implements ISeriesApi<TSeriesType> {
protected _series: Series<TSeriesType>;
protected _dataUpdatesConsumer: DataUpdatesConsumer<TSeriesType>;
Expand Down Expand Up @@ -146,8 +137,7 @@ export class SeriesApi<TSeriesType extends SeriesType> implements ISeriesApi<TSe
}

public applyOptions(options: SeriesPartialOptionsMap[TSeriesType]): void {
const migratedOptions = migrateOptions(options);
this._series.applyOptions(migratedOptions);
this._series.applyOptions(options);
}

public options(): Readonly<SeriesOptionsMap[TSeriesType]> {
Expand Down
12 changes: 4 additions & 8 deletions src/gui/chart-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { DeepPartial } from '../helpers/strict-type-checks';
import { BarPrice, BarPrices } from '../model/bar';
import { ChartModel, ChartOptionsInternal } from '../model/chart-model';
import { Coordinate } from '../model/coordinate';
import { DefaultPriceScaleId } from '../model/default-price-scale';
import {
InvalidateMask,
InvalidationLevel,
TimeScaleInvalidation,
TimeScaleInvalidationType,
} from '../model/invalidate-mask';
import { Point } from '../model/point';
import { PriceAxisPosition } from '../model/price-scale';
import { Series } from '../model/series';
import { TimePoint, TimePointIndex } from '../model/time-data';

Expand Down Expand Up @@ -230,7 +230,7 @@ export class ChartWidget implements IDestroyable {
let targetX = 0;
let targetY = 0;

const drawPriceAxises = (position: PriceAxisPosition) => {
const drawPriceAxises = (position: 'left' | 'right') => {
for (let paneIndex = 0; paneIndex < this._paneWidgets.length; paneIndex++) {
const paneWidget = this._paneWidgets[paneIndex];
const paneWidgetHeight = paneWidget.getSize().h;
Expand Down Expand Up @@ -272,7 +272,7 @@ export class ChartWidget implements IDestroyable {
targetY = 0;
drawPriceAxises('right');
}
const drawStub = (position: PriceAxisPosition) => {
const drawStub = (position: 'left' | 'right') => {
const stub = ensureNotNull(position === 'left' ? this._timeAxisWidget.leftStub() : this._timeAxisWidget.rightStub());
const size = stub.getSize();
const image = stub.getImage();
Expand All @@ -298,11 +298,7 @@ export class ChartWidget implements IDestroyable {
return targetCanvas;
}

public getPriceAxisWidth(position: PriceAxisPosition): number {
if (position === 'none') {
return 0;
}

public getPriceAxisWidth(position: DefaultPriceScaleId): number {
if (position === 'left' && !this._isLeftAxisVisible()) {
return 0;
}
Expand Down
Loading

0 comments on commit f68f62a

Please sign in to comment.