Example 2: A Cascading Menu

The program below shows how to create a cascading menu. The first menu item is "Color Code". Choosing this item displays a submenu with two items on it. When an item on the submenu is chosen, a module named BusinessColorCode is executed. The module’s second parameter depends on which action menu item was chosen. The module color-codes observations according to one of two variables and displays a legend that explains the color-coding. Finally, the module places a bullet mark next to the menu item that was chosen.

 

declare DataObject dobj;
dobj = DataObject.CreateFromFile( "business" );
 
declare ScatterPlot plot;
plot = ScatterPlot.Create( dobj, "Sales", "Profits" );
plot.SetMarkerSize( 5 );
plot.SetObsLabelVar( "Company" );
 
plot.AppendActionMenuItem( "Color Code\nBy &Nation"J,
    "run BusinessColorCode( plot, 'Nation' );" ); 
 
plot.AppendActionMenuItem( "Color Code\nBy &Industry"J,
    "run BusinessColorCode( plot, 'Industry' );" ); 
 
/* color code business data set by Nation or Industry 
   and display legend on plot */ 
start BusinessColorCode( Plot plot, variable );
    if variable='Nation' then do; 
        colors = RED||GREEN||YELLOW||WHITE||BLUE; 
        labels = {"Britain", "France", "Germany", "Japan", "USA"}; 
        end; 
    else if variable = 'Industry' then do; 
        colors = RED||YELLOW||GREEN||BLACK; 
        labels = {"Automobiles", "Electronics", "Food", "Oil"}; 
        end; 
 
    run ColorCodeObs( plot.GetDataObject(), 
        variable, IntToRGB(colors), ncol(colors) ); 
    plot.DrawRemoveCommands(); 
    run DrawLegend( plot, labels, 8, colors, 0, -1, -1, 'IRB' ); 
    plot.BulletActionMenuItem( "Color Code\nBy &"J + variable ); 
finish;
/* Press F11 in the plot window to see the menu. */