Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Hide first and last Division in WPF graph axis

Solved!
Go to solution

I would like to hide the default first and last major division marker in an axes of a WPF graph. I tried to extend RangeDivisionsMode and set my own class object to the MajorDivisions.Mode property on the axis. But even when I return an empty list in RangeDivisionsMode.GetDivisions<TData>(...), the first and last marker is drawn.

 

Thanks in advance, Jonas

Message 1 of 6
(7,108 Views)
Solution
Accepted by jonas.d

The minimum and maximum labels are handeled separately when displaying a scale (though the custom RangeDivisionsMode technique can be used for the minor divisions).


There is no direct configuration option to hide the extreme labels, but you can achieve this effect by initializing the LabelPresenter property on MajorDivisions with a custom implementation:


    class CustomFormatter : GeneralValueFormatter {
        protected override UIElement VisualizeCore<TData>( TData value, ValuePresenterArgs args, UIElement existingVisual ) {
            UIElement element = base.VisualizeCore<TData>( value, args, existingVisual );

            var axis = (Axis<TData>)args.Context;
            Range<TData> range = axis.Range;
            var comparer = range.Comparer;
            bool isExtreme =
                   comparer.Compare( range.Minimum, value ) == 0
                || comparer.Compare( range.Maximum, value ) == 0;
            element.Opacity = isExtreme ? 0.0 : 1.0;

            return element;
        }
    }

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

Thank you

0 Kudos
Message 3 of 6
(7,084 Views)

Hi Paul,

 

just another question concerning RangeDivisionsMode. In VisualizeCore I may create a TextBlock and apply some styling on it. But I can't figure out where the positioning is done. Is there any documentation about extending the default classes? I want to achieve a right-aligned maximum label and a left-aligned minimum label. The width of the axis should equal the window width and should not depend on the min/max label size.

 

Thanks, Jonas

0 Kudos
Message 4 of 6
(7,066 Views)

The short answer to your question is to replace the opacity setting with this:


    RelativeAlignment alignment =
        comparer.Compare( range.Minimum, value ) == 0 ? RelativeAlignment.Near :
        comparer.Compare( range.Maximum, value ) == 0 ? RelativeAlignment.Far :
        RelativeAlignment.Center;
    RegionPanel.SetRelativeHorizontalAlignment( element, alignment );




The longer answer is that, for the first version of the WPF controls, we intentionally left many of the underlying primitive types with minimal documentation, as we may change them in the future. In the current implementation, we use RegionPanel and attached properties like RelativeHorizontalAlignment to perform the layout for many of our controls. Although these exact members may be removed in a later release, we do plan to provide equivalent functionality and stabilize the primitive API over time.


Besides that caveat, I hope you find this answer useful 🙂

~ Paul H
0 Kudos
Message 5 of 6
(7,048 Views)

Just wanted to let you know we have added new MinimumLabelAlignment and MaximumLabelAlignment properties in the Measurement Studio 2015 release.

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