Is there any way to create something like this with SwiftUI (w/o using D3.js) –
// test data
@State private var data: [DataItem] = [
DataItem(title: "chrome", weight: 180, color: .green),
DataItem(title: "firefox", weight: 60, color: .red),
DataItem(title: "safari", weight: 90, color: .blue),
DataItem(title: "edge", weight: 30, color: .orange),
DataItem(title: "ie", weight: 50, color: .yellow),
DataItem(title: "opera", weight: 25, color: .purple)
]
Here in the test data, "weight" denotes which item should be larger/smaller.
One way I can think of is to have X Circles in a given view with size relative to the parent. But that in itself creates issues for positioning and making sure that circles are not touching or overlapping each other.
Not sure about the usage of SpriteKit here? Can that be used or can this be achieved using SwiftUI components only?
2
Answers
This was fun, going back to school math 🙂
Here is my result. The smaller circles all align around the first large one, I didn’t solve the positioning of "opera" in your image, it seems to be accidentally.
Here is the code:
It’s a starting point, no safety checks
ok you motivated me 🙂 here comes the extended version
the frame ist just to show adapt to parent size:
you call it like this:
And here is the code: