Loader for graphs, charts

Hello,

I would like to share a way to put a loader in big graphs.

1.- Add a script transform to the binded data


	system.perspective.sendMessage(
		messageType="startLoading",
		scope="view" 
	)
	
	
	return value

2.- Add another script at the end of all data flow

	system.perspective.sendMessage(
						messageType="finishLoading",
						scope="view"
					)
			
	

3.-In configure scripts add the message handlers startLoading and finishLoading

startLoading:
def onMessageReceived(self, payload):

	system.perspective.openPopup(
	    id="isLoadingGrafica-popup", 
	    view="Page/IsLoadingGrafica",
	    title="",
	    width=273,
	    height=128,
	    overlayDismiss=False,
	    modal=False
	)
--------------------------------------------------------------

finishLoading:

def onMessageReceived(self, payload):

	system.perspective.closePopup(id="isLoadingGrafica-popup")


4.- setup your popup screen as you wish IsLoadingGrafica

image

This way user will always now something is going on while large graphs are loading.

Cheers!

@Alejandro_Alaco , did you find this method better or easier than what @pascal.fragnoud suggested in this post? What did you like more/less?
I ask because I am about to implement this and wanted to see if one method is preferred vs. another.

Frankly, I don't understand why you'd want to introduce an extra layer of messages and handlers. This requires extra setup, for no gain.
The general idea is the same: open a popup, process things, close popup.
The decorator handles this by opening and closing the popup for you, with a try/except/finally to make sure the popup is always closed, even if the code raises an error.
Bringing message into this only adds steps and complexity for which I can't find a justification.
The only thing it brings would be that you don't need to add a function in your script library...
But if that's really an issue, you can define that function in the event/transform and decorate it there. But frankly, if a function may take long enough to warrant a spinner, it probably deserves a spot in the library.

Actually, I guess this could be used to open the spinner on some event and close it on another event, but that sounds like a terrible idea. I really wouldn't do that. I'd rather decorate each event, which adds the possibility of displaying different loading messages for different steps of the process.

4 Likes

But you are using a popup too, no?

Yes, as I said, the general idea is the same:

  • open popup
  • do the slow processing
  • close popup

But I simply call system.perspective.openPopup and closePopup instead of sending messages.
This means we don't need message handlers or anything.

Having this in a decorator also means that the error handling is abstracted and you don't need to worry about it

1 Like

ok, great, thanks for the explanation, will try on