commit a2bf12b01ca64f4016d8ebd56219c0f65eaf65b3
parent 5fc32205c315b36dafc0441ddb57f1ed9e109914
Author: Marc Stibane <marc@taler.net>
Date: Thu, 18 Sep 2025 17:53:44 +0000
cleanup (rename)
Diffstat:
2 files changed, 54 insertions(+), 45 deletions(-)
diff --git a/TalerWallet1/Views/OIM/ChartHistoryView.swift b/TalerWallet1/Views/OIM/ChartHistoryView.swift
@@ -44,7 +44,7 @@ struct ChartHistoryView: View {
let stack: CallStack
private let logger = Logger(subsystem: "net.taler.gnu", category: "Chart")
let currency: OIMcurrency
- @Binding var chartData: [LineMarkData]
+ @Binding var shownItems: [HistoryItem]
@Binding var dataPointWidth: CGFloat
let scrollBack: Bool
@@ -59,23 +59,23 @@ struct ChartHistoryView: View {
@State private var lastDelta: Double?
init(stack: CallStack,
- currency: OIMcurrency, chartData: Binding<[LineMarkData]>, dataPointWidth: Binding<CGFloat>,
+ currency: OIMcurrency, shownItems: Binding<[HistoryItem]>, dataPointWidth: Binding<CGFloat>,
scrollBack: Bool, maxIndex: Int = 1, maxValue: Double = 200
) {
self.stack = stack
self.currency = currency
self.scrollBack = scrollBack
- self._chartData = chartData
+ self._shownItems = shownItems
self._dataPointWidth = dataPointWidth
self.maxYValue = maxValue
self.maxXValue = maxIndex
}
- var lineMarkforSelection: LineMarkData? {
+ var itemForSelection: HistoryItem? {
if let selectedTX {
- for lineMark in chartData {
- if lineMark.distance == -selectedTX {
- return lineMark
+ for item in shownItems {
+ if item.distance == -selectedTX {
+ return item
}
}
}
@@ -89,30 +89,36 @@ struct ChartHistoryView: View {
return false
}
- func magnify(_ newDelta: Double) {
+ func magnify(_ newDelta: Double) -> Bool {
if let lastDelta {
let delta = newDelta - lastDelta
let absDelta = abs(delta)
+ print(absDelta.pTwo)
var width = dataPointWidth
- if delta > 0 { // zoom in
+ if delta > 0.1 { // zoom in
+// width += 10
width += absDelta * 10
dataPointWidth = width < DATAPOINTWIDTH_MAX ? width : DATAPOINTWIDTH_MAX
- } else if delta < 0 { // zoom out
+ } else if delta < -0.1 { // zoom out
+// width -= 10
width -= absDelta * 10
dataPointWidth = width > DATAPOINTWIDTH_MIN ? width : DATAPOINTWIDTH_MIN
+ } else {
+ return false
}
}
+ return true
}
var body: some View {
- let count = chartData.count
+ let count = shownItems.count
let width = dataPointWidth * CGFloat(maxXValue)
// let _ = logger.log("ChartHistoryView \(width.pTwo)")
let chart = Chart {
ForEach(0..<count, id: \.self) { index in
- let data = chartData[index]
- let xVal = -data.distance
- let yVal = yTransform(data.balance)
+ let item = shownItems[index]
+ let xVal = -item.distance
+ let yVal = yTransform(item.balance)
LineMark(x: .value("x", xVal),
y: .value("y", yVal))
.foregroundStyle(WalletColors().talerColor)
@@ -123,7 +129,7 @@ struct ChartHistoryView: View {
.interpolationMethod(.monotone)
// .interpolationMethod(.stepCenter) // stepStart
- if let talerTX = data.talerTX {
+ if let talerTX = item.talerTX {
PointMark(x: .value("x", xVal),
y: .value("y", yVal))
@@ -167,8 +173,9 @@ struct ChartHistoryView: View {
if let newRange { // pinch started - or changed
let newDelta = newRange.upperBound - newRange.lowerBound
// logger.log("selectedRange \(newDelta)")
- magnify(newDelta)
- lastDelta = newDelta
+ if magnify(newDelta) {
+ lastDelta = newDelta
+ }
} else { // pinch ended
lastDelta = nil
}
@@ -210,11 +217,11 @@ struct ChartHistoryView: View {
// Button("Top") { withAnimation { proxy.scrollTo(topID) } }
} // ScrollViewReader
if let selectedTX {
- if let lineMark = lineMarkforSelection {
- if let talerTX = lineMark.talerTX {
+ if let item = itemForSelection {
+ if let talerTX = item.talerTX {
ChartOverlayV(stack: stack.push(),
currency: currency,
- balance: lineMark.balance,
+ balance: item.balance,
talerTX: talerTX)
}
}
@@ -259,10 +266,12 @@ struct ChartOverlayV: View {
VStack {
Spacer()
let balance2 = balance * Double(currency.factor)
+ let incoming = talerTX.common.isIncoming
VStack {
Text("Balance: \(balance2.pTwo)")
.foregroundStyle(WalletColors().gray2)
- OIMamountV(amount: effective, currencyName: currency.currencyStr, factor: currency.factor)
+ OIMamountV(amount: effective, currencyName: currency.currencyStr,
+ factor: currency.factor, mayChangeSpeed: false)
OIMlineView(stack: stack.push(),
cash: cash,
amountVal: $amountVal,
diff --git a/TalerWallet1/Views/OIM/OIMtransactions.swift b/TalerWallet1/Views/OIM/OIMtransactions.swift
@@ -23,7 +23,7 @@ enum OIMtransactionsState {
}
// MARK: -
-struct LineMarkData: Identifiable {
+struct HistoryItem: Identifiable {
var id: String {
if let talerTX {
return talerTX.id
@@ -53,8 +53,8 @@ struct OIMtransactions: View {
@State private var available: Amount? = nil
@State private var viewState: OIMtransactionsState = .chestIsOpen
@State private var closing = false // after user tapped on the open chest
- @State private var lineMarks: [LineMarkData] = []
- @State private var chartData: [LineMarkData] = []
+ @State private var shownItems: [HistoryItem] = []
+ @State private var computedItems: [HistoryItem] = []
@State private var chartMaxY: Double = 200 // max balance
@State private var dataPointWidth: CGFloat = DATAPOINTWIDTH
// when we start fetching transactions in chunks, MinX will get negative (going back in time)
@@ -86,38 +86,38 @@ struct OIMtransactions: View {
func hideHistoryItems(_ interval: TimeInterval = 0) -> TimeInterval {
if interval > 0 {
DispatchQueue.main.asyncAfter(deadline: .now() + interval) {
- let count = lineMarks.count
+ let count = shownItems.count
if count > 0 {
withAnimation {
- lineMarks.removeLast()
+ shownItems.removeLast()
}
if count > 1 {
hideHistoryItems(interval)
}
}
}
- return Double(lineMarks.count) * interval
+ return Double(shownItems.count) * interval
}
- lineMarks = []
+ shownItems = []
return 0
}
@discardableResult
func showHistoryItems(_ interval: TimeInterval = 0) -> TimeInterval {
var delay = 0.0
- let count = chartData.count
+ let count = computedItems.count
let reduce = interval / Double(count + 2)
var index = 0
- for lineMark in chartData {
+ for item in computedItems {
if interval > 0 {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
withAnimation {
- lineMarks.append(lineMark)
+ shownItems.append(item)
}
}
delay += (interval - Double(index) * reduce)
} else {
- lineMarks.append(lineMark)
+ shownItems.append(item)
}
}
return delay
@@ -170,15 +170,15 @@ struct OIMtransactions: View {
ZStack {
HStack {
Spacer(minLength: 0)
- let count = lineMarks.count
+ let count = shownItems.count
if count > 1 {
- let last = lineMarks.last
+ let last = shownItems.last
let maxIndex = last?.distance ?? 20 // should never happen
- let scrollBack = count == chartData.count
+ let scrollBack = count == computedItems.count
// let _ = print("calling ChartHistoryView", count, maxIndex, scrollBack)
ChartHistoryView(stack: stack.push(),
currency: cash.currency,
- chartData: $lineMarks,
+ shownItems: $shownItems,
dataPointWidth: $dataPointWidth,
scrollBack: scrollBack,
maxIndex: maxIndex,
@@ -206,8 +206,8 @@ struct OIMtransactions: View {
cash.update2(availableVal) // set cash to available
cash.setTarget(.history)
debugTick += 1
- if chartData.count == 0 {
- chartData(from: history, balance: balance.available.value) // set chartMaxY, chartData
+ if computedItems.count == 0 {
+ computeData(from: history, balance: balance.available.value) // set chartMaxY, computedData
}
showHistoryItems(Animation.talerDelay0)
}
@@ -221,7 +221,7 @@ struct OIMtransactions: View {
@available(iOS 16.4, *)
extension OIMtransactions {
- func chartData(from history: [TalerTransaction], balance: Double) {
+ func computeData(from history: [TalerTransaction], balance: Double) {
/// Algorithm for the X value of the river of time
/// Endpoint (now) is 0
/// same day transactions have no space between them
@@ -229,14 +229,14 @@ extension OIMtransactions {
/// week differs: add another spacer
/// month differs: add one more spacer
/// year differs: add yet another spacer
- var lineMarks: [LineMarkData] = [ LineMarkData(distance: 0, balance: balance, talerTX: nil) ]
+ var historyItems: [HistoryItem] = [ HistoryItem(distance: 0, balance: balance, talerTX: nil) ]
var balance = balance
var maxBalance = balance
let calendar = Calendar.current // or do we need (identifier: .gregorian) ?
var lastTx = calendar.dateComponents([.year, .month, .day, .weekOfMonth], from: Date.now)
var xIndex = 0
- func lineMark(for talerTransaction: TalerTransaction) -> LineMarkData? {
+ func historyItem(for talerTransaction: TalerTransaction) -> HistoryItem? {
let common = talerTransaction.common
let amount = common.amountEffective
let incoming = common.isIncoming
@@ -269,16 +269,16 @@ extension OIMtransactions {
if balance > maxBalance {
maxBalance = balance
}
- return LineMarkData(distance: xIndex, balance: balance, talerTX: talerTransaction)
+ return HistoryItem(distance: xIndex, balance: balance, talerTX: talerTransaction)
}
for talerTransaction in history {
- if let mark = lineMark(for: talerTransaction) {
- lineMarks.append(mark)
+ if let item = historyItem(for: talerTransaction) {
+ historyItems.append(item)
}
}
- chartData = lineMarks
+ computedItems = historyItems
chartMaxY = maxBalance * yTransform(1.1) // 10 % plus, log2()
// print("computeData:", history.count, xIndex)
}