Fanning Software Consulting

Loading Graphics Commands into cgWindow

QUESTION: I love the resizeable graphics window, cgWindow, but I am having trouble loading multiple commands into the window. I have a plot that I put into cgWindow by setting the Window keyword on the cgPlot command. But, now I have about 10 different plot annotations I want to add to the window with the cgText command. If there were just a single cgText command, I could use the AddCmd keyword. But, if I use the AddCmd keyword with all 10 of these commands, there is a lot of flicking going on because all of the commands are executed every time I load another one.

I realized the cgWindow command itself has a LoadCmd keyword I can use to load these commands the way I want to, without executing the commands until I am ready, but that seems cumbersome. How come there isn't a LoadCmd keyword for the Coyote Graphics routines?

ANSWER: I started to add a LoadCmd keyword to the Coyote Library routines, but fortunately, I stopped myself. I realized there would be no end to it. As soon as I added a LoadCmd keyword, someone would ask for a ReplaceCmd keyword, and so on. Did I really expect everyone who writes a Coyote Graphics command to add 6-8 keywords just to make them work in resizeable graphics windows!? It seemed a dubious strategy if I wanted converts.

So, what I decided to do instead was put this functionality into the cgControl command. This command allows you to turn updates off for the window, until you are ready to start them up again. The sequence of commands you use looks something like this.

   cgPlot, data, ...., /Window  ; Create the resizeable graphics window from the plot.
   cgControl, Execute=0         ; Turn window updating off.
   cgText, ...., /AddCmd        ; Add cgText commands.
   ...                          ; Add as many commands as you like.
   cgControl, Execute=1         ; Turn window updating back on when finished.

Version of IDL used to prepare this article: IDL 7.0.1.

Last Updated: 11 March 2011