Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two price scales #290

Merged
merged 55 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
5a373de
129: two price scales
eugene-korobko Dec 19, 2019
59f0122
129: Fixed overlay behavior
eugene-korobko Dec 24, 2019
a5658f4
129: Fixed graph tests
eugene-korobko Dec 24, 2019
4420961
129: Fixed tslint
eugene-korobko Dec 24, 2019
b9fe1ca
129: Fixed review issues
eugene-korobko Dec 30, 2019
f527624
129: Fixed applying options, added tests
eugene-korobko Dec 30, 2019
73d74c4
129: Improved test
eugene-korobko Dec 31, 2019
d217577
129: Step to new API
eugene-korobko Jan 30, 2020
a6f469b
129: New scales API
eugene-korobko Feb 3, 2020
6b7b792
129: Added doc
eugene-korobko Feb 3, 2020
1be67d2
129: Added graphic tests
eugene-korobko Feb 4, 2020
2ac0db7
129: Fixed processing empty price scale id
eugene-korobko Feb 4, 2020
ae6e1ef
Update src/api/chart-api.ts
eugene-korobko Feb 4, 2020
bd8a3b7
Update src/api/chart-api.ts
eugene-korobko Feb 4, 2020
4e89f7c
Update src/api/chart-api.ts
eugene-korobko Feb 4, 2020
6523a38
Update src/api/chart-api.ts
eugene-korobko Feb 4, 2020
cc734e5
129: Updated docs
eugene-korobko Feb 4, 2020
7fae31f
129: Fixed review issues
eugene-korobko Feb 4, 2020
d77d862
Merge branch 'master' into 129-two-price-axises
eugene-korobko Feb 4, 2020
5409713
129: Fixed applying price scale options
eugene-korobko Feb 6, 2020
c824a58
129: Fixed review issues & tests
eugene-korobko Feb 26, 2020
55aab16
129: Improved typings, added docs
eugene-korobko Feb 28, 2020
0ac12ae
129: Fixed review issues
eugene-korobko Mar 10, 2020
9352908
129: Fixed review issues
eugene-korobko Mar 11, 2020
897c89a
Merge branch 'master' into 129-two-price-axises
eugene-korobko Mar 11, 2020
e38f1ed
129: Fixed backward compatibility
eugene-korobko Mar 12, 2020
97807f5
Updated docs
timocov Mar 19, 2020
599f403
Review style fixes
timocov Mar 19, 2020
21d8974
Fixed build
timocov Mar 19, 2020
1091990
129: Fixed review issues
eugene-korobko Mar 20, 2020
5b1618c
129: Fixed review issues
eugene-korobko Mar 26, 2020
bd75723
129: Fixed linter
eugene-korobko Mar 26, 2020
c152897
129: Fixed linter
eugene-korobko Mar 26, 2020
79402ae
129: Throw exception instead of log
eugene-korobko Mar 27, 2020
8607967
A bit refactored debug messages/errors
timocov Mar 27, 2020
5ba818f
129: Removed PriceScaleAPI cache, improved docs
eugene-korobko Mar 27, 2020
cfc39d7
Apply suggestions from code review
timocov Mar 30, 2020
e3b1453
Update codechecks to pass test
timocov Mar 30, 2020
6245190
Fixed types
timocov Mar 30, 2020
a862876
Merge branch 'master' into 129-two-price-axises
timocov Mar 30, 2020
7630844
Fixed codechecks config after merge master
timocov Mar 30, 2020
26ce7ab
129: Fixed applying scale margins to series
eugene-korobko Mar 30, 2020
c2186f6
Merge branch 'master' into 129-two-price-axises
eugene-korobko Apr 16, 2020
0c748c4
129: Implemented moving series from scale to scale
eugene-korobko Apr 17, 2020
8ce22fb
129: Fixed typo in docs
eugene-korobko Apr 17, 2020
8d69e87
129: Fixed review issues
eugene-korobko Apr 17, 2020
40eebef
129: Fixed review issues
eugene-korobko Apr 22, 2020
9387fa8
Don't generate random price scale id if empty id passed
timocov Apr 29, 2020
19d4823
Fixed tslint error
timocov Apr 29, 2020
2835775
Removed useless method containsSeries
timocov Apr 30, 2020
7e1e0a3
Removed unused hasSeries method
timocov Apr 30, 2020
7e8e764
Extracted default price scales to separate module to avoid circular d…
timocov Apr 30, 2020
9673493
Removed unused method setPriceAutoScaleForAllMainSources
timocov Apr 30, 2020
043145f
Merge branch 'master' into 129-two-price-axises
eugene-korobko May 7, 2020
06ebec2
Merge branch 'master' into 129-two-price-axises
eugene-korobko May 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions docs/3.0-breaking-changes.md
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',
timocov marked this conversation as resolved.
Show resolved Hide resolved
});
```

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: '',
timocov marked this conversation as resolved.
Show resolved Hide resolved
});
```

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.
40 changes: 40 additions & 0 deletions docs/price-scale.md
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.
timocov marked this conversation as resolved.
Show resolved Hide resolved

## 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.
45 changes: 34 additions & 11 deletions docs/series-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ Here are common parameters for every series:

|Name|Type|Default|Description|
|-|----|-------|-|
|`overlay`|`boolean`|`false`|Whether or not series should be an overlay|
|`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 _overlay_ series|
|`scaleMargins`|`{ top, bottom }`|`undefined`|[Margins](#scale-margins) of the price scale of series|

Example:

```javascript
const lineSeries = chart.addLineSeries({
overlay: true,
priceScaleId: 'left',
title: 'Series title example',
scaleMargins: {
top: 0.1,
Expand All @@ -55,15 +55,38 @@ const lineSeries = chart.addLineSeries({
});
```

### Overlay
### Binding to price scale

When adding any series to a chart, you can specify if you want target series to be attached to a price axis. By default, series are attached to a price axis.
When adding any series to a chart, you can specify if you want target series to be attached to a certain price axis - left or right.
By default, series are attached to the right price axis.
This means one can scale the series with price axis. Note that price axis visible range depends on series values.
In contrast, overlay series just draws itself on a chart independent from the price axis.

```javascript
const lineSeries = chart.addLineSeries({
overlay: true,
priceScaleId: 'left',
});
```

In contrast, overlay series just draws itself on a chart independent from the visible price axis.
To create overlay specify unique id as a `priceScaleId` or just keep is as empty string.

```javascript
const lineSeries = chart.addLineSeries({
priceScaleId: 'my-overlay-id',
});
```

At any moment you can get access to the price scale the series is bound to with `priceScale` method and change its options

```javascript
const lineSeries = chart.addLineSeries({
priceScaleId: 'my-overlay-id',
});
lineSeries.priceScale().applyOptions({
scaleMargins: {
top: 0.1,
bottom: 0.3,
},
});
```

Expand All @@ -84,7 +107,7 @@ Typically, we do not want series to be drawn too close to a chart border. It nee

By default, the library keeps an empty space below the data (10%) and above the data (20%).

These values could be adjusted for visible axis using chart options. However, you can also define them for overlay series.
These values could be adjusted for visible axis using chart options. However, you can also define them for series.

The margins is an object with the following properties:

Expand All @@ -95,7 +118,7 @@ Each value of an object is a number between 0 (0%) and 1 (100%).

```javascript
const lineSeries = chart.addLineSeries({
overlay: true,
priceScaleId: 'right,
scaleMargins: {
top: 0.6,
bottom: 0.05,
Expand All @@ -105,11 +128,11 @@ const lineSeries = chart.addLineSeries({

The code above places series at the bottom of a chart.

You can change margins using `ChartApi.applyOptions` for the visible axis:
You can change margins using `ChartApi.applyOptions` for the certain axis:

```javascript
chart.applyOptions({
priceScale: {
rightPriceScale: {
scaleMargins: {
top: 0.6,
bottom: 0.05,
Expand Down
Loading