Last active
December 18, 2020 18:14
-
-
Save jscalo/9c16d5012b2e303b6971a005345f99c4 to your computer and use it in GitHub Desktop.
Revisions
-
jscalo renamed this gist
Dec 18, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jscalo created this gist
Dec 18, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ 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 } }