export default function FunnelTooltip(palette, funnel) { return (context) => { const tooltipModel = context.tooltip const dataIndex = tooltipModel.dataPoints[0].dataIndex const offset = document.getElementById("funnel").getBoundingClientRect() let tooltipEl = document.getElementById('chartjs-tooltip') if (!tooltipEl) { tooltipEl = document.createElement('div') tooltipEl.id = 'chartjs-tooltip' tooltipEl.style.display = 'none' tooltipEl.style.opacity = 0 document.body.appendChild(tooltipEl) } if (tooltipEl && offset && window.innerWidth < 768) { tooltipEl.style.top = offset.y + offset.height + window.scrollY + 15 + 'px' tooltipEl.style.left = offset.x + 'px' tooltipEl.style.right = null tooltipEl.style.opacity = 1 } if (tooltipModel.opacity === 0) { tooltipEl.style.display = 'none' return } if (tooltipModel.body) { const currentStep = funnel.steps[dataIndex] const previousStep = (dataIndex > 0) ? funnel.steps[dataIndex - 1] : null tooltipEl.innerHTML = ` ` } tooltipEl.style.display = null } }