package com.njcn.echarts.json;

import com.njcn.echarts.pojo.constant.PicCommonData;
import org.icepear.echarts.Option;
import org.icepear.echarts.charts.pie.PieLabel;
import org.icepear.echarts.charts.pie.PieSeries;
import org.icepear.echarts.components.grid.Grid;
import org.icepear.echarts.components.legend.Legend;
import org.icepear.echarts.components.title.Title;
import org.icepear.echarts.origin.util.SeriesOption;
import org.icepear.echarts.render.Engine;

import java.util.List;
import java.util.Map;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2023年06月25日 21:42
 */
public class PieGenerator {

    private final static Engine ENGINE = new Engine();


    /***
     * 生成暂降原因
     * @author wr
     * @date 2023/6/21 10:06
     */
    public static String generateReasonOption(List<String> xName, List<Map<String,Object>> map2) {

        Option reasonOption = new Option();
        //取消渲染动画
        reasonOption.setAnimation(false);
        String[] colorArr = {"#526ADE", "#00BFF5","#FFBF00","#77DA63","#D5FF6B"};
        reasonOption.setColor(colorArr);
        //背景色
        reasonOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR);
        //标题
        reasonOption.setTitle(new Title().setRight("10%").setText("暂降原因"));
        //上下左右的图内间距
        reasonOption.setGrid(new Grid().setTop("80px").setLeft("40px").setRight("60px").setBottom("20px"));
        //设置图例
        reasonOption.setLegend(new Legend().setOrient("vertical").setData(xName.toArray()).setTop("26px").setLeft(10).setBottom("94%").setShow(true));
        String s = map2.toString();
        //配置暂降次数
        PieSeries probability = new PieSeries()
                .setType("pie")
                .setName("暂降原因")
                .setLabel(new PieLabel().setFormatter("{b}:{d}%"))
                .setData(map2);
        reasonOption.setSeries(new SeriesOption[]{probability});
        return ENGINE.renderJsonOption(reasonOption);
    }

    /***
     * 生成暂降类型
     * @author wr
     * @date 2023/6/21 10:06
     */
    public static String generateTypeOption(List<String> xName, List<Map<String,Object>> map) {

        Option typeOption = new Option();
        //取消渲染动画
        typeOption.setAnimation(false);
        //背景色
        typeOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR);
        //标题
        typeOption.setTitle(new Title().setRight("10%").setText("暂降类型"));
        //上下左右的图内间距
        typeOption.setGrid(new Grid().setTop("80px").setLeft("40px").setRight("60px").setBottom("20px"));
        //设置图例
        typeOption.setLegend(new Legend().setOrient("vertical").setData(xName.toArray()).setTop("26px").setLeft(10).setBottom("94%").setShow(true));
        //配置暂降次数
        PieSeries probability = new PieSeries()
                .setType("pie")
                .setName("暂降类型")
                .setLabel(new PieLabel().setFormatter("{b}:{d}%"))
                .setData(map);
        typeOption.setSeries(new SeriesOption[]{probability});
        return ENGINE.renderJsonOption(typeOption);
    }

}
