/// <summary> /// 绘制事件点,位置信息来源于计算 /// </summary> ///// <param name="position">事件点显示的位置</param> /// <param name="dataPoint">事件内容</param> private void DrawEventPointHelper(/*Point position, */ EventData eventData) { //Ellipse eventTag = new Ellipse() //{ // StrokeThickness = 10, // Stroke = Brushes.DarkSlateGray, // Fill = Brushes.DarkSlateGray, // Height = 10, // Width = 10 //}; if (!ShowEventTag) { return; } var xPos = CaculateXPosForEventData(eventData); if (xPos == -1) { return; } var yPos = CaculateAverageYPosForXPos(xPos); Image eventTag = new Image(); eventTag.Source = new BitmapImage(new Uri(@"/Resource/EventPoint.ico", UriKind.Relative)); eventTag.MouseLeftButtonDown += (sender, args) => { EventPointWindow msgWindow = new EventPointWindow(); msgWindow.Title = "数据点"; //msgWindow.Description.Text = "Value: " + eventData.RawData; msgWindow.Detail.Text = eventData.Description; msgWindow.Timestamp.Text = eventData.TimeStamp.ToString("yyyy-MM-dd HH:mm:ss"); var pos = Mouse.GetPosition(null); msgWindow.Left = pos.X; msgWindow.Top = pos.Y; msgWindow.Show(); //MessageBox.Show(dataPoint.DataTag.Description); }; Canvas.SetLeft(eventTag, xPos - 5); // 移到线上 Canvas.SetTop(eventTag, yPos - 5); var index = BasePart.Children.Add(eventTag); //_eventPoints.Add(new ComponentItem<Ellipse>(index, eventTag)); _eventPoints.Add(eventTag); }
private void DrawLineHelper(PolylineItem lineItem) { if (lineItem.line == null) { var prop = _linePropertyDictionary[lineItem.LineName]; lineItem.line = new Polyline() { Stroke = new SolidColorBrush(prop.LineColor), StrokeThickness = prop.StrokeThickness }; Border lineControl = (Border)CreateLineControlBorder(prop); lineControl.MouseLeftButtonDown += (sender, args) => { if (lineItem.Visible) { //var tmp = (Border) lineControl; //var label = (Label) tmp.Child; lineControl.Background = Brushes.DarkGray; lineItem.Visible = false; lineItem.line.Visibility = Visibility.Hidden; } else { //var tmp = (Border)lineControl; //var label = (Label)tmp.Child; lineControl.Background = new SolidColorBrush(prop.LineColor); lineItem.Visible = true; lineItem.line.Visibility = Visibility.Visible; } }; LinesStackPanel.Children.Add(lineControl); // 判断双击 int mouseLeftClickCnt = 0; DateTime lastClickTime = DateTime.Now; // 标记高亮 //bool highlightPolyline = false; lineItem.line.MouseLeftButtonDown += (sender, args) => { if (mouseLeftClickCnt == 0) { lastClickTime = DateTime.Now; } if (mouseLeftClickCnt > 0 && mouseLeftClickCnt % 2 == 0 && (DateTime.Now - lastClickTime).TotalMilliseconds < 500) { var pos = args.GetPosition(lineItem.line); var point = lineItem._showableDataPointsBuffer[(int)(pos.X - _originPoint.X)]; EventPointWindow tmpWindowForPoint = new EventPointWindow(); tmpWindowForPoint.LoadEventData(null); // GetPosition参数为null,则默认取全局的绝对坐标(显示屏幕),直接画点即可 var tmpPos = Mouse.GetPosition(null); tmpWindowForPoint.Left = tmpPos.X; tmpWindowForPoint.Top = tmpPos.Y; if (tmpWindowForPoint.ShowDialog().Value) { DrawEventPointHelper(tmpWindowForPoint.CurrentData); } } else { lastClickTime = DateTime.Now; if (!_highlightPolyline) { _highlightPolyline = true; lineItem.line.Stroke = Brushes.Aqua; lineItem.line.StrokeThickness = 1.5; var pos = args.GetPosition(lineItem.line); var point = lineItem._showableDataPointsBuffer[(int)pos.X]; _currentSelectPolylineItem = lineItem; } else { lineItem.line.Stroke = new SolidColorBrush(prop.LineColor); lineItem.line.StrokeThickness = prop.StrokeThickness; } } mouseLeftClickCnt++; }; ////鼠标碰线 //_wave.MouseEnter += (sender, args) => //{ // _wave.Stroke = Brushes.Aqua; // _wave.StrokeThickness = 1.5; // var pos = args.GetPosition(_wave); // var point = _showableDataPointsBuffer[(int) pos.X]; //}; //// 鼠标离开 //_wave.MouseLeave += (sender, args) => //{ // //if (_showPointWindow == false) // //{ // _wave.Stroke = Brushes.Black; // _wave.StrokeThickness = 1; // //_tmpWindowForPoint.Hide(); // //_tmpWindowForPoint.Visibility = Visibility.Hidden; // //} //}; //_wave.MouseMove += (sender, args) => //{ // var pos = args.GetPosition(BasePart); // var point = _showableDataPointsBuffer[(int) (pos.X - _originPoint.X)]; // _tmpWindowForPoint.LoadDataPoint(point); //}; var index = BasePart.Children.Add(lineItem.line); //_wave = new ComponentItem<Polyline>(index, polyLine); //_wave = polyLine; } // 全屏刷新时每次显示全部的buffer数据点内容 // 删除事件点 foreach (var eventPoint in _eventPoints) { BasePart.Children.Remove(eventPoint); } _eventPoints.Clear(); // 画线 lineItem._displayOffset = 0; var tmpPoints = new PointCollection(); foreach (var dataPoint in lineItem._showableDataPointsBuffer) { if (dataPoint != null) { tmpPoints.Add(DrawPointHelper(dataPoint, lineItem._displayOffset++)); } } lineItem.line.Points = tmpPoints; }