I created a CustomRenderableSeries to put TextAnnotations on surface for every drawn point.
I discovered that Draw method is not called when no points are to be drawn in the visible range, so i can’t do any cleanup of the annotations i created in a previous pass.
Is there a way to force Draw method to be called anyway upon surface redraw (for example when zooming)?
Thank you
- Luigi Casiglio asked 4 years ago
- You must login to post comments
Here is my piece of code so you can see how i’m handling the drawing
protected override void Draw(IRenderContext2D renderContext, IRenderPassData renderPassData)
{
base.Draw(renderContext, renderPassData);
foreach (var a in track.Surface.Annotations.ToList())
{
Surface.Annotations.Remove(a);
}
// The data for this render pass
var dataPointSeries = renderPassData.PointSeries as Point2DSeries;
if (dataPointSeries == null || dataPointSeries.Count == 0) return;
var xCalc = renderPassData.XCoordinateCalculator;
// Iterate over the point series
for (int i = 0; i < dataPointSeries.Count; i++)
{
// Get the X value
var x = dataPointSeries.XValues[i];
// Transform coordinate
var xCoord = xCalc.GetCoordinate(x);
if (xCoord >= 0 && xCoord < renderContext.ViewportSize.Height)
{
double yCoord = 0;
var text = <get text from x value>
var TextAnnotation = new TextAnnotation();
TextAnnotation.CoordinateMode = AnnotationCoordinateMode.Relative;
TextAnnotation.VerticalAnchorPoint = VerticalAnchorPoint.Top;
TextAnnotation.X1 = xCoord / renderContext.ViewportSize.Height;
TextAnnotation.Y1 = yCoord;
TextAnnotation.Text = text;
Surface.Annotations.Add(TextAnnotation);
}
}
}
Surface is the current drawn surface.
This solution works well except when the method is not called because of empty data series or no points in the visibile range. In this case the annotations stay on the surface while they should be removed.
- Luigi Casiglio answered 4 years ago
- You must login to post comments
Can you explain your solution with a small piece of code?
I can’t understand your approach.
Thank you
- Luigi Casiglio answered 4 years ago
- You must login to post comments
This is by design unfortunately, RenderableSeries will not be drawn unless they have a DataSeries and data in it. That data must also be on-screen.
However you just said that you want to display text for every drawn point. So why not pass the data for every drawn point to the CustomRenderableSeries and use that data to position your text?
Best regards,
Andrew
- Andrew Burnett-Thompson answered 4 years ago
- You must login to post comments
Please login first to submit.