amcharts5 icon indicating copy to clipboard operation
amcharts5 copied to clipboard

Toggle showTooltipOn based on zoom / scrollbar start end

Open bluefire2121 opened this issue 2 years ago • 1 comments

In amCharts5, is there a way to toggle showTooltipOn based on how many elements are display in a chart at a given zoom level?

I'd like showTooltipOn = 'always' when the distance between scrollbar start and end is 0.2 or less.

I'd like showTooltipOn = 'hover' when the distance between scrollbar start and end is greater than 0.2.

bluefire2121 avatar Oct 14 '22 21:10 bluefire2121

You can use the settings value change callback to monitor the scrollbar's start and end updates and adjust showTooltipOn your series/sprite accordingly:

scrollbar.on('start', (start, target) => {
  updateShowTooltipOn(start, target.get('end'))
})

scrollbar.on('end', (end, target) => {
  updateShowTooltipOn(target.get('start'), end)
}) 

function updateShowTooltipOn(start, end) {
  let showTooltipOn = end - start > .2 ? 'hover' : 'always'
  // set showTooltipOn on your series/sprite/etc here 
}

xorspark avatar Oct 15 '22 11:10 xorspark

Thanks @martynasma , I've tried a similar setup in the past with the difference being an absolute value and checking specifically if end and start are numbers and are not null (otherwise a value of zero will fail the truthy check), but that's the not issue.

The issue is the chart doesn't update again when setting a series column template tooltip after the value of showtooltipon has been updated. :-(

bluefire2121 avatar Oct 26 '22 18:10 bluefire2121

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.

github-actions[bot] avatar Nov 26 '22 00:11 github-actions[bot]