echarts-tooltip-auto-show
Version:
Echarts Tooltip自动轮播工具
2 lines (1 loc) • 3.34 kB
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).EChartsUtils={})}(this,(function(e){"use strict";const n=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();e.loopShowTooltip=function(e,t,o){const i={interval:2e3,loopSeries:!1,seriesIndex:0,updateData:null,bounce:null};if(!e||!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 n=0===s&&o.loopSeries?0===a?d-1:a-1:a;if(t.series){const o=Array.isArray(t.series)?t.series[n].type:t.series.type;"pie"!==o&&"radar"!==o&&"map"!==o||e.dispatchAction({type:"downplay"})}}function f(){function n(){const n=e.getDom();if(!document.documentElement.contains(n))return void A();0!==s||p||"function"!=typeof o.updateData||(o.updateData(),e.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(),e.dispatchAction({type:"highlight",seriesIndex:a,dataIndex:s})),setTimeout((()=>{h.type="hideTip",e.dispatchAction(h),h.type="showTip",e.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&&n(),r=window.setInterval(n,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 x=e.getZr();function y(e){e.event&&(e.event.cancelBubble=!0),h()}function I(){r||f()}function m(n){if(e?.dispatchAction({type:"downplay",seriesIndex:n.seriesIndex}),e?.dispatchAction({type:"highlight",seriesIndex:n.seriesIndex,dataIndex:n.dataIndex}),e?.dispatchAction({type:"showTip",seriesIndex:n.seriesIndex,dataIndex:n.dataIndex}),t.series&&Array.isArray(t.series)&&void 0!==n.seriesIndex){const e=t.series[n.seriesIndex];if(e&&Array.isArray(e.data)){const t=e.data[n.dataIndex];o.bounce&&"function"==typeof o.bounce&&o.bounce(t,n.seriesIndex,n.dataIndex)}}}function b(n){e?.dispatchAction({type:"highlight",seriesIndex:n.seriesIndex,dataIndex:n.dataIndex})}function A(){r&&(clearInterval(r),r=0),n.mobile||n.ios||n.android||n.iPhone||n.iPad?(e.off("touchstart",h),x.off("touchstart",y),x.off("touchend",I)):(e.off("mousemove",h),x.off("mousemove",y),x.off("globalout",I),e.off("mouseover",m),e.off("mouseout",b))}return n.mobile||n.ios||n.android||n.iPhone||n.iPad?(e.on("touchstart",h),x.on("touchstart",y),x.on("touchend",I)):(e.on("mousemove",h),x.on("mousemove",y),x.on("globalout",I),o.bounce&&"function"==typeof o.bounce&&(e.on("mouseover",m),e.on("mouseout",b))),f(),{clearLoop:A,pause:h,resume:f}}}));