Skip to content

Commit

Permalink
feat: candle chart
Browse files Browse the repository at this point in the history
add notice about max displayed candles
add date for hour/minute charts
  • Loading branch information
kosyloa committed May 27, 2024
1 parent d8bec96 commit 73896fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions Samples/DXFeedCandleChart/DXFeedCandleChartApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct DXFeedCandleChartApp: App {
var body: some Scene {
WindowGroup {
CandleChart(symbol: "AAPL",
type: .minute,
endpoint: nil,
ipfAddress: "https://demo:[email protected]/ipf?SYMBOL=")
}
Expand Down
24 changes: 19 additions & 5 deletions Samples/DXFeedCandleChartMac/CandleChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73896fd

Please sign in to comment.