Skip to content

Commit

Permalink
User-defined default expansion of sections. Fixes #19.
Browse files Browse the repository at this point in the history
  • Loading branch information
ngehlenborg committed Jul 25, 2014
1 parent 23d921b commit 6482b06
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ build.sh

.DS_Store
de.walware.r.core.prefs
*.sublime-*
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.3-0
Date: 2012-06-23
Version: 1.4-0
Date: 2014-07-25
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
7 changes: 7 additions & 0 deletions Nozzle.R1/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Release R1-1.4-0 / 25 June 2014

- User-defined default expansion for sections and subsections is now supported
by the newSection() and newSubSection() parameter 'expanded'.

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

Release R1-1.3-0 / 23 June 2013

- Added support to add and display of "related reports", e.g. the reports that
Expand Down
30 changes: 21 additions & 9 deletions Nozzle.R1/R/nozzle.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Harvard Medical School, Center for Biomedical Informatics
# Broad Institute, Cancer Program
#
# Copyright (c) 2011-2013. All rights reserved.
# Copyright (c) 2011-2014. All rights reserved.
#
# TODO: add default state (open/closed) for sections (per default all will be closed in custom reports)

Expand All @@ -14,8 +14,8 @@
#' \tabular{ll}{
#' Package: \tab Nozzle.R1\cr
#' Type: \tab Package\cr
#' Version: \tab 1.3-0\cr
#' Date: \tab 2013-06-23\cr
#' Version: \tab 1.4-0\cr
#' Date: \tab 2014-07-25\cr
#' License: \tab LGPL (>= 2)\cr
#' LazyLoad: \tab yes\cr
#' }
Expand Down Expand Up @@ -708,16 +708,16 @@ newReport <- function( ..., version=0 )
element <- .newGeneralReport( "Nozzle Report", version=version );
}

overview <- newSection( "Overview" );
overview <- newSection( "Overview", expanded=TRUE );
overview$domId <- "overview";

introduction <- newSubSection( "Introduction" );
introduction$domId <- "introduction";

summary <- newSubSection( "Summary" );
summary <- newSubSection( "Summary", expanded=TRUE );
summary$domId <- "summary";

results <- newSection( "Results", class="results" );
results <- newSection( "Results", class="results", expanded=TRUE );
results$domId <- "results";

methods <- newSection( "Methods & Data" );
Expand Down Expand Up @@ -2492,12 +2492,17 @@ addToMeta <- function( report, ... )
#' @param class If set to SECTION.CLASS.RESULTS, results can be reported in this section. If set to SECTION.CLASS.META the section will be a meta data section.
#' @param exportId Unique string to identify this element. Used to retrieve the element using \code{getExportedElement}.
#' @param protection Procection level. One of PROTECTION.PUBLIC, PROTECTION.GROUP, PROTECTION.PRIVATE.
#' @param expanded Whether the section should expanded by default or not.
#' @export
#' @return New element.
#'
#' @author Nils Gehlenborg \email{nils@@hms.harvard.edu}
newSection <- function( ..., class="", exportId=NULL, protection=PROTECTION.PUBLIC )
newSection <- function( ..., class="", exportId=NULL, protection=PROTECTION.PUBLIC, expanded=FALSE )
{
if ( expanded ) {
class <- .concat( class, " visible" );
}

return ( .newElement( .ELEMENT.SECTION, .concat( ... ), class=class, exportId=exportId, protection=protection ) );
}

Expand All @@ -2506,13 +2511,20 @@ newSection <- function( ..., class="", exportId=NULL, protection=PROTECTION.PUBL
#' @param ... Strings that will be concatenated to form the subsection title.
#' @param exportId Unique string to identify this element. Used to retrieve the element using \code{getExportedElement}.
#' @param protection Procection level. One of PROTECTION.PUBLIC, PROTECTION.GROUP, PROTECTION.PRIVATE.
#' @param expanded Whether the section should expanded by default or not. This will not affect the state of parent sections.
#' @export
#' @return New element.
#'
#' @author Nils Gehlenborg \email{nils@@hms.harvard.edu}
newSubSection <- function( ..., exportId=NULL, protection=PROTECTION.PUBLIC )
newSubSection <- function( ..., exportId=NULL, protection=PROTECTION.PUBLIC, expanded=FALSE )
{
return ( .newElement( .ELEMENT.SUBSECTION, .concat( ... ), exportId=exportId, protection=protection ) );
class <- "";

if ( expanded ) {
class <- "visible";
}

return ( .newElement( .ELEMENT.SUBSECTION, .concat( ... ), class=class, exportId=exportId, protection=protection ) );
}


Expand Down
31 changes: 25 additions & 6 deletions Nozzle.R1/inst/js/nozzle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Nozzle R Package - JavaScript Library
*
* Copyright 2011-2013, Harvard Medical School / Broad Institute
* Copyright 2011-2014, Harvard Medical School / Broad Institute
* Authored and maintained by Nils Gehlenborg (nils@hms.harvard.edu)
*/

Expand Down Expand Up @@ -201,7 +201,8 @@ function applyFilePrefixPostfix( prefix, postfix )
ToggleMode = {
TOGGLE: 0,
SHOW: 1,
HIDE: 2
HIDE: 2,
INITIALIZE: 3
};

var toggleContents = function( section, animation, mode, target )
Expand All @@ -227,6 +228,25 @@ function applyFilePrefixPostfix( prefix, postfix )

switch ( mode )
{
case ToggleMode.INITIALIZE:
if ( section.hasClass( "visible" ) )
{
console.log( "Showing section ", section );
body.show();
if ( summarySignificant !== undefined )
{
summarySignificant.addClass( "deactivated" );
}
}

if ( !section.hasClass( "visible" ) )
{
body.hide();
}

button.text( section.hasClass( "visible" ) ? "-" : "+" );
button.attr( "title", section.hasClass( "visible" ) ? "Click to collapse" : "Click to expand" );
break;
case ToggleMode.TOGGLE:
if ( subSections.length == 1 )
{
Expand Down Expand Up @@ -291,7 +311,6 @@ function applyFilePrefixPostfix( prefix, postfix )
var sectionheaders = $( "#" + reportId + " .sectionheader" ).not( ".evidence .sectionheader, .subsubsection .sectionheader" );

sectionheaders.prepend( "<span class=\"button contenttoggle\"><a>" + "-" + "</a></span>" );
sectionheaders.parent().addClass( "visible" );

var buttons = $( "#" + reportId + " .button.contenttoggle" );

Expand Down Expand Up @@ -826,9 +845,9 @@ function reloadStylesheets() {
} );

var toggleDefaultState = function( animate ) {
toggleAllContents( animate, ToggleMode.HIDE );
toggleContents( $( "#overview_" + reportId + ", #summary_" + reportId ), animate );
toggleContents( $( "#results_" + reportId ), animate );
toggleAllContents( animate, ToggleMode.INITIALIZE );
//toggleContents( $( "#overview_" + reportId + ", #summary_" + reportId ), animate );
//toggleContents( $( "#results_" + reportId ), animate );
};

toggleDefaultState( false );
Expand Down
2 changes: 1 addition & 1 deletion Nozzle.R1/inst/js/nozzle.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Nozzle.R1/man/Nozzle.R1-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
}
\details{
\tabular{ll}{ Package: \tab Nozzle.R1\cr Type: \tab
Package\cr Version: \tab 1.3-0\cr Date: \tab
2013-06-23\cr License: \tab LGPL (>= 2)\cr LazyLoad: \tab
Package\cr Version: \tab 1.4-0\cr Date: \tab
2014-07-24\cr License: \tab LGPL (>= 2)\cr LazyLoad: \tab
yes\cr }

Nozzle was designed to facilitate summarization and rapid
Expand Down
5 changes: 4 additions & 1 deletion Nozzle.R1/man/newSection.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
\title{Create a new section element.}
\usage{
newSection(..., class = "", exportId = NULL,
protection = PROTECTION.PUBLIC)
protection = PROTECTION.PUBLIC, expanded = FALSE)
}
\arguments{
\item{...}{Strings that will be concatenated to form the
Expand All @@ -19,6 +19,9 @@

\item{protection}{Procection level. One of
PROTECTION.PUBLIC, PROTECTION.GROUP, PROTECTION.PRIVATE.}

\item{expanded}{Whether the section should expanded by
default or not.}
}
\value{
New element.
Expand Down
6 changes: 5 additions & 1 deletion Nozzle.R1/man/newSubSection.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
\title{Create a new subsection element.}
\usage{
newSubSection(..., exportId = NULL,
protection = PROTECTION.PUBLIC)
protection = PROTECTION.PUBLIC, expanded = FALSE)
}
\arguments{
\item{...}{Strings that will be concatenated to form the
Expand All @@ -15,6 +15,10 @@

\item{protection}{Procection level. One of
PROTECTION.PUBLIC, PROTECTION.GROUP, PROTECTION.PRIVATE.}

\item{expanded}{Whether the section should expanded by
default or not. This will not affect the state of parent
sections.}
}
\value{
New element.
Expand Down
6 changes: 3 additions & 3 deletions examples/demo.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ report2 <- setPreviousReport( report2, "nozzle1.html", "Demo 1" );
report2 <- addTo( report2, addTo( newSection( "My Introduction" ), newParagraph( "Hello World! This is a paragraph of text!" ) ) );
report2 <- addTo( report2, addTo( newSection( "My Methods" ), method2 ) );

report2 <- addTo( report2, addTo( newSection( "My Results", class="results" ),
report2 <- addTo( report2, addTo( newSection( "My Results", class="results", expanded=TRUE ),
addTo( newSubSection( "Nozzle Figure" ), figure1, figure2 ),
addTo( newSubSection( "Nozzle Table" ), table1, table4, table3, table5 ),
addTo( newSubSection( "Nozzle Text" ), paragraph1, list, paragraph2, paragraphPublic,
addTo( newSubSection( "Nozzle Text", expanded=TRUE ), paragraph1, list, paragraph2, paragraphPublic,
paragraphGroup, paragraphPrivate ),
addTo( addTo( newSubSection( "Nozzle Results" ), newParagraph( "A result: ", asSummary( result4 ), ", yay!" ) ) ) ) );

Expand Down Expand Up @@ -367,7 +367,7 @@ writeReport( report1, filename="reports/nozzle1_private", level=PROTECTION.PRIVA

# Examples for Developers
# write a "debug" development version that uses external JS or external CSS for rapid development
#writeReport( report1, filename="reports/nozzle1_debug", debug=TRUE, level=PROTECTION.PRIVATE,
# writeReport( report1, filename="reports/nozzle1_debug", debug=TRUE, level=PROTECTION.PRIVATE,
# debugJavaScript="/Users/nils/Projects/Nozzle/Nozzle.R1/inst/js/nozzle.js",
# debugCss="/Users/nils/Projects/Nozzle/Nozzle.R1/inst/css/nozzle.css" );

Expand Down

0 comments on commit 6482b06

Please sign in to comment.