Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Render only two levels of the sunburst #3783

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
create a pathIndex map
  • Loading branch information
nicholas-codecov committed Mar 3, 2025
commit c317454ad3ff542214d14e1e0ad2f1c00beb8945
28 changes: 26 additions & 2 deletions src/ui/SunburstChart/SunburstChart.jsx
Original file line number Diff line number Diff line change
@@ -26,12 +26,17 @@ function SunburstChart({
const clickHandler = useRef(onClick)
const hoverHandler = useRef(onHover)

/*
* I don't think the depthIndex will work, because we're not trying to render a given depth, we're trying to render a folder and all of its children.
* So we need to render all children of a given folder at once.
*/

// this state stores the root node of the sunburst chart
const [{ root }] = useState(() =>
const [{ root, pathIndex }] = useState(() =>
Sentry.startSpan({ name: 'SunburstChart.createRoot' }, () => {
// go through the data and add `value` to each node
const stack = [data]
const depthIndex = new Map()
const pathIndex = new Map()

// create a new root node with the value of the root node
const result = { ...data, value: selectorHandler.current(data) }
@@ -60,9 +65,28 @@ function SunburstChart({
// partition the data and add the `current` property to each node
return { root, depthIndex }
}

// if the node has children, process them
if (Array.isArray(node.children)) {
node.children.forEach((child) => stack.push(child))
}

const root = partitionFn(result).each((d) => (d.current = d))

root.each((d) => {
// only add to pathIndex if the node has children as it represents a folder
if (d?.children) {
pathIndex.set(d.data.fullPath, d)
}
})

// partition the data and add the `current` property to each node
return { root, pathIndex }
})
)

const [selectedNode, setSelectedNode] = useState(root)

// In this case D3 is handling rendering not React, so useLayoutEffect is used to handle rendering
// and changes outside of the React lifecycle.
useLayoutEffect(() => {