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