Skip to content

Commit

Permalink
fix: Move Sunburst logic from recursion to stack based (#3206)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov authored Sep 18, 2024
1 parent 1e8c05a commit aab98e2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/pages/RepoPage/CoverageTab/OverviewTab/OverviewTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const FileExplorer = lazy(() => import('./subroute/FileExplorer'))
const CoverageChart = lazy(() => import('./subroute/CoverageChart'))
const Sunburst = lazy(() => import('./subroute/Sunburst'))

const MAX_FILE_COUNT = 200_000

const Loader = () => (
<div className="flex items-center justify-center py-16">
<Spinner />
Expand Down Expand Up @@ -50,9 +52,12 @@ function CoverageOverviewTab() {
branch: branch,
})

let displaySunburst = false
const fileCount = data?.branch?.head?.totals?.fileCount
if (typeof fileCount === 'number' && fileCount <= 200_000) {
const withinFileCount =
typeof fileCount === 'number' && fileCount <= MAX_FILE_COUNT

let displaySunburst = false
if (withinFileCount) {
displaySunburst = true
}

Expand Down
38 changes: 31 additions & 7 deletions src/ui/SunburstChart/SunburstChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,39 @@ function SunburstChart({
// Tracks previous location for rendering .. in the breadcrumb.
let previous

const selectorMutate = (node) => {
if (Array.isArray(node.children)) {
return {
...node,
value: selectorHandler.current(node),
children: node.children.map((child) => selectorMutate(child)),
// const selectorMutate = (node) => {
// if (Array.isArray(node.children)) {
// return {
// ...node,
// value: selectorHandler.current(node),
// children: node.children.map((child) => selectorMutate(child)),
// }
// }

// return { ...node, value: selectorHandler.current(node) }
// }

const selectorMutate = (rootNode) => {
const stack = [rootNode]
const result = { ...rootNode, value: selectorHandler.current(rootNode) }
const nodeMap = new Map()
nodeMap.set(rootNode, result)

while (stack.length > 0) {
const node = stack.pop()
const currentNode = nodeMap.get(node)

if (Array.isArray(node.children)) {
currentNode.children = node.children.map((child) => {
const newChild = { ...child, value: selectorHandler.current(child) }
nodeMap.set(child, newChild)
stack.push(child)
return newChild
})
}
}
return { ...node, value: selectorHandler.current(node) }

return result
}

// Process data for use in D3
Expand Down

0 comments on commit aab98e2

Please sign in to comment.