DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Git (455a99ca8d)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
<!DOCTYPE html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<select id="graphs"></select>
<script>
    function transformData(data, path) {
        console.log(path);
        var pathParts = path.split('!');
        var name = pathParts[pathParts.length - 1];
        var transformed = [];
        for (const report of data.map(d => d.report)) {
            var subData = findData(report, path);
            transformed.push(subData.amount);
        }
        console.log(transformed);
        return [{
            label: 'Usage in MiB',
            data: transformed,
            fill: false,
        }];
    }

    function findData(data, parent) {
        parent = parent.split('!');
        parent.reverse();
        while (parent.length) {
            var next = parent.pop();
            console.log(next);
            if ('children' in data) {
                data = data.children;
            }
            data = data[next];
        }
        return data;
    }

    function makeOptions(data, initial) {
        var sel = document.querySelector('#graphs');
        sel.innerHTML = '';
        // TODO: add support for labels that are not present in initial report.
        var rootData = data[0].report;
        console.log(Object.keys(rootData));
        var remaining = Object.keys(rootData).map(k => [k, rootData[k], k]);
        remaining.reverse();
        while (remaining.length) {
            var next = remaining.pop();
            var children = Object.keys(next[1].children).map(k => [k, next[1].children[k], next[2] + '!' + k]);
            children.reverse();
            remaining.push.apply(remaining, children);

            var opt = sel.appendChild(document.createElement('option'));
            opt.innerText = '-'.repeat((next[2].match(/!/g) || []).length) + next[0];
            opt.fullPath = next[2];
        }
        sel.onchange = function() {
            var title = sel.value;
            while (title[0] == '-') {
                title = title.slice(1);
            }
            makeChart({
                'labels': data.map(d => d.seconds + 's'),
                'datasets': transformData(data, sel.selectedOptions[0].fullPath),
            }, title);
        };
        sel.value = initial;
        sel.onchange();
    }

    function makeChart(data, title) {
        var canvas = document.querySelector('#myChart');
        if (canvas) {
            canvas.remove();
        }
        canvas = document.body.appendChild(document.createElement('canvas'));
        canvas.id = 'myChart';
        canvas.width = 800;
        canvas.height = 600;
        var ctx = canvas.getContext('2d');
        var myChart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: data['labels'],
                datasets: data['datasets']
            },
            options: {
                title: {
                    display: true,
                    text: title,
                },
                responsive: false,
                animation: {
                    duration: 0
                },
                elements: {
                    line: {
                        tension: 0
                    }
                },
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero:true
                        }
                    }]
                }
            }
        });
    }

    var data = [/* json data */];
    var initialGraph = "explicit";
    makeOptions(data, initialGraph);
</script>