Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Annotation support for WPF PolarGraph?

Solved!
Go to solution

Does WPF PolarGraph support annotation? It seems that annotation is not supported, any other alternative ways to do this? 

 

Thanks!

0 Kudos
Message 1 of 4
(2,337 Views)

Unfortunately, the positioning logic used by the point and range annotations was only implemented for the simpler Cartesian graph case. However, all of the graphs support custom IRenderable children, allowing you to implement any kind of custom annotation.

~ Paul H
0 Kudos
Message 2 of 4
(2,320 Views)

Thank you Paul. 

 

I am not sure whether I can request demo code of implementing custom annotation from IRenderable.

 

Regards,

Bob

0 Kudos
Message 3 of 4
(2,296 Views)
Solution
Accepted by topic author Bob.Ter

Without other direction, I will guess you are interested in a point annotation. Here is a small example that renders a shape at a given data point:

 

public sealed class CustomAnnotation : IRenderable, IGraphChild {

    private readonly RenderTargetOptions _options = new RenderTargetOptions( null,
        RenderTargetOption.CreateValue( RenderTargetOptionsProperty.Fill, Brushes.Green ),
        RenderTargetOption.CreateValue( RenderTargetOptionsProperty.Stroke, Brushes.Black ),
        RenderTargetOption.CreateValue( RenderTargetOptionsProperty.StrokeThickness, 2.0 ) );

    private Point _dataPoint;

    public Point DataPoint {
        get { return _dataPoint; }
        set {
            _dataPoint = value;

            // Notify graph that data position has changed.
            OnInvalidated( RenderInvalidatedEventArgs.PositionalChange );
        }
    }

    public SupportedRenderModes SupportedRenderModes {
        get { return SupportedRenderModes.Vector; }
    }

    public event EventHandler<RenderInvalidatedEventArgs> Invalidated;

    private void OnInvalidated( RenderInvalidatedEventArgs e ) {
        var handler = this.Invalidated;
        if( handler != null ) {
            handler( this, e );
        }
    }

    public void Render( RenderArgs renderArgs ) {
        // Get the relative position for the specified data point.
        Point relativePosition = _parent.DataToRelative( _parent.GetDefaultPlot( ), new[] { _dataPoint.X, _dataPoint.Y } );

        // Draw a shape centered at that position.
        Size size = new Size( 20, 20 );
        PointShape shape = PointShape.Diamond;
        renderArgs.RenderTarget.DrawShape( _options, relativePosition, shape, size );
    }


    #region IGraphChild Members

    private IQueryableGraph _parent;

    public void RegisterParent( IGraph parent ) {
        _parent = (IQueryableGraph)parent;
    }

    public void UnregisterParent( IGraph parent ) {
        _parent = null;
    }

    public void Initialize( int index ) { }

    public void Uninitialize( ) { }

    #endregion
}

 

You could also use DrawShape to draw an arrow head (or use the drawing technique from this question), and use DrawValue to draw a string or other WPF content.

~ Paul H
Message 4 of 4
(2,289 Views)