UNPKG

echarts-tooltip-auto-show

Version:
2 lines (1 loc) 3.11 kB
const e=function(){const e=navigator.userAgent;return{mobile:Boolean(e.match(/AppleWebKit.*Mobile.*/)),ios:Boolean(e.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)),android:e.includes("Android")||e.includes("Linux"),iPhone:e.includes("iPhone"),iPad:e.includes("iPad")}}();navigator.language.toLowerCase();function n(n,t,o){const i={interval:2e3,loopSeries:!1,seriesIndex:0,updateData:null,bounce:null};if(!n||!t||!t.series)return;let s=0,a=0,r=0;const d=Array.isArray(t.series)?t.series.length:1;let c=0,u="",p=!0;function l(){const e=0===s&&o.loopSeries?0===a?d-1:a-1:a;if(t.series){const o=Array.isArray(t.series)?t.series[e].type:t.series.type;"pie"!==o&&"radar"!==o&&"map"!==o||n.dispatchAction({type:"downplay"})}}function f(){function e(){const e=n.getDom();if(!document.documentElement.contains(e))return void b();0!==s||p||"function"!=typeof o.updateData||(o.updateData(),n.setOption(t));const i=Array.isArray(t.series)?t.series:[t.series],r=i[a];if(!(i&&0!==i.length&&r&&r.type&&r.data&&Array.isArray(r.data)))return;u=r.type,c=r.data.length;const f=r.data[s],h={type:"",seriesIndex:a};switch(u){case"pie":case"map":case"chord":h.name=f.name;break;default:h.seriesIndex=a,h.dataIndex=s}"pie"!==u&&"radar"!==u&&"map"!==u||(p||l(),n.dispatchAction({type:"highlight",seriesIndex:a,dataIndex:s})),setTimeout((()=>{h.type="hideTip",n.dispatchAction(h),h.type="showTip",n.dispatchAction(h),o.bounce&&"function"==typeof o.bounce&&o.bounce(f,a,s)}),0),s=(s+1)%c,o.loopSeries&&0===s&&(a=(a+1)%d),p=!1}r||(p&&e(),r=window.setInterval(e,o.interval))}function h(){r&&(clearInterval(r),r=0,"pie"!==u&&"radar"!==u&&"map"!==u||l())}o?(o.interval=o.interval??i.interval,o.loopSeries=o.loopSeries??i.loopSeries,o.seriesIndex=o.seriesIndex??i.seriesIndex,o.updateData=o.updateData??i.updateData,o.bounce=o.bounce??i.bounce):o=i,a=o.seriesIndex<0||o.seriesIndex>=d?0:o.seriesIndex;const I=n.getZr();function x(e){e.event&&(e.event.cancelBubble=!0),h()}function y(){r||f()}function m(e){if(n?.dispatchAction({type:"downplay",seriesIndex:e.seriesIndex}),n?.dispatchAction({type:"highlight",seriesIndex:e.seriesIndex,dataIndex:e.dataIndex}),n?.dispatchAction({type:"showTip",seriesIndex:e.seriesIndex,dataIndex:e.dataIndex}),t.series&&Array.isArray(t.series)&&void 0!==e.seriesIndex){const n=t.series[e.seriesIndex];if(n&&Array.isArray(n.data)){const t=n.data[e.dataIndex];o.bounce&&"function"==typeof o.bounce&&o.bounce(t,e.seriesIndex,e.dataIndex)}}}function A(e){n?.dispatchAction({type:"highlight",seriesIndex:e.seriesIndex,dataIndex:e.dataIndex})}function b(){r&&(clearInterval(r),r=0),e.mobile||e.ios||e.android||e.iPhone||e.iPad?(n.off("touchstart",h),I.off("touchstart",x),I.off("touchend",y)):(n.off("mousemove",h),I.off("mousemove",x),I.off("globalout",y),n.off("mouseover",m),n.off("mouseout",A))}return e.mobile||e.ios||e.android||e.iPhone||e.iPad?(n.on("touchstart",h),I.on("touchstart",x),I.on("touchend",y)):(n.on("mousemove",h),I.on("mousemove",x),I.on("globalout",y),o.bounce&&"function"==typeof o.bounce&&(n.on("mouseover",m),n.on("mouseout",A))),f(),{clearLoop:b,pause:h,resume:f}}export{n as loopShowTooltip};