fortrangoingonforty/sniffly / 99db101

Browse files

fix stragglers (last item) to overlap in some dirs

Authored by espadonne
SHA
99db10172be79017ef45652095eb522542e0c38b
Parents
13ba3ed
Tree
96ece75

1 changed file

StatusFile+-
M src/layout/squarified.f90 26 16
src/layout/squarified.f90modified
@@ -165,7 +165,7 @@ contains
165165
       pivot_area%x = bounds%x
166166
       pivot_area%y = bounds%y
167167
       pivot_area%width = bounds%width
168
-      pivot_area%height = int((real(pivot_size, real64) / real(total_size, real64)) * real(bounds%height, real64))
168
+      pivot_area%height = nint((real(pivot_size, real64) / real(total_size, real64)) * real(bounds%height, real64))
169169
       pivot_area%height = max(30, min(pivot_area%height, bounds%height - 30))
170170
 
171171
       remaining_area%x = bounds%x
@@ -175,7 +175,7 @@ contains
175175
 
176176
     else if (spiral_direction == 1) then
177177
       ! RIGHT: Pivot on right, remaining on left
178
-      pivot_area%width = int((real(pivot_size, real64) / real(total_size, real64)) * real(bounds%width, real64))
178
+      pivot_area%width = nint((real(pivot_size, real64) / real(total_size, real64)) * real(bounds%width, real64))
179179
       pivot_area%width = max(30, min(pivot_area%width, bounds%width - 30))
180180
       pivot_area%x = bounds%x + bounds%width - pivot_area%width
181181
       pivot_area%y = bounds%y
@@ -188,7 +188,7 @@ contains
188188
 
189189
     else if (spiral_direction == 2) then
190190
       ! BOTTOM: Pivot at bottom, remaining above
191
-      pivot_area%height = int((real(pivot_size, real64) / real(total_size, real64)) * real(bounds%height, real64))
191
+      pivot_area%height = nint((real(pivot_size, real64) / real(total_size, real64)) * real(bounds%height, real64))
192192
       pivot_area%height = max(30, min(pivot_area%height, bounds%height - 30))
193193
       pivot_area%x = bounds%x
194194
       pivot_area%y = bounds%y + bounds%height - pivot_area%height
@@ -203,7 +203,7 @@ contains
203203
       ! LEFT: Pivot on left, remaining on right
204204
       pivot_area%x = bounds%x
205205
       pivot_area%y = bounds%y
206
-      pivot_area%width = int((real(pivot_size, real64) / real(total_size, real64)) * real(bounds%width, real64))
206
+      pivot_area%width = nint((real(pivot_size, real64) / real(total_size, real64)) * real(bounds%width, real64))
207207
       pivot_area%width = max(30, min(pivot_area%width, bounds%width - 30))
208208
       pivot_area%height = bounds%height
209209
 
@@ -277,21 +277,26 @@ contains
277277
       ! Calculate dynamic minimum based on available space
278278
       ! If we have N items and W width, ensure each item gets at most W/N
279279
       available_space = bounds%width
280
-      dynamic_min = max(2, available_space / actual_num_nodes)  ! At least 2 pixels
281
-      dynamic_min = min(dynamic_min, 10)  ! But prefer 10 if space allows
280
+      dynamic_min = max(1, available_space / actual_num_nodes)  ! At least 1 pixel per item
282281
 
283282
       ! Stack left-to-right
284283
       offset = bounds%x
285284
       do i = 1, actual_num_nodes
286285
         if (i < actual_num_nodes) then
287
-          item_size = int((real(nodes(i)%size, real64) / real(actual_total_size, real64)) * real(bounds%width, real64))
286
+          ! Calculate proportional size
287
+          item_size = nint((real(nodes(i)%size, real64) / real(actual_total_size, real64)) * real(bounds%width, real64))
288
+          ! Apply minimum, but check we won't overflow
288289
           item_size = max(dynamic_min, item_size)
290
+          ! Ensure we don't exceed remaining space
291
+          item_size = min(item_size, (bounds%x + bounds%width) - offset - (actual_num_nodes - i))
289292
         else
290
-          ! Last item gets remaining space (prevents overflow)
291
-          item_size = bounds%x + bounds%width - offset
292
-          item_size = max(1, item_size)  ! Ensure at least 1 pixel
293
+          ! Last item gets ALL remaining space (prevents gaps/overlaps)
294
+          item_size = (bounds%x + bounds%width) - offset
293295
         end if
294296
 
297
+        ! Ensure at least 1 pixel
298
+        item_size = max(1, item_size)
299
+
295300
         nodes(i)%bounds%x = offset
296301
         nodes(i)%bounds%y = bounds%y
297302
         nodes(i)%bounds%width = item_size
@@ -302,21 +307,26 @@ contains
302307
     else
303308
       ! Calculate dynamic minimum based on available space
304309
       available_space = bounds%height
305
-      dynamic_min = max(1, available_space / actual_num_nodes)  ! At least 1 pixel
306
-      dynamic_min = min(dynamic_min, 3)  ! But prefer 3 if space allows
310
+      dynamic_min = max(1, available_space / actual_num_nodes)  ! At least 1 pixel per item
307311
 
308312
       ! Stack top-to-bottom
309313
       offset = bounds%y
310314
       do i = 1, actual_num_nodes
311315
         if (i < actual_num_nodes) then
312
-          item_size = int((real(nodes(i)%size, real64) / real(actual_total_size, real64)) * real(bounds%height, real64))
316
+          ! Calculate proportional size
317
+          item_size = nint((real(nodes(i)%size, real64) / real(actual_total_size, real64)) * real(bounds%height, real64))
318
+          ! Apply minimum, but check we won't overflow
313319
           item_size = max(dynamic_min, item_size)
320
+          ! Ensure we don't exceed remaining space
321
+          item_size = min(item_size, (bounds%y + bounds%height) - offset - (actual_num_nodes - i))
314322
         else
315
-          ! Last item gets remaining space (prevents overflow)
316
-          item_size = bounds%y + bounds%height - offset
317
-          item_size = max(1, item_size)  ! Ensure at least 1 pixel
323
+          ! Last item gets ALL remaining space (prevents gaps/overlaps)
324
+          item_size = (bounds%y + bounds%height) - offset
318325
         end if
319326
 
327
+        ! Ensure at least 1 pixel
328
+        item_size = max(1, item_size)
329
+
320330
         nodes(i)%bounds%x = bounds%x
321331
         nodes(i)%bounds%y = offset
322332
         nodes(i)%bounds%width = bounds%width