Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure the Range property of IntensityGraph in WPF?

The equivalent retained mode version of the Windows Forms "draw rectangle call during every Paint event" is to create a Rectangle object once in WPF (and update its properties as needed).

 

If you are trying to position this inside of the intensity graph, you can add the rectangle to the Children collection, and use RelativePanel attached layout properties to position it using relative coordinates. Alternatively, you could add a RangeAnnotation (or RangeCursor) to the Children collection, and position it by specifying data ranges.

~ Paul H
0 Kudos
Message 11 of 17
(1,124 Views)

Thanks Paul. In the XAML i did add the Rectangle as a child of the IntensityGraph. 

Is there any way I can set the X/Y position of this rectangle at runtime, so that I can add the rectangle at the mouse coordinates?

0 Kudos
Message 12 of 17
(1,119 Views)

The intensity graph uses a RelativePanel for layout, so you can use attached properties to position the rectangle with relative coordinates:

...
xmlns:ni="http://schemas.ni.com/controls/2009/xaml/presentation"
xmlns:niPrimitives="http://schemas.ni.com/controls/2009/xaml/presentation/primitives"
...
<ni:IntensityGraph x:Name="graph" ...>
    <ni:IntensityGraph.Children>
        <Rectangle x:Name="rectangle" Fill="Green" Width="10" Height="10"
                   niPrimitives:RelativePanel.RelativeHorizontalAlignment="Center"
                   niPrimitives:RelativePanel.RelativeVerticalAlignment="Center"
                   niPrimitives:RelativePanel.RelativeHorizontalPosition="0.5"
                   niPrimitives:RelativePanel.RelativeVerticalPosition="0.5"
                   />
    </ni:IntensityGraph.Children>
</ni:IntensityGraph>

 

To set the position at run-time based on the mouse position within the plot area (i.e. during the PlotAreaMouse___ events on the graph), you can use the GetPlotAreaPosition and ScreenToRelative methods to translate the mouse position to relative coordinates.

private void OnPlotAreaMouseMove( object sender, MouseEventArgs e ) {
    Point screenPosition = graph.GetPlotAreaPosition( e );
    Point relativePosition = graph.ScreenToRelative( screenPosition );
    RelativePanel.SetRelativeHorizontalPosition( rectangle, relativePosition.X );
    RelativePanel.SetRelativeVerticalPosition( rectangle, relativePosition.Y );
}

(The relative panel also contains properties for relative sizing, if you need the rectangle to fit a range, rather than a fixed size as in the example above.)

~ Paul H
0 Kudos
Message 13 of 17
(1,113 Views)

Thank you Paul. I greatly appreciate you.

 

In my previous post, I was looking to use the InverseMapDataPoint() of the IntensityPlot in IntensityGraph.

You asked me to check with equivalent ScreenToData(), unfortunately this is not resolving my purpose. Some how I need to identify the default plot(IntensityPlot) on my IntensityGraph and  then try calling InverseMapDataPoint()

 

IntensityPlot intensityPlot = (IntensityPlot)PatternIntensityGraph.AllPlots[0];

 

I cannot use the above line of code to get the default plot, as the conversion fails becuase AllPlots[0] returns me the below.

 

[0] {Plot: Label=Intensity Plot, HorizontalScale=AxisInt32: Label=Horizontal Axis, Orientation=Horizontal, Range=[0, 2047], Adjuster=FitExactly, VerticalScale=AxisInt32: Label=Horizontal Axis, Orientation=Vertical, Range=[0, 2047], Adjuster=FitExactly} NationalInstruments.Controls.Primitives.IPlotObserver {NationalInstruments.Controls.Primitives.CartesianPlotObserver}

 

so all my concern is to identify the IntensityPlot of the IntensityGraph at runtime and call InverseMapDataPoint().

0 Kudos
Message 14 of 17
(1,100 Views)

Unfortunately, I don't quite follow what you are asking. InverseMapDataPoint is a method that exists on the Windows Forms NationalInstruments.UI.IntensityPlot type, so it has no interaction with the WPF NationalInstruments.Controls.IntensityGraph API. The example you showed to access AllPlots[0] is the correct code to retrieve the default plot for a WPF graph, but this returns a WPF plot observer type, not a Windows Forms plot type.

~ Paul H
0 Kudos
Message 15 of 17
(1,097 Views)

Paul,  all I wanted is to find a method in WPF which serves the functionality of InverseMapDataPoint() of Winforms.

I agree with you that InverseMapDataPoint()  cannot be used in WPF 🙂

 

0 Kudos
Message 16 of 17
(1,094 Views)

Thanks for the clarification 🙂


So the Windows Forms InverseMapDataPoint method on the plot takes a screen position, and returns the data point that would appear at that position (according to the axes referenced by that plot).

 

The WPF ScreenToData method takes a reference plot and a screen position, and returns the data values that would appear at that position (according to the axes referenced by that plot). The WPF graph supports a broader range of data than just double, which is why the values are returned as a list. The type of each value will match the type of the corresponding axis, so if you are using Axis<double> for both axes, then the list will contain two double values.

 

For example, extending the mouse move event handler from earlier, this would retrieve the data value at a given screen position:

private void OnPlotAreaMouseMove( object sender, MouseEventArgs e ) {
    Point screenPosition = graph.GetPlotAreaPosition( e );
    IList dataPosition = graph.ScreenToData( graph.AllPlots[0], screenPosition );
    ...
}
~ Paul H
0 Kudos
Message 17 of 17
(1,083 Views)