Skip to content

Commit

Permalink
Progress on displaying StackBarCharts
Browse files Browse the repository at this point in the history
  • Loading branch information
Black-Fox-2022 committed May 27, 2024
1 parent a380b59 commit 8889a39
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 11 deletions.
48 changes: 38 additions & 10 deletions Cluster/Chart/BarChart/BarCharTopN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ struct BarChartTopN: View {
let topNQueryResult: TopNQueryResult
let query: CustomQuery

var colorsForAggregators: [String: Color] {
let aggregatorNames = query.aggregations?.map { agg in
getAggregatorName(aggregator: agg)
} ?? []

let colors = Dictionary(uniqueKeysWithValues: zip(aggregatorNames, Color.chartColors))
return colors
}

var body: some View {

Chart {
Expand All @@ -21,18 +30,44 @@ struct BarChartTopN: View {
ForEach(row.result, id: \.self) { (rowResult: AdaptableQueryResultItem) in

ForEach(query.aggregations ?? [], id: \.self) { (aggregator: Aggregator) in
if let metric = getMetric(rowResult: rowResult) {
getBarMark(timeStamp: row.timestamp, name: getAggregatorName(aggregator: aggregator), metric: metric)
if let metricValue = getMetricValue(rowResult: rowResult), let metric = query.metric {
getBarMark(
timeStamp: row.timestamp,
name: getAggregatorName(aggregator: aggregator),
metricValue: metricValue,
metricName: rowResult.dimensions[getDimensionName(from: query.dimension) ?? "Not found"] ?? "Not Found"
)
}
}

}

}
}
// .chartForegroundStyleScale()

}

func getBarMark(timeStamp: Date, name: String, metricValue: Double, metricName: String) -> some ChartContent {
print("MetricName: \(metricName)")
print("Dimension: \(getDimensionName(from: query.dimension) ?? "Not found")")
return BarMark(
x: .value("Date", timeStamp),
y: .value(name, metricValue)
)
.foregroundStyle(by: .value(getDimensionName(from: query.dimension) ?? "Not found", metricName))
}

func getDimensionName(from: DimensionSpec?) -> String? {
switch from {
case .default(let defaultDimensionSpec):
defaultDimensionSpec.outputName
case .extraction(let extractionDimensionSpec):
extractionDimensionSpec.outputName
case .none:
nil
}
}
// swiftlint:disable cyclomatic_complexity
// swiftlint:disable function_body_length
func getAggregatorName(aggregator: Aggregator) -> String {
Expand Down Expand Up @@ -94,7 +129,7 @@ struct BarChartTopN: View {
// swiftlint:enable cyclomatic_complexity
// swiftlint:enable function_body_length

func getMetric(rowResult: AdaptableQueryResultItem) -> Double? {
func getMetricValue(rowResult: AdaptableQueryResultItem) -> Double? {
guard let metric = query.metric, let metricName = getMetricName(metric: metric) else {
return nil
}
Expand All @@ -113,13 +148,6 @@ struct BarChartTopN: View {
}
}

func getBarMark(timeStamp: Date, name: String, metric: Double) -> BarMark {
BarMark(
x: .value("Date", timeStamp),
y: .value(name, metric)
)
}

}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.141",
"green" : "0.749",
"red" : "0.984"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.600",
"green" : "0.827",
"red" : "0.204"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.933",
"green" : "0.827",
"red" : "0.133"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.976",
"green" : "0.475",
"red" : "0.910"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.980",
"green" : "0.647",
"red" : "0.376"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.208",
"green" : "0.902",
"red" : "0.639"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.522",
"green" : "0.443",
"red" : "0.984"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.973",
"green" : "0.741",
"red" : "0.220"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
28 changes: 27 additions & 1 deletion UIComponents/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ extension Color {
static let separatorColor = Color(UIColor.separator)
#endif

static let telemetryOrange = Color("Torange")
static let cardBackground = Color("CardBackgroundColor")
static let customTextColor = Color("CustomTextColor")

Expand All @@ -27,4 +26,31 @@ extension Color {
static let Zinc400 = Color("Zinc400")
static let Zinc600 = Color("Zinc600")

static let telemetryOrange = Color("Torange")
static let telemetryAmber = Color("Tamber")
static let telemetryLime = Color("Tlime")
static let telemetryEmerald = Color("Temerald")
static let telemetryCyan = Color("Tcyan")
static let telemetrySky = Color("Tsky")
static let telemetryIndigo = Color("Tindigo")
static let telemetryFuchsia = Color("Tfuchsia")
static let telemetryRose = Color("Trose")

static var chartColors: [Color] {
[
telemetryOrange,
telemetryAmber,
telemetryLime,
telemetryEmerald,
telemetryCyan,
telemetrySky,
telemetryIndigo,
telemetryFuchsia,
telemetryRose
]
}




}

0 comments on commit 8889a39

Please sign in to comment.