Skip to content

Commit

Permalink
Merge pull request #87 from willdale/add-position-data
Browse files Browse the repository at this point in the history
Add data stream of touch data point
  • Loading branch information
willdale authored Jun 5, 2021
2 parents 21337e1 + c09220a commit 7e69757
Show file tree
Hide file tree
Showing 20 changed files with 164 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//

import SwiftUI
import Combine

/**
Data for drawing and styling a standard Bar Chart.
*/
public final class BarChartData: CTBarChartDataProtocol {
public final class BarChartData: CTBarChartDataProtocol, Publishable {
// MARK: Properties
public let id: UUID = UUID()

Expand All @@ -26,6 +27,10 @@ public final class BarChartData: CTBarChartDataProtocol {

@Published public final var extraLineData: ExtraLineData!

// Publishable
public var subscription = SubscriptionSet().subscription
public let touchedDataPointPublisher = PassthroughSubject<DataPoint,Never>()

public final var noDataText: Text
public final let chartType: (chartType: ChartType, dataSetType: DataSetType)

Expand Down Expand Up @@ -128,6 +133,7 @@ public final class BarChartData: CTBarChartDataProtocol {
if index >= 0 && index < dataSets.dataPoints.count {
dataSets.dataPoints[index].legendTag = dataSets.legendTitle
self.infoView.touchOverlayInfo = [dataSets.dataPoints[index]]
touchedDataPointPublisher.send(dataSets.dataPoints[index])
}
}

Expand All @@ -142,7 +148,7 @@ public final class BarChartData: CTBarChartDataProtocol {
return nil
}

public typealias Set = BarDataSet
public typealias SetType = BarDataSet
public typealias DataPoint = BarChartDataPoint
public typealias CTStyle = BarChartStyle
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
//

import SwiftUI
import Combine

/**
Data model for drawing and styling a Grouped Bar Chart.

The grouping data informs the model as to how the datapoints are linked.
```
*/
public final class GroupedBarChartData: CTMultiBarChartDataProtocol {
public final class GroupedBarChartData: CTMultiBarChartDataProtocol, Publishable {

// MARK: Properties
public let id: UUID = UUID()
Expand All @@ -31,6 +32,10 @@ public final class GroupedBarChartData: CTMultiBarChartDataProtocol {

@Published public final var extraLineData: ExtraLineData!

// Publishable
public var subscription = SubscriptionSet().subscription
public let touchedDataPointPublisher = PassthroughSubject<DataPoint,Never>()

public final var noDataText: Text
public final var chartType: (chartType: ChartType, dataSetType: DataSetType)

Expand Down Expand Up @@ -156,6 +161,7 @@ public final class GroupedBarChartData: CTMultiBarChartDataProtocol {
if subIndex >= 0 && subIndex < dataSets.dataSets[index].dataPoints.count {
dataSets.dataSets[index].dataPoints[subIndex].legendTag = dataSets.dataSets[index].setTitle
self.infoView.touchOverlayInfo = [dataSets.dataSets[index].dataPoints[subIndex]]
touchedDataPointPublisher.send(dataSets.dataSets[index].dataPoints[subIndex])
}
}
}
Expand Down Expand Up @@ -189,7 +195,7 @@ public final class GroupedBarChartData: CTMultiBarChartDataProtocol {
return nil
}

public typealias Set = GroupedBarDataSets
public typealias SetType = GroupedBarDataSets
public typealias DataPoint = GroupedBarDataPoint
public typealias CTStyle = BarChartStyle
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//

import SwiftUI
import Combine

/**
Data for drawing and styling a standard Bar Chart.
*/
public final class HorizontalBarChartData: CTHorizontalBarChartDataProtocol {
public final class HorizontalBarChartData: CTHorizontalBarChartDataProtocol, Publishable {
// MARK: Properties
public let id: UUID = UUID()

Expand All @@ -26,6 +27,10 @@ public final class HorizontalBarChartData: CTHorizontalBarChartDataProtocol {

@Published public final var extraLineData: ExtraLineData!

// Publishable
public var subscription = SubscriptionSet().subscription
public let touchedDataPointPublisher = PassthroughSubject<DataPoint,Never>()

public final var noDataText: Text
public final let chartType: (chartType: ChartType, dataSetType: DataSetType)

Expand Down Expand Up @@ -167,6 +172,7 @@ public final class HorizontalBarChartData: CTHorizontalBarChartDataProtocol {
if index >= 0 && index < dataSets.dataPoints.count {
dataSets.dataPoints[index].legendTag = dataSets.legendTitle
self.infoView.touchOverlayInfo = [dataSets.dataPoints[index]]
touchedDataPointPublisher.send(dataSets.dataPoints[index])
}
}

Expand All @@ -181,7 +187,7 @@ public final class HorizontalBarChartData: CTHorizontalBarChartDataProtocol {
return nil
}

public typealias Set = BarDataSet
public typealias SetType = BarDataSet
public typealias DataPoint = BarChartDataPoint
public typealias CTStyle = BarChartStyle
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//

import SwiftUI
import Combine

/**
Data for drawing and styling a ranged Bar Chart.
*/
public final class RangedBarChartData: CTRangedBarChartDataProtocol {
public final class RangedBarChartData: CTRangedBarChartDataProtocol, Publishable {
// MARK: Properties
public let id: UUID = UUID()

Expand All @@ -26,6 +27,10 @@ public final class RangedBarChartData: CTRangedBarChartDataProtocol {

@Published public final var extraLineData: ExtraLineData!

// Publishable
public var subscription = SubscriptionSet().subscription
public let touchedDataPointPublisher = PassthroughSubject<DataPoint,Never>()

public final var noDataText: Text
public final let chartType: (chartType: ChartType, dataSetType: DataSetType)

Expand Down Expand Up @@ -138,6 +143,7 @@ public final class RangedBarChartData: CTRangedBarChartDataProtocol {
if index >= 0 && index < dataSets.dataPoints.count {
dataSets.dataPoints[index].legendTag = dataSets.legendTitle
self.infoView.touchOverlayInfo = [dataSets.dataPoints[index]]
touchedDataPointPublisher.send(dataSets.dataPoints[index])
}
}

Expand All @@ -152,7 +158,7 @@ public final class RangedBarChartData: CTRangedBarChartDataProtocol {
return nil
}

public typealias Set = RangedBarDataSet
public typealias SetType = RangedBarDataSet
public typealias DataPoint = RangedBarDataPoint
public typealias CTStyle = BarChartStyle
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
//

import SwiftUI
import Combine

/**
Data model for drawing and styling a Stacked Bar Chart.

The grouping data informs the model as to how the datapoints are linked.
*/
public final class StackedBarChartData: CTMultiBarChartDataProtocol {
public final class StackedBarChartData: CTMultiBarChartDataProtocol, Publishable {

// MARK: Properties
public let id: UUID = UUID()
Expand All @@ -30,6 +31,10 @@ public final class StackedBarChartData: CTMultiBarChartDataProtocol {

@Published public final var extraLineData: ExtraLineData!

// Publishable
public var subscription = SubscriptionSet().subscription
public let touchedDataPointPublisher = PassthroughSubject<DataPoint,Never>()

public final var noDataText: Text
public final var chartType: (chartType: ChartType, dataSetType: DataSetType)

Expand Down Expand Up @@ -139,6 +144,7 @@ public final class StackedBarChartData: CTMultiBarChartDataProtocol {
if index >= 0 && index < dataSets.dataSets[superIndex].dataPoints.count {
dataSets.dataSets[superIndex].dataPoints[index].legendTag = dataSets.dataSets[superIndex].setTitle
self.infoView.touchOverlayInfo = [dataSets.dataSets[superIndex].dataPoints[index]]
touchedDataPointPublisher.send(dataSets.dataSets[superIndex].dataPoints[index])
}
}
}
Expand Down Expand Up @@ -198,7 +204,7 @@ public final class StackedBarChartData: CTMultiBarChartDataProtocol {
return (yIndex, endPointOfElements)
}

public typealias Set = StackedBarDataSets
public typealias SetType = StackedBarDataSets
public typealias DataPoint = StackedBarDataPoint
public typealias CTStyle = BarChartStyle
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ extension CTBarChartDataProtocol where Self.CTStyle.Mark == BarMarkerType {
//
//
// MARK: Standard / Ranged
extension CTBarChartDataProtocol where Self.Set.ID == UUID,
Self.Set.DataPoint.ID == UUID,
Self.Set: CTStandardBarChartDataSet,
Self.Set.DataPoint: CTBarColourProtocol {
extension CTBarChartDataProtocol where Self.SetType.ID == UUID,
Self.SetType.DataPoint.ID == UUID,
Self.SetType: CTStandardBarChartDataSet,
Self.SetType.DataPoint: CTBarColourProtocol {
internal func setupLegends() {
switch self.barStyle.colourFrom {
case .barStyle:
Expand Down
12 changes: 6 additions & 6 deletions Sources/SwiftUICharts/BarChart/Views/SubViews/Bars.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ internal struct GradientStopsPartBar: View {
internal struct RangedBarChartColourCell<CD:RangedBarChartData>: View {

private let chartData: CD
private let dataPoint: CD.Set.DataPoint
private let dataPoint: CD.SetType.DataPoint
private let colour: Color
private let barSize: CGRect

internal init(
chartData: CD,
dataPoint: CD.Set.DataPoint,
dataPoint: CD.SetType.DataPoint,
colour: Color,
barSize: CGRect
) {
Expand Down Expand Up @@ -379,15 +379,15 @@ internal struct RangedBarChartColourCell<CD:RangedBarChartData>: View {
internal struct RangedBarChartColoursCell<CD:RangedBarChartData>: View {

private let chartData: CD
private let dataPoint: CD.Set.DataPoint
private let dataPoint: CD.SetType.DataPoint
private let colours: [Color]
private let startPoint: UnitPoint
private let endPoint: UnitPoint
private let barSize: CGRect

internal init(
chartData: CD,
dataPoint: CD.Set.DataPoint,
dataPoint: CD.SetType.DataPoint,
colours: [Color],
startPoint: UnitPoint,
endPoint: UnitPoint,
Expand Down Expand Up @@ -430,15 +430,15 @@ internal struct RangedBarChartColoursCell<CD:RangedBarChartData>: View {
internal struct RangedBarChartStopsCell<CD:RangedBarChartData>: View {

private let chartData: CD
private let dataPoint: CD.Set.DataPoint
private let dataPoint: CD.SetType.DataPoint
private let stops: [Gradient.Stop]
private let startPoint: UnitPoint
private let endPoint: UnitPoint
private let barSize: CGRect

internal init(
chartData: CD,
dataPoint: CD.Set.DataPoint,
dataPoint: CD.SetType.DataPoint,
stops: [Gradient.Stop],
startPoint: UnitPoint,
endPoint: UnitPoint,
Expand Down
26 changes: 13 additions & 13 deletions Sources/SwiftUICharts/LineChart/Extras/LineChartEnums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public enum PointShape {
case point // Attached to the data points.
```
*/
public enum MarkerAttachemnt {
public enum MarkerAttachment {
/// Attached to the line.
case line(dot: Dot)
/// Attached to the data points.
Expand All @@ -74,12 +74,12 @@ public enum MarkerAttachemnt {
```
case none // No overlay markers.
case indicator(style: DotStyle) // Dot that follows the path.
case vertical(attachment: MarkerAttachemnt) // Vertical line from top to bottom.
case full(attachment: MarkerAttachemnt) // Full width and height of view intersecting at a specified point.
case bottomLeading(attachment: MarkerAttachemnt) // From bottom and leading edges meeting at a specified point.
case bottomTrailing(attachment: MarkerAttachemnt) // From bottom and trailing edges meeting at a specified point.
case topLeading(attachment: MarkerAttachemnt) // From top and leading edges meeting at a specified point.
case topTrailing(attachment: MarkerAttachemnt) // From top and trailing edges meeting at a specified point.
case vertical(attachment: MarkerAttachment) // Vertical line from top to bottom.
case full(attachment: MarkerAttachment) // Full width and height of view intersecting at a specified point.
case bottomLeading(attachment: MarkerAttachment) // From bottom and leading edges meeting at a specified point.
case bottomTrailing(attachment: MarkerAttachment) // From bottom and trailing edges meeting at a specified point.
case topLeading(attachment: MarkerAttachment) // From top and leading edges meeting at a specified point.
case topTrailing(attachment: MarkerAttachment) // From top and trailing edges meeting at a specified point.
```
*/
public enum LineMarkerType: MarkerType {
Expand All @@ -88,17 +88,17 @@ public enum LineMarkerType: MarkerType {
/// Dot that follows the path.
case indicator(style: DotStyle)
/// Vertical line from top to bottom.
case vertical(attachment: MarkerAttachemnt, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
case vertical(attachment: MarkerAttachment, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
/// Full width and height of view intersecting at a specified point.
case full(attachment: MarkerAttachemnt, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
case full(attachment: MarkerAttachment, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
/// From bottom and leading edges meeting at a specified point.
case bottomLeading(attachment: MarkerAttachemnt, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
case bottomLeading(attachment: MarkerAttachment, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
/// From bottom and trailing edges meeting at a specified point.
case bottomTrailing(attachment: MarkerAttachemnt, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
case bottomTrailing(attachment: MarkerAttachment, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
/// From top and leading edges meeting at a specified point.
case topLeading(attachment: MarkerAttachemnt, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
case topLeading(attachment: MarkerAttachment, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
/// From top and trailing edges meeting at a specified point.
case topTrailing(attachment: MarkerAttachemnt, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
case topTrailing(attachment: MarkerAttachment, colour: Color = Color.primary, style: StrokeStyle = StrokeStyle())
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
//

import SwiftUI
import Combine

/**
Data for drawing and styling a single line, line chart.

This model contains the data and styling information for a single line, line chart.
*/
public final class LineChartData: CTLineChartDataProtocol {
public final class LineChartData: CTLineChartDataProtocol, Publishable {

// MARK: Properties
public final let id: UUID = UUID()
Expand All @@ -31,6 +32,10 @@ public final class LineChartData: CTLineChartDataProtocol {

@Published public final var extraLineData: ExtraLineData!

// Publishable
public var subscription = SubscriptionSet().subscription
public let touchedDataPointPublisher = PassthroughSubject<DataPoint,Never>()

internal final var isFilled: Bool = false

// MARK: Initializer
Expand Down Expand Up @@ -75,7 +80,6 @@ public final class LineChartData: CTLineChartDataProtocol {
if let label = self.dataSets.dataPoints[i].xAxisLabel {
if label != "" {
TempText(chartData: self, label: label, rotation: angle)

.frame(width: min(self.getXSection(dataSet: self.dataSets, chartSize: self.viewData.chartSize), self.viewData.xAxislabelWidths.min() ?? 0),
height: self.viewData.xAxisLabelHeights.max() ?? 0)
.offset(x: CGFloat(i) * (geo.frame(in: .local).width / CGFloat(self.dataSets.dataPoints.count - 1)),
Expand Down Expand Up @@ -133,7 +137,7 @@ public final class LineChartData: CTLineChartDataProtocol {
chartSize: chartSize)
}

public typealias Set = LineDataSet
public typealias SetType = LineDataSet
public typealias DataPoint = LineChartDataPoint
}

Expand Down Expand Up @@ -181,6 +185,7 @@ extension LineChartData {
self.infoView.touchOverlayInfo = [dataSets.dataPoints[index]]
}
}
touchedDataPointPublisher.send(dataSets.dataPoints[index])
}
}
}
Loading

0 comments on commit 7e69757

Please sign in to comment.