Skip to content

Commit

Permalink
customize color to dxfeed color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed May 2, 2024
1 parent 37c9702 commit 0e88a91
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 32 deletions.
10 changes: 8 additions & 2 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
643F41F92BDFE1B200A2176D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 643F41F82BDFE1B200A2176D /* Assets.xcassets */; };
643F41FC2BDFE1B200A2176D /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 643F41FB2BDFE1B200A2176D /* Preview Assets.xcassets */; };
643F42012BDFE25D00A2176D /* CandleStickChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 643F42002BDFE25D00A2176D /* CandleStickChart.swift */; };
643F42032BE3742D00A2176D /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 646979712A3B5AF60003A9BA /* Colors.xcassets */; };
64437A8F2A9DEE6F005929B2 /* InstrumentProfile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64437A8E2A9DEE6F005929B2 /* InstrumentProfile.swift */; };
64437A922A9DF1DE005929B2 /* NativeInstrumentProfileReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64437A912A9DF1DE005929B2 /* NativeInstrumentProfileReader.swift */; };
6447A5DB2A8E559000739CCF /* ILastingEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6447A5DA2A8E559000739CCF /* ILastingEvent.swift */; };
Expand Down Expand Up @@ -1935,6 +1936,8 @@
dependencies = (
);
name = DXFeedCandleChart;
packageProductDependencies = (
);
productName = DXFeedCandleChart;
productReference = 643F41F22BDFE1B000A2176D /* DXFeedCandleChart.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -2154,6 +2157,8 @@
Base,
);
mainGroup = 803BAC0329BFA50700FFAB1C;
packageReferences = (
);
productRefGroup = 803BAC0E29BFA50700FFAB1C /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -2190,6 +2195,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
643F42032BE3742D00A2176D /* Colors.xcassets in Resources */,
643F41FC2BDFE1B200A2176D /* Preview Assets.xcassets in Resources */,
643F41F92BDFE1B200A2176D /* Assets.xcassets in Resources */,
);
Expand Down Expand Up @@ -3032,7 +3038,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Samples/DXFeedCandleChart/Preview Content\"";
DEVELOPMENT_ASSET_PATHS = "";
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
Expand Down Expand Up @@ -3067,7 +3073,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Samples/DXFeedCandleChart/Preview Content\"";
DEVELOPMENT_ASSET_PATHS = "";
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
Expand Down
71 changes: 42 additions & 29 deletions Samples/DXFeedCandleChart/CandleStickChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ extension StockPrice {
}

var accessibilityDescription: String {
return "Open: \(self.open.formatted(currency: currency)), Close: \(self.close.formatted(currency: currency)), High: \(self.high.formatted(currency: currency)), Low: \(self.low.formatted(currency: currency))"
return """
Open: \(self.open.formatted(currency: currency)), \
Close: \(self.close.formatted(currency: currency)), \
High: \(self.high.formatted(currency: currency)), \
Low: \(self.low.formatted(currency: currency))
"""
}
}

Expand Down Expand Up @@ -93,16 +98,13 @@ class CandleList: ObservableObject, SnapshotDelegate {
let candle = event.candle
result.append(candle)
}
if isSnapshot {
DispatchQueue.main.async {
DispatchQueue.main.async {
if isSnapshot {
self.candles = result.map({ candle in
let price = StockPrice(candle: candle, currency: self.currency)
return price
})
}

} else {
DispatchQueue.main.async {
} else {
result.forEach { candle in
let newPrice = StockPrice(candle: candle, currency: self.currency)
if let index = self.candles.firstIndex(where: { price in
Expand Down Expand Up @@ -193,45 +195,53 @@ struct CandleStickChart: View {
self.symbol = symbol
self.list = CandleList(symbol: symbol)
self.list.updateDate(date: self.date, type: self.type)

}

var body: some View {
GeometryReader { reader in
List {

Section {
DatePicker(
"Start Date",
selection: $date,
displayedComponents: [.date]
).onChange(of: date) { oldValue, newValue in
selectedPrice = nil
xAxisValues = CandleStickChart.calculateXaxisValues(firstValue: newValue)
list.updateDate(date: newValue,type: type)
}
Picker("Type", selection: $type) {
chart.frame(height: max(reader.size.height/2, 300))
}.listRowBackground(Color.cellBackground)


Section("Chart parameters") {
Picker("Candle type", selection: $type) {
ForEach(CandleType.allCases, id: \.self) { category in
Text(String(describing: category).capitalized).tag(category)
}
}.onChange(of: type) { oldValue, newValue in
selectedPrice = nil
list.updateDate(date: date, type: newValue)
}.pickerStyle(SegmentedPickerStyle())

.foregroundStyle(.text)
DatePicker(
selection: $date,
displayedComponents: [.date]
){
Text("Choose from time")
}.onChange(of: date) { oldValue, newValue in
selectedPrice = nil
xAxisValues = CandleStickChart.calculateXaxisValues(firstValue: newValue)
list.updateDate(date: newValue,type: type)
}
.datePickerStyle(.compact)
.foregroundStyle(.text)

}
Section {
chart.frame(height: reader.size.height/2)
}
Section {
Text("""
Symbol: \(symbol)
Type: \(String(describing: type).capitalized)
Description: \(list.descriptionString)
From time: \(date)
""" )
.font(.callout)
}
.listRowBackground(Color.cellBackground)
.listRowSeparator(.hidden)
}
.preferredColorScheme(.dark)
.background(.tableBackground)
.scrollContentBackground(.hidden)

}
}

private var chart: some View {
Chart($list.candles) { binding in
let price = binding.wrappedValue
Expand Down Expand Up @@ -307,9 +317,11 @@ From time: \(date)
.frame(width: boxWidth, alignment: .leading)
.background {
RoundedRectangle(cornerRadius: 13)
.fill(Color.priceBackground)
.foregroundStyle(.thickMaterial)
.padding(.horizontal, -8)
.padding(.vertical, -4)

}
.offset(x: boxOffset)
.gesture(
Expand Down Expand Up @@ -472,4 +484,5 @@ struct CandleInfoView: View {
.font(.headline)
.padding(.vertical)
}

}
3 changes: 2 additions & 1 deletion Samples/DXFeedCandleChart/DXFeedCandleChartApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import SwiftUI
struct DXFeedCandleChartApp: App {
var body: some Scene {
WindowGroup {
CandleStickChart(symbol: "ETH/USD:GDAX")
CandleStickChart(symbol: "AAPL")
}
}
}




0 comments on commit 0e88a91

Please sign in to comment.