<!doctype html>
<html>

{% set title="Storage consumption per distribution" %}

<head>
    <title>{{ title }}</title>
    <script src="Chart.bundle.js"></script>
    <script src="utils.js"></script>
    <script src="moment.min.js"></script>
    <style>
    canvas {
        -moz-user-select: none;
        -webkit-user-select: none;
        -ms-user-select: none;
    }
    </style>
</head>

<body>
    <div style="width:75%">
        <canvas id="canvas"></canvas>
    </div>
    <script>
        var color = Chart.helpers.color;
        var scatterChartData = {
            datasets: {{ datasets|tojson }}
        };

        function fix_dataset(value, index, array) {
            if (value["label"].includes("fedora")) {
                value["borderColor"] =  window.chartColors.blue;
            }
            if (value["label"].includes("epel")) {
                value["borderColor"] =  window.chartColors.yellow;
            }
            if (value["label"].includes("centos")) {
                value["borderColor"] =  window.chartColors.red;
            }
        };

        window.onload = function() {

            scatterChartData["datasets"].forEach(fix_dataset);

            var ctx = document.getElementById("canvas").getContext("2d");
            window.myScatter = Chart.Scatter(ctx, {
                data: scatterChartData,
                options: {
                    title: {
                        display: true,
                        text: '{{ title }}',
                    },
                    tooltips: {
                        callbacks: {
                            label: function(item, data) {
                                index = item.datasetIndex;
                                dataset = data.datasets[index];
                                return dataset.label
                                       + " => " + new Date(item.xLabel).toISOString().slice(0,10)
                                       + " => " + Math.round(item.yLabel / 1024 / 1024 * 10)/10 + " GB";
                            }
                        }
                    },
                    scales: {
                        xAxes: [{
                            ticks: {
                                callback: (value) => {
                                    return new Date(value).toLocaleDateString(
                                        "en-US",
                                        {month: "short",year: "numeric"}
                                    );
                                }
                            }
                        }],
                        yAxes: [{
                            ticks: {
                                callback: (value) => {
                                    return Math.round(value / 1024 / 1024 *10)/10 + " GB";
                                }
                            }
                        }]

                    }
                }
            });
        };
    </script>
</body>

</html>
