1 | $(document).ready(() => { |
||
2 | $('.selectpicker').selectpicker(); |
||
3 | |||
4 | loadInitialProduct(reloadCharts); |
||
5 | |||
6 | $('#id_after').on('dp.change', reloadCharts); |
||
7 | $('#id_before').on('dp.change', reloadCharts); |
||
8 | document.getElementById('id_test_plan').onchange = reloadCharts; |
||
9 | document.getElementById('id_product').onchange = () => { |
||
10 | updateTestPlanSelectFromProduct(reloadCharts); |
||
11 | }; |
||
12 | }); |
||
13 | |||
14 | function reloadCharts() { |
||
15 | const query = {}; |
||
16 | |||
17 | const testPlanId = $('#id_test_plan').val(); |
||
18 | const productId = $('#id_product').val(); |
||
19 | |||
20 | if (testPlanId) { |
||
21 | query['plan'] = testPlanId; |
||
22 | } else if (productId) { |
||
23 | query['category__product_id'] = productId; |
||
24 | } |
||
25 | |||
26 | const dateBefore = $('#id_before'); |
||
27 | if (dateBefore.val()) { |
||
28 | query['create_date__lte'] = dateBefore.data('DateTimePicker').date().format('YYYY-MM-DD 23:59:59'); |
||
29 | } |
||
30 | |||
31 | const dateAfter = $('#id_after'); |
||
32 | if (dateAfter.val()) { |
||
33 | query['create_date__gte'] = dateAfter.data('DateTimePicker').date().format('YYYY-MM-DD 00:00:00'); |
||
34 | } |
||
35 | |||
36 | jsonRPC('Testing.breakdown', query, result => { |
||
37 | drawAutomatedBar(result.count); |
||
38 | drawPrioritiesChart(result.priorities); |
||
39 | drawCategoriesChart(result.categories); |
||
40 | }, true); |
||
41 | } |
||
42 | |||
43 | function drawAutomatedBar(count) { |
||
44 | d3.select('#total-count') |
||
0 ignored issues
–
show
|
|||
45 | .style('font-weight', 'bold') |
||
46 | .style('font-size', '18px') |
||
47 | .text(count.all); |
||
48 | |||
49 | d3.selectAll('.progress-bar') |
||
50 | .attr('aria-valuemin', '0') |
||
51 | .attr('aria-valuemax', '100'); |
||
52 | |||
53 | d3.select('.automated-legend-text > span').remove(); |
||
54 | d3.select('.manual-legend-text > span').remove(); |
||
55 | |||
56 | d3.select('.automated-legend-text') |
||
57 | .append('span') |
||
58 | .text(` - ${count.automated}`); |
||
59 | |||
60 | d3.select('.manual-legend-text') |
||
61 | .append('span') |
||
62 | .text(` - ${count.manual}`); |
||
63 | |||
64 | const automatedPercent = count.automated / count.all * 100; |
||
65 | |||
66 | d3.select('.automated-bar') |
||
67 | .attr('aria-valuenow', `${automatedPercent}`) |
||
68 | .attr('title', `${count.automated} Automated`) |
||
69 | .style('width', `${automatedPercent}%`); |
||
70 | |||
71 | const manualPercent = count.manual / count.all * 100; |
||
72 | |||
73 | d3.select('.manual-bar') |
||
74 | .attr('aria-valuenow', `${manualPercent}`) |
||
75 | .attr('title', `${count.manual} Manual`) |
||
76 | .style('width', `${manualPercent}%`); |
||
77 | } |
||
78 | |||
79 | function drawPrioritiesChart(priorities) { |
||
80 | drawChart(priorities, 'priority', '#priorities-chart'); |
||
81 | } |
||
82 | |||
83 | function drawCategoriesChart(categories) { |
||
84 | drawChart(categories, 'category', '#categories-chart'); |
||
85 | } |
||
86 | |||
87 | function drawChart(data, type, selector) { |
||
88 | const categories = new Set(); |
||
89 | let groups = [[]]; |
||
90 | let chartData = []; |
||
91 | |||
92 | Object.values(data).forEach(entry => { |
||
93 | Object.keys(entry).forEach(key => categories.add(key)); |
||
94 | }); |
||
95 | |||
96 | Object.entries(data).forEach(entry => { |
||
97 | let group = entry[0]; |
||
98 | groups[0].push(group); |
||
99 | |||
100 | let dataEntry = [group]; |
||
101 | |||
102 | categories.forEach(cat => { |
||
103 | let count = entry[1][cat]; |
||
104 | if (!count) { |
||
105 | count = 0; |
||
106 | } |
||
107 | dataEntry.push(count); |
||
108 | }); |
||
109 | |||
110 | chartData.push(dataEntry); |
||
111 | }); |
||
112 | |||
113 | let chartConfig = $().c3ChartDefaults().getDefaultStackedBarConfig(); |
||
114 | chartConfig.bindto = selector; |
||
115 | chartConfig.axis = { |
||
116 | x: { |
||
117 | categories: Array.from(categories), |
||
118 | type: 'category', |
||
119 | }, |
||
120 | y: { |
||
121 | tick: { |
||
122 | format: showOnlyRoundNumbers |
||
0 ignored issues
–
show
The variable
showOnlyRoundNumbers seems to be never declared. If this is a global, consider adding a /** global: showOnlyRoundNumbers */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN.
Loading history...
|
|||
123 | } |
||
124 | } |
||
125 | }; |
||
126 | chartConfig.data = { |
||
127 | columns: chartData, |
||
128 | groups: groups, |
||
129 | type: 'bar', |
||
130 | order: null |
||
131 | }; |
||
132 | chartConfig.color = { |
||
133 | pattern: [ |
||
134 | $.pfPaletteColors.blue, |
||
135 | $.pfPaletteColors.red100, |
||
136 | ] |
||
137 | }; |
||
138 | chartConfig.grid = { |
||
139 | show: false |
||
140 | }; |
||
141 | |||
142 | c3.generate(chartConfig); |
||
0 ignored issues
–
show
The variable
c3 seems to be never declared. If this is a global, consider adding a /** global: c3 */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN.
Loading history...
|
|||
143 | } |
||
144 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.