public BasicChart()
 {
     this.Events = EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.PointerMotionMask;
     selectionStart = new ChartCursor ();
     selectionStart.Visible = false;
     selectionEnd = new ChartCursor ();
     selectionEnd.Visible = false;
     AddCursor (selectionStart, AxisDimension.X);
     AddCursor (selectionEnd, AxisDimension.X);
     selectionStart.ValueChanged += new EventHandler (OnSelectionCursorChanged);
     selectionEnd.ValueChanged += new EventHandler (OnSelectionCursorChanged);
 }
 void OnSelectionCursorChanged(object sender, EventArgs args)
 {
     if (enableSelection) {
         if (selectionStart.Value > selectionEnd.Value) {
             ChartCursor tmp = selectionStart;
             selectionStart = selectionEnd;
             selectionEnd = tmp;
         }
         OnSelectionChanged ();
     }
 }
        void DrawCursorLabel(ChartCursor cursor)
        {
            Gdk.GC gc = new Gdk.GC (GdkWindow);
               		gc.RgbFgColor = cursor.Color;

            int x, y;
            GetPoint (cursor.Value, cursor.Value, out x, out y);

            if (cursor.Dimension == AxisDimension.X) {

                string text;

                if (cursor.LabelAxis != null) {
                    double minStep = GetMinTickStep (cursor.Dimension);
                    TickEnumerator tenum = cursor.LabelAxis.GetTickEnumerator (minStep);
                    tenum.Init (cursor.Value);
                    text = tenum.CurrentLabel;
                } else {
                    text = GetValueLabel (cursor.Dimension, cursor.Value);
                }

                if (text != null && text.Length > 0) {
                    Pango.Layout layout = new Pango.Layout (this.PangoContext);
                    layout.FontDescription = Pango.FontDescription.FromString ("Tahoma 8");
                    layout.SetMarkup (text);

                    int tw, th;
                    layout.GetPixelSize (out tw, out th);
                    int tl = x - tw/2;
                    int tt = top + 4;
                    if (tl + tw + 2 >= left + width) tl = left + width - tw - 1;
                    if (tl < left + 1) tl = left + 1;
                    GdkWindow.DrawRectangle (Style.WhiteGC, true, tl - 1, tt - 1, tw + 2, th + 2);
                    GdkWindow.DrawRectangle (Style.BlackGC, false, tl - 2, tt - 2, tw + 3, th + 3);
                    GdkWindow.DrawLayout (gc, tl, tt, layout);
                }
            } else {
                throw new NotSupportedException ();
            }
        }
        void DrawCursor(ChartCursor cursor)
        {
            Gdk.GC gc = new Gdk.GC (GdkWindow);
               		gc.RgbFgColor = cursor.Color;

            int x, y;
            GetPoint (cursor.Value, cursor.Value, out x, out y);

            if (cursor.Dimension == AxisDimension.X) {
                int cy = top - AreaBorderWidth - 1;
                Point[] ps = new Point [4];
                ps [0] = new Point (x, cy);
                ps [1] = new Point (x + (cursor.HandleSize/2), cy - cursor.HandleSize + 1);
                ps [2] = new Point (x - (cursor.HandleSize/2), cy - cursor.HandleSize + 1);
                ps [3] = ps [0];
                GdkWindow.DrawPolygon (gc, false, ps);
                if (activeCursor == cursor)
                    GdkWindow.DrawPolygon (gc, true, ps);
                GdkWindow.DrawLine (gc, x, top, x, top + height);
            } else {
                throw new NotSupportedException ();
            }
        }
        protected override bool OnButtonPressEvent(Gdk.EventButton ev)
        {
            if (ev.Button == 1) {
                foreach (ChartCursor cursor in cursors) {
                    int cx, cy;
                    GetPoint (cursor.Value, cursor.Value, out cx, out cy);
                    if (cursor.Dimension == AxisDimension.X) {
                        if (Math.Abs (ev.X - cx) <= 2 || (ev.Y < top && (Math.Abs (ev.X - cx) <= cursor.HandleSize/2))) {
                            activeCursor = cursor;
                            draggingCursor = true;
                            activeCursor.ShowValueLabel = true;
                            QueueDraw ();
                            break;
                        }
                    } else {
                        // Implement
                    }
                }

                if (enableSelection && !draggingCursor) {
                    selectionStart.Visible = true;
                    selectionEnd.Visible = true;

                    double x, y;
                    GetValue ((int)ev.X, (int)ev.Y, out x, out y);
                    // avoid cursor swaping
                    ChartCursor c1 = selectionStart;
                    ChartCursor c2 = selectionEnd;
                    c1.Value = x;
                    c2.Value = x;
                    activeCursor = selectionEnd;
                    activeCursor.ShowValueLabel = true;
                    draggingCursor = true;
                    QueueDraw ();
                }

                if (draggingCursor)
                    return true;
            }
            return base.OnButtonPressEvent (ev);
        }
 public void RemoveCursor(ChartCursor cursor)
 {
     cursor.ValueChanged -= new EventHandler (OnCursorChanged);
     cursor.LayoutChanged -= new EventHandler (OnCursorChanged);
     cursors.Remove (cursor);
     QueueDraw ();
 }
 public void AddCursor(ChartCursor cursor, AxisDimension dimension)
 {
     cursor.Dimension = dimension;
     cursor.ValueChanged += new EventHandler (OnCursorChanged);
     cursor.LayoutChanged += new EventHandler (OnCursorChanged);
     cursors.Add (cursor);
     xrangeChanged = yrangeChanged = true;
     QueueDraw ();
 }