const defaultOptions = {
  title: {
    text: '展会访问数据',
    left: 'left',
    top: 0,
    textStyle: {
      fontSize: 17
    }
  },
  textStyle: {
    color: '#909090'
  },
  grid: {
    top: 37,
    left: 40,
    right: 0,
    bottom: 20
  },
  color: ["#17D2D2", "#738EFE"],
  legend: {
    left: 'right',
    itemWidth: 14,
    icon: 'roundRect',
    textStyle: {
      fontSize: 11
    }
  },

  tooltip: {
    show: true,
    trigger: 'axis'
  },
  xAxis: {
    type: 'value',
    // boundaryGap: false,
    axisTick: {
      show: false
    },
    axisLine: {
      lineStyle: {
        color: '#e5e5e5'
      }
    },
    axisLabel: {
      align: 'right'
    },
    splitLine: {
      lineStyle: {
        color: '#e5e5e5'
      }
    }
  },
  yAxis: {
    type: 'value',
    axisTick: {
      show: false
    },
    axisLine: {
      lineStyle: {
        color: '#e5e5e5'
      }
    },
    axisLabel: {
      margin: 7,
      formatter (value) {
        return value.toString()
      }
    },
    splitLine: {
      lineStyle: {
        color: '#e5e5e5'
      }
    }
  }
}

function isObject (value) {
  return Object.prototype.toString.call(value) === '[object Object]'
}
export function mergeOptions (options, defaultOption=defaultOptions) {
  Object.keys(defaultOption).forEach(item => {
    if (!options[item]) {
      options[item] = defaultOption[item]
    } else {
      if (isObject(options[item])) {
        mergeOptions(options[item], defaultOption[item])
      }
    }
  })
  return options
}

