| | |
| | | public event Action<int> SelectedPointIndexChangedEvent; |
| | | #endregion |
| | | |
| | | #region Initial |
| | | #region Private Initial |
| | | |
| | | /// <summary> |
| | | /// 初始化图表 |
| | |
| | | |
| | | #endregion Initial |
| | | |
| | | #region SetBindingData |
| | | #region Private Chart Event |
| | | |
| | | private int _pick_point_index = -1; |
| | | private void chartControl1_MouseDown(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_initial_data) |
| | | return; |
| | | var hitInfo = chartControl1.CalcHitInfo(e.Location); |
| | | _pick_point_index = -1; |
| | | if (e.Button == MouseButtons.Left) |
| | | { |
| | | if (hitInfo.InSeriesPoint && hitInfo.SeriesPoint.Tag is int index) |
| | | { |
| | | _pick_point_index = index; |
| | | this.SelectedPointIndexChangedEvent?.Invoke(_pick_point_index); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void chartControl1_MouseMove(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | var diagram_coordinates = _diagram.PointToDiagram(e.Location); |
| | | var axis_value = diagram_coordinates.GetAxisValue(_axis_y); |
| | | if (axis_value == null) |
| | | return; |
| | | _series_edit_pt.Points[_pick_point_index].Values[0] = axis_value.NumericalValue; |
| | | _series_edit_pt.Points[_pick_point_index].NumericalArgument = diagram_coordinates.NumericalArgument; |
| | | } |
| | | |
| | | |
| | | private void chartControl1_MouseUp(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | var x = _series_edit_pt.Points[_pick_point_index].NumericalArgument; |
| | | var y = _series_edit_pt.Points[_pick_point_index].Values[0]; |
| | | x = Math.Round(x, 2); |
| | | y = Math.Round(y, 2); |
| | | SetPointValue(_pick_point_index, x, y); |
| | | _pick_point_index = -1; |
| | | } |
| | | |
| | | private void chartControl1_KeyUp(object sender, KeyEventArgs e) |
| | | { |
| | | if (_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | double space_x = _coordinate.CoordSpaceX / 50; |
| | | double space_y = _coordinate.CoordSpaceY / 50; |
| | | double x = _series_edit_pt.Points[_pick_point_index].NumericalArgument; |
| | | double y = _series_edit_pt.Points[_pick_point_index].Values[0]; |
| | | if (e.KeyCode == Keys.Up) |
| | | { |
| | | y += space_y; |
| | | } |
| | | else if (e.KeyCode == Keys.Down) |
| | | { |
| | | y -= space_y; |
| | | } |
| | | else if (e.KeyCode == Keys.Left) |
| | | { |
| | | x -= space_x; |
| | | } |
| | | else if (e.KeyCode == Keys.Right) |
| | | { |
| | | x += space_x; |
| | | } |
| | | x = Math.Round(x, 2); |
| | | y = Math.Round(y, 2); |
| | | _series_edit_pt.Points[_pick_point_index].NumericalArgument = x; |
| | | _series_edit_pt.Points[_pick_point_index].Values[0] = y; |
| | | SetPointValue(_pick_point_index, x, y); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 更新数据 |
| | | /// </summary> |
| | | private void SetPointValue(int index, double x, double y) |
| | | { |
| | | if (IsInvalidData()) |
| | | return; |
| | | _def_pt_list[index].X = x; |
| | | _def_pt_list[index].Y = y; |
| | | this.DefinePointChangedEvent?.Invoke(_def_pt_list); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Set |
| | | |
| | | /// <summary> |
| | | /// 绑定数据 |
| | |
| | | |
| | | #endregion Calc |
| | | |
| | | #region Chart Event |
| | | |
| | | private int _pick_point_index = -1; |
| | | private void chartControl1_MouseDown(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_initial_data) |
| | | return; |
| | | var hitInfo = chartControl1.CalcHitInfo(e.Location); |
| | | _pick_point_index = -1; |
| | | if (e.Button == MouseButtons.Left) |
| | | { |
| | | if (hitInfo.InSeriesPoint && hitInfo.SeriesPoint.Tag is int index) |
| | | { |
| | | _pick_point_index = index; |
| | | this.SelectedPointIndexChangedEvent?.Invoke(_pick_point_index); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void chartControl1_MouseMove(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | var diagram_coordinates = _diagram.PointToDiagram(e.Location); |
| | | var axis_value = diagram_coordinates.GetAxisValue(_axis_y); |
| | | if (axis_value == null) |
| | | return; |
| | | _series_edit_pt.Points[_pick_point_index].Values[0] = axis_value.NumericalValue; |
| | | _series_edit_pt.Points[_pick_point_index].NumericalArgument = diagram_coordinates.NumericalArgument; |
| | | } |
| | | |
| | | |
| | | private void chartControl1_MouseUp(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | var x = _series_edit_pt.Points[_pick_point_index].NumericalArgument; |
| | | var y = _series_edit_pt.Points[_pick_point_index].Values[0]; |
| | | x = Math.Round(x, 2); |
| | | y = Math.Round(y, 2); |
| | | SetPointValue(_pick_point_index, x, y); |
| | | _pick_point_index = -1; |
| | | } |
| | | |
| | | private void chartControl1_KeyUp(object sender, KeyEventArgs e) |
| | | { |
| | | if (_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | double space_x = _coordinate.CoordSpaceX / 50; |
| | | double space_y = _coordinate.CoordSpaceY / 50; |
| | | double x = _series_edit_pt.Points[_pick_point_index].NumericalArgument; |
| | | double y = _series_edit_pt.Points[_pick_point_index].Values[0]; |
| | | if (e.KeyCode == Keys.Up) |
| | | { |
| | | y += space_y; |
| | | } |
| | | else if (e.KeyCode == Keys.Down) |
| | | { |
| | | y -= space_y; |
| | | } |
| | | else if (e.KeyCode == Keys.Left) |
| | | { |
| | | x -= space_x; |
| | | } |
| | | else if (e.KeyCode == Keys.Right) |
| | | { |
| | | x += space_x; |
| | | } |
| | | x = Math.Round(x, 2); |
| | | y = Math.Round(y, 2); |
| | | _series_edit_pt.Points[_pick_point_index].NumericalArgument = x; |
| | | _series_edit_pt.Points[_pick_point_index].Values[0] = y; |
| | | SetPointValue(_pick_point_index, x, y); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 更新数据 |
| | | /// </summary> |
| | | private void SetPointValue(int index, double x, double y) |
| | | { |
| | | if (IsInvalidData()) |
| | | return; |
| | | _def_pt_list[index].X = x; |
| | | _def_pt_list[index].Y = y; |
| | | this.DefinePointChangedEvent?.Invoke(_def_pt_list); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | |
| | | } |