From cf5b3da8f8d4eaeb72c4c5d62796b268c09b239e Mon Sep 17 00:00:00 2001 From: Mark Silverwood Date: Mon, 5 Jun 2023 12:06:44 +0100 Subject: [PATCH] fix re-enabling of autoSize after disabling it --- src/gui/chart-widget.ts | 1 + .../applying-options/re-enable-autosize.js | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/e2e/graphics/test-cases/applying-options/re-enable-autosize.js diff --git a/src/gui/chart-widget.ts b/src/gui/chart-widget.ts index 5cd01d5cd6..6099c8c3cd 100644 --- a/src/gui/chart-widget.ts +++ b/src/gui/chart-widget.ts @@ -802,6 +802,7 @@ export class ChartWidget implements IDestroyable { if (this._observer !== null) { this._observer.disconnect(); } + this._observer = null; } } diff --git a/tests/e2e/graphics/test-cases/applying-options/re-enable-autosize.js b/tests/e2e/graphics/test-cases/applying-options/re-enable-autosize.js new file mode 100644 index 0000000000..693e377559 --- /dev/null +++ b/tests/e2e/graphics/test-cases/applying-options/re-enable-autosize.js @@ -0,0 +1,45 @@ +window.ignoreMouseMove = true; +function generateData() { + 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: i, + }); + + time.setUTCDate(time.getUTCDate() + 1); + } + + return res; +} + +function runTestCase(container) { + const box = document.createElement('div'); + box.style.position = 'absolute'; + box.style.top = 0; + box.style.left = 0; + box.style.width = '200px'; + box.style.height = '200px'; + container.appendChild(box); + + const chart = LightweightCharts.createChart(box, { autoSize: true, height: 200, width: 200 }); + const mainSeries = chart.addAreaSeries(); + + mainSeries.setData(generateData()); + + return new Promise(resolve => { + requestAnimationFrame(() => { + // remove autoSize + chart.applyOptions({ autoSize: false }); + box.style.height = '225px'; + requestAnimationFrame(() => { + // enable autoSize again. + // This test case is checking that you can have autoSize enabled, then removed, and then re-added again + chart.applyOptions({ autoSize: true }); + box.style.height = '250px'; + setTimeout(resolve, 300); + }); + }); + }); +}