08-30-2013 10:09 AM
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
08-30-2013 01:00 PM
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.)
09-03-2013 01:39 PM
Thank you. This lead me to the solution I wanted.