UNPKG

@progress/kendo-react-charts

Version:

React Chart renders a wide range of high-quality data visualizations. KendoReact Charts package

9 lines (8 loc) 3.06 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("react"),j=require("@progress/kendo-charts"),u=require("@progress/kendo-react-common"),w=require("../package-metadata.js"),K=require("./propTypes.js"),y=require("./SankeyTooltip.js");function V(e){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const k=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(c,o,k.get?k:{enumerable:!0,get:()=>e[o]})}}return c.default=e,Object.freeze(c)}const t=V(I),x=12,g={offset:x,visible:!0},z=["nodeEnter","nodeLeave","linkEnter","linkLeave","nodeClick","linkClick"],A=(e,c)=>{e&&(e.unbind(),z.forEach(o=>{c[o]&&e.bind(o,c[o])}))},b=t.forwardRef((e,c)=>{const o=!u.validatePackage(w.packageMetadata,{component:"Sankey"}),k=u.getLicenseMessage(w.packageMetadata),s=t.useRef(null),r=t.useRef(null),d=u.useRtl(s,e.dir,[e.dir,s.current]),f=t.useRef(null),v=u.useDocument(s),{data:C,links:E,nodes:T,labels:L,title:R,legend:S,tooltip:p=g,disableAutoLayout:O,disableKeyboardNavigation:h}=e,M=t.useRef(void 0);M.current=e;const[N,P]=t.useState(null),q=t.useCallback(a=>{const{visible:i,appendTo:n=v().body,offset:m=x,nodeComponent:H=y.NodeTooltipContent,linkComponent:W=y.LinkTooltipContent}={...g,...p};if(i){const _={appendTo:n,event:a,offset:m,dir:d,Content:a.targetType==="node"?H:W};P(_)}},[p,d,v]),D=t.useCallback(()=>{P(null)},[]),l=t.useCallback((a,i)=>{const n=M.current[a];if(n){const m={...i,nativeEvent:i.originalEvent,target:f.current};n.call(void 0,m)}},[]);return t.useEffect(()=>{const a={data:C,links:E,nodes:T,labels:L,title:R,legend:S,disableAutoLayout:O,disableKeyboardNavigation:h,rtl:d==="rtl",tooltip:{...g,...p}};if(r.current)r.current.setOptions(a);else if(u.canUseDOM&&s.current){const i=j.sankeyTheme(s.current);r.current=new j.Sankey(s.current,a,i),A(r.current,{nodeEnter:n=>{l("onNodeEnter",n)},nodeLeave:n=>{l("onNodeLeave",n)},linkEnter:n=>{l("onLinkEnter",n)},linkLeave:n=>{l("onLinkLeave",n)},nodeClick:n=>{l("onNodeClick",n)},linkClick:n=>{l("onLinkClick",n)}}),r.current.bind("tooltipShow",q),r.current.bind("tooltipHide",D)}return()=>{r.current&&(r.current.destroy(),r.current=null)}},[C,E,T,L,R,S,O,h,d,p,D,q,l]),t.useImperativeHandle(f,()=>({get element(){return s.current},exportVisual:a=>r.current.exportVisual(a),props:e}),[]),t.useImperativeHandle(c,()=>f.current),t.createElement(t.Fragment,null,t.createElement("div",{ref:s,className:e.className,style:e.style,dir:d}),N&&t.createElement(y.TooltipComponent,{...N}),o&&t.createElement(u.WatermarkOverlay,{message:k}))});b.propTypes=K.sankeyPropTypes;b.displayName="KendoReactSankey";exports.Sankey=b;