import { deepAssign } from '../utils/baseUtils'
/**
 * 图表自适应调整，宽高阈值分为两档，500和1000
 * 
 *      | G  | H  | I
 * 1000 +----+----+---
 *      | D  | E  | F
 *  500 +----+----+---
 *      | A  | B  | C
 *    0 +----+----+---
 *      0   500  1000
 */
export default function(chartType, legendVisible, dataZoomVisible, assignConfig) {
    if(chartType === 'bar' || chartType === 'line' || chartType === 'scatter') {
        return legendVisible ? [{
            query: { minWidth: 1000, minHeight: 1000 }, // I
            option: deepAssign({ legend: { type: 'scroll', top: 50, right: 50, orient: 'vertical', height: '80%', width: '35%' }, grid: { right: '20%'} }, assignConfig)
        }, {
            query: { maxWidth: 1000, minHeight: 1000 }, // H
            option: !dataZoomVisible ? deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 50, orient: 'horizontal', width: '90%' }, grid: { bottom: 100 } }, assignConfig) :
                deepAssign({ legend: { type: 'scroll', right: 'center', top: 50, orient: 'horizontal', width: '90%' }, }, assignConfig)
        }, {
            query: { maxWidth: 500, minHeight: 1000 }, // G
            option: !dataZoomVisible ? deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 50, orient: 'horizontal', width: '90%' }, }, assignConfig) :
                deepAssign({ legend: { type: 'scroll', right: 'center', top: 50, orient: 'horizontal', width: '90%' }, }, assignConfig)
        }, {
            query: { minWidth: 1000, maxHeight: 1000 }, // F
            option: deepAssign({ legend: { type: 'scroll', top: 50, right: 50, bottom: 100, orient: 'vertical', width: '35%' }, grid: { right: '16%' } }, assignConfig)
        }, {
            query: { maxWidth: 1000, maxHeight: 1000 }, // E
            option: !dataZoomVisible ? deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 50, orient: 'horizontal', width: '90%' }, grid: { bottom: 100 } }, assignConfig) :
                deepAssign({ legend: { type: 'scroll', right: 'center', top: 50, orient: 'horizontal', width: '90%' }, grid: { top: 100 } }, assignConfig)
        }, {
            query: { maxWidth: 500, maxHeight: 1000 }, // D
            option: !dataZoomVisible ? deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 0, orient: 'horizontal', width: '90%' }, grid: { bottom: 50 } }, assignConfig) :
                deepAssign({ legend: { type: 'scroll', right: 'center', top: 0, orient: 'horizontal', width: '90%' }, }, assignConfig)
        }, {
            query: { minWidth: 1000, maxHeight: 500 }, // C
            option: deepAssign({ legend: {  type: 'scroll', top: 50, right: 50, orient: 'vertical', height: '80%', width: '35%' }, grid: { right: '20%'} }, assignConfig)
        }, {
            query: { maxWidth: 1000, maxHeight: 500 }, // B
            option: !dataZoomVisible ? deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 0, orient: 'horizontal', width: '90%' }, grid: { top: 50, left: 80, right: 80, bottom: 50 } }, assignConfig) :
                deepAssign({ legend: { type: 'scroll', right: 'center', top: 20, orient: 'horizontal', width: '90%' }, grid: { top: 80, left: 80, right: 80 } }, assignConfig)
        }, {
            query: { maxWidth: 500, maxHeight: 500 }, // A
            option: !dataZoomVisible ? deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 0, orient: 'horizontal', width: '90%' }, grid: { top: 50, left: 80, right: 80 } }, assignConfig) :
                deepAssign({ legend: { type: 'scroll', right: 'center', top: 20, orient: 'horizontal', width: '90%' }, grid: { top: 80, left: 80, right: 80 } }, assignConfig)
        }] : []
    }else if(chartType === 'pie') {
        return [{
            query: { minWidth: 1000, minHeight: 1000 }, // I
            option: deepAssign({ legend: { type: 'scroll', top: 'center', right: 50, orient: 'vertical', height: '80%', width: '35%' }, series: [{ radius: [0, '65%'], center: ['35%', '50%'] }] }, assignConfig)
        }, {
            query: { maxWidth: 1000, minHeight: 1000 }, // H
            option: deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 50, orient: 'horizontal', width: '90%' }, series: [{ radius: [0, '55%'], center: ['50%', '40%'] }] }, assignConfig)
        }, {
            query: { maxWidth: 500, minHeight: 1000 }, // G
            option: deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 50, orient: 'horizontal', width: '90%' }, series: [{ radius: [0, '65%'], center: ['50%', '55%'] }] }, assignConfig)
        }, {
            query: { minWidth: 1000, maxHeight: 1000 }, // F
            option: deepAssign({ legend: { type: 'scroll', top: 'center', right: 50, orient: 'vertical', height: '80%', width: '35%' }, series: [{ radius: [0, '65%'], center: ['35%', '50%'] }] }, assignConfig)
        }, {
            query: { maxWidth: 1000, maxHeight: 1000 }, // E
            option: deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 50, orient: 'horizontal', width: '90%' }, series: [{ radius: [0, '55%'], center: ['50%', '40%'] }] }, assignConfig)
        }, {
            query: { maxWidth: 500, maxHeight: 1000 }, // D
            option: deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 0, orient: 'horizontal', width: '90%' }, series: [{ radius: [0, '55%'], center: ['50%', '40%'] }] }, assignConfig)
        }, {
            query: { minWidth: 1000, maxHeight: 500 }, // C
            option: deepAssign({ legend: { type: 'scroll', top: 'center', right: 50, orient: 'vertical', height: '80%', width: '35%' }, series: [{ radius: [0, '65%'], center: ['35%', '50%'] }] }, assignConfig)
        }, {
            query: { maxWidth: 1000, maxHeight: 500 }, // B
            option: deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 0, orient: 'horizontal', width: '90%' }, series: [{ radius: [0, '65%'], center: ['50%', '45%'] }] }, assignConfig)
        }, {
            query: { maxWidth: 500, maxHeight: 500 }, // A
            option: deepAssign({ legend: { type: 'scroll', right: 'center', bottom: 0, orient: 'horizontal', width: '90%' }, series: [{ radius: [0, '65%'], center: ['50%', '45%'] }] }, assignConfig)
        }]
    } 
}