Page 1 of 1
Strange Drawline behaviour with the Dragline event handler
Posted: Thu Sep 30, 2010 8:02 am
by 8751509
Greetings,
I have a strange problem I dont understand how to get around.
Basically I have locked Drawline endpoints to points on a candle series (I didnt use the nearest point tool due to poor performance issues)
Now I can drag the drawline either by its ends or the complete line and it 'locks' to the values as I desire ... however as soon as I mouse up, the line redraws itself in another position on the chart.
Included is a demo app that highlights this behaviour.
using the app If you create a Drawline and then drag that line you will see the ends of the line tracking the price data .... as soon as you release the mouse the line gets drawn in a completely new position.
Why does this happen ? (I've stepped into the source code of the Drawline.cs and can see something weird going on in the mouseup event ... but there I am in the dark.
What is the work around? I'd like my drawline to stay where I last put it.
Cheers Phil.
Re: Strange Drawline behaviour with the Dragline event handler
Posted: Thu Sep 30, 2010 11:28 am
by narcis
I'm afraid this is a bug, which I have added to the defect list (TF02015178) to be fixed as a high priority issue, but there's no workaround I can think of for now. The bug can be narrowed down to this code:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
Steema.TeeChart.Styles.Candle candle1 = new Steema.TeeChart.Styles.Candle(tChart1.Chart);
candle1.FillSampleValues();
Steema.TeeChart.Tools.DrawLine drawLine1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
drawLine1.Series = candle1;
drawLine1.DragLine += new Steema.TeeChart.Tools.DrawLineEventHandler(drawLine1_DragLine);
}
void drawLine1_DragLine(Steema.TeeChart.Tools.DrawLine sender)
{
Steema.TeeChart.Styles.Series s = sender.Series;
if (sender.Selected != null)
{
Steema.TeeChart.Tools.DrawLineItem line = sender.Selected;
Steema.TeeChart.Tools.NearestPoint nearestPoint1 = new Steema.TeeChart.Tools.NearestPoint(s);
nearestPoint1.Active = false;
Point startP = new Point(s.CalcXPosValue(line.StartPos.X), s.CalcYPosValue(line.StartPos.Y));
Point endP = new Point(s.CalcXPosValue(line.EndPos.X), s.CalcYPosValue(line.EndPos.Y));
int index0 = nearestPoint1.GetNearestPoint(startP);
int index1 = nearestPoint1.GetNearestPoint(endP);
line.StartPos = new Steema.TeeChart.Drawing.PointDouble(s.XValues[index0], s.YValues[index0]);
line.EndPos = new Steema.TeeChart.Drawing.PointDouble(s.XValues[index1], s.YValues[index1]);
}
}
Re: Strange Drawline behaviour with the Dragline event handler
Posted: Thu Sep 30, 2010 11:37 pm
by 8751509
Ah I see ... let me ponder a second
.
.
.
.
AAAAAAAAAAAAAAAAAAAAAAAAARGH .. what am I gonna do now ????????
.
.
.
.
ok I'm composed now ... have you seen any alternative methods to achieve the same goal ? the goal being to lock drawline ends to price values ?
Cheers Phil
Re: Strange Drawline behaviour with the Dragline event handler
Posted: Fri Oct 01, 2010 8:05 am
by narcis
Hi Phil,
A workaround is fixing lines position in the MouseUp event, for example:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private Steema.TeeChart.Tools.DrawLine drawLine1;
private void InitializeChart()
{
Steema.TeeChart.Styles.Candle candle1 = new Steema.TeeChart.Styles.Candle(tChart1.Chart);
candle1.FillSampleValues();
drawLine1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
drawLine1.Series = candle1;
drawLine1.DragLine += new Steema.TeeChart.Tools.DrawLineEventHandler(drawLine1_DragLine);
tChart1.MouseUp += new MouseEventHandler(tChart1_MouseUp);
}
void tChart1_MouseUp(object sender, MouseEventArgs e)
{
PositionLine(drawLine1.Series);
}
Steema.TeeChart.Tools.DrawLineItem line;
void drawLine1_DragLine(Steema.TeeChart.Tools.DrawLine sender)
{
Steema.TeeChart.Styles.Series s = sender.Series;
if (sender.Selected != null)
{
line = sender.Selected;
PositionLine(s);
}
}
private void PositionLine(Steema.TeeChart.Styles.Series s)
{
if (line != null)
{
Steema.TeeChart.Tools.NearestPoint nearestPoint1 = new Steema.TeeChart.Tools.NearestPoint(s);
nearestPoint1.Active = false;
Point startP = new Point(s.CalcXPosValue(line.StartPos.X), s.CalcYPosValue(line.StartPos.Y));
Point endP = new Point(s.CalcXPosValue(line.EndPos.X), s.CalcYPosValue(line.EndPos.Y));
int index0 = nearestPoint1.GetNearestPoint(startP);
int index1 = nearestPoint1.GetNearestPoint(endP);
line.StartPos = new Steema.TeeChart.Drawing.PointDouble(s.XValues[index0], s.YValues[index0]);
line.EndPos = new Steema.TeeChart.Drawing.PointDouble(s.XValues[index1], s.YValues[index1]);
}
}
Re: Strange Drawline behaviour with the Dragline event handler
Posted: Sat Oct 02, 2010 12:29 am
by 8751509
Ah nice ...
I
eventually had a similiar idea of storing the values whilst in the DragLine event handler and then reapplying those values once I get to the DraggedLine handler ... but there was always the slight chance of the values becoming corrupted before application in the final event ...
I like your idea better of using the same nearest point mechanism 'one last time' to sort everything out ....
I withdraw my scream of consternation
Cheers Phil.
Re: Strange Drawline behaviour with the Dragline event handler
Posted: Mon Oct 11, 2010 11:23 am
by narcis
Hi Phil,
We have been investigating the issue further and we don't think this one is a bug as the code works as expected. What happens in the code is that StartPos and EndPos are set in the DragLine event which is called after the FromPoint and ToPoint fields have been set. These two fields then reset the StartPos and EndPos values in the DoMouseUp method, and as they are not synchronised with the latter then the problem occurs. This is due to where the DragLine and DraggedLine events are called in the TeeChart code. We could think about events such as BeforeDragLine and AfterDragLine to avoid such confusion. Anyhow, as the code is, the workaround is the following:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
Steema.TeeChart.Tools.NearestPoint nearestPoint1;
Steema.TeeChart.Tools.DrawLine drawLine1;
Steema.TeeChart.Drawing.PointDouble pd1, pd2;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
Steema.TeeChart.Styles.Candle candle1 = new Steema.TeeChart.Styles.Candle(tChart1.Chart);
candle1.FillSampleValues();
nearestPoint1 = new Steema.TeeChart.Tools.NearestPoint(candle1);
nearestPoint1.Active = false;
drawLine1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
drawLine1.Series = candle1;
drawLine1.DragLine += new Steema.TeeChart.Tools.DrawLineEventHandler(drawLine1_DragLine);
drawLine1.DraggedLine += new Steema.TeeChart.Tools.DrawLineEventHandler(drawLine1_DraggedLine);
}
void drawLine1_DraggedLine(Steema.TeeChart.Tools.DrawLine sender)
{
Steema.TeeChart.Styles.Series s = sender.Series;
if (sender.Selected != null)
{
Steema.TeeChart.Tools.DrawLineItem line = sender.Selected;
line.StartPos = pd1;
line.EndPos = pd2;
}
}
void drawLine1_DragLine(Steema.TeeChart.Tools.DrawLine sender)
{
Steema.TeeChart.Styles.Series s = sender.Series;
if (sender.Selected != null)
{
Steema.TeeChart.Tools.DrawLineItem line = sender.Selected;
Point startP = drawLine1.FromPoint;
Point endP = drawLine1.ToPoint;
int index0 = nearestPoint1.GetNearestPoint(startP);
int index1 = nearestPoint1.GetNearestPoint(endP);
pd1 = new Steema.TeeChart.Drawing.PointDouble(s.XValues[index0], s.YValues[index0]);
pd2 = new Steema.TeeChart.Drawing.PointDouble(s.XValues[index1], s.YValues[index1]);
line.StartPos = pd1;
line.EndPos = pd2;
}
}
I eventually had a similiar idea of storing the values whilst in the DragLine event handler and then reapplying those values once I get to the DraggedLine handler ... but there was always the slight chance of the values becoming corrupted before application in the final event ...
Why do you think values could get corrupted?
Re: Strange Drawline behaviour with the Dragline event handler
Posted: Tue Oct 12, 2010 2:51 am
by 8751509
tnx for the feedback Narcis,
Corruption of values was just an "off hand" thought for a particular idiosyncrasy of my code, not yours (multiple drawlines on the go at the one time basically).... I adopted a slight variant of your workaround that has been performing solidly ever since.
Still good thing to keep in my mind for future tools ..
Cheers.