/// <summary> /// Рисует координаты. /// </summary> /// <param name="coordinates"></param> /// <param name="parameters"></param> /// <param name="frame"></param> /// <param name="canvas"></param> public void Paint(Coordinates coordinates, Parameters parameters, RestrictiveFrame frame, SKCanvas canvas) { foreach (TypeOfAxis type in Enum.GetValues(typeof(TypeOfAxis))) { DrawMarks(type, coordinates, parameters, frame, canvas); } }
/// <summary> /// Рисует рамку. /// </summary> /// <param name="frame">Рамка.</param> /// <param name="canvas">Холст.</param> public void Paint(RestrictiveFrame frame, SKCanvas canvas) { canvas.DrawLine(frame.GetFirstPointX(), frame.GetFirstPointY(), frame.GetSecondPointX(), frame.GetFirstPointY(), frame.Paint); canvas.DrawLine(frame.GetSecondPointX(), frame.GetFirstPointY(), frame.GetSecondPointX(), frame.GetSecondPointY(), frame.Paint); canvas.DrawLine(frame.GetSecondPointX(), frame.GetSecondPointY(), frame.GetFirstPointX(), frame.GetSecondPointY(), frame.Paint); canvas.DrawLine(frame.GetFirstPointX(), frame.GetSecondPointY(), frame.GetFirstPointX(), frame.GetFirstPointY(), frame.Paint); }
/// <summary> /// Возвращает коэффициент масштабирования для X-точек. /// </summary> /// <param name="parameters"></param> /// <param name="frame"></param> /// <returns></returns> protected float GetXScalingFactor(Parameters parameters, RestrictiveFrame frame) { // Ненулевой float scalingFactor = 0.01f; float point = 0; while (Convert.ToInt32(point) != Convert.ToInt32(frame.GetSecondPointX())) { float x = (float)(parameters.Fmax); point = frame.GetFirstPointX() + x * scalingFactor; scalingFactor += 0.01f; } return(scalingFactor); }
/// <summary> /// Возвращает коэффициент масштабирования для Y-точек. /// </summary> /// <param name="parameters"></param> /// <param name="frame"></param> /// <returns></returns> protected float GetYScalingFactor(Parameters parameters, RestrictiveFrame frame) { // Ненулевой float scalingFactor = 0.01f; float point = 0; while (Convert.ToInt32(point) != Convert.ToInt32(frame.GetSecondPointY())) { // Здесь макс значение по y float y = (float)(30); point = frame.GetFirstPointY() + y * scalingFactor; scalingFactor += 0.01f; } return(scalingFactor); }
/// <summary> /// Рисует ФЧХ для параметра. /// </summary> /// <param name="plot"></param> /// <param name="parameters"></param> /// <param name="canvas"></param> private void PaintSParameter(ParameterType type, SKPaint paint, Plot plot, Parameters parameters, SKCanvas canvas) { // цикл для расчета коэффициента масштабирования координат X RestrictiveFrame frame = plot.Frame; float scalingFactor = base.GetXScalingFactor(parameters, frame); double i = plot.Frame.GetFirstPointX(); float j = (float)parameters.Fmin; while (j * scalingFactor <= parameters.Fmax * scalingFactor) { float x = j; float y = plot.GetCenterPointOfYAxis(); // Встречаем отрицательную бесконечность на 1 шаге. if (parameters.GetMagnitude(ParameterType.S12, x) == Double.NegativeInfinity) { i += 0.04f; j += 0.04f; continue; } // Инвертирование значений. float currentPhase = (float)parameters.GetPhase(type, x); y += -(currentPhase); if (plot.FirstPointY + y >= plot.SecondPointY) { i += 0.04f; j += 0.04f; continue; } canvas.DrawPoint(plot.FirstPointX + x * scalingFactor, y, paint); i += 0.04f; j += 0.04f; } }
/// <summary> /// Рисует определенные координаты. /// </summary> /// <param name="coordinates"></param> /// <param name="parameters"></param> /// <param name="frame"></param> /// <param name="canvas"></param> private void DrawMarks(TypeOfAxis type, Coordinates coordinates, Parameters parameters, RestrictiveFrame frame, SKCanvas canvas) { float xScalingFactor = base.GetXScalingFactor(parameters, frame); float yScalingFactor = base.GetYScalingFactor(parameters, frame); // Смещенная точка. float shiftPoint = frame.GetFirstPointX() - frame.GetSecondPointX() * _margin; byte quantityOfIterations = 0; float number = 0; float j = (float)parameters.Fmin; double i = 0; switch (type) { case TypeOfAxis.X: i = frame.GetFirstPointX(); while (i <= frame.GetSecondPointX()) { if (Convert.ToInt32(j) == Convert.ToInt32(parameters.Fmax)) { break; } float x = j * xScalingFactor; x += frame.GetFirstPointX(); // Через каждую 25-ю итерацию - целое число. if (quantityOfIterations == 25) { number = Convert.ToInt32(j); canvas.DrawText($"{number}", x, frame.GetSecondPointY() + frame.GetSecondPointY() * _margin, PaintsKeeper.paints["Text Paint"]); // grid canvas.DrawLine(x, frame.GetFirstPointY(), x, frame.GetSecondPointY(), frame.GridPaint); quantityOfIterations = 0; } i += 0.04f; j += 0.04f; quantityOfIterations += 1; } canvas.DrawText($"{coordinates.NameOfXAxis}", frame.GetCenterPointX(), frame.GetSecondPointY() + 2 * frame.GetSecondPointY() * _margin, PaintsKeeper.paints["Text Paint"]); break; case TypeOfAxis.Y: // 0 canvas.DrawText("0", shiftPoint, frame.GetCenterPointY(), PaintsKeeper.paints["Text Paint"]); canvas.DrawLine(frame.GetFirstPointX(), frame.GetCenterPointY(), frame.GetSecondPointX(), frame.GetCenterPointY(), frame.Paint); // положительная часть оси Y float valueToShow = 0; float currentPoint = frame.GetCenterPointY(); while (currentPoint >= frame.GetFirstPointY()) { canvas.DrawText($"{valueToShow.ToString("#")}", shiftPoint, currentPoint, PaintsKeeper.paints["Text Paint"]); // grid canvas.DrawLine(frame.GetFirstPointX(), currentPoint, frame.GetSecondPointX(), currentPoint, frame.GridPaint); valueToShow += 50; currentPoint -= 50; } // отрицательная часть оси Y valueToShow = 0; currentPoint = frame.GetCenterPointY(); while (currentPoint <= frame.GetSecondPointY()) { canvas.DrawText($"{valueToShow.ToString("#")}", shiftPoint, currentPoint, PaintsKeeper.paints["Text Paint"]); // grid canvas.DrawLine(frame.GetFirstPointX(), currentPoint, frame.GetSecondPointX(), currentPoint, frame.GridPaint); valueToShow -= 50; currentPoint += 50; } // Название оси shiftPoint -= frame.GetSecondPointX() * _margin; SKPath path = new SKPath(); path.MoveTo(shiftPoint, frame.GetCenterPointY()); path.LineTo(shiftPoint, frame.GetFirstPointY()); canvas.DrawTextOnPath($"{coordinates.NameOfYAxis}", path, 0, 0, PaintsKeeper.paints["Text Paint"]); path.Close(); break; } }