Chapter 12: Reports and Journals

Question 12.1: At the top of my report, there is a text string that begins “Where…”. How can I remove this information from my report and instead show it in the top OutlineBox?

Question 12.2: How can I use a variable in a Where statement so that the window title and Where text show the actual variable values rather than the variable name?

Question 12.3: How can I arrange my report so that I have two graphs per row?

Question 12.4: How can I get a handle to the journal window so that I can save it?

Question 12.5: How can I change the name of the journal window?

Question 12.6: How do I insert the contents of a data table into a journal, under a specific OutlineBox?

Question 12.7: I need to save my report as a .jrp file in my script. How is this done?

Question 12.8: How can I use a map as a filter?

Question 12.9: How do I create a tabbed report?

Question 12.10: My graph has a local data filter.  How can I save both components as one interactive HTML file?

Question 12.1: At the top of my report, there is a text string that begins “Where…”. How can I remove this information from my report and instead show it in the top OutlineBox?

Figure 12.1 Where String in Bivariate Report

Figure 12.1 Where String in Bivariate Report  

Solution 12.1:

The Where information appears as text above the OutlineBox. When you review the display tree, you will notice that the TextBox is at the same level as the OutlineBox (a previous sibling).  One way to access this TextBox is to send the Parent message to the OutlineBox and then subscript to the first TextBox. Finally, the Where text can be removed from the report by changing the Visibility of the TextBox to “Collapse”.

The Where information can be added to the existing OutlineBox title by first extracting the current title.  Then the new title can be assigned by concatenating the desired text to the original title.

NOTE: The number associated with the TextBox is 1 in this case. However, if the Report Preferences have been set for “Date Title on Output” or “Data Table Title on Output”, the TextBox number for the Where information might be 2 or 3.  More information about parent and child relationships within reports can be found in the Scripting Guide.

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create a few Bivariate plots to demonstrate

   the Where text */

For( i = 12, i <= 14, i++,

    biv = dt << Bivariate(

            Y( :height ),

            X( :weight ),

            Where( :age == i),

            Fit Polynomial( 3, {Line Color( "Green" ), Line Style( Smooth )} )

    );

    Wait( 1 );  //For demonstration purposes

 

    /* Hide the TextBox containing the Where text */

    (Report( biv ) << Parent)[Text Box( 1 )] << Visibility("Collapse" );

    Wait( 1 );  //For demonstration purposes.

           

    /* Add Where information to first OutlineBox */

    currentText = Report( biv )[Outline Box( 1 )] << Get Title;

    Report( biv )[Outline Box( 1 )] << Set Title(

            currentText || ", age = " || Char( i )

    );

    Wait( 1 );  //For demonstration purposes, allowing time to view change

);

Result 12.1:

Figure 12.2  Where Text Removed and OutlineBox Title Updated

Figure 12.2 Where Text Removed and OutlineBox Title Updated

Question 12.2: How can I use a variable in a Where statement so that the window title and Where text show the actual variable values rather than the variable name? 

Solution 12.2:

Build an expression, and then use Eval Expr() to resolve the global variable prior to evaluation of the expression:

/* Open the Fitness sample data table */

dt = Open( "$SAMPLE_DATA/Fitness.jmp" );

 

/* Assign the criteria to a global variable */

selVar = "M";

 

/* Build the main expression */

bivExpr = Expr(

    dt << Bivariate(

        Y( :MaxPulse ),

        X( :RstPulse ), 

        /* Identify the global variable by wrapping it with the Expr function */       

        Where( :sex == Expr( selVar ) )

    )

);

 

/* Resolve the variable expression first, then evaluate the main expression */

Eval( Eval Expr( bivExpr ) );

This solution illustrates how to use a global variable that contains a string, and how to place it in a Where clause in an analysis launch. First, an expression is built that contains a Where clause, which itself contains an expression. 

In the last line of code, the Eval Expr() function evaluates the Expr( selVar ) within the main expression, bivExpr. Finally, the Eval() function evaluates the main expression, bivExpr.

Result 12.2

Figure 12.3 Where Text Replaced

Figure 12.3 Where Text Replaced

 

Question 12.3: How can I arrange my report so that I have two graphs per row? 

 

Solution 12.3:

Use a Lineup Box() to arrange each By level report within a New Window:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Use the Lineup Box with the N Col argument to arrange the By level plots */

nw = New Window( "Bivariate Report",

    Lineup Box( N Col( 2 ), Spacing( 10 ), dt << Bivariate( Y( :weight ), X( :height ), By( :age ) ) )

);

Lineup Box() is a Display Box constructor that aids in the spatial arrangement of reports.  The N Col argument in Lineup Box() establishes two columns for the By level display boxes.  To learn more about Lineup Box() and its arguments, see the Scripting Index topic.

Result 12.3:

Figure 12.4  Bivariate Reports Arranged Two Graphs per Row

Figure 12.4 Bivariate Reports Arranged Two Graphs per Row 


 

Question 12.4: How can I get a handle to the journal window so that I can save it? 

Solution 12.4: 

Use the Current Journal() function, as shown in the following code:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Generate the desired analysis */

biv = dt << Bivariate( Y( :weight ), X( :height ), Fit Line );

 

/* Create a journal of the report */

Report( biv ) << Journal;

 

/* Obtain a handle to the current journal */

jrn = Current Journal();

 

/* Save the journal */

jrn << Save Journal( "$DOCUMENTS/DistJournal.jrn" );

The Current Journal() function returns a reference to the active journal that is open in the JMP application.

Result 12.5:

Figure 12.5 Journaled Report

Figure 12.5 Journaled Report

Figure 12.6 Journal Saved to Documents Folder

Figure 12.6 Journal Saved to Documents Folder

Question 12.5: How can I change the name of the journal window? 

Solution 12.5: 

Use Set Window Title() to set the title to the journal window, as shown in the following code:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create a journaled report using the New Window option */

jw = New Window( "Generic Journal Title",

    <<Journal,

    biv = dt << Bivariate( Y( :weight ), X( :height ), Fit Line )

);

 

/* Set the title of the journal window */

jw << Set Window Title( "My New Journal" );

The Set Window Title() message can be used to change any window titles.

Result 12.5:

Figure 12.7 Journal after Name Change

Figure 12.7 Journal after Name Change


 

Question 12.6: How do I insert the contents of a data table into a journal, under a specific OutlineBox?

 

Solution 12.6:

The following example shows how to insert the sample data table, Big Class, under the Summary of Fit OutlineBox in a journal that contains a Bivariate report:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Generate the desired analysis */

biv = dt << Bivariate( Y( :weight ), X( :height ), Fit Line );

 

/* Create a journal of the report */

Report( biv ) << Journal;

 

/* Obtain a handle to the current journal */

jrn = Current Journal();

 

/* Insert an OutlineBox containing the data table as a report object under the Summary of Fit table */

jrn["Summary of Fit"] << Append(

    Outline Box( dt << Get Name || " Data Table", dt << Get As Report )

);

To append the data table as a report object under a particular OutlineBox in the main journal, send the Append() message to that OutlineBox.

Result 12.6:

Figure 12.8  Journal with Data Table Inserted

Figure 12.8 Journal with Data Table Inserted

 

Question 12.7: I need to save my report as a .jrp file in my script.  How is this done?

Solution 12.7:

There is no Save() option for the .jrp file type. The following method serves as a workaround.

Extract the script from the platform, and then use the Save Text File() command to save the file path and script as a text file, using the .jrp file extension:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create a distribution platform */

dist = dt << Distribution(

    Continuous Distribution( Column( :weight ) ),

    Nominal Distribution( Column( :age ) )

);

 

/* Get a script of the distribution platform */

distScript = dist << Get Script;

 

/* Save the file path and script as a text file, and specify .JRP as file type */

tfpath = Save Text File(

    "$DOCUMENTS/DistributionReport.jrp",

    "[Open("$SAMPLE_DATABig Class.jmp");]" || Char( Name Expr( distScript ) )

);

When creating a JMP report file (.jrp) in a script using the Save Text File() function, remember to specify the file path with the .jrp extension as the first argument.  The second argument is the script that will be executed when opening the file.  The first part of the script opens the data table.  Notice how it is enclosed by a [ string ] function, which enables you to use quotation marks or escape characters within the argument. This is concatenated to the platform script, which is wrapped in Name Expr() to return the script without evaluating and Char() to wrap the script in quotation marks for concatenation to the other parts of the script string. 

Result 12.7:

Figure 12.9 Report is Saved as .jrp File Type

Figure 12.9 Report is Saved as .jrp File Type

Figure 12.10 Report File Opened

Figure 12.10 Report File Opened

 

Question 12.8: How can I use a map as a filter?

Solution 12.8:

Use Data Filter Context Box() in conjunction with the Data Filter Source Box() to make a map plot the filter for a different plot within a report:

/* Open the SATByYear sample data table. */

dt = Open( "$SAMPLE_DATA/SATByYear.jmp" );

 

/* Create a New Window that will hold the filter(map) and the scatterplot to be filtered */

nw = New Window( "Use Map as Filter",

    /* Wraps both the source filter and the report being filtered */

    dfcb =Data Filter Context Box(

        H List Box(

            /* Wraps the map platform, which is the source filter */

            dfsb2 = Data Filter Source Box(

                gb1 = dt << Graph Builder(

                    Size( 273, 275 ),

                    Show Control Panel( 0 ),

                    Fit to Window( "Off" ),

                    Variables(

                        Color( :Name( "Expenditure (1997)" ) ), Shape( :State )

                    ),

                    Elements( Map Shapes( Legend( 2 ) ) ),

                    SendToReport(

                        Dispatch(

                            {},

                           "",

                            ScaleBox( 2 ),

                            {Min( 14.7815165876777 ), Max( 60.2184834123223 ),

                             Inc( 10 ), Minor Ticks( 1 ),

                            Label Row Nesting( 1 )}

                        ),

                        Dispatch(

                            {},

                           "400",

                            ScaleBox,

                            {Legend Model(

                               2,

                                Properties(

                                   0,

                                    {gradient(

                                        {Color Theme( "White to Green" ),

                                         Label Format( "Fixed Dec", 15, 0 )}

                                    )}

                                )

                            )}

                        )

                    )

                )

            ),

           /* Report that is being filtered */

            gb2 = dt << Graph Builder(

                Size( 534, 453 ),

                Show Control Panel( 0 ),

                Fit to Window( "Off" ),

                Variables( X( :SAT Verbal ), Y( :SAT Math ) ),

                Elements( Points( X, Y, Legend( 2 ) ),

                    Smoother( X, Y, Legend( 3 ) )

                )

            )

        )

    ) /* End of context box */

);

The Data Filter Context Box() and Data Filter Source Box() constructs enable you to create local data filters using graphs.  In this example, we used a Graph Builder map plot as the designated filter for a scatter plot, but you can use a variety of graphs and reports to create your own hierarchy of filtering.  Remember to wrap both the filtering display box and the display boxes to be filtered with the Data Filter Context Box(), and then wrap your filtering display with the Data Filter Source Box().

Result 12.8

Figure 12.11 Map as Filter Report

Figure 12.11 Map as Filter Report

 

 

Question 12.9: How do I create a tabbed report?

Solution 12.9:

This example solution creates a tabbed report to hold three platforms: Distribution, Bivariate, and Oneway:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create a new window to hold three tab pages, one each for platform */

tabWin = New Window( "Fit Y by X Reports",

    /* The Tab Box is the container for the Tab Page Boxes */

    tb = Tab Box(

        /* Tab 1 */

            Tab Page Box(

                    Title("Distribution" ),

                    dist = dt << Distribution(

                            Continuous Distribution( Column( :weight ) ),

                            Nominal Distribution( Column( :age ) )

                    )

            ),

        /* Tab 2 */

            Tab Page Box( Title( "Bivariate" ), biv = dt << Bivariate( Y( :weight ), X( :height ), Fit Line ) ),

        /* Tab 3 */

            Tab Page Box(

                    Title("Oneway" ),

                    ow = dt << Oneway( Y( :height ), X( :sex ), Means( 1 ), Mean Diamonds( 1 ) )

            )

    )

);

The Tab Box is a container for other display boxes, the Tab Page Boxes.  Each Tab Page Box holds the title for the tabs and contents.

Another option for creating a tabbed report is to use the Application Builder.  To see an example application that uses the Tab Box with Tab Page Boxes, go to File New Application and choose the Presentation sample.

Result 12.9:

Figure 12.12 Tabbed Report

Figure 12.12 Tabbed Report

 

Question 12.10: My graph has a local data filter.  How can I save both components as one interactive HTML file?

 

Solution 12.10:

Send the save message to the Top Parent of the report, which is a higher level in the display tree:

/* Open the sample data table, Big Class.jmp */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create a graph builder plot with a local data filter */

gb = dt << Graph Builder(

    Size( 534, 454 ),

    Show Control Panel( 0 ),

    Variables( X( :height ), Y( :weight ) ),

    Elements( Points( X, Y, Legend( 10 ) ), Line Of Fit( X, Y, Legend( 13 ) ) ),

    Local Data Filter( Add Filter( columns( :sex ) ) )

);

 

/* Send message to Top Parent will include the Local Data Filter in saved HTML file*/

(gb << Top Parent) << Save Interactive HTML( "$DOCUMENTS/GraphBuilder_DataFilter.html" );

 

Result 12.10:

Figure 12.13 Report with Local Data Filter

Figure 12.13 Report with Local Data Filter

Figure 12.14 Saved Interactive HTML Report

Figure 12.14 Saved Interactive HTML Report

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset