import * as echarts from 'echarts'
import _ from 'lodash';
export const getOption = (datas) => {
    datas = datas?.reverse();
    let max = _.max(datas?.map(data => data.acreage));
    max = max * 1.2
    const colors = ['#0CEAFC', '#4A76F8', '#E3A41C', '#1E58FC'];
    const sum = _.sumBy(datas, 'acreage');
    return {
        tooltip:{},
        legend: {
            show: true,
            orient: 'vertical',
            right: 'center',
            icon: 'circle',
            itemWidth: 10,
            itemHeight: 10,
            top: 'bottom',
            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.acreage
                return `${item.name}   面积：${valueText} ${unit}   占比：${Math.round(valueText / sum * 10000) / 100}%`;
            },
        },
        series: [
            {
                name: '',
                type: 'pie',
                radius: ['0', '100'],
                center: ['50%', '40%'],
                // roseType: 'area',
                color: colors,
                label: {
                    show: false
                },
                data: datas?.map?.(data => {
                    return {
                        name: data.name,
                        value: data.acreage
                    }
                })
            },
            {
                type: 'pie',
                radius: ['112', '114'],
                data: [
                    {
                        value: 50,
                        name: '',
                        itemStyle: {
                            color: '#ffffff4d'
                        }
                    },
                ],
                center: ['50%', '40%'],
                label: {
                    show: false
                }
            }
        ]
    };

}