Skip to content

Commit

Permalink
Graph gradient
Browse files Browse the repository at this point in the history
  • Loading branch information
macmade committed Jun 26, 2021
1 parent 1e59973 commit 709cde8
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions Sensors/Classes/SensorGraphView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ public class SensorGraphView: NSView

private func drawGraph( in rect: NSRect, kind: SensorData.Kind, values: [ CGFloat ], min: CGFloat, max: CGFloat, color: NSColor )
{
let path = NSBezierPath()
path.lineWidth = 1
let p1 = NSBezierPath()
let p2 = NSBezierPath()
p1.lineWidth = 1
p2.lineWidth = 0

if min == max && kind != .thermal
{
path.move( to: NSPoint( x: rect.origin.x, y: rect.origin.y + rect.size.height / 2 ) )
path.line( to: NSPoint( x: rect.origin.x + rect.size.width, y: rect.origin.y + rect.size.height / 2 ) )
p1.move( to: NSPoint( x: rect.origin.x, y: rect.origin.y + rect.size.height / 2 ) )
p1.line( to: NSPoint( x: rect.origin.x + rect.size.width, y: rect.origin.y + rect.size.height / 2 ) )
p2.move( to: NSPoint( x: rect.origin.x, y: rect.origin.y + rect.size.height / 2 ) )
p2.line( to: NSPoint( x: rect.origin.x + rect.size.width, y: rect.origin.y + rect.size.height / 2 ) )
}
else
{
Expand All @@ -96,16 +100,26 @@ public class SensorGraphView: NSView

if i == 0
{
path.move( to: NSPoint( x: x, y: y ) )
p1.move( to: NSPoint( x: x, y: y ) )
p2.move( to: NSPoint( x: x, y: y ) )
}
else
{
path.line( to: NSPoint( x: x, y: y ) )
p1.line( to: NSPoint( x: x, y: y ) )
p2.line( to: NSPoint( x: x, y: y ) )
}
}
}

p2.line( to: NSPoint( x: rect.origin.x + rect.size.width, y: rect.origin.y ) )
p2.line( to: NSPoint( x: rect.origin.x, y: rect.origin.y ) )
p2.close()

let gradient = NSGradient( colors: [ color.withAlphaComponent( 0.25 ), color.withAlphaComponent( 0 ) ] )

gradient?.draw( in: p2, angle: -90 )

color.setStroke()
path.stroke()
p1.stroke()
}
}

0 comments on commit 709cde8

Please sign in to comment.