POC

by maritavindedal

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<figure class="highcharts-figure">
    <div id="container"></div>
    <p class="highcharts-description">
        This bar chart compares the estimated production of corn and wheat for 2023 across six countries: 
        the USA, China, Brazil, the EU, Argentina, and India. Corn production significantly exceeds wheat production 
        in countries like the USA and Brazil, while wheat production surpasses corn in the EU. The chart uses metric tons 
        (MT) as the unit and highlights data sourced from IndexMundi.
    </p>
</figure>

CSS

@import url("https://code.highcharts.com/css/highcharts.css");

#container {
    max-width: 800px;
    margin: 1em auto;
}

#pref-menu-dialog {
    z-index: 9999;
    background-color: white;
    padding: 20px;
    border: 1px solid black;
    border-radius: 5px;
    min-width: 320px;
}

.pref {
    display: flex;
    align-items: center;
    gap: 10px;
}

h3 {
    margin-bottom: 10px;
}

/* To avoid screen reader region disappearing after chart.update() */
#highcharts-screen-reader-region-before-0 > div:first-child {
    position: static !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    white-space: normal !important;
    clip: auto !important;
    margin-top: 0 !important;
    opacity: 1 !important;
}

.highcharts-button-normal:hover,
.highcharts-button-normal-hover {
    cursor: pointer;
}

JavaScript

/**
 * TODO: Reset dark/light mode if contrast section is pressed? 
 * TODO: Add preview to showing text size with aA
 * TODO: Add dark mode to whole website
 * TODO: Decrease contrast of the purple series
 * TODO: Tweak colors for contrast and border
 * TODO: Create a short desc for points
 * TODO: Add visible alt text for the points
 * TODO: Add info region box for the chart with checkbox
 * TODO: Add white border to the columns of the chart?
 * TODO: Add local storage
 */

// Storing preference states globally
let selectedVerbosity = 'full',
    selectedTextSize = 'default',
    isContrastChecked = false,
    isBorderChecked = false,
    selectedColorTheme = 'default';

function initializeChart() {
    const chart = Highcharts.chart('container', getChartConfig());
    chart.prefMenu = {};
    addPrefButton(chart);
    addCustomA11yComponent(chart);
    addPrefButtonScreenReader(chart);
    return chart;
}

function getChartConfig() {
    return {
        chart: {
            type: 'column',
            styledMode: true
        },
        title: {
            text: 'Corn vs wheat estimated production for 2023'
        },
        subtitle: {
            text:
                'Source: <a target="_blank" ' +
                'href="https://www.indexmundi.com/agriculture/?commodity=corn">indexmundi</a>'
        },
        xAxis: {
            categories: ['USA', 'China', 'Brazil', 'EU', 'Argentina', 'India'],
            crosshair: true,
            accessibility: {
                description: 'Countries'
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: '1000 metric tons (MT)'
            }
        },
        tooltip: {
            valueSuffix: ' (1000 MT)'
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: [
            {
                name: 'Corn',
                data: [387749, 280000, 129000,...