-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
132 lines (118 loc) · 3.92 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>
<title>Scatterplot Graph using D3 v.3</title>
<link href="https://fonts.googleapis.com/css?family=Material+Icons|Raleway" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.0.13/vuetify.min.css">
<style>
/* Hide side scrollbar if content does not need it */
html {
overflow-y: auto;
}
.application {
font-family: 'Raleway', sans-serif;
line-height: 2rem;
text-align: center;
}
/* Full screen background */
#app {
/* Location of the image */
/* background-image: url(https://raw.githubusercontent.com/ijklim/gdp/gh-pages/assets/img/bg.jpg); */
background-image: url(assets/img/bg.jpg);
/* Background image is centered vertically and horizontally at all times */
background-position: center center;
/* Background image doesn't tile */
background-repeat: no-repeat;
/* Background image is fixed in the viewport so that it doesn't move when
the content's height is greater than the image's height */
background-attachment: fixed;
/* This is what makes the background image rescale based
on the container's size */
background-size: cover;
/* Set a background color that will be displayed
while the background image is loading */
background-color: #464646;
}
.tooltip {
font-family: 'Raleway';
font-size: 1.2em;
position: absolute;
top: 0px;
left: 0px;
padding: 10px 20px;
border-radius: 5px;
background: rgba(13, 71, 161, .9);
color: white;
max-width: 250px;
}
</style>
</head>
<body>
<!-- https://codepen.io/ivanlim/full/??? -->
<!-- Vuetify Material color palette: https://vuetifyjs.com/en/style/colors -->
<v-app id="app">
<v-container fluid fill-height>
<v-layout align-center wrap>
<v-flex xs12 class="mb-5">
<d3-wrapper :app-name="appName" :d3-data="d3Data"></d3-wrapper>
</v-flex>
</v-layout>
</v-container>
</v-app>
<script src='https://cdn.jsdelivr.net/npm/vue'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.0.13/vuetify.min.js"></script>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="./components/d3-wrapper.js"></script>
<script src="./components/d3-scatterplot-graph.js"></script>
<script type='text/javascript'>
let v = new Vue({
el: '#app',
data () {
return {
appName: 'Doping in Professional Bicycle Racing',
d3Data: [],
}
},
methods: {
formatTooltipData (value) {
return `
<div>
${value.Name}: ${value.Nationality}<br>
${value.Year}, Time: ${value.Time}
` +
(value.Doping ? `<br><br>${value.Doping}` : '') +
`
</div>
`;
},
initD3Data () {
let url = 'https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/cyclist-data.json';
fetch(url)
.then(response => response.json())
.then(json => {
let rank1Time = this.timeToSeconds(json[0].Time);
this.d3Data = json.map(value => ({
hasDopingAllegation: value.Doping != '',
name: value.Name,
tooltip: this.formatTooltipData(value),
x: this.timeToSeconds(value.Time) - rank1Time,
y: value.Place,
}));
})
.catch(error => {
console.error("Error encountered", error);
});
},
timeToSeconds (time) {
let t = time.split(':');
return (t[0] * 60 + (+t[1]));
},
},
mounted () {
this.initD3Data();
}
});
</script>
</body>