From ae27d22740773be354bd0d7f9e36af713f21d5ef Mon Sep 17 00:00:00 2001 From: Evgeniy Timokhov Date: Tue, 26 May 2020 18:28:08 +0300 Subject: [PATCH] Don't adjust size simultaneously when options were applied to time scale Fixes #443 --- src/gui/chart-widget.ts | 8 +--- .../empty-time-scale-options.js | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 tests/e2e/graphics/test-cases/applying-options/empty-time-scale-options.js diff --git a/src/gui/chart-widget.ts b/src/gui/chart-widget.ts index ab697747d5..38771f12d8 100644 --- a/src/gui/chart-widget.ts +++ b/src/gui/chart-widget.ts @@ -104,13 +104,7 @@ export class ChartWidget implements IDestroyable { container.appendChild(this._element); this._updateTimeAxisVisibility(); - this._model.timeScale().optionsApplied().subscribe( - () => { - this._updateTimeAxisVisibility(); - this.adjustSize(); - }, - this - ); + this._model.timeScale().optionsApplied().subscribe(this._model.fullUpdate.bind(this._model), this); } public model(): ChartModel { diff --git a/tests/e2e/graphics/test-cases/applying-options/empty-time-scale-options.js b/tests/e2e/graphics/test-cases/applying-options/empty-time-scale-options.js new file mode 100644 index 0000000000..d903001d22 --- /dev/null +++ b/tests/e2e/graphics/test-cases/applying-options/empty-time-scale-options.js @@ -0,0 +1,38 @@ +function generateBar(i, target) { + var step = (i % 20) / 1000; + var base = i / 5; + target.open = base * (1 - step); + target.high = base * (1 + 2 * step); + target.low = base * (1 - 2 * step); + target.close = base * (1 + step); +} + +function generateData() { + var res = []; + var time = new Date(Date.UTC(2018, 0, 1, 0, 0, 0, 0)); + for (var i = 0; i < 500; ++i) { + var item = { + time: time.getTime() / 1000, + }; + time.setUTCDate(time.getUTCDate() + 1); + + generateBar(i, item); + res.push(item); + } + return res; +} + +// eslint-disable-next-line no-unused-vars +function runTestCase(container) { + var chart = LightweightCharts.createChart(container); + + var mainSeries = chart.addCandlestickSeries(); + + mainSeries.setData(generateData()); + + chart.applyOptions({ + leftPriceScale: { visible: true }, + rightPriceScale: { visible: true }, + timeScale: {}, + }); +}