ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Resizing chart on resizing dialog window
Posted by Ulrich Telle on Jul-14-2018 02:35
I started to experiment with the extra sample "Real-time Sweep Chart" in combination with wxWidgets. In principle, I got it to work rather quickly. However, I observe a slightly different behaviour on resizing the dialog window depending on whether I increase or decrease the dialog window size.

If I decrease the dialog window size, the transition is smooth. That is, the chart seems to be redrawn frequently while resizing. But if I increase the dialog window size, a "frozen" version of the previous, smaller chart is visible in the left upper corner while the rest of the window background is grey, and then - after finishing the resize operation - with a short delay the larger version of the chart becomes visible.

Is this a known effect or could this be a glitch in my chart viewer implementation for wxWidgets? In the latter case, any idea what could have gone wrong?

Regards,

Ulrich

  Re: Resizing chart on resizing dialog window
Posted by Peter Kwan on Jul-14-2018 14:36
Hi Ulrich,

In charting, resizing means redrawing a new chart of a different size. It is normal to have some delay. It is similar to resizing the browser window. If you open a complex web page and drag the browser window, you may notice it takes some time for the browser to redraw at a bigger window size.

In our "Real-time Sweep Chart" sample code, in the resize event, it triggers the "viewPortChanged" event. In the "viewPortChanged" event handler, it redraws at the new size and displays it.

If you think the delay is abnormally large, you may try to print out some debug message to track the timing. (In Visual Studio, I often use the TRACE macro to print to the debug window. I am not sure if similar features are available in your development environment.

First, please determine when the resize event occur. Does the resize event occur as the mouse is dragging the window border, or does it occur only after the resize is completed (when you release the mouse button)?

When the resize event occur, does not viewPortChanged event also occurs shortly afterwards? In the original sample code, the chart will be redrawn based on the window size. In wxWidgets, during a resize event, is the reported window size being the size after the resize or before the resize?

In many GUI frameworks, many mouse related events (such as mouse move or drag to resize) can occur very frequently. For example, it may generate a hundred resize events per second as the mouse moves. Since it is not practical to update the screen that fast, in the CChartViewer implementation, we have timers that combine multiple ViewPortChanged events together into one event. In brief, it two viewPortChanged events occur within a short time, it will delay the second viewPortChanged event up for sometime (typically 20ms but is configurable using CChartViewer:;setUpdateInterval). If more viewPortChanged events come in during the delay period, they will be combined together. After the delay, the combined viewPortChanged event will be triggered.

For your case, if your have ported the above logic as well, please check if it is working. Insert statements to print when the viewPortChanged events are received, whether they trigger the delay, and whether a combined viewPortChanged event is triggered after the delay.

If you found that the viewPortChanged event occurs only with minimal delay, then you may check whether the updated chart is actually sent to the screen. In the MFC CChartViewer, the chart is sent to the screen when displayChart is called. Please check when this method is being called.

Regards
Peter Kwan

  Re: Resizing chart on resizing dialog window
Posted by Ulrich Telle on Jul-14-2018 21:31
Hi Peter,

thank you for your detailed description of the event flow.

In my implementation of the chart viewer for wxWidgets I closely followed the QT implementation. That is, I use the same logic and set up the same delay logic and timer events.

I added several debug output statements to see the sequence of events. Interestingly, there is indeed a difference visible, depending on whether the resize operation makes the window smaller or larger.

If the window is resized to a smaller size, I see that the hold timer events occur between the resize events. The hold timer interval is 20 ms (update interval), and the event handling method is called every 20 to 30 ms. This leads to redrawing the chart several times during resizing. That is, the application shows the expected and desired behaviour.

However, if the window is resized to a larger size, method updateViewPort is called from the resize event handler, but always returns immediately, because the hold timer flag is true/active. The problem is that the hold timer events do NOT occur while the resizing is still ongoing. Only after I release the left mouse button, and thus finishing the resizing operation, or stop moving the mouse, the hold timer event occurs and the chart is redrawn.

Obviously the hold timer events get lost somehow on enlarging the window, but not on making the window smaller. That's really strange.

If I change the update interval to 0 ms, that is, in fact deactivating the hold timer, the window is redrawn more often, and the resize operation looks slightly smoother. However, this is certainly not a good solution.

Probably it has something to do with the event handling in wxWidgets. I will ask one of the wxWidgets core developers whether he has an idea what might be going on.

Regards,

Ulrich

  Re: Resizing chart on resizing dialog window
Posted by Ulrich Telle on Jul-14-2018 23:55
In the meantime I made a few further experiments. It seems that wxWidgets' own OnPaint event was somehow competing with the timer events. I slightly modified my code ... and now enlarging the window works also as expected. There is still a small delay on redrawing the chart while resizing, but this is to be expected and certainly depends on the complexity of the chart.

Regards,

Ulrich

P.S.: I have now ported already 19 out of 21 ChartDirector sample applications to wxWidgets.