From 6a881aed2899e780cb40d887ba4d91c7db126efc Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Mon, 6 Apr 2026 14:51:44 +0200 Subject: [PATCH] fix: fixed Line Chart draw offset --- Kit/Widgets/LineChart.swift | 13 ++++++------- Kit/plugins/Charts.swift | 2 +- Modules/CPU/popup.swift | 2 +- Modules/RAM/popup.swift | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Kit/Widgets/LineChart.swift b/Kit/Widgets/LineChart.swift index 7c41cf77..45006565 100644 --- a/Kit/Widgets/LineChart.swift +++ b/Kit/Widgets/LineChart.swift @@ -226,17 +226,16 @@ public class LineChart: WidgetWrapper { } context.saveGState() - - let chartFrame = NSRect( - x: x+offset+lineWidth, - y: offset, + context.translateBy(x: x+offset+lineWidth, y: offset) + + let chartSize = NSSize( width: box.bounds.width - (offset*2+lineWidth), height: box.bounds.height - offset ) self.chart.color = color - self.chart.setFrameSize(NSSize(width: chartFrame.width, height: chartFrame.height)) - self.chart.draw(chartFrame) - + self.chart.setFrameSize(chartSize) + self.chart.draw(NSRect(origin: .zero, size: chartSize)) + context.restoreGState() if self.boxState || self.frameState { diff --git a/Kit/plugins/Charts.swift b/Kit/plugins/Charts.swift index 42bf8486..613cc056 100644 --- a/Kit/plugins/Charts.swift +++ b/Kit/plugins/Charts.swift @@ -233,7 +233,7 @@ public class LineChartView: NSView { } let point = CGPoint( - x: (CGFloat(i) * xRatio) + dirtyRect.origin.x, + x: CGFloat(i) * xRatio, y: y ) line.append(point) diff --git a/Modules/CPU/popup.swift b/Modules/CPU/popup.swift index de96e269..16e0161d 100644 --- a/Modules/CPU/popup.swift +++ b/Modules/CPU/popup.swift @@ -238,7 +238,7 @@ internal class Popup: PopupWrapper { box.layer?.backgroundColor = NSColor.lightGray.withAlphaComponent(0.1).cgColor box.layer?.cornerRadius = 3 - let chartFrame = NSRect(x: 1, y: 0, width: box.frame.width, height: box.frame.height) + let chartFrame = NSRect(x: 1, y: 0, width: box.frame.width - 2, height: box.frame.height) self.lineChart = LineChartView(frame: chartFrame, num: self.lineChartHistory, scale: self.lineChartScale, fixedScale: self.lineChartFixedScale) self.lineChart?.color = self.chartColor box.addSubview(self.lineChart!) diff --git a/Modules/RAM/popup.swift b/Modules/RAM/popup.swift index 3fd362be..08e027ba 100644 --- a/Modules/RAM/popup.swift +++ b/Modules/RAM/popup.swift @@ -164,7 +164,7 @@ internal class Popup: PopupWrapper { container.layer?.backgroundColor = NSColor.lightGray.withAlphaComponent(0.1).cgColor container.layer?.cornerRadius = 3 - let chartFrame = NSRect(x: 1, y: 0, width: view.frame.width, height: container.frame.height) + let chartFrame = NSRect(x: 1, y: 0, width: view.frame.width - 2, height: container.frame.height) self.chart = LineChartView(frame: chartFrame, num: self.lineChartHistory, scale: self.lineChartScale, fixedScale: self.lineChartFixedScale) self.chart?.color = self.chartColor container.addSubview(self.chart!)