From 9006c3fb21722845cb902642956162f32b7432e8 Mon Sep 17 00:00:00 2001 From: Rich Fellure Date: Thu, 1 Aug 2024 12:54:01 -0600 Subject: [PATCH] Remove breaking change, try different approach. --- .../Shared/Models/Protocols/SharedProtocols.swift | 11 ----------- .../Models/Protocols/SharedProtocolsExtensions.swift | 7 +++++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Sources/SwiftUICharts/Shared/Models/Protocols/SharedProtocols.swift b/Sources/SwiftUICharts/Shared/Models/Protocols/SharedProtocols.swift index 0d17fd05..51ff211c 100644 --- a/Sources/SwiftUICharts/Shared/Models/Protocols/SharedProtocols.swift +++ b/Sources/SwiftUICharts/Shared/Models/Protocols/SharedProtocols.swift @@ -146,17 +146,6 @@ public protocol CTSingleDataSetProtocol: CTDataSetProtocol { } -extension CTSingleDataSetProtocol where Self.DataPoint: CTStandardDataPointProtocol { - - /// Get average for the DataSet - func average() -> Double { - dataPoints - .map(\.value) - .reduce(0, +) - .divide(by: Double(dataPoints.count)) - } -} - /** Protocol for data sets that require a multiple sets of data . */ diff --git a/Sources/SwiftUICharts/Shared/Models/Protocols/SharedProtocolsExtensions.swift b/Sources/SwiftUICharts/Shared/Models/Protocols/SharedProtocolsExtensions.swift index 783f1cf0..37eb62e4 100644 --- a/Sources/SwiftUICharts/Shared/Models/Protocols/SharedProtocolsExtensions.swift +++ b/Sources/SwiftUICharts/Shared/Models/Protocols/SharedProtocolsExtensions.swift @@ -221,8 +221,11 @@ extension CTMultiDataSetProtocol where Self.DataSet.DataPoint: CTStandardDataPoi public func average() -> Double { self.dataSets - .compactMap { - $0.average() + .compactMap { dataSet -> Double in + dataSet.dataPoints + .map(\.value) + .reduce(0, +) + .divide(by: Double(dataSet.dataPoints.count)) } .reduce(0, +) .divide(by: Double(self.dataSets.count))