Conditions | 1 |
Paths | 1 |
Total Lines | 57 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | $(document).ready(() => { |
||
106 | function drawChart(data, type, selector) { |
||
107 | const categories = new Set(); |
||
108 | let groups = [[]]; |
||
109 | let chartData = []; |
||
110 | |||
111 | Object.values(data).forEach(entry => { |
||
112 | Object.keys(entry).forEach(key => categories.add(key)); |
||
113 | }); |
||
114 | |||
115 | Object.entries(data).forEach(entry => { |
||
116 | let group = entry[0]; |
||
117 | groups[0].push(group); |
||
118 | |||
119 | let dataEntry = [group]; |
||
120 | |||
121 | categories.forEach(cat => { |
||
122 | let count = entry[1][cat]; |
||
123 | if (!count) { |
||
124 | count = 0; |
||
125 | } |
||
126 | dataEntry.push(count); |
||
127 | }); |
||
128 | |||
129 | chartData.push(dataEntry); |
||
130 | }); |
||
131 | |||
132 | let chartConfig = $().c3ChartDefaults().getDefaultStackedBarConfig(); |
||
133 | chartConfig.bindto = selector; |
||
134 | chartConfig.axis = { |
||
135 | x: { |
||
136 | categories: Array.from(categories), |
||
137 | type: 'category', |
||
138 | }, |
||
139 | y: { |
||
140 | tick: { |
||
141 | format: showOnlyRoundNumbers |
||
142 | } |
||
143 | } |
||
144 | }; |
||
145 | chartConfig.data = { |
||
146 | columns: chartData, |
||
147 | groups: groups, |
||
148 | type: 'bar', |
||
149 | order: null |
||
150 | }; |
||
151 | chartConfig.color = { |
||
152 | pattern: [ |
||
153 | $.pfPaletteColors.blue, |
||
154 | $.pfPaletteColors.red100, |
||
155 | ] |
||
156 | }; |
||
157 | chartConfig.grid = { |
||
158 | show: false |
||
159 | }; |
||
160 | |||
161 | c3.generate(chartConfig); |
||
162 | } |
||
163 | |||
170 |
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.