From 42924dc2c37e13a0614789a55040b7ba77b5cc8f Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 22 Dec 2017 12:53:46 +0100 Subject: [PATCH] Add some rough error handling to diagrams.js --- js/diagrams.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/js/diagrams.js b/js/diagrams.js index 0076e29..ff5d0b8 100644 --- a/js/diagrams.js +++ b/js/diagrams.js @@ -2,8 +2,18 @@ // https://bl.ocks.org/mbostock/3884955 function createLineGraph(containerId, raceData){ - console.log(raceData); + // Rough input validation + if(raceData.raceInfo === undefined) { + console.error(["Sorry, that raceData is empty. :-(", raceData]); + return; // early return to avoid errors + } else { + console.log(raceData); + } + var enhancedLapData = processor.getEnhancedLapDataPerDriver(raceData); + console.log(enhancedLapData); + + // Configuration var height = 720; var width = 1080; var linePointSize = 5; @@ -37,9 +47,6 @@ function createLineGraph(containerId, raceData){ x.domain([0, raceData.lapTimes.size]); y.domain([raceData.drivers.length, 1]); - var enhancedLapData = processor.getEnhancedLapDataPerDriver(raceData); - console.log(enhancedLapData); - // Adds all lines enhancedLapData.forEach((driverLapData, driverIndex) => { //console.log(driverLapData);