private void DrawLinePointDot(Graphics g, SolidBrush brush, ref LinePoint pOrig, ref PointF pDot) { if (float.IsNaN(pOrig.Value)) { if (Chart.ShowInvalidPoint && this.YAxes.Mode != YAxesMode.Digital) { g.FillRectangle(Brushes.Black, pDot.X - 4f, pDot.Y - 4f, 8, 8); } } else { g.FillEllipse(brush, pDot.X - 2.5f, pDot.Y - 2.5f, 5, 5); } }
private void MarkMaxMin(LinePoint linePoint) { float val = linePoint.Value; if ((!float.IsInfinity(val)) && (!float.IsNaN(val)) && (!float.IsNegativeInfinity(val)) && (!float.IsPositiveInfinity(val))) { if (float.IsNaN(maxVal)) { maxVal = val; minVal = val; } else { if (val > maxVal) { maxVal = val; } else if (val < minVal) { minVal = val; } } } }
public LinePoint GetCursorPoint(bool print, List<LinePoint> lineSegment) { LinePoint pt = new LinePoint(0, float.NaN); RectangleF disRect = print ? this.LineArea.PrintRectangle : this.LineArea.Rectangle; Point pCursor = this.LineArea.CurveGroup.CursorPoint; long time = (long)((pCursor.X - disRect.X) / CurveGroup.ScaleSize * this.LineArea.CurveGroup.XAxes.TimeScale) + this.LineArea.CurveGroup.XAxes.OriginalTime; if (this.TimeDayAlign) { List<LinePoint> points = lineSegment; int pCnt = points.Count; if (pCnt > 0) { int startIndex = 0; int endIndex = pCnt - 1; if (points[0].DayAlignTime > time) return pt; if (points[endIndex].DayAlignTime < time) { return points[endIndex]; } int midIndex = -1; while (startIndex + 1 < endIndex) { midIndex = (startIndex + endIndex) / 2; if (points[midIndex].DayAlignTime < time) { startIndex = midIndex; } else if (points[midIndex].DayAlignTime > time) { endIndex = midIndex; } else { for (int j = midIndex; j >= 0; j--) { float val = points[j].Value; if (float.IsInfinity(val) || float.IsNaN(val) || float.IsNegativeInfinity(val) || float.IsPositiveInfinity(val)) continue; return points[j]; } return points[0]; } } if (midIndex > 0) { for (int j = startIndex; j >= 0; j--) { float val = points[j].Value; if (float.IsInfinity(val) || float.IsNaN(val) || float.IsNegativeInfinity(val) || float.IsPositiveInfinity(val)) continue; return points[j]; } return points[0]; } else { return points[0]; } } } else { List<LinePoint> points = lineSegment; int pCnt = points.Count; if (pCnt > 0) { int startIndex = 0; int endIndex = pCnt - 1; if (points[0].Time > time) return pt; if (points[endIndex].Time < time) { return points[endIndex]; } int midIndex = -1; while (startIndex + 1 < endIndex) { midIndex = (startIndex + endIndex) / 2; if (points[midIndex].Time < time) { startIndex = midIndex; } else if (points[midIndex].Time > time) { endIndex = midIndex; } else { for (int j = midIndex; j >= 0; j--) { float val = points[j].Value; if (float.IsInfinity(val) || float.IsNaN(val) || float.IsNegativeInfinity(val) || float.IsPositiveInfinity(val)) continue; return points[j]; } return points[0]; } } if (midIndex > 0) { for (int j = startIndex; j >= 0; j--) { float val = points[j].Value; if (float.IsInfinity(val) || float.IsNaN(val) || float.IsNegativeInfinity(val) || float.IsPositiveInfinity(val)) continue; return points[j]; } return points[0]; } else { return points[0]; } } } return pt; }
private void DrawLine(Graphics g, RectangleF rect, List<LinePoint> points, bool print) { if (this.Visible == false) return; RectangleF disRect = print ? this.LineArea.PrintRectangle : this.LineArea.Rectangle; // RectangleF borderRect = new RectangleF(disRect.X, disRect.Top + LineArea.CaptionHeight, disRect.Width, disRect.Height - LineArea.CaptionHeight - LineArea.XScaleHeight); RectangleF borderRect = disRect; float lastValue = float.NaN; bool prevValid = false; long prevTime = -1; long prevX = -1; float prevStart = 0; float prevEnd = 0; float prevMax = float.MinValue; float prevMin = float.MaxValue; XAxes xAxes = this.Chart.XAxes; long timeEnd = xAxes.OriginalTime + (long)((borderRect.Width + CurveGroup.MarginRight) * 1d / CurveGroup.ScaleSize * xAxes.TimeScale); bool lookbackPoint = false; int lookbackNum = 0; using (Pen pen = new Pen(this.LineColor, this.LineWidth)) using (SolidBrush brush = new SolidBrush(this.LineColor)) { if (print) { pen.Color = Color.Lime; brush.Color = Color.Lime; } int pCnt = points.Count; int startIndex = SearchPoint(points, xAxes.OriginalTime); startIndex -= 10; if (startIndex < 0) { startIndex = 0; } for (int i = startIndex; i >= 0; i--) { float val = points[i].Value; if (float.IsInfinity(val) || float.IsNaN(val) || float.IsNegativeInfinity(val) || float.IsPositiveInfinity(val)) continue; startIndex = i; break; } for (int i = startIndex; i < pCnt; i++) { lookbackPoint = false; LinePoint pOrig = points[i]; LinePoint p = pOrig; if (this.TimeDayAlign) { p.Time = p.DayAlignTime; } if (i > 1 && i < pCnt) { if ((points[i-2].Time > timeEnd) && (points[i-1].Time > timeEnd) && (points[i].Time > timeEnd)) { break; } } if (float.IsNaN(pOrig.Value)) { p = new LinePoint(pOrig.Time, lastValue); } if (float.IsNaN(p.Value) || float.IsInfinity(p.Value) || float.IsNegativeInfinity(p.Value) || float.IsPositiveInfinity(p.Value)) { if (prevValid && (prevX >= 0) && (prevX < borderRect.Width) && (prevMax > prevMin)) { if (prevMax > 0 && prevMin < borderRect.Height) { float max = Math.Min(prevMax, borderRect.Height); float min = Math.Max(prevMin, 0); g.DrawLine(pen, prevX + borderRect.X, borderRect.Bottom - min, prevX + borderRect.X, borderRect.Bottom - max); } } lastValue = float.NaN; prevValid = false; } else { lastValue = p.Value; long posX = (p.Time - xAxes.OriginalTime) * CurveGroup.ScaleSize / xAxes.TimeScale; float posY = 0; if (this.YAxes.Mode == YAxesMode.Auto) { posY = (p.Value - this.LineArea.SharedYAxes.YAxesMin) / (this.LineArea.SharedYAxes.YAxesMax - this.LineArea.SharedYAxes.YAxesMin) * borderRect.Height; } else { posY = (p.Value - this.YAxes.YAxesMin) / (this.YAxes.YAxesMax - this.YAxes.YAxesMin) * borderRect.Height; } if (prevX + borderRect.X <= this.LineArea.CurveGroup.CursorPoint.X) { this.CursorValue = p.Value; } if (prevValid && (posX == prevX)) { prevEnd = posY; if (posY > prevMax) { prevMax = posY; } if (posY < prevMin) { prevMin = posY; } } else { if (posX != prevX) { if (prevValid && (prevX >= 0) && (prevX < borderRect.Width) && (prevMax > prevMin)) { if (prevMax > 0 && prevMin < borderRect.Height) { float max = Math.Min(prevMax, borderRect.Height); float min = Math.Max(prevMin, 0); g.DrawLine(pen, prevX + borderRect.X, borderRect.Bottom - min, prevX + borderRect.X, borderRect.Bottom - max); } } } if (prevValid && (posX > prevX)) { if (i > 0) { PointF p1 = new PointF(prevX + borderRect.X, borderRect.Bottom - prevEnd); PointF p2 = new PointF(posX + borderRect.X, borderRect.Bottom - posY); RectangleF rectBig = new RectangleF(borderRect.X - 1, borderRect.Y - 1, borderRect.Width + 2, borderRect.Height + 2); DrawLine(g, pen, rectBig, p1, p2); } } //if (prevValid && (posX < prevX)) if (prevValid && (prevTime - p.Time) > 10L * 1000000L) { lookbackPoint = true; lookbackNum++; } prevX = posX; prevStart = posY; prevMax = posY; prevMin = posY; prevEnd = posY; prevValid = true; } //绘制点 if (this.LineArea.CurveGroup.DrawPointFlagXAxesScale >= this.LineArea.CurveGroup.XAxes.TimeScale) { PointF pDot = new PointF(borderRect.X + posX, borderRect.Bottom - posY); //把边框扩大1个像素 RectangleF rectBig = new RectangleF(borderRect.X - 1, borderRect.Y - 1, borderRect.Width + 2, borderRect.Height + 2); if (rectBig.Contains(pDot)) { if (lookbackPoint) { g.FillRectangle(brush, pDot.X - 7f, pDot.Y - 7f, 14, 14); using (Font font = new Font("雅黑", 8)) { StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; g.DrawString(lookbackNum.ToString(), font, Brushes.Black, new RectangleF(pDot.X - 7f, pDot.Y - 7f, 14, 14), sf); } } else { DrawLinePointDot(g, brush, ref pOrig, ref pDot); } } } } prevTime = p.Time; } } }
public override bool AddPoint(LinePoint linePoint) { MarkMaxMin(linePoint); MakeYAxes(); if (currentSeg == null) { currentSeg = new List<LinePoint>(); listSegment.Add(currentSeg); } else if(linePoint.Time<PrevPointTime-10*LineArea.TicksPerSecond) { currentSeg = new List<LinePoint>(); listSegment.Add(currentSeg); } currentSeg.Add(linePoint); PrevPointTime = linePoint.Time; return base.AddPoint(linePoint); }
public LinePoint GetCursorPoint(bool print, List <LinePoint> lineSegment) { LinePoint pt = new LinePoint(0, float.NaN); RectangleF disRect = print ? this.LineArea.PrintRectangle : this.LineArea.Rectangle; Point pCursor = this.LineArea.CurveGroup.CursorPoint; long time = (long)((pCursor.X - disRect.X) / CurveGroup.ScaleSize * this.LineArea.CurveGroup.XAxes.TimeScale) + this.LineArea.CurveGroup.XAxes.OriginalTime; if (this.TimeDayAlign) { List <LinePoint> points = lineSegment; int pCnt = points.Count; if (pCnt > 0) { int startIndex = 0; int endIndex = pCnt - 1; if (points[0].DayAlignTime > time) { return(pt); } if (points[endIndex].DayAlignTime < time) { return(points[endIndex]); } int midIndex = -1; while (startIndex + 1 < endIndex) { midIndex = (startIndex + endIndex) / 2; if (points[midIndex].DayAlignTime < time) { startIndex = midIndex; } else if (points[midIndex].DayAlignTime > time) { endIndex = midIndex; } else { for (int j = midIndex; j >= 0; j--) { float val = points[j].Value; if (float.IsInfinity(val) || float.IsNaN(val) || float.IsNegativeInfinity(val) || float.IsPositiveInfinity(val)) { continue; } return(points[j]); } return(points[0]); } } if (midIndex > 0) { for (int j = startIndex; j >= 0; j--) { float val = points[j].Value; if (float.IsInfinity(val) || float.IsNaN(val) || float.IsNegativeInfinity(val) || float.IsPositiveInfinity(val)) { continue; } return(points[j]); } return(points[0]); } else { return(points[0]); } } } else { List <LinePoint> points = lineSegment; int pCnt = points.Count; if (pCnt > 0) { int startIndex = 0; int endIndex = pCnt - 1; if (points[0].Time > time) { return(pt); } if (points[endIndex].Time < time) { return(points[endIndex]); } int midIndex = -1; while (startIndex + 1 < endIndex) { midIndex = (startIndex + endIndex) / 2; if (points[midIndex].Time < time) { startIndex = midIndex; } else if (points[midIndex].Time > time) { endIndex = midIndex; } else { for (int j = midIndex; j >= 0; j--) { float val = points[j].Value; if (float.IsInfinity(val) || float.IsNaN(val) || float.IsNegativeInfinity(val) || float.IsPositiveInfinity(val)) { continue; } return(points[j]); } return(points[0]); } } if (midIndex > 0) { for (int j = startIndex; j >= 0; j--) { float val = points[j].Value; if (float.IsInfinity(val) || float.IsNaN(val) || float.IsNegativeInfinity(val) || float.IsPositiveInfinity(val)) { continue; } return(points[j]); } return(points[0]); } else { return(points[0]); } } } return(pt); }
public bool GetPoint(int pointIndex, ref LinePoint linePoint) { return true; }
public virtual bool AddPoint(LinePoint linePoint) { listLinePoint.Add(linePoint); return true; }
private void DrawCurve() { HHDevice device = comboBoxEdit2.SelectedItem as HHDevice; HHDeviceProperty devProp = comboBoxEdit1.SelectedItem as HHDeviceProperty; DateTime timeSel = DateTime.Now; if (comboBoxEdit3.SelectedIndex >= 0) { timeSel = (DateTime)comboBoxEdit3.SelectedItem; } HHDeviceProperty devBindProp = device.GetProperty(devProp); List<DevCurve> curves = devBindProp.Curves; UltraChart.CurveGroup grp = chart.GroupList[0]; grp.ClearChartObject(); LineArea area = new LineArea(chart, "道岔曲线", true); area.IsShowFoldFlag = false; area.IsFold = false; area.YAxes.Mode = YAxesMode.Manual; area.YAxes.YAxesMin = curves[0].ADMin; area.YAxes.YAxesMax = curves[0].ADMax; area.YAxes.Precision = 3; area.YAxes.UnitString = ""; grp.AddChartObject(area); grp.XAxes.SetOrgTime(ChartGraph.DateTime2ChartTime(timeSel), 0); chart.AutoSetXScale(); List<StationCurve> listCurve = DataStorage.DatabaseModule.GetInstance().QueryCurveHistory(curves[0].Group.Type, curves[0].Index, timeSel); string[][] curveNames = new string[][] { new string[]{"曲线"}, new string[]{"曲线1","曲线2"}, new string[]{"A相","B相","C相"}, }; for (int i = 0; i < curves.Count; i++) { LineCurve line = new LineCurve(chart, curveNames[curves.Count-1][i], 0); line.LineColor = ColorList[i % ColorList.Length]; area.AddLine(line); if (listCurve != null && listCurve.Count > 0 && listCurve[i] != null) { for (int j = 0; j < listCurve[i].Points.Length; j++) { DateTime time = timeSel.AddMilliseconds(curves[i].TimeInterval * j); //40毫秒 LinePoint point = new LinePoint(); point.Value = listCurve[i].Points[j]; point.Time = ChartGraph.DateTime2ChartTime(time); line.AddPoint(point); } } } chart.AutoSetXScale(); chart.Draw(); }