diff --git a/.eslintrc b/.eslintrc index 330bf09f50f..e3b18209809 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,7 @@ { "root": true, "extends": [ - "eslint:recommended", + "eslint:recommended" ], "env": { "commonjs": true @@ -16,7 +16,7 @@ "brace-style": [0, "stroustrup", {"allowSingleLine": true}], "curly": [0, "multi"], "camelcase": [0, {"properties": "never"}], - "comma-spacing": [0, {"before": false, "after": true}], + "comma-spacing": [2, {"before": false, "after": true}], "comma-style": [2, "last"], "semi": [2], "semi-spacing": [2, {"before": false, "after": true}], @@ -36,7 +36,7 @@ "no-whitespace-before-property": [2], "no-unexpected-multiline": [2], "no-floating-decimal": [2], - "space-infix-ops": [0, {"int32Hint": false}], + "space-infix-ops": [2, {"int32Hint": true}], "quotes": [2, "single"], "dot-notation": [2], "operator-linebreak": [2, "after"], @@ -50,5 +50,5 @@ "no-loop-func": [2], "no-console": [0], "no-unused-labels": [2] - }, + } } diff --git a/src/components/annotations/index.js b/src/components/annotations/index.js index ce3d21ae138..60385078844 100644 --- a/src/components/annotations/index.js +++ b/src/components/annotations/index.js @@ -68,7 +68,7 @@ function handleAnnotationDefaults(annIn, fullLayout) { Lib.coerceFont(coerce, 'font', fullLayout.font); // positioning - var axLetters = ['x','y']; + var axLetters = ['x', 'y']; for(var i = 0; i < 2; i++) { var axLetter = axLetters[i], tdMock = {_fullLayout: fullLayout}; @@ -78,21 +78,21 @@ function handleAnnotationDefaults(annIn, fullLayout) { // x, y var defaultPosition = 0.5; - if(axRef!=='paper') { + if(axRef !== 'paper') { var ax = Axes.getFromId(tdMock, axRef); defaultPosition = ax.range[0] + defaultPosition * (ax.range[1] - ax.range[0]); // convert date or category strings to numbers - if(['date','category'].indexOf(ax.type)!==-1 && - typeof annIn[axLetter]==='string') { + if(['date', 'category'].indexOf(ax.type) !== -1 && + typeof annIn[axLetter] === 'string') { var newval; - if(ax.type==='date') { + if(ax.type === 'date') { newval = Lib.dateTime2ms(annIn[axLetter]); - if(newval!==false) annIn[axLetter] = newval; + if(newval !== false) annIn[axLetter] = newval; } - else if((ax._categories||[]).length) { + else if((ax._categories || []).length) { newval = ax._categories.indexOf(annIn[axLetter]); - if(newval!==-1) annIn[axLetter] = newval; + if(newval !== -1) annIn[axLetter] = newval; } } } @@ -119,7 +119,7 @@ annotations.drawAll = function(gd) { annotations.add = function(gd) { var nextAnn = gd._fullLayout.annotations.length; - Plotly.relayout(gd, 'annotations['+nextAnn+']', 'add'); + Plotly.relayout(gd, 'annotations[' + nextAnn + ']', 'add'); }; // ----------------------------------------------------- @@ -139,7 +139,7 @@ annotations.draw = function(gd, index, opt, value) { fullLayout = gd._fullLayout, i; - if(!isNumeric(index) || index===-1) { + if(!isNumeric(index) || index === -1) { // no index provided - we're operating on ALL annotations if(!index && Array.isArray(value)) { // a whole annotation array is passed in @@ -149,14 +149,14 @@ annotations.draw = function(gd, index, opt, value) { annotations.drawAll(gd); return; } - else if(value==='remove') { + else if(value === 'remove') { // delete all delete layout.annotations; fullLayout.annotations = []; annotations.drawAll(gd); return; } - else if(opt && value!=='add') { + else if(opt && value !== 'add') { // make the same change to all annotations for(i = 0; i < fullLayout.annotations.length; i++) { annotations.draw(gd, i, opt, value); @@ -171,24 +171,24 @@ annotations.draw = function(gd, index, opt, value) { } if(!opt && value) { - if(value==='remove') { - fullLayout._infolayer.selectAll('.annotation[data-index="'+index+'"]') + if(value === 'remove') { + fullLayout._infolayer.selectAll('.annotation[data-index="' + index + '"]') .remove(); - fullLayout.annotations.splice(index,1); - layout.annotations.splice(index,1); - for(i=index; iindex; i--) { + for(i = fullLayout.annotations.length - 1; i > index; i--) { fullLayout._infolayer - .selectAll('.annotation[data-index="'+(i-1)+'"]') - .attr('data-index',String(i)); - annotations.draw(gd,i); + .selectAll('.annotation[data-index="' + (i - 1) + '"]') + .attr('data-index', String(i)); + annotations.draw(gd, i); } } } // remove the existing annotation if there is one - fullLayout._infolayer.selectAll('.annotation[data-index="'+index+'"]').remove(); + fullLayout._infolayer.selectAll('.annotation[data-index="' + index + '"]').remove(); // remember a few things about what was already there, var optionsIn = layout.annotations[index], @@ -243,8 +243,8 @@ annotations.draw = function(gd, index, opt, value) { // or axis type. // the defaults will be consistent most of the time anyway, // except in log/linear changes - if(optionsEdit[axLetter]!==undefined || - optionsIn[axLetter]===undefined) { + if(optionsEdit[axLetter] !== undefined || + optionsIn[axLetter] === undefined) { continue; } @@ -253,7 +253,7 @@ annotations.draw = function(gd, index, opt, value) { position = optionsIn[axLetter], axTypeOld = oldPrivate['_' + axLetter + 'type']; - if(optionsEdit[axLetter + 'ref']!==undefined) { + if(optionsEdit[axLetter + 'ref'] !== undefined) { var autoAnchor = optionsIn[axLetter + 'anchor'] === 'auto', plotSize = (axLetter === 'x' ? gs.w : gs.h), halfSizeFrac = (oldPrivate['_' + axLetter + 'size'] || 0) / @@ -285,15 +285,15 @@ annotations.draw = function(gd, index, opt, value) { if(autoAnchor) { var posPlus = position + halfSizeFrac, posMinus = position - halfSizeFrac; - if(position + posMinus < 2/3) position = posMinus; - else if(position + posPlus > 4/3) position = posPlus; + if(position + posMinus < 2 / 3) position = posMinus; + else if(position + posPlus > 4 / 3) position = posPlus; } } else if(axNew) { // paper -> data // first see if we need to adjust auto alignment if(autoAnchor) { - if(position < 1/3) position += halfSizeFrac; - else if(position > 2/3) position -= halfSizeFrac; + if(position < 1 / 3) position += halfSizeFrac; + else if(position > 2 / 3) position -= halfSizeFrac; } // next convert to fraction of the axis @@ -306,13 +306,13 @@ annotations.draw = function(gd, index, opt, value) { } } - if(axNew && axNew===axOld && axTypeOld) { - if(axTypeOld==='log' && axNew.type!=='log') { - position = Math.pow(10,position); + if(axNew && axNew === axOld && axTypeOld) { + if(axTypeOld === 'log' && axNew.type !== 'log') { + position = Math.pow(10, position); } - else if(axTypeOld!=='log' && axNew.type==='log') { - position = (position>0) ? - Math.log(position)/Math.LN10 : undefined; + else if(axTypeOld !== 'log' && axNew.type === 'log') { + position = (position > 0) ? + Math.log(position) / Math.LN10 : undefined; } } @@ -356,8 +356,8 @@ annotations.draw = function(gd, index, opt, value) { borderfull = borderwidth + borderpad; var annbg = ann.append('rect') - .attr('class','bg') - .style('stroke-width', borderwidth+'px') + .attr('class', 'bg') + .style('stroke-width', borderwidth + 'px') .call(Color.stroke, options.bordercolor) .call(Color.fill, options.bgcolor); @@ -402,9 +402,9 @@ annotations.draw = function(gd, index, opt, value) { options._h = annheight; function shiftFraction(v, anchor) { - if(anchor==='auto') { - if(v < 1/3) anchor = 'left'; - else if(v > 2/3) anchor = 'right'; + if(anchor === 'auto') { + if(v < 1 / 3) anchor = 'left'; + else if(v > 2 / 3) anchor = 'right'; else anchor = 'center'; } return { @@ -420,8 +420,8 @@ annotations.draw = function(gd, index, opt, value) { var annotationIsOffscreen = false; ['x', 'y'].forEach(function(axLetter) { var ax = Axes.getFromId(gd, - options[axLetter+'ref']||axLetter), - dimAngle = (textangle + (axLetter==='x' ? 0 : 90)) * Math.PI/180, + options[axLetter + 'ref'] || axLetter), + dimAngle = (textangle + (axLetter === 'x' ? 0 : 90)) * Math.PI / 180, annSize = outerwidth * Math.abs(Math.cos(dimAngle)) + outerheight * Math.abs(Math.sin(dimAngle)), anchor = options[axLetter + 'anchor'], @@ -438,7 +438,7 @@ annotations.draw = function(gd, index, opt, value) { annotationIsOffscreen = true; return; } - annPosPx[axLetter] = ax._offset+ax.l2p(options[axLetter]); + annPosPx[axLetter] = ax._offset + ax.l2p(options[axLetter]); alignPosition = 0.5; } else { @@ -494,13 +494,13 @@ annotations.draw = function(gd, index, opt, value) { } annbg.call(Drawing.setRect, borderwidth / 2, borderwidth / 2, - outerwidth-borderwidth, outerheight - borderwidth); + outerwidth - borderwidth, outerheight - borderwidth); var annX = Math.round(annPosPx.x - outerwidth / 2), annY = Math.round(annPosPx.y - outerheight / 2); ann.call(Lib.setTranslate, annX, annY); - var annbase = 'annotations['+index+']'; + var annbase = 'annotations[' + index + ']'; // add the arrow // uses options[arrowwidth,arrowcolor,arrowhead] for styling @@ -525,8 +525,8 @@ annotations.draw = function(gd, index, opt, value) { applyTransform2 = Lib.apply2DTransform2(transform), // calculate and transform bounding box - xHalf = annbg.attr('width')/2, - yHalf = annbg.attr('height')/2, + xHalf = annbg.attr('width') / 2, + yHalf = annbg.attr('height') / 2, edges = [ [arrowX0 - xHalf, arrowY0 - yHalf, arrowX0 - xHalf, arrowY0 + yHalf], [arrowX0 - xHalf, arrowY0 + yHalf, arrowX0 + xHalf, arrowY0 + yHalf], @@ -565,8 +565,8 @@ annotations.draw = function(gd, index, opt, value) { .attr('data-index', String(index)); var arrow = arrowgroup.append('path') - .attr('d', 'M'+arrowX0+','+arrowY0+'L'+arrowX+','+arrowY) - .style('stroke-width', strokewidth+'px') + .attr('d', 'M' + arrowX0 + ',' + arrowY0 + 'L' + arrowX + ',' + arrowY) + .style('stroke-width', strokewidth + 'px') .call(Color.stroke, Color.rgb(arrowColor)); annotations.arrowhead(arrow, options.arrowhead, 'end', options.arrowsize); @@ -576,10 +576,10 @@ annotations.draw = function(gd, index, opt, value) { .classed('anndrag', true) .attr({ 'data-index': String(index), - d: 'M3,3H-3V-3H3ZM0,0L' + (arrowX0-arrowX) + ',' + (arrowY0-arrowY), - transform: 'translate('+arrowX+','+arrowY+')' + d: 'M3,3H-3V-3H3ZM0,0L' + (arrowX0 - arrowX) + ',' + (arrowY0 - arrowY), + transform: 'translate(' + arrowX + ',' + arrowY + ')' }) - .style('stroke-width', (strokewidth+6)+'px') + .style('stroke-width', (strokewidth + 6) + 'px') .call(Color.stroke, 'rgba(0,0,0,0)') .call(Color.fill, 'rgba(0,0,0,0)'); @@ -597,24 +597,24 @@ annotations.draw = function(gd, index, opt, value) { anny0 = pos.y; update = {}; if(xa && xa.autorange) { - update[xa._name+'.autorange'] = true; + update[xa._name + '.autorange'] = true; } if(ya && ya.autorange) { - update[ya._name+'.autorange'] = true; + update[ya._name + '.autorange'] = true; } }, moveFn: function(dx, dy) { - arrowgroup.attr('transform', 'translate('+dx+','+dy+')'); + arrowgroup.attr('transform', 'translate(' + dx + ',' + dy + ')'); var annxy0 = applyTransform(annx0, anny0), xcenter = annxy0[0] + dx, ycenter = annxy0[1] + dy; ann.call(Lib.setTranslate, xcenter, ycenter); - update[annbase+'.x'] = xa ? + update[annbase + '.x'] = xa ? (options.x + dx / xa._m) : ((arrowX + dx - gs.l) / gs.w); - update[annbase+'.y'] = ya ? + update[annbase + '.y'] = ya ? (options.y + dy / ya._m) : (1 - ((arrowY + dy - gs.t) / gs.h)); @@ -660,8 +660,8 @@ annotations.draw = function(gd, index, opt, value) { ann.call(Lib.setTranslate, x0 + dx, y0 + dy); var csr = 'pointer'; if(options.showarrow) { - update[annbase+'.ax'] = options.ax + dx; - update[annbase+'.ay'] = options.ay + dy; + update[annbase + '.ax'] = options.ax + dx; + update[annbase + '.ay'] = options.ay + dy; drawArrow(dx, dy); } else { @@ -724,14 +724,14 @@ annotations.draw = function(gd, index, opt, value) { this.attr({'data-unformatted': options.text}); this.call(textLayout); var update = {}; - update['annotations['+index+'].text'] = options.text; + update['annotations[' + index + '].text'] = options.text; if(xa && xa.autorange) { - update[xa._name+'.autorange'] = true; + update[xa._name + '.autorange'] = true; } if(ya && ya.autorange) { - update[ya._name+'.autorange'] = true; + update[ya._name + '.autorange'] = true; } - Plotly.relayout(gd,update); + Plotly.relayout(gd, update); }); } else anntext.call(textLayout); @@ -754,7 +754,7 @@ annotations.arrowhead = function(el3, style, ends, mag) { if(typeof ends !== 'string' || !ends) ends = 'end'; - var scale = (Drawing.getPx(el3,'stroke-width') || 1) * mag, + var scale = (Drawing.getPx(el3, 'stroke-width') || 1) * mag, stroke = el3.style('stroke') || Color.defaultLine, opacity = el3.style('stroke-opacity') || 1, doStart = ends.indexOf('start') >= 0, @@ -819,7 +819,7 @@ annotations.arrowhead = function(el3, style, ends, mag) { } var drawhead = function(p, rot) { - if(style>5) rot=0; // don't rotate square or circle + if(style > 5) rot = 0; // don't rotate square or circle d3.select(el.parentElement).append('path') .attr({ 'class': el3.attr('class'), @@ -875,9 +875,9 @@ function annAutorange(gd) { ya = Axes.getFromId(gd, ann.yref); if(!(xa || ya)) return; - var halfWidth = (ann._xsize || 0)/2, + var halfWidth = (ann._xsize || 0) / 2, xShift = ann._xshift || 0, - halfHeight = (ann._ysize || 0)/2, + halfHeight = (ann._ysize || 0) / 2, yShift = ann._yshift || 0, leftSize = halfWidth - xShift, rightSize = halfWidth + xShift, @@ -891,7 +891,7 @@ function annAutorange(gd) { bottomSize = Math.max(bottomSize, headSize); } if(xa && xa.autorange) { - Axes.expand(xa, [xa.l2c(ann.x)],{ + Axes.expand(xa, [xa.l2c(ann.x)], { ppadplus: rightSize, ppadminus: leftSize }); @@ -921,7 +921,7 @@ function lineIntersect(x1, y1, x2, y2, x3, y3, x4, y4) { var t = (b * f - c * e) / det, u = (b * d - a * e) / det; // segments do not intersect? - if(u<0 || u>1 || t<0 || t>1) return null; + if(u < 0 || u > 1 || t < 0 || t > 1) return null; return {x: x1 + a * t, y: y1 + d * t}; } diff --git a/src/components/color/index.js b/src/components/color/index.js index 655c514652a..fe22aca72aa 100644 --- a/src/components/color/index.js +++ b/src/components/color/index.js @@ -41,18 +41,18 @@ color.addOpacity = function(cstr, op) { // color.background is assumed behind it color.combine = function(front, back) { var fc = tinycolor(front).toRgb(); - if(fc.a===1) return tinycolor(front).toRgbString(); + if(fc.a === 1) return tinycolor(front).toRgbString(); - 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 + 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 }, 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(); }; @@ -110,7 +110,7 @@ function cleanOne(val) { if(isNumeric(val) || typeof val !== 'string') return val; var valTrim = val.trim(); - if(valTrim.substr(0,3) !== 'rgb') return val; + if(valTrim.substr(0, 3) !== 'rgb') return val; var match = valTrim.match(/^rgba?\s*\(([^()]*)\)$/); if(!match) return val; diff --git a/src/components/colorbar/draw.js b/src/components/colorbar/draw.js index 28c83ae1e78..3d287532a51 100644 --- a/src/components/colorbar/draw.js +++ b/src/components/colorbar/draw.js @@ -58,7 +58,7 @@ module.exports = function draw(gd, id) { gs = fullLayout._size; if((typeof opts.fillcolor !== 'function') && (typeof opts.line.color !== 'function')) { - fullLayout._infolayer.selectAll('g.'+id).remove(); + fullLayout._infolayer.selectAll('g.' + id).remove(); return; } var zrange = d3.extent(((typeof opts.fillcolor === 'function') ? @@ -71,7 +71,7 @@ module.exports = function draw(gd, id) { fillcolormap = typeof opts.fillcolor === 'function' ? opts.fillcolor : function() { return opts.fillcolor; }; - var l0 = opts.levels.end + opts.levels.size/100, + var l0 = opts.levels.end + opts.levels.size / 100, ls = opts.levels.size, zr0 = (1.001 * zrange[0] - 0.001 * zrange[1]), zr1 = (1.001 * zrange[1] - 0.001 * zrange[0]); @@ -89,19 +89,19 @@ module.exports = function draw(gd, id) { } else { filllevels = linelevels.map(function(v) { - return v-opts.levels.size / 2; + return v - opts.levels.size / 2; }); filllevels.push(filllevels[filllevels.length - 1] + opts.levels.size); } } - else if(opts.fillcolor && typeof opts.fillcolor==='string') { + else if(opts.fillcolor && typeof opts.fillcolor === 'string') { // doesn't matter what this value is, with a single value // we'll make a single fill rect covering the whole bar filllevels = [0]; } - if(opts.levels.size<0) { + if(opts.levels.size < 0) { linelevels.reverse(); filllevels.reverse(); } @@ -118,18 +118,18 @@ module.exports = function draw(gd, id) { var originalPlotHeight = fullLayout.height - fullLayout.margin.t - fullLayout.margin.b, originalPlotWidth = fullLayout.width - fullLayout.margin.l - fullLayout.margin.r, thickPx = Math.round(opts.thickness * - (opts.thicknessmode==='fraction' ? originalPlotWidth : 1)), + (opts.thicknessmode === 'fraction' ? originalPlotWidth : 1)), thickFrac = thickPx / gs.w, lenPx = Math.round(opts.len * - (opts.lenmode==='fraction' ? originalPlotHeight : 1)), + (opts.lenmode === 'fraction' ? originalPlotHeight : 1)), lenFrac = lenPx / gs.h, - xpadFrac = opts.xpad/gs.w, - yExtraPx = (opts.borderwidth + opts.outlinewidth)/2, + xpadFrac = opts.xpad / gs.w, + yExtraPx = (opts.borderwidth + opts.outlinewidth) / 2, ypadFrac = opts.ypad / gs.h, // x positioning: do it initially just for left anchor, // then fix at the end (since we don't know the width yet) - xLeft = Math.round(opts.x*gs.w + opts.xpad), + xLeft = Math.round(opts.x * gs.w + opts.xpad), // for dragging... this is getting a little muddled... xLeftFrac = opts.x - thickFrac * ({middle: 0.5, right: 1}[opts.xanchor]||0), @@ -137,8 +137,8 @@ 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), - yBottomPx = Math.round(gs.h * (1-yBottomFrac)), - yTopPx = yBottomPx-lenPx, + yBottomPx = Math.round(gs.h * (1 - yBottomFrac)), + yTopPx = yBottomPx - lenPx, titleEl, cbAxisIn = { type: 'linear', @@ -195,11 +195,11 @@ module.exports = function draw(gd, id) { // save for other callers to access this axis component.axis = cbAxisOut; - if(['top','bottom'].indexOf(opts.titleside)!==-1) { + if(['top', 'bottom'].indexOf(opts.titleside) !== -1) { cbAxisOut.titleside = opts.titleside; cbAxisOut.titlex = opts.x + xpadFrac; cbAxisOut.titley = yBottomFrac + - (opts.titleside==='top' ? lenFrac-ypadFrac : ypadFrac); + (opts.titleside === 'top' ? lenFrac - ypadFrac : ypadFrac); } if(opts.line.color && opts.tickmode === 'auto') { @@ -208,18 +208,18 @@ module.exports = function draw(gd, id) { var dtick = opts.levels.size; // expand if too many contours, so we don't get too many ticks var autoNtick = Lib.constrain( - (yBottomPx-yTopPx)/50, 4, 15) + 1, - dtFactor = (zrange[1]-zrange[0]) / - ((opts.nticks||autoNtick)*dtick); - if(dtFactor>1) { - var dtexp = Math.pow(10,Math.floor( - Math.log(dtFactor)/Math.LN10)); - dtick *= dtexp * Lib.roundUp(dtFactor/dtexp,[2,5,10]); + (yBottomPx - yTopPx) / 50, 4, 15) + 1, + dtFactor = (zrange[1] - zrange[0]) / + ((opts.nticks || autoNtick) * dtick); + if(dtFactor > 1) { + var dtexp = Math.pow(10, Math.floor( + Math.log(dtFactor) / Math.LN10)); + dtick *= dtexp * Lib.roundUp(dtFactor / dtexp, [2, 5, 10]); // if the contours are at round multiples, reset tick0 // so they're still at round multiples. Otherwise, // keep the first label on the first contour level - if((Math.abs(opts.levels.start)/ - opts.levels.size+1e-6)%1 < 2e-6) { + if((Math.abs(opts.levels.start) / + opts.levels.size + 1e-6) % 1 < 2e-6) { cbAxisOut.tick0 = 0; } } @@ -229,31 +229,31 @@ module.exports = function draw(gd, id) { // set domain after init, because we may want to // allow it outside [0,1] cbAxisOut.domain = [ - yBottomFrac+ypadFrac, - yBottomFrac+lenFrac-ypadFrac + yBottomFrac + ypadFrac, + yBottomFrac + lenFrac - ypadFrac ]; cbAxisOut.setScale(); // now draw the elements - var container = fullLayout._infolayer.selectAll('g.'+id).data([0]); - container.enter().append('g').classed(id,true) + var container = fullLayout._infolayer.selectAll('g.' + id).data([0]); + container.enter().append('g').classed(id, true) .each(function() { var s = d3.select(this); - s.append('rect').classed('cbbg',true); - s.append('g').classed('cbfills',true); - s.append('g').classed('cblines',true); - s.append('g').classed('cbaxis',true).classed('crisp',true); - s.append('g').classed('cbtitleunshift',true) - .append('g').classed('cbtitle',true); - s.append('rect').classed('cboutline',true); + s.append('rect').classed('cbbg', true); + s.append('g').classed('cbfills', true); + s.append('g').classed('cblines', true); + s.append('g').classed('cbaxis', true).classed('crisp', true); + s.append('g').classed('cbtitleunshift', true) + .append('g').classed('cbtitle', true); + s.append('rect').classed('cboutline', true); s.select('.cbtitle').datum(0); }); - container.attr('transform','translate('+Math.round(gs.l)+ - ','+Math.round(gs.t)+')'); + container.attr('transform', 'translate(' + Math.round(gs.l) + + ',' + Math.round(gs.t) + ')'); // TODO: this opposite transform is a hack until we make it // more rational which items get this offset var titleCont = container.select('.cbtitleunshift') - .attr('transform', 'translate(-'+ + .attr('transform', 'translate(-' + Math.round(gs.l) + ',-' + Math.round(gs.t) + ')'); @@ -281,14 +281,14 @@ module.exports = function draw(gd, id) { } function drawAxis() { - if(['top','bottom'].indexOf(opts.titleside)!==-1) { + if(['top', 'bottom'].indexOf(opts.titleside) !== -1) { // squish the axis top to make room for the title var titleGroup = container.select('.cbtitle'), titleText = titleGroup.select('text'), titleTrans = - [-opts.outlinewidth/2, opts.outlinewidth/2], + [-opts.outlinewidth / 2, opts.outlinewidth / 2], mathJaxNode = titleGroup - .select('.h'+cbAxisOut._id+'title-math-group') + .select('.h' + cbAxisOut._id + 'title-math-group') .node(), lineSize = 15.6; if(titleText.node()) { @@ -297,10 +297,10 @@ module.exports = function draw(gd, id) { } if(mathJaxNode) { titleHeight = Drawing.bBox(mathJaxNode).height; - if(titleHeight>lineSize) { + if(titleHeight > lineSize) { // not entirely sure how mathjax is doing // vertical alignment, but this seems to work. - titleTrans[1] -= (titleHeight-lineSize)/2; + titleTrans[1] -= (titleHeight - lineSize) / 2; } } else if(titleText.node() && @@ -313,49 +313,49 @@ module.exports = function draw(gd, id) { // TODO: configurable titleHeight += 5; - if(opts.titleside==='top') { - cbAxisOut.domain[1] -= titleHeight/gs.h; + if(opts.titleside === 'top') { + cbAxisOut.domain[1] -= titleHeight / gs.h; titleTrans[1] *= -1; } else { - cbAxisOut.domain[0] += titleHeight/gs.h; + cbAxisOut.domain[0] += titleHeight / gs.h; var nlines = Math.max(1, titleText.selectAll('tspan.line').size()); - titleTrans[1] += (1-nlines)*lineSize; + titleTrans[1] += (1 - nlines) * lineSize; } titleGroup.attr('transform', - 'translate('+titleTrans+')'); + 'translate(' + titleTrans + ')'); cbAxisOut.setScale(); } } container.selectAll('.cbfills,.cblines,.cbaxis') - .attr('transform','translate(0,'+ - Math.round(gs.h*(1-cbAxisOut.domain[1]))+')'); + .attr('transform', 'translate(0,' + + Math.round(gs.h * (1 - cbAxisOut.domain[1])) + ')'); var fills = container.select('.cbfills') .selectAll('rect.cbfill') .data(filllevels); fills.enter().append('rect') - .classed('cbfill',true) - .style('stroke','none'); + .classed('cbfill', true) + .style('stroke', 'none'); fills.exit().remove(); - fills.each(function(d,i) { + fills.each(function(d, i) { var z = [ - (i===0) ? zrange[0] : - (filllevels[i]+filllevels[i-1])/2, - (i===filllevels.length-1) ? zrange[1] : - (filllevels[i]+filllevels[i+1])/2 + (i === 0) ? zrange[0] : + (filllevels[i] + filllevels[i - 1]) / 2, + (i === filllevels.length - 1) ? zrange[1] : + (filllevels[i] + filllevels[i + 1]) / 2 ] .map(cbAxisOut.c2p) .map(Math.round); // offset the side adjoining the next rectangle so they // overlap, to prevent antialiasing gaps - if(i!==filllevels.length-1) { - z[1] += (z[1]>z[0]) ? 1 : -1; + if(i !== filllevels.length - 1) { + z[1] += (z[1] > z[0]) ? 1 : -1; } @@ -368,9 +368,9 @@ module.exports = function draw(gd, id) { // use an opaque fill even when alpha channels present d3.select(this).attr({ x: xLeft, - width: Math.max(thickPx,2), + width: Math.max(thickPx, 2), y: d3.min(z), - height: Math.max(d3.max(z)-d3.min(z),2), + height: Math.max(d3.max(z) - d3.min(z), 2), fill: opaqueColor }); }); @@ -380,23 +380,23 @@ module.exports = function draw(gd, id) { .data(opts.line.color && opts.line.width ? linelevels : []); lines.enter().append('path') - .classed('cbline',true); + .classed('cbline', true); lines.exit().remove(); lines.each(function(d) { d3.select(this) - .attr('d','M'+xLeft+',' + - (Math.round(cbAxisOut.c2p(d))+(opts.line.width/2)%1) + - 'h'+thickPx) + .attr('d', 'M' + xLeft + ',' + + (Math.round(cbAxisOut.c2p(d)) + (opts.line.width / 2) % 1) + + 'h' + thickPx) .call(Drawing.lineGroupStyle, opts.line.width, linecolormap(d), opts.line.dash); }); // force full redraw of labels and ticks - cbAxisOut._axislayer.selectAll('g.'+cbAxisOut._id+'tick,path') + cbAxisOut._axislayer.selectAll('g.' + cbAxisOut._id + 'tick,path') .remove(); - cbAxisOut._pos = xLeft+thickPx + - (opts.outlinewidth||0)/2 - (opts.ticks==='outside' ? 1 : 0); + cbAxisOut._pos = xLeft + thickPx + + (opts.outlinewidth||0) / 2 - (opts.ticks === 'outside' ? 1 : 0); cbAxisOut.side = 'right'; // separate out axis and title drawing, @@ -408,12 +408,12 @@ module.exports = function draw(gd, id) { return Axes.doTicks(gd, cbAxisOut, true); }, function() { - if(['top','bottom'].indexOf(opts.titleside)===-1) { + if(['top', 'bottom'].indexOf(opts.titleside) === -1) { var fontSize = cbAxisOut.titlefont.size, y = cbAxisOut._offset + cbAxisOut._length / 2, x = gs.l + (cbAxisOut.position || 0) * gs.w + ((cbAxisOut.side === 'right') ? - 10 + fontSize*((cbAxisOut.showticklabels ? 1 : 0.5)) : - -10 - fontSize*((cbAxisOut.showticklabels ? 0.5 : 0))); + 10 + fontSize * ((cbAxisOut.showticklabels ? 1 : 0.5)) : + -10 - fontSize * ((cbAxisOut.showticklabels ? 0.5 : 0))); // the 'h' + is a hack to get around the fact that // convertToTspans rotates any 'y...' class by 90 degrees. @@ -467,16 +467,16 @@ module.exports = function draw(gd, id) { // continuing positioning // TODO: why are we redrawing multiple times now with this? // I guess autoMargin doesn't like being post-promise? - var innerWidth = thickPx + opts.outlinewidth/2 + + var innerWidth = thickPx + opts.outlinewidth / 2 + Drawing.bBox(cbAxisOut._axislayer.node()).width; titleEl = titleCont.select('text'); if(titleEl.node() && !titleEl.classed('js-placeholder')) { var mathJaxNode = titleCont - .select('.h'+cbAxisOut._id+'title-math-group') + .select('.h' + cbAxisOut._id + 'title-math-group') .node(), titleWidth; if(mathJaxNode && - ['top','bottom'].indexOf(opts.titleside)!==-1) { + ['top', 'bottom'].indexOf(opts.titleside) !== -1) { titleWidth = Drawing.bBox(mathJaxNode).width; } else { @@ -488,19 +488,19 @@ module.exports = function draw(gd, id) { Drawing.bBox(titleCont.node()).right - xLeft - gs.l; } - innerWidth = Math.max(innerWidth,titleWidth); + innerWidth = Math.max(innerWidth, titleWidth); } - var outerwidth = 2*opts.xpad + innerWidth + - opts.borderwidth + opts.outlinewidth/2, - outerheight = yBottomPx-yTopPx; + var outerwidth = 2 * opts.xpad + innerWidth + + opts.borderwidth + opts.outlinewidth / 2, + outerheight = yBottomPx - yTopPx; container.select('.cbbg').attr({ - x: xLeft-opts.xpad - - (opts.borderwidth + opts.outlinewidth)/2, + x: xLeft - opts.xpad - + (opts.borderwidth + opts.outlinewidth) / 2, y: yTopPx - yExtraPx, - width: Math.max(outerwidth,2), - height: Math.max(outerheight + 2*yExtraPx,2) + width: Math.max(outerwidth, 2), + height: Math.max(outerheight + 2 * yExtraPx, 2) }) .call(Color.fill, opts.bgcolor) .call(Color.stroke, opts.bordercolor) @@ -509,9 +509,9 @@ module.exports = function draw(gd, id) { container.selectAll('.cboutline').attr({ x: xLeft, y: yTopPx + opts.ypad + - (opts.titleside==='top' ? titleHeight : 0), - width: Math.max(thickPx,2), - height: Math.max(outerheight - 2*opts.ypad - titleHeight, 2) + (opts.titleside === 'top' ? titleHeight : 0), + width: Math.max(thickPx, 2), + height: Math.max(outerheight - 2 * opts.ypad - titleHeight, 2) }) .call(Color.stroke, opts.outlinecolor) .style({ @@ -523,10 +523,10 @@ module.exports = function draw(gd, id) { var xoffset = ({center: 0.5, right: 1}[opts.xanchor] || 0) * outerwidth; container.attr('transform', - 'translate('+(gs.l-xoffset)+','+gs.t+')'); + 'translate(' + (gs.l - xoffset) + ',' + gs.t + ')'); //auto margin adjustment - Plots.autoMargin(gd, id,{ + Plots.autoMargin(gd, id, { x: opts.x, y: opts.y, l: outerwidth * ({right: 1, center: 0.5}[opts.xanchor] || 0), @@ -559,11 +559,11 @@ module.exports = function draw(gd, id) { }, moveFn: function(dx, dy) { container.attr('transform', - t0+' ' + 'translate('+dx+','+dy+')'); + t0 + ' ' + 'translate(' + dx + ',' + dy + ')'); - xf = dragElement.align(xLeftFrac + (dx/gs.w), thickFrac, + xf = dragElement.align(xLeftFrac + (dx / gs.w), thickFrac, 0, 1, opts.xanchor); - yf = dragElement.align(yBottomFrac - (dy/gs.h), lenFrac, + yf = dragElement.align(yBottomFrac - (dy / gs.h), lenFrac, 0, 1, opts.yanchor); var csr = dragElement.getCursor(xf, yf, @@ -573,7 +573,7 @@ module.exports = function draw(gd, id) { doneFn: function(dragged) { setCursor(container); - if(dragged && xf!==undefined && yf!==undefined) { + if(dragged && xf !== undefined && yf !== undefined) { Plotly.restyle(gd, {'colorbar.x': xf, 'colorbar.y': yf}, getTrace().index); @@ -615,7 +615,7 @@ module.exports = function draw(gd, id) { Object.keys(o).forEach(function(name) { // in case something random comes through // that's not an option, ignore it - if(typeof component[name]==='function') { + if(typeof component[name] === 'function') { component[name](o[name]); } }); diff --git a/src/components/colorscale/calc.js b/src/components/colorscale/calc.js index cd2f83b4194..1900353e25d 100644 --- a/src/components/colorscale/calc.js +++ b/src/components/colorscale/calc.js @@ -31,11 +31,11 @@ module.exports = function calc(trace, vals, containerStr, cLetter) { max = container[cLetter + 'max'], scl = container.colorscale; - if(auto!==false || min===undefined) { + if(auto !== false || min === undefined) { min = Lib.aggNums(Math.min, null, vals); } - if(auto!==false || max===undefined) { + if(auto !== false || max === undefined) { max = Lib.aggNums(Math.max, null, vals); } diff --git a/src/components/colorscale/defaults.js b/src/components/colorscale/defaults.js index 7839882da67..bb4a20b238d 100644 --- a/src/components/colorscale/defaults.js +++ b/src/components/colorscale/defaults.js @@ -22,7 +22,7 @@ var flipScale = require('./flip_scale'); module.exports = function colorScaleDefaults(traceIn, traceOut, layout, coerce, opts) { var prefix = opts.prefix, cLetter = opts.cLetter, - containerStr = prefix.slice(0, prefix.length-1), + containerStr = prefix.slice(0, prefix.length - 1), containerIn = prefix ? Lib.nestedProperty(traceIn, containerStr).get() || {} : traceIn, @@ -41,7 +41,7 @@ module.exports = function colorScaleDefaults(traceIn, traceOut, layout, coerce, // handles both the trace case (autocolorscale is false by default) and // the marker and marker.line case (autocolorscale is true by default) var autoColorscaleDftl; - if(sclIn!==undefined) autoColorscaleDftl = !isValidScale(sclIn); + if(sclIn !== undefined) autoColorscaleDftl = !isValidScale(sclIn); coerce(prefix + 'autocolorscale', autoColorscaleDftl); var sclOut = coerce(prefix + 'colorscale'); diff --git a/src/components/colorscale/flip_scale.js b/src/components/colorscale/flip_scale.js index bea5facee2b..38688cda1ef 100644 --- a/src/components/colorscale/flip_scale.js +++ b/src/components/colorscale/flip_scale.js @@ -14,7 +14,7 @@ module.exports = function flipScale(scl) { sclNew = new Array(N), si; - for(var i = N-1, j = 0; i >= 0; i--, j++) { + for(var i = N - 1, j = 0; i >= 0; i--, j++) { si = scl[i]; sclNew[j] = [1 - si[0], si[1]]; } diff --git a/src/components/colorscale/has_colorscale.js b/src/components/colorscale/has_colorscale.js index 6d41b3d4116..9e28d51f5de 100644 --- a/src/components/colorscale/has_colorscale.js +++ b/src/components/colorscale/has_colorscale.js @@ -33,12 +33,12 @@ module.exports = function hasColorscale(trace, containerStr) { } return ( - (typeof container==='object' && container!==null) && ( + (typeof container === 'object' && container !== null) && ( isArrayWithOneNumber || - container.showscale===true || + container.showscale === true || (isNumeric(container.cmin) && isNumeric(container.cmax)) || isValidScale(container.colorscale) || - (typeof container.colorbar==='object' && container.colorbar!==null) + (typeof container.colorbar === 'object' && container.colorbar !== null) ) ); }; diff --git a/src/components/colorscale/is_valid_scale_array.js b/src/components/colorscale/is_valid_scale_array.js index 6bc56c09ffd..5c7bed6584e 100644 --- a/src/components/colorscale/is_valid_scale_array.js +++ b/src/components/colorscale/is_valid_scale_array.js @@ -19,10 +19,10 @@ 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; + if(+scl[0][0] !== 0 || +scl[scl.length - 1][0] !== 1) return false; for(var i = 0; i < scl.length; i++) { si = scl[i]; - if(si.length!==2 || +si[0] (4/3) - vc) return vmax; + if(vmin < (2 / 3) - vc) return vmin; + if(vmax > (4 / 3) - vc) return vmax; return vc; }; diff --git a/src/components/dragelement/cursor.js b/src/components/dragelement/cursor.js index 8bffe085592..f5f2b902c30 100644 --- a/src/components/dragelement/cursor.js +++ b/src/components/dragelement/cursor.js @@ -22,9 +22,9 @@ var cursorset = [ ]; module.exports = function getCursor(x, y, xanchor, yanchor) { - if(xanchor === 'left') x=0; - else if(xanchor === 'center') x=1; - else if(xanchor === 'right') x=2; + if(xanchor === 'left') x = 0; + else if(xanchor === 'center') x = 1; + else if(xanchor === 'right') x = 2; else x = Lib.constrain(Math.floor(x * 3), 0, 2); if(yanchor === 'bottom') y = 0; diff --git a/src/components/dragelement/index.js b/src/components/dragelement/index.js index e9d1ce56b9c..35d8c602780 100644 --- a/src/components/dragelement/index.js +++ b/src/components/dragelement/index.js @@ -96,7 +96,7 @@ dragElement.init = function init(options) { if(Math.abs(dx) < minDrag) dx = 0; if(Math.abs(dy) < minDrag) dy = 0; - if(dx||dy) { + if(dx || dy) { gd._dragged = true; dragElement.unhover(gd); } diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index 44d3076184c..d5703c27e31 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -36,12 +36,12 @@ drawing.font = function(s, family, size, color) { family = family.family; } if(family) s.style('font-family', family); - if(size+1) s.style('font-size', size + 'px'); + if(size + 1) s.style('font-size', size + 'px'); if(color) s.call(Color.fill, color); }; -drawing.setPosition = function(s, x, y) { s.attr('x',x).attr('y',y); }; -drawing.setSize = function(s, w, h) { s.attr('width',w).attr('height',h); }; +drawing.setPosition = function(s, x, y) { s.attr('x', x).attr('y', y); }; +drawing.setSize = function(s, w, h) { s.attr('width', w).attr('height', h); }; drawing.setRect = function(s, x, y, w, h) { s.call(drawing.setPosition, x, y).call(drawing.setSize, w, h); }; @@ -54,8 +54,8 @@ drawing.translatePoints = function(s, xa, ya) { p = d3.select(this); if(isNumeric(x) && isNumeric(y)) { // for multiline text this works better - if(this.nodeName==='text') p.attr('x',x).attr('y',y); - else p.attr('transform', 'translate('+x+','+y+')'); + if(this.nodeName === 'text') p.attr('x', x).attr('y', y); + else p.attr('transform', 'translate(' + x + ',' + y + ')'); } else p.remove(); }); @@ -64,7 +64,7 @@ drawing.translatePoints = function(s, xa, ya) { drawing.getPx = function(s, styleAttr) { // helper to pull out a px value from a style that may contain px units // s is a d3 selection (will pull from the first one) - return Number(s.style(styleAttr).replace(/px$/,'')); + return Number(s.style(styleAttr).replace(/px$/, '')); }; drawing.crispRound = function(td, lineWidth, dflt) { @@ -76,19 +76,19 @@ drawing.crispRound = function(td, lineWidth, dflt) { // but not for static plots - these don't get antialiased anyway. if(td._context.staticPlot) return lineWidth; - if(lineWidth<1) return 1; + if(lineWidth < 1) return 1; return Math.round(lineWidth); }; drawing.lineGroupStyle = function(s, lw, lc, ld) { - s.style('fill','none') + s.style('fill', 'none') .each(function(d) { - var line = (((d||[])[0]||{}).trace||{}).line||{}, - lw1 = lw||line.width||0, - dash = ld||line.dash||''; + var line = (((d || [])[0] || {}).trace || {}).line || {}, + lw1 = lw || line.width||0, + dash = ld || line.dash || ''; d3.select(this) - .call(Color.stroke,lc||line.color) + .call(Color.stroke, lc || line.color) .call(drawing.dashLine, dash, lw1); }); }; @@ -96,15 +96,15 @@ drawing.lineGroupStyle = function(s, lw, lc, ld) { drawing.dashLine = function(s, dash, lineWidth) { var dlw = Math.max(lineWidth, 3); - if(dash==='solid') dash = ''; - else if(dash==='dot') dash = dlw+'px,'+dlw+'px'; - else if(dash==='dash') dash = (3*dlw)+'px,'+(3*dlw)+'px'; - else if(dash==='longdash') dash = (5*dlw)+'px,'+(5*dlw)+'px'; - else if(dash==='dashdot') { - dash = (3*dlw)+'px,'+dlw+'px,'+dlw+'px,'+dlw+'px'; + if(dash === 'solid') dash = ''; + else if(dash === 'dot') dash = dlw + 'px,' + dlw + 'px'; + else if(dash === 'dash') dash = (3 * dlw) + 'px,' + (3 * dlw) + 'px'; + else if(dash === 'longdash') dash = (5 * dlw) + 'px,' + (5 * dlw) + 'px'; + else if(dash === 'dashdot') { + dash = (3 * dlw) + 'px,' + dlw + 'px,' + dlw + 'px,' + dlw + 'px'; } - else if(dash==='longdashdot') { - dash = (5*dlw)+'px,'+(2*dlw)+'px,'+dlw+'px,'+(2*dlw)+'px'; + else if(dash === 'longdashdot') { + dash = (5 * dlw) + 'px,' + (2 * dlw) + 'px,' + dlw + 'px,' + (2 * dlw) + 'px'; } // otherwise user wrote the dasharray themselves - leave it be @@ -115,14 +115,14 @@ drawing.dashLine = function(s, dash, lineWidth) { }; drawing.fillGroupStyle = function(s) { - s.style('stroke-width',0) + s.style('stroke-width', 0) .each(function(d) { var shape = d3.select(this); try { shape.call(Color.fill, d[0].trace.fillcolor); } catch(e) { - console.log(e,s); + console.log(e, s); shape.remove(); } }); @@ -139,7 +139,7 @@ drawing.symbolList = []; Object.keys(SYMBOLDEFS).forEach(function(k) { var symDef = SYMBOLDEFS[k]; drawing.symbolList = drawing.symbolList.concat( - [symDef.n, k, symDef.n+100, k+'-open']); + [symDef.n, k, symDef.n + 100, k + '-open']); drawing.symbolNames[symDef.n] = k; drawing.symbolFuncs[symDef.n] = symDef.f; if(symDef.needLine) { @@ -150,7 +150,7 @@ Object.keys(SYMBOLDEFS).forEach(function(k) { } else { drawing.symbolList = drawing.symbolList.concat( - [symDef.n+200, k+'-dot', symDef.n+300, k+'-open-dot']); + [symDef.n + 200, k + '-dot', symDef.n + 300, k + '-open-dot']); } }); var MAXSYMBOL = drawing.symbolNames.length, @@ -162,17 +162,17 @@ drawing.symbolNumber = function(v) { var vbase = 0; if(v.indexOf('-open') > 0) { vbase = 100; - v = v.replace('-open',''); + v = v.replace('-open', ''); } if(v.indexOf('-dot') > 0) { vbase += 200; - v = v.replace('-dot',''); + v = v.replace('-dot', ''); } v = drawing.symbolNames.indexOf(v); - if(v>=0) { v += vbase; } + if(v >= 0) { v += vbase; } } - if((v%100 >= MAXSYMBOL) || v>=400) { return 0; } - return Math.floor(Math.max(v,0)); + if((v % 100 >= MAXSYMBOL) || v >= 400) { return 0; } + return Math.floor(Math.max(v, 0)); }; drawing.pointStyle = function(s, trace) { @@ -190,7 +190,7 @@ drawing.pointStyle = function(s, trace) { var r; // handle multi-trace graph edit case - if(d.ms==='various' || marker.size==='various') r = 3; + if(d.ms === 'various' || marker.size === 'various') r = 3; else r = subTypes.isBubble(trace) ? sizeFn(d.ms) : (marker.size || 6) / 2; @@ -199,22 +199,22 @@ drawing.pointStyle = function(s, trace) { // turn the symbol into a sanitized number var x = drawing.symbolNumber(d.mx || marker.symbol) || 0, - xBase = x%100; + xBase = x % 100; // save if this marker is open // because that impacts how to handle colors - d.om = x%200 >= 100; + d.om = x % 200 >= 100; return drawing.symbolFuncs[xBase](r) + (x >= 200 ? DOTPATH : ''); }) - .style('opacity',function(d) { - return (d.mo+1 || marker.opacity+1) - 1; + .style('opacity', function(d) { + return (d.mo + 1 || marker.opacity + 1) - 1; }); } // allow array marker and marker line colors to be // scaled by given max and min to colorscales - var markerIn = (trace._input||{}).marker||{}, + var markerIn = (trace._input || {}).marker || {}, markerScale = drawing.tryColorscale(marker, markerIn, ''), lineScale = drawing.tryColorscale(marker, markerIn, 'line.'); @@ -229,9 +229,9 @@ drawing.pointStyle = function(s, trace) { fillColor = marker.outliercolor; } else { - lineWidth = (d.mlw+1 || markerLine.width+1 || + lineWidth = (d.mlw + 1 || markerLine.width + 1 || // TODO: we need the latter for legends... can we get rid of it? - (d.trace ? d.trace.marker.line.width : 0) + 1) -1; + (d.trace ? d.trace.marker.line.width : 0) + 1) - 1; if('mlc' in d) lineColor = d.mlcc = lineScale(d.mlc); // weird case: array wasn't long enough to apply to every point @@ -249,7 +249,7 @@ drawing.pointStyle = function(s, trace) { // and use fill color as stroke color p.call(Color.stroke, fillColor) .style({ - 'stroke-width': (lineWidth||1) + 'px', + 'stroke-width': (lineWidth || 1) + 'px', fill: 'none' }); } @@ -315,37 +315,37 @@ drawing.textPointStyle = function(s, trace) { } var pos = d.tp || trace.textposition, - v = pos.indexOf('top')!==-1 ? 'top' : - pos.indexOf('bottom')!==-1 ? 'bottom' : 'middle', - h = pos.indexOf('left')!==-1 ? 'end' : - pos.indexOf('right')!==-1 ? 'start' : 'middle', + v = pos.indexOf('top') !== -1 ? 'top' : + pos.indexOf('bottom') !== -1 ? 'bottom' : 'middle', + h = pos.indexOf('left') !== -1 ? 'end' : + pos.indexOf('right') !== -1 ? 'start' : 'middle', fontSize = d.ts || trace.textfont.size, // if markers are shown, offset a little more than // the nominal marker size // ie 2/1.6 * nominal, bcs some markers are a bit bigger - r = d.mrc ? (d.mrc/0.8 + 1) : 0; + r = d.mrc ? (d.mrc / 0.8 + 1) : 0; - fontSize = (isNumeric(fontSize) && fontSize>0) ? fontSize : 0; + fontSize = (isNumeric(fontSize) && fontSize > 0) ? fontSize : 0; p.call(drawing.font, d.tf || trace.textfont.family, fontSize, d.tc || trace.textfont.color) - .attr('text-anchor',h) + .attr('text-anchor', h) .text(text) .call(svgTextUtils.convertToTspans); var pgroup = d3.select(this.parentNode), tspans = p.selectAll('tspan.line'), - numLines = ((tspans[0].length||1)-1)*LINEEXPAND+1, - dx = TEXTOFFSETSIGN[h]*r, - dy = fontSize*0.75 + TEXTOFFSETSIGN[v]*r + - (TEXTOFFSETSIGN[v]-1)*numLines*fontSize/2; + numLines = ((tspans[0].length || 1) - 1) * LINEEXPAND + 1, + dx = TEXTOFFSETSIGN[h] * r, + dy = fontSize * 0.75 + TEXTOFFSETSIGN[v] * r + + (TEXTOFFSETSIGN[v] - 1) * numLines * fontSize / 2; // fix the overall text group position - pgroup.attr('transform','translate('+dx+','+dy+')'); + pgroup.attr('transform', 'translate(' + dx + ',' + dy + ')'); // then fix multiline text - if(numLines>1) { + if(numLines > 1) { tspans.attr({ x: p.attr('x'), y: p.attr('y') }); } }); @@ -354,60 +354,60 @@ drawing.textPointStyle = function(s, trace) { // generalized Catmull-Rom splines, per // http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf var CatmullRomExp = 0.5; -drawing.smoothopen = function(pts,smoothness) { - if(pts.length<3) { return 'M' + pts.join('L');} - var path = 'M'+pts[0], +drawing.smoothopen = function(pts, smoothness) { + if(pts.length < 3) { return 'M' + pts.join('L');} + var path = 'M' + pts[0], tangents = [], i; - for(i=1; i=maxSavedBBoxes) { + if(savedBBoxes.length >= maxSavedBBoxes) { d3.selectAll('[data-bb]').attr('data-bb', null); savedBBoxes = []; } // cache this bbox - node.setAttribute('data-bb',savedBBoxes.length); + node.setAttribute('data-bb', savedBBoxes.length); savedBBoxes.push(bb); return Lib.extendFlat({}, bb); diff --git a/src/components/drawing/symbol_defs.js b/src/components/drawing/symbol_defs.js index cb83d2c1299..47946197309 100644 --- a/src/components/drawing/symbol_defs.js +++ b/src/components/drawing/symbol_defs.js @@ -23,271 +23,271 @@ module.exports = { circle: { n: 0, f: function(r) { - var rs = d3.round(r,2); - return 'M'+rs+',0A'+rs+','+rs+' 0 1,1 0,-'+rs+ - 'A'+rs+','+rs+' 0 0,1 '+rs+',0Z'; + var rs = d3.round(r, 2); + return 'M' + rs + ',0A' + rs + ',' + rs + ' 0 1,1 0,-' + rs + + 'A' + rs + ',' + rs + ' 0 0,1 ' + rs + ',0Z'; } }, square: { n: 1, f: function(r) { - var rs = d3.round(r,2); - return 'M'+rs+','+rs+'H-'+rs+'V-'+rs+'H'+rs+'Z'; + var rs = d3.round(r, 2); + return 'M' + rs + ',' + rs + 'H-' + rs + 'V-' + rs + 'H' + rs + 'Z'; } }, diamond: { n: 2, f: function(r) { - var rd = d3.round(r*1.3,2); - return 'M'+rd+',0L0,'+rd+'L-'+rd+',0L0,-'+rd+'Z'; + var rd = d3.round(r * 1.3, 2); + return 'M' + rd + ',0L0,' + rd + 'L-' + rd + ',0L0,-' + rd + 'Z'; } }, cross: { n: 3, f: function(r) { - var rc = d3.round(r*0.4,2), - rc2 = d3.round(r*1.2,2); - return 'M'+rc2+','+rc+'H'+rc+'V'+rc2+'H-'+rc+ - 'V'+rc+'H-'+rc2+'V-'+rc+'H-'+rc+'V-'+rc2+ - 'H'+rc+'V-'+rc+'H'+rc2+'Z'; + var rc = d3.round(r * 0.4, 2), + rc2 = d3.round(r * 1.2, 2); + return 'M' + rc2 + ',' + rc + 'H' + rc + 'V' + rc2 + 'H-' + rc + + 'V' + rc + 'H-' + rc2 + 'V-' + rc + 'H-' + rc + 'V-' + rc2 + + 'H' + rc + 'V-' + rc + 'H' + rc2 + 'Z'; } }, x: { n: 4, f: function(r) { - var rx = d3.round(r*0.8/Math.sqrt(2),2), - ne = 'l'+rx+','+rx, - se = 'l'+rx+',-'+rx, - sw = 'l-'+rx+',-'+rx, - nw = 'l-'+rx+','+rx; - return 'M0,'+rx+ne+se+sw+se+sw+nw+sw+nw+ne+nw+ne+'Z'; + var rx = d3.round(r * 0.8 / Math.sqrt(2), 2), + ne = 'l' + rx + ',' + rx, + se = 'l' + rx + ',-' + rx, + sw = 'l-' + rx + ',-' + rx, + nw = 'l-' + rx + ',' + rx; + return 'M0,' + rx + ne + se + sw + se + sw + nw + sw + nw + ne + nw + ne + 'Z'; } }, 'triangle-up': { n: 5, f: function(r) { - var rt = d3.round(r*2/Math.sqrt(3),2), - r2 = d3.round(r/2,2), - rs = d3.round(r,2); - return 'M-'+rt+','+r2+'H'+rt+'L0,-'+rs+'Z'; + var rt = d3.round(r * 2 / Math.sqrt(3), 2), + r2 = d3.round(r / 2, 2), + rs = d3.round(r, 2); + return 'M-' + rt + ',' + r2 + 'H' + rt + 'L0,-' + rs + 'Z'; } }, 'triangle-down': { n: 6, f: function(r) { - var rt = d3.round(r*2/Math.sqrt(3),2), - r2 = d3.round(r/2,2), - rs = d3.round(r,2); - return 'M-'+rt+',-'+r2+'H'+rt+'L0,'+rs+'Z'; + var rt = d3.round(r * 2 / Math.sqrt(3), 2), + r2 = d3.round(r / 2, 2), + rs = d3.round(r, 2); + return 'M-' + rt + ',-' + r2 + 'H' + rt + 'L0,' + rs + 'Z'; } }, 'triangle-left': { n: 7, f: function(r) { - var rt = d3.round(r*2/Math.sqrt(3),2), - r2 = d3.round(r/2,2), - rs = d3.round(r,2); - return 'M'+r2+',-'+rt+'V'+rt+'L-'+rs+',0Z'; + var rt = d3.round(r * 2 / Math.sqrt(3), 2), + r2 = d3.round(r / 2, 2), + rs = d3.round(r, 2); + return 'M' + r2 + ',-' + rt + 'V' + rt + 'L-' + rs + ',0Z'; } }, 'triangle-right': { n: 8, f: function(r) { - var rt = d3.round(r*2/Math.sqrt(3),2), - r2 = d3.round(r/2,2), - rs = d3.round(r,2); - return 'M-'+r2+',-'+rt+'V'+rt+'L'+rs+',0Z'; + var rt = d3.round(r * 2 / Math.sqrt(3), 2), + r2 = d3.round(r / 2, 2), + rs = d3.round(r, 2); + return 'M-' + r2 + ',-' + rt + 'V' + rt + 'L' + rs + ',0Z'; } }, 'triangle-ne': { n: 9, f: function(r) { - var r1 = d3.round(r*0.6,2), - r2 = d3.round(r*1.2,2); - return 'M-'+r2+',-'+r1+'H'+r1+'V'+r2+'Z'; + var r1 = d3.round(r * 0.6, 2), + r2 = d3.round(r * 1.2, 2); + return 'M-' + r2 + ',-' + r1 + 'H' + r1 + 'V' + r2 + 'Z'; } }, 'triangle-se': { n: 10, f: function(r) { - var r1 = d3.round(r*0.6,2), - r2 = d3.round(r*1.2,2); - return 'M'+r1+',-'+r2+'V'+r1+'H-'+r2+'Z'; + var r1 = d3.round(r * 0.6, 2), + r2 = d3.round(r * 1.2, 2); + return 'M' + r1 + ',-' + r2 + 'V' + r1 + 'H-' + r2 + 'Z'; } }, 'triangle-sw': { n: 11, f: function(r) { - var r1 = d3.round(r*0.6,2), - r2 = d3.round(r*1.2,2); - return 'M'+r2+','+r1+'H-'+r1+'V-'+r2+'Z'; + var r1 = d3.round(r * 0.6, 2), + r2 = d3.round(r * 1.2, 2); + return 'M' + r2 + ',' + r1 + 'H-' + r1 + 'V-' + r2 + 'Z'; } }, 'triangle-nw': { n: 12, f: function(r) { - var r1 = d3.round(r*0.6,2), - r2 = d3.round(r*1.2,2); - return 'M-'+r1+','+r2+'V-'+r1+'H'+r2+'Z'; + var r1 = d3.round(r * 0.6, 2), + r2 = d3.round(r * 1.2, 2); + return 'M-' + r1 + ',' + r2 + 'V-' + r1 + 'H' + r2 + 'Z'; } }, pentagon: { n: 13, f: function(r) { - var x1 = d3.round(r*0.951,2), - x2 = d3.round(r*0.588,2), - y0 = d3.round(-r,2), - y1 = d3.round(r*-0.309,2), - y2 = d3.round(r*0.809,2); - return 'M'+x1+','+y1+'L'+x2+','+y2+'H-'+x2+ - 'L-'+x1+','+y1+'L0,'+y0+'Z'; + var x1 = d3.round(r * 0.951, 2), + x2 = d3.round(r * 0.588, 2), + y0 = d3.round(-r, 2), + y1 = d3.round(r * -0.309, 2), + y2 = d3.round(r * 0.809, 2); + return 'M' + x1 + ',' + y1 + 'L' + x2 + ',' + y2 + 'H-' + x2 + + 'L-' + x1 + ',' + y1 + 'L0,' + y0 + 'Z'; } }, hexagon: { n: 14, f: function(r) { - var y0 = d3.round(r,2), - y1 = d3.round(r/2,2), - x = d3.round(r*Math.sqrt(3)/2,2); - return 'M'+x+',-'+y1+'V'+y1+'L0,'+y0+ - 'L-'+x+','+y1+'V-'+y1+'L0,-'+y0+'Z'; + var y0 = d3.round(r, 2), + y1 = d3.round(r / 2, 2), + x = d3.round(r * Math.sqrt(3) / 2, 2); + return 'M' + x + ',-' + y1 + 'V' + y1 + 'L0,' + y0 + + 'L-' + x + ',' + y1 + 'V-' + y1 + 'L0,-' + y0 + 'Z'; } }, hexagon2: { n: 15, f: function(r) { - var x0 = d3.round(r,2), - x1 = d3.round(r/2,2), - y = d3.round(r*Math.sqrt(3)/2,2); - return 'M-'+x1+','+y+'H'+x1+'L'+x0+ - ',0L'+x1+',-'+y+'H-'+x1+'L-'+x0+',0Z'; + var x0 = d3.round(r, 2), + x1 = d3.round(r / 2, 2), + y = d3.round(r * Math.sqrt(3) / 2, 2); + return 'M-' + x1 + ',' + y + 'H' + x1 + 'L' + x0 + + ',0L' + x1 + ',-' + y + 'H-' + x1 + 'L-' + x0 + ',0Z'; } }, octagon: { n: 16, f: function(r) { - var a = d3.round(r*0.924,2), - b = d3.round(r*0.383,2); - return 'M-'+b+',-'+a+'H'+b+'L'+a+',-'+b+'V'+b+ - 'L'+b+','+a+'H-'+b+'L-'+a+','+b+'V-'+b+'Z'; + var a = d3.round(r * 0.924, 2), + b = d3.round(r * 0.383, 2); + return 'M-' + b + ',-' + a + 'H' + b + 'L' + a + ',-' + b + 'V' + b + + 'L' + b + ',' + a + 'H-' + b + 'L-' + a + ',' + b + 'V-' + b + 'Z'; } }, star: { n: 17, f: function(r) { - var rs = r*1.4, - x1 = d3.round(rs*0.225,2), - x2 = d3.round(rs*0.951,2), - x3 = d3.round(rs*0.363,2), - x4 = d3.round(rs*0.588,2), - y0 = d3.round(-rs,2), - y1 = d3.round(rs*-0.309,2), - y3 = d3.round(rs*0.118,2), - y4 = d3.round(rs*0.809,2), - y5 = d3.round(rs*0.382,2); - return 'M'+x1+','+y1+'H'+x2+'L'+x3+','+y3+ - 'L'+x4+','+y4+'L0,'+y5+'L-'+x4+','+y4+ - 'L-'+x3+','+y3+'L-'+x2+','+y1+'H-'+x1+ - 'L0,'+y0+'Z'; + var rs = r * 1.4, + x1 = d3.round(rs * 0.225, 2), + x2 = d3.round(rs * 0.951, 2), + x3 = d3.round(rs * 0.363, 2), + x4 = d3.round(rs * 0.588, 2), + y0 = d3.round(-rs, 2), + y1 = d3.round(rs * -0.309, 2), + y3 = d3.round(rs * 0.118, 2), + y4 = d3.round(rs * 0.809, 2), + y5 = d3.round(rs * 0.382, 2); + return 'M' + x1 + ',' + y1 + 'H' + x2 + 'L' + x3 + ',' + y3 + + 'L' + x4 + ',' + y4 + 'L0,' + y5 + 'L-' + x4 + ',' + y4 + + 'L-' + x3 + ',' + y3 + 'L-' + x2 + ',' + y1 + 'H-' + x1 + + 'L0,' + y0 + 'Z'; } }, hexagram: { n: 18, f: function(r) { - var y = d3.round(r*0.66,2), - x1 = d3.round(r*0.38,2), - x2 = d3.round(r*0.76,2); - return 'M-'+x2+',0l-'+x1+',-'+y+'h'+x2+ - 'l'+x1+',-'+y+'l'+x1+','+y+'h'+x2+ - 'l-'+x1+','+y+'l'+x1+','+y+'h-'+x2+ - 'l-'+x1+','+y+'l-'+x1+',-'+y+'h-'+x2+'Z'; + var y = d3.round(r * 0.66, 2), + x1 = d3.round(r * 0.38, 2), + x2 = d3.round(r * 0.76, 2); + return 'M-' + x2 + ',0l-' + x1 + ',-' + y + 'h' + x2 + + 'l' + x1 + ',-' + y + 'l' + x1 + ',' + y + 'h' + x2 + + 'l-' + x1 + ',' + y + 'l' + x1 + ',' + y + 'h-' + x2 + + 'l-' + x1 + ',' + y + 'l-' + x1 + ',-' + y + 'h-' + x2 + 'Z'; } }, 'star-triangle-up': { n: 19, f: function(r) { - var x = d3.round(r*Math.sqrt(3)*0.8,2), - y1 = d3.round(r*0.8,2), - y2 = d3.round(r*1.6,2), - rc = d3.round(r*4,2), - aPart = 'A '+rc+','+rc+' 0 0 1 '; - return 'M-'+x+','+y1+aPart+x+','+y1+ - aPart+'0,-'+y2+aPart+'-'+x+','+y1+'Z'; + var x = d3.round(r * Math.sqrt(3) * 0.8, 2), + y1 = d3.round(r * 0.8, 2), + y2 = d3.round(r * 1.6, 2), + rc = d3.round(r * 4, 2), + aPart = 'A ' + rc + ',' + rc + ' 0 0 1 '; + return 'M-' + x + ',' + y1 + aPart + x + ',' + y1 + + aPart + '0,-' + y2 + aPart + '-' + x + ',' + y1 + 'Z'; } }, 'star-triangle-down': { n: 20, f: function(r) { - var x = d3.round(r*Math.sqrt(3)*0.8,2), - y1 = d3.round(r*0.8,2), - y2 = d3.round(r*1.6,2), - rc = d3.round(r*4,2), - aPart = 'A '+rc+','+rc+' 0 0 1 '; - return 'M'+x+',-'+y1+aPart+'-'+x+',-'+y1+ - aPart+'0,'+y2+aPart+x+',-'+y1+'Z'; + var x = d3.round(r * Math.sqrt(3) * 0.8, 2), + y1 = d3.round(r * 0.8, 2), + y2 = d3.round(r * 1.6, 2), + rc = d3.round(r * 4, 2), + aPart = 'A ' + rc + ',' + rc + ' 0 0 1 '; + return 'M' + x + ',-' + y1 + aPart + '-' + x + ',-' + y1 + + aPart + '0,' + y2 + aPart + x + ',-' + y1 + 'Z'; } }, 'star-square': { n: 21, f: function(r) { - var rp = d3.round(r*1.1,2), - rc = d3.round(r*2,2), - aPart = 'A '+rc+','+rc+' 0 0 1 '; - return 'M-'+rp+',-'+rp+aPart+'-'+rp+','+rp+ - aPart+rp+','+rp+aPart+rp+',-'+rp+ - aPart+'-'+rp+',-'+rp+'Z'; + var rp = d3.round(r * 1.1, 2), + rc = d3.round(r * 2, 2), + aPart = 'A ' + rc + ',' + rc + ' 0 0 1 '; + return 'M-' + rp + ',-' + rp + aPart + '-' + rp + ',' + rp + + aPart + rp + ',' + rp + aPart + rp + ',-' + rp + + aPart + '-' + rp + ',-' + rp + 'Z'; } }, 'star-diamond': { n: 22, f: function(r) { - var rp = d3.round(r*1.4,2), - rc = d3.round(r*1.9,2), - aPart = 'A '+rc+','+rc+' 0 0 1 '; - return 'M-'+rp+',0'+aPart+'0,'+rp+ - aPart+rp+',0'+aPart+'0,-'+rp+ - aPart+'-'+rp+',0'+'Z'; + var rp = d3.round(r * 1.4, 2), + rc = d3.round(r * 1.9, 2), + aPart = 'A ' + rc + ',' + rc + ' 0 0 1 '; + return 'M-' + rp + ',0' + aPart + '0,' + rp + + aPart + rp + ',0' + aPart + '0,-' + rp + + aPart + '-' + rp + ',0' + 'Z'; } }, 'diamond-tall': { n: 23, f: function(r) { - var x = d3.round(r*0.7,2), - y = d3.round(r*1.4,2); - return 'M0,'+y+'L'+x+',0L0,-'+y+'L-'+x+',0Z'; + var x = d3.round(r * 0.7, 2), + y = d3.round(r * 1.4, 2); + return 'M0,' + y + 'L' + x + ',0L0,-' + y + 'L-' + x + ',0Z'; } }, 'diamond-wide': { n: 24, f: function(r) { - var x = d3.round(r*1.4,2), - y = d3.round(r*0.7,2); - return 'M0,'+y+'L'+x+',0L0,-'+y+'L-'+x+',0Z'; + var x = d3.round(r * 1.4, 2), + y = d3.round(r * 0.7, 2); + return 'M0,' + y + 'L' + x + ',0L0,-' + y + 'L-' + x + ',0Z'; } }, hourglass: { n: 25, f: function(r) { - var rs = d3.round(r,2); - return 'M'+rs+','+rs+'H-'+rs+'L'+rs+',-'+rs+'H-'+rs+'Z'; + var rs = d3.round(r, 2); + return 'M' + rs + ',' + rs + 'H-' + rs + 'L' + rs + ',-' + rs + 'H-' + rs + 'Z'; }, noDot: true }, bowtie: { n: 26, f: function(r) { - var rs = d3.round(r,2); - return 'M'+rs+','+rs+'V-'+rs+'L-'+rs+','+rs+'V-'+rs+'Z'; + var rs = d3.round(r, 2); + return 'M' + rs + ',' + rs + 'V-' + rs + 'L-' + rs + ',' + rs + 'V-' + rs + 'Z'; }, noDot: true }, 'circle-cross': { n: 27, f: function(r) { - var rs = d3.round(r,2); - return 'M0,'+rs+'V-'+rs+'M'+rs+',0H-'+rs+ - 'M'+rs+',0A'+rs+','+rs+' 0 1,1 0,-'+rs+ - 'A'+rs+','+rs+' 0 0,1 '+rs+',0Z'; + var rs = d3.round(r, 2); + return 'M0,' + rs + 'V-' + rs + 'M' + rs + ',0H-' + rs + + 'M' + rs + ',0A' + rs + ',' + rs + ' 0 1,1 0,-' + rs + + 'A' + rs + ',' + rs + ' 0 0,1 ' + rs + ',0Z'; }, needLine: true, noDot: true @@ -295,12 +295,12 @@ module.exports = { 'circle-x': { n: 28, f: function(r) { - var rs = d3.round(r,2), - rc = d3.round(r/Math.sqrt(2),2); - return 'M'+rc+','+rc+'L-'+rc+',-'+rc+ - 'M'+rc+',-'+rc+'L-'+rc+','+rc+ - 'M'+rs+',0A'+rs+','+rs+' 0 1,1 0,-'+rs+ - 'A'+rs+','+rs+' 0 0,1 '+rs+',0Z'; + var rs = d3.round(r, 2), + rc = d3.round(r / Math.sqrt(2), 2); + return 'M' + rc + ',' + rc + 'L-' + rc + ',-' + rc + + 'M' + rc + ',-' + rc + 'L-' + rc + ',' + rc + + 'M' + rs + ',0A' + rs + ',' + rs + ' 0 1,1 0,-' + rs + + 'A' + rs + ',' + rs + ' 0 0,1 ' + rs + ',0Z'; }, needLine: true, noDot: true @@ -308,9 +308,9 @@ module.exports = { 'square-cross': { n: 29, f: function(r) { - var rs = d3.round(r,2); - return 'M0,'+rs+'V-'+rs+'M'+rs+',0H-'+rs+ - 'M'+rs+','+rs+'H-'+rs+'V-'+rs+'H'+rs+'Z'; + var rs = d3.round(r, 2); + return 'M0,' + rs + 'V-' + rs + 'M' + rs + ',0H-' + rs + + 'M' + rs + ',' + rs + 'H-' + rs + 'V-' + rs + 'H' + rs + 'Z'; }, needLine: true, noDot: true @@ -318,10 +318,10 @@ module.exports = { 'square-x': { n: 30, f: function(r) { - var rs = d3.round(r,2); - return 'M'+rs+','+rs+'L-'+rs+',-'+rs+ - 'M'+rs+',-'+rs+'L-'+rs+','+rs+ - 'M'+rs+','+rs+'H-'+rs+'V-'+rs+'H'+rs+'Z'; + var rs = d3.round(r, 2); + return 'M' + rs + ',' + rs + 'L-' + rs + ',-' + rs + + 'M' + rs + ',-' + rs + 'L-' + rs + ',' + rs + + 'M' + rs + ',' + rs + 'H-' + rs + 'V-' + rs + 'H' + rs + 'Z'; }, needLine: true, noDot: true @@ -329,9 +329,9 @@ module.exports = { 'diamond-cross': { n: 31, f: function(r) { - var rd = d3.round(r*1.3,2); - return 'M'+rd+',0L0,'+rd+'L-'+rd+',0L0,-'+rd+'Z'+ - 'M0,-'+rd+'V'+rd+'M-'+rd+',0H'+rd; + var rd = d3.round(r * 1.3, 2); + return 'M' + rd + ',0L0,' + rd + 'L-' + rd + ',0L0,-' + rd + 'Z' + + 'M0,-' + rd + 'V' + rd + 'M-' + rd + ',0H' + rd; }, needLine: true, noDot: true @@ -339,11 +339,11 @@ module.exports = { 'diamond-x': { n: 32, f: function(r) { - var rd = d3.round(r*1.3,2), - r2 = d3.round(r*0.65,2); - return 'M'+rd+',0L0,'+rd+'L-'+rd+',0L0,-'+rd+'Z'+ - 'M-'+r2+',-'+r2+'L'+r2+','+r2+ - 'M-'+r2+','+r2+'L'+r2+',-'+r2; + var rd = d3.round(r * 1.3, 2), + r2 = d3.round(r * 0.65, 2); + return 'M' + rd + ',0L0,' + rd + 'L-' + rd + ',0L0,-' + rd + 'Z' + + 'M-' + r2 + ',-' + r2 + 'L' + r2 + ',' + r2 + + 'M-' + r2 + ',' + r2 + 'L' + r2 + ',-' + r2; }, needLine: true, noDot: true @@ -351,8 +351,8 @@ module.exports = { 'cross-thin': { n: 33, f: function(r) { - var rc = d3.round(r*1.4,2); - return 'M0,'+rc+'V-'+rc+'M'+rc+',0H-'+rc; + var rc = d3.round(r * 1.4, 2); + return 'M0,' + rc + 'V-' + rc + 'M' + rc + ',0H-' + rc; }, needLine: true, noDot: true @@ -360,9 +360,9 @@ module.exports = { 'x-thin': { n: 34, f: function(r) { - var rx = d3.round(r,2); - return 'M'+rx+','+rx+'L-'+rx+',-'+rx+ - 'M'+rx+',-'+rx+'L-'+rx+','+rx; + var rx = d3.round(r, 2); + return 'M' + rx + ',' + rx + 'L-' + rx + ',-' + rx + + 'M' + rx + ',-' + rx + 'L-' + rx + ',' + rx; }, needLine: true, noDot: true @@ -370,11 +370,11 @@ module.exports = { asterisk: { n: 35, f: function(r) { - var rc = d3.round(r*1.2,2); - var rs = d3.round(r*0.85,2); - return 'M0,'+rc+'V-'+rc+'M'+rc+',0H-'+rc+ - 'M'+rs+','+rs+'L-'+rs+',-'+rs+ - 'M'+rs+',-'+rs+'L-'+rs+','+rs; + var rc = d3.round(r * 1.2, 2); + var rs = d3.round(r * 0.85, 2); + return 'M0,' + rc + 'V-' + rc + 'M' + rc + ',0H-' + rc + + 'M' + rs + ',' + rs + 'L-' + rs + ',-' + rs + + 'M' + rs + ',-' + rs + 'L-' + rs + ',' + rs; }, needLine: true, noDot: true @@ -382,22 +382,22 @@ module.exports = { hash: { n: 36, f: function(r) { - var r1 = d3.round(r/2,2), - r2 = d3.round(r,2); - return 'M'+r1+','+r2+'V-'+r2+ - 'm-'+r2+',0V'+r2+ - 'M'+r2+','+r1+'H-'+r2+ - 'm0,-'+r2+'H'+r2; + var r1 = d3.round(r / 2, 2), + r2 = d3.round(r, 2); + return 'M' + r1 + ',' + r2 + 'V-' + r2 + + 'm-' + r2 + ',0V' + r2 + + 'M' + r2 + ',' + r1 + 'H-' + r2 + + 'm0,-' + r2 + 'H' + r2; }, needLine: true }, 'y-up': { n: 37, f: function(r) { - var x = d3.round(r*1.2,2), - y0 = d3.round(r*1.6,2), - y1 = d3.round(r*0.8,2); - return 'M-'+x+','+y1+'L0,0M'+x+','+y1+'L0,0M0,-'+y0+'L0,0'; + var x = d3.round(r * 1.2, 2), + y0 = d3.round(r * 1.6, 2), + y1 = d3.round(r * 0.8, 2); + return 'M-' + x + ',' + y1 + 'L0,0M' + x + ',' + y1 + 'L0,0M0,-' + y0 + 'L0,0'; }, needLine: true, noDot: true @@ -405,10 +405,10 @@ module.exports = { 'y-down': { n: 38, f: function(r) { - var x = d3.round(r*1.2,2), - y0 = d3.round(r*1.6,2), - y1 = d3.round(r*0.8,2); - return 'M-'+x+',-'+y1+'L0,0M'+x+',-'+y1+'L0,0M0,'+y0+'L0,0'; + var x = d3.round(r * 1.2, 2), + y0 = d3.round(r * 1.6, 2), + y1 = d3.round(r * 0.8, 2); + return 'M-' + x + ',-' + y1 + 'L0,0M' + x + ',-' + y1 + 'L0,0M0,' + y0 + 'L0,0'; }, needLine: true, noDot: true @@ -416,10 +416,10 @@ module.exports = { 'y-left': { n: 39, f: function(r) { - var y = d3.round(r*1.2,2), - x0 = d3.round(r*1.6,2), - x1 = d3.round(r*0.8,2); - return 'M'+x1+','+y+'L0,0M'+x1+',-'+y+'L0,0M-'+x0+',0L0,0'; + var y = d3.round(r * 1.2, 2), + x0 = d3.round(r * 1.6, 2), + x1 = d3.round(r * 0.8, 2); + return 'M' + x1 + ',' + y + 'L0,0M' + x1 + ',-' + y + 'L0,0M-' + x0 + ',0L0,0'; }, needLine: true, noDot: true @@ -427,10 +427,10 @@ module.exports = { 'y-right': { n: 40, f: function(r) { - var y = d3.round(r*1.2,2), - x0 = d3.round(r*1.6,2), - x1 = d3.round(r*0.8,2); - return 'M-'+x1+','+y+'L0,0M-'+x1+',-'+y+'L0,0M'+x0+',0L0,0'; + var y = d3.round(r * 1.2, 2), + x0 = d3.round(r * 1.6, 2), + x1 = d3.round(r * 0.8, 2); + return 'M-' + x1 + ',' + y + 'L0,0M-' + x1 + ',-' + y + 'L0,0M' + x0 + ',0L0,0'; }, needLine: true, noDot: true @@ -438,8 +438,8 @@ module.exports = { 'line-ew': { n: 41, f: function(r) { - var rc = d3.round(r*1.4,2); - return 'M'+rc+',0H-'+rc; + var rc = d3.round(r * 1.4, 2); + return 'M' + rc + ',0H-' + rc; }, needLine: true, noDot: true @@ -447,8 +447,8 @@ module.exports = { 'line-ns': { n: 42, f: function(r) { - var rc = d3.round(r*1.4,2); - return 'M0,'+rc+'V-'+rc; + var rc = d3.round(r * 1.4, 2); + return 'M0,' + rc + 'V-' + rc; }, needLine: true, noDot: true @@ -456,8 +456,8 @@ module.exports = { 'line-ne': { n: 43, f: function(r) { - var rx = d3.round(r,2); - return 'M'+rx+',-'+rx+'L-'+rx+','+rx; + var rx = d3.round(r, 2); + return 'M' + rx + ',-' + rx + 'L-' + rx + ',' + rx; }, needLine: true, noDot: true @@ -465,8 +465,8 @@ module.exports = { 'line-nw': { n: 44, f: function(r) { - var rx = d3.round(r,2); - return 'M'+rx+','+rx+'L-'+rx+',-'+rx; + var rx = d3.round(r, 2); + return 'M' + rx + ',' + rx + 'L-' + rx + ',-' + rx; }, needLine: true, noDot: true diff --git a/src/components/errorbars/defaults.js b/src/components/errorbars/defaults.js index 9aba2acafa6..2146b8ca2d4 100644 --- a/src/components/errorbars/defaults.js +++ b/src/components/errorbars/defaults.js @@ -53,15 +53,15 @@ module.exports = function(traceIn, traceOut, defaultColor, opts) { coerce('tracerefminus'); } } - else if(type==='percent' || type==='constant') { + else if(type === 'percent' || type === 'constant') { coerce('value'); if(!symmetric) coerce('valueminus'); } - var copyAttr = 'copy_'+opts.inherit+'style'; + var copyAttr = 'copy_' + opts.inherit + 'style'; if(opts.inherit) { var inheritObj = traceOut['error_' + opts.inherit]; - if((inheritObj||{}).visible) { + if((inheritObj || {}).visible) { coerce(copyAttr, !(containerIn.color || isNumeric(containerIn.thickness) || isNumeric(containerIn.width))); diff --git a/src/components/errorbars/plot.js b/src/components/errorbars/plot.js index dd05c65e7df..3f44ed58df1 100644 --- a/src/components/errorbars/plot.js +++ b/src/components/errorbars/plot.js @@ -59,7 +59,7 @@ module.exports = function plot(traces, plotinfo) { coords.yh + 'h' + (2 * yw) + // hat 'm-' + yw + ',0V' + coords.ys; // bar - if(!coords.noYS) path += 'm-' + yw +',0h' + (2 * yw); // shoe + if(!coords.noYS) path += 'm-' + yw + ',0h' + (2 * yw); // shoe errorbar.append('path') .classed('yerror', true) diff --git a/src/components/legend/defaults.js b/src/components/legend/defaults.js index aa6e8794ca5..71b53b89643 100644 --- a/src/components/legend/defaults.js +++ b/src/components/legend/defaults.js @@ -36,8 +36,8 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) { if(Plots.traceIs(trace, 'pie')) visibleTraces++; } - if((Plots.traceIs(trace, 'bar') && layoutOut.barmode==='stack') || - ['tonextx','tonexty'].indexOf(trace.fill)!==-1) { + if((Plots.traceIs(trace, 'bar') && layoutOut.barmode === 'stack') || + ['tonextx', 'tonexty'].indexOf(trace.fill) !== -1) { defaultOrder = helpers.isGrouped({traceorder: defaultOrder}) ? 'grouped+reversed' : 'reversed'; } diff --git a/src/components/legend/draw.js b/src/components/legend/draw.js index 310b81c0ebe..9c6dd4e1bb7 100644 --- a/src/components/legend/draw.js +++ b/src/components/legend/draw.js @@ -148,7 +148,7 @@ module.exports = function draw(gd) { // and these values are mutated in repositionLegend. var gs = fullLayout._size, lx = gs.l + gs.w * opts.x, - ly = gs.t + gs.h * (1-opts.y); + ly = gs.t + gs.h * (1 - opts.y); if(anchorUtils.isRightAnchor(opts)) { lx -= opts.width; @@ -251,7 +251,7 @@ module.exports = function draw(gd) { scrollHandler(scrollBarY, scrollBoxY); - legend.on('wheel',null); + legend.on('wheel', null); legend.on('wheel', function() { scrollBoxY = Lib.constrain( scrollBox.attr('data-scroll') - @@ -263,8 +263,8 @@ module.exports = function draw(gd) { d3.event.preventDefault(); }); - scrollBar.on('.drag',null); - scrollBox.on('.drag',null); + scrollBar.on('.drag', null); + scrollBox.on('.drag', null); var drag = d3.behavior.drag().on('drag', function() { scrollBarY = Lib.constrain( d3.event.y - constants.scrollBarHeight / 2, @@ -317,8 +317,8 @@ module.exports = function draw(gd) { Lib.setTranslate(legend, newX, newY); - xf = dragElement.align(newX, 0, gs.l, gs.l+gs.w, opts.xanchor); - yf = dragElement.align(newY, 0, gs.t+gs.h, gs.t, opts.yanchor); + xf = dragElement.align(newX, 0, gs.l, gs.l + gs.w, opts.xanchor); + yf = dragElement.align(newY, 0, gs.t + gs.h, gs.t, opts.yanchor); }, doneFn: function(dragged) { if(dragged && xf !== undefined && yf !== undefined) { @@ -500,7 +500,7 @@ function computeLegendDimensions(gd, groups, traces) { opts.height += 10 + borderwidth * 2; if(isGrouped) { - opts.height += (opts._lgroupsLength-1) * opts.tracegroupgap; + opts.height += (opts._lgroupsLength - 1) * opts.tracegroupgap; } traces.selectAll('.legendtoggle') diff --git a/src/components/legend/get_legend_data.js b/src/components/legend/get_legend_data.js index a8698f140fe..a8ca0748c07 100644 --- a/src/components/legend/get_legend_data.js +++ b/src/components/legend/get_legend_data.js @@ -93,7 +93,7 @@ module.exports = function getLegendData(calcdata, opts) { for(i = 0; i < lgroupsLength; i++) { ltraces = lgroupToTraces[lgroups[i]][0]; - legendData[0][helpers.isReversed(opts) ? lgroupsLength-i-1 : i] = ltraces; + legendData[0][helpers.isReversed(opts) ? lgroupsLength - i - 1 : i] = ltraces; } lgroupsLength = 1; } diff --git a/src/components/legend/style.js b/src/components/legend/style.js index 8ff88fe3e2a..d5299f24e63 100644 --- a/src/components/legend/style.js +++ b/src/components/legend/style.js @@ -57,7 +57,7 @@ module.exports = function style(s) { function styleLines(d) { var trace = d[0].trace, - showFill = trace.visible && trace.fill && trace.fill!=='none', + showFill = trace.visible && trace.fill && trace.fill !== 'none', showLine = subTypes.hasLines(trace); var fill = d3.select(this).select('.legendfill').selectAll('path') @@ -153,7 +153,7 @@ function stylePoints(d) { var txt = ptgroup.selectAll('g.pointtext') .data(showText ? dMod : []); txt.enter() - .append('g').classed('pointtext',true) + .append('g').classed('pointtext', true) .append('text').attr('transform', 'translate(20,0)'); txt.exit().remove(); txt.selectAll('text').call(Drawing.textPointStyle, tMod); @@ -167,14 +167,14 @@ function styleBars(d) { .selectAll('path.legendbar') .data(Plots.traceIs(trace, 'bar') ? [d] : []); barpath.enter().append('path').classed('legendbar', true) - .attr('d','M6,6H-6V-6H6Z') + .attr('d', 'M6,6H-6V-6H6Z') .attr('transform', 'translate(20,0)'); barpath.exit().remove(); barpath.each(function(d) { var w = (d.mlw + 1 || markerLine.width + 1) - 1, p = d3.select(this); - p.style('stroke-width',w+'px') + p.style('stroke-width', w + 'px') .call(Color.fill, d.mc || marker.color); if(w) { @@ -197,7 +197,7 @@ function styleBoxes(d) { var w = (d.lw + 1 || trace.line.width + 1) - 1, p = d3.select(this); - p.style('stroke-width', w+'px') + p.style('stroke-width', w + 'px') .call(Color.fill, d.fc || trace.fillcolor); if(w) { diff --git a/src/components/modebar/buttons.js b/src/components/modebar/buttons.js index b3805db0780..9635b30cc37 100644 --- a/src/components/modebar/buttons.js +++ b/src/components/modebar/buttons.js @@ -219,7 +219,7 @@ function handleCartesian(gd, ev) { } else { // if ALL traces have orientation 'h', 'hovermode': 'x' otherwise: 'y' - if(astr==='hovermode' && (val==='x' || val==='y')) { + if(astr === 'hovermode' && (val === 'x' || val === 'y')) { val = fullLayout._isHoriz ? 'y' : 'x'; button.setAttribute('data-val', val); } diff --git a/src/components/shapes/index.js b/src/components/shapes/index.js index 0e493e7a287..3fde60c54d7 100644 --- a/src/components/shapes/index.js +++ b/src/components/shapes/index.js @@ -48,7 +48,7 @@ function handleShapeDefaults(shapeIn, fullLayout) { shapeType = coerce('type', dfltType); // positioning - var axLetters = ['x','y']; + var axLetters = ['x', 'y']; for(var i = 0; i < 2; i++) { var axLetter = axLetters[i], tdMock = {_fullLayout: fullLayout}; @@ -109,7 +109,7 @@ shapes.drawAll = function(gd) { shapes.add = function(gd) { var nextShape = gd._fullLayout.shapes.length; - Plotly.relayout(gd, 'shapes['+nextShape+']', 'add'); + Plotly.relayout(gd, 'shapes[' + nextShape + ']', 'add'); }; // ----------------------------------------------------- @@ -257,8 +257,8 @@ function updateShape(gd, index, opt, value) { // or axis type. // the defaults will be consistent most of the time anyway, // except in log/linear changes - if(optionsEdit[posAttr]!==undefined || - optionsIn[posAttr]===undefined) { + if(optionsEdit[posAttr] !== undefined || + optionsIn[posAttr] === undefined) { continue; } @@ -270,7 +270,7 @@ function updateShape(gd, index, opt, value) { position = optionsIn[posAttr], linearizedPosition; - if(optionsEdit[axLetter + 'ref']!==undefined) { + if(optionsEdit[axLetter + 'ref'] !== undefined) { // first convert to fraction of the axis if(axOld) { linearizedPosition = dataToLinear(axOld)(position); @@ -398,9 +398,9 @@ function shapePath(gd, options) { y2p = function(v) { return gs.t + gs.h * (1 - v); }; } - if(type==='path') { - if(xa && xa.type==='date') x2p = decodeDate(x2p); - if(ya && ya.type==='date') y2p = decodeDate(y2p); + if(type === 'path') { + if(xa && xa.type === 'date') x2p = decodeDate(x2p); + if(ya && ya.type === 'date') y2p = decodeDate(y2p); return shapes.convertPath(options.path, x2p, y2p); } @@ -409,8 +409,8 @@ function shapePath(gd, options) { y0 = y2p(options.y0), y1 = y2p(options.y1); - if(type==='line') return 'M'+x0+','+y0+'L'+x1+','+y1; - if(type==='rect') return 'M'+x0+','+y0+'H'+x1+'V'+y1+'H'+x0+'Z'; + if(type === 'line') return 'M' + x0 + ',' + y0 + 'L' + x1 + ',' + y1; + if(type === 'rect') return 'M' + x0 + ',' + y0 + 'H' + x1 + 'V' + y1 + 'H' + x0 + 'Z'; // circle var cx = (x0 + x1) / 2, cy = (y0 + y1) / 2, @@ -526,7 +526,7 @@ shapes.calcAutorange = function(gd) { }; function shapeBounds(ax, v0, v1, path, paramsToUse) { - var convertVal = (ax.type==='category') ? Number : ax.d2c; + var convertVal = (ax.type === 'category') ? Number : ax.d2c; if(v0 !== undefined) return [convertVal(v0), convertVal(v1)]; if(!path) return; @@ -540,7 +540,7 @@ function shapeBounds(ax, v0, v1, path, paramsToUse) { params, val; - if(ax.type==='date') convertVal = decodeDate(convertVal); + if(ax.type === 'date') convertVal = decodeDate(convertVal); for(i = 0; i < segments.length; i++) { segment = segments[i]; diff --git a/src/components/titles/index.js b/src/components/titles/index.js index 9fedc319856..d2282596ab3 100644 --- a/src/components/titles/index.js +++ b/src/components/titles/index.js @@ -93,7 +93,7 @@ Titles.draw = function(gd, titleClass, options) { .attr('class', titleClass); function titleLayout(titleEl) { - Lib.syncOrAsync([drawTitle,scootTitle], titleEl); + Lib.syncOrAsync([drawTitle, scootTitle], titleEl); } function drawTitle(titleEl) { @@ -104,7 +104,7 @@ Titles.draw = function(gd, titleClass, options) { titleEl.style({ 'font-family': font, - 'font-size': d3.round(fontSize,2) + 'px', + 'font-size': d3.round(fontSize, 2) + 'px', fill: Color.rgb(fontColor), opacity: opacity * Color.opacity(fontColor), 'font-weight': Plots.fontWeight @@ -133,7 +133,7 @@ Titles.draw = function(gd, titleClass, options) { top: 'bottom', bottom: 'top' }[avoid.side], - shiftSign = (['left','top'].indexOf(avoid.side) !== -1) ? + shiftSign = (['left', 'top'].indexOf(avoid.side) !== -1) ? -1 : 1, pad = isNumeric(avoid.pad) ? avoid.pad : 2, titlebb = Drawing.bBox(titleGroup.node()), @@ -144,7 +144,7 @@ Titles.draw = function(gd, titleClass, options) { bottom: fullLayout.height }, maxshift = avoid.maxShift || ( - (paperbb[avoid.side]-titlebb[avoid.side]) * + (paperbb[avoid.side] - titlebb[avoid.side]) * ((avoid.side === 'left' || avoid.side === 'top') ? -1 : 1)); // Prevent the title going off the paper if(maxshift < 0) shift = maxshift; @@ -197,7 +197,7 @@ Titles.draw = function(gd, titleClass, options) { d3.select(this).transition() .duration(100).style('opacity', 1); }) - .on('mouseout.opacity',function() { + .on('mouseout.opacity', function() { d3.select(this).transition() .duration(1000).style('opacity', 0); }); diff --git a/src/fonts/mathjax_config.js b/src/fonts/mathjax_config.js index 23881802724..613463ac884 100644 --- a/src/fonts/mathjax_config.js +++ b/src/fonts/mathjax_config.js @@ -21,7 +21,7 @@ if(typeof MathJax !== 'undefined') { skipStartupTypeset: true, displayAlign: 'left', tex2jax: { - inlineMath: [['$','$'],['\\(','\\)']] + inlineMath: [['$', '$'], ['\\(', '\\)']] } }); diff --git a/src/lib/coerce.js b/src/lib/coerce.js index c00c510295c..c21a5410b7f 100644 --- a/src/lib/coerce.js +++ b/src/lib/coerce.js @@ -29,7 +29,7 @@ exports.valObjects = { otherOpts: ['dflt'], coerceFunction: function(v, propOut, dflt) { if(Array.isArray(v)) propOut.set(v); - else if(dflt!==undefined) propOut.set(dflt); + else if(dflt !== undefined) propOut.set(dflt); } }, enumerated: { @@ -41,7 +41,7 @@ exports.valObjects = { otherOpts: ['dflt', 'coerceNumber', 'arrayOk'], coerceFunction: function(v, propOut, dflt, opts) { if(opts.coerceNumber) v = +v; - if(opts.values.indexOf(v)===-1) propOut.set(dflt); + if(opts.values.indexOf(v) === -1) propOut.set(dflt); else propOut.set(v); } }, @@ -50,7 +50,7 @@ exports.valObjects = { requiredOpts: [], otherOpts: ['dflt'], coerceFunction: function(v, propOut, dflt) { - if(v===true || v===false) propOut.set(v); + if(v === true || v === false) propOut.set(v); else propOut.set(dflt); } }, @@ -65,8 +65,8 @@ exports.valObjects = { otherOpts: ['dflt', 'min', 'max', 'arrayOk'], coerceFunction: function(v, propOut, dflt, opts) { if(!isNumeric(v) || - (opts.min!==undefined && vopts.max)) { + (opts.min !== undefined && v < opts.min) || + (opts.max !== undefined && v > opts.max)) { propOut.set(dflt); } else propOut.set(+v); @@ -81,9 +81,9 @@ exports.valObjects = { requiredOpts: [], otherOpts: ['dflt', 'min', 'max'], coerceFunction: function(v, propOut, dflt, opts) { - if(v%1 || !isNumeric(v) || - (opts.min!==undefined && vopts.max)) { + if(v % 1 || !isNumeric(v) || + (opts.min !== undefined && v < opts.min) || + (opts.max !== undefined && v > opts.max)) { propOut.set(dflt); } else propOut.set(+v); @@ -99,13 +99,13 @@ exports.valObjects = { // TODO 'values shouldn't be in there (edge case: 'dash' in Scatter) otherOpts: ['dflt', 'noBlank', 'strict', 'arrayOk', 'values'], coerceFunction: function(v, propOut, dflt, opts) { - if(opts.strict===true && typeof v !== 'string') { + if(opts.strict === true && typeof v !== 'string') { propOut.set(dflt); return; } var s = String(v); - if(v===undefined || (opts.noBlank===true && !s)) { + if(v === undefined || (opts.noBlank === true && !s)) { propOut.set(dflt); } else propOut.set(s); @@ -151,10 +151,10 @@ exports.valObjects = { requiredOpts: [], otherOpts: ['dflt'], coerceFunction: function(v, propOut, dflt) { - if(v==='auto') propOut.set('auto'); + if(v === 'auto') propOut.set('auto'); else if(!isNumeric(v)) propOut.set(dflt); else { - if(Math.abs(v)>180) v -= Math.round(v/360)*360; + if(Math.abs(v) > 180) v -= Math.round(v / 360) * 360; propOut.set(+v); } } @@ -192,16 +192,16 @@ exports.valObjects = { propOut.set(dflt); return; } - if(opts.extras.indexOf(v)!==-1) { + if(opts.extras.indexOf(v) !== -1) { propOut.set(v); return; } var vParts = v.split('+'), i = 0; - while(i 2 || !(h >= 0 && h <= 23)) return false; - d += 3600000*h; + d += 3600000 * h; if(p.length === 1) return d; // minute m = Number(p[1]); if(p[1].length > 2 || !(m >= 0 && m <= 59)) return false; - d += 60000*m; + d += 60000 * m; if(p.length === 2) return d; // second s = Number(p[2]); if(!(s >= 0 && s < 60)) return false; - return d+s*1000; + return d + s * 1000; }; // is string s a date? (see above) @@ -121,31 +121,31 @@ 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; } - if(!r) r=0; + if(!r) r = 0; var d = new Date(ms), s = d3.time.format('%Y-%m-%d')(d); - if(r<7776000000) { + if(r < 7776000000) { // <90 days: add hours - s+=' '+lpad(d.getHours(),2); - if(r<432000000) { + s += ' ' + lpad(d.getHours(), 2); + if(r < 432000000) { // <5 days: add minutes - s+=':'+lpad(d.getMinutes(),2); - if(r<10800000) { + s += ':' + lpad(d.getMinutes(), 2); + if(r < 10800000) { // <3 hours: add seconds - s+=':'+lpad(d.getSeconds(),2); - if(r<300000) { + s += ':' + lpad(d.getSeconds(), 2); + if(r < 300000) { // <5 minutes: add ms - s+='.'+lpad(d.getMilliseconds(),3); + s += '.' + lpad(d.getMilliseconds(), 3); } } } // strip trailing zeros - return s.replace(/([:\s]00)*\.?[0]*$/,''); + return s.replace(/([:\s]00)*\.?[0]*$/, ''); } return s; }; @@ -232,8 +232,8 @@ var dateTimeFormats = { var a = dateTimeFormats[dateType][timeType]; // 'date time', then 'time date' - a.push(formatter(dateFormat+'~'+timeFormat)); - a.push(formatter(timeFormat+'~'+dateFormat)); + a.push(formatter(dateFormat + '~' + timeFormat)); + a.push(formatter(timeFormat + '~' + dateFormat)); }); }); }); @@ -241,18 +241,18 @@ var dateTimeFormats = { // precompiled regexps for performance var matchword = /[a-z]*/g, - shortenword = function(m) { return m.substr(0,3); }, + shortenword = function(m) { return m.substr(0, 3); }, weekdaymatch = /(mon|tue|wed|thu|fri|sat|sun|the|of|st|nd|rd|th)/g, separatormatch = /[\s,\/\-\.\(\)]+/g, ampmmatch = /~?([ap])~?m(~|$)/, - replaceampm = function(m,ap) { return ap+'m '; }, + replaceampm = function(m, ap) { return ap + 'm '; }, match4Y = /\d\d\d\d/, matchMonthName = /(^|~)[a-z]{3}/, matchAMPM = /[ap]m/, matchcolon = /:/, matchquarter = /q([1-4])/, - quarters = ['31~mar','30~jun','30~sep','31~dec'], - replacequarter = function(m,n) { return quarters[n-1]; }, + quarters = ['31~mar', '30~jun', '30~sep', '31~dec'], + replacequarter = function(m, n) { return quarters[n - 1]; }, matchTZ = / ?([+\-]\d\d:?\d\d|Z)$/; function getDateType(v) { diff --git a/src/lib/gl_format_color.js b/src/lib/gl_format_color.js index 50b765dd59b..79937b6a7dc 100644 --- a/src/lib/gl_format_color.js +++ b/src/lib/gl_format_color.js @@ -50,14 +50,14 @@ function formatColor(containerIn, opacityIn, len) { if(isArrayColorIn) { getColor = function(c, i) { - return c[i]===undefined ? colorDflt : sclFunc(c[i]); + return c[i] === undefined ? colorDflt : sclFunc(c[i]); }; } else getColor = validateColor; if(isArrayOpacityIn) { getOpacity = function(o, i) { - return o[i]===undefined ? opacityDflt : validateOpacity(o[i]); + return o[i] === undefined ? opacityDflt : validateOpacity(o[i]); }; } else getOpacity = validateOpacity; diff --git a/src/lib/html2unicode.js b/src/lib/html2unicode.js index d0cfc574c2c..c01ae754a19 100644 --- a/src/lib/html2unicode.js +++ b/src/lib/html2unicode.js @@ -25,7 +25,7 @@ function fixSuperScript(x) { var nidx = x.indexOf('', idx); if(nidx < idx) break; - x = x.slice(0, idx) + toSuperScript(x.slice(idx+5, nidx)) + x.slice(nidx+6); + x = x.slice(0, idx) + toSuperScript(x.slice(idx + 5, nidx)) + x.slice(nidx + 6); } return x; @@ -49,11 +49,11 @@ function fixEntities(x) { continue; } - var entity = ENTITIES[x.slice(idx+1, nidx)]; + var entity = ENTITIES[x.slice(idx + 1, nidx)]; if(entity) { - x = x.slice(0, idx) + entity + x.slice(nidx+1); + x = x.slice(0, idx) + entity + x.slice(nidx + 1); } else { - x = x.slice(0, idx) + x.slice(nidx+1); + x = x.slice(0, idx) + x.slice(nidx + 1); } } diff --git a/src/lib/index.js b/src/lib/index.js index 612dd2fa065..2d742a12e94 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -206,7 +206,7 @@ lib.OptionControl = function(opt, optname) { self.optionList.push(optObj); }; - self['_'+optname] = opt; + self['_' + optname] = opt; return self; }; @@ -355,7 +355,7 @@ lib.pushUnique = function(array, item) { lib.mergeArray = function(traceAttr, cd, cdAttr) { if(Array.isArray(traceAttr)) { var imax = Math.min(traceAttr.length, cd.length); - for(var i=0; i 1 ? decimalSep + x[1] : ''; // Years are ignored for thousands separators - if(thouSep && (x.length > 1 || x1.length>4)) { + if(thouSep && (x.length > 1 || x1.length > 4)) { while(thousandsRe.test(x1)) { x1 = x1.replace(thousandsRe, '$1' + thouSep + '$2'); } diff --git a/src/lib/matrix.js b/src/lib/matrix.js index 395ea13c3ee..54aeac27ffc 100644 --- a/src/lib/matrix.js +++ b/src/lib/matrix.js @@ -73,7 +73,7 @@ exports.translationMatrix = function(x, y) { // rotate by alpha around (0,0) exports.rotationMatrix = function(alpha) { - var a = alpha*Math.PI/180; + var a = alpha * Math.PI / 180; return [[Math.cos(a), -Math.sin(a), 0], [Math.sin(a), Math.cos(a), 0], [0, 0, 1]]; diff --git a/src/lib/nested_property.js b/src/lib/nested_property.js index 411610ef396..ac51e2ab4bd 100644 --- a/src/lib/nested_property.js +++ b/src/lib/nested_property.js @@ -45,16 +45,16 @@ module.exports = function nestedProperty(container, propStr) { if(indexed) { if(indexed[1]) propParts[j] = indexed[1]; // allow propStr to start with bracketed array indices - else if(j === 0) propParts.splice(0,1); + else if(j === 0) propParts.splice(0, 1); else throw 'bad property string'; indices = indexed[2] - .substr(1,indexed[2].length-2) + .substr(1, indexed[2].length - 2) .split(']['); - for(i=0; i 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, ' '); + return (_str || '').replace(STRIP_TAGS, ' '); }; function convertToSVG(_str) { @@ -260,7 +260,7 @@ function convertToSVG(_str) { // anchor and br are the only ones that don't turn into a tspan if(tag === 'a') { if(close) return ''; - else if(extra.substr(0,4).toLowerCase() !== 'href') return ''; + else if(extra.substr(0, 4).toLowerCase() !== 'href') return ''; else { var dummyAnchor = document.createElement('a'); dummyAnchor.href = extra.substr(4).replace(/["'=]/g, ''); @@ -303,7 +303,7 @@ 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; @@ -311,7 +311,7 @@ function convertToSVG(_str) { 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[1]) previousOpenTag = search[i2]; @@ -319,7 +319,7 @@ function convertToSVG(_str) { } } if(previousOpenTag) { - result.splice(brIndex+1, 0, previousOpenTag); + result.splice(brIndex + 1, 0, previousOpenTag); result.splice(brIndex, 0, ''); count += 2; } @@ -334,7 +334,7 @@ function convertToSVG(_str) { // 1) bringing the base font size into convertToTspans, or // 2) only allowing relative percentage font sizes. // I think #2 is the way to go - return ''+ d +''; + return '' + d + ''; }); } @@ -425,7 +425,7 @@ util.makeEditable = function(context, _delegate, options) { opacity: 1, 'background-color': options.background || 'transparent', outline: '#ffffff33 1px solid', - margin: [-parseFloat(that.style('font-size'))/8+1, 0, 0, -1].join('px ') + 'px', + margin: [-parseFloat(that.style('font-size')) / 8 + 1, 0, 0, -1].join('px ') + 'px', padding: '0', 'box-sizing': 'border-box' }) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 9b7acb1af60..d6ed0a60d43 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -186,7 +186,7 @@ Plotly.plot = function(gd, data, layout, config) { cd = calcdata[i]; trace = cd[0].trace; if(trace.visible !== true || !trace._module.colorbar) { - Plots.autoMargin(gd, 'cb'+trace.uid); + Plots.autoMargin(gd, 'cb' + trace.uid); } else trace._module.colorbar(gd, cd); } @@ -197,9 +197,9 @@ Plotly.plot = function(gd, data, layout, config) { function marginPushersAgain() { // in case the margins changed, draw margin pushers again - var seq = JSON.stringify(fullLayout._size)===oldmargins ? + var seq = JSON.stringify(fullLayout._size) === oldmargins ? [] : [marginPushers, layoutStyles]; - return Lib.syncOrAsync(seq.concat(Fx.init),gd); + return Lib.syncOrAsync(seq.concat(Fx.init), gd); } function positionAndAutorange() { @@ -349,7 +349,7 @@ function getGraphDiv(gd) { return gdElement; } - else if(gd===null || gd===undefined) { + else if(gd === null || gd === undefined) { throw new Error('DOM element provided is null or undefined'); } @@ -403,8 +403,8 @@ function plotPolar(gd, data, layout) { var paperDiv = plotContainer.selectAll('.svg-container') .data([0]); paperDiv.enter().append('div') - .classed('svg-container',true) - .style('position','relative'); + .classed('svg-container', true) + .style('position', 'relative'); // empty it everytime for now paperDiv.html(''); @@ -415,7 +415,7 @@ function plotPolar(gd, data, layout) { Plotly.micropolar.manager.fillLayout(gd); if(gd._fullLayout.autosize === 'initial' && gd._context.autosizable) { - plotAutoSize(gd,{}); + plotAutoSize(gd, {}); gd._fullLayout.autosize = layout.autosize = true; } // resize canvas @@ -458,13 +458,13 @@ function plotPolar(gd, data, layout) { title.attr({'data-unformatted': placeholderText}) .text(placeholderText) .style({opacity: opacity}) - .on('mouseover.opacity',function() { + .on('mouseover.opacity', function() { d3.select(this).transition().duration(100) - .style('opacity',1); + .style('opacity', 1); }) - .on('mouseout.opacity',function() { + .on('mouseout.opacity', function() { d3.select(this).transition().duration(1000) - .style('opacity',0); + .style('opacity', 0); }); } @@ -519,11 +519,11 @@ function cleanLayout(layout) { // old method of axis type - isdate and islog (before category existed) if(!ax.type) { - if(ax.isdate) ax.type='date'; - else if(ax.islog) ax.type='log'; - else if(ax.isdate===false && ax.islog===false) ax.type='linear'; + if(ax.isdate) ax.type = 'date'; + else if(ax.islog) ax.type = 'log'; + else if(ax.isdate === false && ax.islog === false) ax.type = 'linear'; } - if(ax.autorange==='withzero' || ax.autorange==='tozero') { + if(ax.autorange === 'withzero' || ax.autorange === 'tozero') { ax.autorange = true; ax.rangemode = 'tozero'; } @@ -551,11 +551,11 @@ function cleanLayout(layout) { for(i = 0; i < annotationsLen; i++) { var ann = layout.annotations[i]; if(ann.ref) { - if(ann.ref==='paper') { + if(ann.ref === 'paper') { ann.xref = 'paper'; ann.yref = 'paper'; } - else if(ann.ref==='data') { + else if(ann.ref === 'data') { ann.xref = 'x'; ann.yref = 'y'; } @@ -569,7 +569,7 @@ function cleanLayout(layout) { console.log('shapes must be an array'); delete layout.shapes; } - var shapesLen = (layout.shapes||[]).length; + var shapesLen = (layout.shapes || []).length; for(i = 0; i < shapesLen; i++) { var shape = layout.shapes[i]; cleanAxRef(shape, 'xref'); @@ -676,7 +676,7 @@ function cleanData(data, existingData) { for(i = 0; i < 100; i++) { newUid = Lib.randstr(uids); - if(suids.indexOf(newUid)===-1) break; + if(suids.indexOf(newUid) === -1) break; } trace.uid = Lib.randstr(uids); uids.push(trace.uid); @@ -689,7 +689,7 @@ function cleanData(data, existingData) { // BACKWARD COMPATIBILITY FIXES // use xbins to bin data in x, and ybins to bin data in y - if(trace.type==='histogramy' && 'xbins' in trace && !('ybins' in trace)) { + if(trace.type === 'histogramy' && 'xbins' in trace && !('ybins' in trace)) { trace.ybins = trace.xbins; delete trace.xbins; } @@ -708,8 +708,8 @@ function cleanData(data, existingData) { // convert bardir to orientation, and put the data into // the axes it's eventually going to be used with if('bardir' in trace) { - if(trace.bardir==='h' && (Plots.traceIs(trace, 'bar') || - trace.type.substr(0,9)==='histogram')) { + if(trace.bardir === 'h' && (Plots.traceIs(trace, 'bar') || + trace.type.substr(0, 9) === 'histogram')) { trace.orientation = 'h'; swapXYData(trace); } @@ -718,8 +718,8 @@ function cleanData(data, existingData) { // now we have only one 1D histogram type, and whether // it uses x or y data depends on trace.orientation - if(trace.type==='histogramy') swapXYData(trace); - if(trace.type==='histogramx' || trace.type==='histogramy') { + if(trace.type === 'histogramy') swapXYData(trace); + if(trace.type === 'histogramx' || trace.type === 'histogramy') { trace.type = 'histogram'; } @@ -803,11 +803,11 @@ function cleanData(data, existingData) { function cleanTextPosition(textposition) { var posY = 'middle', posX = 'center'; - if(textposition.indexOf('top')!==-1) posY = 'top'; - else if(textposition.indexOf('bottom')!==-1) posY = 'bottom'; + if(textposition.indexOf('top') !== -1) posY = 'top'; + else if(textposition.indexOf('bottom') !== -1) posY = 'bottom'; - if(textposition.indexOf('left')!==-1) posX = 'left'; - else if(textposition.indexOf('right')!==-1) posX = 'right'; + if(textposition.indexOf('left') !== -1) posX = 'left'; + else if(textposition.indexOf('right') !== -1) posX = 'right'; return posY + ' ' + posX; } @@ -898,7 +898,7 @@ function doCalcdata(gd) { if(!cd[0].t) cd[0].t = {}; cd[0].trace = trace; - Lib.markTime('done with calcdata for '+i); + Lib.markTime('done with calcdata for ' + i); calcdata[i] = cd; } } @@ -1552,18 +1552,18 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { if(typeof astr === 'string') aobj[astr] = val; else if(Lib.isPlainObject(astr)) { aobj = astr; - if(traces===undefined) traces = val; // the 3-arg form + if(traces === undefined) traces = val; // the 3-arg form } else { - console.log('restyle fail',astr,val,traces); + console.log('restyle fail', astr, val, traces); return Promise.reject(); } if(Object.keys(aobj).length) gd.changed = true; - if(isNumeric(traces)) traces=[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 @@ -1572,11 +1572,11 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { // in principle we generally shouldn't need to redo ALL traces... that's // harder though. var recalcAttrs = [ - 'mode','visible','type','orientation','fill', - 'histfunc','histnorm','text', + 'mode', 'visible', 'type', 'orientation', 'fill', + 'histfunc', 'histnorm', 'text', 'x', 'y', 'z', 'a', 'b', 'c', - 'xtype','x0','dx','ytype','y0','dy','xaxis','yaxis', + 'xtype', 'x0', 'dx', 'ytype', 'y0', 'dy', 'xaxis', 'yaxis', 'line.width', 'connectgaps', 'transpose', 'zsmooth', 'showscale', 'marker.showscale', @@ -1584,16 +1584,16 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { 'autocolorscale', 'marker.autocolorscale', 'colorscale', 'marker.colorscale', 'reversescale', 'marker.reversescale', - 'autobinx','nbinsx','xbins','xbins.start','xbins.end','xbins.size', - 'autobiny','nbinsy','ybins','ybins.start','ybins.end','ybins.size', - 'autocontour','ncontours','contours','contours.coloring', - 'error_y','error_y.visible','error_y.value','error_y.type', - 'error_y.traceref','error_y.array','error_y.symmetric', - 'error_y.arrayminus','error_y.valueminus','error_y.tracerefminus', - 'error_x','error_x.visible','error_x.value','error_x.type', - 'error_x.traceref','error_x.array','error_x.symmetric', - 'error_x.arrayminus','error_x.valueminus','error_x.tracerefminus', - 'swapxy','swapxyaxes','orientationaxes', + 'autobinx', 'nbinsx', 'xbins', 'xbins.start', 'xbins.end', 'xbins.size', + 'autobiny', 'nbinsy', 'ybins', 'ybins.start', 'ybins.end', 'ybins.size', + 'autocontour', 'ncontours', 'contours', 'contours.coloring', + 'error_y', 'error_y.visible', 'error_y.value', 'error_y.type', + 'error_y.traceref', 'error_y.array', 'error_y.symmetric', + 'error_y.arrayminus', 'error_y.valueminus', 'error_y.tracerefminus', + 'error_x', 'error_x.visible', 'error_x.value', 'error_x.type', + 'error_x.traceref', 'error_x.array', 'error_x.symmetric', + 'error_x.arrayminus', 'error_x.valueminus', 'error_x.tracerefminus', + 'swapxy', 'swapxyaxes', 'orientationaxes', 'marker.colors', 'values', 'labels', 'label0', 'dlabel', 'sort', 'textinfo', 'textposition', 'textfont.size', 'textfont.family', 'textfont.color', 'insidetextfont.size', 'insidetextfont.family', 'insidetextfont.color', @@ -1615,17 +1615,17 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { // TODO: could we break this out as well? var autorangeAttrs = [ 'marker', 'marker.size', 'textfont', - 'boxpoints','jitter','pointpos','whiskerwidth','boxmean' + 'boxpoints', 'jitter', 'pointpos', 'whiskerwidth', 'boxmean' ]; // replotAttrs attributes need a replot (because different // objects need to be made) but not a recalc var replotAttrs = [ 'zmin', 'zmax', 'zauto', 'marker.cmin', 'marker.cmax', 'marker.cauto', - 'contours.start','contours.end','contours.size', + 'contours.start', 'contours.end', 'contours.size', 'contours.showlines', - 'line','line.smoothing','line.shape', - 'error_y.width','error_x.width','error_x.copy_ystyle', + 'line', 'line.smoothing', 'line.shape', + 'error_y.width', 'error_x.width', 'error_x.copy_ystyle', 'marker.maxdisplayed' ]; // these ones show up in restyle because they make more sense @@ -1641,7 +1641,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { // these ones may alter the axis type // (at least if the first trace is involved) var axtypeAttrs = [ - 'type','x','y','x0','y0','orientation','xaxis','yaxis' + 'type', 'x', 'y', 'x0', 'y0', 'orientation', 'xaxis', 'yaxis' ]; // flags for which kind of update we need to do @@ -1671,7 +1671,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { // for autoranging multiple axes function addToAxlist(axid) { var axName = Plotly.Axes.id2name(axid); - if(axlist.indexOf(axName)===-1) { axlist.push(axName); } + if(axlist.indexOf(axName) === -1) { axlist.push(axName); } } function autorangeAttr(axName) { return 'LAYOUT' + axName + '.autorange'; } function rangeAttr(axName) { return 'LAYOUT' + axName + '.range'; } @@ -1681,9 +1681,9 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { // val=undefined will not set a value, just record what the value was. // val=null will delete the attribute // attr can be an array to set several at once (all to the same val) - function doextra(attr,val,i) { + function doextra(attr, val, i) { if(Array.isArray(attr)) { - attr.forEach(function(a) { doextra(a,val,i); }); + attr.forEach(function(a) { doextra(a, val, i); }); return; } // quit if explicitly setting this elsewhere @@ -1699,10 +1699,10 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { if(!(attr in undoit)) { undoit[attr] = a0(); } - if(undoit[attr][i]===undefined) { - undoit[attr][i]=extraparam.get(); + if(undoit[attr][i] === undefined) { + undoit[attr][i] = extraparam.get(); } - if(val!==undefined) { + if(val !== undefined) { extraparam.set(val); } } @@ -1722,7 +1722,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, @@ -1736,16 +1736,16 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { // set attribute in gd.data undoit[ai] = a0(); - for(i=0; i1 && + else if(p.parts[0].indexOf('legend') !== -1) dolegend = true; + else if(ai.indexOf('title') !== -1) doticks = true; + else if(p.parts[0].indexOf('bgcolor') !== -1) dolayoutstyle = true; + else if(p.parts.length > 1 && Lib.containsAny(p.parts[1], ['tick', 'exponent', 'grid', 'zeroline'])) { doticks = true; } - else if(ai.indexOf('.linewidth')!==-1 && - ai.indexOf('axis')!==-1) { + else if(ai.indexOf('.linewidth') !== -1 && + ai.indexOf('axis') !== -1) { doticks = dolayoutstyle = true; } - else if(p.parts.length>1 && p.parts[1].indexOf('line')!==-1) { + else if(p.parts.length > 1 && p.parts[1].indexOf('line') !== -1) { dolayoutstyle = true; } - else if(p.parts.length>1 && p.parts[1]==='mirror') { + else if(p.parts.length > 1 && p.parts[1] === 'mirror') { doticks = dolayoutstyle = true; } - else if(ai==='margin.pad') { + else if(ai === 'margin.pad') { doticks = dolayoutstyle = true; } - else if(p.parts[0]==='margin' || - p.parts[1]==='autorange' || - p.parts[1]==='rangemode' || - p.parts[1]==='type' || - p.parts[1]==='domain' || + else if(p.parts[0] === 'margin' || + p.parts[1] === 'autorange' || + p.parts[1] === 'rangemode' || + p.parts[1] === 'type' || + p.parts[1] === 'domain' || ai.match(/^(bar|box|font)/)) { docalc = true; } @@ -2353,8 +2353,8 @@ Plotly.relayout = function relayout(gd, astr, val) { * of subplots - scenes - which require scene.updateFx to be called. */ else if(['hovermode', 'dragmode'].indexOf(ai) !== -1) domodebar = true; - else if(['hovermode','dragmode','height', - 'width','autosize'].indexOf(ai)===-1) { + else if(['hovermode', 'dragmode', 'height', + 'width', 'autosize'].indexOf(ai) === -1) { doplot = true; } @@ -2369,7 +2369,7 @@ Plotly.relayout = function relayout(gd, astr, val) { // calculate autosizing - if size hasn't changed, // will remove h&w so we don't need to redraw - if(aobj.autosize) aobj = plotAutoSize(gd,aobj); + if(aobj.autosize) aobj = plotAutoSize(gd, aobj); if(aobj.height || aobj.width || aobj.autosize) docalc = true; @@ -2406,7 +2406,7 @@ Plotly.relayout = function relayout(gd, astr, val) { if(doticks) { seq.push(function() { - Plotly.Axes.doTicks(gd,'redraw'); + Plotly.Axes.doTicks(gd, 'redraw'); drawMainTitle(gd); return Plots.previousPromises(gd); }); @@ -2547,7 +2547,7 @@ function plotAutoSize(gd, aobj) { reservedWidth = reservedMargins.left + reservedMargins.right, reservedHeight = reservedMargins.bottom + reservedMargins.top, gdBB = fullLayout._container.node().getBoundingClientRect(), - factor = 1 - 2*context.frameMargins; + factor = 1 - 2 * context.frameMargins; newWidth = Math.round(factor * (gdBB.width - reservedWidth)); newHeight = Math.round(factor * (gdBB.height - reservedHeight)); @@ -2597,7 +2597,7 @@ function makePlotFramework(gd) { fullLayout._paperdiv = fullLayout._container.selectAll('.svg-container').data([0]); fullLayout._paperdiv.enter().append('div') .classed('svg-container', true) - .style('position','relative'); + .style('position', 'relative'); // Initial autosize if(fullLayout.autosize === 'initial') { @@ -2701,7 +2701,7 @@ function makePlotFramework(gd) { // position and style the containers, make main title var frameWorkDone = Lib.syncOrAsync([ layoutStyles, - function goAxes() { return Plotly.Axes.doTicks(gd,'redraw'); }, + function goAxes() { return Plotly.Axes.doTicks(gd, 'redraw'); }, Fx.init ], gd); @@ -2792,8 +2792,8 @@ function makeCartesianPlotFramwork(gd, subplots) { ya.overlaying = false; } - var mainplot = xa2._id+ya2._id; - if(mainplot!==subplot && subplots.indexOf(mainplot)!==-1) { + var mainplot = xa2._id + ya2._id; + if(mainplot !== subplot && subplots.indexOf(mainplot) !== -1) { plotinfo.mainplot = mainplot; overlays.push(plotinfo); @@ -2906,8 +2906,8 @@ function lsInner(gd) { if(plotinfo.bg) { plotinfo.bg .call(Drawing.setRect, - xa._offset-gs.p, ya._offset-gs.p, - xa._length+2*gs.p, ya._length+2*gs.p) + xa._offset - gs.p, ya._offset - gs.p, + xa._length + 2 * gs.p, ya._length + 2 * gs.p) .call(Color.fill, fullLayout.plot_bgcolor); } @@ -2938,22 +2938,22 @@ function lsInner(gd) { var xlw = Drawing.crispRound(gd, xa.linewidth, 1), ylw = Drawing.crispRound(gd, ya.linewidth, 1), - xp = gs.p+ylw, - xpathPrefix = 'M'+(-xp)+',', - xpathSuffix = 'h'+(xa._length+2*xp), - showfreex = xa.anchor==='free' && - freefinished.indexOf(xa._id)===-1, - freeposx = gs.h*(1-(xa.position||0))+((xlw/2)%1), + xp = gs.p + ylw, + xpathPrefix = 'M' + (-xp) + ',', + xpathSuffix = 'h' + (xa._length + 2 * xp), + showfreex = xa.anchor === 'free' && + freefinished.indexOf(xa._id) === -1, + freeposx = gs.h * (1 - (xa.position||0)) + ((xlw / 2) % 1), showbottom = - (xa.anchor===ya._id && (xa.mirror||xa.side!=='top')) || - xa.mirror==='all' || xa.mirror==='allticks' || - (xa.mirrors && xa.mirrors[ya._id+'bottom']), - bottompos = ya._length+gs.p+xlw/2, + (xa.anchor === ya._id && (xa.mirror || xa.side !== 'top')) || + xa.mirror === 'all' || xa.mirror === 'allticks' || + (xa.mirrors && xa.mirrors[ya._id + 'bottom']), + bottompos = ya._length + gs.p + xlw / 2, showtop = - (xa.anchor===ya._id && (xa.mirror||xa.side==='top')) || - xa.mirror==='all' || xa.mirror==='allticks' || - (xa.mirrors && xa.mirrors[ya._id+'top']), - toppos = -gs.p-xlw/2, + (xa.anchor === ya._id && (xa.mirror || xa.side === 'top')) || + xa.mirror === 'all' || xa.mirror === 'allticks' || + (xa.mirrors && xa.mirrors[ya._id + 'top']), + toppos = -gs.p - xlw / 2, // shorten y axis lines so they don't overlap x axis lines yp = gs.p, @@ -2961,21 +2961,21 @@ function lsInner(gd) { // TODO: this gets more complicated with multiple x and y axes ypbottom = showbottom ? 0 : xlw, yptop = showtop ? 0 : xlw, - ypathSuffix = ','+(-yp-yptop)+ - 'v'+(ya._length+2*yp+yptop+ypbottom), - showfreey = ya.anchor==='free' && - freefinished.indexOf(ya._id)===-1, - freeposy = gs.w*(ya.position||0)+((ylw/2)%1), + ypathSuffix = ',' + (-yp - yptop) + + 'v' + (ya._length + 2 * yp + yptop + ypbottom), + showfreey = ya.anchor === 'free' && + freefinished.indexOf(ya._id) === -1, + freeposy = gs.w * (ya.position||0) + ((ylw / 2) % 1), showleft = - (ya.anchor===xa._id && (ya.mirror||ya.side!=='right')) || - ya.mirror==='all' || ya.mirror==='allticks' || - (ya.mirrors && ya.mirrors[xa._id+'left']), - leftpos = -gs.p-ylw/2, + (ya.anchor === xa._id && (ya.mirror || ya.side !== 'right')) || + ya.mirror === 'all' || ya.mirror === 'allticks' || + (ya.mirrors && ya.mirrors[xa._id + 'left']), + leftpos = -gs.p - ylw / 2, showright = - (ya.anchor===xa._id && (ya.mirror||ya.side==='right')) || - ya.mirror==='all' || ya.mirror==='allticks' || - (ya.mirrors && ya.mirrors[xa._id+'right']), - rightpos = xa._length+gs.p+ylw/2; + (ya.anchor === xa._id && (ya.mirror || ya.side === 'right')) || + ya.mirror === 'all' || ya.mirror === 'allticks' || + (ya.mirrors && ya.mirrors[xa._id + 'right']), + rightpos = xa._length + gs.p + ylw / 2; // save axis line positions for ticks, draggers, etc to reference // each subplot gets an entry: @@ -2986,8 +2986,8 @@ function lsInner(gd) { showtop ? toppos : undefined, showfreex ? freeposx : undefined ]; - if(xa.anchor===ya._id) { - xa._linepositions[subplot][3] = xa.side==='top' ? + if(xa.anchor === ya._id) { + xa._linepositions[subplot][3] = xa.side === 'top' ? toppos : bottompos; } else if(showfreex) { @@ -2999,8 +2999,8 @@ function lsInner(gd) { showright ? rightpos : undefined, showfreey ? freeposy : undefined ]; - if(ya.anchor===xa._id) { - ya._linepositions[subplot][3] = ya.side==='right' ? + if(ya.anchor === xa._id) { + ya._linepositions[subplot][3] = ya.side === 'right' ? rightpos : leftpos; } else if(showfreey) { @@ -3009,47 +3009,47 @@ function lsInner(gd) { // translate all the extra stuff to have the // same origin as the plot area or axes - var origin = 'translate('+xa._offset+','+ya._offset+')', + var origin = 'translate(' + xa._offset + ',' + ya._offset + ')', originx = origin, originy = origin; if(showfreex) { - originx = 'translate('+xa._offset+','+gs.t+')'; + originx = 'translate(' + xa._offset + ',' + gs.t + ')'; toppos += ya._offset - gs.t; bottompos += ya._offset - gs.t; } if(showfreey) { - originy = 'translate('+gs.l+','+ya._offset+')'; + originy = 'translate(' + gs.l + ',' + ya._offset + ')'; leftpos += xa._offset - gs.l; rightpos += xa._offset - gs.l; } plotinfo.xlines .attr('transform', originx) - .attr('d',( - (showbottom ? (xpathPrefix+bottompos+xpathSuffix) : '') + - (showtop ? (xpathPrefix+toppos+xpathSuffix) : '') + - (showfreex ? (xpathPrefix+freeposx+xpathSuffix) : '')) || + .attr('d', ( + (showbottom ? (xpathPrefix + bottompos + xpathSuffix) : '') + + (showtop ? (xpathPrefix + toppos + xpathSuffix) : '') + + (showfreex ? (xpathPrefix + freeposx + xpathSuffix) : '')) || // so it doesn't barf with no lines shown 'M0,0') - .style('stroke-width',xlw+'px') + .style('stroke-width', xlw + 'px') .call(Color.stroke, xa.showline ? xa.linecolor : 'rgba(0,0,0,0)'); plotinfo.ylines .attr('transform', originy) - .attr('d',( - (showleft ? ('M'+leftpos+ypathSuffix) : '') + - (showright ? ('M'+rightpos+ypathSuffix) : '') + - (showfreey ? ('M'+freeposy+ypathSuffix) : '')) || + .attr('d', ( + (showleft ? ('M' + leftpos + ypathSuffix) : '') + + (showright ? ('M' + rightpos + ypathSuffix) : '') + + (showfreey ? ('M' + freeposy + ypathSuffix) : '')) || 'M0,0') - .attr('stroke-width',ylw+'px') - .call(Color.stroke,ya.showline ? + .attr('stroke-width', ylw + 'px') + .call(Color.stroke, ya.showline ? ya.linecolor : 'rgba(0,0,0,0)'); - plotinfo.xaxislayer.attr('transform',originx); - plotinfo.yaxislayer.attr('transform',originy); - plotinfo.gridlayer.attr('transform',origin); - plotinfo.zerolinelayer.attr('transform',origin); - plotinfo.draglayer.attr('transform',origin); + plotinfo.xaxislayer.attr('transform', originx); + plotinfo.yaxislayer.attr('transform', originy); + plotinfo.gridlayer.attr('transform', origin); + plotinfo.zerolinelayer.attr('transform', origin); + plotinfo.draglayer.attr('transform', origin); // mark free axes as displayed, so we don't draw them again if(showfreex) { freefinished.push(xa._id); } diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 5c61c8b42ec..c979449e3f0 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -78,14 +78,14 @@ axes.counterLetter = function(id) { // incorporate a new minimum difference and first tick into // forced -axes.minDtick = function(ax,newDiff,newFirst,allow) { +axes.minDtick = function(ax, newDiff, newFirst, allow) { // doesn't make sense to do forced min dTick on log or category axes, // and the plot itself may decide to cancel (ie non-grouped bars) - if(['log','category'].indexOf(ax.type)!==-1 || !allow) { + if(['log', 'category'].indexOf(ax.type) !== -1 || !allow) { ax._minDtick = 0; } // null means there's nothing there yet - else if(ax._minDtick===null) { + else if(ax._minDtick === null) { ax._minDtick = newDiff; ax._forceTick0 = newFirst; } @@ -93,8 +93,8 @@ axes.minDtick = function(ax,newDiff,newFirst,allow) { // existing minDtick is an integer multiple of newDiff // (within rounding err) // and forceTick0 can be shifted to newFirst - if((ax._minDtick/newDiff+1e-6)%1 < 2e-6 && - (((newFirst-ax._forceTick0)/newDiff%1) + + if((ax._minDtick / newDiff + 1e-6) % 1 < 2e-6 && + (((newFirst - ax._forceTick0) / newDiff % 1) + 1.000001) % 1 < 2e-6) { ax._minDtick = newDiff; ax._forceTick0 = newFirst; @@ -102,8 +102,8 @@ axes.minDtick = function(ax,newDiff,newFirst,allow) { // if the converse is true (newDiff is a multiple of minDtick and // newFirst can be shifted to forceTick0) then do nothing - same // forcing stands. Otherwise, cancel forced minimum - else if((newDiff/ax._minDtick+1e-6)%1 > 2e-6 || - (((newFirst-ax._forceTick0)/ax._minDtick%1) + + else if((newDiff / ax._minDtick + 1e-6) % 1 > 2e-6 || + (((newFirst - ax._forceTick0) / ax._minDtick % 1) + 1.000001) % 1 > 2e-6) { ax._minDtick = 0; } @@ -126,9 +126,9 @@ axes.getAutoRange = function(ax) { maxmax = Math.max(maxmax, ax._max[i].val); } - var j,minpt,maxpt,minbest,maxbest,dp,dv, + var j, minpt, maxpt, minbest, maxbest, dp, dv, mbest = 0, - axReverse = (ax.range && ax.range[1]0 && dp>0 && dv/dp > mbest) { + dv = maxpt.val - minpt.val; + dp = ax._length - minpt.pad - maxpt.pad; + if(dv > 0 && dp > 0 && dv / dp > mbest) { minbest = minpt; maxbest = maxpt; - mbest = dv/dp; + mbest = dv / dp; } } } if(minmin === maxmax) { newRange = axReverse ? - [minmin+1, ax.rangemode!=='normal' ? 0 : minmin-1] : - [ax.rangemode!=='normal' ? 0 : minmin-1, minmin+1]; + [minmin + 1, ax.rangemode !== 'normal' ? 0 : minmin - 1] : + [ax.rangemode !== 'normal' ? 0 : minmin - 1, minmin + 1]; } else if(mbest) { - if(ax.type==='linear' || ax.type==='-') { - if(ax.rangemode==='tozero' && minbest.val>=0) { + if(ax.type === 'linear' || ax.type === '-') { + if(ax.rangemode === 'tozero' && minbest.val >= 0) { minbest = {val: 0, pad: 0}; } - else if(ax.rangemode==='nonnegative') { - if(minbest.val - mbest*minbest.pad<0) { + else if(ax.rangemode === 'nonnegative') { + if(minbest.val - mbest * minbest.pad < 0) { minbest = {val: 0, pad: 0}; } - if(maxbest.val<0) { + if(maxbest.val < 0) { maxbest = {val: 1, pad: 0}; } } // in case it changed again... - mbest = (maxbest.val-minbest.val) / - (ax._length-minbest.pad-maxbest.pad); + mbest = (maxbest.val - minbest.val) / + (ax._length - minbest.pad - maxbest.pad); } newRange = [ - minbest.val - mbest*minbest.pad, - maxbest.val + mbest*maxbest.pad + minbest.val - mbest * minbest.pad, + maxbest.val + mbest * maxbest.pad ]; // don't let axis have zero size if(newRange[0] === newRange[1]) { - newRange = [newRange[0]-1, newRange[0]+1]; + newRange = [newRange[0] - 1, newRange[0] + 1]; } // maintain reversal @@ -254,7 +254,7 @@ axes.saveRangeInitial = function(gd, overwrite) { // (unless one end is overridden by tozero) // tozero: (boolean) make sure to include zero if axis is linear, // and make it a tight bound if possible -var FP_SAFE = Number.MAX_VALUE/2; +var FP_SAFE = Number.MAX_VALUE / 2; axes.expand = function(ax, data, options) { if(!(ax.autorange || ax._needsExpand) || !data) return; if(!ax._min) ax._min = []; @@ -263,52 +263,52 @@ axes.expand = function(ax, data, options) { if(!ax._m) ax.setScale(); var len = data.length, - extrappad = options.padded ? ax._length*0.05 : 0, - tozero = options.tozero && (ax.type==='linear' || ax.type==='-'), + extrappad = options.padded ? ax._length * 0.05 : 0, + tozero = options.tozero && (ax.type === 'linear' || ax.type === '-'), i, j, v, di, dmin, dmax, ppadiplus, ppadiminus, includeThis, vmin, vmax; function getPad(item) { if(Array.isArray(item)) { - return function(i) { return Math.max(Number(item[i]||0),0); }; + return function(i) { return Math.max(Number(item[i]||0), 0); }; } else { - var v = Math.max(Number(item||0),0); + var v = Math.max(Number(item||0), 0); return function() { return v; }; } } - var ppadplus = getPad((ax._m>0 ? + var ppadplus = getPad((ax._m > 0 ? options.ppadplus : options.ppadminus) || options.ppad || 0), - ppadminus = getPad((ax._m>0 ? + ppadminus = getPad((ax._m > 0 ? options.ppadminus : options.ppadplus) || options.ppad || 0), - vpadplus = getPad(options.vpadplus||options.vpad), - vpadminus = getPad(options.vpadminus||options.vpad); + vpadplus = getPad(options.vpadplus || options.vpad), + vpadminus = getPad(options.vpadminus || options.vpad); function addItem(i) { di = data[i]; if(!isNumeric(di)) return; ppadiplus = ppadplus(i) + extrappad; ppadiminus = ppadminus(i) + extrappad; - vmin = di-vpadminus(i); - vmax = di+vpadplus(i); + vmin = di - vpadminus(i); + vmax = di + vpadplus(i); // special case for log axes: if vpad makes this object span // more than an order of mag, clip it to one order. This is so // we don't have non-positive errors or absurdly large lower // range due to rounding errors - if(ax.type==='log' && vmin=ppadiminus) { + if(v.val <= dmin && v.pad >= ppadiminus) { includeThis = false; } - else if(v.val>=dmin && v.pad<=ppadiminus) { - ax._min.splice(j,1); + else if(v.val >= dmin && v.pad <= ppadiminus) { + ax._min.splice(j, 1); j--; } } if(includeThis) { ax._min.push({ val: dmin, - pad: (tozero && dmin===0) ? 0 : ppadiminus + pad: (tozero && dmin === 0) ? 0 : ppadiminus }); } } if(goodNumber(dmax)) { includeThis = true; - for(j=0; j=dmax && v.pad>=ppadiplus) { + if(v.val >= dmax && v.pad >= ppadiplus) { includeThis = false; } - else if(v.val<=dmax && v.pad<=ppadiplus) { - ax._max.splice(j,1); + else if(v.val <= dmax && v.pad <= ppadiplus) { + ax._max.splice(j, 1); j--; } } if(includeThis) { ax._max.push({ val: dmax, - pad: (tozero && dmax===0) ? 0 : ppadiplus + pad: (tozero && dmax === 0) ? 0 : ppadiplus }); } } @@ -359,15 +359,15 @@ axes.expand = function(ax, data, options) { // For efficiency covering monotonic or near-monotonic data, // check a few points at both ends first and then sweep // through the middle - for(i=0; i<6; i++) addItem(i); - for(i=len-1; i>5; i--) addItem(i); + for(i = 0; i < 6; i++) addItem(i); + for(i = len - 1; i > 5; i--) addItem(i); }; -axes.autoBin = function(data,ax,nbins,is2d) { +axes.autoBin = function(data, ax, nbins, is2d) { var datamin = Lib.aggNums(Math.min, null, data), datamax = Lib.aggNums(Math.max, null, data); - if(ax.type==='category') { + if(ax.type === 'category') { return { start: datamin - 0.5, end: datamax + 0.5, @@ -376,7 +376,7 @@ axes.autoBin = function(data,ax,nbins,is2d) { } var size0; - if(nbins) size0 = ((datamax-datamin)/nbins); + if(nbins) size0 = ((datamax - datamin) / nbins); else { // totally auto: scale off std deviation so the highest bin is // somewhat taller than the total number of bins, but don't let @@ -387,14 +387,14 @@ axes.autoBin = function(data,ax,nbins,is2d) { Math.log(distinctData.minDiff) / Math.LN10)), // TODO: there are some date cases where this will fail... minSize = msexp * Lib.roundUp( - distinctData.minDiff/msexp, [0.9, 1.9, 4.9, 9.9], true); + distinctData.minDiff / msexp, [0.9, 1.9, 4.9, 9.9], true); size0 = Math.max(minSize, 2 * Lib.stdev(data) / Math.pow(data.length, is2d ? 0.25 : 0.4)); } // piggyback off autotick code to make "nice" bin sizes var dummyax = { - type: ax.type==='log' ? 'linear' : ax.type, + type: ax.type === 'log' ? 'linear' : ax.type, range: [datamin, datamax] }; axes.autoTicks(dummyax, size0); @@ -404,7 +404,7 @@ axes.autoBin = function(data,ax,nbins,is2d) { function nearEdge(v) { // is a value within 1% of a bin edge? - return (1 + (v-binstart)*100/dummyax.dtick)%100 < 2; + return (1 + (v - binstart) * 100 / dummyax.dtick) % 100 < 2; } // check for too many data points right at the edges of bins @@ -415,21 +415,21 @@ axes.autoBin = function(data,ax,nbins,is2d) { midcount = 0, intcount = 0, blankcount = 0; - for(var i=0; i0 && ax.dtick 0 && ax.dtick < ax._minDtick * 2) { ax.dtick = ax._minDtick; ax.tick0 = ax._forceTick0; } @@ -502,34 +502,34 @@ axes.calcTicks = function calcTicks(ax) { // check for missing tick0 if(!ax.tick0) { - ax.tick0 = (ax.type==='date') ? - new Date(2000,0,1).getTime() : 0; + ax.tick0 = (ax.type === 'date') ? + new Date(2000, 0, 1).getTime() : 0; } // now figure out rounding of tick values autoTickRound(ax); // find the first tick - ax._tmin=axes.tickFirst(ax); + ax._tmin = axes.tickFirst(ax); // check for reversed axis - var axrev = (ax.range[1]=endtick):(x<=endtick); - x = axes.tickIncrement(x,ax.dtick,axrev)) { + (axrev) ? (x >= endtick) : (x <= endtick); + x = axes.tickIncrement(x, ax.dtick, axrev)) { vals.push(x); // prevent infinite loops - if(vals.length>1000) break; + if(vals.length > 1000) break; } // save the last tick as well as first, so we can @@ -666,7 +666,7 @@ axes.autoTicks = function(ax, roughDTick) { ax.dtick = (roughDTick > 0.3) ? 'D2' : 'D1'; } } - else if(ax.type==='category') { + else if(ax.type === 'category') { ax.tick0 = 0; ax.dtick = Math.ceil(Math.max(roughDTick, 1)); } @@ -681,7 +681,7 @@ axes.autoTicks = function(ax, roughDTick) { if(ax.dtick === 0) ax.dtick = 1; // TODO: this is from log axis histograms with autorange off - if(!isNumeric(ax.dtick) && typeof ax.dtick !=='string') { + if(!isNumeric(ax.dtick) && typeof ax.dtick !== 'string') { var olddtick = ax.dtick; ax.dtick = 1; throw 'ax.dtick error: ' + String(olddtick); @@ -728,7 +728,7 @@ function autoTickRound(ax) { } } } - else if(dtick.charAt(0) === 'M') ax._tickround = (dtick.length===2) ? 'm' : 'y'; + else if(dtick.charAt(0) === 'M') ax._tickround = (dtick.length === 2) ? 'm' : 'y'; else ax._tickround = null; } @@ -837,14 +837,14 @@ var yearFormat = d3.time.format('%Y'), // %{n}f where n is the max number of digits // of fractional seconds var fracMatch = /%(\d?)f/g; -function modDateFormat(fmt,x) { +function modDateFormat(fmt, x) { var fm = fmt.match(fracMatch), d = new Date(x); if(fm) { - var digits = Math.min(+fm[1]||6,6), - fracSecs = String((x/1000 % 1) + 2.0000005) - .substr(2,digits).replace(/0+$/,'')||'0'; - return d3.time.format(fmt.replace(fracMatch,fracSecs))(d); + var digits = Math.min(+fm[1] || 6, 6), + fracSecs = String((x / 1000 % 1) + 2.0000005) + .substr(2, digits).replace(/0+$/, '') || '0'; + return d3.time.format(fmt.replace(fracMatch, fracSecs))(d); } else { return d3.time.format(fmt)(d); @@ -879,21 +879,21 @@ axes.tickText = function(ax, x, hover) { var first_or_last; if(showAttr === undefined) return true; - if(hover) return showAttr==='none'; + if(hover) return showAttr === 'none'; first_or_last = { first: ax._tmin, last: ax._tmax }[showAttr]; - return showAttr!=='all' && x!==first_or_last; + return showAttr !== 'all' && x !== first_or_last; } - hideexp = ax.exponentformat!=='none' && isHidden(ax.showexponent) ? 'hide' : ''; + hideexp = ax.exponentformat !== 'none' && isHidden(ax.showexponent) ? 'hide' : ''; - if(ax.type==='date') formatDate(ax, out, hover, extraPrecision); - else if(ax.type==='log') formatLog(ax, out, hover, extraPrecision, hideexp); - else if(ax.type==='category') formatCategory(ax, out); + if(ax.type === 'date') formatDate(ax, out, hover, extraPrecision); + else if(ax.type === 'log') formatLog(ax, out, hover, extraPrecision, hideexp); + else if(ax.type === 'category') formatCategory(ax, out); else formatLinear(ax, out, hover, extraPrecision, hideexp); // add prefix and suffix @@ -926,37 +926,37 @@ function formatDate(ax, out, hover, extraPrecision) { suffix = '', tt; if(hover && ax.hoverformat) { - tt = modDateFormat(ax.hoverformat,x); + tt = modDateFormat(ax.hoverformat, x); } else if(ax.tickformat) { - tt = modDateFormat(ax.tickformat,x); + tt = modDateFormat(ax.tickformat, x); // TODO: potentially hunt for ways to automatically add more // precision to the hover text? } else { if(extraPrecision) { - if(isNumeric(tr)) tr+=2; + if(isNumeric(tr)) tr += 2; 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); + if(tr === 'y') tt = yearFormat(d); + else if(tr === 'm') tt = monthFormat(d); else { - if(x===ax._tmin && !hover) { - suffix = '
'+yearFormat(d); + if(x === ax._tmin && !hover) { + suffix = '
' + yearFormat(d); } - if(tr==='d') tt = dayFormat(d); - else if(tr==='H') tt = hourFormat(d); + if(tr === 'd') tt = dayFormat(d); + else if(tr === 'H') tt = hourFormat(d); else { - if(x===ax._tmin && !hover) { - suffix = '
'+dayFormat(d)+', '+yearFormat(d); + if(x === ax._tmin && !hover) { + suffix = '
' + dayFormat(d) + ', ' + yearFormat(d); } tt = minuteFormat(d); - if(tr!=='M') { + if(tr !== 'M') { tt += secondFormat(d); - if(tr!=='S') { - tt += numFormat(mod(x/1000,1),ax,'none',hover) + if(tr !== 'S') { + tt += numFormat(mod(x / 1000, 1), ax, 'none', hover) .substr(1); } } @@ -969,13 +969,13 @@ function formatDate(ax, out, hover, extraPrecision) { function formatLog(ax, out, hover, extraPrecision, hideexp) { var dtick = ax.dtick, x = out.x; - if(extraPrecision && ((typeof dtick !== 'string') || dtick.charAt(0)!=='L')) dtick = 'L3'; + if(extraPrecision && ((typeof dtick !== 'string') || dtick.charAt(0) !== 'L')) dtick = 'L3'; if(ax.tickformat || (typeof dtick === 'string' && dtick.charAt(0) === 'L')) { out.text = numFormat(Math.pow(10, x), ax, hideexp, extraPrecision); } - else if(isNumeric(dtick)||((dtick.charAt(0)==='D')&&(mod(x+0.01,1)<0.1))) { - if(['e','E','power'].indexOf(ax.exponentformat)!==-1) { + else if(isNumeric(dtick) || ((dtick.charAt(0) === 'D') && (mod(x + 0.01, 1) < 0.1))) { + if(['e', 'E', 'power'].indexOf(ax.exponentformat) !== -1) { var p = Math.round(x); if(p === 0) out.text = 1; else if(p === 1) out.text = '10'; @@ -985,9 +985,9 @@ function formatLog(ax, out, hover, extraPrecision, hideexp) { out.fontSize *= 1.25; } else { - out.text = numFormat(Math.pow(10,x), ax,'','fakehover'); - if(dtick==='D1' && ax._id.charAt(0)==='y') { - out.dy -= out.fontSize/6; + out.text = numFormat(Math.pow(10, x), ax, '', 'fakehover'); + if(dtick === 'D1' && ax._id.charAt(0) === 'y') { + out.dy -= out.fontSize / 6; } } } @@ -998,7 +998,7 @@ function formatLog(ax, out, hover, extraPrecision, hideexp) { else throw 'unrecognized dtick ' + String(dtick); // if 9's are printed on log scale, move the 10's away a bit - if(ax.dtick==='D1') { + if(ax.dtick === 'D1') { var firstChar = String(out.text).charAt(0); if(firstChar === '0' || firstChar === '1') { if(ax._id.charAt(0) === 'y') { @@ -1023,7 +1023,7 @@ function formatLinear(ax, out, hover, extraPrecision, hideexp) { // don't add an exponent to zero if we're showing all exponents // so the only reason you'd show an exponent on zero is if it's the // ONLY tick to get an exponent (first or last) - if(ax.showexponent==='all' && Math.abs(out.x/ax.dtick)<1e-6) { + if(ax.showexponent === 'all' && Math.abs(out.x / ax.dtick) < 1e-6) { hideexp = 'hide'; } out.text = numFormat(out.x, ax, hideexp, extraPrecision); @@ -1049,7 +1049,7 @@ function numFormat(v, ax, fmtoverride, hover) { // make a dummy axis obj to get the auto rounding and exponent var ah = { exponentformat: ax.exponentformat, - dtick: ax.showexponent==='none' ? ax.dtick : + dtick: ax.showexponent === 'none' ? ax.dtick : (isNumeric(v) ? Math.abs(v) || 1 : 1), // if not showing any exponents, don't change the exponent // from what we calculate @@ -1061,7 +1061,7 @@ function numFormat(v, ax, fmtoverride, hover) { if(ax.hoverformat) tickformat = ax.hoverformat; } - if(tickformat) return d3.format(tickformat)(v).replace(/-/g,'\u2212'); + if(tickformat) return d3.format(tickformat)(v).replace(/-/g, '\u2212'); // 'epsilon' - rounding increment var e = Math.pow(10, -tickRound) / 2; @@ -1224,7 +1224,7 @@ axes.getSubplots = function(gd, ax) { bMatch = b.match(spMatch); if(aMatch[1] === bMatch[1]) { - return +(aMatch[2]||1) - (bMatch[2]||1); + return +(aMatch[2] || 1) - (bMatch[2] || 1); } return +(aMatch[1]||0) - (bMatch[1]||0); @@ -1264,7 +1264,7 @@ axes.makeClipPaths = function(gd) { for(i = 0; i < xaList.length; i++) { clipList.push({x: xaList[i], y: fullHeight}); for(j = 0; j < yaList.length; j++) { - if(i===0) clipList.push({x: fullWidth, y: yaList[j]}); + if(i === 0) clipList.push({x: fullWidth, y: yaList[j]}); clipList.push({x: xaList[i], y: yaList[j]}); } } @@ -1434,13 +1434,13 @@ axes.doTicks = function(gd, axid, skipTitle) { function drawTicks(container, tickpath) { var ticks = container.selectAll('path.' + tcls) - .data(ax.ticks==='inside' ? valsClipped : vals, datafn); + .data(ax.ticks === 'inside' ? valsClipped : vals, datafn); if(tickpath && ax.ticks) { ticks.enter().append('path').classed(tcls, 1).classed('ticks', 1) .classed('crisp', 1) .call(Color.stroke, ax.tickcolor) .style('stroke-width', tickWidth + 'px') - .attr('d',tickpath); + .attr('d', tickpath); ticks.attr('transform', transfn); ticks.exit().remove(); } @@ -1484,7 +1484,7 @@ axes.doTicks = function(gd, axid, skipTitle) { if(isNumeric(angle) && Math.abs(angle) === 90) { return 'middle'; } - return axside==='right' ? 'start' : 'end'; + return axside === 'right' ? 'start' : 'end'; }; } var maxFontSize = 0, @@ -1524,7 +1524,7 @@ axes.doTicks = function(gd, axid, skipTitle) { maxFontSize = Math.max(maxFontSize, d.fontSize); }); - function positionLabels(s,angle) { + function positionLabels(s, angle) { s.each(function(d) { var anchor = labelanchor(angle); var thisLabel = d3.select(this), @@ -1562,7 +1562,7 @@ axes.doTicks = function(gd, axid, skipTitle) { // do this without waiting, using the last calculated angle to // minimize flicker, then do it again when we know all labels are // there, putting back the prescribed angle to check for overlaps. - positionLabels(tickLabels,ax._lastangle || ax.tickangle); + positionLabels(tickLabels, ax._lastangle || ax.tickangle); function allLabelsReady() { return labelsReady.length && Promise.all(labelsReady); @@ -1574,7 +1574,7 @@ axes.doTicks = function(gd, axid, skipTitle) { // check for auto-angling if x labels overlap // don't auto-angle at all for log axes with // base and digit format - if(axletter==='x' && !isNumeric(ax.tickangle) && + if(axletter === 'x' && !isNumeric(ax.tickangle) && (ax.type !== 'log' || String(ax.dtick).charAt(0) !== 'D')) { var lbbArray = []; tickLabels.each(function(d) { @@ -1720,7 +1720,7 @@ axes.doTicks = function(gd, axid, skipTitle) { zlcontainer = plotinfo.zerolinelayer, gridvals = plotinfo['hidegrid' + axletter] ? [] : valsClipped, gridpath = ax._gridpath || - 'M0,0' + ((axletter==='x') ? 'v' : 'h') + counteraxis._length, + 'M0,0' + ((axletter === 'x') ? 'v' : 'h') + counteraxis._length, grid = gridcontainer.selectAll('path.' + gcls) .data((ax.showgrid === false) ? [] : gridvals, datafn); grid.enter().append('path').classed(gcls, 1) @@ -1781,7 +1781,7 @@ axes.doTicks = function(gd, axid, skipTitle) { var container = plotinfo[axletter + 'axislayer'], // [bottom or left, top or right, free, main] - linepositions = ax._linepositions[subplot]||[], + linepositions = ax._linepositions[subplot] || [], counteraxis = plotinfo[counterLetter](), mainSubplot = counteraxis._id === ax.anchor, ticksides = [false, false, false], @@ -1856,7 +1856,7 @@ function makeAxisGroups(gd, traces) { var group0 = groups[groupsi[0]], groupj; - if(groupsi.length>1) { + if(groupsi.length > 1) { for(j = 1; j < groupsi.length; j++) { groupj = groups[groupsi[j]]; mergeAxisGroups(group0.x, groupj.x); @@ -1935,7 +1935,7 @@ function swapAxisGroup(gd, xIds, yIds) { var ann = gd._fullLayout.annotations[i]; if(xIds.indexOf(ann.xref) !== -1 && yIds.indexOf(ann.yref) !== -1) { - Lib.swapAttrs(layout.annotations[i],['?']); + Lib.swapAttrs(layout.annotations[i], ['?']); } } } @@ -1968,4 +1968,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 14364cbfdb3..080e9eb9355 100644 --- a/src/plots/cartesian/axis_defaults.js +++ b/src/plots/cartesian/axis_defaults.js @@ -162,7 +162,7 @@ function setAutoType(ax, data) { // first check for histograms, as the count direction // should always default to a linear axis - if(d0.type==='histogram' && + if(d0.type === 'histogram' && axLetter === {v: 'y', h: 'x'}[d0.orientation || 'v']) { ax.type = 'linear'; return; @@ -188,7 +188,7 @@ function setAutoType(ax, data) { ax.type = autoType(boxPositions); } else { - ax.type = autoType(d0[axLetter] || [d0[axLetter+'0']]); + ax.type = autoType(d0[axLetter] || [d0[axLetter + '0']]); } } diff --git a/src/plots/cartesian/axis_ids.js b/src/plots/cartesian/axis_ids.js index f2dba39a961..58d3a6330c1 100644 --- a/src/plots/cartesian/axis_ids.js +++ b/src/plots/cartesian/axis_ids.js @@ -35,7 +35,7 @@ exports.cleanId = function cleanId(id, axLetter) { if(!id.match(constants.AX_ID_PATTERN)) return; if(axLetter && id.charAt(0) !== axLetter) return; - var axNum = id.substr(1).replace(/^0+/,''); + var axNum = id.substr(1).replace(/^0+/, ''); if(axNum === '1') axNum = ''; return id.charAt(0) + axNum; }; @@ -94,8 +94,8 @@ exports.listIds = function(gd, axletter) { exports.getFromId = function(gd, id, type) { var fullLayout = gd._fullLayout; - if(type === 'x') id = id.replace(/y[0-9]*/,''); - else if(type === 'y') id = id.replace(/x[0-9]*/,''); + if(type === 'x') id = id.replace(/y[0-9]*/, ''); + else if(type === 'y') id = id.replace(/x[0-9]*/, ''); return fullLayout[exports.id2name(id)]; }; diff --git a/src/plots/cartesian/dragbox.js b/src/plots/cartesian/dragbox.js index 6dc13c6ad01..cccf64d56ba 100644 --- a/src/plots/cartesian/dragbox.js +++ b/src/plots/cartesian/dragbox.js @@ -81,7 +81,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { .style({fill: 'transparent', 'stroke-width': 0}) .attr('data-subplot', plotinfo.id); dragger3.call(Drawing.setRect, x, y, w, h) - .call(setCursor,cursor); + .call(setCursor, cursor); var dragger = dragger3.node(); // still need to make the element if the axes are disabled @@ -160,17 +160,17 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { lum = gd._hmpixcount ? (gd._hmlumcount / gd._hmpixcount) : tinycolor(gd._fullLayout.plot_bgcolor).getLuminance(); - path0 = 'M0,0H'+pw+'V'+ph+'H0V0'; + path0 = 'M0,0H' + pw + 'V' + ph + 'H0V0'; dimmed = false; zoomMode = 'xy'; zb = zoomlayer.append('path') .attr('class', 'zoombox') .style({ - 'fill': lum>0.2 ? 'rgba(0,0,0,0)' : 'rgba(255,255,255,0)', + 'fill': lum > 0.2 ? 'rgba(0,0,0,0)' : 'rgba(255,255,255,0)', 'stroke-width': 0 }) - .attr('transform','translate(' + xs + ', ' + ys + ')') + .attr('transform', 'translate(' + xs + ', ' + ys + ')') .attr('d', path0 + 'Z'); corners = zoomlayer.append('path') @@ -181,8 +181,8 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { 'stroke-width': 1, opacity: 0 }) - .attr('transform','translate(' + xs + ', ' + ys + ')') - .attr('d','M0,0Z'); + .attr('transform', 'translate(' + xs + ', ' + ys + ')') + .attr('d', 'M0,0Z'); clearSelect(); for(var i = 0; i < allaxes.length; i++) forceNumbers(allaxes[i].range); @@ -240,14 +240,14 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { else { zoomMode = 'xy'; corners.attr('d', - 'M'+(box.l-3.5)+','+(box.t-0.5+clen)+'h3v'+(-clen)+ - 'h'+clen+'v-3h-'+(clen+3)+'ZM'+ - (box.r+3.5)+','+(box.t-0.5+clen)+'h-3v'+(-clen)+ - 'h'+(-clen)+'v-3h'+(clen+3)+'ZM'+ - (box.r+3.5)+','+(box.b+0.5-clen)+'h-3v'+clen+ - 'h'+(-clen)+'v3h'+(clen+3)+'ZM'+ - (box.l-3.5)+','+(box.b+0.5-clen)+'h3v'+clen+ - 'h'+clen+'v3h-'+(clen+3)+'Z'); + 'M' + (box.l - 3.5) + ',' + (box.t - 0.5 + clen) + 'h3v' + (-clen) + + 'h' + clen + 'v-3h-' + (clen + 3) + 'ZM' + + (box.r + 3.5) + ',' + (box.t - 0.5 + clen) + 'h-3v' + (-clen) + + 'h' + (-clen) + 'v-3h' + (clen + 3) + 'ZM' + + (box.r + 3.5) + ',' + (box.b + 0.5 - clen) + 'h-3v' + clen + + 'h' + (-clen) + 'v3h' + (clen + 3) + 'ZM' + + (box.l - 3.5) + ',' + (box.b + 0.5 - clen) + 'h3v' + clen + + 'h' + clen + 'v3h-' + (clen + 3) + 'Z'); } box.w = box.r - box.l; box.h = box.b - box.t; @@ -255,15 +255,15 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { // Not sure about the addition of window.scrollX/Y... // seems to work but doesn't seem robust. zb.attr('d', - path0+'M'+(box.l)+','+(box.t)+'v'+(box.h)+ - 'h'+(box.w)+'v-'+(box.h)+'h-'+(box.w)+'Z'); + path0 + 'M' + (box.l) + ',' + (box.t) + 'v' + (box.h) + + 'h' + (box.w) + 'v-' + (box.h) + 'h-' + (box.w) + 'Z'); if(!dimmed) { zb.transition() - .style('fill', lum>0.2 ? 'rgba(0,0,0,0.4)' : + .style('fill', lum > 0.2 ? 'rgba(0,0,0,0.4)' : 'rgba(255,255,255,0.3)') .duration(200); corners.transition() - .style('opacity',1) + .style('opacity', 1) .duration(200); dimmed = true; } @@ -300,7 +300,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { dragTail(zoomMode); if(SHOWZOOMOUTTIP && gd.data && gd._context.showTips) { - Lib.notifier('Double-click to
zoom back out','long'); + Lib.notifier('Double-click to
zoom back out', 'long'); SHOWZOOMOUTTIP = false; } } @@ -311,7 +311,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { else if(numClicks === 2 && !singleEnd) doubleClick(); else if(numClicks === 1 && singleEnd) { var ax = ns ? ya[0] : xa[0], - end = (ns==='s' || ew==='w') ? 0 : 1, + end = (ns === 's' || ew === 'w') ? 0 : 1, attrStr = ax._name + '.range[' + end + ']', initialText = getEndText(ax, end), hAlign = 'left', @@ -335,7 +335,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { verticalAlign: vAlign }) .on('edit', function(text) { - var v = ax.type==='category' ? ax.c2l(text) : ax.d2l(text); + var v = ax.type === 'category' ? ax.c2l(text) : ax.d2l(text); if(v !== undefined) { Plotly.relayout(gd, attrStr, v); } @@ -344,7 +344,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { } // scroll zoom, on all draggers except corners - var scrollViewBox = [0,0,pw,ph], + var scrollViewBox = [0, 0, pw, ph], // wait a little after scrolling before redrawing redrawTimer = null, REDRAWDELAY = 300, @@ -362,8 +362,8 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { // if the plot has scrollbars (more than a tiny excess) // disable scrollzoom too. - if(pc.scrollHeight-pc.clientHeight>10 || - pc.scrollWidth-pc.clientWidth>10) { + if(pc.scrollHeight - pc.clientHeight > 10 || + pc.scrollWidth - pc.clientWidth > 10) { return; } @@ -380,9 +380,9 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { gbb = mainplot.draglayer.select('.nsewdrag') .node().getBoundingClientRect(), xfrac = (e.clientX - gbb.left) / gbb.width, - vbx0 = scrollViewBox[0] + scrollViewBox[2]*xfrac, - yfrac = (gbb.bottom - e.clientY)/gbb.height, - vby0 = scrollViewBox[1]+scrollViewBox[3]*(1-yfrac), + vbx0 = scrollViewBox[0] + scrollViewBox[2] * xfrac, + yfrac = (gbb.bottom - e.clientY) / gbb.height, + vby0 = scrollViewBox[1] + scrollViewBox[3] * (1 - yfrac), i; function zoomWheelOneAxis(ax, centerFraction, zoom) { @@ -406,12 +406,12 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { // viewbox redraw at first updateSubplots(scrollViewBox); - ticksAndAnnotations(ns,ew); + ticksAndAnnotations(ns, ew); // then replot after a delay to make sure // no more scrolling is coming redrawTimer = setTimeout(function() { - scrollViewBox = [0,0,pw,ph]; + scrollViewBox = [0, 0, pw, ph]; dragTail(); }, REDRAWDELAY); @@ -419,14 +419,14 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { } // everything but the corners gets wheel zoom - if(ns.length*ew.length!==1) { + if(ns.length * ew.length !== 1) { // still seems to be some confusion about onwheel vs onmousewheel... - if(dragger.onwheel!==undefined) dragger.onwheel = zoomWheel; - else if(dragger.onmousewheel!==undefined) dragger.onmousewheel = zoomWheel; + if(dragger.onwheel !== undefined) dragger.onwheel = zoomWheel; + else if(dragger.onmousewheel !== undefined) dragger.onmousewheel = zoomWheel; } // plotDrag: move the plot in response to a drag - function plotDrag(dx,dy) { + function plotDrag(dx, dy) { function dragAxList(axList, pix) { for(var i = 0; i < axList.length; i++) { var axi = axList[i]; @@ -450,8 +450,8 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { // d<0 is expanding (cursor is off the plot, axis end moves // nonlinearly so you can expand far) function dZoom(d) { - return 1-((d>=0) ? Math.min(d,0.9) : - 1/(1/Math.max(d,-0.3)+3.222)); + return 1 - ((d >= 0) ? Math.min(d, 0.9) : + 1 / (1 / Math.max(d, -0.3) + 3.222)); } // dz: set a new value for one end (0 or 1) of an axis array ax, @@ -580,17 +580,17 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { // through relayout - this lets relayout manage undo/redo for(var i = 0; i < allaxes.length; i++) { var axi = allaxes[i]; - if(zoommode && zoommode.indexOf(axi._id.charAt(0))===-1) { + if(zoommode && zoommode.indexOf(axi._id.charAt(0)) === -1) { continue; } - if(axi._r[0] !== axi.range[0]) attrs[axi._name+'.range[0]'] = axi.range[0]; - if(axi._r[1] !== axi.range[1]) attrs[axi._name+'.range[1]'] = axi.range[1]; + if(axi._r[0] !== axi.range[0]) attrs[axi._name + '.range[0]'] = axi.range[0]; + if(axi._r[1] !== axi.range[1]) attrs[axi._name + '.range[1]'] = axi.range[1]; - axi.range=axi._r.slice(); + axi.range = axi._r.slice(); } - updateSubplots([0,0,pw,ph]); - Plotly.relayout(gd,attrs); + updateSubplots([0, 0, pw, ph]); + Plotly.relayout(gd, attrs); } // updateSubplots - find all plot viewboxes that should be @@ -604,8 +604,8 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { var subplot = plotinfos[subplots[i]], xa2 = subplot.x(), ya2 = subplot.y(), - editX = ew && xa.indexOf(xa2)!==-1 && !xa2.fixedrange, - editY = ns && ya.indexOf(ya2)!==-1 && !ya2.fixedrange; + editX = ew && xa.indexOf(xa2) !== -1 && !xa2.fixedrange, + editY = ns && ya.indexOf(ya2) !== -1 && !ya2.fixedrange; if(editX || editY) { // plot requires offset position and @@ -636,14 +636,14 @@ function getEndText(ax, end) { if(ax.type === 'date') { return Lib.ms2DateTime(initialVal, diff); } - else if(ax.type==='log') { + else if(ax.type === 'log') { dig = Math.ceil(Math.max(0, -Math.log(diff) / Math.LN10)) + 3; return d3.format('.' + dig + 'g')(Math.pow(10, initialVal)); } else { // linear numeric (or category... but just show numbers here) dig = Math.floor(Math.log(Math.abs(initialVal)) / Math.LN10) - Math.floor(Math.log(diff) / Math.LN10) + 4; - return d3.format('.'+String(dig)+'g')(initialVal); + return d3.format('.' + String(dig) + 'g')(initialVal); } } diff --git a/src/plots/cartesian/graph_interact.js b/src/plots/cartesian/graph_interact.js index d181c0d2ad7..02169649378 100644 --- a/src/plots/cartesian/graph_interact.js +++ b/src/plots/cartesian/graph_interact.js @@ -91,15 +91,15 @@ fx.init = function(gd) { if(!fullLayout._has('cartesian') || gd._context.staticPlot) return; - var subplots = Object.keys(fullLayout._plots || {}).sort(function(a,b) { + var subplots = Object.keys(fullLayout._plots || {}).sort(function(a, b) { // sort overlays last, then by x axis number, then y axis number if((fullLayout._plots[a].mainplot && true) === (fullLayout._plots[b].mainplot && true)) { var aParts = a.split('y'), bParts = b.split('y'); - return (aParts[0]===bParts[0]) ? - (Number(aParts[1]||1) - Number(bParts[1]||1)) : - (Number(aParts[0]||1) - Number(bParts[0]||1)); + return (aParts[0] === bParts[0]) ? + (Number(aParts[1] || 1) - Number(bParts[1] || 1)) : + (Number(aParts[0] || 1) - Number(bParts[0] || 1)); } return fullLayout._plots[a].mainplot ? 1 : -1; }); @@ -113,14 +113,14 @@ fx.init = function(gd) { ya = plotinfo.y(), // the y position of the main x axis line - y0 = (xa._linepositions[subplot]||[])[3], + y0 = (xa._linepositions[subplot] || [])[3], // the x position of the main y axis line - x0 = (ya._linepositions[subplot]||[])[3]; + x0 = (ya._linepositions[subplot] || [])[3]; var DRAGGERSIZE = constants.DRAGGERSIZE; - if(isNumeric(y0) && xa.side==='top') y0 -= DRAGGERSIZE; - if(isNumeric(x0) && ya.side!=='right') x0 -= DRAGGERSIZE; + if(isNumeric(y0) && xa.side === 'top') y0 -= DRAGGERSIZE; + if(isNumeric(x0) && ya.side !== 'right') x0 -= DRAGGERSIZE; // main and corner draggers need not be repeated for // overlaid subplots - these draggers drag them all @@ -128,7 +128,7 @@ fx.init = function(gd) { // main dragger goes over the grids and data, so we use its // mousemove events for all data hover effects var maindrag = dragBox(gd, plotinfo, 0, 0, - xa._length, ya._length,'ns','ew'); + xa._length, ya._length, 'ns', 'ew'); maindrag.onmousemove = function(evt) { fx.hover(gd, evt, subplot); @@ -167,23 +167,23 @@ fx.init = function(gd) { // x axis draggers - if you have overlaid plots, // these drag each axis separately if(isNumeric(y0)) { - if(xa.anchor==='free') y0 -= fullLayout._size.h*(1-ya.domain[1]); - dragBox(gd, plotinfo, xa._length*0.1, y0, - xa._length*0.8, DRAGGERSIZE, '', 'ew'); + if(xa.anchor === 'free') y0 -= fullLayout._size.h * (1 - ya.domain[1]); + dragBox(gd, plotinfo, xa._length * 0.1, y0, + xa._length * 0.8, DRAGGERSIZE, '', 'ew'); dragBox(gd, plotinfo, 0, y0, - xa._length*0.1, DRAGGERSIZE, '', 'w'); - dragBox(gd, plotinfo, xa._length*0.9, y0, - xa._length*0.1, DRAGGERSIZE, '', 'e'); + xa._length * 0.1, DRAGGERSIZE, '', 'w'); + dragBox(gd, plotinfo, xa._length * 0.9, y0, + xa._length * 0.1, DRAGGERSIZE, '', 'e'); } // y axis draggers if(isNumeric(x0)) { - if(ya.anchor==='free') x0 -= fullLayout._size.w*xa.domain[0]; - dragBox(gd, plotinfo, x0, ya._length*0.1, - DRAGGERSIZE, ya._length*0.8, 'ns', ''); - dragBox(gd, plotinfo, x0, ya._length*0.9, - DRAGGERSIZE, ya._length*0.1, 's', ''); + if(ya.anchor === 'free') x0 -= fullLayout._size.w * xa.domain[0]; + dragBox(gd, plotinfo, x0, ya._length * 0.1, + DRAGGERSIZE, ya._length * 0.8, 'ns', ''); + dragBox(gd, plotinfo, x0, ya._length * 0.9, + DRAGGERSIZE, ya._length * 0.1, 's', ''); dragBox(gd, plotinfo, x0, 0, - DRAGGERSIZE, ya._length*0.1, 'n', ''); + DRAGGERSIZE, ya._length * 0.1, 'n', ''); } }); @@ -211,10 +211,10 @@ fx.init = function(gd) { // hover labels for multiple horizontal bars get tilted by some angle, // then need to be offset differently if they overlap var YANGLE = constants.YANGLE, - YA_RADIANS = Math.PI*YANGLE/180, + YA_RADIANS = Math.PI * YANGLE / 180, // expansion of projected height - YFACTOR = 1/Math.sin(YA_RADIANS), + YFACTOR = 1 / Math.sin(YA_RADIANS), // to make the appropriate post-rotation x offset, // you need both x and y offsets @@ -224,13 +224,13 @@ var YANGLE = constants.YANGLE, // convenience functions for mapping all relevant axes function flat(subplots, v) { var out = []; - for(var i=subplots.length; i>0; i--) out.push(v); + for(var i = subplots.length; i > 0; i--) out.push(v); return out; } function p2c(axArray, v) { var out = []; - for(var i=0; i gd._lastHoverTime + constants.HOVERMINTIME) { - hover(gd,evt,subplot); + hover(gd, evt, subplot); gd._lastHoverTime = Date.now(); return; } // Queue up the next hover for 100ms from now (if no further events) gd._hoverTimer = setTimeout(function() { - hover(gd,evt,subplot); + hover(gd, evt, subplot); gd._lastHoverTime = Date.now(); gd._hoverTimer = undefined; }, constants.HOVERMINTIME); @@ -332,7 +332,7 @@ function hover(gd, evt, subplot) { }), hovermode = evt.hovermode || fullLayout.hovermode; - if(['x','y','closest'].indexOf(hovermode)===-1 || !gd.calcdata || + if(['x', 'y', 'closest'].indexOf(hovermode) === -1 || !gd.calcdata || gd.querySelector('.zoombox') || gd._dragging) { return dragElement.unhoverRaw(gd, evt); } @@ -369,16 +369,16 @@ function hover(gd, evt, subplot) { if(Array.isArray(evt)) { // user specified an array of points to highlight hovermode = 'array'; - for(itemnum = 0; itemnumdbb.width || ypx<0 || ypx>dbb.height) { - return dragElement.unhoverRaw(gd,evt); + if(xpx < 0 || xpx > dbb.width || ypx < 0 || ypx > dbb.height) { + return dragElement.unhoverRaw(gd, evt); } } else { if('xpx' in evt) xpx = evt.xpx; - else xpx = xaArray[0]._length/2; + else xpx = xaArray[0]._length / 2; if('ypx' in evt) ypx = evt.ypx; - else ypx = yaArray[0]._length/2; + else ypx = yaArray[0]._length / 2; } if('xval' in evt) xvalArray = flat(subplots, evt.xval); @@ -436,7 +436,7 @@ function hover(gd, evt, subplot) { // find the closest point in each trace // this is minimum dx and/or dy, depending on mode // and the pixel position for the label (labelXpx, labelYpx) - for(curvenum = 0; curvenum1 || trace.hoverinfo.indexOf('name')!==-1) ? trace.name : undefined, + name: (gd.data.length > 1 || trace.hoverinfo.indexOf('name') !== -1) ? trace.name : undefined, // point properties - override all of these index: false, // point index in trace - only used by plotly.js hoverdata consumers distance: Math.min(distance, constants.MAXDIST), // pixel distance or pseudo-distance @@ -474,7 +474,7 @@ function hover(gd, evt, subplot) { // for a highlighting array, figure out what // we're searching for with this element - if(mode==='array') { + if(mode === 'array') { var selection = evt[curvenum]; if('pointNumber' in selection) { pointData.index = selection.pointNumber; @@ -502,7 +502,7 @@ function hover(gd, evt, subplot) { var newPoints = trace._module.hoverPoints(pointData, xval, yval, mode); if(newPoints) { var newPoint; - for(var newPointNum=0; newPointNum closedataPreviousLength) { + if(hovermode === 'closest' && hoverData.length > closedataPreviousLength) { hoverData.splice(0, closedataPreviousLength); distance = hoverData[0].distance; } @@ -524,11 +524,11 @@ function hover(gd, evt, subplot) { } // nothing left: remove all labels and quit - if(hoverData.length===0) return dragElement.unhoverRaw(gd,evt); + if(hoverData.length === 0) return dragElement.unhoverRaw(gd, evt); // if there's more than one horz bar trace, // rotate the labels so they don't overlap - var rotateLabels = hovermode==='y' && searchData.length>1; + var rotateLabels = hovermode === 'y' && searchData.length > 1; hoverData.sort(function(d1, d2) { return d1.distance - d2.distance; }); @@ -556,7 +556,7 @@ function hover(gd, evt, subplot) { // pull out just the data that's useful to // other people and send it to the event - for(itemnum = 0; itemnum=0 && pointData.index= 0 && pointData.index < cd.length) { pointData.distance = 0; } else pointData.index = false; @@ -616,7 +616,7 @@ fx.getClosest = function(cd, distfn, pointData) { // this is the longest loop... if this bogs down, we may need // to create pre-sorted data (by x or y), not sure how to // do this for 'closest' - for(var i=0; i128 ? + contrastColor = tinycolor(traceColor).getBrightness() > 128 ? '#000' : Color.background; - if(d.name && d.zLabelVal===undefined) { + if(d.name && d.zLabelVal === undefined) { // strip out any html elements from d.name (if it exists at all) // Note that this isn't an XSS vector, only because it never gets // attached to the DOM var tmp = document.createElement('p'); tmp.innerHTML = d.name; - name = tmp.textContent||''; + name = tmp.textContent || ''; - if(name.length>15) name = name.substr(0,12)+'...'; + if(name.length > 15) name = name.substr(0, 12) + '...'; } // used by other modules (initially just ternary) that @@ -942,21 +942,21 @@ function createHoverText(hoverData, opts) { // the rest of this will still apply, so such modules // can still put things in (x|y|z)Label, text, and name // and hoverinfo will still determine their visibility - if(d.extraText!==undefined) text += d.extraText; + if(d.extraText !== undefined) text += d.extraText; - if(d.zLabel!==undefined) { - if(d.xLabel!==undefined) text += 'x: ' + d.xLabel + '
'; - if(d.yLabel!==undefined) text += 'y: ' + d.yLabel + '
'; + if(d.zLabel !== undefined) { + if(d.xLabel !== undefined) text += 'x: ' + d.xLabel + '
'; + if(d.yLabel !== undefined) text += 'y: ' + d.yLabel + '
'; text += (text ? 'z: ' : '') + d.zLabel; } - else if(showCommonLabel && d[hovermode+'Label']===t0) { - text = d[(hovermode==='x' ? 'y' : 'x') + 'Label'] || ''; + else if(showCommonLabel && d[hovermode + 'Label'] === t0) { + text = d[(hovermode === 'x' ? 'y' : 'x') + 'Label'] || ''; } - else if(d.xLabel===undefined) { - if(d.yLabel!==undefined) text = d.yLabel; + else if(d.xLabel === undefined) { + if(d.yLabel !== undefined) text = d.yLabel; } - else if(d.yLabel===undefined) text = d.xLabel; - else text = '('+d.xLabel+', '+d.yLabel+')'; + else if(d.yLabel === undefined) text = d.xLabel; + else text = '(' + d.xLabel + ', ' + d.yLabel + ')'; if(d.text && !Array.isArray(d.text)) text += (text ? '
' : '') + d.text; @@ -970,27 +970,27 @@ function createHoverText(hoverData, opts) { // main label var tx = g.select('text.nums') - .style('fill',contrastColor) - .call(Drawing.setPosition,0,0) + .style('fill', contrastColor) + .call(Drawing.setPosition, 0, 0) .text(text) - .attr('data-notex',1) + .attr('data-notex', 1) .call(svgTextUtils.convertToTspans); tx.selectAll('tspan.line') - .call(Drawing.setPosition,0,0); + .call(Drawing.setPosition, 0, 0); var tx2 = g.select('text.name'), tx2width = 0; // secondary label for non-empty 'name' - if(name && name!==text) { - tx2.style('fill',traceColor) + if(name && name !== text) { + tx2.style('fill', traceColor) .text(name) - .call(Drawing.setPosition,0,0) - .attr('data-notex',1) + .call(Drawing.setPosition, 0, 0) + .attr('data-notex', 1) .call(svgTextUtils.convertToTspans); tx2.selectAll('tspan.line') - .call(Drawing.setPosition,0,0); - tx2width = tx2.node().getBoundingClientRect().width+2*HOVERTEXTPAD; + .call(Drawing.setPosition, 0, 0); + tx2width = tx2.node().getBoundingClientRect().width + 2 * HOVERTEXTPAD; } else { tx2.remove(); @@ -1003,17 +1003,17 @@ function createHoverText(hoverData, opts) { stroke: contrastColor }); var tbb = tx.node().getBoundingClientRect(), - htx = d.xa._offset+(d.x0+d.x1)/2, - hty = d.ya._offset+(d.y0+d.y1)/2, - dx = Math.abs(d.x1-d.x0), - dy = Math.abs(d.y1-d.y0), - txTotalWidth = tbb.width+HOVERARROWSIZE+HOVERTEXTPAD+tx2width, + htx = d.xa._offset + (d.x0 + d.x1) / 2, + hty = d.ya._offset + (d.y0 + d.y1) / 2, + dx = Math.abs(d.x1 - d.x0), + dy = Math.abs(d.y1 - d.y0), + txTotalWidth = tbb.width + HOVERARROWSIZE + HOVERTEXTPAD + tx2width, anchorStartOK, anchorEndOK; - d.ty0 = outerTop-tbb.top; - d.bx = tbb.width+2*HOVERTEXTPAD; - d.by = tbb.height+2*HOVERTEXTPAD; + d.ty0 = outerTop - tbb.top; + d.bx = tbb.width + 2 * HOVERTEXTPAD; + d.by = tbb.height + 2 * HOVERTEXTPAD; d.anchor = 'start'; d.txwidth = tbb.width; d.tx2width = tx2width; @@ -1044,10 +1044,10 @@ function createHoverText(hoverData, opts) { } else d.anchor = 'middle'; } - tx.attr('text-anchor',d.anchor); - if(tx2width) tx2.attr('text-anchor',d.anchor); - g.attr('transform','translate('+htx+','+hty+')'+ - (rotateLabels ? 'rotate('+YANGLE+')' : '')); + tx.attr('text-anchor', d.anchor); + if(tx2width) tx2.attr('text-anchor', d.anchor); + g.attr('transform', 'translate(' + htx + ',' + hty + ')' + + (rotateLabels ? 'rotate(' + YANGLE + ')' : '')); }); return hoverLabels; @@ -1070,19 +1070,19 @@ function hoverAvoidOverlaps(hoverData, ax) { // make groups of touching points pointgroups = hoverData - .map(function(d,i) { + .map(function(d, i) { var axis = d[ax]; return [{ i: i, dp: 0, pos: d.pos, posref: d.posref, - size: d.by*(axis._id.charAt(0)==='x' ? YFACTOR : 1)/2, + size: d.by * (axis._id.charAt(0) === 'x' ? YFACTOR : 1) / 2, pmin: axis._offset, - pmax: axis._offset+axis._length + pmax: axis._offset + axis._length }]; }) - .sort(function(a,b) { return a[0].posref-b[0].posref; }), + .sort(function(a, b) { return a[0].posref - b[0].posref; }), donepositioning, topOverlap, bottomOverlap, @@ -1092,26 +1092,26 @@ function hoverAvoidOverlaps(hoverData, ax) { function constrainGroup(grp) { var minPt = grp[0], - maxPt = grp[grp.length-1]; + maxPt = grp[grp.length - 1]; // overlap with the top - positive vals are overlaps - topOverlap = minPt.pmin-minPt.pos-minPt.dp+minPt.size; + topOverlap = minPt.pmin - minPt.pos - minPt.dp + minPt.size; // overlap with the bottom - positive vals are overlaps - bottomOverlap = maxPt.pos+maxPt.dp+maxPt.size-minPt.pmax; + bottomOverlap = maxPt.pos + maxPt.dp + maxPt.size - minPt.pmax; // check for min overlap first, so that we always // see the largest labels // allow for .01px overlap, so we don't get an // infinite loop from rounding errors - if(topOverlap>0.01) { - for(j=grp.length-1; j>=0; j--) grp[j].dp += topOverlap; + if(topOverlap > 0.01) { + for(j = grp.length - 1; j >= 0; j--) grp[j].dp += topOverlap; donepositioning = false; } - if(bottomOverlap<0.01) return; - if(topOverlap<-0.01) { + if(bottomOverlap < 0.01) return; + if(topOverlap < -0.01) { // make sure we're not pushing back and forth - for(j=grp.length-1; j>=0; j--) grp[j].dp -= bottomOverlap; + for(j = grp.length - 1; j >= 0; j--) grp[j].dp -= bottomOverlap; donepositioning = false; } if(!donepositioning) return; @@ -1120,43 +1120,43 @@ function hoverAvoidOverlaps(hoverData, ax) { // first see how many points we need to delete var deleteCount = 0; - for(i=0; iminPt.pmax) deleteCount++; + if(pti.pos + pti.dp + pti.size > minPt.pmax) deleteCount++; } // start by deleting points whose data is off screen - for(i=grp.length-1; i>=0; i--) { - if(deleteCount<=0) break; + for(i = grp.length - 1; i >= 0; i--) { + if(deleteCount <= 0) break; pti = grp[i]; // pos has already been constrained to [pmin,pmax] // so look for points close to that to delete - if(pti.pos>minPt.pmax-1) { + if(pti.pos > minPt.pmax - 1) { pti.del = true; deleteCount--; } } - for(i=0; i=0; j--) grp[j].dp -= bottomOverlap; + bottomOverlap = pti.size * 2; + for(j = grp.length - 1; j >= 0; j--) grp[j].dp -= bottomOverlap; } } // then delete points that go off the bottom - for(i=grp.length-1; i>=0; i--) { - if(deleteCount<=0) break; + for(i = grp.length - 1; i >= 0; i--) { + if(deleteCount <= 0) break; pti = grp[i]; - if(pti.pos+pti.dp+pti.size>minPt.pmax) { + if(pti.pos + pti.dp + pti.size > minPt.pmax) { pti.del = true; deleteCount--; } @@ -1165,7 +1165,7 @@ function hoverAvoidOverlaps(hoverData, ax) { // loop through groups, combining them if they overlap, // until nothing moves - while(!donepositioning && nummoves<=hoverData.length) { + while(!donepositioning && nummoves <= hoverData.length) { // to avoid infinite loops, don't move more times // than there are traces nummoves++; @@ -1174,31 +1174,31 @@ function hoverAvoidOverlaps(hoverData, ax) { // reverse this if it does donepositioning = true; i = 0; - while(i0.01 && (p0.pmin === p1.pmin) && (p0.pmax === p1.pmax)) { + if(topOverlap > 0.01 && (p0.pmin === p1.pmin) && (p0.pmax === p1.pmax)) { // push the new point(s) added to this group out of the way - for(j=g1.length-1; j>=0; j--) g1[j].dp += topOverlap; + for(j = g1.length - 1; j >= 0; j--) g1[j].dp += topOverlap; // add them to the group - g0.push.apply(g0,g1); - pointgroups.splice(i+1,1); + g0.push.apply(g0, g1); + pointgroups.splice(i + 1, 1); // adjust for minimum average movement sumdp = 0; - for(j=g0.length-1; j>=0; j--) sumdp += g0[j].dp; - bottomOverlap = sumdp/g0.length; - for(j=g0.length-1; j>=0; j--) g0[j].dp -= bottomOverlap; + for(j = g0.length - 1; j >= 0; j--) sumdp += g0[j].dp; + bottomOverlap = sumdp / g0.length; + for(j = g0.length - 1; j >= 0; j--) g0[j].dp -= bottomOverlap; donepositioning = false; } else i++; @@ -1209,9 +1209,9 @@ function hoverAvoidOverlaps(hoverData, ax) { } // now put these offsets into hoverData - for(i=pointgroups.length-1; i>=0; i--) { + for(i = pointgroups.length - 1; i >= 0; i--) { var grp = pointgroups[i]; - for(j=grp.length-1; j>=0; j--) { + for(j = grp.length - 1; j >= 0; j--) { var pt = grp[j], hoverPt = hoverData[pt.i]; hoverPt.offset = pt.dp; @@ -1229,36 +1229,36 @@ function alignHoverText(hoverLabels, rotateLabels) { g.remove(); return; } - var horzSign = d.anchor==='end' ? -1 : 1, + var horzSign = d.anchor === 'end' ? -1 : 1, tx = g.select('text.nums'), alignShift = {start: 1, end: -1, middle: 0}[d.anchor], - txx = alignShift*(HOVERARROWSIZE+HOVERTEXTPAD), - tx2x = txx+alignShift*(d.txwidth+HOVERTEXTPAD), + txx = alignShift * (HOVERARROWSIZE + HOVERTEXTPAD), + tx2x = txx + alignShift * (d.txwidth + HOVERTEXTPAD), offsetX = 0, offsetY = d.offset; - if(d.anchor==='middle') { - txx-=d.tx2width/2; - tx2x-=d.tx2width/2; + if(d.anchor === 'middle') { + txx -= d.tx2width / 2; + tx2x -= d.tx2width / 2; } if(rotateLabels) { offsetY *= -YSHIFTY; - offsetX = d.offset*YSHIFTX; + offsetX = d.offset * YSHIFTX; } - g.select('path').attr('d',d.anchor==='middle' ? + g.select('path').attr('d', d.anchor === 'middle' ? // middle aligned: rect centered on data - ('M-'+(d.bx/2)+',-'+(d.by/2)+'h'+d.bx+'v'+d.by+'h-'+d.bx+'Z') : + ('M-' + (d.bx / 2) + ',-' + (d.by / 2) + 'h' + d.bx + 'v' + d.by + 'h-' + d.bx + 'Z') : // left or right aligned: side rect with arrow to data - ('M0,0L'+(horzSign*HOVERARROWSIZE+offsetX)+','+(HOVERARROWSIZE+offsetY)+ - 'v'+(d.by/2-HOVERARROWSIZE)+ - 'h'+(horzSign*d.bx)+ - 'v-'+d.by+ - 'H'+(horzSign*HOVERARROWSIZE+offsetX)+ - 'V'+(offsetY-HOVERARROWSIZE)+ + ('M0,0L' + (horzSign * HOVERARROWSIZE + offsetX) + ',' + (HOVERARROWSIZE + offsetY) + + 'v' + (d.by / 2 - HOVERARROWSIZE) + + 'h' + (horzSign * d.bx) + + 'v-' + d.by + + 'H' + (horzSign * HOVERARROWSIZE + offsetX) + + 'V' + (offsetY - HOVERARROWSIZE) + 'Z')); tx.call(Drawing.setPosition, - txx+offsetX, offsetY+d.ty0-d.by/2+HOVERTEXTPAD) + txx + offsetX, offsetY + d.ty0 - d.by / 2 + HOVERTEXTPAD) .selectAll('tspan.line') .attr({ x: tx.attr('x'), @@ -1268,13 +1268,13 @@ function alignHoverText(hoverLabels, rotateLabels) { if(d.tx2width) { g.select('text.name, text.name tspan.line') .call(Drawing.setPosition, - tx2x+alignShift*HOVERTEXTPAD+offsetX, - offsetY+d.ty0-d.by/2+HOVERTEXTPAD); + tx2x + alignShift * HOVERTEXTPAD + offsetX, + offsetY + d.ty0 - d.by / 2 + HOVERTEXTPAD); g.select('rect') .call(Drawing.setRect, - tx2x+(alignShift-1)*d.tx2width/2+offsetX, - offsetY-d.by/2-1, - d.tx2width, d.by+2); + tx2x + (alignShift - 1) * d.tx2width / 2 + offsetX, + offsetY - d.by / 2 - 1, + d.tx2width, d.by + 2); } }); } @@ -1283,13 +1283,13 @@ function hoverChanged(gd, evt, oldhoverdata) { // don't emit any events if nothing changed or // if fx.hover was called manually if(!evt.target) return false; - if(!oldhoverdata || oldhoverdata.length!==gd._hoverdata.length) return true; + if(!oldhoverdata || oldhoverdata.length !== gd._hoverdata.length) return true; - for(var i = oldhoverdata.length-1; i>=0; i--) { + for(var i = oldhoverdata.length - 1; i >= 0; i--) { var oldPt = oldhoverdata[i], newPt = gd._hoverdata[i]; - if(oldPt.curveNumber!==newPt.curveNumber || - String(oldPt.pointNumber)!==String(newPt.pointNumber)) { + if(oldPt.curveNumber !== newPt.curveNumber || + String(oldPt.pointNumber) !== String(newPt.pointNumber)) { return true; } } @@ -1297,7 +1297,7 @@ function hoverChanged(gd, evt, oldhoverdata) { } // on click -fx.click = function(gd,evt) { +fx.click = function(gd, evt) { if(gd._hoverdata && evt && evt.target) { gd.emit('plotly_click', {points: gd._hoverdata}); // why do we get a double event without this??? @@ -1314,9 +1314,9 @@ fx.click = function(gd,evt) { // note that for closest mode, two inbox's will get added in quadrature // args are (signed) difference from the two opposite edges // count one edge as in, so that over continuous ranges you never get a gap -fx.inbox = function(v0,v1) { - if(v0*v1<0 || v0===0) { - return constants.MAXDIST*(0.6-0.3/Math.max(3,Math.abs(v0-v1))); +fx.inbox = function(v0, v1) { + if(v0 * v1 < 0 || v0 === 0) { + return constants.MAXDIST * (0.6 - 0.3 / Math.max(3, Math.abs(v0 - v1))); } return Infinity; }; diff --git a/src/plots/cartesian/layout_defaults.js b/src/plots/cartesian/layout_defaults.js index 15273f50b33..4278e2d467a 100644 --- a/src/plots/cartesian/layout_defaults.js +++ b/src/plots/cartesian/layout_defaults.js @@ -134,7 +134,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) { letter: axLetter, counterAxes: {x: yaList, y: xaList}[axLetter].map(axisIds.name2id), overlayableAxes: {x: xaList, y: yaList}[axLetter].filter(function(axName2) { - return axName2!==axName && !(layoutIn[axName2]||{}).overlaying; + return axName2 !== axName && !(layoutIn[axName2] || {}).overlaying; }).map(axisIds.name2id) }; diff --git a/src/plots/cartesian/select.js b/src/plots/cartesian/select.js index b88f1176f6f..9c36daf30a2 100644 --- a/src/plots/cartesian/select.js +++ b/src/plots/cartesian/select.js @@ -42,12 +42,12 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { pts = filteredPolygon([[x0, y0]], constants.BENDPX); } - var outlines = plot.selectAll('path.select-outline').data([1,2]); + var outlines = plot.selectAll('path.select-outline').data([1, 2]); outlines.enter() .append('path') .attr('class', function(d) { return 'select-outline select-outline-' + d; }) - .attr('transform','translate(' + xs + ', ' + ys + ')') + .attr('transform', 'translate(' + xs + ', ' + ys + ')') .attr('d', path0 + 'Z'); var corners = plot.append('path') @@ -57,8 +57,8 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { stroke: color.defaultLine, 'stroke-width': 1 }) - .attr('transform','translate(' + xs + ', ' + ys + ')') - .attr('d','M0,0Z'); + .attr('transform', 'translate(' + xs + ', ' + ys + ')') + .attr('d', 'M0,0Z'); // find the traces to search for selection points @@ -136,7 +136,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { else { // diagonal motion poly = polygonTester([[x0, y0], [x0, y1], [x1, y1], [x1, y0]]); - corners.attr('d','M0,0Z'); + corners.attr('d', 'M0,0Z'); } outlines.attr('d', 'M' + poly.xmin + ',' + poly.ymin + 'H' + (poly.xmax - 1) + 'V' + (poly.ymax - 1) + diff --git a/src/plots/cartesian/set_convert.js b/src/plots/cartesian/set_convert.js index e601ee80062..3dd45c3788e 100644 --- a/src/plots/cartesian/set_convert.js +++ b/src/plots/cartesian/set_convert.js @@ -43,23 +43,23 @@ module.exports = function setConvert(ax) { var clipMult = 10; function toLog(v, clip) { - if(v>0) return Math.log(v)/Math.LN10; + if(v > 0) return Math.log(v) / Math.LN10; - else if(v<=0 && clip && ax.range && ax.range.length===2) { + else if(v <= 0 && clip && ax.range && ax.range.length === 2) { // clip NaN (ie past negative infinity) to clipMult axis // length past the negative edge var r0 = ax.range[0], r1 = ax.range[1]; - return 0.5*(r0 + r1 - 3 * clipMult * Math.abs(r0 - r1)); + return 0.5 * (r0 + r1 - 3 * clipMult * Math.abs(r0 - r1)); } else return constants.BADNUM; } - function fromLog(v) { return Math.pow(10,v); } + 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; + ax.c2l = (ax.type === 'log') ? toLog : num; + ax.l2c = (ax.type === 'log') ? fromLog : num; ax.l2d = function(v) { return ax.c2d(ax.l2c(v)); }; ax.p2d = function(v) { return ax.l2d(ax.p2l(v)); }; @@ -80,36 +80,36 @@ module.exports = function setConvert(ax) { // make sure we have a range (linearized data values) // and that it stays away from the limits of javascript numbers - if(!ax.range || ax.range.length!==2 || ax.range[0]===ax.range[1]) { - ax.range = [-1,1]; + if(!ax.range || ax.range.length !== 2 || ax.range[0] === ax.range[1]) { + ax.range = [-1, 1]; } - for(i=0; i<2; i++) { + for(i = 0; i < 2; i++) { if(!isNumeric(ax.range[i])) { - ax.range[i] = isNumeric(ax.range[1-i]) ? - (ax.range[1-i] * (i ? 10 : 0.1)) : + ax.range[i] = isNumeric(ax.range[1 - i]) ? + (ax.range[1 - i] * (i ? 10 : 0.1)) : (i ? 1 : -1); } - if(ax.range[i]<-(Number.MAX_VALUE/2)) { - ax.range[i] = -(Number.MAX_VALUE/2); + if(ax.range[i] < -(Number.MAX_VALUE / 2)) { + ax.range[i] = -(Number.MAX_VALUE / 2); } - else if(ax.range[i]>Number.MAX_VALUE/2) { - ax.range[i] = Number.MAX_VALUE/2; + else if(ax.range[i] > Number.MAX_VALUE / 2) { + ax.range[i] = Number.MAX_VALUE / 2; } } - if(ax._id.charAt(0)==='y') { - ax._offset = gs.t+(1-ax.domain[1])*gs.h; - ax._length = gs.h*(ax.domain[1]-ax.domain[0]); - ax._m = ax._length/(ax.range[0]-ax.range[1]); - ax._b = -ax._m*ax.range[1]; + if(ax._id.charAt(0) === 'y') { + ax._offset = gs.t + (1 - ax.domain[1]) * gs.h; + ax._length = gs.h * (ax.domain[1] - ax.domain[0]); + ax._m = ax._length / (ax.range[0] - ax.range[1]); + ax._b = -ax._m * ax.range[1]; } else { - ax._offset = gs.l+ax.domain[0]*gs.w; - ax._length = gs.w*(ax.domain[1]-ax.domain[0]); - ax._m = ax._length/(ax.range[1]-ax.range[0]); - ax._b = -ax._m*ax.range[0]; + ax._offset = gs.l + ax.domain[0] * gs.w; + ax._length = gs.w * (ax.domain[1] - ax.domain[0]); + ax._m = ax._length / (ax.range[1] - ax.range[0]); + ax._b = -ax._m * ax.range[0]; } if(!isFinite(ax._m) || !isFinite(ax._b)) { @@ -128,12 +128,12 @@ module.exports = function setConvert(ax) { return d3.round(ax._b + ax._m * v, 2); }; - ax.p2l = function(px) { return (px-ax._b)/ax._m; }; + 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)); }; - if(['linear','log','-'].indexOf(ax.type)!==-1) { + if(['linear', 'log', '-'].indexOf(ax.type) !== -1) { ax.c2d = num; ax.d2c = function(v) { v = cleanDatum(v); @@ -144,7 +144,7 @@ module.exports = function setConvert(ax) { else return ax.d2c(v); }; } - else if(ax.type==='date') { + else if(ax.type === 'date') { ax.c2d = function(v) { return isNumeric(v) ? Lib.ms2DateTime(v) : constants.BADNUM; }; @@ -157,7 +157,7 @@ module.exports = function setConvert(ax) { // check if date strings or js date objects are provided for range // and convert to ms - if(ax.range && ax.range.length>1) { + if(ax.range && ax.range.length > 1) { try { var ar1 = ax.range.map(Lib.dateTime2ms); if(!isNumeric(ax.range[0]) && isNumeric(ar1[0])) { @@ -170,7 +170,7 @@ module.exports = function setConvert(ax) { catch(e) { console.log(e, ax.range); } } } - else if(ax.type==='category') { + else if(ax.type === 'category') { ax.c2d = function(v) { return ax._categories[Math.round(v)]; @@ -216,16 +216,16 @@ module.exports = function setConvert(ax) { for(i = 0; i < arrayIn.length; i++) arrayOut[i] = ax.d2c(arrayIn[i]); } else { - var v0 = ((axletter+'0') in tdc) ? - ax.d2c(tdc[axletter+'0']) : 0, - dv = (tdc['d'+axletter]) ? - Number(tdc['d'+axletter]) : 1; + var v0 = ((axletter + '0') in tdc) ? + ax.d2c(tdc[axletter + '0']) : 0, + dv = (tdc['d' + axletter]) ? + Number(tdc['d' + axletter]) : 1; // the opposing data, for size if we have x and dx etc - arrayIn = tdc[{x: 'y',y: 'x'}[axletter]]; + arrayIn = tdc[{x: 'y', y: 'x'}[axletter]]; arrayOut = new Array(arrayIn.length); - for(i = 0; i < arrayIn.length; i++) arrayOut[i] = v0+i*dv; + for(i = 0; i < arrayIn.length; i++) arrayOut[i] = v0 + i * dv; } return arrayOut; }; diff --git a/src/plots/cartesian/tick_label_defaults.js b/src/plots/cartesian/tick_label_defaults.js index 11608362711..9d5a83d67a1 100644 --- a/src/plots/cartesian/tick_label_defaults.js +++ b/src/plots/cartesian/tick_label_defaults.js @@ -69,13 +69,13 @@ function getShowAttrDflt(containerIn) { 'showtickprefix', 'showticksuffix'], showAttrs = showAttrsAll.filter(function(a) { - return containerIn[a]!==undefined; + return containerIn[a] !== undefined; }), sameVal = function(a) { - return containerIn[a]===containerIn[showAttrs[0]]; + 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/geo.js b/src/plots/geo/geo.js index 7ac07044c41..968fc671251 100644 --- a/src/plots/geo/geo.js +++ b/src/plots/geo/geo.js @@ -92,7 +92,7 @@ proto.plot = function(geoData, fullLayout, promises) { topojsonNameNew = topojsonUtils.getTopojsonName(geoLayout); - if(_this.topojson===null || topojsonNameNew!==_this.topojsonName) { + if(_this.topojson === null || topojsonNameNew !== _this.topojsonName) { _this.topojsonName = topojsonNameNew; if(PlotlyGeoAssets.topojson[_this.topojsonName] !== undefined) { @@ -197,7 +197,7 @@ proto.updateFx = function(hovermode) { proto.makeProjection = function(geoLayout) { var projLayout = geoLayout.projection, projType = projLayout.type, - isNew = this.projection===null || projType!==this.projectionType, + isNew = this.projection === null || projType !== this.projectionType, projection; if(isNew) { @@ -314,7 +314,7 @@ proto.drawTopo = function(selection, layerName, geoLayout) { if(geoLayout['show' + layerName] !== true) return; var topojson = this.topojson, - datum = layerName==='frame' ? + datum = layerName === 'frame' ? constants.sphereSVG : topojsonFeature(topojson, topojson.objects[layerName]); @@ -342,7 +342,7 @@ proto.drawGraticule = function(selection, axisName, geoLayout) { var scopeDefaults = constants.scopeDefaults[geoLayout.scope], lonaxisRange = scopeDefaults.lonaxisRange, lataxisRange = scopeDefaults.lataxisRange, - step = axisName==='lonaxis' ? + step = axisName === 'lonaxis' ? [axisLayout.dtick] : [0, axisLayout.dtick], graticule = makeGraticule(lonaxisRange, lataxisRange, step); @@ -367,7 +367,7 @@ proto.drawLayout = function(geoLayout) { for(var i = 0; i < baseLayers.length; i++) { layerName = baseLayers[i]; - if(axesNames.indexOf(layerName)!==-1) { + if(axesNames.indexOf(layerName) !== -1) { this.drawGraticule(gBaseLayer, layerName, geoLayout); } else this.drawTopo(gBaseLayer, layerName, geoLayout); @@ -407,10 +407,10 @@ proto.styleLayer = function(selection, layerName, geoLayout) { var fillLayers = constants.fillLayers, lineLayers = constants.lineLayers; - if(fillLayers.indexOf(layerName)!==-1) { + if(fillLayers.indexOf(layerName) !== -1) { styleFillLayer(selection, layerName, geoLayout); } - else if(lineLayers.indexOf(layerName)!==-1) { + else if(lineLayers.indexOf(layerName) !== -1) { styleLineLayer(selection, layerName, geoLayout); } }; @@ -424,7 +424,7 @@ proto.styleLayout = function(geoLayout) { for(var i = 0; i < baseLayers.length; i++) { layerName = baseLayers[i]; - if(axesNames.indexOf(layerName)!==-1) { + if(axesNames.indexOf(layerName) !== -1) { styleGraticule(gBaseLayer, layerName, geoLayout); } else this.styleLayer(gBaseLayer, layerName, geoLayout); diff --git a/src/plots/geo/layout/axis_defaults.js b/src/plots/geo/layout/axis_defaults.js index 39ebd8978ca..b88700dcbfb 100644 --- a/src/plots/geo/layout/axis_defaults.js +++ b/src/plots/geo/layout/axis_defaults.js @@ -34,10 +34,10 @@ module.exports = function supplyGeoAxisLayoutDefaults(geoLayoutIn, geoLayoutOut) projRotation = projLayout.rotation; dfltSpans = constants[axisName + 'Span']; - halfSpan = dfltSpans[projType]!==undefined ? + halfSpan = dfltSpans[projType] !== undefined ? dfltSpans[projType] / 2 : dfltSpans['*'] / 2; - rotateAngle = axisName==='lonaxis' ? + rotateAngle = axisName === 'lonaxis' ? projRotation.lon : projRotation.lat; @@ -58,7 +58,7 @@ module.exports = function supplyGeoAxisLayoutDefaults(geoLayoutIn, geoLayoutOut) Lib.noneOrAll(axisIn.range, axisOut.range, [0, 1]); coerce('tick0', range[0]); - coerce('dtick', axisName==='lonaxis' ? 30 : 10); + coerce('dtick', axisName === 'lonaxis' ? 30 : 10); var show = coerce('showgrid'); if(show) { diff --git a/src/plots/geo/layout/defaults.js b/src/plots/geo/layout/defaults.js index 06f756d7a95..d211282b547 100644 --- a/src/plots/geo/layout/defaults.js +++ b/src/plots/geo/layout/defaults.js @@ -34,8 +34,8 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce) { var resolution = coerce('resolution'); var projType = coerce('projection.type', scopeParams.projType); - var isAlbersUsa = projType==='albers usa'; - var isConic = projType.indexOf('conic')!==-1; + var isAlbersUsa = projType === 'albers usa'; + var isConic = projType.indexOf('conic') !== -1; if(isConic) { var dfltProjParallels = scopeParams.projParallels || [0, 60]; @@ -79,7 +79,7 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce) { coerce('countrywidth'); } - if(scope==='usa' || (scope==='north america' && resolution===50)) { + if(scope === 'usa' || (scope === 'north america' && resolution === 50)) { // Only works for: // USA states at 110m // USA states + Canada provinces at 50m @@ -102,7 +102,7 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce) { supplyGeoAxisLayoutDefaults(geoLayoutIn, geoLayoutOut); // bind a few helper variables - geoLayoutOut._isHighRes = resolution===50; + geoLayoutOut._isHighRes = resolution === 50; geoLayoutOut._clipAngle = constants.lonaxisSpan[projType] / 2; geoLayoutOut._isAlbersUsa = isAlbersUsa; geoLayoutOut._isConic = isConic; diff --git a/src/plots/geo/set_scale.js b/src/plots/geo/set_scale.js index 9621a2eff79..3cc5920ad8b 100644 --- a/src/plots/geo/set_scale.js +++ b/src/plots/geo/set_scale.js @@ -128,7 +128,7 @@ function makeRangeBox(lon0, lat0, lon1, lat1) { type: 'Polygon', coordinates: [ [ [lon0, lat0], - [lon0 , lat1], + [lon0, lat1], [lon0 + dlon4, lat1], [lon0 + 2 * dlon4, lat1], [lon0 + 3 * dlon4, lat1], diff --git a/src/plots/geo/zoom.js b/src/plots/geo/zoom.js index b52f4a4ca65..b18a0c6e4cf 100644 --- a/src/plots/geo/zoom.js +++ b/src/plots/geo/zoom.js @@ -313,7 +313,7 @@ function unRoll(rotateAngles, pt, lastRotate) { b = Math.sqrt(a * a - g * g); } - var newYaw2 = 180 - newYaw1 - 2*theta, + var newYaw2 = 180 - newYaw1 - 2 * theta, newPitch1 = (Math.atan2(h, f) - Math.atan2(z, b)) * degrees, newPitch2 = (Math.atan2(h, f) - Math.atan2(z, -b)) * degrees; @@ -333,7 +333,7 @@ function angleDistance(yaw0, pitch0, yaw1, pitch1) { // reduce an angle in degrees to [-180,180] function angleMod(angle) { - return (angle % 360 + 540) %360 - 180; + return (angle % 360 + 540) % 360 - 180; } // rotate a cartesian vector @@ -342,8 +342,8 @@ function angleMod(angle) { function rotateCartesian(vector, axis, angle) { var angleRads = angle * radians, vectorOut = vector.slice(), - ax1 = (axis===0) ? 1 : 0, - ax2 = (axis===2) ? 1 : 2, + ax1 = (axis === 0) ? 1 : 0, + ax2 = (axis === 2) ? 1 : 2, cosa = Math.cos(angleRads), sina = Math.sin(angleRads); diff --git a/src/plots/gl2d/convert.js b/src/plots/gl2d/convert.js index 50b1521bff6..2321224bd39 100644 --- a/src/plots/gl2d/convert.js +++ b/src/plots/gl2d/convert.js @@ -20,7 +20,7 @@ function Axes2DOptions(scene) { this.pixelRatio = scene.pixelRatio; this.screenBox = [0, 0, 1, 1]; - this.viewBox = [0 ,0, 1, 1]; + this.viewBox = [0, 0, 1, 1]; this.dataBox = [-1, -1, 1, 1]; this.borderLineEnable = [false, false, false, false]; @@ -53,7 +53,7 @@ function Axes2DOptions(scene) { this.labels = ['x', 'y']; this.labelEnable = [true, true, false, false]; - this.labelAngle = [0, Math.PI/2, 0, 3.0*Math.PI/2]; + this.labelAngle = [0, Math.PI / 2, 0, 3.0 * Math.PI / 2]; this.labelPad = [15, 15, 15, 15]; this.labelSize = [12, 12]; this.labelFont = ['sans-serif', 'sans-serif']; @@ -114,27 +114,27 @@ proto.merge = function(options) { axTitle = /Click to enter .+ title/.test(ax.title) ? '' : ax.title; for(j = 0; j <= 2; j += 2) { - this.labelEnable[i+j] = false; - this.labels[i+j] = htmlToUnicode(axTitle); - this.labelColor[i+j] = str2RGBArray(ax.titlefont.color); - this.labelFont[i+j] = ax.titlefont.family; - this.labelSize[i+j] = ax.titlefont.size; - this.labelPad[i+j] = this.getLabelPad(axisName, ax); - - this.tickEnable[i+j] = false; - this.tickColor[i+j] = str2RGBArray((ax.tickfont || {}).color); - this.tickAngle[i+j] = (ax.tickangle === 'auto') ? + this.labelEnable[i + j] = false; + this.labels[i + j] = htmlToUnicode(axTitle); + this.labelColor[i + j] = str2RGBArray(ax.titlefont.color); + this.labelFont[i + j] = ax.titlefont.family; + this.labelSize[i + j] = ax.titlefont.size; + this.labelPad[i + j] = this.getLabelPad(axisName, ax); + + this.tickEnable[i + j] = false; + this.tickColor[i + j] = str2RGBArray((ax.tickfont || {}).color); + this.tickAngle[i + j] = (ax.tickangle === 'auto') ? 0 : Math.PI * -ax.tickangle / 180; - this.tickPad[i+j] = this.getTickPad(ax); + this.tickPad[i + j] = this.getTickPad(ax); - this.tickMarkLength[i+j] = 0; - this.tickMarkWidth[i+j] = ax.tickwidth || 0; - this.tickMarkColor[i+j] = str2RGBArray(ax.tickcolor); + this.tickMarkLength[i + j] = 0; + this.tickMarkWidth[i + j] = ax.tickwidth || 0; + this.tickMarkColor[i + j] = str2RGBArray(ax.tickcolor); - this.borderLineEnable[i+j] = false; - this.borderLineColor[i+j] = str2RGBArray(ax.linecolor); - this.borderLineWidth[i+j] = ax.linewidth || 0; + this.borderLineEnable[i + j] = false; + this.borderLineColor[i + j] = str2RGBArray(ax.linecolor); + this.borderLineWidth[i + j] = ax.linewidth || 0; } hasSharedAxis = this.hasSharedAxis(ax); @@ -153,19 +153,19 @@ proto.merge = function(options) { // and are never show on subplots that share existing axes. if(hasAxisInDfltPos) this.labelEnable[i] = true; - else if(hasAxisInAltrPos) this.labelEnable[i+2] = true; + else if(hasAxisInAltrPos) this.labelEnable[i + 2] = true; if(hasAxisInDfltPos) this.tickEnable[i] = ax.showticklabels; - else if(hasAxisInAltrPos) this.tickEnable[i+2] = ax.showticklabels; + else if(hasAxisInAltrPos) this.tickEnable[i + 2] = ax.showticklabels; // Grid lines and ticks can appear on both sides of the scene // and can appear on subplot that share existing axes via `ax.mirror`. if(hasAxisInDfltPos || mirrorLines) this.borderLineEnable[i] = ax.showline; - if(hasAxisInAltrPos || mirrorLines) this.borderLineEnable[i+2] = ax.showline; + if(hasAxisInAltrPos || mirrorLines) this.borderLineEnable[i + 2] = ax.showline; if(hasAxisInDfltPos || mirrorTicks) this.tickMarkLength[i] = this.getTickMarkLength(ax); - if(hasAxisInAltrPos || mirrorTicks) this.tickMarkLength[i+2] = this.getTickMarkLength(ax); + if(hasAxisInAltrPos || mirrorTicks) this.tickMarkLength[i + 2] = this.getTickMarkLength(ax); this.gridLineEnable[i] = ax.showgrid; this.gridLineColor[i] = str2RGBArray(ax.gridcolor); diff --git a/src/plots/gl2d/scene2d.js b/src/plots/gl2d/scene2d.js index 138efa71085..68d04622779 100644 --- a/src/plots/gl2d/scene2d.js +++ b/src/plots/gl2d/scene2d.js @@ -179,12 +179,12 @@ proto.toImage = function(format) { gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, pixels); // flip pixels - for(var j=0,k=h-1; j bounds[i+2]) { + if(bounds[i] > bounds[i + 2]) { bounds[i] = -1; - bounds[i+2] = 1; + bounds[i + 2] = 1; } ax = this[AXES[i]]; - ax._length = options.viewBox[i+2] - options.viewBox[i]; + ax._length = options.viewBox[i + 2] - options.viewBox[i]; Axes.doAutoRange(ax); } @@ -465,7 +465,7 @@ proto.draw = function() { var result = glplot.pick( (x / glplot.pixelRatio) + size.l + domainX[0] * size.w, - (y / glplot.pixelRatio) - (size.t + (1-domainY[1]) * size.h) + (y / glplot.pixelRatio) - (size.t + (1 - domainY[1]) * size.h) ); if(result && fullLayout.hovermode) { diff --git a/src/plots/gl3d/camera.js b/src/plots/gl3d/camera.js index 83c91ab40ef..3b93c7ba3fb 100644 --- a/src/plots/gl3d/camera.js +++ b/src/plots/gl3d/camera.js @@ -59,9 +59,9 @@ function createCamera(element, options) { var t = now(); var delay = this.delay; var ctime = t - 2 * delay; - view.idle(t-delay); + view.idle(t - delay); view.recalcMatrix(ctime); - view.flush(t - (100+delay * 2)); + view.flush(t - (100 + delay * 2)); var allEqual = true; var matrix = view.computedMatrix; for(var i = 0; i < 16; ++i) { @@ -115,7 +115,7 @@ function createCamera(element, options) { //Hacky time warping stuff to generate smooth animation var t0 = now(); view._active.lookAt(t0, curEye, curCenter, curUp); - view._active.lookAt(t0 + 500, curEye, curCenter, [0,0,1]); + view._active.lookAt(t0 + 500, curEye, curCenter, [0, 0, 1]); view._active.flush(t0); } return view.getMode(); @@ -188,9 +188,9 @@ function createCamera(element, options) { var ctrl = !!mods.control; var alt = !!mods.alt; var shift = !!mods.shift; - var left = !!(buttons&1); - var right = !!(buttons&2); - var middle = !!(buttons&4); + var left = !!(buttons & 1); + var right = !!(buttons & 2); + var middle = !!(buttons & 4); var scale = 1.0 / element.clientHeight; var dx = scale * (x - lastX); diff --git a/src/plots/gl3d/layout/convert.js b/src/plots/gl3d/layout/convert.js index 8c7ba11955a..3d9201e3815 100644 --- a/src/plots/gl3d/layout/convert.js +++ b/src/plots/gl3d/layout/convert.js @@ -28,34 +28,34 @@ function AxesOptions() { this.tickFont = [ 'sans-serif', 'sans-serif', 'sans-serif' ]; this.tickSize = [ 12, 12, 12 ]; this.tickAngle = [ 0, 0, 0 ]; - this.tickColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]; + this.tickColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ]; this.tickPad = [ 18, 18, 18 ]; this.labels = [ 'x', 'y', 'z' ]; this.labelEnable = [ true, true, true ]; - this.labelFont = ['Open Sans','Open Sans','Open Sans']; + this.labelFont = ['Open Sans', 'Open Sans', 'Open Sans']; this.labelSize = [ 20, 20, 20 ]; this.labelAngle = [ 0, 0, 0 ]; - this.labelColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]; + this.labelColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ]; this.labelPad = [ 30, 30, 30 ]; this.lineEnable = [ true, true, true ]; this.lineMirror = [ false, false, false ]; this.lineWidth = [ 1, 1, 1 ]; - this.lineColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]; + this.lineColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ]; this.lineTickEnable = [ true, true, true ]; this.lineTickMirror = [ false, false, false ]; this.lineTickLength = [ 10, 10, 10 ]; this.lineTickWidth = [ 1, 1, 1 ]; - this.lineTickColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]; + this.lineTickColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ]; this.gridEnable = [ true, true, true ]; this.gridWidth = [ 1, 1, 1 ]; - this.gridColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]; + this.gridColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ]; this.zeroEnable = [ true, true, true ]; - this.zeroLineColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]; + this.zeroLineColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ]; this.zeroLineWidth = [ 2, 2, 2 ]; this.backgroundEnable = [ true, true, true ]; @@ -124,7 +124,7 @@ proto.merge = function(sceneLayout) { } if('mirror' in axes) { - if(['ticks','all','allticks'].indexOf(axes.mirror) !== -1) { + if(['ticks', 'all', 'allticks'].indexOf(axes.mirror) !== -1) { opts.lineTickMirror[i] = true; opts.lineMirror[i] = true; } else if(axes.mirror === true) { diff --git a/src/plots/gl3d/layout/spikes.js b/src/plots/gl3d/layout/spikes.js index 507e17b8a7f..124bfa1aa59 100644 --- a/src/plots/gl3d/layout/spikes.js +++ b/src/plots/gl3d/layout/spikes.js @@ -15,11 +15,11 @@ var AXES_NAMES = ['xaxis', 'yaxis', 'zaxis']; function SpikeOptions() { this.enabled = [true, true, true]; - this.colors = [[0,0,0,1], - [0,0,0,1], - [0,0,0,1]]; + this.colors = [[0, 0, 0, 1], + [0, 0, 0, 1], + [0, 0, 0, 1]]; this.drawSides = [true, true, true]; - this.lineWidth = [1,1,1]; + this.lineWidth = [1, 1, 1]; } var proto = SpikeOptions.prototype; diff --git a/src/plots/gl3d/layout/tick_marks.js b/src/plots/gl3d/layout/tick_marks.js index fec14bf0b67..46746915388 100644 --- a/src/plots/gl3d/layout/tick_marks.js +++ b/src/plots/gl3d/layout/tick_marks.js @@ -18,14 +18,14 @@ var convertHTML = require('../../../lib/html2unicode'); var AXES_NAMES = ['xaxis', 'yaxis', 'zaxis']; -var centerPoint = [0,0,0]; +var centerPoint = [0, 0, 0]; function contourLevelsFromTicks(ticks) { var result = new Array(3); - for(var i=0; i<3; ++i) { + for(var i = 0; i < 3; ++i) { var tlevel = ticks[i]; var clevel = new Array(tlevel.length); - for(var j=0; j dataBounds[1][j]) { dataScale[j] = 1.0; } @@ -380,7 +380,7 @@ proto.plot = function(sceneData, fullLayout, layout) { dataScale[j] = 1.0; } else { - dataScale[j] = 1.0/(dataBounds[1][j] - dataBounds[0][j]); + dataScale[j] = 1.0 / (dataBounds[1][j] - dataBounds[0][j]); } } } @@ -391,7 +391,7 @@ proto.plot = function(sceneData, fullLayout, layout) { //Update traces for(i = 0; i < sceneData.length; ++i) { data = sceneData[i]; - if(data.visible!==true) { + if(data.visible !== true) { continue; } trace = this.traces[data.uid]; @@ -409,9 +409,9 @@ proto.plot = function(sceneData, fullLayout, layout) { var traceIds = Object.keys(this.traces); trace_id_loop: - for(i = 0; i fullLayout.width*0.5) o.l = o.r = 0; - if(o.b+o.t > fullLayout.height*0.5) o.b = o.t = 0; + if(o.l + o.r > fullLayout.width * 0.5) o.l = o.r = 0; + 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} }; } @@ -926,7 +926,7 @@ plots.doAutoMargin = function(gd) { mb = Math.max(fullLayout.margin.b || 0, 0), pm = fullLayout._pushmargin; - if(fullLayout.margin.autoexpand!==false) { + if(fullLayout.margin.autoexpand !== false) { // fill in the requested margins pm.base = { l: {val: 0, size: ml}, @@ -937,8 +937,8 @@ plots.doAutoMargin = function(gd) { // now cycle through all the combinations of l and r // (and t and b) to find the required margins Object.keys(pm).forEach(function(k1) { - var pushleft = pm[k1].l||{}, - pushbottom = pm[k1].b||{}, + var pushleft = pm[k1].l || {}, + pushbottom = pm[k1].b || {}, fl = pushleft.val, pl = pushleft.size, fb = pushbottom.val, @@ -947,12 +947,12 @@ plots.doAutoMargin = function(gd) { if(isNumeric(pl) && pm[k2].r) { var fr = pm[k2].r.val, pr = pm[k2].r.size; - if(fr>fl) { - var newl = (pl*fr + - (pr-fullLayout.width)*fl) / (fr-fl), - newr = (pr*(1-fl) + - (pl-fullLayout.width)*(1-fr)) / (fr-fl); - if(newl>=0 && newr>=0 && newl+newr>ml+mr) { + if(fr > fl) { + var newl = (pl * fr + + (pr - fullLayout.width) * fl) / (fr - fl), + newr = (pr * (1 - fl) + + (pl - fullLayout.width) * (1 - fr)) / (fr - fl); + if(newl >= 0 && newr >= 0 && newl + newr > ml + mr) { ml = newl; mr = newr; } @@ -961,12 +961,12 @@ plots.doAutoMargin = function(gd) { if(isNumeric(pb) && pm[k2].t) { var ft = pm[k2].t.val, pt = pm[k2].t.size; - if(ft>fb) { - var newb = (pb*ft + - (pt-fullLayout.height)*fb) / (ft-fb), - newt = (pt*(1-fb) + - (pb-fullLayout.height)*(1-ft)) / (ft-fb); - if(newb>=0 && newt>=0 && newb+newt>mb+mt) { + if(ft > fb) { + var newb = (pb * ft + + (pt - fullLayout.height) * fb) / (ft - fb), + newt = (pt * (1 - fb) + + (pb - fullLayout.height) * (1 - ft)) / (ft - fb); + if(newb >= 0 && newt >= 0 && newb + newt > mb + mt) { mb = newb; mt = newt; } @@ -981,12 +981,12 @@ plots.doAutoMargin = function(gd) { gs.t = Math.round(mt); gs.b = Math.round(mb); gs.p = Math.round(fullLayout.margin.pad); - gs.w = Math.round(fullLayout.width)-gs.l-gs.r; - gs.h = Math.round(fullLayout.height)-gs.t-gs.b; + gs.w = Math.round(fullLayout.width) - gs.l - gs.r; + gs.h = Math.round(fullLayout.height) - gs.t - gs.b; // if things changed and we're not already redrawing, trigger a redraw - if(!gd._replotting && oldmargins!=='{}' && - oldmargins!==JSON.stringify(fullLayout._size)) { + if(!gd._replotting && oldmargins !== '{}' && + oldmargins !== JSON.stringify(fullLayout._size)) { return Plotly.plot(gd); } }; @@ -1028,38 +1028,38 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) { return null; } if(Lib.isPlainObject(d)) { - var o={}, v, src; + var o = {}, v, src; for(v in d) { // remove private elements and functions // _ is for private, [ is a mistake ie [object Object] - if(typeof d[v]==='function' || - ['_','['].indexOf(v.charAt(0))!==-1) { + if(typeof d[v] === 'function' || + ['_', '['].indexOf(v.charAt(0)) !== -1) { continue; } // look for src/data matches and remove the appropriate one - if(mode==='keepdata') { + if(mode === 'keepdata') { // keepdata: remove all ...src tags - if(v.substr(v.length-3)==='src') { + if(v.substr(v.length - 3) === 'src') { continue; } } - else if(mode==='keepstream') { + else if(mode === 'keepstream') { // keep sourced data if it's being streamed. // similar to keepref, but if the 'stream' object exists // in a trace, we will keep the data array. - src = d[v+'src']; - if(typeof src==='string' && src.indexOf(':')>0) { + src = d[v + 'src']; + if(typeof src === 'string' && src.indexOf(':') > 0) { if(!Lib.isPlainObject(d.stream)) { continue; } } } - else if(mode!=='keepall') { + else if(mode !== 'keepall') { // keepref: remove sourced data but only // if the source tag is well-formed - src = d[v+'src']; - if(typeof src==='string' && src.indexOf(':')>0) { + src = d[v + 'src']; + if(typeof src === 'string' && src.indexOf(':') > 0) { continue; } } @@ -1096,5 +1096,5 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) { if(gd.framework && gd.framework.isPolar) obj = gd.framework.getConfig(); - return (output==='object') ? obj : JSON.stringify(obj); + return (output === 'object') ? obj : JSON.stringify(obj); }; diff --git a/src/plots/polar/undo_manager.js b/src/plots/polar/undo_manager.js index 18174d38a9e..5b9018aaa02 100644 --- a/src/plots/polar/undo_manager.js +++ b/src/plots/polar/undo_manager.js @@ -58,7 +58,7 @@ module.exports = function UndoManager() { hasUndo: function() { return index !== -1; }, hasRedo: function() { return index < (undoCommands.length - 1); }, getCommands: function() { return undoCommands; }, - getPreviousCommand: function() { return undoCommands[index-1]; }, + getPreviousCommand: function() { return undoCommands[index - 1]; }, getIndex: function() { return index; } }; }; diff --git a/src/plots/ternary/ternary.js b/src/plots/ternary/ternary.js index 06ceaa47677..7939463fbd1 100644 --- a/src/plots/ternary/ternary.js +++ b/src/plots/ternary/ternary.js @@ -172,7 +172,7 @@ proto.makeFramework = function() { _this.initInteractions(); }; -var w_over_h = Math.sqrt(4/3); +var w_over_h = Math.sqrt(4 / 3); proto.adjustLayout = function(ternaryLayout, graphSize) { var _this = this, @@ -300,7 +300,7 @@ proto.adjustLayout = function(ternaryLayout, graphSize) { }); setConvert(caxis); - var triangleClip = 'M' + x0 + ',' + (y0 + h) + 'h' + w + 'l-' + (w/2) + ',-' + h + 'Z'; + var triangleClip = 'M' + x0 + ',' + (y0 + h) + 'h' + w + 'l-' + (w / 2) + ',-' + h + 'Z'; _this.clipDef.select('path').attr('d', triangleClip); _this.layers.plotbg.select('path').attr('d', triangleClip); @@ -478,13 +478,13 @@ proto.initInteractions = function() { mins = mins0; span0 = _this.aaxis.range[1] - mins0.a; lum = tinycolor(_this.graphDiv._fullLayout[_this.id].bgcolor).getLuminance(); - path0 = 'M0,' + _this.h + 'L' + (_this.w / 2) +', 0L' + _this.w + ',' + _this.h + 'Z'; + path0 = 'M0,' + _this.h + 'L' + (_this.w / 2) + ', 0L' + _this.w + ',' + _this.h + 'Z'; dimmed = false; zb = zoomContainer.append('path') .attr('class', 'zoombox') .style({ - 'fill': lum>0.2 ? 'rgba(0,0,0,0)' : 'rgba(255,255,255,0)', + 'fill': lum > 0.2 ? 'rgba(0,0,0,0)' : 'rgba(255,255,255,0)', 'stroke-width': 0 }) .attr('d', path0); @@ -497,7 +497,7 @@ proto.initInteractions = function() { 'stroke-width': 1, opacity: 0 }) - .attr('d','M0,0Z'); + .attr('d', 'M0,0Z'); clearSelect(); } @@ -541,11 +541,11 @@ proto.initInteractions = function() { if(!dimmed) { zb.transition() - .style('fill', lum>0.2 ? 'rgba(0,0,0,0.4)' : + .style('fill', lum > 0.2 ? 'rgba(0,0,0,0.4)' : 'rgba(255,255,255,0.3)') .duration(200); corners.transition() - .style('opacity',1) + .style('opacity', 1) .duration(200); dimmed = true; } @@ -568,7 +568,7 @@ proto.initInteractions = function() { Plotly.relayout(gd, attrs); if(SHOWZOOMOUTTIP && gd.data && gd._context.showTips) { - Lib.notifier('Double-click to
zoom back out','long'); + Lib.notifier('Double-click to
zoom back out', 'long'); SHOWZOOMOUTTIP = false; } } diff --git a/src/snapshot/download.js b/src/snapshot/download.js index f7a72fad9fd..418ceb9a176 100644 --- a/src/snapshot/download.js +++ b/src/snapshot/download.js @@ -29,7 +29,7 @@ function downloadImage(gd, opts) { // default to png opts.format = opts.format || 'png'; - return new Promise(function(resolve,reject) { + return new Promise(function(resolve, reject) { if(gd._snapshotInProgress) { reject(new Error('Snapshotting already in progress.')); } @@ -51,7 +51,7 @@ function downloadImage(gd, opts) { promise.then(function(result) { gd._snapshotInProgress = false; - return fileSaver(result,filename); + return fileSaver(result, filename); }).then(function(name) { resolve(name); }).catch(function(err) { diff --git a/src/snapshot/index.js b/src/snapshot/index.js index 15473249544..4cbe774aa9c 100644 --- a/src/snapshot/index.js +++ b/src/snapshot/index.js @@ -15,7 +15,7 @@ function getDelay(fullLayout) { if(!fullLayout._has) return 0; // maybe we should add a 'gl' (and 'svg') layoutCategory ?? - return (fullLayout._has('gl3d')|| fullLayout._has('gl2d')) ? 500 : 0; + return (fullLayout._has('gl3d') || fullLayout._has('gl2d')) ? 500 : 0; } function getRedrawFunc(gd) { diff --git a/src/snapshot/svgtoimg.js b/src/snapshot/svgtoimg.js index 146259e633e..55d11bbf041 100644 --- a/src/snapshot/svgtoimg.js +++ b/src/snapshot/svgtoimg.js @@ -31,16 +31,16 @@ function svgToImg(opts) { // Leave here just in case the CORS/tainted IE issue gets resolved if(Lib.isIE()) { // replace double quote with single quote - svg = svg.replace(/"/gi,'\''); + svg = svg.replace(/"/gi, '\''); // url in svg are single quoted // since we changed double to single // we'll need to change these to double-quoted - svg = svg.replace(/(\('#)(.*)('\))/gi,'(\"$2\")'); + svg = svg.replace(/(\('#)(.*)('\))/gi, '(\"$2\")'); // font names with spaces will be escaped single-quoted // we'll need to change these to double-quoted - svg = svg.replace(/(\\')/gi,'\"'); + svg = svg.replace(/(\\')/gi, '\"'); // IE only support svg - if(format!=='svg') { + if(format !== 'svg') { var ieSvgError = new Error('Sorry IE does not support downloading from canvas. Try {format:\'svg\'} instead.'); reject(ieSvgError); // eventually remove the ev diff --git a/src/traces/bar/calc.js b/src/traces/bar/calc.js index d4a702f0c83..7468cebdb48 100644 --- a/src/traces/bar/calc.js +++ b/src/traces/bar/calc.js @@ -22,12 +22,12 @@ module.exports = function calc(gd, trace) { // note: this logic for choosing orientation is // duplicated in graph_obj->setstyles - var xa = Axes.getFromId(gd, trace.xaxis||'x'), - ya = Axes.getFromId(gd, trace.yaxis||'y'), + var xa = Axes.getFromId(gd, trace.xaxis || 'x'), + ya = Axes.getFromId(gd, trace.yaxis || 'y'), orientation = trace.orientation || ((trace.x && !trace.y) ? 'h' : 'v'), pos, size, i; - if(orientation==='h') { + if(orientation === 'h') { size = xa.makeCalcdata(trace, 'x'); pos = ya.makeCalcdata(trace, 'y'); } @@ -39,7 +39,7 @@ module.exports = function calc(gd, trace) { // create the "calculated data" to plot var serieslen = Math.min(pos.length, size.length), cd = []; - for(i=0; i=2 ? roundWithLine(v) : + return Math.abs(v - vc) >= 2 ? roundWithLine(v) : // but if it's very thin, expand it so it's // necessarily visible, even if it might overlap // its neighbor - (v>vc ? Math.ceil(v) : Math.floor(v)); + (v > vc ? Math.ceil(v) : Math.floor(v)); } if(!gd._context.staticPlot) { // if bars are not fully opaque or they have a line @@ -92,15 +92,15 @@ module.exports = function plot(gd, plotinfo, cdbar) { // no line, expand to a full pixel to make sure we // can see them var op = Color.opacity(di.mc || trace.marker.color), - fixpx = (op<1 || lw>0.01) ? + fixpx = (op < 1 || lw > 0.01) ? roundWithLine : expandToVisible; - x0 = fixpx(x0,x1); - x1 = fixpx(x1,x0); - y0 = fixpx(y0,y1); - y1 = fixpx(y1,y0); + x0 = fixpx(x0, x1); + x1 = fixpx(x1, x0); + y0 = fixpx(y0, y1); + y1 = fixpx(y1, y0); } d3.select(this).attr('d', - 'M'+x0+','+y0+'V'+y1+'H'+x1+'V'+y0+'Z'); + 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z'); }); }); diff --git a/src/traces/bar/set_positions.js b/src/traces/bar/set_positions.js index a7d8027afb1..14daefccfe4 100644 --- a/src/traces/bar/set_positions.js +++ b/src/traces/bar/set_positions.js @@ -35,7 +35,7 @@ module.exports = function setPositions(gd, plotinfo) { pa = plotinfo[pLetter](), sa = plotinfo[sLetter](); - gd._fullData.forEach(function(trace,i) { + gd._fullData.forEach(function(trace, i) { if(trace.visible === true && Plots.traceIs(trace, 'bar') && trace.orientation === dir && @@ -74,7 +74,7 @@ module.exports = function setPositions(gd, plotinfo) { gd.calcdata[i].forEach(function(v) { if(overlap) return; comparelist.forEach(function(cp) { - if(Math.abs(v.p-cp) < barDiff) overlap = true; + if(Math.abs(v.p - cp) < barDiff) overlap = true; }); }); if(overlap) return; @@ -116,7 +116,7 @@ module.exports = function setPositions(gd, plotinfo) { else barposition(bl); var stack = (fullLayout.barmode === 'stack'), - relative = (fullLayout.barmode ==='relative'), + relative = (fullLayout.barmode === 'relative'), norm = fullLayout.barnorm; // bar size range and stacking calculation @@ -128,7 +128,7 @@ module.exports = function setPositions(gd, plotinfo) { // so we don't have to redo this later var sMax = sa.l2c(sa.c2l(0)), sMin = sMax, - sums={}, + sums = {}, // make sure if p is different only by rounding, // we still stack @@ -154,8 +154,8 @@ module.exports = function setPositions(gd, plotinfo) { if(stack || relative) { ti[j][sLetter] = barEnd; if(!norm && isNumeric(sa.c2l(barEnd))) { - sMax = Math.max(sMax,barEnd); - sMin = Math.min(sMin,barEnd); + sMax = Math.max(sMax, barEnd); + sMin = Math.min(sMin, barEnd); } } } @@ -163,9 +163,9 @@ module.exports = function setPositions(gd, plotinfo) { if(norm) { padded = false; - var top = norm==='fraction' ? 1 : 100, + var top = norm === 'fraction' ? 1 : 100, relAndNegative = false, - tiny = top/1e9; // in case of rounding error in sum + 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 diff --git a/src/traces/bar/style.js b/src/traces/bar/style.js index c53f68f5b8d..6d5835da6f2 100644 --- a/src/traces/bar/style.js +++ b/src/traces/bar/style.js @@ -28,11 +28,11 @@ module.exports = function style(gd) { // crispEdges to turn off antialiasing so an artificial gap // isn't introduced. .each(function(d) { - if((fullLayout.barmode==='stack' && barcount>1) || - (fullLayout.bargap===0 && - fullLayout.bargroupgap===0 && + if((fullLayout.barmode === 'stack' && barcount > 1) || + (fullLayout.bargap === 0 && + fullLayout.bargroupgap === 0 && !d[0].trace.marker.line.width)) { - d3.select(this).attr('shape-rendering','crispEdges'); + d3.select(this).attr('shape-rendering', 'crispEdges'); } }); @@ -41,7 +41,7 @@ module.exports = function style(gd) { var trace = d[0].trace, marker = trace.marker, markerLine = marker.line, - markerIn = (trace._input||{}).marker||{}, + markerIn = (trace._input || {}).marker || {}, markerScale = Drawing.tryColorscale(marker, markerIn, ''), lineScale = Drawing.tryColorscale(marker, markerIn, 'line.'); @@ -50,7 +50,7 @@ module.exports = function style(gd) { // by given max and min to colorscales var fillColor, lineColor, - lineWidth = (d.mlw+1 || markerLine.width+1) - 1, + lineWidth = (d.mlw + 1 || markerLine.width + 1) - 1, p = d3.select(this); if('mc' in d) fillColor = d.mcc = markerScale(d.mc); diff --git a/src/traces/box/calc.js b/src/traces/box/calc.js index 641df5c8792..cafd8eb16c7 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; @@ -51,13 +51,13 @@ module.exports = function calc(gd, trace) { var pos0; if(posLetter in trace) pos = posAxis.makeCalcdata(trace, posLetter); else { - if(posLetter+'0' in trace) pos0 = trace[posLetter+'0']; + if(posLetter + '0' in trace) pos0 = trace[posLetter + '0']; else if('name' in trace && ( - posAxis.type==='category' || + posAxis.type === 'category' || (isNumeric(trace.name) && - ['linear','log'].indexOf(posAxis.type)!==-1) || + ['linear', 'log'].indexOf(posAxis.type) !== -1) || (Lib.isDateTime(trace.name) && - posAxis.type==='date') + posAxis.type === 'date') )) { pos0 = trace.name; } @@ -73,7 +73,7 @@ module.exports = function calc(gd, trace) { // get distinct positions and min difference var dv = Lib.distinctVals(pos); posDistinct = dv.vals; - dPos = dv.minDiff/2; + dPos = dv.minDiff / 2; function binVal(cd, val, pos, posDistinct, dPos) { var posDistinctLength = posDistinct.length, @@ -89,14 +89,14 @@ module.exports = function calc(gd, trace) { bins[i] = p - dPos; valBinned[i] = []; } - bins.push(posDistinct[posDistinctLength-1] + dPos); + bins.push(posDistinct[posDistinctLength - 1] + dPos); // bin the values for(i = 0; i < valLength; ++i) { v = val[i]; if(!isNumeric(v)) continue; n = Lib.findBin(pos[i], bins); - if(n>=0 && n= 0 && n < valLength) valBinned[n].push(v); } return valBinned; @@ -115,22 +115,22 @@ module.exports = function calc(gd, trace) { cdi.val = v; // put all values into calcdata cdi.min = v[0]; - cdi.max = v[l-1]; - cdi.mean = Lib.mean(v,l); - cdi.sd = Lib.stdev(v,l,cdi.mean); + cdi.max = v[l - 1]; + cdi.mean = Lib.mean(v, l); + cdi.sd = Lib.stdev(v, l, cdi.mean); cdi.q1 = Lib.interp(v, 0.25); // first quartile cdi.med = Lib.interp(v, 0.5); // median cdi.q3 = Lib.interp(v, 0.75); // third quartile // lower and upper fences - last point inside // 1.5 interquartile ranges from quartiles cdi.lf = Math.min(cdi.q1, v[ - Math.min(Lib.findBin(2.5*cdi.q1-1.5*cdi.q3,v,true)+1, l-1)]); - cdi.uf = Math.max(cdi.q3,v[ - Math.max(Lib.findBin(2.5*cdi.q3-1.5*cdi.q1,v), 0)]); + Math.min(Lib.findBin(2.5 * cdi.q1 - 1.5 * cdi.q3, v, true) + 1, l - 1)]); + cdi.uf = Math.max(cdi.q3, v[ + Math.max(Lib.findBin(2.5 * cdi.q3 - 1.5 * cdi.q1, v), 0)]); // lower and upper outliers - 3 IQR out (don't clip to max/min, // this is only for discriminating suspected & far outliers) - cdi.lo = 4*cdi.q1-3*cdi.q3; - cdi.uo = 4*cdi.q3-3*cdi.q1; + cdi.lo = 4 * cdi.q1 - 3 * cdi.q3; + cdi.uo = 4 * cdi.q3 - 3 * cdi.q1; } } diff --git a/src/traces/box/defaults.js b/src/traces/box/defaults.js index 33d7f53fd1e..61d9653d8a9 100644 --- a/src/traces/box/defaults.js +++ b/src/traces/box/defaults.js @@ -35,7 +35,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor) { coerce('orientation', defaultOrientation); - coerce('line.color', (traceIn.marker||{}).color || defaultColor); + coerce('line.color', (traceIn.marker || {}).color || defaultColor); coerce('line.width', 2); coerce('fillcolor', Color.addOpacity(traceOut.line.color, 0.5)); @@ -49,8 +49,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor) { coerce('boxpoints'); if(boxpoints) { - coerce('jitter', boxpoints==='all' ? 0.3 : 0); - coerce('pointpos', boxpoints==='all' ? -1.5 : 0); + coerce('jitter', boxpoints === 'all' ? 0.3 : 0); + coerce('pointpos', boxpoints === 'all' ? -1.5 : 0); coerce('marker.symbol'); coerce('marker.opacity'); @@ -59,7 +59,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor) { coerce('marker.line.color'); coerce('marker.line.width'); - if(boxpoints==='suspectedoutliers') { + if(boxpoints === 'suspectedoutliers') { coerce('marker.line.outliercolor', traceOut.marker.color); coerce('marker.line.outlierwidth'); } diff --git a/src/traces/box/hover.js b/src/traces/box/hover.js index ef5fa9b52ae..34e3f06c7e9 100644 --- a/src/traces/box/hover.js +++ b/src/traces/box/hover.js @@ -26,7 +26,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { val, valLetter, valAxis; // adjust inbox w.r.t. to calculate box size - boxDelta = (hovermode==='closest') ? 2.5*t.bdPos : t.bdPos; + boxDelta = (hovermode === 'closest') ? 2.5 * t.bdPos : t.bdPos; if(trace.orientation === 'h') { dx = function(di) { @@ -58,31 +58,31 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { Fx.getClosest(cd, distfn, pointData); // skip the rest (for this trace) if we didn't find a close point - if(pointData.index===false) return; + if(pointData.index === false) return; // create the item(s) in closedata for this point // the closest data point var di = cd[pointData.index], lc = trace.line.color, - mc = (trace.marker||{}).color; + mc = (trace.marker || {}).color; if(Color.opacity(lc) && trace.line.width) pointData.color = lc; else if(Color.opacity(mc) && trace.boxpoints) pointData.color = mc; else pointData.color = trace.fillcolor; - pointData[posLetter+'0'] = posAxis.c2p(di.pos + t.bPos - t.bdPos, true); - pointData[posLetter+'1'] = posAxis.c2p(di.pos + t.bPos + t.bdPos, true); + pointData[posLetter + '0'] = posAxis.c2p(di.pos + t.bPos - t.bdPos, true); + pointData[posLetter + '1'] = posAxis.c2p(di.pos + t.bPos + t.bdPos, true); Axes.tickText(posAxis, posAxis.c2l(di.pos), 'hover').text; - pointData[posLetter+'LabelVal'] = di.pos; + pointData[posLetter + 'LabelVal'] = di.pos; // box plots: each "point" gets many labels var usedVals = {}, - attrs = ['med','min','q1','q3','max'], + attrs = ['med', 'min', 'q1', 'q3', 'max'], attr, pointData2; if(trace.boxmean) attrs.push('mean'); - if(trace.boxpoints) [].push.apply(attrs,['lf', 'uf']); + if(trace.boxpoints) [].push.apply(attrs, ['lf', 'uf']); for(var i = 0; i < attrs.length; i++) { attr = attrs[i]; @@ -93,12 +93,12 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { // copy out to a new object for each value to label val = valAxis.c2p(di[attr], true); pointData2 = Lib.extendFlat({}, pointData); - pointData2[valLetter+'0'] = pointData2[valLetter+'1'] = val; - pointData2[valLetter+'LabelVal'] = di[attr]; + pointData2[valLetter + '0'] = pointData2[valLetter + '1'] = val; + pointData2[valLetter + 'LabelVal'] = di[attr]; pointData2.attr = attr; - if(attr==='mean' && ('sd' in di) && trace.boxmean==='sd') { - pointData2[valLetter+'err'] = di.sd; + if(attr === 'mean' && ('sd' in di) && trace.boxmean === 'sd') { + pointData2[valLetter + 'err'] = di.sd; } pointData.name = ''; // only keep name on the first item (median) closeData.push(pointData2); diff --git a/src/traces/box/plot.js b/src/traces/box/plot.js index 71fbcf9c7e0..81b47d715c3 100644 --- a/src/traces/box/plot.js +++ b/src/traces/box/plot.js @@ -23,11 +23,11 @@ function seed() { function rand() { var lastVal = randSeed; - randSeed = (69069*randSeed + 1)%4294967296; + randSeed = (69069 * randSeed + 1) % 4294967296; // don't let consecutive vals be too close together // gets away from really trying to be random, in favor of better local uniformity if(Math.abs(randSeed - lastVal) < 429496729) return rand(); - return randSeed/4294967296; + return randSeed / 4294967296; } // constants for dynamic jitter (ie less jitter for sparser points) @@ -45,25 +45,25 @@ module.exports = function plot(gd, plotinfo, cdbox) { .selectAll('g.trace.boxes') .data(cdbox) .enter().append('g') - .attr('class','trace boxes'); + .attr('class', 'trace boxes'); boxtraces.each(function(d) { var t = d[0].t, trace = d[0].trace, - group = (fullLayout.boxmode==='group' && gd.numboxes>1), + group = (fullLayout.boxmode === 'group' && gd.numboxes > 1), // box half width - bdPos = t.dPos*(1-fullLayout.boxgap)*(1-fullLayout.boxgroupgap)/(group ? gd.numboxes : 1), + bdPos = t.dPos * (1 - fullLayout.boxgap) * (1 - fullLayout.boxgroupgap) / (group ? gd.numboxes : 1), // box center offset - bPos = group ? 2*t.dPos*(-0.5+(t.boxnum+0.5)/gd.numboxes)*(1-fullLayout.boxgap) : 0, + bPos = group ? 2 * t.dPos * (-0.5 + (t.boxnum + 0.5) / gd.numboxes) * (1 - fullLayout.boxgap) : 0, // whisker width - wdPos = bdPos*trace.whiskerwidth; + wdPos = bdPos * trace.whiskerwidth; if(trace.visible !== true || t.emptybox) { d3.select(this).remove(); return; } // set axis via orientation - if(trace.orientation==='h') { + if(trace.orientation === 'h') { posAxis = ya; valAxis = xa; } else { @@ -82,7 +82,7 @@ module.exports = function plot(gd, plotinfo, cdbox) { d3.select(this).selectAll('path.box') .data(Lib.identity) .enter().append('path') - .attr('class','box') + .attr('class', 'box') .each(function(d) { var posc = posAxis.c2p(d.pos + bPos, true), pos0 = posAxis.c2p(d.pos + bPos - bdPos, true), @@ -94,23 +94,23 @@ module.exports = function plot(gd, plotinfo, cdbox) { // make sure median isn't identical to either of the // quartiles, so we can see it m = Lib.constrain(valAxis.c2p(d.med, true), - Math.min(q1, q3)+1, Math.max(q1, q3)-1), - lf = valAxis.c2p(trace.boxpoints===false ? d.min : d.lf, true), - uf = valAxis.c2p(trace.boxpoints===false ? d.max : d.uf, true); + Math.min(q1, q3) + 1, Math.max(q1, q3) - 1), + lf = valAxis.c2p(trace.boxpoints === false ? d.min : d.lf, true), + uf = valAxis.c2p(trace.boxpoints === false ? d.max : d.uf, true); if(trace.orientation === 'h') { d3.select(this).attr('d', - 'M'+m+','+pos0+'V'+pos1+ // median line - 'M'+q1+','+pos0+'V'+pos1+'H'+q3+'V'+pos0+'Z'+ // box - 'M'+q1+','+posc+'H'+lf+'M'+q3+','+posc+'H'+uf+ // whiskers - ((trace.whiskerwidth===0) ? '' : // whisker caps - 'M'+lf+','+posw0+'V'+posw1+'M'+uf+','+posw0+'V'+posw1)); + 'M' + m + ',' + pos0 + 'V' + pos1 + // median line + 'M' + q1 + ',' + pos0 + 'V' + pos1 + 'H' + q3 + 'V' + pos0 + 'Z' + // box + 'M' + q1 + ',' + posc + 'H' + lf + 'M' + q3 + ',' + posc + 'H' + uf + // whiskers + ((trace.whiskerwidth === 0) ? '' : // whisker caps + 'M' + lf + ',' + posw0 + 'V' + posw1 + 'M' + uf + ',' + posw0 + 'V' + posw1)); } else { d3.select(this).attr('d', - 'M'+pos0+','+m+'H'+pos1+ // median line - 'M'+pos0+','+q1+'H'+pos1+'V'+q3+'H'+pos0+'Z'+ // box - 'M'+posc+','+q1+'V'+lf+'M'+posc+','+q3+'V'+uf+ // whiskers - ((trace.whiskerwidth===0) ? '' : // whisker caps - 'M'+posw0+','+lf+'H'+posw1+'M'+posw0+','+uf+'H'+posw1)); + 'M' + pos0 + ',' + m + 'H' + pos1 + // median line + 'M' + pos0 + ',' + q1 + 'H' + pos1 + 'V' + q3 + 'H' + pos0 + 'Z' + // box + 'M' + posc + ',' + q1 + 'V' + lf + 'M' + posc + ',' + q3 + 'V' + uf + // whiskers + ((trace.whiskerwidth === 0) ? '' : // whisker caps + 'M' + posw0 + ',' + lf + 'H' + posw1 + 'M' + posw0 + ',' + uf + 'H' + posw1)); } }); @@ -127,11 +127,11 @@ module.exports = function plot(gd, plotinfo, cdbox) { return d; }) .enter().append('g') - .attr('class','points') + .attr('class', 'points') .selectAll('path') .data(function(d) { - var pts = (trace.boxpoints==='all') ? d.val : - d.val.filter(function(v) { return (vd.uf); }), + var pts = (trace.boxpoints === 'all') ? d.val : + d.val.filter(function(v) { return (v < d.lf || v > d.uf); }), spreadLimit = (d.q3 - d.q1) * JITTERSPREAD, jitterFactors = [], maxJitterFactor = 0, @@ -144,18 +144,18 @@ module.exports = function plot(gd, plotinfo, cdbox) { // dynamic jitter if(trace.jitter) { - for(i=0; id.lo) { - p.so=true; + if(trace.boxpoints === 'suspectedoutliers' && v < d.uo && v > d.lo) { + p.so = true; } return p; }); @@ -198,26 +198,26 @@ module.exports = function plot(gd, plotinfo, cdbox) { d3.select(this).selectAll('path.mean') .data(Lib.identity) .enter().append('path') - .attr('class','mean') - .style('fill','none') + .attr('class', 'mean') + .style('fill', 'none') .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), m = valAxis.c2p(d.mean, true), - sl = valAxis.c2p(d.mean-d.sd, true), - sh = valAxis.c2p(d.mean+d.sd, true); - if(trace.orientation==='h') { + sl = valAxis.c2p(d.mean - d.sd, true), + sh = valAxis.c2p(d.mean + d.sd, true); + if(trace.orientation === 'h') { d3.select(this).attr('d', - 'M'+m+','+pos0+'V'+pos1+ - ((trace.boxmean!=='sd') ? '' : - 'm0,0L'+sl+','+posc+'L'+m+','+pos0+'L'+sh+','+posc+'Z')); + 'M' + m + ',' + pos0 + 'V' + pos1 + + ((trace.boxmean !== 'sd') ? '' : + 'm0,0L' + sl + ',' + posc + 'L' + m + ',' + pos0 + 'L' + sh + ',' + posc + 'Z')); } else { d3.select(this).attr('d', - 'M'+pos0+','+m+'H'+pos1+ - ((trace.boxmean!=='sd') ? '' : - 'm0,0L'+posc+','+sl+'L'+pos0+','+m+'L'+posc+','+sh+'Z')); + 'M' + pos0 + ',' + m + 'H' + pos1 + + ((trace.boxmean !== 'sd') ? '' : + 'm0,0L' + posc + ',' + sl + 'L' + pos0 + ',' + m + 'L' + posc + ',' + sh + 'Z')); } }); } diff --git a/src/traces/box/set_positions.js b/src/traces/box/set_positions.js index 63364919055..1666b0450b4 100644 --- a/src/traces/box/set_positions.js +++ b/src/traces/box/set_positions.js @@ -47,8 +47,8 @@ module.exports = function setPositions(gd, plotinfo) { trace.yaxis === ya._id) { boxlist.push(j); if(trace.boxpoints !== false) { - minPad = Math.max(minPad, trace.jitter-trace.pointpos-1); - maxPad = Math.max(maxPad, trace.jitter+trace.pointpos-1); + minPad = Math.max(minPad, trace.jitter - trace.pointpos - 1); + maxPad = Math.max(maxPad, trace.jitter + trace.pointpos - 1); } } } @@ -64,11 +64,11 @@ module.exports = function setPositions(gd, plotinfo) { // and then use for posAxis autorange var boxdv = Lib.distinctVals(boxpointlist), - dPos = boxdv.minDiff/2; + dPos = boxdv.minDiff / 2; // if there's no duplication of x points, // disable 'group' mode by setting numboxes=1 - if(boxpointlist.length===boxdv.vals.length) gd.numboxes = 1; + if(boxpointlist.length === boxdv.vals.length) gd.numboxes = 1; // check for forced minimum dtick Axes.minDtick(posAxis, boxdv.minDiff, boxdv.vals[0], true); @@ -81,11 +81,11 @@ module.exports = function setPositions(gd, plotinfo) { // autoscale the x axis - including space for points if they're off the side // TODO: this will overdo it if the outermost boxes don't have // their points as far out as the other boxes - var padfactor = (1-fullLayout.boxgap) * (1-fullLayout.boxgroupgap) * + var padfactor = (1 - fullLayout.boxgap) * (1 - fullLayout.boxgroupgap) * dPos / gd.numboxes; Axes.expand(posAxis, boxdv.vals, { - vpadminus: dPos+minPad*padfactor, - vpadplus: dPos+maxPad*padfactor + vpadminus: dPos + minPad * padfactor, + vpadplus: dPos + maxPad * padfactor }); } }; diff --git a/src/traces/box/style.js b/src/traces/box/style.js index 19216d93840..e890ce73f25 100644 --- a/src/traces/box/style.js +++ b/src/traces/box/style.js @@ -22,13 +22,13 @@ module.exports = function style(gd) { var trace = d[0].trace, lineWidth = trace.line.width; d3.select(this).selectAll('path.box') - .style('stroke-width', lineWidth+'px') + .style('stroke-width', lineWidth + 'px') .call(Color.stroke, trace.line.color) .call(Color.fill, trace.fillcolor); d3.select(this).selectAll('path.mean') .style({ 'stroke-width': lineWidth, - 'stroke-dasharray': (2*lineWidth)+'px,'+lineWidth+'px' + 'stroke-dasharray': (2 * lineWidth) + 'px,' + lineWidth + 'px' }) .call(Color.stroke, trace.line.color); d3.select(this).selectAll('g.points path') diff --git a/src/traces/contour/plot.js b/src/traces/contour/plot.js index fc71afb0032..f7c6b8ad16b 100644 --- a/src/traces/contour/plot.js +++ b/src/traces/contour/plot.js @@ -25,10 +25,10 @@ module.exports = function plot(gd, plotinfo, cdcontours) { // some constants to help with marching squares algorithm // where does the path start for each index? -var BOTTOMSTART = [1,9,13,104,713], - TOPSTART = [4,6,7,104,713], - LEFTSTART = [8,12,14,208,1114], - RIGHTSTART = [2,3,11,208,1114], +var BOTTOMSTART = [1, 9, 13, 104, 713], + TOPSTART = [4, 6, 7, 104, 713], + LEFTSTART = [8, 12, 14, 208, 1114], + RIGHTSTART = [2, 3, 11, 208, 1114], // which way [dx,dy] do we leave a given index? // saddles are already disambiguated @@ -87,9 +87,9 @@ function plotOne(gd, plotinfo, cd) { findAllPaths(pathinfo); var leftedge = xa.c2p(x[0], true), - rightedge = xa.c2p(x[x.length-1], true), + rightedge = xa.c2p(x[x.length - 1], true), bottomedge = ya.c2p(y[0], true), - topedge = ya.c2p(y[y.length-1], true), + topedge = ya.c2p(y[y.length - 1], true), perimeter = [ [leftedge, topedge], [rightedge, topedge], @@ -110,7 +110,7 @@ function plotOne(gd, plotinfo, cd) { function emptyPathinfo(contours, plotinfo, cd0) { var cs = contours.size || 1, pathinfo = []; - for(var ci = contours.start; ci < contours.end + cs/10; ci += cs) { + for(var ci = contours.start; ci < contours.end + cs / 10; ci += cs) { pathinfo.push({ level: ci, // all the cells with nontrivial marching index @@ -143,7 +143,7 @@ function emptyPathinfo(contours, plotinfo, cd0) { // except that the saddles bifurcate and I represent them // as the decimal combination of the two appropriate // non-saddle indices -function getMarchingIndex(val,corners) { +function getMarchingIndex(val, corners) { var mi = (corners[0][0] > val ? 0 : 1) + (corners[0][1] > val ? 0 : 2) + (corners[1][1] > val ? 0 : 4) + @@ -167,7 +167,7 @@ function makeCrossings(pathinfo) { var z = pathinfo[0].z, m = z.length, n = z[0].length, // we already made sure z isn't ragged in interp2d - twoWide = m===2 || n===2, + twoWide = m === 2 || n === 2, xi, yi, startIndices, @@ -178,26 +178,26 @@ function makeCrossings(pathinfo) { pi, i; - for(yi = 0; yi20) { - mi = CHOOSESADDLE[mi][(marchStep[0]||marchStep[1])<0 ? 0 : 1]; + for(cnt = 0; cnt < 10000; cnt++) { // just to avoid infinite loops + if(mi > 20) { + mi = CHOOSESADDLE[mi][(marchStep[0] || marchStep[1]) < 0 ? 0 : 1]; pi.crossings[locStr] = SADDLEREMAINDER[mi]; } else { @@ -248,23 +248,23 @@ function makePath(pi, loc, edgeflag) { loc[1] += marchStep[1]; // don't include the same point multiple times - if(equalPts(pts[pts.length-1], pts[pts.length-2])) pts.pop(); + if(equalPts(pts[pts.length - 1], pts[pts.length - 2])) pts.pop(); locStr = loc.join(','); // have we completed a loop, or reached an edge? - if((locStr===startLocStr && marchStep.join(',')===startStepStr) || + if((locStr === startLocStr && marchStep.join(',') === startStepStr) || (edgeflag && ( - (marchStep[0] && (loc[0]<0 || loc[0]>n-2)) || - (marchStep[1] && (loc[1]<0 || loc[1]>m-2))))) { + (marchStep[0] && (loc[0] < 0 || loc[0] > n - 2)) || + (marchStep[1] && (loc[1] < 0 || loc[1] > m - 2))))) { break; } mi = pi.crossings[locStr]; } - if(cnt===10000) { + if(cnt === 10000) { console.log('Infinite loop in contour?'); } - var closedpath = equalPts(pts[0], pts[pts.length-1]), + var closedpath = equalPts(pts[0], pts[pts.length - 1]), totaldist = 0, distThresholdFactor = 0.2 * pi.smoothing, alldists = [], @@ -280,58 +280,58 @@ function makePath(pi, loc, edgeflag) { // check for points that are too close together (<1/5 the average dist, // less if less smoothed) and just take the center (or avg of center 2) // this cuts down on funny behavior when a point is very close to a contour level - for(cnt=1; cnt=cropstart; cnt--) { + for(cnt = pts.length - 2; cnt >= cropstart; cnt--) { distgroup = alldists[cnt]; - if(distgroup=cropstart; cnt2--) { - if(distgroup+alldists[cnt2]= cropstart; cnt2--) { + if(distgroup + alldists[cnt2] < distThreshold) { distgroup += alldists[cnt2]; } else break; } // closed path with close points wrapping around the boundary? - if(closedpath && cnt===pts.length-2) { - for(cnt3=0; cnt320 && edgeflag) { + if(mi > 20 && edgeflag) { // these saddles start at +/- x - if(mi===208 || mi===1114) { + if(mi === 208 || mi === 1114) { // if we're starting at the left side, we must be going right - dx = loc[0]===0 ? 1 : -1; + dx = loc[0] === 0 ? 1 : -1; } else { // if we're starting at the bottom, we must be going up - dy = loc[1]===0 ? 1 : -1; + dy = loc[1] === 0 ? 1 : -1; } } - else if(BOTTOMSTART.indexOf(mi)!==-1) dy = 1; - else if(LEFTSTART.indexOf(mi)!==-1) dx = 1; - else if(TOPSTART.indexOf(mi)!==-1) dy = -1; + else if(BOTTOMSTART.indexOf(mi) !== -1) dy = 1; + else if(LEFTSTART.indexOf(mi) !== -1) dx = 1; + else if(TOPSTART.indexOf(mi) !== -1) dy = -1; else dx = -1; return [dx, dy]; } @@ -448,7 +448,7 @@ function equalPts(pt1, pt2) { function ptDist(pt1, pt2) { var dx = pt1[0] - pt2[0], dy = pt1[1] - pt2[1]; - return Math.sqrt(dx*dx + dy*dy); + return Math.sqrt(dx * dx + dy * dy); } function getInterpPx(pi, loc, step) { @@ -459,14 +459,14 @@ function getInterpPx(pi, loc, step) { ya = pi.yaxis; if(step[1]) { - var dx = (pi.level - zxy) / (pi.z[locy][locx+1] - zxy); - return [xa.c2p((1-dx) * pi.x[locx] + dx * pi.x[locx+1], true), + var dx = (pi.level - zxy) / (pi.z[locy][locx + 1] - zxy); + return [xa.c2p((1 - dx) * pi.x[locx] + dx * pi.x[locx + 1], true), ya.c2p(pi.y[locy], true)]; } else { - var dy = (pi.level - zxy) / (pi.z[locy+1][locx] - zxy); + var dy = (pi.level - zxy) / (pi.z[locy + 1][locx] - zxy); return [xa.c2p(pi.x[locx], true), - ya.c2p((1-dy) * pi.y[locy] + dy * pi.y[locy+1], true)]; + ya.c2p((1 - dy) * pi.y[locy] + dy * pi.y[locy + 1], true)]; } } @@ -486,25 +486,25 @@ function makeContourGroup(plotinfo, cd, id) { function makeBackground(plotgroup, perimeter, contours) { var bggroup = plotgroup.selectAll('g.contourbg').data([0]); - bggroup.enter().append('g').classed('contourbg',true); + bggroup.enter().append('g').classed('contourbg', true); var bgfill = bggroup.selectAll('path') - .data(contours.coloring==='fill' ? [0] : []); + .data(contours.coloring === 'fill' ? [0] : []); bgfill.enter().append('path'); bgfill.exit().remove(); bgfill - .attr('d','M'+perimeter.join('L')+'Z') - .style('stroke','none'); + .attr('d', 'M' + perimeter.join('L') + 'Z') + .style('stroke', 'none'); } function makeFills(plotgroup, pathinfo, perimeter, contours) { var fillgroup = plotgroup.selectAll('g.contourfill') .data([0]); fillgroup.enter().append('g') - .classed('contourfill',true); + .classed('contourfill', true); var fillitems = fillgroup.selectAll('path') - .data(contours.coloring==='fill' ? pathinfo : []); + .data(contours.coloring === 'fill' ? pathinfo : []); fillitems.enter().append('path'); fillitems.exit().remove(); fillitems.each(function(pi) { @@ -516,15 +516,15 @@ function makeFills(plotgroup, pathinfo, perimeter, contours) { var fullpath = joinAllPaths(pi, perimeter); if(!fullpath) d3.select(this).remove(); - else d3.select(this).attr('d',fullpath).style('stroke', 'none'); + else d3.select(this).attr('d', fullpath).style('stroke', 'none'); }); } function joinAllPaths(pi, perimeter) { var fullpath = (pi.edgepaths.length || pi.z[0][0] < pi.level) ? - '' : ('M'+perimeter.join('L')+'Z'), + '' : ('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, @@ -542,13 +542,13 @@ function joinAllPaths(pi, perimeter) { addpath = Drawing.smoothopen(pi.edgepaths[i], pi.smoothing); fullpath += newloop ? addpath : addpath.replace(/^M/, 'L'); startsleft.splice(startsleft.indexOf(i), 1); - endpt = pi.edgepaths[i][pi.edgepaths[i].length-1]; + endpt = pi.edgepaths[i][pi.edgepaths[i].length - 1]; nexti = -1; //now loop through sides, moving our endpoint until we find a new start - for(cnt=0; cnt<4; cnt++) { // just to prevent infinite loops + for(cnt = 0; cnt < 4; cnt++) { // just to prevent infinite loops if(!endpt) { - console.log('missing end?',i,pi); + console.log('missing end?', i, pi); break; } @@ -557,19 +557,19 @@ function joinAllPaths(pi, perimeter) { else if(isbottom(endpt)) newendpt = perimeter[3]; // right bottom else if(isright(endpt)) newendpt = perimeter[2]; // left bottom - for(possiblei=0; possiblei < pi.edgepaths.length; possiblei++) { + for(possiblei = 0; possiblei < pi.edgepaths.length; possiblei++) { var ptNew = pi.edgepaths[possiblei][0]; // is ptNew on the (horz. or vert.) segment from endpt to newendpt? - if(Math.abs(endpt[0]-newendpt[0]) < 0.01) { - if(Math.abs(endpt[0]-ptNew[0]) < 0.01 && - (ptNew[1]-endpt[1]) * (newendpt[1]-ptNew[1]) >= 0) { + if(Math.abs(endpt[0] - newendpt[0]) < 0.01) { + if(Math.abs(endpt[0] - ptNew[0]) < 0.01 && + (ptNew[1] - endpt[1]) * (newendpt[1] - ptNew[1]) >= 0) { newendpt = ptNew; nexti = possiblei; } } - else if(Math.abs(endpt[1]-newendpt[1]) < 0.01) { - if(Math.abs(endpt[1]-ptNew[1]) < 0.01 && - (ptNew[0]-endpt[0]) * (newendpt[0]-ptNew[0]) >= 0) { + else if(Math.abs(endpt[1] - newendpt[1]) < 0.01) { + if(Math.abs(endpt[1] - ptNew[1]) < 0.01 && + (ptNew[0] - endpt[0]) * (newendpt[0] - ptNew[0]) >= 0) { newendpt = ptNew; nexti = possiblei; } @@ -582,8 +582,8 @@ function joinAllPaths(pi, perimeter) { endpt = newendpt; - if(nexti>=0) break; - fullpath += 'L'+newendpt; + if(nexti >= 0) break; + fullpath += 'L' + newendpt; } if(nexti === pi.edgepaths.length) { @@ -595,7 +595,7 @@ function joinAllPaths(pi, perimeter) { // if we closed back on a loop we already included, // close it and start a new loop - newloop = (startsleft.indexOf(i)===-1); + newloop = (startsleft.indexOf(i) === -1); if(newloop) { i = startsleft[0]; fullpath += 'Z'; @@ -614,32 +614,32 @@ function makeLines(plotgroup, pathinfo, contours) { var smoothing = pathinfo[0].smoothing; var linegroup = plotgroup.selectAll('g.contourlevel') - .data(contours.showlines===false ? [] : pathinfo); + .data(contours.showlines === false ? [] : pathinfo); linegroup.enter().append('g') - .classed('contourlevel',true); + .classed('contourlevel', true); linegroup.exit().remove(); var opencontourlines = linegroup.selectAll('path.openline') .data(function(d) { return d.edgepaths; }); opencontourlines.enter().append('path') - .classed('openline',true); + .classed('openline', true); opencontourlines.exit().remove(); opencontourlines .attr('d', function(d) { return Drawing.smoothopen(d, smoothing); }) - .style('stroke-miterlimit',1); + .style('stroke-miterlimit', 1); var closedcontourlines = linegroup.selectAll('path.closedline') .data(function(d) { return d.paths; }); closedcontourlines.enter().append('path') - .classed('closedline',true); + .classed('closedline', true); closedcontourlines.exit().remove(); closedcontourlines .attr('d', function(d) { return Drawing.smoothclosed(d, smoothing); }) - .style('stroke-miterlimit',1); + .style('stroke-miterlimit', 1); } function clipGaps(plotGroup, plotinfo, cd0, perimeter) { diff --git a/src/traces/heatmap/calc.js b/src/traces/heatmap/calc.js index a48af753fe6..ec9b33a9a5a 100644 --- a/src/traces/heatmap/calc.js +++ b/src/traces/heatmap/calc.js @@ -27,8 +27,8 @@ module.exports = function calc(gd, trace) { // prepare the raw data // run makeCalcdata on x and y even for heatmaps, in case of category mappings - var xa = Axes.getFromId(gd, trace.xaxis||'x'), - ya = Axes.getFromId(gd, trace.yaxis||'y'), + var xa = Axes.getFromId(gd, trace.xaxis || 'x'), + ya = Axes.getFromId(gd, trace.yaxis || 'y'), isContour = Plots.traceIs(trace, 'contour'), isHist = Plots.traceIs(trace, 'histogram'), zsmooth = isContour ? 'best' : trace.zsmooth, @@ -82,25 +82,25 @@ module.exports = function calc(gd, trace) { // check whether we really can smooth (ie all boxes are about the same size) if(zsmooth === 'fast') { - if(xa.type==='log' || ya.type==='log') { + if(xa.type === 'log' || ya.type === 'log') { noZsmooth('log axis found'); } else if(!isHist) { if(x.length) { - var avgdx = (x[x.length-1]-x[0]) / (x.length-1), - maxErrX = Math.abs(avgdx/100); - for(i=0; imaxErrX) { + var avgdx = (x[x.length - 1] - x[0]) / (x.length - 1), + maxErrX = Math.abs(avgdx / 100); + for(i = 0; i < x.length - 1; i++) { + if(Math.abs(x[i + 1] - x[i] - avgdx) > maxErrX) { noZsmooth('x scale is not linear'); break; } } } if(y.length && zsmooth === 'fast') { - var avgdy = (y[y.length-1]-y[0])/(y.length-1), - maxErrY = Math.abs(avgdy/100); - for(i=0; imaxErrY) { + var avgdy = (y[y.length - 1] - y[0]) / (y.length - 1), + maxErrY = Math.abs(avgdy / 100); + for(i = 0; i < y.length - 1; i++) { + if(Math.abs(y[i + 1] - y[i] - avgdy) > maxErrY) { noZsmooth('y scale is not linear'); break; } @@ -111,9 +111,9 @@ module.exports = function calc(gd, trace) { // create arrays of brick boundaries, to be used by autorange and heatmap.plot var xlen = maxRowLength(z), - xIn = trace.xtype==='scaled' ? '' : trace.x, + xIn = trace.xtype === 'scaled' ? '' : trace.x, xArray = makeBoundArray(trace, xIn, x0, dx, xlen, xa), - yIn = trace.ytype==='scaled' ? '' : trace.y, + yIn = trace.ytype === 'scaled' ? '' : trace.y, yArray = makeBoundArray(trace, yIn, y0, dy, z.length, ya); Axes.expand(xa, xArray); @@ -124,7 +124,7 @@ module.exports = function calc(gd, trace) { // auto-z and autocolorscale if applicable colorscaleCalc(trace, z, '', 'z'); - if(isContour && trace.contours && trace.contours.coloring==='heatmap') { + if(isContour && trace.contours && trace.contours.coloring === 'heatmap') { var hmType = trace.type === 'contour' ? 'heatmap' : 'histogram2d'; cd0.xfill = makeBoundArray(hmType, xIn, x0, dx, xlen, xa); cd0.yfill = makeBoundArray(hmType, yIn, y0, dy, z.length, ya); @@ -177,7 +177,7 @@ function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, ax) { dv, i; - if(Array.isArray(arrayIn) && !isHist && (ax.type!=='category')) { + if(Array.isArray(arrayIn) && !isHist && (ax.type !== 'category')) { arrayIn = arrayIn.map(ax.d2c); var len = arrayIn.length; @@ -187,13 +187,13 @@ function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, ax) { if(len <= numbricks) { // contour plots only want the centers if(isContour || isGL2D) arrayOut = arrayIn.slice(0, numbricks); - else if(numbricks === 1) arrayOut = [arrayIn[0]-0.5,arrayIn[0]+0.5]; + else if(numbricks === 1) arrayOut = [arrayIn[0] - 0.5, arrayIn[0] + 0.5]; else { - arrayOut = [1.5*arrayIn[0]-0.5*arrayIn[1]]; - for(i=1; i=z[0].length || ny<0 || ny>z.length) { + if(nx < 0 || nx >= z[0].length || ny < 0 || ny > z.length) { return; } } - else if(Fx.inbox(xval-x[0], xval-x[x.length-1]) > Fx.MAXDIST || - Fx.inbox(yval-y[0], yval-y[y.length-1]) > Fx.MAXDIST) { + else if(Fx.inbox(xval - x[0], xval - x[x.length - 1]) > Fx.MAXDIST || + Fx.inbox(yval - y[0], yval - y[y.length - 1]) > Fx.MAXDIST) { return; } else { if(contour) { var i2; - x2 = [2*x[0]-x[1]]; + x2 = [2 * x[0] - x[1]]; - for(i2=1; i2v) { + else if(size[n] > v) { size[n] = v; - return v-size[n]; + return v - size[n]; } } return 0; @@ -62,9 +62,9 @@ module.exports = { size[n] = v; return v; } - else if(size[n]=0 && n= 0 && n < nMax) total += binfunc(n, i, size, rawCounterData, counts); } // average and/or normalize the data, if needed @@ -102,15 +102,15 @@ module.exports = function calc(gd, trace) { var serieslen = Math.min(pos.length, size.length), cd = [], firstNonzero = 0, - lastNonzero = serieslen-1; + lastNonzero = serieslen - 1; // look for empty bins at the ends to remove, so autoscale omits them - for(i=0; ifirstNonzero; i--) { + for(i = serieslen - 1; i > firstNonzero; i--) { if(size[i]) { lastNonzero = i; break; @@ -118,7 +118,7 @@ module.exports = function calc(gd, trace) { } // create the "calculated data" to plot - for(i=firstNonzero; i<=lastNonzero; i++) { + for(i = firstNonzero; i <= lastNonzero; i++) { if((isNumeric(pos[i]) && isNumeric(size[i]))) { cd.push({p: pos[i], s: size[i], b: 0}); } diff --git a/src/traces/histogram/defaults.js b/src/traces/histogram/defaults.js index 61effc4f338..a415ff00797 100644 --- a/src/traces/histogram/defaults.js +++ b/src/traces/histogram/defaults.js @@ -29,17 +29,17 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout coerce('text'); var orientation = coerce('orientation', (y && !x) ? 'h' : 'v'), - sample = traceOut[orientation==='v' ? 'x' : 'y']; + sample = traceOut[orientation === 'v' ? 'x' : 'y']; if(!(sample && sample.length)) { traceOut.visible = false; return; } - var hasAggregationData = traceOut[orientation==='h' ? 'x' : 'y']; + var hasAggregationData = traceOut[orientation === 'h' ? 'x' : 'y']; if(hasAggregationData) coerce('histfunc'); - var binDirections = (orientation==='h') ? ['y'] : ['x']; + var binDirections = (orientation === 'h') ? ['y'] : ['x']; handleBinDefaults(traceIn, traceOut, coerce, binDirections); handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout); diff --git a/src/traces/histogram/norm_functions.js b/src/traces/histogram/norm_functions.js index b2c541a6508..eafe0bbe86f 100644 --- a/src/traces/histogram/norm_functions.js +++ b/src/traces/histogram/norm_functions.js @@ -13,21 +13,21 @@ module.exports = { percent: function(size, total) { var nMax = size.length, - norm = 100/total; - for(var n=0; nserieslen) x.splice(serieslen, x.length-serieslen); - if(y.length>serieslen) y.splice(serieslen, y.length-serieslen); + if(x.length > serieslen) x.splice(serieslen, x.length - serieslen); + if(y.length > serieslen) y.splice(serieslen, y.length - serieslen); Lib.markTime('done convert data'); // calculate the bins if(trace.autobinx || !('xbins' in trace)) { trace.xbins = Axes.autoBin(x, xa, trace.nbinsx, '2d'); - if(trace.type==='histogram2dcontour') { + if(trace.type === 'histogram2dcontour') { trace.xbins.start -= trace.xbins.size; trace.xbins.end += trace.xbins.size; } @@ -47,8 +47,8 @@ module.exports = function calc(gd, trace) { trace._input.xbins = trace.xbins; } if(trace.autobiny || !('ybins' in trace)) { - trace.ybins = Axes.autoBin(y,ya,trace.nbinsy,'2d'); - if(trace.type==='histogram2dcontour') { + trace.ybins = Axes.autoBin(y, ya, trace.nbinsy, '2d'); + if(trace.type === 'histogram2dcontour') { trace.ybins.start -= trace.ybins.size; trace.ybins.end += trace.ybins.size; } @@ -60,16 +60,16 @@ module.exports = function calc(gd, trace) { z = []; var onecol = [], zerocol = [], - xbins = (typeof(trace.xbins.size)==='string') ? [] : trace.xbins, - ybins = (typeof(trace.xbins.size)==='string') ? [] : trace.ybins, + xbins = (typeof(trace.xbins.size) === 'string') ? [] : trace.xbins, + ybins = (typeof(trace.xbins.size) === 'string') ? [] : trace.ybins, total = 0, n, m, - counts=[], + counts = [], norm = trace.histnorm, func = trace.histfunc, - densitynorm = (norm.indexOf('density')!==-1), - extremefunc = (func==='max' || func==='min'), + densitynorm = (norm.indexOf('density') !== -1), + extremefunc = (func === 'max' || func === 'min'), sizeinit = (extremefunc ? null : 0), binfunc = binFunctions.count, normfunc = normFunctions[norm], @@ -86,8 +86,8 @@ module.exports = function calc(gd, trace) { trace.z : (('marker' in trace && Array.isArray(trace.marker.color)) ? trace.marker.color : ''); - if(rawCounterData && func!=='count') { - doavg = func==='avg'; + if(rawCounterData && func !== 'count') { + doavg = func === 'avg'; binfunc = binFunctions[func]; } @@ -96,8 +96,8 @@ module.exports = function calc(gd, trace) { binend = binspec.end + (binspec.start - Axes.tickIncrement(binspec.start, binspec.size)) / 1e6; - for(i=binspec.start; i=0 && n=0 && m= 0 && n < nx && m >= 0 && m < ny) { total += binfunc(n, i, z[m], rawCounterData, counts[m]); } } // normalize, if needed if(doavg) { - for(m=0; m=0 - [[],[]] // y>=0: x<0, x>=0 + [[], []], // y<0: x<0, x>=0 + [[], []] // y>=0: x<0, x>=0 ], hasOutsideText = false; @@ -580,8 +580,8 @@ function scalePies(cdpie, plotSize) { pieBoxHeight / maxExtent(trace.tilt, Math.cos(tiltAxisRads), trace.depth) ) / (2 + 2 * maxPull); - cd0.cx = plotSize.l + plotSize.w * (trace.domain.x[1] + trace.domain.x[0])/2; - cd0.cy = plotSize.t + plotSize.h * (2 - trace.domain.y[1] - trace.domain.y[0])/2; + cd0.cx = plotSize.l + plotSize.w * (trace.domain.x[1] + trace.domain.x[0]) / 2; + cd0.cy = plotSize.t + plotSize.h * (2 - trace.domain.y[1] - trace.domain.y[0]) / 2; if(trace.scalegroup && scaleGroups.indexOf(trace.scalegroup) === -1) { scaleGroups.push(trace.scalegroup); diff --git a/src/traces/scatter/hover.js b/src/traces/scatter/hover.js index 8ade45b51b1..737a6509149 100644 --- a/src/traces/scatter/hover.js +++ b/src/traces/scatter/hover.js @@ -25,17 +25,17 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { // always will show up regardless of point size, but // prioritize smaller points var rad = Math.max(3, di.mrc || 0); - return Math.max(Math.abs(xa.c2p(di.x)-xa.c2p(xval))-rad, 1-3/rad); + return Math.max(Math.abs(xa.c2p(di.x) - xa.c2p(xval)) - rad, 1 - 3 / rad); }, dy = function(di) { var rad = Math.max(3, di.mrc || 0); - return Math.max(Math.abs(ya.c2p(di.y)-ya.c2p(yval))-rad, 1-3/rad); + return Math.max(Math.abs(ya.c2p(di.y) - ya.c2p(yval)) - rad, 1 - 3 / rad); }, dxy = function(di) { var rad = Math.max(3, di.mrc || 0), - dx = Math.abs(xa.c2p(di.x)-xa.c2p(xval)), - dy = Math.abs(ya.c2p(di.y)-ya.c2p(yval)); - return Math.max(Math.sqrt(dx*dx + dy*dy)-rad, 1-3/rad); + dx = Math.abs(xa.c2p(di.x) - xa.c2p(xval)), + dy = Math.abs(ya.c2p(di.y) - ya.c2p(yval)); + return Math.max(Math.sqrt(dx * dx + dy * dy) - rad, 1 - 3 / rad); }, distfn = Fx.getDistanceFunction(hovermode, dx, dy, dxy); diff --git a/src/traces/scatter/plot.js b/src/traces/scatter/plot.js index 7c10cf41732..2044c854fa1 100644 --- a/src/traces/scatter/plot.js +++ b/src/traces/scatter/plot.js @@ -244,14 +244,14 @@ function selectMarkers(gd, plotinfo, cdscatter) { if(mnum === 0) return; var cd = d.filter(function(v) { - return v.x>=xr[0] && v.x<=xr[1] && v.y>=yr[0] && v.y<=yr[1]; + return v.x >= xr[0] && v.x <= xr[1] && v.y >= yr[0] && v.y <= yr[1]; }), inc = Math.ceil(cd.length / mnum), tnum = 0; cdscatter.forEach(function(cdj, j) { var tracei = cdj[0].trace; if(subTypes.hasMarkers(tracei) && - tracei.marker.maxdisplayed>0 && j 0 && j < i) { tnum++; } }); @@ -260,7 +260,7 @@ function selectMarkers(gd, plotinfo, cdscatter) { // display this formula offsets successive traces by 1/3 of the // increment, adding an extra small amount after each triplet so // it's not quite periodic - var i0 = Math.round(tnum*inc/3 + Math.floor(tnum/3) * inc/7.1); + var i0 = Math.round(tnum * inc / 3 + Math.floor(tnum / 3) * inc / 7.1); // for error bars: save in cd which markers to show // so we don't have to repeat this diff --git a/src/traces/scatter/select.js b/src/traces/scatter/select.js index 25362f12186..2743ca83fca 100644 --- a/src/traces/scatter/select.js +++ b/src/traces/scatter/select.js @@ -57,7 +57,7 @@ module.exports = function selectPoints(searchInfo, polygon) { // d.dim in pointStyle in case something goes wrong with selection. cd[0].node3.selectAll('path.point') .style('opacity', function(d) { - return ((d.mo+1 || opacity+1) - 1) * (d.dim ? DESELECTDIM : 1); + return ((d.mo + 1 || opacity + 1) - 1) * (d.dim ? DESELECTDIM : 1); }); cd[0].node3.selectAll('text') .style('opacity', function(d) { diff --git a/src/traces/scatter3d/attributes.js b/src/traces/scatter3d/attributes.js index d43fadce201..56a3b78bd57 100644 --- a/src/traces/scatter3d/attributes.js +++ b/src/traces/scatter3d/attributes.js @@ -41,7 +41,7 @@ function makeProjectionAttr(axLetter) { role: 'style', min: 0, max: 10, - dflt: 2/3, + dflt: 2 / 3, description: [ 'Sets the scale factor determining the size of the', 'projection marker points.' diff --git a/src/traces/scatter3d/calc_errors.js b/src/traces/scatter3d/calc_errors.js index 47e892458ab..9897ffa7e85 100644 --- a/src/traces/scatter3d/calc_errors.js +++ b/src/traces/scatter3d/calc_errors.js @@ -50,7 +50,7 @@ function calculateErrors(data, scaleFactor) { var errorBounds = new Array(n); for(var i = 0; i < n; i++) { - var bound = [[0,0,0], [0,0,0]]; + var bound = [[0, 0, 0], [0, 0, 0]]; for(var j = 0; j < 3; j++) { if(errors[j]) { diff --git a/src/traces/scatter3d/convert.js b/src/traces/scatter3d/convert.js index 01588df0ed6..434850fb8ba 100644 --- a/src/traces/scatter3d/convert.js +++ b/src/traces/scatter3d/convert.js @@ -36,8 +36,8 @@ function LineWithMarkers(scene, uid) { this.mode = ''; this.dataPoints = []; this.axesBounds = [ - [-Infinity,-Infinity,-Infinity], - [Infinity,Infinity,Infinity] + [-Infinity, -Infinity, -Infinity], + [Infinity, Infinity, Infinity] ]; this.textLabels = null; this.data = null; @@ -58,7 +58,7 @@ proto.handlePick = function(selection) { selection.object = this.scatterPlot; this.scatterPlot.highlight(selection.data); } - if(this.textLabels && this.textLabels[selection.data.index]!==undefined) { + if(this.textLabels && this.textLabels[selection.data.index] !== undefined) { selection.textLabel = this.textLabels[selection.data.index]; } else selection.textLabel = ''; @@ -75,13 +75,13 @@ proto.handlePick = function(selection) { }; function constructDelaunay(points, color, axis) { - var u = (axis+1)%3; - var v = (axis+2)%3; + var u = (axis + 1) % 3; + var v = (axis + 2) % 3; var filteredPoints = []; var filteredIds = []; var i; - for(i=0; i= 0) coerce('surfacecolor', lineColor || markerColor); diff --git a/src/traces/scattergl/convert.js b/src/traces/scattergl/convert.js index 36ef0556dca..98f0b3da500 100644 --- a/src/traces/scattergl/convert.js +++ b/src/traces/scattergl/convert.js @@ -208,9 +208,9 @@ function _convertColor(colors, opacities, count) { var result = new Array(4 * count); for(var i = 0; i < count; ++i) { - for(var j = 0; j < 3; ++j) result[4*i+j] = colors[i][j]; + for(var j = 0; j < 3; ++j) result[4 * i + j] = colors[i][j]; - result[4*i+3] = colors[i][3] * opacities[i]; + result[4 * i + 3] = colors[i][3] * opacities[i]; } return result; @@ -447,8 +447,8 @@ proto.updateFancy = function(options) { this.scatterOptions.borderWidths[i] = 0.5 * borderWidths[index]; for(j = 0; j < 4; ++j) { - this.scatterOptions.colors[4*i+j] = colors[4*index+j]; - this.scatterOptions.borderColors[4*i+j] = borderColors[4*index+j]; + this.scatterOptions.colors[4 * i + j] = colors[4 * index + j]; + this.scatterOptions.borderColors[4 * i + j] = borderColors[4 * index + j]; } } @@ -479,7 +479,7 @@ proto.updateLines = function(options, positions) { var y = this.yData; linePositions = new Float32Array(2 * x.length); - for(i=0; i)' at the moment - var clipPathId = clipPathAttr.substring(5, clipPathAttr.length-1); + var clipPathId = clipPathAttr.substring(5, clipPathAttr.length - 1); var clipBBox = getClipBBox(clipPathId); return minBBox(elementBBox, clipBBox); diff --git a/test/jasmine/assets/mouse_event.js b/test/jasmine/assets/mouse_event.js index 5c09af0de76..9800215bbfa 100644 --- a/test/jasmine/assets/mouse_event.js +++ b/test/jasmine/assets/mouse_event.js @@ -10,7 +10,7 @@ module.exports = function(type, x, y, opts) { fullOpts.buttons = opts.buttons; } - var el = document.elementFromPoint(x,y); + var el = document.elementFromPoint(x, y); var ev = new window.MouseEvent(type, fullOpts); el.dispatchEvent(ev); }; diff --git a/test/jasmine/tests/axes_test.js b/test/jasmine/tests/axes_test.js index 8b58b06ded4..ce1ac5106a2 100644 --- a/test/jasmine/tests/axes_test.js +++ b/test/jasmine/tests/axes_test.js @@ -18,7 +18,7 @@ describe('Test axes', function() { describe('swap', function() { it('should swap most attributes and fix placeholder titles', function() { var gd = { - data: [{x: [1,2,3], y: [1,2,3]}], + data: [{x: [1, 2, 3], y: [1, 2, 3]}], layout: { xaxis: { title: 'A Title!!!', @@ -57,7 +57,7 @@ describe('Test axes', function() { // for reference: // noSwapAttrs = ['anchor', 'domain', 'overlaying', 'position', 'side', 'tickangle']; var gd = { - data: [{x: [1,2,3], y: [1,2,3]}], + data: [{x: [1, 2, 3], y: [1, 2, 3]}], layout: { xaxis: { anchor: 'free', @@ -87,8 +87,8 @@ describe('Test axes', function() { it('should swap shared attributes, combine linear/log, and move annotations', function() { var gd = { data: [ - {x: [1,2,3], y: [1,2,3]}, - {x: [1,2,3], y: [1,2,3], xaxis: 'x2'} + {x: [1, 2, 3], y: [1, 2, 3]}, + {x: [1, 2, 3], y: [1, 2, 3], xaxis: 'x2'} ], layout: { xaxis: { @@ -400,25 +400,25 @@ describe('Test axes', function() { describe('setting, or not setting categoryorder if it is not explicitly declared', function() { it('should set categoryorder to default if categoryorder and categoryarray are not supplied', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {xaxis: {type: 'category'}}); + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], {xaxis: {type: 'category'}}); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); expect(gd._fullLayout.xaxis.categorarray).toBe(undefined); }); it('should set categoryorder to default even if type is not set to category explicitly', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}]); + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}]); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); expect(gd._fullLayout.xaxis.categorarray).toBe(undefined); }); it('should NOT set categoryorder to default if type is not category', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}]); + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}]); expect(gd._fullLayout.yaxis.categoryorder).toBe(undefined); expect(gd._fullLayout.xaxis.categorarray).toBe(undefined); }); it('should set categoryorder to default if type is overridden to be category', function() { - PlotlyInternal.plot(gd, [{x: [1,2,3,4,5], y: [15,11,12,13,14]}], {yaxis: {type: 'category'}}); + PlotlyInternal.plot(gd, [{x: [1, 2, 3, 4, 5], y: [15, 11, 12, 13, 14]}], {yaxis: {type: 'category'}}); expect(gd._fullLayout.xaxis.categoryorder).toBe(undefined); expect(gd._fullLayout.yaxis.categorarray).toBe(undefined); expect(gd._fullLayout.yaxis.categoryorder).toBe('trace'); @@ -430,23 +430,23 @@ describe('Test axes', function() { describe('setting categoryorder to "array"', function() { it('should leave categoryorder on "array" if it is supplied', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { - xaxis: {type: 'category', categoryorder: 'array', categoryarray: ['b','a','d','e','c']} + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { + xaxis: {type: 'category', categoryorder: 'array', categoryarray: ['b', 'a', 'd', 'e', 'c']} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('array'); - expect(gd._fullLayout.xaxis.categoryarray).toEqual(['b','a','d','e','c']); + expect(gd._fullLayout.xaxis.categoryarray).toEqual(['b', 'a', 'd', 'e', 'c']); }); it('should switch categoryorder on "array" if it is not supplied but categoryarray is supplied', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { - xaxis: {type: 'category', categoryarray: ['b','a','d','e','c']} + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { + xaxis: {type: 'category', categoryarray: ['b', 'a', 'd', 'e', 'c']} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('array'); - expect(gd._fullLayout.xaxis.categoryarray).toEqual(['b','a','d','e','c']); + expect(gd._fullLayout.xaxis.categoryarray).toEqual(['b', 'a', 'd', 'e', 'c']); }); it('should revert categoryorder to "trace" if "array" is supplied but there is no list', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: {type: 'category', categoryorder: 'array'} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); @@ -458,7 +458,7 @@ describe('Test axes', function() { describe('do not set categoryorder to "array" if list exists but empty', function() { it('should switch categoryorder to default if list is not supplied', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: {type: 'category', categoryorder: 'array', categoryarray: []} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); @@ -466,7 +466,7 @@ describe('Test axes', function() { }); it('should not switch categoryorder on "array" if categoryarray is supplied but empty', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: {type: 'category', categoryarray: []} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); @@ -477,24 +477,24 @@ describe('Test axes', function() { describe('do NOT set categoryorder to "array" if it has some other proper value', function() { it('should use specified categoryorder if it is supplied even if categoryarray exists', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { - xaxis: {type: 'category', categoryorder: 'trace', categoryarray: ['b','a','d','e','c']} + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { + xaxis: {type: 'category', categoryorder: 'trace', categoryarray: ['b', 'a', 'd', 'e', 'c']} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); expect(gd._fullLayout.xaxis.categoryarray).toBe(undefined); }); it('should use specified categoryorder if it is supplied even if categoryarray exists', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { - xaxis: {type: 'category', categoryorder: 'category ascending', categoryarray: ['b','a','d','e','c']} + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { + xaxis: {type: 'category', categoryorder: 'category ascending', categoryarray: ['b', 'a', 'd', 'e', 'c']} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('category ascending'); expect(gd._fullLayout.xaxis.categoryarray).toBe(undefined); }); it('should use specified categoryorder if it is supplied even if categoryarray exists', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { - xaxis: {type: 'category', categoryorder: 'category descending', categoryarray: ['b','a','d','e','c']} + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { + xaxis: {type: 'category', categoryorder: 'category descending', categoryarray: ['b', 'a', 'd', 'e', 'c']} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('category descending'); expect(gd._fullLayout.xaxis.categoryarray).toBe(undefined); @@ -505,7 +505,7 @@ describe('Test axes', function() { describe('setting categoryorder to the default if the value is unexpected', function() { it('should switch categoryorder to "trace" if mode is supplied but invalid', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: {type: 'category', categoryorder: 'invalid value'} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); @@ -513,11 +513,11 @@ describe('Test axes', function() { }); it('should switch categoryorder to "array" if mode is supplied but invalid and list is supplied', function() { - PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { - xaxis: {type: 'category', categoryorder: 'invalid value', categoryarray: ['b','a','d','e','c']} + PlotlyInternal.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { + xaxis: {type: 'category', categoryorder: 'invalid value', categoryarray: ['b', 'a', 'd', 'e', 'c']} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('array'); - expect(gd._fullLayout.xaxis.categoryarray).toEqual(['b','a','d','e','c']); + expect(gd._fullLayout.xaxis.categoryarray).toEqual(['b', 'a', 'd', 'e', 'c']); }); }); @@ -525,7 +525,7 @@ describe('Test axes', function() { }); describe('handleTickDefaults', function() { - var data = [{ x: [1,2,3], y: [3,4,5] }], + var data = [{ x: [1, 2, 3], y: [3, 4, 5] }], gd; beforeEach(function() { @@ -657,7 +657,7 @@ describe('Test axes', function() { expect(axOut.tick0).toBe(undefined); expect(axOut.dtick).toBe(undefined); - axIn = {tickvals: [1,2,3], tick0: 1, dtick: 1}; + axIn = {tickvals: [1, 2, 3], tick0: 1, dtick: 1}; axOut = {}; mockSupplyDefaults(axIn, axOut, 'linear'); expect(axOut.tick0).toBe(undefined); @@ -677,17 +677,17 @@ describe('Test axes', function() { }); it('should set tickvals and ticktext iff tickmode=array', function() { - var axIn = {tickmode: 'auto', tickvals: [1,2,3], ticktext: ['4','5','6']}, + var axIn = {tickmode: 'auto', tickvals: [1, 2, 3], ticktext: ['4', '5', '6']}, axOut = {}; mockSupplyDefaults(axIn, axOut, 'linear'); expect(axOut.tickvals).toBe(undefined); expect(axOut.ticktext).toBe(undefined); - axIn = {tickvals: [2,4,6,8], ticktext: ['who','do','we','appreciate']}; + axIn = {tickvals: [2, 4, 6, 8], ticktext: ['who', 'do', 'we', 'appreciate']}; axOut = {}; mockSupplyDefaults(axIn, axOut, 'linear'); - expect(axOut.tickvals).toEqual([2,4,6,8]); - expect(axOut.ticktext).toEqual(['who','do','we','appreciate']); + expect(axOut.tickvals).toEqual([2, 4, 6, 8]); + expect(axOut.ticktext).toEqual(['who', 'do', 'we', 'appreciate']); }); }); @@ -809,7 +809,7 @@ describe('Test axes', function() { } }; - expect(listFunc(gd, '' , true)) + expect(listFunc(gd, '', true)) .toEqual([{ _id: 'x2' }, { _id: 'y2' }]); }); diff --git a/test/jasmine/tests/calcdata_test.js b/test/jasmine/tests/calcdata_test.js index d727f51c904..fb9c3049994 100644 --- a/test/jasmine/tests/calcdata_test.js +++ b/test/jasmine/tests/calcdata_test.js @@ -16,14 +16,14 @@ describe('calculated data and points', function() { describe('connectGaps', function() { it('should exclude null and undefined points when false', function() { - Plotly.plot(gd, [{ x: [1,2,3,undefined,5], y: [1,null,3,4,5]}], {}); + Plotly.plot(gd, [{ x: [1, 2, 3, undefined, 5], y: [1, null, 3, 4, 5]}], {}); expect(gd.calcdata[0][1]).toEqual({ x: false, y: false}); expect(gd.calcdata[0][3]).toEqual({ x: false, y: false}); }); it('should exclude null and undefined points as categories when false', function() { - Plotly.plot(gd, [{ x: [1,2,3,undefined,5], y: [1,null,3,4,5] }], { xaxis: { type: 'category' }}); + Plotly.plot(gd, [{ x: [1, 2, 3, undefined, 5], y: [1, null, 3, 4, 5] }], { xaxis: { type: 'category' }}); expect(gd.calcdata[0][1]).toEqual({ x: false, y: false}); expect(gd.calcdata[0][3]).toEqual({ x: false, y: false}); @@ -36,7 +36,7 @@ describe('calculated data and points', function() { it('should output categories in the given order by default', function() { - Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category' }}); @@ -49,7 +49,7 @@ describe('calculated data and points', function() { it('should output categories in the given order if `trace` order is explicitly specified', function() { - Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'trace' // Also, if axis tick order is made configurable, shouldn't we make trace order configurable? @@ -70,7 +70,7 @@ describe('calculated data and points', function() { it('should output categories in ascending domain alphanumerical order', function() { - Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'category ascending' }}); @@ -84,7 +84,7 @@ describe('calculated data and points', function() { it('should output categories in descending domain alphanumerical order', function() { - Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'category descending' }}); @@ -98,7 +98,7 @@ describe('calculated data and points', function() { it('should output categories in ascending domain alphanumerical order even if categories are all numbers', function() { - Plotly.plot(gd, [{x: [3,1,5,2,4], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: [3, 1, 5, 2, 4], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'category ascending' }}); @@ -112,10 +112,10 @@ describe('calculated data and points', function() { it('should output categories in categoryorder order even if category array is defined', function() { - Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'category ascending', - categoryarray: ['b','a','d','e','c'] // These must be ignored. Alternative: error? + categoryarray: ['b', 'a', 'd', 'e', 'c'] // These must be ignored. Alternative: error? }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 2, y: 15})); @@ -127,7 +127,7 @@ describe('calculated data and points', function() { it('should output categories in ascending domain alphanumerical order, excluding undefined', function() { - Plotly.plot(gd, [{x: ['c',undefined,'e','b','d'], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', undefined, 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'category ascending' }}); @@ -143,10 +143,10 @@ describe('calculated data and points', function() { it('should output categories in explicitly supplied order, independent of trace order', function() { - Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'array', - categoryarray: ['b','a','d','e','c'] + categoryarray: ['b', 'a', 'd', 'e', 'c'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 4, y: 15})); @@ -158,10 +158,10 @@ describe('calculated data and points', function() { it('should output categories in explicitly supplied order even if category values are all numbers', function() { - Plotly.plot(gd, [{x: [3,1,5,2,4], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: [3, 1, 5, 2, 4], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'array', - categoryarray: [2,1,4,5,3] + categoryarray: [2, 1, 4, 5, 3] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 4, y: 15})); @@ -173,10 +173,10 @@ describe('calculated data and points', function() { it('should output categories in explicitly supplied order, independent of trace order, pruned', function() { - Plotly.plot(gd, [{x: ['c',undefined,'e','b','d'], y: [15,11,12,null,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', undefined, 'e', 'b', 'd'], y: [15, 11, 12, null, 14]}], { xaxis: { type: 'category', categoryorder: 'array', - categoryarray: ['b','a','d','e','c'] + categoryarray: ['b', 'a', 'd', 'e', 'c'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 4, y: 15})); @@ -188,10 +188,10 @@ describe('calculated data and points', function() { it('should output categories in explicitly supplied order even if not all categories are present', function() { - Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'array', - categoryarray: ['b','x','a','d','z','e','c'] + categoryarray: ['b', 'x', 'a', 'd', 'z', 'e', 'c'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 6, y: 15})); @@ -203,10 +203,10 @@ describe('calculated data and points', function() { it('should output categories in explicitly supplied order even if some missing categories were at the beginning or end of categoryarray', function() { - Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'array', - categoryarray: ['y','b','x','a','d','z','e','c', 'q', 'k'] + categoryarray: ['y', 'b', 'x', 'a', 'd', 'z', 'e', 'c', 'q', 'k'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 7, y: 15})); @@ -230,10 +230,10 @@ describe('calculated data and points', function() { // BUT keeps it if a data point with null is added; test is almost identical to the one above // except that it explicitly adds an axis tick for y - Plotly.plot(gd, [{x: ['c','a','e','b','d', 'y'], y: [15,11,12,13,14, null]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd', 'y'], y: [15, 11, 12, 13, 14, null]}], { xaxis: { type: 'category', categoryorder: 'array', - categoryarray: ['y','b','x','a','d','z','e','c', 'q', 'k'] + categoryarray: ['y', 'b', 'x', 'a', 'd', 'z', 'e', 'c', 'q', 'k'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 7, y: 15})); @@ -250,10 +250,10 @@ describe('calculated data and points', function() { it('should output categories in explicitly supplied order even if not all categories are present, and should interact with a null value orthogonally', function() { - Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,null,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, null, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'array', - categoryarray: ['b','x','a','d','z','e','c'] + categoryarray: ['b', 'x', 'a', 'd', 'z', 'e', 'c'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 6, y: 15})); @@ -265,10 +265,10 @@ describe('calculated data and points', function() { it('should output categories in explicitly supplied order first, if not all categories are covered', function() { - Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: { + Plotly.plot(gd, [{x: ['c', 'a', 'e', 'b', 'd'], y: [15, 11, 12, 13, 14]}], { xaxis: { type: 'category', categoryorder: 'array', - categoryarray: ['b','a','x','c'] + categoryarray: ['b', 'a', 'x', 'c'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 3, y: 15})); @@ -326,7 +326,7 @@ describe('calculated data and points', function() { ], { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'trace', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 0, y: 10})); @@ -357,7 +357,7 @@ describe('calculated data and points', function() { ], { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'category ascending', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] // this is the expected sorted outcome: ['Bearing','Bulb','Cord','Fuse','Gear','Leak','Motor','Plug','Pump','Seals','Switch'] }}); @@ -389,7 +389,7 @@ describe('calculated data and points', function() { ], { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'category descending', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] // this is the expected sorted outcome: ["Switch", "Seals", "Pump", "Plug", "Motor", "Leak", "Gear", "Fuse", "Cord", "Bulb", "Bearing"] }}); @@ -421,7 +421,7 @@ describe('calculated data and points', function() { ], { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'array', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 9, y: 10})); @@ -483,7 +483,7 @@ describe('calculated data and points', function() { ], { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'trace', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 0, y: 10})); @@ -515,7 +515,7 @@ describe('calculated data and points', function() { ], { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'category ascending', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] // this is the expected sorted outcome: ['Bearing','Bulb','Cord','Fuse','Gear','Leak','Motor','Plug','Pump','Seals','Switch'] }}); @@ -548,7 +548,7 @@ describe('calculated data and points', function() { ], { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'category descending', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] // this is the expected sorted outcome: ["Switch", "Seals", "Pump", "Plug", "Motor", "Leak", "Gear", "Fuse", "Cord", "Bulb", "Bearing"] }}); @@ -581,7 +581,7 @@ describe('calculated data and points', function() { ], { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'array', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 9, y: 10})); @@ -641,7 +641,7 @@ describe('calculated data and points', function() { ], { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'trace', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] }}); expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 0, y: 10})); @@ -670,7 +670,7 @@ describe('calculated data and points', function() { ], { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'category ascending', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] // this is the expected sorted outcome: ['Bearing','Bulb','Cord','Fuse','Gear','Leak','Motor','Plug','Pump','Seals','Switch'] }}); @@ -700,7 +700,7 @@ describe('calculated data and points', function() { ], { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'category descending', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] // this is the expected sorted outcome: ["Switch", "Seals", "Pump", "Plug", "Motor", "Leak", "Gear", "Fuse", "Cord", "Bulb", "Bearing"] }}); @@ -731,7 +731,7 @@ describe('calculated data and points', function() { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'array', - categoryarray: ['Bearing','Motor','Gear'] + categoryarray: ['Bearing', 'Motor', 'Gear'] } }); @@ -762,7 +762,7 @@ describe('calculated data and points', function() { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'array', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] } }); @@ -797,7 +797,7 @@ describe('calculated data and points', function() { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'array', - categoryarray: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak'] + categoryarray: ['Switch', 'Bearing', 'Motor', 'Seals', 'Pump', 'Cord', 'Plug', 'Bulb', 'Fuse', 'Gear', 'Leak'] } }); @@ -832,7 +832,7 @@ describe('calculated data and points', function() { xaxis: { // type: 'category', // commented out to rely on autotyping for added realism categoryorder: 'array', - categoryarray: ['Bearing','Motor','Gear'] + categoryarray: ['Bearing', 'Motor', 'Gear'] } }); diff --git a/test/jasmine/tests/choropleth_test.js b/test/jasmine/tests/choropleth_test.js index 75e03d4533d..1cdcdcd28aa 100644 --- a/test/jasmine/tests/choropleth_test.js +++ b/test/jasmine/tests/choropleth_test.js @@ -20,7 +20,7 @@ describe('Test choropleth', function() { it('should slice z if it is longer than locations', function() { traceIn = { - locations: ['CAN','USA'], + locations: ['CAN', 'USA'], z: [1, 2, 3] }; diff --git a/test/jasmine/tests/colorscale_test.js b/test/jasmine/tests/colorscale_test.js index 776d84b118a..dba9936b7a1 100644 --- a/test/jasmine/tests/colorscale_test.js +++ b/test/jasmine/tests/colorscale_test.js @@ -365,7 +365,7 @@ describe('Test colorscale:', function() { z = [[undefined, undefined], [0.5, undefined]]; calcColorscale(trace, z, '', 'z'); expect(trace.autocolorscale).toBe(true); - expect(trace.colorscale[trace.colorscale.length-1]) + expect(trace.colorscale[trace.colorscale.length - 1]) .toEqual([1, 'rgb(220,220,220)']); }); @@ -373,12 +373,12 @@ describe('Test colorscale:', function() { describe('makeScaleFunction', function() { var scale = [ - [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)'] + [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)'] ], scaleFunction = Colorscale.makeScaleFunction(scale, 2, 3); diff --git a/test/jasmine/tests/config_test.js b/test/jasmine/tests/config_test.js index 13b28d9f96e..eeda25ab966 100644 --- a/test/jasmine/tests/config_test.js +++ b/test/jasmine/tests/config_test.js @@ -50,8 +50,8 @@ describe('config argument', function() { gd = createGraphDiv(); Plotly.plot(gd, [ - { x: [1,2,3], y: [1,2,3] }, - { x: [1,2,3], y: [3,2,1] } + { x: [1, 2, 3], y: [1, 2, 3] }, + { x: [1, 2, 3], y: [3, 2, 1] } ], { width: 600, height: 400, diff --git a/test/jasmine/tests/download_test.js b/test/jasmine/tests/download_test.js index f072e8918c6..40d68529e25 100644 --- a/test/jasmine/tests/download_test.js +++ b/test/jasmine/tests/download_test.js @@ -72,8 +72,8 @@ describe('Plotly.downloadImage', function() { // stop observing observer.disconnect(); // look for an added and removed link - var linkadded = domchanges[domchanges.length-2].addedNodes[0].outerHTML; - var linkdeleted = domchanges[domchanges.length-1].removedNodes[0].outerHTML; + var linkadded = domchanges[domchanges.length - 2].addedNodes[0].outerHTML; + var linkdeleted = domchanges[domchanges.length - 1].removedNodes[0].outerHTML; // check for a