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

/**
 * @param option: Object 图表配置档
 */
export default (option) => {
    let _option = { ...option };
    let viewType = _option.series ? (_option.series[0].type) : null;

    // 动画
    _option.animation = false;
    // 悬浮提示
    _option.tooltip = null;
    // 图例
    _option.legend = null;
    // 容器
    _option.grid = {
        left: 10,
        right: 10,
        top: 10,
        bottom: 10,
        containLabel: false
    }
    _option.dataZoom = null;
    // 图形
    if(viewType ==='bar') { // 柱状图
        _option.series = _option.series.map(s => ({
            ...s, showSymbol: false, silent: true,
        }));
        // x轴
        _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].axisLabel = {
                ..._option.yAxis[0].axisLabel,
                show: false,
            }
        ) : (
            _option.yAxis.axisLabel = {
                ..._option.yAxis.axisLabel,
                show: false,
            }
        )) : _option.yAxis = {
            axisLabel: {
                show: false,
            } 
        };
    }else if(viewType === 'line') { // 折线图
        _option.series = _option.series.map(s => ({
            ...s, showSymbol: false, silent: true
        }));
        // x轴
        _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].axisLabel = {
                ..._option.yAxis[0].axisLabel,
                show: false,
            }
        ) : (
            _option.yAxis.axisLabel = {
                ..._option.yAxis.axisLabel,
                show: false,
            }
        )) : _option.yAxis = {
            axisLabel: {
                show: false,
            } 
        };
    }else if(viewType === 'pie') { // 饼图
        _option.series = _option.series.map(s => ({
            ...s, label: { show: false }, labelLine: { show: false }, silent: true
        }));
    }else if(viewType === 'scatter') { // 散点图
        _option.series = _option.series.map(s => ({
            ...s, silent: true
        }));
    }
    
    return _option;
}