ni.com is currently undergoing scheduled maintenance.
Some services may be unavailable at this time. Please contact us for help or try again later.
10-15-2012 02:25 AM
I have a wpf on which I add Point Annotations and Range Annotation programmatically, when the user clicks the the buttons "Take Point Annotation" and "Take Range Annoation". I would like to select an annotation when the user clicks on it an make him able to modify or delete. I used getChildrenAtPoint method of the graph but the collection that this method returns is always empty...
My graph definition is:
<ni:Graph Name="graph" HitTestMode="RenderedInterpolation" PlotAreaMouseLeftButtonUp="graph_PlotAreaMouseLeftButtonUp">
<ni:Graph.Axes>
<ni:AxisDouble x:Name="xAxis" Range="0,10" Orientation="Horizontal"></ni:AxisDouble>
<ni:AxisDouble x:Name="yAxis" Range="0,20" Orientation="Vertical"></ni:AxisDouble>
</ni:Graph.Axes>
<ni:Graph.Children>
<ni:Cursor Name="simpleCursor">
<ni:Cursor.ValuePresenter>
<nic:ValueFormatterGroup>
<nic:ValueFormatterGroup.DefaultFormatter>
<nic:GeneralValueFormatter x:Name="valueFormatter" Format="0.00"></nic:GeneralValueFormatter>
</nic:ValueFormatterGroup.DefaultFormatter>
</nic:ValueFormatterGroup>
</ni:Cursor.ValuePresenter>
</ni:Cursor>
<ni:MultiPlotCursor Name="mpCursor" Visibility="Hidden"></ni:MultiPlotCursor>
<ni:RangeCursor Name="rangeCursor" HorizontalRange="4,6" VerticalRange="4,6" Visibility="Hidden"></ni:RangeCursor>
</ni:Graph.Children>
</ni:Graph>
and the the addAnnotation method is:
private void TakeRangeAnnotation_Executed(object sender, ExecutedRoutedEventArgs e)
{
WindowAnnotation dialog = new WindowAnnotation();
if (dialog.ShowDialog() == true)
{
NationalInstruments.Controls.RangeAnnotation ann = new NationalInstruments.Controls.RangeAnnotation();
ann.HorizontalRange = rangeCursor.ActualHorizontalRange;
ann.VerticalRange = rangeCursor.ActualVerticalRange;
ann.Label = dialog.Annotation;
ann.HorizontalAxis = xAxis;
ann.VerticalAxis = yAxis;
graph.Children.Add(ann);
}
}
I call the getChlidrenAtPoint method on the PlotAreaMouseLeftButtonUp event:
private void graph_PlotAreaMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Point mousePos = e.GetPosition(graph);
Point screenPos = graph.GetPlotAreaPosition(e);
IEnumerable<object> children1 = graph.GetChildrenAtPoint(mousePos);
IEnumerable<object> children2 = graph.GetChildrenAtPoint(screenPos);
I tried both mouse position and PlotAreaPosition but the two collections are always empty, also if I click on a Range Annotation
Solved! Go to Solution.
10-15-2012 11:07 AM
I was able to reproduce the issue you were seeing, and confirmed there is a bug in our code that prevents annotations from appearing in hit test results. We have created a work item to fix this issue.
To workaround this, here is an example of how you can perform manual hit testing for a RangeAnnotation in a graph configured with double horizontal and vertical axes:
double[] dataValue = graph.ScreenToData(plot, screenPos).Cast<double>().ToArray();
foreach( var rangeAnnotation in graph.Children.OfType<RangeAnnotation>() ) {
var horizontalRange = (Range<double>)rangeAnnotation.HorizontalRange;
var verticalRange = (Range<double>)rangeAnnotation.VerticalRange;
if( horizontalRange.Contains(dataValue[0])
&& verticalRange.Contains(dataValue[1]) ) {
// matching range annotation found
}
}
10-24-2012 10:22 AM
Problem Solved? If so, please set Phansen answer as the correct one.
Thanks.
Mattia
04-05-2013 12:34 PM
Just wanted to let you know this issue (#374462) was fixed in the Measurement Studio 2013 release.