// valuesMonitor chart option
function getDefaultOption () {
    return {
        darkMode: true,
        backgroundColor: 'transparent',
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'cross'
            }
        },
        title: {
            left: 'center',
            text: '',
            show: true
        },
        grid: {
            show: true,
            backgroundColor: 'transparent',
            borderWidth: 0,
            top: 32,
            bottom: 8,
            left: 30,
            right: 16
        },
        toolbox: {
            show: false,
            feature: {
                dataZoom: {
                    yAxisIndex: 'none'
                },
                restore: {},
                saveAsImage: {}
            }
        },
        xAxis: {
            type: 'time'
        },
        yAxis: {
            type: 'value',
            splitLine: {
                show: true
            },
            min: 0
        },
        dataZoom: [
        ],
        dataset: [
            {
                id: 'dataset_raw',
                source: []
            }
        ],
        series: [

        ]
    }
}
function getDatasetAndSeries (lineProps) {
    const datasetAppend = []
    const series = []
    function getLine (props) {
        return {
            type: 'line',
            datasetId_Test: props.datasetId,
            datasetIndex: 0,
            showSymbol: false,
            name: props.name,
            endLabel: {
                show: false,
                formatter: function (params) {
                    return params.value[3] + ': ' + params.value[0];
                }
            },
            labelLayout: {
                moveOverlap: 'shiftY'
            },
            emphasis: {
                focus: 'series'
            },
            encode: props.encode
        }
    }
    lineProps.forEach(p => {
        let singleLine = getLine(p)
        singleLine = { ...singleLine, ...p.others }
        series.push(singleLine)
        if (Object.keys(p.dataRules).length > 0 && p.hasAloneDataset) {
            datasetAppend.push({
                id: p.datasetId,
                fromDatasetId: 'dataset_raw',
                transform: {
                    type: 'filter',
                    config: p.dataRules
                }
            })
        }
    });

    return { datasetAppend, series }
}
export function calLineProps (lineProps) {
    return getDatasetAndSeries(lineProps)
}
export function mergeOption (personal, lineProps) {
    // add dataSet, line
    const cal = getDatasetAndSeries(lineProps);
    const datasetAppend = cal.datasetAppend
    const series = cal.series

    const defaultOption = getDefaultOption()
    defaultOption.series = series
    defaultOption.dataset = defaultOption.dataset.concat(datasetAppend)

    return { ...defaultOption, ...personal }
}
