Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
Lines | 65 |
Ratio | 100 % |
Changes | 4 | ||
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 | var filename_status = '/api/current', |
||
189 | View Code Duplication | function buildSummaryChart(summary) { |
|
1 ignored issue
–
show
|
|||
190 | sugarloaf.dates = summaryToDates(summary), |
||
191 | width = 800 - MARGINS.left - MARGINS.right, |
||
192 | height = 200 - MARGINS.top - MARGINS.bottom; |
||
193 | sugarloaf.dataset = datesToDataset(sugarloaf.dates); |
||
194 | |||
195 | sugarloaf.summary_x = d3.time.scale() |
||
196 | .range([0, width]) |
||
197 | .domain(d3.extent(sugarloaf.dates.map(function(d) { |
||
198 | return d.datetime; |
||
199 | }))); |
||
200 | |||
201 | sugarloaf.summary_y = d3.scale.linear() |
||
202 | .rangeRound([height, 0]) |
||
203 | .domain([0, d3.max(sugarloaf.dates, function(d) { return countDate(d)})]); |
||
204 | |||
205 | sugarloaf.summary_stack = d3.layout.stack(); |
||
206 | |||
207 | sugarloaf.summary_stack_layers = sugarloaf.summary_stack(sugarloaf.dataset); |
||
208 | |||
209 | sugarloaf.summary_area = d3.svg.area() |
||
210 | .interpolate('cardinal') |
||
211 | .x(function(d) { return sugarloaf.summary_x(d.x)}) |
||
212 | .y0(function(d) { return sugarloaf.summary_y(d.y0)}) |
||
213 | .y1(function(d) { return sugarloaf.summary_y(d.y0 + d.y)}); |
||
214 | |||
215 | sugarloaf.summary_color = d3.scale.ordinal() |
||
216 | // green, blue, black, double-black, terrain-park closed |
||
217 | .range(['#00A64B', '#2D2D94', '#6D6D6D', '#000', '#F6AE3B', '#FFF']) |
||
218 | .domain(['green', 'blue', 'black', 'double-black', 'terrain-park', 'closed']); |
||
219 | |||
220 | sugarloaf.summary_xAxis = d3.svg.axis() |
||
221 | .scale(sugarloaf.summary_x) |
||
222 | .orient('bottom') |
||
223 | //.ticks(d3.time.sundays, 1) |
||
224 | .ticks(10) |
||
225 | //.tickSubdivide(true) |
||
226 | .tickFormat(d3.time.format("%b %e")); |
||
227 | |||
228 | sugarloaf.summary_yAxis = d3.svg.axis() |
||
229 | .scale(sugarloaf.summary_y) |
||
230 | .orient('left'); |
||
231 | |||
232 | var svg = d3.select('#chart-summary').append('svg') |
||
233 | .attr('width', width + MARGINS.left + MARGINS.right) |
||
234 | .attr('height', height + MARGINS.top + MARGINS.bottom) |
||
235 | .append('g') |
||
236 | .attr('transform', 'translate(' + MARGINS.left + ',' + MARGINS.top +')'); |
||
237 | |||
238 | var selection = svg.selectAll('.series') |
||
239 | .data(sugarloaf.summary_stack_layers) |
||
240 | .enter().append('path') |
||
241 | .attr('class', 'layer') |
||
242 | .attr('d', function(d) { return sugarloaf.summary_area(d);}) |
||
243 | .style('fill', function(d, i) { return sugarloaf.summary_color(Object.keys(sugarloaf.difficulty_order)[i]) }); |
||
244 | |||
245 | svg.append('g') |
||
246 | .attr('class', 'x axis') |
||
247 | .attr('transform', 'translate(0,' + height + ')') |
||
248 | .call(sugarloaf.summary_xAxis); |
||
249 | |||
250 | svg.append('g') |
||
251 | .attr('class', 'y axis') |
||
252 | .call(sugarloaf.summary_yAxis); |
||
253 | } |
||
254 | |||
265 | }); |
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.