@ -57,36 +57,35 @@ var logRun = function(runObject, callback){
//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
vargenerateCircles=function(error,data){
//bind circles with data
varcircles=d3.select('#points').selectAll('circle')//ghost selction of circles
.data(data,function(d){
//match data based on d.id, not index
returnd.id
});
//add extra circles if there is extra data
circles
.enter()//for all data that has not yet been mapped...
.append('circle')//create a circle
.attr('cx',function(datum,index){
//convert date value into pixel value and set it to cx
returnxScale(newDate(datum.date));
})
.attr('cy',function(datum,index){
//convert distance datum into pixel value and set it to cy
returnyScale(datum.distance);
});
//if any circles remain that don't match data, remove them
circles.exit().remove();
//attach event handlers after circle creation
attachDragHandlers();//attach drag handlers
attachDeleteHandlers();//attach delete handlers
}
varrender=function(){
d3.json('/runs',function(error,data){//get all run data
//bind circles with data
varcircles=d3.select('#points').selectAll('circle')//ghost selction of circles
.data(data,function(d){
//match data based on d.id, not index
returnd.id
});
//add extra circles if there is extra data
circles
.enter()//for all data that has not yet been mapped...
.append('circle')//create a circle
.attr('cx',function(datum,index){
//convert date value into pixel value and set it to cx
returnxScale(newDate(datum.date));
})
.attr('cy',function(datum,index){
//convert distance datum into pixel value and set it to cy
returnyScale(datum.distance);
});
//if any circles remain that don't match data, remove them
circles.exit().remove();
//attach event handlers after circle creation
attachDragHandlers();//attach drag handlers
attachDeleteHandlers();//attach delete handlers
});
d3.json('/runs',generateCircles);
};
render();//render on page load
//Attach click handler to circles
varattachDeleteHandlers=function(){
d3.selectAll('circle').on('click',function(d){
@ -133,19 +132,38 @@ var attachDragHandlers = function(){
d3.selectAll('circle').call(drag);
};
//create axes
varxAxis=d3.axisBottom(xScale);//create axis, not yet applied
varyAxis=d3.axisLeft(yScale);//create axis, not yet applied
d3.select('svg').append('g').attr('id','x-axis').attr('transform','translate(0,'+HEIGHT+')').call(xAxis);//apply xAxis, also, x axis must be moved to bottom of svg
d3.select('svg').append('g').attr('id','y-axis').call(yAxis);//y axis is good as it is, apply it
//callback for zooming
varzoomCallback=function(){
lastTransform=d3.event.transform;//save the transform for later inversion with clicks
d3.select('#points').attr("transform",d3.event.transform);//apply transform to g element containing circles
varxAxis=d3.axisBottom(xScale);//create axis, not yet applied
varyAxis=d3.axisLeft(yScale);//create axis, not yet applied
d3.select('svg').append('g').attr('id','x-axis').attr('transform','translate(0,'+HEIGHT+')').call(xAxis);//apply xAxis, also, x axis must be moved to bottom of svg
d3.select('svg').append('g').attr('id','y-axis').call(yAxis);//y axis is good as it is, apply it
//callback for zooming
varzoomCallback=function(){
lastTransform=d3.event.transform;//save the transform for later inversion with clicks
d3.select('#points').attr("transform",d3.event.transform);//apply transform to g element containing circles