I've found what's happening and have a fix, though I'd like advice on whether it's something I'm doing or if there's a bug. My code boils down to:
public void OnBeforePaint(NPanel panel, NPanelPaintEventArgs eventArgs)
(
DoStuff();
if (requiresRecalculate)
{
this.chartControl.document.Calculate();
this.chartControl.document.RecalcLayout(this.chartControl.document.CurrentRenderingContext);
}
}
if requiresRecalculate is false then we're Ok and all data interactivity behaves as expected.
However, if requiresRecalculate is true, then when clicking on the rendered chart, OnBeforePaint is entered again, as though the chart hasn't finished rendering.
My use of the mouse wheel fixed it because DoStuff() makes requiresRecalculate false.
My solution is to add extra checking in DoStuff, so that once requiresRecalculate has fired once, then on the second entry DoStuff detects the action has occurred, so we are done and don't recalculate again.
Extra info:
I notice that OnBeforePaint is entered twice when displaying the chart.
The second time originates from the following code, specifically the bolded line. It seems there may be some unexpected interaction here? Should I achieve this in a different way or modify this code?
/// <summary>Intercepts mouse move to allow a cursor change depending upon the object beneath</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="NMouseEventArgs"/> instance containing the event data.</param>
/// <remarks>Code idea supplied by Nevron</remarks>
public override void OnMouseMove(object sender, NMouseEventArgs e)
{
if (e == null)
return;
NControlView view = (NControlView)this.GetView();
NHitTestCacheService hitTestService = view.GetServiceOfType(typeof (NHitTestCacheService)) as NHitTestCacheService;
if (hitTestService == null)
return;
NHitTestResult hitTestResult = new NHitTestResult(hitTestService.HitTest(new NPointF(e.X, e.Y)) as NChartNode);
INMouseService mouseService = (INMouseService) view.GetServiceOfType(typeof (INMouseService));
bool cursorSet = false;
if (hitTestResult.ChartElement == ChartElement.DataPoint && hitTestResult.Chart != null)
{
CartesianChartDefinition cartesianChartDefinition = hitTestResult.Chart.Tag as CartesianChartDefinition;
ChartSeries series = cartesianChartDefinition?.ChartSeriesSet.HavingId((int) hitTestResult.Series.Tag);
if (series != null && series.AllowDragging)
{
mouseService.Cursor = cartesianChartDefinition.ChartLayout == CartesianChartLayout.Vertical ? Cursors.SizeNS : Cursors.SizeWE;
cursorSet = true;
}
}
if (!cursorSet)
mouseService.Cursor = Cursors.Default;
}
Many thanks
Kevin