Page 1 of 1

Using GetPointerStyle event to apply different styles to line segments works incorrectly

Posted: Fri Sep 02, 2022 8:16 am
by 15685014
Hello. I've tried to use GetPointerStyle event to apply different styles to line segments as described here:

Code: Select all

private void Form1_Load(object sender, EventArgs e)
{
	var lineChart = new Line();
	lineChart.LinePen.Width = 2;
	lineChart.Pointer.Style = PointerStyles.Circle;
	lineChart.Pointer.Visible = true;

	tChart1.Series.Add(lineChart);

	lineChart.FillSampleValues(10);
	lineChart.GetPointerStyle += line_GetPointerStyle;
}


void line_GetPointerStyle(Steema.TeeChart.Styles.CustomPoint series, Steema.TeeChart.Styles.GetPointerStyleEventArgs e)
{
	if ((e.ValueIndex == 3) || (e.ValueIndex == 6))
		series.LinePen.Style = Steema.TeeChart.Drawing.DashStyle.Dash;
	else
		series.LinePen.Style = Steema.TeeChart.Drawing.DashStyle.Solid;
}
As you can see I want a segment that leads to point #3 and a segment that leads to point #6 to be dashed.
But as the result a segment that leads to point #5 and a segment that leads to point #8 is dashed:
Безымянный.png
Безымянный.png (30.76 KiB) Viewed 5403 times
I use Steema.TeeChart.NET 4.2022.05.26 on .NET 5.0 (that also reproduces with latest Steema.TeeChart.NET 4.2022.08.23).
Looks like a bug or am I missing something?

Re: Using GetPointerStyle event to apply different styles to line segments works incorrectly

Posted: Fri Sep 02, 2022 10:27 am
by Christopher
Hello,
bairog wrote:
Fri Sep 02, 2022 8:16 am
Looks like a bug or am I missing something?
In this particular case, I think the GetPointerStyle is not the best event to use—if you use the BeforeDrawPoint event you will obtain the results you expect:

Code: Select all

    private void InitializeChart()
    {
      var lineChart = new Line();
      lineChart.LinePen.Width = 2;
      lineChart.Pointer.Style = PointerStyles.Circle;
      lineChart.Pointer.Visible = true;

      tChart1.Series.Add(lineChart);

      lineChart.FillSampleValues(10);
      //lineChart.GetPointerStyle += line_GetPointerStyle;
      lineChart.BeforeDrawPoint += LineChart_BeforeDrawPoint;

      tChart1.Legend.Visible = false;
    }

    private void LineChart_BeforeDrawPoint(Series Series, BeforeDrawPointEventArgs e)
    {
      var series = (CustomPoint)Series;
      if ((e.ValueIndex == 3) || (e.ValueIndex == 6))
        series.LinePen.Style = Steema.TeeChart.Drawing.DashStyle.Dash;
      else
        series.LinePen.Style = Steema.TeeChart.Drawing.DashStyle.Solid;
    }
Screenshot from 2022-09-02 12-25-28.png
Screenshot from 2022-09-02 12-25-28.png (34.58 KiB) Viewed 5394 times
This is because the GetPointerStyle is specific to the pointer, and in the source-code is called after the line is drawn.

Re: Using GetPointerStyle event to apply different styles to line segments works incorrectly

Posted: Fri Sep 02, 2022 10:33 am
by 15685014
Thank you, BeforeDrawPoint event is working correctly. But but I'm still curious why GetPointerStyle event woks unexpected way?

Re: Using GetPointerStyle event to apply different styles to line segments works incorrectly

Posted: Fri Sep 02, 2022 10:47 am
by Christopher
bairog wrote:
Fri Sep 02, 2022 10:33 am
Thank you, BeforeDrawPoint event is working correctly. But but I'm still curious why GetPointerStyle event woks unexpected way?
In essence, what's happening is this (pseudo code)

Code: Select all

foreach (var point in series)
{
     void DrawPoint(Point point)
     {
          void DrawPointer(Point point)
          {
               DoDrawPointerEvent(point);
               /*draw the pointer*/
          }

          DoDrawPointEvent(point);
          DrawLine(point);
          DrawPointer(point);
     }
    
     DrawPoint(point);
}
So by the time we draw the pointer the line has already been drawn, meaning that changes to the ChartPen of the line won't be drawn until the next cycle.