-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathesip_key_heatmap.html
155 lines (131 loc) · 5.91 KB
/
esip_key_heatmap.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
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<style>
#chart {
margin: auto;
width: 75%;
}
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="http://d3js.org/d3.v3.js"></script>
</head>
<body>
<p>Sample text</p>
<div id="chart"></div>
<div id="dataset-picker">
</div>
<script type="text/javascript">
var margin = { top: 50, right: 0, bottom: 100, left: 350 },
width = 200, //1200 - margin.left - margin.right,
height = 1050 - margin.top - margin.bottom,
gridSize = 25, //Math.floor(width / 24),
legendElementWidth = gridSize*2,
buckets = 9,
colors = ["#66bd63","#a6d96a","#d9ef8b","#ffffbf","#fee08b","#fdae61","#f46d43","#d73027","#a50026"], // alternatively colorbrewer.YlGnBu[9]
times = ["2010", "2011", "2012", "2013", "2014", "2015", "2016"],
days = ["Atmospheric Composition","Biogeosciences","Computational Geophysics","Cryosphere", "Education", "Geochemistry","Geodesy and Gravity", "Global Change", "History of Geophysics", "Hydrology", "Informatics", "Ionosphere", "Magnetospheric Physics", "Marine Geology and Geophysics", "Mathematical Geophysics", "Atmospheric Processes", "Mineralogy and Petrology", "Oceanography: General", "Natural Hazards", "Nonlinear Geophysics", "Oceanography: Physical", "Oceanography: Biological and Chemical","Planetary Sciences: Solid Surface Planets", "Planetary Sciences: Solar System Objects", "Policy Sciences", "Public Issues", "Radio Sciences", "Seismology", "Solar Physics, Astrophysics, and Astronomy", "Space Plasma Physics", "Space Weather", "Tectonophysics", "Volcanology", "Geographic Location", "General or Miscellaneous"];
datasets = ["data/esip_keyword_heatmap.tsv"];
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; })
.style("text-anchor", "end")
.attr("transform", "translate(-6," + gridSize / 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; })
// .attr("y", 0)
.style("text-anchor", "start")
.attr("transform", function(d,i){
return "translate("+((gridSize/2)+(i*gridSize))+",-5) rotate(-65)";
});
// .attr("transform", "translate(" + gridSize / 2 + ", -6) rotate(90)");
//.attr("class", function(d, i) { return ((i >= 7 && i <= 16) ? "timeLabel mono axis axis-worktime" : "timeLabel mono axis"); });
var heatmapChart = function(tsvFile) {
d3.tsv(tsvFile,
function(d) {
return {
day: +d.day,
hour: +d.hour,
value: +d.value
};
},
function(error, 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; })
.attr("y", function(d) { return (d.day - 1) * gridSize; })
.attr("rx", 4)
.attr("ry", 4)
.attr("class", "hour bordered")
.attr("width", gridSize)
.attr("height", gridSize)
.style("fill", colors[0]);
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")
.attr("transform", "translate(-275, 0)");
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();
});
};
heatmapChart(datasets[0]);
//var datasetpicker = d3.select("#dataset-picker").selectAll(".dataset-button")
// .data(datasets);
//datasetpicker.enter()
// .append("input")
// .attr("value", function(d){ return "Dataset " + d })
// .attr("type", "button")
// .attr("class", "dataset-button")
// .on("click", function(d) {
// heatmapChart(d);
// });
</script>
</body>
</html>