

const getSankeyChart = (data = [], links = []) => {
  const option = {
    tooltip: {
      trigger: 'item',
      triggerOn: 'mousemove'
    },
    series: {
      type: 'sankey',
      // 禁止鼠标拖拽/缩放平移，避免图表被交互改变
      draggable: false,
      roam: false,
      left: 16,
      right: 16,
      top: 14,
      bottom: 14,
      nodeAlign: 'right', // 目标效果：人名贴右侧
      emphasis: {
        focus: 'adjacency'
      },
      // 所有色块宽度增加三倍
      nodeWidth: 54,
      nodeGap: 10,
      layoutIterations: 32,
      lineStyle: {
        color: 'rgba(0, 0, 0, 0.08)', // 浅灰“行背景带”的基色
        opacity: 1,
        curveness: 0.2
      },
      label: {
        show: true,
        formatter: function (params) {
          return `${params.name}`;
        },
        position: 'right',
        fontSize: 16,
        color: '#303133',
        overflow: 'truncate',
        width: 140
      },
      edgeLabel: {
        show: true,
        formatter: function (params) {
          const val = params.value || 0;
          return `$${Number(val).toLocaleString()}`;
        },
        color: '#303133',
        fontSize: 16,
        overflow: 'truncate',
        width: 140,
        align: 'center'
      },
      itemStyle: {
        borderWidth: 0
      },
      nodeSort: 'descending',
      levels: [
        // depth = 0（机构节点）
        {
          depth: 0,
          itemStyle: {
            borderWidth: 0
          },
          label: {
            position: 'right',
            color: '#303133',
            fontSize: 16,
            overflow: 'truncate',
            width: 140
          }
        },
        // depth = 1（人物节点）
        {
          depth: 1,
          itemStyle: {
            color: '#34C38F'
          },
          label: {
            // 人物名称移至色块左侧
            position: 'left',
            // 让文字最右侧紧贴绿色色块左侧
            distance: 5,
            color: '#303133',
            fontSize: 16,
            overflow: 'truncate',
            width: 120,
            align: 'right'
          }
        }
      ],
      data: data,
      links: links
    }
  };

  return option
}

export default getSankeyChart