import * as echarts from 'echarts'
import _ from 'lodash';
export const getOption = (datas) => {
    datas = datas?.reverse();
    let max = _.max(datas?.map(data => data.money));
    max = max * 1.2
    const colors = ['#1F68E2', '#E2C334', '#00E9CB', '#44DA84', '#747DF8', '#31B9FF'];
    const sum = _.sumBy(datas, 'money');
    return {
        tooltip:{},
        legend: {
            show: true,
            orient: 'vertical',
            right: '0',
            icon: 'circle',
            itemWidth: 10,
            itemHeight: 10,
            top: 'center',
            textStyle: {
                color: '#fff',
                fontSize: 14,
            },
            itemGap: 16,
            formatter: function (name) {
                let index = datas.findIndex((item) => item.name === name);
                const item = datas[index];
                if (!item) {
                    return null;
                }
                const unit = item.unit;
                const valueText = item.money
                return `${item.name} ${valueText} ${unit}`;
            },
        },
        series: [
            {
                name: '',
                type: 'pie',
                radius: ['0', '80'],
                center: ['30%', '50%'],
                // roseType: 'area',
                color: colors,
                label: {
                    show: false
                },
                data: datas?.map?.(data => {
                    return {
                        name: data.name,
                        value: data.money
                    }
                })
            },
            {
                type: 'pie',
                radius: ['92', '94'],
                data: [
                    {
                        value: 50,
                        name: '',
                        itemStyle: {
                            color: '#ffffff4d'
                        }
                    },
                ],
                center: ['30%', '50%'],
                label: {
                    show: false
                }
            }
        ]
    };

}