Created
February 19, 2018 15:41
-
-
Save mmuszynski/b3265d83c2d69687f8688d78da159b3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override func draw(_ dirtyRect: NSRect) { | |
for location in Int(dirtyRect.origin.x)..<Int(dirtyRect.origin.x + dirtyRect.size.width) { | |
let colorBox = NSBezierPath(rect: NSRect(x: CGFloat(location), y:0, width: 2.0, height: self.bounds.size.height)) | |
var alpha: CGFloat = 1.0 | |
if location < drawValues.count { | |
let locationPower = drawValues[location] | |
guard let locationmax = drawValues.max() else { | |
fatalError() | |
} | |
if locationmax == 0 { | |
alpha = 0 | |
} else { | |
alpha = CGFloat(locationPower / locationmax) | |
} | |
alpha = alpha < minimumAlpha ? minimumAlpha : alpha | |
} | |
var color = colorData[location] ?? NSColor(calibratedRed: 0.75, green: 0.75, blue: 0.75, alpha: 1.0) | |
color = NSColor(calibratedRed: color.redComponent, green: color.greenComponent, blue: color.blueComponent, alpha: alpha) | |
color.setFill() | |
colorBox.fill() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment