SwiftSunburstDiagram icon indicating copy to clipboard operation
SwiftSunburstDiagram copied to clipboard

Receive callback with Node on tap

Open mateuszjablonski opened this issue 5 years ago • 2 comments

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.

mateuszjablonski avatar Feb 08 '20 21:02 mateuszjablonski

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
  }

OpConTech avatar Jul 27 '21 16:07 OpConTech

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...")
        })

OpConTech avatar Jul 28 '21 17:07 OpConTech