import { MUTICHARTCOLORS } from "@/common/constant";
const getPieChart = (data) => {
  const colorList = MUTICHARTCOLORS
  let showData = data
  if(data.length > 12) {
    showData = data.slice(0,11)
    let num = 0
    data.slice(13,).forEach(item => {
      num = num + item.value
    })
    showData = [...showData, {name: '其他', value: num}]
  }
  let option = {
    color: colorList,
    legend: {
      show: true,
      top: 12
    },
    series: [
      {
        type: 'pie',
        radius: [150, 180],
        // height: '96%',
        left: 'center',
        top: 60,
        width: '98%',
        height: '90%',
        itemStyle: {
          borderColor: '#fff',
          borderWidth: 1
        },
        label: {
          alignTo: 'edge',
          formatter: '{name|{b}}\n{time|{c} 条 {d}%}',
          minMargin: 5,
          edgeDistance: 10,
          lineHeight: 25,
          rich: {
            name: {
              color: 'rgba(59, 65, 75, 1)',
              fontFamily: 'Microsoft YaHei',
              fontSize: 16,
              fontWeight: 'bold',
            },
            time: {
              fontSize: 16,
              fontFamily: 'Microsoft YaHei',
              color: '#rgba(95, 101, 108, 1)'
            }
          }
        },
        labelLine: {
          length: 15,
          length2: 0,
          maxSurfaceAngle: 80
        },
        labelLayout: function (params) {
          const isLeft = params.labelRect.x < 556 / 2;
          const points = params.labelLinePoints;
          // Update the end point.
          points[2][0] = isLeft
            ? params.labelRect.x
            : params.labelRect.x + params.labelRect.width;
          return {
            labelLinePoints: points
          };
        },
        data: showData
      }]
  }
  return option
}

export default getPieChart;