Added Pitstoppoints

This commit is contained in:
sirsandmann 2017-12-13 00:12:11 +01:00
parent 8c97d8280f
commit 9fcee3e8cf
5 changed files with 43 additions and 7 deletions

View File

@ -56,4 +56,15 @@ function createLineGraph(containerId, raceData){
svg.append("g")
.call(d3.axisRight(y))
.attr("transform", "translate( " + (width) + ", 0 )");
console.log(transformPitStopDataToPointData(raceData));
// 12. Appends a circle for each datapoint
svg.selectAll(".dot")
.data(transformPitStopDataToPointData(raceData))
.enter().append("circle") // Uses the enter().append() method
.attr("class", "dot") // Assign a class for styling
.attr("cx", function(d, i) { return x(d.lap) })
.attr("cy", function(d) { return y(d.position) })
.attr("r", 5);
}

View File

@ -10,5 +10,5 @@ preprocessor.load(function(data) {
var seasons = preprocessor.getResults().seasons;
for(var year in seasons) yearSelector.append("<option>" + year + "</option>");
createLineGraph("#lineGraphBox", processor.getRace(1));
createLineGraph("#lineGraphBox", processor.getRace(864));
});

View File

@ -49,7 +49,7 @@ function transformRaceDataToLineData(raceData){
raceData.lapTimes.forEach((lap, lapIn) => {
var drivPos = processor.getPositionOfDriver(driver, lap, raceData.drivers.length + 1 );
if( drivPos < raceData.drivers.length + 1 ){
lapsOfDriverInLineDataFormat.push({ 'lap': lapIn, 'position': processor.getPositionOfDriver(driver, lap, raceData.drivers.length + 1 )});
lapsOfDriverInLineDataFormat.push({ 'lap': lapIn, 'position': processor.getPositionOfDriver(driver, lap, raceData.drivers.length + 1 ), 'driverId': driver.driverId});
}
});
lineData.splice(drivIn, 0, lapsOfDriverInLineDataFormat);
@ -57,11 +57,36 @@ function transformRaceDataToLineData(raceData){
return lineData;
}
function transformPitStopDataToPointData(raceData){
var pointData = [];
raceData.pitStops.forEach(pitStop => {
var driver = queries.getDriverById(pitStop.driverId);
var lap = raceData.lapTimes.get(pitStop.lap);
pointData.push({'position': processor.getPositionOfDriver(driver, lap , raceData.drivers.length + 1), "lap": pitStop.lap});
});
return pointData;
}
function getPositionOfQualifying(raceData, driver){
var qualData = raceData.qualifying.filter( qualData => qualData.driverId == driver.driverId);
return qualData[0].position;
}
// eigentlich war für TickData gedacht
function getDriverCodeAndPositionArray(raceData, lapNumber){
var posDriverCode = [];
if(lapNumber == 0){
raceData.qualifying.forEach(qualData => {
posDriverCode.push(getDriverCodeById(raceData, qualData.driverId) + " " + qualData.position)
});
}
return posDriverCode;
}
function getDriverCodeById(raceData,driverId){
return raceData.drivers.filter(driv=> driv.driverId == driverId)[0].code;
}
function getColorValue(index, all){
var r = 0;
var g = 0;