UNPKG

@dfsj/echarts

Version:

专业的水文曲线组件或构造函数以及通用的echart二次封装图表

12 lines (10 loc) 7.21 kB
/** * * @dfsj/echarts: 专业的水文曲线组件或构造函数以及通用的echart二次封装图表 * 版本: v4.0.0-alpha.9 * 作者:yangbo <1747837358@qq.com> * 日期:2026-07-10 17:09:23 * * */ import{toConsumableArray as t,slicedToArray as o}from"../../_virtual/_rollupPluginBabelHelpers.js";import{toArea as e,max as l,min as r,to as a,findNowIndex as i}from"../../utils/tools.js";import n from"../../utils/assign.js";import s from"./default.js";import u,{TYPE_SYMBOL as d}from"../../config.js";import{last as f}from"lodash-es";import{createLinearInterpolator as c}from"commons-math-interpolation/Linear";import{useECharts as p}from"../../hooks/useECharts.js";import{useTable as h}from"../../view/useTable.js";function v(v,m){var y=p(v),g=y.setOptions,w=y.echarts,x=y.getInstance,b=y.container,C=h(),O=(C.open,C.close,C.props),k=C.toggleTable;O.container=b;var B=function(t,o,e,l){return null==o&&null==e&&null==l?'<article class="tooltip">\n <fieldset>\n <legend style="color: '.concat(u.markColor[4],'">').concat(t,"</legend> \n </fieldset>\n </article>"):'<article class="tooltip">\n <fieldset>\n <legend>'.concat(t,"</legend>\n <li><i>对应流量</i><i>").concat(a(o),"(m³/s)</i></li>\n <li><i>流量差</i><i>").concat(a(e),"(m³/s)</i></li>\n <li><i>水位差</i><i>").concat(a(l),"(m)</i></li>\n </fieldset>\n </article>")},E=function(t,o,e,l,r){var i=arguments.length>5&&void 0!==arguments[5]?arguments[5]:1,n=o.coord([o.value(0),o.value(1)]),s=o.value(3),d=o.value(1),f="".concat(o.value(2),":").concat(a(o.value(1)),"(m)"),c=e>=d&&u.indexColor[o.value(4)]||u.markColor.safe,p="rgba(51,51,51,0.6)",h=o.value(5),v=r[h-1]||0;if(h>0){var m=o.coord([0,l[h-1].altitude]);o.coord([0,l[h-0].altitude])[1]-m[1]<30&&(v=r[h]=1-v)}if("stage"===s)return{type:"group",children:[{type:"path",shape:{pathData:v?u.icon.stageMirror:u.icon.stage,x:n[0]-3*i-210*v,y:n[1]-18.5*i,width:190*i,height:30*i},style:{fill:c,shadowBlur:8*i,shadowColor:"rgba(255,255,255,0.3)"},styleEmphasis:{shadowBlur:5*i,shadowColor:p,shadowOffsetX:i,shadowOffsetY:3*i}},{type:"text",style:{text:f,x:n[0]+20*i-210*v,y:n[1]-10*i,font:"normal 11px arial",fill:"#fff",borderWidth:1,borderRadius:20*i,backgroundColor:c,lineWidth:100*i,verticalAlign:"middle",padding:[4*i,5*i,2*i,5*i]},styleEmphasis:{font:"normal 12px arial",fill:c,shadowColor:p,shadowBlur:10*i,shadowOffsetX:i,shadowOffsetY:3*i,backgroundColor:"#fff"}}]};if("altitude"===s)return{type:"group",children:[{type:"path",shape:{pathData:v?u.icon.altitudeMirror:u.icon.altitude,x:n[0]-3*i-210*v,y:n[1]-23*i,width:190*i,height:30*i},style:{fill:c,shadowBlur:8*i,shadowColor:"rgba(255,255,255,0.3)"},styleEmphasis:{shadowBlur:2*i,shadowColor:p,shadowOffsetX:i,shadowOffsetY:3*i}},{type:"text",style:{text:f,x:n[0]+20*i-210*v,y:n[1]-10*i,font:"normal 11px arial",fill:"#fff",borderWidth:1,borderRadius:20*i,backgroundColor:c,lineWidth:100*i,verticalAlign:"middle",padding:[4*i,5*i,2*i,5*i]},styleEmphasis:{font:"normal 12px arial",fill:c,shadowColor:p,shadowBlur:10*i,shadowOffsetX:i,shadowOffsetY:3*i,backgroundColor:"#fff"}}]};if("exception"===s)return c=u.markColor[4],{type:"group",children:[{type:"path",shape:{pathData:u.icon.exception,x:n[0],y:n[1],width:10,height:30},style:{fill:c,shadowBlur:8*i,shadowColor:"rgba(255,255,255,0.3)"},styleEmphasis:{shadowBlur:2*i,shadowColor:p,shadowOffsetX:i,shadowOffsetY:3*i}}]};var y=[];return{type:"group",children:[{z2:5,type:"circle",shape:{cx:n[0],cy:n[1],r:3},style:{fill:"#fff",stroke:c}},{type:"polyline",shape:{points:[n,[],y]},style:{fill:null,lineWidth:2*i,stroke:c,shadowBlur:8*i,shadowColor:"#fff"},styleEmphasis:{shadowBlur:2*i,shadowColor:p,shadowOffsetX:i,shadowOffsetY:3*i}},{type:"text",style:{text:f,x:y[0],y:y[1]-12*i,font:"normal 12px arial",fill:"#fff",borderWidth:1,borderRadius:20*i,backgroundColor:c,lineWidth:100*i,padding:[6*i,10*i,3*i,10*i]},styleEmphasis:{font:"normal 13px arial",shadowColor:p,shadowBlur:10*i,shadowOffsetX:i,shadowOffsetY:3*i}}]}};return{createOptions:function(t){var o;if(null!=t&&null!==(o=t.layout)&&void 0!==o&&o.length){var e=r(t.layout,1),a=l(t.layout,1),i=.1*(a-e)||1;return{yAxis:{min:e-i,max:a+i}}}return{}},setOptions:g,echarts:w,getInstance:x,container:b,assemble:function(u,p){var h,v=x(),y=null!=m&&m.C?n({},s,m.C):s,g=n({},y,p),w=[0];if(null!=u){var b,C,k,j;O.value=u,O.chart=v;var W=u.layout||[],X=u.source||[];g.dataset.source=null!==(b=u.source)&&void 0!==b?b:[];var Y=e(g.$area,u.area,X),I=null!==(C=l(W,0))&&void 0!==C?C:0,A=null!==(k=r(W,0))&&void 0!==k?k:0,M=u.center||(I+A)/2,T=(I-A)/1e3*50,D=null!==(j=r(W,1))&&void 0!==j?j:0,R=u.points&&u.points.slice().filter(function(t){return t.altitude}).sort(function(t,o){return o.altitude-t.altitude})||[];w=R.map(function(){return 0}),g.series[1]={z:9,type:"custom"},g.series[0].data=u.layout,g.series[1].data=R.map(function(t,o){var e,l=null!==(e=null==t?void 0:t.layout)&&void 0!==e?e:M+T,r=t.altitude,a=t.symbol||d[t.type]||"altitude";return{value:[l,r,t.label||t.name,a,t.level,o]}}),g.series[1].renderItem=function(t,o){var e,l,r=null===(e=v.getOption())||void 0===e||null===(e=e.timeline)||void 0===e||null===(e=e[0])||void 0===e?void 0:e.currentIndex,a=X.length?null==X||null===(l=X[r])||void 0===l?void 0:l[1]:0;return E(t,o,a,R,w,1)},h=X.map(function(t,o){var e,l,r=null!==(e=null===(l=f(u.layout))||void 0===l?void 0:l[0])&&void 0!==e?e:0;return{title:{text:["时间:"+t[0],null!=t[1]?"水位:".concat(a(t[1]),"m"):"",null!=t[2]?"流量:".concat(a(t[2]),"m³/s"):""].filter(function(t){return t}).join(" ")},series:[{},{},n({data:[[0,t[1]],[r,t[1]],[r,D]],amplitude:3},g.$water),n({data:[{value:[M,t[1]],label:{formatter:"当前水位:".concat(a(t[1]),"(m)\n当前流量:").concat(a(t[2]),"(m³/s)")}}]},g.$current)]}}),g.timeline.data=X.map(function(t,o){if(null==Y)return{value:t[0],tooltip:{formatter:t[0]}};var e=Y.find(function(t){return t.index[0]<=o&&o<=t.index[1]}),l={formatter:e?"".concat(e.title," ").concat(t[0]):t[0]};return n({tooltip:l,value:t[0]},e)});try{var $=new Map;$.set(D,0),X.forEach(function(t){$.set(t[1],t[2])});var z=t($.entries()).sort(function(t,o){return t[0]-o[0]}),P=z.map(function(t){return o(t,1)[0]}),_=z.map(function(t){return o(t,2)[1]}),H=c(P,_);g.tooltip.formatter=function(t){var o,e,l,r,a,i,n=null!==(o=null===(e=v.getOption())||void 0===e||null===(e=e.timeline)||void 0===e||null===(e=e[0])||void 0===e?void 0:e.currentIndex)&&void 0!==o?o:0,s=null!==(l=null===(r=u.source)||void 0===r||null===(r=r[n])||void 0===r?void 0:r[1])&&void 0!==l?l:0,d=null!==(a=null===(i=u.source)||void 0===i||null===(i=i[n])||void 0===i?void 0:i[2])&&void 0!==a?a:0,f=H(t.value[1]),c=H(t.value[1])-d,p=t.value[1]-s;return"exception"==t.value[3]?B(t.value[2]):B(t.value[2],f,c,p)}}catch(t){console.error("[useCrossSection] interpolation error:",t)}var L=Y&&Y.find(function(t){return"history"===t.type});g.timeline.currentIndex=null==L?i(X):Math.max(L.index[1],0)}return{baseOption:g,options:h}},tooltip:B,renderMarkPoint:E,toggleTable:k}}export{v as useCrossSection};