summaryrefslogtreecommitdiff
path: root/assets/js/src/CumulativeFlowDiagram.js
blob: b22fd2e9dd749ba0225ce3e0479a2b1f7f4ddc95 (plain)
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
Kanboard.CumulativeFlowDiagram = function(app) {
    this.app = app;
};

Kanboard.CumulativeFlowDiagram.prototype.execute = function() {
    if (this.app.hasId("analytic-cfd")) {
        this.show();
    }
};

Kanboard.CumulativeFlowDiagram.prototype.show = function() {
    var chart = $("#chart");
    var metrics = chart.data("metrics");
    var columns = [];
    var groups = [];
    var categories = [];
    var inputFormat = d3.time.format("%Y-%m-%d");
    var outputFormat = d3.time.format(chart.data("date-format"));

    for (var i = 0; i < metrics.length; i++) {

        for (var j = 0; j < metrics[i].length; j++) {

            if (i == 0) {
                columns.push([metrics[i][j]]);

                if (j > 0) {
                    groups.push(metrics[i][j]);
                }
            }
            else {

                columns[j].push(metrics[i][j]);

                if (j == 0) {
                    categories.push(outputFormat(inputFormat.parse(metrics[i][j])));
                }
            }
        }
    }

    c3.generate({
        data: {
            columns: columns,
            type: 'area-spline',
            groups: [groups]
        },
        axis: {
            x: {
                type: 'category',
                categories: categories
            }
        }
    });
};