Skip to content

Commit

Permalink
Merge pull request #57 from ashchan/update-chart-on-portfolio-change
Browse files Browse the repository at this point in the history
Fix GrowthChart not updating issue by adding PortfolioSettings
  • Loading branch information
ashchan authored Dec 14, 2021
2 parents 9fc0cc7 + 5ae7f56 commit 0e2e3e5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
1 change: 0 additions & 1 deletion Shared/Models/Portfolio/PortfolioConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ extension Portfolio {
startAt = Calendar.utc.date(from: components)!.startOfMonth
currencyCode = config.currencyCode

// TODO: only rebuild if startAt has been changed
sortedAccounts.forEach { $0.rebuildRecords() }
}
}
3 changes: 2 additions & 1 deletion macOS/Views/PortfolioView/GrowthChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI
import Charts

struct GrowthChart: NSViewRepresentable {
@EnvironmentObject var portfolioSettings: PortfolioSettings
@State var portfolio: Portfolio

typealias NSViewType = LineChartView
Expand All @@ -17,7 +18,6 @@ struct GrowthChart: NSViewRepresentable {
let view = LineChartView()
view.leftAxis.axisMinimum = 0
view.leftAxis.drawGridLinesEnabled = false
view.leftAxis.valueFormatter = ChartValueFormatter(portfolio: portfolio)
view.xAxis.labelPosition = .bottom
view.xAxis.drawGridLinesEnabled = false
view.xAxis.valueFormatter = ChartDateFormatter()
Expand All @@ -31,6 +31,7 @@ struct GrowthChart: NSViewRepresentable {
}

func updateNSView(_ nsView: LineChartView, context: Context) {
nsView.leftAxis.valueFormatter = ChartValueFormatter(portfolio: portfolio)
nsView.data = chartData
if let max = nsView.data?.yMax {
nsView.leftAxis.axisMaximum = max + 2_000
Expand Down
2 changes: 1 addition & 1 deletion macOS/Views/Sidebar/PortfolioRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct PortfolioRow: View {
})
) {
NavigationLink(
destination: PortfolioView(portfolio: portfolio, showingConfigureSheet: $showingConfigureSheet),
destination: PortfolioView(portfolio: portfolio, showingConfigureSheet: $showingConfigureSheet).environmentObject(portfolioSettings),
tag: "\(portfolio.tag)-overview",
selection: $selection
) {
Expand Down

0 comments on commit 0e2e3e5

Please sign in to comment.