-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
126 lines (113 loc) · 3.47 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
<!DOCTYPE html>
<html lang='en'>
<meta charset='UTF-8'>
<style>
table {
border-collapse: collapse;
width: 60%;
}
th {
height: 80px;
background-color: mediumaquamarine;
}
th, td {
padding: 15px;
text-align: left;
}
tr:hover {
background-color: #b4b4b4;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
table, th, td {
border: 1px solid lightslategray;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
</style>
<body width='500' height='1000'></body>
<script src='src/d3.js'></script>
<script src='src/underscore.js'></script>
<script>
const svg = d3.select("body");
const cols = [{
head: 'Leaderboard Position',
cl: 'thispos',
html: function (row) {
console.log(row);
return row
}
},
{
head: 'Username',
cl: 'un',
html: function (row) {
return row.username
}
},
{
head: 'CW Leaderboard Position',
cl: 'cdwpos',
html: function (row) {
return row.leaderboardPosition
}
}
]
const table = svg.append('table');
// replace with your own pls
const CODEWARSAPIKEY = 'JhLQB35PuvZGGVBpmqJn';
// WARNING: Do not continue to use the below proxy url at deployment stage -- you're totally reliant on someone elses Heroku app.
// For instructions to deploy your own check out: https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe/43881141
const proxyurl = "https://cors-anywhere.herokuapp.com/";
const codewarsUrl = "https://www.codewars.com/api/v1/users/";
// Get the data and build our object
const participants = d3.csv('src/codewars_usernames.csv');
const participantInfo = participants.then((data) => {
promises = data.map(row => d3.json(proxyurl + codewarsUrl + row.Username + '?access_key=' +
CODEWARSAPIKEY))
return Promise.all(promises.map(res => {
return res;
}))
})
const promise3 = participantInfo.then((pData) => {
let sortedParts = _.sortBy(pData, 'leaderboardPosition')
return sortedParts;
})
const boardBuilder = promise3.then((pData) => {
let numberRows = pData.length;
// build the outline
console.log(pData)
table.append('thead').append('tr')
.selectAll('th')
.data(cols).enter()
.append('th')
.attr('class', (r) => {
return r.cl
})
.text((r) => {
return r.head
});
table.append('tbody')
.selectAll('tr')
.data(pData).enter()
.append('tr')
.selectAll('td')
.data(function (row, i) {
// evaluate column objects against the current row
return cols.map(function (c) {
var cell = {};
d3.keys(c).forEach(function (k) {
cell[k] = typeof c[k] == 'function' ? c[k](row, i) : c[k];
});
return cell;
});
}).enter()
.append('td')
.html((r) => {
return (_.indexOf(pData, r.html) >= 0 ? _.indexOf(pData, r.html) : r.html)
})
.attr('class', (r) => {
return r.cl
});
})
</script>