package com.njcn.echarts.json;

import com.njcn.echarts.pojo.constant.PicCommonData;
import org.icepear.echarts.Option;
import org.icepear.echarts.charts.bar.BarLabel;
import org.icepear.echarts.charts.bar.BarSeries;
import org.icepear.echarts.charts.bar3D.Bar3DSeries;
import org.icepear.echarts.components.coord.AxisNameTextStyle;
import org.icepear.echarts.components.coord.SplitLine;
import org.icepear.echarts.components.coord.cartesian.CategoryAxis;
import org.icepear.echarts.components.coord.cartesian.ValueAxis;
import org.icepear.echarts.components.grid.Grid;
import org.icepear.echarts.components.grid3D.Grid3D;
import org.icepear.echarts.components.grid3D.ViewControl;
import org.icepear.echarts.components.inRange.InRange;
import org.icepear.echarts.components.legend.Legend;
import org.icepear.echarts.components.series.LineStyle;
import org.icepear.echarts.components.title.Title;
import org.icepear.echarts.components.visualMap.ContinousVisualMap;
import org.icepear.echarts.origin.util.SeriesOption;
import org.icepear.echarts.render.Engine;

import java.util.List;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2023年06月25日 20:10
 */
public class BarGenerator {

    private final static Engine ENGINE = new Engine();


    /***
     * 生成月份统计
     * @author wr
     * @date 2023/6/21 10:06
     */
    public static String generateMonthOption(List<String> xName, List<Integer> times, String year, Integer flag) {
        xName.set(0, xName.get(0) + "\n" + "(" + year + ")");
        String name;
        Option monthOption = new Option();
        //取消渲染动画
        monthOption.setAnimation(false);
        //背景色
        monthOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR);
        //标题
        if (flag == 0) {
            monthOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("月份统计"));
            name = "月份";
        } else {
            monthOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("天数统计"));
            name = "天数";
        }
        //上下左右的图内间距
        monthOption.setGrid(new Grid().setTop("80px").setLeft("40px").setRight("60px").setBottom("20px"));
        //设置图例
        monthOption.setLegend(new Legend().setData(new String[]{"暂降次数"}).setTop("26px").setLeft(10).setBottom("94%").setShow(true));
        //设置图例对应的颜色
        monthOption.setColor(new String[]{"#FF8C00"});
        //横坐标
        monthOption.setXAxis(new CategoryAxis()
                .setBoundaryGap(true)
                .setName(name)
                .setNameTextStyle(new AxisNameTextStyle().setFontStyle("15px"))
                .setData(xName.toArray())
        );
        //纵坐标
        monthOption.setYAxis(new ValueAxis[]{
                new ValueAxis()
                        .setName("次")
                        .setType("value")
        });

        //配置暂降次数
        BarSeries probability = new BarSeries()
                .setName("暂降次数")
                .setLabel(new BarLabel().setShow(true).setColor("#8B008B"))
                .setData(times);
        monthOption.setSeries(new SeriesOption[]{probability});
        return ENGINE.renderJsonOption(monthOption);
    }


    /***
     * 生成暂降密度图
     * @author hongawen
     * @date 2023/6/25 20:12
     */
    public static String generateEventDensity(Number[][] data) {
        Option option3D = new Option();
        option3D.setBackgroundColor("#fff");
        option3D.setTitle(new Title().setText("暂降密度图").setX("center"));
        option3D.setVisualMap(new ContinousVisualMap().setMax(20).setShow(false).setInRange(new InRange().setColor(new String[]{"#313695", "#00BB00", "#ff8000", "#a50026"})));
        option3D.setXAxis3D(new CategoryAxis().setName("剩余电压(%)").setData(new String[]{"0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100"}));
        option3D.setYAxis3D(new CategoryAxis()
                .setName("持续时间(cyc)")
                .setData(new String[]{"1cyc", "2cyc", "3cyc", "4cyc", "5cyc", "6~10cyc", "10~20cyc", "20~30cyc", "30~60cyc"})
                .setSplitLine(new SplitLine().setLineStyle(new LineStyle().setColor("#").setType("dashed").setOpacity(0.5)))
        );
        option3D.setZAxis3D(new ValueAxis().setSplitNumber(8).setMinInterval(5).setName("次数"));
        option3D.setGrid3D(new Grid3D()
                .setViewControl(new ViewControl().setBeta(8).setAlpha(5))
                .setBoxWidth(200)
                .setBoxDepth(80)
        );
        Bar3DSeries bar3DSeries = new Bar3DSeries()
                .setData(data)
                .setShading("realistic");
        option3D.setSeries(new SeriesOption[]{bar3DSeries});
        return ENGINE.renderJsonOption(option3D);
    }
}
