Chart fixes

This commit is contained in:
Ilya Laktyushin 2020-03-25 20:44:20 +04:00
parent 79024f66f1
commit e854d7b4fa
27 changed files with 143 additions and 61 deletions

View File

@ -1044,7 +1044,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
case .groupReference: case .groupReference:
gesture?.cancel() gesture?.cancel()
} }
}, present: { [weak self] c in }, present: { c in
present(c) present(c)
}) })
self.interaction = interaction self.interaction = interaction

View File

@ -78,15 +78,17 @@ public struct ChartDetailsViewModel {
public internal(set) var title: String public internal(set) var title: String
public internal(set) var showArrow: Bool public internal(set) var showArrow: Bool
public internal(set) var showPrefixes: Bool public internal(set) var showPrefixes: Bool
public internal(set) var isLoading: Bool
public internal(set) var values: [Value] public internal(set) var values: [Value]
public internal(set) var totalValue: Value? public internal(set) var totalValue: Value?
public internal(set) var tapAction: (() -> Void)? public internal(set) var tapAction: (() -> Void)?
public internal(set) var hideAction: (() -> Void)? public internal(set) var hideAction: (() -> Void)?
static let blank = ChartDetailsViewModel(title: "", showArrow: false, showPrefixes: false, values: [], totalValue: nil, tapAction: nil, hideAction: nil) static let blank = ChartDetailsViewModel(title: "", showArrow: false, showPrefixes: false, isLoading: false, values: [], totalValue: nil, tapAction: nil, hideAction: nil)
public init(title: String, public init(title: String,
showArrow: Bool, showArrow: Bool,
showPrefixes: Bool, showPrefixes: Bool,
isLoading: Bool,
values: [Value], values: [Value],
totalValue: Value?, totalValue: Value?,
tapAction: (() -> Void)?, tapAction: (() -> Void)?,
@ -94,6 +96,7 @@ public struct ChartDetailsViewModel {
self.title = title self.title = title
self.showArrow = showArrow self.showArrow = showArrow
self.showPrefixes = showPrefixes self.showPrefixes = showPrefixes
self.isLoading = isLoading
self.values = values self.values = values
self.totalValue = totalValue self.totalValue = totalValue
self.tapAction = tapAction self.tapAction = tapAction

View File

@ -36,7 +36,7 @@ public struct ChartsCollection {
} }
public extension ChartsCollection { public extension ChartsCollection {
public init(from decodedData: [String: Any]) throws { init(from decodedData: [String: Any]) throws {
guard let columns = decodedData["columns"] as? [[Any]] else { guard let columns = decodedData["columns"] as? [[Any]] else {
throw ChartsError.generalConversion("Unable to get columns from: \(decodedData)") throw ChartsError.generalConversion("Unable to get columns from: \(decodedData)")
} }

View File

@ -137,7 +137,7 @@ public class BaseChartController: ChartThemeContainer {
} }
public var isChartRangePagingEnabled: Bool = false public var isChartRangePagingEnabled: Bool = false
public var minimumSelectedChartRange: CGFloat = 0.05 public var minimumSelectedChartRange: CGFloat = 0.085
public var chartRangePagingClosure: ((Bool, CGFloat) -> Void)? // isEnabled, PageSize public var chartRangePagingClosure: ((Bool, CGFloat) -> Void)? // isEnabled, PageSize
public func setChartRangePagingEnabled(isEnabled: Bool, minimumSelectionSize: CGFloat) { public func setChartRangePagingEnabled(isEnabled: Bool, minimumSelectionSize: CGFloat) {
isChartRangePagingEnabled = isEnabled isChartRangePagingEnabled = isEnabled
@ -178,7 +178,7 @@ public class BaseChartController: ChartThemeContainer {
public var setBackButtonVisibilityClosure: ((Bool, Bool) -> Void)? public var setBackButtonVisibilityClosure: ((Bool, Bool) -> Void)?
public var refreshChartToolsClosure: ((Bool) -> Void)? public var refreshChartToolsClosure: ((Bool) -> Void)?
public func didTapZoomIn(date: Date) { public func didTapZoomIn(date: Date, pointIndex: Int) {
fatalError("Abstract") fatalError("Abstract")
} }

View File

@ -24,6 +24,7 @@ class GeneralChartComponentController: ChartThemeContainer {
var lastChartInteractionPoint: CGPoint = .zero var lastChartInteractionPoint: CGPoint = .zero
var isChartInteractionBegun: Bool = false var isChartInteractionBegun: Bool = false
var isChartInteracting: Bool = false var isChartInteracting: Bool = false
var ignoreInteraction: Bool = false
let isZoomed: Bool let isZoomed: Bool
var isZoomable = true var isZoomable = true
@ -169,6 +170,14 @@ class GeneralChartComponentController: ChartThemeContainer {
} }
func chartInteractionDidBegin(point: CGPoint) { func chartInteractionDidBegin(point: CGPoint) {
guard !ignoreInteraction else {
return
}
if !isChartInteractionBegun && detailsVisible {
self.hideDetailsView(animated: true)
ignoreInteraction = true
return
}
let chartFrame = self.chartFrame() let chartFrame = self.chartFrame()
guard chartFrame.width > 0 else { return } guard chartFrame.width > 0 else { return }
let horizontalRange = currentHorizontalMainChartRange let horizontalRange = currentHorizontalMainChartRange
@ -185,19 +194,24 @@ class GeneralChartComponentController: ChartThemeContainer {
showDetailsView(at: chartValue, detailsViewPosition: detailsViewPosition, dataIndex: minIndex, date: closestDate, animted: chartWasInteracting) showDetailsView(at: chartValue, detailsViewPosition: detailsViewPosition, dataIndex: minIndex, date: closestDate, animted: chartWasInteracting)
} }
var detailsVisible = false
func showDetailsView(at chartPosition: CGFloat, detailsViewPosition: CGFloat, dataIndex: Int, date: Date, animted: Bool) { func showDetailsView(at chartPosition: CGFloat, detailsViewPosition: CGFloat, dataIndex: Int, date: Date, animted: Bool) {
setDetailsViewModel?(chartDetailsViewModel(closestDate: date, pointIndex: dataIndex), animted) setDetailsViewModel?(chartDetailsViewModel(closestDate: date, pointIndex: dataIndex), animted)
setDetailsChartVisibleClosure?(true, true) setDetailsChartVisibleClosure?(true, true)
setDetailsViewPositionClosure?(detailsViewPosition) setDetailsViewPositionClosure?(detailsViewPosition)
detailsVisible = true
} }
func chartInteractionDidEnd() { func chartInteractionDidEnd() {
isChartInteractionBegun = false
isChartInteracting = false isChartInteracting = false
ignoreInteraction = false
} }
func hideDetailsView(animated: Bool) { func hideDetailsView(animated: Bool) {
isChartInteractionBegun = false isChartInteractionBegun = false
setDetailsChartVisibleClosure?(false, animated) setDetailsChartVisibleClosure?(false, animated)
detailsVisible = false
} }
var visibleDetailsChartValues: [ChartsCollection.Chart] { var visibleDetailsChartValues: [ChartsCollection.Chart] {
@ -323,13 +337,13 @@ class GeneralChartComponentController: ChartThemeContainer {
let viewModel = ChartDetailsViewModel(title: dateString, let viewModel = ChartDetailsViewModel(title: dateString,
showArrow: self.isZoomable && !self.isZoomed, showArrow: self.isZoomable && !self.isZoomed,
showPrefixes: false, showPrefixes: false,
isLoading: false,
values: values, values: values,
totalValue: nil, totalValue: nil,
tapAction: { [weak self] in tapAction: { [weak self] in
self?.zoomInOnDateClosure?(closestDate) }, self?.zoomInOnDateClosure?(closestDate) },
hideAction: { [weak self] in hideAction: { [weak self] in
self?.setDetailsChartVisibleClosure?(false, true) self?.setDetailsChartVisibleClosure?(false, true)
}) })
return viewModel return viewModel
} }
@ -338,11 +352,11 @@ class GeneralChartComponentController: ChartThemeContainer {
let fromDate = Date(timeIntervalSince1970: TimeInterval(currentHorizontalMainChartRange.lowerBound) + 1) let fromDate = Date(timeIntervalSince1970: TimeInterval(currentHorizontalMainChartRange.lowerBound) + 1)
let toDate = Date(timeIntervalSince1970: TimeInterval(currentHorizontalMainChartRange.upperBound)) let toDate = Date(timeIntervalSince1970: TimeInterval(currentHorizontalMainChartRange.upperBound))
if Calendar.utc.startOfDay(for: fromDate) == Calendar.utc.startOfDay(for: toDate) { if Calendar.utc.startOfDay(for: fromDate) == Calendar.utc.startOfDay(for: toDate) {
let stirng = BaseConstants.headerFullZoomedFormatter.string(from: fromDate) let string = BaseConstants.headerFullZoomedFormatter.string(from: fromDate)
self.setChartTitleClosure?(stirng, animated) self.setChartTitleClosure?(string, animated)
} else { } else {
let stirng = "\(BaseConstants.headerMediumRangeFormatter.string(from: fromDate)) - \(BaseConstants.headerMediumRangeFormatter.string(from: toDate))" let string = "\(BaseConstants.headerMediumRangeFormatter.string(from: fromDate)) - \(BaseConstants.headerMediumRangeFormatter.string(from: toDate))"
self.setChartTitleClosure?(stirng, animated) self.setChartTitleClosure?(string, animated)
} }
} }
} }

View File

@ -18,6 +18,7 @@ public class BaseLinesChartController: BaseChartController {
var zoomChartVisibility: [Bool] var zoomChartVisibility: [Bool]
var lastChartInteractionPoint: CGPoint = .zero var lastChartInteractionPoint: CGPoint = .zero
var isChartInteractionBegun: Bool = false var isChartInteractionBegun: Bool = false
var ignoreInteraction: Bool = false
var initialChartRange: ClosedRange<CGFloat> = BaseConstants.defaultRange var initialChartRange: ClosedRange<CGFloat> = BaseConstants.defaultRange
var zoomedChartRange: ClosedRange<CGFloat> = BaseConstants.defaultRange var zoomedChartRange: ClosedRange<CGFloat> = BaseConstants.defaultRange
@ -71,7 +72,8 @@ public class BaseLinesChartController: BaseChartController {
} }
public override func chartInteractionDidEnd() { public override func chartInteractionDidEnd() {
isChartInteractionBegun = false
ignoreInteraction = false
} }
public override func cancelChartInteraction() { public override func cancelChartInteraction() {
@ -98,7 +100,7 @@ public class BaseLinesChartController: BaseChartController {
} }
func chartDetailsViewModel(closestDate: Date, pointIndex: Int) -> ChartDetailsViewModel { func chartDetailsViewModel(closestDate: Date, pointIndex: Int, loading: Bool) -> ChartDetailsViewModel {
let values: [ChartDetailsViewModel.Value] = actualChartsCollection.chartValues.enumerated().map { arg in let values: [ChartDetailsViewModel.Value] = actualChartsCollection.chartValues.enumerated().map { arg in
let (index, component) = arg let (index, component) = arg
return ChartDetailsViewModel.Value(prefix: nil, return ChartDetailsViewModel.Value(prefix: nil,
@ -118,20 +120,25 @@ public class BaseLinesChartController: BaseChartController {
let viewModel = ChartDetailsViewModel(title: dateString, let viewModel = ChartDetailsViewModel(title: dateString,
showArrow: total > 0 && self.isZoomable && !self.isZoomed, showArrow: total > 0 && self.isZoomable && !self.isZoomed,
showPrefixes: false, showPrefixes: false,
isLoading: loading,
values: values, values: values,
totalValue: nil, totalValue: nil,
tapAction: { [weak self] in self?.didTapZoomIn(date: closestDate) }, tapAction: { [weak self] in
hideAction: { [weak self] in self?.didTapZoomIn(date: closestDate, pointIndex: pointIndex)
self?.setDetailsChartVisibleClosure?(false, true) }, hideAction: { [weak self] in
self?.cancelChartInteraction()
}) })
return viewModel return viewModel
} }
public override func didTapZoomIn(date: Date) { public override func didTapZoomIn(date: Date, pointIndex: Int) {
guard isZoomed == false else { return } guard isZoomed == false else { return }
cancelChartInteraction()
setDetailsViewModel?(chartDetailsViewModel(closestDate: date, pointIndex: pointIndex, loading: true), false)
self.getDetailsData?(date, { updatedCollection in self.getDetailsData?(date, { updatedCollection in
if let updatedCollection = updatedCollection { if let updatedCollection = updatedCollection {
self.cancelChartInteraction()
self.initialChartRange = self.currentHorizontalRange self.initialChartRange = self.currentHorizontalRange
if let startDate = updatedCollection.axisValues.first, if let startDate = updatedCollection.axisValues.first,
let endDate = updatedCollection.axisValues.last { let endDate = updatedCollection.axisValues.last {

View File

@ -122,14 +122,22 @@ public class GeneralLinesChartController: BaseLinesChartController {
} }
public override func chartInteractionDidBegin(point: CGPoint) { public override func chartInteractionDidBegin(point: CGPoint) {
guard !ignoreInteraction else {
return
}
if !isChartInteractionBegun && !self.verticalLineRenderer.values.isEmpty {
self.cancelChartInteraction()
ignoreInteraction = true
return
}
let horizontalRange = mainLinesRenderer.horizontalRange.current let horizontalRange = mainLinesRenderer.horizontalRange.current
let chartFrame = self.chartFrame() let chartFrame = self.chartFrame()
guard chartFrame.width > 0 else { return } guard chartFrame.width > 0 else { return }
let chartInteractionWasBegin = isChartInteractionBegun
let dateToFind = Date(timeIntervalSince1970: TimeInterval(horizontalRange.distance * point.x + horizontalRange.lowerBound)) let dateToFind = Date(timeIntervalSince1970: TimeInterval(horizontalRange.distance * point.x + horizontalRange.lowerBound))
guard let (closestDate, minIndex) = findClosestDateTo(dateToFind: dateToFind) else { return } guard let (closestDate, minIndex) = findClosestDateTo(dateToFind: dateToFind) else { return }
let chartInteractionWasBegin = isChartInteractionBegun
super.chartInteractionDidBegin(point: point) super.chartInteractionDidBegin(point: point)
self.lineBulletsRenderer.bullets = chartLines.compactMap { chart in self.lineBulletsRenderer.bullets = chartLines.compactMap { chart in
@ -139,7 +147,7 @@ public class GeneralLinesChartController: BaseLinesChartController {
let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970) let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970)
let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX
self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex), chartInteractionWasBegin) self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex, loading: false), chartInteractionWasBegin)
self.setDetailsChartVisibleClosure?(true, true) self.setDetailsChartVisibleClosure?(true, true)
self.setDetailsViewPositionClosure?(detailsViewPosition) self.setDetailsViewPositionClosure?(detailsViewPosition)
self.verticalLineRenderer.values = [chartValue] self.verticalLineRenderer.values = [chartValue]

View File

@ -149,6 +149,14 @@ public class TwoAxisLinesChartController: BaseLinesChartController {
} }
public override func chartInteractionDidBegin(point: CGPoint) { public override func chartInteractionDidBegin(point: CGPoint) {
guard !ignoreInteraction else {
return
}
if !isChartInteractionBegun && !self.verticalLineRenderer.values.isEmpty {
self.cancelChartInteraction()
ignoreInteraction = true
return
}
let horizontalRange = currentHorizontalRange let horizontalRange = currentHorizontalRange
let chartFrame = self.chartFrame() let chartFrame = self.chartFrame()
guard chartFrame.width > 0 else { return } guard chartFrame.width > 0 else { return }
@ -168,7 +176,7 @@ public class TwoAxisLinesChartController: BaseLinesChartController {
let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970) let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970)
let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX
self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex), chartInteractionWasBegin) self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex, loading: false), chartInteractionWasBegin)
self.setDetailsChartVisibleClosure?(true, true) self.setDetailsChartVisibleClosure?(true, true)
self.setDetailsViewPositionClosure?(detailsViewPosition) self.setDetailsViewPositionClosure?(detailsViewPosition)
self.verticalLineRenderer.values = [chartValue] self.verticalLineRenderer.values = [chartValue]

View File

@ -153,6 +153,7 @@ class PercentChartComponentController: GeneralChartComponentController {
let viewModel = ChartDetailsViewModel(title: dateString, let viewModel = ChartDetailsViewModel(title: dateString,
showArrow: total > 0 && self.isZoomable && !self.isZoomed, showArrow: total > 0 && self.isZoomable && !self.isZoomed,
showPrefixes: true, showPrefixes: true,
isLoading: false,
values: values, values: values,
totalValue: nil, totalValue: nil,
tapAction: { [weak self] in tapAction: { [weak self] in

View File

@ -48,7 +48,7 @@ public class PercentPieChartController: BaseChartController {
controller.chartFrame = { [unowned self] in self.chartFrame() } controller.chartFrame = { [unowned self] in self.chartFrame() }
controller.cartViewBounds = { [unowned self] in self.cartViewBounds() } controller.cartViewBounds = { [unowned self] in self.cartViewBounds() }
controller.zoomInOnDateClosure = { [unowned self] date in controller.zoomInOnDateClosure = { [unowned self] date in
self.didTapZoomIn(date: date) self.didTapZoomIn(date: date, pointIndex: 0)
} }
controller.setChartTitleClosure = { [unowned self] (title, animated) in controller.setChartTitleClosure = { [unowned self] (title, animated) in
self.setChartTitleClosure?(title, animated) self.setChartTitleClosure?(title, animated)
@ -272,7 +272,7 @@ public class PercentPieChartController: BaseChartController {
switchToChart(chartsCollection: newCollection, isZoomed: true, animated: true) switchToChart(chartsCollection: newCollection, isZoomed: true, animated: true)
} }
public override func didTapZoomIn(date: Date) { public override func didTapZoomIn(date: Date, pointIndex: Int) {
self.didTapZoomIn(date: date, animated: true) self.didTapZoomIn(date: date, animated: true)
} }

View File

@ -150,6 +150,7 @@ class PieChartComponentController: GeneralChartComponentController {
let viewModel = ChartDetailsViewModel(title: "", let viewModel = ChartDetailsViewModel(title: "",
showArrow: false, showArrow: false,
showPrefixes: false, showPrefixes: false,
isLoading: false,
values: [ChartDetailsViewModel.Value(prefix: nil, values: [ChartDetailsViewModel.Value(prefix: nil,
title: title, title: title,
value: valueString, value: valueString,

View File

@ -40,7 +40,7 @@ public class DailyBarsChartController: BaseChartController {
controller.chartFrame = { [unowned self] in self.chartFrame() } controller.chartFrame = { [unowned self] in self.chartFrame() }
controller.cartViewBounds = { [unowned self] in self.cartViewBounds() } controller.cartViewBounds = { [unowned self] in self.cartViewBounds() }
controller.zoomInOnDateClosure = { [unowned self] date in controller.zoomInOnDateClosure = { [unowned self] date in
self.didTapZoomIn(date: date) self.didTapZoomIn(date: date, pointIndex: 0)
} }
controller.setChartTitleClosure = { [unowned self] (title, animated) in controller.setChartTitleClosure = { [unowned self] (title, animated) in
self.setChartTitleClosure?(title, animated) self.setChartTitleClosure?(title, animated)
@ -205,7 +205,7 @@ public class DailyBarsChartController: BaseChartController {
} }
} }
public override func didTapZoomIn(date: Date) { public override func didTapZoomIn(date: Date, pointIndex: Int) {
guard isZoomed == false else { return } guard isZoomed == false else { return }
if isZoomed { if isZoomed {
return linesController.hideDetailsView(animated: true) return linesController.hideDetailsView(animated: true)

View File

@ -43,7 +43,7 @@ public class StackedBarsChartController: BaseChartController {
controller.chartFrame = { [unowned self] in self.chartFrame() } controller.chartFrame = { [unowned self] in self.chartFrame() }
controller.cartViewBounds = { [unowned self] in self.cartViewBounds() } controller.cartViewBounds = { [unowned self] in self.cartViewBounds() }
controller.zoomInOnDateClosure = { [unowned self] date in controller.zoomInOnDateClosure = { [unowned self] date in
self.didTapZoomIn(date: date) self.didTapZoomIn(date: date, pointIndex: 0)
} }
controller.setChartTitleClosure = { [unowned self] (title, animated) in controller.setChartTitleClosure = { [unowned self] (title, animated) in
self.setChartTitleClosure?(title, animated) self.setChartTitleClosure?(title, animated)
@ -220,7 +220,7 @@ public class StackedBarsChartController: BaseChartController {
} }
} }
public override func didTapZoomIn(date: Date) { public override func didTapZoomIn(date: Date, pointIndex: Int) {
guard isZoomed == false else { return } guard isZoomed == false else { return }
if isZoomed { if isZoomed {
return zoomedBarsController.hideDetailsView(animated: true) return zoomedBarsController.hideDetailsView(animated: true)

View File

@ -43,7 +43,7 @@ public class StepBarsChartController: BaseChartController {
controller.chartFrame = { [unowned self] in self.chartFrame() } controller.chartFrame = { [unowned self] in self.chartFrame() }
controller.cartViewBounds = { [unowned self] in self.cartViewBounds() } controller.cartViewBounds = { [unowned self] in self.cartViewBounds() }
controller.zoomInOnDateClosure = { [unowned self] date in controller.zoomInOnDateClosure = { [unowned self] date in
self.didTapZoomIn(date: date) self.didTapZoomIn(date: date, pointIndex: 0)
} }
controller.setChartTitleClosure = { [unowned self] (title, animated) in controller.setChartTitleClosure = { [unowned self] (title, animated) in
self.setChartTitleClosure?("", animated) self.setChartTitleClosure?("", animated)
@ -228,7 +228,7 @@ public class StepBarsChartController: BaseChartController {
} }
} }
public override func didTapZoomIn(date: Date) { public override func didTapZoomIn(date: Date, pointIndex: Int) {
guard isZoomed == false else { return } guard isZoomed == false else { return }
if isZoomed { if isZoomed {
return zoomedBarsController.hideDetailsView(animated: true) return zoomedBarsController.hideDetailsView(animated: true)

View File

@ -152,6 +152,15 @@ public class TwoAxisStepBarsChartController: BaseLinesChartController {
} }
public override func chartInteractionDidBegin(point: CGPoint) { public override func chartInteractionDidBegin(point: CGPoint) {
guard !ignoreInteraction else {
return
}
if !isChartInteractionBegun && !self.verticalLineRenderer.values.isEmpty {
self.cancelChartInteraction()
ignoreInteraction = true
return
}
let horizontalRange = currentHorizontalRange let horizontalRange = currentHorizontalRange
let chartFrame = self.chartFrame() let chartFrame = self.chartFrame()
guard chartFrame.width > 0 else { return } guard chartFrame.width > 0 else { return }
@ -183,8 +192,8 @@ public class TwoAxisStepBarsChartController: BaseLinesChartController {
} }
let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970) let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970)
let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX + barOffset
self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex), chartInteractionWasBegin) self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex, loading: false), chartInteractionWasBegin)
self.setDetailsChartVisibleClosure?(true, true) self.setDetailsChartVisibleClosure?(true, true)
self.setDetailsViewPositionClosure?(detailsViewPosition) self.setDetailsViewPositionClosure?(detailsViewPosition)
self.verticalLineRenderer.values = [chartValue] self.verticalLineRenderer.values = [chartValue]

View File

@ -39,6 +39,9 @@ class PieChartRenderer: BaseChartRenderer {
} }
private(set) var selectedSegment: Int? private(set) var selectedSegment: Int?
func selectSegmentAt(at indexToSelect: Int?, animated: Bool) { func selectSegmentAt(at indexToSelect: Int?, animated: Bool) {
guard selectedSegment != indexToSelect else {
return
}
selectedSegment = indexToSelect selectedSegment = indexToSelect
for (index, animator) in setlectedSegmentsAnimators.enumerated() { for (index, animator) in setlectedSegmentsAnimators.enumerated() {
let fraction: CGFloat = (index == indexToSelect) ? 1.0 : 0.0 let fraction: CGFloat = (index == indexToSelect) ? 1.0 : 0.0

View File

@ -49,6 +49,7 @@ class ChartDetailsView: UIControl {
addSubview(titleLabel) addSubview(titleLabel)
addSubview(arrowView) addSubview(arrowView)
addSubview(arrowButton) addSubview(arrowButton)
addSubview(activityIndicator)
} }
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
@ -60,21 +61,32 @@ class ChartDetailsView: UIControl {
titleLabel.setText(viewModel.title, animated: false) titleLabel.setText(viewModel.title, animated: false)
titleLabel.setVisible(!viewModel.title.isEmpty, animated: false) titleLabel.setVisible(!viewModel.title.isEmpty, animated: false)
arrowView.setVisible(viewModel.showArrow, animated: false) arrowView.setVisible(viewModel.showArrow && !viewModel.isLoading, animated: false)
arrowButton.isUserInteractionEnabled = viewModel.showArrow arrowButton.isUserInteractionEnabled = viewModel.showArrow && !viewModel.isLoading
self.isEnabled = !viewModel.isLoading
if viewModel.isLoading {
activityIndicator.isHidden = false
activityIndicator.startAnimating()
} else {
activityIndicator.isHidden = true
activityIndicator.stopAnimating()
}
let width: CGFloat = margin * 2 + (viewModel.showPrefixes ? (prefixLabelWidth + margin) : 0) + textLabelWidth + valueLabelWidth let width: CGFloat = margin * 2 + (viewModel.showPrefixes ? (prefixLabelWidth + margin) : 0) + textLabelWidth + valueLabelWidth
var y: CGFloat = verticalMargins var y: CGFloat = verticalMargins
if (!viewModel.title.isEmpty || viewModel.showArrow) { if (!viewModel.title.isEmpty || viewModel.showArrow) {
titleLabel.frame = CGRect(x: margin, y: y, width: width, height: labelHeight) titleLabel.frame = CGRect(x: margin, y: y, width: width, height: labelHeight)
arrowView.frame = CGRect(x: width - 6 - margin, y: margin, width: 6, height: 10) arrowView.frame = CGRect(x: width - 6 - margin, y: margin + 2, width: 6, height: 10)
activityIndicator.transform = CGAffineTransform(scaleX: 0.65, y: 0.65)
activityIndicator.center = CGPoint(x: width - 3 - margin, y: 16.0)
y += labelHeight y += labelHeight
} }
let labelsCount: Int = viewModel.values.count + ((viewModel.totalValue == nil) ? 0 : 1) let labelsCount: Int = viewModel.values.count + ((viewModel.totalValue == nil) ? 0 : 1)
arrowButton.frame = CGRect(x: 0.0, y: 0.0, width: width, height: 30.0)
setLabelsCount(array: &prefixViews, setLabelsCount(array: &prefixViews,
count: viewModel.showPrefixes ? labelsCount : 0, count: viewModel.showPrefixes ? labelsCount : 0,
font: UIFont.systemFont(ofSize: 12, weight: .bold)) font: UIFont.systemFont(ofSize: 12, weight: .bold))
@ -143,12 +155,13 @@ class ChartDetailsView: UIControl {
} }
}) })
self.textHeight = textHeight self.textHeight = textHeight
arrowButton.frame = CGRect(x: 0.0, y: 0.0, width: width, height: y)
} }
override var intrinsicContentSize: CGSize { override var intrinsicContentSize: CGSize {
if let viewModel = viewModel { if let viewModel = viewModel {
var height = ((!viewModel.title.isEmpty || viewModel.showArrow) ? labelHeight : 0) + var height = ((!viewModel.title.isEmpty || viewModel.showArrow) ? labelHeight : 0) +
// (CGFloat(viewModel.values.filter({ $0.visible }).count) * labelHeight) +
(viewModel.totalValue?.visible == true ? labelHeight : 0) + (viewModel.totalValue?.visible == true ? labelHeight : 0) +
verticalMargins * 2 verticalMargins * 2
@ -206,6 +219,7 @@ extension ChartDetailsView: ChartThemeContainer {
} }
UIView.perform(animated: animated) { UIView.perform(animated: animated) {
self.arrowView.tintColor = theme.chartDetailsArrowColor self.arrowView.tintColor = theme.chartDetailsArrowColor
self.activityIndicator.color = theme.chartDetailsArrowColor
self.backgroundColor = theme.chartDetailsViewColor self.backgroundColor = theme.chartDetailsViewColor
} }
} }

View File

@ -57,7 +57,7 @@ public extension ChartTheme {
context.addLine(to: CGPoint(x: 110.0, y: 21.0)) context.addLine(to: CGPoint(x: 110.0, y: 21.0))
context.addLine(to: CGPoint(x: 107.0, y: 25.0)) context.addLine(to: CGPoint(x: 107.0, y: 25.0))
context.strokePath() context.strokePath()
})?.resizableImage(withCapInsets: UIEdgeInsets(top: 15.0, left: 15.0, bottom: 15.0, right: 15.0), resizingMode: .stretch) })?.resizableImage(withCapInsets: UIEdgeInsets(top: 15.0, left: 11.0, bottom: 15.0, right: 11.0), resizingMode: .stretch)
self.init(chartTitleColor: presentationTheme.list.itemPrimaryTextColor, actionButtonColor: presentationTheme.list.itemAccentColor, chartBackgroundColor: presentationTheme.list.itemBlocksBackgroundColor, chartLabelsColor: presentationTheme.chart.labelsColor, chartHelperLinesColor: presentationTheme.chart.helperLinesColor, chartStrongLinesColor: presentationTheme.chart.strongLinesColor, barChartStrongLinesColor: presentationTheme.chart.barStrongLinesColor, chartDetailsTextColor: presentationTheme.chart.detailsTextColor, chartDetailsArrowColor: presentationTheme.chart.detailsArrowColor, chartDetailsViewColor: presentationTheme.chart.detailsViewColor, rangeViewFrameColor: rangeViewFrameColor, rangeViewTintColor: presentationTheme.list.blocksBackgroundColor.withAlphaComponent(0.5), rangeViewMarkerColor: rangeViewMarkerColor, rangeCropImage: rangeImage) self.init(chartTitleColor: presentationTheme.list.itemPrimaryTextColor, actionButtonColor: presentationTheme.list.itemAccentColor, chartBackgroundColor: presentationTheme.list.itemBlocksBackgroundColor, chartLabelsColor: presentationTheme.chart.labelsColor, chartHelperLinesColor: presentationTheme.chart.helperLinesColor, chartStrongLinesColor: presentationTheme.chart.strongLinesColor, barChartStrongLinesColor: presentationTheme.chart.barStrongLinesColor, chartDetailsTextColor: presentationTheme.chart.detailsTextColor, chartDetailsArrowColor: presentationTheme.chart.detailsArrowColor, chartDetailsViewColor: presentationTheme.chart.detailsViewColor, rangeViewFrameColor: rangeViewFrameColor, rangeViewTintColor: presentationTheme.list.blocksBackgroundColor.withAlphaComponent(0.5), rangeViewMarkerColor: rangeViewMarkerColor, rangeCropImage: rangeImage)
} }
@ -124,6 +124,10 @@ public final class ChartNode: ASDisplayNode {
}) })
} }
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func setupTheme(_ theme: ChartTheme) { public func setupTheme(_ theme: ChartTheme) {
self.chartView.apply(theme: theme, animated: false) self.chartView.apply(theme: theme, animated: false)
} }
@ -136,11 +140,7 @@ public final class ChartNode: ASDisplayNode {
self.chartView.setup(controller: controller, displayRange: displayRange) self.chartView.setup(controller: controller, displayRange: displayRange)
} }
public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { public func resetInteraction() {
return super.hitTest(point, with: event) self.chartView.resetDetailsView()
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
} }
} }

View File

@ -83,6 +83,10 @@ class ChartStackSection: UIView, ChartThemeContainer {
backButton.setVisible(false, animated: false) backButton.setVisible(false, animated: false)
} }
public func resetDetailsView() {
controller?.cancelChartInteraction()
}
func apply(theme: ChartTheme, animated: Bool) { func apply(theme: ChartTheme, animated: Bool) {
self.theme = theme self.theme = theme

View File

@ -123,12 +123,12 @@ class ChartView: UIControl {
let detailsViewSize = detailsView.intrinsicContentSize let detailsViewSize = detailsView.intrinsicContentSize
maxDetailsViewWidth = max(maxDetailsViewWidth, detailsViewSize.width) maxDetailsViewWidth = max(maxDetailsViewWidth, detailsViewSize.width)
if maxDetailsViewWidth + detailsTableLeftOffset > detailsViewPosition { if maxDetailsViewWidth + detailsTableLeftOffset > detailsViewPosition {
detailsView.frame = CGRect(x: min(detailsViewPosition + detailsTableLeftOffset, bounds.width - maxDetailsViewWidth), detailsView.frame = CGRect(x: min(detailsViewPosition + detailsTableLeftOffset, bounds.width - maxDetailsViewWidth - detailsTableLeftOffset),
y: chartInsets.top + detailsTableTopOffset, y: chartInsets.top + detailsTableTopOffset,
width: maxDetailsViewWidth, width: maxDetailsViewWidth,
height: detailsViewSize.height) height: detailsViewSize.height)
} else { } else {
detailsView.frame = CGRect(x: detailsViewPosition - maxDetailsViewWidth - detailsTableLeftOffset, detailsView.frame = CGRect(x: min(detailsViewPosition - maxDetailsViewWidth - detailsTableLeftOffset, bounds.width - maxDetailsViewWidth - detailsTableLeftOffset),
y: chartInsets.top + detailsTableTopOffset, y: chartInsets.top + detailsTableTopOffset,
width: maxDetailsViewWidth, width: maxDetailsViewWidth,
height: detailsViewSize.height) height: detailsViewSize.height)

View File

@ -10,9 +10,9 @@ import GraphCore
import AppBundle import AppBundle
private enum Constants { private enum Constants {
static let cropIndocatorLineWidth: CGFloat = 1 static let cropIndicatorLineWidth: CGFloat = 1
static let markerSelectionRange: CGFloat = 25 static let markerSelectionRange: CGFloat = 25
static let defaultMinimumRangeDistance: CGFloat = 0.05 static let defaultMinimumRangeDistance: CGFloat = 0.1
static let titntAreaWidth: CGFloat = 10 static let titntAreaWidth: CGFloat = 10
static let horizontalContentMargin: CGFloat = 16 static let horizontalContentMargin: CGFloat = 16
static let cornerRadius: CGFloat = 5 static let cornerRadius: CGFloat = 5
@ -56,9 +56,9 @@ class RangeChartView: UIControl {
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
layoutMargins = UIEdgeInsets(top: Constants.cropIndocatorLineWidth, layoutMargins = UIEdgeInsets(top: Constants.cropIndicatorLineWidth,
left: Constants.horizontalContentMargin, left: Constants.horizontalContentMargin,
bottom: Constants.cropIndocatorLineWidth, bottom: Constants.cropIndicatorLineWidth,
right: Constants.horizontalContentMargin) right: Constants.horizontalContentMargin)
self.setup() self.setup()
@ -289,9 +289,9 @@ private extension RangeChartView {
func layoutViews() { func layoutViews() {
cropFrameView.frame = CGRect(x: locationInView(for: lowerBound), cropFrameView.frame = CGRect(x: locationInView(for: lowerBound),
y: contentFrame.minY - Constants.cropIndocatorLineWidth, y: contentFrame.minY - Constants.cropIndicatorLineWidth,
width: locationInView(for: upperBound) - locationInView(for: lowerBound), width: locationInView(for: upperBound) - locationInView(for: lowerBound),
height: contentFrame.height + Constants.cropIndocatorLineWidth * 2) height: contentFrame.height + Constants.cropIndicatorLineWidth * 2)
if chartView.frame != contentFrame { if chartView.frame != contentFrame {
chartView.frame = contentFrame chartView.frame = contentFrame

View File

@ -501,6 +501,13 @@ public func channelStatsController(context: AccountContext, peerId: PeerId, cach
} }
let controller = ItemListController(context: context, state: signal) let controller = ItemListController(context: context, state: signal)
controller.contentOffsetChanged = { [weak controller] _, _ in
controller?.forEachItemNode({ itemNode in
if let itemNode = itemNode as? StatsGraphItemNode {
itemNode.resetInteraction()
}
})
}
controller.didDisappear = { [weak controller] _ in controller.didDisappear = { [weak controller] _ in
controller?.clearItemNodesHighlight(animated: true) controller?.clearItemNodesHighlight(animated: true)
} }

View File

@ -114,6 +114,10 @@ class StatsGraphItemNode: ListViewItemNode {
} }
} }
func resetInteraction() {
self.chartNode.resetInteraction()
}
func asyncLayout() -> (_ item: StatsGraphItem, _ params: ListViewItemLayoutParams, _ insets: ItemListNeighbors) -> (ListViewItemNodeLayout, () -> Void) { func asyncLayout() -> (_ item: StatsGraphItem, _ params: ListViewItemLayoutParams, _ insets: ItemListNeighbors) -> (ListViewItemNodeLayout, () -> Void) {
let currentItem = self.item let currentItem = self.item
let currentVisibilityHeight = self.visibilityHeight let currentVisibilityHeight = self.visibilityHeight

View File

@ -166,13 +166,13 @@ private enum CallFeedbackControllerEntry: ItemListNodeEntry {
func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem {
let arguments = arguments as! CallFeedbackControllerArguments let arguments = arguments as! CallFeedbackControllerArguments
switch self { switch self {
case let .reasonsHeader(theme, text): case let .reasonsHeader(_, text):
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
case let .reason(theme, reason, title, value): case let .reason(_, reason, title, value):
return ItemListSwitchItem(presentationData: presentationData, title: title, value: value, maximumNumberOfLines: 2, sectionId: self.section, style: .blocks, updated: { value in return ItemListSwitchItem(presentationData: presentationData, title: title, value: value, maximumNumberOfLines: 2, sectionId: self.section, style: .blocks, updated: { value in
arguments.toggleReason(reason, value) arguments.toggleReason(reason, value)
}) })
case let .comment(theme, text, placeholder): case let .comment(_, text, placeholder):
return ItemListMultilineInputItem(presentationData: presentationData, text: text, placeholder: placeholder, maxLength: nil, sectionId: self.section, style: .blocks, textUpdated: { updatedText in return ItemListMultilineInputItem(presentationData: presentationData, text: text, placeholder: placeholder, maxLength: nil, sectionId: self.section, style: .blocks, textUpdated: { updatedText in
arguments.updateComment(updatedText) arguments.updateComment(updatedText)
}, updatedFocus: { focused in }, updatedFocus: { focused in
@ -180,11 +180,11 @@ private enum CallFeedbackControllerEntry: ItemListNodeEntry {
arguments.scrollToComment() arguments.scrollToComment()
} }
}, tag: CallFeedbackControllerEntryTag.comment) }, tag: CallFeedbackControllerEntryTag.comment)
case let .includeLogs(theme, title, value): case let .includeLogs(_, title, value):
return ItemListSwitchItem(presentationData: presentationData, title: title, value: value, sectionId: self.section, style: .blocks, updated: { value in return ItemListSwitchItem(presentationData: presentationData, title: title, value: value, sectionId: self.section, style: .blocks, updated: { value in
arguments.toggleIncludeLogs(value) arguments.toggleIncludeLogs(value)
}) })
case let .includeLogsInfo(theme, text): case let .includeLogsInfo(_, text):
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
} }
} }
@ -312,7 +312,6 @@ public func callFeedbackController(sharedContext: SharedAccountContext, account:
} }
var resultItemNode: ListViewItemNode? var resultItemNode: ListViewItemNode?
let state = stateValue.with({ $0 })
let _ = controller.frameForItemNode({ itemNode in let _ = controller.frameForItemNode({ itemNode in
if let itemNode = itemNode as? ItemListItemNode { if let itemNode = itemNode as? ItemListItemNode {
if let tag = itemNode.tag, tag.isEqual(to: targetTag) { if let tag = itemNode.tag, tag.isEqual(to: targetTag) {

View File

@ -427,7 +427,6 @@ public func customizeDefaultDarkTintedPresentationTheme(theme: PresentationTheme
helperLinesColor: accentColor?.withMultiplied(hue: 1.037, saturation: 0.271, brightness: 0.671).withAlphaComponent(0.35), helperLinesColor: accentColor?.withMultiplied(hue: 1.037, saturation: 0.271, brightness: 0.671).withAlphaComponent(0.35),
strongLinesColor: accentColor?.withMultiplied(hue: 1.037, saturation: 0.271, brightness: 0.671).withAlphaComponent(0.35), strongLinesColor: accentColor?.withMultiplied(hue: 1.037, saturation: 0.271, brightness: 0.671).withAlphaComponent(0.35),
barStrongLinesColor: accentColor?.withMultiplied(hue: 1.033, saturation: 0.211, brightness: 0.882).withAlphaComponent(0.45), barStrongLinesColor: accentColor?.withMultiplied(hue: 1.033, saturation: 0.211, brightness: 0.882).withAlphaComponent(0.45),
detailsArrowColor: accentColor?.withMultiplied(hue: 1.051, saturation: 0.254, brightness: 0.376),
detailsViewColor: accentColor?.withMultiplied(hue: 1.035, saturation: 0.571, brightness: 0.184), detailsViewColor: accentColor?.withMultiplied(hue: 1.035, saturation: 0.571, brightness: 0.184),
rangeViewFrameColor: accentColor?.withMultiplied(hue: 1.030, saturation: 0.494, brightness: 0.349) rangeViewFrameColor: accentColor?.withMultiplied(hue: 1.030, saturation: 0.494, brightness: 0.349)
) )
@ -808,7 +807,7 @@ public func makeDefaultDarkTintedPresentationTheme(extendingThemeReference: Pres
strongLinesColor: UIColor(rgb: 0xbacce1, alpha: 0.35), strongLinesColor: UIColor(rgb: 0xbacce1, alpha: 0.35),
barStrongLinesColor: UIColor(rgb: 0xbacce1, alpha: 0.45), barStrongLinesColor: UIColor(rgb: 0xbacce1, alpha: 0.45),
detailsTextColor: UIColor(rgb: 0xffffff), detailsTextColor: UIColor(rgb: 0xffffff),
detailsArrowColor: UIColor(rgb: 0x4c5460), detailsArrowColor: UIColor(rgb: 0xffffff),
detailsViewColor: UIColor(rgb: 0x19232f), detailsViewColor: UIColor(rgb: 0x19232f),
rangeViewFrameColor: UIColor(rgb: 0x354659), rangeViewFrameColor: UIColor(rgb: 0x354659),
rangeViewMarkerColor: UIColor(rgb: 0xffffff) rangeViewMarkerColor: UIColor(rgb: 0xffffff)

View File

@ -8,5 +8,8 @@
"info" : { "info" : {
"version" : 1, "version" : 1,
"author" : "xcode" "author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
} }
} }

View File

@ -300,8 +300,6 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
} }
} }
} }
} else if let animationNode = self.animationNode as? ManagedDiceAnimationNode {
} }
} }