[SCOTTPLOT/WINFORM] ScatterPlotListDraggable 클래스 : MovePointFunc 속성을 사용해 분산형 리스트 드래그 제한하기
ScottPlot/WinForm 2022. 2. 25. 22:22728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ScottPlot;
using ScottPlot.Plottable;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
Plot plot = new Plot(800, 600);
double[] xValueArray = DataGen.Consecutive(20);
double[] yValueArray = DataGen.Sin(20);
ScatterPlotListDraggable scatterPlotListDraggable = new ScatterPlotListDraggable();
scatterPlotListDraggable.AddRange(xValueArray, yValueArray);
scatterPlotListDraggable.MarkerSize = 5;
plot.Add(scatterPlotListDraggable);
scatterPlotListDraggable.MovePointFunc = ProcessMovePoint;
this.formsPlot.Reset(plot);
this.formsPlot.Refresh();
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 이동 포인트 처리하기 - ProcessMovePoint(xValueArray, yValueArray, index, coordinate)
/// <summary>
/// 이동 포인트 처리하기
/// </summary>
/// <param name="xValueArray">X 값 배열</param>
/// <param name="yValueArray">Y 값 배열</param>
/// <param name="index">인덱스</param>
/// <param name="coordinate">좌표</param>
/// <returns>좌표</returns>
private Coordinate ProcessMovePoint(List<double> xValueArray, List<double> yValueArray, int index, Coordinate coordinate)
{
int leftIndex = Math.Max(index - 1, 0 );
int rightIndex = Math.Min(index + 1, xValueArray.Count - 1);
double newX = coordinate.X;
newX = Math.Max(newX, xValueArray[leftIndex ]);
newX = Math.Min(newX, xValueArray[rightIndex]);
return new Coordinate(newX, coordinate.Y);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요