Skip to content
Browse files

Fixes related to d3.dispatch API change.

  • Loading branch information...
1 parent 1b8779e commit 70e9ee679acca4402244137b1ae7ddd48ea563f4 @mbostock mbostock committed
Showing with 31 additions and 42 deletions.
  1. +18 −24 lib/cube/client/board.js
  2. +12 −17 lib/cube/client/piece.js
  3. +1 −1 package.json
View
42 lib/cube/client/board.js
@@ -24,23 +24,22 @@ cube.board = function(url, id) {
d3.select(svg)
.attr("class", "board");
- event.size.add(resize);
- event.squareSize.add(resize);
- event.squareRadius.add(resize);
- event.padding.add(resize);
+ event.on("size.board", resize);
+ event.on("squareSize.board", resize);
+ event.on("squareRadius.board", resize);
+ event.on("padding.board", resize);
function message(message) {
var e = JSON.parse(message.data);
switch (e.type) {
case "view": {
- event.view.dispatch.call(board, e);
+ event.view.call(board, e);
break;
}
case "add": {
var piece = board.add(cube.piece.type[e.piece.type])
.fromJSON(e.piece)
- .off("move", add)
- .on("move", move);
+ .on("move.board", move);
d3.select(piece.node())
.style("opacity", 1e-6)
@@ -55,12 +54,12 @@ cube.board = function(url, id) {
pieces.some(function(piece) {
if (piece.id == e.piece.id) {
piece
- .off("move", move)
+ .on("move.board", null)
.transition(d3.transition().duration(500))
.fromJSON(e.piece);
// Renable events after transition starts.
- d3.timer(function() { piece.on("move", move); }, 250);
+ d3.timer(function() { piece.on("move.board", move); }, 250);
return true;
}
});
@@ -70,7 +69,7 @@ cube.board = function(url, id) {
pieces.some(function(piece) {
if (piece.id == e.piece.id) {
piece
- .off("move", move)
+ .on("move.board", null)
.transition(d3.transition().duration(500))
.size(e.piece.size)
.position(e.piece.position);
@@ -79,7 +78,7 @@ cube.board = function(url, id) {
svg.parentNode.appendChild(piece.node());
// Renable events after transition starts.
- d3.timer(function() { piece.on("move", move); }, 250);
+ d3.timer(function() { piece.on("move.board", move); }, 250);
return true;
}
});
@@ -125,7 +124,7 @@ cube.board = function(url, id) {
// A one-time listener to send an add event on mouseup.
function add() {
socket.send(JSON.stringify({type: "add", id: id, piece: this}));
- this.off("move", add).on("move", move);
+ this.on("move.board", move);
}
function move() {
@@ -153,50 +152,45 @@ cube.board = function(url, id) {
};
board.on = function(type, listener) {
- event[type].add(listener);
- return board;
- };
-
- board.off = function(type, listener) {
- event[type].remove(listener);
+ event.on(type, listener);
return board;
};
board.size = function(x) {
if (!arguments.length) return size;
- event.size.dispatch.call(board, size = x);
+ event.size.call(board, size = x);
return board;
};
board.squareSize = function(x) {
if (!arguments.length) return squareSize;
- event.squareSize.dispatch.call(board, squareSize = x);
+ event.squareSize.call(board, squareSize = x);
return board;
};
board.squareRadius = function(x) {
if (!arguments.length) return squareRadius;
- event.squareRadius.dispatch.call(board, squareRadius = x);
+ event.squareRadius.call(board, squareRadius = x);
return board;
};
board.padding = function(x) {
if (!arguments.length) return padding;
- event.padding.dispatch.call(board, padding = x);
+ event.padding.call(board, padding = x);
return board;
};
board.add = function(type) {
var piece = type(board);
piece.id = ++pieceId;
- piece.on("move", add).on("edit", edit);
+ piece.on("move.board", add).on("edit.board", edit);
svg.parentNode.appendChild(piece.node());
pieces.push(piece);
return piece;
};
board.remove = function(piece, silent) {
- piece.off("move", move).off("edit", edit);
+ piece.on("move.board", null).on("edit.board", null);
if (silent) {
d3.select(piece.node())
.style("opacity", 1)
View
29 lib/cube/client/piece.js
@@ -38,12 +38,12 @@ cube.piece = function(board) {
}
board
- .on("padding", resize)
- .on("squareSize", resize);
+ .on("padding.piece", resize)
+ .on("squareSize.piece", resize);
- event.position.add(resize);
- event.size.add(resize);
- event.deserialize.add(deserialize);
+ event.on("position.piece", resize);
+ event.on("size.piece", resize);
+ event.on("deserialize.piece", deserialize);
function resize() {
var squareSize = board.squareSize(),
@@ -76,18 +76,13 @@ cube.piece = function(board) {
};
piece.on = function(type, listener) {
- event[type].add(listener);
- return piece;
- };
-
- piece.off = function(type, listener) {
- event[type].remove(listener);
+ event.on(type, listener);
return piece;
};
piece.size = function(x) {
if (!arguments.length) return size;
- event.size.dispatch.call(piece, size = x);
+ event.size.call(piece, size = x);
return piece;
};
@@ -101,23 +96,23 @@ cube.piece = function(board) {
piece.position = function(x) {
if (!arguments.length) return position;
- event.position.dispatch.call(piece, position = x);
+ event.position.call(piece, position = x);
return piece;
};
piece.toJSON = function() {
var x = {id: piece.id, size: size, position: position};
- event.serialize.dispatch.call(piece, x);
+ event.serialize.call(piece, x);
return x;
};
piece.fromJSON = function(x) {
- event.deserialize.dispatch.call(piece, x);
+ event.deserialize.call(piece, x);
return piece;
};
piece.edit = function() {
- event.edit.dispatch.call(piece);
+ event.edit.call(piece);
return piece;
};
@@ -149,7 +144,7 @@ cube.piece = function(board) {
} else {
transition = x.select(function() { return div; });
d3.timer(function() {
- event.move.dispatch.call(piece);
+ event.move.call(piece);
return transition = selection;
});
}
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "cube",
- "version": "0.0.10",
+ "version": "0.0.11",
"description": "A system for time series visualization using MongoDB, Node and D3.",
"keywords": ["time series", "visualization"],
"homepage": "http://square.github.com/cube/",

0 comments on commit 70e9ee6

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