summaryrefslogtreecommitdiff
path: root/assets/js/analytic.js
blob: 14cbc815093343d45f640ee8a63a0791e5e4c772 (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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

Kanboard.Analytic = (function() {

    return {
        Init: function() {

            if (Kanboard.Exists("analytic-task-repartition")) {
                Kanboard.Analytic.TaskRepartition.Init();
            }
            else if (Kanboard.Exists("analytic-user-repartition")) {
                Kanboard.Analytic.UserRepartition.Init();
            }
            else if (Kanboard.Exists("analytic-cfd")) {
                Kanboard.Analytic.CFD.Init();
            }
        }
    };

})();

Kanboard.Analytic.CFD = (function() {

    function fetchData()
    {
        jQuery.getJSON($("#chart").attr("data-url"), function(data) {
            drawGraph(data.metrics, data.labels, data.columns);
        });
    }

    function drawGraph(metrics, labels, columns)
    {
        var series = prepareSeries(metrics, labels);

        var svg = dimple.newSvg("#chart", "100%", 380);
        var chart = new dimple.chart(svg, series);

        var x = chart.addCategoryAxis("x", labels['day']);
        x.addOrderRule("Date");

        chart.addMeasureAxis("y", labels['total']);

        var s = chart.addSeries(labels['column'], dimple.plot.area);
        s.addOrderRule(columns.reverse());

        chart.addLegend(10, 10, 500, 30, "left");
        chart.draw();
    }

    function prepareSeries(metrics, labels)
    {
        var series = [];

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

            var row = {};
            row[labels['column']] = metrics[i]['column_title'];
            row[labels['day']] = metrics[i]['day'];
            row[labels['total']] = metrics[i]['total'];
            series.push(row);
        }

        return series;
    }

    return {
        Init: fetchData
    };

})();

Kanboard.Analytic.TaskRepartition = (function() {

    function fetchData()
    {
        jQuery.getJSON($("#chart").attr("data-url"), function(data) {
            drawGraph(data.metrics, data.labels);
        });
    }

    function drawGraph(metrics, labels)
    {
        var series = prepareSeries(metrics, labels);

        var svg = dimple.newSvg("#chart", "100%", 350);

        var chart = new dimple.chart(svg, series);
        chart.addMeasureAxis("p", labels["nb_tasks"]);
        var ring = chart.addSeries(labels["column_title"], dimple.plot.pie);
        ring.innerRadius = "50%";
        chart.addLegend(0, 0, 100, "100%", "left");
        chart.draw();
    }

    function prepareSeries(metrics, labels)
    {
        var series = [];

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

            var serie = {};
            serie[labels["nb_tasks"]] = metrics[i]["nb_tasks"];
            serie[labels["column_title"]] = metrics[i]["column_title"];

            series.push(serie);
        }

        return series;
    }

    return {
        Init: fetchData
    };

})();

Kanboard.Analytic.UserRepartition = (function() {

    function fetchData()
    {
        jQuery.getJSON($("#chart").attr("data-url"), function(data) {
            drawGraph(data.metrics, data.labels);
        });
    }

    function drawGraph(metrics, labels)
    {
        var series = prepareSeries(metrics, labels);

        var svg = dimple.newSvg("#chart", "100%", 350);

        var chart = new dimple.chart(svg, series);
        chart.addMeasureAxis("p", labels["nb_tasks"]);
        var ring = chart.addSeries(labels["user"], dimple.plot.pie);
        ring.innerRadius = "50%";
        chart.addLegend(0, 0, 100, "100%", "left");
        chart.draw();
    }

    function prepareSeries(metrics, labels)
    {
        var series = [];

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

            var serie = {};
            serie[labels["nb_tasks"]] = metrics[i]["nb_tasks"];
            serie[labels["user"]] = metrics[i]["user"];

            series.push(serie);
        }

        return series;
    }

    return {
        Init: fetchData
    };

})();