window.customs = (function (){
    let getAnchorOption = function () {
        let anchorOption = Cookies.getObj('anchorOption');
        if (!anchorOption) {
            anchorOption = [
                {
                    title: '基线',
                    ratio: 0,
                    grid: true,
                    chart: true
                },
                {
                    title: '中轴',
                    ratio: 1,
                    grid: true,
                    chart: true
                },
                {
                    title: '平衡',
                    ratio: 1.809,
                    grid: true,
                    chart: true
                },
                {
                    title: '顶部',
                    ratio: 2.6180339887,
                    grid: true,
                    chart: true
                }
            ];
        }
        return anchorOption;
    }, getAnchorOptionToGridCols = function () {
        let anchorOption = getAnchorOption(), cols = [];
        anchorOption.forEach((option) => {
            if (!option.grid) return true;
            cols.push({
                title: option.title,
                templet: function (d) {
                    return (d.priceBase + d.priceUnit * option.ratio).toFixed(2);
                }
            });
        })
        return cols;
    }, getAnchorOptionForChart = function () {
        let anchorOption = getAnchorOption().reverse(), cols = [];
        anchorOption.forEach((option) => {
            if (!option.chart) return true;
            cols.push({
                title: option.title,
                ratio: option.ratio,
                data: []
            });
        });
        return cols;
    }, setAnchorOption = function (anchorOption) {
        Cookies.setObj('anchorOption', anchorOption, 365);
    }, dispatchSelected = function (chart) {
        let selected = Cookies.getObj('legendSelected');
        if (selected) {
            Object.keys(selected).forEach((k, index) => {
                if (index == 0) return true;
                chart.dispatchAction({type:selected[k]?'legendSelect':'legendUnSelect', name:k});
            });
        }
    };
    
    return {
        getAnchorOption: getAnchorOption,
        getAnchorOptionToGridCols: getAnchorOptionToGridCols,
        getAnchorOptionForChart: getAnchorOptionForChart,
        setAnchorOption: setAnchorOption,
        dispatchSelected: dispatchSelected
    }
    
})();