mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Chart fixes
This commit is contained in:
parent
79024f66f1
commit
e854d7b4fa
@ -1044,7 +1044,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
|
||||
case .groupReference:
|
||||
gesture?.cancel()
|
||||
}
|
||||
}, present: { [weak self] c in
|
||||
}, present: { c in
|
||||
present(c)
|
||||
})
|
||||
self.interaction = interaction
|
||||
|
@ -78,15 +78,17 @@ public struct ChartDetailsViewModel {
|
||||
public internal(set) var title: String
|
||||
public internal(set) var showArrow: Bool
|
||||
public internal(set) var showPrefixes: Bool
|
||||
public internal(set) var isLoading: Bool
|
||||
public internal(set) var values: [Value]
|
||||
public internal(set) var totalValue: Value?
|
||||
public internal(set) var tapAction: (() -> 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,
|
||||
showArrow: Bool,
|
||||
showPrefixes: Bool,
|
||||
isLoading: Bool,
|
||||
values: [Value],
|
||||
totalValue: Value?,
|
||||
tapAction: (() -> Void)?,
|
||||
@ -94,6 +96,7 @@ public struct ChartDetailsViewModel {
|
||||
self.title = title
|
||||
self.showArrow = showArrow
|
||||
self.showPrefixes = showPrefixes
|
||||
self.isLoading = isLoading
|
||||
self.values = values
|
||||
self.totalValue = totalValue
|
||||
self.tapAction = tapAction
|
||||
|
@ -36,7 +36,7 @@ public struct 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 {
|
||||
throw ChartsError.generalConversion("Unable to get columns from: \(decodedData)")
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ public class BaseChartController: ChartThemeContainer {
|
||||
}
|
||||
|
||||
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 func setChartRangePagingEnabled(isEnabled: Bool, minimumSelectionSize: CGFloat) {
|
||||
isChartRangePagingEnabled = isEnabled
|
||||
@ -178,7 +178,7 @@ public class BaseChartController: ChartThemeContainer {
|
||||
public var setBackButtonVisibilityClosure: ((Bool, Bool) -> Void)?
|
||||
public var refreshChartToolsClosure: ((Bool) -> Void)?
|
||||
|
||||
public func didTapZoomIn(date: Date) {
|
||||
public func didTapZoomIn(date: Date, pointIndex: Int) {
|
||||
fatalError("Abstract")
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ class GeneralChartComponentController: ChartThemeContainer {
|
||||
var lastChartInteractionPoint: CGPoint = .zero
|
||||
var isChartInteractionBegun: Bool = false
|
||||
var isChartInteracting: Bool = false
|
||||
var ignoreInteraction: Bool = false
|
||||
let isZoomed: Bool
|
||||
var isZoomable = true
|
||||
|
||||
@ -169,6 +170,14 @@ class GeneralChartComponentController: ChartThemeContainer {
|
||||
}
|
||||
|
||||
func chartInteractionDidBegin(point: CGPoint) {
|
||||
guard !ignoreInteraction else {
|
||||
return
|
||||
}
|
||||
if !isChartInteractionBegun && detailsVisible {
|
||||
self.hideDetailsView(animated: true)
|
||||
ignoreInteraction = true
|
||||
return
|
||||
}
|
||||
let chartFrame = self.chartFrame()
|
||||
guard chartFrame.width > 0 else { return }
|
||||
let horizontalRange = currentHorizontalMainChartRange
|
||||
@ -185,19 +194,24 @@ class GeneralChartComponentController: ChartThemeContainer {
|
||||
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) {
|
||||
setDetailsViewModel?(chartDetailsViewModel(closestDate: date, pointIndex: dataIndex), animted)
|
||||
setDetailsChartVisibleClosure?(true, true)
|
||||
setDetailsViewPositionClosure?(detailsViewPosition)
|
||||
detailsVisible = true
|
||||
}
|
||||
|
||||
func chartInteractionDidEnd() {
|
||||
isChartInteractionBegun = false
|
||||
isChartInteracting = false
|
||||
ignoreInteraction = false
|
||||
}
|
||||
|
||||
func hideDetailsView(animated: Bool) {
|
||||
isChartInteractionBegun = false
|
||||
setDetailsChartVisibleClosure?(false, animated)
|
||||
detailsVisible = false
|
||||
}
|
||||
|
||||
var visibleDetailsChartValues: [ChartsCollection.Chart] {
|
||||
@ -323,13 +337,13 @@ class GeneralChartComponentController: ChartThemeContainer {
|
||||
let viewModel = ChartDetailsViewModel(title: dateString,
|
||||
showArrow: self.isZoomable && !self.isZoomed,
|
||||
showPrefixes: false,
|
||||
isLoading: false,
|
||||
values: values,
|
||||
totalValue: nil,
|
||||
tapAction: { [weak self] in
|
||||
self?.zoomInOnDateClosure?(closestDate) },
|
||||
hideAction: { [weak self] in
|
||||
self?.setDetailsChartVisibleClosure?(false, true)
|
||||
|
||||
})
|
||||
return viewModel
|
||||
}
|
||||
@ -338,11 +352,11 @@ class GeneralChartComponentController: ChartThemeContainer {
|
||||
let fromDate = Date(timeIntervalSince1970: TimeInterval(currentHorizontalMainChartRange.lowerBound) + 1)
|
||||
let toDate = Date(timeIntervalSince1970: TimeInterval(currentHorizontalMainChartRange.upperBound))
|
||||
if Calendar.utc.startOfDay(for: fromDate) == Calendar.utc.startOfDay(for: toDate) {
|
||||
let stirng = BaseConstants.headerFullZoomedFormatter.string(from: fromDate)
|
||||
self.setChartTitleClosure?(stirng, animated)
|
||||
let string = BaseConstants.headerFullZoomedFormatter.string(from: fromDate)
|
||||
self.setChartTitleClosure?(string, animated)
|
||||
} else {
|
||||
let stirng = "\(BaseConstants.headerMediumRangeFormatter.string(from: fromDate)) - \(BaseConstants.headerMediumRangeFormatter.string(from: toDate))"
|
||||
self.setChartTitleClosure?(stirng, animated)
|
||||
let string = "\(BaseConstants.headerMediumRangeFormatter.string(from: fromDate)) - \(BaseConstants.headerMediumRangeFormatter.string(from: toDate))"
|
||||
self.setChartTitleClosure?(string, animated)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public class BaseLinesChartController: BaseChartController {
|
||||
var zoomChartVisibility: [Bool]
|
||||
var lastChartInteractionPoint: CGPoint = .zero
|
||||
var isChartInteractionBegun: Bool = false
|
||||
var ignoreInteraction: Bool = false
|
||||
|
||||
var initialChartRange: ClosedRange<CGFloat> = BaseConstants.defaultRange
|
||||
var zoomedChartRange: ClosedRange<CGFloat> = BaseConstants.defaultRange
|
||||
@ -71,7 +72,8 @@ public class BaseLinesChartController: BaseChartController {
|
||||
}
|
||||
|
||||
public override func chartInteractionDidEnd() {
|
||||
|
||||
isChartInteractionBegun = false
|
||||
ignoreInteraction = false
|
||||
}
|
||||
|
||||
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 (index, component) = arg
|
||||
return ChartDetailsViewModel.Value(prefix: nil,
|
||||
@ -118,20 +120,25 @@ public class BaseLinesChartController: BaseChartController {
|
||||
let viewModel = ChartDetailsViewModel(title: dateString,
|
||||
showArrow: total > 0 && self.isZoomable && !self.isZoomed,
|
||||
showPrefixes: false,
|
||||
isLoading: loading,
|
||||
values: values,
|
||||
totalValue: nil,
|
||||
tapAction: { [weak self] in self?.didTapZoomIn(date: closestDate) },
|
||||
hideAction: { [weak self] in
|
||||
self?.setDetailsChartVisibleClosure?(false, true)
|
||||
tapAction: { [weak self] in
|
||||
self?.didTapZoomIn(date: closestDate, pointIndex: pointIndex)
|
||||
}, hideAction: { [weak self] in
|
||||
self?.cancelChartInteraction()
|
||||
})
|
||||
return viewModel
|
||||
}
|
||||
|
||||
public override func didTapZoomIn(date: Date) {
|
||||
public override func didTapZoomIn(date: Date, pointIndex: Int) {
|
||||
guard isZoomed == false else { return }
|
||||
cancelChartInteraction()
|
||||
|
||||
setDetailsViewModel?(chartDetailsViewModel(closestDate: date, pointIndex: pointIndex, loading: true), false)
|
||||
|
||||
self.getDetailsData?(date, { updatedCollection in
|
||||
if let updatedCollection = updatedCollection {
|
||||
self.cancelChartInteraction()
|
||||
self.initialChartRange = self.currentHorizontalRange
|
||||
if let startDate = updatedCollection.axisValues.first,
|
||||
let endDate = updatedCollection.axisValues.last {
|
||||
|
@ -122,14 +122,22 @@ public class GeneralLinesChartController: BaseLinesChartController {
|
||||
}
|
||||
|
||||
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 chartFrame = self.chartFrame()
|
||||
guard chartFrame.width > 0 else { return }
|
||||
let chartInteractionWasBegin = isChartInteractionBegun
|
||||
|
||||
let dateToFind = Date(timeIntervalSince1970: TimeInterval(horizontalRange.distance * point.x + horizontalRange.lowerBound))
|
||||
guard let (closestDate, minIndex) = findClosestDateTo(dateToFind: dateToFind) else { return }
|
||||
|
||||
let chartInteractionWasBegin = isChartInteractionBegun
|
||||
super.chartInteractionDidBegin(point: point)
|
||||
|
||||
self.lineBulletsRenderer.bullets = chartLines.compactMap { chart in
|
||||
@ -139,7 +147,7 @@ public class GeneralLinesChartController: BaseLinesChartController {
|
||||
|
||||
let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970)
|
||||
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.setDetailsViewPositionClosure?(detailsViewPosition)
|
||||
self.verticalLineRenderer.values = [chartValue]
|
||||
|
@ -149,6 +149,14 @@ public class TwoAxisLinesChartController: BaseLinesChartController {
|
||||
}
|
||||
|
||||
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 chartFrame = self.chartFrame()
|
||||
guard chartFrame.width > 0 else { return }
|
||||
@ -168,7 +176,7 @@ public class TwoAxisLinesChartController: BaseLinesChartController {
|
||||
|
||||
let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970)
|
||||
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.setDetailsViewPositionClosure?(detailsViewPosition)
|
||||
self.verticalLineRenderer.values = [chartValue]
|
||||
|
@ -153,6 +153,7 @@ class PercentChartComponentController: GeneralChartComponentController {
|
||||
let viewModel = ChartDetailsViewModel(title: dateString,
|
||||
showArrow: total > 0 && self.isZoomable && !self.isZoomed,
|
||||
showPrefixes: true,
|
||||
isLoading: false,
|
||||
values: values,
|
||||
totalValue: nil,
|
||||
tapAction: { [weak self] in
|
||||
|
@ -48,7 +48,7 @@ public class PercentPieChartController: BaseChartController {
|
||||
controller.chartFrame = { [unowned self] in self.chartFrame() }
|
||||
controller.cartViewBounds = { [unowned self] in self.cartViewBounds() }
|
||||
controller.zoomInOnDateClosure = { [unowned self] date in
|
||||
self.didTapZoomIn(date: date)
|
||||
self.didTapZoomIn(date: date, pointIndex: 0)
|
||||
}
|
||||
controller.setChartTitleClosure = { [unowned self] (title, animated) in
|
||||
self.setChartTitleClosure?(title, animated)
|
||||
@ -272,7 +272,7 @@ public class PercentPieChartController: BaseChartController {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -150,6 +150,7 @@ class PieChartComponentController: GeneralChartComponentController {
|
||||
let viewModel = ChartDetailsViewModel(title: "",
|
||||
showArrow: false,
|
||||
showPrefixes: false,
|
||||
isLoading: false,
|
||||
values: [ChartDetailsViewModel.Value(prefix: nil,
|
||||
title: title,
|
||||
value: valueString,
|
||||
|
@ -40,7 +40,7 @@ public class DailyBarsChartController: BaseChartController {
|
||||
controller.chartFrame = { [unowned self] in self.chartFrame() }
|
||||
controller.cartViewBounds = { [unowned self] in self.cartViewBounds() }
|
||||
controller.zoomInOnDateClosure = { [unowned self] date in
|
||||
self.didTapZoomIn(date: date)
|
||||
self.didTapZoomIn(date: date, pointIndex: 0)
|
||||
}
|
||||
controller.setChartTitleClosure = { [unowned self] (title, animated) in
|
||||
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 }
|
||||
if isZoomed {
|
||||
return linesController.hideDetailsView(animated: true)
|
||||
|
@ -43,7 +43,7 @@ public class StackedBarsChartController: BaseChartController {
|
||||
controller.chartFrame = { [unowned self] in self.chartFrame() }
|
||||
controller.cartViewBounds = { [unowned self] in self.cartViewBounds() }
|
||||
controller.zoomInOnDateClosure = { [unowned self] date in
|
||||
self.didTapZoomIn(date: date)
|
||||
self.didTapZoomIn(date: date, pointIndex: 0)
|
||||
}
|
||||
controller.setChartTitleClosure = { [unowned self] (title, animated) in
|
||||
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 }
|
||||
if isZoomed {
|
||||
return zoomedBarsController.hideDetailsView(animated: true)
|
||||
|
@ -43,7 +43,7 @@ public class StepBarsChartController: BaseChartController {
|
||||
controller.chartFrame = { [unowned self] in self.chartFrame() }
|
||||
controller.cartViewBounds = { [unowned self] in self.cartViewBounds() }
|
||||
controller.zoomInOnDateClosure = { [unowned self] date in
|
||||
self.didTapZoomIn(date: date)
|
||||
self.didTapZoomIn(date: date, pointIndex: 0)
|
||||
}
|
||||
controller.setChartTitleClosure = { [unowned self] (title, animated) in
|
||||
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 }
|
||||
if isZoomed {
|
||||
return zoomedBarsController.hideDetailsView(animated: true)
|
||||
|
@ -152,6 +152,15 @@ public class TwoAxisStepBarsChartController: BaseLinesChartController {
|
||||
}
|
||||
|
||||
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 chartFrame = self.chartFrame()
|
||||
guard chartFrame.width > 0 else { return }
|
||||
@ -183,8 +192,8 @@ public class TwoAxisStepBarsChartController: BaseLinesChartController {
|
||||
}
|
||||
|
||||
let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970)
|
||||
let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX
|
||||
self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex), chartInteractionWasBegin)
|
||||
let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX + barOffset
|
||||
self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex, loading: false), chartInteractionWasBegin)
|
||||
self.setDetailsChartVisibleClosure?(true, true)
|
||||
self.setDetailsViewPositionClosure?(detailsViewPosition)
|
||||
self.verticalLineRenderer.values = [chartValue]
|
||||
|
@ -39,6 +39,9 @@ class PieChartRenderer: BaseChartRenderer {
|
||||
}
|
||||
private(set) var selectedSegment: Int?
|
||||
func selectSegmentAt(at indexToSelect: Int?, animated: Bool) {
|
||||
guard selectedSegment != indexToSelect else {
|
||||
return
|
||||
}
|
||||
selectedSegment = indexToSelect
|
||||
for (index, animator) in setlectedSegmentsAnimators.enumerated() {
|
||||
let fraction: CGFloat = (index == indexToSelect) ? 1.0 : 0.0
|
||||
|
@ -49,6 +49,7 @@ class ChartDetailsView: UIControl {
|
||||
addSubview(titleLabel)
|
||||
addSubview(arrowView)
|
||||
addSubview(arrowButton)
|
||||
addSubview(activityIndicator)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
@ -60,21 +61,32 @@ class ChartDetailsView: UIControl {
|
||||
|
||||
titleLabel.setText(viewModel.title, animated: false)
|
||||
titleLabel.setVisible(!viewModel.title.isEmpty, animated: false)
|
||||
arrowView.setVisible(viewModel.showArrow, animated: false)
|
||||
arrowButton.isUserInteractionEnabled = viewModel.showArrow
|
||||
arrowView.setVisible(viewModel.showArrow && !viewModel.isLoading, animated: false)
|
||||
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
|
||||
var y: CGFloat = verticalMargins
|
||||
|
||||
if (!viewModel.title.isEmpty || viewModel.showArrow) {
|
||||
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
|
||||
}
|
||||
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,
|
||||
count: viewModel.showPrefixes ? labelsCount : 0,
|
||||
font: UIFont.systemFont(ofSize: 12, weight: .bold))
|
||||
@ -143,12 +155,13 @@ class ChartDetailsView: UIControl {
|
||||
}
|
||||
})
|
||||
self.textHeight = textHeight
|
||||
|
||||
arrowButton.frame = CGRect(x: 0.0, y: 0.0, width: width, height: y)
|
||||
}
|
||||
|
||||
override var intrinsicContentSize: CGSize {
|
||||
if let viewModel = viewModel {
|
||||
var height = ((!viewModel.title.isEmpty || viewModel.showArrow) ? labelHeight : 0) +
|
||||
// (CGFloat(viewModel.values.filter({ $0.visible }).count) * labelHeight) +
|
||||
(viewModel.totalValue?.visible == true ? labelHeight : 0) +
|
||||
verticalMargins * 2
|
||||
|
||||
@ -206,6 +219,7 @@ extension ChartDetailsView: ChartThemeContainer {
|
||||
}
|
||||
UIView.perform(animated: animated) {
|
||||
self.arrowView.tintColor = theme.chartDetailsArrowColor
|
||||
self.activityIndicator.color = theme.chartDetailsArrowColor
|
||||
self.backgroundColor = theme.chartDetailsViewColor
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public extension ChartTheme {
|
||||
context.addLine(to: CGPoint(x: 110.0, y: 21.0))
|
||||
context.addLine(to: CGPoint(x: 107.0, y: 25.0))
|
||||
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)
|
||||
}
|
||||
@ -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) {
|
||||
self.chartView.apply(theme: theme, animated: false)
|
||||
}
|
||||
@ -136,11 +140,7 @@ public final class ChartNode: ASDisplayNode {
|
||||
self.chartView.setup(controller: controller, displayRange: displayRange)
|
||||
}
|
||||
|
||||
public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
||||
return super.hitTest(point, with: event)
|
||||
}
|
||||
|
||||
required public init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
public func resetInteraction() {
|
||||
self.chartView.resetDetailsView()
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,10 @@ class ChartStackSection: UIView, ChartThemeContainer {
|
||||
backButton.setVisible(false, animated: false)
|
||||
}
|
||||
|
||||
public func resetDetailsView() {
|
||||
controller?.cancelChartInteraction()
|
||||
}
|
||||
|
||||
func apply(theme: ChartTheme, animated: Bool) {
|
||||
self.theme = theme
|
||||
|
||||
|
@ -123,12 +123,12 @@ class ChartView: UIControl {
|
||||
let detailsViewSize = detailsView.intrinsicContentSize
|
||||
maxDetailsViewWidth = max(maxDetailsViewWidth, detailsViewSize.width)
|
||||
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,
|
||||
width: maxDetailsViewWidth,
|
||||
height: detailsViewSize.height)
|
||||
} else {
|
||||
detailsView.frame = CGRect(x: detailsViewPosition - maxDetailsViewWidth - detailsTableLeftOffset,
|
||||
detailsView.frame = CGRect(x: min(detailsViewPosition - maxDetailsViewWidth - detailsTableLeftOffset, bounds.width - maxDetailsViewWidth - detailsTableLeftOffset),
|
||||
y: chartInsets.top + detailsTableTopOffset,
|
||||
width: maxDetailsViewWidth,
|
||||
height: detailsViewSize.height)
|
||||
|
@ -10,9 +10,9 @@ import GraphCore
|
||||
import AppBundle
|
||||
|
||||
private enum Constants {
|
||||
static let cropIndocatorLineWidth: CGFloat = 1
|
||||
static let cropIndicatorLineWidth: CGFloat = 1
|
||||
static let markerSelectionRange: CGFloat = 25
|
||||
static let defaultMinimumRangeDistance: CGFloat = 0.05
|
||||
static let defaultMinimumRangeDistance: CGFloat = 0.1
|
||||
static let titntAreaWidth: CGFloat = 10
|
||||
static let horizontalContentMargin: CGFloat = 16
|
||||
static let cornerRadius: CGFloat = 5
|
||||
@ -56,9 +56,9 @@ class RangeChartView: UIControl {
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
layoutMargins = UIEdgeInsets(top: Constants.cropIndocatorLineWidth,
|
||||
layoutMargins = UIEdgeInsets(top: Constants.cropIndicatorLineWidth,
|
||||
left: Constants.horizontalContentMargin,
|
||||
bottom: Constants.cropIndocatorLineWidth,
|
||||
bottom: Constants.cropIndicatorLineWidth,
|
||||
right: Constants.horizontalContentMargin)
|
||||
|
||||
self.setup()
|
||||
@ -289,9 +289,9 @@ private extension RangeChartView {
|
||||
|
||||
func layoutViews() {
|
||||
cropFrameView.frame = CGRect(x: locationInView(for: lowerBound),
|
||||
y: contentFrame.minY - Constants.cropIndocatorLineWidth,
|
||||
y: contentFrame.minY - Constants.cropIndicatorLineWidth,
|
||||
width: locationInView(for: upperBound) - locationInView(for: lowerBound),
|
||||
height: contentFrame.height + Constants.cropIndocatorLineWidth * 2)
|
||||
height: contentFrame.height + Constants.cropIndicatorLineWidth * 2)
|
||||
|
||||
if chartView.frame != contentFrame {
|
||||
chartView.frame = contentFrame
|
||||
|
@ -501,6 +501,13 @@ public func channelStatsController(context: AccountContext, peerId: PeerId, cach
|
||||
}
|
||||
|
||||
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?.clearItemNodesHighlight(animated: true)
|
||||
}
|
||||
|
@ -114,6 +114,10 @@ class StatsGraphItemNode: ListViewItemNode {
|
||||
}
|
||||
}
|
||||
|
||||
func resetInteraction() {
|
||||
self.chartNode.resetInteraction()
|
||||
}
|
||||
|
||||
func asyncLayout() -> (_ item: StatsGraphItem, _ params: ListViewItemLayoutParams, _ insets: ItemListNeighbors) -> (ListViewItemNodeLayout, () -> Void) {
|
||||
let currentItem = self.item
|
||||
let currentVisibilityHeight = self.visibilityHeight
|
||||
|
@ -166,13 +166,13 @@ private enum CallFeedbackControllerEntry: ItemListNodeEntry {
|
||||
func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem {
|
||||
let arguments = arguments as! CallFeedbackControllerArguments
|
||||
switch self {
|
||||
case let .reasonsHeader(theme, text):
|
||||
case let .reasonsHeader(_, text):
|
||||
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
|
||||
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
|
||||
arguments.updateComment(updatedText)
|
||||
}, updatedFocus: { focused in
|
||||
@ -180,11 +180,11 @@ private enum CallFeedbackControllerEntry: ItemListNodeEntry {
|
||||
arguments.scrollToComment()
|
||||
}
|
||||
}, 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
|
||||
arguments.toggleIncludeLogs(value)
|
||||
})
|
||||
case let .includeLogsInfo(theme, text):
|
||||
case let .includeLogsInfo(_, text):
|
||||
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
|
||||
}
|
||||
}
|
||||
@ -312,7 +312,6 @@ public func callFeedbackController(sharedContext: SharedAccountContext, account:
|
||||
}
|
||||
|
||||
var resultItemNode: ListViewItemNode?
|
||||
let state = stateValue.with({ $0 })
|
||||
let _ = controller.frameForItemNode({ itemNode in
|
||||
if let itemNode = itemNode as? ItemListItemNode {
|
||||
if let tag = itemNode.tag, tag.isEqual(to: targetTag) {
|
||||
|
@ -427,7 +427,6 @@ public func customizeDefaultDarkTintedPresentationTheme(theme: PresentationTheme
|
||||
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),
|
||||
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),
|
||||
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),
|
||||
barStrongLinesColor: UIColor(rgb: 0xbacce1, alpha: 0.45),
|
||||
detailsTextColor: UIColor(rgb: 0xffffff),
|
||||
detailsArrowColor: UIColor(rgb: 0x4c5460),
|
||||
detailsArrowColor: UIColor(rgb: 0xffffff),
|
||||
detailsViewColor: UIColor(rgb: 0x19232f),
|
||||
rangeViewFrameColor: UIColor(rgb: 0x354659),
|
||||
rangeViewMarkerColor: UIColor(rgb: 0xffffff)
|
||||
|
@ -8,5 +8,8 @@
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
@ -300,8 +300,6 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let animationNode = self.animationNode as? ManagedDiceAnimationNode {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user