Merge pull request #2 from F1Vis/Init_Axis

Added Pitstoppoints
This commit is contained in:
Flo 2017-12-13 00:13:07 +01:00 committed by GitHub
commit 75330865ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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

@ -29,7 +29,7 @@ var processor = {
//Gets the position of Driver with driverid in specific lap
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){
return lapEntryWithDrivId[0].position;
}else{

View File

@ -11,7 +11,7 @@ var queries = {
*/
getDriversByNationality: function() {
var rawData = preprocessor.getResults();
// Extract interesting data from raw data.
var nationalities = {};
for(var i in rawData.drivers) {
@ -100,7 +100,7 @@ var queries = {
myMap.set(lapNum,data);
}
var dt = myMap.get(lapNum);
dt.push(d);
dt.push(d);
myMap.set(lapNum,dt);
});
@ -111,7 +111,7 @@ var queries = {
getRaceById: function(raceId){
var rawData = preprocessor.getResults();
return rawData.races[raceId];
return rawData.races[raceId];
},
getRacesByYear: function(year){
@ -126,7 +126,7 @@ var queries = {
races.sort((o1,o2) => o1["round"] - o2["round"]);
return races;
},
getQualifingDataByRaceId: function(raceId) {

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;