Repeat render if changes are made in invoked events#3952
Repeat render if changes are made in invoked events#3952swharden merged 9 commits intoScottPlot:mainfrom
Conversation
…s (events are not invoked on second render).
…AxisRules make a change that the user wants to take action on)
E.g. something changes during an invoked event, then an axis rule makes a change, and then soemthing changes again during another invoked event. Have put a counter to prevent endless loop of renders.
|
It seems rather wasteful to render things 3 times to get the required result. I wonder if there is a better way of achieving the desired results by having the axes communicate without each other? Maybe you could upload a github code example to demonstrate the issue? |
(short-circuit logical operators and making a private set)
(response to code review)
I agree! I wasn't able to work out anything more sophistocated. This solved a problem for me, but if a better solution can be found that would be great.
Sure. Code smaple below. I demonstrated the original problem in Discord, but this more complete sample code captures the full behaviour described in the pull request: Demonstration of the code (with the fix in place) follows: If you change the left axis
If you change the right axis:
|
|
For completeness, below demonstrates the behaviour without this PR: If you change the left axis
If you change the right axis
|
|
Hmm, I see. Are you getting the artifacts of it jumping around a lot as you pan? I'm not sure of a good solution, maybe someone else will come along with an idea. |
No, panning is nice and smooth. I used to get jumping with SnapToTicks rules, but I resolved that in a recent PR. Thanks for review and consideration. Happy to let this sit wiating further comments or thoughts from others. I can use in my fork in the meantime. |
|
Hi @BrianAtZetica, thanks for this PR and @bforlgreen for your input along the way! The WPF demo you shared was really useful for testing this out. I consolidated all of the proposed logic in the render manager class and did it in such a way that does not add any properties. What do you think about this implementation? If you think it looks good I'll merge it and it will be in the next release! 🚀 |
Actually, I'll merge this now and any suggestions can be made in new PRs. Thanks again! |
Looks great to me! Thanks so much. |
* upstream/main: Fix interaction of axis panels when scale factor is more than 1 (ScottPlot#3994) Added ResetMinAndMaxValues() to DataLoggerSource.cs (ScottPlot#3993) CoordinateLine: add constructor overloads (ScottPlot#3987) Colormap.GetColors() (ScottPlot#3983) Added a constructor overload that accepts List<Coordinates> (ScottPlot#3982) Signal: improve support for IReadOnlyList<T> (ScottPlot#3978) Axes: improve sharpness of axis lines, tick marks, and grid lines (ScottPlot#3976) adding console write file name function (ScottPlot#3965) Color.ToColor() Sandbox: extend minimal API Sandbox: Create .NET API project SVG XML Updates (ScottPlot#3957) Repeat render if changes are made in invoked events (ScottPlot#3952) CI: autoformat Experimental DataLogger2 using a `CircularBuffer<T>` (ScottPlot#3946)




I had a requirement to synchronise two vertical axes (representing depth and elevation), but:
I was finding that if the user changed either vertical axis the other axis would update using the invoked AxisLimitsChanged event, but the render was already in progress, so the change was not seen until the next render occurred. This meant the two axes did not have the correct synchronisation.
The solution implemented in this PR is to test for changes made to axis limits by invoked events, and set a flag in the RenderManager to indicate that a repeat render is required.
However, my scenario was even more complex due to the depth axis snapping to tick values. When the user changed (zoomed/panned) the elevation axis, my AxisLimitsChanged event would change the depth axis. But on the repeat render, the depth axis then snaps to tick intervals and needs to invoke the AxisLimtisChanged event a second time. With the Depth axis now changed, I update the elevation axis, and I need to render a 3rd time to see this change.
I've set the rendering to repeat as long as it detects an axis change during invoked events, but have put a maximum limit of 5 repeat renders (to avoid an endless loop) - this could be made into a parameter in the future perhaps.