/**
 *  关联关系分析
 *
 * @author Administrator
 * @since 2021/6/24
 */
layui.use(['layer'], function () {
    Util.get('/business/analysis/counts/12month', {}).then(res => {
        if (res.flag) {
            if (res.data.length === 0) {
                return
            }
            let x_data = [], s_data = [];
            for (let data of res.data) {
                x_data.push(data.months);
                s_data.push(data.counts);
            }
            let myChart = echarts.init(document.getElementById('div1'));
            let option = {
                tooltip: {},
                xAxis: {
                    type: 'category',
                    data: x_data,
                    axisLabel: {
                        interval: 0,
                        rotate: 40
                    }
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: s_data,
                        type: 'bar',
                        label: {
                            show: true,
                            position: 'top'
                        },
                    }
                ]
            };
            myChart.setOption(option);
        }
    })

    Util.get('/business/analysis/counts/resource-type', {}).then(res => {
        if (res.flag) {
            if (res.data.length === 0) {
                return
            }
            let s_data = [];
            for (let data of res.data) {
                s_data.push({name: data.type, value: data.counts});
            }
            let myChart = echarts.init(document.getElementById('div2'));
            let option = {
                tooltip: {
                    trigger: 'item',
                    formatter: '{a} <br/>{b} : {c} ({d}%)'
                },
                legend: {
                    //bottom: 0,
                    //left: 'center'
                    type: 'scroll',
                    orient: 'vertical',
                    right: 5,
                    top: 5,
                    bottom: 0,
                },
                series: [
                    {
                        name: '已关联个数',
                        type: 'pie',
                        radius:'60%',
                        //radius: ['30%', '65%'],
                        center: ['50%', '50%'],
                        avoidLabelOverlap: false,
                       /* itemStyle: {
                            borderRadius: 10,
                            borderColor: '#fff',
                            borderWidth: 2
                        },*/
                        emphasis: {
                            label: {
                                show: true,
                                fontSize: 40,
                                fontWeight: 'bold'
                            }
                        },
                        data: s_data
                    }
                ]
            };
            myChart.setOption(option);
        }
    })

    Util.get('/business/analysis/counts/resource-number?type=user', {}).then(res => {
        if (res.flag) {
            if (res.data.length === 0) {
                return
            }
            let x_data = [], s_data = [];
            for (let data of res.data) {
                x_data.push(data.name);
                s_data.push(data.counts);
            }
            let myChart = echarts.init(document.getElementById('div3'));
            let option = {
                tooltip: {},
                xAxis: {
                    type: 'category',
                    data: x_data,
                    axisLabel: {
                        interval: 0,
                        rotate: 40
                    }
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: s_data,
                        type: 'bar',
                        label: {
                            show: true,
                            position: 'top'
                        },
                    }
                ]
            };
            myChart.setOption(option);
        }
    })


    Util.get('/business/analysis/counts/directory-link', {}).then(res => {
        if (res.flag) {
            if (res.data.length === 0) {
                return
            }
            let s_data = [];
            for (let data of res.data) {
                let name = data.type;
                switch (data.type){
                    case 'LINK_DIR':
                        name = '链接的目录';
                        break;
                    case 'LINK_FILE':
                        name = '链接的文件';
                        break;
                    case 'LINK_METADATA':
                        name = '链接的数据表';
                        break;

                }
                s_data.push({name: name, value: data.counts});
            }
            let myChart = echarts.init(document.getElementById('div4'));
            let option = {
                tooltip: {
                    trigger: 'item',
                    formatter: '{a} <br/>{b} : {c} ({d}%)'
                },
                legend: {
                    //bottom: '5%',
                    //left: 'center'
                    type: 'scroll',
                    orient: 'vertical',
                    right: 5,
                    top: 5,
                    bottom: 0,
                },
                series: [
                    {
                        name: '已关联个数',
                        type: 'pie',
                        radius: '60%',
                        center: ['50%', '50%'],
                        avoidLabelOverlap: false,
                        itemStyle: {
                            borderRadius: 10,
                            borderColor: '#fff',
                            borderWidth: 2
                        },
                        emphasis: {
                            label: {
                                show: true,
                                fontSize: 40,
                                fontWeight: 'bold'
                            }
                        },
                        data: s_data
                    }
                ]
            };
            myChart.setOption(option);
        }
    })
});

