Added Pitstoppoints
This commit is contained in:
parent
8c97d8280f
commit
9fcee3e8cf
@ -56,4 +56,15 @@ function createLineGraph(containerId, raceData){
|
|||||||
svg.append("g")
|
svg.append("g")
|
||||||
.call(d3.axisRight(y))
|
.call(d3.axisRight(y))
|
||||||
.attr("transform", "translate( " + (width) + ", 0 )");
|
.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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,5 @@ preprocessor.load(function(data) {
|
|||||||
var seasons = preprocessor.getResults().seasons;
|
var seasons = preprocessor.getResults().seasons;
|
||||||
for(var year in seasons) yearSelector.append("<option>" + year + "</option>");
|
for(var year in seasons) yearSelector.append("<option>" + year + "</option>");
|
||||||
|
|
||||||
createLineGraph("#lineGraphBox", processor.getRace(1));
|
createLineGraph("#lineGraphBox", processor.getRace(864));
|
||||||
});
|
});
|
||||||
|
@ -29,7 +29,7 @@ var processor = {
|
|||||||
|
|
||||||
//Gets the position of Driver with driverid in specific lap
|
//Gets the position of Driver with driverid in specific lap
|
||||||
getPositionOfDriver: function(driver, lap, defaultReturn){
|
getPositionOfDriver: function(driver, lap, defaultReturn){
|
||||||
var lapEntryWithDrivId =lap.filter( drivLap => drivLap.driverId == driver.driverId );
|
var lapEntryWithDrivId = lap.filter( drivLap => drivLap.driverId == driver.driverId );
|
||||||
if(lapEntryWithDrivId.length > 0){
|
if(lapEntryWithDrivId.length > 0){
|
||||||
return lapEntryWithDrivId[0].position;
|
return lapEntryWithDrivId[0].position;
|
||||||
}else{
|
}else{
|
||||||
|
27
js/util.js
27
js/util.js
@ -49,7 +49,7 @@ function transformRaceDataToLineData(raceData){
|
|||||||
raceData.lapTimes.forEach((lap, lapIn) => {
|
raceData.lapTimes.forEach((lap, lapIn) => {
|
||||||
var drivPos = processor.getPositionOfDriver(driver, lap, raceData.drivers.length + 1 );
|
var drivPos = processor.getPositionOfDriver(driver, lap, raceData.drivers.length + 1 );
|
||||||
if( drivPos < 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);
|
lineData.splice(drivIn, 0, lapsOfDriverInLineDataFormat);
|
||||||
@ -57,11 +57,36 @@ function transformRaceDataToLineData(raceData){
|
|||||||
return lineData;
|
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){
|
function getPositionOfQualifying(raceData, driver){
|
||||||
var qualData = raceData.qualifying.filter( qualData => qualData.driverId == driver.driverId);
|
var qualData = raceData.qualifying.filter( qualData => qualData.driverId == driver.driverId);
|
||||||
return qualData[0].position;
|
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){
|
function getColorValue(index, all){
|
||||||
var r = 0;
|
var r = 0;
|
||||||
var g = 0;
|
var g = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user