| Conditions | 1 |
| Paths | 1 |
| Total Lines | 98 |
| Lines | 98 |
| Ratio | 100 % |
| 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 | var filename_status = '/api/current', |
||
| 15 | View Code Duplication | function buildCharts() { |
|
|
|
|||
| 16 | sugarloaf.ndx = crossfilter(sugarloaf.data.trails); |
||
| 17 | |||
| 18 | sugarloaf.openDim = sugarloaf.ndx.dimension(function(d) { |
||
| 19 | if (d.open) { |
||
| 20 | return 'Open'; |
||
| 21 | } else { |
||
| 22 | return 'Closed'; |
||
| 23 | }; |
||
| 24 | }); |
||
| 25 | sugarloaf.openGroup = sugarloaf.openDim.group().reduceCount(function(d) { |
||
| 26 | return d.open; |
||
| 27 | }); |
||
| 28 | sugarloaf.openChart = dc.rowChart('#chart-row-open'); |
||
| 29 | sugarloaf.openChart |
||
| 30 | .width(WIDTH) |
||
| 31 | .height(HEIGHT/2) |
||
| 32 | .margins(MARGINS) |
||
| 33 | .dimension(sugarloaf.openDim) |
||
| 34 | .group(sugarloaf.openGroup) |
||
| 35 | .elasticX(true); |
||
| 36 | |||
| 37 | |||
| 38 | sugarloaf.groomedDim = sugarloaf.ndx.dimension(function(d) { |
||
| 39 | if (d.groomed) { |
||
| 40 | return 'Groomed'; |
||
| 41 | } else { |
||
| 42 | return 'Ungroomed'; |
||
| 43 | } |
||
| 44 | }); |
||
| 45 | sugarloaf.groomedGroup = sugarloaf.groomedDim.group().reduceCount(function(d) { |
||
| 46 | return d.groomed; |
||
| 47 | }) |
||
| 48 | sugarloaf.groomedChart = dc.rowChart('#chart-row-groomed'); |
||
| 49 | sugarloaf.groomedChart |
||
| 50 | .width(WIDTH) |
||
| 51 | .height(HEIGHT/2) |
||
| 52 | .margins(MARGINS) |
||
| 53 | .dimension(sugarloaf.groomedDim) |
||
| 54 | .group(sugarloaf.groomedGroup) |
||
| 55 | .elasticX(true); |
||
| 56 | |||
| 57 | |||
| 58 | sugarloaf.snowmakingDim = sugarloaf.ndx.dimension(function(d) { |
||
| 59 | if (d.snowmaking) { |
||
| 60 | return 'Snowmaking in progress'; |
||
| 61 | } else { |
||
| 62 | return 'Not snowmaking'; |
||
| 63 | } |
||
| 64 | }); |
||
| 65 | sugarloaf.snowmakingGroup = sugarloaf.snowmakingDim.group().reduceCount(function(d) { |
||
| 66 | return d.snowmaking; |
||
| 67 | }); |
||
| 68 | sugarloaf.snowmakingChart = dc.rowChart('#chart-row-snowmaking'); |
||
| 69 | sugarloaf.snowmakingChart |
||
| 70 | .width(WIDTH) |
||
| 71 | .height(HEIGHT/2) |
||
| 72 | .margins(MARGINS) |
||
| 73 | .dimension(sugarloaf.snowmakingDim) |
||
| 74 | .group(sugarloaf.snowmakingGroup) |
||
| 75 | .elasticX(true); |
||
| 76 | |||
| 77 | sugarloaf.difficultyDim = sugarloaf.ndx.dimension(function(d) { |
||
| 78 | return d.difficulty; |
||
| 79 | }); |
||
| 80 | sugarloaf.difficultyGroup = sugarloaf.difficultyDim.group().reduceCount(function(d) { |
||
| 81 | return d.difficulty; |
||
| 82 | }); |
||
| 83 | sugarloaf.difficultyChart = dc.rowChart('#chart-row-difficulty'); |
||
| 84 | sugarloaf.difficultyChart |
||
| 85 | .width(WIDTH) |
||
| 86 | .height(HEIGHT) |
||
| 87 | .margins(MARGINS) |
||
| 88 | .dimension(sugarloaf.difficultyDim) |
||
| 89 | .group(sugarloaf.difficultyGroup) |
||
| 90 | .ordering(function(d) { |
||
| 91 | return sugarloaf.difficulty_order[d.key]; |
||
| 92 | }) |
||
| 93 | .elasticX(true); |
||
| 94 | |||
| 95 | |||
| 96 | sugarloaf.areaDim = sugarloaf.ndx.dimension(function(d) { |
||
| 97 | return d.area; |
||
| 98 | }); |
||
| 99 | sugarloaf.areaGroup = sugarloaf.areaDim.group().reduceCount(function(d) { |
||
| 100 | return d.area; |
||
| 101 | }); |
||
| 102 | sugarloaf.areaChart = dc.rowChart('#chart-row-area'); |
||
| 103 | sugarloaf.areaChart |
||
| 104 | .width(WIDTH) |
||
| 105 | .height(HEIGHT * 2) |
||
| 106 | .margins(MARGINS) |
||
| 107 | .dimension(sugarloaf.areaDim) |
||
| 108 | .group(sugarloaf.areaGroup) |
||
| 109 | .elasticX(true); |
||
| 110 | |||
| 111 | dc.renderAll(); |
||
| 112 | } |
||
| 113 | |||
| 118 | }); |