Skip to content

Commit 684b8e3

Browse files
authored
Merge pull request #5 from yuntan/main
Number label for level label
2 parents ad811a2 + d5d828b commit 684b8e3

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

AxisContributionExample/Shared/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct ContentView: View {
1313

1414
@Environment(\.colorScheme) private var colorScheme
1515

16-
@State private var constant: ACConstant = .init(axisMode: .horizontal)
16+
@State private var constant: ACConstant = .init(axisMode: .horizontal, levelLabel: .number)
1717
@State private var rowSize: CGFloat = 11
1818
@State private var rowImageName: String = ""
1919
@State private var dates: [Date] = []

Sources/AxisContribution/AxisContribution.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public struct AxisContribution<B, F>: View where B: View, F: View {
123123
private var levelView: some View {
124124
if constant.showLevelView {
125125
HStack(spacing: constant.spacing * 0.5) {
126-
Text("Less")
126+
Text(constant.levelLabel == .moreOrLess ? "Less" : "0")
127127
.font(constant.font)
128128
.opacity(0.6)
129129
HStack(spacing: 0) {
@@ -135,7 +135,7 @@ public struct AxisContribution<B, F>: View where B: View, F: View {
135135
}
136136
}.scaleEffect(0.82)
137137
}
138-
Text("More")
138+
Text(constant.levelLabel == .moreOrLess ? "More" : "\(constant.levelSpacing * 4)+")
139139
.font(constant.font)
140140
.opacity(0.6)
141141
}

Sources/AxisContribution/Model/ACConstant.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public enum ACAxisMode: Equatable {
3333
case vertical
3434
}
3535

36+
/// Defines the label type of level label below the grid view.
37+
public enum ACLevelLavel: Equatable {
38+
case moreOrLess
39+
case number
40+
}
41+
3642
/// Settings that define the contribution view.
3743
public struct ACConstant: Equatable {
3844

@@ -57,6 +63,9 @@ public struct ACConstant: Equatable {
5763
/// Whether the level label below the grid view is visible
5864
public var showLevelView: Bool
5965

66+
/// The label type of the level label.
67+
public var levelLabel: ACLevelLavel
68+
6069
/// Initializes `ACConstant`
6170
/// - Parameters:
6271
/// - fromDate: The start date to display the list of contributions. The default value is `1 year from today.`.
@@ -66,20 +75,23 @@ public struct ACConstant: Equatable {
6675
/// - axisMode: The axis mode of the component. The default value is `.horizontal`.
6776
/// - font: The font used for text. The default value is `.system(size: 9)`.
6877
/// - showLevelView: Whether the level label below the grid view is visible. The default value is `true`.
78+
/// - levelLabel: The label type of the level label. The default value is `.moreOrLess`.
6979
public init(from fromDate: Date? = nil,
7080
to toDate: Date? = nil,
7181
spacing: CGFloat = 4,
7282
levelSpacing: Int = 3,
7383
axisMode: ACAxisMode = .horizontal,
7484
font: Font = .system(size: 9),
75-
showLevelView: Bool = true) {
85+
showLevelView: Bool = true,
86+
levelLabel: ACLevelLavel = .moreOrLess) {
7687
self.fromDate = fromDate == nil ? Date().dateYearAgo : fromDate!
7788
self.toDate = toDate == nil ? Date() : toDate!
7889
self.spacing = spacing
7990
self.levelSpacing = levelSpacing
8091
self.axisMode = axisMode
8192
self.font = font
8293
self.showLevelView = showLevelView
94+
self.levelLabel = levelLabel
8395
}
8496

8597
public static func == (lhs: Self, rhs: Self) -> Bool {

0 commit comments

Comments
 (0)