05-11-2018 06:33 AM
Does WPF PolarGraph support annotation? It seems that annotation is not supported, any other alternative ways to do this?
Thanks!
Solved! Go to Solution.
05-11-2018 09:48 AM
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.
05-14-2018 12:20 AM
Thank you Paul.
I am not sure whether I can request demo code of implementing custom annotation from IRenderable.
Regards,
Bob
05-14-2018 10:32 AM
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.