Last active
December 18, 2020 18:14
-
-
Save jscalo/9c16d5012b2e303b6971a005345f99c4 to your computer and use it in GitHub Desktop.
This file contains 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
private func updateLines(samples: [Float], yMidline: CGFloat) { | |
let maxSampleMagnitude = max(dataProvider.summarySampleMax, -(dataProvider.summarySampleMin), Float.leastNonzeroMagnitude) | |
let yScalingFactor = bounds.height / 2 / CGFloat(maxSampleMagnitude) | |
var xPos: CGFloat = 0 | |
let cnt = samples.count | |
var idx = 0 | |
let visibleDur = dataProvider.duration / Double(viewPort.zoom) | |
let startTime = (Double(viewPort.startingXUnit) / Double(viewPort.xAxisUnits)) * dataProvider.duration | |
while idx < cnt && xPos < bounds.maxX && idx < layers.count { | |
let time = startTime + Double(xPos) / Double(viewPort.visibleWidth) * visibleDur | |
let sample = dataProvider.sample(at: time) | |
let layer = layers[idx] | |
layer.isHidden = false | |
let y = CGFloat(sample) * yScalingFactor | |
layer.frame = CGRect(x: xPos, y: yMidline - y, width: 1, height: 2 * y) | |
xPos += 1.0 / viewPort.screenScale | |
idx += 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment