package com.youchain.report_data.utils;

import cn.hutool.json.JSONUtil;
import com.youchain.exception.handler.ApiError;
import com.youchain.exception.handler.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.icepear.echarts.Gauge;
import org.icepear.echarts.Option;
import org.icepear.echarts.charts.gauge.*;
import org.icepear.echarts.components.series.ItemStyle;
import org.icepear.echarts.components.series.LineStyle;
import org.icepear.echarts.liuxue.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.ArrayList;
import java.util.List;

import static org.springframework.http.HttpStatus.BAD_REQUEST;

@Slf4j
public class PieChart {
    public static Option pieStyle(String color0, String color1, String scoreName, double percentage){
        List<ColorStops> colorStops=new ArrayList<>();
        colorStops.add(new ColorStops(0,color0));
        colorStops.add(new ColorStops(1,color1));
        JianBianColor jianBianColor=new JianBianColor("linear",0.8,0,0,1,colorStops,false);
        Gauge gauge = new Gauge()
                .setTooltip("item")
                .addSeries(new GaugeSeries().setName("Pressure")
                        .setStartAngle(90)
                        .setEndAngle(-270)
                        .setMin(0)
                        .setMax(100)
                        .setItemStyle(new ItemStyle().setColor("#FDFF00"))
                        .setProgress(new GaugeProgress().setShow(true).setRoundCap(false).setWidth(20).setItemStyle(new ItemStyle().setColor(jianBianColor).setBorderWidth(0)))
                        .setPointer(new GaugePointer().setShow(false))
                        .setAxisLine(new AxisLine().setLineStyle(new LineStyle().setWidth(20)))
                        .setSplitLine(new SplitLine(-62,0,new LineStyle().setWidth(3).setColor("#ff0000")))
                        .setAxisTick(new AxisTick(-45,5,new LineStyle().setWidth(3).setColor("#ff0000")))
                        .setAxisLabel(new AxisLabel())
                        .setAnchor(new GaugeAnchor().setShow(false))
                        .setTitle(new GaugeTitle().setShow(false))
                        .setDetail(new GaugeDetail().setValueAnimation(true).setWidth("100%").setBorderRadius(8).setOffsetCenter(new String[]{"0","0%"}).setFontSize(30).setColor("#f0f0ff"))
                        .setData(new GaugeDataItem[] { new GaugeDataItem().setValue(percentage).setName(scoreName) }));
        return gauge.getOption();
    }
}
