Skip to content

Commit

Permalink
Merge pull request #843 from tradingview/fix823-incorrect-bar-spacing…
Browse files Browse the repository at this point in the history
…-when-edges-are-fixed
  • Loading branch information
timocov authored Sep 10, 2021
2 parents ccd4080 + 89426ae commit bdb0760
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/model/time-scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ export class TimeScale {
private _minBarSpacing(): number {
// if both options are enabled then limit bar spacing so that zooming-out is not possible
// if it would cause either the first or last points to move too far from an edge
if (this._options.fixLeftEdge && this._options.fixRightEdge) {
if (this._options.fixLeftEdge && this._options.fixRightEdge && this._points.length !== 0) {
return this._width / this._points.length;
}

Expand Down
36 changes: 36 additions & 0 deletions tests/e2e/graphics/test-cases/applying-options/fix-both-edges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function generateBar(i, target) {
const step = (i % 20) / 1000;
const base = i;
target.open = base * (1 - step);
target.high = base * (1 + 2 * step);
target.low = base * (1 - 2 * step);
target.close = base * (1 + step);
}

function generateData() {
const res = [];
const time = new Date(Date.UTC(2018, 0, 1, 0, 0, 0, 0));
for (let i = 0; i < 500; ++i) {
const item = {
time: time.getTime() / 1000,
};
time.setUTCDate(time.getUTCDate() + 1);

generateBar(i, item);
res.push(item);
}
return res;
}

function runTestCase(container) {
const chart = LightweightCharts.createChart(container, {
timeScale: {
fixLeftEdge: true,
fixRightEdge: true,
},
});

const mainSeries = chart.addCandlestickSeries();

mainSeries.setData(generateData());
}

0 comments on commit bdb0760

Please sign in to comment.