From 268cc89c8b1c33eed34dd11190a6bfffc58dd681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 15 Feb 2016 21:24:26 -0500 Subject: [PATCH 1/5] enforce key-spacing --- .eslintrc | 2 +- src/components/annotations/index.js | 2 +- src/components/color/index.js | 12 +-- src/components/colorbar/draw.js | 12 +-- src/components/colorscale/scales.js | 28 +++---- src/components/drawing/index.js | 13 +++- src/components/titles/index.js | 4 +- src/lib/dates.js | 14 ++-- src/lib/svg_text_utils.js | 2 +- src/plot_api/plot_api.js | 2 +- src/plots/cartesian/axes.js | 34 ++++----- src/plots/cartesian/axis_defaults.js | 4 +- src/plots/cartesian/graph_interact.js | 26 +++++-- src/plots/cartesian/position_defaults.js | 2 +- src/plots/geo/index.js | 2 +- src/plots/gl3d/scene.js | 6 +- src/plots/plots.js | 22 +++--- src/traces/bar/set_positions.js | 4 +- src/traces/contour/plot.js | 10 +-- src/traces/histogram2d/attributes.js | 2 +- src/traces/histogram2dcontour/attributes.js | 2 +- src/traces/mesh3d/convert.js | 18 ++--- src/traces/scatter3d/convert.js | 84 +++++++++++---------- src/traces/scattergl/convert.js | 2 +- test/jasmine/tests/gl3daxes_test.js | 2 +- test/jasmine/tests/lib_test.js | 2 +- test/jasmine/tests/plot_promise_test.js | 8 +- 27 files changed, 171 insertions(+), 150 deletions(-) diff --git a/.eslintrc b/.eslintrc index 5844375527f..38f318881b9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,7 +19,7 @@ "comma-style": [2, "last"], "semi": [2], "semi-spacing": [2, {"before": false, "after": true}], - "key-spacing": [0, {"beforeColon": false, "afterColon": true}], + "key-spacing": [2, {"beforeColon": false, "afterColon": true}], "no-spaced-func": [2], "space-in-parens": [2, "never"], "space-before-function-paren": [2, "never"], diff --git a/src/components/annotations/index.js b/src/components/annotations/index.js index 7c6fb5778f9..deaf1965c4c 100644 --- a/src/components/annotations/index.js +++ b/src/components/annotations/index.js @@ -572,7 +572,7 @@ annotations.draw = function(gd, index, opt, value) { .attr({ 'data-index': String(index), d: 'M3,3H-3V-3H3ZM0,0L' + (arrowX0-arrowX) + ',' + (arrowY0-arrowY), - transform:'translate('+arrowX+','+arrowY+')' + transform: 'translate('+arrowX+','+arrowY+')' }) .style('stroke-width', (strokewidth+6)+'px') .call(Plotly.Color.stroke, 'rgba(0,0,0,0)') diff --git a/src/components/color/index.js b/src/components/color/index.js index b7f6922aa24..92cb8370ff7 100644 --- a/src/components/color/index.js +++ b/src/components/color/index.js @@ -45,14 +45,14 @@ color.combine = function(front, back){ var bc = tinycolor(back||color.background).toRgb(), bcflat = bc.a===1 ? bc : { - r:255*(1-bc.a) + bc.r*bc.a, - g:255*(1-bc.a) + bc.g*bc.a, - b:255*(1-bc.a) + bc.b*bc.a + r: 255 * (1-bc.a) + bc.r*bc.a, + g: 255 * (1-bc.a) + bc.g*bc.a, + b: 255 * (1-bc.a) + bc.b*bc.a }, fcflat = { - r:bcflat.r*(1-fc.a) + fc.r*fc.a, - g:bcflat.g*(1-fc.a) + fc.g*fc.a, - b:bcflat.b*(1-fc.a) + fc.b*fc.a + r: bcflat.r*(1-fc.a) + fc.r*fc.a, + g: bcflat.g*(1-fc.a) + fc.g*fc.a, + b: bcflat.b*(1-fc.a) + fc.b*fc.a }; return tinycolor(fcflat).toRgbString(); }; diff --git a/src/components/colorbar/draw.js b/src/components/colorbar/draw.js index 64d3ab55f91..10e3f5e8702 100644 --- a/src/components/colorbar/draw.js +++ b/src/components/colorbar/draw.js @@ -132,7 +132,7 @@ module.exports = function draw(gd, id) { // y positioning we can do correctly from the start yBottomFrac = opts.y + lenFrac * - (({top:-0.5, bottom:0.5}[opts.yanchor]||0)-0.5), + (({top: -0.5, bottom: 0.5}[opts.yanchor] || 0) - 0.5), yBottomPx = Math.round(fullLayout._size.h * (1-yBottomFrac)), yTopPx = yBottomPx-lenPx, titleEl, @@ -431,7 +431,7 @@ module.exports = function draw(gd, id) { }); // fix positioning for xanchor!='left' - var xoffset = ({center:0.5, right:1}[opts.xanchor]||0) * + var xoffset = ({center: 0.5, right: 1}[opts.xanchor] || 0) * outerwidth; container.attr('transform', 'translate('+(fullLayout._size.l-xoffset)+','+fullLayout._size.t+')'); @@ -440,10 +440,10 @@ module.exports = function draw(gd, id) { Plots.autoMargin(gd, id,{ x: opts.x, y: opts.y, - l: outerwidth*({right:1, center:0.5}[opts.xanchor]||0), - r: outerwidth*({left:1, center:0.5}[opts.xanchor]||0), - t: outerheight*({bottom:1, middle:0.5}[opts.yanchor]||0), - b: outerheight*({top:1, middle:0.5}[opts.yanchor]||0) + l: outerwidth * ({right: 1, center: 0.5}[opts.xanchor] || 0), + r: outerwidth * ({left: 1, center: 0.5}[opts.xanchor] || 0), + t: outerheight * ({bottom: 1, middle: 0.5}[opts.yanchor] || 0), + b: outerheight * ({top: 1, middle: 0.5}[opts.yanchor] || 0) }); } diff --git a/src/components/colorscale/scales.js b/src/components/colorscale/scales.js index 582b1e3c6e7..93fccc0e314 100644 --- a/src/components/colorscale/scales.js +++ b/src/components/colorscale/scales.js @@ -10,31 +10,31 @@ module.exports = { - 'Greys':[[0,'rgb(0,0,0)'],[1,'rgb(255,255,255)']], + 'Greys': [[0,'rgb(0,0,0)'],[1,'rgb(255,255,255)']], - 'YIGnBu':[[0,'rgb(8, 29, 88)'],[0.125,'rgb(37, 52, 148)'], + 'YIGnBu': [[0,'rgb(8, 29, 88)'],[0.125,'rgb(37, 52, 148)'], [0.25,'rgb(34, 94, 168)'],[0.375,'rgb(29, 145, 192)'], [0.5,'rgb(65, 182, 196)'],[0.625,'rgb(127, 205, 187)'], [0.75,'rgb(199, 233, 180)'],[0.875,'rgb(237, 248, 217)'], [1,'rgb(255, 255, 217)']], - 'Greens':[[0,'rgb(0, 68, 27)'],[0.125,'rgb(0, 109, 44)'], + 'Greens': [[0,'rgb(0, 68, 27)'],[0.125,'rgb(0, 109, 44)'], [0.25,'rgb(35, 139, 69)'],[0.375,'rgb(65, 171, 93)'], [0.5,'rgb(116, 196, 118)'],[0.625,'rgb(161, 217, 155)'], [0.75,'rgb(199, 233, 192)'],[0.875,'rgb(229, 245, 224)'], [1,'rgb(247, 252, 245)']], - 'YIOrRd':[[0,'rgb(128, 0, 38)'],[0.125,'rgb(189, 0, 38)'], + 'YIOrRd': [[0,'rgb(128, 0, 38)'],[0.125,'rgb(189, 0, 38)'], [0.25,'rgb(227, 26, 28)'],[0.375,'rgb(252, 78, 42)'], [0.5,'rgb(253, 141, 60)'],[0.625,'rgb(254, 178, 76)'], [0.75,'rgb(254, 217, 118)'],[0.875,'rgb(255, 237, 160)'], [1,'rgb(255, 255, 204)']], - 'Bluered':[[0,'rgb(0,0,255)'],[1,'rgb(255,0,0)']], + 'Bluered': [[0,'rgb(0,0,255)'],[1,'rgb(255,0,0)']], // modified RdBu based on // www.sandia.gov/~kmorel/documents/ColorMaps/ColorMapsExpanded.pdf - 'RdBu':[[0,'rgb(5, 10, 172)'],[0.35,'rgb(106, 137, 247)'], + 'RdBu': [[0,'rgb(5, 10, 172)'],[0.35,'rgb(106, 137, 247)'], [0.5,'rgb(190,190,190)'],[0.6,'rgb(220, 170, 132)'], [0.7,'rgb(230, 145, 90)'],[1,'rgb(178, 10, 28)']], // Scale for non-negative numeric values @@ -45,39 +45,39 @@ module.exports = { [0.5, 'rgb(70, 100, 245)'], [0.6, 'rgb(90, 120, 245)'], [0.7, 'rgb(106, 137, 247)'], [1, 'rgb(220, 220, 220)']], - 'Picnic':[[0,'rgb(0,0,255)'],[0.1,'rgb(51,153,255)'], + 'Picnic': [[0,'rgb(0,0,255)'],[0.1,'rgb(51,153,255)'], [0.2,'rgb(102,204,255)'],[0.3,'rgb(153,204,255)'], [0.4,'rgb(204,204,255)'],[0.5,'rgb(255,255,255)'], [0.6,'rgb(255,204,255)'],[0.7,'rgb(255,153,255)'], [0.8,'rgb(255,102,204)'],[0.9,'rgb(255,102,102)'], [1,'rgb(255,0,0)']], - 'Rainbow':[[0,'rgb(150,0,90)'],[0.125,'rgb(0, 0, 200)'], + 'Rainbow': [[0,'rgb(150,0,90)'],[0.125,'rgb(0, 0, 200)'], [0.25,'rgb(0, 25, 255)'],[0.375,'rgb(0, 152, 255)'], [0.5,'rgb(44, 255, 150)'],[0.625,'rgb(151, 255, 0)'], [0.75,'rgb(255, 234, 0)'],[0.875,'rgb(255, 111, 0)'], [1,'rgb(255, 0, 0)']], - 'Portland':[[0,'rgb(12,51,131)'],[0.25,'rgb(10,136,186)'], + 'Portland': [[0,'rgb(12,51,131)'],[0.25,'rgb(10,136,186)'], [0.5,'rgb(242,211,56)'],[0.75,'rgb(242,143,56)'], [1,'rgb(217,30,30)']], - 'Jet':[[0,'rgb(0,0,131)'],[0.125,'rgb(0,60,170)'], + 'Jet': [[0,'rgb(0,0,131)'],[0.125,'rgb(0,60,170)'], [0.375,'rgb(5,255,255)'],[0.625,'rgb(255,255,0)'], [0.875,'rgb(250,0,0)'],[1,'rgb(128,0,0)']], - 'Hot':[[0,'rgb(0,0,0)'],[0.3,'rgb(230,0,0)'], + 'Hot': [[0,'rgb(0,0,0)'],[0.3,'rgb(230,0,0)'], [0.6,'rgb(255,210,0)'],[1,'rgb(255,255,255)']], - 'Blackbody':[[0,'rgb(0,0,0)'],[0.2,'rgb(230,0,0)'], + 'Blackbody': [[0,'rgb(0,0,0)'],[0.2,'rgb(230,0,0)'], [0.4,'rgb(230,210,0)'],[0.7,'rgb(255,255,255)'], [1,'rgb(160,200,255)']], - 'Earth':[[0,'rgb(0,0,130)'],[0.1,'rgb(0,180,180)'], + 'Earth': [[0,'rgb(0,0,130)'],[0.1,'rgb(0,180,180)'], [0.2,'rgb(40,210,40)'],[0.4,'rgb(230,230,50)'], [0.6,'rgb(120,70,20)'],[1,'rgb(255,255,255)']], - 'Electric':[[0,'rgb(0,0,0)'],[0.15,'rgb(30,0,100)'], + 'Electric': [[0,'rgb(0,0,0)'],[0.15,'rgb(30,0,100)'], [0.4,'rgb(120,0,100)'],[0.6,'rgb(160,90,0)'], [0.8,'rgb(230,200,0)'],[1,'rgb(255,250,220)']], diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index 8e0f48fcbfe..e9227fab2b8 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -296,7 +296,7 @@ drawing.tryColorscale = function(cont, contIn, prefix) { }; // draw text at points -var TEXTOFFSETSIGN = {start:1, end:-1, middle:0, bottom:1, top:-1}, +var TEXTOFFSETSIGN = {start: 1, end: -1, middle: 0, bottom: 1, top: -1}, LINEEXPAND = 1.3; drawing.textPointStyle = function(s, trace) { s.each(function(d){ @@ -467,7 +467,10 @@ drawing.makeTester = function(gd) { testref.enter().append('path') .classed('js-reference-point', true) .attr('d','M0,0H1V1H0Z') - .style({'stroke-width':0, fill:'black'}); + .style({ + 'stroke-width': 0, + fill: 'black' + }); if(!tester.node()._cache) { tester.node()._cache = {}; @@ -498,7 +501,11 @@ drawing.bBox = function(node) { var testNode = node.cloneNode(true); tester.appendChild(testNode); // standardize its position... do we really want to do this? - d3.select(testNode).attr({x:0, y:0, transform:''}); + d3.select(testNode).attr({ + x: 0, + y: 0, + transform: '' + }); var testRect = testNode.getBoundingClientRect(), refRect = test3.select('.js-reference-point') diff --git a/src/components/titles/index.js b/src/components/titles/index.js index 4cde7f9f0b9..6435cee79f1 100644 --- a/src/components/titles/index.js +++ b/src/components/titles/index.js @@ -59,8 +59,8 @@ Titles.draw = function(gd, title) { xa, ya, avoid = { - selection:d3.select(gd).selectAll('g.'+cont._id+'tick'), - side:cont.side + selection: d3.select(gd).selectAll('g.'+cont._id+'tick'), + side: cont.side }, // multiples of fontsize to offset label from axis offsetBase = colorbar ? 0 : 1.5, diff --git a/src/lib/dates.js b/src/lib/dates.js index 5a5ef676cef..cc7096c4aec 100644 --- a/src/lib/dates.js +++ b/src/lib/dates.js @@ -166,22 +166,22 @@ exports.ms2DateTime = function(ms, r) { // TODO: this is way out of date vs. the server-side version var timeFormats = { // 24 hour - H:['%H:%M:%S~%L', '%H:%M:%S', '%H:%M'], + H: ['%H:%M:%S~%L', '%H:%M:%S', '%H:%M'], // with am/pm - I:['%I:%M:%S~%L%p', '%I:%M:%S%p', '%I:%M%p'], + I: ['%I:%M:%S~%L%p', '%I:%M:%S%p', '%I:%M%p'], // no colon, ie only date or date with hour (could also support eg 12h34m?) - D:['%H', '%I%p', '%Hh'] + D: ['%H', '%I%p', '%Hh'] }; var dateFormats = { - Y:[ + Y: [ '%Y~%m~%d', '%Y%m%d', '%y%m%d', // YYMMDD, has 6 digits together so will match Y, not y '%m~%d~%Y', // MM/DD/YYYY has first precedence '%d~%m~%Y' // then DD/MM/YYYY ], - Yb:[ + Yb: [ '%b~%d~%Y', // eg nov 21 2013 '%d~%b~%Y', // eg 21 nov 2013 '%Y~%d~%b', // eg 2013 21 nov (or 2013 q3, after replacement) @@ -191,12 +191,12 @@ var dateFormats = { * the two-digit year cases have so many potential ambiguities * it's not even funny, but we'll try them anyway. */ - y:[ + y: [ '%m~%d~%y', '%d~%m~%y', '%y~%m~%d' ], - yb:[ + yb: [ '%b~%d~%y', '%d~%b~%y', '%y~%d~%b', diff --git a/src/lib/svg_text_utils.js b/src/lib/svg_text_utils.js index d8b246d7318..cd5f674198f 100644 --- a/src/lib/svg_text_utils.js +++ b/src/lib/svg_text_utils.js @@ -149,7 +149,7 @@ util.convertToTspans = function(_context, _callback){ var newSvgW = getSize(newSvg, 'width'), newSvgH = getSize(newSvg, 'height'), newX = +that.attr('x') - newSvgW * - {start:0, middle:0.5, end:1}[that.attr('text-anchor') || 'start'], + {start: 0, middle: 0.5, end: 1}[that.attr('text-anchor') || 'start'], // font baseline is about 1/4 fontSize below centerline textHeight = parseInt(that.style('font-size'), 10) || getSize(that, 'height'), diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index a9ff977ea9c..15f06bcab7e 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -1831,7 +1831,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { // it flips everything and the axes else if(ai==='orientationaxes') { cont.orientation = - {v:'h', h:'v'}[contFull.orientation]; + {v: 'h', h: 'v'}[contFull.orientation]; } swapXYData(cont); } diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 8f20cb41c23..4ad40b86d18 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -153,14 +153,14 @@ axes.doAutoRange = function(ax) { else if(mbest) { if(ax.type==='linear' || ax.type==='-') { if(ax.rangemode==='tozero' && minbest.val>=0) { - minbest = {val:0, pad:0}; + minbest = {val: 0, pad: 0}; } else if(ax.rangemode==='nonnegative') { if(minbest.val - mbest*minbest.pad<0) { - minbest = {val:0, pad:0}; + minbest = {val: 0, pad: 0}; } if(maxbest.val<0) { - maxbest = {val:1, pad:0}; + maxbest = {val: 1, pad: 0}; } } @@ -309,8 +309,8 @@ axes.expand = function(ax, data, options) { } if(includeThis) { ax._min.push({ - val:dmin, - pad:(tozero && dmin===0) ? 0 : ppadiminus + val: dmin, + pad: (tozero && dmin===0) ? 0 : ppadiminus }); } } @@ -329,8 +329,8 @@ axes.expand = function(ax, data, options) { } if(includeThis) { ax._max.push({ - val:dmax, - pad:(tozero && dmax===0) ? 0 : ppadiplus + val: dmax, + pad: (tozero && dmax===0) ? 0 : ppadiplus }); } } @@ -375,7 +375,7 @@ axes.autoBin = function(data,ax,nbins,is2d) { // piggyback off autotick code to make "nice" bin sizes var dummyax = { type: ax.type==='log' ? 'linear' : ax.type, - range:[datamin, datamax] + range: [datamin, datamax] }; axes.autoTicks(dummyax, size0); var binstart = axes.tickIncrement( @@ -916,7 +916,7 @@ function formatDate(ax, out, hover, extraPrecision) { else { if(extraPrecision) { if(isNumeric(tr)) tr+=2; - else tr = {y:'m', m:'d', d:'H', H:'M', M:'S', S:2}[tr]; + else tr = {y: 'm', m: 'd', d: 'H', H: 'M', M: 'S', S: 2}[tr]; } if(tr==='y') tt = yearFormat(d); else if(tr==='m') tt = monthFormat(d); @@ -1028,7 +1028,7 @@ function numFormat(v, ax, fmtoverride, hover) { if(hover) { // make a dummy axis obj to get the auto rounding and exponent var ah = { - exponentformat:ax.exponentformat, + exponentformat: ax.exponentformat, dtick: ax.showexponent==='none' ? ax.dtick : (isNumeric(v) ? Math.abs(v) || 1 : 1), // if not showing any exponents, don't change the exponent @@ -1539,7 +1539,7 @@ axes.doTicks = function(td, axid, skipTitle) { else { var mjShift = Plotly.Drawing.bBox(mathjaxGroup.node()).width * - {end:-0.5, start:0.5}[anchor]; + {end: -0.5, start: 0.5}[anchor]; mathjaxGroup.attr('transform', transform + (mjShift ? 'translate(' + mjShift + ',0)' : '')); } @@ -1575,9 +1575,9 @@ axes.doTicks = function(td, axid, skipTitle) { lbbArray.push({ // ignore about y, just deal with x overlaps - top:0, - bottom:10, - height:10, + top: 0, + bottom: 10, + height: 10, left: x-bb.width/2, // impose a 2px gap right: x+bb.width/2 + 2, @@ -1658,10 +1658,10 @@ axes.doTicks = function(td, axid, skipTitle) { } var showZl = (ax.range[0]*ax.range[1]<=0) && ax.zeroline && (ax.type==='linear' || ax.type==='-') && gridvals.length && - (hasBarsOrFill || clipEnds({x:0}) || !ax.showline); + (hasBarsOrFill || clipEnds({x: 0}) || !ax.showline); var zl = zlcontainer.selectAll('path.'+zcls) - .data(showZl ? [{x:0}] : []); + .data(showZl ? [{x: 0}] : []); zl.enter().append('path').classed(zcls,1).classed('zl',1) .classed('crisp',1) .attr('d',gridpath); @@ -1754,7 +1754,7 @@ function makeAxisGroups(gd, traces) { } if(!groupsi.length) { - groups.push({x:[xi], y: [yi]}); + groups.push({x: [xi], y: [yi]}); continue; } diff --git a/src/plots/cartesian/axis_defaults.js b/src/plots/cartesian/axis_defaults.js index a1e112adb42..3376e32a410 100644 --- a/src/plots/cartesian/axis_defaults.js +++ b/src/plots/cartesian/axis_defaults.js @@ -141,7 +141,7 @@ function setAutoType(ax, data){ // first check for histograms, as the count direction // should always default to a linear axis if(d0.type==='histogram' && - axLetter === {v:'y', h:'x'}[d0.orientation || 'v']) { + axLetter === {v: 'y', h: 'x'}[d0.orientation || 'v']) { ax.type='linear'; return; } @@ -171,7 +171,7 @@ function setAutoType(ax, data){ } function getBoxPosLetter(trace) { - return {v:'x', h:'y'}[trace.orientation || 'v']; + return {v: 'x', h: 'y'}[trace.orientation || 'v']; } function isBoxWithoutPositionCoords(trace, axLetter) { diff --git a/src/plots/cartesian/graph_interact.js b/src/plots/cartesian/graph_interact.js index c418bcdce6c..e57a4656e26 100644 --- a/src/plots/cartesian/graph_interact.js +++ b/src/plots/cartesian/graph_interact.js @@ -718,8 +718,8 @@ fx.loneHover = function(hoverItem, opts) { index: 0, hoverinfo: '' }, - xa: {_offset:0}, - ya: {_offset:0}, + xa: {_offset: 0}, + ya: {_offset: 0}, index: 0 }; @@ -819,7 +819,10 @@ function createHoverText(hoverData, opts) { (outerTop-tbb.bottom-HOVERARROWSIZE-HOVERTEXTPAD) : (outerTop-tbb.top+HOVERARROWSIZE+HOVERTEXTPAD))) .selectAll('tspan.line') - .attr({x:ltext.attr('x'), y:ltext.attr('y')}); + .attr({ + x: ltext.attr('x'), + y: ltext.attr('y') + }); var topsign = xa.side==='top' ? '-' : ''; lpath.attr('d','M0,0'+ @@ -839,7 +842,10 @@ function createHoverText(hoverData, opts) { (ya.side==='right' ? 1 : -1)*(HOVERTEXTPAD+HOVERARROWSIZE), outerTop-tbb.top-tbb.height/2) .selectAll('tspan.line') - .attr({x:ltext.attr('x'), y:ltext.attr('y')}); + .attr({ + x: ltext.attr('x'), + y: ltext.attr('y') + }); var leftsign = ya.side==='right' ? '' : '-'; lpath.attr('d','M0,0'+ @@ -967,7 +973,10 @@ function createHoverText(hoverData, opts) { } g.select('path') - .style({fill:traceColor, stroke:contrastColor}); + .style({ + fill: traceColor, + stroke: contrastColor + }); var tbb = tx.node().getBoundingClientRect(), htx = xa._offset+(d.x0+d.x1)/2, hty = ya._offset+(d.y0+d.y1)/2, @@ -1194,7 +1203,7 @@ function alignHoverText(hoverLabels, rotateLabels) { } var horzSign = d.anchor==='end' ? -1 : 1, tx = g.select('text.nums'), - alignShift = {start:1,end:-1,middle:0}[d.anchor], + alignShift = {start: 1, end: -1, middle: 0}[d.anchor], txx = alignShift*(HOVERARROWSIZE+HOVERTEXTPAD), tx2x = txx+alignShift*(d.txwidth+HOVERTEXTPAD), offsetX = 0, @@ -1223,7 +1232,10 @@ function alignHoverText(hoverLabels, rotateLabels) { tx.call(Plotly.Drawing.setPosition, txx+offsetX, offsetY+d.ty0-d.by/2+HOVERTEXTPAD) .selectAll('tspan.line') - .attr({x:tx.attr('x'), y:tx.attr('y')}); + .attr({ + x: tx.attr('x'), + y: tx.attr('y') + }); if(d.tx2width) { g.select('text.name, text.name tspan.line') diff --git a/src/plots/cartesian/position_defaults.js b/src/plots/cartesian/position_defaults.js index 97898d86f55..7963ae55d0e 100644 --- a/src/plots/cartesian/position_defaults.js +++ b/src/plots/cartesian/position_defaults.js @@ -21,7 +21,7 @@ module.exports = function handlePositionDefaults(containerIn, containerOut, coer var anchor = Lib.coerce(containerIn, containerOut, { anchor: { - valType:'enumerated', + valType: 'enumerated', values: ['free'].concat(counterAxes), dflt: isNumeric(containerIn.position) ? 'free' : (counterAxes[0] || 'free') diff --git a/src/plots/geo/index.js b/src/plots/geo/index.js index 0bf83683a9f..5c169c99d4b 100644 --- a/src/plots/geo/index.js +++ b/src/plots/geo/index.js @@ -40,7 +40,7 @@ exports.plot = function plotGeo(gd) { * initialize object to keep reference to every loaded topojson */ if(window.PlotlyGeoAssets === undefined) { - window.PlotlyGeoAssets = { topojson : {} }; + window.PlotlyGeoAssets = { topojson: {} }; } for(var i = 0; i < geoIds.length; i++) { diff --git a/src/plots/gl3d/scene.js b/src/plots/gl3d/scene.js index 24bca5395f5..887b33c8dc3 100644 --- a/src/plots/gl3d/scene.js +++ b/src/plots/gl3d/scene.js @@ -572,9 +572,9 @@ proto.getCamera = function getCamera() { var eye = this.glplot.camera.eye; return { - up: {x:up[0], y:up[1], z:up[2]}, - center: {x:center[0], y:center[1], z:center[2]}, - eye: {x:eye[0], y:eye[1], z:eye[2]} + up: {x: up[0], y: up[1], z: up[2]}, + center: {x: center[0], y: center[1], z: center[2]}, + eye: {x: eye[0], y: eye[1], z: eye[2]} }; }; diff --git a/src/plots/plots.js b/src/plots/plots.js index 443951e13bc..15a5e24bd66 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -326,7 +326,7 @@ plots.addLinks = function(gd) { linkContainer.enter().append('text') .classed('js-plot-link-container', true) .style({ - 'font-family':'"Open Sans", Arial, sans-serif', + 'font-family': '"Open Sans", Arial, sans-serif', 'font-size': '12px', 'fill': Plotly.Color.defaultLine, 'pointer-events': 'all' @@ -382,7 +382,7 @@ function positionPlayWithData(gd, container){ .attr({ 'xlink:xlink:href': '#', 'class': 'link--impt link--embedview', - 'font-weight':'bold' + 'font-weight': 'bold' }) .text(gd._context.linkText + ' ' + String.fromCharCode(187)); @@ -862,10 +862,10 @@ plots.autoMargin = function(gd,id,o) { if(o.b+o.t > fullLayout.height*0.5) o.b = o.t = 0; fullLayout._pushmargin[id] = { - l: {val:o.x, size: o.l+pad}, - r: {val:o.x, size: o.r+pad}, - b: {val:o.y, size: o.b+pad}, - t: {val:o.y, size: o.t+pad} + l: {val: o.x, size: o.l+pad}, + r: {val: o.x, size: o.r+pad}, + b: {val: o.y, size: o.b+pad}, + t: {val: o.y, size: o.t+pad} }; } @@ -891,10 +891,10 @@ plots.doAutoMargin = function(gd) { if(fullLayout.margin.autoexpand!==false) { // fill in the requested margins pm.base = { - l:{val:0, size:ml}, - r:{val:1, size:mr}, - t:{val:1, size:mt}, - b:{val:0, size:mb} + l: {val: 0, size: ml}, + r: {val: 1, size: mr}, + t: {val: 1, size: mt}, + b: {val: 0, size: mb} }; // now cycle through all the combinations of l and r // (and t and b) to find the required margins @@ -1046,7 +1046,7 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults){ } var obj = { - data:(data||[]).map(function(v){ + data: (data || []).map(function(v){ var d = stripObj(v); // fit has some little arrays in it that don't contain data, // just fit params and meta diff --git a/src/traces/bar/set_positions.js b/src/traces/bar/set_positions.js index 9da1a3a2736..92740f8d9df 100644 --- a/src/traces/bar/set_positions.js +++ b/src/traces/bar/set_positions.js @@ -30,8 +30,8 @@ module.exports = function setPositions(gd, plotinfo) { ['v', 'h'].forEach(function(dir){ var bl = [], - pLetter = {v:'x', h:'y'}[dir], - sLetter = {v:'y', h:'x'}[dir], + pLetter = {v: 'x', h: 'y'}[dir], + sLetter = {v: 'y', h: 'x'}[dir], pa = plotinfo[pLetter](), sa = plotinfo[sLetter](); diff --git a/src/traces/contour/plot.js b/src/traces/contour/plot.js index f6cd7acb979..e8cf7fc67a0 100644 --- a/src/traces/contour/plot.js +++ b/src/traces/contour/plot.js @@ -112,16 +112,16 @@ function emptyPathinfo(contours, plotinfo, cd0) { pathinfo = []; for(var ci = contours.start; ci < contours.end + cs/10; ci += cs) { pathinfo.push({ - level:ci, + level: ci, // all the cells with nontrivial marching index - crossings:{}, + crossings: {}, // starting points on the edges of the lattice for each contour - starts:[], + starts: [], // all unclosed paths (may have less items than starts, // if a path is closed by rounding) - edgepaths:[], + edgepaths: [], // all closed paths - paths:[], + paths: [], // store axes so we can convert to px xaxis: plotinfo.x(), yaxis: plotinfo.y(), diff --git a/src/traces/histogram2d/attributes.js b/src/traces/histogram2d/attributes.js index 0a95fbc99c0..e1a703d0bae 100644 --- a/src/traces/histogram2d/attributes.js +++ b/src/traces/histogram2d/attributes.js @@ -28,7 +28,7 @@ module.exports = { histnorm: histogramAttrs.histnorm, histfunc: histogramAttrs.histfunc, - autobinx:histogramAttrs.autobinx, + autobinx: histogramAttrs.autobinx, nbinsx: histogramAttrs.nbinsx, xbins: histogramAttrs.xbins, autobiny: histogramAttrs.autobiny, diff --git a/src/traces/histogram2dcontour/attributes.js b/src/traces/histogram2dcontour/attributes.js index 4b4f8131d07..51c9e3da554 100644 --- a/src/traces/histogram2dcontour/attributes.js +++ b/src/traces/histogram2dcontour/attributes.js @@ -19,7 +19,7 @@ module.exports = { histnorm: histogram2dAttrs.histnorm, histfunc: histogram2dAttrs.histfunc, - autobinx:histogram2dAttrs.autobinx, + autobinx: histogram2dAttrs.autobinx, nbinsx: histogram2dAttrs.nbinsx, xbins: histogram2dAttrs.xbins, autobiny: histogram2dAttrs.autobiny, diff --git a/src/traces/mesh3d/convert.js b/src/traces/mesh3d/convert.js index efeed65b773..4b74904138b 100644 --- a/src/traces/mesh3d/convert.js +++ b/src/traces/mesh3d/convert.js @@ -105,16 +105,16 @@ proto.update = function(data) { var config = { positions: positions, - cells: cells, - ambient: data.lighting.ambient, - diffuse: data.lighting.diffuse, - specular: data.lighting.specular, + cells: cells, + ambient: data.lighting.ambient, + diffuse: data.lighting.diffuse, + specular: data.lighting.specular, roughness: data.lighting.roughness, - fresnel: data.lighting.fresnel, - opacity: data.opacity, - contourEnable: data.contour.show, - contourColor: str2RgbaArray(data.contour.color).slice(0,3), - contourWidth: data.contour.width, + fresnel: data.lighting.fresnel, + opacity: data.opacity, + contourEnable: data.contour.show, + contourColor: str2RgbaArray(data.contour.color).slice(0,3), + contourWidth: data.contour.width, useFacetNormals: data.flatshading }; diff --git a/src/traces/scatter3d/convert.js b/src/traces/scatter3d/convert.js index def340e4e46..b1b561fb3a3 100644 --- a/src/traces/scatter3d/convert.js +++ b/src/traces/scatter3d/convert.js @@ -35,8 +35,10 @@ function LineWithMarkers(scene, uid) { this.color = null; this.mode = ''; this.dataPoints = []; - this.axesBounds = [[-Infinity,-Infinity,-Infinity], - [Infinity,Infinity,Infinity]]; + this.axesBounds = [ + [-Infinity,-Infinity,-Infinity], + [Infinity,Infinity,Infinity] + ]; this.textLabels = null; this.data = null; } @@ -96,9 +98,9 @@ function constructDelaunay(points, color, axis) { } } return { - positions: points, - cells: cells, - meshColor: color + positions: points, + cells: cells, + meshColor: color }; } @@ -197,8 +199,8 @@ function convertPlotlyOptions(scene, data) { //Build object parameters params = { position: points, - mode: data.mode, - text: text + mode: data.mode, + text: text }; if ('line' in data) { @@ -295,13 +297,13 @@ proto.update = function(data) { this.dataPoints = options.position; lineOptions = { - gl: gl, - position: options.position, - color: options.lineColor, - lineWidth: options.lineWidth || 1, - dashes: dashPattern[0], - dashScale: dashPattern[1], - opacity: data.opacity + gl: gl, + position: options.position, + color: options.lineColor, + lineWidth: options.lineWidth || 1, + dashes: dashPattern[0], + dashScale: dashPattern[1], + opacity: data.opacity }; if (this.mode.indexOf('lines') !== -1) { @@ -321,16 +323,16 @@ proto.update = function(data) { if(data.marker && data.marker.opacity) scatterOpacity *= data.marker.opacity; scatterOptions = { - gl: gl, - position: options.position, - color: options.scatterColor, - size: options.scatterSize, - glyph: options.scatterMarker, - opacity: scatterOpacity, + gl: gl, + position: options.position, + color: options.scatterColor, + size: options.scatterSize, + glyph: options.scatterMarker, + opacity: scatterOpacity, orthographic: true, - lineWidth: options.scatterLineWidth, - lineColor: options.scatterLineColor, - project: options.project, + lineWidth: options.scatterLineWidth, + lineColor: options.scatterLineColor, + project: options.project, projectScale: options.projectScale, projectOpacity: options.projectOpacity }; @@ -349,18 +351,18 @@ proto.update = function(data) { } textOptions = { - gl: gl, - position: options.position, - glyph: options.text, - color: options.textColor, - size: options.textSize, - angle: options.textAngle, - alignment: options.textOffset, - font: options.textFont, + gl: gl, + position: options.position, + glyph: options.text, + color: options.textColor, + size: options.textSize, + angle: options.textAngle, + alignment: options.textOffset, + font: options.textFont, orthographic: true, - lineWidth: 0, - project: false, - opacity: data.opacity + lineWidth: 0, + project: false, + opacity: data.opacity }; this.textLabels = options.text; @@ -379,13 +381,13 @@ proto.update = function(data) { } errorOptions = { - gl: gl, - position: options.position, - color: options.errorColor, - error: options.errorBounds, - lineWidth: options.errorLineWidth, - capSize: options.errorCapSize, - opacity: data.opacity + gl: gl, + position: options.position, + color: options.errorColor, + error: options.errorBounds, + lineWidth: options.errorLineWidth, + capSize: options.errorCapSize, + opacity: data.opacity }; if(this.errorBars) { if(options.errorBounds) { diff --git a/src/traces/scattergl/convert.js b/src/traces/scattergl/convert.js index a3cf21ed8c1..089da9e7fc5 100644 --- a/src/traces/scattergl/convert.js +++ b/src/traces/scattergl/convert.js @@ -49,7 +49,7 @@ function LineWithMarkers(scene, uid) { color: [0, 0, 0, 1], width: 1, fill: [false, false, false, false], - fillColor: [ + fillColor: [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], diff --git a/test/jasmine/tests/gl3daxes_test.js b/test/jasmine/tests/gl3daxes_test.js index 13ccafd24c7..fb8e8b20f9c 100644 --- a/test/jasmine/tests/gl3daxes_test.js +++ b/test/jasmine/tests/gl3daxes_test.js @@ -11,7 +11,7 @@ describe('Test Gl3dAxes', function() { var options = { font: 'Open Sans', scene: {id: 'scene'}, - data: [{x:[], y:[]}] + data: [{x: [], y: []}] }; beforeEach(function() { diff --git a/test/jasmine/tests/lib_test.js b/test/jasmine/tests/lib_test.js index f51385bf608..1f148f05f20 100644 --- a/test/jasmine/tests/lib_test.js +++ b/test/jasmine/tests/lib_test.js @@ -375,7 +375,7 @@ describe('Test lib.js:', function() { propR.set([]); propS.set(null); - expect(obj).toEqual({c:[]}); + expect(obj).toEqual({c: []}); }); diff --git a/test/jasmine/tests/plot_promise_test.js b/test/jasmine/tests/plot_promise_test.js index 9e326625ba9..e1df695fbdc 100644 --- a/test/jasmine/tests/plot_promise_test.js +++ b/test/jasmine/tests/plot_promise_test.js @@ -351,7 +351,7 @@ describe('Plotly.___ methods', function() { beforeEach(function(done) { var data = [{ x: [1,2,3], y: [4,5,6] }], - layout = {hovermode:'closest'}, + layout = {hovermode: 'closest'}, initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, layout); @@ -378,7 +378,7 @@ describe('Plotly.___ methods', function() { beforeEach(function(done) { var data = [{ x: [1,2,3], y: [4,5,6] }], - layout = {hovermode:'closest'}, + layout = {hovermode: 'closest'}, initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, layout); @@ -405,7 +405,7 @@ describe('Plotly.___ methods', function() { beforeEach(function(done) { var data = [{ x: [1,2,3], y: [4,5,6] }], - layout = {hovermode:'closest'}, + layout = {hovermode: 'closest'}, initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, layout); @@ -432,7 +432,7 @@ describe('Plotly.___ methods', function() { beforeEach(function(done) { var data = [{ x: [1,2,3], y: [4,5,6] }], - layout = {hovermode:'closest'}, + layout = {hovermode: 'closest'}, initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, layout); From a90c5fc979cfe0a85a75740e8e1cb46eac92fb1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 15 Feb 2016 21:48:44 -0500 Subject: [PATCH 2/5] decrease max empty lines limit to 2 --- .eslintrc | 2 +- test/jasmine/tests/extend_test.js | 1 - test/jasmine/tests/plots_test.js | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.eslintrc b/.eslintrc index 38f318881b9..c62ed99ca0e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,7 +8,7 @@ }, "rules": { "no-trailing-spaces": [2], - "no-multiple-empty-lines": [2, {"max": 3, "maxEOF": 1}], + "no-multiple-empty-lines": [2, {"max": 2, "maxEOF": 1}], "linebreak-style": [2, "unix"], "indent": [2, 4, {"SwitchCase": 1}], "max-len": [0, 80], diff --git a/test/jasmine/tests/extend_test.js b/test/jasmine/tests/extend_test.js index 882fa387476..e74e29c3edc 100644 --- a/test/jasmine/tests/extend_test.js +++ b/test/jasmine/tests/extend_test.js @@ -45,7 +45,6 @@ var undef = { }; - describe('extendFlat', function() { 'use strict'; diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index dd84121e275..c83d6ea7d63 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -4,7 +4,6 @@ var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); - describe('Test Plots', function() { 'use strict'; From 33255f17f811a8d1dbfc3ae61928a2d145382d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 15 Feb 2016 22:31:32 -0500 Subject: [PATCH 3/5] enfore keyword-spacing rule, - so that if() and for() are the norm. --- .eslintrc | 7 +++ devtools/test_dashboard/buttons.js | 4 +- src/components/annotations/index.js | 2 +- .../colorscale/is_valid_scale_array.js | 2 +- src/components/modebar/buttons.js | 6 +- src/components/modebar/index.js | 10 +-- src/components/shapes/index.js | 2 +- src/fonts/mathjax_config.js | 2 +- src/lib/dates.js | 44 ++++++------- src/lib/events.js | 14 ++--- src/lib/index.js | 20 +++--- src/lib/matrix.js | 10 +-- src/lib/notifier.js | 4 +- src/lib/queue.js | 14 ++--- src/lib/show_no_webgl_msg.js | 2 +- src/lib/stats.js | 22 +++---- src/lib/svg_text_utils.js | 8 +-- src/plots/cartesian/axes.js | 12 ++-- src/plots/cartesian/clean_datum.js | 2 +- src/plots/cartesian/set_convert.js | 6 +- src/plots/cartesian/tick_defaults.js | 3 +- src/plots/geo/zoom.js | 10 +-- src/plots/gl2d/scene2d.js | 2 +- src/plots/gl3d/index.js | 4 +- src/plots/gl3d/layout/axis_defaults.js | 6 +- src/plots/gl3d/layout/convert.js | 62 +++++++++---------- src/plots/gl3d/layout/spikes.js | 2 +- src/plots/gl3d/layout/tick_marks.js | 6 +- src/snapshot/cloneplot.js | 30 ++++----- src/snapshot/svgtoimg.js | 2 +- src/snapshot/toimage.js | 2 +- src/traces/box/calc.js | 14 ++--- src/traces/box/defaults.js | 6 +- src/traces/box/hover.js | 4 +- src/traces/box/plot.js | 6 +- src/traces/box/set_positions.js | 16 ++--- src/traces/heatmap/calc.js | 2 +- src/traces/scatter/calc.js | 4 +- src/traces/scatter3d/convert.js | 24 +++---- src/traces/surface/convert.js | 14 ++--- src/traces/surface/defaults.js | 18 +++--- tasks/util/get_image_request_options.js | 3 +- test/image/compare_pixels_test.js | 4 +- test/image/make_baseline.js | 14 ++--- test/jasmine/tests/geolayout_test.js | 2 +- test/jasmine/tests/gl3daxes_test.js | 4 +- test/jasmine/tests/plot_api_test.js | 2 +- 47 files changed, 233 insertions(+), 226 deletions(-) diff --git a/.eslintrc b/.eslintrc index c62ed99ca0e..bbf234f284b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -20,6 +20,13 @@ "semi": [2], "semi-spacing": [2, {"before": false, "after": true}], "key-spacing": [2, {"beforeColon": false, "afterColon": true}], + "keyword-spacing": [2, {"overrides": { + "if": {"after": false}, + "for": {"after": false}, + "while": {"after": false}, + "switch": {"after": false}, + "catch": {"after": false} + }}], "no-spaced-func": [2], "space-in-parens": [2, "never"], "space-before-function-paren": [2, "never"], diff --git a/devtools/test_dashboard/buttons.js b/devtools/test_dashboard/buttons.js index c698982f121..94f282f97c6 100644 --- a/devtools/test_dashboard/buttons.js +++ b/devtools/test_dashboard/buttons.js @@ -65,12 +65,12 @@ function plotButtons(plots, figDir) { /* * Grab the currently loaded plot and make an image - replacing the plot. */ - if (!gd) return; + if(!gd) return; var layout = gd.layout; var data = gd.data; - if (!layout || !data) return; + if(!layout || !data) return; Plotly.Plots.getSubplotIds(gd._fullLayout, 'gl3d').forEach(function(key) { var scene = gd._fullLayout[key]._scene; diff --git a/src/components/annotations/index.js b/src/components/annotations/index.js index deaf1965c4c..a8dc8cf0786 100644 --- a/src/components/annotations/index.js +++ b/src/components/annotations/index.js @@ -186,7 +186,7 @@ annotations.draw = function(gd, index, opt, value) { Plotly.Lib.extendFlat({}, value) : {text: 'New text'}; - if (layout.annotations) { + if(layout.annotations) { layout.annotations.splice(index, 0, rule); } else { layout.annotations = [rule]; diff --git a/src/components/colorscale/is_valid_scale_array.js b/src/components/colorscale/is_valid_scale_array.js index 52be9b1021c..6bc56c09ffd 100644 --- a/src/components/colorscale/is_valid_scale_array.js +++ b/src/components/colorscale/is_valid_scale_array.js @@ -20,7 +20,7 @@ module.exports = function isValidScaleArray(scl) { if(!Array.isArray(scl)) return false; else { if(+scl[0][0]!==0 || +scl[scl.length-1][0]!==1) return false; - for (var i = 0; i < scl.length; i++) { + for(var i = 0; i < scl.length; i++) { si = scl[i]; if(si.length!==2 || +si[0] 2) return false; + if(datetime.length > 2) return false; var p = datetime[0].split('-'); // date part - if (p.length > 3 || (p.length !== 3 && datetime[1])) return false; + if(p.length > 3 || (p.length !== 3 && datetime[1])) return false; // year - if (p[0].length === 4) y = Number(p[0]); - else if (p[0].length === 2) { + if(p[0].length === 4) y = Number(p[0]); + else if(p[0].length === 2) { var yNow = new Date().getFullYear(); y = ((Number(p[0]) - yNow + 70)%100 + 200)%100 + yNow - 70; } else return false; - if (!isNumeric(y)) return false; - if (p.length === 1) return new Date(y,0,1).getTime(); // year only + if(!isNumeric(y)) return false; + if(p.length === 1) return new Date(y,0,1).getTime(); // year only // month m = Number(p[1]) - 1; // new Date() uses zero-based months - if (p[1].length > 2 || !(m >= 0 && m <= 11)) return false; - if (p.length === 2) return new Date(y, m, 1).getTime(); // year-month + if(p[1].length > 2 || !(m >= 0 && m <= 11)) return false; + if(p.length === 2) return new Date(y, m, 1).getTime(); // year-month // day d = Number(p[2]); - if (p[2].length > 2 || !(d >= 1 && d <= 31)) return false; + if(p[2].length > 2 || !(d >= 1 && d <= 31)) return false; // now save the date part d = new Date(y, m, d).getTime(); - if (!datetime[1]) return d; // year-month-day + if(!datetime[1]) return d; // year-month-day p = datetime[1].split(':'); - if (p.length > 3) return false; + if(p.length > 3) return false; // hour h = Number(p[0]); - if (p[0].length > 2 || !(h >= 0 && h <= 23)) return false; + if(p[0].length > 2 || !(h >= 0 && h <= 23)) return false; d += 3600000*h; - if (p.length === 1) return d; + if(p.length === 1) return d; // minute m = Number(p[1]); - if (p[1].length > 2 || !(m >= 0 && m <= 59)) return false; + if(p[1].length > 2 || !(m >= 0 && m <= 59)) return false; d += 60000*m; - if (p.length === 2) return d; + if(p.length === 2) return d; // second s = Number(p[2]); - if (!(s >= 0 && s < 60)) return false; + if(!(s >= 0 && s < 60)) return false; return d+s*1000; }; @@ -270,13 +270,13 @@ function getTimeType(v) { exports.parseDate = function(v) { // is it already a date? just return it - if (v.getTime) return v; + if(v.getTime) return v; /** * otherwise, if it's not a string, return nothing * the case of numbers that just have years will get * dealt with elsewhere. */ - if (typeof v !== 'string') return false; + if(typeof v !== 'string') return false; // first clean up the string a bit to reduce the number of formats we have to test v = v.toLowerCase() @@ -320,13 +320,13 @@ exports.parseDate = function(v) { formatList = dateTimeFormats[dateType][timeType]; len = formatList.length; - for (var i = 0; i < len; i++) { + for(var i = 0; i < len; i++) { out = formatList[i].parse(v); - if (out) break; + if(out) break; } // If not an instance of Date at this point, just return it. - if (!(out instanceof Date)) return false; + if(!(out instanceof Date)) return false; // parse() method interprets arguments with local time zone. var tzoff = out.getTimezoneOffset(); // In general (default) this is not what we want, so force into UTC: diff --git a/src/lib/events.js b/src/lib/events.js index bdbe0268cb6..e4d67a53d90 100644 --- a/src/lib/events.js +++ b/src/lib/events.js @@ -21,7 +21,7 @@ var Events = { * If we have already instantiated an emitter for this plot * return early. */ - if (plotObj._ev instanceof EventEmitter) return plotObj; + if(plotObj._ev instanceof EventEmitter) return plotObj; var ev = new EventEmitter(); @@ -53,7 +53,7 @@ var Events = { * events. */ plotObj.emit = function(event, data) { - if (typeof $ !== 'undefined') { + if(typeof $ !== 'undefined') { $(plotObj).trigger(event, data); } @@ -76,7 +76,7 @@ var Events = { * If Jquery exists run all its handlers for this event and * collect the return value of the LAST handler function */ - if (typeof $ !== 'undefined') { + if(typeof $ !== 'undefined') { jQueryHandlerValue = $(plotObj).triggerHandler(event, data); } @@ -84,21 +84,21 @@ var Events = { * Now run all the node style event handlers */ var ev = plotObj._ev; - if (!ev) return jQueryHandlerValue; + if(!ev) return jQueryHandlerValue; var handlers = ev._events[event]; - if (!handlers) return jQueryHandlerValue; + if(!handlers) return jQueryHandlerValue; /* * handlers can be function or an array of functions */ - if (typeof handlers === 'function') handlers = [handlers]; + if(typeof handlers === 'function') handlers = [handlers]; var lastHandler = handlers.pop(); /* * Call all the handlers except the last one. */ - for (var i = 0; i < handlers.length; i++) { + for(var i = 0; i < handlers.length; i++) { handlers[i](data); } diff --git a/src/lib/index.js b/src/lib/index.js index 961a5ab0cf4..f378e6fc1ea 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -149,9 +149,9 @@ lib.randstr = function randstr(existing, bits, base) { * Include number of bits, the base of the string you want * and an optional array of existing strings to avoid. */ - if (!base) base = 16; - if (bits === undefined) bits = 24; - if (bits <= 0) return '0'; + if(!base) base = 16; + if(bits === undefined) bits = 24; + if(bits <= 0) return '0'; var digits = Math.log(Math.pow(2, bits)) / Math.log(base), res = '', @@ -159,25 +159,25 @@ lib.randstr = function randstr(existing, bits, base) { b, x; - for (i = 2; digits === Infinity; i *= 2) { + for(i = 2; digits === Infinity; i *= 2) { digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i; } var rem = digits - Math.floor(digits); - for (i = 0; i < Math.floor(digits); i++) { + for(i = 0; i < Math.floor(digits); i++) { x = Math.floor(Math.random() * base).toString(base); res = x + res; } - if (rem) { + if(rem) { b = Math.pow(base, rem); x = Math.floor(Math.random() * b).toString(base); res = x + res; } var parsed = parseInt(res, base); - if ((existing && (existing.indexOf(res) > -1)) || + if((existing && (existing.indexOf(res) > -1)) || (parsed !== Infinity && parsed >= Math.pow(2, bits))) { return randstr(existing, bits, base); } @@ -194,8 +194,8 @@ lib.OptionControl = function(opt, optname) { * * See FitOpts for example of usage */ - if (!opt) opt = {}; - if (!optname) optname = 'opt'; + if(!opt) opt = {}; + if(!optname) optname = 'opt'; var self = {}; self.optionList = []; @@ -305,7 +305,7 @@ lib.syncOrAsync = function(sequence, arg, finalStep) { * http://stackoverflow.com/questions/6680825/return-string-without-trailing-slash */ lib.stripTrailingSlash = function(str) { - if (str.substr(-1) === '/') return str.substr(0, str.length - 1); + if(str.substr(-1) === '/') return str.substr(0, str.length - 1); return str; }; diff --git a/src/lib/matrix.js b/src/lib/matrix.js index 23c7e488375..395ea13c3ee 100644 --- a/src/lib/matrix.js +++ b/src/lib/matrix.js @@ -27,12 +27,12 @@ exports.transposeRagged = function(z) { i, j; // Maximum row length: - for (i = 0; i < zlen; i++) maxlen = Math.max(maxlen, z[i].length); + for(i = 0; i < zlen; i++) maxlen = Math.max(maxlen, z[i].length); var t = new Array(maxlen); - for (i = 0; i < maxlen; i++) { + for(i = 0; i < maxlen; i++) { t[i] = new Array(zlen); - for (j = 0; j < zlen; j++) t[i][j] = z[j][i]; + for(j = 0; j < zlen; j++) t[i][j] = z[j][i]; } return t; @@ -40,7 +40,7 @@ exports.transposeRagged = function(z) { // our own dot function so that we don't need to include numeric exports.dot = function(x, y) { - if (!(x.length && y.length) || x.length !== y.length) return null; + if(!(x.length && y.length) || x.length !== y.length) return null; var len = x.length, out, @@ -91,7 +91,7 @@ exports.rotationXYMatrix = function(a, x, y) { exports.apply2DTransform = function(transform) { return function() { var args = arguments; - if (args.length === 3) { + if(args.length === 3) { args = args[0]; }//from map var xy = arguments.length === 1 ? args[0] : [args[0], args[1]]; diff --git a/src/lib/notifier.js b/src/lib/notifier.js index 214824f8da6..a1bfbfcc14f 100644 --- a/src/lib/notifier.js +++ b/src/lib/notifier.js @@ -27,8 +27,8 @@ module.exports = function(text, displayLength) { NOTEDATA.push(text); var ts = 1000; - if (isNumeric(displayLength)) ts = displayLength; - else if (displayLength === 'long') ts = 3000; + if(isNumeric(displayLength)) ts = displayLength; + else if(displayLength === 'long') ts = 3000; var notifierContainer = d3.select('body') .selectAll('.plotly-notifier') diff --git a/src/lib/queue.js b/src/lib/queue.js index 049911b0eed..8ed12237cc9 100644 --- a/src/lib/queue.js +++ b/src/lib/queue.js @@ -66,13 +66,13 @@ queue.add = function(gd, undoFunc, undoArgs, redoFunc, redoArgs) { // if we're already playing an undo or redo, or if this is an auto operation // (like pane resize... any others?) then we don't save this to the undo queue - if (gd.autoplay) { - if (!gd.undoQueue.inSequence) gd.autoplay = false; + if(gd.autoplay) { + if(!gd.undoQueue.inSequence) gd.autoplay = false; return; } // if we're not in a sequence or are just starting, we need a new queue item - if (!gd.undoQueue.sequence || gd.undoQueue.beginSequence) { + if(!gd.undoQueue.sequence || gd.undoQueue.beginSequence) { queueObj = {undo: {calls: [], args: []}, redo: {calls: [], args: []}}; gd.undoQueue.queue.splice(queueIndex, gd.undoQueue.queue.length - queueIndex, queueObj); gd.undoQueue.index += 1; @@ -125,7 +125,7 @@ queue.undo = function undo(gd) { gd.framework.undo(); return; } - if (gd.undoQueue === undefined || + if(gd.undoQueue === undefined || isNaN(gd.undoQueue.index) || gd.undoQueue.index <= 0) { return; @@ -139,7 +139,7 @@ queue.undo = function undo(gd) { // this sequence keeps things from adding to the queue during undo/redo gd.undoQueue.inSequence = true; - for (i = 0; i < queueObj.undo.calls.length; i++) { + for(i = 0; i < queueObj.undo.calls.length; i++) { queue.plotDo(gd, queueObj.undo.calls[i], queueObj.undo.args[i]); } gd.undoQueue.inSequence = false; @@ -158,7 +158,7 @@ queue.redo = function redo(gd) { gd.framework.redo(); return; } - if (gd.undoQueue === undefined || + if(gd.undoQueue === undefined || isNaN(gd.undoQueue.index) || gd.undoQueue.index >= gd.undoQueue.queue.length) { return; @@ -169,7 +169,7 @@ queue.redo = function redo(gd) { // this sequence keeps things from adding to the queue during undo/redo gd.undoQueue.inSequence = true; - for (i = 0; i < queueObj.redo.calls.length; i++) { + for(i = 0; i < queueObj.redo.calls.length; i++) { queue.plotDo(gd, queueObj.redo.calls[i], queueObj.redo.args[i]); } gd.undoQueue.inSequence = false; diff --git a/src/lib/show_no_webgl_msg.js b/src/lib/show_no_webgl_msg.js index 9230a9952b3..203b29e1932 100644 --- a/src/lib/show_no_webgl_msg.js +++ b/src/lib/show_no_webgl_msg.js @@ -23,7 +23,7 @@ var noop = function() {}; */ module.exports = function showWebGlMsg(scene) { for(var prop in scene) { - if (typeof scene[prop] === 'function') scene[prop] = noop; + if(typeof scene[prop] === 'function') scene[prop] = noop; } scene.destroy = function() { diff --git a/src/lib/stats.js b/src/lib/stats.js index cd2cf531b75..a827ab1e8df 100644 --- a/src/lib/stats.js +++ b/src/lib/stats.js @@ -28,17 +28,17 @@ var isNumeric = require('fast-isnumeric'); exports.aggNums = function(f, v, a, len) { var i, b; - if (!len) len = a.length; - if (!isNumeric(v)) v = false; - if (Array.isArray(a[0])) { + if(!len) len = a.length; + if(!isNumeric(v)) v = false; + if(Array.isArray(a[0])) { b = new Array(len); for(i = 0; i < len; i++) b[i] = exports.aggNums(f, v, a[i]); a = b; } - for (i = 0; i < len; i++) { - if (!isNumeric(v)) v = a[i]; - else if (isNumeric(a[i])) v = f(+v, +a[i]); + for(i = 0; i < len; i++) { + if(!isNumeric(v)) v = a[i]; + else if(isNumeric(a[i])) v = f(+v, +a[i]); } return v; }; @@ -57,8 +57,8 @@ exports.mean = function(data, len) { }; exports.variance = function(data, len, mean) { - if (!len) len = exports.len(data); - if (!isNumeric(mean)) mean = exports.mean(data, len); + if(!len) len = exports.len(data); + if(!isNumeric(mean)) mean = exports.mean(data, len); return exports.aggNums(function(a, b) { return a + Math.pow(b - mean, 2); @@ -85,10 +85,10 @@ exports.stdev = function(data, len, mean) { * @return {Number} - percentile */ exports.interp = function(arr, n) { - if (!isNumeric(n)) throw 'n should be a finite number'; + if(!isNumeric(n)) throw 'n should be a finite number'; n = n * arr.length - 0.5; - if (n < 0) return arr[0]; - if (n > arr.length - 1) return arr[arr.length - 1]; + if(n < 0) return arr[0]; + if(n > arr.length - 1) return arr[arr.length - 1]; var frac = n % 1; return frac * arr[Math.ceil(n)] + (1 - frac) * arr[Math.floor(n)]; }; diff --git a/src/lib/svg_text_utils.js b/src/lib/svg_text_utils.js index cd5f674198f..021843fd599 100644 --- a/src/lib/svg_text_utils.js +++ b/src/lib/svg_text_utils.js @@ -35,7 +35,7 @@ d3.selection.prototype.appendSVG = function(_svgString) { this.node().appendChild(this.node().ownerDocument.importNode(childNode, true)); childNode = childNode.nextSibling; } - if (dom.querySelector('parsererror')){ + if(dom.querySelector('parsererror')){ console.log(dom.querySelector('parsererror div').textContent); return null; } @@ -297,13 +297,13 @@ function convertToSVG(_str){ return tspanStart + (style ? ' style="' + style + '"' : '') + '>'; } } - else{ + else { return Plotly.util.xml_entity_encode(d).replace(/'); index > 0; index = result.indexOf('
', index+1)){ + for(var index = result.indexOf('
'); index > 0; index = result.indexOf('
', index+1)){ indices.push(index); } var count = 0; @@ -463,7 +463,7 @@ util.makeEditable = function(context, _delegate, options){ .transition().remove(); dispatch.cancel.call(that, this.textContent); } - else{ + else { dispatch.input.call(that, this.textContent); d3.select(this).call(alignHTMLWith(that, container, options)); } diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 4ad40b86d18..6782837d611 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -650,7 +650,7 @@ axes.autoTicks = function(ax, roughDTick){ ax.tick0 = 0; ax.dtick = Math.ceil(Math.max(roughDTick, 1)); } - else{ + else { // auto ticks always start at 0 ax.tick0 = 0; base = Math.pow(10, Math.floor(Math.log(roughDTick) / Math.LN10)); @@ -858,8 +858,8 @@ axes.tickText = function(ax, x, hover){ function isHidden(showAttr) { var first_or_last; - if (showAttr===undefined) return true; - if (hover) return showAttr==='none'; + if(showAttr === undefined) return true; + if(hover) return showAttr==='none'; first_or_last = { first: ax._tmin, @@ -877,8 +877,8 @@ axes.tickText = function(ax, x, hover){ else formatLinear(ax, out, hover, extraPrecision, hideexp); // add prefix and suffix - if (ax.tickprefix && !isHidden(ax.showtickprefix)) out.text = ax.tickprefix + out.text; - if (ax.ticksuffix && !isHidden(ax.showticksuffix)) out.text += ax.ticksuffix; + if(ax.tickprefix && !isHidden(ax.showtickprefix)) out.text = ax.tickprefix + out.text; + if(ax.ticksuffix && !isHidden(ax.showticksuffix)) out.text += ax.ticksuffix; return out; }; @@ -1135,7 +1135,7 @@ function numSeparate(nStr, separators) { // even if there is a thousands separator, don't use it on // 4-digit integers (like years) if(thou && (x.length > 1 || x1.length>4)) { - while (findThousands.test(x1)) { + while(findThousands.test(x1)) { x1 = x1.replace(findThousands, '$1' + thou + '$2'); } } diff --git a/src/plots/cartesian/clean_datum.js b/src/plots/cartesian/clean_datum.js index e4e32b92cea..c8d58535204 100644 --- a/src/plots/cartesian/clean_datum.js +++ b/src/plots/cartesian/clean_datum.js @@ -20,7 +20,7 @@ var Lib = require('../../lib'); * but also handling dates, numbers, and NaN, null, Infinity etc */ module.exports = function cleanDatum(c) { - try{ + try { if(typeof c === 'object' && c !== null && c.getTime) { return Lib.ms2DateTime(c); } diff --git a/src/plots/cartesian/set_convert.js b/src/plots/cartesian/set_convert.js index 2070dc30cb6..043c35a1629 100644 --- a/src/plots/cartesian/set_convert.js +++ b/src/plots/cartesian/set_convert.js @@ -69,7 +69,7 @@ module.exports = function setConvert(ax) { i; // TODO cleaner way to handle this case - if (!ax._categories) ax._categories = []; + if(!ax._categories) ax._categories = []; // make sure we have a domain (pull it in from the axis // this one is overlaying if necessary) @@ -112,7 +112,7 @@ module.exports = function setConvert(ax) { ax._b = -ax._m*ax.range[0]; } - if (!isFinite(ax._m) || !isFinite(ax._b)) { + if(!isFinite(ax._m) || !isFinite(ax._b)) { Lib.notifier( 'Something went wrong with axis scaling', 'long'); @@ -140,7 +140,7 @@ module.exports = function setConvert(ax) { return isNumeric(v) ? Number(v) : constants.BADNUM; }; ax.d2l = function(v, clip) { - if (ax.type === 'log') return ax.c2l(ax.d2c(v), clip); + if(ax.type === 'log') return ax.c2l(ax.d2c(v), clip); else return ax.d2c(v); }; } diff --git a/src/plots/cartesian/tick_defaults.js b/src/plots/cartesian/tick_defaults.js index e3b079e5c35..5479397daa5 100644 --- a/src/plots/cartesian/tick_defaults.js +++ b/src/plots/cartesian/tick_defaults.js @@ -78,7 +78,8 @@ function getShowAttrDflt(containerIn) { sameVal = function(a){ return containerIn[a]===containerIn[showAttrs[0]]; }; - if (showAttrs.every(sameVal) || showAttrs.length===1) { + + if(showAttrs.every(sameVal) || showAttrs.length===1) { return containerIn[showAttrs[0]]; } } diff --git a/src/plots/geo/zoom.js b/src/plots/geo/zoom.js index cb22a05cbc2..b52f4a4ca65 100644 --- a/src/plots/geo/zoom.js +++ b/src/plots/geo/zoom.js @@ -218,7 +218,7 @@ function zoomClipped(geo, projLayout) { }); function zoomstarted(dispatch) { - if (!zooming++) dispatch({type: 'zoomstart'}); + if(!zooming++) dispatch({type: 'zoomstart'}); } function zoomed(dispatch) { @@ -226,7 +226,7 @@ function zoomClipped(geo, projLayout) { } function zoomended(dispatch) { - if (!--zooming) dispatch({type: 'zoomend'}); + if(!--zooming) dispatch({type: 'zoomend'}); } return d3.rebind(zoom, event, 'on'); @@ -266,7 +266,7 @@ function multiply(a, b) { } function rotateBetween(a, b) { - if (!a || !b) return; + if(!a || !b) return; var axis = cross(a, b), norm = Math.sqrt(dot(axis, axis)), halfgamma = 0.5 * Math.acos(Math.max(-1, Math.min(1, dot(a, b)))), @@ -373,7 +373,7 @@ function cartesian(spherical) { function dot(a, b) { var s = 0; - for (var i = 0, n = a.length; i < n; ++i) s += a[i] * b[i]; + for(var i = 0, n = a.length; i < n; ++i) s += a[i] * b[i]; return s; } @@ -394,7 +394,7 @@ function d3_eventDispatch(target) { n = arguments.length, argumentz = []; - while (++i < n) argumentz.push(arguments[i]); + while(++i < n) argumentz.push(arguments[i]); var dispatch = d3.dispatch.apply(null, argumentz); diff --git a/src/plots/gl2d/scene2d.js b/src/plots/gl2d/scene2d.js index 37440e9d8e6..0cc7ddb847b 100644 --- a/src/plots/gl2d/scene2d.js +++ b/src/plots/gl2d/scene2d.js @@ -201,7 +201,7 @@ proto.toImage = function(format) { var dataURL; - switch (format) { + switch(format) { case 'jpeg': dataURL = canvas.toDataURL('image/jpeg'); break; diff --git a/src/plots/gl3d/index.js b/src/plots/gl3d/index.js index 19dba4b1953..032b0714e30 100644 --- a/src/plots/gl3d/index.js +++ b/src/plots/gl3d/index.js @@ -81,10 +81,10 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) // clean scene ids, 'scene1' -> 'scene' exports.cleanId = function cleanId(id) { - if (!id.match(/^scene[0-9]*$/)) return; + if(!id.match(/^scene[0-9]*$/)) return; var sceneNum = id.substr(5); - if (sceneNum === '1') sceneNum = ''; + if(sceneNum === '1') sceneNum = ''; return 'scene' + sceneNum; }; diff --git a/src/plots/gl3d/layout/axis_defaults.js b/src/plots/gl3d/layout/axis_defaults.js index 7abad5d2edd..c0473aefbf4 100644 --- a/src/plots/gl3d/layout/axis_defaults.js +++ b/src/plots/gl3d/layout/axis_defaults.js @@ -24,7 +24,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, options) { return Lib.coerce(containerIn, containerOut, layoutAttributes, attr, dflt); } - for (var j = 0; j < axesNames.length; j++) { + for(var j = 0; j < axesNames.length; j++) { var axName = axesNames[j]; containerIn = layoutIn[axName] || {}; @@ -48,12 +48,12 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, options) { containerOut.setScale = noop; - if (coerce('showspikes')) { + if(coerce('showspikes')) { coerce('spikesides'); coerce('spikethickness'); coerce('spikecolor'); } - if (coerce('showbackground')) coerce('backgroundcolor'); + if(coerce('showbackground')) coerce('backgroundcolor'); coerce('showaxeslabels'); } diff --git a/src/plots/gl3d/layout/convert.js b/src/plots/gl3d/layout/convert.js index d598ec1672e..8c7ba11955a 100644 --- a/src/plots/gl3d/layout/convert.js +++ b/src/plots/gl3d/layout/convert.js @@ -73,61 +73,61 @@ var proto = AxesOptions.prototype; proto.merge = function(sceneLayout) { var opts = this; - for (var i = 0; i < 3; ++i) { + for(var i = 0; i < 3; ++i) { var axes = sceneLayout[AXES_NAMES[i]]; /////// Axes labels // opts.labels[i] = convertHTML(axes.title); - if ('titlefont' in axes) { - if (axes.titlefont.color) opts.labelColor[i] = str2RgbaArray(axes.titlefont.color); - if (axes.titlefont.family) opts.labelFont[i] = axes.titlefont.family; - if (axes.titlefont.size) opts.labelSize[i] = axes.titlefont.size; + if('titlefont' in axes) { + if(axes.titlefont.color) opts.labelColor[i] = str2RgbaArray(axes.titlefont.color); + if(axes.titlefont.family) opts.labelFont[i] = axes.titlefont.family; + if(axes.titlefont.size) opts.labelSize[i] = axes.titlefont.size; } /////// LINES //////// - if ('showline' in axes) opts.lineEnable[i] = axes.showline; - if ('linecolor' in axes) opts.lineColor[i] = str2RgbaArray(axes.linecolor); - if ('linewidth' in axes) opts.lineWidth[i] = axes.linewidth; + if('showline' in axes) opts.lineEnable[i] = axes.showline; + if('linecolor' in axes) opts.lineColor[i] = str2RgbaArray(axes.linecolor); + if('linewidth' in axes) opts.lineWidth[i] = axes.linewidth; - if ('showgrid' in axes) opts.gridEnable[i] = axes.showgrid; - if ('gridcolor' in axes) opts.gridColor[i] = str2RgbaArray(axes.gridcolor); - if ('gridwidth' in axes) opts.gridWidth[i] = axes.gridwidth; + if('showgrid' in axes) opts.gridEnable[i] = axes.showgrid; + if('gridcolor' in axes) opts.gridColor[i] = str2RgbaArray(axes.gridcolor); + if('gridwidth' in axes) opts.gridWidth[i] = axes.gridwidth; // Remove zeroline if axis type is log // otherwise the zeroline is incorrectly drawn at 1 on log axes - if (axes.type === 'log') opts.zeroEnable[i] = false; - else if ('zeroline' in axes) opts.zeroEnable[i] = axes.zeroline; - if ('zerolinecolor' in axes) opts.zeroLineColor[i] = str2RgbaArray(axes.zerolinecolor); - if ('zerolinewidth' in axes) opts.zeroLineWidth[i] = axes.zerolinewidth; + if(axes.type === 'log') opts.zeroEnable[i] = false; + else if('zeroline' in axes) opts.zeroEnable[i] = axes.zeroline; + if('zerolinecolor' in axes) opts.zeroLineColor[i] = str2RgbaArray(axes.zerolinecolor); + if('zerolinewidth' in axes) opts.zeroLineWidth[i] = axes.zerolinewidth; //////// TICKS ///////// /// tick lines - if ('ticks' in axes && !!axes.ticks) opts.lineTickEnable[i] = true; + if('ticks' in axes && !!axes.ticks) opts.lineTickEnable[i] = true; else opts.lineTickEnable[i] = false; - if ('ticklen' in axes) { + if('ticklen' in axes) { opts.lineTickLength[i] = opts._defaultLineTickLength[i] = axes.ticklen; } - if ('tickcolor' in axes) opts.lineTickColor[i] = str2RgbaArray(axes.tickcolor); - if ('tickwidth' in axes) opts.lineTickWidth[i] = axes.tickwidth; - if ('tickangle' in axes) { + if('tickcolor' in axes) opts.lineTickColor[i] = str2RgbaArray(axes.tickcolor); + if('tickwidth' in axes) opts.lineTickWidth[i] = axes.tickwidth; + if('tickangle' in axes) { opts.tickAngle[i] = (axes.tickangle === 'auto') ? 0 : Math.PI * -axes.tickangle / 180; } - //// tick labels - if ('showticklabels' in axes) opts.tickEnable[i] = axes.showticklabels; - if ('tickfont' in axes) { - if (axes.tickfont.color) opts.tickColor[i] = str2RgbaArray(axes.tickfont.color); - if (axes.tickfont.family) opts.tickFont[i] = axes.tickfont.family; - if (axes.tickfont.size) opts.tickSize[i] = axes.tickfont.size; + // tick labels + if('showticklabels' in axes) opts.tickEnable[i] = axes.showticklabels; + if('tickfont' in axes) { + if(axes.tickfont.color) opts.tickColor[i] = str2RgbaArray(axes.tickfont.color); + if(axes.tickfont.family) opts.tickFont[i] = axes.tickfont.family; + if(axes.tickfont.size) opts.tickSize[i] = axes.tickfont.size; } - if ('mirror' in axes) { - if (['ticks','all','allticks'].indexOf(axes.mirror) !== -1) { + if('mirror' in axes) { + if(['ticks','all','allticks'].indexOf(axes.mirror) !== -1) { opts.lineTickMirror[i] = true; opts.lineMirror[i] = true; - } else if (axes.mirror === true) { + } else if(axes.mirror === true) { opts.lineTickMirror[i] = false; opts.lineMirror[i] = true; } else { @@ -136,8 +136,8 @@ proto.merge = function(sceneLayout) { } } else opts.lineMirror[i] = false; - ////// grid background - if ('showbackground' in axes && axes.showbackground !== false) { + // grid background + if('showbackground' in axes && axes.showbackground !== false) { opts.backgroundEnable[i] = true; opts.backgroundColor[i] = str2RgbaArray(axes.backgroundcolor); } else opts.backgroundEnable[i] = false; diff --git a/src/plots/gl3d/layout/spikes.js b/src/plots/gl3d/layout/spikes.js index fc0df7bcc2d..507e17b8a7f 100644 --- a/src/plots/gl3d/layout/spikes.js +++ b/src/plots/gl3d/layout/spikes.js @@ -25,7 +25,7 @@ function SpikeOptions() { var proto = SpikeOptions.prototype; proto.merge = function(sceneLayout) { - for (var i = 0; i < 3; ++i) { + for(var i = 0; i < 3; ++i) { var axes = sceneLayout[AXES_NAMES[i]]; this.enabled[i] = axes.showspikes; diff --git a/src/plots/gl3d/layout/tick_marks.js b/src/plots/gl3d/layout/tick_marks.js index 3b84aebeed9..fec14bf0b67 100644 --- a/src/plots/gl3d/layout/tick_marks.js +++ b/src/plots/gl3d/layout/tick_marks.js @@ -40,13 +40,13 @@ function computeTickMarks(scene) { var ticks = [[],[],[]]; - for (var i = 0; i < 3; ++i) { + for(var i = 0; i < 3; ++i) { var axes = sceneLayout[AXES_NAMES[i]]; axes._length = (glRange[i].hi - glRange[i].lo) * glRange[i].pixelsPerDataUnit / scene.dataScale[i]; - if (Math.abs(axes._length) === Infinity) { + if(Math.abs(axes._length) === Infinity) { ticks[i] = []; } else { axes.range[0] = (glRange[i].lo) / scene.dataScale[i]; @@ -62,7 +62,7 @@ function computeTickMarks(scene) { // running the autoticks here, then setting // autoticks to false to get around the 2D handling in calcTicks. var tickModeCached = axes.tickmode; - if (axes.tickmode === 'auto') { + if(axes.tickmode === 'auto') { axes.tickmode = 'linear'; var nticks = axes.nticks || Plotly.Lib.constrain((axes._length/40), 4, 9); Plotly.Axes.autoTicks(axes, Math.abs(axes.range[1]-axes.range[0])/nticks); diff --git a/src/snapshot/cloneplot.js b/src/snapshot/cloneplot.js index 7678bcdf602..b7ac366017b 100644 --- a/src/snapshot/cloneplot.js +++ b/src/snapshot/cloneplot.js @@ -18,7 +18,7 @@ var extendDeep = Plotly.Lib.extendDeep; function cloneLayoutOverride(tileClass) { var override; - switch (tileClass) { + switch(tileClass) { case 'themes__thumb': override = { autosize: true, @@ -60,7 +60,7 @@ function keyIsAxis(keyName) { module.exports = function clonePlot(graphObj, options) { // Polar plot compatibility - if (graphObj.framework && graphObj.framework.isPolar) { + if(graphObj.framework && graphObj.framework.isPolar) { graphObj = graphObj.framework.getConfig(); } @@ -70,22 +70,22 @@ module.exports = function clonePlot(graphObj, options) { var newData = extendDeep([], oldData); var newLayout = extendDeep({}, oldLayout, cloneLayoutOverride(options.tileClass)); - if (options.width) newLayout.width = options.width; - if (options.height) newLayout.height = options.height; + if(options.width) newLayout.width = options.width; + if(options.height) newLayout.height = options.height; - if (options.tileClass === 'thumbnail' || options.tileClass === 'themes__thumb') { + if(options.tileClass === 'thumbnail' || options.tileClass === 'themes__thumb') { // kill annotations newLayout.annotations = []; var keys = Object.keys(newLayout); - for (i = 0; i < keys.length; i++) { - if (keyIsAxis(keys[i])) { + for(i = 0; i < keys.length; i++) { + if(keyIsAxis(keys[i])) { newLayout[keys[i]].title = ''; } } // kill colorbar and pie labels - for (i = 0; i < newData.length; i++) { + for(i = 0; i < newData.length; i++) { var trace = newData[i]; trace.showscale = false; if(trace.marker) trace.marker.showscale = false; @@ -93,17 +93,17 @@ module.exports = function clonePlot(graphObj, options) { } } - if (Array.isArray(options.annotations)) { - for (i = 0; i < options.annotations.length; i++) { + if(Array.isArray(options.annotations)) { + for(i = 0; i < options.annotations.length; i++) { newLayout.annotations.push(options.annotations[i]); } } var sceneIds = Plotly.Plots.getSubplotIds(newLayout, 'gl3d'); - if (sceneIds.length) { + if(sceneIds.length) { var axesImageOverride = {}; - if (options.tileClass === 'thumbnail') { + if(options.tileClass === 'thumbnail') { axesImageOverride = { title: '', showaxeslabels: false, @@ -111,7 +111,7 @@ module.exports = function clonePlot(graphObj, options) { linetickenable: false }; } - for (i = 0; i < sceneIds.length; i++) { + for(i = 0; i < sceneIds.length; i++) { var sceneId = sceneIds[i]; extendFlat(newLayout[sceneId].xaxis, axesImageOverride); @@ -124,7 +124,7 @@ module.exports = function clonePlot(graphObj, options) { } var td = document.createElement('div'); - if (options.tileClass) td.className = options.tileClass; + if(options.tileClass) td.className = options.tileClass; var plotTile = { td: td, @@ -143,7 +143,7 @@ module.exports = function clonePlot(graphObj, options) { } }; - if (options.setBackground !== 'transparent') { + if(options.setBackground !== 'transparent') { plotTile.config.setBackground = options.setBackground || 'opaque'; } diff --git a/src/snapshot/svgtoimg.js b/src/snapshot/svgtoimg.js index d2a055f6f0c..8dc868cb937 100644 --- a/src/snapshot/svgtoimg.js +++ b/src/snapshot/svgtoimg.js @@ -37,7 +37,7 @@ function svgToImg(opts) { DOMURL.revokeObjectURL(url); ctx.drawImage(img, 0, 0); - switch (format) { + switch(format) { case 'jpeg': imgData = canvas.toDataURL('image/jpeg'); break; diff --git a/src/snapshot/toimage.js b/src/snapshot/toimage.js index 5184b60818d..5eac155d5af 100644 --- a/src/snapshot/toimage.js +++ b/src/snapshot/toimage.js @@ -57,7 +57,7 @@ function toImage(gd, opts) { }); ev.clean = function() { - if (clonedGd) clonedGd.remove(); + if(clonedGd) clonedGd.remove(); }; }, delay); diff --git a/src/traces/box/calc.js b/src/traces/box/calc.js index 69df8d435ae..641df5c8792 100644 --- a/src/traces/box/calc.js +++ b/src/traces/box/calc.js @@ -24,7 +24,7 @@ module.exports = function calc(gd, trace) { posAxis, posLetter, pos, posDistinct, dPos; // Set value (val) and position (pos) keys via orientation - if (orientation==='h') { + if(orientation==='h') { valAxis = xa; valLetter = 'x'; posAxis = ya; @@ -49,10 +49,10 @@ module.exports = function calc(gd, trace) { // (or set x (y) to a constant array matching y (x)) function getPos(gd, trace, posLetter, posAxis, val) { var pos0; - if (posLetter in trace) pos = posAxis.makeCalcdata(trace, posLetter); + if(posLetter in trace) pos = posAxis.makeCalcdata(trace, posLetter); else { - if (posLetter+'0' in trace) pos0 = trace[posLetter+'0']; - else if ('name' in trace && ( + if(posLetter+'0' in trace) pos0 = trace[posLetter+'0']; + else if('name' in trace && ( posAxis.type==='category' || (isNumeric(trace.name) && ['linear','log'].indexOf(posAxis.type)!==-1) || @@ -83,7 +83,7 @@ module.exports = function calc(gd, trace) { i, p, n, v; // store distinct pos in cd, find bins, init. valBinned - for (i = 0; i < posDistinctLength; ++i) { + for(i = 0; i < posDistinctLength; ++i) { p = posDistinct[i]; cd[i] = {pos: p}; bins[i] = p - dPos; @@ -92,7 +92,7 @@ module.exports = function calc(gd, trace) { bins.push(posDistinct[posDistinctLength-1] + dPos); // bin the values - for (i = 0; i < valLength; ++i) { + for(i = 0; i < valLength; ++i) { v = val[i]; if(!isNumeric(v)) continue; n = Lib.findBin(pos[i], bins); @@ -108,7 +108,7 @@ module.exports = function calc(gd, trace) { function calculateStats(cd, valBinned) { var v, l, cdi, i; - for (i = 0; i < valBinned.length; ++i) { + for(i = 0; i < valBinned.length; ++i) { v = valBinned[i].sort(Lib.sorterAsc); l = v.length; cdi = cd[i]; diff --git a/src/traces/box/defaults.js b/src/traces/box/defaults.js index 10c14e99233..33d7f53fd1e 100644 --- a/src/traces/box/defaults.js +++ b/src/traces/box/defaults.js @@ -22,10 +22,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor) { x = coerce('x'), defaultOrientation; - if (y && y.length) { + if(y && y.length) { defaultOrientation = 'v'; - if (!x) coerce('x0'); - } else if (x && x.length) { + if(!x) coerce('x0'); + } else if(x && x.length) { defaultOrientation = 'h'; coerce('y0'); } else { diff --git a/src/traces/box/hover.js b/src/traces/box/hover.js index b22dd70c2f4..236e08facf6 100644 --- a/src/traces/box/hover.js +++ b/src/traces/box/hover.js @@ -28,7 +28,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { // adjust inbox w.r.t. to calculate box size boxDelta = (hovermode==='closest') ? 2.5*t.bdPos : t.bdPos; - if (trace.orientation==='h') { + if(trace.orientation === 'h') { dx = function(di){ return Fx.inbox(di.min - xval, di.max - xval); }; @@ -84,7 +84,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { if(trace.boxmean) attrs.push('mean'); if(trace.boxpoints) [].push.apply(attrs,['lf', 'uf']); - for (var i=0; i Date: Mon, 29 Feb 2016 14:52:10 -0500 Subject: [PATCH 4/5] enforce space-before-blocks, - so that: if() { / for() { and function() { not: if(){ / for(){ and function(){ are the norm --- .eslintrc | 1 + src/components/annotations/index.js | 20 +++---- src/components/color/index.js | 2 +- src/components/colorbar/draw.js | 14 ++--- src/components/drawing/index.js | 14 ++--- src/components/errorbars/index.js | 12 ++-- src/components/legend/index.js | 36 ++++++------ src/components/titles/index.js | 12 ++-- src/fonts/mathjax_config.js | 2 +- src/lib/dates.js | 4 +- src/lib/index.js | 10 ++-- src/lib/queue.js | 4 +- src/lib/search.js | 6 +- src/lib/stats.js | 4 +- src/lib/svg_text_utils.js | 74 ++++++++++++------------- src/plot_api/plot_api.js | 12 ++-- src/plot_api/plot_schema.js | 2 +- src/plotly.js | 10 ++-- src/plots/cartesian/axes.js | 72 ++++++++++++------------ src/plots/cartesian/axis_defaults.js | 2 +- src/plots/cartesian/graph_interact.js | 58 +++++++++---------- src/plots/cartesian/layout_defaults.js | 2 +- src/plots/cartesian/select.js | 2 +- src/plots/cartesian/set_convert.js | 16 +++--- src/plots/cartesian/tick_defaults.js | 6 +- src/plots/plots.js | 14 ++--- src/plots/polar/micropolar_manager.js | 24 ++++---- src/plots/polar/undo_manager.js | 22 ++++---- src/traces/bar/hover.js | 8 +-- src/traces/bar/plot.js | 4 +- src/traces/bar/set_positions.js | 16 +++--- src/traces/bar/style.js | 6 +- src/traces/box/hover.js | 8 +-- src/traces/box/plot.js | 16 +++--- src/traces/box/style.js | 2 +- src/traces/contour/colorbar.js | 8 +-- src/traces/contour/plot.js | 12 ++-- src/traces/contour/style.js | 6 +- src/traces/heatmap/colorbar.js | 6 +- src/traces/heatmap/plot.js | 8 +-- src/traces/histogram2d/calc.js | 4 +- src/traces/scatter/colorbar.js | 6 +- src/traces/scatter/plot.js | 4 +- src/traces/scatter/style.js | 2 +- src/traces/scattergeo/plot.js | 2 +- tasks/header.js | 2 +- test/jasmine/assets/custom_matchers.js | 4 +- test/jasmine/tests/click_test.js | 6 +- test/jasmine/tests/lib_test.js | 2 +- test/jasmine/tests/plot_promise_test.js | 34 ++++++------ 50 files changed, 312 insertions(+), 311 deletions(-) diff --git a/.eslintrc b/.eslintrc index bbf234f284b..8279363a134 100644 --- a/.eslintrc +++ b/.eslintrc @@ -30,6 +30,7 @@ "no-spaced-func": [2], "space-in-parens": [2, "never"], "space-before-function-paren": [2, "never"], + "space-before-blocks": [2], "no-multi-spaces": [2], "space-infix-ops": [0, {"int32Hint": false}], "quotes": [2, "single"], diff --git a/src/components/annotations/index.js b/src/components/annotations/index.js index a8dc8cf0786..f033d3265f7 100644 --- a/src/components/annotations/index.js +++ b/src/components/annotations/index.js @@ -363,7 +363,7 @@ annotations.draw = function(gd, index, opt, value) { .attr('data-unformatted', options.text) .text(options.text); - function textLayout(s){ + function textLayout(s) { s.call(Plotly.Drawing.font, font) .attr({ 'text-anchor': { @@ -375,7 +375,7 @@ annotations.draw = function(gd, index, opt, value) { return s; } - function drawGraphicalElements(){ + function drawGraphicalElements() { // make sure lines are aligned the way they will be // at the end, even if their position changes @@ -395,8 +395,8 @@ annotations.draw = function(gd, index, opt, value) { options._w = annwidth; options._h = annheight; - function shiftFraction(v, anchor){ - if(anchor==='auto'){ + function shiftFraction(v, anchor) { + if(anchor==='auto') { if(v < 1/3) anchor = 'left'; else if(v > 2/3) anchor = 'right'; else anchor = 'center'; @@ -469,7 +469,7 @@ annotations.draw = function(gd, index, opt, value) { // make sure the arrowhead (if there is one) // and the annotation center are visible - if(options.showarrow){ + if(options.showarrow) { arrowX = Plotly.Lib.constrain(annPosPx.x - options.ax, 1, fullLayout.width - 1); arrowY = Plotly.Lib.constrain(annPosPx.y - options.ay, 1, fullLayout.height - 1); } @@ -498,7 +498,7 @@ annotations.draw = function(gd, index, opt, value) { // add the arrow // uses options[arrowwidth,arrowcolor,arrowhead] for styling - var drawArrow = function(dx, dy){ + var drawArrow = function(dx, dy) { d3.select(gd) .selectAll('.annotation-arrow-g[data-index="' + index + '"]') .remove(); @@ -541,7 +541,7 @@ annotations.draw = function(gd, index, opt, value) { return; } - edges.forEach(function(x){ + edges.forEach(function(x) { var p = lineIntersect(arrowX0, arrowY0, arrowX, arrowY, x[0], x[1], x[2], x[3]); if(p) { @@ -711,7 +711,7 @@ annotations.draw = function(gd, index, opt, value) { if(gd._context.editable) { anntext.call(Plotly.util.makeEditable, ann) .call(textLayout) - .on('edit', function(_text){ + .on('edit', function(_text) { options.text = _text; this.attr({'data-unformatted': options.text}); this.call(textLayout); @@ -839,7 +839,7 @@ annotations.calcAutorange = function(gd) { if(!annotationList.length || !gd._fullData.length) return; var annotationAxes = {}; - annotationList.forEach(function(ann){ + annotationList.forEach(function(ann) { annotationAxes[ann.xref] = true; annotationAxes[ann.yref] = true; }); @@ -863,7 +863,7 @@ function annAutorange(gd) { // relative to their anchor points // use the arrow and the text bg rectangle, // as the whole anno may include hidden text in its bbox - fullLayout.annotations.forEach(function(ann){ + fullLayout.annotations.forEach(function(ann) { var xa = Plotly.Axes.getFromId(gd, ann.xref), ya = Plotly.Axes.getFromId(gd, ann.yref); if(!(xa || ya)) return; diff --git a/src/components/color/index.js b/src/components/color/index.js index 92cb8370ff7..655c514652a 100644 --- a/src/components/color/index.js +++ b/src/components/color/index.js @@ -39,7 +39,7 @@ color.addOpacity = function(cstr, op) { // combine two colors into one apparent color // if back has transparency or is missing, // color.background is assumed behind it -color.combine = function(front, back){ +color.combine = function(front, back) { var fc = tinycolor(front).toRgb(); if(fc.a===1) return tinycolor(front).toRgbString(); diff --git a/src/components/colorbar/draw.js b/src/components/colorbar/draw.js index 10e3f5e8702..8dc4545accf 100644 --- a/src/components/colorbar/draw.js +++ b/src/components/colorbar/draw.js @@ -50,7 +50,7 @@ module.exports = function draw(gd, id) { // evaluated halfway between levels opts.filllevels = null; - function component(){ + function component() { var fullLayout = gd._fullLayout; if((typeof opts.fillcolor !== 'function') && (typeof opts.line.color !== 'function')) { @@ -63,9 +63,9 @@ module.exports = function draw(gd, id) { filllevels = [], l, linecolormap = typeof opts.line.color === 'function' ? - opts.line.color : function(){ return opts.line.color; }, + opts.line.color : function() { return opts.line.color; }, fillcolormap = typeof opts.fillcolor === 'function' ? - opts.fillcolor : function(){ return opts.fillcolor; }; + opts.fillcolor : function() { return opts.fillcolor; }; var l0 = opts.levels.end + opts.levels.size/100, ls = opts.levels.size, @@ -84,7 +84,7 @@ module.exports = function draw(gd, id) { } } else { - filllevels = linelevels.map(function(v){ + filllevels = linelevels.map(function(v) { return v-opts.levels.size / 2; }); filllevels.push(filllevels[filllevels.length - 1] + @@ -233,7 +233,7 @@ module.exports = function draw(gd, id) { // now draw the elements var container = fullLayout._infolayer.selectAll('g.'+id).data([0]); container.enter().append('g').classed(id,true) - .each(function(){ + .each(function() { var s = d3.select(this); s.append('rect').classed('cbbg',true); s.append('g').classed('cbfills',true); @@ -260,7 +260,7 @@ module.exports = function draw(gd, id) { Titles.draw(gd, cbAxisOut._id + 'title'); } - function drawAxis(){ + function drawAxis() { if(['top','bottom'].indexOf(opts.titleside)!==-1) { // squish the axis top to make room for the title var titleGroup = container.select('.cbtitle'), @@ -373,7 +373,7 @@ module.exports = function draw(gd, id) { return Axes.doTicks(gd, cbAxisOut); } - function positionCB(){ + function positionCB() { // wait for the axis & title to finish rendering before // continuing positioning // TODO: why are we redrawing multiple times now with this? diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index e9227fab2b8..135e24dd2b4 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -41,8 +41,8 @@ drawing.setRect = function(s, x, y, w, h) { s.call(drawing.setPosition, x, y).call(drawing.setSize, w, h); }; -drawing.translatePoints = function(s, xa, ya){ - s.each(function(d){ +drawing.translatePoints = function(s, xa, ya) { + s.each(function(d) { // put xp and yp into d if pixel scaling is already done var x = d.xp || xa.c2p(d.x), y = d.yp || ya.c2p(d.y), @@ -77,7 +77,7 @@ drawing.crispRound = function(td, lineWidth, dflt) { drawing.lineGroupStyle = function(s, lw, lc, ld) { s.style('fill','none') - .each(function(d){ + .each(function(d) { var line = (((d||[])[0]||{}).trace||{}).line||{}, lw1 = lw||line.width||0, dash = ld||line.dash||''; @@ -111,7 +111,7 @@ drawing.dashLine = function(s, dash, lineWidth) { drawing.fillGroupStyle = function(s) { s.style('stroke-width',0) - .each(function(d){ + .each(function(d) { var shape = d3.select(this); try { shape.call(Plotly.Color.fill, d[0].trace.fillcolor); @@ -203,7 +203,7 @@ drawing.pointStyle = function(s, trace) { return drawing.symbolFuncs[xBase](r) + (x >= 200 ? DOTPATH : ''); }) - .style('opacity',function(d){ + .style('opacity',function(d) { return (d.mo+1 || marker.opacity+1) - 1; }); } @@ -213,7 +213,7 @@ drawing.pointStyle = function(s, trace) { markerScale = drawing.tryColorscale(marker, markerIn, ''), lineScale = drawing.tryColorscale(marker, markerIn, 'line.'); - s.each(function(d){ + s.each(function(d) { // 'so' is suspected outliers, for box plots var fillColor, lineColor, @@ -299,7 +299,7 @@ drawing.tryColorscale = function(cont, contIn, prefix) { var TEXTOFFSETSIGN = {start: 1, end: -1, middle: 0, bottom: 1, top: -1}, LINEEXPAND = 1.3; drawing.textPointStyle = function(s, trace) { - s.each(function(d){ + s.each(function(d) { var p = d3.select(this), text = d.tx || trace.text; if(!text || Array.isArray(text)) { diff --git a/src/components/errorbars/index.js b/src/components/errorbars/index.js index 2a4c9101c54..4f68e91d37b 100644 --- a/src/components/errorbars/index.js +++ b/src/components/errorbars/index.js @@ -70,7 +70,7 @@ errorBars.plot = function(gd, plotinfo, cd) { .data(cd) .enter().append('g') .attr('class','errorbars') - .each(function(d){ + .each(function(d) { var trace = d[0].trace, xObj = trace.error_x, yObj = trace.error_y, @@ -82,7 +82,7 @@ errorBars.plot = function(gd, plotinfo, cd) { d3.select(this).selectAll('g') .data(Lib.identity) .enter().append('g') - .each(function(d){ + .each(function(d) { coords = errorcoords(d, xa, ya); var eb = d3.select(this), path; @@ -90,7 +90,7 @@ errorBars.plot = function(gd, plotinfo, cd) { if(yObj.visible && isNumeric(coords.x) && isNumeric(coords.yh) && - isNumeric(coords.ys)){ + isNumeric(coords.ys)) { var yw = yObj.width; path = 'M'+(coords.x-yw)+','+coords.yh+'h'+(2*yw) + // hat 'm-'+yw+',0V'+coords.ys; // bar @@ -102,7 +102,7 @@ errorBars.plot = function(gd, plotinfo, cd) { } if(xObj.visible && isNumeric(coords.y) && isNumeric(coords.xh) && - isNumeric(coords.xs)){ + isNumeric(coords.xs)) { var xw = (xObj.copy_ystyle ? yObj : xObj).width; path = 'M'+coords.xh+','+(coords.y-xw)+'v'+(2*xw) + // hat 'm0,-'+xw+'H'+coords.xs; // bar @@ -116,8 +116,8 @@ errorBars.plot = function(gd, plotinfo, cd) { }); }; -errorBars.style = function(gd){ - d3.select(gd).selectAll('g.errorbars').each(function(d){ +errorBars.style = function(gd) { + d3.select(gd).selectAll('g.errorbars').each(function(d) { var eb = d3.select(this), trace = d[0].trace, yObj = trace.error_y||{}, diff --git a/src/components/legend/index.js b/src/components/legend/index.js index 058f5c120b8..892cbd78544 100644 --- a/src/components/legend/index.js +++ b/src/components/legend/index.js @@ -87,7 +87,7 @@ legend.supplyLayoutDefaults = function(layoutIn, layoutOut, fullData) { // same functions for styling traces in the popovers // ----------------------------------------------------- -legend.lines = function(d){ +legend.lines = function(d) { var trace = d[0].trace, showFill = trace.visible && trace.fill && trace.fill!=='none', showLine = subTypes.hasLines(trace); @@ -107,7 +107,7 @@ legend.lines = function(d){ line.call(Drawing.lineGroupStyle); }; -legend.points = function(d){ +legend.points = function(d) { var d0 = d[0], trace = d0.trace, showMarkers = subTypes.hasMarkers(trace), @@ -192,7 +192,7 @@ legend.points = function(d){ }; -legend.bars = function(d){ +legend.bars = function(d) { var trace = d[0].trace, marker = trace.marker||{}, markerLine = marker.line||{}, @@ -203,7 +203,7 @@ legend.bars = function(d){ .attr('d','M6,6H-6V-6H6Z') .attr('transform','translate(20,0)'); barpath.exit().remove(); - barpath.each(function(d){ + barpath.each(function(d) { var w = (d.mlw+1 || markerLine.width+1) - 1, p = d3.select(this); p.style('stroke-width',w+'px') @@ -214,7 +214,7 @@ legend.bars = function(d){ }); }; -legend.boxes = function(d){ +legend.boxes = function(d) { var trace = d[0].trace, pts = d3.select(this).select('g.legendpoints') .selectAll('path.legendbox') @@ -224,7 +224,7 @@ legend.boxes = function(d){ .attr('d', 'M6,6H-6V-6H6Z') .attr('transform', 'translate(20,0)'); pts.exit().remove(); - pts.each(function(d){ + pts.each(function(d) { var w = (d.lw+1 || trace.line.width+1) - 1, p = d3.select(this); p.style('stroke-width', w+'px') @@ -249,7 +249,7 @@ legend.pie = function(d) { }; legend.style = function(s) { - s.each(function(d){ + s.each(function(d) { var traceGroup = d3.select(this); var fill = traceGroup @@ -283,7 +283,7 @@ legend.style = function(s) { .each(legend.points); }; -legend.texts = function(context, td, d, i, traces){ +legend.texts = function(context, td, d, i, traces) { var fullLayout = td._fullLayout, trace = d[0].trace, isPie = Plots.traceIs(trace, 'pie'), @@ -308,17 +308,17 @@ legend.texts = function(context, td, d, i, traces){ .call(Drawing.font, fullLayout.legend.font) .text(name); - function textLayout(s){ - Plotly.util.convertToTspans(s, function(){ + function textLayout(s) { + Plotly.util.convertToTspans(s, function() { if(td.firstRender) legend.repositionLegend(td, traces); }); s.selectAll('tspan.line').attr({x: s.attr('x')}); } - if(td._context.editable && !isPie){ + if(td._context.editable && !isPie) { text.call(Plotly.util.makeEditable) .call(textLayout) - .on('edit', function(text){ + .on('edit', function(text) { this.attr({'data-unformatted': text}); this.text(text) .call(textLayout); @@ -597,11 +597,11 @@ legend.draw = function(td) { legendsvg.call(Drawing.setRect, lx, ly, opts.width, scrollheight); // If scrollbar should be shown. - if(td.firstRender && opts.height - scrollheight > 0 && !td._context.staticPlot){ + if(td.firstRender && opts.height - scrollheight > 0 && !td._context.staticPlot) { bg.attr({ width: opts.width - 2 * opts.borderwidth + constants.scrollBarWidth }); - legendsvg.node().addEventListener('wheel', function(e){ + legendsvg.node().addEventListener('wheel', function(e) { e.preventDefault(); scrollHandler(e.deltaY / 20); }); @@ -610,7 +610,7 @@ legend.draw = function(td) { e.preventDefault(); function mMove(e) { - if(e.buttons === 1){ + if(e.buttons === 1) { scrollHandler(e.movementY); } } @@ -634,7 +634,7 @@ legend.draw = function(td) { ); } - function scrollHandler(delta){ + function scrollHandler(delta) { var scrollBarTrack = scrollheight - constants.scrollBarHeight - 2 * constants.scrollBarMargin, translateY = scrollBox.attr('data-scroll'), @@ -693,7 +693,7 @@ legend.draw = function(td) { } }; -legend.repositionLegend = function(td, traces){ +legend.repositionLegend = function(td, traces) { var fullLayout = td._fullLayout, gs = fullLayout._size, opts = fullLayout.legend, @@ -702,7 +702,7 @@ legend.repositionLegend = function(td, traces){ opts.width = 0, opts.height = 0, - traces.each(function(d){ + traces.each(function(d) { var trace = d[0].trace, g = d3.select(this), bg = g.selectAll('.legendtoggle'), diff --git a/src/components/titles/index.js b/src/components/titles/index.js index 6435cee79f1..0da50d3d9fc 100644 --- a/src/components/titles/index.js +++ b/src/components/titles/index.js @@ -95,7 +95,7 @@ Titles.draw = function(gd, title) { // TODO: need a better solution than this hack title = 'h' + title; } - else if(axletter === 'x'){ + else if(axletter === 'x') { xa = cont; ya = (xa.anchor === 'free') ? {_offset: gs.t + (1 - (xa.position || 0)) * gs.h, _length: 0} : @@ -110,7 +110,7 @@ Titles.draw = function(gd, title) { options = {x: x, y: y, 'text-anchor': 'middle'}; if(!avoid.side) avoid.side = 'bottom'; } - else if(axletter === 'y'){ + else if(axletter === 'y') { ya = cont; xa = (ya.anchor === 'free') ? {_offset: gs.l + (ya.position || 0) * gs.w, _length: 0} : @@ -175,7 +175,7 @@ Titles.draw = function(gd, title) { // for now) - ie don't use .classed .attr('class', title); - function titleLayout(titleEl){ + function titleLayout(titleEl) { Lib.syncOrAsync([drawTitle,scootTitle], titleEl); } @@ -204,7 +204,7 @@ Titles.draw = function(gd, title) { function scootTitle(titleElIn) { var titleGroup = d3.select(titleElIn.node().parentNode); - if(avoid && avoid.selection && avoid.side && txt){ + if(avoid && avoid.selection && avoid.side && txt) { titleGroup.attr('transform', null); // move toward avoid.side (= left, right, top, bottom) if needed @@ -241,7 +241,7 @@ Titles.draw = function(gd, title) { // iterate over a set of elements (avoid.selection) // to avoid collisions with - avoid.selection.each(function(){ + avoid.selection.each(function() { var avoidbb = Drawing.bBox(this); if(Lib.bBoxIntersect(titlebb, avoidbb, pad)) { @@ -286,7 +286,7 @@ Titles.draw = function(gd, title) { }); } - if(gd._context.editable){ + if(gd._context.editable) { if(!txt) setPlaceholder(); el.call(svgTextUtils.makeEditable) diff --git a/src/fonts/mathjax_config.js b/src/fonts/mathjax_config.js index d172e89045b..23881802724 100644 --- a/src/fonts/mathjax_config.js +++ b/src/fonts/mathjax_config.js @@ -13,7 +13,7 @@ /** * Check and configure MathJax */ -if(typeof MathJax !== 'undefined'){ +if(typeof MathJax !== 'undefined') { exports.MathJax = true; MathJax.Hub.Config({ diff --git a/src/lib/dates.js b/src/lib/dates.js index a297a518eea..897af6ab8d5 100644 --- a/src/lib/dates.js +++ b/src/lib/dates.js @@ -109,7 +109,7 @@ exports.isDateTime = function(s) { }; // pad a number with zeroes, to given # of digits before the decimal point -function lpad(val, digits){ +function lpad(val, digits) { return String(val + Math.pow(10, digits)).substr(1); } @@ -121,7 +121,7 @@ function lpad(val, digits){ * If rng is big, the later parts of time will be omitted */ exports.ms2DateTime = function(ms, r) { - if(typeof(d3)==='undefined'){ + if(typeof(d3)==='undefined') { console.log('d3 is not defined'); return; } diff --git a/src/lib/index.js b/src/lib/index.js index f378e6fc1ea..8f2235928cd 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -85,7 +85,7 @@ lib.swapAttrs = function(cont, attrList, part1, part2) { * for maximum effect use: * return pauseEvent(e); */ -lib.pauseEvent = function(e){ +lib.pauseEvent = function(e) { if(e.stopPropagation) e.stopPropagation(); if(e.preventDefault) e.preventDefault(); e.cancelBubble = true; @@ -105,7 +105,7 @@ lib.VERBOSE = false; lib.TIMER = new Date().getTime(); // console.log that only runs if VERBOSE is on -lib.log = function(){ +lib.log = function() { if(lib.VERBOSE) console.log.apply(console, arguments); }; @@ -113,7 +113,7 @@ lib.log = function(){ * markTime - for debugging, mark the number of milliseconds * since the previous call to markTime and log arbitrary info too */ -lib.markTime = function(v){ +lib.markTime = function(v) { if(!lib.VERBOSE) return; var t2 = new Date().getTime(); console.log(v, t2 - lib.TIMER, '(msec)'); @@ -132,7 +132,7 @@ lib.constrain = function(v, v0, v1) { * ie {left,right,top,bottom,width,height}, overlap? * takes optional padding pixels */ -lib.bBoxIntersect = function(a, b, pad){ +lib.bBoxIntersect = function(a, b, pad) { pad = pad || 0; return (a.left <= b.right + pad && b.left <= a.right + pad && @@ -281,7 +281,7 @@ lib.promiseError = function(err) { console.log(err, err.stack); }; lib.syncOrAsync = function(sequence, arg, finalStep) { var ret, fni; - function continueAsync(){ + function continueAsync() { lib.markTime('async done ' + fni.name); return lib.syncOrAsync(sequence, arg, finalStep); } diff --git a/src/lib/queue.js b/src/lib/queue.js index 8ed12237cc9..25572003897 100644 --- a/src/lib/queue.js +++ b/src/lib/queue.js @@ -121,7 +121,7 @@ queue.stopSequence = function(gd) { queue.undo = function undo(gd) { var queueObj, i; - if(gd.framework && gd.framework.isPolar){ + if(gd.framework && gd.framework.isPolar) { gd.framework.undo(); return; } @@ -154,7 +154,7 @@ queue.undo = function undo(gd) { queue.redo = function redo(gd) { var queueObj, i; - if(gd.framework && gd.framework.isPolar){ + if(gd.framework && gd.framework.isPolar) { gd.framework.redo(); return; } diff --git a/src/lib/search.js b/src/lib/search.js index 5ff6e64d19d..8df2fde398b 100644 --- a/src/lib/search.js +++ b/src/lib/search.js @@ -40,7 +40,7 @@ exports.findBin = function(val, bins, linelow) { test = linelow ? greaterOrEqual : greaterThan; } // c is just to avoid infinite loops if there's an error - while(n1 < n2 && c++ < 100){ + while(n1 < n2 && c++ < 100) { n = Math.floor((n1 + n2) / 2); if(test(bins[n], val)) n1 = n + 1; else n2 = n; @@ -90,7 +90,7 @@ exports.distinctVals = function(valsIn) { * particularly useful for date/time where things are not powers of 10 * binary search is probably overkill here... */ -exports.roundUp = function(val, arrayIn, reverse){ +exports.roundUp = function(val, arrayIn, reverse) { var low = 0, high = arrayIn.length - 1, mid, @@ -99,7 +99,7 @@ exports.roundUp = function(val, arrayIn, reverse){ dhigh = reverse ? 1 : 0, rounded = reverse ? Math.ceil : Math.floor; // c is just to avoid infinite loops if there's an error - while(low < high && c++ < 100){ + while(low < high && c++ < 100) { mid = rounded((low + high) / 2); if(arrayIn[mid] <= val) low = mid + dlow; else high = mid - dhigh; diff --git a/src/lib/stats.js b/src/lib/stats.js index a827ab1e8df..4927f49e02a 100644 --- a/src/lib/stats.js +++ b/src/lib/stats.js @@ -48,12 +48,12 @@ exports.aggNums = function(f, v, a, len) { * even need to use aggNums instead of .length, to toss out non-numerics */ exports.len = function(data) { - return exports.aggNums(function(a){ return a + 1; }, 0, data); + return exports.aggNums(function(a) { return a + 1; }, 0, data); }; exports.mean = function(data, len) { if(!len) len = exports.len(data); - return exports.aggNums(function(a, b){ return a + b; }, 0, data) / len; + return exports.aggNums(function(a, b) { return a + b; }, 0, data) / len; }; exports.variance = function(data, len, mean) { diff --git a/src/lib/svg_text_utils.js b/src/lib/svg_text_utils.js index 021843fd599..b0860ab7c2c 100644 --- a/src/lib/svg_text_utils.js +++ b/src/lib/svg_text_utils.js @@ -35,7 +35,7 @@ d3.selection.prototype.appendSVG = function(_svgString) { this.node().appendChild(this.node().ownerDocument.importNode(childNode, true)); childNode = childNode.nextSibling; } - if(dom.querySelector('parsererror')){ + if(dom.querySelector('parsererror')) { console.log(dom.querySelector('parsererror div').textContent); return null; } @@ -46,7 +46,7 @@ d3.selection.prototype.appendSVG = function(_svgString) { util.html_entity_decode = function(s) { var hiddenDiv = d3.select('body').append('div').style({display: 'none'}).html(''); - var replaced = s.replace(/(&[^;]*;)/gi, function(d){ + var replaced = s.replace(/(&[^;]*;)/gi, function(d) { if(d==='<') { return '<'; } // special handling for brackets if(d==='&rt;') { return '>'; } return hiddenDiv.html(d).text(); // everything else, let the browser decode it to unicode @@ -55,17 +55,17 @@ util.html_entity_decode = function(s) { return replaced; }; -util.xml_entity_encode = function(str){ +util.xml_entity_encode = function(str) { return str.replace(/&(?!\w+;|\#[0-9]+;| \#x[0-9A-F]+;)/g,'&'); }; // text converter -function getSize(_selection, _dimension){ +function getSize(_selection, _dimension) { return _selection.node().getBoundingClientRect()[_dimension]; } -util.convertToTspans = function(_context, _callback){ +util.convertToTspans = function(_context, _callback) { var str = _context.text(); var converted = convertToSVG(str); var that = _context; @@ -85,7 +85,7 @@ util.convertToTspans = function(_context, _callback){ } function showText() { - if(!parent.empty()){ + if(!parent.empty()) { svgClass = that.attr('class') + '-math'; parent.select('svg.' + svgClass).remove(); } @@ -107,7 +107,7 @@ util.convertToTspans = function(_context, _callback){ if(_callback) _callback.call(that); } - if(tex){ + if(tex) { var td = Plotly.Lib.getPlotDiv(that.node()); ((td && td._promises)||[]).push(new Promise(function(resolve) { that.style({visibility: 'hidden'}); @@ -155,17 +155,17 @@ util.convertToTspans = function(_context, _callback){ getSize(that, 'height'), dy = -textHeight/4; - if(svgClass[0] === 'y'){ + if(svgClass[0] === 'y') { mathjaxGroup.attr({ transform: 'rotate(' + [-90, +that.attr('x'), +that.attr('y')] + ') translate(' + [-newSvgW / 2, dy - newSvgH / 2] + ')' }); newSvg.attr({x: +that.attr('x'), y: +that.attr('y')}); } - else if(svgClass[0] === 'l'){ + else if(svgClass[0] === 'l') { newSvg.attr({x: that.attr('x'), y: dy - (newSvgH / 2)}); } - else if(svgClass[0] === 'a'){ + else if(svgClass[0] === 'a') { newSvg.attr({x: 0, y: dy}); } else { @@ -190,7 +190,7 @@ function cleanEscapesForTex(s) { .replace(/(>|>|>)/g, '\\gt '); } -function texToSVG(_texString, _config, _callback){ +function texToSVG(_texString, _config, _callback) { var randomID = 'math-output-' + Plotly.Lib.randstr([],64); var tmpDiv = d3.select('body').append('div') .attr({id: randomID}) @@ -198,10 +198,10 @@ function texToSVG(_texString, _config, _callback){ .style({'font-size': _config.fontSize + 'px'}) .text(cleanEscapesForTex(_texString)); - MathJax.Hub.Queue(['Typeset', MathJax.Hub, tmpDiv.node()], function(){ + MathJax.Hub.Queue(['Typeset', MathJax.Hub, tmpDiv.node()], function() { var glyphDefs = d3.select('body').select('#MathJax_SVG_glyphs'); - if(tmpDiv.select('.MathJax_SVG').empty() || !tmpDiv.select('svg').node()){ + if(tmpDiv.select('.MathJax_SVG').empty() || !tmpDiv.select('svg').node()) { console.log('There was an error in the tex syntax.', _texString); _callback(); } @@ -232,20 +232,20 @@ var PROTOCOLS = ['http:', 'https:', 'mailto:']; var STRIP_TAGS = new RegExp(']*)?/?>', 'g'); -util.plainText = function(_str){ +util.plainText = function(_str) { // strip out our pseudo-html so we have a readable // version to put into text fields return (_str||'').replace(STRIP_TAGS, ' '); }; -function convertToSVG(_str){ +function convertToSVG(_str) { var htmlEntitiesDecoded = Plotly.util.html_entity_decode(_str); var result = htmlEntitiesDecoded - .split(/(<[^<>]*>)/).map(function(d){ + .split(/(<[^<>]*>)/).map(function(d) { var match = d.match(/<(\/?)([^ >]*)\s*(.*)>/i), tag = match && match[2].toLowerCase(), style = TAG_STYLES[tag]; - if(style !== undefined){ + if(style !== undefined) { var close = match[1], extra = match[3], /** @@ -258,7 +258,7 @@ function convertToSVG(_str){ */ extraStyle = extra.match(/^style\s*=\s*"([^"]+)"\s*/i); // anchor and br are the only ones that don't turn into a tspan - if(tag === 'a'){ + if(tag === 'a') { if(close) return ''; else if(extra.substr(0,4).toLowerCase() !== 'href') return ''; else { @@ -303,22 +303,22 @@ function convertToSVG(_str){ }); var indices = []; - for(var index = result.indexOf('
'); index > 0; index = result.indexOf('
', index+1)){ + for(var index = result.indexOf('
'); index > 0; index = result.indexOf('
', index+1)) { indices.push(index); } var count = 0; - indices.forEach(function(d){ + indices.forEach(function(d) { var brIndex = d + count; var search = result.slice(0, brIndex); var previousOpenTag = ''; - for(var i2=search.length-1; i2>=0; i2--){ + for(var i2=search.length-1; i2>=0; i2--) { var isTag = search[i2].match(/<(\/?).*>/i); - if(isTag && search[i2] !== '
'){ + if(isTag && search[i2] !== '
') { if(!isTag[1]) previousOpenTag = search[i2]; break; } } - if(previousOpenTag){ + if(previousOpenTag) { result.splice(brIndex+1, 0, previousOpenTag); result.splice(brIndex, 0, ''); count += 2; @@ -327,8 +327,8 @@ function convertToSVG(_str){ var joined = result.join(''); var splitted = joined.split(/
/gi); - if(splitted.length > 1){ - result = splitted.map(function(d, i){ + if(splitted.length > 1) { + result = splitted.map(function(d, i) { // TODO: figure out max font size of this line and alter dy // this requires either: // 1) bringing the base font size into convertToTspans, or @@ -341,7 +341,7 @@ function convertToSVG(_str){ return result.join(''); } -function alignHTMLWith(_base, container, options){ +function alignHTMLWith(_base, container, options) { var alignH = options.horizontalAlign, alignV = options.verticalAlign || 'top', bRect = _base.node().getBoundingClientRect(), @@ -366,7 +366,7 @@ function alignHTMLWith(_base, container, options){ getLeft = function() { return bRect.left; }; } - return function(){ + return function() { thisRect = this.node().getBoundingClientRect(); this.style({ top: (getTop() - cRect.top) + 'px', @@ -379,7 +379,7 @@ function alignHTMLWith(_base, container, options){ // Editable title -util.makeEditable = function(context, _delegate, options){ +util.makeEditable = function(context, _delegate, options) { if(!options) options = {}; var that = this; var dispatch = d3.dispatch('edit', 'input', 'cancel'); @@ -389,7 +389,7 @@ util.makeEditable = function(context, _delegate, options){ var handlerElement = _delegate || textSelection; if(_delegate) textSelection.style({'pointer-events': 'none'}); - function handleClick(){ + function handleClick() { appendEditable(); that.style({opacity: 0}); // also hide any mathjax svg @@ -412,7 +412,7 @@ util.makeEditable = function(context, _delegate, options){ el.focus(); } - function appendEditable(){ + function appendEditable() { var plotDiv = d3.select(Plotly.Lib.getPlotDiv(that.node())), container = plotDiv.select('.svg-container'), div = container.append('div'); @@ -432,7 +432,7 @@ util.makeEditable = function(context, _delegate, options){ .attr({contenteditable: true}) .text(options.text || that.attr('data-unformatted')) .call(alignHTMLWith(that, container, options)) - .on('blur', function(){ + .on('blur', function() { that.text(this.textContent) .style({opacity: 1}); var svgClass = d3.select(this).attr('class'), @@ -447,19 +447,19 @@ util.makeEditable = function(context, _delegate, options){ d3.select(document).on('mouseup', null); dispatch.edit.call(that, text); }) - .on('focus', function(){ + .on('focus', function() { var context = this; - d3.select(document).on('mouseup', function(){ + d3.select(document).on('mouseup', function() { if(d3.event.target === context) return false; if(document.activeElement === div.node()) div.node().blur(); }); }) - .on('keyup', function(){ - if(d3.event.which === 27){ + .on('keyup', function() { + if(d3.event.which === 27) { that.style({opacity: 1}); d3.select(this) .style({opacity: 0}) - .on('blur', function(){ return false; }) + .on('blur', function() { return false; }) .transition().remove(); dispatch.cancel.call(that, this.textContent); } @@ -468,7 +468,7 @@ util.makeEditable = function(context, _delegate, options){ d3.select(this).call(alignHTMLWith(that, container, options)); } }) - .on('keydown', function(){ + .on('keydown', function() { if(d3.event.which === 13) this.blur(); }) .call(selectElementContents); diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 15f06bcab7e..effb40c96ed 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -304,7 +304,7 @@ Plotly.plot = function(gd, data, layout, config) { // An initial paint must be completed before these components can be // correctly sized and the whole plot re-margined. gd._replotting must // be set to false before these will work properly. - function finalDraw(){ + function finalDraw() { Shapes.drawAll(gd); Plotly.Annotations.drawAll(gd); Legend.draw(gd); @@ -451,9 +451,9 @@ function plotPolar(gd, data, layout) { var title = polarPlotSVG.select('.title-group text') .call(titleLayout); - if(gd._context.editable){ + if(gd._context.editable) { title.attr({'data-unformatted': txt}); - if(!txt || txt === placeholderText){ + if(!txt || txt === placeholderText) { opacity = 0.2; title.attr({'data-unformatted': placeholderText}) .text(placeholderText) @@ -470,7 +470,7 @@ function plotPolar(gd, data, layout) { var setContenteditable = function() { this.call(Plotly.util.makeEditable) - .on('edit', function(text){ + .on('edit', function(text) { gd.framework({layout: {title: text}}); this.attr({'data-unformatted': text}) .text(text) @@ -1530,7 +1530,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { if(isNumeric(traces)) traces=[traces]; else if(!Array.isArray(traces) || !traces.length) { - traces=gd._fullData.map(function(v,i){ return i; }); + traces=gd._fullData.map(function(v,i) { return i; }); } // recalcAttrs attributes need a full regeneration of calcdata @@ -1686,7 +1686,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { newVal; redoit[ai] = vi; - if(ai.substr(0,6)==='LAYOUT'){ + if(ai.substr(0,6)==='LAYOUT') { param = Lib.nestedProperty(gd.layout, ai.replace('LAYOUT', '')); undoit[ai] = [param.get()]; // since we're allowing val to be an array, allow it here too, diff --git a/src/plot_api/plot_schema.js b/src/plot_api/plot_schema.js index 2a24910dddf..9dbed44d3f5 100644 --- a/src/plot_api/plot_schema.js +++ b/src/plot_api/plot_schema.js @@ -242,7 +242,7 @@ function getModule(arg) { } function removeUnderscoreAttrs(attributes) { - Object.keys(attributes).forEach(function(k){ + Object.keys(attributes).forEach(function(k) { if(k.charAt(0) === '_' && UNDERSCORE_ATTRS.indexOf(k) === -1) delete attributes[k]; }); diff --git a/src/plotly.js b/src/plotly.js index d5541efc628..3ae37158882 100644 --- a/src/plotly.js +++ b/src/plotly.js @@ -52,21 +52,21 @@ exports.Legend = require('./components/legend'); exports.ModeBar = require('./components/modebar'); exports.register = function register(_modules) { - if(!_modules){ + if(!_modules) { throw new Error('No argument passed to Plotly.register.'); - } else if(_modules && !Array.isArray(_modules)){ + } else if(_modules && !Array.isArray(_modules)) { _modules = [_modules]; } - for(var i = 0; i < _modules.length; i++){ + for(var i = 0; i < _modules.length; i++) { var newModule = _modules[i]; - if(newModule && newModule.moduleType !== 'trace'){ + if(newModule && newModule.moduleType !== 'trace') { throw new Error('Invalid module was attempted to be registered!'); } else { Plots.register(newModule, newModule.name, newModule.categories, newModule.meta); - if(!Plots.subplotsRegistry[newModule.basePlotModule.name]){ + if(!Plots.subplotsRegistry[newModule.basePlotModule.name]) { Plots.registerSubplot(newModule.basePlotModule); } } diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 6782837d611..c562a50fdf7 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -254,7 +254,7 @@ axes.expand = function(ax, data, options) { } else { var v = Math.max(Number(item||0),0); - return function(){ return v; }; + return function() { return v; }; } } var ppadplus = getPad((ax._m>0 ? @@ -459,7 +459,7 @@ axes.calcTicks = function calcTicks(ax) { if(ax.tickmode === 'array') return arrayTicks(ax); // calculate max number of (auto) ticks to display based on plot size - if(ax.tickmode === 'auto' || !ax.dtick){ + if(ax.tickmode === 'auto' || !ax.dtick) { var nt = ax.nticks, minPx; if(!nt) { @@ -583,38 +583,38 @@ function roundDTick(roughDTick, base, roundingSet) { // log with linear ticks: L# where # is the linear tick spacing // log showing powers plus some intermediates: // D1 shows all digits, D2 shows 2 and 5 -axes.autoTicks = function(ax, roughDTick){ +axes.autoTicks = function(ax, roughDTick) { var base; - if(ax.type === 'date'){ + if(ax.type === 'date') { ax.tick0 = new Date(2000, 0, 1).getTime(); - if(roughDTick > 15778800000){ + if(roughDTick > 15778800000) { // years if roughDTick > 6mo roughDTick /= 31557600000; base = Math.pow(10, Math.floor(Math.log(roughDTick) / Math.LN10)); ax.dtick = 'M' + (12 * roundDTick(roughDTick, base, roundBase10)); } - else if(roughDTick > 1209600000){ + else if(roughDTick > 1209600000) { // months if roughDTick > 2wk roughDTick /= 2629800000; ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24); } - else if(roughDTick > 43200000){ + else if(roughDTick > 43200000) { // days if roughDTick > 12h ax.dtick = roundDTick(roughDTick, 86400000, roundDays); // get week ticks on sunday ax.tick0 = new Date(2000, 0, 2).getTime(); } - else if(roughDTick > 1800000){ + else if(roughDTick > 1800000) { // hours if roughDTick > 30m ax.dtick = roundDTick(roughDTick, 3600000, roundBase24); } - else if(roughDTick > 30000){ + else if(roughDTick > 30000) { // minutes if roughDTick > 30sec ax.dtick = roundDTick(roughDTick, 60000, roundBase60); } - else if(roughDTick > 500){ + else if(roughDTick > 500) { // seconds if roughDTick > 0.5sec ax.dtick = roundDTick(roughDTick, 1000, roundBase60); } @@ -624,12 +624,12 @@ axes.autoTicks = function(ax, roughDTick){ ax.dtick = roundDTick(roughDTick, base, roundBase10); } } - else if(ax.type === 'log'){ + else if(ax.type === 'log') { ax.tick0 = 0; //only show powers of 10 if(roughDTick > 0.7) ax.dtick = Math.ceil(roughDTick); - else if(Math.abs(ax.range[1] - ax.range[0]) < 1){ + else if(Math.abs(ax.range[1] - ax.range[0]) < 1) { // span is less than one power of 10 var nt = 1.5 * Math.abs((ax.range[1] - ax.range[0]) / roughDTick); @@ -718,7 +718,7 @@ function autoTickRound(ax) { // for pure powers of 10 // numeric ticks always have constant differences, other datetime ticks // can all be calculated as constant number of milliseconds -axes.tickIncrement = function(x, dtick, axrev){ +axes.tickIncrement = function(x, dtick, axrev) { var axSign = axrev ? -1 : 1; // includes all dates smaller than month, and pure 10^n in log @@ -728,7 +728,7 @@ axes.tickIncrement = function(x, dtick, axrev){ dtSigned = axSign * Number(dtick.substr(1)); // Dates: months (or years) - if(tType === 'M'){ + if(tType === 'M') { var y = new Date(x); // is this browser consistent? setMonth edits a date but // returns that date's milliseconds @@ -752,7 +752,7 @@ axes.tickIncrement = function(x, dtick, axrev){ }; // calculate the first tick on an axis -axes.tickFirst = function(ax){ +axes.tickFirst = function(ax) { var axrev = ax.range[1] < ax.range[0], sRound = axrev ? Math.floor : Math.ceil, // add a tiny extra bit to make sure we get ticks @@ -777,7 +777,7 @@ axes.tickFirst = function(ax){ t1; // Dates: months (or years) - if(tType === 'M'){ + if(tType === 'M') { t0 = new Date(tick0); r0 = new Date(r0); mdif = (r0.getFullYear() - t0.getFullYear()) * 12 + @@ -837,7 +837,7 @@ function modDateFormat(fmt,x) { // ax is the axis layout, x is the tick value // hover is a (truthy) flag for whether to show numbers with a bit // more precision for hovertext -axes.tickText = function(ax, x, hover){ +axes.tickText = function(ax, x, hover) { var out = tickTextObj(ax, x), hideexp, arrayMode = ax.tickmode === 'array', @@ -933,7 +933,7 @@ function formatDate(ax, out, hover, extraPrecision) { } tt = minuteFormat(d); - if(tr!=='M'){ + if(tr!=='M') { tt += secondFormat(d); if(tr!=='S') { tt += numFormat(mod(x/1000,1),ax,'none',hover) @@ -1336,7 +1336,7 @@ axes.doTicks = function(td, axid, skipTitle) { if(!axid || axid==='redraw') { return Plotly.Lib.syncOrAsync(axes.list(td, '', true).map(function(ax) { - return function(){ + return function() { if(!ax._id) return; var axDone = axes.doTicks(td,ax._id); if(axid==='redraw') ax._r = ax.range.slice(); @@ -1366,7 +1366,7 @@ axes.doTicks = function(td, axid, skipTitle) { var axletter = axid.charAt(0), counterLetter = axes.counterLetter(axid), vals = axes.calcTicks(ax), - datafn = function(d){ return d.text + d.x + ax.mirror; }, + datafn = function(d) { return d.text + d.x + ax.mirror; }, tcls = axid+'tick', gcls = axid+'grid', zcls = axid+'zl', @@ -1382,7 +1382,7 @@ axes.doTicks = function(td, axid, skipTitle) { // positioning arguments for x vs y axes if(axletter==='x') { sides = ['bottom', 'top']; - transfn = function(d){ + transfn = function(d) { return 'translate('+ax.l2p(d.x)+',0)'; }; // dumb templating with string concat @@ -1392,7 +1392,7 @@ axes.doTicks = function(td, axid, skipTitle) { } else if(axletter==='y') { sides = ['left', 'right']; - transfn = function(d){ + transfn = function(d) { return 'translate(0,'+ax.l2p(d.x)+')'; }; tickprefix = 'M'; @@ -1407,7 +1407,7 @@ axes.doTicks = function(td, axid, skipTitle) { // then we flip if outside XOR y axis ticksign = [-1, 1, axside===sides[1] ? 1 : -1]; if((ax.ticks!=='inside') === (axletter==='x')) { - ticksign = ticksign.map(function(v){ return -v; }); + ticksign = ticksign.map(function(v) { return -v; }); } // remove zero lines, grid lines, and inside ticks if they're within @@ -1447,13 +1447,13 @@ axes.doTicks = function(td, axid, skipTitle) { var labelx, labely, labelanchor, labelpos0; if(axletter==='x') { var flipit = axside==='bottom' ? 1 : -1; - labelx = function(d){ return d.dx; }; + labelx = function(d) { return d.dx; }; labelpos0 = position + (labelStandoff+pad)*flipit; - labely = function(d){ + labely = function(d) { return d.dy+labelpos0+d.fontSize * (axside==='bottom' ? 1 : -0.5); }; - labelanchor = function(angle){ + labelanchor = function(angle) { if(!isNumeric(angle) || angle===0 || angle===180) { return 'middle'; } @@ -1461,13 +1461,13 @@ axes.doTicks = function(td, axid, skipTitle) { }; } else { - labely = function(d){ return d.dy+d.fontSize/2; }; - labelx = function(d){ + labely = function(d) { return d.dy+d.fontSize/2; }; + labelx = function(d) { return d.dx + position + (labelStandoff + pad + (Math.abs(ax.tickangle)===90 ? d.fontSize/2 : 0)) * (axside==='right' ? 1 : -1); }; - labelanchor = function(angle){ + labelanchor = function(angle) { if(isNumeric(angle) && Math.abs(angle)===90) { return 'middle'; } @@ -1482,7 +1482,7 @@ axes.doTicks = function(td, axid, skipTitle) { // only so tex has predictable alignment that we can // alter later .attr('text-anchor', 'middle') - .each(function(d){ + .each(function(d) { var thisLabel = d3.select(this), newPromise = td._promises.length; thisLabel @@ -1498,7 +1498,7 @@ axes.doTicks = function(td, axid, skipTitle) { // all here so take it out of td._promises and // instead position the label and promise this in // labelsReady - labelsReady.push(td._promises.pop().then(function(){ + labelsReady.push(td._promises.pop().then(function() { positionLabels(thisLabel, ax.tickangle); })); } @@ -1509,7 +1509,7 @@ axes.doTicks = function(td, axid, skipTitle) { }); tickLabels.exit().remove(); - tickLabels.each(function(d){ + tickLabels.each(function(d) { maxFontSize = Math.max(maxFontSize, d.fontSize); }); @@ -1553,11 +1553,11 @@ axes.doTicks = function(td, axid, skipTitle) { // there, putting back the prescribed angle to check for overlaps. positionLabels(tickLabels,ax._lastangle || ax.tickangle); - function allLabelsReady(){ + function allLabelsReady() { return labelsReady.length && Promise.all(labelsReady); } - function fixLabelOverlaps(){ + function fixLabelOverlaps() { positionLabels(tickLabels,ax.tickangle); // check for auto-angling if x labels overlap @@ -1566,7 +1566,7 @@ axes.doTicks = function(td, axid, skipTitle) { if(axletter==='x' && !isNumeric(ax.tickangle) && (ax.type!=='log' || String(ax.dtick).charAt(0)!=='D')) { var lbbArray = []; - tickLabels.each(function(d){ + tickLabels.each(function(d) { var s = d3.select(this), thisLabel = s.select('.text-math-group'), x = ax.l2p(d.x); @@ -1873,4 +1873,4 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes) { // mod - version of modulus that always restricts to [0,divisor) // rather than built-in % which gives a negative value for negative v -function mod(v,d){ return ((v%d) + d) % d; } +function mod(v,d) { return ((v%d) + d) % d; } diff --git a/src/plots/cartesian/axis_defaults.js b/src/plots/cartesian/axis_defaults.js index 3376e32a410..2e2e5e19366 100644 --- a/src/plots/cartesian/axis_defaults.js +++ b/src/plots/cartesian/axis_defaults.js @@ -124,7 +124,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce, return containerOut; }; -function setAutoType(ax, data){ +function setAutoType(ax, data) { // new logic: let people specify any type they want, // only autotype if type is '-' if(ax.type!=='-') return; diff --git a/src/plots/cartesian/graph_interact.js b/src/plots/cartesian/graph_interact.js index e57a4656e26..b84eb742273 100644 --- a/src/plots/cartesian/graph_interact.js +++ b/src/plots/cartesian/graph_interact.js @@ -226,7 +226,7 @@ function p2c(axArray, v) { } function quadrature(dx, dy) { - return function(di){ + return function(di) { var x = dx(di), y = dy(di); return Math.sqrt(x*x + y*y); @@ -270,13 +270,13 @@ fx.hover = function(gd, evt, subplot) { if(gd._lastHoverTime === undefined) gd._lastHoverTime = 0; // If we have an update queued, discard it now - if (gd._hoverTimer !== undefined) { + if(gd._hoverTimer !== undefined) { clearTimeout(gd._hoverTimer); gd._hoverTimer = undefined; } // Is it more than 100ms since the last update? If so, force // an update now (synchronously) and exit - if (Date.now() > gd._lastHoverTime + constants.HOVERMINTIME) { + if(Date.now() > gd._lastHoverTime + constants.HOVERMINTIME) { hover(gd,evt,subplot); gd._lastHoverTime = Date.now(); return; @@ -292,7 +292,7 @@ fx.hover = function(gd, evt, subplot) { fx.unhover = function(gd, evt, subplot) { if(typeof gd === 'string') gd = document.getElementById(gd); // Important, clear any queued hovers - if (gd._hoverTimer) { + if(gd._hoverTimer) { clearTimeout(gd._hoverTimer); gd._hoverTimer = undefined; } @@ -301,8 +301,8 @@ fx.unhover = function(gd, evt, subplot) { // The actual implementation is here: -function hover(gd, evt, subplot){ - if(subplot === 'pie'){ +function hover(gd, evt, subplot) { + if(subplot === 'pie') { gd.emit('plotly_hover', { points: [evt] }); @@ -315,7 +315,7 @@ function hover(gd, evt, subplot){ plotinfo = fullLayout._plots[subplot], // list of all overlaid subplots to look at subplots = [subplot].concat(plotinfo.overlays - .map(function(pi){ return pi.id; })), + .map(function(pi) { return pi.id; })), xaArray = subplots.map(function(spId) { return Plotly.Axes.getFromId(gd, spId, 'x'); }), @@ -358,7 +358,7 @@ function hover(gd, evt, subplot){ // Figure out what we're hovering on: // mouse location or user-supplied data - if(Array.isArray(evt)){ + if(Array.isArray(evt)) { // user specified an array of points to highlight hovermode = 'array'; for(itemnum = 0; itemnum0) return Math.log(v)/Math.LN10; else if(v<=0 && clip && ax.range && ax.range.length===2) { @@ -55,8 +55,8 @@ module.exports = function setConvert(ax) { else return constants.BADNUM; } - function fromLog(v){ return Math.pow(10,v); } - function num(v){ return isNumeric(v) ? Number(v) : constants.BADNUM; } + function fromLog(v) { return Math.pow(10,v); } + function num(v) { return isNumeric(v) ? Number(v) : constants.BADNUM; } ax.c2l = (ax.type==='log') ? toLog : num; ax.l2c = (ax.type==='log') ? fromLog : num; @@ -64,7 +64,7 @@ module.exports = function setConvert(ax) { ax.p2d = function(v) { return ax.l2d(ax.p2l(v)); }; // set scaling to pixels - ax.setScale = function(){ + ax.setScale = function() { var gs = ax._td._fullLayout._size, i; @@ -131,11 +131,11 @@ module.exports = function setConvert(ax) { ax.p2l = function(px) { return (px-ax._b)/ax._m; }; ax.c2p = function(v, clip) { return ax.l2p(ax.c2l(v, clip)); }; - ax.p2c = function(px){ return ax.l2c(ax.p2l(px)); }; + ax.p2c = function(px) { return ax.l2c(ax.p2l(px)); }; if(['linear','log','-'].indexOf(ax.type)!==-1) { ax.c2d = num; - ax.d2c = function(v){ + ax.d2c = function(v) { v = cleanDatum(v); return isNumeric(v) ? Number(v) : constants.BADNUM; }; @@ -149,7 +149,7 @@ module.exports = function setConvert(ax) { return isNumeric(v) ? Lib.ms2DateTime(v) : constants.BADNUM; }; - ax.d2c = function(v){ + ax.d2c = function(v) { return (isNumeric(v)) ? Number(v) : Lib.dateTime2ms(v); }; @@ -185,7 +185,7 @@ module.exports = function setConvert(ax) { // TODO: sorting options - do the sorting // progressively here as we insert? - if(v !== null && v !== undefined && ax._categories.indexOf(v) === -1){ + if(v !== null && v !== undefined && ax._categories.indexOf(v) === -1) { ax._categories.push(v); } diff --git a/src/plots/cartesian/tick_defaults.js b/src/plots/cartesian/tick_defaults.js index 5479397daa5..7e8440617ec 100644 --- a/src/plots/cartesian/tick_defaults.js +++ b/src/plots/cartesian/tick_defaults.js @@ -42,7 +42,7 @@ module.exports = function handleTickDefaults(containerIn, containerOut, coerce, Lib.coerceFont(coerce, 'tickfont', options.font || {}); coerce('tickangle'); - if(axType !== 'category'){ + if(axType !== 'category') { var tickFormat = coerce('tickformat'); if(!tickFormat && axType !== 'date') { coerce('showexponent', showAttrDflt); @@ -72,10 +72,10 @@ function getShowAttrDflt(containerIn) { var showAttrsAll = ['showexponent', 'showtickprefix', 'showticksuffix'], - showAttrs = showAttrsAll.filter(function(a){ + showAttrs = showAttrsAll.filter(function(a) { return containerIn[a]!==undefined; }), - sameVal = function(a){ + sameVal = function(a) { return containerIn[a]===containerIn[showAttrs[0]]; }; diff --git a/src/plots/plots.js b/src/plots/plots.js index 15a5e24bd66..79bc17fe4fa 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -264,10 +264,10 @@ plots.redrawText = function(gd) { } return new Promise(function(resolve) { - setTimeout(function(){ + setTimeout(function() { Plotly.Annotations.drawAll(gd); Plotly.Legend.draw(gd); - (gd.calcdata||[]).forEach(function(d){ + (gd.calcdata||[]).forEach(function(d) { if(d[0]&&d[0].t&&d[0].t.cb) d[0].t.cb(); }); resolve(plots.previousPromises(gd)); @@ -307,7 +307,7 @@ plots.resize = function(gd) { plots.previousPromises = function(gd) { if((gd._promises || []).length) { return Promise.all(gd._promises) - .then(function(){ gd._promises=[]; }); + .then(function() { gd._promises=[]; }); } }; @@ -331,7 +331,7 @@ plots.addLinks = function(gd) { 'fill': Plotly.Color.defaultLine, 'pointer-events': 'all' }) - .each(function(){ + .each(function() { var links = d3.select(this); links.append('tspan').classed('js-link-to-tool', true); links.append('tspan').classed('js-link-spacer', true); @@ -376,7 +376,7 @@ plots.addLinks = function(gd) { // note that now this function is only adding the brand in // iframes and 3rd-party apps -function positionPlayWithData(gd, container){ +function positionPlayWithData(gd, container) { container.text(''); var link = container.append('a') .attr({ @@ -975,7 +975,7 @@ plots.doAutoMargin = function(gd) { * @param {Boolean} useDefaults If truthy, use _fullLayout and _fullData * @returns {Object|String} */ -plots.graphJson = function(gd, dataonly, mode, output, useDefaults){ +plots.graphJson = function(gd, dataonly, mode, output, useDefaults) { // if the defaults aren't supplied yet, we need to do that... if ((useDefaults && dataonly && !gd._fullData) || (useDefaults && !dataonly && !gd._fullLayout)) { @@ -1046,7 +1046,7 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults){ } var obj = { - data: (data || []).map(function(v){ + data: (data || []).map(function(v) { var d = stripObj(v); // fit has some little arrays in it that don't contain data, // just fit params and meta diff --git a/src/plots/polar/micropolar_manager.js b/src/plots/polar/micropolar_manager.js index 65a9f971a31..b3f1fddf23e 100644 --- a/src/plots/polar/micropolar_manager.js +++ b/src/plots/polar/micropolar_manager.js @@ -17,11 +17,11 @@ var manager = module.exports = {}; var extendDeepAll = Plotly.Lib.extendDeepAll; -manager.framework = function(_gd){ +manager.framework = function(_gd) { var config, previousConfigClone, plot, convertedInput, container; var undoManager = new UndoManager(); - function exports(_inputConfig, _container){ + function exports(_inputConfig, _container) { if(_container) container = _container; d3.select(d3.select(container).node().parentNode).selectAll('.svg-container>*:not(.chart-root)').remove(); @@ -38,22 +38,22 @@ manager.framework = function(_gd){ return config; } exports.isPolar = true; - exports.svg = function(){ return plot.svg(); }; - exports.getConfig = function(){ return config; }; - exports.getLiveConfig = function(){ + exports.svg = function() { return plot.svg(); }; + exports.getConfig = function() { return config; }; + exports.getLiveConfig = function() { return Plotly.micropolar.adapter.plotly().convert(plot.getLiveConfig(), true); }; - exports.getLiveScales = function(){ return {t: plot.angularScale(), r: plot.radialScale()}; }; - exports.setUndoPoint = function(){ + exports.getLiveScales = function() { return {t: plot.angularScale(), r: plot.radialScale()}; }; + exports.setUndoPoint = function() { var that = this; var configClone = Plotly.micropolar.util.cloneJson(config); - (function(_configClone, _previousConfigClone){ + (function(_configClone, _previousConfigClone) { undoManager.add({ - undo: function(){ + undo: function() { //console.log('undo', _previousConfigClone); if(_previousConfigClone) that(_previousConfigClone); }, - redo: function(){ + redo: function() { //console.log('redo', _configClone); that(_configClone); } @@ -61,8 +61,8 @@ manager.framework = function(_gd){ })(configClone, previousConfigClone); previousConfigClone = Plotly.micropolar.util.cloneJson(configClone); }; - exports.undo = function(){ undoManager.undo(); }; - exports.redo = function(){ undoManager.redo(); }; + exports.undo = function() { undoManager.undo(); }; + exports.redo = function() { undoManager.redo(); }; return exports; }; diff --git a/src/plots/polar/undo_manager.js b/src/plots/polar/undo_manager.js index 2dc75b8f73b..18174d38a9e 100644 --- a/src/plots/polar/undo_manager.js +++ b/src/plots/polar/undo_manager.js @@ -16,7 +16,7 @@ module.exports = function UndoManager() { isExecuting = false, callback; - function execute(command, action){ + function execute(command, action) { if(!command) return this; isExecuting = true; @@ -27,15 +27,15 @@ module.exports = function UndoManager() { } return { - add: function(command){ + add: function(command) { if(isExecuting) return this; undoCommands.splice(index + 1, undoCommands.length - index); undoCommands.push(command); index = undoCommands.length - 1; return this; }, - setCallback: function(callbackFunc){ callback = callbackFunc; }, - undo: function(){ + setCallback: function(callbackFunc) { callback = callbackFunc; }, + undo: function() { var command = undoCommands[index]; if(!command) return this; execute(command, 'undo'); @@ -43,7 +43,7 @@ module.exports = function UndoManager() { if(callback) callback(command.undo); return this; }, - redo: function(){ + redo: function() { var command = undoCommands[index + 1]; if(!command) return this; execute(command, 'redo'); @@ -51,14 +51,14 @@ module.exports = function UndoManager() { if(callback) callback(command.redo); return this; }, - clear: function(){ + clear: function() { undoCommands = []; index = -1; }, - hasUndo: function(){ return index !== -1; }, - hasRedo: function(){ return index < (undoCommands.length - 1); }, - getCommands: function(){ return undoCommands; }, - getPreviousCommand: function(){ return undoCommands[index-1]; }, - getIndex: function(){ return index; } + hasUndo: function() { return index !== -1; }, + hasRedo: function() { return index < (undoCommands.length - 1); }, + getCommands: function() { return undoCommands; }, + getPreviousCommand: function() { return undoCommands[index-1]; }, + getIndex: function() { return index; } }; }; diff --git a/src/traces/bar/hover.js b/src/traces/bar/hover.js index 5d431d8e5b6..a667baaec02 100644 --- a/src/traces/bar/hover.js +++ b/src/traces/bar/hover.js @@ -30,21 +30,21 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { var dx, dy; if(trace.orientation==='h') { - dx = function(di){ + dx = function(di) { // add a gradient so hovering near the end of a // bar makes it a little closer match return Fx.inbox(di.b-xval, di.x-xval) + (di.x-xval)/(di.x-di.b); }; - dy = function(di){ + dy = function(di) { var centerPos = barPos(di) - yval; return Fx.inbox(centerPos - barDelta, centerPos + barDelta); }; } else { - dy = function(di){ + dy = function(di) { return Fx.inbox(di.b-yval, di.y-yval) + (di.y-yval)/(di.y-di.b); }; - dx = function(di){ + dx = function(di) { var centerPos = barPos(di) - xval; return Fx.inbox(centerPos - barDelta, centerPos + barDelta); }; diff --git a/src/traces/bar/plot.js b/src/traces/bar/plot.js index f35bc3dca2f..316e813965b 100644 --- a/src/traces/bar/plot.js +++ b/src/traces/bar/plot.js @@ -31,7 +31,7 @@ module.exports = function plot(gd, plotinfo, cdbar) { bartraces.append('g') .attr('class','points') - .each(function(d){ + .each(function(d) { var t = d[0].t, trace = d[0].trace; @@ -40,7 +40,7 @@ module.exports = function plot(gd, plotinfo, cdbar) { d3.select(this).selectAll('path') .data(Lib.identity) .enter().append('path') - .each(function(di){ + .each(function(di) { // now display the bar // clipped xf/yf (2nd arg true): non-positive // log values go off-screen by plotwidth diff --git a/src/traces/bar/set_positions.js b/src/traces/bar/set_positions.js index 92740f8d9df..4e486113300 100644 --- a/src/traces/bar/set_positions.js +++ b/src/traces/bar/set_positions.js @@ -28,7 +28,7 @@ module.exports = function setPositions(gd, plotinfo) { ya = plotinfo.y(), i, j; - ['v', 'h'].forEach(function(dir){ + ['v', 'h'].forEach(function(dir) { var bl = [], pLetter = {v: 'x', h: 'y'}[dir], sLetter = {v: 'y', h: 'x'}[dir], @@ -56,7 +56,7 @@ module.exports = function setPositions(gd, plotinfo) { // find the min. difference between any points // in any traces in bl1 var pvals = []; - bl1.forEach(function(i){ + bl1.forEach(function(i) { gd.calcdata[i].forEach(function(v) { pvals.push(v.p); }); }); var dv = Lib.distinctVals(pvals), @@ -97,7 +97,7 @@ module.exports = function setPositions(gd, plotinfo) { var barCenter; function setBarCenter(v) { v[pLetter] = v.p + barCenter; } - for(var i = 0; i < bl1.length; i++){ + for(var i = 0; i < bl1.length; i++) { var t = gd.calcdata[bl1[i]][0].t; t.barwidth = barDiff * (1 - fullLayout.bargroupgap); t.poffset = ((overlap ? (2 * i + 1 - bl1.length) * barDiff : 0) - @@ -111,7 +111,7 @@ module.exports = function setPositions(gd, plotinfo) { } if(fullLayout.barmode === 'overlay') { - bl.forEach(function(bli){ barposition([bli]); }); + bl.forEach(function(bli) { barposition([bli]); }); } else barposition(bl); @@ -119,7 +119,7 @@ module.exports = function setPositions(gd, plotinfo) { norm = fullLayout.barnorm; // bar size range and stacking calculation - if(stack || norm){ + if(stack || norm) { // for stacked bars, we need to evaluate every step in every // stack, because negative bars mean the extremes could be // anywhere @@ -138,7 +138,7 @@ module.exports = function setPositions(gd, plotinfo) { ti, scale; - for(i = 0; i < bl.length; i++){ // trace index + for(i = 0; i < bl.length; i++) { // trace index ti = gd.calcdata[bl[i]]; for(j = 0; j < ti.length; j++) { sv = Math.round(ti[j].p / sumround); @@ -164,7 +164,7 @@ module.exports = function setPositions(gd, plotinfo) { tiny = top/1e9; // in case of rounding error in sum sMin = 0; sMax = stack ? top : 0; - for(i = 0; i < bl.length; i++){ // trace index + for(i = 0; i < bl.length; i++) { // trace index ti = gd.calcdata[bl[i]]; for(j = 0; j < ti.length; j++) { scale = top / sums[Math.round(ti[j].p/sumround)]; @@ -195,7 +195,7 @@ module.exports = function setPositions(gd, plotinfo) { // these bar tops in calcdata var fs = function(v) { v[sLetter] = v.s; return v.s; }; - for(i = 0; i < bl.length; i++){ + for(i = 0; i < bl.length; i++) { Axes.expand(sa, gd.calcdata[bl[i]].map(fs), {tozero: true, padded: true}); } diff --git a/src/traces/bar/style.js b/src/traces/bar/style.js index 5e05697880c..7b6ebd43f50 100644 --- a/src/traces/bar/style.js +++ b/src/traces/bar/style.js @@ -26,17 +26,17 @@ module.exports = function style(gd) { // for gapless (either stacked or neighboring grouped) bars use // crispEdges to turn off antialiasing so an artificial gap // isn't introduced. - .each(function(d){ + .each(function(d) { if((fullLayout.barmode==='stack' && barcount>1) || (fullLayout.bargap===0 && fullLayout.bargroupgap===0 && - !d[0].trace.marker.line.width)){ + !d[0].trace.marker.line.width)) { d3.select(this).attr('shape-rendering','crispEdges'); } }); // then style the individual bars - s.selectAll('g.points').each(function(d){ + s.selectAll('g.points').each(function(d) { var trace = d[0].trace, marker = trace.marker, markerLine = marker.line, diff --git a/src/traces/box/hover.js b/src/traces/box/hover.js index 236e08facf6..ef5fa9b52ae 100644 --- a/src/traces/box/hover.js +++ b/src/traces/box/hover.js @@ -29,10 +29,10 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { boxDelta = (hovermode==='closest') ? 2.5*t.bdPos : t.bdPos; if(trace.orientation === 'h') { - dx = function(di){ + dx = function(di) { return Fx.inbox(di.min - xval, di.max - xval); }; - dy = function(di){ + dy = function(di) { var pos = di.pos + t.bPos - yval; return Fx.inbox(pos - boxDelta, pos + boxDelta); }; @@ -41,11 +41,11 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { valLetter = 'x'; valAxis = xa; } else { - dx = function(di){ + dx = function(di) { var pos = di.pos + t.bPos - xval; return Fx.inbox(pos - boxDelta, pos + boxDelta); }; - dy = function(di){ + dy = function(di) { return Fx.inbox(di.min - yval, di.max - yval); }; posLetter = 'x'; diff --git a/src/traces/box/plot.js b/src/traces/box/plot.js index 48f220dd17f..71fbcf9c7e0 100644 --- a/src/traces/box/plot.js +++ b/src/traces/box/plot.js @@ -47,7 +47,7 @@ module.exports = function plot(gd, plotinfo, cdbox) { .enter().append('g') .attr('class','trace boxes'); - boxtraces.each(function(d){ + boxtraces.each(function(d) { var t = d[0].t, trace = d[0].trace, group = (fullLayout.boxmode==='group' && gd.numboxes>1), @@ -83,7 +83,7 @@ module.exports = function plot(gd, plotinfo, cdbox) { .data(Lib.identity) .enter().append('path') .attr('class','box') - .each(function(d){ + .each(function(d) { var posc = posAxis.c2p(d.pos + bPos, true), pos0 = posAxis.c2p(d.pos + bPos - bdPos, true), pos1 = posAxis.c2p(d.pos + bPos + bdPos, true), @@ -119,8 +119,8 @@ module.exports = function plot(gd, plotinfo, cdbox) { d3.select(this).selectAll('g.points') // since box plot points get an extra level of nesting, each // box needs the trace styling info - .data(function(d){ - d.forEach(function(v){ + .data(function(d) { + d.forEach(function(v) { v.t = t; v.trace = trace; }); @@ -129,9 +129,9 @@ module.exports = function plot(gd, plotinfo, cdbox) { .enter().append('g') .attr('class','points') .selectAll('path') - .data(function(d){ + .data(function(d) { var pts = (trace.boxpoints==='all') ? d.val : - d.val.filter(function(v){ return (vd.uf); }), + d.val.filter(function(v) { return (vd.uf); }), spreadLimit = (d.q3 - d.q1) * JITTERSPREAD, jitterFactors = [], maxJitterFactor = 0, @@ -164,7 +164,7 @@ module.exports = function plot(gd, plotinfo, cdbox) { newJitter = trace.jitter * 2 / maxJitterFactor; } - return pts.map(function(v, i){ + return pts.map(function(v, i) { var posOffset = trace.pointpos, p; if(trace.jitter) { @@ -200,7 +200,7 @@ module.exports = function plot(gd, plotinfo, cdbox) { .enter().append('path') .attr('class','mean') .style('fill','none') - .each(function(d){ + .each(function(d) { var posc = posAxis.c2p(d.pos + bPos, true), pos0 = posAxis.c2p(d.pos + bPos - bdPos, true), pos1 = posAxis.c2p(d.pos + bPos + bdPos, true), diff --git a/src/traces/box/style.js b/src/traces/box/style.js index 09eba91fcab..19216d93840 100644 --- a/src/traces/box/style.js +++ b/src/traces/box/style.js @@ -18,7 +18,7 @@ module.exports = function style(gd) { var s = d3.select(gd).selectAll('g.trace.boxes'); s.style('opacity', function(d) { return d[0].trace.opacity; }) - .each(function(d){ + .each(function(d) { var trace = d[0].trace, lineWidth = trace.line.width; d3.select(this).selectAll('path.box') diff --git a/src/traces/contour/colorbar.js b/src/traces/contour/colorbar.js index e51137488a5..f11972a2ced 100644 --- a/src/traces/contour/colorbar.js +++ b/src/traces/contour/colorbar.js @@ -22,7 +22,7 @@ module.exports = function colorbar(gd, cd) { gd._fullLayout._infolayer.selectAll('.' + cbId).remove(); - if(trace.showscale === false){ + if(trace.showscale === false) { Plots.autoMargin(gd, cbId); return; } @@ -37,11 +37,11 @@ module.exports = function colorbar(gd, cd) { scl = getColorscale(trace.colorscale), extraLevel = contours.coloring==='lines' ? 0 : 1, colormap = d3.scale.linear().interpolate(d3.interpolateRgb), - colorDomain = scl.map(function(si){ + colorDomain = scl.map(function(si) { return (si[0]*(nc+extraLevel-1)-(extraLevel/2)) * cs + contours.start; }), - colorRange = scl.map(function(si){ return si[1]; }); + colorRange = scl.map(function(si) { return si[1]; }); // colorbar fill and lines if(contours.coloring==='heatmap') { @@ -54,7 +54,7 @@ module.exports = function colorbar(gd, cd) { end: trace.zmax, size: (trace.zmax-trace.zmin)/254 }); - colorDomain = scl.map(function(si){ + colorDomain = scl.map(function(si) { return si[0]*(trace.zmax-trace.zmin) + trace.zmin; }); diff --git a/src/traces/contour/plot.js b/src/traces/contour/plot.js index e8cf7fc67a0..fc71afb0032 100644 --- a/src/traces/contour/plot.js +++ b/src/traces/contour/plot.js @@ -507,7 +507,7 @@ function makeFills(plotgroup, pathinfo, perimeter, contours) { .data(contours.coloring==='fill' ? pathinfo : []); fillitems.enter().append('path'); fillitems.exit().remove(); - fillitems.each(function(pi){ + fillitems.each(function(pi) { // join all paths for this level together into a single path // first follow clockwise around the perimeter to close any open paths // if the whole perimeter is above this level, start with a path @@ -524,7 +524,7 @@ function joinAllPaths(pi, perimeter) { var fullpath = (pi.edgepaths.length || pi.z[0][0] < pi.level) ? '' : ('M'+perimeter.join('L')+'Z'), i = 0, - startsleft = pi.edgepaths.map(function(v,i){ return i; }), + startsleft = pi.edgepaths.map(function(v,i) { return i; }), newloop = true, endpt, newendpt, @@ -620,23 +620,23 @@ function makeLines(plotgroup, pathinfo, contours) { linegroup.exit().remove(); var opencontourlines = linegroup.selectAll('path.openline') - .data(function(d){ return d.edgepaths; }); + .data(function(d) { return d.edgepaths; }); opencontourlines.enter().append('path') .classed('openline',true); opencontourlines.exit().remove(); opencontourlines - .attr('d', function(d){ + .attr('d', function(d) { return Drawing.smoothopen(d, smoothing); }) .style('stroke-miterlimit',1); var closedcontourlines = linegroup.selectAll('path.closedline') - .data(function(d){ return d.paths; }); + .data(function(d) { return d.paths; }); closedcontourlines.enter().append('path') .classed('closedline',true); closedcontourlines.exit().remove(); closedcontourlines - .attr('d', function(d){ + .attr('d', function(d) { return Drawing.smoothclosed(d, smoothing); }) .style('stroke-miterlimit',1); diff --git a/src/traces/contour/style.js b/src/traces/contour/style.js index e48ed71973d..998c9453839 100644 --- a/src/traces/contour/style.js +++ b/src/traces/contour/style.js @@ -30,12 +30,12 @@ module.exports = function style(gd) { scl = getColorscale(trace.colorscale), extraLevel = colorLines ? 0 : 1, colormap = d3.scale.linear() - .domain(scl.map(function(si){ + .domain(scl.map(function(si) { return (si[0]*(nc+extraLevel-1)-(extraLevel/2)) * cs + contours.start; })) .interpolate(d3.interpolateRgb) - .range(scl.map(function(si){ return si[1]; })); + .range(scl.map(function(si) { return si[1]; })); c.selectAll('g.contourlevel').each(function(d, i) { d3.select(this).selectAll('path') @@ -47,7 +47,7 @@ module.exports = function style(gd) { c.selectAll('g.contourbg path') .style('fill', colormap(contours.start - cs/2)); c.selectAll('g.contourfill path') - .style('fill',function(d, i){ + .style('fill',function(d, i) { return colormap(contours.start + (i+0.5)*cs); }); }); diff --git a/src/traces/heatmap/colorbar.js b/src/traces/heatmap/colorbar.js index e79775acf36..f56619b7643 100644 --- a/src/traces/heatmap/colorbar.js +++ b/src/traces/heatmap/colorbar.js @@ -30,15 +30,15 @@ module.exports = function colorbar(gd, cd) { gd._fullLayout._infolayer.selectAll('.' + cbId).remove(); - if(!trace.showscale){ + if(!trace.showscale) { Plots.autoMargin(gd, cbId); return; } var cb = cd[0].t.cb = drawColorbar(gd, cbId); cb.fillcolor(d3.scale.linear() - .domain(scl.map(function(v){ return zmin + v[0]*(zmax-zmin); })) - .range(scl.map(function(v){ return v[1]; }))) + .domain(scl.map(function(v) { return zmin + v[0]*(zmax-zmin); })) + .range(scl.map(function(v) { return v[1]; }))) .filllevels({start: zmin, end: zmax, size: (zmax-zmin)/254}) .options(trace.colorbar)(); diff --git a/src/traces/heatmap/plot.js b/src/traces/heatmap/plot.js index 7464185433e..14023970bbf 100644 --- a/src/traces/heatmap/plot.js +++ b/src/traces/heatmap/plot.js @@ -161,8 +161,8 @@ function plotOne(gd, plotinfo, cd) { // interpolate for color scale // use an array instead of color strings, so we preserve alpha var s = d3.scale.linear() - .domain(scl.map(function(si){ return si[0]; })) - .range(scl.map(function(si){ + .domain(scl.map(function(si) { return si[0]; })) + .range(scl.map(function(si) { var c = tinycolor(si[1]).toRgb(); return [c.r, c.g, c.b, c.a]; })) @@ -180,11 +180,11 @@ function plotOne(gd, plotinfo, cd) { Lib.identity; } else { - xpx = function(index){ + xpx = function(index) { return Lib.constrain(Math.round(xa.c2p(x[index]) - left), 0, imageWidth); }; - ypx = function(index){ + ypx = function(index) { return Lib.constrain(Math.round(ya.c2p(y[index]) - top), 0, imageHeight); }; diff --git a/src/traces/histogram2d/calc.js b/src/traces/histogram2d/calc.js index 3c1a3f309a7..de7bd39a318 100644 --- a/src/traces/histogram2d/calc.js +++ b/src/traces/histogram2d/calc.js @@ -127,11 +127,11 @@ module.exports = function calc(gd, trace) { y0 += dy/2; if(densitynorm) { - xinc = onecol.map(function(v,i){ + xinc = onecol.map(function(v,i) { if(Array.isArray(xbins)) return 1/(xbins[i+1]-xbins[i]); return 1/dx; }); - yinc = z.map(function(v,i){ + yinc = z.map(function(v,i) { if(Array.isArray(ybins)) return 1/(ybins[i+1]-ybins[i]); return 1/dy; }); diff --git a/src/traces/scatter/colorbar.js b/src/traces/scatter/colorbar.js index 411d7a6509c..d15e1d8ecb4 100644 --- a/src/traces/scatter/colorbar.js +++ b/src/traces/scatter/colorbar.js @@ -28,7 +28,7 @@ module.exports = function colorbar(gd, cd) { // TODO unify Scatter.colorbar and Heatmap.colorbar // TODO make Plotly[module].colorbar support multiple colorbar per trace - if((marker === undefined) || !marker.showscale){ + if((marker === undefined) || !marker.showscale) { Plots.autoMargin(gd, cbId); return; } @@ -44,8 +44,8 @@ module.exports = function colorbar(gd, cd) { var cb = cd[0].t.cb = drawColorbar(gd, cbId); cb.fillcolor(d3.scale.linear() - .domain(scl.map(function(v){ return cmin + v[0] * (cmax - cmin); })) - .range(scl.map(function(v){ return v[1]; }))) + .domain(scl.map(function(v) { return cmin + v[0] * (cmax - cmin); })) + .range(scl.map(function(v) { return v[1]; }))) .filllevels({start: cmin, end: cmax, size: (cmax - cmin) / 254}) .options(marker.colorbar)(); diff --git a/src/traces/scatter/plot.js b/src/traces/scatter/plot.js index 09345bcea7d..8be8f3274be 100644 --- a/src/traces/scatter/plot.js +++ b/src/traces/scatter/plot.js @@ -38,7 +38,7 @@ module.exports = function plot(gd, plotinfo, cdscatter) { var prevpath = '', tozero, tonext, nexttonext; - scattertraces.each(function(d){ + scattertraces.each(function(d) { var trace = d[0].trace, line = trace.line, tr = d3.select(this); @@ -145,7 +145,7 @@ module.exports = function plot(gd, plotinfo, cdscatter) { // remove paths that didn't get used scattertraces.selectAll('path:not([d])').remove(); - function visFilter(d){ + function visFilter(d) { return d.filter(function(v) { return v.vis; }); } diff --git a/src/traces/scatter/style.js b/src/traces/scatter/style.js index e788ed257f6..a6d434ff2af 100644 --- a/src/traces/scatter/style.js +++ b/src/traces/scatter/style.js @@ -22,7 +22,7 @@ module.exports = function style(gd) { }); s.selectAll('g.points') - .each(function(d){ + .each(function(d) { d3.select(this).selectAll('path.point') .call(Drawing.pointStyle, d.trace || d[0].trace); d3.select(this).selectAll('text') diff --git a/src/traces/scattergeo/plot.js b/src/traces/scattergeo/plot.js index 8c16d3159b8..4408835a2ed 100644 --- a/src/traces/scattergeo/plot.js +++ b/src/traces/scattergeo/plot.js @@ -212,7 +212,7 @@ plotScatterGeo.style = function(geo) { selection.style('opacity', function(trace) { return trace.opacity; }); selection.selectAll('g.points') - .each(function(trace){ + .each(function(trace) { d3.select(this).selectAll('path.point') .call(Drawing.pointStyle, trace); d3.select(this).selectAll('text') diff --git a/tasks/header.js b/tasks/header.js index 96b327946c0..541956b7204 100644 --- a/tasks/header.js +++ b/tasks/header.js @@ -34,7 +34,7 @@ var licenseStr = licenseSrc.substring(2, licenseSrc.length - 2); var srcGlob = path.join(constants.pathToSrc, '**/*.js'); var libGlob = path.join(constants.pathToLib, '**/*.js'); -glob('{' + srcGlob + ',' + libGlob + '}', function(err, files){ +glob('{' + srcGlob + ',' + libGlob + '}', function(err, files) { files.forEach(function(file) { fs.readFile(file, 'utf-8', function(err, code) { diff --git a/test/jasmine/assets/custom_matchers.js b/test/jasmine/assets/custom_matchers.js index 549e6369129..1e5c52a4678 100644 --- a/test/jasmine/assets/custom_matchers.js +++ b/test/jasmine/assets/custom_matchers.js @@ -1,10 +1,10 @@ module.exports = { // toBeCloseTo... but for arrays - toBeCloseToArray: function(){ + toBeCloseToArray: function() { return { compare: function(actual, expected, precision) { - if(precision !== 0){ + if(precision !== 0) { precision = Math.pow(10, -precision) / 2 || 0.005; } diff --git a/test/jasmine/tests/click_test.js b/test/jasmine/tests/click_test.js index 5740f7f7f73..28227a14ce9 100644 --- a/test/jasmine/tests/click_test.js +++ b/test/jasmine/tests/click_test.js @@ -131,7 +131,7 @@ describe('click interactions', function() { } it('when set to \'reset+autorange\' (the default) should work when \'autorange\' is on', function(done) { - Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function(){ + Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() { expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX); expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY); @@ -152,7 +152,7 @@ describe('click interactions', function() { it('when set to \'reset+autorange\' (the default) should reset to set range on double click', function(done) { mockCopy = setRanges(mockCopy); - Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function(){ + Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() { expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX); expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY); @@ -173,7 +173,7 @@ describe('click interactions', function() { it('when set to \'reset+autorange\' (the default) should autosize on 1st double click and reset on 2nd', function(done) { mockCopy = setRanges(mockCopy); - Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function(){ + Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() { expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX); expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY); diff --git a/test/jasmine/tests/lib_test.js b/test/jasmine/tests/lib_test.js index 1f148f05f20..fd1a2f5c28b 100644 --- a/test/jasmine/tests/lib_test.js +++ b/test/jasmine/tests/lib_test.js @@ -300,7 +300,7 @@ describe('Test lib.js:', function() { // we don't need this, it's better just to set the whole // array, ie np(obj, 'arr') var obj = {arr: [1, 2, 3]}; - expect(function(){ np(obj, 'arr[-1]'); }).toThrow('bad property string'); + expect(function() { np(obj, 'arr[-1]'); }).toThrow('bad property string'); }); it('should access properties of objects in an array with index -1', function() { diff --git a/test/jasmine/tests/plot_promise_test.js b/test/jasmine/tests/plot_promise_test.js index e1df695fbdc..2ef2585851a 100644 --- a/test/jasmine/tests/plot_promise_test.js +++ b/test/jasmine/tests/plot_promise_test.js @@ -18,7 +18,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.plot(createGraphDiv(), data, {}); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -50,7 +50,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.plot(gd, data, {}); - promise.then(null, function(){ + promise.then(null, function() { promiseRejected = true; done(); }); @@ -76,7 +76,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.plot(gd, data, {}); - promise.then(null, function(){ + promise.then(null, function() { promiseRejected = true; done(); }); @@ -100,7 +100,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.redraw(initialDiv); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -123,7 +123,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.newPlot(createGraphDiv(), data, {}); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -149,7 +149,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.extendTraces(initialDiv, { y: [[2]] }, [0], 3); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -175,7 +175,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.prependTraces(initialDiv, { y: [[2]] }, [0], 3); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -201,7 +201,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.addTraces(initialDiv, [{ x: [1,2,3], y: [1,2,3] }], [1]); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -227,7 +227,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.deleteTraces(initialDiv, [0]); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -253,7 +253,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.deleteTraces(initialDiv, [0]); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -282,7 +282,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.moveTraces(initialDiv, 0, 1); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -308,7 +308,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.restyle(initialDiv, 'marker.color', 'rgb(255,0,0)'); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -334,7 +334,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.restyle(initialDiv, undefined, ''); - promise.then(null, function(){ + promise.then(null, function() { promiseRejected = true; done(); }); @@ -358,7 +358,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.relayout(initialDiv, 'hovermode', false); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -385,7 +385,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.relayout(initialDiv, 'hovermode', false); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -413,7 +413,7 @@ describe('Plotly.___ methods', function() { initialDiv.framework = { isPolar: true }; promise = Plotly.relayout(initialDiv, 'hovermode', false); - promise.then(function(gd){ + promise.then(function(gd) { promiseGd = gd; done(); }); @@ -439,7 +439,7 @@ describe('Plotly.___ methods', function() { promise = Plotly.relayout(initialDiv, undefined, false); - promise.then(null, function(){ + promise.then(null, function() { promiseRejected = true; done(); }); From fa7afedd50da1f6667461a8a93c7feabc233383e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 29 Feb 2016 14:52:28 -0500 Subject: [PATCH 5/5] lint leftovers from rebase --- src/components/legend/index.js | 8 +- src/plot_api/plot_api.js | 154 ++++++++++++++++----------------- src/plots/gl3d/scene.js | 24 ++--- src/plots/plots.js | 40 ++++----- 4 files changed, 113 insertions(+), 113 deletions(-) diff --git a/src/components/legend/index.js b/src/components/legend/index.js index 892cbd78544..61931f2e396 100644 --- a/src/components/legend/index.js +++ b/src/components/legend/index.js @@ -795,9 +795,9 @@ legend.repositionLegend = function(td, traces) { Plots.autoMargin(td,'legend',{ x: opts.x, y: opts.y, - l: opts.width * ({right:1, center:0.5}[xanchor] || 0), - r: opts.width * ({left:1, center:0.5}[xanchor] || 0), - b: opts.height * ({top:1, middle:0.5}[yanchor] || 0), - t: opts.height * ({bottom:1, middle:0.5}[yanchor] || 0) + l: opts.width * ({right: 1, center: 0.5}[xanchor] || 0), + r: opts.width * ({left: 1, center: 0.5}[xanchor] || 0), + b: opts.height * ({top: 1, middle: 0.5}[yanchor] || 0), + t: opts.height * ({bottom: 1, middle: 0.5}[yanchor] || 0) }); }; diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index effb40c96ed..e4eda4ca963 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -181,10 +181,10 @@ Plotly.plot = function(gd, data, layout, config) { Legend.draw(gd); - for (i = 0; i < calcdata.length; i++) { + for(i = 0; i < calcdata.length; i++) { cd = calcdata[i]; trace = cd[0].trace; - if (trace.visible !== true || !trace._module.colorbar) { + if(trace.visible !== true || !trace._module.colorbar) { Plots.autoMargin(gd, 'cb'+trace.uid); } else trace._module.colorbar(gd, cd); @@ -601,7 +601,7 @@ function cleanLayout(layout) { /* * Moved from rotate -> orbit for dragmode */ - if (layout.dragmode === 'rotate') layout.dragmode = 'orbit'; + if(layout.dragmode === 'rotate') layout.dragmode = 'orbit'; // cannot have scene1, numbering goes scene, scene2, scene3... if(layout.scene1) { @@ -671,7 +671,7 @@ function cleanData(data, existingData) { for(var tracei = 0; tracei < data.length; tracei++) { var trace = data[tracei]; // assign uids to each trace and detect collisions. - if (!('uid' in trace) || suids.indexOf(trace.uid) !== -1) { + if(!('uid' in trace) || suids.indexOf(trace.uid) !== -1) { var newUid, i; for(i=0; i<100; i++) { newUid = Lib.randstr(uids); @@ -841,28 +841,28 @@ function doCalcdata(gd) { // delete category list, if there is one, so we start over // to be filled in later by ax.d2c - for (i = 0; i < axList.length; i++) { + for(i = 0; i < axList.length; i++) { axList[i]._categories = []; } - for (i = 0; i < fullData.length; i++) { + for(i = 0; i < fullData.length; i++) { trace = fullData[i]; module = trace._module; cd = []; - if (module && trace.visible === true) { - if (module.calc) cd = module.calc(gd, trace); + if(module && trace.visible === true) { + if(module.calc) cd = module.calc(gd, trace); } // make sure there is a first point // this ensures there is a calcdata item for every trace, // even if cartesian logic doesn't handle it - if (!Array.isArray(cd) || !cd[0]) cd = [{x: false, y: false}]; + if(!Array.isArray(cd) || !cd[0]) cd = [{x: false, y: false}]; // add the trace-wide properties to the first point, // per point properties to every point // t is the holder for trace-wide properties - if (!cd[0].t) cd[0].t = {}; + if(!cd[0].t) cd[0].t = {}; cd[0].trace = trace; Lib.markTime('done with calcdata for '+i); @@ -882,9 +882,9 @@ function positivifyIndices(indices, maxIndex) { i, index; - for (i = 0; i < indices.length; i++) { + for(i = 0; i < indices.length; i++) { index = indices[i]; - if (index < 0) { + if(index < 0) { positiveIndices.push(parentLength + index); } else { positiveIndices.push(index); @@ -906,21 +906,21 @@ function assertIndexArray(gd, indices, arrayName) { var i, index; - for (i = 0; i < indices.length; i++) { + for(i = 0; i < indices.length; i++) { index = indices[i]; // validate that indices are indeed integers - if (index !== parseInt(index, 10)) { + if(index !== parseInt(index, 10)) { throw new Error('all values in ' + arrayName + ' must be integers'); } // check that all indices are in bounds for given gd.data array length - if (index >= gd.data.length || index < -gd.data.length) { + if(index >= gd.data.length || index < -gd.data.length) { throw new Error(arrayName + ' must be valid indices for gd.data.'); } // check that indices aren't repeated - if (indices.indexOf(index, i + 1) > -1 || + if(indices.indexOf(index, i + 1) > -1 || index >= 0 && indices.indexOf(-gd.data.length + index) > -1 || index < 0 && indices.indexOf(gd.data.length + index) > -1) { throw new Error('each index in ' + arrayName + ' must be unique.'); @@ -938,28 +938,28 @@ function assertIndexArray(gd, indices, arrayName) { function checkMoveTracesArgs(gd, currentIndices, newIndices) { // check that gd has attribute 'data' and 'data' is array - if (!Array.isArray(gd.data)) { + if(!Array.isArray(gd.data)) { throw new Error('gd.data must be an array.'); } // validate currentIndices array - if (typeof currentIndices === 'undefined') { + if(typeof currentIndices === 'undefined') { throw new Error('currentIndices is a required argument.'); - } else if (!Array.isArray(currentIndices)) { + } else if(!Array.isArray(currentIndices)) { currentIndices = [currentIndices]; } assertIndexArray(gd, currentIndices, 'currentIndices'); // validate newIndices array if it exists - if (typeof newIndices !== 'undefined' && !Array.isArray(newIndices)) { + if(typeof newIndices !== 'undefined' && !Array.isArray(newIndices)) { newIndices = [newIndices]; } - if (typeof newIndices !== 'undefined') { + if(typeof newIndices !== 'undefined') { assertIndexArray(gd, newIndices, 'newIndices'); } // check currentIndices and newIndices are the same length if newIdices exists - if (typeof newIndices !== 'undefined' && currentIndices.length !== newIndices.length) { + if(typeof newIndices !== 'undefined' && currentIndices.length !== newIndices.length) { throw new Error('current and new indices must be of equal length.'); } @@ -976,33 +976,33 @@ function checkAddTracesArgs(gd, traces, newIndices) { value; // check that gd has attribute 'data' and 'data' is array - if (!Array.isArray(gd.data)) { + if(!Array.isArray(gd.data)) { throw new Error('gd.data must be an array.'); } // make sure traces exists - if (typeof traces === 'undefined') { + if(typeof traces === 'undefined') { throw new Error('traces must be defined.'); } // make sure traces is an array - if (!Array.isArray(traces)) { + if(!Array.isArray(traces)) { traces = [traces]; } // make sure each value in traces is an object - for (i = 0; i < traces.length; i++) { + for(i = 0; i < traces.length; i++) { value = traces[i]; - if (typeof value !== 'object' || (Array.isArray(value) || value === null)) { + if(typeof value !== 'object' || (Array.isArray(value) || value === null)) { throw new Error('all values in traces array must be non-array objects'); } } // make sure we have an index for each trace - if (typeof newIndices !== 'undefined' && !Array.isArray(newIndices)) { + if(typeof newIndices !== 'undefined' && !Array.isArray(newIndices)) { newIndices = [newIndices]; } - if (typeof newIndices !== 'undefined' && newIndices.length !== traces.length) { + if(typeof newIndices !== 'undefined' && newIndices.length !== traces.length) { throw new Error( 'if indices is specified, traces.length must equal indices.length' ); @@ -1023,33 +1023,33 @@ function assertExtendTracesArgs(gd, update, indices, maxPoints) { var maxPointsIsObject = Lib.isPlainObject(maxPoints); - if (!Array.isArray(gd.data)) { + if(!Array.isArray(gd.data)) { throw new Error('gd.data must be an array'); } - if (!Lib.isPlainObject(update)) { + if(!Lib.isPlainObject(update)) { throw new Error('update must be a key:value object'); } - if (typeof indices === 'undefined') { + if(typeof indices === 'undefined') { throw new Error('indices must be an integer or array of integers'); } assertIndexArray(gd, indices, 'indices'); - for (var key in update) { + for(var key in update) { /* * Verify that the attribute to be updated contains as many trace updates * as indices. Failure must result in throw and no-op */ - if (!Array.isArray(update[key]) || update[key].length !== indices.length) { + if(!Array.isArray(update[key]) || update[key].length !== indices.length) { throw new Error('attribute ' + key + ' must be an array of length equal to indices array length'); } /* * if maxPoints is an object it must match keys and array lengths of 'update' 1:1 */ - if (maxPointsIsObject && + if(maxPointsIsObject && (!(key in maxPoints) || !Array.isArray(maxPoints[key]) || maxPoints[key].length !== update[key].length)) { throw new Error('when maxPoints is set as a key:value object it must contain a 1:1 ' + @@ -1074,15 +1074,15 @@ function getExtendProperties(gd, update, indices, maxPoints) { var trace, target, prop, insert, maxp; // allow scalar index to represent a single trace position - if (!Array.isArray(indices)) indices = [indices]; + if(!Array.isArray(indices)) indices = [indices]; // negative indices are wrapped around to their positive value. Equivalent to python indexing. indices = positivifyIndices(indices, gd.data.length - 1); // loop through all update keys and traces and harvest validated data. - for (var key in update) { + for(var key in update) { - for (var j = 0; j < indices.length; j++) { + for(var j = 0; j < indices.length; j++) { /* * Choose the trace indexed by the indices map argument and get the prop setter-getter @@ -1098,10 +1098,10 @@ function getExtendProperties(gd, update, indices, maxPoints) { target = prop.get(); insert = update[key][j]; - if (!Array.isArray(insert)) { + if(!Array.isArray(insert)) { throw new Error('attribute: ' + key + ' index: ' + j + ' must be an array'); } - if (!Array.isArray(target)) { + if(!Array.isArray(target)) { throw new Error('cannot extend missing or non-array attribute: ' + key); } @@ -1112,7 +1112,7 @@ function getExtendProperties(gd, update, indices, maxPoints) { maxp = maxPointsIsObject ? maxPoints[key][j] : maxPoints; // could have chosen null here, -1 just tells us to not take a window - if (!isNumeric(maxp)) maxp = -1; + if(!isNumeric(maxp)) maxp = -1; /* * Wrap the nestedProperty in an object containing required data @@ -1153,7 +1153,7 @@ function spliceTraces(gd, update, indices, maxPoints, lengthenArray, spliceArray undoPoints = {}; var target, prop, maxp; - for (var i = 0; i < updateProps.length; i++) { + for(var i = 0; i < updateProps.length; i++) { /* * prop is the object returned by Lib.nestedProperties @@ -1167,7 +1167,7 @@ function spliceTraces(gd, update, indices, maxPoints, lengthenArray, spliceArray * If maxp is set within post-extension trace.length, splice to maxp length. * Otherwise skip function call as splice op will have no effect anyway. */ - if (maxp >= 0 && maxp < target.length) remainder = spliceArray(target, maxp); + if(maxp >= 0 && maxp < target.length) remainder = spliceArray(target, maxp); /* * to reverse this operation we need the size of the original trace as the reverse @@ -1180,8 +1180,8 @@ function spliceTraces(gd, update, indices, maxPoints, lengthenArray, spliceArray */ prop.set(target); - if (!Array.isArray(undoUpdate[prop.astr])) undoUpdate[prop.astr] = []; - if (!Array.isArray(undoPoints[prop.astr])) undoPoints[prop.astr] = []; + if(!Array.isArray(undoUpdate[prop.astr])) undoUpdate[prop.astr] = []; + if(!Array.isArray(undoPoints[prop.astr])) undoPoints[prop.astr] = []; /* * build the inverse update object for the undo operation @@ -1236,7 +1236,7 @@ Plotly.extendTraces = function extendTraces(gd, update, indices, maxPoints) { var promise = Plotly.redraw(gd); var undoArgs = [gd, undo.update, indices, undo.maxPoints]; - if (Queue) { + if(Queue) { Queue.add(gd, Plotly.prependTraces, undoArgs, extendTraces, arguments); } @@ -1265,7 +1265,7 @@ Plotly.prependTraces = function prependTraces(gd, update, indices, maxPoints) { var promise = Plotly.redraw(gd); var undoArgs = [gd, undo.update, indices, undo.maxPoints]; - if (Queue) { + if(Queue) { Queue.add(gd, Plotly.extendTraces, undoArgs, prependTraces, arguments); } @@ -1296,31 +1296,31 @@ Plotly.addTraces = function addTraces(gd, traces, newIndices) { checkAddTracesArgs(gd, traces, newIndices); // make sure traces is an array - if (!Array.isArray(traces)) { + if(!Array.isArray(traces)) { traces = [traces]; } cleanData(traces, gd.data); // add the traces to gd.data (no redrawing yet!) - for (i = 0; i < traces.length; i += 1) { + for(i = 0; i < traces.length; i += 1) { gd.data.push(traces[i]); } // to continue, we need to call moveTraces which requires currentIndices - for (i = 0; i < traces.length; i++) { + for(i = 0; i < traces.length; i++) { currentIndices.push(-traces.length + i); } // if the user didn't define newIndices, they just want the traces appended // i.e., we can simply redraw and be done - if (typeof newIndices === 'undefined') { + if(typeof newIndices === 'undefined') { promise = Plotly.redraw(gd); - if (Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); + if(Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); return promise; } // make sure indices is property defined - if (!Array.isArray(newIndices)) { + if(!Array.isArray(newIndices)) { newIndices = [newIndices]; } @@ -1338,10 +1338,10 @@ Plotly.addTraces = function addTraces(gd, traces, newIndices) { // if we're here, the user has defined specific places to place the new traces // this requires some extra work that moveTraces will do - if (Queue) Queue.startSequence(gd); - if (Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); + if(Queue) Queue.startSequence(gd); + if(Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); promise = Plotly.moveTraces(gd, currentIndices, newIndices); - if (Queue) Queue.stopSequence(gd); + if(Queue) Queue.stopSequence(gd); return promise; }; @@ -1364,9 +1364,9 @@ Plotly.deleteTraces = function deleteTraces(gd, indices) { deletedTrace; // make sure indices are defined - if (typeof indices === 'undefined') { + if(typeof indices === 'undefined') { throw new Error('indices must be an integer or array of integers.'); - } else if (!Array.isArray(indices)) { + } else if(!Array.isArray(indices)) { indices = [indices]; } assertIndexArray(gd, indices, 'indices'); @@ -1376,14 +1376,14 @@ Plotly.deleteTraces = function deleteTraces(gd, indices) { // we want descending here so that splicing later doesn't affect indexing indices.sort(Lib.sorterDes); - for (i = 0; i < indices.length; i += 1) { + for(i = 0; i < indices.length; i += 1) { deletedTrace = gd.data.splice(indices[i], 1)[0]; traces.push(deletedTrace); } var promise = Plotly.redraw(gd); - if (Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); + if(Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); return promise; }; @@ -1438,9 +1438,9 @@ Plotly.moveTraces = function moveTraces(gd, currentIndices, newIndices) { currentIndices = Array.isArray(currentIndices) ? currentIndices : [currentIndices]; // if undefined, define newIndices to point to the end of gd.data array - if (typeof newIndices === 'undefined') { + if(typeof newIndices === 'undefined') { newIndices = []; - for (i = 0; i < currentIndices.length; i++) { + for(i = 0; i < currentIndices.length; i++) { newIndices.push(-currentIndices.length + i); } } @@ -1455,16 +1455,16 @@ Plotly.moveTraces = function moveTraces(gd, currentIndices, newIndices) { // at this point, we've coerced the index arrays into predictable forms // get the traces that aren't being moved around - for (i = 0; i < gd.data.length; i++) { + for(i = 0; i < gd.data.length; i++) { // if index isn't in currentIndices, include it in ignored! - if (currentIndices.indexOf(i) === -1) { + if(currentIndices.indexOf(i) === -1) { newData.push(gd.data[i]); } } // get a mapping of indices to moving traces - for (i = 0; i < currentIndices.length; i++) { + for(i = 0; i < currentIndices.length; i++) { movingTraceMap.push({newIndex: newIndices[i], trace: gd.data[currentIndices[i]]}); } @@ -1474,7 +1474,7 @@ Plotly.moveTraces = function moveTraces(gd, currentIndices, newIndices) { }); // now, add the moving traces back in, in order! - for (i = 0; i < movingTraceMap.length; i += 1) { + for(i = 0; i < movingTraceMap.length; i += 1) { newData.splice(movingTraceMap[i].newIndex, 0, movingTraceMap[i].trace); } @@ -1482,7 +1482,7 @@ Plotly.moveTraces = function moveTraces(gd, currentIndices, newIndices) { var promise = Plotly.redraw(gd); - if (Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); + if(Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); return promise; }; @@ -1846,11 +1846,11 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { } // swap hovermode if set to "compare x/y data" - if (ai === 'orientationaxes') { + if(ai === 'orientationaxes') { var hovermode = Lib.nestedProperty(gd.layout, 'hovermode'); - if (hovermode.get() === 'x') { + if(hovermode.get() === 'x') { hovermode.set('y'); - } else if (hovermode.get() === 'y') { + } else if(hovermode.get() === 'y') { hovermode.set('x'); } } @@ -1927,7 +1927,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { // do we need to force a recalc? var autorangeOn = false; - Plotly.Axes.list(gd).forEach(function(ax){ + Plotly.Axes.list(gd).forEach(function(ax) { if(ax.autorange) autorangeOn = true; }); if(docalc || dolayout || (docalcAutorange && autorangeOn)) { @@ -2180,7 +2180,7 @@ Plotly.relayout = function relayout(gd, astr, val) { // logical XOR (ie are we toggling log) if(pleaf==='type' && ((parentFull.type === 'log') !== (vi === 'log'))) { var ax = parentIn; - if (!ax || !ax.range) { + if(!ax || !ax.range) { doextra(ptrunk+'.autorange', true); } else if(!parentFull.autorange) { @@ -2259,8 +2259,8 @@ Plotly.relayout = function relayout(gd, astr, val) { else { // check whether we can short-circuit a full redraw // 3d or geo at this point just needs to redraw. - if (p.parts[0].indexOf('scene') === 0) doplot = true; - else if (p.parts[0].indexOf('geo') === 0) doplot = true; + if(p.parts[0].indexOf('scene') === 0) doplot = true; + else if(p.parts[0].indexOf('geo') === 0) doplot = true; else if(fullLayout._hasGL2D && (ai.indexOf('axis') !== -1 || p.parts[0] === 'plot_bgcolor') ) doplot = true; @@ -2404,9 +2404,9 @@ function calculateReservedMargins(margins) { var resultingMargin = {left: 0, right: 0, bottom: 0, top: 0}, marginName; - if (margins) { - for (marginName in margins) { - if (margins.hasOwnProperty(marginName)) { + if(margins) { + for(marginName in margins) { + if(margins.hasOwnProperty(marginName)) { resultingMargin.left += margins[marginName].left || 0; resultingMargin.right += margins[marginName].right || 0; resultingMargin.bottom += margins[marginName].bottom || 0; diff --git a/src/plots/gl3d/scene.js b/src/plots/gl3d/scene.js index 887b33c8dc3..a7800eb7f9b 100644 --- a/src/plots/gl3d/scene.js +++ b/src/plots/gl3d/scene.js @@ -49,13 +49,13 @@ function render(scene) { var keys = Object.keys(scene.traces); var lastPicked = null; var selection = scene.glplot.selection; - for (var i = 0; i < keys.length; ++i) { + for(var i = 0; i < keys.length; ++i) { var trace = scene.traces[keys[i]]; if(trace.handlePick(selection)) { lastPicked = trace; } - if (trace.setContourLevels) trace.setContourLevels(); + if(trace.setContourLevels) trace.setContourLevels(); } function formatter(axisName, val) { @@ -162,7 +162,7 @@ function initializeGLPlot(scene, fullLayout, canvas, gl) { try { scene.glplot = createPlot(glplotOptions); } - catch (e) { + catch(e) { /* * createPlot will throw when webgl is not enabled in the client. * Lets return an instance of the module with all functions noop'd. @@ -321,7 +321,7 @@ proto.plot = function(sceneData, fullLayout, layout) { var fullSceneLayout = fullLayout[this.id]; var sceneLayout = layout[this.id]; - if (fullSceneLayout.bgcolor) this.glplot.clearColor = str2RGBAarray(fullSceneLayout.bgcolor); + if(fullSceneLayout.bgcolor) this.glplot.clearColor = str2RGBAarray(fullSceneLayout.bgcolor); else this.glplot.clearColor = [0, 0, 0, 0]; this.glplot.snapToData = true; @@ -340,7 +340,7 @@ proto.plot = function(sceneData, fullLayout, layout) { this.glplot.update({}); // Update axes functions BEFORE updating traces - for (i = 0; i < 3; ++i) { + for(i = 0; i < 3; ++i) { var axis = fullSceneLayout[axisProperties[i]]; setConvert(axis); } @@ -484,9 +484,9 @@ proto.plot = function(sceneData, fullLayout, layout) { var axisAutoScaleFactor = 4; var aspectRatio; - if (fullSceneLayout.aspectmode === 'auto') { + if(fullSceneLayout.aspectmode === 'auto') { - if (Math.max.apply(null, axesScaleRatio)/Math.min.apply(null, axesScaleRatio) <= axisAutoScaleFactor) { + if(Math.max.apply(null, axesScaleRatio)/Math.min.apply(null, axesScaleRatio) <= axisAutoScaleFactor) { /* * USE DATA MODE WHEN AXIS RANGE DIMENSIONS ARE RELATIVELY EQUAL @@ -501,13 +501,13 @@ proto.plot = function(sceneData, fullLayout, layout) { aspectRatio = [1, 1, 1]; } - } else if (fullSceneLayout.aspectmode === 'cube') { + } else if(fullSceneLayout.aspectmode === 'cube') { aspectRatio = [1, 1, 1]; - } else if (fullSceneLayout.aspectmode === 'data') { + } else if(fullSceneLayout.aspectmode === 'data') { aspectRatio = axesScaleRatio; - } else if (fullSceneLayout.aspectmode === 'manual') { + } else if(fullSceneLayout.aspectmode === 'manual') { var userRatio = fullSceneLayout.aspectratio; aspectRatio = [userRatio.x, userRatio.y, userRatio.z]; @@ -534,7 +534,7 @@ proto.plot = function(sceneData, fullLayout, layout) { var domain = fullSceneLayout.domain || null, size = fullLayout._size || null; - if (domain && size) { + if(domain && size) { var containerStyle = this.container.style; containerStyle.position = 'absolute'; containerStyle.left = (size.l + domain.x[0] * size.w) + 'px'; @@ -646,7 +646,7 @@ proto.updateFx = function(dragmode, hovermode) { }; proto.toImage = function(format) { - if (!format) format = 'png'; + if(!format) format = 'png'; if(this.staticMode) this.container.appendChild(STATIC_CANVAS); diff --git a/src/plots/plots.js b/src/plots/plots.js index 79bc17fe4fa..a65162ffc92 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -279,14 +279,14 @@ plots.redrawText = function(gd) { plots.resize = function(gd) { return new Promise(function(resolve, reject) { - if (!gd || d3.select(gd).style('display') === 'none'){ + if(!gd || d3.select(gd).style('display') === 'none') { reject(new Error('Resize must be passed a plot div element.')); } - if (gd._redrawTimer) clearTimeout(gd._redrawTimer); + if(gd._redrawTimer) clearTimeout(gd._redrawTimer); gd._redrawTimer = setTimeout(function() { - if ((gd._fullLayout || {}).autosize) { + if((gd._fullLayout || {}).autosize) { // autosizing doesn't count as a change that needs saving var oldchanged = gd.changed; @@ -348,7 +348,7 @@ plots.addLinks = function(gd) { // IE doesn't like getComputedTextLength if an element // isn't visible, which it (sometimes?) isn't // apparently offsetParent is null for invisibles. - if (text && text.getComputedTextLength() >= (fullLayout.width - 20)) { + if(text && text.getComputedTextLength() >= (fullLayout.width - 20)) { // Align the text at the left attrs['text-anchor'] = 'start'; attrs.x = 5; @@ -458,7 +458,7 @@ plots.supplyDefaults = function(gd) { newFullLayout._dataLength = newData.length; // then do the data - for (i = 0; i < newData.length; i++) { + for(i = 0; i < newData.length; i++) { trace = newData[i]; fullTrace = plots.supplyDataDefaults(trace, i, newFullLayout); @@ -473,17 +473,17 @@ plots.supplyDefaults = function(gd) { else if('r' in fullTrace) newFullLayout._hasPolar = true; _module = fullTrace._module; - if (_module && modules.indexOf(_module)===-1) modules.push(_module); + if(_module && modules.indexOf(_module)===-1) modules.push(_module); } // special cases that introduce interactions between traces - for (i = 0; i < modules.length; i++) { + for(i = 0; i < modules.length; i++) { _module = modules[i]; - if (_module.cleanData) _module.cleanData(newFullData); + if(_module.cleanData) _module.cleanData(newFullData); } - if (oldFullData.length === newData.length) { - for (i = 0; i < newFullData.length; i++) { + if(oldFullData.length === newData.length) { + for(i = 0; i < newFullData.length; i++) { relinkPrivateKeys(newFullData[i], oldFullData[i]); } } @@ -505,15 +505,15 @@ plots.supplyDefaults = function(gd) { // can't quite figure out how to get rid of this... each axis needs // a reference back to the DOM object for just a few purposes axList = Plotly.Axes.list(gd); - for (i = 0; i < axList.length; i++) { + for(i = 0; i < axList.length; i++) { ax = axList[i]; ax._td = gd; ax.setScale(); } // update object references in calcdata - if ((gd.calcdata || []).length === newFullData.length) { - for (i = 0; i < newFullData.length; i++) { + if((gd.calcdata || []).length === newFullData.length) { + for(i = 0; i < newFullData.length; i++) { trace = newFullData[i]; (gd.calcdata[i][0] || {}).trace = trace; } @@ -573,7 +573,7 @@ function relinkPrivateKeys(toLayout, fromLayout) { var keys = Object.keys(fromLayout); var j; - for (var i = 0; i < keys.length; ++i) { + for(var i = 0; i < keys.length; ++i) { var k = keys[i]; if(k.charAt(0)==='_' || typeof fromLayout[k]==='function') { // if it already exists at this point, it's something @@ -582,7 +582,7 @@ function relinkPrivateKeys(toLayout, fromLayout) { toLayout[k] = fromLayout[k]; } - else if (Array.isArray(fromLayout[k]) && + else if(Array.isArray(fromLayout[k]) && Array.isArray(toLayout[k]) && fromLayout[k].length && Lib.isPlainObject(fromLayout[k][0])) { @@ -597,11 +597,11 @@ function relinkPrivateKeys(toLayout, fromLayout) { relinkPrivateKeys(toLayout[k][j], fromLayout[k][j]); } } - else if (Lib.isPlainObject(fromLayout[k]) && + else if(Lib.isPlainObject(fromLayout[k]) && Lib.isPlainObject(toLayout[k])) { // recurse into objects, but only if they still exist relinkPrivateKeys(toLayout[k], fromLayout[k]); - if (!Object.keys(toLayout[k]).length) delete toLayout[k]; + if(!Object.keys(toLayout[k]).length) delete toLayout[k]; } } } @@ -831,13 +831,13 @@ plots.sanitizeMargins = function(fullLayout) { // as width >= 10 by supplyDefaults // similarly for margin.t + margin.b - if (plotWidth < 0) { + if(plotWidth < 0) { correction = (width - 1) / (margin.l + margin.r); margin.l = Math.floor(correction * margin.l); margin.r = Math.floor(correction * margin.r); } - if (plotHeight < 0) { + if(plotHeight < 0) { correction = (height - 1) / (margin.t + margin.b); margin.t = Math.floor(correction * margin.t); margin.b = Math.floor(correction * margin.b); @@ -977,7 +977,7 @@ plots.doAutoMargin = function(gd) { */ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) { // if the defaults aren't supplied yet, we need to do that... - if ((useDefaults && dataonly && !gd._fullData) || + if((useDefaults && dataonly && !gd._fullData) || (useDefaults && !dataonly && !gd._fullLayout)) { plots.supplyDefaults(gd); }