You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I needed to merge sliders if they overlapped and found a function in the documentation (https://refreshless.com/nouislider/examples/#section-merging-tooltips) that could help me achieve this. However, I had to set a hardcoded minimum proximity, which was not ideal since my tooltips have different sizes.
To address this issue, I updated the script for merging tooltips. Here's the code I used:
/** * @param slider HtmlElement with an initialized slider * @param separator String joining tooltips */exportfunctionmergeTooltips(slider,separator){vartextIsRtl=window.getComputedStyle(slider).direction==="rtl";varisRtl=slider.noUiSlider.options.direction==="rtl";varisVertical=slider.noUiSlider.options.orientation==="vertical";vartooltips=slider.noUiSlider.getTooltips();varorigins=slider.noUiSlider.getOrigins();// Move tooltips into the origin element. The default stylesheet handles this.tooltips.forEach(function(tooltip,index){if(tooltip){origins[index].appendChild(tooltip);}});slider.noUiSlider.on("update",function(values,handle,unencoded,tap,positions){varpools=[[]];varpoolPositions=[[]];varpoolValues=[[]];varatPool=0;// Assign the first tooltip to the first pool, if the tooltip is configuredif(tooltips[0]){pools[0][0]=0;poolPositions[0][0]=positions[0];poolValues[0][0]=values[0];}for(vari=1;i<positions.length;i++){// HERE's MY CODEconsttooltipLeft=tooltips[i-1].getBoundingClientRect();consttooltipRight=tooltips[i].getBoundingClientRect();if(!(tooltipLeft.x<tooltipRight.x&&tooltipLeft.x+tooltipLeft.width>tooltipRight.x)){atPool++;pools[atPool]=[];poolValues[atPool]=[];poolPositions[atPool]=[];}// HERE's MY CODE ENDif(tooltips[i]){pools[atPool].push(i);poolValues[atPool].push(values[i]);poolPositions[atPool].push(positions[i]);}}pools.forEach(function(pool,poolIndex){varhandlesInPool=pool.length;for(varj=0;j<handlesInPool;j++){varhandleNumber=pool[j];if(j===handlesInPool-1){varoffset=0;poolPositions[poolIndex].forEach(function(value){offset+=1000-value;});vardirection=isVertical ? "bottom" : "right";varlast=isRtl ? 0 : handlesInPool-1;varlastOffset=1000-poolPositions[poolIndex][last];offset=(textIsRtl&&!isVertical ? 100 : 0)+offset/handlesInPool-lastOffset;// Center this tooltip over the affected handlestooltips[handleNumber].innerHTML=poolValues[poolIndex].join(separator);tooltips[handleNumber].style.removeProperty("visibility");tooltips[handleNumber].style[direction]=offset+"%";}else{// Hide this tooltiptooltips[handleNumber].style.visibility="hidden";}}});});}
My approach uses tooltip position and widths to determine which tooltips need to be merged, which I believe is an improvement over a hardcoded percentage.
Thank you for taking the time to read my issue and for any feedback you may have.
The text was updated successfully, but these errors were encountered:
Hello! Thank you for a good slider!
I needed to merge sliders if they overlapped and found a function in the documentation (https://refreshless.com/nouislider/examples/#section-merging-tooltips) that could help me achieve this. However, I had to set a hardcoded minimum proximity, which was not ideal since my tooltips have different sizes.
To address this issue, I updated the script for merging tooltips. Here's the code I used:
My approach uses tooltip position and widths to determine which tooltips need to be merged, which I believe is an improvement over a hardcoded percentage.
Thank you for taking the time to read my issue and for any feedback you may have.
The text was updated successfully, but these errors were encountered: