diff --git a/css/main.css b/css/main.css
index 0a6dd99..a42e659 100644
--- a/css/main.css
+++ b/css/main.css
@@ -15,6 +15,14 @@ body {
/*border: 1px solid grey;*/
}
+#courseSelection li.hover {
+ background-color: #e2eaff;
+}
+
+#courseSelection li.selected {
+ border-color: #aaaaff;
+}
+
/* This container will allow scaling svg, so we don't need to care about it in d3.js */
.svg-container {
display: inline-block;
diff --git a/index.html b/index.html
index f846861..c153711 100644
--- a/index.html
+++ b/index.html
@@ -76,7 +76,10 @@
-
+
+
+
+
+
+
+
diff --git a/js/main.js b/js/main.js
index 19358aa..d2b7a0c 100644
--- a/js/main.js
+++ b/js/main.js
@@ -44,8 +44,9 @@ preprocessor.load(function(data) {
yearSelector.change(function(event) {
var selectedYear = $(event.target).val();
slyelement.curRaces = processor.getRacesByYear(selectedYear);
+ // Empty the course selector
$("#courseSelection").empty();
- // Add all the races to the selector
+ // ... and fill it with fresh races to choose from
for(var race in slyelement.curRaces) {
var raceD = slyelement.curRaces[race];
$("#courseSelection").append("" +
@@ -54,15 +55,35 @@ preprocessor.load(function(data) {
$("#courseSelection li").click(function(event) {
var raceI = event.currentTarget.attributes.data.value;
- if(slyelement.curRaceId == raceI){ return; }
+ // Internal check if element was already selected
+ if(slyelement.curRaceId == raceI){ return true; }
slyelement.curRaceId = raceI;
+ // Clear previously selected courses
+ $("#courseSelection .selected").removeClass("selected");
+ // Mark selected course
+ $(event.currentTarget).addClass("selected");
+ // Fetch race data
var rdata = slyelement.curRaces.filter(r => r.raceInfo.raceId == raceI)[0];
+ // Put information about race into race info box
+ $("#race-infobox").html(renderRaceInfoBox(rdata)); // See util.js
+ // Put information about drivers into driver info box
+ $("#driver-infobox").html(renderDriverInfoBox(rdata)); // See util.js
+ // Hand off to diagram rendering
$("#lineGraphBox").empty();
createLineGraph("#lineGraphBox", rdata);
});
slyelement.obj.reload();
}
+ // Refresh carousell after building the selector
slyelement.obj.reload();
+ // Register hover event
+ $("#courseSelection li").hover(function(event){
+ // handlerIn
+ $(event.currentTarget).addClass("hover");
+ }, function(event) {
+ // handlerOut
+ $(event.currentTarget).removeClass("hover");
+ });
// TODO: Now add all the images without disturbing the user
for(var race in slyelement.curRaces) {
@@ -107,4 +128,6 @@ preprocessor.load(function(data) {
// Select most recent year by default
$("#seasonByYearSelector").val($("#seasonByYearSelector option").first().val()).change();
+ // Enable tooltips
+ $('[data-toggle="tooltip"]').tooltip()
});
diff --git a/js/util.js b/js/util.js
index f8161c8..ed03079 100644
--- a/js/util.js
+++ b/js/util.js
@@ -147,3 +147,35 @@ function getImageFromWikipedia(data,pageName,imagesize,callback){
}
});
};
+
+function renderRaceInfoBox(race) {
+ var raceInfo = race.raceInfo;
+ var circuit = preprocessor.getResults().circuits[raceInfo.circuitId];
+ //console.log(raceInfo);
+ var content = "";
+
+ content = ""+raceInfo.name+"
";
+ content += ""+circuit.name+" ("+circuit.location+", "+circuit.country+")
";
+ content += ""+raceInfo.date.toLocaleDateString("de-DE")+"
"
+ content += "";
+ content += "
See Race on Wikipedia ";
+ content += "
See Circuit on Wikipedia";
+ content += "
";
+ return content;
+}
+
+function renderDriverInfoBox(race) {
+ var raceInfo = race.raceInfo;
+ var circuit = preprocessor.getResults().circuits[raceInfo.circuitId];
+ console.log(raceInfo);
+ var content = "";
+
+ content = ""+raceInfo.name+"
";
+ content += ""+circuit.name+" ("+circuit.location+", "+circuit.country+")
";
+ content += ""+raceInfo.date.toLocaleDateString("de-DE")+"
"
+ content += "";
+ content += "
See Race on Wikipedia ";
+ content += "
See Circuit on Wikipedia";
+ content += "
";
+ return content;
+}