Skip to content

Commit 8594804

Browse files
authored
Fix sunburst: aggregate sub-threshold files instead of filtering (#64)
* Fix size representation by aggregating small files into 'Other files' node * Remove package-lock.json from tracking (already in .gitignore) Co-authored-by: zz85 <314997+zz85@users.noreply.github.com>
1 parent ce70d26 commit 8594804

3 files changed

Lines changed: 47 additions & 297 deletions

File tree

app/js/data.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,50 @@ function setNodeFilter(data) {
5555
}
5656
if (!d._children) return null
5757

58-
const children = d._children.filter(c => (c.sum / data.sum) * 100 > HIDE_THRESHOLD)
59-
return children
58+
// Separate children into visible and hidden based on threshold
59+
// NOTE: Threshold is calculated relative to the parent node (d.sum), not the root.
60+
// This ensures correct filtering behavior when zoomed into subdirectories.
61+
const visibleChildren = []
62+
const hiddenChildren = []
63+
64+
d._children.forEach(c => {
65+
if ((c.sum / d.sum) * 100 > HIDE_THRESHOLD) {
66+
visibleChildren.push(c)
67+
} else {
68+
hiddenChildren.push(c)
69+
}
70+
})
71+
72+
// If there are hidden children, create an aggregate "Other files" node
73+
// This ensures the visual representation accurately reflects the actual space usage
74+
if (hiddenChildren.length > 0) {
75+
// Calculate total size and count of hidden items
76+
let otherSum = 0
77+
let otherCount = 0
78+
hiddenChildren.forEach(c => {
79+
otherSum += c.sum
80+
otherCount += c.count
81+
})
82+
83+
// Create synthetic "Other files" node
84+
const otherNode = {
85+
name: `Other files (${hiddenChildren.length} items)`,
86+
sum: otherSum,
87+
count: otherCount,
88+
size: otherSum,
89+
value: otherSum,
90+
depth: d.depth + 1,
91+
parent: d,
92+
_children: null, // Other files node has no children
93+
children: null,
94+
_isOtherFiles: true, // Mark this as a synthetic node
95+
color: d3.lab(85, 0, 0) // Light gray color to distinguish it
96+
}
97+
98+
visibleChildren.push(otherNode)
99+
}
100+
101+
return visibleChildren
60102
// return depth < LEVELS ? d._children : null;
61103
})
62104
}

app/js/sunburst.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ function SunBurst() {
206206
}
207207

208208
function zoomIn(p) {
209+
// Prevent zooming into "Other files" synthetic nodes
210+
if (p._isOtherFiles) return
211+
209212
if (p.depth > 1) {
210213
p = p.parent
211214
}

app/package-lock.json

Lines changed: 0 additions & 295 deletions
This file was deleted.

0 commit comments

Comments
 (0)