Replacing Data in an iTool
You can replace or update data in an existing iTool using either of two methods: using the iTool's creation routine and one of the VIEW keywords, or by retrieving the data object and calling the SetData method. Both methods will change the data stored in the Data Manager and will cause the display to be updated automatically.
Using the iTool Creation Routine
You can replace data in an existing iTool by using the iTool's creation command with the VIEW_NUMBER or VIEW_NEXT keyword set to a view that uses the data you wish to replace.
Note
The visualization is removed and recreated when you replace data using this technique. Any property changes you may have made to the old visualization will be lost. To preserve changes made to the visualization, see Using the SetData Method.
For example, suppose you have an iPlot tool with a single view, created with the following command:
Assuming the iPlot tool is selected, the following command will replace the data in the tool (myData1) with a new data set (myData2):
IPLOT, myData2, VIEW_NUMBER=1Note
The view number starts at 1, and corresponds to the position of the view within the graphics window (not necessarily the position on the screen). In the case of a gridded window layout, views are added to the iTool window beginning in the upper left-hand corner, and proceeding left to right and then down. You can see the position of a given view within the container by inspecting the tree view of the Visualization Browser. You can also re-order views using the items in the Edit → Order menu in the iTool.
In our example, if myData1 is not in use by any other iTool, it will be removed from the iTools Data Manager by this operation. If myData1 is used by a visualization in another view or another iTool, it will not be deleted.
Note
If the currently-active iTool contains only one view, setting the VIEW_NEXT keyword has the same effect as setting VIEW_NUMBER=1.
Using the SetData Method
You can replace the data that underlies a visualization using the SetData method of the IDLitData class. This technique has the advantage of preserving other changes you may have made to your visualization (property changes, etc.), but requires that you first retrieve the object identifier for the data item you want to replace. This, in turn, requires that you know the parameter name of the of the parameter that contains the data.
Retrieving Parameter Names from the Visualization
To retrieve a list of parameter names for a visualization type, use the QueryParameter method of the IDLitParameter class. The following example creates a plot visualization and retrieves the names of the plot visualization's registered parameters:
; Create the plot visualization IPLOT, RANDOMU(seed, 15) idTool = IGETCURRENT(TOOL=oTool) ; Retrieve the object reference to the plot visualization object. idPlot = oTool->FindIdentifiers('*plot', /VISUALIZATIONS) oPlot = oTool->GetByIdentifier(idPlot) ; Retrieve and print the parameter names. oPlotParams = oPlot->QueryParameter(COUNT=count) For i=0,count-1 DO PRINT, oPlotParams[i]
IDL prints:
Setting a New Data Value
Once you know the name of the parameter whose data you wish to change, retrieve the IDLitData object associated with that parameter using the GetParameter method of the IDLitParameter class. You can then use the SetData method of the IDLitData class to insert new data into the parameter. The following example changes the data associated with the "Y" parameter of the plot visualization created in the previous section:
Using the FindIdentifiers Method
It is also possible to use the FindIdentifiers method to retrieve the full identifier of a data object stored in the Data Manager, and use that identifier to retrieve the IDLitData object using the GetByIdentifier method of the IDLitContainer class. While this approach might seem simpler than retrieving the parameter names from the visualization and using the GetParameter method, it has the drawback that identifiers for objects in the Data Manager do not necessarily correspond to a single visualization. As a result, it can be difficult to determine which data item is which, based solely on inspection of the identifier.
Under some circumstances this may not be a problem. For example, if your code creates a new visualization based on data supplied at the command line, you will know that the data object or objects created in the Data Manager will be the last items in the Data Manager container object. The following code creates a new surface visualization using the ISURFACE command, and then immediately retrieves the data identifier of the last data item inserted into the Data Manager:
ISURFACE, DIST(40) idTool = IGETCURRENT(TOOL=oTool) allData = oTool->FindIdentifiers(/DATA_MANAGER, COUNT=c) idDataSurface = allData[c-1] PRINT, idDataSurface
IDL prints:
You then could the use the data identifier to retrieve a reference to the data object and change the data value using the SetData method:
oSurfaceData = oTool->GetByIdentifier(idDataSurface) success = oSurfaceData->SetData(1/(DIST(40)+1))