Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📈 [RUN-228] Show linear target line #3

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,42 @@ struct GoalChartView: View {
}
}

if let goal = store.goal.target, store.showTarget, let start = columns.first?.index, let end = columns.last?.index {
LineMark(
x: .value("index", start),
y: .value("distance", goal.converted(to: .primaryUnit()).value),
series: .value("goal", "b")
)
.foregroundStyle(tint)
if let goal = store.goal.target, let start = columns.first?.index, let end = columns.last?.index {
if store.showTarget {
LineMark(
x: .value("index", start),
y: .value("distance", goal.converted(to: .primaryUnit()).value),
series: .value("goal", "b")
)
.lineStyle(StrokeStyle(lineWidth: 1, dash: [1]))
.foregroundStyle(tint)

LineMark(
x: .value("index", end),
y: .value("distance", goal.converted(to: .primaryUnit()).value),
series: .value("goal", "b")
)
.foregroundStyle(tint)
LineMark(
x: .value("index", end),
y: .value("distance", goal.converted(to: .primaryUnit()).value),
series: .value("goal", "b")
)
.lineStyle(StrokeStyle(lineWidth: 1, dash: [1]))
.foregroundStyle(tint)
}

if store.showRate {
LineMark(
x: .value("index", start),
y: .value("distance", 0),
series: .value("rate", goal.converted(to: .primaryUnit()).value)
)
.lineStyle(StrokeStyle(lineWidth: 1, dash: [1]))
.foregroundStyle(tint)

LineMark(
x: .value("index", end),
y: .value("distance", goal.converted(to: .primaryUnit()).value),
series: .value("rate", goal.converted(to: .primaryUnit()).value)
)
.lineStyle(StrokeStyle(lineWidth: 1, dash: [1]))
.foregroundStyle(tint)
}
}
}
.chartScrollableAxes([.horizontal])
Expand Down Expand Up @@ -124,6 +146,12 @@ struct GoalChartView: View {
if store.goal.target != nil {
HStack {
Spacer()
ChartButton(
title: "Rate",
symbol: "chart.line.uptrend.xyaxis",
selected: $store.showRate.animation()
)

ChartButton(
title: L10n.Goals.Detail.Chart.targetButton,
symbol: "target",
Expand All @@ -140,10 +168,10 @@ struct GoalChartView: View {
let min = 0
let maxValue: Int
let goalValue: Int
if store.showTarget, let goal = store.goal.target?.converted(to: .primaryUnit()) {
if showFullRange, let goal = store.goal.target?.converted(to: .primaryUnit()) {
goalValue = Int(ceil(goal.value))
} else {
goalValue = store.showTarget ? 0 : 20
goalValue = showFullRange ? 0 : 20
}

if let cumulativeDistance = columns.last?.cumulativeDistance {
Expand All @@ -153,6 +181,10 @@ struct GoalChartView: View {
}
return min ... (maxValue + 10)
}

var showFullRange: Bool {
store.showTarget || store.showRate
}
}

#Preview("Weekly") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ public struct GoalDetailFeature: Reducer {
var emptyStateRuns: [Run]

@Shared var showTarget: Bool
@Shared var showRate: Bool

public init(
goal: Goal,
intervalDate: Date? = nil,
runs: [Run]? = nil,
emptyStateRuns: [Run] = [],
showTarget: Bool = false
showTarget: Bool = false,
showRate: Bool = false
) {
self.goal = goal
self.intervalDate = intervalDate
self.runs = runs
self.emptyStateRuns = emptyStateRuns

_showTarget = .init(wrappedValue: showTarget, .appStorage("show_target_\(goal.period.rawValue)"))
_showRate = .init(wrappedValue: showRate, .appStorage("show_rate_\(goal.period.rawValue)"))
}

var title: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "git@github.com:pointfreeco/swift-composable-architecture.git",
"state" : {
"revision" : "e6c0959044cbe2c934ac0ce9c3c4ead86350f44f",
"version" : "1.10.2"
"revision" : "433a23118f739078644ebeb4009e23d307af694a",
"version" : "1.10.4"
}
},
{
Expand Down