Fill Ellipse Tool

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Fill Ellipse Tool

Post by Quant » Sat Jan 09, 2016 5:58 am

Hi,

We require fill properties (like Fill Color/Pattern, Transparency %, etc.) of Drawline Tool for following shapes:
1] Ellipse
2] Rectangle
3] Horizontal Parallel Line
4] Rectangle Parallel Line

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Fill Ellipse Tool

Post by Christopher » Mon Jan 11, 2016 10:47 am

Quant wrote: We require fill properties (like Fill Color/Pattern, Transparency %, etc.) of Drawline Tool for following shapes:
The DrawLine Tool enables a user to draw lines on a TeeChart. Lines only have Pen characteristics, unlike the shapes you mention which have both Pen and Brush characteristics. I'm not sure I understand how you want the DrawLine Tool to draw anything other than lines. Could you please explain?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Fill Ellipse Tool

Post by Quant » Tue Jan 12, 2016 4:05 am

The DrawLine Tool enables a user to draw lines on a TeeChart. Lines only have Pen characteristics, unlike the shapes you mention which have both Pen and Brush characteristics. I'm not sure I understand how you want the DrawLine Tool to draw anything other than lines. Could you please explain?
DrawLine Tool also provides a style property which has options for following shapes:
  • Line,
    HorizParallel,
    VertParallel,
    Rectangle,
    Ellipse
We did check the source code of DrawLine.cs and we knew that it has only Pen Characteristics but we have a requirement where user wants fill properties (like fill color, fill pattern, transparency etc.) for shapes other than Line. It would be of great feature for TeeChart if these shapes have a fill properties because user can use these tools for highlighting specific regions based on their needs. So we would like to request you to consider this requirement. Going further, if you are considering this requirement for future release please provide us some kind of solution to complete this requirement asap.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Fill Ellipse Tool

Post by Christopher » Wed Jan 13, 2016 5:29 pm

Quant wrote:So we would like to request you to consider this requirement. Going further, if you are considering this requirement for future release please provide us some kind of solution to complete this requirement asap.
I have added this request as an enhancement to our issue tracking software with id=1405.

In the meantime, a workaround is relatively straightforward. Firstly, add this class to your code:

Code: Select all

  public class MyDrawLine : DrawLine
  {
    public MyDrawLine(Chart c) : base(c)
    {
      Brush = new ChartBrush(c);
    }

    public ChartBrush Brush { get; set; }


    protected override void ChartEvent(EventArgs e)
    {
      if (e is AfterDrawEventArgs)
      {
        if (Lines.Count > 0)
        {
          foreach (DrawLineItem l in Lines)
          {
            RedrawBrushLine(l);
          }
        }
        if (drawing)
        {
          RedrawBrushLine(Selected);
        }
      }

      base.ChartEvent(e);
    }

    private void RedrawBrushLine(DrawLineItem line)
    {
      Graphics3D g = Chart.Graphics3D;

      g.Brush = Brush;

      if ((Chart != null) && g.ValidState())
      {
        DrawLineStyle s = (line == null) ? this.Style : line.Style;

        bool oldPen = g.Pen.Visible;
        g.Pen.Visible = false;

        ClipDrawingRegion(g);
        if (line == null)
        {
          DoDrawLine(g, this.FromPoint, this.ToPoint, s);
        }
        else
        {
          DoDrawLine(g, AxisPoint(line.StartPos), AxisPoint(line.EndPos), s);
        }

        g.Pen.Visible = oldPen;
        g.UnClip();
      }
    }

    private void DoDrawLine(Graphics3D g, Point StartPos, Point EndPos, DrawLineStyle AStyle)
    {
      if (!base.Chart.Aspect.View3D)
      {
        if (AStyle != DrawLineStyle.Line)
        {
          if (AStyle == DrawLineStyle.Rectangle)
          {
            g.Rectangle(Utils.FromLTRB(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y));
          }
          else if (AStyle == DrawLineStyle.Ellipse)
          {
            g.Ellipse(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y);
          }
        }
      }
      else if (AStyle != DrawLineStyle.Line)
      {
        if (AStyle == DrawLineStyle.Rectangle)
        {
          g.Rectangle(Utils.FromLTRB(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y), 0);
        }
        else if (AStyle == DrawLineStyle.Ellipse)
        {
          g.Ellipse(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y, 0);
        }
      }
    }
  }
And then consume it in an example like this:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;

      Line line1 = new Line(tChart1.Chart);

      line1.Add(2, 2);
      line1.Add(8, 8);

      MyDrawLine drawLine1 = new MyDrawLine(tChart1.Chart);
      drawLine1.Pen.Color = Color.Yellow;
      drawLine1.Pen.Width = 2;
      drawLine1.Brush.Color = Color.Red;

      Steema.TeeChart.Tools.DrawLineItem I = new Steema.TeeChart.Tools.DrawLineItem(drawLine1);
      double tmp = line1.YValues.Range / 5.0;
      I.StartPos = new PointDouble(5, line1.YValues.Maximum - tmp);
      I.EndPos = new PointDouble(7, line1.YValues.Minimum + tmp);
      I.Style = DrawLineStyle.Rectangle;
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Fill Ellipse Tool

Post by Quant » Thu Jan 14, 2016 4:04 am

Thanks for the help.
But we already updated DrawLine.cs which works as required. Check the below code snippet :

Code: Select all

	private void DoDrawLine(Graphics3D g, Point StartPos, Point EndPos, DrawLineStyle AStyle)
    {
      bool oldBrush, oldPen;
      
        if (AStyle != DrawLineStyle.Line)
        {
          if (AStyle == DrawLineStyle.HorizParallel)
          {
            g.HorizontalLine(StartPos.X, EndPos.X, StartPos.Y);
            g.HorizontalLine(StartPos.X, EndPos.X, EndPos.Y);
            if (IsFilled)
            {
                g.Brush.Color = FillColor;
                g.Brush.Transparency = FillTransparency;

                //Add Rectangle with Transparency
                oldPen = g.Pen.Visible;
                g.Pen.Visible = false;
                g.Rectangle(Utils.FromLTRB(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y));
                g.Pen.Visible = oldPen;
            }
          }
          else if (AStyle == DrawLineStyle.Rectangle)
          {
            oldBrush = g.Brush.Visible;
            if (IsFilled)
            {
                g.Brush.Color = FillColor;
                g.Brush.Transparency = FillTransparency;

                g.Brush.Visible = true;
            }
            else
            {
                g.Brush.Visible = false;
            }
            g.Rectangle(Utils.FromLTRB(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y));
            g.Brush.Visible = oldBrush;
          }
          else if (AStyle == DrawLineStyle.Ellipse)
          {
            oldBrush = g.Brush.Visible;
            if (IsFilled)
            {
                g.Brush.Color = FillColor;
                g.Brush.Transparency = FillTransparency;

                g.Brush.Visible = true;
            }
            else
            {
                g.Brush.Visible = false;
            }
            g.Ellipse(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y);
            g.Brush.Visible = oldBrush;
          }
          else
          {
            g.VerticalLine(StartPos.X, StartPos.Y, EndPos.Y);
            g.VerticalLine(EndPos.X, StartPos.Y, EndPos.Y);
            if (IsFilled)
            {
                g.Brush.Color = FillColor;
                g.Brush.Transparency = FillTransparency;

                //Add Rectangle with Transparency
                oldPen = g.Pen.Visible;
                g.Pen.Visible = false;
                g.Rectangle(Utils.FromLTRB(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y));
                g.Pen.Visible = oldPen;
            } 
          }
        }
        else
        {
          g.Line(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y);
        }
      
    }

We also added following additional properties to DrawLine class as :
  • IsFilled
    FillColor
    FillTransparency
Do revert for any suggestion or any code changes related to above code snippet.

Post Reply