diff --git a/Sources/SwiftUICharts/Shared/Extras/Extensions.swift b/Sources/SwiftUICharts/Shared/Extras/Extensions.swift index eca00d1a..3bb8b651 100644 --- a/Sources/SwiftUICharts/Shared/Extras/Extensions.swift +++ b/Sources/SwiftUICharts/Shared/Extras/Extensions.swift @@ -35,20 +35,6 @@ extension View { } extension View { -<<<<<<< HEAD - @ViewBuilder - func `ifElseElseIf`(_ condition: Bool, - _ secondCondition: Bool, - if ifTransform: (Self) -> TrueContent, - elseIf elseIfTransform: (Self) -> MidContent, - else elseTransform: (Self) -> FalseContent - ) -> some View { - - if condition { - ifTransform(self) - } else if secondCondition { - elseIfTransform(self) -======= /** View modifier to conditionally add a view modifier else add a different one. @@ -60,7 +46,6 @@ extension View { ) -> some View { if condition { ifTransform(self) ->>>>>>> version-2 } else { elseTransform(self) } @@ -83,24 +68,18 @@ extension View { } } -<<<<<<< HEAD - func animateOnDisAppear(using animation: Animation = Animation.easeInOut(duration: 1), _ action: @escaping () -> Void) -> some View { -======= /** Reverse animation when the view disappears. [HWS](https://www.hackingwithswift.com/quick-start/swiftui/how-to-start-an-animation-immediately-after-a-view-appears) */ func animateOnDisappear(using animation: Animation = Animation.easeInOut(duration: 1), _ action: @escaping () -> Void) -> some View { ->>>>>>> version-2 return onDisappear { withAnimation(animation) { action() } } } -<<<<<<< HEAD -======= } extension Color { @@ -116,5 +95,4 @@ extension Color { return Color(.windowBackgroundColor) #endif } ->>>>>>> version-2 } diff --git a/Sources/SwiftUICharts/Shared/Models/ChartMetadata.swift b/Sources/SwiftUICharts/Shared/Models/ChartMetadata.swift index ee671b3f..0a1949cd 100644 --- a/Sources/SwiftUICharts/Shared/Models/ChartMetadata.swift +++ b/Sources/SwiftUICharts/Shared/Models/ChartMetadata.swift @@ -13,14 +13,6 @@ import SwiftUI Contains the Title, Subtitle and colour information for them. */ public struct ChartMetadata { -<<<<<<< HEAD - /// The charts Title - public var title : String? - /// The charts subtitle - public var subtitle : String? - /// The title for the legend - public var lineLegend : String? -======= /// The charts title public var title : String /// The charts subtitle @@ -29,7 +21,6 @@ public struct ChartMetadata { public var titleColour : Color /// Color of the subtitle public var subtitleColour: Color ->>>>>>> version-2 /// Model to hold the metadata for the chart. /// - Parameters: diff --git a/Sources/SwiftUICharts/Shared/ViewModifiers/HeaderBox.swift b/Sources/SwiftUICharts/Shared/ViewModifiers/HeaderBox.swift index 27ab78c6..1b8fc1eb 100644 --- a/Sources/SwiftUICharts/Shared/ViewModifiers/HeaderBox.swift +++ b/Sources/SwiftUICharts/Shared/ViewModifiers/HeaderBox.swift @@ -32,35 +32,6 @@ internal struct HeaderBox: ViewModifier where T: CTChartData { var touchOverlay: some View { VStack(alignment: .trailing) { -<<<<<<< HEAD - if chartData.viewData.isTouchCurrent, - let value = chartData.viewData.touchOverlayInfo?.value { - - - switch chartData.viewData.units { - case .none: - Text("\(value, specifier: chartData.viewData.touchSpecifier)") - .font(.title3) - case .prefix(of: let units): - Text("\(units) \(value, specifier: chartData.viewData.touchSpecifier)") - .font(.title3) - case .suffix(of: let units): - Text("\(value, specifier: chartData.viewData.touchSpecifier) \(units)") - .font(.title3) - } - - - - } else { - Text("") - .font(.title3) - } - if chartData.viewData.isTouchCurrent, - let label = chartData.viewData.touchOverlayInfo?.pointDescription { - Text("\(label)") - .font(.subheadline) - } else { -======= if chartData.infoView.isTouchCurrent { ForEach(chartData.infoView.touchOverlayInfo, id: \.id) { point in @@ -76,7 +47,6 @@ internal struct HeaderBox: ViewModifier where T: CTChartData { } else { Text("") .font(.title3) ->>>>>>> version-2 Text("") .font(.subheadline) } diff --git a/Sources/SwiftUICharts/Shared/ViewModifiers/TouchOverlay.swift b/Sources/SwiftUICharts/Shared/ViewModifiers/TouchOverlay.swift index 7250fc7a..c4f5f5e4 100644 --- a/Sources/SwiftUICharts/Shared/ViewModifiers/TouchOverlay.swift +++ b/Sources/SwiftUICharts/Shared/ViewModifiers/TouchOverlay.swift @@ -8,40 +8,6 @@ import SwiftUI #if !os(tvOS) -<<<<<<< HEAD -/// Detects input either from touch of pointer. Finds the nearest data point and displays the relevent information. -internal struct TouchOverlay: ViewModifier { - - @EnvironmentObject var chartData: ChartData - - /// Decimal precision for labels - private let specifier : String - private var units : Units - private let touchMarkerLineWidth : CGFloat = 1 // API? - - /// Boolean that indicates whether touch is currently being detected - @State private var isTouchCurrent : Bool = false - /// Current location of the touch input - @State private var touchLocation : CGPoint = CGPoint(x: 0, y: 0) - /// The data point closest to the touch input - @State private var selectedPoint : ChartDataPoint? - /// The location for the nearest data point to the touch input - @State private var pointLocation : CGPoint = CGPoint(x: 0, y: 0) - /// Frame information of the data point information box - @State private var boxFrame : CGRect = CGRect(x: 0, y: 0, width: 0, height: 50) - /// Placement of the data point information box - @State private var boxLocation : CGPoint = CGPoint(x: 0, y: 0) - /// Placement of place the markers intersecting the data points location - @State private var markerLocation : CGPoint = CGPoint(x: 0, y: 0) - - /// Detects input either from touch of pointer. Finds the nearest data point and displays the relevent information. - /// - Parameters: - /// - specifier: Decimal precision for labels - /// - infoBoxPlacement: Placement of the data point information panel when touch overlay modifier is applied. - internal init(specifier: String, units: Units) { - self.specifier = specifier - self.units = units -======= /** Finds the nearest data point and displays the relevent information. */ @@ -56,7 +22,6 @@ internal struct TouchOverlay: ViewModifier where T: CTChartData { self.chartData = chartData self.chartData.infoView.touchSpecifier = specifier self.chartData.infoView.touchUnit = unit ->>>>>>> version-2 } internal func body(content: Content) -> some View { @@ -71,167 +36,6 @@ internal struct TouchOverlay: ViewModifier where T: CTChartData { chartData.setTouchInteraction(touchLocation: value.location, chartSize: geo.frame(in: .local)) } -<<<<<<< HEAD - - if chartData.chartStyle.infoBoxPlacement == .floating { - setBoxLocationation(boxFrame: boxFrame, chartSize: geo) - markerLocation.x = setMarkerXLocation(chartSize: geo) - markerLocation.y = setMarkerYLocation(chartSize: geo) - } else if chartData.chartStyle.infoBoxPlacement == .header { - chartData.chartStyle.infoBoxPlacement = .header - chartData.viewData.isTouchCurrent = true - chartData.viewData.touchOverlayInfo = selectedPoint - chartData.viewData.units = units - } - } - .onEnded { _ in - isTouchCurrent = false - chartData.viewData.isTouchCurrent = false - } - ) - if isTouchCurrent { - TouchOverlayMarker(position: pointLocation) - .stroke(Color(.gray), lineWidth: touchMarkerLineWidth) - if chartData.chartStyle.infoBoxPlacement == .floating, let lineChartStyle = chartData.lineStyle { - TouchOverlayBox(selectedPoint: selectedPoint, specifier: specifier, units: units, boxFrame: $boxFrame, ignoreZero: lineChartStyle.ignoreZero) - .position(x: boxLocation.x, y: 0 + (boxFrame.height / 2)) - } - } - } - } - } else { content } - } - - // MARK: - Bar Chart - /// Gets the nearest data point to the touch location based on the X axis. - /// - Parameters: - /// - touchLocation: Current location of the touch - /// - chartSize: The size of the chart view as the parent view. - internal func getDataPointLineChart(touchLocation: CGPoint, chartSize: GeometryProxy) /* -> ChartDataPoint */ { - let dataPoints : [ChartDataPoint] = chartData.dataPoints - let xSection : CGFloat = chartSize.size.width / CGFloat(dataPoints.count - 1) - let index = Int((touchLocation.x + (xSection / 2)) / xSection) - if index >= 0 && index < dataPoints.count { - self.selectedPoint = dataPoints[index] - } - } - /// Gets the location of the data point in the view. For Line Chart - /// - Parameters: - /// - touchLocation: Current location of the touch - /// - chartSize: The size of the chart view as the parent view. - internal func getPointLocationLineChart(touchLocation: CGPoint, chartSize: GeometryProxy) /* -> CGPoint */ { - - let minValue : Double - let range : Double - - switch chartData.lineStyle.baseline { - case .minimumValue: - minValue = chartData.minValue() - range = chartData.range() - case .minimumWithMaximum(of: let value): - minValue = min(chartData.minValue(), value) - range = chartData.maxValue() - min(chartData.minValue(), value) - case .zero: - minValue = 0 - range = chartData.maxValue() - } - - let dataPointCount : Int = chartData.dataPoints.count - let xSection : CGFloat = chartSize.size.width / CGFloat(dataPointCount - 1) - let ySection : CGFloat = chartSize.size.height / CGFloat(range) - let index = Int((touchLocation.x + (xSection / 2)) / xSection) - - if index >= 0 && index < dataPointCount { - if !chartData.lineStyle.ignoreZero { - self.pointLocation = CGPoint(x: CGFloat(index) * xSection, - y: (CGFloat(chartData.dataPoints[index].value - minValue) * -ySection) + chartSize.size.height) - } else { - var pointValue : Double - if chartData.dataPoints[index].value == 0 { - if index > 0 && index < chartData.dataPoints.count - 1 { - // Set data point value as halfway between the previous and next value - pointValue = (chartData.dataPoints[index-1].value + chartData.dataPoints[index+1].value) / 2 - } else { - pointValue = chartData.dataPoints[index].value - } - } else { - pointValue = chartData.dataPoints[index].value - } - self.pointLocation = CGPoint(x: CGFloat(index) * xSection, - y: (CGFloat(pointValue - minValue) * -ySection) + chartSize.size.height) - } - } - } - - // MARK: - Bar Chart - /// Gets the nearest data point to the touch location based on the X axis. - /// - Parameters: - /// - touchLocation: Current location of the touch - /// - chartSize: The size of the chart view as the parent view. - internal func getDataPointBarChart(touchLocation: CGPoint, chartSize: GeometryProxy) /* -> ChartDataPoint */ { - let dataPoints : [ChartDataPoint] = chartData.dataPoints - let xSection : CGFloat = chartSize.size.width / CGFloat(dataPoints.count) - let index : Int = Int((touchLocation.x) / xSection) - if index >= 0 && index < dataPoints.count { - self.selectedPoint = dataPoints[index] - } - } - - /// Gets the location of the data point in the view. For BarChart - /// - Parameters: - /// - touchLocation: Current location of the touch - /// - chartSize: The size of the chart view as the parent view. - internal func getPointLocationBarChart(touchLocation: CGPoint, chartSize: GeometryProxy) /* -> CGPoint */ { - - let dataPointCount : Int = chartData.dataPoints.count - let xSection : CGFloat = chartSize.size.width / CGFloat(dataPointCount) - let ySection : CGFloat = chartSize.size.height / CGFloat(chartData.maxValue()) - - let index = Int((touchLocation.x) / xSection) - - if index >= 0 && index < dataPointCount { - self.pointLocation = CGPoint(x: (CGFloat(index) * xSection) + (xSection / 2), - y: (chartSize.size.height - CGFloat(chartData.dataPoints[index].value) * ySection)) - } - } - - // MARK: - Both - /// Sets the point info box location while keeping it within the parent view. - /// - Parameters: - /// - boxFrame: The size of the point info box. - /// - chartSize: The size of the chart view as the parent view. - internal func setBoxLocationation(boxFrame: CGRect, chartSize: GeometryProxy) { - if touchLocation.x < chartSize.frame(in: .local).minX + (boxFrame.width / 2) { - boxLocation.x = chartSize.frame(in: .local).minX + (boxFrame.width / 2) - } else if touchLocation.x > chartSize.frame(in: .local).maxX - (boxFrame.width / 2) { - boxLocation.x = chartSize.frame(in: .local).maxX - (boxFrame.width / 2) - } else { - boxLocation.x = touchLocation.x - } - } - /// Sets the X axis marker location while keeping it within the parent view. - /// - Parameter chartSize: The size of the chart view as the parent view. - /// - Returns: Position of the marker. - internal func setMarkerXLocation(chartSize: GeometryProxy) -> CGFloat { - if touchLocation.x < chartSize.frame(in: .local).minX { - return chartSize.frame(in: .local).minX - } else if touchLocation.x > chartSize.frame(in: .local).maxX { - return chartSize.frame(in: .local).maxX - } else { - return touchLocation.x - } - } - /// Sets the Y axis marker location while keeping it within the parent view. - /// - Parameter chartSize: The size of the chart view as the parent view. - /// - Returns: Position of the marker. - internal func setMarkerYLocation(chartSize: GeometryProxy) -> CGFloat { - if touchLocation.y < chartSize.frame(in: .local).minY { - return chartSize.frame(in: .local).minY - } else if touchLocation.y > chartSize.frame(in: .local).maxY { - return chartSize.frame(in: .local).maxY - } else { - return touchLocation.y -======= .onEnded { _ in chartData.infoView.isTouchCurrent = false chartData.infoView.touchOverlayInfo = [] @@ -244,7 +48,6 @@ internal struct TouchOverlay: ViewModifier where T: CTChartData { } } } else { content } ->>>>>>> version-2 } } } @@ -252,15 +55,6 @@ internal struct TouchOverlay: ViewModifier where T: CTChartData { extension View { #if !os(tvOS) -<<<<<<< HEAD - /// Adds an overlay to detect touch and display the relivent information from the nearest data point. - /// - Parameter specifier: Decimal precision for labels - public func touchOverlay(specifier: String = "%.0f", units: Units = .none) -> some View { - self.modifier(TouchOverlay(specifier: specifier, units: units)) - } - #elseif os(tvOS) - public func touchOverlay(specifier: String = "%.0f", units: Units = .none) -> some View { -======= /** Adds touch interaction with the chart. @@ -304,7 +98,6 @@ extension View { specifier: String = "%.0f", unit : TouchUnit = .none ) -> some View { ->>>>>>> version-2 self.modifier(EmptyModifier()) } #endif diff --git a/Sources/SwiftUICharts/Shared/Views/TouchOverlayBox.swift b/Sources/SwiftUICharts/Shared/Views/TouchOverlayBox.swift index 35441a9a..4d5d082c 100644 --- a/Sources/SwiftUICharts/Shared/Views/TouchOverlayBox.swift +++ b/Sources/SwiftUICharts/Shared/Views/TouchOverlayBox.swift @@ -12,65 +12,10 @@ View that displays information from the touch events. */ internal struct TouchOverlayBox: View { -<<<<<<< HEAD - private var selectedPoint : ChartDataPoint? - private var specifier : String - private var units : Units - private var ignoreZero : Bool -======= @ObservedObject var chartData: T ->>>>>>> version-2 @Binding private var boxFrame: CGRect -<<<<<<< HEAD - internal init(selectedPoint : ChartDataPoint?, - specifier : String = "%.0f", - units : Units, - boxFrame : Binding, - ignoreZero : Bool - ) { - self.selectedPoint = selectedPoint - self.specifier = specifier - self.units = units - self._boxFrame = boxFrame - self.ignoreZero = ignoreZero - } - - internal var body: some View { - VStack { - if ignoreZero && selectedPoint?.value != 0 { - switch units { - case .none: - Text("\(selectedPoint?.value ?? 0, specifier: specifier)") - .font(.subheadline) - case .prefix(of: let value): - Text("\(value) \(selectedPoint?.value ?? 0, specifier: specifier)") - .font(.subheadline) - case .suffix(of: let value): - Text("\(selectedPoint?.value ?? 0, specifier: specifier) \(value)") - .font(.subheadline) - } - } else if !ignoreZero { - switch units { - case .none: - Text("\(selectedPoint?.value ?? 0, specifier: specifier)") - .font(.subheadline) - case .prefix(of: let value): - Text("\(value) \(selectedPoint?.value ?? 0, specifier: specifier)") - .font(.subheadline) - case .suffix(of: let value): - Text("\(selectedPoint?.value ?? 0, specifier: specifier) \(value)") - .font(.subheadline) - } - } - if let label = selectedPoint?.pointDescription { - Text(label) - .font(.subheadline) - } else if let label = selectedPoint?.xAxisLabel { - Text(label) - .font(.subheadline) -======= internal init(chartData: T, boxFrame : Binding ) { @@ -95,7 +40,6 @@ internal struct TouchOverlayBox: View { .font(.subheadline) .foregroundColor(chartData.chartStyle.infoBoxDescriptionColour) Spacer() ->>>>>>> version-2 } } diff --git a/Sources/SwiftUICharts/SharedLineAndBar/Shapes/Marker.swift b/Sources/SwiftUICharts/SharedLineAndBar/Shapes/Marker.swift index 2ad55fee..4f33503a 100644 --- a/Sources/SwiftUICharts/SharedLineAndBar/Shapes/Marker.swift +++ b/Sources/SwiftUICharts/SharedLineAndBar/Shapes/Marker.swift @@ -13,38 +13,6 @@ internal struct Marker: Shape { private let value : Double private let chartType : ChartType -<<<<<<< HEAD:Sources/SwiftUICharts/Shared/Shapes/Marker.swift - private let minValue : Double - private let range : Double - - internal init(chartData : ChartData, - markerValue : Double = 0, - isAverage : Bool, - chartType : ChartType - ) { - self.chartData = chartData - self.markerValue = markerValue - self.isAverage = isAverage - self.chartType = chartType - - switch chartData.lineStyle.baseline { - case .minimumValue: - self.minValue = chartData.minValue() - self.range = chartData.range() - case .minimumWithMaximum(of: let value): - self.minValue = min(chartData.minValue(), value) - self.range = chartData.maxValue() - min(chartData.minValue(), value) - case .zero: - self.minValue = 0 - self.range = chartData.maxValue() - } - } - - internal func path(in rect: CGRect) -> Path { - - let value : Double = isAverage ? chartData.average() : markerValue - -======= let range : Double let minValue: Double let maxValue: Double @@ -64,7 +32,6 @@ internal struct Marker: Shape { internal func path(in rect: CGRect) -> Path { ->>>>>>> version-2:Sources/SwiftUICharts/SharedLineAndBar/Shapes/Marker.swift var path = Path() let pointY : CGFloat