From 13cd7a2ab6dec22412a607bbf9dada8288c2b1db Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Mon, 23 Mar 2020 16:55:02 +0400 Subject: [PATCH] Fix chart size and clipping --- build-system/prepare-build-variables.sh | 2 +- .../Charts/Controllers/BaseChartController.swift | 2 +- .../Stacked Bars/TwoAxisStepBarsChartController.swift | 1 - .../Sources/Charts/Renderes/BarChartRenderer.swift | 6 ++---- .../Sources/Charts/Renderes/LinesChartRenderer.swift | 4 ++++ .../Charts/Renderes/VerticalScalesRenderer.swift | 10 +++------- submodules/GraphUI/Sources/ChartStackSection.swift | 6 +++--- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/build-system/prepare-build-variables.sh b/build-system/prepare-build-variables.sh index d88042f518..b48f0ce9ad 100755 --- a/build-system/prepare-build-variables.sh +++ b/build-system/prepare-build-variables.sh @@ -17,7 +17,7 @@ prepare_build_variables () { ;; esac - local BAZEL="$(which bazel)" + local BAZEL="/Users/ilya/bin/bazel" if [ "$BAZEL" = "" ]; then echo "bazel not found in PATH" exit 1 diff --git a/submodules/GraphCore/Sources/Charts/Controllers/BaseChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/BaseChartController.swift index 6274296c18..bb067c7d8d 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/BaseChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/BaseChartController.swift @@ -16,7 +16,7 @@ import UIKit enum BaseConstants { static let defaultRange: ClosedRange = 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 = { diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift index ef8de8284f..5729bda287 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift @@ -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] diff --git a/submodules/GraphCore/Sources/Charts/Renderes/BarChartRenderer.swift b/submodules/GraphCore/Sources/Charts/Renderes/BarChartRenderer.swift index 7c7a9310ff..e798e6b3f9 100644 --- a/submodules/GraphCore/Sources/Charts/Renderes/BarChartRenderer.swift +++ b/submodules/GraphCore/Sources/Charts/Renderes/BarChartRenderer.swift @@ -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() diff --git a/submodules/GraphCore/Sources/Charts/Renderes/LinesChartRenderer.swift b/submodules/GraphCore/Sources/Charts/Renderes/LinesChartRenderer.swift index 39117b4da8..db288c1401 100644 --- a/submodules/GraphCore/Sources/Charts/Renderes/LinesChartRenderer.swift +++ b/submodules/GraphCore/Sources/Charts/Renderes/LinesChartRenderer.swift @@ -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() } } diff --git a/submodules/GraphCore/Sources/Charts/Renderes/VerticalScalesRenderer.swift b/submodules/GraphCore/Sources/Charts/Renderes/VerticalScalesRenderer.swift index 1408b12cd5..ba0af18a5c 100644 --- a/submodules/GraphCore/Sources/Charts/Renderes/VerticalScalesRenderer.swift +++ b/submodules/GraphCore/Sources/Charts/Renderes/VerticalScalesRenderer.swift @@ -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) diff --git a/submodules/GraphUI/Sources/ChartStackSection.swift b/submodules/GraphUI/Sources/ChartStackSection.swift index 485c7eccbb..ddca56442d 100644 --- a/submodules/GraphUI/Sources/ChartStackSection.swift +++ b/submodules/GraphUI/Sources/ChartStackSection.swift @@ -152,12 +152,12 @@ class ChartStackSection: UIView, ChartThemeContainer { let bounds = self.bounds self.titleLabel.frame = CGRect(origin: CGPoint(x: backButton.alpha > 0.0 ? 36.0 : 0.0, y: 5.0), size: CGSize(width: bounds.width, height: 28.0)) self.sectionContainerView.frame = CGRect(origin: CGPoint(), size: CGSize(width: bounds.width, height: 750.0)) - self.chartView.frame = CGRect(origin: CGPoint(), size: CGSize(width: bounds.width, height: 250.0)) + self.chartView.frame = CGRect(origin: CGPoint(), size: CGSize(width: bounds.width, height: 310.0)) self.rangeView.isHidden = !self.displayRange - self.rangeView.frame = CGRect(origin: CGPoint(x: 0.0, y: 250.0), size: CGSize(width: bounds.width, height: 42.0)) - self.visibilityView.frame = CGRect(origin: CGPoint(x: 0.0, y: self.displayRange ? 308.0 : 266.0), size: CGSize(width: bounds.width, height: 350.0)) + self.rangeView.frame = CGRect(origin: CGPoint(x: 0.0, y: 310.0), size: CGSize(width: bounds.width, height: 42.0)) + self.visibilityView.frame = CGRect(origin: CGPoint(x: 0.0, y: self.displayRange ? 368.0 : 326.0), size: CGSize(width: bounds.width, height: 350.0)) self.backButton.frame = CGRect(x: 0.0, y: 0.0, width: 96.0, height: 38.0) self.chartView.setNeedsDisplay()