forked from Dimillian/ACHNBrowserUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Turnips Chart): add vertical legend with strided value to 50
- Loading branch information
1 parent
3e50404
commit 26087f9
Showing
3 changed files
with
69 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
ACHNBrowserUI/ACHNBrowserUI/views/turnips/charts/TurnipsChartVerticalLegend.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// TurnipsChartVerticalLegend.swift | ||
// ACHNBrowserUI | ||
// | ||
// Created by Renaud JENNY on 05/05/2020. | ||
// Copyright © 2020 Thomas Ricouard. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import Backend | ||
|
||
struct TurnipsChartVerticalLegend: View { | ||
let predictions: TurnipPredictions | ||
private let steps = 50 | ||
|
||
var body: some View { | ||
GeometryReader(content: h) | ||
} | ||
|
||
func h(geometry: GeometryProxy) -> some View { | ||
let frame = geometry.frame(in: .local) | ||
let (minY, maxY, ratioY, _) = predictions.minMax?.minMaxAndRatios(rect: frame) ?? (0, 0, 0, 0) | ||
|
||
let roundedMin = Int(minY)/steps * steps | ||
let roundedMax = (Int(maxY) + steps)/steps * steps | ||
return ZStack { | ||
ForEach(Array(stride(from: roundedMin, to: roundedMax, by: steps)), id: \.self) { value in | ||
Text("\(value)") | ||
.font(.footnote) | ||
.fontWeight(.semibold) | ||
.foregroundColor(.text) | ||
.position(x: frame.midX, y: (maxY - CGFloat(value)) * ratioY) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters