highcharts / highcharts-ios

iOS wrapper for Highcharts.
Other
127 stars 39 forks source link

How to hide tooltip tapping on it or the same selected segment of chart in SWIFT #308

Closed oleh-hastov closed 4 years ago

oleh-hastov commented 4 years ago

How to hide tooltip tapping on it or the same selected segment of the chart in iOS? Can you provide SWIFT example, please?

ihnatmoisieiev commented 4 years ago

Hello @gasta-java,

what do you mean the same selected segment of the chart?

oleh-hastov commented 4 years ago

@ihnatmoisieiev So I am attaching a screenshot. You can see the first rect is tooltip and the second is same selected segment

Screenshot at Apr 27 18-49-25
ihnatmoisieiev commented 4 years ago

@gasta-java please try to add the following configuration to your HIOptions obejct:

let chart = HIChart()
chart.events = HIEvents()
chart.events.load = HIFunction(jsFunction: "function () { var chart = this, series = chart.series, addEvent = Highcharts.addEvent; series.forEach(function (serie) { serie.data.forEach(function(point) { addEvent(point.graphic.element, 'touchstart', function(){ if (!point.series.chart.tooltip.isHidden) { point.series.chart.tooltip.hide(); } else { point.series.chart.tooltip.refresh(point, {}, true); } }); }); }); }")
options.chart = chart
oleh-hastov commented 4 years ago

@ihnatmoisieiev thank you a lot! It works for tapping on selected segment. But it does not work for tapping on the tooltip by itself. The tooltip looks like does not catch touch events. Can you help with this, please? For example: If I tap on the zone I marked on the img it does not close tooltip but opens tooltip for the segment which is under the tooltip at tapped point:

Screenshot at Apr 28 17-31-03
ihnatmoisieiev commented 4 years ago

@gasta-java unfortunately, there is no any default implementation for this. As a workaround, you can try the following:

let plotOptions = HIPlotOptions()
plotOptions.series = HISeries()
plotOptions.series.point = HIPoint()
plotOptions.series.point.events = HIEvents()
plotOptions.series.point.events.click = HIFunction(jsFunction: "function() { var chart = this.series.chart, addEvent = Highcharts.addEvent; if (chart.tooltip && !chart.tooltip.addedEvent) { addEvent(chart.tooltip.label.element, 'touchstart', function() { if (!point.series.chart.tooltip.isHidden) { point.series.chart.tooltip.hide(); } else { point.series.chart.tooltip.refresh(point, {}, true); } chart.tooltip.addedEvent = true; }); } }")
options.plotOptions = plotOptions
oleh-hastov commented 4 years ago

@ihnatmoisieiev thanks! But for some reason, it does not work. Can't we just catch a click on tooltip somehow and close it?

ihnatmoisieiev commented 4 years ago

@gasta-java unfortunately, it's impossible as I know.

oleh-hastov commented 4 years ago

@ihnatmoisieiev thanks, got it. So do you have any thoughts why your example does nto close tooltip when I try it? plotOptions.series.point.events.click = HIFunction(jsFunction: "function() { var chart = this.series.chart, addEvent = Highcharts.addEvent; if (chart.tooltip && !chart.tooltip.addedEvent) { addEvent(chart.tooltip.label.element, 'touchstart', function() { if (!point.series.chart.tooltip.isHidden) { point.series.chart.tooltip.hide(); } else { point.series.chart.tooltip.refresh(point, {}, true); } chart.tooltip.addedEvent = true; }); } }")

ihnatmoisieiev commented 4 years ago

@gasta-java it works for me:

Screen-Recording-2020-04-30-at-09 35 20

oleh-hastov commented 4 years ago

@ihnatmoisieiev okay, it looks like it's 'cause you're using default tooltip. So okay, I will investigate this;

ihnatmoisieiev commented 4 years ago

Closing due to inactivity.