From 73896fdcd97a327eb6be0f2c5429dd6fc6b2050d Mon Sep 17 00:00:00 2001 From: kosyloa Date: Mon, 27 May 2024 14:06:49 +0200 Subject: [PATCH] feat: candle chart add notice about max displayed candles add date for hour/minute charts --- .../DXFeedCandleChartApp.swift | 1 + .../DXFeedCandleChartMac/CandleChart.swift | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Samples/DXFeedCandleChart/DXFeedCandleChartApp.swift b/Samples/DXFeedCandleChart/DXFeedCandleChartApp.swift index bd0fe49bc..d86ce6a33 100644 --- a/Samples/DXFeedCandleChart/DXFeedCandleChartApp.swift +++ b/Samples/DXFeedCandleChart/DXFeedCandleChartApp.swift @@ -12,6 +12,7 @@ struct DXFeedCandleChartApp: App { var body: some Scene { WindowGroup { CandleChart(symbol: "AAPL", + type: .minute, endpoint: nil, ipfAddress: "https://demo:demo@tools.dxfeed.com/ipf?SYMBOL=") } diff --git a/Samples/DXFeedCandleChartMac/CandleChart.swift b/Samples/DXFeedCandleChartMac/CandleChart.swift index 22b012757..bcd57ecca 100644 --- a/Samples/DXFeedCandleChartMac/CandleChart.swift +++ b/Samples/DXFeedCandleChartMac/CandleChart.swift @@ -92,16 +92,18 @@ struct CandleChart: View { GeometryReader { reader in List { Section { - chart.frame(height: max(reader.size.height - 150, 300)) - .onAppear { + VStack(alignment: .leading) { + chart.onAppear { // just workaround for swiftuicharts + scroll to self.list.fakeLoading() DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { self.selectedPrice = nil self.list.updateDate(type: self.type) } - } + Text("NOTICE: only the last \(CandleChartModel.maxCout) candles are displayed") + .font(Font.system(size: 10)) + }.frame(height: max(reader.size.height - 150, 300)) } .listRowBackground(Color.sectionBackground) Section("Chart parameters") { @@ -156,7 +158,15 @@ struct CandleChart: View { case .year: Text(shortDateFormatter.string(from: date)) case .minute: - Text(hourDateFormatter.string(from: date)) + VStack { + Text(dateFormatter.string(from: date)) + Text(hourDateFormatter.string(from: date)) + } + case .hour: + VStack { + Text(dateFormatter.string(from: date)) + Text(hourDateFormatter.string(from: date)) + } default: Text(dateFormatter.string(from: date)) } @@ -236,7 +246,11 @@ struct CandleChart: View { return AnyView(view .chartScrollableAxes(.horizontal) .chartXVisibleDomain(length: list.visibleDomains()) - .chartScrollPosition(x: $list.xScrollPosition)) + .chartScrollPosition(x: $list.xScrollPosition) + .onChange(of: list.xScrollPosition) { + selectedPrice = nil + } + ) } #endif return view