summaryrefslogtreecommitdiff
path: root/plugins/TimeMachine/Assets/js/components/chart-project-time-machine.js
blob: 0ae20256429f223659060ac61e8423ea1fe1b8b9 (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
KB.component('chart-project-analytics-time-comparison', function (containerElement, options) {
    this.render = function () {
        let spent = options.labelSpent;
        let estimated = options.labelEstimated;
        let data = [];
        let result = [];
        let groupsSpent = [];
        let groupsEstimated = [];
        let categories = [options.labelOpen, options.labelClosed];

        for (let metric in options.metrics) {
            data[metric+'-'+spent] = [metric+'-'+spent];
            data[metric+'-'+estimated] = [metric+'-'+estimated];
            groupsSpent.push(metric+'-'+spent);
            groupsEstimated.push(metric+'-'+estimated);
            data[metric+'-'+spent].push(options.metrics[metric]['open'].time_spent);
            data[metric+'-'+estimated].push(options.metrics[metric]['open'].time_estimated);
            data[metric+'-'+spent].push(options.metrics[metric]['closed'].time_spent);
            data[metric+'-'+estimated].push(options.metrics[metric]['closed'].time_estimated);
            result.push(data[metric+'-'+estimated]);
            result.push(data[metric+'-'+spent]);
        }
        result.sort();

        KB.dom(containerElement).add(KB.dom('div').attr('id', 'chart').build());

        c3.generate({
            data: {
                columns: result,
                type: 'bar',
                groups: [
                    groupsEstimated,
                    groupsSpent
                ]
            },
            bar: {
                width: {
                    ratio: 0.5
                }
            },
            axis: {
                x: {
                    type: 'category',
                    categories: categories
                }
            },
            legend: {
                show: true
            }
        });
    };
});

KB.component('chart-project-analytics-spent-time-by-dates', function (containerElement, options) {
    this.render = function () {
        let spentTime = [options.labelSpent];
        spentTime.push(options.metrics['open']);
        spentTime.push(options.metrics['closed']);
        let categories = [options.labelOpen, options.labelClosed];

        KB.dom(containerElement).add(KB.dom('div').attr('id', 'chart').build());

        c3.generate({
            data: {
                columns: [spentTime],
                type: 'bar'
            },
            bar: {
                width: {
                    ratio: 0.3
                }
            },
            axis: {
                x: {
                    type: 'category',
                    categories: categories
                }
            },
            legend: {
                show: true
            }
        });
    };
});