Skip to content

Commit

Permalink
fix: overlay align to the right when no left/right price scale defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Ffloriel committed Dec 7, 2021
1 parent f8b7d30 commit d70b804
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ module.exports = [
{
name: 'Standalone',
path: 'dist/lightweight-charts.standalone.production.js',
limit: '44.0 KB',
limit: '44.01 KB',
},
];
15 changes: 12 additions & 3 deletions src/model/chart-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,18 @@ export class ChartModel implements IDestroyable {

return;
}

res.priceScale.applyOptions(options);
this._priceScalesOptionsChanged.fire();
if (priceScaleId === 'left') {
this.applyOptions({
leftPriceScale: options,
});
} else if (priceScaleId === 'right') {
this.applyOptions({
rightPriceScale: options,
});
} else {
res.priceScale.applyOptions(options);
this._priceScalesOptionsChanged.fire();
}
}

public findPriceScale(priceScaleId: string): PriceScaleOnPane | null {
Expand Down
7 changes: 3 additions & 4 deletions src/views/pane/pane-price-axis-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ export class PanePriceAxisView implements IPaneView {
}

const position = pane.priceScalePosition(priceScale);
if (position === 'overlay') {
return null;
}
// with no left and right price scale, overlay will be align to the right
const align = position === 'overlay' ? 'right' : position;

const options = this._chartModel.priceAxisRendererOptions();
if (options.fontSize !== this._fontSize) {
this._fontSize = options.fontSize;
this._textWidthCache.reset();
}

this._renderer.setParams(this._priceAxisView.paneRenderer(), options, width, position);
this._renderer.setParams(this._priceAxisView.paneRenderer(), options, width, align);
return this._renderer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function generateData(func) {
const res = [];
const time = new Date(Date.UTC(2018, 0, 1, 0, 0, 0, 0));
for (let i = 0; i < 500; ++i) {
res.push({
time: time.getTime() / 1000,
value: func(i),
});

time.setUTCDate(time.getUTCDate() + 1);
}
return res;
}

function runTestCase(container) {
const chart = LightweightCharts.createChart(container);

const line1 = chart.addLineSeries({
priceScaleId: 'overlay',
color: 'rgb(255, 0, 0)',
title: 'SIN',
});
const line2 = chart.addLineSeries({
priceScaleId: 'overlay',
color: 'rgb(0, 255, 0)',
title: 'COS',
});

line1.setData(generateData(Math.sin));
line2.setData(generateData(Math.cos));
}

0 comments on commit d70b804

Please sign in to comment.