summaryrefslogtreecommitdiff
path: root/src/main/resources/static/scripts.js
blob: 8f08ee56ff586b382fd85e69f9b78867555b63ce (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
const dateFormatOptions = { year: 'numeric', month: '2-digit', day: '2-digit' };
const dateFormat = new Intl.DateTimeFormat('de-DE', dateFormatOptions);

const dateTimeFormatOptions = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: 'numeric', second: 'numeric' };
const dateTimeFormat = new Intl.DateTimeFormat('de-DE', dateTimeFormatOptions);

window.onload = () => {
    Array.from(document.getElementsByTagName('time')).forEach((timeTag) => {
        let date = Date.parse(timeTag.getAttribute('datetime'));
        if (! isNaN(date)) {
            timeTag.innerText = dateTimeFormat.format(date);
        }
    });
};

function drawPieChart(url, elemId, title) {
    fetch(url)
        .then(resp => resp.json())
        .then(data => {
            let chartDom = document.getElementById(elemId);
            let chart = echarts.init(chartDom);
            let option= {
                title: {
                    text: title,
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                color: data.map(i => i.color),
                series: [
                    {
                        type: 'pie',
                        radius: ['40%', '70%'],
                        avoidLabelOverlap: false,
                        label: {
                            show: false,
                            position: 'center'
                        },
                        labelLine: {
                            show: false
                        },
                        data: data
                    }
                ]
            };

            option && chart.setOption(option);
        });

}

function drawBarChart(url, elemId, title) {
    fetch(url)
        .then(resp => resp.json())
        .then(data => {
            let chartDom = document.getElementById(elemId);
            let chart = echarts.init(chartDom);
            let option= {
                title: {
                    text: title,
                    left: 'center'
                },
                xAxis: {
                    type: 'category',
                    data: data.map(i => dateFormat.format(Date.parse(i.date)))
                },
                yAxis: {
                    type: 'value',
                    minInterval: 2,
                },
                tooltip: {
                    trigger: 'item'
                },
                animation: false,
                color: ['slategray', 'red', 'darkorange', 'green', 'slategray'],
                series: [
                    {
                        name: 'UNKNOWN',
                        type: 'bar',
                        stack: 'total',
                        data: data.map(i => i.nameValues.unknown)
                    },
                    {
                        name: 'ERROR',
                        type: 'bar',
                        stack: 'total',
                        data: data.map(i => i.nameValues.error)
                    },
                    {
                        name: 'WARNING',
                        type: 'bar',
                        stack: 'total',
                        data: data.map(i => i.nameValues.warning)
                    },
                    {
                        name: 'SUCCESS',
                        type: 'bar',
                        stack: 'total',
                        data: data.map(i => i.nameValues.success)
                    },
                    {
                        name: 'DUPLICATION',
                        type: 'bar',
                        stack: 'total',
                        data: data.map(i => i.nameValues.duplication)
                    }
                ]
            };

            option && chart.setOption(option);
        });
}