Skip to content

Commit

Permalink
Add an ESLint config for use with datatracker javascript and apply it to
Browse files Browse the repository at this point in the history
document_timeline.js. Also, I consider the graphical timeline stuff stable,
so I'll use this commit to say: Branch ready for merge.
 - Legacy-Id: 10566
  • Loading branch information
larseggert committed Dec 10, 2015
1 parent 0f1c823 commit bdf8089
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
rules: {
indent: [2, 4],
camelcase: 0,
"require-jsdoc": 0,
quotes: [2, "double"],
"no-multiple-empty-lines": [2, {max: 2}],
"quote-props": [2, "as-needed"],
"brace-style": [2, "1tbs", {allowSingleLine: true}]
},
env: {
browser: true,
jquery: true
},
globals: {
d3: true
},
extends: "google"
};
21 changes: 12 additions & 9 deletions ietf/static/ietf/js/document_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ var width;

function offset(d, i) {
// increase the y offset if the document name changed in this revision
if (i > 0 && data[i - 1].name !== d.name || d.rev.match("^rfc\d+$"))
if (i > 0 && data[i - 1].name !== d.name || d.rev.match("^rfc\d+$")) {
bar_y += bar_height;
}
return "translate(" + x_scale(d.published) + ", " + bar_y + ")";
}


function bar_width(d, i) {
if (i < data.length - 1)
if (i < data.length - 1) {
return x_scale(data[i + 1].published) - x_scale(d.published);
}
}


Expand Down Expand Up @@ -62,8 +64,9 @@ function draw_timeline() {
bar_height = parseFloat($("body").css("line-height"));

var div = $("#timeline");
if (div.is(":empty"))
if (div.is(":empty")) {
div.append("<svg></svg>");
}
var chart = d3.select("#timeline svg").attr("width", width);

var gradient = chart.append("defs")
Expand Down Expand Up @@ -120,7 +123,7 @@ function draw_timeline() {
g.append("text")
.attr({
x: 3,
y: bar_height/2
y: bar_height / 2
})
.text(function(d) { return d.rev; });

Expand All @@ -146,7 +149,7 @@ function draw_timeline() {
chart.append("g")
.attr({
class: "y axis",
transform: "translate(10, " + bar_height/2 + ")"
transform: "translate(10, " + bar_height / 2 + ")"
})
.call(y_axis)
.selectAll("text")
Expand All @@ -162,17 +165,17 @@ function draw_timeline() {


d3.json("doc.json", function(error, json) {
if (error) return;
data = json["rev_history"];
if (error) { return; }
data = json.rev_history;

if (data.length) {
// make js dates out of publication dates
data.forEach(function(d) { d.published = new Date(d.published); });

// add pseudo entry 185 days after last rev (when the ID will expire)
var pseudo = new Date(data[data.length - 1].published.getTime() +
1000*60*60*24*185);
data.push({ name: "", rev: "", published: pseudo});
1000 * 60 * 60 * 24 * 185);
data.push({name: "", rev: "", published: pseudo});
draw_timeline();
}
});
Expand Down

0 comments on commit bdf8089

Please sign in to comment.