Last active
January 9, 2022 20:13
-
-
Save DavidPiper94/5077ec335bc6512e0cb70a103ef21576 to your computer and use it in GitHub Desktop.
Example code for article about Audio Graphs - Using a categorical axis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 | |
enum Category: String { | |
case UIKit, SwiftUI | |
// 2 | |
static var order = [Category.UIKit.rawValue, Category.SwiftUI.rawValue] | |
} | |
// 3 | |
private var categoricalXAxis: AXCategoricalDataAxisDescriptor { | |
AXCategoricalDataAxisDescriptor( | |
title: "UI Frameworks", | |
categoryOrder: Category.order | |
) | |
} | |
private var yAxis: AXNumericDataAxisDescriptor { | |
AXNumericDataAxisDescriptor( | |
title: "Number of years since introduction.", | |
range: (0...12), | |
gridlinePositions: [], | |
valueDescriptionProvider: { (value: Double) -> String in | |
"\(value)" | |
} | |
) | |
} | |
private var series: [AXDataSeriesDescriptor] { | |
// 4 | |
let values: [(Category, Double)] = [ | |
(.UIKit, 12.0), | |
(.SwiftUI, 3.0), | |
] | |
// 5 | |
let dataPoints = values.map { (category, value) in | |
AXDataPoint(x: category.rawValue, y: value) | |
} | |
return [ | |
AXDataSeriesDescriptor( | |
name: "Age of UI frameworks", | |
isContinuous: true, | |
dataPoints: dataPoints | |
) | |
] | |
} | |
var accessibilityChartDescriptor: AXChartDescriptor? { | |
get { | |
AXChartDescriptor( | |
title: "Age of UI frameworks", | |
summary: "This graph compares the age of UIKit and SwiftUI", | |
xAxis: categoricalXAxis, | |
yAxis: yAxis, | |
series: series | |
) | |
} | |
set { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment