■ ScatterPlotListDraggable 클래스의 MovePointFunc 속성을 사용해 분산형 리스트 드래그를 제한하는 방법을 보여준다.
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
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 } } |