@@ -26,7 +26,7 @@ class SvgTreemapExporter implements DataExporterInterface
2626 */
2727 public function export (array $ classes , string $ filename ): void
2828 {
29- $ svg = $ this ->generateSvgTreemap ($ classes );
29+ $ svg = $ this ->generateSvgTreemap (classes: $ classes );
3030
3131 if (file_put_contents ($ filename , $ svg ) === false ) {
3232 throw new CognitiveAnalysisException ("Unable to write to file: $ filename " );
@@ -47,19 +47,19 @@ private function generateSvgTreemap(array $classes): string
4747
4848 $ rects = [];
4949 $ this ->layoutTreemap (
50- $ items ,
51- 0 ,
52- 0 ,
53- self ::SVG_WIDTH ,
54- self ::SVG_HEIGHT ,
55- true , // $vertical
56- $ rects, // $rects
57- self ::PADDING // $padding
50+ items: $ items ,
51+ x: 0 ,
52+ y: 0 ,
53+ width: self ::SVG_WIDTH ,
54+ height: self ::SVG_HEIGHT ,
55+ vertical: true ,
56+ rects: $ rects,
57+ padding: self ::PADDING
5858 );
5959
60- $ svgRects = $ this ->renderSvgRects ($ rects , $ minScore , $ maxScore );
60+ $ svgRects = $ this ->renderSvgRects (rects: $ rects , minScore: $ minScore , maxScore: $ maxScore );
6161
62- return $ this ->wrapSvg ($ svgRects );
62+ return $ this ->wrapSvg (rectsSvg: $ svgRects );
6363 }
6464
6565 /**
@@ -122,8 +122,8 @@ private function renderSvgRects(array $rects, float $minScore, float $maxScore):
122122 {
123123 $ svgRects = [];
124124 foreach ($ rects as $ rect ) {
125- $ normalizedScore = $ this ->normalizeScore ($ rect ['score ' ], $ minScore , $ maxScore );
126- $ svgRects [] = $ this ->renderSvgRect ($ rect , $ normalizedScore );
125+ $ normalizedScore = $ this ->normalizeScore (score: $ rect ['score ' ], minScore: $ minScore , maxScore: $ maxScore );
126+ $ svgRects [] = $ this ->renderSvgRect (rect: $ rect , normalizedScore: $ normalizedScore );
127127 }
128128
129129 return implode ("\n" , $ svgRects );
@@ -142,7 +142,7 @@ private function renderSvgRect(array $rect, float $normalizedScore): string
142142 $ y = $ rect ['y ' ] + self ::PADDING ;
143143 $ width = max (0 , $ rect ['width ' ] - self ::PADDING * 2 );
144144 $ height = max (0 , $ rect ['height ' ] - self ::PADDING * 2 );
145- $ color = $ this ->scoreToColor ($ normalizedScore );
145+ $ color = $ this ->scoreToColor (score: $ normalizedScore );
146146 $ class = htmlspecialchars ($ rect ['class ' ]);
147147 $ churn = $ rect ['churn ' ];
148148 $ score = $ rect ['score ' ];
@@ -254,7 +254,10 @@ private function layoutTreemap(
254254 }
255255
256256 $ sum = array_sum (array_column ($ items , 'churn ' ));
257- $ splitIdx = $ this ->findSplitIndex ($ items , $ sum );
257+ $ splitIdx = $ this ->findSplitIndex (
258+ items: $ items ,
259+ sum: $ sum
260+ );
258261
259262 $ first = array_slice ($ items , 0 , $ splitIdx );
260263 $ second = array_slice ($ items , $ splitIdx );
@@ -264,15 +267,51 @@ private function layoutTreemap(
264267 if ($ vertical ) {
265268 $ w1 = $ width * ($ firstSum / $ sum );
266269 $ w2 = $ width - $ w1 ;
267- $ this ->layoutTreemap ($ first , $ x , $ y , $ w1 , $ height , false , $ rects , $ padding );
268- $ this ->layoutTreemap ($ second , $ x + $ w1 , $ y , $ w2 , $ height , false , $ rects , $ padding );
270+ $ this ->layoutTreemap (
271+ items: $ first ,
272+ x: $ x ,
273+ y: $ y ,
274+ width: $ w1 ,
275+ height: $ height ,
276+ vertical: false ,
277+ rects: $ rects ,
278+ padding: $ padding
279+ );
280+ $ this ->layoutTreemap (
281+ items: $ second ,
282+ x: $ x + $ w1 ,
283+ y: $ y ,
284+ width: $ w2 ,
285+ height: $ height ,
286+ vertical: false ,
287+ rects: $ rects ,
288+ padding: $ padding
289+ );
269290 return ;
270291 }
271292
272293 $ h1 = $ height * ($ firstSum / $ sum );
273294 $ h2 = $ height - $ h1 ;
274- $ this ->layoutTreemap ($ first , $ x , $ y , $ width , $ h1 , true , $ rects , $ padding );
275- $ this ->layoutTreemap ($ second , $ x , $ y + $ h1 , $ width , $ h2 , true , $ rects , $ padding );
295+ $ this ->layoutTreemap (
296+ items: $ first ,
297+ x: $ x ,
298+ y: $ y ,
299+ width: $ width ,
300+ height: $ h1 ,
301+ vertical: true ,
302+ rects: $ rects ,
303+ padding: $ padding
304+ );
305+ $ this ->layoutTreemap (
306+ items: $ second ,
307+ x: $ x ,
308+ y: $ y + $ h1 ,
309+ width: $ width ,
310+ height: $ h2 ,
311+ vertical: true ,
312+ rects: $ rects ,
313+ padding: $ padding
314+ );
276315 }
277316
278317 /**
0 commit comments