leongersen / noUiSlider

noUiSlider is a lightweight, ARIA-accessible JavaScript range slider with multi-touch and keyboard support. It is fully GPU animated: no reflows, so it is fast; even on older devices. It also fits wonderfully in responsive designs and has no dependencies.
https://refreshless.com/nouislider/
MIT License
5.69k stars 656 forks source link

Joining overlapping tooltips #1032

Closed omuryildirim closed 4 years ago

omuryildirim commented 4 years ago

Goal: join and display single tooltip whenever two tooltips overlaps.

Solution: Catch overlapping tooltips by calculating their start and end points in x coordinate. Then add a new tooltip to the handle on the right side. Add a margin-left to adjust it to middle of two handles. Finally, make overlapping tooltips invisible.

Hope this fix helps everyone in need of it. Thanks for your contributions with noUiSlider.

jasongrout commented 4 years ago

FYI, ion slider (used by R shiny) has a nice polished UX for this. If the tooltips would overlap, they join into a single tooltip:

Screen Shot 2020-01-07 at 11 38 31 AM
jbarradas commented 4 years ago

Is anyone working on this? Just ran into this issue. Screenshot from 2020-02-21 10-17-57

leongersen commented 4 years ago

The documentation now has an example for merging overlapping tooltips. Thanks for contributing, everyone!

image

bjarnef commented 4 years ago

@leongersen thanks, it seems to work great! 👍

When e.g. the two handles have same value, would it be possible to merge these to a single tooltip value?

image

Examples from Ion.RangeSlider

Handles with different values image

Handles with same value image

jasongrout commented 4 years ago

Thanks! This example goes a long ways to making the slider more user friendly. It does seem to have some glitches in some cases, for example when I set the sliders to have 47.85, 50, 65.42, 73.60, and 73.60:

Screen Shot 2020-05-07 at 3 03 36 AM
leongersen commented 4 years ago

@bjarnef Yes, you could extend the line poolValues[poolIndex].join(separator); in the example by filtering it for unique values.

@jasongrout You could slightly increase the threshold passed to the mergeTooltips function in the example,. e.g. to 20.

bjarnef commented 4 years ago

@leongersen thanks, it seems to work perfect!

I modfied these lines.

var tooltipValues = poolValues[poolIndex].filter((v, i, a) => a.indexOf(v) === i); 

// Center this tooltip over the affected handles
tooltips[handleNumber].innerHTML = tooltipValues.join(separator);

image

github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.