From f16595524739194ec80115e2048177cda15c5454 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Mon, 9 May 2022 21:39:02 +0200 Subject: [PATCH] feat: use shadow point array when clicking on the line chart. It prevents missing the data when previewing the chart by clicking --- Kit/plugins/Charts.swift | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Kit/plugins/Charts.swift b/Kit/plugins/Charts.swift index 7259ee6a..5810b0ba 100644 --- a/Kit/plugins/Charts.swift +++ b/Kit/plugins/Charts.swift @@ -34,6 +34,7 @@ public class LineChartView: NSView { public var id: String = UUID().uuidString public var points: [Double] + public var shadowPoints: [Double] = [] public var transparent: Bool = true public var color: NSColor = controlAccentColor @@ -64,7 +65,12 @@ public class LineChartView: NSView { public override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) - if self.points.isEmpty { + var points = self.points + if self.stop { + points = self.shadowPoints + } + + if points.isEmpty { return } @@ -79,9 +85,9 @@ public class LineChartView: NSView { let offset: CGFloat = 1 / (NSScreen.main?.backingScaleFactor ?? 1) let height: CGFloat = self.frame.size.height - self.frame.origin.y - offset - let xRatio: CGFloat = self.frame.size.width / CGFloat(self.points.count) + let xRatio: CGFloat = self.frame.size.width / CGFloat(points.count) - let list = self.points.enumerated().compactMap { (i: Int, v: Double) -> (value: Double, point: CGPoint) in + let list = points.enumerated().compactMap { (i: Int, v: Double) -> (value: Double, point: CGPoint) in let x: CGFloat = (CGFloat(i) * xRatio) + dirtyRect.origin.x let y = CGFloat((CGFloat(truncating: v as NSNumber) * height)) + dirtyRect.origin.y + offset @@ -91,7 +97,7 @@ public class LineChartView: NSView { let line = NSBezierPath() line.move(to: list[0].point) - for i in 1..