added time argument

This commit is contained in:
Barbara Borges Ribeiro
2016-03-21 21:53:34 +00:00
parent 2a35ba64f7
commit bdc6554ca8
3 changed files with 23 additions and 32 deletions

View File

@@ -41,12 +41,15 @@ writeReactLog <- function(file=stdout(), sessionToken = NULL) {
#' enabled, it's possible for any user of your app to see at least some
#' of the source code of your reactive expressions and observers.
#'
#' @param time A boolean that specifies whether or not to display the
#' time that each reactive.
#'
#' @export
showReactLog <- function() {
utils::browseURL(renderReactLog())
showReactLog <- function(time = TRUE) {
utils::browseURL(renderReactLog(time = as.logical(time)))
}
renderReactLog <- function(sessionToken = NULL) {
renderReactLog <- function(sessionToken = NULL, time) {
templateFile <- system.file('www/reactive-graph.html', package='shiny')
html <- paste(readLines(templateFile, warn=FALSE), collapse='\r\n')
tc <- textConnection(NULL, 'w')
@@ -55,6 +58,7 @@ renderReactLog <- function(sessionToken = NULL) {
cat('\n', file=tc)
flush(tc)
html <- sub('__DATA__', paste(textConnectionValue(tc), collapse='\r\n'), html, fixed=TRUE)
html <- sub('__TIME__', paste0('"', time, '"'), html, fixed=TRUE)
file <- tempfile(fileext = '.html')
writeLines(html, file)
return(file)

View File

@@ -994,8 +994,10 @@ var log = [
"time": 1449212781.0257
}
];
var time = true;
try {
log = __DATA__;
time = String(__TIME__).toLowerCase() === 'true';
} catch (e) {}
var nodes = {};
@@ -1046,31 +1048,6 @@ function getTargetCoords(node) {
}
}
// this is not actually being called anywhere...
// function multilineTextNode(node) {
// var MAX_LINES = 6;
// var fade = false;
// var el = d3.select(this);
// var lines = el.text().split('\n');
// if (lines.length > MAX_LINES) {
// lines.splice(MAX_LINES);
// fade = true;
// }
// el.text('');
// var tspan = el.selectAll('.tspanLabel').data(lines);
// tspan.enter().append('tspan');
// tspan
// .attr('x', 8)
// .attr('dy', function(line, i) { return i > 0 ? '1em' : 0})
// .attr('opacity', function(line, i) {
// if (!fade)
// return 1;
// return Math.min(1, (MAX_LINES - i) * 0.25 - 0.15);
// })
// .classed('tspanLabel', true)
// .text(function(line) { return line; });
// }
function update() {
force.size([document.documentElement.clientWidth / 4,
document.documentElement.clientHeight / 4]);
@@ -1207,7 +1184,7 @@ function createNodeWithUndo(data) {
label: data.label,
type: data.type,
hide: data.hide,
timeLabel: data.timeLabel //////////////////// !!!!!!!!!!!! ////////////
timeLabel: data.timeLabel
};
nodes[data.id] = node;
pushUndo(function() {
@@ -1318,7 +1295,12 @@ var callbacks = {
dep: function(data) {
var dependsOn = nodes[data.dependsOn];
if (!dependsOn) {
createNodeWithUndo({id: data.dependsOn, label: data.dependsOn, type: 'value', timeLabel: ''});
createNodeWithUndo({
id: data.dependsOn,
label: data.dependsOn,
type: 'value',
timeLabel: ''
});
dependsOn = nodes[data.dependsOn];
}
if (dependsOn.hide) {
@@ -1400,7 +1382,8 @@ var callbacks = {
var node = nodes[data.id];
node.running = false;
var timeElapsed = (parseFloat(data.time) - parseFloat(node.start)) * 1000
node.timeLabel = 'time elapsed: ' + (Math.round(timeElapsed * 1000) / 1000) + ' ms';
var timeLabel = 'time elapsed: ' + (Math.round(timeElapsed * 1000) / 1000) + ' ms';
node.timeLabel = time ? timeLabel : '';
pushUndo(function() {
node.running = true;
node.timeLabel = ''

View File

@@ -4,7 +4,11 @@
\alias{showReactLog}
\title{Reactive Log Visualizer}
\usage{
showReactLog()
showReactLog(time = TRUE)
}
\arguments{
\item{time}{A boolean that specifies whether or not to display the
time that each reactive.}
}
\description{
Provides an interactive browser-based tool for visualizing reactive