JSFiddle - React, Tailwind, and code Playground

by maritavindedal

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/sonification.js"></script>

<div id="outer">
    <div id="overlay">
      <button class="btn" id="sonify">Click to play chart</button>
    </div>
    <figure class="highcharts-figure">
        <div id="container"></div>
    </figure>  
</div>

CSS

.btn {
    background-color: #25386f;
    border: 1 px solid #25386f;
    color: #fff;
    min-height: 40px;
    width: 30%;
    border-radius: 4px;
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    padding: .375rem .75rem;
    margin-bottom: .25rem;
    margin-top: .25rem;
}

.highcharts-figure {
  width: 100%;
  height: 100%;
  margin: 0;
}

#outer {
    min-width: 360px;
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

#overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    z-index: 999;
    background-color: rgba(255, 255, 255, 0.75);
}

JavaScript

var chart = Highcharts.chart('container', {
    chart: {
        type: 'spline'
    },
    title: {
        text: 'Sonify series in order'
    },
    subtitle: {
        text: 'Earcon on highest point in series'
    },
    plotOptions: {
        series: {
            sonification: {
                events: {
                    onPointStart: function (e, point) {
                        point.onMouseOver();
                    }
                }
            }
        }
    },
    sonification: {
        duration: 7000,
        defaultInstrumentOptions: {
            minFrequency: 220,
            maxFrequency: 2200,
            mapping: {
                duration: 200
            }
        },
        earcons: [{
            // Define the earcon we want to play
            earcon: new Highcharts.sonification.Earcon({
                instruments: [{
                    instrument: 'triangleMajor',
                    playOptions: {
                        // Play a quick rising frequency
                        frequency: function (time) {
                            return time * 1760 + 440;
                        },
                        volume: 0.3,
                        duration: 200
                    }
                }]
            }),
            // Play this earcon if this point is the highest in the series.
            condition: function (point) {
                var series = point.series;
                return point.y === Math.max.apply(Math, series.points.map(
                    function (p) {
                        return p.y;
                    }
                ));
            }
        }],
        events: {
            // Play a quick triangle tone on series start
            onSeriesStart: function () {
                document.getElementById('sonify').style.visibility='hidden';
                document.getElementById('overlay').style.visibility='hidden'; 
            },
            onEnd: function () {
               ...