|
|
|
@ -57,8 +57,7 @@ var logRun = function(runObject, callback){
|
|
|
|
|
|
|
|
|
|
|
|
//Render circles
|
|
|
|
//Render circles
|
|
|
|
//var dateParser = d3.time.format("%Y-%m-%d %H:%M:%S.%L +00:00"); -- can use this if date format is not proper
|
|
|
|
//var dateParser = d3.time.format("%Y-%m-%d %H:%M:%S.%L +00:00"); -- can use this if date format is not proper
|
|
|
|
var render = function(){
|
|
|
|
var generateCircles = function(error, data){
|
|
|
|
d3.json('/runs', function(error, data){ //get all run data
|
|
|
|
|
|
|
|
//bind circles with data
|
|
|
|
//bind circles with data
|
|
|
|
var circles = d3.select('#points').selectAll('circle')//ghost selction of circles
|
|
|
|
var circles = d3.select('#points').selectAll('circle')//ghost selction of circles
|
|
|
|
.data(data, function(d){
|
|
|
|
.data(data, function(d){
|
|
|
|
@ -82,11 +81,11 @@ var render = function(){
|
|
|
|
//attach event handlers after circle creation
|
|
|
|
//attach event handlers after circle creation
|
|
|
|
attachDragHandlers(); //attach drag handlers
|
|
|
|
attachDragHandlers(); //attach drag handlers
|
|
|
|
attachDeleteHandlers(); //attach delete handlers
|
|
|
|
attachDeleteHandlers(); //attach delete handlers
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var render = function(){
|
|
|
|
|
|
|
|
d3.json('/runs', generateCircles);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
render(); //render on page load
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Attach click handler to circles
|
|
|
|
//Attach click handler to circles
|
|
|
|
var attachDeleteHandlers = function(){
|
|
|
|
var attachDeleteHandlers = function(){
|
|
|
|
d3.selectAll('circle').on('click', function(d){
|
|
|
|
d3.selectAll('circle').on('click', function(d){
|
|
|
|
@ -133,6 +132,22 @@ var attachDragHandlers = function(){
|
|
|
|
d3.selectAll('circle').call(drag);
|
|
|
|
d3.selectAll('circle').call(drag);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d3.json('/runs', function(error, data){
|
|
|
|
|
|
|
|
var distanceDomain = d3.extent(data, function(element){
|
|
|
|
|
|
|
|
return element.distance;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
var dateDomain = d3.extent(data, function(element){
|
|
|
|
|
|
|
|
return new Date(element.date);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(distanceDomain[0] !== undefined && distanceDomain[1] !== undefined){
|
|
|
|
|
|
|
|
yScale.domain(distanceDomain);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(dateDomain[0] !== undefined && dateDomain[1] !== undefined){
|
|
|
|
|
|
|
|
xScale.domain(dateDomain);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//create axes
|
|
|
|
//create axes
|
|
|
|
var xAxis = d3.axisBottom(xScale); //create axis, not yet applied
|
|
|
|
var xAxis = d3.axisBottom(xScale); //create axis, not yet applied
|
|
|
|
var yAxis = d3.axisLeft(yScale); //create axis, not yet applied
|
|
|
|
var yAxis = d3.axisLeft(yScale); //create axis, not yet applied
|
|
|
|
@ -149,3 +164,6 @@ var zoomCallback = function(){
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var zoom = d3.zoom().on('zoom', zoomCallback); //create zoom behavior
|
|
|
|
var zoom = d3.zoom().on('zoom', zoomCallback); //create zoom behavior
|
|
|
|
d3.select('svg').call(zoom); //apply zoom behavior to svg
|
|
|
|
d3.select('svg').call(zoom); //apply zoom behavior to svg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
generateCircles(null, data);
|
|
|
|
|
|
|
|
});
|
|
|
|
|