var colors = ['#5793f3', '#d14a61', '#675bba'];

export default {
  color: colors,
  title: {
    text: '月出行最早开始时间',
    textStyle: {
      color: '#fff'
    }
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross'
    },
    formatter (pamams) {
      let doc = `
            <div>${pamams[0].name}</div>
        `
      pamams.forEach(item => {
        let str = `<div>
                    <span style="background: ${item.color};width: 10px;height: 10px;border-radius: 50%;display: inline-block;"></span> ${item.seriesName}: ${millisecondToDate(Number(item.data))}
                  </div>`
        doc += str
      })
      return doc
    }
  },
  grid: {
    left: '1%',
    right: '8%',
    bottom: '6%',
    containLabel: true
  },
  toolbox: {
    // feature: {
    //   dataView: {show: true, readOnly: false},
    //   restore: {show: true},
    //   saveAsImage: {show: true}
    // }
  },
  legend: {
    textStyle: {
      color: '#fff'
    }
  },
  xAxis: [
    {
      type: 'category',
      axisTick: {
        alignWithLabel: true,
        textStyle: {
          color: '#2DA2FD'
        }
      },
      axisLabel: {
        color: '#fff',
        // formatter: function (param) {
          // return new Date(parseInt(param)).toLocaleString().split(' ')[0]
          // return param
        // },
      },
      data: ['1月', '2月', '3月', '4月', '5月']
    }
  ],
  yAxis: [
    {
      type: 'value',
      name: '时间',
      axisLine: {
        lineStyle: {
          color: '#5a6379'
        }
      },
      max: 86399000,
      axisLabel: {
        formatter: function (param) {
          return millisecondToDate(Number(param))
        },
        color: '#fff'
      },
      nameTextStyle: {
        color: '#fff',
        padding: [0, 0, 0, 50]
      },
      splitLine: {
        lineStyle: {
          color: '#5a6379'
        }
      }
    }
  ],
  series: [
    {
      name: '月出行最早开始时间',
      type: 'line',
      data: [ 8024000, 24765000, 27765000, 26765000, 25765000]
    },
    {
      name: '出行最早开始时间',
      type: 'line',
      data: [ 23765000, 8024000, 8024000, 8024000, 8024000]
    }
  ]
};

function millisecondToDate (msd) {
  var time = parseInt(msd)
  var timeArray = []
  var n
  n = Math.floor(time / 604800000)
  if (n > 0) {
    time = time % 604800000
    timeArray.push(n + '周')
  }
  n = Math.floor(time / 86400000)
  if (n > 0) {
    time = time % 86400000
    timeArray.push(n + '天')
  }
  n = Math.floor(time / 3600000)
  if (n >= 0) {
    if (n < 10) {
      time = time % 3600000
      timeArray.push('0' + n + ':')
    } else {
      time = time % 3600000
      timeArray.push(n + ':')
    }
  }
  n = Math.floor(time / 60000)
  if (n >= 0) {
    if (n < 10) {
      time = time % 60000
      timeArray.push('0' + n + ':')
    } else {
      time = time % 60000
      timeArray.push(n + ':')
    }
  }
  n = Math.floor(time / 1000)
  if (n >= 0) {
    if (n < 10) {
      timeArray.push('0' + n)
    } else {
      timeArray.push(n)
    }
  }
  timeArray = timeArray.join('')
  return timeArray
}