P粉8113491122023-09-01 18:38:29
In this case, the click event ultimately triggers a behavior similar to a "switch".
By default, we see the root node and all child nodes of the hierarchy.
Clicking on a ring with at least one child node (e.g. 'A') will filter out its parent node ('Root') and sibling node ('B') and visually treat the ring as a new For the root node, we only see the hierarchy under the ring (that is, the ring filtering switch is turned on, and the attribute nextLevel
in the event data is set to 'A' accordingly, such as "A is the new root node") .
Clicking on the ring again - now the innermost ring - turns off the filter and the parent and sibling nodes reappear, nextLevel
is set to 'Root'.
Clicking on a ring with no child nodes (e.g. 'a' or 'B') has no effect, so nextLevel
is undefined in this case.
In fact, the attribute nextLevel
reflects the change of state.
Now to better understand what's going on in the click handler, you might want to check the currentpath
(or for consistency, a slightly tweaked version) as well as the nextLevel
Existence/value:
Plotly.newPlot('graph', [{ type: 'sunburst', parents: ['', 'Root', 'Root', 'A'], labels: ['Root', 'A', 'B', 'a'] }]).then(gd => { gd.on('plotly_sunburstclick', data => { const pt = data.points[0] const path = ((pt.currentPath ?? '/') + pt.label).replace('Root', '') console.log('path:', path) // 点击元素的路径 console.log('nextLevel:', data.nextLevel) // 如果有的话,新根节点的标签 }) })