public void SetMagnitudes (double [] magnitudeData)
{
if (curveLayer == null) {
curveLayer = new CAShapeLayer ();
curveLayer.FillColor = UIColor.FromRGBA (0.31f, 0.37f, 0.73f, 0.8f).CGColor;
graphLayer.AddSublayer (curveLayer);
}
var bezierPath = new CGPath ();
var width = graphLayer.Bounds.Width;
bezierPath.MoveToPoint (leftMargin, graphLayer.Frame.Height + bottomMargin);
float lastDbPos = 0f;
float location = leftMargin;
var frequencyCount = frequencies?.Count ?? 0;
var pixelRatio = (int)(Math.Ceiling (width / frequencyCount));
for (int i = 0; i < frequencyCount; i++) {
var dbValue = 20 * Math.Log10 (magnitudeData [i]);
float dbPos;
if (dbValue < -defaultGain)
dbPos = GetLocationForDbValue (-defaultGain);
else if (dbValue > defaultGain)
dbPos = GetLocationForDbValue (defaultGain);
else
dbPos = GetLocationForDbValue ((float)dbValue);
if (Math.Abs (lastDbPos - dbPos) >= 0.1)
bezierPath.AddLineToPoint (location, dbPos);
lastDbPos = dbPos;
location += pixelRatio;
if (location > width + graphLayer.Frame.X) {
location = (float)width + (float)graphLayer.Frame.X;
break;
}
}
bezierPath.AddLineToPoint (location, graphLayer.Frame.Y + graphLayer.Frame.Height + bottomMargin);
bezierPath.CloseSubpath ();
CATransaction.Begin ();
CATransaction.DisableActions = true;
curveLayer.Path = bezierPath;
CATransaction.Commit ();
UpdateControls (true);
}