Swift 旭日图

Swift Version License Swift Package Manager compatible CocoaPods Compatible

旭日图是一个使用 SwiftUI 编写的库,可以轻松地根据对象树渲染图表。类似于环形图、旭日图、多级饼图。

diagram with icons only diagram with icons and text

此库需要 Swift 5.1 和 Xcode 11,公共 API 中的某些功能尚未实现(见下文)。

要求

安装

Swift Package Manager

Swift Package Manager 是一个用于自动分发 Swift 代码的工具,并且已集成到 swift 编译器中。 现在它已集成到 Xcode 11 中。

设置好 Swift 包后,将 SunburstDiagram 添加为依赖项就像将其添加到 Package.swiftdependencies 值一样简单。

dependencies: [
    .package(url: "https://github.com/lludo/SwiftSunburstDiagram.git")
]

Cocoapods

CocoaPods 是 Cocoa 项目的依赖管理工具。 有关用法和安装说明,请访问他们的网站。 要使用 CocoaPods 将 Alamofire 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

pod 'SunburstDiagram', '~> 1.1.0'

手动

如果您不想使用 Swift Package Manager,您可以手动将 SunburstDiagram 集成到您的项目中。

功能

用法

// Create your configuration model
let configuration = SunburstConfiguration(nodes: [
    Node(name: "Walking", value: 10.0, backgroundColor: .systemBlue),
    Node(name: "Restaurant", value: 30.0, backgroundColor: .systemRed, children: [
        Node(name: "Dessert", image: UIImage(named: "croissant"), value: 6.0),
        Node(name: "Dinner", image: UIImage(named: "poultry"), value: 10.0),
    ]),
    Node(name: "Transport", value: 10.0, backgroundColor: .systemPurple),
    Node(name: "Home", value: 50.0, backgroundColor: .systemTeal),
])

// Get the view controller for the SunburstView
let viewController = UIHostingController(rootView: SunburstView(configuration: configuration))

交流

如果您发现错误或想讨论新的功能,请随时给我留言。 如果您想要贡献,欢迎所有 pull request。 谢谢!

演示应用

此仓库中的演示应用也是用 SwiftUI 编写的,可以以图形化和反应式的方式体验此库的 API。 它也可以在 App Store 上免费下载

iOS demo app first screenshot iOS demo app second screenshot iOS demo app third screenshot

macOS demo app screenshot

待办事项

灵感来源

该项目的灵感来自 DaisyDisk UI 和 Apple SwiftUI 使用 SwiftUI 构建自定义视图 WWDC2019 会议。