Permalink
Browse files

More tweaking

  • Loading branch information...
1 parent e0d2b86 commit 6d38336c2366465bddfd2dbd95205c0594bd8531 @hadley committed Dec 6, 2012
Showing with 57 additions and 62 deletions.
  1. +2 −1 R/server.r
  2. BIN data/nesting.rda
  3. BIN data/roxygen3.rda
  4. +33 −21 inst/d3/profr.coffee
  5. +22 −40 inst/d3/profr.js
View
@@ -34,7 +34,7 @@ profr_server <- function(base = getOption("profr.path"), appname = "profr") {
}
base <- normalizePath(base)
- server <<- Rhttpd$new()
+ server <- Rhttpd$new()
server$add(make_router(base), appname)
port <- tools:::httpdPort
@@ -43,6 +43,7 @@ profr_server <- function(base = getOption("profr.path"), appname = "profr") {
server$start(quiet = TRUE)
}
+ server <<- server
invisible(server)
}
View
Binary file not shown.
View
Binary file not shown.
View
@@ -3,6 +3,7 @@
# * use g for better semantic grouping
# * better transitions from http://mbostock.github.com/d3/talk/20111018/partition.html
# * approximation for text width
+# * translate/scale entire viewport instead of individuals?
margin = {top: 10, right: 10, bottom: 10, left: 10}
line_height = 25
@@ -20,7 +21,10 @@ subset =
x_max: Infinity
y_min: 1
-width = (d) -> x_scale(d.end) - x_scale(d.start)
+width = (d) ->
+ left = Math.max(0, x_scale(d.end))
+ right = Math.min(x_scale(d.start), subset.x_max)
+ left - right
id = (d) -> [d.start, d.level]
# Ensure svg fills entire window (with round number of lines),
@@ -36,13 +40,14 @@ rescale = ->
.attr("width", win_width)
.attr("height", win_height)
- shown = (el for el in data when (el.level - subset.x_min) < lines and el.start >= subset.x_min and
- el.end <= subset.x_max and el.level >= subset.y_min)
+ if (subset.x_max == Infinity)
+ subset.x_max = d3.max(data, (d) -> d.end)
+
x_scale = d3.scale.linear()
- .range([0, win_width])
- .domain([subset.x_min, d3.max(shown, (d) -> d.end)])
+ .rangeRound([0, win_width])
+ .domain([subset.x_min, subset.x_max])
y_scale = d3.scale.linear()
- .range([0, win_height])
+ .rangeRound([0, win_height])
.domain([subset.y_min - 1, lines + subset.y_min])
# -1 so there's enough room for the info bar
@@ -80,33 +85,40 @@ redraw = ->
rescale()
# Draw box for each function
- rect = svg.selectAll("rect").data(shown, id)
+ g = svg.selectAll("g").data(data, id).enter()
+ .append("g")
+
+ svg.selectAll("g").data(data, id)
+ .transition(750)
+ .attr("transform", (d) ->
+ "translate(" + x_scale(d.start) + "," + y_scale(d.level) + ")")
- rect.enter().append("rect")
+ g.append("rect")
.on("mouseover", (d) -> mouse_over(d))
.on("mouseout", (d) -> mouse_out(d))
.on("click", ((d) -> click(d)), false)
+ .attr("height", (d) -> line_height + "px")
+
+ svg.selectAll("rect").data(data, id)
+ .transition(750)
+ .attr("width", width)
- rect.exit().remove()
+ # rect.exit().remove()
- rect
- .transition()
- .attr("x", (d) -> x_scale(d.start))
- .attr("y", (d) -> y_scale(d.level))
- .attr("height", (d) -> y_scale(d.level + 1) - y_scale(d.level))
- .attr("width", (d) -> x_scale(d.end) - x_scale(d.start))
+ # rect
+ # .transition()
# Label functions, if space
- text = svg.selectAll("text").data(shown, id)
+ # text = svg.selectAll("text").data(shown, id)
- text.enter().append("text")
+ text = g.append("text")
.text((d) -> d.f)
+ .attr("y", "18px")
+ .attr("x", "5px")
- text.exit().remove()
+ # text.exit().remove()
- text.transition()
- .attr("x", (d) -> x_scale(d.start) + 4)
- .attr("y", (d) -> y_scale(d.level + 0.75))
+ # text.transition()
text
.each((d) -> this.__width = this.getBBox().width)
View
@@ -30,37 +30,30 @@
};
width = function(d) {
- return x_scale(d.end) - x_scale(d.start);
+ var left, right;
+ left = Math.max(0, x_scale(d.end));
+ right = Math.min(x_scale(d.start), subset.x_max);
+ return left - right;
};
id = function(d) {
return [d.start, d.level];
};
rescale = function() {
- var el, height, lines, win_height, win_width;
+ var height, lines, win_height, win_width;
win_width = window.innerWidth - margin.left - margin.right;
win_height = window.innerHeight - margin.top - margin.bottom;
lines = win_height / line_height << 0;
height = lines * line_height;
svg.attr("width", win_width).attr("height", win_height);
- shown = (function() {
- var _i, _len, _results;
- _results = [];
- for (_i = 0, _len = data.length; _i < _len; _i++) {
- el = data[_i];
- if ((el.level - subset.x_min) < lines && el.start >= subset.x_min && el.end <= subset.x_max && el.level >= subset.y_min) {
- _results.push(el);
- }
- }
- return _results;
- })();
- x_scale = d3.scale.linear().range([0, win_width]).domain([
- subset.x_min, d3.max(shown, function(d) {
+ if (subset.x_max === Infinity) {
+ subset.x_max = d3.max(data, function(d) {
return d.end;
- })
- ]);
- return y_scale = d3.scale.linear().range([0, win_height]).domain([subset.y_min - 1, lines + subset.y_min]);
+ });
+ }
+ x_scale = d3.scale.linear().rangeRound([0, win_width]).domain([subset.x_min, subset.x_max]);
+ return y_scale = d3.scale.linear().rangeRound([0, win_height]).domain([subset.y_min - 1, lines + subset.y_min]);
};
mouse_over = function(rec) {
@@ -117,36 +110,25 @@
});
redraw = function() {
- var rect, text;
+ var g, text;
rescale();
- rect = svg.selectAll("rect").data(shown, id);
- rect.enter().append("rect").on("mouseover", function(d) {
+ g = svg.selectAll("g").data(data, id).enter().append("g");
+ svg.selectAll("g").data(data, id).transition(750).attr("transform", function(d) {
+ return "translate(" + x_scale(d.start) + "," + y_scale(d.level) + ")";
+ });
+ g.append("rect").on("mouseover", function(d) {
return mouse_over(d);
}).on("mouseout", function(d) {
return mouse_out(d);
}).on("click", (function(d) {
return click(d);
- }), false);
- rect.exit().remove();
- rect.transition().attr("x", function(d) {
- return x_scale(d.start);
- }).attr("y", function(d) {
- return y_scale(d.level);
- }).attr("height", function(d) {
- return y_scale(d.level + 1) - y_scale(d.level);
- }).attr("width", function(d) {
- return x_scale(d.end) - x_scale(d.start);
+ }), false).attr("height", function(d) {
+ return line_height + "px";
});
- text = svg.selectAll("text").data(shown, id);
- text.enter().append("text").text(function(d) {
+ svg.selectAll("rect").data(data, id).transition(750).attr("width", width);
+ text = g.append("text").text(function(d) {
return d.f;
- });
- text.exit().remove();
- text.transition().attr("x", function(d) {
- return x_scale(d.start) + 4;
- }).attr("y", function(d) {
- return y_scale(d.level + 0.75);
- });
+ }).attr("y", "18px").attr("x", "5px");
return text.each(function(d) {
return this.__width = this.getBBox().width;
}).style("opacity", function(d) {

0 comments on commit 6d38336

Please sign in to comment.