From 17539a5da4a2e70944ee0ecf639f86f395cb2ba4 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 29 Dec 2017 20:46:13 +0100 Subject: [PATCH] Repair missing pit stop dots --- js/diagrams.js | 45 ++++++++++++++++++++++++--------------------- js/processor.js | 1 + js/queries.js | 4 +--- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/js/diagrams.js b/js/diagrams.js index 7e307b3..a7fb42c 100644 --- a/js/diagrams.js +++ b/js/diagrams.js @@ -57,7 +57,7 @@ function createLineGraph(containerId, raceData){ y.domain([raceData.drivers.length, 1]); var enhancedLapData = processor.getEnhancedLapDataPerDriver(raceData); - console.log(["enhancedLapData", enhancedLapData]); + //console.log(["enhancedLapData", enhancedLapData]); // Adds all lines enhancedLapData.forEach((driverLapData, driverIndex) => { @@ -72,6 +72,28 @@ function createLineGraph(containerId, raceData){ .attr("stroke", getColorValue(driverIndex, enhancedLapData.length) ) .attr("d", lineDataDefinition); + driverLapData.laps.forEach((singleLap, singleLapIndex)=> { + //console.log(["driverLaps.forEach", singleLap, singleLapIndex]); + if(singleLap.pitStop){ + //Appends a circle for each datapoint + svg.selectAll(".pitstoppoint") + .data([singleLap]) + .enter().append("circle") // Uses the enter().append() method + .attr("class", "dot pitstopdot") // Assign a class for styling + .attr("data-line", driverLapData.driver.driverId) + .attr("data-opacitychange", 1) + .attr("data-highlighted", 0) + .attr("data-elemtype", elemTypes.pitstoppoint) + .attr("fill", getColorValue(driverIndex, enhancedLapData.length)) + .attr("cx", function(d, i) {return x(d.lap) }) + .attr("cy", function(d, i) { return y(d.position) }) + .attr("r", linePointSize * 1.2) + .on("click", handleClickOnPoint) + .on("mouseover", handleMouseOverLinePoint) + .on("mouseout", handleMouseOutLinePoint); + } + }); + //Appends a circle for each datapoint svg.selectAll(".linepoint") .data(driverLapData.laps) @@ -107,26 +129,7 @@ function createLineGraph(containerId, raceData){ .on("mouseout", handleMouseOutLinePoint) .style("opacity", 0); - driverLapData.laps.forEach((singleLap, singleLapIndex)=> { - if(singleLap.pitStop){ - //Appends a circle for each datapoint - svg.selectAll(".pitstoppoint") - .data([singleLap]) - .enter().append("circle") // Uses the enter().append() method - .attr("class", "dot pitstoppoint") // Assign a class for styling - .attr("data-line", driverLapData.driver.driverId) - .attr("data-opacitychange", 1) - .attr("data-highlighted", 0) - .attr("data-elemtype", elemTypes.pitstoppoint) - .attr("fill", getColorValue(driverIndex, enhancedLapData.length)) - .attr("cx", function(d, i) {return x(d.lap) }) - .attr("cy", function(d, i) { return y(d.position) }) - .attr("r", linePointSize * 1.2) - .on("click", handleClickOnPoint) - .on("mouseover", handleMouseOverLinePoint) - .on("mouseout", handleMouseOutLinePoint); - } - }); + // in case the driver ended the race too early, get the status why he quit /*TODO: Mouseover for Rectangle*/ diff --git a/js/processor.js b/js/processor.js index 56db0cb..35d411f 100644 --- a/js/processor.js +++ b/js/processor.js @@ -68,6 +68,7 @@ var processor = { lapData.laps.sort((o1,o2) => o1["lap"] - o2["lap"]); result.push(lapData); }); + return result; }, diff --git a/js/queries.js b/js/queries.js index 6d55f1f..ff3d82f 100644 --- a/js/queries.js +++ b/js/queries.js @@ -76,14 +76,12 @@ var queries = { var tempList = []; for(var key in rawData.pitStops){ - if(rawData.pitStops[key].raceId == raceId){ + if(rawData.pitStops[key].raceId == raceId) { tempList.push(rawData.pitStops[key]); } } - tempList.sort((o1,o2) => o1["stop"] - o2["stop"]); //var tempList = rawData.pitStops.filter(cur => cur.raceId == raceId); - return tempList; },