<template>
  <div>
    <div id="chart">
      <apexchart
        type="raincloud"
        height="420"
        :options="chartOptions"
        :series="series"
      ></apexchart>
    </div>
  </div>
</template>

<script>
import VueApexCharts from 'vue-apexcharts'

import 'apexcharts/features/raincloud'

// Raw observations per group (Box-Muller Gaussian; Math.random is seeded by
// the sample template). One group is deliberately bimodal: the cloud shows
// the two modes that the box alone would hide, which is the whole point of
// stacking all three layers.
function sample(mean, sd, n) {
  var points = []
  for (var k = 0; k < n; k++) {
    var u1 = Math.random(),
      u2 = Math.random()
    var g = Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2)
    points.push(Math.round((mean + g * sd) * 100) / 100)
  }
  return points
}

export default {
  components: {
    apexchart: VueApexCharts,
  },
  data: function () {
    return {
      series: [
        {
          name: 'Bill ratio',
          data: [
            { x: 'Adelie', points: sample(2.12, 0.16, 150) },
            { x: 'Chinstrap', points: sample(2.65, 0.14, 70) },
            {
              x: 'Gentoo',
              points: sample(3.08, 0.1, 60).concat(sample(3.28, 0.09, 60)),
            },
          ],
        },
      ],
      chartOptions: {
        chart: {
          type: 'raincloud',
          height: 420,
        },
        colors: ['#FE9C64', '#00A29B', '#2E93fA'],
        title: {
          text: 'Bill ratios of three penguin species',
        },
        subtitle: {
          text: 'Horizontal layout: cloud above the axis line, box and rain below',
        },
        plotOptions: {
          bar: {
            horizontal: true,
            distributed: true,
          },
        },
        legend: {
          show: false,
        },
        xaxis: {
          title: {
            text: 'Bill ratio (length / depth)',
          },
        },
      },
    }
  },
}
</script>

<style>
#chart {
  max-width: 820px;
  margin: 35px auto;
}
</style>