mirror of
https://github.com/yJason/ClashX-Dashboard.git
synced 2026-03-01 00:35:19 +08:00
feat: TrafficGraphView gridOverlay
This commit is contained in:
@@ -45,15 +45,41 @@ struct TrafficGraphView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var graphView: some View {
|
var graphView: some View {
|
||||||
DSFSparklineLineGraphView.SwiftUI(
|
ZStack {
|
||||||
dataSource: dataSource,
|
DSFSparklineLineGraphView.SwiftUI(
|
||||||
graphColor: graphColor,
|
dataSource: dataSource,
|
||||||
interpolated: false,
|
graphColor: graphColor,
|
||||||
showZeroLine: false
|
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]) {
|
func updateChart(_ values: [CGFloat]) {
|
||||||
let max = values.max() ?? CGFloat(labelsCount) * 1000
|
let max = values.max() ?? CGFloat(labelsCount) * 1000
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user