Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I detect if the tooltip is being shown? (I want to check for a deselect event) #496

Closed
meirinberg opened this issue Oct 15, 2024 · 5 comments
Labels

Comments

@meirinberg
Copy link

meirinberg commented Oct 15, 2024

I see that this was an old Highcharts question here with the answer leading to this JSFiddle. However, I haven't found the way to check if the tooltip is hidden using AAChartKit-Swift. For my application, I use the basic and custom callbacks to pass data when the user selects points (using moveOverEventMessage in basic instances and .mouseOver(js injection) when I need to pass a custom object). This works great and it allows me to show chart details that are synchronized with the tooltip (awesome!). However, I'd like these details to disappear when the tooltip disappears so I need to know when the tooltip is showing or when the user deselects.

This is my initial attempt, but the callback doesn't fire when the tooltip is hidden:

            aaOptions.chart?.events(
                AAChartEvents()
                    .load("""
                    function() {
                        const tooltip = this.chart.tooltip;
                        let message = {
                        selectionID: ""
                        };
                        if (tooltip.isHidden && window.webkit && window.webkit.messageHandlers) {
                            window.webkit.messageHandlers.deselect.postMessage(message);
                        }
                    }
            """))

Any help is appreciated, thank you!

@AAChartModel
Copy link
Owner

Refer to this commit:

@AAChartModel
Copy link
Owner

However, using a timer to get the isHidden status of the tooltip is a bad idea; it is both annoying and highly inefficient.

AAChartModel added a commit that referenced this issue Oct 15, 2024
@AAChartModel
Copy link
Owner

With the help of online AI tools, I found a better solution.
Please refer to this commit for the improved approach:

@AAChartModel
Copy link
Owner

You need to update the demo to see the all new code.

@meirinberg
Copy link
Author

meirinberg commented Oct 15, 2024

That worked! The following code snippet is exactly what I wanted.

  .load("""
        function() {
            Highcharts.wrap(Highcharts.Tooltip.prototype, 'hide', function (proceed, delay) {
                proceed.apply(this, Array.prototype.slice.call(arguments, 1));
                window.webkit.messageHandlers.deselect.postMessage('Tooltip is being hidden');
            });
        }
        """))

Thanks so much for the fast and helpful response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants