highcharts
Version:
JavaScript charting framework
14 lines • 8.4 kB
JavaScript
/**
* Highcharts JS v13.0.1 (2026-08-17)
* @module highcharts/modules/dependency-wheel
* @requires highcharts
* @requires highcharts/modules/sankey
*
* Dependency wheel module
*
* (c) 2010-2026 Highsoft AS
* Author: Torstein Hønsi
*
* A commercial license may be required depending on use,
* see www.highcharts.com/license
*/import*as t from"../highcharts.js";let e={};e.n=t=>{let a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a:a}),a},e.d=(t,a)=>{if(Array.isArray(a))for(var r=0;r<a.length;){var i=a[r++],o=a[r++];e.o(t,i)?0===o&&r++:0===o?Object.defineProperty(t,i,{enumerable:!0,value:a[r++]}):Object.defineProperty(t,i,{enumerable:!0,get:o})}else for(var i in a)e.o(a,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:a[i]})},e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let a=t.default;var r,i,o=e.n(a);let{defaultOptions:n}=o(),{noop:s}=o(),l={radius:0,scope:"stack",where:void 0},h=t.default.SeriesRegistry;var d=e.n(h);let{sankey:{prototype:{pointClass:p}}}=d().seriesTypes,c=class extends p{getSumTo(){let t=0;for(let e of this.linksFrom)t+=e.weightTo||e.weight||0;for(let e of this.linksTo)t+=e.weight||0;return t}getDataLabelPath(t){let e=this,r=e.series.chart.renderer,i=e.shapeArgs,o=e.angle<0||e.angle>Math.PI,n=i.start||0,s=i.end||0;return e.dataLabelPath?(e.dataLabelPath=e.dataLabelPath.destroy(),delete e.dataLabelPath):(0,a.wrap)(t,"destroy",function(t){return e.dataLabelPath&&(e.dataLabelPath=e.dataLabelPath.destroy()),t.call(this)}),e.dataLabelPath=r.arc({open:!0,longArc:Math.abs(Math.abs(n)-Math.abs(s))<Math.PI?0:1}).attr({x:i.x,y:i.y,r:(i.r||0)+(0,a.pInt)(t.options?.distance||0),start:o?n:s,end:o?s:n,clockwise:+o}).add(r.defs),e.dataLabelPath}isValid(){return!0}};var g=i||(i={});g.compose=function(t,e){return t.sankeyColumn=new u(t,e),t};class u{constructor(t,e){this.points=t,this.series=e}getTranslationFactor(t){let e=this.points,a=e.slice(),r=t.chart,i=t.options.minLinkWidth||0,o,n=0,s,l=(r.plotSizeY||0)-(t.options.borderWidth||0)-(e.length-1)*t.nodePadding;for(;e.length;){for(n=l/e.sankeyColumn.sum(),o=!1,s=e.length;s--;)e[s].getSum()*n<i&&(e.splice(s,1),l=Math.max(0,l-i),o=!0);if(!o)break}for(let t of(e.length=0,a))e.push(t);return n}top(t){let e=this.series,r=e.nodePadding,i=this.points.reduce((a,i)=>(a>0&&(a+=r),a+=Math.max(i.getSum()*t,e.options.minLinkWidth||0)),0);return(0,a.getAlignFactor)(e.options.nodeAlignment||"center")*((e.chart.plotSizeY||0)-i)}left(t){let e=this.series,a=e.chart,r=e.options.equalNodes,i=a.inverted?a.plotHeight:a.plotWidth,o=e.nodePadding,n=this.points.reduce((a,n)=>(a>0&&(a+=o),a+=r?i/n.series.nodes.length-o:Math.max(n.getSum()*t,e.options.minLinkWidth||0)),0);return((a.plotSizeX||0)-Math.round(n))/2}sum(){return this.points.reduce((t,e)=>t+e.getSum(),0)}offset(t,e){let r=this.points,i=this.series,o=i.nodePadding,n=0,s;if(i.is("organization")&&t.hangsFrom)return{absoluteTop:t.hangsFrom.nodeY};for(let l=0;l<r.length;l++){let h=r[l].getSum(),d=Math.max(h*e,i.options.minLinkWidth||0),p=t.options[i.chart.inverted?"offsetHorizontal":"offsetVertical"],c=t.options.offset||0;if(s=h?d+o:0,r[l]===t)return{relativeTop:n+((0,a.defined)(p)?(0,a.relativeLength)(p,d):(0,a.relativeLength)(c,s))};n+=s}}}g.SankeyColumnAdditions=u;let f=i,m=t.default.SVGElement;var y=e.n(m);let{composed:b,deg2rad:x}=o(),{deg2rad:P}=o(),{pie:T,sankey:k}=d().seriesTypes;r=y(),(0,a.pushUnique)(b,"TextPath")&&((0,a.addEvent)(r,"afterGetBBox",function(t){let e=t.bBox,a=this.element?.querySelector("textPath");if(a){let t=[],{b:r,h:i}=this.renderer.fontMetrics(this.element),o=i-r,n=RegExp('(<tspan>|<tspan(?!\\sclass="highcharts-br")[^>]*>|<\\/tspan>)',"g"),s=a.innerHTML.replace(n,"").split(/<tspan class="highcharts-br"[^>]*>/),l=s.length,h=(t,e)=>{let{x:i,y:n}=e,s=(a.getRotationOfChar(t)-90)*x,l=Math.cos(s),h=Math.sin(s);return[[i-o*l,n-o*h],[i+r*l,n+r*h]]};for(let e=0,r=0;r<l;r++){let i=s[r].length;for(let o=0;o<i;o+=5)try{let i=e+o+r,[n,s]=h(i,a.getStartPositionOfChar(i));0===o?(t.push(s),t.push(n)):(0===r&&t.unshift(s),r===l-1&&t.push(n))}catch{break}e+=i-1;try{let i=e+r,o=a.getEndPositionOfChar(i),[n,s]=h(i,o);t.unshift(s),t.unshift(n)}catch{break}}t.length&&t.push(t[0].slice()),e.polygon=t}return e}),(0,a.addEvent)(r,"beforeAddingDataLabel",function(t){let e=t.labelOptions,a=t.point,r=e[a.formatPrefix+"TextPath"]||e.textPath;r&&!e.useHTML&&(this.setTextPath(a.getDataLabelPath?.(this)||a.graphic,r),a.dataLabelPath&&!r.enabled&&(a.dataLabelPath=a.dataLabelPath.destroy()))}),r.prototype.setTextPath=r.prototype.setTextPath??function(t,e){let r=this.renderer.url,i=this.text||this,o=i.textPath,{attributes:n,enabled:s}=(0,a.merge)({enabled:!0,attributes:{dy:-5,startOffset:"50%",textAnchor:"middle"}},e);if(t=t||o&&o.path,o?.undo(),t&&s){let e=(0,a.addEvent)(i,"afterModifyTree",e=>{if(t&&s){let o=t.attr("id");o||t.attr("id",o=(0,a.uniqueKey)());let s={x:0,y:0};(0,a.defined)(n.dx)&&(s.dx=n.dx,delete n.dx),(0,a.defined)(n.dy)&&(s.dy=n.dy,delete n.dy),i.attr(s),this.attr({transform:""}),this.box&&(this.box=this.box.destroy());let l=e.nodes.slice(0);e.nodes.length=0,e.nodes[0]={tagName:"textPath",attributes:(0,a.extend)(n,{"text-anchor":n.textAnchor,href:`${r}#${o}`}),children:l}}});i.textPath={path:t,undo:e}}else i.attr({dx:0,dy:0}),delete i.textPath;return this.added&&(i.textCache="",this.renderer.buildText(i)),this});class M extends k{animate(t){if(!t){let t=(0,a.animObject)(this.options.animation).duration/2/this.nodes.length,e=0;for(let a of this.nodes){let r=a.graphic;r&&(r.attr({opacity:0}),setTimeout(()=>{a.graphic&&a.graphic.animate({opacity:1},{duration:t})},t*e++))}for(let t of this.points){let e=t.graphic;!t.isNode&&e&&e.attr({opacity:0}).animate({opacity:1},this.options.animation)}}}createNode(t){let e=super.createNode(t);return e.getSum=()=>{let t=0;for(let a of e.linksFrom)t+=a.weight||0;for(let a of e.linksTo)t+=a.weightTo||a.weight||0;return t},e.offset=t=>{let a=t=>t.fromNode===e?t.toNode:t.fromNode,r=0,i=e.linksFrom.concat(e.linksTo),o;i.sort((t,e)=>a(t).index-a(e).index);for(let t=0;t<i.length;t++)if(a(i[t]).index>e.index){i=i.slice(0,t).reverse().concat(i.slice(t).reverse()),o=!0;break}o||i.reverse();for(let a=0;a<i.length;a++){if(i[a]===t)return r;let o=i[a].weight||0;r+=i[a].to===e.id&&i[a].weightTo||o}},e}createNodeColumns(){let t=[f.compose([],this)];for(let e of this.nodes)e.column=0,t[0].push(e);return t}getNodePadding(){return this.options.nodePadding/Math.PI}translate(){var t;let e=this.options,r=2*Math.PI/(this.chart.plotHeight+this.getNodePadding()),i=this.getCenter(),o=((e.startAngle||0)-90)*P,n=(t=e.borderRadius,!(0,a.isObject)(t)&&(t={radius:t||0}),(0,a.merge)(l,void 0,t)).radius;for(let t of(super.translate(),this.nodeColumns[0]))if(t.sum){let s=t.shapeArgs,l=i[0],h=i[1],d=i[2]/2,p="auto"===e.nodeWidth?20:e.nodeWidth,c=d-(0,a.relativeLength)(p||0,d),g=o+r*(s.y||0),u=o+r*((s.y||0)+(s.height||0));for(let a of(t.angle=g+(u-g)/2,t.shapeType="arc",t.shapeArgs={x:l,y:h,r:d,innerR:c,start:g,end:u,borderRadius:n},t.dlBox={x:l+Math.cos((g+u)/2)*(d+c)/2,y:h+Math.sin((g+u)/2)*(d+c)/2,width:1,height:1},t.linksFrom))if(a.linkBase){let t,i,n=a.linkBase.map((n,s)=>{let d=r*n,p=Math.cos(o+d)*(c+1),g=Math.sin(o+d)*(c+1);return t=e.curveFactor||0,(i=Math.abs(a.linkBase[3-s]*r-d))>Math.PI&&(i=2*Math.PI-i),(i*=c)<c&&(t*=i/c),{x:l+p,y:h+g,cpX:l+(1-t)*p,cpY:h+(1-t)*g}});a.shapeArgs={d:[["M",n[0].x,n[0].y],["A",c,c,0,0,1,n[1].x,n[1].y],["C",n[1].cpX,n[1].cpY,n[2].cpX,n[2].cpY,n[2].x,n[2].y],["A",c,c,0,0,1,n[3].x,n[3].y],["C",n[3].cpX,n[3].cpY,n[0].cpX,n[0].cpY,n[0].x,n[0].y]]}}}}translateLink(t){let e=Math.max((t.weightTo||t.weight||0)*this.translationFactor,this.options.minLinkWidth||0),a=this.getY(t,t.toNode,"linksTo",e);super.translateLink(t,a),t.linkBase[3]=a+e}translateNode(t,e){super.translateNode(t,e),t.sumTo=t.getSumTo()}}M.defaultOptions=(0,a.merge)(k.defaultOptions,{center:[null,null],curveFactor:.6,startAngle:0,dataLabels:{allowOverlap:!0,textPath:{enabled:!1,attributes:{dy:5}}},tooltip:{pointFormat:"{point.fromNode.name} → {point.toNode.name}: <b>{point.weight}</b><br/>{#if point.weightTo}{point.toNode.name} → {point.fromNode.name}: <b>{point.weightTo}</b><br/>{/if}"}}),(0,a.extend)(M.prototype,{orderNodes:!1,pointArrayMap:["from","to","weight","weightTo"],getCenter:T.prototype.getCenter}),M.prototype.pointClass=c,d().registerSeriesType("dependencywheel",M);let L=o();export{L as default};