From 97b4099f450c0842178f2c541749f98a1e555477 Mon Sep 17 00:00:00 2001 From: mrFq1 <1xxbx0il0@mozmail.com> Date: Wed, 26 Apr 2023 16:21:33 +0800 Subject: [PATCH] feat: TrafficGraphView gridOverlay --- .../Overview/TrafficGraphView.swift | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/ClashX Dashboard/Views/ContentTabs/Overview/TrafficGraphView.swift b/ClashX Dashboard/Views/ContentTabs/Overview/TrafficGraphView.swift index 0a2a4eb..94a0ef4 100644 --- a/ClashX Dashboard/Views/ContentTabs/Overview/TrafficGraphView.swift +++ b/ClashX Dashboard/Views/ContentTabs/Overview/TrafficGraphView.swift @@ -45,15 +45,41 @@ struct TrafficGraphView: View { } var graphView: some View { - DSFSparklineLineGraphView.SwiftUI( - dataSource: dataSource, - graphColor: graphColor, - interpolated: false, - showZeroLine: false - - ) + ZStack { + DSFSparklineLineGraphView.SwiftUI( + dataSource: dataSource, + graphColor: graphColor, + interpolated: false, + showZeroLine: false + ) + + DSFSparklineSurface.SwiftUI([ + gridOverlay + ]) + } } + let gridOverlay: DSFSparklineOverlay = { + let grid = DSFSparklineOverlay.GridLines() + grid.dataSource = .init(values: [1], range: 0...1) + + + var floatValues = [CGFloat]() + for i in 0...labelsCount { + floatValues.append(CGFloat(i) / CGFloat(labelsCount)) + } + let _ = floatValues.removeFirst() + + grid.floatValues = floatValues.reversed() + + grid.strokeColor = DSFColor.systemGray.withAlphaComponent(0.3).cgColor + grid.strokeWidth = 0.5 + grid.dashStyle = [2, 2] + + return grid + }() + + func updateChart(_ values: [CGFloat]) { let max = values.max() ?? CGFloat(labelsCount) * 1000