Add an ESLint config for use with datatracker javascript and apply it to

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
This commit is contained in:
Lars Eggert 2015-12-10 09:02:58 +00:00
parent 0f1c823a6e
commit bdf8089688
2 changed files with 31 additions and 9 deletions

19
.eslintrc.js Normal file
View file

@ -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"
};

View file

@ -10,15 +10,17 @@ var width;
function offset(d, i) { function offset(d, i) {
// increase the y offset if the document name changed in this revision // 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; bar_y += bar_height;
}
return "translate(" + x_scale(d.published) + ", " + bar_y + ")"; return "translate(" + x_scale(d.published) + ", " + bar_y + ")";
} }
function bar_width(d, i) { 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); return x_scale(data[i + 1].published) - x_scale(d.published);
}
} }
@ -62,8 +64,9 @@ function draw_timeline() {
bar_height = parseFloat($("body").css("line-height")); bar_height = parseFloat($("body").css("line-height"));
var div = $("#timeline"); var div = $("#timeline");
if (div.is(":empty")) if (div.is(":empty")) {
div.append("<svg></svg>"); div.append("<svg></svg>");
}
var chart = d3.select("#timeline svg").attr("width", width); var chart = d3.select("#timeline svg").attr("width", width);
var gradient = chart.append("defs") var gradient = chart.append("defs")
@ -120,7 +123,7 @@ function draw_timeline() {
g.append("text") g.append("text")
.attr({ .attr({
x: 3, x: 3,
y: bar_height/2 y: bar_height / 2
}) })
.text(function(d) { return d.rev; }); .text(function(d) { return d.rev; });
@ -146,7 +149,7 @@ function draw_timeline() {
chart.append("g") chart.append("g")
.attr({ .attr({
class: "y axis", class: "y axis",
transform: "translate(10, " + bar_height/2 + ")" transform: "translate(10, " + bar_height / 2 + ")"
}) })
.call(y_axis) .call(y_axis)
.selectAll("text") .selectAll("text")
@ -162,8 +165,8 @@ function draw_timeline() {
d3.json("doc.json", function(error, json) { d3.json("doc.json", function(error, json) {
if (error) return; if (error) { return; }
data = json["rev_history"]; data = json.rev_history;
if (data.length) { if (data.length) {
// make js dates out of publication dates // make js dates out of publication dates
@ -171,8 +174,8 @@ d3.json("doc.json", function(error, json) {
// add pseudo entry 185 days after last rev (when the ID will expire) // add pseudo entry 185 days after last rev (when the ID will expire)
var pseudo = new Date(data[data.length - 1].published.getTime() + var pseudo = new Date(data[data.length - 1].published.getTime() +
1000*60*60*24*185); 1000 * 60 * 60 * 24 * 185);
data.push({ name: "", rev: "", published: pseudo}); data.push({name: "", rev: "", published: pseudo});
draw_timeline(); draw_timeline();
} }
}); });