Skip to content

Instantly share code, notes, and snippets.

@cesarpachon
Forked from refactornator/text.js
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cesarpachon/9a8925e0ec71eafb9993 to your computer and use it in GitHub Desktop.
Save cesarpachon/9a8925e0ec71eafb9993 to your computer and use it in GitHub Desktop.
// Set up initial code for visualization
var svg = d3.select(controller.element).append("svg")
.attr("width", "100%").attr("height", "100%")
.append("g")
.attr("transform", "translate(10,10)");
// This function receives a JS Array of JS Objects
// representing the current state of your data.
controller.update = function (data) {
// Join new data with old elements, if any.
var text = svg.selectAll("text")
.data(data, function (d) {
return d.group;
});
// Update old elements as needed
text.attr("class", "update");
// Create new elements as needed.
text.enter().append("text")
.attr("class", "enter")
.attr("y", function(d, i) { return i * 15; })
.attr("dy", ".35em");
text.text(function(d) {
return d.group + " - " + d.current.count;
});
// EXIT
// Remove old elements as needed.
text.exit().remove();
};
controller.onAdd = function(addedObject) { };
controller.onChange = function(changedObject) { };
controller.onRemove = function(removedObject) { };
// Provide any additional code to tear down the visualization.
// By default children of controller.element are being removed.
controller.clear = function () { };
controller.resize = function(newWidth, newHeight) {
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment