UNPKG

highcharts

Version:
11 lines 11.4 kB
/** * Highcharts JS v12.3.0 (2025-06-21) * @module modules/arc-diagram * @requires highcharts/modules/sankey * * Arc diagram module * * (c) 2021 Piotr Madej * * License: www.highcharts.com/license */import*as t from"../highcharts.js";import"./sankey.js";var e,o,s={};s.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return s.d(e,{a:e}),e},s.d=(t,e)=>{for(var o in e)s.o(e,o)&&!s.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let i=t.default;var n=s.n(i);s.d({},{});let a=t.default.SeriesRegistry;var r=s.n(a);let{series:{prototype:l,prototype:{pointClass:{prototype:h}}}}=r(),{defined:d,extend:p,find:u,merge:c,pick:f}=n();!function(t){function e(){return this.data=[].concat(this.points||[],this.nodes),l.destroy.apply(this,arguments)}function o(){this.nodes&&(this.nodes.forEach(t=>{t.destroy()}),this.nodes.length=0),l.setData.apply(this,arguments)}function s(t){let e=arguments,o=this.isNode?this.linksTo.concat(this.linksFrom):[this.fromNode,this.toNode];"select"!==t&&o.forEach(t=>{t&&t.series&&(h.setState.apply(t,e),!t.isNode&&(t.fromNode.graphic&&h.setState.apply(t.fromNode,e),t.toNode&&t.toNode.graphic&&h.setState.apply(t.toNode,e)))}),h.setState.apply(this,e)}function i(t,e,o,s){let i=this.series.options.nodes,n=this.series.options.data,a=n?.length||0,r=n?.[this.index];if(h.update.call(this,t,!this.isNode&&e,o,s),this.isNode){let t=(i||[]).reduce((t,e,o)=>this.id===e.id?o:t,-1),s=c(i&&i[t]||{},n?.[this.index]||{});n&&(r?n[this.index]=r:n.length=a),i?t>=0?i[t]=s:i.push(s):this.series.options.nodes=[s],f(e,!0)&&this.series.chart.redraw(o)}}t.compose=function(t,n){let a=t.prototype,r=n.prototype;return a.setNodeState=s,a.setState=s,a.update=i,r.destroy=e,r.setData=o,n},t.createNode=function(t){let e=this.pointClass,o=(t,e)=>u(t,t=>t.id===e),s=o(this.nodes,t),i;if(!s){i=this.options.nodes&&o(this.options.nodes,t);let n=new e(this,p({className:"highcharts-node",isNode:!0,id:t,y:1},i));n.linksTo=[],n.linksFrom=[],n.getSum=function(){let t=0,e=0;return n.linksTo.forEach(e=>{t+=e.weight||0}),n.linksFrom.forEach(t=>{e+=t.weight||0}),Math.max(t,e)},n.offset=function(t,e){let o=0;for(let s=0;s<n[e].length;s++){if(n[e][s]===t)return o;o+=n[e][s].weight}},n.hasShape=function(){let t=0;return n.linksTo.forEach(e=>{e.outgoing&&t++}),!n.linksTo.length||t!==n.linksTo.length},n.index=this.nodes.push(n)-1,s=n}return s.formatPrefix="node",s.name=s.name||s.options.id||"",s.mass=f(s.options.mass,s.options.marker&&s.options.marker.radius,this.options.marker&&this.options.marker.radius,4),s},t.destroy=e,t.generatePoints=function(){let t=this.chart,e={};l.generatePoints.call(this),this.nodes||(this.nodes=[]),this.colorCounter=0,this.nodes.forEach(t=>{t.linksFrom.length=0,t.linksTo.length=0,t.level=t.options.level}),this.points.forEach(o=>{d(o.from)&&(e[o.from]||(e[o.from]=this.createNode(o.from)),e[o.from].linksFrom.push(o),o.fromNode=e[o.from],t.styledMode?o.colorIndex=f(o.options.colorIndex,e[o.from].colorIndex):o.color=o.options.color||e[o.from].color),d(o.to)&&(e[o.to]||(e[o.to]=this.createNode(o.to)),e[o.to].linksTo.push(o),o.toNode=e[o.to]),o.name=o.name||o.id},this),this.nodeLookup=e},t.setNodeState=s,t.updateNode=i}(e||(e={}));let m=e,{seriesTypes:{sankey:{prototype:{pointClass:g}}}}=r(),{extend:y}=n();class x extends g{isValid(){return!0}}y(x.prototype,{setState:m.setNodeState});let{defined:k,getAlignFactor:b,relativeLength:S}=n();var L=o||(o={});L.compose=function(t,e){return t.sankeyColumn=new P(t,e),t};class P{constructor(t,e){this.points=t,this.series=e}getTranslationFactor(t){let e=this.points,o=e.slice(),s=t.chart,i=t.options.minLinkWidth||0,n,a=0,r,l=(s.plotSizeY||0)-(t.options.borderWidth||0)-(e.length-1)*t.nodePadding;for(;e.length;){for(a=l/e.sankeyColumn.sum(),n=!1,r=e.length;r--;)e[r].getSum()*a<i&&(e.splice(r,1),l=Math.max(0,l-i),n=!0);if(!n)break}for(let t of(e.length=0,o))e.push(t);return a}top(t){let e=this.series,o=e.nodePadding,s=this.points.reduce((s,i)=>(s>0&&(s+=o),s+=Math.max(i.getSum()*t,e.options.minLinkWidth||0)),0);return b(e.options.nodeAlignment||"center")*((e.chart.plotSizeY||0)-s)}left(t){let e=this.series,o=e.chart,s=e.options.equalNodes,i=o.inverted?o.plotHeight:o.plotWidth,n=e.nodePadding,a=this.points.reduce((o,a)=>(o>0&&(o+=n),o+=s?i/a.series.nodes.length-n:Math.max(a.getSum()*t,e.options.minLinkWidth||0)),0);return((o.plotSizeX||0)-Math.round(a))/2}sum(){return this.points.reduce((t,e)=>t+e.getSum(),0)}offset(t,e){let o=this.points,s=this.series,i=s.nodePadding,n=0,a;if(s.is("organization")&&t.hangsFrom)return{absoluteTop:t.hangsFrom.nodeY};for(let r=0;r<o.length;r++){let l=o[r].getSum(),h=Math.max(l*e,s.options.minLinkWidth||0),d=t.options[s.chart.inverted?"offsetHorizontal":"offsetVertical"],p=t.options.offset||0;if(a=l?h+i:0,o[r]===t)return{relativeTop:n+(k(d)?S(d,h):S(p,a))};n+=a}}}L.SankeyColumnAdditions=P;let N=o,v=t.default.Series;var T=s.n(v);let C=t.default.SVGRenderer;var M=s.n(C);let W=t.default.SVGElement;var A=s.n(W);let{deg2rad:O}=n(),{addEvent:w,merge:z,uniqueKey:Y,defined:E,extend:F}=n();function X(t,e){e=z(!0,{enabled:!0,attributes:{dy:-5,startOffset:"50%",textAnchor:"middle"}},e);let o=this.renderer.url,s=this.text||this,i=s.textPath,{attributes:n,enabled:a}=e;if(t=t||i&&i.path,i&&i.undo(),t&&a){let e=w(s,"afterModifyTree",e=>{if(t&&a){let i=t.attr("id");i||t.attr("id",i=Y());let a={x:0,y:0};E(n.dx)&&(a.dx=n.dx,delete n.dx),E(n.dy)&&(a.dy=n.dy,delete n.dy),s.attr(a),this.attr({transform:""}),this.box&&(this.box=this.box.destroy());let r=e.nodes.slice(0);e.nodes.length=0,e.nodes[0]={tagName:"textPath",attributes:F(n,{"text-anchor":n.textAnchor,href:`${o}#${i}`}),children:r}}});s.textPath={path:t,undo:e}}else s.attr({dx:0,dy:0}),delete s.textPath;return this.added&&(s.textCache="",this.renderer.buildText(s)),this}function B(t){let e=t.bBox,o=this.element?.querySelector("textPath");if(o){let t=[],{b:s,h:i}=this.renderer.fontMetrics(this.element),n=i-s,a=RegExp('(<tspan>|<tspan(?!\\sclass="highcharts-br")[^>]*>|<\\/tspan>)',"g"),r=o.innerHTML.replace(a,"").split(/<tspan class="highcharts-br"[^>]*>/),l=r.length,h=(t,e)=>{let{x:i,y:a}=e,r=(o.getRotationOfChar(t)-90)*O,l=Math.cos(r),h=Math.sin(r);return[[i-n*l,a-n*h],[i+s*l,a+s*h]]};for(let e=0,s=0;s<l;s++){let i=r[s].length;for(let n=0;n<i;n+=5)try{let i=e+n+s,[a,r]=h(i,o.getStartPositionOfChar(i));0===n?(t.push(r),t.push(a)):(0===s&&t.unshift(r),s===l-1&&t.push(a))}catch(t){break}e+=i-1;try{let i=e+s,n=o.getEndPositionOfChar(i),[a,r]=h(i,n);t.unshift(r),t.unshift(a)}catch(t){break}}t.length&&t.push(t[0].slice()),e.polygon=t}return e}function H(t){let e=t.labelOptions,o=t.point,s=e[o.formatPrefix+"TextPath"]||e.textPath;s&&!e.useHTML&&(this.setTextPath(o.getDataLabelPath?.(this)||o.graphic,s),o.dataLabelPath&&!s.enabled&&(o.dataLabelPath=o.dataLabelPath.destroy()))}({compose:function(t){w(t,"afterGetBBox",B),w(t,"beforeAddingDataLabel",H);let e=t.prototype;e.setTextPath||(e.setTextPath=X)}}).compose(A());let{prototype:{symbols:D}}=M(),{seriesTypes:{column:R,sankey:q}}=r(),{crisp:j,extend:I,merge:V,pick:_,relativeLength:G}=n();class $ extends q{createNodeColumns(){let t=this,e=t.chart,o=N.compose([],t);return o.sankeyColumn.maxLength=e.inverted?e.plotHeight:e.plotWidth,o.sankeyColumn.getTranslationFactor=t=>{let s=o.slice(),i=this.options.minLinkWidth||0,n,a=0,r,l,h=0,d=1,p=0,u=(e.plotSizeX||0)-(t.options.marker&&t.options.marker.lineWidth||0)-(o.length-1)*t.nodePadding;for(;o.length;){for(a=u/o.sankeyColumn.sum(),n=!1,r=o.length;r--;){l=o[r].getSum()*a*d;let t=Math.min(e.plotHeight,e.plotWidth);l>t?d=Math.min(t/l,d):l<i&&(o.splice(r,1),u-=i,l=i,n=!0),p+=l*(1-d)/2,h=Math.max(h,l)}if(!n)break}return o.length=0,s.forEach(t=>{t.scale=d,o.push(t)}),o.sankeyColumn.maxRadius=h,o.sankeyColumn.scale=d,o.sankeyColumn.additionalSpace=p,a},o.sankeyColumn.offset=function(s,i){let n=s.series.options.equalNodes,a=t.nodePadding,r=Math.min(e.plotWidth,e.plotHeight,(o.sankeyColumn.maxLength||0)/t.nodes.length-a),l=o.sankeyColumn.additionalSpace||0,h;for(let e=0;e<o.length;e++){let d=o[e].getSum()*(o.sankeyColumn.scale||0),p=n?r:Math.max(d*i,t.options.minLinkWidth||0);if(h=d?p+a:0,o[e]===s)return{relativeLeft:l+G(s.options.offset||0,h)};l+=h}},t.nodes.forEach(function(t){t.column=0,o.push(t)}),[o]}translateLink(t){let e=t.fromNode,o=t.toNode,s=this.chart,i=this.translationFactor,n=t.options,a=this.options,r=_(n.linkWeight,a.linkWeight,Math.max((t.weight||0)*i*e.scale,this.options.minLinkWidth||0)),l=t.series.options.centeredLinks,h=e.nodeY,d=(e,o)=>{let s=(e.offset(t,o)||0)*i;return Math.min(e.nodeX+s,e.nodeX+(e.shapeArgs&&e.shapeArgs.height||0)-r)},p=l?e.nodeX+((e.shapeArgs.height||0)-r)/2:d(e,"linksFrom"),u=l?o.nodeX+((o.shapeArgs.height||0)-r)/2:d(o,"linksTo"),c=h;p>u&&([p,u]=[u,p]),a.reversed&&([p,u]=[u,p],c=(s.plotSizeY||0)-c),t.shapeType="path",t.linkBase=[p,p+r,u,u+r];let f=(u+r-p)/Math.abs(u+r-p)*_(a.linkRadius,Math.min(Math.abs(u+r-p)/2,e.nodeY-Math.abs(r)));t.shapeArgs={d:[["M",p,c],["A",(u+r-p)/2,f,0,0,1,u+r,c],["L",u,c],["A",(u-p-r)/2,f-r,0,0,0,p+r,c],["Z"]]},t.dlBox={x:p+(u-p)/2,y:c-f,height:r,width:0},t.tooltipPos=s.inverted?[(s.plotSizeY||0)-t.dlBox.y-r/2,(s.plotSizeX||0)-t.dlBox.x]:[t.dlBox.x,t.dlBox.y+r/2],t.y=t.plotY=1,t.x=t.plotX=1,t.color||(t.color=e.color)}translateNode(t,e){let o=this.translationFactor,s=this.chart,i=s.inverted?s.plotWidth:s.plotHeight,n=this.options,a=Math.min(s.plotWidth,s.plotHeight,i/t.series.nodes.length-this.nodePadding),r=t.getSum()*(e.sankeyColumn.scale||0),l=n.equalNodes?a:Math.max(r*o,this.options.minLinkWidth||0),h=n.marker?.lineWidth||0,d=e.sankeyColumn.offset(t,o),p=j(_(d&&d.absoluteLeft,(e.sankeyColumn.left(o)||0)+(d&&d.relativeLeft||0)),h),u=V(n.marker,t.options.marker),c=u.symbol,f=u.radius,m=parseInt(n.offset,10)*((s.inverted?s.plotWidth:s.plotHeight)-(j(this.colDistance*(t.column||0)+(u.lineWidth||0)/2,h)+(e.sankeyColumn.scale||0)*(e.sankeyColumn.maxRadius||0)/2))/100;if(t.sum=r,r){t.nodeX=p,t.nodeY=m;let e=t.options.width||n.width||l,o=t.options.height||n.height||l,i=m;n.reversed&&(i=(s.plotSizeY||0)-m,s.inverted&&(i=(s.plotSizeY||0)-m)),this.mapOptionsToLevel&&(t.dlOptions=q.getDLOptions({level:this.mapOptionsToLevel[t.level],optionsPoint:t.options})),t.plotX=1,t.plotY=1,t.tooltipPos=s.inverted?[(s.plotSizeY||0)-i-o/2,(s.plotSizeX||0)-p-e/2]:[p+e/2,i+o/2],t.shapeType="path",t.shapeArgs={d:D[c||"circle"](p,i-(f||o)/2,f||e,f||o),width:f||e,height:f||o},t.dlBox={x:p+e/2,y:i,height:0,width:0}}else t.dlOptions={enabled:!1}}drawDataLabels(){if(this.options.dataLabels){let t=this.options.dataLabels.textPath;R.prototype.drawDataLabels.call(this,this.nodes),this.options.dataLabels.textPath=this.options.dataLabels.linkTextPath,R.prototype.drawDataLabels.call(this,this.data),this.options.dataLabels.textPath=t}}pointAttribs(t,e){if(t&&t.isNode){let{...t}=T().prototype.pointAttribs.apply(this,arguments);return t}return super.pointAttribs.apply(this,arguments)}markerAttribs(t){return t.isNode?super.markerAttribs.apply(this,arguments):{}}}$.defaultOptions=V(q.defaultOptions,{centeredLinks:!1,equalNodes:!1,dataLabels:{linkTextPath:{attributes:{startOffset:"25%"}}},marker:{fillOpacity:1,lineWidth:0,states:{},symbol:"circle"},offset:"100%",reversed:!1}),I($.prototype,{orderNodes:!1}),$.prototype.pointClass=x,r().registerSeriesType("arcdiagram",$);let Z=n();export{Z as default};