UNPKG

@dfsj/echarts

Version:

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

12 lines (10 loc) 3.87 kB
/** * * @dfsj/echarts: 专业的水文曲线组件或构造函数以及通用的echart二次封装图表 * 版本: v4.0.0-alpha.9 * 作者:yangbo <1747837358@qq.com> * 日期:2026-07-10 17:09:23 * * */ import{objectSpread2 as e,toConsumableArray as n}from"../../_virtual/_rollupPluginBabelHelpers.js";import t from"../../utils/assign.js";import r,{CATEGORY as i}from"../../config.js";import{toIndices as o}from"../../utils/render.js";import{to as a,ensure as l,complexMinMaxIndex as s,minimum as u,maximum as c}from"../../utils/tools.js";import d,{tooltipByMulti as m}from"./default.js";import{EMPTY_ARRAY as f}from"@dfsj/utils";import{useECharts as x}from"../../hooks/useECharts.js";import{buildLegend as p,createTabulationFeature as v,createStatisticFeature as h}from"../../utils/assemble.js";import{useTable as y}from"../../view/useTable.js";import{useStatistic as g}from"../../view/useStatistic.js";function I(I){var A=x(I),b=A.setOptions,j=A.echarts,k=A.getInstance,S=A.container,$=y(),C=($.open,$.close,$.props),L=$.toggleTable;C.container=S;var O=g(),F=(O.open,O.close,O.props),T=O.toggleStatistic,W=function(e,n){var i,o=(null===(i=e.areas)||void 0===i?void 0:i.map(function(e){return t({shape:"rect",value:e.time,gridIndex:[0,1],itemStyle:{fill:e.back||r.areaColor[e.type]}},r.mark.shape.rect)}))||f,a=l(e.split).reduce(function(e,i){var o,a,l;return e.concat([t({shape:"line",value:i,gridIndex:[0],xAxisIndex:0,yAxisIndex:0},r.mark.shape.line),t({shape:"line",value:i,gridIndex:[1],xAxisIndex:1,yAxisIndex:2},r.mark.shape.line),t({shape:"text",value:i,gridIndex:[1],xAxisIndex:1,yAxisIndex:2,label:{text:null!==(o=null==n||null===(a=n.splitFormat)||void 0===a?void 0:a.call(n,i))&&void 0!==o?o:i,offset:null!==(l=null==n?void 0:n.markOffset)&&void 0!==l?l:[0,"-7%"]}},r.mark.shape.text)])},[]);return o.concat(a)};return{setOptions:b,echarts:j,getInstance:k,container:S,createOptions:function(e){if(null==e)return null;var n=s(e,i.FLOW);return{yAxis:[{layout:i.RAINFALL,name:"降雨�?mm)",min:0,max:function(e){return Math.round(e.max+.1*(e.max-e.min))}},{layout:i.SWC,name:"土壤含水�?%)",min:0,max:function(e){return Math.round(e.max+.1*(e.max-e.min))}},{layout:i.FLOW,name:"流量(m³/s)",min:function(e){return u(e,n)},max:function(e){return c(e,n)}},{layout:"",name:""}]}},assemble:function(l,s){var u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:k(),c=t({},d,s);if(null!=l){var f;C.value=l,C.chart=u,F.chart=u,F.value=l;var x=0,y=c.yAxis,g=[y[0].$layout|y[1].$layout,y[2].$layout|y[3].$layout];c.dataset.source=l.source;var I=[];c.series=l.dimensions.filter(function(e,n){return n>0&&"string"!=typeof e}).map(function(n,o){var a=c.yAxis.findIndex(function(e){return e.$layout&n.code}),s=g.findIndex(function(e){return e&n.code}),u=c.$series.find(function(e){return e.$code&n.code}),d={x:0,y:o+1},m=n.code&i.RAINFALL?r.rainfallColor[x++]:void 0;if(0==(null==n?void 0:n.renderInChart)){var f=l.dimensions.findIndex(function(e){return e.name==n.name});return I.push(e(e({},n),{},{index:f,yAxisIndex:a,xAxisIndex:s,encode:d})),null}return t({yAxisIndex:a,xAxisIndex:s,color:m,encode:d,name:n.name,selected:n.selected,visible:!0},u)}).filter(Boolean),c.tooltip.formatter=function(e){var n,t=null==e||null===(n=e[0])||void 0===n?void 0:n.data,r=m(e);return I.length&&I.forEach(function(e){r.push("<li>".concat(e.name,"</i><i>").concat(a(t[null==e?void 0:e.index]),"</i></li>"))}),"<article class='tooltip'> ".concat(r.join(" ")," </article>")};var A=o(l,c,g);null!=A&&A.length&&(f=c.series).push.apply(f,n(A));var b=W(l,c);null!=b&&b.length&&c.series.push(t({data:b},r.mark.series));var j=p(c.series);c.legend.data=j.data,c.legend.selected=j.selected,c.toolbox.feature.myTabulation=v(L),c.toolbox.feature.myStatistics=h(T)}return c},toggleTable:L,toggleStatistic:T}}export{I as useComplexHydrology};