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

  tooltip: {
    show: true,
    trigger: 'axis'
    // formatter: "{c} {d}"
  },
  xAxis: {
    type: 'category',
    // boundaryGap: false,
    data: [],
    boundaryGap: false,
    axisTick: {
      show: false
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: '#e5e5e5'
      }
    },
    splitLine: {
      lineStyle: {
        color: '#e5e5e5'
      }
    },
    axisLabel: {
      showMaxLabel: true
    }
  },
  yAxis: {
    type: 'value',
    minInterval: 1,
    axisTick: {
      show: false
    },
    axisLine: {
      show: true,
      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
}

