From e1e80cce232a1efbebc1e3dbe236ecf957464c68 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 13 Dec 2013 17:09:15 -0500 Subject: [PATCH] Fix lint errors in gallery and add its JS files to lint.sh --- gallery/annotations.js | 22 +++++++------- gallery/avoid-min-zero.js | 8 ++--- gallery/callbacks.js | 4 +-- gallery/color-cycle.js | 2 +- gallery/data.js | 2 +- gallery/drawing.js | 34 +++++++++++---------- gallery/edge-padding.js | 6 ++-- gallery/gallery.js | 48 +++++++++++++++-------------- gallery/highlighted-series.js | 4 +-- gallery/highlighted-weekends.js | 67 ++++++++++++++++++++--------------------- gallery/independent-series.js | 20 ++++++------ gallery/interaction-api.js | 10 +++--- gallery/interaction.js | 23 ++++++++------ gallery/linear-regression.js | 14 ++++----- gallery/link-interaction.js | 6 ++-- gallery/number-format.js | 6 ++-- gallery/plotter.js | 7 +++-- gallery/stock.js | 10 +++--- gallery/synchronize.js | 1 + gallery/two-axes.js | 8 ++--- lint.sh | 9 ++---- 21 files changed, 158 insertions(+), 153 deletions(-) diff --git a/gallery/annotations.js b/gallery/annotations.js index e0e0319..af0c542 100644 --- a/gallery/annotations.js +++ b/gallery/annotations.js @@ -44,15 +44,15 @@ Gallery.register( var html = ""; for (var i = 0; i < ann.length; i++) { var name = nameAnnotation(ann[i]); - html += "" - html += name + ": " + (ann[i].shortText || '(icon)') + html += ""; + html += name + ": " + (ann[i].shortText || '(icon)'); html += " -> " + ann[i].text + "
"; } document.getElementById("list").innerHTML = html; - } - } + } + } ); - + var last_ann = 0; annotations = []; for (var x = 10; x < 15; x += 2) { @@ -78,7 +78,7 @@ Gallery.register( } } ); g.setAnnotations(annotations); - + document.getElementById('add').onclick = function() { var x = last_ann + 2; var annnotations = g.annotations(); @@ -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( { diff --git a/gallery/avoid-min-zero.js b/gallery/avoid-min-zero.js index 9d72980..96a3cbc 100644 --- a/gallery/avoid-min-zero.js +++ b/gallery/avoid-min-zero.js @@ -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" + @@ -30,7 +30,7 @@ Gallery.register( { stepPlot: true } - ) + ); var g3 = new Dygraph(document.getElementById("graph3"), "Date,Temperature\n" + "2008-05-07,0\n" + @@ -42,7 +42,7 @@ Gallery.register( { avoidMinZero: true } - ) + ); var g4 = new Dygraph(document.getElementById("graphd4"), "Date,Temperature\n" + "2008-05-07,0\n" + @@ -55,6 +55,6 @@ Gallery.register( stepPlot: true, avoidMinZero: true } - ) + ); } }); diff --git a/gallery/callbacks.js b/gallery/callbacks.js index 8891b4c..dfa4a97 100644 --- a/gallery/callbacks.js +++ b/gallery/callbacks.js @@ -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; diff --git a/gallery/color-cycle.js b/gallery/color-cycle.js index 96f125c..a625d7c 100644 --- a/gallery/color-cycle.js +++ b/gallery/color-cycle.js @@ -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" + diff --git a/gallery/data.js b/gallery/data.js index 52105e4..bbccab0 100644 --- a/gallery/data.js +++ b/gallery/data.js @@ -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"; -} +}; diff --git a/gallery/drawing.js b/gallery/drawing.js index b25341b..4452967 100644 --- a/gallery/drawing.js +++ b/gallery/drawing.js @@ -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; @@ -54,7 +54,7 @@ Gallery.register( closest_row = row; } } - + if (closest_row != -1) { if (lastDrawRow === null) { lastDrawRow = closest_row; @@ -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; } @@ -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++) { @@ -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'; @@ -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, @@ -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 }); diff --git a/gallery/edge-padding.js b/gallery/edge-padding.js index deaa2fa..160f4bf 100644 --- a/gallery/edge-padding.js +++ b/gallery/edge-padding.js @@ -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(); diff --git a/gallery/gallery.js b/gallery/gallery.js index f4b6e70..002f7ca 100644 --- a/gallery/gallery.js +++ b/gallery/gallery.js @@ -1,3 +1,4 @@ +/*jshint loopfunc:true */ var Gallery = {}; Gallery.entries = {}; @@ -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); } } @@ -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"; } @@ -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('