import * as echarts from "echarts";

var data = [
  {
    name: "人工智能与信息技术",
    value: 27
  },
  {
    name: "生物医学与健康",
    value: 22
  },
  {
    name: "能源与环境技术",
    value: 18
  },
  {
    name: "先进制造与材料",
    value: 15
  },
  {
    name: "国家安全与国防",
    value: 12
  },
  {
    name: "航空航天",
    value: 8
  }
];
// 计算总和
function getTotal(data) {
return data.reduce((sum, item) => sum + item.value, 0);
};

export const pieOption = {
  tooltip: {
    trigger: 'item'
  },
  legend: {
    orient: 'vertical',
    x: 'right',
    y: 'center',
    align: 'left',
    left:'50%',
    data: data.map(item => item.name),
    textStyle: { // 图例字体样式
      color: "rgba(59, 65, 75, 1)",
      fontSize: 16
      },
    formatter: function(name) {
    var total = getTotal(data);
    var item = data.find(item => item.name === name);
    var percentage = ((item.value / total) * 100).toFixed(2);
    return `${name} ${percentage}%`;
    }
  },
  series: [
    {
      name: '频度',
      type: 'pie',
      center: ['25%', '50%'],
      radius: ['40%', '70%'],
      avoidLabelOverlap: false,
      label: {
        show: false,
        position: 'center'
      },
      
      labelLine: {
        show: false
      },
      data: [
        {
          name: "人工智能与信息技术",
          value: 27,
          itemStyle:{color: 'rgba(105, 177, 255, 1)'}
        },
        {
          name: "生物医学与健康",
          value: 22,
          itemStyle:{color: 'rgba(255, 236, 61, 1)'}
        },
        {
          name: "能源与环境技术",
          value: 18,
          itemStyle:{color: 'rgba(135, 232, 222, 1)'}
        },
        {
          name: "先进制造与材料",
          value: 15,
          itemStyle:{color: 'rgba(133, 165, 255, 1)'}
        },
        {
          name: "国家安全与国防",
          value: 12,
          itemStyle:{color: 'rgba(255, 120, 117, 1)'}
        },
        {
          name: "航空航天",
          value: 8,
          itemStyle:{color: 'rgba(179, 127, 235, 1)'}
        }
      ]
    }
  ]
};

var data1 = [
  {
    name: "捐赠基金",
    value: 27
  },
  {
    name: "政府拨款",
    value: 22
  },
  {
    name: "企业合作",
    value: 18
  },
  {
    name: "学费收入",
    value: 15
  },
  {
    name: "其他来源",
    value: 12
  }
];


export const pieOption1 = {
  legend: {
    orient: 'vertical',
    x: 'right',
    y: 'center',
    align: 'left',
    left:'60%',
    data: data1.map(item => item.name),
    textStyle: { // 图例字体样式
      color: "rgba(59, 65, 75, 1)",
      fontSize: 16
      },
    formatter: function(name) {
    var total = getTotal(data1);
    var item = data1.find(item => item.name === name);
    var percentage = ((item.value / total) * 100).toFixed(2);
    return `${name} ${percentage}%`;
    }
  },
  series: [
    {
      name: '频度',
      type: 'pie',
      center: ['30%', '50%'],
      radius: ['40%', '70%'],
      avoidLabelOverlap: false,
      label: {
        show: false,
        position: 'center'
      },
      
      labelLine: {
        show: false
      },
      data: [
        {
          name: "捐赠基金",
          value: 27,
          itemStyle:{color: 'rgba(105, 177, 255, 1)'}
        },
        {
          name: "政府拨款",
          value: 22,
          itemStyle:{color: 'rgba(255, 236, 61, 1)'}
        },
        {
          name: "企业合作",
          value: 18,
          itemStyle:{color: 'rgba(135, 232, 222, 1)'}
        },
        {
          name: "学费收入",
          value: 15,
          itemStyle:{color: 'rgba(133, 165, 255, 1)'}
        },
        {
          name: "其他来源",
          value: 12,
          itemStyle:{color: 'rgba(255, 120, 117, 1)'}
        }
      ]
    }
  ]
};


export const raderOption = {
    title: { text: '' },
    legend: {
      icon: 'circle',
      orient: 'vertical',      // 纵向排列
      right: 50,                // 贴右边
      top: 'center',           // 垂直居中
      align: 'left',           // 文字在图标左侧
      textStyle: { // 图例字体样式
        color: "rgba(59, 65, 75, 1)",
        fontSize: "16px"
        }
      
    },
    radar: {
      radius: '60%',          // 关键：缩小整个雷达
      indicator: [
        { name: '能源领域', max: 6500 },
        { name: '集成电路', max: 16000 },
        { name: '人工智能', max: 30000 },
        { name: '通信网络', max: 38000 },
        { name: '量子科技', max: 52000 },
        { name: '生物科技', max: 25000 }
      ],
      axisName: {
        formatter: '{value}',
        color: 'rgba(59, 65, 75, 1)',
        fontSize: 16,
        fontWeight: 700
      }
    },
    series: [
      {
        name: 'Budget vs spending',
        type: 'radar',
        data: [
          {
            value: [4200, 3000, 20000, 35000, 50000, 18000],
            name: '研究型大学',
            areaStyle: { color: 'rgba(5, 95, 194, 0.2)' }
          },
          {
            value: [5000, 14000, 28000, 26000, 42000, 21000],
            name: '国家实验室',
            areaStyle: { color: 'rgba(250, 140, 22, 0.2)' }
          },
          {
            value: [4000, 14000, 18000, 21000, 32000, 10000],
            name: '科技企业',
            areaStyle: { color: 'rgba(179, 127, 235, 0.2)' }
          },
          {
            value: [4000, 14000, 18000, 21000, 32000, 10000],
            name: '国防承包商',
            areaStyle: { color: 'rgba(33, 129, 57, 0.2)' }
          }
        ]
      }
    ]
  };

export const raderOption1 = {
    grid: {
        top: '3%',
        right: '3%',
        bottom: '1%',
        left: '1%',
        containLabel: true
    },
    radar: {
      radius: '60%',          // 关键：缩小整个雷达
      indicator: [
        { name: '能源领域', max: 6500 },
        { name: '集成电路', max: 16000 },
        { name: '人工智能', max: 30000 },
        { name: '通信网络', max: 38000 },
        { name: '量子科技', max: 52000 },
        { name: '生物科技', max: 25000 }
      ],
      axisName: {
        formatter: '{value}',
        color: 'rgba(59, 65, 75, 1)',
        fontSize: 16,
        fontWeight: 700
      }
    },
    series: [
      {
        name: 'Budget vs spending',
        type: 'radar',
        data: [
          {
            value: [4200, 3000, 20000, 35000, 50000, 18000],
            name: '哈佛大学',
            areaStyle: { color: 'rgba(179, 127, 235, 0.1)' }
          }
        ]
      }
    ]
  };

export const barOption = {
    tooltip: {
        trigger: "axis",
        axisPointer: {
            type: "shadow"
        }
    },
    grid: {
        top: '3%',
        right: '3%',
        bottom: '1%',
        left: '1%',
        containLabel: true
    },
    
    xAxis: [{
        axisLine: {
            lineStyle: {
                width: 1,
                color: "rgba(231, 243, 255, 1)"
            }
        },
        axisTick:
            { show: false },
        type: "category",
        boundaryGap: [100, 100],
        axisLabel: {
            color: "rgba(95, 101, 108, 1)",
            // fontSize: 22,
            // fontWeight: 400
        },
        data: ["2016","2017","2018","2019", "2020", "2021", "2022", "2023", "2024", "2025"],
    }],
    
    yAxis: {
        type: "value",
        axisLine: {
            lineStyle: {
                type: "dashed"
            }
        },

        axisLabel: {
            color: "rgba(95, 101, 108, 1)",
            // fontSize: 22,
            // fontWeight: 400
        },
        splitNumber: 5,
        splitLine: {
            lineStyle: {
                width: 1,
                type: "dashed",
                color: "rgba(231, 243, 255, 1)"
            },

        }
    },
    series: [
        {
            name: "专利数量",
            data: [80, 90, 110, 130, 140, 160, 200,250,300,340],
            type: "bar",
            barWidth: 20,
            itemStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                    { offset: 0, color: "rgba(46, 165, 255, 1)" },
                    // { offset: 0.5, color: '#188df0' },
                    { offset: 1, color: "rgba(46, 165, 255, 0)" }
                ])
                // borderRadius: [6, 6, 0, 0]
            },
            label:{
                show:false,
                position:'top',
                textStyle:{
                    fontSize:'20px',
                    fontWeight:400,
                    color:'rgba(255, 255, 255, 1)'
                }

            }
        }
    ]
};

export const lineChart = {
  tooltip: {
        trigger: "axis",
        axisPointer: {
            type: "shadow"
        }
    },
    grid: {
      left: '2%',
      top: '8%',
      right: '2%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      splitLine: {
        show: false
      },
      axisLine: {
        show: false
      },
      data: ["2016","2017","2018","2019", "2020", "2021", "2022", "2023", "2024", "2025"],
    },
    yAxis: {
      type: 'value',
      splitLine: {
        show: true, lineStyle: {
          type: "dashed",
          color: "#E7F3FF"
        }
      },
      axisLine: {
        show: false
      },

    },
    color: ['rgba(255, 149, 77, 1)'],
    series: [
      {
        data: [50,60,80,100,110,140,180,260,280,330],
        type: 'line',
        emphasis: {
          focus: 'series'
        },
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: 'rgba(255, 149, 77, 0.5)' // 起始颜色：深色
          }, {
            offset: 1,
            color: 'rgba(255, 149, 77, 0)' // 结束颜色：浅色且透明度降低
          }])
        },
      }
    ]
  
};

export const lineChart1 = {
  tooltip: {
        trigger: "axis",
        axisPointer: {
            type: "shadow"
        }
    },
    grid: {
      left: '2%',
      top: '8%',
      right: '2%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      splitLine: {
        show: false
      },
      axisLine: {
        show: false
      },
      data: ["2016","2017","2018","2019", "2020", "2021", "2022", "2023", "2024", "2025"],
    },
    yAxis: {
      type: 'value',
      splitLine: {
        show: true, lineStyle: {
          type: "dashed",
          color: "#E7F3FF"
        }
      },
      axisLine: {
        show: false
      },

    },
    color: ['rgba(33, 129, 57, 1)'],
    series: [
      {
        data: [50,60,80,100,110,140,180,260,280,330],
        type: 'line',
        emphasis: {
          focus: 'series'
        },
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: 'rgba(33, 129, 57, 0.5)' // 起始颜色：深色
          }, {
            offset: 1,
            color: 'rgba(33, 129, 57, 0)' // 结束颜色：浅色且透明度降低
          }])
        },
      }
    ]
  
};


const nameList = ["教育学院","文理学院","法学院","商学院","工程学院","医学院"];
const valueList = [21,21,25,79,95,109];

export const horizontalBaroption = {
    grid: {
        top: '0',
        right: '3%',
        bottom: '1%',
        left: '1%',
        containLabel: true
    },
    color: ['#ce4f51', '#1778ff'],
    xAxis: {
        type: 'value',
        splitLine: {
            show: false
        },
        show: false
    },
    yAxis: {
        type: 'category',
        data: nameList,
        splitLine: {
            show: false
        },
        axisTick: {
            show: false
        },
        axisLine: {
            show: false
        },
        axisLabel: {
            show: true
        }
    },
    series: [{
        type: 'bar',
        data: valueList.map((item, index) => {
            return {
                value: item,
                label: {
                    textStyle: {
                        color: index < 3 ? '#1778ff' : '#ce4f51'
                    }
                }
            };
        }),
        label: {
            show: true,
            position: [650, -2]
        },
        barWidth: 8,
        itemStyle: {
            color: function (params) {
                if (params.dataIndex < 3) {
                    return new echarts.graphic.LinearGradient(0, 0, 1, 0,
                        [{
                            offset: 0,
                            color: 'rgba(22, 119, 255, 0)'
                        },
                        {
                            offset: 1,
                            color: '#1778ff'
                        }
                        ]);
                } else {
                    return new echarts.graphic.LinearGradient(0, 0, 1, 0,
                        [{
                            offset: 0,
                            color: 'rgba(206, 79, 81, 0)'
                        },
                        {
                            offset: 1,
                            color: '#ce4f51'
                        }
                        ]);
                }

            },
            barBorderRadius: 4,
        }
    }]
    };