From 745c14bb7f21ae72c27d3a6edbd3b3192f61ddbe Mon Sep 17 00:00:00 2001 From: louisnw Date: Sat, 24 Feb 2024 13:01:37 +0000 Subject: [PATCH] Fix toolbox hotkey chart selection and toolbox resize display bug (#267) --- lightweight_charts/js/callback.js | 2 -- lightweight_charts/js/funcs.js | 22 ++++++++++++++++------ lightweight_charts/js/toolbox.js | 5 +++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lightweight_charts/js/callback.js b/lightweight_charts/js/callback.js index 34e594a..5d1cde3 100644 --- a/lightweight_charts/js/callback.js +++ b/lightweight_charts/js/callback.js @@ -225,8 +225,6 @@ function makeSearchBox(chart) { chart.chart.subscribeCrosshairMove((param) => { if (param.point) yPrice = param.point.y; }) - window.selectedChart = chart - chart.wrapper.addEventListener('mouseover', (event) => window.selectedChart = chart) chart.commandFunctions.push((event) => { if (selectedChart !== chart) return false if (searchWindow.style.display === 'none') { diff --git a/lightweight_charts/js/funcs.js b/lightweight_charts/js/funcs.js index dc61ffa..ec61abc 100644 --- a/lightweight_charts/js/funcs.js +++ b/lightweight_charts/js/funcs.js @@ -70,6 +70,10 @@ if (!window.Chart) { if (this.commandFunctions[i](event)) break } }) + + window.selectedChart = this + this.wrapper.addEventListener('mouseover', (e) => window.selectedChart = this) + if (!autoSize) return window.addEventListener('resize', () => this.reSize()) } @@ -78,14 +82,20 @@ if (!window.Chart) { this.chart.resize(window.innerWidth * this.scale.width, (window.innerHeight * this.scale.height) - topBarOffset) this.wrapper.style.width = `${100 * this.scale.width}%` this.wrapper.style.height = `${100 * this.scale.height}%` - if (this.legend) { - if (this.scale.height === 0 || this.scale.width === 0) { - this.legend.div.style.display = 'none' - } - else { - this.legend.div.style.display = 'flex' + + if (this.scale.height === 0 || this.scale.width === 0) { + this.legend.div.style.display = 'none' + if (this.toolBox) { + this.toolBox.elem.style.display = 'none' } } + else { + this.legend.div.style.display = 'flex' + if (this.toolBox) { + this.toolBox.elem.style.display = 'flex' + } + } + } makeCandlestickSeries() { diff --git a/lightweight_charts/js/toolbox.js b/lightweight_charts/js/toolbox.js index c33296b..d899cb8 100644 --- a/lightweight_charts/js/toolbox.js +++ b/lightweight_charts/js/toolbox.js @@ -117,6 +117,11 @@ if (!window.ToolBox) { this.chart.activeIcon.action(true) }) this.chart.commandFunctions.push((event) => { + + if (this.chart !== window.selectedChart) { + return + } + if (event.altKey && event.code === keyCmd) { event.preventDefault() if (this.chart.activeIcon) {