How to draw incoming data gradually?
- Dominant language
- Swift
- Stars
- 28k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Hello guys,
It's just a question. Sorry if this is a repetition. The problem is I can't manage to draw incoming data step by step. I can't find such a flag. Now entries are coming gradually - not all at once. But sdk renders them across the full width of the chart view straight away despite the count of them. I need them to draw dot by dot from left to right and only after reaching right edge to start scaling. It seems that there is such bool flag, but I didn't manage to fine it. I would appreciate any help. Below the code.
```
import UIKit
import Charts
import RxSwift
import RxCocoa
struct ChartViewModel {
let blueValue: Driver
}
final class ChartView: UIView {
private lazy var blueSet = makeEmptySet(color: .blue)
private lazy var blueLineCharView = makeChartView()
private let bag = DisposeBag()
init(model: ChartViewModel) {
super.init(frame: .zero)
setup()
setupConstraints()
bind(model)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setup() {
backgroundColor = .clear
addSubview(blueLineCharView)
}
private func setupConstraints() {
blueLineCharView.make {
$0.edges.equalToSuperview()
}
}
private func bind(_ model: ChartViewModel) {
model.blueValue.drive(onNext: { [weak self] value in
guard let self = self, let value = value else { return }
self.blueSet.append(value)
self.blueLineCharView.data = LineChartData(dataSet: self.blueSet)
})
.disposed(by: bag)
}
private func makeChartView() -> LineChartView {
let chartView = LineChartView()
chartView.backgroundColor = .clear
chartView.leftAxis.enabled = false
chartView.rightAxis.enabled = false
chartView.xAxis.enabled = false
chartView.isUserInteractionEnabled = false
chartView.legend.enabled = false
chartView.dragEnabled = false
return chartView
}
private func makeEmptySet(color: UIColor) -> LineChartDataSet {
let set = LineChartDataSet(entries: [])
set.drawCirclesEnabled = false
set.drawValuesEnabled = false
set.mode = .cubicBezier
set.lineWidth = 2
set.setColor(color)
set.drawVerticalHighlightIndicatorEnabled = false
set.drawHorizontalHighlightIndicatorEnabled = false
return set
}
}
```
Contributor guide
Research direction
Start by tracing the LineChartView update path and the LineChartDataSet.append usage shown in the example, then check how the chart viewport and x-axis bounds are calculated as entries arrive. Done means confirming whether the requested left-to-right growth and post-edge scaling are supported and identifying the relevant setting or documenting that it requires a library change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- data-visualization, mobile-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100