<script>
export default {
  name: 'UiChartYaxisGroup',
  inject: ['UiChart'],
  provide() {
    return {
      UiChartYaxisGroup: this
    }
  },
  data() {
    return {
      items: []
    }
  },
  created() {
    this.UiChart.setOption('yAxis', this.items)
  },
  render(h) {
    return h('div', this.$scopedSlots.default ? this.$scopedSlots.default() : null)
  },
  methods: {
    addYaxis(option) {
      if (!option) {
        return
      }
      this.items.push(option)
      this.UiChart.setOption('yAxis', this.items)
    },
    removeYaxis(id) {
      let index = -1
      this.items.some((v, i) => {
        if (v.id === id) {
          index = i
          return true
        }
      })
      if (index < 0) {
        return
      }
      this.items.splice(index, 1)
      this.UiChart.setOption('yAxis', this.items)
    }
  }
}
</script>
