Skip to content

Instantly share code, notes, and snippets.

@refactornator
Created August 14, 2013 14:48
Show Gist options
  • Save refactornator/6231760 to your computer and use it in GitHub Desktop.
Save refactornator/6231760 to your computer and use it in GitHub Desktop.
Zoomdata sample visualization illustrating the JS client API.
// 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