Skip to content

Commit

Permalink
Added support for related reports. Fixes #17.
Browse files Browse the repository at this point in the history
  • Loading branch information
ngehlenborg committed Jun 24, 2013
1 parent d99ca98 commit 23d921b
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Nozzle.R1/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: Nozzle.R1
Type: Package
Title: Nozzle Reports
Version: 1.2-0
Date: 2012-05-21
Version: 1.3-0
Date: 2012-06-23
Author: Nils Gehlenborg <nils@hms.harvard.edu>
Maintainer: Nils Gehlenborg <nils@hms.harvard.edu>
Description: The Nozzle package provides an API to generate HTML reports with
Expand Down
1 change: 1 addition & 0 deletions Nozzle.R1/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export(addRelatedReport)
export(addTo)
export(addToInput)
export(addToIntroduction)
Expand Down
10 changes: 9 additions & 1 deletion Nozzle.R1/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Release R1-1.3-0 / 23 June 2013

- Added support to add and display of "related reports", e.g. the reports that
correspond to the same analysis but were applied to different inputs.

-----------------

Release R1-1.2-0 / 21 May 2013

- Added folding sections for maintainer and citation information.
Expand All @@ -6,12 +13,14 @@ Release R1-1.2-0 / 21 May 2013
version. This is useful for reports that are part of a larger set of reports
that are being generated together.

-----------------

Release R1-1.1-1 / 15 May 2013

- Fixed problem with subtitle if reports generated with Nozzle versions older than
R1-1.1-0 were rendered with R1-1.1-0.

-----------------

Release R1-1.1-0 / 14 May 2013

Expand All @@ -30,7 +39,6 @@ Release R1-1.1-0 / 14 May 2013

-----------------


Release R1-1.0-0 / 8 January 2013

- Fully documented API.
Expand Down
94 changes: 90 additions & 4 deletions Nozzle.R1/R/nozzle.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#' \tabular{ll}{
#' Package: \tab Nozzle.R1\cr
#' Type: \tab Package\cr
#' Version: \tab 1.2-0\cr
#' Date: \tab 2013-05-15\cr
#' Version: \tab 1.3-0\cr
#' Date: \tab 2013-06-23\cr
#' License: \tab LGPL (>= 2)\cr
#' LazyLoad: \tab yes\cr
#' }
Expand All @@ -42,7 +42,7 @@ NULL

.nozzleEnv <- new.env();

.PACKAGE.VERSION <- "1.2-0";
.PACKAGE.VERSION <- "1.3-0";

.ELEMENT.REPORT <- "_report_";
.ELEMENT.SECTION <- "_section_";
Expand Down Expand Up @@ -730,7 +730,7 @@ newReport <- function( ..., version=0 )
references$domId <- "references";

meta <- newSection( "Meta Information", class="meta" )
meta$domId <- "meta";
meta$domId <- "meta";

# If a new predefined section is added here a ".hasPredefinedXXXSection" function needs to be added below as well as an an "addToXXX" function.

Expand Down Expand Up @@ -862,6 +862,9 @@ newCustomReport <- function( ..., version=0 )

element$navigation$previousUrl <- NA;
element$navigation$previousName <- NA;

# report navigation: related reports matrix (name: STRING, url: STRING, significant findings: BOOLEAN)
element$relatedReports <- matrix( NA, nrow=0, ncol=3 );

return ( element );
}
Expand Down Expand Up @@ -933,6 +936,29 @@ setParentReport <- function( report, url, ... )
}


#' Add the URL, title, and signficance status of a related report, e.g. one summarizing the same type of analysis but on a different input set.
#' @param report Report object.
#' @param name Name of the related report.
#' @param url URL of the related report (may be relative).
#' @param isSignificant Flag indicating whether the related report contains significant findings.
#' @export
#' @return Updated report element.
#'
#' @author nils
addRelatedReport <- function( report, name, url, isSignificant=FALSE )
{
if ( is.null( report$relatedReports ) )
{
report$relatedReports <- matrix( NA, nrow=0, ncol=3 );
}

report$relatedReports = rbind( report$relatedReports, c( name=name, url=url, isSignificant=isSignificant ) )

return ( report );
}



#' Get the title of \code{report}.
#' @param report Report element.
#' @export
Expand Down Expand Up @@ -4017,6 +4043,14 @@ writeReport <- function( report, filename=DEFAULT.REPORT.FILENAME, debug=FALSE,
.write( "<script type=\"text/javascript\">", file );
.writeJsonElement( "nozzleMeta", report$meta, file );
.writeJsonElement( "nozzleNavigation", report$navigation, file );
if ( !is.null( report$relatedReports ) )
{
.writeJsonMatrix( "nozzleRelatedReports", report$relatedReports, file );
}
else
{
.writeJsonMatrix( "nozzleRelatedReports", matrix( NA, nrow=0, ncol=3 ), file );
}
.write( "</script>", file );

# === REPORT META END ===
Expand Down Expand Up @@ -4299,6 +4333,58 @@ writeReport <- function( report, filename=DEFAULT.REPORT.FILENAME, debug=FALSE,
}


# write rows of matrix as an array of objects, using column header as field names
.writeJsonMatrix <- function( jsVariable, element, file )
{
.write( "var ", jsVariable, " = [", file );

if ( dim( element )[1] > 0 && dim( element )[2] > 0 )
{
for ( r in 1:dim( element )[1] )
{
.write( " { ", file, nobreak=T );

for ( c in 1:dim( element )[2] )
{
.write( "\"", colnames(element)[c], "\"", ": ", file, nobreak=T );

if ( is.numeric( element[r,c] ) )
{
.write( element[r,c], file, nobreak=T )
}
else if ( element[r,c] == "TRUE" )
{
.write( "true", file, nobreak=T )
}
else if ( element[r,c] == "FALSE" )
{
.write( "false", file, nobreak=T )
}
else
{
.write( "\"", element[r,c], "\"", file, nobreak=T )
}

if ( c < dim( element )[2] )
{
.write( ", ", file, nobreak=T );
}
}

.write( " }", file, nobreak=T );

if ( r < dim( element )[1] )
{
.write( ",", file );
}
}
}
.write( "", file );
.write( "];", file );
}



.writeJsonNumeric <- function( name, value, file, indent=0 )
{
if ( length( value ) == 1 )
Expand Down
66 changes: 65 additions & 1 deletion Nozzle.R1/inst/css/nozzle.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ li p {
text-transform: uppercase;
}


.menuitem {
display: inline-block;
padding-left: 5px;
Expand All @@ -52,6 +51,62 @@ li p {
background-color: #eeeeee;
}

ul.submenu {
display: inline;
margin-left: 0;
padding-left: 0;
}

ul.submenu, ul.submenu li, ul.submenu ul {
list-style: none;
}

ul.submenu ul {
visibility: hidden;
position: absolute;
top: 1.75em;
z-index: 598;
padding-right: 5px;
padding-left: 5px;
margin-left: -6px;
border: 1px solid #ccc;
//border-top: none;
color: #666666;
cursor: pointer;
border-bottom-left-radius: 0.55ex;
border-bottom-right-radius: 0.55ex;
background-color: #efefef;
-webkit-box-shadow: 0px 2px 4px black;
-moz-box-shadow: 0px 2px 4px black;
-opera-box-shadow: 0px 2px 4px black;
box-shadow: 0px 2px 4px black;
}

ul.submenu ul li {
float: none;
text-transform: none;
line-height: 2em;
}

ul.submenu ul li:hover {
text-decoration: underline;
}

ul.submenu .submenuhead:hover {
/*
-webkit-box-shadow: 0px 0px 0px black;
-moz-box-shadow: 0px 0px 0px black;
-opera-box-shadow: 0px 0px 0px black;
box-shadow: 0px 0px 0px black;
*/
z-index: -600;
border-bottom-left-radius: 0ex;
}

ul.submenu .submenuhead:hover > ul {
visibility: visible;
}

.menuitem a {
text-decoration: none;
color: #666666;
Expand Down Expand Up @@ -595,6 +650,15 @@ div.significant {
}


span.summary-small {
width: 6px;
height: 6px;
display: inline-block;
position: relative;
border-radius: 15ex;
top: -1px;
}

span.summary {
color: #919191;
cursor: default;
Expand Down
2 changes: 1 addition & 1 deletion Nozzle.R1/inst/css/nozzle.min.css

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions Nozzle.R1/inst/js/nozzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,29 @@ function applyFilePrefixPostfix( prefix, postfix )
menu += "<div class=\"menuitem deactivated\">&gt;</div>";
}

if ( nozzleRelatedReports != null && nozzleRelatedReports.length > 0 ) {
menu += "<ul class=\"submenu\"><li id=\"menu_related_reports_button\" class=\"menuitem submenuhead\">" + nozzleRelatedReports.length + " Related Reports";

menu += "<ul id=\"menu_related_reports_list\">";
for ( var i = 0; i < nozzleRelatedReports.length; ++i ) {
menu += "<li class=\"submenuitem\"><a href=\"" + nozzleRelatedReports[i].url + "\">" + nozzleRelatedReports[i].name + "</a>"

if ( nozzleRelatedReports[i].isSignificant ) {
menu += "&nbsp;<span class=\"summary-small significant\" title=\"Report contains findings that crossed a significance threshold.\"></span>";
}

menu += "</li>" ;

}
menu += "</ul>"; // submenu

menu += "</li></ul>"; // submenuhead

}
else {
// there are no related reports, ignore
}

menu += "<div class=\"menuitem separator\"></div>";

menu += "<div class=\"menuitem\" id=\"menu_expand_all\">Expand All</div>\
Expand All @@ -411,6 +434,12 @@ function applyFilePrefixPostfix( prefix, postfix )
menu += "</div></div>";

getFrame().prepend( menu );

/*
$( "#menu_related_reports_button" ).hover( function() {
$( "#menu_related_reports_list" ).show();
});
*/

$( "#menu_expand_all" ).click( function() {
toggleAllContents( true, ToggleMode.SHOW );
Expand Down
Loading

0 comments on commit 23d921b

Please sign in to comment.