| | |
| | | _line_visible = value; |
| | | _const_line_x.Visible = value; |
| | | _const_line_y.Visible = value; |
| | | _anno_txt_query_info.Visible = value; |
| | | SetAxisXValue(); |
| | | } |
| | | } |
| | |
| | | |
| | | #endregion |
| | | |
| | | #region Public Evnet |
| | | |
| | | /// <summary> |
| | | /// 坐标变换事件 |
| | | /// </summary> |
| | | public event Action<PumpCoordinate> CoordinateChangedEvent = null; |
| | | |
| | | /// <summary> |
| | | /// 查询点变换事件 |
| | | /// </summary> |
| | | public event Action<(long DbId,string Tag,double X,double Y)> AnnotationChangedEvent = null; |
| | | |
| | | #endregion |
| | | |
| | | #region Private Initial |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | this.chartControl1.SetChartDisplay(); |
| | | this.chartControl1.RuntimeHitTesting = true; |
| | | this.chartControl1.AnimationStartMode = ChartAnimationMode.OnLoad; |
| | | //this.chartControl1.AnimationStartMode = ChartAnimationMode.OnLoad; |
| | | |
| | | this.chartControl1.ObjectHotTracked += new DevExpress.XtraCharts.HotTrackEventHandler(this.chartControl1_ObjectHotTracked); |
| | | this.chartControl1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseMove); |
| | | this.chartControl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseUp); |
| | | this.chartControl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseDown); |
| | | this.chartControl1.Resize += new System.EventHandler(this.chartControl1_Resize); |
| | | this.chartControl1.CustomPaint += ChartControl1_CustomPaint; |
| | | |
| | | |
| | | |
| | | |
| | | _diagram = (XYDiagram)this.chartControl1.Diagram; |
| | | _default_pane = _diagram.DefaultPane; |
| | |
| | | _axis_y_eff.Alignment = AxisAlignment.Far; |
| | | _axis_y_power = _diagram.SecondaryAxesY.GetAxisByName("AxisYPower"); |
| | | _axis_y_power.SetSecondaryAxisYQPDisplay(); |
| | | |
| | | |
| | | _const_line_x = (ConstantLine)_diagram.AxisX.ConstantLines.GetElementByName("ConstantLineX"); |
| | | _const_line_x.SetWorkPointLineDisplay(); |
| | |
| | | _axis_y_power.GridLines.Visible = false; |
| | | |
| | | _const_line_x.Visible = false; |
| | | _const_line_y.Visible = false; |
| | | _const_line_y.Visible = false; |
| | | |
| | | _anno_txt_query_info = this.chartControl1.AnnotationRepository[0] as TextAnnotation; |
| | | _anno_txt_query_info.SetTextAnnoWorkPointDisplay(); |
| | | _anno_txt_query_info.Visible = false; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 初始化坐标轴 |
| | |
| | | } |
| | | |
| | | private bool _on_move_x_line = false; |
| | | private bool _on_move_y_line = false; |
| | | private bool _on_move_y_line = false; |
| | | private bool _on_move_annotation = false; |
| | | private TextAnnotation _on_move_annotation_obj = null; |
| | | private void chartControl1_MouseDown(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_initial_data) |
| | |
| | | _on_move_y_line = true; |
| | | } |
| | | } |
| | | else if (hitInfo.InAnnotation) |
| | | { |
| | | if (hitInfo.Annotation.Tag is not string id) |
| | | return; |
| | | if (!long.TryParse(id, out long db_id)) |
| | | return; |
| | | _on_move_annotation = true; |
| | | _on_move_annotation_obj = (TextAnnotation)hitInfo.Annotation; |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | return; |
| | | double chartQ = axis_value.NumericalValue; |
| | | SetAxisXValue(chartQ); |
| | | |
| | | } |
| | | else if (_on_move_y_line) |
| | | { |
| | |
| | | this.chartControl1.Cursor = Cursors.Default; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private void chartControl1_MouseUp(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_initial_data) |
| | | return; |
| | | if (_on_move_annotation && _on_move_annotation_obj != null) |
| | | { |
| | | if (this.AnnotationChangedEvent != null) |
| | | { |
| | | var db_id = Convert.ToInt64(_on_move_annotation_obj.Tag); |
| | | |
| | | var pane_anchor_pt = _on_move_annotation_obj.AnchorPoint as PaneAnchorPoint; |
| | | if (pane_anchor_pt != null) |
| | | { |
| | | var diagram_coordinates = _diagram.PointToDiagram(e.Location); |
| | | AxisValue axis_x_value= diagram_coordinates.GetAxisValue(_axis_x_flow); |
| | | AxisValue axis_y_value = diagram_coordinates.GetAxisValue(pane_anchor_pt.AxisYCoordinate.Axis); |
| | | |
| | | if (axis_x_value==null|| axis_y_value==null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var tag = pane_anchor_pt.Tag?.ToString() ?? null; |
| | | var x = axis_x_value.NumericalValue; |
| | | var y = axis_y_value.NumericalValue; |
| | | |
| | | pane_anchor_pt.AxisXCoordinate.AxisValue = x; |
| | | pane_anchor_pt.AxisYCoordinate.AxisValue = y; |
| | | this.AnnotationChangedEvent?.Invoke((db_id, tag, x, y)); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | _on_move_x_line = false; |
| | | _on_move_y_line = false; |
| | | _on_move_annotation = false; |
| | | _on_move_annotation_obj = null; |
| | | } |
| | | |
| | | private void chartControl1_Resize(object sender, EventArgs e) |
| | | { |
| | | var x = this.chartControl1.Location.X + this.chartControl1.Width*0.90; |
| | | var y = this.chartControl1.Location.Y+this.chartControl1.Height *0.1; |
| | | |
| | | (_anno_txt_query_info.AnchorPoint as ChartAnchorPoint).X = (int)x; |
| | | (_anno_txt_query_info.AnchorPoint as ChartAnchorPoint).Y = (int)y; |
| | | } |
| | | |
| | | |
| | | private void ChartControl1_CustomPaint(object sender, CustomPaintEventArgs e) |
| | | { |
| | |
| | | _initial_data = false; |
| | | this.chartControl1.BeginInit(); |
| | | this.chartControl1.Series.Clear(); |
| | | this.chartControl1.AnnotationRepository.Clear(); |
| | | for (int i = this.chartControl1.AnnotationRepository.Count - 1; i > 0; i--) |
| | | { |
| | | if (i == 0) |
| | | break; |
| | | this.chartControl1.AnnotationRepository.RemoveAt(i); |
| | | } |
| | | this.chartControl1.Legend.CustomItems.Clear(); |
| | | this.chartControl1.EndInit(); |
| | | } |
| | |
| | | |
| | | this.chartControl1.BeginInit(); |
| | | this.chartControl1.Series.Clear(); |
| | | this.chartControl1.AnnotationRepository.Clear(); |
| | | for (int i = this.chartControl1.AnnotationRepository.Count - 1; i > 0; i--) |
| | | { |
| | | if (i == 0) |
| | | break; |
| | | this.chartControl1.AnnotationRepository.RemoveAt(i); |
| | | } |
| | | this.chartControl1.Legend.CustomItems.Clear(); |
| | | if (IsInvalidData()) |
| | | { |
| | |
| | | axis_x = _axis_x_flow; |
| | | axis_y = _axis_y_power; |
| | | pane = _split_panel? _bottom_pane: _default_pane; |
| | | } |
| | | } |
| | | |
| | | if (vm.AnnotationList != null && vm.AnnotationList.Any()) |
| | | { |
| | | foreach (var name in vm.AnnotationList) |
| | | { |
| | | AddAnnotation(vm.Id, name.Text, vm.Color, axis_y, pane, new Geometry.Point2d(name.X, name.Y), -40); |
| | | } |
| | | AddAnnotation(vm.Id, name.Tag, name.Text, vm.Color, axis_y, pane, new Geometry.Point2d(name.X, name.Y), 0,0); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | this.chartControl1.Series.Add(series); |
| | | } |
| | | |
| | | private void AddAnnotation(string id, string caption, Color color, AxisYBase axis_y, XYDiagramPaneBase pane, Yw.Geometry.Point2d pt, double angle = -10) |
| | | private void AddAnnotation(string id, string tag, string caption, Color color, AxisYBase axis_y, XYDiagramPaneBase pane, Yw.Geometry.Point2d pt, double angle = -10, double connector_length = 20) |
| | | { |
| | | if (pt == null) |
| | | return; |
| | |
| | | pane_anchor_pt.AxisYCoordinate.Axis = axis_y; |
| | | pane_anchor_pt.AxisXCoordinate.AxisValue = anchor_pt.X; |
| | | pane_anchor_pt.AxisYCoordinate.AxisValue = anchor_pt.Y; |
| | | pane_anchor_pt.Tag = tag; |
| | | |
| | | |
| | | |
| | | var relative_position = new DevExpress.XtraCharts.RelativePosition(); |
| | | relative_position.Angle = angle; |
| | | relative_position.ConnectorLength = 20; |
| | | |
| | | relative_position.ConnectorLength = connector_length; |
| | | |
| | | var text_annotation = new TextAnnotation(); |
| | | text_annotation.AnchorPoint = pane_anchor_pt; |
| | | text_annotation.AutoHeight = true; |
| | |
| | | text_annotation.Padding.Left = 1; |
| | | text_annotation.Padding.Right = 1; |
| | | text_annotation.Padding.Top = 1; |
| | | text_annotation.RuntimeMoving = true; |
| | | text_annotation.RuntimeAnchoring = false; |
| | | text_annotation.RuntimeMoving = false; |
| | | text_annotation.RuntimeAnchoring = true; |
| | | text_annotation.RuntimeResizing = false; |
| | | text_annotation.RuntimeRotation = false; |
| | | text_annotation.RuntimeEditing = false; |
| | | text_annotation.Text = caption; |
| | | text_annotation.TextColor = color; |
| | | text_annotation.ShapePosition = relative_position; |
| | | text_annotation.Visible = true; |
| | | text_annotation.EnableAntialiasing = DefaultBoolean.True; |
| | | |
| | | text_annotation.DXFont = new DevExpress.Drawing.DXFont(this.Font.Name, 10F); |
| | | |
| | | this.chartControl1.AnnotationRepository.Add(text_annotation); |
| | |
| | | _const_line_x.Title.Visible = false; |
| | | _const_line_y.Visible = false; |
| | | _const_line_y.Title.Visible = false; |
| | | _anno_txt_query_info.Visible = false; |
| | | return; |
| | | } |
| | | else |
| | |
| | | _const_line_x.Title.Visible = true; |
| | | _const_line_y.Visible = true; |
| | | _const_line_y.Title.Visible = true; |
| | | _anno_txt_query_info.Visible = true; |
| | | } |
| | | if (this.IsInvalidData()) |
| | | return; |
| | | var vm_sel = _vm_list.Find(x => x.IsSelect); |
| | | if (vm_sel == null) |
| | | var qh = _vm_list.Find(x => x.IsSelect&&x.CurveType== eCurveType.QH); |
| | | if (qh == null) |
| | | return; |
| | | |
| | | var min_x = vm_sel.FitPointList.Min(x => x.X); |
| | | var max_x = vm_sel.FitPointList.Max(x => x.X); |
| | | var min_x = qh.FitPointList.Min(x => x.X); |
| | | var max_x = qh.FitPointList.Max(x => x.X); |
| | | |
| | | if (x == null) |
| | | { |
| | |
| | | } |
| | | |
| | | var x_value = x.Value; |
| | | var y_value = vm_sel.FitPointList.GetInterPointsY(x_value)?.FirstOrDefault(); |
| | | var y_value = qh.FitPointList.GetInterPointsY(x_value)?.FirstOrDefault(); |
| | | |
| | | _const_line_x.AxisValue = x_value; |
| | | _const_line_x.Title.Text = $"{x_value:N1}"; |
| | | |
| | | _const_line_y.AxisValue = y_value; |
| | | _const_line_y.Title.Text = $"{y_value:N1}"; |
| | | |
| | | var query_info_builder = new StringBuilder(); |
| | | query_info_builder.AppendLine($"{x_value:N2} m³/h "); |
| | | query_info_builder.AppendLine($"{y_value:N2} m"); |
| | | |
| | | var qe = _vm_list.Find(x => x.IsSelect && x.CurveType == eCurveType.QE); |
| | | if (qe != null) |
| | | { |
| | | var eff = qe.FitPointList.GetInterPointsY(x_value).FirstOrDefault(); |
| | | query_info_builder.AppendLine($"{eff:N2} % "); |
| | | } |
| | | |
| | | var qp = _vm_list.Find(x => x.IsSelect && x.CurveType == eCurveType.QP); |
| | | if (qp != null) |
| | | { |
| | | var power = qp.FitPointList.GetInterPointsY(x_value).FirstOrDefault(); |
| | | query_info_builder.Append($"{power:N2} kW/h "); |
| | | } |
| | | |
| | | |
| | | _anno_txt_query_info.Text = query_info_builder.ToString(); |
| | | _anno_txt_query_info.AutoSize = true; |
| | | _anno_txt_query_info.Visible = true; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | |
| | | #endregion |
| | | } |
| | | } |
| | | |
| | | ///// <summary> |
| | | ///// 设置图表轴 |
| | | ///// </summary> |
| | | //private void SetChartAxis() |
| | | //{ |
| | | // _axis_x_flow.Visibility = DefaultBoolean.False; |
| | | // _axis_x_flow.GridLines.Visible = false; |
| | | // _axis_y_head.Visibility = DefaultBoolean.False; |
| | | // _axis_y_head.GridLines.Visible = false; |
| | | // _axis_y_eff.Visibility = DefaultBoolean.False; |
| | | // _axis_y_eff.GridLines.Visible = false; |
| | | // _axis_y_power.Visibility = DefaultBoolean.False; |
| | | // _axis_y_power.GridLines.Visible = false; |
| | | // if (_coordinate == null) |
| | | // { |
| | | // _const_line_x.Visible = false; |
| | | // _const_line_y.Visible = false; |
| | | // _bottom_pane.Visibility = ChartElementVisibility.Hidden; |
| | | // return; |
| | | // } |
| | | |
| | | |
| | | // //计算刻度 Q |
| | | // var axisQLabels = new List<CustomAxisLabel>(); |
| | | // var disQ = _coordinate.CoordMinQ; |
| | | // for (int i = 0; i < _coordinate.GridNumberX + 1; i++) |
| | | // { |
| | | // axisQLabels.Add(new CustomAxisLabel(disQ.ToString("N0"), disQ)); |
| | | // disQ = disQ + _coordinate.CoordSpaceQ; |
| | | // } |
| | | |
| | | // _axis_x_flow.CustomLabels.Clear(); |
| | | // _axis_x_flow.CustomLabels.AddRange(axisQLabels.ToArray()); |
| | | // _axis_x_flow.Visibility = DefaultBoolean.True; |
| | | // _axis_x_flow.GridLines.Visible = true; |
| | | |
| | | |
| | | // //计算刻度 |
| | | // var axis_head_labels = new List<CustomAxisLabel>(); |
| | | // var display_head = _coordinate.CoordMinH + _coordinate.CoordSpaceH * _coordinate.StartLineNoH; |
| | | // for (int i = _coordinate.StartLineNoH; i < _coordinate.EndLineNoH + 1; i++) |
| | | // { |
| | | // axis_head_labels.Add(new CustomAxisLabel(display_head.ToString(), display_head)); |
| | | // display_head = display_head + _coordinate.CoordSpaceH; |
| | | // } |
| | | |
| | | // _axis_y_head.CustomLabels.Clear(); |
| | | // _axis_y_head.CustomLabels.AddRange(axis_head_labels.ToArray()); |
| | | // _axis_y_head.Visibility = DefaultBoolean.True; |
| | | // _axis_y_head.GridLines.Visible = true; |
| | | |
| | | // //效率 |
| | | // if (_maxE > _minE && _eff_visible) |
| | | // { |
| | | // //计算刻度 |
| | | // var label_list = new List<CustomAxisLabel>(); |
| | | // var display_eff = _coordinate.CoordMinE + _coordinate.CoordSpaceE * _coordinate.StartLineNoE; |
| | | // for (int i = _coordinate.StartLineNoE; i < _coordinate.EndLineNoE + 1; i++) |
| | | // { |
| | | // label_list.Add(new CustomAxisLabel(display_eff.ToString(), display_eff)); |
| | | // display_eff = display_eff + _coordinate.CoordSpaceE; |
| | | // } |
| | | |
| | | // _axis_y_eff.CustomLabels.Clear(); |
| | | // _axis_y_eff.CustomLabels.AddRange(label_list.ToArray()); |
| | | // _axis_y_eff.Visibility = DefaultBoolean.True; |
| | | // _axis_y_eff.GridLines.Visible = true; |
| | | // } |
| | | |
| | | // //功率 |
| | | // if (_maxP > _minP && _power_visible) |
| | | // { |
| | | // //计算刻度 |
| | | // var label_list = new List<CustomAxisLabel>(); |
| | | // double display_power = _coordinate.CoordMinP + _coordinate.CoordSpaceP * _coordinate.StartLineNoP; |
| | | // for (int i = _coordinate.StartLineNoP; i < _coordinate.EndLineNoP + 1; i++) |
| | | // { |
| | | // label_list.Add(new CustomAxisLabel(display_power.ToString(), display_power)); |
| | | // display_power = display_power + _coordinate.CoordSpaceP; |
| | | // } |
| | | |
| | | // _axis_y_power.CustomLabels.Clear(); |
| | | // _axis_y_power.CustomLabels.AddRange(label_list.ToArray()); |
| | | // _axis_y_power.Visibility = DefaultBoolean.True; |
| | | // _axis_y_power.GridLines.Visible = true; |
| | | // } |
| | | |
| | | |
| | | // _axis_x_flow.SetAxisRange(_coordinate.CoordMinQ, _coordinate.CoordMinQ + _coordinate.GridNumberX * _coordinate.CoordSpaceQ); |
| | | // if (_split_panel) |
| | | // { |
| | | // if (_power_visible) |
| | | // { |
| | | // var grid_count_head = _coordinate.EndLineNoH - _coordinate.StartLineNoH; |
| | | // var grid_count_eff = _coordinate.EndLineNoE - _coordinate.StartLineNoE; |
| | | // int grid_count_add = Math.Max(grid_count_head, grid_count_eff); |
| | | // if (_eff_visible) |
| | | // grid_count_add += +5;//多两条 |
| | | |
| | | // var max_axis_head = _coordinate.CoordMinH + _coordinate.EndLineNoH * _coordinate.CoordSpaceH; |
| | | // var min_axis_head = max_axis_head - grid_count_add * _coordinate.CoordSpaceH; |
| | | // _axis_y_head.SetAxisRange(min_axis_head, max_axis_head); |
| | | |
| | | // var min_axis_eff = _coordinate.CoordMinE + _coordinate.StartLineNoE * _coordinate.CoordSpaceE; |
| | | // var max_axis_eff = min_axis_eff + grid_count_add * _coordinate.CoordSpaceE; |
| | | |
| | | // _axis_y_eff.SetAxisRange(min_axis_eff, max_axis_eff); |
| | | // _bottom_pane.Visibility = ChartElementVisibility.Visible; |
| | | // } |
| | | // else |
| | | // { |
| | | // var grid_count_power = _coordinate.EndLineNoP - _coordinate.StartLineNoP; |
| | | // var grid_delete_head = grid_count_power * _coordinate.CoordSpaceH; |
| | | // grid_delete_head = _coordinate.CoordMinH < 0 ? -grid_delete_head : grid_delete_head; |
| | | |
| | | // var grid_delete_eff = grid_count_power * _coordinate.CoordSpaceE; |
| | | // grid_delete_eff = _coordinate.CoordMinE < 0 ? -grid_delete_eff : grid_delete_eff; |
| | | |
| | | // _axis_y_head.SetAxisRange(_coordinate.CoordMinH - grid_delete_head, _coordinate.CoordMinH + _coordinate.GridNumberY * _coordinate.CoordSpaceH); |
| | | // _axis_y_eff.SetAxisRange(_coordinate.CoordMinE - grid_delete_eff, _coordinate.CoordMinE + _coordinate.GridNumberY * _coordinate.CoordSpaceE); |
| | | |
| | | // _bottom_pane.Visibility = ChartElementVisibility.Hidden; |
| | | // } |
| | | |
| | | // if ((!_eff_visible) && (!_power_visible)) |
| | | // { |
| | | // _axis_y_head.SetAxisRange(_coordinate.DispMinH(), _coordinate.DispMaxH()); |
| | | // } |
| | | // _axis_y_power.SetAxisRange(_coordinate.DispMinP(), _coordinate.DispMaxP()); |
| | | // } |
| | | // else |
| | | // { |
| | | // if ((!_eff_visible) && (!_power_visible)) |
| | | // { |
| | | // _axis_y_head.SetAxisRange(_coordinate.DispMinH(), _coordinate.DispMaxH()); |
| | | // } |
| | | // else if ((!_eff_visible) && _power_visible) |
| | | // { |
| | | // var grid_count_eff = _coordinate.EndLineNoE - _coordinate.StartLineNoE; |
| | | // if (_coordinate.EndLineNoH - _coordinate.StartLineNoH < 6) |
| | | // grid_count_eff++; |
| | | // var grid_delete_head = grid_count_eff * _coordinate.CoordSpaceH; |
| | | // grid_delete_head = _coordinate.CoordMinH < 0 ? -grid_delete_head : grid_delete_head; |
| | | // var grid_delete_power = grid_count_eff * _coordinate.CoordSpaceP; |
| | | |
| | | // _axis_y_head.SetAxisRange(_coordinate.CoordMinH - grid_delete_head, _coordinate.CoordMinH + _coordinate.GridNumberY * _coordinate.CoordSpaceH); |
| | | // _axis_y_power.SetAxisRange(_coordinate.CoordMinP, _coordinate.CoordMinP + _coordinate.GridNumberY * _coordinate.CoordSpaceP - grid_delete_power); |
| | | // } |
| | | // else if (_eff_visible && (!_power_visible)) |
| | | // { |
| | | // var grid_count_power = _coordinate.EndLineNoP - _coordinate.StartLineNoP; |
| | | // var grid_delete_head = grid_count_power * _coordinate.CoordSpaceH; |
| | | // grid_delete_head = _coordinate.CoordMinH < 0 ? -grid_delete_head : grid_delete_head; |
| | | |
| | | // var grid_delete_eff = grid_count_power * _coordinate.CoordSpaceE; |
| | | // grid_delete_eff = _coordinate.CoordMinE < 0 ? -grid_delete_eff : grid_delete_eff; |
| | | |
| | | // _axis_y_head.SetAxisRange(_coordinate.CoordMinH - grid_delete_head, _coordinate.CoordMinH + _coordinate.GridNumberY * _coordinate.CoordSpaceH); |
| | | // _axis_y_eff.SetAxisRange(_coordinate.CoordMinE - grid_delete_eff, _coordinate.CoordMinE + _coordinate.GridNumberY * _coordinate.CoordSpaceE); |
| | | // } |
| | | // else |
| | | // { |
| | | // _axis_y_head.SetAxisRange(_coordinate.CoordMinH, _coordinate.CoordMinH + _coordinate.GridNumberY * _coordinate.CoordSpaceH); |
| | | // _axis_y_eff.SetAxisRange(_coordinate.CoordMinE, _coordinate.CoordMinE + _coordinate.GridNumberY * _coordinate.CoordSpaceE); |
| | | // _axis_y_power.SetAxisRange(_coordinate.CoordMinP, _coordinate.CoordMinP + _coordinate.GridNumberY * _coordinate.CoordSpaceP); |
| | | // } |
| | | |
| | | // _bottom_pane.Visibility = ChartElementVisibility.Hidden; |
| | | // } |
| | | |
| | | //} |
| | | } |