/**
 * 为图表option二次设置样式属性
 */

/**
 * @param option: Object 图表配置档
 */
export default (option) => {
    if(!option || ((!option.series || option.series.length === 0) && (!option.baseOption || !option.baseOption.series || option.baseOption.series.length === 0))) {
        return {};
    }
    let _option = !!option.baseOption ? JSON.parse(JSON.stringify(option.baseOption)) : JSON.parse(JSON.stringify(option));
    let viewType = _option.series ? (_option.series[0].type) : undefined;

    // 动画
    _option.animation = false;
    // 悬浮提示
    _option.tooltip = undefined;
    // 工具箱
    _option.toolbox = undefined;
    // 图例
    _option.legend = undefined;
    // 容器
    _option.grid = {
        left: 10,
        right: 10,
        top: 10,
        bottom: 10,
        containLabel: false
    }
    _option.dataZoom = undefined;
    _option.series = _option.series ? _option.series.map(s => ({
        ...s, label: {
            normal: { show: false }
        },
    })) : _option.series;
    // X轴
    _option.xAxis ? (_option.xAxis.length > 0 ? _option.xAxis[0].name = '' : ( _option.xAxis.name = '' ) ) : _option.xAxis = { name: '' };
    _option.xAxis ? (_option.xAxis.length > 0 ? (
        _option.xAxis[0].axisLabel = {
            ..._option.xAxis[0].axisLabel,
            show: false,
        }
    ) : (
        _option.xAxis.axisLabel = {
            ..._option.xAxis.axisLabel,
            show: false,
        }
    )) : _option.xAxis = {
        axisLabel: {
            show: false,
        } 
    };
    // y轴
    _option.yAxis ? (_option.yAxis.length > 0 ? _option.yAxis[0].name = '' : ( _option.yAxis.name = '' ) ) : _option.yAxis = { name: '' };
    _option.yAxis ? (_option.yAxis.length > 0 ? (
        _option.yAxis[0].axisLabel = {
            ..._option.yAxis[0].axisLabel,
            show: false,
        }
    ) : (
        _option.yAxis.axisLabel = {
            ..._option.yAxis.axisLabel,
            show: false,
        }
    )) : _option.yAxis = {
        axisLabel: {
            show: false,
        } 
    };

    // 图形
    if(viewType ==='bar') { // 柱状图
        _option.series = _option.series.map(s => ({
            ...s, showSymbol: false, silent: true,
        }));
    }else if(viewType === 'line') { // 折线图
        _option.series = _option.series.map(s => ({
            ...s, showSymbol: false, silent: true
        }));
    }else if(viewType === 'pie') { // 饼图
        _option.series = _option.series.map(s => ({
            ...s,
            center: ['50%', '50%'],
            radius: [(s.radius ? (s.radius[0] ? '40%' : 0) || 0 : 0), '85%'],
            label: { show: false },
            labelLine: { show: false },
            silent: true
        }));
        delete _option.xAxis;
        delete _option.yAxis;
    }else if(viewType === 'scatter') { // 散点图
        _option.series = _option.series.map(s => ({
            ...s, silent: true
        }));
    }
    
    return _option;
}