Moved the Y-Axis text updating into an own function, added comment

This commit is contained in:
Maschell 2017-12-31 13:15:11 +01:00
parent 141c15bf7f
commit 855a5e6c96
1 changed files with 33 additions and 22 deletions

View File

@ -508,6 +508,7 @@ function createLineGraph(containerId, raceData){
var t = d3.event.transform;
x.domain(t.rescaleX(x2).domain());
updateElements();
//call the brush function
context.select(".brush").call(brush.move, x.range().map(t.invertX, t));
}
@ -521,14 +522,26 @@ function createLineGraph(containerId, raceData){
// Update xAxis
focus.select(".axis--x").call(xAxis);
updateYAxisText();
// Update gridlines
focus.select(".xAxisGridlines").call(xAxisGridlines);
}
function updateYAxisText(){
console.log("lol");
var xAxisValues = d3.extent(x.domain());
if(xAxisValues[1] > 1){
// Get the min/max lap.
var startLap = Math.floor(xAxisValues[0]);
var endLap = Math.floor(xAxisValues[1]);
// Redraw the left Y axis
focus.select(".axis--y-left").call(d3.axisLeft(y).ticks(raceData.drivers.length).tickFormat(function(d) {
return getDriverCodeFromPosAndLap(raceData, startLap, d) + " " + d;
}));
// Redraw the right Y axis
focus.select(".axis--y-right").call(
d3.axisRight(y)
.ticks(raceData.drivers.length)
@ -537,13 +550,11 @@ function createLineGraph(containerId, raceData){
if(getDriverCodeFromPosAndLap(raceData, endLap, d)){
driverCode = getDriverCodeFromPosAndLap(raceData, endLap, d);
}else{
driverCode = getDriverCodeFromPosAndLap(raceData, endLap - 1, d); // only if the driver has finished..
driverCode = getDriverCodeFromPosAndLap(raceData, endLap - 1, d); // TODO: only if the driver has finished..
}
return d + " " + driverCode ;
}));
}
// Update gridlines
focus.select(".xAxisGridlines").call(xAxisGridlines);
}
}