Working With EVRIADDON

From Eigenvector Research Documentation Wiki
Jump to navigation Jump to search

The evriaddon object allows for existing functions to "query" for additional functionality. A good example is the editds_importmethods function that defines import methods. This function adds additional import methods to those included with PLS_Toolbox.

Object Properties

Querying evriaddon_connection will return an object which has help built into it:

obj = evriaddon_connection

at the end of the object's entrypoint listing it says:

   Entry Points:
       analysistypes                        : ---
       importmethods                        : ---
       importmethods_filter                 : ---
       savemodelas                          : ---
       preprocess                           : ---
       browse_post_gui_init                 : ---
       browse_shortcuts                     : ---
       ...
       load_postload                        : ---
       autoimport_postload                  : ---
       addsourceinfo_prefilter              : ---
       plotgui_toolbar                      : ---
    Entrypoint Help: use "obj.help.entrypoint"

for example:

>> obj.help.analysis_calcmodel_callback
ans =
    fn(fig,eventdata,handles);  %perform user-specified events when calc model is clicked (calc or apply).


The help specifies what the function I/O is expected to be for the given entry point.

Examples

NOTE: Some of these examples add toolbar buttons. A list of available icons can be seen with the following command. These icons should be used as the first input to the button definition.

toolbar icons

Adding a Custom Import Function

  • Since there's already an entry in the @evriaddon/addon_pls_toolbox.m file that points to editds_importmethods we simply need to add the function created in step one to the list of import methods within editds_importmethods. Edit this file and add an entry for the new import method.
  • Your entry will show up the next time you use the import menu item.

Adding an PLOTGUI Toolbar Button

In this example we'll add a button to the plotgui toolbar (the toolbar that appears on the "target" figure) that creates a static plot.

  • The function that uses evriaddon in this situation is plotgui_toolbar.m. Opening this function we can see that to add a button we need to add an entry to the list (n x 7 cell array of strings) of buttons with the following format:
icon tag callback enable/disable tooltip separator on/off push/toggle button

Create a function (in the PLS_Toolbox/utilities folder) named "myplotguibuttons.m". All the function will do is take the existing button list and add an entry for an additional button. Looking at where plotgui_toolbar.m calls evriaddon I know it passes two inputs, the button list (btn) and figure handle (targfig). We ignore targfig for now because we don't need any figure information. The code should then be simply:

function btn = myplotguibuttons(btn,targfig)
%MYPLOTGUIBUTTONS Utility function to add toolbar buttons.

btn = [btn
  {
  'plot'  'makestaticplot'  'plotgui(''menuselection'',''ViewSpawn'')'  'enable' 'Create a static plot.' 'on'  'push'
  }];

I chose the "plot" icon, a unique tag name, a simple plotgui command, and appropriate values for the rest of the settings.


  • In the PLS_Toolbox/utilities/@evriaddon folder, open the addon_pls_toolbox.m file. Here, add an "entry point" for plotgui_toolbar and assign it the function handle of the function we created above. It should look similar to:
...

out.priority = 1;
out.importmethods = @editds_importmethods;
out.preprocess    = @preprouser;
out.plotgui_toolbar = @myplotguibuttons;

...
  • Test your new button:
load arch
plogtgui(arch)


Adding an Analysis Toolbar Button

Building off of the above example, a toolbar button can be added to the analysis window. Two functions will be needed, one to create the button and one to be called by the button. Similar steps will be followed:

  • Create a function (in the PLS_Toolbox/utilities folder) named "myanalysis_toolbarfcn.m". This function will add a toolbar button if the analysis is PCA or MPCA. Looking at where toobar_buttonsets.m calls evriaddon, it passes two inputs, the current analysis method and button list. If the current method is PCA or MPCA a button will be added that calls into a custom plotting function with the figure handle.
function mylist = myanalysis_toolbarfcn(varargin)
%MYANALYSIS_TOOLBARFCN - Utility function to add toolbar buttons.

current_analysis = varargin{1};
mylist = varargin{2};

if ismember(current_analysis,{'pca' 'mpca'})
  mylist = [mylist
    {
    'coffee'  'CustomPlot'  'myanalysis_plot(gcbf)'  'enable' 'Create a custom plot.' 'on'  'push'
    }];
end
  • In the PLS_Toolbox/utilities/@evriaddon folder, open the addon_pls_toolbox.m file. Here, add an "entry point" for toolbar_buttonsets and assign it the function handle of the function we created in step above. It should look similar to:
...

out.priority = 1;
out.importmethods = @editds_importmethods;
out.preprocess    = @preprouser;
out.toolbar_buttonsets = @myanalysis_toolbarfcn;

...
  • Create the myanalysis_plot function. In this example function it shows how to get data and the model from the analysis window and then link and plot data:
function out = myanalysis_plot(analysis_figure)
%MYANALYSIS_PLOT - Test custom plot for analysis. 

handles = guidata(analysis_figure);
myxblock = analysis('getobjdata','xblock',handles);
mymodl = analysis('getobjdata','model',handles);

if isempty(myxblock) | isempty(mymodl)
  return
end

%Get prepro from model.
ppx = mymodl.detail.preprocessing{1};

%Apply prepro to xblock and create new dataset object of data to be
%plotted.
myxblock_pp = preprocess('apply',ppx,myxblock);

%Add the data to analysis and get "id" back that we can link with. 
dataid_pp = analysis('setobjdata','myxblock_ppdata',handles,myxblock_pp);

%Link data back to x-block.
xdataid = analysis('getobj','xblock',handles);
linkmap = [1 1];%Link first mode, coud add second mode as well. linkmap = [[1;2] [1;2]]
linkshareddata(xdataid,'add',dataid_pp,'analysis',struct('linkmap',linkmap,'isdependent',1));
linkshareddata(dataid_pp,'add',xdataid,'analysis',struct('linkmap',linkmap));

%Make plot with plotgui.
plotgui('new',dataid_pp,'plotby',0,'name','My PrePro XData');
  • Test the new button by opening PCA and trying it.