Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Show round/whole numbers on x-axis when zoomed in

I want to show nice round numbers on the x-axis when the user zooms in.  It seems like I have to choose between CreateIntervalMode and CreateCountMode but I don't think they get me what I want.  What I really want is CreateIntervalMode with an offset because if the user zooms in to a range of 0.24 to 2.26 I would like the interval to be 0.2 but I want the first tick mark to be 0.4 not 0.24.  

 

If I use interval mode then I would get numbers like 0.24, 0.44, 0.64, etc.

 

If I use count mode then I would get numbers like 0.24, 0.42, 0.60, etc (depending on how many counts I specify).

 

Neither of those are what I want.

 

Is there a way to accomplish this?

 

Thanks,
Dan

0 Kudos
Message 1 of 3
(5,525 Views)

There is no pre-defined mode with the behavior you want, but you can always define your own. Here is an example using a very simplisitic method to generate divisions along a custom interval:


    public sealed class CustomDivisionsMode : RangeDivisionsMode {
        public double? Interval { get; set; }

        public override IList<TData> GetDivisions<TData>( IRangeDataMapper<TData> mapper, int divisionsEstimate ) {
            var doubleMapper = (IRangeDataMapper<double>)mapper;
            var range = doubleMapper.Range;

            double interval = Interval ?? 1.0;
            double start = Math.Floor( range.Minimum / interval ) * interval;
            var divisions = Enumerable.Range( 0, int.MaxValue )
                .Select( i => start + interval * i )
                .TakeWhile( d => d <= range.Maximum )
                .Cast<TData>( )
                .ToList( );

            return divisions;
        }

        public override IList<TData> GetSubdivisions<TData>( IRangeDataMapper<TData> mapper, IList<TData> dependentDivisions ) {
            return Auto.GetSubdivisions<TData>( mapper, dependentDivisions );
        }
    }


In XAML you would declare it on your axis as:


    <ni:AxisDouble Orientation="Horizontal" Range="0.24, 2.26">
        <ni:AxisDouble.MajorDivisions>
            <ni:RangeLabeledDivisions>
                <ni:RangeLabeledDivisions.Mode>
                    <local:CustomDivisionsMode Interval="0.2" />
                </ni:RangeLabeledDivisions.Mode>
            </ni:RangeLabeledDivisions>
        </ni:AxisDouble.MajorDivisions>
    </ni:AxisDouble>


(Note that the scale always includes the minimum and maximum labels; to hide them, you could look into a custom label presenter.)

~ Paul H
0 Kudos
Message 2 of 3
(5,521 Views)

Thank you.  This lead me to the solution I wanted.

0 Kudos
Message 3 of 3
(5,500 Views)