Built with blockbuilder.org
forked from romsson's block: simple line chart from dataset
forked from anonymous's block: simple line chart from dataset
forked from Naram22's block: simple line chart from dataset
forked from Naram22's block: simple line chart from dataset
forked from Naram22's block: simple line chart from dataset
forked from Naram22's block: simple line chart from dataset
forked from Naram22's block: projet
forked from Naram22's block: projet
forked from Naram22's block: projet
forked from Naram22's block: projet v11
forked from Naram22's block: projet v11
forked from Naram22's block: projet v16
forked from Naram22's block: projet v16
forked from Naram22's block: projet v17
forked from Naram22's block: projet debug
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v3.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
.plot {
fill: rgba(250, 250, 255, 0.6);
}
.grid .tick {
stroke: lightgrey;
opacity: 0.7;
}
.grid path {
stroke-width: 0;
}
.axis text {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.line1 {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
.line2 {
fill: none;
stroke: steelblue;
stroke-width: 0.5px;
stroke-dasharray: 10;
}
button {
position: absolute;
right: 30px;
top: 30px;
}
</style>
</head>
<body>
<button>Reset</button>
<script>
var player={};
var result={};
var axis_x=["1st Rnd","2nd Rnd","3rd Rnd","4th Rnd","Quarter","Semi","Finals"];
var tab_tournament =["Australian Open", "French Open", "Wimbledon", "US Open"];
var tab_year=[];
for(i=2000;i<2017;i++){
tab_year.push(i);}
var year = tab_year[10];
var tournament=tab_tournament[1];
d3.csv("resultat_atp.csv", function(data) {
for (var i=0;i<data.length;i++){
if(data[i].Date.split("/")[2]==year){
if(data[i].Tournament==tournament){
var line_tour_debut=i;
break;
}
}
}
for (var i=0;i<data.length;i++){
if(data[i].Date.split("/")[2]==year){
if(data[i].Tournament==tournament){
var line_tour_fin=i;
}
}
}
line_tour_fin=line_tour_fin+1;
console.log(line_tour_debut +" "+line_tour_fin)
// Extract the name of the player and his ranking
var r=0;
for (var i=line_tour_debut;i<line_tour_fin;i++){
if (isNaN(player[data[i].Winner]) && data[i].WRank !== "N/A"){
player[data[i].Winner]=data[i].WRank;
}
if (isNaN(player[data[i].Winner]) && data[i].WRank == "N/A"){
player[data[i].Loser]=700+r;
data[i].WRank = 700+r;
r=r+1;
}
if (isNaN(player[data[i].Loser]) && data[i].LRank !== "N/A"){
player[data[i].Loser]=data[i].LRank;
}
if (isNaN(player[data[i].Loser]) && data[i].LRank == "N/A"){
player[data[i].Loser]=700+r;
data[i].LRank = 700+r;
r=r+1;
}
}
for (var a=0;a<128;a++){
console.log(Object.keys(player)[a]);
//a=2;
var j=0;
var k=0;
var m=0;
var rank=player[Object.keys(player)[a]];
result[rank+ " "+Object.keys(player)[a]] = [];
for (var i=line_tour_debut;i<line_tour_fin;i++){
if (data[i].Winner == Object.keys(player)[a]){
result[rank+ " "+Object.keys(player)[a]].push
({"Round": axis_x[j], "difference": data[i].LRank-rank, "status":"V", "opponent" :data[i].Loser});
j=j+1;
k=i;
}
}
var player_inter=Object.keys(player)[a];
if(j>0){
if (j<axis_x.length-1){
while (j<axis_x.length){
for (var l=k+1;l<line_tour_fin;l++){
if (data[l].Winner == player_inter){
//console.log("Winner" + " " +data[l].Winner)
result[rank+ " "+Object.keys(player)[a]].push
({"Round": axis_x[j], "difference": data[l].WRank-rank, "status":"L","opponent" :data[l].Winner});
j=j+1;
k=l;
break;
} else if (data[l].Loser == player_inter){
//console.log("Loser" + " " +data[l].Winner)
result[rank+ " "+Object.keys(player)[a]].push
({"Round": axis_x[j], "difference": data[l].WRank-rank, "status":"L","opponent" :data[l].Winner});
j=j+1;
k=l;
player_inter=data[l].Winner
break;
}
}
}
}
}
} // loop for
console.log(result)
});
</script>
</body>
https://d3js.org/d3.v3.min.js