Skip to content
Browse files

Merge branch 'release'

  • Loading branch information...
2 parents 24913a1 + 543ca6d commit d91919c23c454765459c64409ce71d0dd0cad98d @mbostock mbostock committed Oct 11, 2011
View
2 lib/cube/client/cube.js
@@ -1 +1,3 @@
cube = {version: "0.0.1"};
+
+var cube_time = d3.time.format.iso;
View
58 lib/cube/client/piece-area.js
@@ -18,28 +18,15 @@ cube.piece.type.area = function(board) {
var query = div.append("textarea")
.attr("class", "query")
- .style("margin-left", "4px")
- .style("height", "20px")
- .style("border-radius", "4px")
- .style("border", "solid 1px #ccc")
- .style("resize", "none")
.attr("placeholder", "query expression…")
.on("keyup.area", querychange)
.on("focus.area", area.focus)
.on("blur.area", area.blur);
var time = div.append("div")
.attr("class", "time")
- .style("margin-top", "1px")
- .style("margin-left", "4px")
- .style("line-height", "20px")
.text("Time Range:")
.append("select")
- .style("margin-right", "4px")
- .style("float", "right")
- .style("height", "20px")
- .style("border-radius", "4px")
- .style("border", "solid 1px #ccc")
.on("change.area", area.edit)
.on("focus.area", area.focus)
.on("blur.area", area.blur);
@@ -58,19 +45,20 @@ cube.piece.type.area = function(board) {
.attr("value", cube_piece_areaValue)
.text(function(d) { return d.description; });
} else {
- var m = [6, 40, 14, 10],
+ var m = [6, 40, 14, 10], // top, right, bottom, left margins
socket;
var svg = div.append("svg:svg");
var x = d3.time.scale(),
y = d3.scale.linear(),
- xAxis = d3.svg.axis().scale(x).tickSubdivide(true),
+ xAxis = d3.svg.axis().scale(x).orient("bottom").tickSubdivide(true),
yAxis = d3.svg.axis().scale(y).orient("right");
var a = d3.svg.area()
.interpolate("step-after")
.x(function(d) { return x(d.time); })
+ .y0(function(d) { return y(0); })
.y1(function(d) { return y(d.value); });
var l = d3.svg.line()
@@ -107,9 +95,10 @@ cube.piece.type.area = function(board) {
x.range([0, w]);
y.range([h, 0]);
- xAxis.ticks(w / 80).tickSize(-h);
- yAxis.ticks(h / 25).tickSize(-w);
- a.y0(h);
+
+ // Adjust the ticks based on the current chart dimensions.
+ xAxis.ticks(w / 80).tickSize(-h, 0);
+ yAxis.ticks(h / 25).tickSize(-w, 0);
transition.select("svg")
.attr("width", w + m[1] + m[3])
@@ -120,7 +109,9 @@ cube.piece.type.area = function(board) {
transition.select(".x.axis")
.attr("transform", "translate(0," + h + ")")
- .call(xAxis);
+ .call(xAxis)
+ .select("path")
+ .attr("transform", "translate(0," + (y(0) - h) + ")");
transition.select(".y.axis")
.attr("transform", "translate(" + w + ",0)")
@@ -133,9 +124,19 @@ cube.piece.type.area = function(board) {
function redraw() {
if (data.length > 1) data[data.length - 1].value = data[data.length - 2].value;
- y.domain([0, d3.max(data, cube_piece_areaValue) || 1]).nice();
+
+ var z = board.squareSize(),
+ h = area.size()[1] * z - m[0] - m[2],
+ min = d3.min(data, cube_piece_areaValue),
+ max = d3.max(data, cube_piece_areaValue);
+
+ if ((min < 0) && (max < 0)) max = 0;
+ else if ((min > 0) && (max > 0)) min = 0;
+ y.domain([min, max]).nice();
+
div.select(".area").attr("d", a(data));
- div.select(".y.axis").call(yAxis);
+ div.select(".y.axis").call(yAxis.tickFormat(cube_piece_format(y.domain())));
+ div.select(".x.axis").call(xAxis).select("path").attr("transform", "translate(0," + (y(0) - h) + ")");
div.select(".line").attr("d", l(data));
return true;
}
@@ -186,8 +187,8 @@ cube.piece.type.area = function(board) {
timeout = setTimeout(function() {
socket.send(JSON.stringify({
expression: json.query,
- start: t0,
- stop: t1,
+ start: cube_time(t0),
+ stop: cube_time(t1),
step: dt1
}));
timeout = setTimeout(function() {
@@ -200,7 +201,7 @@ cube.piece.type.area = function(board) {
// TODO compute contiguous segments on the fly
function store(message) {
var d = JSON.parse(message.data),
- i = d3.bisectLeft(data.map(cube_piece_areaTime), d.time = new Date(d.time));
+ i = d3.bisectLeft(data.map(cube_piece_areaTime), d.time = cube_time.parse(d.time));
if (i < 0 || data[i].time - d.time) {
if (d.value != null) {
data.splice(i, 0, d);
@@ -231,3 +232,12 @@ function cube_piece_areaTime(d) {
function cube_piece_areaValue(d) {
return d.value;
}
+
+var cube_piece_formatNumber = d3.format(".2r");
+
+function cube_piece_format(domain) {
+ var prefix = d3.formatPrefix(Math.max(-domain[0], domain[1]), 2);
+ return function(value) {
+ return cube_piece_formatNumber(value * prefix.scale) + prefix.symbol;
+ };
+}
View
22 lib/cube/client/piece-sum.js
@@ -2,7 +2,7 @@ cube.piece.type.sum = function(board) {
var timeout,
socket,
data = 0,
- format = d3.format(",.0f");
+ format = d3.format(".2s");
var sum = cube.piece(board)
.on("size", resize)
@@ -19,28 +19,15 @@ cube.piece.type.sum = function(board) {
var query = div.append("textarea")
.attr("class", "query")
- .style("margin-left", "4px")
- .style("height", "20px")
- .style("border-radius", "4px")
- .style("border", "solid 1px #ccc")
- .style("resize", "none")
.attr("placeholder", "query expression…")
.on("keyup.sum", querychange)
.on("focus.sum", sum.focus)
.on("blur.sum", sum.blur);
var time = div.append("div")
.attr("class", "time")
- .style("margin-top", "1px")
- .style("margin-left", "4px")
- .style("line-height", "20px")
.text("Time Range:")
.append("select")
- .style("margin-right", "4px")
- .style("float", "right")
- .style("height", "20px")
- .style("border-radius", "4px")
- .style("border", "solid 1px #ccc")
.on("change.sum", sum.edit)
.on("focus.sum", sum.focus)
.on("blur.sum", sum.blur);
@@ -58,9 +45,6 @@ cube.piece.type.sum = function(board) {
.property("selected", function(d, i) { return i == 1; })
.attr("value", cube_piece_areaValue)
.text(function(d) { return d.description; });
- } else {
- div
- .style("text-align", "right");
}
function resize() {
@@ -120,8 +104,8 @@ cube.piece.type.sum = function(board) {
function load() {
socket.send(JSON.stringify({
expression: json.query,
- start: t0,
- stop: t1,
+ start: cube_time(t0),
+ stop: cube_time(t1),
step: dt
}));
timeout = setTimeout(function() {
View
8 lib/cube/client/piece-text.js
@@ -16,18 +16,10 @@ cube.piece.type.text = function(board) {
var content = div.append("textarea")
.attr("class", "content")
- .style("margin-left", "4px")
- .style("height", "20px")
- .style("border-radius", "4px")
- .style("border", "solid 1px #ccc")
- .style("resize", "none")
.attr("placeholder", "text content…")
.on("keyup.text", textchange)
.on("focus.text", text.focus)
.on("blur.text", text.blur);
- } else {
- div
- .style("text-align", "right");
}
function resize() {
View
40 lib/cube/client/piece.css
@@ -29,6 +29,32 @@
margin: 4px;
}
+.piece textarea {
+ margin-left: 4px;
+ height: 20px;
+ border-radius: 4px;
+ border: solid 1px #ccc;
+ resize: none;
+}
+
+.piece .time {
+ margin-top: 1px;
+ margin-left: 4px;
+ line-height: 20px;
+}
+
+.piece select {
+ margin-right: 4px;
+ float: right;
+ height: 20px;
+ border-radius: 4px;
+ border: solid 1px #ccc;
+}
+
+.view .piece.sum, .view .piece.text {
+ text-align: right;
+}
+
.resize {
position: absolute;
padding: 6px;
@@ -95,8 +121,16 @@
stroke: #666;
}
+.axis {
+ shape-rendering: crispEdges;
+}
+
.axis .domain {
- display: none;
+ fill: none;
+}
+
+.x.axis .domain {
+ stroke: #000;
}
.x.axis line {
@@ -110,7 +144,3 @@
.y.axis line {
stroke: #eee;
}
-
-.y.axis g:first-child {
- display: none;
-}
View
2 lib/cube/index.js
@@ -1,4 +1,4 @@
-exports.version = "0.0.8";
+exports.version = "0.0.9";
exports.emitter = require("./server/emitter");
exports.server = require("./server/server");
exports.collector = require("./server/collector");
View
2 package.json
@@ -8,7 +8,7 @@
"repository": {"type": "git", "url": "http://github.com/square/cube.git"},
"main": "./lib/cube",
"dependencies": {
- "d3": "2.3.4",
+ "d3": "2.4.2",
"mongodb": "0.9.6-15",
"pegjs": "0.6.2",
"vows": "0.5.11",

0 comments on commit d91919c

Please sign in to comment.
Something went wrong with that request. Please try again.