SwiftSunburstDiagram
SwiftSunburstDiagram copied to clipboard
Receive callback with Node on tap
I am using the chart as a part of user interface, enabling them to select the option, that interests them most. Is it possible to receive a callback with a node, after user taps on it? Also it would be nice to be able to disable focused state for nodes, so that you need to tap only once to go inside/outside note.
In ArcView.swift there is func isNodeSelected() -> Bool {}
So you could customize that function. For example:
func isNodeSelected() -> Bool {
print("Node is selected....", configuration.selectedNode?.name ?? "node name not found")
return configuration.allowsSelection && arc.node == configuration.selectedNode
}
I just noticed that in DataModel.swift @lludo made the entire configuration observable and published all the vars: public class SunburstConfiguration: ObservableObject
So all you have to do is use .onRecieve for your SwiftUI view to monitor for any tap on an arc:
VStack {
SunburstView(configuration: configuration)
}.onReceive(configuration.$selectedNode, perform: { _ in
Print(configuration.selectedNode?.name, " is the selected node...")
})