Skip to content

Commit e1ff3a5

Browse files
committed
Beginnings of graphical document timelines using d3.js
- Legacy-Id: 10546
1 parent 9728186 commit e1ff3a5

4 files changed

Lines changed: 132 additions & 1 deletion

File tree

ietf/bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": [],
66
"dependencies": {
77
"bootstrap-datepicker": "1.5.0",
8+
"d3": "3.5.10",
89
"font-awesome": "4.5.0",
910
"html5shiv": "3.7.3",
1011
"jquery": "1.11.3",

ietf/externals/static/d3/d3.min.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ietf/templates/doc/document_draft.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
.inline { display: inline; }
1414
{% endblock %}
1515

16+
{% block js %}
17+
<script>
18+
$(window).on({
19+
resize: function (event) {
20+
draw_timeline();
21+
},
22+
load: function (event) {
23+
draw_timeline();
24+
}
25+
});
26+
</script>
27+
{% endblock %}
28+
29+
1630
{% block title %}
1731
{% if doc.get_state_slug == "rfc" %}
1832
RFC {{ rfc_number }}
@@ -26,6 +40,7 @@
2640
{{ top|safe }}
2741

2842
{% include "doc/revisions_list.html" %}
43+
{% include "doc/timeline.html" %}
2944

3045
<table class="table table-condensed">
3146
<thead id="message-row">
@@ -34,7 +49,7 @@
3449
<th colspan="4" class="alert-warning">The information below is for an old version of the document</th>
3550
{% else %}
3651
<th colspan="4"></th>
37-
{% endif %}
52+
{% endif %}
3853
</tr>
3954
</thead>
4055

ietf/templates/doc/timeline.html

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{% load staticfiles %}
2+
<script src="{% static 'd3/d3.min.js' %}"></script>
3+
4+
<style>
5+
#timeline { width: 100%; }
6+
#timeline text { fill: white; }
7+
#timeline > :nth-child(odd) { fill: steelblue; }
8+
#timeline > :nth-child(even) { fill: red; }
9+
10+
.axis path,
11+
.axis line {
12+
fill: none;
13+
stroke: black;
14+
}
15+
16+
#timeline .axis text {
17+
fill: black;
18+
font-size: small;
19+
}
20+
</style>
21+
22+
<svg id="timeline"></svg>
23+
24+
<script>
25+
26+
var data = [
27+
{% for r in rev_history %}
28+
{% if forloop.first %}
29+
{ name: '{{ r.2 }}'.substring(0, 4), rev: '', time: new Date('{{ r.2 }}'.substring(0, 4))},
30+
{% endif %}
31+
{ name: '{{r.0}}', rev: '{{r.1}}', time: new Date('{{ r.2 }}')},
32+
{% if forloop.last %}
33+
{ name: (parseInt('{{ r.2 }}'.substring(0, 4)) + 1).toString(), rev: '', time: new Date((parseInt('{{ r.2 }}'.substring(0, 4)) + 1).toString())},
34+
{% endif %}
35+
{% endfor %}
36+
];
37+
38+
var x;
39+
var y;
40+
var bar_height;
41+
42+
43+
function offset(d, i) {
44+
if (i > 1 && data[i - 1].name !== d.name || d.rev.match("rfc"))
45+
y += bar_height;
46+
return "translate(" + x(d.time) + ", " + y + ")";
47+
}
48+
49+
50+
function bar_width(d, i) {
51+
if (i > 0 && i < data.length - 1)
52+
return x(data[i + 1].time) - x(d.time);
53+
}
54+
55+
56+
function draw_timeline() {
57+
var w = $("#timeline").width();
58+
bar_height = parseFloat($("body").css('line-height'));
59+
60+
x = d3.time.scale().domain([
61+
d3.min(data, function(d) { return d.time; }),
62+
d3.max(data, function(d) { return d.time; })
63+
]).range([0, w]);
64+
65+
y = 0;
66+
var chart = d3.select("#timeline");
67+
var bar = chart.selectAll("g").data(data);
68+
69+
// update
70+
bar
71+
.attr("transform", offset)
72+
.select("rect")
73+
.attr("width", bar_width);
74+
75+
// enter
76+
var g = bar.enter()
77+
.append("g")
78+
.attr("transform", offset);
79+
g.append("rect")
80+
.attr({
81+
height: bar_height,
82+
width: bar_width
83+
});
84+
g.append("text")
85+
.attr("y", bar_height/2)
86+
.text(function (d) { return d.rev; });
87+
88+
// exit
89+
bar.exit().remove();
90+
91+
chart.attr("height", y + 3*bar_height);
92+
93+
var axis = d3.svg.axis()
94+
.scale(x)
95+
.tickValues(data.slice(1, -1).map(function(d) { return d.time; }))
96+
.tickFormat(d3.time.format("%b %Y"))
97+
.orient("bottom");
98+
99+
chart.append("g")
100+
.attr("class", "x axis")
101+
.attr("transform", "translate(0, " + y + ")")
102+
.call(axis)
103+
.selectAll("text")
104+
.style("text-anchor", "end")
105+
.attr("transform", "translate(-13, 10) rotate(-90)");
106+
}
107+
108+
</script>
109+
110+

0 commit comments

Comments
 (0)