Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Scaling vertical axis of wpf intensity graph

Solved!
Go to solution

Hi,

I am trying to scale the vertical axis of a wpf IntensityGraph, but I am not sure how to this. For example, take the example called ColorScale from your examples. Here the data resides in an array of 201 and adjuster is set to Loosely giving vertical axis from 0 to 200. But If would like to scale the axis from 0 to 400 with the exact same data, how is this done? I would also like the axis to be adjustabel, i.e. InteractionMode set to EditRange, and when the new axis is set from 0 to 200 only half the circle should show.

0 Kudos
Message 1 of 6
(2,566 Views)

I believe the Scale Axis Values question would cover the display part? For example, using the CustomSampleRateFormatter from the second link with Rate="2" will display from 0 to 400:

 

<ni:IntensityGraph.VerticalAxis>
    <ni:AxisDouble Label="Intensity Y Axis">
        <ni:AxisDouble.MajorDivisions>
            <ni:RangeLabeledDivisions>
                <local:CustomSampleRateFormatter Rate="2" />
            </ni:RangeLabeledDivisions>
        </ni:AxisDouble.MajorDivisions>
    </ni:AxisDouble>
</ni:IntensityGraph.VerticalAxis>

 

 

You can further override the formatter’s TryParse method to control how interactive range editing works, or handle the RangeChanged event on the axis.

~ Paul H
0 Kudos
Message 2 of 6
(2,460 Views)

Thanks for the help Paul! The solution works for the scaling, but I still have some issues/questions. When adding arrays of size 2000 with Rate = 2, the scale will be from -1 to 4000. I guess this has to do with the fact that first pixel runs from -.5 to 0.5? Any solution to run axis from 0 to 3999? I also normally has interaction mode set to edit range, but when I enter 1000 as new maxvalue this is changed to 2000 as this is also scaled with 2, which is not wanted. Any ideas?

0 Kudos
Message 3 of 6
(2,427 Views)

Sorry Paul I didn't read the part where you already recomended to override the formatter’s TryParse method to control how interactive range editing works. Do you have an example on this?

0 Kudos
Message 4 of 6
(2,424 Views)
Solution
Accepted by topic author OddvarC

For TryParse, reverse the scaling done in FormatCore:

 

public override bool TryParse<TData>( string value, ValuePresenterArgs args, out TData parsedValue ) {
    if( !base.TryParse( value, args, out parsedValue ) )
        return false;

    double result = (Convert.ToDouble( parsedValue ) - Start) / Rate;
    parsedValue = (TData)Convert.ChangeType( result, typeof( TData ) );
    return true;
}

 

 

The intensity renderer displays samples centered on the X and Y values passed in. For arrays, this does mean samples will be centered on integer indices (e.g. the sample at index (0,0) would be drawn from −0.5 to +0.5). If you are still using the FixedSizeIntensityChartCollection from earlier questions, you could change the row and column values to be centered between integer indices instead:

SequenceBufferPool.CreateIntervalBuffer( rowCount, Unit.None, 0.5, 1.0 )

~ Paul H
0 Kudos
Message 5 of 6
(2,410 Views)

Thanks, works perfectly!!

0 Kudos
Message 6 of 6
(2,396 Views)