I have 2 design goals. Given the desired location of the the top left of my Annotation, draw an annotation at that point. Also, draw a line from the center of the annotation to the target point. The location could be specified in ScreenCoordinates or AxisValues. Example: Adding an annotation at Screen Coords (.6,.6) means the top left corner of the annotation is at (.6,.6) and the line draws to the center of the annotation.
Any tips on this? I've tried setting the Anchor to (0,0). This will get me an annotation drawn at the correct location, but the line draws to the corner of the annotations. I've tried setting the anchor to (.5,.5), and the line draws as desired, but the location is off.
I've thought about binding to the actualwidth and height and converting, but these are properties do not exist. Any tips?
Annotation Anchor is responsible for too much.
Moderator: Queue Moderators
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Annotation Anchor is responsible for too much.
Anchor works also as center point of rotation
The actual width and height in pixels can be calculated as instructed here:
http://www.arction.com/forum/viewtopic.php?f=16&t=404
You should set LocationCoordinateSystem = ScreenCoordinates and set the LocationScreenCoords values as to match the position you need to show it.
In Anchor, 0 means left or top, and 1 means right or bottom. So it's a relative factor.
The actual width and height in pixels can be calculated as instructed here:
http://www.arction.com/forum/viewtopic.php?f=16&t=404
You should set LocationCoordinateSystem = ScreenCoordinates and set the LocationScreenCoords values as to match the position you need to show it.
In Anchor, 0 means left or top, and 1 means right or bottom. So it's a relative factor.
LightningChart Support Team, PT
Re: Annotation Anchor is responsible for too much.
Im requesting that the arrow source point and the anchor become divorced. I'd like to be able to keep my anchor in the top left corner of my annotation. I'd also like to draw my arrow from the center, or from the corner nearest the target point. Would you add such a feature?
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Annotation Anchor is responsible for too much.
I'm wondering if Style = Callout suits your purpose directly?
We would rather not make the modification because there's too many properties in Annotations already, and we'd have to program all mouse interactivity and for editing the line end point as well... Easily talking about week of work for a minor feature.
How about just using two annotations? One with Style = Rectangle and another with Style = Arrow. Here's the code to accomplish this:
You may want to call UpdateArrow() in chart.SizeChanged and axis.RangeChanged event handlers too.
I hope this helps
We would rather not make the modification because there's too many properties in Annotations already, and we'd have to program all mouse interactivity and for editing the line end point as well... Easily talking about week of work for a minor feature.
How about just using two annotations? One with Style = Rectangle and another with Style = Arrow. Here's the code to accomplish this:
Code: Select all
public partial class MainWindow : Window
{
LightningChartUltimate m_chart;
AnnotationXY m_annotArrow;
AnnotationXY m_annotRectangle;
public MainWindow()
{
InitializeComponent();
CreateChart();
m_chart.MouseDoubleClick += new MouseButtonEventHandler(m_chart_MouseDoubleClick);
}
void m_chart_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
m_chart.BeginUpdate();
ViewXY v = m_chart.ViewXY;
AxisX xAxis = v.XAxes[0];
AxisY yAxis = v.YAxes[0];
v.Annotations.Clear();
//Arrow
m_annotArrow = new AnnotationXY(v, xAxis, yAxis);
m_annotArrow.Style = AnnotationStyle.Arrow;
m_annotArrow.LocationCoordinateSystem = CoordinateSystem.ScreenCoordinates;
m_annotArrow.TextStyle.Visible = false;
m_annotArrow.ArrowLineStyle.Color = Colors.Red;
m_annotArrow.AnchorAdjustByMouse = false;
m_annotArrow.MoveByMouse = false;
m_annotArrow.ResizeByMouse = false;
m_annotArrow.RotateByMouse = false;
m_annotArrow.TargetMoveByMouse = false;
m_annotArrow.TargetAxisValues.SetValues(2, 0);
v.Annotations.Add(m_annotArrow);
//Rectangle
m_annotRectangle = new AnnotationXY(v, xAxis, yAxis);
m_annotRectangle.Style = AnnotationStyle.Rectangle;
m_annotRectangle.LocationCoordinateSystem = CoordinateSystem.AxisValues;
m_annotRectangle.LocationAxisValues.SetValues(3, 7);
m_annotRectangle.Anchor.SetValues(0, 0); //Top-left
m_annotRectangle.ResizeByMouse = false;
m_annotRectangle.RotateByMouse = false;
m_annotRectangle.TargetMoveByMouse = false;
m_annotRectangle.AnchorAdjustByMouse = false;
m_annotRectangle.MovedByMouse += new MouseEventHandler(annotRectangle_MovedByMouse);
m_annotRectangle.AnchorAdjustedByMouse += new AnnotationBase.AnchorAdjustedByMouseHandler(m_annotRectangle_AnchorAdjustedByMouse);
m_annotRectangle.Text = "This is an \nannotation";
v.Annotations.Add(m_annotRectangle);
UpdateArrow();
m_chart.EndUpdate();
}
void CreateChart()
{
m_chart = new LightningChartUltimate();
gridMain.Children.Add(m_chart);
}
void m_annotRectangle_AnchorAdjustedByMouse(AnnotationBase sender, PointFloat oldAnchor, PointFloat newAnchor, ref bool cancelRendering)
{
UpdateArrow();
}
void annotRectangle_MovedByMouse(object sender, MouseEventArgs e)
{
UpdateArrow();
}
void UpdateArrow()
{
//Reposition the arrow annotation's Location
PointInt size = m_chart.MeasureText(m_annotRectangle.Text, m_annotRectangle.TextStyle.Font);
int iRectWidth = size.X + m_annotRectangle.AutoSizePadding * 2;
int iRectHeight = size.Y + m_annotRectangle.AutoSizePadding * 2;
//Rectangle annotation's location coordinate
int iX = (int) m_chart.ViewXY.XAxes[0].ValueToCoord(m_annotRectangle.LocationAxisValues.X);
int iY = (int) m_chart.ViewXY.YAxes[0].ValueToCoord(m_annotRectangle.LocationAxisValues.Y);
//Boundaries
int iLeft = iX - (int)((double)(m_annotRectangle.Anchor.X) * (double)iRectWidth);
int iTop = iY - (int)((double)(m_annotRectangle.Anchor.Y) * (double)iRectHeight);
int iRight = iX + iRectWidth;
int iBottom = iY + iRectHeight;
//Use this for center of annotation
//m_annotArrow.LocationScreenCoords.SetValues((iLeft + iRight) / 2, (iTop + iBottom) / 2);
//Use this for center of bottom edge
m_annotArrow.LocationScreenCoords.SetValues((iLeft + iRight) / 2, iBottom);
}
}
I hope this helps
LightningChart Support Team, PT