UNPKG

@devgateway/dvz-ui-react

Version:

A modular, embeddable React component library for data visualization and UI, built with TypeScript. Provides reusable components for charts, maps, dashboards, and more, with built-in support for internationalization and Redux integration.

2 lines (1 loc) 3.97 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),ie=require("react"),le=require("@nivo/sankey"),re=require("react-intl"),ae=require("../common/ChartTooltip.js"),de=s=>{var j,y,p,C,O;const{marginLeft:v,marginTop:N,marginRight:L,marginBottom:B,options:ge,intl:T,format:F,colors:me,height:S,showLegends:h,tickColor:he,colorGenerator:q,legendLabel:u,legendCheckBack:ue,legendLabelBack:ke,legendLabelColor:k,reverseLegend:H,measures:xe,dimension1:fe,dimension2:be,dimension3:je,mode:ye,app:pe,tooltipHTML:Ce,tooltip:m,filters:Oe,layout:M,group:ve,noDataMessage:Ne,tooltipEnabled:P,tooltipEnableMarkdown:R,sort:w,nodeThickness:E,nodeOpacity:I,nodeHoverOpacity:z,nodeInnerPadding:$,nodeSpacing:D,nodeHoverOthersOpacity:G,nodeBorderWidth:_,nodeBorderRadius:W,linkOpacity:A,linkHoverOpacity:J,linkHoverOthersOpacity:K,linkContract:Q,enableLinkGradient:U,enableLabels:V,labelPosition:X,labelPadding:Y,useCustomLabelColor:Z,labelTextColor:ee,labelOrientation:ne,legendPosition:r,useLabelBackground:x,useCheckBoxBackground:d}=s,[a,oe]=ie.useState([]),te=o=>{const t=a.slice();if(t.indexOf(o)>-1){const l=t.indexOf(o);t.splice(l,1)}else t.push(o);oe(t)},se={top:N,right:L,bottom:B,left:v},f=()=>e.jsx(e.Fragment,{children:h&&u&&e.jsx("div",{className:"legend item",children:e.jsx("label",{className:"legend-title",children:u})})}),b=()=>{var t,l,g;const o=(g=(l=(t=s==null?void 0:s.options)==null?void 0:t.data)==null?void 0:l.nodes)==null?void 0:g.slice();return H&&o.reverse(),e.jsx(e.Fragment,{children:h&&(o==null?void 0:o.map(n=>{const i=a.indexOf(n.id)==-1;return e.jsxs("div",{className:`legend item ${i?"":"ignore"}`,onClick:()=>te(n.id),children:[d&&e.jsx("input",{className:i?"":"ignore",type:"checkbox",checked:i,readOnly:!0,style:{backgroundColor:n.color,color:"#000"}}),!d&&e.jsx("input",{type:"checkbox",checked:i,readOnly:!0,style:{color:"#000"}}),d&&e.jsx("span",{className:"checkmark-with-bg",style:{backgroundColor:n.color}}),!d&&e.jsx("span",{className:"checkmark"}),x&&e.jsx("label",{className:i?"":"ignore",style:{backgroundColor:n.color,color:k},children:n.id}),!x&&e.jsx("label",{className:i?"":"ignore",style:{color:k},children:n.id})]})}))})};let c={nodes:[],links:[]};if(console.log("sankey props ===>",s),(j=s.options)!=null&&j.data&&((p=(y=s.options)==null?void 0:y.data)!=null&&p.nodes)&&((O=(C=s.options)==null?void 0:C.data)!=null&&O.nodes.length)){const{links:o,nodes:t}=s.options.data;t.forEach(n=>{n.color=q.getColor(n.id)});const l=o.filter(n=>a.indexOf(n.source)==-1&&a.indexOf(n.target)==-1)||[],g=t.filter(n=>a.indexOf(n.id)==-1&&l.find(i=>i.source==n.id||i.target==n.id));c={links:l,nodes:g}}return e.jsx("div",{style:{height:S},children:e.jsxs(e.Fragment,{children:[c.nodes.length&&c.links.length?e.jsx(le.ResponsiveSankey,{data:c,margin:se,layout:M,align:"justify",sort:w,colors:{datum:"color"},nodeOpacity:I,nodeHoverOthersOpacity:G,nodeThickness:E,nodeSpacing:D,nodeBorderWidth:_,nodeBorderColor:{from:"color",modifiers:[["darker",.8]]},linkTooltip:o=>P&&m&&m.trim().length>0?e.jsx(ae.default,{intl:T,format:F,d:o,tooltip:m,tooltipEnableMarkdown:R}):null,enableLabels:V,linkHoverOpacity:J,nodeHoverOpacity:z,nodeInnerPadding:$,nodeBorderRadius:W,linkOpacity:A,linkHoverOthersOpacity:K,linkContract:Q,enableLinkGradient:U,labelPosition:X,labelOrientation:ne,labelPadding:Y,labelTextColor:Z?ee:{from:"color",modifiers:[["darker",1]]}}):e.jsx(e.Fragment,{}),(r=="top"||r=="bottom")&&e.jsx("div",{className:`legends container has-standard-12-font-size ${r}`,children:e.jsxs("div",{className:"legend-sections",children:[e.jsx("div",{className:"title-section",children:f()}),e.jsx("div",{className:"legends container has-standard-12-font-size items-section",children:b()})]})}),(r=="right"||r=="left")&&e.jsxs("div",{className:`legends container has-standard-12-font-size ${r}`,children:[f(),b()]})]})})},ce=re.injectIntl(de);exports.default=ce;