Beispiel #1
0
 /* 绘制游标
  */
 protected override void _DrawCursors(Graphics g, Point pt)
 {
     for (int ijk = 0; ijk < _Curves.Count; ++ijk)
     {
         ChartCurve2V cc = _Curves[ijk] as ChartCurve2V;
         if (cc == null)
         {
             continue;
         }
         Dictionary <int, Dictionary <int, ChartCursor2V> > cc_cursors = cc._ChartCursors2V;
         ChartCursor2V cursor = _GetNearestPtCursor(pt.X, pt.Y, cc_cursors);
         if (cursor != null)
         {
             g.FillEllipse(_OutlinePtBrush, cursor.Pt_x - _CURSOR_HALF_SIDE, cursor.Pt_y - _CURSOR_HALF_SIDE, _CURSOR_HALF_SIDE << 1, _CURSOR_HALF_SIDE << 1);
             string info = "";
             if (CursorFormat == null)
             {
                 StringBuilder sb = new StringBuilder();
                 sb.Append("X:").Append(cc.XAxisValueFormat.Format(cursor.X_max)).Append(cc.XAxisUnitName).Append("-Y:").Append(cc.YAxisValueFormat.Format(cursor.Y_max)).Append(cc.YAxisUnitName).Append("\r\n");
                 info = sb.ToString();
                 sb.Clear();
             }
             else
             {
                 info = CursorFormat.Format <int>(cursor.YIndex);
             }
             if (!string.IsNullOrEmpty(info))
             {
                 _DrawCursor(g, info, new Point(cursor.Pt_x, cursor.Pt_y), cc.Pen, _AxesFont, cc.Brush, _DragRectBrush, _DestImage.Width, _DestImage.Height);
             }
         }
     }
 }
Beispiel #2
0
        /* 绘制单条曲线
         */
        protected override void _DrawSingleCurve(Graphics g, int width, int height, ChartCurve1V c)
        {
            ChartCurve2V cc           = c as ChartCurve2V;
            Rectangle    rect_grid    = _GetGridRect(width, height);
            int          chart_width  = rect_grid.Width;
            int          chart_height = rect_grid.Height;
            List <Point> pts          = new List <Point>();
            List <float> data_y       = cc.YAxisData;
            List <float> data_x       = cc.XAxisData;

            if (data_y.Count < 2)
            {
                return;
            }
            cc._ChartCursors2V.Clear();
            float y_axis_max, y_axis_min;

            if (YAxisCombined)
            {
                y_axis_max = _YAxisMaxValueUsed;
                y_axis_min = _YAxisMinValueUsed;
            }
            else
            {
                y_axis_max = cc.YAxisMaxValueUsed;
                y_axis_min = cc.YAxisMinValueUsed;
            }
            float x_axis_max, x_axis_min;

            if (XAxisCombined)
            {
                x_axis_max = _XAxisMaxValueUsed;
                x_axis_min = _XAxisMinValueUsed;
            }
            else
            {
                x_axis_max = cc.XAxisMaxValueUsed;
                x_axis_min = cc.XAxisMinValueUsed;
            }
            for (int i = 0; i < data_x.Count && i < data_y.Count; ++i)
            {
                float x_v  = data_x[i];
                int   pt_x = rect_grid.X + _GetXAxisPos(x_v, x_axis_max, x_axis_min, rect_grid.Width);

                float y_v  = data_y[i];
                int   pt_y = rect_grid.Y + _GetYAxisPos(y_v, y_axis_max, y_axis_min, rect_grid.Height);

                pts.Add(new Point(pt_x, pt_y));
                ChartCursor2V cursor = new ChartCursor2V
                {
                    Pt_x     = pt_x,
                    Pt_y     = pt_y,
                    XValue   = x_v,
                    YValue   = y_v,
                    Pt_count = 1,
                    Y_max    = y_v,
                    Y_min    = y_v,
                    X_max    = x_v,
                    X_min    = x_v,
                };
                if (!cc._ChartCursors2V.Keys.Contains(pt_x))
                {
                    cc._ChartCursors2V.Add(pt_x, new Dictionary <int, ChartCursor2V>());
                    cc._ChartCursors2V[pt_x].Add(pt_y, cursor);
                }
                else
                {
                    if (!cc._ChartCursors2V[pt_x].Keys.Contains(pt_y))
                    {
                        cc._ChartCursors2V[pt_x].Add(pt_y, cursor);
                    }
                    else
                    {
                        ChartCursor2V cursor_exist = cc._ChartCursors2V[pt_x][pt_y];
                        cursor_exist.Pt_count++;
                        cursor_exist.Y_max = (cursor_exist.Y_max >= y_v ? cursor_exist.Y_max : y_v);
                        cursor_exist.Y_min = (cursor_exist.Y_min <= y_v ? cursor_exist.Y_min : y_v);
                        cursor_exist.X_max = (cursor_exist.X_max >= x_v ? cursor_exist.X_max : x_v);
                        cursor_exist.X_min = (cursor_exist.X_min >= x_v ? cursor_exist.X_min : x_v);
                    }
                }
            }
            if (pts.Count > 1)
            {
                g.DrawLines(cc.Pen, pts.ToArray());
                Rectangle r = new Rectangle();
                r.Width  = 4;
                r.Height = 4;
                foreach (var kv in cc._ChartCursors2V)
                {
                    int pt_x = kv.Key;
                    if (cc._ChartCursors2V.Keys.Contains(pt_x + 1) || cc._ChartCursors2V.Keys.Contains(pt_x - 1))
                    {
                        continue;
                    }
                    foreach (var kv2 in kv.Value)
                    {
                        int pt_y = kv2.Key;
                        if (kv.Value.Keys.Contains(pt_y + 1) || kv.Value.Keys.Contains(pt_y - 1))
                        {
                            continue;
                        }
                        r.X = pt_x - 2;
                        r.Y = pt_y - 2;
                        g.DrawRectangle(cc.Pen, r);
                    }
                }
            }
            else if (pts.Count == 1)
            {
                g.DrawRectangle(cc.Pen, new Rectangle(pts[0].X - 2, pts[0].Y - 2, 4, 4));
            }
        }