-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
188 lines (164 loc) · 7.4 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>Heatmap FIUBA</title>
<style>
rect.bordered {
stroke: #E6E6E6;
stroke-width:2px;
}
text.mono {
font-size: 9pt;
font-family: Consolas, courier;
fill: #aaa;
}
text.axis-workweek {
fill: #000;
}
text.axis-worktime {
fill: #000;
}
</style>
<script src="//d3js.org/d3.v3.js"></script>
</head>
<body>
<h1>Heatmap FIUBA</h1>
<div id="chart"></div>
<div id="dataset-picker"></div>
<div id="carrera-picker"></div>
<a href="https://github.com/lugfi/heatmap-fiuba"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
<script type="text/javascript">
var margin = { top: 50, right: 0, bottom: 100, left: 30 },
width = 960 - margin.left - margin.right,
height = 430 - margin.top - margin.bottom,
gridSize = Math.floor(width / 48),
legendElementWidth = gridSize*4,
buckets = 9,
colors = ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"], // alternatively colorbrewer.YlGnBu[9]
days = ["Lu", "Ma", "Mi", "Ju", "Vi", "Sa", "Do"],
times = ["1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12a", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p", "12p"];
var datasets = ["Horarios_2Q2017.json", "Horarios_1Q2017.json", "Horarios_1Q2016.json", "Horarios_2Q2016.json", "Horarios_1Q2015.json", "Horarios_2Q2015.json", "Horarios_2Q2014.json"];
var carreras = ["Civil", "Industrial", "Naval", "Agrim", "Mecánica", "Electricista", "Electrónica", "Química", "Sistemas", "Informática", "Alimentos", "Ing. Agrim"];
var globalData = null;
var svg = d3.select("#chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var dayLabels = svg.selectAll(".dayLabel")
.data(days)
.enter().append("text")
.text(function (d) { return d; })
.attr("x", 0)
.attr("y", function (d, i) { return i * gridSize * 2; })
.style("text-anchor", "end")
.attr("transform", "translate(-6," + gridSize * 2 / 1.5 + ")")
.attr("class", function (d, i) { return ((i >= 0 && i <= 4) ? "dayLabel mono axis axis-workweek" : "dayLabel mono axis"); });
var timeLabels = svg.selectAll(".timeLabel")
.data(times)
.enter().append("text")
.text(function(d) { return d; })
.attr("x", function(d, i) { return i * gridSize * 2; })
.attr("y", 0)
.style("text-anchor", "middle")
.attr("transform", "translate(" + gridSize * 2 / 2 + ", -6)")
.attr("class", function(d, i) { return ((i >= 7 && i <= 16) ? "timeLabel mono axis axis-worktime" : "timeLabel mono axis"); });
var heatmapChart = function(data) {
var colorScale = d3.scale.quantile()
.domain([0, buckets - 1, d3.max(data, function (d) { return d.value; })])
.range(colors);
var cards = svg.selectAll(".hour")
.data(data, function(d) {return d.day+':'+d.hour;});
cards.append("title");
cards.enter().append("rect")
.attr("x", function(d) { return (d.hour - 1) * gridSize * 2; })
.attr("y", function(d) { return (d.day - 1) * gridSize * 2; })
.attr("rx", 4)
.attr("ry", 4)
.attr("class", "hour bordered")
.attr("width", gridSize)
.attr("height", gridSize * 2)
.style("fill", colors[0])
.append("svg:title")
.text(function(d) { return d.value; });;
cards.transition().duration(1000)
.style("fill", function(d) { return colorScale(d.value); });
cards.select("title").text(function(d) { return d.value; });
cards.exit().remove();
var legend = svg.selectAll(".legend")
.data([0].concat(colorScale.quantiles()), function(d) { return d; });
legend.enter().append("g")
.attr("class", "legend");
legend.append("rect")
.attr("x", function(d, i) { return legendElementWidth * i; })
.attr("y", height)
.attr("width", legendElementWidth)
.attr("height", gridSize / 2)
.style("fill", function(d, i) { return colors[i]; });
legend.append("text")
.attr("class", "mono")
.text(function(d) { return "≥ " + Math.round(d); })
.attr("x", function(d, i) { return legendElementWidth * i; })
.attr("y", height + gridSize);
legend.exit().remove();
};
var transformData = function(materias) {
var data = materias.map(function(m) {
return m.cursos.map(function(cu) {
return cu.clases.map(function(cl) {
var horas = [];
for (var i = 0; i < cl.fin - cl.inicio; i++) {
horas.push(i);
}
return horas.map(function(h) {
return {
day: cl.dia + 1,
hour: (cl.inicio + h) / 2 + 7
};
});
}).reduce(function(a, b) { return a.concat(b); });
}).reduce(function(a, b) { return a.concat(b); });
}).reduce(function(a, b) { return a.concat(b); });
return d3.nest()
.key(function(d) { return d.day + "/" + d.hour; })
.rollup(function(v) { return v.length; })
.entries(data)
.map(function(d) {
return {
day: d.key.split("/")[0],
hour: d.key.split("/")[1],
value: d.values
}
});
}
d3.json(datasets[0], function(data) {
globalData = data;
heatmapChart(transformData(data.materias));
});
var datasetpicker = d3.select("#dataset-picker").selectAll(".dataset-button")
.data(datasets);
datasetpicker.enter()
.append("input")
.attr("value", function(d){ return d })
.attr("type", "button")
.attr("class", "dataset-button")
.on("click", function(d) {
d3.json(d, function(data) {
globalData = data;
heatmapChart(transformData(data.materias));
});
});
var carrerapicker = d3.select("#carrera-picker").selectAll(".carrera-button")
.data(carreras);
carrerapicker.enter()
.append("input")
.attr("value", function(d, i){ return d })
.attr("type", "button")
.attr("class", "carrera-button")
.on("click", function(d, i) {
heatmapChart(transformData(globalData.carreras[i].materias.map(function(m) { return globalData.materias[m] })));
});
</script>
</body>
</html>