-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #290 from tradingview/129-two-price-axises
- Loading branch information
Showing
34 changed files
with
1,334 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
# Version 3.0 breaking change | ||
|
||
Lighweight charts library 3.0 announces the major improvement: supporting two price scales. | ||
In order of keeping API clear and consistent, we desided to allow breaking change of the API. | ||
We understand disadvantages of breaking changes in the API, so we have not removed support of the current API at all, but have deprecated it, so the most common cases will continue working. | ||
You could refer new API [here](./price-scale.md) | ||
|
||
Following are migration rules. | ||
|
||
## Default behavior | ||
|
||
Default behavior is not changed. If you do not specify price scale options, the chart will have right price scale visible and all the serieses will assign to it. | ||
|
||
## Left price scale | ||
|
||
If you need the price scale to be drawn on the left side, you should make following changes. | ||
instead of | ||
|
||
```javascript | ||
var chart = LightweightCharts.createChart(container, { | ||
priceScale: { | ||
position: 'left', | ||
}, | ||
}); | ||
``` | ||
|
||
use | ||
|
||
```javascript | ||
var chart = LightweightCharts.createChart(container, { | ||
rightPriceScale: { | ||
visible: false, | ||
}, | ||
leftPriceScale: { | ||
visible: true, | ||
}, | ||
}); | ||
``` | ||
|
||
then specify target price scale while creating a series: | ||
|
||
```javascript | ||
var histSeries = chart.addHistogramSeries({ | ||
priceScaleId: 'left', | ||
}); | ||
``` | ||
|
||
New version fully supports this case via old API, however this support will be removed in the future releases. | ||
|
||
## No price scale | ||
|
||
To create chart without any visible price scale, instead of | ||
|
||
```javascript | ||
var chart = LightweightCharts.createChart(container, { | ||
priceScale: { | ||
position: 'none', | ||
}, | ||
}); | ||
``` | ||
|
||
use | ||
|
||
```javascript | ||
var chart = LightweightCharts.createChart(container, { | ||
leftPriceScale: { | ||
visible: false, | ||
}, | ||
rightPriceScale: { | ||
visible: false, | ||
}, | ||
}); | ||
``` | ||
|
||
New version fully supports this case via old API, however this support will be removed in the future releases. | ||
|
||
## Creating overlay | ||
|
||
To create an overlay series, instead of | ||
|
||
```javascript | ||
var histogramSeries = chart.addHistogramSeries({ | ||
overlay: true, | ||
}); | ||
``` | ||
|
||
use | ||
|
||
```javascript | ||
var histogramSeries = chart.addHistogramSeries({ | ||
// or any other _the same_ id for all overlay series | ||
priceScaleId: '', | ||
}); | ||
``` | ||
|
||
New version fully supports this case via old API, however this support will be removed in the future releases. | ||
|
||
## Move price scale from right to left or vice versa | ||
|
||
To do this, instead of | ||
|
||
```javascript | ||
var chart = LightweightCharts.createChart(container); | ||
|
||
var mainSeries = chart.addLineSeries(); | ||
|
||
... | ||
|
||
chart.applyOptions({ | ||
priceScale: { | ||
position: 'left', | ||
}, | ||
}); | ||
``` | ||
|
||
use | ||
|
||
```javascript | ||
var chart = LightweightCharts.createChart(container); | ||
|
||
var mainSeries = chart.addLineSeries(); | ||
|
||
... | ||
|
||
chart.applyOptions({ | ||
leftPriceScale: { | ||
visible: 'true', | ||
}, | ||
rightPriceScale: { | ||
visible: 'false', | ||
}, | ||
}); | ||
|
||
mainSeries.applyOptions({ | ||
priceScaleId: 'left, | ||
}); | ||
``` | ||
New version does not support this case via old API, so, if you use it, you should migrate your code in order of keeping it working. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Price Scale | ||
|
||
Price Scale is an object that maps prices to coordinates and vice versa. | ||
The rules of converting depend on price scale mod, visible height of chart and visible part of data. | ||
|
||
Chart always has two predefined price scales: left and right, and unlimited number of overlay scales. | ||
Left and right price scales could be visible, overlay price scales are always hidden, so the user cannot interact them directly. | ||
|
||
## Autoscale | ||
|
||
Autoscaling is a feature of automatic adjusting price scale to fit the visible range of data. | ||
Autoscaling is enabled by default, however you could turn it off by zooming price scale or calling `PriceScaleApi.setOptions` method with `autoScale` field set to false. | ||
Overlay price scales are always autoscaled. | ||
|
||
## PriceScale ID | ||
|
||
Each price scale has corresponsing ID to refer it via API. Left and right price scales have predefined IDs `left` and `right`. | ||
While creating a series, you could specify PriceScaleID. | ||
If this id refers to already existing price scale, new series will share the price scale with already existing series. | ||
If specified price scale does not exist, it will be implicitly created. | ||
So to create two series on the same overlay price scale just specify the same `priceScaleId` for them. | ||
You could get `id` of the scale with `PriceScaleApi.id` method. | ||
|
||
## Percentage scales | ||
|
||
Percentage mode of price scale allows relative comparing of series. | ||
All the serieses attached to the percentage scale are placed to have the first visible data item on the same point. | ||
Percentage scales are always autoscaled. | ||
|
||
## Logarithmic scales | ||
|
||
The reason of having logarithmic scales is comparing relative change instead of absolute change. | ||
On regular scale every candle with 100-points change has the same height. | ||
On logarithmic scale every candle with 2% change has the same height. | ||
Logarithmic scale cannot be percentage. | ||
|
||
## Equality of price scales | ||
|
||
Lightweight charts library does not guarantee to return the same instance of `PriceScaleApi` object while returning the same actual price scale. | ||
So you should never compare objects of `PriceScaleApi`, comapre `PriceScaleApi.id()` values instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.