# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name  : radar_chart.py
# @Time       : 2020/12/1 下午4:50
# @Author     : X. Peng
# @Email      : acepengxiong@163.com
# @Software   : PyCharm
# -----------------------------------------------------------------------------

import pyecharts.options as opts
from pyecharts.charts import Radar, Bar
from snapshot_phantomjs import snapshot
from pyecharts.render import make_snapshot


def gen_radar_chart():
    """
    Gallery 使用 pyecharts 1.1.0
    参考地址: https://echarts.apache.org/examples/editor.html?c=radar
    目前无法实现的功能:
    1、雷达图周围的图例的 textStyle 暂时无法设置背景颜色
    """
    v1 = [[4300, 10000, 28000, 35000, 50000]]

    (
        Radar(
            init_opts=opts.InitOpts(bg_color="#fff", animation_opts=opts.AnimationOpts(animation=False)))
            .add_schema(
            schema=[
                opts.RadarIndicatorItem(name="绝对收益", max_=6500),
                opts.RadarIndicatorItem(name="业绩持续性", max_=16000),
                opts.RadarIndicatorItem(name="风险调整后收益", max_=30000),
                opts.RadarIndicatorItem(name="极端风险", max_=38000),
                opts.RadarIndicatorItem(name="抗风险能力", max_=52000),
            ],
            splitarea_opt=opts.SplitAreaOpts(
                is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1, color=[
                    'rgba(198, 167, 116, 0.5)',
                    'rgba(198, 167, 116, 0.4)',
                    'rgba(198, 167, 116, 0.3)',
                    'rgba(198, 167, 116, 0.2)',
                    'rgba(198, 167, 116, 0.1)',
                ])
            ),
            textstyle_opts=opts.TextStyleOpts(color="#000", font_size=16),
        )
            .add(
            series_name="预算分配（Allocated Budget）",
            data=v1,
            linestyle_opts=opts.LineStyleOpts(width=2, color="#C6A774"),
            tooltip_opts=None
        )
            .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
            .set_global_opts(
            title_opts=opts.TitleOpts(
                title="综合评分", subtitle="66.32", pos_top="center", pos_left="46%",
                title_textstyle_opts={'color': '#333',
                                      'fontSize': 18,
                                      'lineHeight': 20,
                                      'fontWeight': 'normal'
                                      },
                subtitle_textstyle_opts={'color': '#222A77',
                                         'fontSize': 20,
                                         'lineHeight': 23,
                                         'fontWeight': 'bolder',
                                         }),
            legend_opts=opts.LegendOpts(selected_mode=False, is_show=False)
        )
            .render("basic_radar_chart.html")
    )
    make_snapshot(snapshot, "basic_radar_chart.html", "basic_radar_chart.png", delay=2)


if __name__ == '__main__':
    gen_radar_chart()