Conditions | 3 |
Total Lines | 75 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 | import { |
||
66 | |||
67 | function showHighlightBackground(dimension: ReturnType<typeof findGroupBackgroundDimension>) { |
||
68 | if (!dimension) { |
||
69 | return; |
||
70 | } |
||
71 | const highlightBackground = selectHighlightBackground(); |
||
72 | const detailsButtonRectSelection = selectDetailsButtonRect(); |
||
73 | const detailsButtonTextSelection = selectDetailsButtonText(); |
||
74 | |||
75 | const isBackgroundActive = highlightBackground.style('opacity') === String(BACKGROUND_HIGHLIGHT_OPACITY); |
||
76 | |||
77 | const scale = ZoomScaleStorage.getScale(); |
||
78 | |||
79 | const { |
||
80 | buttonWidth, |
||
81 | buttonHeight, |
||
82 | buttonX, |
||
83 | buttonY, |
||
84 | buttonRadius, |
||
85 | buttonTextFontSize, |
||
86 | buttonTextPositionX, |
||
87 | buttonTextPositionY, |
||
88 | } = getButtonDimension(dimension, scale); |
||
89 | |||
90 | const elementsNextAttributes = [ |
||
91 | { |
||
92 | x: dimension.x, |
||
93 | y: dimension.y, |
||
94 | width: dimension.width, |
||
95 | height: dimension.height, |
||
96 | opacity: BACKGROUND_HIGHLIGHT_OPACITY, |
||
97 | }, |
||
98 | { |
||
99 | x: buttonX, |
||
100 | y: buttonY, |
||
101 | rx: buttonRadius, |
||
102 | ry: buttonRadius, |
||
103 | width: buttonWidth, |
||
104 | height: buttonHeight, |
||
105 | opacity: 1, |
||
106 | }, |
||
107 | { |
||
108 | fontSize: buttonTextFontSize, |
||
109 | x: buttonTextPositionX, |
||
110 | y: buttonTextPositionY, |
||
111 | opacity: 1, |
||
112 | }, |
||
113 | ]; |
||
114 | |||
115 | if (isBackgroundActive) { |
||
116 | selectAll([highlightBackground.node(), detailsButtonRectSelection.node(), detailsButtonTextSelection.node()]) |
||
117 | .data(elementsNextAttributes) |
||
118 | .transition() |
||
119 | .duration(TRANSITION_DURATION) |
||
120 | .attr('x', data => data.x) |
||
121 | .attr('y', data => data.y) |
||
122 | .attr('rx', data => data.rx || 0) |
||
123 | .attr('ry', data => data.ry || 0) |
||
124 | .attr('width', data => data.width || 0) |
||
125 | .attr('height', data => data.height || 0) |
||
126 | .attr('font-size', data => data.fontSize || 0); |
||
127 | } else { |
||
128 | selectDetailsButtonWrapper().raise(); |
||
129 | selectAll([highlightBackground.node(), detailsButtonRectSelection.node(), detailsButtonTextSelection.node()]) |
||
130 | .data(elementsNextAttributes) |
||
131 | .attr('x', data => data.x) |
||
132 | .attr('y', data => data.y) |
||
133 | .attr('rx', data => data.rx || 0) |
||
134 | .attr('ry', data => data.ry || 0) |
||
135 | .attr('width', data => data.width || 0) |
||
136 | .attr('height', data => data.height || 0) |
||
137 | .attr('font-size', data => data.fontSize || 0) |
||
138 | .transition() |
||
139 | .duration(TRANSITION_DURATION) |
||
140 | .style('opacity', data => data.opacity); |
||
141 | } |
||
151 |