Skip to content

Commit

Permalink
refactoring candle view
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed May 22, 2024
1 parent 6cbb6e2 commit 35c56b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
16 changes: 3 additions & 13 deletions Samples/DXFeedCandleChartMac/CandleChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,7 @@ struct CandleChart: View {
}
}

func getYScale() -> ClosedRange<Double> {
if list.candles.count == 0 {
return 0...0
}
if type == .minute {
return list.minValue...list.maxValue
} else {
return (list.minValue*0.95)...list.maxValue*1.05
}
}


private var chart: some View {
Chart($list.candles) { binding in
Expand All @@ -154,7 +145,7 @@ struct CandleChart: View {
.chartXScale(domain: .automatic(dataType: String.self) { dates in
dates = list.xValues
})
.chartYScale(domain: getYScale())
.chartYScale(domain: list.yScale())
.chartYAxis { AxisMarks(preset: .extended) }
.chartXAxis {
if list.loadingInProgress {
Expand Down Expand Up @@ -325,8 +316,7 @@ struct CandlePlot: ChartContent {
}()
}

// MARK: - Detail Info View about candle

// MARK: - Info View with Prices
struct CandleInfoView: View {
let price: CandleModel
let currency: String
Expand Down
15 changes: 13 additions & 2 deletions Samples/DXFeedCandleChartMac/CandleChartModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class CandleChartModel: ObservableObject {
@Published var xAxisLabels = [String]()
var xValues = [String]()

var maxValue: Double = 0
var minValue: Double = Double.greatestFiniteMagnitude
private var maxValue: Double = 0
private var minValue: Double = Double.greatestFiniteMagnitude
var type = CandlePickerType.year

var loadingInProgress = false
Expand Down Expand Up @@ -122,6 +122,17 @@ class CandleChartModel: ObservableObject {
return pointsOnScreen
}

func yScale() -> ClosedRange<Double> {
if candles.count == 0 {
return 0...0
}
if type == .minute {
return minValue...maxValue
} else {
return (minValue*0.95)...maxValue*1.05
}
}

private static func calculateXaxisValues(with type: CandlePickerType, values: [CandleModel]) -> [String] {
var visiblePages: Double = 1
let valuesCount = values.count
Expand Down

0 comments on commit 35c56b9

Please sign in to comment.