-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
207 lines (167 loc) · 4.66 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE html>
<!--
based on some example on bl.ocks.org/mbostock
* panning: http://mbostock.github.io/d3/talk/20111018/area-gradient.html
-->
<html xmlns:xlink="http://www.w3.org/1999/xlink">
<meta charset="utf-8">
<style>
body {
font: 14px sans-serif;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.page {
fill: steelblue;
}
.chapter {
fill: firebrick;
}
.chapter:hover, .page:hover {
cursor: pointer;
}
div#position {
position: fixed;
left: 100px;
border: 1px solid black;
background: white;
min-width: 100px;
padding: 5px;
}
div#position dl {
margin: 0;
}
div#position dd, div#position dt {
float: left;
margin: 0;
}
div#position dt {
width: 60px;
clear: left;
}
div#position p {
margin-bottom: 0;
}
p#message {
position: fixed;
top: 600px;
left: 30px;
}
p#loading {
position: fixed;
top: 650px;
left: 30px;
}
.spin {
position: fixed;
top: 250px;
left: 50%;
}
</style>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="jquery.spin.js"></script>
<link rel="stylesheet" href="jquery.spin.css">
<body>
<script src="http://d3js.org/d3.v2.js?2.9.6"></script>
<div class="spin" data-spin></div>
<div id="position">
<dl>
<dt id="tag">tag
<dd>
<dt id="page">page
<dd>
</dl>
<br style="clear: both">
<p id="chapter">
</div>
<p id="loading">Please stand by while the graph is rendering. This might take a while.</p>
<p id="message">
The horizontal axis corresponds to tags (roughly time), the blue dots show page number currently occupied by the tag, and the red dots show chapter currently occupied by tag. Hover your mouse over a dot for info, and you can click on a dot to go to the tag page.
</p>
<script>
// hide by default
$("div#position").hide();
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 30000 - margin.left - margin.right,
height = 600 - margin.top - margin.bottom;
var x = d3.scale.linear()
.range([0, width]);
var y1 = d3.scale.linear()
.range([height, 0]);
var y2 = d3.scale.linear()
.range([height, 0]);
var svg = d3.select("body").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 chapters = []
$.getJSON("chapters.php", function(json) {
chapters = json;
});
function updatePosition(d) {
$("div#position").show();
$("dt#tag + dd").text(d.tag);
$("dt#page + dd").text(d.page);
$("p#chapter").text("in Chapter " + d.chapter + ": " + chapters[d.chapter - 1].title);
}
function clearPosition() {
$("div#position").hide();
}
d3.json("scatter.php", function(data) {
// select all tags and order them for position-lookup
var tags = [];
data.forEach(function(d) {
tags.push(d.tag);
});
tags.sort();
// convert to integers where required
data.forEach(function(d) {
d.chapter = +d.chapter; // TODO better syntax for this?
d.page = +d.page; // TODO better syntax for this?
});
// compute the scales' domains.
x.domain([0, tags.length]);
y1.domain(d3.extent(data, function(d) { return d.chapter; }));
y2.domain(d3.extent(data, function(d) { return d.page; }));
// add the x-axis
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.svg.axis().scale(x).orient("bottom"));
// add the y-axis
svg.append("g")
.attr("class", "y axis")
.call(d3.svg.axis().scale(y1).orient("left"));
// add the y-axis
svg.append("g")
.attr("class", "y axis")
.call(d3.svg.axis().scale(y2).orient("right"));
// add the points
svg.selectAll(".point")
.data(data)
.enter().append("svg:a")
.attr("xlink:href", function(d) { return "http://stacks.math.columbia.edu/tag/" + d.tag; })
.append("circle")
.attr("class", "chapter")
.attr("r", function(d) { return d.chapter ? 3 : 0; })
.attr("transform", function(d) { return "translate(" + x(tags.indexOf(d.tag)) + "," + y1(d.chapter) + ")"; })
.on("mouseenter", updatePosition)
.on("mouseleave", clearPosition)
svg.selectAll(".point")
.data(data)
.enter().append("svg:a")
.attr("xlink:href", function(d) { return "http://stacks.math.columbia.edu/tag/" + d.tag; })
.append("circle")
.attr("class", "page")
.attr("r", function(d) { return d.chapter ? 3 : 0; })
.attr("transform", function(d) { return "translate(" + x(tags.indexOf(d.tag)) + "," + y2(d.page) + ")"; })
.on("mouseenter", updatePosition)
.on("mouseleave", clearPosition)
$(".spin").hide();
$("#loading").hide();
});
</script>