mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Fix chart size and clipping
This commit is contained in:
@@ -16,7 +16,7 @@ import UIKit
|
||||
|
||||
enum BaseConstants {
|
||||
static let defaultRange: ClosedRange<CGFloat> = 0...1
|
||||
static let minimumAxisYLabelsDistance: CGFloat = 90
|
||||
static let minimumAxisYLabelsDistance: CGFloat = 85
|
||||
static let monthDayDateFormatter = DateFormatter.utc(format: "MMM d")
|
||||
static let timeDateFormatter = DateFormatter.utc(format: "HH:mm")
|
||||
static let headerFullRangeFormatter: DateFormatter = {
|
||||
|
||||
@@ -156,7 +156,6 @@ public class TwoAxisStepBarsChartController: BaseLinesChartController {
|
||||
super.chartInteractionDidBegin(point: point)
|
||||
|
||||
for graphController in graphControllers {
|
||||
|
||||
var bullets: [LineBulletsRenderer.Bullet] = []
|
||||
if let component = graphController.chartBars.components.first {
|
||||
let location = graphController.chartBars.locations[minIndex]
|
||||
|
||||
@@ -197,9 +197,7 @@ class BarChartRenderer: BaseChartRenderer {
|
||||
leftX = rightX
|
||||
barIndex += 1
|
||||
}
|
||||
|
||||
let colorOffset = Double((1.0 - (1.0 - generalUnselectedAlpha) * selectedIndexAnimator.current) * chartsAlpha)
|
||||
|
||||
|
||||
for (index, component) in bars.components.enumerated().reversed() {
|
||||
if maxValues[index] < optimizationLevel {
|
||||
continue
|
||||
@@ -209,7 +207,7 @@ class BarChartRenderer: BaseChartRenderer {
|
||||
context.setLineWidth(self.lineWidth)
|
||||
context.setStrokeColor(GColor.valueBetween(start: backgroundColorAnimator.current.color,
|
||||
end: component.color,
|
||||
offset: colorOffset).cgColor)
|
||||
offset: 1.0).cgColor)
|
||||
context.beginPath()
|
||||
context.addLines(between: backgroundPaths[index])
|
||||
context.strokePath()
|
||||
|
||||
@@ -59,6 +59,8 @@ class LinesChartRenderer: BaseChartRenderer {
|
||||
if chartsAlpha == 0 { return }
|
||||
let range = renderRange(bounds: bounds, chartFrame: chartFrame)
|
||||
|
||||
context.clip(to: CGRect(origin: CGPoint(x: 0.0, y: chartFrame.minY), size: CGSize(width: chartFrame.width + chartFrame.origin.x * 2.0, height: chartFrame.height)))
|
||||
|
||||
for (index, toLine) in toLines.enumerated() {
|
||||
let alpha = linesAlphaAnimators[index].current * chartsAlpha
|
||||
if alpha == 0 { continue }
|
||||
@@ -434,6 +436,8 @@ class LinesChartRenderer: BaseChartRenderer {
|
||||
}
|
||||
context.setAlpha(1.0)
|
||||
}
|
||||
|
||||
context.resetClip()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class VerticalScalesRenderer: BaseChartRenderer {
|
||||
}
|
||||
}
|
||||
var horizontalLinesWidth: CGFloat = GView.oneDevicePixel
|
||||
var lavelsAsisOffset: CGFloat = 6
|
||||
var labelsAxisOffset: CGFloat = 6
|
||||
var labelsColor: GColor = .black {
|
||||
didSet {
|
||||
setNeedsDisplay()
|
||||
@@ -118,18 +118,14 @@ class VerticalScalesRenderer: BaseChartRenderer {
|
||||
func drawVerticalLabels(_ labels: [LinesChartLabel], attributes: [NSAttributedString.Key: Any]) {
|
||||
if isRightAligned {
|
||||
for label in labels {
|
||||
let y = transform(toChartCoordinateVertical: label.value, chartFrame: chartFrame) - labelsFont.pointSize - lavelsAsisOffset
|
||||
|
||||
|
||||
|
||||
|
||||
let y = transform(toChartCoordinateVertical: label.value, chartFrame: chartFrame) - labelsFont.pointSize - labelsAxisOffset
|
||||
let attributedString = NSAttributedString(string: label.text, attributes: attributes)
|
||||
let textNode = LabelNode.layoutText(attributedString, bounds.size)
|
||||
textNode.1.draw(CGRect(origin: CGPoint(x:chartFrame.maxX - textNode.0.size.width, y: y), size: textNode.0.size), in: context, backingScaleFactor: deviceScale)
|
||||
}
|
||||
} else {
|
||||
for label in labels {
|
||||
let y = transform(toChartCoordinateVertical: label.value, chartFrame: chartFrame) - labelsFont.pointSize - lavelsAsisOffset
|
||||
let y = transform(toChartCoordinateVertical: label.value, chartFrame: chartFrame) - labelsFont.pointSize - labelsAxisOffset
|
||||
let attributedString = NSAttributedString(string: label.text, attributes: attributes)
|
||||
let textNode = LabelNode.layoutText(attributedString, bounds.size)
|
||||
textNode.1.draw(CGRect(origin: CGPoint(x:chartFrame.minX, y: y), size: textNode.0.size), in: context, backingScaleFactor: deviceScale)
|
||||
|
||||
Reference in New Issue
Block a user