Skip to content

Commit

Permalink
Fix lint errors in gallery and add its JS files to lint.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Dec 13, 2013
1 parent 60b94c8 commit e1e80cc
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 153 deletions.
22 changes: 11 additions & 11 deletions gallery/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ Gallery.register(
var html = "";
for (var i = 0; i < ann.length; i++) {
var name = nameAnnotation(ann[i]);
html += "<span id='" + name + "'>"
html += name + ": " + (ann[i].shortText || '(icon)')
html += "<span id='" + name + "'>";
html += name + ": " + (ann[i].shortText || '(icon)');
html += " -> " + ann[i].text + "</span><br/>";
}
document.getElementById("list").innerHTML = html;
}
}
}
}
);

var last_ann = 0;
annotations = [];
for (var x = 10; x < 15; x += 2) {
Expand All @@ -78,7 +78,7 @@ Gallery.register(
}
} );
g.setAnnotations(annotations);

document.getElementById('add').onclick = function() {
var x = last_ann + 2;
var annnotations = g.annotations();
Expand All @@ -91,26 +91,26 @@ Gallery.register(
} );
last_ann = x;
g.setAnnotations(annotations);
}
};

var bottom = document.getElementById('bottom');

bottom.onclick = function() {
var to_bottom = bottom.textContent == 'Shove to bottom';

var anns = g.annotations();
for (var i = 0; i < anns.length; i++) {
anns[i].attachAtBottom = to_bottom;
}
g.setAnnotations(anns);

if (to_bottom) {
bottom.textContent = 'Lift back up';
} else {
bottom.textContent = 'Shove to bottom';
}
}
};

var saveBg = '';
var num = 0;
g.updateOptions( {
Expand Down
8 changes: 4 additions & 4 deletions gallery/avoid-min-zero.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gallery.register(
"2008-05-10,0\n" +
"2008-05-11,3\n" +
"2008-05-12,4\n"
)
);
var g2 = new Dygraph(document.getElementById("graphd2"),
"Date,Temperature\n" +
"2008-05-07,0\n" +
Expand All @@ -30,7 +30,7 @@ Gallery.register(
{
stepPlot: true
}
)
);
var g3 = new Dygraph(document.getElementById("graph3"),
"Date,Temperature\n" +
"2008-05-07,0\n" +
Expand All @@ -42,7 +42,7 @@ Gallery.register(
{
avoidMinZero: true
}
)
);
var g4 = new Dygraph(document.getElementById("graphd4"),
"Date,Temperature\n" +
"2008-05-07,0\n" +
Expand All @@ -55,6 +55,6 @@ Gallery.register(
stepPlot: true,
avoidMinZero: true
}
)
);
}
});
4 changes: 2 additions & 2 deletions gallery/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ Gallery.register(
var showLabels = document.getElementById('showLabels');
showLabels.onclick = function() {
g.updateOptions({showLabelsOnHighlight: showLabels.checked});
}
};

var s = document.getElementById("status");
var clearStatus = function() {
s.innerHTML = '';
}
};
document.getElementById('clear').onclick = clearStatus;

var g = null;
Expand Down
2 changes: 1 addition & 1 deletion gallery/color-cycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gallery.register(
['#284785', '#EE1111', '#8AE234'],
['#444444', '#888888', '#DDDDDD'],
null
]
];
chart = new Dygraph(document.getElementById("blah"),
"X,a,b,c\n" +
"10,12345,23456,34567\n" +
Expand Down
2 changes: 1 addition & 1 deletion gallery/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2682,4 +2682,4 @@ var stockData = function() {
"2009-08-15,9135.34;9496.28;9580.63,4232.5768877934;4399.8072592826;4438.88821965029\n" +
"2009-09-15,9280.67;9712.28;9829.87,4297.2232125907;4497.07133894216;4551.51896800004\n" +
"2009-10-15,9487.67;9712.73;10092.2,4388.84340147194;4492.9525342659;4668.48924723722\n";
}
};
34 changes: 18 additions & 16 deletions gallery/drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ Gallery.register(

run: function() {
var zoom = document.getElementById('tool_zoom');
zoom.onclick = function() { change_tool(zoom) };
zoom.onclick = function() { change_tool(zoom); };
var pencil = document.getElementById('tool_pencil');
pencil.onclick = function() { change_tool(pencil) };
pencil.onclick = function() { change_tool(pencil); };
var eraser = document.getElementById('tool_eraser');
eraser.onclick = function() { change_tool(eraser) };
eraser.onclick = function() { change_tool(eraser); };

var start_date = new Date("2002/12/29").getTime();
var end_date = new Date().getTime();
var data = [];
for (var d = start_date; d < end_date; d += 604800 * 1000) {
var millis = d + 2 * 3600 * 1000;
data.push( [ new Date(new Date(millis).strftime("%Y/%m/%d")), 50 ]);
data.push( [ new Date(Dygraph.dateString_(millis)), 50 ]);
}

var isDrawing = false;
var lastDrawRow = null, lastDrawValue = null;
var tool = 'pencil';
var valueRange = [0, 100];

function setPoint(event, g, context) {
var graphPos = Dygraph.findPos(g.graphDiv);
var canvasx = Dygraph.pageX(event) - graphPos.x;
Expand All @@ -54,7 +54,7 @@ Gallery.register(
closest_row = row;
}
}

if (closest_row != -1) {
if (lastDrawRow === null) {
lastDrawRow = closest_row;
Expand All @@ -69,7 +69,9 @@ Gallery.register(
var val = lastDrawValue + coeff * (row - lastDrawRow);
val = Math.max(valueRange[0], Math.min(val, valueRange[1]));
data[row][1] = val;
if (val == null || isNaN(val)) console.log(val);
if (val === null || value === undefined || isNaN(val)) {
console.log(val);
}
} else if (tool == 'eraser') {
data[row][1] = null;
}
Expand All @@ -80,13 +82,13 @@ Gallery.register(
g.setSelection(closest_row); // prevents the dot from being finnicky.
}
}

function finishDraw() {
isDrawing = false;
lastDrawRow = null;
lastDrawValue = null;
}

var change_tool = function(tool_div) {
var ids = ['tool_zoom', 'tool_pencil', 'tool_eraser'];
for (var i = 0; i < ids.length; i++) {
Expand All @@ -98,7 +100,7 @@ Gallery.register(
}
}
tool = tool_div.id.replace('tool_', '');

var dg_div = document.getElementById("draw_div");
if (tool == 'pencil') {
dg_div.style.cursor = 'url(images/cursor-pencil.png) 2 30, auto';
Expand All @@ -107,9 +109,9 @@ Gallery.register(
} else if (tool == 'zoom') {
dg_div.style.cursor = 'crosshair';
}
}
};
change_tool(document.getElementById("tool_pencil"));

g = new Dygraph(document.getElementById("draw_div"), data,
{
valueRange: valueRange,
Expand Down Expand Up @@ -160,13 +162,13 @@ Gallery.register(
var xOffset = g.toDomCoords(axis[0], null)[0];
var x = event.offsetX - xOffset;
var w = g.toDomCoords(axis[1], null)[0] - xOffset;
var xPct = w == 0 ? 0 : (x / w);
var xPct = w === 0 ? 0 : (x / w);

var delta = axis[1] - axis[0];
var increment = delta * percentage;
var foo = [increment * xPct, increment * (1 - xPct)];
var dateWindow = [ axis[0] + foo[0], axis[1] - foo[1] ];

g.updateOptions({
dateWindow: dateWindow
});
Expand Down
6 changes: 4 additions & 2 deletions gallery/edge-padding.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ Gallery.register(
avoidMinZero: false,
xRangePad: 3,
yRangePad: 10,
drawAxesAtZero: true})};
drawAxesAtZero: true});
};
mode[1].onchange = function() {
updateGraphOpts({
avoidMinZero: true,
xRangePad: 0,
yRangePad: null,
drawAxesAtZero: false})};
drawAxesAtZero: false});
};
mode[0].checked = true;
mode[0].onchange();

Expand Down
48 changes: 25 additions & 23 deletions gallery/gallery.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*jshint loopfunc:true */
var Gallery = {};

Gallery.entries = {};
Expand Down Expand Up @@ -42,9 +43,9 @@ Gallery.start = function() {

innerDiv.textContent = demo.name;
div.onclick = function(demo, id) { return function() {
if (Gallery.runningDemo != null) {
if (Gallery.runningDemo !== null) {
Gallery.runningDemo.innerDiv.className = "";
if (Gallery.runningDemo.clean != null) {
if (Gallery.runningDemo.clean) {
Gallery.runningDemo.clean(Gallery.workareaChild);
}
}
Expand Down Expand Up @@ -73,9 +74,10 @@ Gallery.start = function() {
javascriptLink.textContent = "Javascript";

var css = getCss(id);
var cssLink;
if (css) {
Gallery.create("span", codeSpan).textContent = " | ";
var cssLink = Gallery.create("a", codeSpan);
cssLink = Gallery.create("a", codeSpan);
cssLink.textContent = "CSS";
}

Expand All @@ -93,37 +95,37 @@ Gallery.start = function() {
var html = Gallery.workareaChild.innerHTML;

// tweak for use in jsfiddle
javascript = " $(document).ready(" + javascript + "\n);"
javascript = " $(document).ready(" + javascript + "\n);";
jQuery('<textarea/>', { name: 'html' })
.val(html)
.hide()
.appendTo(jsfs);
.val(html)
.hide()
.appendTo(jsfs);

jQuery('<textarea/>', { name: 'js' })
.val(javascript)
.hide()
.appendTo(jsfs);
.val(javascript)
.hide()
.appendTo(jsfs);

if (css) {
jQuery('<textarea/>', { name: 'css' })
.val(css)
.hide()
.appendTo(jsfs);
}
.val(css)
.hide()
.appendTo(jsfs);
}
jQuery('<input/>', {
type: 'text',
name: 'title',
value: 'title tbd'
})
.hide()
.appendTo(jsfs);
.hide()
.appendTo(jsfs);
jQuery('<input/>', {
type: 'text',
name: 'description',
value: 'desc tbd'
})
.hide()
.appendTo(jsfs);
.hide()
.appendTo(jsfs);

htmlLink.onclick = function() {
Gallery.textarea.show("HTML", html);
Expand All @@ -146,7 +148,7 @@ Gallery.start = function() {

Gallery.hashChange();

window.onhashchange = Gallery.setHash;("hashchange", Gallery.hashChange, false);
window.onhashchange = Gallery.setHash;
};

var getCss = function(id) {
Expand All @@ -161,7 +163,7 @@ var getCss = function(id) {
var rule = rules[j];
var cssText = rule.cssText;
var key = "#workarea #" + id + " ";
if (cssText.indexOf(key) == 0) {
if (cssText.indexOf(key) === 0) {
arry.push(cssText.substr(key.length));
}
}
Expand All @@ -173,7 +175,7 @@ var getCss = function(id) {
}
}
return "not found";
}
};

Gallery.register = function(id, demo) {
if (Gallery.entries[id]) {
Expand All @@ -185,12 +187,12 @@ Gallery.register = function(id, demo) {

Gallery.hashChange = function(event) {
if (location.hash) {
if (location.hash.indexOf("#g/") == 0) {
if (location.hash.indexOf("#g/") === 0) {
var id = location.hash.substring(3) + "-toc";
var elem = document.getElementById(id);
elem.onclick();
return;
}
}
Gallery.workareaChild.innerHTML = "<h3>Select a demo from the gallery on the left</h3>"
Gallery.workareaChild.innerHTML = "<h3>Select a demo from the gallery on the left</h3>";
};
4 changes: 2 additions & 2 deletions gallery/highlighted-series.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ var makeGraph = function(className, numSeries, numRows, isStacked) {
highlightSeriesOpts: {
strokeWidth: 3,
strokeBorderWidth: 1,
highlightCircleSize: 5,
},
highlightCircleSize: 5
}
});
var onclick = function(ev) {
if (g.isSeriesLocked()) {
Expand Down
Loading

0 comments on commit e1e80cc

Please sign in to comment.