diff --git a/.eslintrc b/.eslintrc index 185abda5ef4..330c1ef6ffa 100644 --- a/.eslintrc +++ b/.eslintrc @@ -29,7 +29,7 @@ "max-len": [0, 80], "brace-style": [0, "stroustrup", {"allowSingleLine": true}], "curly": [2, "multi-line"], - "camelcase": [0, {"properties": "never"}], + "camelcase": [2, {"properties": "never"}], "comma-spacing": [2, {"before": false, "after": true}], "comma-style": [2, "last"], "semi": [2], @@ -63,6 +63,7 @@ "no-shadow": [0, {"builtinGlobals": true}], "block-scoped-var": [2], "no-unused-vars": [2], + "one-var": [2, {"initialized": "never"}], "no-undef-init": [2], "no-use-before-define": [2, "nofunc"], "no-loop-func": [2], diff --git a/devtools/image_viewer/viewer.js b/devtools/image_viewer/viewer.js index 3d777b1de4d..71bcc494f51 100644 --- a/devtools/image_viewer/viewer.js +++ b/devtools/image_viewer/viewer.js @@ -3,16 +3,16 @@ var path = require('path'); var d3 = require('d3'); -var $plotlist = document.getElementById('plot-list'), - $toggles = document.getElementById('plot-toggles'), - $images = document.getElementById('plot-images'), - $mock = document.getElementById('plot-mock'), - $toggleBaseline = document.createElement('button'), - $toggleTest = document.createElement('button'), - $toggleDiff = document.createElement('button'), - $imgBaseline = document.createElement('img'), - $imgTest = document.createElement('img'), - $imgDiff = document.createElement('img'); +var $plotlist = document.getElementById('plot-list'); +var $toggles = document.getElementById('plot-toggles'); +var $images = document.getElementById('plot-images'); +var $mock = document.getElementById('plot-mock'); +var $toggleBaseline = document.createElement('button'); +var $toggleTest = document.createElement('button'); +var $toggleDiff = document.createElement('button'); +var $imgBaseline = document.createElement('img'); +var $imgTest = document.createElement('img'); +var $imgDiff = document.createElement('img'); $toggles.style.display = 'none'; $images.style.display = 'none'; @@ -21,13 +21,13 @@ setupToggle($toggleBaseline, $imgBaseline, 'Baseline'); setupToggle($toggleTest, $imgTest, 'Test'); setupToggle($toggleDiff, $imgDiff, 'Diff'); -var pathToRoot = path.join(__dirname, '../../'), - pathToImageTest = path.join(pathToRoot, 'test/image'), - pathToBuild = path.join(pathToRoot, 'build/'), - dirMocks = path.join(pathToImageTest, 'mocks/'), - dirBaseline = path.join(pathToImageTest, 'baselines/'), - dirTest = path.join(pathToBuild, 'test_images/'), - dirDiff = path.join(pathToBuild, 'test_images_diff/'); +var pathToRoot = path.join(__dirname, '../../'); +var pathToImageTest = path.join(pathToRoot, 'test/image'); +var pathToBuild = path.join(pathToRoot, 'build/'); +var dirMocks = path.join(pathToImageTest, 'mocks/'); +var dirBaseline = path.join(pathToImageTest, 'baselines/'); +var dirTest = path.join(pathToBuild, 'test_images/'); +var dirDiff = path.join(pathToBuild, 'test_images_diff/'); // N.B. brfs only understand hard-coded paths var imageNames = fs.readFileSync( diff --git a/devtools/test_dashboard/devtools.js b/devtools/test_dashboard/devtools.js index b1a0242dd20..8dbb9b3ab32 100644 --- a/devtools/test_dashboard/devtools.js +++ b/devtools/test_dashboard/devtools.js @@ -179,7 +179,8 @@ searchBar.addEventListener('keyup', debounce(searchMocks, 250)); function debounce(func, wait, immediate) { var timeout; return function() { - var context = this, args = arguments; + var context = this; + var args = arguments; var later = function() { timeout = null; if(!immediate) func.apply(context, args); diff --git a/package-lock.json b/package-lock.json index 290bb5a6d0e..a3d40162289 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3283,9 +3283,9 @@ } }, "eslint": { - "version": "5.10.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.10.0.tgz", - "integrity": "sha512-HpqzC+BHULKlnPwWae9MaVZ5AXJKpkxCVXQHrFaRw3hbDj26V/9ArYM4Rr/SQ8pi6qUPLXSSXC4RBJlyq2Z2OQ==", + "version": "5.11.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.11.0.tgz", + "integrity": "sha512-gbEg0ttToZPkZUv2yYjpipxuYrv/9aSSmgM4V6GkiO3u04QosHYBtduUCqLEulEg3YvNDAkk3OWzyQJ/heZ3Nw==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", @@ -3334,9 +3334,9 @@ "dev": true }, "debug": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz", - "integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", "dev": true, "requires": { "ms": "^2.1.1" diff --git a/package.json b/package.json index 0de26499922..0836953cce2 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "deep-equal": "^1.0.1", "derequire": "^2.0.6", "ecstatic": "^3.3.0", - "eslint": "^5.10.0", + "eslint": "^5.11.0", "falafel": "^2.0.0", "fs-extra": "^2.0.0", "fuse.js": "^3.3.0", diff --git a/src/components/annotations/click.js b/src/components/annotations/click.js index e9bb11aae89..15e5882db8f 100644 --- a/src/components/annotations/click.js +++ b/src/components/annotations/click.js @@ -82,11 +82,11 @@ function onClick(gd, hoverData) { * } */ function getToggleSets(gd, hoverData) { - var annotations = gd._fullLayout.annotations, - onSet = [], - offSet = [], - explicitOffSet = [], - hoverLen = (hoverData || []).length; + var annotations = gd._fullLayout.annotations; + var onSet = []; + var offSet = []; + var explicitOffSet = []; + var hoverLen = (hoverData || []).length; var i, j, anni, showMode, pointj, xa, ya, toggleType; diff --git a/src/components/annotations/convert_coords.js b/src/components/annotations/convert_coords.js index 5da3832457e..b8a40904d70 100644 --- a/src/components/annotations/convert_coords.js +++ b/src/components/annotations/convert_coords.js @@ -28,19 +28,19 @@ var toLogRange = require('../../lib/to_log_range'); module.exports = function convertCoords(gd, ax, newType, doExtra) { ax = ax || {}; - var toLog = (newType === 'log') && (ax.type === 'linear'), - fromLog = (newType === 'linear') && (ax.type === 'log'); + var toLog = (newType === 'log') && (ax.type === 'linear'); + var fromLog = (newType === 'linear') && (ax.type === 'log'); if(!(toLog || fromLog)) return; - var annotations = gd._fullLayout.annotations, - axLetter = ax._id.charAt(0), - ann, - attrPrefix; + var annotations = gd._fullLayout.annotations; + var axLetter = ax._id.charAt(0); + var ann; + var attrPrefix; function convert(attr) { - var currentVal = ann[attr], - newVal = null; + var currentVal = ann[attr]; + var newVal = null; if(toLog) newVal = toLogRange(currentVal, ax.range); else newVal = Math.pow(10, currentVal); diff --git a/src/components/annotations/defaults.js b/src/components/annotations/defaults.js index b04657c2995..497841055ac 100644 --- a/src/components/annotations/defaults.js +++ b/src/components/annotations/defaults.js @@ -39,9 +39,10 @@ function handleAnnotationDefaults(annIn, annOut, fullLayout) { var showArrow = annOut.showarrow; // positioning - var axLetters = ['x', 'y'], - arrowPosDflt = [-10, -30], - gdMock = {_fullLayout: fullLayout}; + var axLetters = ['x', 'y']; + var arrowPosDflt = [-10, -30]; + var gdMock = {_fullLayout: fullLayout}; + for(var i = 0; i < 2; i++) { var axLetter = axLetters[i]; @@ -57,9 +58,9 @@ function handleAnnotationDefaults(annIn, annOut, fullLayout) { Axes.coercePosition(annOut, gdMock, coerce, axRef, axLetter, 0.5); if(showArrow) { - var arrowPosAttr = 'a' + axLetter, - // axref, ayref - aaxRef = Axes.coerceRef(annIn, annOut, gdMock, arrowPosAttr, 'pixel'); + var arrowPosAttr = 'a' + axLetter; + // axref, ayref + var aaxRef = Axes.coerceRef(annIn, annOut, gdMock, arrowPosAttr, 'pixel'); // for now the arrow can only be on the same axis or specified as pixels // TODO: sometime it might be interesting to allow it to be on *any* axis diff --git a/src/components/annotations/draw.js b/src/components/annotations/draw.js index 5ad8f8d09ee..c9901349fc4 100644 --- a/src/components/annotations/draw.js +++ b/src/components/annotations/draw.js @@ -117,8 +117,8 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { // calculated pixel positions // x & y each will get text, head, and tail as appropriate - var annPosPx = {x: {}, y: {}}, - textangle = +options.textangle || 0; + var annPosPx = {x: {}, y: {}}; + var textangle = +options.textangle || 0; // create the components // made a single group to contain all, so opacity can work right @@ -185,9 +185,9 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { }); } - var borderwidth = options.borderwidth, - borderpad = options.borderpad, - borderfull = borderwidth + borderpad; + var borderwidth = options.borderwidth; + var borderpad = options.borderpad; + var borderfull = borderwidth + borderpad; var annTextBG = annTextGroupInner.append('rect') .attr('class', 'bg') @@ -270,24 +270,24 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { var letters = ['x', 'y']; for(var i = 0; i < letters.length; i++) { - var axLetter = letters[i], - axRef = options[axLetter + 'ref'] || axLetter, - tailRef = options['a' + axLetter + 'ref'], - ax = {x: xa, y: ya}[axLetter], - dimAngle = (textangle + (axLetter === 'x' ? 0 : -90)) * Math.PI / 180, - // note that these two can be either positive or negative - annSizeFromWidth = outerWidth * Math.cos(dimAngle), - annSizeFromHeight = outerHeight * Math.sin(dimAngle), - // but this one is the positive total size - annSize = Math.abs(annSizeFromWidth) + Math.abs(annSizeFromHeight), - anchor = options[axLetter + 'anchor'], - overallShift = options[axLetter + 'shift'] * (axLetter === 'x' ? 1 : -1), - posPx = annPosPx[axLetter], - basePx, - textPadShift, - alignPosition, - autoAlignFraction, - textShift; + var axLetter = letters[i]; + var axRef = options[axLetter + 'ref'] || axLetter; + var tailRef = options['a' + axLetter + 'ref']; + var ax = {x: xa, y: ya}[axLetter]; + var dimAngle = (textangle + (axLetter === 'x' ? 0 : -90)) * Math.PI / 180; + // note that these two can be either positive or negative + var annSizeFromWidth = outerWidth * Math.cos(dimAngle); + var annSizeFromHeight = outerHeight * Math.sin(dimAngle); + // but this one is the positive total size + var annSize = Math.abs(annSizeFromWidth) + Math.abs(annSizeFromHeight); + var anchor = options[axLetter + 'anchor']; + var overallShift = options[axLetter + 'shift'] * (axLetter === 'x' ? 1 : -1); + var posPx = annPosPx[axLetter]; + var basePx; + var textPadShift; + var alignPosition; + var autoAlignFraction; + var textShift; /* * calculate the *primary* pixel position @@ -353,8 +353,8 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { posPx.head = Lib.constrain(posPx.head, 1, maxPx - 1); } if(tailRef === 'pixel') { - var shiftPlus = -Math.max(posPx.tail - 3, posPx.text), - shiftMinus = Math.min(posPx.tail + 3, posPx.text) - maxPx; + var shiftPlus = -Math.max(posPx.tail - 3, posPx.text); + var shiftMinus = Math.min(posPx.tail + 3, posPx.text) - maxPx; if(shiftPlus > 0) { posPx.tail += shiftPlus; posPx.text += shiftPlus; @@ -451,32 +451,32 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { .selectAll('.annotation-arrow-g') .remove(); - var headX = annPosPx.x.head, - headY = annPosPx.y.head, - tailX = annPosPx.x.tail + dx, - tailY = annPosPx.y.tail + dy, - textX = annPosPx.x.text + dx, - textY = annPosPx.y.text + dy, - - // find the edge of the text box, where we'll start the arrow: - // create transform matrix to rotate the text box corners - transform = Lib.rotationXYMatrix(textangle, textX, textY), - applyTransform = Lib.apply2DTransform(transform), - applyTransform2 = Lib.apply2DTransform2(transform), - - // calculate and transform bounding box - width = +annTextBG.attr('width'), - height = +annTextBG.attr('height'), - xLeft = textX - 0.5 * width, - xRight = xLeft + width, - yTop = textY - 0.5 * height, - yBottom = yTop + height, - edges = [ - [xLeft, yTop, xLeft, yBottom], - [xLeft, yBottom, xRight, yBottom], - [xRight, yBottom, xRight, yTop], - [xRight, yTop, xLeft, yTop] - ].map(applyTransform2); + var headX = annPosPx.x.head; + var headY = annPosPx.y.head; + var tailX = annPosPx.x.tail + dx; + var tailY = annPosPx.y.tail + dy; + var textX = annPosPx.x.text + dx; + var textY = annPosPx.y.text + dy; + + // find the edge of the text box, where we'll start the arrow: + // create transform matrix to rotate the text box corners + var transform = Lib.rotationXYMatrix(textangle, textX, textY); + var applyTransform = Lib.apply2DTransform(transform); + var applyTransform2 = Lib.apply2DTransform2(transform); + + // calculate and transform bounding box + var width = +annTextBG.attr('width'); + var height = +annTextBG.attr('height'); + var xLeft = textX - 0.5 * width; + var xRight = xLeft + width; + var yTop = textY - 0.5 * height; + var yBottom = yTop + height; + var edges = [ + [xLeft, yTop, xLeft, yBottom], + [xLeft, yBottom, xRight, yBottom], + [xRight, yBottom, xRight, yTop], + [xRight, yTop, xLeft, yTop] + ].map(applyTransform2); // Remove the line if it ends inside the box. Use ray // casting for rotated boxes: see which edges intersect a @@ -500,9 +500,9 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { } }); - var strokewidth = options.arrowwidth, - arrowColor = options.arrowcolor, - arrowSide = options.arrowside; + var strokewidth = options.arrowwidth; + var arrowColor = options.arrowcolor; + var arrowSide = options.arrowside; var arrowGroup = annGroup.append('g') .style({opacity: Color.opacity(arrowColor)}) @@ -557,9 +557,9 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { } }, moveFn: function(dx, dy) { - var annxy0 = applyTransform(annx0, anny0), - xcenter = annxy0[0] + dx, - ycenter = annxy0[1] + dy; + var annxy0 = applyTransform(annx0, anny0); + var xcenter = annxy0[0] + dx; + var ycenter = annxy0[1] + dy; annTextGroupInner.call(Drawing.setTranslate, xcenter, ycenter); modifyItem('x', xa ? @@ -629,9 +629,8 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { xUpdate = xa.p2r(xa.r2p(options.x) + dx); } else { - var widthFraction = options._xsize / gs.w, - xLeft = options.x + (options._xshift - options.xshift) / gs.w - - widthFraction / 2; + var widthFraction = options._xsize / gs.w; + var xLeft = options.x + (options._xshift - options.xshift) / gs.w - widthFraction / 2; xUpdate = dragElement.align(xLeft + dx / gs.w, widthFraction, 0, 1, options.xanchor); @@ -640,9 +639,8 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { if(ya) { yUpdate = ya.p2r(ya.r2p(options.y) + dy); } else { - var heightFraction = options._ysize / gs.h, - yBottom = options.y - (options._yshift + options.yshift) / gs.h - - heightFraction / 2; + var heightFraction = options._ysize / gs.h; + var yBottom = options.y - (options._yshift + options.yshift) / gs.h - heightFraction / 2; yUpdate = dragElement.align(yBottom - dy / gs.h, heightFraction, 0, 1, options.yanchor); diff --git a/src/components/annotations/draw_arrow_head.js b/src/components/annotations/draw_arrow_head.js index c3b7dc93db4..55fc1002c88 100644 --- a/src/components/annotations/draw_arrow_head.js +++ b/src/components/annotations/draw_arrow_head.js @@ -69,8 +69,8 @@ module.exports = function drawArrowHead(el3, ends, options) { hideLine(); return; } - var backOffX = backOff * Math.cos(startRot), - backOffY = backOff * Math.sin(startRot); + var backOffX = backOff * Math.cos(startRot); + var backOffY = backOff * Math.sin(startRot); end.x += backOffX; end.y += backOffY; @@ -83,8 +83,8 @@ module.exports = function drawArrowHead(el3, ends, options) { hideLine(); return; } - var startBackOffX = startBackOff * Math.cos(startRot), - startbackOffY = startBackOff * Math.sin(startRot); + var startBackOffX = startBackOff * Math.cos(startRot); + var startbackOffY = startBackOff * Math.sin(startRot); start.x -= startBackOffX; start.y -= startbackOffY; @@ -93,12 +93,12 @@ module.exports = function drawArrowHead(el3, ends, options) { } } else if(el.nodeName === 'path') { - var pathlen = el.getTotalLength(), - // using dash to hide the backOff region of the path. - // if we ever allow dash for the arrow we'll have to - // do better than this hack... maybe just manually - // combine the two - dashArray = ''; + var pathlen = el.getTotalLength(); + // using dash to hide the backOff region of the path. + // if we ever allow dash for the arrow we'll have to + // do better than this hack... maybe just manually + // combine the two + var dashArray = ''; if(pathlen < backOff + startBackOff) { hideLine(); diff --git a/src/components/calendars/index.js b/src/components/calendars/index.js index 616ad35902e..495f58fe0b6 100644 --- a/src/components/calendars/index.js +++ b/src/components/calendars/index.js @@ -126,10 +126,11 @@ var d3ToWorldCalendars = { }; function worldCalFmt(fmt, x, calendar) { - var dateJD = Math.floor((x + 0.05) / ONEDAY) + EPOCHJD, - cDate = getCal(calendar).fromJD(dateJD), - i = 0, - modifier, directive, directiveLen, directiveObj, replacementPart; + var dateJD = Math.floor((x + 0.05) / ONEDAY) + EPOCHJD; + var cDate = getCal(calendar).fromJD(dateJD); + var i = 0; + var modifier, directive, directiveLen, directiveObj, replacementPart; + while((i = fmt.indexOf('%', i)) !== -1) { modifier = fmt.charAt(i + 1); if(modifier === '0' || modifier === '-' || modifier === '_') { diff --git a/src/components/color/index.js b/src/components/color/index.js index ce9e6f616f5..2fab6abeaf7 100644 --- a/src/components/color/index.js +++ b/src/components/color/index.js @@ -47,17 +47,17 @@ color.combine = function(front, back) { var fc = tinycolor(front).toRgb(); if(fc.a === 1) return tinycolor(front).toRgbString(); - var bc = tinycolor(back || 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 - }; + var bc = tinycolor(back || background).toRgb(); + var 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 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 + }; return tinycolor(fcflat).toRgbString(); }; @@ -99,11 +99,8 @@ color.fill = function(s, c) { color.clean = function(container) { if(!container || typeof container !== 'object') return; - var keys = Object.keys(container), - i, - j, - key, - val; + var keys = Object.keys(container); + var i, j, key, val; for(i = 0; i < keys.length; i++) { key = keys[i]; @@ -142,8 +139,8 @@ function cleanOne(val) { var match = valTrim.match(/^rgba?\s*\(([^()]*)\)$/); if(!match) return val; - var parts = match[1].trim().split(/\s*[\s,]\s*/), - rgba = valTrim.charAt(3) === 'a' && parts.length === 4; + var parts = match[1].trim().split(/\s*[\s,]\s*/); + var rgba = valTrim.charAt(3) === 'a' && parts.length === 4; if(!rgba && parts.length !== 3) return val; for(var i = 0; i < parts.length; i++) { diff --git a/src/components/colorbar/defaults.js b/src/components/colorbar/defaults.js index 8225f2d0801..6594c536ec6 100644 --- a/src/components/colorbar/defaults.js +++ b/src/components/colorbar/defaults.js @@ -18,10 +18,9 @@ var handleTickLabelDefaults = require('../../plots/cartesian/tick_label_defaults var attributes = require('./attributes'); - module.exports = function colorbarDefaults(containerIn, containerOut, layout) { - var colorbarOut = Template.newContainer(containerOut, 'colorbar'), - colorbarIn = containerIn.colorbar || {}; + var colorbarOut = Template.newContainer(containerOut, 'colorbar'); + var colorbarIn = containerIn.colorbar || {}; function coerce(attr, dflt) { return Lib.coerce(colorbarIn, colorbarOut, attributes, attr, dflt); diff --git a/src/components/colorbar/draw.js b/src/components/colorbar/draw.js index 8e5b968fa06..340ba1282c9 100644 --- a/src/components/colorbar/draw.js +++ b/src/components/colorbar/draw.js @@ -64,8 +64,8 @@ module.exports = function draw(gd, id) { opts.zrange = null; function component() { - var fullLayout = gd._fullLayout, - gs = fullLayout._size; + var fullLayout = gd._fullLayout; + var gs = fullLayout._size; if((typeof opts.fillcolor !== 'function') && (typeof opts.line.color !== 'function') && !opts.fillgradient) { @@ -83,10 +83,10 @@ module.exports = function draw(gd, id) { var l; var i; - 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]); + var l0 = opts.levels.end + opts.levels.size / 100; + var ls = opts.levels.size; + var zr0 = (1.001 * zrange[0] - 0.001 * zrange[1]); + var zr1 = (1.001 * zrange[1] - 0.001 * zrange[0]); for(i = 0; i < 1e5; i++) { l = opts.levels.start + i * ls; if(ls > 0 ? (l >= l0) : (l <= l0)) break; @@ -134,72 +134,70 @@ module.exports = function draw(gd, id) { // when the colorbar itself is pushing the margins. // but then the fractional size is calculated based on the // actual graph size, so that the axes will size correctly. - var plotHeight = gs.h, - plotWidth = gs.w, - thickPx = Math.round(opts.thickness * - (opts.thicknessmode === 'fraction' ? plotWidth : 1)), - thickFrac = thickPx / gs.w, - lenPx = Math.round(opts.len * - (opts.lenmode === 'fraction' ? plotHeight : 1)), - lenFrac = lenPx / gs.h, - 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), - // for dragging... this is getting a little muddled... - xLeftFrac = opts.x - thickFrac * - ({middle: 0.5, right: 1}[opts.xanchor]||0), - - // 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, - titleEl, - cbAxisIn = { - type: 'linear', - range: zrange, - tickmode: opts.tickmode, - nticks: opts.nticks, - tick0: opts.tick0, - dtick: opts.dtick, - tickvals: opts.tickvals, - ticktext: opts.ticktext, - ticks: opts.ticks, - ticklen: opts.ticklen, - tickwidth: opts.tickwidth, - tickcolor: opts.tickcolor, - showticklabels: opts.showticklabels, - tickfont: opts.tickfont, - tickangle: opts.tickangle, - tickformat: opts.tickformat, - exponentformat: opts.exponentformat, - separatethousands: opts.separatethousands, - showexponent: opts.showexponent, - showtickprefix: opts.showtickprefix, - tickprefix: opts.tickprefix, - showticksuffix: opts.showticksuffix, - ticksuffix: opts.ticksuffix, - title: opts.title, - showline: true, - anchor: 'free', - side: 'right', - position: 1 - }, - cbAxisOut = { - type: 'linear', - _id: 'y' + id - }, - axisOptions = { - letter: 'y', - font: fullLayout.font, - noHover: true, - noTickson: true, - calendar: fullLayout.calendar // not really necessary (yet?) - }; + var plotHeight = gs.h; + var plotWidth = gs.w; + var thickPx = Math.round(opts.thickness * (opts.thicknessmode === 'fraction' ? plotWidth : 1)); + var thickFrac = thickPx / gs.w; + var lenPx = Math.round(opts.len * (opts.lenmode === 'fraction' ? plotHeight : 1)); + var lenFrac = lenPx / gs.h; + var xpadFrac = opts.xpad / gs.w; + var yExtraPx = (opts.borderwidth + opts.outlinewidth) / 2; + var 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) + var xLeft = Math.round(opts.x * gs.w + opts.xpad); + // for dragging... this is getting a little muddled... + var xLeftFrac = opts.x - thickFrac * ({middle: 0.5, right: 1}[opts.xanchor]||0); + + // y positioning we can do correctly from the start + var yBottomFrac = opts.y + lenFrac * (({top: -0.5, bottom: 0.5}[opts.yanchor] || 0) - 0.5); + var yBottomPx = Math.round(gs.h * (1 - yBottomFrac)); + var yTopPx = yBottomPx - lenPx; + + var titleEl; + + var cbAxisIn = { + type: 'linear', + range: zrange, + tickmode: opts.tickmode, + nticks: opts.nticks, + tick0: opts.tick0, + dtick: opts.dtick, + tickvals: opts.tickvals, + ticktext: opts.ticktext, + ticks: opts.ticks, + ticklen: opts.ticklen, + tickwidth: opts.tickwidth, + tickcolor: opts.tickcolor, + showticklabels: opts.showticklabels, + tickfont: opts.tickfont, + tickangle: opts.tickangle, + tickformat: opts.tickformat, + exponentformat: opts.exponentformat, + separatethousands: opts.separatethousands, + showexponent: opts.showexponent, + showtickprefix: opts.showtickprefix, + tickprefix: opts.tickprefix, + showticksuffix: opts.showticksuffix, + ticksuffix: opts.ticksuffix, + title: opts.title, + showline: true, + anchor: 'free', + side: 'right', + position: 1 + }; + var cbAxisOut = { + type: 'linear', + _id: 'y' + id + }; + var axisOptions = { + letter: 'y', + font: fullLayout.font, + noHover: true, + noTickson: true, + calendar: fullLayout.calendar // not really necessary (yet?) + }; // Coerce w.r.t. Axes layoutAttributes: // re-use axes.js logic without updating _fullData @@ -230,10 +228,8 @@ module.exports = function draw(gd, id) { cbAxisOut.tick0 = opts.levels.start; 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); + var autoNtick = Lib.constrain((yBottomPx - yTopPx) / 50, 4, 15) + 1; + var dtFactor = (zrange[1] - zrange[0]) / ((opts.nticks || autoNtick) * dtick); if(dtFactor > 1) { var dtexp = Math.pow(10, Math.floor( Math.log(dtFactor) / Math.LN10)); @@ -289,9 +285,9 @@ module.exports = function draw(gd, id) { // draw the title so we know how much room it needs // when we squish the axis. This one only applies to // top or bottom titles, not right side. - var x = gs.l + (opts.x + xpadFrac) * gs.w, - fontSize = cbAxisOut.title.font.size, - y; + var x = gs.l + (opts.x + xpadFrac) * gs.w; + var fontSize = cbAxisOut.title.font.size; + var y; if(opts.title.side === 'top') { y = (1 - (yBottomFrac + lenFrac - ypadFrac)) * gs.h + @@ -309,14 +305,13 @@ module.exports = function draw(gd, id) { function drawAxis() { if(['top', 'bottom'].indexOf(opts.title.side) !== -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], - mathJaxNode = titleGroup - .select('.h' + cbAxisOut._id + 'title-math-group') - .node(), - lineSize = 15.6; + var titleGroup = container.select('.cbtitle'); + var titleText = titleGroup.select('text'); + var titleTrans = [-opts.outlinewidth / 2, opts.outlinewidth / 2]; + var mathJaxNode = titleGroup + .select('.h' + cbAxisOut._id + 'title-math-group') + .node(); + var lineSize = 15.6; if(titleText.node()) { lineSize = parseInt(titleText.node().style.fontSize, 10) * LINE_SPACING; @@ -460,11 +455,11 @@ module.exports = function draw(gd, id) { }, function() { if(['top', 'bottom'].indexOf(opts.title.side) === -1) { - var fontSize = cbAxisOut.title.font.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))); + var fontSize = cbAxisOut.title.font.size; + var y = cbAxisOut._offset + cbAxisOut._length / 2; + var 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))); // the 'h' + is a hack to get around the fact that // convertToTspans rotates any 'y...' class by 90 degrees. @@ -517,8 +512,8 @@ module.exports = function draw(gd, id) { if(titleEl.node() && !titleEl.classed(cn.jsPlaceholder)) { var mathJaxNode = titleCont .select('.h' + cbAxisOut._id + 'title-math-group') - .node(), - titleWidth; + .node(); + var titleWidth; if(mathJaxNode && ['top', 'bottom'].indexOf(opts.title.side) !== -1) { titleWidth = Drawing.bBox(mathJaxNode).width; @@ -536,8 +531,8 @@ module.exports = function draw(gd, id) { } var outerwidth = 2 * opts.xpad + innerWidth + - opts.borderwidth + opts.outlinewidth / 2, - outerheight = yBottomPx - yTopPx; + opts.borderwidth + opts.outlinewidth / 2; + var outerheight = yBottomPx - yTopPx; container.select('.cbbg').attr({ x: xLeft - opts.xpad - @@ -652,11 +647,9 @@ module.exports = function draw(gd, id) { } function getTrace() { - var idNum = id.substr(2), - i, - trace; - for(i = 0; i < gd._fullData.length; i++) { - trace = gd._fullData[i]; + var idNum = id.substr(2); + for(var i = 0; i < gd._fullData.length; i++) { + var trace = gd._fullData[i]; if(trace.uid === idNum) return trace; } } diff --git a/src/components/colorscale/helpers.js b/src/components/colorscale/helpers.js index 676a3fb8699..81e786a2d66 100644 --- a/src/components/colorscale/helpers.js +++ b/src/components/colorscale/helpers.js @@ -114,10 +114,10 @@ function flipScale(scl) { function makeColorScaleFunc(specs, opts) { opts = opts || {}; - var domain = specs.domain, - range = specs.range, - N = range.length, - _range = new Array(N); + var domain = specs.domain; + var range = specs.range; + var N = range.length; + var _range = new Array(N); for(var i = 0; i < N; i++) { var rgba = tinycolor(range[i]).toRgb(); @@ -129,9 +129,9 @@ function makeColorScaleFunc(specs, opts) { .range(_range) .clamp(true); - var noNumericCheck = opts.noNumericCheck, - returnArray = opts.returnArray, - sclFunc; + var noNumericCheck = opts.noNumericCheck; + var returnArray = opts.returnArray; + var sclFunc; if(noNumericCheck && returnArray) { sclFunc = _sclFunc; diff --git a/src/components/dragelement/align.js b/src/components/dragelement/align.js index bd77be34425..171c278f488 100644 --- a/src/components/dragelement/align.js +++ b/src/components/dragelement/align.js @@ -15,9 +15,9 @@ // based on where you are, and return the fraction corresponding to // that position on the object module.exports = function align(v, dv, v0, v1, anchor) { - var vmin = (v - v0) / (v1 - v0), - vmax = vmin + dv / (v1 - v0), - vc = (vmin + vmax) / 2; + var vmin = (v - v0) / (v1 - v0); + var vmax = vmin + dv / (v1 - v0); + var vc = (vmin + vmax) / 2; // explicitly specified anchor if(anchor === 'left' || anchor === 'bottom') return vmin; diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index b014c3ffb87..1d3b89962ec 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -133,9 +133,9 @@ drawing.crispRound = function(gd, lineWidth, dflt) { drawing.singleLineStyle = function(d, s, lw, lc, ld) { s.style('fill', 'none'); - var line = (((d || [])[0] || {}).trace || {}).line || {}, - lw1 = lw || line.width||0, - dash = ld || line.dash || ''; + var line = (((d || [])[0] || {}).trace || {}).line || {}; + var lw1 = lw || line.width||0; + var dash = ld || line.dash || ''; Color.stroke(s, lc || line.color); drawing.dashLine(s, dash, lw1); @@ -144,9 +144,9 @@ drawing.singleLineStyle = function(d, s, lw, lc, ld) { drawing.lineGroupStyle = function(s, lw, lc, ld) { 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 || {}; + var lw1 = lw || line.width||0; + var dash = ld || line.dash || ''; d3.select(this) .call(Color.stroke, lc || line.color) @@ -235,9 +235,10 @@ Object.keys(SYMBOLDEFS).forEach(function(k) { drawing.symbolNoFill[symDef.n] = true; } }); -var MAXSYMBOL = drawing.symbolNames.length, - // add a dot in the middle of the symbol - DOTPATH = 'M0,0.5L0.5,0L0,-0.5L-0.5,0Z'; + +var MAXSYMBOL = drawing.symbolNames.length; +// add a dot in the middle of the symbol +var DOTPATH = 'M0,0.5L0.5,0L0,-0.5L-0.5,0Z'; drawing.symbolNumber = function(v) { if(typeof v === 'string') { @@ -741,8 +742,9 @@ drawing.selectedTextStyle = function(s, trace) { var CatmullRomExp = 0.5; drawing.smoothopen = function(pts, smoothness) { if(pts.length < 3) { return 'M' + pts.join('L');} - var path = 'M' + pts[0], - tangents = [], i; + var path = 'M' + pts[0]; + var tangents = []; + var i; for(i = 1; i < pts.length - 1; i++) { tangents.push(makeTangent(pts[i - 1], pts[i], pts[i + 1], smoothness)); } @@ -756,11 +758,10 @@ drawing.smoothopen = function(pts, smoothness) { drawing.smoothclosed = function(pts, smoothness) { if(pts.length < 3) { return 'M' + pts.join('L') + 'Z'; } - var path = 'M' + pts[0], - pLast = pts.length - 1, - tangents = [makeTangent(pts[pLast], - pts[0], pts[1], smoothness)], - i; + var path = 'M' + pts[0]; + var pLast = pts.length - 1; + var tangents = [makeTangent(pts[pLast], pts[0], pts[1], smoothness)]; + var i; for(i = 1; i < pLast; i++) { tangents.push(makeTangent(pts[i - 1], pts[i], pts[i + 1], smoothness)); } @@ -776,16 +777,16 @@ drawing.smoothclosed = function(pts, smoothness) { }; function makeTangent(prevpt, thispt, nextpt, smoothness) { - var d1x = prevpt[0] - thispt[0], - d1y = prevpt[1] - thispt[1], - d2x = nextpt[0] - thispt[0], - d2y = nextpt[1] - thispt[1], - d1a = Math.pow(d1x * d1x + d1y * d1y, CatmullRomExp / 2), - d2a = Math.pow(d2x * d2x + d2y * d2y, CatmullRomExp / 2), - numx = (d2a * d2a * d1x - d1a * d1a * d2x) * smoothness, - numy = (d2a * d2a * d1y - d1a * d1a * d2y) * smoothness, - denom1 = 3 * d2a * (d1a + d2a), - denom2 = 3 * d1a * (d1a + d2a); + var d1x = prevpt[0] - thispt[0]; + var d1y = prevpt[1] - thispt[1]; + var d2x = nextpt[0] - thispt[0]; + var d2y = nextpt[1] - thispt[1]; + var d1a = Math.pow(d1x * d1x + d1y * d1y, CatmullRomExp / 2); + var d2a = Math.pow(d2x * d2x + d2y * d2y, CatmullRomExp / 2); + var numx = (d2a * d2a * d1x - d1a * d1a * d2x) * smoothness; + var numy = (d2a * d2a * d1y - d1a * d1a * d2y) * smoothness; + var denom1 = 3 * d2a * (d1a + d2a); + var denom2 = 3 * d1a * (d1a + d2a); return [ [ d3.round(thispt[0] + (denom1 && numx / denom1), 2), @@ -1031,9 +1032,9 @@ drawing.setClipUrl = function(s, localId, gd) { drawing.getTranslate = function(element) { // Note the separator [^\d] between x and y in this regex // We generally use ',' but IE will convert it to ' ' - var re = /.*\btranslate\((-?\d*\.?\d*)[^-\d]*(-?\d*\.?\d*)[^\d].*/, - getter = element.attr ? 'attr' : 'getAttribute', - transform = element[getter]('transform') || ''; + var re = /.*\btranslate\((-?\d*\.?\d*)[^-\d]*(-?\d*\.?\d*)[^\d].*/; + var getter = element.attr ? 'attr' : 'getAttribute'; + var transform = element[getter]('transform') || ''; var translate = transform.replace(re, function(match, p1, p2) { return [p1, p2].join(' '); @@ -1047,11 +1048,10 @@ drawing.getTranslate = function(element) { }; drawing.setTranslate = function(element, x, y) { - - var re = /(\btranslate\(.*?\);?)/, - getter = element.attr ? 'attr' : 'getAttribute', - setter = element.attr ? 'attr' : 'setAttribute', - transform = element[getter]('transform') || ''; + var re = /(\btranslate\(.*?\);?)/; + var getter = element.attr ? 'attr' : 'getAttribute'; + var setter = element.attr ? 'attr' : 'setAttribute'; + var transform = element[getter]('transform') || ''; x = x || 0; y = y || 0; @@ -1066,10 +1066,9 @@ drawing.setTranslate = function(element, x, y) { }; drawing.getScale = function(element) { - - var re = /.*\bscale\((\d*\.?\d*)[^\d]*(\d*\.?\d*)[^\d].*/, - getter = element.attr ? 'attr' : 'getAttribute', - transform = element[getter]('transform') || ''; + var re = /.*\bscale\((\d*\.?\d*)[^\d]*(\d*\.?\d*)[^\d].*/; + var getter = element.attr ? 'attr' : 'getAttribute'; + var transform = element[getter]('transform') || ''; var translate = transform.replace(re, function(match, p1, p2) { return [p1, p2].join(' '); @@ -1083,11 +1082,10 @@ drawing.getScale = function(element) { }; drawing.setScale = function(element, x, y) { - - var re = /(\bscale\(.*?\);?)/, - getter = element.attr ? 'attr' : 'getAttribute', - setter = element.attr ? 'attr' : 'setAttribute', - transform = element[getter]('transform') || ''; + var re = /(\bscale\(.*?\);?)/; + var getter = element.attr ? 'attr' : 'getAttribute'; + var setter = element.attr ? 'attr' : 'setAttribute'; + var transform = element[getter]('transform') || ''; x = x || 1; y = y || 1; diff --git a/src/components/drawing/symbol_defs.js b/src/components/drawing/symbol_defs.js index 45c7e3401d9..85943c92e31 100644 --- a/src/components/drawing/symbol_defs.js +++ b/src/components/drawing/symbol_defs.js @@ -45,8 +45,8 @@ module.exports = { cross: { n: 3, f: function(r) { - var rc = d3.round(r * 0.4, 2), - rc2 = d3.round(r * 1.2, 2); + var rc = d3.round(r * 0.4, 2); + var 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'; @@ -55,90 +55,90 @@ module.exports = { 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; + var rx = d3.round(r * 0.8 / Math.sqrt(2), 2); + var ne = 'l' + rx + ',' + rx; + var se = 'l' + rx + ',-' + rx; + var sw = 'l-' + rx + ',-' + rx; + var 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); + var rt = d3.round(r * 2 / Math.sqrt(3), 2); + var r2 = d3.round(r / 2, 2); + var 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); + var rt = d3.round(r * 2 / Math.sqrt(3), 2); + var r2 = d3.round(r / 2, 2); + var 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); + var rt = d3.round(r * 2 / Math.sqrt(3), 2); + var r2 = d3.round(r / 2, 2); + var 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); + var rt = d3.round(r * 2 / Math.sqrt(3), 2); + var r2 = d3.round(r / 2, 2); + var 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); + var r1 = d3.round(r * 0.6, 2); + var 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); + var r1 = d3.round(r * 0.6, 2); + var 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); + var r1 = d3.round(r * 0.6, 2); + var 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); + var r1 = d3.round(r * 0.6, 2); + var 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); + var x1 = d3.round(r * 0.951, 2); + var x2 = d3.round(r * 0.588, 2); + var y0 = d3.round(-r, 2); + var y1 = d3.round(r * -0.309, 2); + var y2 = d3.round(r * 0.809, 2); return 'M' + x1 + ',' + y1 + 'L' + x2 + ',' + y2 + 'H-' + x2 + 'L-' + x1 + ',' + y1 + 'L0,' + y0 + 'Z'; } @@ -146,9 +146,9 @@ module.exports = { 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); + var y0 = d3.round(r, 2); + var y1 = d3.round(r / 2, 2); + var 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'; } @@ -156,9 +156,9 @@ module.exports = { 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); + var x0 = d3.round(r, 2); + var x1 = d3.round(r / 2, 2); + var 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'; } @@ -166,8 +166,8 @@ module.exports = { octagon: { n: 16, f: function(r) { - var a = d3.round(r * 0.924, 2), - b = d3.round(r * 0.383, 2); + var a = d3.round(r * 0.924, 2); + var 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'; } @@ -175,16 +175,16 @@ module.exports = { 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); + var rs = r * 1.4; + var x1 = d3.round(rs * 0.225, 2); + var x2 = d3.round(rs * 0.951, 2); + var x3 = d3.round(rs * 0.363, 2); + var x4 = d3.round(rs * 0.588, 2); + var y0 = d3.round(-rs, 2); + var y1 = d3.round(rs * -0.309, 2); + var y3 = d3.round(rs * 0.118, 2); + var y4 = d3.round(rs * 0.809, 2); + var 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 + @@ -194,9 +194,9 @@ module.exports = { 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); + var y = d3.round(r * 0.66, 2); + var x1 = d3.round(r * 0.38, 2); + var 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 + @@ -206,11 +206,11 @@ module.exports = { '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 '; + var x = d3.round(r * Math.sqrt(3) * 0.8, 2); + var y1 = d3.round(r * 0.8, 2); + var y2 = d3.round(r * 1.6, 2); + var rc = d3.round(r * 4, 2); + var aPart = 'A ' + rc + ',' + rc + ' 0 0 1 '; return 'M-' + x + ',' + y1 + aPart + x + ',' + y1 + aPart + '0,-' + y2 + aPart + '-' + x + ',' + y1 + 'Z'; } @@ -218,11 +218,11 @@ module.exports = { '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 '; + var x = d3.round(r * Math.sqrt(3) * 0.8, 2); + var y1 = d3.round(r * 0.8, 2); + var y2 = d3.round(r * 1.6, 2); + var rc = d3.round(r * 4, 2); + var aPart = 'A ' + rc + ',' + rc + ' 0 0 1 '; return 'M' + x + ',-' + y1 + aPart + '-' + x + ',-' + y1 + aPart + '0,' + y2 + aPart + x + ',-' + y1 + 'Z'; } @@ -230,9 +230,9 @@ module.exports = { '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 '; + var rp = d3.round(r * 1.1, 2); + var rc = d3.round(r * 2, 2); + var aPart = 'A ' + rc + ',' + rc + ' 0 0 1 '; return 'M-' + rp + ',-' + rp + aPart + '-' + rp + ',' + rp + aPart + rp + ',' + rp + aPart + rp + ',-' + rp + aPart + '-' + rp + ',-' + rp + 'Z'; @@ -241,9 +241,9 @@ module.exports = { '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 '; + var rp = d3.round(r * 1.4, 2); + var rc = d3.round(r * 1.9, 2); + var aPart = 'A ' + rc + ',' + rc + ' 0 0 1 '; return 'M-' + rp + ',0' + aPart + '0,' + rp + aPart + rp + ',0' + aPart + '0,-' + rp + aPart + '-' + rp + ',0' + 'Z'; @@ -252,16 +252,16 @@ module.exports = { 'diamond-tall': { n: 23, f: function(r) { - var x = d3.round(r * 0.7, 2), - y = d3.round(r * 1.4, 2); + var x = d3.round(r * 0.7, 2); + var 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); + var x = d3.round(r * 1.4, 2); + var y = d3.round(r * 0.7, 2); return 'M0,' + y + 'L' + x + ',0L0,-' + y + 'L-' + x + ',0Z'; } }, @@ -295,8 +295,8 @@ module.exports = { 'circle-x': { n: 28, f: function(r) { - var rs = d3.round(r, 2), - rc = d3.round(r / Math.sqrt(2), 2); + var rs = d3.round(r, 2); + var 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 + @@ -339,8 +339,8 @@ module.exports = { 'diamond-x': { n: 32, f: function(r) { - var rd = d3.round(r * 1.3, 2), - r2 = d3.round(r * 0.65, 2); + var rd = d3.round(r * 1.3, 2); + var 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; @@ -385,8 +385,8 @@ module.exports = { hash: { n: 36, f: function(r) { - var r1 = d3.round(r / 2, 2), - r2 = d3.round(r, 2); + var r1 = d3.round(r / 2, 2); + var r2 = d3.round(r, 2); return 'M' + r1 + ',' + r2 + 'V-' + r2 + 'm-' + r2 + ',0V' + r2 + 'M' + r2 + ',' + r1 + 'H-' + r2 + @@ -398,9 +398,9 @@ module.exports = { '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); + var x = d3.round(r * 1.2, 2); + var y0 = d3.round(r * 1.6, 2); + var y1 = d3.round(r * 0.8, 2); return 'M-' + x + ',' + y1 + 'L0,0M' + x + ',' + y1 + 'L0,0M0,-' + y0 + 'L0,0'; }, needLine: true, @@ -410,9 +410,9 @@ 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); + var x = d3.round(r * 1.2, 2); + var y0 = d3.round(r * 1.6, 2); + var y1 = d3.round(r * 0.8, 2); return 'M-' + x + ',-' + y1 + 'L0,0M' + x + ',-' + y1 + 'L0,0M0,' + y0 + 'L0,0'; }, needLine: true, @@ -422,9 +422,9 @@ 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); + var y = d3.round(r * 1.2, 2); + var x0 = d3.round(r * 1.6, 2); + var x1 = d3.round(r * 0.8, 2); return 'M' + x1 + ',' + y + 'L0,0M' + x1 + ',-' + y + 'L0,0M-' + x0 + ',0L0,0'; }, needLine: true, @@ -434,9 +434,9 @@ 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); + var y = d3.round(r * 1.2, 2); + var x0 = d3.round(r * 1.6, 2); + var x1 = d3.round(r * 0.8, 2); return 'M-' + x1 + ',' + y + 'L0,0M-' + x1 + ',-' + y + 'L0,0M' + x0 + ',0L0,0'; }, needLine: true, diff --git a/src/components/errorbars/calc.js b/src/components/errorbars/calc.js index 56742248010..ccf28db316d 100644 --- a/src/components/errorbars/calc.js +++ b/src/components/errorbars/calc.js @@ -34,9 +34,9 @@ module.exports = function calc(gd) { }; function calcOneAxis(calcTrace, trace, axis, coord) { - var opts = trace['error_' + coord] || {}, - isVisible = (opts.visible && ['linear', 'log'].indexOf(axis.type) !== -1), - vals = []; + var opts = trace['error_' + coord] || {}; + var isVisible = (opts.visible && ['linear', 'log'].indexOf(axis.type) !== -1); + var vals = []; if(!isVisible) return; @@ -67,8 +67,8 @@ function calcOneAxis(calcTrace, trace, axis, coord) { var errors = computeError(calcCoord, iIn); if(isNumeric(errors[0]) && isNumeric(errors[1])) { - var shoe = calcPt[coord + 's'] = calcCoord - errors[0], - hat = calcPt[coord + 'h'] = calcCoord + errors[1]; + var shoe = calcPt[coord + 's'] = calcCoord - errors[0]; + var hat = calcPt[coord + 'h'] = calcCoord + errors[1]; vals.push(shoe, hat); } } diff --git a/src/components/errorbars/compute_error.js b/src/components/errorbars/compute_error.js index 87512817aed..e778fc4234c 100644 --- a/src/components/errorbars/compute_error.js +++ b/src/components/errorbars/compute_error.js @@ -26,8 +26,8 @@ * - error[1] : " " " " positive " */ module.exports = function makeComputeError(opts) { - var type = opts.type, - symmetric = opts.symmetric; + var type = opts.type; + var symmetric = opts.symmetric; if(type === 'data') { var array = opts.array || []; @@ -54,8 +54,8 @@ module.exports = function makeComputeError(opts) { } } else { - var computeErrorValue = makeComputeErrorValue(type, opts.value), - computeErrorValueMinus = makeComputeErrorValue(type, opts.valueminus); + var computeErrorValue = makeComputeErrorValue(type, opts.value); + var computeErrorValueMinus = makeComputeErrorValue(type, opts.valueminus); if(symmetric || opts.valueminus === undefined) { return function computeError(dataPt) { diff --git a/src/components/errorbars/defaults.js b/src/components/errorbars/defaults.js index 056e40909ef..37c5da0c9a2 100644 --- a/src/components/errorbars/defaults.js +++ b/src/components/errorbars/defaults.js @@ -36,8 +36,8 @@ module.exports = function(traceIn, traceOut, defaultColor, opts) { if(visible === false) return; - var type = coerce('type', 'array' in containerIn ? 'data' : 'percent'), - symmetric = true; + var type = coerce('type', 'array' in containerIn ? 'data' : 'percent'); + var symmetric = true; if(type !== 'sqrt') { symmetric = coerce('symmetric', diff --git a/src/components/errorbars/plot.js b/src/components/errorbars/plot.js index 0921881d038..753e45ebbd1 100644 --- a/src/components/errorbars/plot.js +++ b/src/components/errorbars/plot.js @@ -24,13 +24,13 @@ module.exports = function plot(gd, traces, plotinfo, transitionOpts) { var hasAnimation = transitionOpts && transitionOpts.duration > 0; traces.each(function(d) { - var trace = d[0].trace, - // || {} is in case the trace (specifically scatterternary) - // doesn't support error bars at all, but does go through - // the scatter.plot mechanics, which calls ErrorBars.plot - // internally - xObj = trace.error_x || {}, - yObj = trace.error_y || {}; + var trace = d[0].trace; + // || {} is in case the trace (specifically scatterternary) + // doesn't support error bars at all, but does go through + // the scatter.plot mechanics, which calls ErrorBars.plot + // internally + var xObj = trace.error_x || {}; + var yObj = trace.error_y || {}; var keyFunc; diff --git a/src/components/errorbars/style.js b/src/components/errorbars/style.js index 1b156d123b6..7107ebca991 100644 --- a/src/components/errorbars/style.js +++ b/src/components/errorbars/style.js @@ -16,9 +16,9 @@ var Color = require('../color'); module.exports = function style(traces) { traces.each(function(d) { - var trace = d[0].trace, - yObj = trace.error_y || {}, - xObj = trace.error_x || {}; + var trace = d[0].trace; + var yObj = trace.error_y || {}; + var xObj = trace.error_x || {}; var s = d3.select(this); diff --git a/src/components/fx/helpers.js b/src/components/fx/helpers.js index 2698a7e1761..730fe2343eb 100644 --- a/src/components/fx/helpers.js +++ b/src/components/fx/helpers.js @@ -95,8 +95,8 @@ exports.inbox = function inbox(v0, v1, passVal) { exports.quadrature = function quadrature(dx, dy) { return function(di) { - var x = dx(di), - y = dy(di); + var x = dx(di); + var y = dy(di); return Math.sqrt(x * x + y * y); }; }; diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index daa77e3700d..c18e2946a18 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -198,9 +198,8 @@ exports.multiHovers = function multiHovers(hoverItems, opts) { }); - var container3 = d3.select(opts.container), - outerContainer3 = opts.outerContainer ? - d3.select(opts.outerContainer) : container3; + var container3 = d3.select(opts.container); + var outerContainer3 = opts.outerContainer ? d3.select(opts.outerContainer) : container3; var fullOpts = { hovermode: 'closest', @@ -618,11 +617,11 @@ function _hover(gd, evt, subplot, noHoverEvent) { outerContainer: fullLayout._paperdiv, event: evt }; - var oldspikepoints = gd._spikepoints, - newspikepoints = { - vLinePoint: spikePoints.vLinePoint, - hLinePoint: spikePoints.hLinePoint - }; + var oldspikepoints = gd._spikepoints; + var newspikepoints = { + vLinePoint: spikePoints.vLinePoint, + hLinePoint: spikePoints.hLinePoint + }; gd._spikepoints = newspikepoints; // Now if it is not restricted by spikedistance option, set the points to draw the spikelines diff --git a/src/components/images/convert_coords.js b/src/components/images/convert_coords.js index d30507c5d46..1568c0276db 100644 --- a/src/components/images/convert_coords.js +++ b/src/components/images/convert_coords.js @@ -33,25 +33,25 @@ var toLogRange = require('../../lib/to_log_range'); module.exports = function convertCoords(gd, ax, newType, doExtra) { ax = ax || {}; - var toLog = (newType === 'log') && (ax.type === 'linear'), - fromLog = (newType === 'linear') && (ax.type === 'log'); + var toLog = (newType === 'log') && (ax.type === 'linear'); + var fromLog = (newType === 'linear') && (ax.type === 'log'); if(!(toLog || fromLog)) return; - var images = gd._fullLayout.images, - axLetter = ax._id.charAt(0), - image, - attrPrefix; + var images = gd._fullLayout.images; + var axLetter = ax._id.charAt(0); + var image; + var attrPrefix; for(var i = 0; i < images.length; i++) { image = images[i]; attrPrefix = 'images[' + i + '].'; if(image[axLetter + 'ref'] === ax._id) { - var currentPos = image[axLetter], - currentSize = image['size' + axLetter], - newPos = null, - newSize = null; + var currentPos = image[axLetter]; + var currentSize = image['size' + axLetter]; + var newPos = null; + var newSize = null; if(toLog) { newPos = toLogRange(currentPos, ax.range); diff --git a/src/components/images/defaults.js b/src/components/images/defaults.js index ac210aad3a5..4aeb427cc73 100644 --- a/src/components/images/defaults.js +++ b/src/components/images/defaults.js @@ -44,13 +44,13 @@ function imageDefaults(imageIn, imageOut, fullLayout) { coerce('sizing'); coerce('opacity'); - var gdMock = { _fullLayout: fullLayout }, - axLetters = ['x', 'y']; + var gdMock = { _fullLayout: fullLayout }; + var axLetters = ['x', 'y']; for(var i = 0; i < 2; i++) { // 'paper' is the fallback axref - var axLetter = axLetters[i], - axRef = Axes.coerceRef(imageIn, imageOut, gdMock, axLetter, 'paper'); + var axLetter = axLetters[i]; + var axRef = Axes.coerceRef(imageIn, imageOut, gdMock, axLetter, 'paper'); Axes.coercePosition(imageOut, gdMock, coerce, axRef, axLetter, 0); } diff --git a/src/components/images/draw.js b/src/components/images/draw.js index d2e2b61e654..0bce91d2f7a 100644 --- a/src/components/images/draw.js +++ b/src/components/images/draw.js @@ -14,12 +14,12 @@ var Axes = require('../../plots/cartesian/axes'); var xmlnsNamespaces = require('../../constants/xmlns_namespaces'); module.exports = function draw(gd) { - var fullLayout = gd._fullLayout, - imageDataAbove = [], - imageDataSubplot = {}, - imageDataBelow = [], - subplot, - i; + var fullLayout = gd._fullLayout; + var imageDataAbove = []; + var imageDataSubplot = {}; + var imageDataBelow = []; + var subplot; + var i; // Sort into top, subplot, and bottom layers for(i = 0; i < fullLayout.images.length; i++) { @@ -124,23 +124,22 @@ module.exports = function draw(gd) { var thisImage = d3.select(this); // Axes if specified - var xa = Axes.getFromId(gd, d.xref), - ya = Axes.getFromId(gd, d.yref); + var xa = Axes.getFromId(gd, d.xref); + var ya = Axes.getFromId(gd, d.yref); - var size = fullLayout._size, - width = xa ? Math.abs(xa.l2p(d.sizex) - xa.l2p(0)) : d.sizex * size.w, - height = ya ? Math.abs(ya.l2p(d.sizey) - ya.l2p(0)) : d.sizey * size.h; + var size = fullLayout._size; + var width = xa ? Math.abs(xa.l2p(d.sizex) - xa.l2p(0)) : d.sizex * size.w; + var height = ya ? Math.abs(ya.l2p(d.sizey) - ya.l2p(0)) : d.sizey * size.h; // Offsets for anchor positioning - var xOffset = width * anchors.x[d.xanchor].offset, - yOffset = height * anchors.y[d.yanchor].offset; + var xOffset = width * anchors.x[d.xanchor].offset; + var yOffset = height * anchors.y[d.yanchor].offset; var sizing = anchors.x[d.xanchor].sizing + anchors.y[d.yanchor].sizing; // Final positions - var xPos = (xa ? xa.r2p(d.x) + xa._offset : d.x * size.w + size.l) + xOffset, - yPos = (ya ? ya.r2p(d.y) + ya._offset : size.h - d.y * size.h + size.t) + yOffset; - + var xPos = (xa ? xa.r2p(d.x) + xa._offset : d.x * size.w + size.l) + xOffset; + var yPos = (ya ? ya.r2p(d.y) + ya._offset : size.h - d.y * size.h + size.t) + yOffset; // Construct the proper aspectRatio attribute switch(d.sizing) { @@ -164,9 +163,9 @@ module.exports = function draw(gd) { // Set proper clipping on images - var xId = xa ? xa._id : '', - yId = ya ? ya._id : '', - clipAxes = xId + yId; + var xId = xa ? xa._id : ''; + var yId = ya ? ya._id : ''; + var clipAxes = xId + yId; Drawing.setClipUrl( thisImage, @@ -176,9 +175,9 @@ module.exports = function draw(gd) { } var imagesBelow = fullLayout._imageLowerLayer.selectAll('image') - .data(imageDataBelow), - imagesAbove = fullLayout._imageUpperLayer.selectAll('image') - .data(imageDataAbove); + .data(imageDataBelow); + var imagesAbove = fullLayout._imageUpperLayer.selectAll('image') + .data(imageDataAbove); imagesBelow.enter().append('image'); imagesAbove.enter().append('image'); diff --git a/src/components/legend/draw.js b/src/components/legend/draw.js index 76c5e2c08ca..feed9e63925 100644 --- a/src/components/legend/draw.js +++ b/src/components/legend/draw.js @@ -131,10 +131,10 @@ module.exports = function draw(gd) { } // Position and size the legend - var lxMin = 0, - lxMax = fullLayout.width, - lyMin = 0, - lyMax = fullLayout.height; + var lxMin = 0; + var lxMax = fullLayout.width; + var lyMin = 0; + var lyMax = fullLayout.height; computeLegendDimensions(gd, groups, traces); @@ -149,9 +149,9 @@ module.exports = function draw(gd) { // Scroll section must be executed after repositionLegend. // It requires the legend width, height, x and y to position the scrollbox // 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); + var gs = fullLayout._size; + var lx = gs.l + gs.w * opts.x; + var ly = gs.t + gs.h * (1 - opts.y); if(Lib.isRightAnchor(opts)) { lx -= opts._width; @@ -168,8 +168,8 @@ module.exports = function draw(gd) { } // Make sure the legend left and right sides are visible - var legendWidth = opts._width, - legendWidthMax = gs.w; + var legendWidth = opts._width; + var legendWidthMax = gs.w; if(legendWidth > legendWidthMax) { lx = gs.l; @@ -184,8 +184,8 @@ module.exports = function draw(gd) { // Make sure the legend top and bottom are visible // (legends with a scroll bar are not allowed to stretch beyond the extended // margins) - var legendHeight = opts._height, - legendHeightMax = gs.h; + var legendHeight = opts._height; + var legendHeightMax = gs.h; if(legendHeight > legendHeightMax) { ly = gs.t; @@ -328,8 +328,8 @@ module.exports = function draw(gd) { y0 = transform.y; }, moveFn: function(dx, dy) { - var newX = x0 + dx, - newY = y0 + dy; + var newX = x0 + dx; + var newY = y0 + dy; Drawing.setTranslate(legend, newX, newY); @@ -468,8 +468,8 @@ function ensureLength(str, maxLength) { } function setupTraceToggle(g, gd) { - var newMouseDownTime, - numClicks = 1; + var newMouseDownTime; + var numClicks = 1; var traceToggle = Lib.ensureSingle(g, 'rect', 'legendtoggle', function(s) { s.style('cursor', 'pointer') @@ -563,9 +563,9 @@ function computeLegendDimensions(gd, groups, traces) { } traces.each(function(d) { - var legendItem = d[0], - textHeight = legendItem.height, - textWidth = legendItem.width; + var legendItem = d[0]; + var textHeight = legendItem.height; + var textWidth = legendItem.width; Drawing.setTranslate(this, borderwidth, @@ -585,8 +585,8 @@ function computeLegendDimensions(gd, groups, traces) { extraWidth = 40; } else if(isGrouped) { - var groupXOffsets = [opts._width], - groupData = groups.data(); + var groupXOffsets = [opts._width]; + var groupData = groups.data(); for(var i = 0, n = groupData.length; i < n; i++) { var textWidths = groupData[i].map(function(legendItemArray) { @@ -605,13 +605,13 @@ function computeLegendDimensions(gd, groups, traces) { }); groups.each(function() { - var group = d3.select(this), - groupTraces = group.selectAll('g.traces'), - groupHeight = 0; + var group = d3.select(this); + var groupTraces = group.selectAll('g.traces'); + var groupHeight = 0; groupTraces.each(function(d) { - var legendItem = d[0], - textHeight = legendItem.height; + var legendItem = d[0]; + var textHeight = legendItem.height; Drawing.setTranslate(this, 0, @@ -627,13 +627,13 @@ function computeLegendDimensions(gd, groups, traces) { opts._width += borderwidth * 2; } else { - var rowHeight = 0, - maxTraceHeight = 0, - maxTraceWidth = 0, - offsetX = 0, - fullTracesWidth = 0, - traceGap = opts.tracegroupgap || 5, - oneRowLegend; + var rowHeight = 0; + var maxTraceHeight = 0; + var maxTraceWidth = 0; + var offsetX = 0; + var fullTracesWidth = 0; + var traceGap = opts.tracegroupgap || 5; + var oneRowLegend; // calculate largest width for traces and use for width of all legend items traces.each(function(d) { @@ -644,8 +644,8 @@ function computeLegendDimensions(gd, groups, traces) { // check if legend fits in one row oneRowLegend = fullLayout._size.w > borderwidth + fullTracesWidth - traceGap; traces.each(function(d) { - var legendItem = d[0], - traceWidth = oneRowLegend ? 40 + d[0].width : maxTraceWidth; + var legendItem = d[0]; + var traceWidth = oneRowLegend ? 40 + d[0].width : maxTraceWidth; if((borderwidth + offsetX + traceGap + traceWidth) > fullLayout._size.w) { offsetX = 0; @@ -695,8 +695,8 @@ function computeLegendDimensions(gd, groups, traces) { } function expandMargin(gd) { - var fullLayout = gd._fullLayout, - opts = fullLayout.legend; + var fullLayout = gd._fullLayout; + var opts = fullLayout.legend; var xanchor = 'left'; if(Lib.isRightAnchor(opts)) { @@ -726,8 +726,8 @@ function expandMargin(gd) { } function expandHorizontalMargin(gd) { - var fullLayout = gd._fullLayout, - opts = fullLayout.legend; + var fullLayout = gd._fullLayout; + var opts = fullLayout.legend; var xanchor = 'left'; if(Lib.isRightAnchor(opts)) { diff --git a/src/components/legend/get_legend_data.js b/src/components/legend/get_legend_data.js index c96d34407f0..6b7a9e4c056 100644 --- a/src/components/legend/get_legend_data.js +++ b/src/components/legend/get_legend_data.js @@ -14,12 +14,11 @@ var helpers = require('./helpers'); module.exports = function getLegendData(calcdata, opts) { - var lgroupToTraces = {}, - lgroups = [], - hasOneNonBlankGroup = false, - slicesShown = {}, - lgroupi = 0; - + var lgroupToTraces = {}; + var lgroups = []; + var hasOneNonBlankGroup = false; + var slicesShown = {}; + var lgroupi = 0; var i, j; function addOneItem(legendGroup, legendItem) { @@ -75,9 +74,9 @@ module.exports = function getLegendData(calcdata, opts) { if(!lgroups.length) return []; // rearrange lgroupToTraces into a d3-friendly array of arrays - var lgroupsLength = lgroups.length, - ltraces, - legendData; + var lgroupsLength = lgroups.length; + var ltraces; + var legendData; if(hasOneNonBlankGroup && helpers.isGrouped(opts)) { legendData = new Array(lgroupsLength); diff --git a/src/components/legend/handle_click.js b/src/components/legend/handle_click.js index 608c4a272da..1c31a075ce9 100644 --- a/src/components/legend/handle_click.js +++ b/src/components/legend/handle_click.js @@ -93,8 +93,8 @@ module.exports = function handleClick(g, gd, numClicks) { } if(Registry.traceIs(fullTrace, 'pie')) { - var thisLabel = legendItem.label, - thisLabelIndex = hiddenSlices.indexOf(thisLabel); + var thisLabel = legendItem.label; + var thisLabelIndex = hiddenSlices.indexOf(thisLabel); if(numClicks === 1) { if(thisLabelIndex === -1) hiddenSlices.push(thisLabel); diff --git a/src/components/legend/style.js b/src/components/legend/style.js index e959e061dcb..94a7be8727f 100644 --- a/src/components/legend/style.js +++ b/src/components/legend/style.js @@ -242,20 +242,22 @@ module.exports = function style(s, gd) { } function styleBars(d) { - var trace = d[0].trace, - marker = trace.marker || {}, - markerLine = marker.line || {}, - barpath = d3.select(this).select('g.legendpoints') - .selectAll('path.legendbar') - .data(Registry.traceIs(trace, 'bar') ? [d] : []); + var trace = d[0].trace; + var marker = trace.marker || {}; + var markerLine = marker.line || {}; + + var barpath = d3.select(this).select('g.legendpoints') + .selectAll('path.legendbar') + .data(Registry.traceIs(trace, 'bar') ? [d] : []); barpath.enter().append('path').classed('legendbar', true) .attr('d', 'M6,6H-6V-6H6Z') .attr('transform', 'translate(20,0)'); barpath.exit().remove(); + barpath.each(function(d) { - var p = d3.select(this), - d0 = d[0], - w = (d0.mlw + 1 || markerLine.width + 1) - 1; + var p = d3.select(this); + var d0 = d[0]; + var w = (d0.mlw + 1 || markerLine.width + 1) - 1; p.style('stroke-width', w + 'px') .call(Color.fill, d0.mc || marker.color); @@ -267,18 +269,20 @@ module.exports = function style(s, gd) { } function styleBoxes(d) { - var trace = d[0].trace, - pts = d3.select(this).select('g.legendpoints') - .selectAll('path.legendbox') - .data(Registry.traceIs(trace, 'box-violin') && trace.visible ? [d] : []); + var trace = d[0].trace; + + var pts = d3.select(this).select('g.legendpoints') + .selectAll('path.legendbox') + .data(Registry.traceIs(trace, 'box-violin') && trace.visible ? [d] : []); pts.enter().append('path').classed('legendbox', true) // if we want the median bar, prepend M6,0H-6 .attr('d', 'M6,6H-6V-6H6Z') .attr('transform', 'translate(20,0)'); pts.exit().remove(); + pts.each(function() { - var w = trace.line.width, - p = d3.select(this); + var w = trace.line.width; + var p = d3.select(this); p.style('stroke-width', w + 'px') .call(Color.fill, trace.fillcolor); @@ -290,10 +294,11 @@ module.exports = function style(s, gd) { } function styleCandles(d) { - var trace = d[0].trace, - pts = d3.select(this).select('g.legendpoints') - .selectAll('path.legendcandle') - .data(trace.type === 'candlestick' && trace.visible ? [d, d] : []); + var trace = d[0].trace; + + var pts = d3.select(this).select('g.legendpoints') + .selectAll('path.legendcandle') + .data(trace.type === 'candlestick' && trace.visible ? [d, d] : []); pts.enter().append('path').classed('legendcandle', true) .attr('d', function(_, i) { if(i) return 'M-15,0H-8M-8,6V-6H8Z'; // increasing @@ -302,10 +307,11 @@ module.exports = function style(s, gd) { .attr('transform', 'translate(20,0)') .style('stroke-miterlimit', 1); pts.exit().remove(); + pts.each(function(_, i) { var container = trace[i ? 'increasing' : 'decreasing']; - var w = container.line.width, - p = d3.select(this); + var w = container.line.width; + var p = d3.select(this); p.style('stroke-width', w + 'px') .call(Color.fill, container.fillcolor); @@ -317,10 +323,11 @@ module.exports = function style(s, gd) { } function styleOHLC(d) { - var trace = d[0].trace, - pts = d3.select(this).select('g.legendpoints') - .selectAll('path.legendohlc') - .data(trace.type === 'ohlc' && trace.visible ? [d, d] : []); + var trace = d[0].trace; + + var pts = d3.select(this).select('g.legendpoints') + .selectAll('path.legendohlc') + .data(trace.type === 'ohlc' && trace.visible ? [d, d] : []); pts.enter().append('path').classed('legendohlc', true) .attr('d', function(_, i) { if(i) return 'M-15,0H0M-8,-6V0'; // increasing @@ -329,10 +336,11 @@ module.exports = function style(s, gd) { .attr('transform', 'translate(20,0)') .style('stroke-miterlimit', 1); pts.exit().remove(); + pts.each(function(_, i) { var container = trace[i ? 'increasing' : 'decreasing']; - var w = container.line.width, - p = d3.select(this); + var w = container.line.width; + var p = d3.select(this); p.style('fill', 'none') .call(Drawing.dashLine, container.line.dash, w); @@ -344,10 +352,11 @@ module.exports = function style(s, gd) { } function stylePies(d) { - var trace = d[0].trace, - pts = d3.select(this).select('g.legendpoints') - .selectAll('path.legendpie') - .data(Registry.traceIs(trace, 'pie') && trace.visible ? [d] : []); + var trace = d[0].trace; + + var pts = d3.select(this).select('g.legendpoints') + .selectAll('path.legendpie') + .data(Registry.traceIs(trace, 'pie') && trace.visible ? [d] : []); pts.enter().append('path').classed('legendpie', true) .attr('d', 'M6,6H-6V-6H6Z') .attr('transform', 'translate(20,0)'); diff --git a/src/components/modebar/buttons.js b/src/components/modebar/buttons.js index eca5d398ead..eb9d5684ce9 100644 --- a/src/components/modebar/buttons.js +++ b/src/components/modebar/buttons.js @@ -197,10 +197,9 @@ function handleCartesian(gd, ev) { var ax, i; if(astr === 'zoom') { - var mag = (val === 'in') ? 0.5 : 2, - r0 = (1 + mag) / 2, - r1 = (1 - mag) / 2; - + var mag = (val === 'in') ? 0.5 : 2; + var r0 = (1 + mag) / 2; + var r1 = (1 - mag) / 2; var axName; for(i = 0; i < axList.length; i++) { @@ -344,9 +343,9 @@ function handleCamera3d(gd, ev) { var aobj = {}; for(var i = 0; i < sceneIds.length; i++) { - var sceneId = sceneIds[i], - key = sceneId + '.camera', - scene = fullLayout[sceneId]._scene; + var sceneId = sceneIds[i]; + var key = sceneId + '.camera'; + var scene = fullLayout[sceneId]._scene; if(attr === 'resetDefault') { aobj[key] = null; diff --git a/src/components/modebar/manage.js b/src/components/modebar/manage.js index 194733598ca..923165605fd 100644 --- a/src/components/modebar/manage.js +++ b/src/components/modebar/manage.js @@ -25,9 +25,9 @@ var modeBarButtons = require('./buttons'); * */ module.exports = function manageModeBar(gd) { - var fullLayout = gd._fullLayout, - context = gd._context, - modeBar = fullLayout._modeBar; + var fullLayout = gd._fullLayout; + var context = gd._context; + var modeBar = fullLayout._modeBar; if(!context.displayModeBar && !context.watermark) { if(modeBar) { diff --git a/src/components/modebar/modebar.js b/src/components/modebar/modebar.js index 70f44d8cabb..fe402281279 100644 --- a/src/components/modebar/modebar.js +++ b/src/components/modebar/modebar.js @@ -45,9 +45,9 @@ var proto = ModeBar.prototype; proto.update = function(graphInfo, buttons) { this.graphInfo = graphInfo; - var context = this.graphInfo._context, - fullLayout = this.graphInfo._fullLayout, - modeBarId = 'modebar-' + fullLayout._uid; + var context = this.graphInfo._context; + var fullLayout = this.graphInfo._fullLayout; + var modeBarId = 'modebar-' + fullLayout._uid; this.element.setAttribute('id', modeBarId); this._uid = modeBarId; @@ -145,8 +145,8 @@ proto.createGroup = function() { * @Return {HTMLelement} */ proto.createButton = function(config) { - var _this = this, - button = document.createElement('a'); + var _this = this; + var button = document.createElement('a'); button.setAttribute('rel', 'tooltip'); button.className = 'modebar-btn'; @@ -204,10 +204,10 @@ proto.createButton = function(config) { */ proto.createIcon = function(thisIcon) { var iconHeight = isNumeric(thisIcon.height) ? - Number(thisIcon.height) : - thisIcon.ascent - thisIcon.descent, - svgNS = 'http://www.w3.org/2000/svg', - icon; + Number(thisIcon.height) : + thisIcon.ascent - thisIcon.descent; + var svgNS = 'http://www.w3.org/2000/svg'; + var icon; if(thisIcon.path) { icon = document.createElementNS(svgNS, 'svg'); @@ -245,16 +245,16 @@ proto.createIcon = function(thisIcon) { * @Return {HTMLelement} */ proto.updateActiveButton = function(buttonClicked) { - var fullLayout = this.graphInfo._fullLayout, - dataAttrClicked = (buttonClicked !== undefined) ? - buttonClicked.getAttribute('data-attr') : - null; + var fullLayout = this.graphInfo._fullLayout; + var dataAttrClicked = (buttonClicked !== undefined) ? + buttonClicked.getAttribute('data-attr') : + null; this.buttonElements.forEach(function(button) { - var thisval = button.getAttribute('data-val') || true, - dataAttr = button.getAttribute('data-attr'), - isToggleButton = (button.getAttribute('data-toggle') === 'true'), - button3 = d3.select(button); + var thisval = button.getAttribute('data-val') || true; + var dataAttr = button.getAttribute('data-attr'); + var isToggleButton = (button.getAttribute('data-toggle') === 'true'); + var button3 = d3.select(button); // Use 'data-toggle' and 'buttonClicked' to toggle buttons // that have no one-to-one equivalent in fullLayout @@ -301,8 +301,8 @@ proto.hasButtons = function(buttons) { * @return {HTMLDivElement} The logo image wrapped in a group */ proto.getLogo = function() { - var group = this.createGroup(), - a = document.createElement('a'); + var group = this.createGroup(); + var a = document.createElement('a'); a.href = 'https://plot.ly/'; a.target = '_blank'; diff --git a/src/components/rangeselector/draw.js b/src/components/rangeselector/draw.js index 1e6cc145d2e..ca197b5df81 100644 --- a/src/components/rangeselector/draw.js +++ b/src/components/rangeselector/draw.js @@ -44,9 +44,9 @@ module.exports = function draw(gd) { }); selectors.each(function(d) { - var selector = d3.select(this), - axisLayout = d, - selectorLayout = axisLayout.rangeselector; + var selector = d3.select(this); + var axisLayout = d; + var selectorLayout = axisLayout.rangeselector; var buttons = selector.selectAll('g.button') .data(Lib.filterVisible(selectorLayout.buttons)); diff --git a/src/components/rangeselector/get_update_object.js b/src/components/rangeselector/get_update_object.js index c5fd25e245f..3dcba729b4a 100644 --- a/src/components/rangeselector/get_update_object.js +++ b/src/components/rangeselector/get_update_object.js @@ -31,10 +31,8 @@ module.exports = function getUpdateObject(axisLayout, buttonLayout) { function getXRange(axisLayout, buttonLayout) { var currentRange = axisLayout.range; var base = new Date(axisLayout.r2l(currentRange[1])); - - var step = buttonLayout.step, - count = buttonLayout.count; - + var step = buttonLayout.step; + var count = buttonLayout.count; var range0; switch(buttonLayout.stepmode) { diff --git a/src/components/rangeslider/draw.js b/src/components/rangeslider/draw.js index 1b80f2abc9e..56b8cba1287 100644 --- a/src/components/rangeslider/draw.js +++ b/src/components/rangeslider/draw.js @@ -127,9 +127,9 @@ module.exports = function(gd) { // update data <--> pixel coordinate conversion methods - var range0 = axisOpts.r2l(opts.range[0]), - range1 = axisOpts.r2l(opts.range[1]), - dist = range1 - range0; + var range0 = axisOpts.r2l(opts.range[0]); + var range1 = axisOpts.r2l(opts.range[1]); + var dist = range1 - range0; opts.p2d = function(v) { return (v / opts._width) * dist + range0; @@ -142,9 +142,9 @@ module.exports = function(gd) { opts._rl = [range0, range1]; if(oppAxisRangeOpts.rangemode !== 'match') { - var range0OppAxis = oppAxisOpts.r2l(oppAxisRangeOpts.range[0]), - range1OppAxis = oppAxisOpts.r2l(oppAxisRangeOpts.range[1]), - distOppAxis = range1OppAxis - range0OppAxis; + var range0OppAxis = oppAxisOpts.r2l(oppAxisRangeOpts.range[0]); + var range1OppAxis = oppAxisOpts.r2l(oppAxisRangeOpts.range[1]); + var distOppAxis = range1OppAxis - range0OppAxis; opts.d2pOppAxis = function(v) { return (v - range0OppAxis) / distOppAxis * opts._height; @@ -185,17 +185,17 @@ module.exports = function(gd) { }; function setupDragElement(rangeSlider, gd, axisOpts, opts) { - var slideBox = rangeSlider.select('rect.' + constants.slideBoxClassName).node(), - grabAreaMin = rangeSlider.select('rect.' + constants.grabAreaMinClassName).node(), - grabAreaMax = rangeSlider.select('rect.' + constants.grabAreaMaxClassName).node(); + var slideBox = rangeSlider.select('rect.' + constants.slideBoxClassName).node(); + var grabAreaMin = rangeSlider.select('rect.' + constants.grabAreaMinClassName).node(); + var grabAreaMax = rangeSlider.select('rect.' + constants.grabAreaMaxClassName).node(); rangeSlider.on('mousedown', function() { - var event = d3.event, - target = event.target, - startX = event.clientX, - offsetX = startX - rangeSlider.node().getBoundingClientRect().left, - minVal = opts.d2p(axisOpts._rl[0]), - maxVal = opts.d2p(axisOpts._rl[1]); + var event = d3.event; + var target = event.target; + var startX = event.clientX; + var offsetX = startX - rangeSlider.node().getBoundingClientRect().left; + var minVal = opts.d2p(axisOpts._rl[0]); + var maxVal = opts.d2p(axisOpts._rl[1]); var dragCover = dragElement.coverSlip(); @@ -259,8 +259,8 @@ function setDataRange(rangeSlider, gd, axisOpts, opts) { return axisOpts.l2r(Lib.constrain(v, opts._rl[0], opts._rl[1])); } - var dataMin = clamp(opts.p2d(opts._pixelMin)), - dataMax = clamp(opts.p2d(opts._pixelMax)); + var dataMin = clamp(opts.p2d(opts._pixelMin)); + var dataMax = clamp(opts.p2d(opts._pixelMax)); window.requestAnimationFrame(function() { Registry.call('_guiRelayout', gd, axisOpts._name + '.range', [dataMin, dataMax]); @@ -282,8 +282,8 @@ function setPixelRange(rangeSlider, gd, axisOpts, opts, oppAxisOpts, oppAxisRang return Lib.constrain(v, -hw2, opts._width + hw2); } - var pixelMin = clamp(opts.d2p(axisOpts._rl[0])), - pixelMax = clamp(opts.d2p(axisOpts._rl[1])); + var pixelMin = clamp(opts.d2p(axisOpts._rl[0])); + var pixelMax = clamp(opts.d2p(axisOpts._rl[1])); rangeSlider.select('rect.' + constants.slideBoxClassName) .attr('x', pixelMin) @@ -297,8 +297,8 @@ function setPixelRange(rangeSlider, gd, axisOpts, opts, oppAxisOpts, oppAxisRang .attr('width', opts._width - pixelMax); if(oppAxisRangeOpts.rangemode !== 'match') { - var pixelMinOppAxis = opts._height - clampOppAxis(opts.d2pOppAxis(oppAxisOpts._rl[1])), - pixelMaxOppAxis = opts._height - clampOppAxis(opts.d2pOppAxis(oppAxisOpts._rl[0])); + var pixelMinOppAxis = opts._height - clampOppAxis(opts.d2pOppAxis(oppAxisOpts._rl[1])); + var pixelMaxOppAxis = opts._height - clampOppAxis(opts.d2pOppAxis(oppAxisOpts._rl[0])); rangeSlider.select('rect.' + constants.maskMinOppAxisClassName) .attr('x', pixelMin) @@ -320,8 +320,8 @@ function setPixelRange(rangeSlider, gd, axisOpts, opts, oppAxisOpts, oppAxisRang // https://github.com/plotly/plotly.js/pull/1409 var offset = 0.5; - var xMin = Math.round(clampHandle(pixelMin - hw2)) - offset, - xMax = Math.round(clampHandle(pixelMax - hw2)) + offset; + var xMin = Math.round(clampHandle(pixelMin - hw2)) - offset; + var xMax = Math.round(clampHandle(pixelMax - hw2)) + offset; rangeSlider.select('g.' + constants.grabberMinClassName) .attr('transform', 'translate(' + xMin + ',' + offset + ')'); @@ -340,8 +340,8 @@ function drawBg(rangeSlider, gd, axisOpts, opts) { }); var borderCorrect = (opts.borderwidth % 2) === 0 ? - opts.borderwidth : - opts.borderwidth - 1; + opts.borderwidth : + opts.borderwidth - 1; var offsetShift = -opts._offsetShift; var lw = Drawing.crispRound(gd, opts.borderwidth); @@ -386,12 +386,12 @@ function drawRangePlot(rangeSlider, gd, axisOpts, opts) { var mainplotinfo; rangePlots.each(function(id, i) { - var plotgroup = d3.select(this), - isMainPlot = (i === 0); + var plotgroup = d3.select(this); + var isMainPlot = (i === 0); - var oppAxisOpts = axisIDs.getFromId(gd, id, 'y'), - oppAxisName = oppAxisOpts._name, - oppAxisRangeOpts = opts[oppAxisName]; + var oppAxisOpts = axisIDs.getFromId(gd, id, 'y'); + var oppAxisName = oppAxisOpts._name; + var oppAxisRangeOpts = opts[oppAxisName]; var mockFigure = { data: [], @@ -448,8 +448,8 @@ function filterRangePlotCalcData(calcData, subplotId) { var out = []; for(var i = 0; i < calcData.length; i++) { - var calcTrace = calcData[i], - trace = calcTrace[0].trace; + var calcTrace = calcData[i]; + var trace = calcTrace[0].trace; if(trace.xaxis + trace.yaxis === subplotId) { out.push(calcTrace); diff --git a/src/components/shapes/calc_autorange.js b/src/components/shapes/calc_autorange.js index b1aa79ad935..744a124f681 100644 --- a/src/components/shapes/calc_autorange.js +++ b/src/components/shapes/calc_autorange.js @@ -16,8 +16,8 @@ var helpers = require('./helpers'); module.exports = function calcAutorange(gd) { - var fullLayout = gd._fullLayout, - shapeList = Lib.filterVisible(fullLayout.shapes); + var fullLayout = gd._fullLayout; + var shapeList = Lib.filterVisible(fullLayout.shapes); if(!shapeList.length || !gd._fullData.length) return; @@ -28,8 +28,8 @@ module.exports = function calcAutorange(gd) { var ax, bounds; if(shape.xref !== 'paper') { - var vx0 = shape.xsizemode === 'pixel' ? shape.xanchor : shape.x0, - vx1 = shape.xsizemode === 'pixel' ? shape.xanchor : shape.x1; + var vx0 = shape.xsizemode === 'pixel' ? shape.xanchor : shape.x0; + var vx1 = shape.xsizemode === 'pixel' ? shape.xanchor : shape.x1; ax = Axes.getFromId(gd, shape.xref); bounds = shapeBounds(ax, vx0, vx1, shape.path, constants.paramIsX); @@ -39,8 +39,8 @@ module.exports = function calcAutorange(gd) { } if(shape.yref !== 'paper') { - var vy0 = shape.ysizemode === 'pixel' ? shape.yanchor : shape.y0, - vy1 = shape.ysizemode === 'pixel' ? shape.yanchor : shape.y1; + var vy0 = shape.ysizemode === 'pixel' ? shape.yanchor : shape.y0; + var vy1 = shape.ysizemode === 'pixel' ? shape.yanchor : shape.y1; ax = Axes.getFromId(gd, shape.yref); bounds = shapeBounds(ax, vy0, vy1, shape.path, constants.paramIsY); @@ -60,17 +60,17 @@ function calcYPaddingOptions(shape) { } function calcPaddingOptions(lineWidth, sizeMode, v0, v1, path, isYAxis) { - var ppad = lineWidth / 2, - axisDirectionReverted = isYAxis; + var ppad = lineWidth / 2; + var axisDirectionReverted = isYAxis; if(sizeMode === 'pixel') { var coords = path ? - helpers.extractPathCoords(path, isYAxis ? constants.paramIsY : constants.paramIsX) : - [v0, v1]; - var maxValue = Lib.aggNums(Math.max, null, coords), - minValue = Lib.aggNums(Math.min, null, coords), - beforePad = minValue < 0 ? Math.abs(minValue) + ppad : ppad, - afterPad = maxValue > 0 ? maxValue + ppad : ppad; + helpers.extractPathCoords(path, isYAxis ? constants.paramIsY : constants.paramIsX) : + [v0, v1]; + var maxValue = Lib.aggNums(Math.max, null, coords); + var minValue = Lib.aggNums(Math.min, null, coords); + var beforePad = minValue < 0 ? Math.abs(minValue) + ppad : ppad; + var afterPad = maxValue > 0 ? maxValue + ppad : ppad; return { ppad: ppad, @@ -88,14 +88,14 @@ function shapeBounds(ax, v0, v1, path, paramsToUse) { if(v0 !== undefined) return [convertVal(v0), convertVal(v1)]; if(!path) return; - var min = Infinity, - max = -Infinity, - segments = path.match(constants.segmentRE), - i, - segment, - drawnParam, - params, - val; + var min = Infinity; + var max = -Infinity; + var segments = path.match(constants.segmentRE); + var i; + var segment; + var drawnParam; + var params; + var val; if(ax.type === 'date') convertVal = helpers.decodeDate(convertVal); diff --git a/src/components/shapes/defaults.js b/src/components/shapes/defaults.js index fff7f9d612b..c3be87769fb 100644 --- a/src/components/shapes/defaults.js +++ b/src/components/shapes/defaults.js @@ -40,21 +40,21 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) { coerce('line.width'); coerce('line.dash'); - var dfltType = shapeIn.path ? 'path' : 'rect', - shapeType = coerce('type', dfltType), - xSizeMode = coerce('xsizemode'), - ySizeMode = coerce('ysizemode'); + var dfltType = shapeIn.path ? 'path' : 'rect'; + var shapeType = coerce('type', dfltType); + var xSizeMode = coerce('xsizemode'); + var ySizeMode = coerce('ysizemode'); // positioning var axLetters = ['x', 'y']; for(var i = 0; i < 2; i++) { - var axLetter = axLetters[i], - attrAnchor = axLetter + 'anchor', - sizeMode = axLetter === 'x' ? xSizeMode : ySizeMode, - gdMock = {_fullLayout: fullLayout}, - ax, - pos2r, - r2pos; + var axLetter = axLetters[i]; + var attrAnchor = axLetter + 'anchor'; + var sizeMode = axLetter === 'x' ? xSizeMode : ySizeMode; + var gdMock = {_fullLayout: fullLayout}; + var ax; + var pos2r; + var r2pos; // xref, yref var axRef = Axes.coerceRef(shapeIn, shapeOut, gdMock, axLetter, '', 'paper'); @@ -71,17 +71,17 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) { // Coerce x0, x1, y0, y1 if(shapeType !== 'path') { - var dflt0 = 0.25, - dflt1 = 0.75; + var dflt0 = 0.25; + var dflt1 = 0.75; // hack until V2.0 when log has regular range behavior - make it look like other // ranges to send to coerce, then put it back after // this is all to give reasonable default position behavior on log axes, which is // a pretty unimportant edge case so we could just ignore this. - var attr0 = axLetter + '0', - attr1 = axLetter + '1', - in0 = shapeIn[attr0], - in1 = shapeIn[attr1]; + var attr0 = axLetter + '0'; + var attr1 = axLetter + '1'; + var in0 = shapeIn[attr0]; + var in1 = shapeIn[attr1]; shapeIn[attr0] = pos2r(shapeIn[attr0], true); shapeIn[attr1] = pos2r(shapeIn[attr1], true); diff --git a/src/components/shapes/draw.js b/src/components/shapes/draw.js index 04cc4cd7084..ffdb82ba167 100644 --- a/src/components/shapes/draw.js +++ b/src/components/shapes/draw.js @@ -94,12 +94,11 @@ function drawOne(gd, index) { function drawShape(shapeLayer) { var attrs = { - 'data-index': index, - 'fill-rule': 'evenodd', - d: getPathString(gd, options) - }, - lineColor = options.line.width ? - options.line.color : 'rgba(0,0,0,0)'; + 'data-index': index, + 'fill-rule': 'evenodd', + d: getPathString(gd, options) + }; + var lineColor = options.line.width ? options.line.color : 'rgba(0,0,0,0)'; var path = shapeLayer.append('path') .attr(attrs) @@ -144,22 +143,22 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) { var pathIn; // setup conversion functions - var xa = Axes.getFromId(gd, shapeOptions.xref), - ya = Axes.getFromId(gd, shapeOptions.yref), - x2p = helpers.getDataToPixel(gd, xa), - y2p = helpers.getDataToPixel(gd, ya, true), - p2x = helpers.getPixelToData(gd, xa), - p2y = helpers.getPixelToData(gd, ya, true); + var xa = Axes.getFromId(gd, shapeOptions.xref); + var ya = Axes.getFromId(gd, shapeOptions.yref); + var x2p = helpers.getDataToPixel(gd, xa); + var y2p = helpers.getDataToPixel(gd, ya, true); + var p2x = helpers.getPixelToData(gd, xa); + var p2y = helpers.getPixelToData(gd, ya, true); var sensoryElement = obtainSensoryElement(); var dragOptions = { - element: sensoryElement.node(), - gd: gd, - prepFn: startDrag, - doneFn: endDrag, - clickFn: abortDrag - }, - dragMode; + element: sensoryElement.node(), + gd: gd, + prepFn: startDrag, + doneFn: endDrag, + clickFn: abortDrag + }; + var dragMode; dragElement.init(dragOptions); @@ -170,8 +169,8 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) { } function createLineDragHandles() { - var minSensoryWidth = 10, - sensoryWidth = Math.max(shapeOptions.line.width, minSensoryWidth); + var minSensoryWidth = 10; + var sensoryWidth = Math.max(shapeOptions.line.width, minSensoryWidth); // Helper shapes group // Note that by setting the `data-index` attr, it is ensured that @@ -232,13 +231,13 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) { // choose 'move' or 'resize' // based on initial position of cursor within the drag element - var w = dragBBox.right - dragBBox.left, - h = dragBBox.bottom - dragBBox.top, - x = evt.clientX - dragBBox.left, - y = evt.clientY - dragBBox.top, - cursor = (!isPath && w > MINWIDTH && h > MINHEIGHT && !evt.shiftKey) ? - dragElement.getCursor(x / w, 1 - y / h) : - 'move'; + var w = dragBBox.right - dragBBox.left; + var h = dragBBox.bottom - dragBBox.top; + var x = evt.clientX - dragBBox.left; + var y = evt.clientY - dragBBox.top; + var cursor = (!isPath && w > MINWIDTH && h > MINHEIGHT && !evt.shiftKey) ? + dragElement.getCursor(x / w, 1 - y / h) : + 'move'; setCursor(shapePath, cursor); @@ -316,9 +315,9 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) { function moveShape(dx, dy) { if(shapeOptions.type === 'path') { - var noOp = function(coord) { return coord; }, - moveX = noOp, - moveY = noOp; + var noOp = function(coord) { return coord; }; + var moveX = noOp; + var moveY = noOp; if(xPixelSized) { modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx)); @@ -359,9 +358,9 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) { function resizeShape(dx, dy) { if(isPath) { // TODO: implement path resize, don't forget to update dragMode code - var noOp = function(coord) { return coord; }, - moveX = noOp, - moveY = noOp; + var noOp = function(coord) { return coord; }; + var moveX = noOp; + var moveY = noOp; if(xPixelSized) { modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx)); @@ -393,10 +392,10 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) { } } else { - var newN = (~dragMode.indexOf('n')) ? n0 + dy : n0, - newS = (~dragMode.indexOf('s')) ? s0 + dy : s0, - newW = (~dragMode.indexOf('w')) ? w0 + dx : w0, - newE = (~dragMode.indexOf('e')) ? e0 + dx : e0; + var newN = (~dragMode.indexOf('n')) ? n0 + dy : n0; + var newS = (~dragMode.indexOf('s')) ? s0 + dy : s0; + var newW = (~dragMode.indexOf('w')) ? w0 + dx : w0; + var newE = (~dragMode.indexOf('e')) ? e0 + dx : e0; // Do things in opposing direction for y-axis. // Hint: for data-sized shapes the reversal of axis direction is done in p2y. @@ -485,10 +484,10 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) { } function deactivateClipPathTemporarily(shapePath, shapeOptions, gd) { - var xref = shapeOptions.xref, - yref = shapeOptions.yref, - xa = Axes.getFromId(gd, xref), - ya = Axes.getFromId(gd, yref); + var xref = shapeOptions.xref; + var yref = shapeOptions.yref; + var xa = Axes.getFromId(gd, xref); + var ya = Axes.getFromId(gd, yref); var clipAxes = ''; if(xref !== 'paper' && !xa.autorange) clipAxes += xref; @@ -503,12 +502,12 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) { } function getPathString(gd, options) { - var type = options.type, - xa = Axes.getFromId(gd, options.xref), - ya = Axes.getFromId(gd, options.yref), - gs = gd._fullLayout._size, - x2r, x2p, y2r, y2p, - x0, x1, y0, y1; + var type = options.type; + var xa = Axes.getFromId(gd, options.xref); + var ya = Axes.getFromId(gd, options.yref); + var gs = gd._fullLayout._size; + var x2r, x2p, y2r, y2p; + var x0, x1, y0, y1; if(xa) { x2r = helpers.shapePositionToRange(xa); @@ -554,33 +553,33 @@ function getPathString(gd, options) { 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, - rx = Math.abs(cx - x0), - ry = Math.abs(cy - y0), - rArc = 'A' + rx + ',' + ry, - rightPt = (cx + rx) + ',' + cy, - topPt = cx + ',' + (cy - ry); + var cx = (x0 + x1) / 2; + var cy = (y0 + y1) / 2; + var rx = Math.abs(cx - x0); + var ry = Math.abs(cy - y0); + var rArc = 'A' + rx + ',' + ry; + var rightPt = (cx + rx) + ',' + cy; + var topPt = cx + ',' + (cy - ry); return 'M' + rightPt + rArc + ' 0 1,1 ' + topPt + rArc + ' 0 0,1 ' + rightPt + 'Z'; } function convertPath(options, x2p, y2p) { - var pathIn = options.path, - xSizemode = options.xsizemode, - ySizemode = options.ysizemode, - xAnchor = options.xanchor, - yAnchor = options.yanchor; - + var pathIn = options.path; + var xSizemode = options.xsizemode; + var ySizemode = options.ysizemode; + var xAnchor = options.xanchor; + var yAnchor = options.yanchor; return pathIn.replace(constants.segmentRE, function(segment) { - var paramNumber = 0, - segmentType = segment.charAt(0), - xParams = constants.paramIsX[segmentType], - yParams = constants.paramIsY[segmentType], - nParams = constants.numParams[segmentType]; + var paramNumber = 0; + var segmentType = segment.charAt(0); + var xParams = constants.paramIsX[segmentType]; + var yParams = constants.paramIsY[segmentType]; + var nParams = constants.numParams[segmentType]; var paramString = segment.substr(1).replace(constants.paramRE, function(param) { if(xParams[paramNumber]) { @@ -608,11 +607,11 @@ function convertPath(options, x2p, y2p) { function movePath(pathIn, moveX, moveY) { return pathIn.replace(constants.segmentRE, function(segment) { - var paramNumber = 0, - segmentType = segment.charAt(0), - xParams = constants.paramIsX[segmentType], - yParams = constants.paramIsY[segmentType], - nParams = constants.numParams[segmentType]; + var paramNumber = 0; + var segmentType = segment.charAt(0); + var xParams = constants.paramIsX[segmentType]; + var yParams = constants.paramIsY[segmentType]; + var nParams = constants.numParams[segmentType]; var paramString = segment.substr(1).replace(constants.paramRE, function(param) { if(paramNumber >= nParams) return param; diff --git a/src/components/shapes/helpers.js b/src/components/shapes/helpers.js index aac463393d0..0ed52c2fdb9 100644 --- a/src/components/shapes/helpers.js +++ b/src/components/shapes/helpers.js @@ -59,8 +59,8 @@ exports.extractPathCoords = function(path, paramsToUse) { }; exports.getDataToPixel = function(gd, axis, isVertical) { - var gs = gd._fullLayout._size, - dataToPixel; + var gs = gd._fullLayout._size; + var dataToPixel; if(axis) { var d2r = exports.shapePositionToRange(axis); @@ -82,8 +82,8 @@ exports.getDataToPixel = function(gd, axis, isVertical) { }; exports.getPixelToData = function(gd, axis, isVertical) { - var gs = gd._fullLayout._size, - pixelToData; + var gs = gd._fullLayout._size; + var pixelToData; if(axis) { var r2d = exports.rangeToShapePosition(axis); diff --git a/src/components/sliders/draw.js b/src/components/sliders/draw.js index b224d940176..4d7b4ff013e 100644 --- a/src/components/sliders/draw.js +++ b/src/components/sliders/draw.js @@ -24,8 +24,8 @@ var FROM_TL = alignmentConstants.FROM_TL; var FROM_BR = alignmentConstants.FROM_BR; module.exports = function draw(gd) { - var fullLayout = gd._fullLayout, - sliderData = makeSliderData(fullLayout, gd); + var fullLayout = gd._fullLayout; + var sliderData = makeSliderData(fullLayout, gd); // draw a container for *all* sliders: var sliders = fullLayout._infolayer @@ -103,8 +103,8 @@ function autoMarginId(sliderOpts) { // This really only just filters by visibility: function makeSliderData(fullLayout, gd) { - var contOpts = fullLayout[constants.name], - sliderData = []; + var contOpts = fullLayout[constants.name]; + var sliderData = []; for(var i = 0; i < contOpts.length; i++) { var item = contOpts[i]; diff --git a/src/components/updatemenus/draw.js b/src/components/updatemenus/draw.js index 778e01b685e..a7a07613c9c 100644 --- a/src/components/updatemenus/draw.js +++ b/src/components/updatemenus/draw.js @@ -24,8 +24,8 @@ var constants = require('./constants'); var ScrollBox = require('./scrollbox'); module.exports = function draw(gd) { - var fullLayout = gd._fullLayout, - menuData = Lib.filterVisible(fullLayout[constants.name]); + var fullLayout = gd._fullLayout; + var menuData = Lib.filterVisible(fullLayout[constants.name]); /* Update menu data is bound to the header-group. * The items in the header group are always present. @@ -99,8 +99,8 @@ module.exports = function draw(gd) { } // setup scrollbox - var scrollBoxId = 'updatemenus' + fullLayout._uid, - scrollBox = new ScrollBox(gd, gButton, scrollBoxId); + var scrollBoxId = 'updatemenus' + fullLayout._uid; + var scrollBox = new ScrollBox(gd, gButton, scrollBoxId); // remove exiting header, remove dropped buttons and reset margins if(headerGroups.enter().size()) { @@ -356,9 +356,9 @@ function drawScrollBox(gd, gHeader, gButton, scrollBox, menuOpts, position) { var isVertical = (direction === 'up' || direction === 'down'); var dims = menuOpts._dims; - var active = menuOpts.active, - translateX, translateY, - i; + var active = menuOpts.active; + var translateX, translateY; + var i; if(isVertical) { translateY = 0; for(i = 0; i < active; i++) { @@ -390,8 +390,8 @@ function drawScrollBox(gd, gHeader, gButton, scrollBox, menuOpts, position) { } function hideScrollBox(scrollBox) { - var hasHBar = !!scrollBox.hbar, - hasVBar = !!scrollBox.vbar; + var hasHBar = !!scrollBox.hbar; + var hasVBar = !!scrollBox.vbar; if(hasHBar) { scrollBox.hbar diff --git a/src/components/updatemenus/scrollbox.js b/src/components/updatemenus/scrollbox.js index d9b5b553e69..ab9de74b69a 100644 --- a/src/components/updatemenus/scrollbox.js +++ b/src/components/updatemenus/scrollbox.js @@ -79,26 +79,26 @@ ScrollBox.barColor = '#808BA4'; * @param {number} [translateY=0] Vertical offset (in pixels) */ ScrollBox.prototype.enable = function enable(position, translateX, translateY) { - var fullLayout = this.gd._fullLayout, - fullWidth = fullLayout.width, - fullHeight = fullLayout.height; + var fullLayout = this.gd._fullLayout; + var fullWidth = fullLayout.width; + var fullHeight = fullLayout.height; // compute position of scrollbox this.position = position; - var l = this.position.l, - w = this.position.w, - t = this.position.t, - h = this.position.h, - direction = this.position.direction, - isDown = (direction === 'down'), - isLeft = (direction === 'left'), - isRight = (direction === 'right'), - isUp = (direction === 'up'), - boxW = w, - boxH = h, - boxL, boxR, - boxT, boxB; + var l = this.position.l; + var w = this.position.w; + var t = this.position.t; + var h = this.position.h; + var direction = this.position.direction; + var isDown = (direction === 'down'); + var isLeft = (direction === 'left'); + var isRight = (direction === 'right'); + var isUp = (direction === 'up'); + var boxW = w; + var boxH = h; + var boxL, boxR; + var boxT, boxB; if(!isDown && !isLeft && !isRight && !isUp) { this.position.direction = 'down'; @@ -149,12 +149,12 @@ ScrollBox.prototype.enable = function enable(position, translateX, translateY) { }; // compute position of horizontal scroll bar - var needsHorizontalScrollBar = (w > boxW), - hbarW = ScrollBox.barLength + 2 * ScrollBox.barPad, - hbarH = ScrollBox.barWidth + 2 * ScrollBox.barPad, - // draw horizontal scrollbar on the bottom side - hbarL = l, - hbarT = t + h; + var needsHorizontalScrollBar = (w > boxW); + var hbarW = ScrollBox.barLength + 2 * ScrollBox.barPad; + var hbarH = ScrollBox.barWidth + 2 * ScrollBox.barPad; + // draw horizontal scrollbar on the bottom side + var hbarL = l; + var hbarT = t + h; if(hbarT + hbarH > fullHeight) hbarT = fullHeight - hbarH; @@ -190,12 +190,12 @@ ScrollBox.prototype.enable = function enable(position, translateX, translateY) { } // compute position of vertical scroll bar - var needsVerticalScrollBar = (h > boxH), - vbarW = ScrollBox.barWidth + 2 * ScrollBox.barPad, - vbarH = ScrollBox.barLength + 2 * ScrollBox.barPad, - // draw vertical scrollbar on the right side - vbarL = l + w, - vbarT = t; + var needsVerticalScrollBar = (h > boxH); + var vbarW = ScrollBox.barWidth + 2 * ScrollBox.barPad; + var vbarH = ScrollBox.barLength + 2 * ScrollBox.barPad; + // draw vertical scrollbar on the right side + var vbarL = l + w; + var vbarT = t; if(vbarL + vbarW > fullWidth) vbarL = fullWidth - vbarW; @@ -231,11 +231,11 @@ ScrollBox.prototype.enable = function enable(position, translateX, translateY) { } // setup a clip path (if scroll bars are needed) - var clipId = this.id, - clipL = boxL - 0.5, - clipR = (needsVerticalScrollBar) ? boxR + vbarW + 0.5 : boxR + 0.5, - clipT = boxT - 0.5, - clipB = (needsHorizontalScrollBar) ? boxB + hbarH + 0.5 : boxB + 0.5; + var clipId = this.id; + var clipL = boxL - 0.5; + var clipR = (needsVerticalScrollBar) ? boxR + vbarW + 0.5 : boxR + 0.5; + var clipT = boxT - 0.5; + var clipB = (needsHorizontalScrollBar) ? boxB + hbarH + 0.5 : boxB + 0.5; var clipPath = fullLayout._topdefs.selectAll('#' + clipId) .data((needsHorizontalScrollBar || needsVerticalScrollBar) ? [0] : []); @@ -354,8 +354,8 @@ ScrollBox.prototype.disable = function disable() { * @method */ ScrollBox.prototype._onBoxDrag = function onBarDrag() { - var translateX = this.translateX, - translateY = this.translateY; + var translateX = this.translateX; + var translateY = this.translateY; if(this.hbar) { translateX -= d3.event.dx; @@ -374,8 +374,8 @@ ScrollBox.prototype._onBoxDrag = function onBarDrag() { * @method */ ScrollBox.prototype._onBoxWheel = function onBarWheel() { - var translateX = this.translateX, - translateY = this.translateY; + var translateX = this.translateX; + var translateY = this.translateY; if(this.hbar) { translateX += d3.event.deltaY; @@ -394,14 +394,14 @@ ScrollBox.prototype._onBoxWheel = function onBarWheel() { * @method */ ScrollBox.prototype._onBarDrag = function onBarDrag() { - var translateX = this.translateX, - translateY = this.translateY; + var translateX = this.translateX; + var translateY = this.translateY; if(this.hbar) { - var xMin = translateX + this._hbarXMin, - xMax = xMin + this._hbarTranslateMax, - x = Lib.constrain(d3.event.x, xMin, xMax), - xf = (x - xMin) / (xMax - xMin); + var xMin = translateX + this._hbarXMin; + var xMax = xMin + this._hbarTranslateMax; + var x = Lib.constrain(d3.event.x, xMin, xMax); + var xf = (x - xMin) / (xMax - xMin); var translateXMax = this.position.w - this._box.w; @@ -409,10 +409,10 @@ ScrollBox.prototype._onBarDrag = function onBarDrag() { } if(this.vbar) { - var yMin = translateY + this._vbarYMin, - yMax = yMin + this._vbarTranslateMax, - y = Lib.constrain(d3.event.y, yMin, yMax), - yf = (y - yMin) / (yMax - yMin); + var yMin = translateY + this._vbarYMin; + var yMax = yMin + this._vbarTranslateMax; + var y = Lib.constrain(d3.event.y, yMin, yMax); + var yf = (y - yMin) / (yMax - yMin); var translateYMax = this.position.h - this._box.h; @@ -431,8 +431,8 @@ ScrollBox.prototype._onBarDrag = function onBarDrag() { */ ScrollBox.prototype.setTranslate = function setTranslate(translateX, translateY) { // store translateX and translateY (needed by mouse event handlers) - var translateXMax = this.position.w - this._box.w, - translateYMax = this.position.h - this._box.h; + var translateXMax = this.position.w - this._box.w; + var translateYMax = this.position.h - this._box.h; translateX = Lib.constrain(translateX || 0, 0, translateXMax); translateY = Lib.constrain(translateY || 0, 0, translateYMax); diff --git a/src/lib/coerce.js b/src/lib/coerce.js index 0129ef40578..c590992085d 100644 --- a/src/lib/coerce.js +++ b/src/lib/coerce.js @@ -233,8 +233,8 @@ exports.valObjectMeta = { propOut.set(v); return; } - var vParts = v.split('+'), - i = 0; + var vParts = v.split('+'); + var i = 0; while(i < vParts.length) { var vi = vParts[i]; if(opts.flags.indexOf(vi) === -1 || vParts.indexOf(vi) < i) { @@ -415,9 +415,9 @@ exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt * returns false if there is no user input. */ exports.coerce2 = function(containerIn, containerOut, attributes, attribute, dflt) { - var propIn = nestedProperty(containerIn, attribute), - propOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt), - valIn = propIn.get(); + var propIn = nestedProperty(containerIn, attribute); + var propOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt); + var valIn = propIn.get(); return (valIn !== undefined && valIn !== null) ? propOut : false; }; @@ -510,9 +510,9 @@ function validate(value, opts) { return valObjectDef.validateFunction(value, opts); } - var failed = {}, - out = failed, - propMock = { set: function(v) { out = v; } }; + var failed = {}; + var out = failed; + var propMock = { set: function(v) { out = v; } }; // 'failed' just something mutable that won't be === anything else diff --git a/src/lib/dates.js b/src/lib/dates.js index 1027a797928..e406ee8bdcf 100644 --- a/src/lib/dates.js +++ b/src/lib/dates.js @@ -170,12 +170,12 @@ exports.dateTime2ms = function(s, calendar) { var match = s.match(isChinese ? DATETIME_REGEXP_CN : DATETIME_REGEXP); if(!match) return BADNUM; - var y = match[1], - m = match[3] || '1', - d = Number(match[5] || 1), - H = Number(match[7] || 0), - M = Number(match[9] || 0), - S = Number(match[11] || 0); + var y = match[1]; + var m = match[3] || '1'; + var d = Number(match[5] || 1); + var H = Number(match[7] || 0); + var M = Number(match[9] || 0); + var S = Number(match[11] || 0); if(isWorld) { // disallow 2-digit years for world calendars @@ -252,18 +252,17 @@ exports.ms2DateTime = function(ms, r, calendar) { if(!r) r = 0; - var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10), - msRounded = Math.round(ms - msecTenths / 10), - dateStr, h, m, s, msec10, d; + var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10); + var msRounded = Math.round(ms - msecTenths / 10); + var dateStr, h, m, s, msec10, d; if(isWorldCalendar(calendar)) { - var dateJD = Math.floor(msRounded / ONEDAY) + EPOCHJD, - timeMs = Math.floor(mod(ms, ONEDAY)); + var dateJD = Math.floor(msRounded / ONEDAY) + EPOCHJD; + var timeMs = Math.floor(mod(ms, ONEDAY)); try { dateStr = Registry.getComponentMethod('calendars', 'getCal')(calendar) .fromJD(dateJD).formatDate('yyyy-mm-dd'); - } - catch(e) { + } catch(e) { // invalid date in this calendar - fall back to Gyyyy-mm-dd dateStr = utcFormat('G%Y-%m-%d')(new Date(msRounded)); } @@ -273,8 +272,7 @@ exports.ms2DateTime = function(ms, r, calendar) { // it manually (after the '-' if there is one) if(dateStr.charAt(0) === '-') { while(dateStr.length < 11) dateStr = '-0' + dateStr.substr(1); - } - else { + } else { while(dateStr.length < 10) dateStr = '0' + dateStr; } @@ -311,13 +309,13 @@ exports.ms2DateTime = function(ms, r, calendar) { exports.ms2DateTimeLocal = function(ms) { if(!(ms >= MIN_MS + ONEDAY && ms <= MAX_MS - ONEDAY)) return BADNUM; - var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10), - d = new Date(Math.round(ms - msecTenths / 10)), - dateStr = d3.time.format('%Y-%m-%d')(d), - h = d.getHours(), - m = d.getMinutes(), - s = d.getSeconds(), - msec10 = d.getUTCMilliseconds() * 10 + msecTenths; + var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10); + var d = new Date(Math.round(ms - msecTenths / 10)); + var dateStr = d3.time.format('%Y-%m-%d')(d); + var h = d.getHours(); + var m = d.getMinutes(); + var s = d.getSeconds(); + var msec10 = d.getUTCMilliseconds() * 10 + msecTenths; return includeTime(dateStr, h, m, s, msec10); }; @@ -381,10 +379,10 @@ var fracMatch = /%\d?f/g; function modDateFormat(fmt, x, formatter, calendar) { fmt = fmt.replace(fracMatch, function(match) { - var digits = Math.min(+(match.charAt(1)) || 6, 6), - fracSecs = ((x / 1000 % 1) + 2) - .toFixed(digits) - .substr(2).replace(/0+$/, '') || '0'; + var digits = Math.min(+(match.charAt(1)) || 6, 6); + var fracSecs = ((x / 1000 % 1) + 2) + .toFixed(digits) + .substr(2).replace(/0+$/, '') || '0'; return fracSecs; }); @@ -516,16 +514,15 @@ exports.incrementMonth = function(ms, dMonth, calendar) { if(calendar) { try { - var dateJD = Math.round(ms / ONEDAY) + EPOCHJD, - calInstance = Registry.getComponentMethod('calendars', 'getCal')(calendar), - cDate = calInstance.fromJD(dateJD); + var dateJD = Math.round(ms / ONEDAY) + EPOCHJD; + var calInstance = Registry.getComponentMethod('calendars', 'getCal')(calendar); + var cDate = calInstance.fromJD(dateJD); if(dMonth % 12) calInstance.add(cDate, dMonth, 'm'); else calInstance.add(cDate, dMonth / 12, 'y'); return (cDate.toJD() - EPOCHJD) * ONEDAY + timeMs; - } - catch(e) { + } catch(e) { Loggers.error('invalid ms ' + ms + ' in calendar ' + calendar); // then keep going in gregorian even though the result will be 'Invalid' } @@ -542,12 +539,12 @@ exports.incrementMonth = function(ms, dMonth, calendar) { * calendar (string) the calendar to test against */ exports.findExactDates = function(data, calendar) { - var exactYears = 0, - exactMonths = 0, - exactDays = 0, - blankCount = 0, - d, - di; + var exactYears = 0; + var exactMonths = 0; + var exactDays = 0; + var blankCount = 0; + var d; + var di; var calInstance = ( isWorldCalendar(calendar) && diff --git a/src/lib/extend.js b/src/lib/extend.js index 3e615e7d04b..c9aeaa3d0b8 100644 --- a/src/lib/extend.js +++ b/src/lib/extend.js @@ -60,8 +60,8 @@ exports.extendDeepNoArrays = function() { * */ function _extend(inputs, isDeep, keepAllKeys, noArrayCopies) { - var target = inputs[0], - length = inputs.length; + var target = inputs[0]; + var length = inputs.length; var input, key, src, copy, copyIsArray, clone, allPrimitives; diff --git a/src/lib/filter_unique.js b/src/lib/filter_unique.js index 6fd6c212629..710776b18ed 100644 --- a/src/lib/filter_unique.js +++ b/src/lib/filter_unique.js @@ -32,9 +32,9 @@ * @return {array} new filtered array */ module.exports = function filterUnique(array) { - var seen = {}, - out = [], - j = 0; + var seen = {}; + var out = []; + var j = 0; for(var i = 0; i < array.length; i++) { var item = array[i]; diff --git a/src/lib/geo_location_utils.js b/src/lib/geo_location_utils.js index 069a1f1133c..e1510800053 100644 --- a/src/lib/geo_location_utils.js +++ b/src/lib/geo_location_utils.js @@ -50,8 +50,8 @@ function getLocationId(locationmode, location) { function countryNameToISO3(countryName) { for(var i = 0; i < countryIds.length; i++) { - var iso3 = countryIds[i], - regex = new RegExp(countryRegex[iso3]); + var iso3 = countryIds[i]; + var regex = new RegExp(countryRegex[iso3]); if(regex.test(countryName.trim().toLowerCase())) return iso3; } diff --git a/src/lib/geometry2d.js b/src/lib/geometry2d.js index 5675609b1f1..8e17c77664a 100644 --- a/src/lib/geometry2d.js +++ b/src/lib/geometry2d.js @@ -16,18 +16,18 @@ var mod = require('./mod').mod; */ exports.segmentsIntersect = segmentsIntersect; function segmentsIntersect(x1, y1, x2, y2, x3, y3, x4, y4) { - var a = x2 - x1, - b = x3 - x1, - c = x4 - x3, - d = y2 - y1, - e = y3 - y1, - f = y4 - y3, - det = a * f - c * d; + var a = x2 - x1; + var b = x3 - x1; + var c = x4 - x3; + var d = y2 - y1; + var e = y3 - y1; + var f = y4 - y3; + var det = a * f - c * d; // parallel lines? intersection is undefined // ignore the case where they are colinear if(det === 0) return null; - var t = (b * f - c * e) / det, - u = (b * d - a * e) / det; + var t = (b * f - c * e) / det; + var u = (b * d - a * e) / det; // segments do not intersect? if(u < 0 || u > 1 || t < 0 || t > 1) return null; @@ -45,15 +45,15 @@ exports.segmentDistance = function segmentDistance(x1, y1, x2, y2, x3, y3, x4, y var y12 = y2 - y1; var x34 = x4 - x3; var y34 = y4 - y3; - var l2_12 = x12 * x12 + y12 * y12; - var l2_34 = x34 * x34 + y34 * y34; + var ll12 = x12 * x12 + y12 * y12; + var ll34 = x34 * x34 + y34 * y34; // calculate distance squared, then take the sqrt at the very end var dist2 = Math.min( - perpDistance2(x12, y12, l2_12, x3 - x1, y3 - y1), - perpDistance2(x12, y12, l2_12, x4 - x1, y4 - y1), - perpDistance2(x34, y34, l2_34, x1 - x3, y1 - y3), - perpDistance2(x34, y34, l2_34, x2 - x3, y2 - y3) + perpDistance2(x12, y12, ll12, x3 - x1, y3 - y1), + perpDistance2(x12, y12, ll12, x4 - x1, y4 - y1), + perpDistance2(x34, y34, ll34, x1 - x3, y1 - y3), + perpDistance2(x34, y34, ll34, x2 - x3, y2 - y3) ); return Math.sqrt(dist2); @@ -63,15 +63,15 @@ exports.segmentDistance = function segmentDistance(x1, y1, x2, y2, x3, y3, x4, y * distance squared from segment ab to point c * [xab, yab] is the vector b-a * [xac, yac] is the vector c-a - * l2_ab is the length squared of (b-a), just to simplify calculation + * llab is the length squared of (b-a), just to simplify calculation */ -function perpDistance2(xab, yab, l2_ab, xac, yac) { - var fc_ab = (xac * xab + yac * yab); - if(fc_ab < 0) { +function perpDistance2(xab, yab, llab, xac, yac) { + var fcAB = (xac * xab + yac * yab); + if(fcAB < 0) { // point c is closer to point a return xac * xac + yac * yac; } - else if(fc_ab > l2_ab) { + else if(fcAB > llab) { // point c is closer to point b var xbc = xac - xab; var ybc = yac - yab; @@ -80,7 +80,7 @@ function perpDistance2(xab, yab, l2_ab, xac, yac) { else { // perpendicular distance is the shortest var crossProduct = xac * yab - yac * xab; - return crossProduct * crossProduct / l2_ab; + return crossProduct * crossProduct / llab; } } diff --git a/src/lib/index.js b/src/lib/index.js index e4652691f8b..8aa54b2eae3 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -200,10 +200,10 @@ lib.swapAttrs = function(cont, attrList, part1, part2) { if(!part1) part1 = 'x'; if(!part2) part2 = 'y'; for(var i = 0; i < attrList.length; i++) { - var attr = attrList[i], - xp = lib.nestedProperty(cont, attr.replace('?', part1)), - yp = lib.nestedProperty(cont, attr.replace('?', part2)), - temp = xp.get(); + var attr = attrList[i]; + var xp = lib.nestedProperty(cont, attr.replace('?', part1)); + var yp = lib.nestedProperty(cont, attr.replace('?', part2)); + var temp = xp.get(); xp.set(yp.get()); yp.set(temp); } @@ -252,8 +252,8 @@ lib.bBoxIntersect = function(a, b, pad) { * x1, x2: optional extra args */ lib.simpleMap = function(array, func, x1, x2) { - var len = array.length, - out = new Array(len); + var len = array.length; + var out = new Array(len); for(var i = 0; i < len; i++) out[i] = func(array[i], x1, x2); return out; }; @@ -341,15 +341,15 @@ lib.smooth = function(arrayIn, FWHM) { FWHM = Math.round(FWHM) || 0; // only makes sense for integers if(FWHM < 2) return arrayIn; - var alen = arrayIn.length, - alen2 = 2 * alen, - wlen = 2 * FWHM - 1, - w = new Array(wlen), - arrayOut = new Array(alen), - i, - j, - k, - v; + var alen = arrayIn.length; + var alen2 = 2 * alen; + var wlen = 2 * FWHM - 1; + var w = new Array(wlen); + var arrayOut = new Array(alen); + var i; + var j; + var k; + var v; // first make the window array for(i = 0; i < wlen; i++) { @@ -427,10 +427,10 @@ lib.noneOrAll = function(containerIn, containerOut, attrList) { */ if(!containerIn) return; - var hasAny = false, - hasAll = true, - i, - val; + var hasAny = false; + var hasAll = true; + var i; + var val; for(i = 0; i < attrList.length; i++) { val = containerIn[attrList[i]]; @@ -634,11 +634,10 @@ lib.getTargetArray = function(trace, transformOpts) { lib.minExtend = function(obj1, obj2) { var objOut = {}; if(typeof obj2 !== 'object') obj2 = {}; - var arrayLen = 3, - keys = Object.keys(obj1), - i, - k, - v; + var arrayLen = 3; + var keys = Object.keys(obj1); + var i, k, v; + for(i = 0; i < keys.length; i++) { k = keys[i]; v = obj1[k]; @@ -704,8 +703,8 @@ lib.addStyleRule = function(selector, styleString) { * to a stylesheet uniquely identified by a uid */ lib.addRelatedStyleRule = function(uid, selector, styleString) { - var id = 'plotly.js-style-' + uid, - style = document.getElementById(id); + var id = 'plotly.js-style-' + uid; + var style = document.getElementById(id); if(!style) { style = document.createElement('style'); style.setAttribute('id', id); @@ -728,8 +727,8 @@ lib.addRelatedStyleRule = function(uid, selector, styleString) { * to remove from the page a stylesheet identified by a given uid */ lib.deleteRelatedStyleRule = function(uid) { - var id = 'plotly.js-style-' + uid, - style = document.getElementById(id); + var id = 'plotly.js-style-' + uid; + var style = document.getElementById(id); if(style) lib.removeElement(style); }; @@ -820,9 +819,9 @@ lib.ensureSingleById = function(parent, nodeType, id, enterFn) { * @return {Object} the constructed object with a full nested path */ lib.objectFromPath = function(path, value) { - var keys = path.split('.'), - tmpObj, - obj = tmpObj = {}; + var keys = path.split('.'); + var tmpObj; + var obj = tmpObj = {}; for(var i = 0; i < keys.length; i++) { var key = keys[i]; @@ -977,13 +976,13 @@ lib.numSeparate = function(value, separators, separatethousands) { value = String(value); } - var thousandsRe = /(\d+)(\d{3})/, - decimalSep = separators.charAt(0), - thouSep = separators.charAt(1); + var thousandsRe = /(\d+)(\d{3})/; + var decimalSep = separators.charAt(0); + var thouSep = separators.charAt(1); - var x = value.split('.'), - x1 = x[0], - x2 = x.length > 1 ? decimalSep + x[1] : ''; + var x = value.split('.'); + var x1 = x[0]; + var x2 = x.length > 1 ? decimalSep + x[1] : ''; // Years are ignored for thousands separators if(thouSep && (x.length > 1 || x1.length > 4 || separatethousands)) { diff --git a/src/lib/matrix.js b/src/lib/matrix.js index 685fd38bd33..2b2cd4640d5 100644 --- a/src/lib/matrix.js +++ b/src/lib/matrix.js @@ -22,10 +22,9 @@ exports.init2dArray = function(rowLength, colLength) { * transposing-a-2d-array-in-javascript */ exports.transposeRagged = function(z) { - var maxlen = 0, - zlen = z.length, - i, - j; + var maxlen = 0; + var zlen = z.length; + var i, j; // Maximum row length: for(i = 0; i < zlen; i++) maxlen = Math.max(maxlen, z[i].length); @@ -42,9 +41,9 @@ exports.transposeRagged = function(z) { exports.dot = function(x, y) { if(!(x.length && y.length) || x.length !== y.length) return null; - var len = x.length, - out, - i; + var len = x.length; + var out; + var i; if(x[0].length) { // mat-vec or mat-mat diff --git a/src/lib/nested_property.js b/src/lib/nested_property.js index b88017445a0..f5d3b9270b4 100644 --- a/src/lib/nested_property.js +++ b/src/lib/nested_property.js @@ -33,11 +33,11 @@ module.exports = function nestedProperty(container, propStr) { throw 'bad property string'; } - var j = 0, - propParts = propStr.split('.'), - indexed, - indices, - i; + var j = 0; + var propParts = propStr.split('.'); + var indexed; + var indices; + var i; // check for parts of the nesting hierarchy that are numbers (ie array elements) while(j < propParts.length) { @@ -76,12 +76,12 @@ module.exports = function nestedProperty(container, propStr) { function npGet(cont, parts) { return function() { - var curCont = cont, - curPart, - allSame, - out, - i, - j; + var curCont = cont; + var curPart; + var allSame; + var out; + var i; + var j; for(i = 0; i < parts.length - 1; i++) { curPart = parts[i]; @@ -132,12 +132,12 @@ function isDeletable(val, propStr) { function npSet(cont, parts, propStr) { return function(val) { - var curCont = cont, - propPart = '', - containerLevels = [[cont, propPart]], - toDelete = isDeletable(val, propStr), - curPart, - i; + var curCont = cont; + var propPart = ''; + var containerLevels = [[cont, propPart]]; + var toDelete = isDeletable(val, propStr); + var curPart; + var i; for(i = 0; i < parts.length - 1; i++) { curPart = parts[i]; @@ -196,13 +196,13 @@ function joinPropStr(propStr, newPart) { // handle special -1 array index function setArrayAll(containerArray, innerParts, val, propStr) { - var arrayVal = isArrayOrTypedArray(val), - allSet = true, - thisVal = val, - thisPropStr = propStr.replace('-1', 0), - deleteThis = arrayVal ? false : isDeletable(val, thisPropStr), - firstPart = innerParts[0], - i; + var arrayVal = isArrayOrTypedArray(val); + var allSet = true; + var thisVal = val; + var thisPropStr = propStr.replace('-1', 0); + var deleteThis = arrayVal ? false : isDeletable(val, thisPropStr); + var firstPart = innerParts[0]; + var i; for(i = 0; i < containerArray.length; i++) { thisPropStr = propStr.replace('-1', i); diff --git a/src/lib/polygon.js b/src/lib/polygon.js index fb07a677af6..cb64d28f401 100644 --- a/src/lib/polygon.js +++ b/src/lib/polygon.js @@ -31,12 +31,12 @@ var polygon = module.exports = {}; * returns boolean: is pt inside the polygon (including on its edges) */ polygon.tester = function tester(ptsIn) { - var pts = ptsIn.slice(), - xmin = pts[0][0], - xmax = xmin, - ymin = pts[0][1], - ymax = ymin, - i; + var pts = ptsIn.slice(); + var xmin = pts[0][0]; + var xmax = xmin; + var ymin = pts[0][1]; + var ymax = ymin; + var i; pts.push(pts[0]); for(i = 1; i < pts.length; i++) { @@ -49,8 +49,8 @@ polygon.tester = function tester(ptsIn) { // do we have a rectangle? Handle this here, so we can use the same // tester for the rectangular case without sacrificing speed - var isRect = false, - rectFirstEdgeTest; + var isRect = false; + var rectFirstEdgeTest; if(pts.length === 5) { if(pts[0][0] === pts[1][0]) { // vert, horz, vert, horz @@ -72,8 +72,8 @@ polygon.tester = function tester(ptsIn) { } function rectContains(pt, omitFirstEdge) { - var x = pt[0], - y = pt[1]; + var x = pt[0]; + var y = pt[1]; if(x === BADNUM || x < xmin || x > xmax || y === BADNUM || y < ymin || y > ymax) { // pt is outside the bounding box of polygon @@ -85,23 +85,23 @@ polygon.tester = function tester(ptsIn) { } function contains(pt, omitFirstEdge) { - var x = pt[0], - y = pt[1]; + var x = pt[0]; + var y = pt[1]; if(x === BADNUM || x < xmin || x > xmax || y === BADNUM || y < ymin || y > ymax) { // pt is outside the bounding box of polygon return false; } - var imax = pts.length, - x1 = pts[0][0], - y1 = pts[0][1], - crossings = 0, - i, - x0, - y0, - xmini, - ycross; + var imax = pts.length; + var x1 = pts[0][0]; + var y1 = pts[0][1]; + var crossings = 0; + var i; + var x0; + var y0; + var xmini; + var ycross; for(i = 1; i < imax; i++) { // find all crossings of a vertical line upward from pt with @@ -183,14 +183,14 @@ polygon.tester = function tester(ptsIn) { * @returns boolean: true means this segment is bent, false means straight */ var isBent = polygon.isSegmentBent = function isBent(pts, start, end, tolerance) { - var startPt = pts[start], - segment = [pts[end][0] - startPt[0], pts[end][1] - startPt[1]], - segmentSquared = dot(segment, segment), - segmentLen = Math.sqrt(segmentSquared), - unitPerp = [-segment[1] / segmentLen, segment[0] / segmentLen], - i, - part, - partParallel; + var startPt = pts[start]; + var segment = [pts[end][0] - startPt[0], pts[end][1] - startPt[1]]; + var segmentSquared = dot(segment, segment); + var segmentLen = Math.sqrt(segmentSquared); + var unitPerp = [-segment[1] / segmentLen, segment[0] / segmentLen]; + var i; + var part; + var partParallel; for(i = start + 1; i < end; i++) { part = [pts[i][0] - startPt[0], pts[i][1] - startPt[1]]; @@ -216,14 +216,14 @@ var isBent = polygon.isSegmentBent = function isBent(pts, start, end, tolerance) * filtered is the resulting filtered Array of [x, y] pairs */ polygon.filter = function filter(pts, tolerance) { - var ptsFiltered = [pts[0]], - doneRawIndex = 0, - doneFilteredIndex = 0; + var ptsFiltered = [pts[0]]; + var doneRawIndex = 0; + var doneFilteredIndex = 0; function addPt(pt) { pts.push(pt); - var prevFilterLen = ptsFiltered.length, - iLast = doneRawIndex; + var prevFilterLen = ptsFiltered.length; + var iLast = doneRawIndex; ptsFiltered.splice(doneFilteredIndex + 1); for(var i = iLast + 1; i < pts.length; i++) { diff --git a/src/lib/push_unique.js b/src/lib/push_unique.js index ca2dcf30d4c..a54e4ef5c2e 100644 --- a/src/lib/push_unique.js +++ b/src/lib/push_unique.js @@ -23,9 +23,8 @@ */ module.exports = function pushUnique(array, item) { if(item instanceof RegExp) { - var itemStr = item.toString(), - i; - for(i = 0; i < array.length; i++) { + var itemStr = item.toString(); + for(var i = 0; i < array.length; i++) { if(array[i] instanceof RegExp && array[i].toString() === itemStr) { return array; } diff --git a/src/lib/search.js b/src/lib/search.js index 2d745cc9284..6b7dc5c0520 100644 --- a/src/lib/search.js +++ b/src/lib/search.js @@ -75,10 +75,10 @@ exports.distinctVals = function(valsIn) { var vals = valsIn.slice(); // otherwise we sort the original array... vals.sort(exports.sorterAsc); - var l = vals.length - 1, - minDiff = (vals[l] - vals[0]) || 1, - errDiff = minDiff / (l || 1) / 10000, - v2 = [vals[0]]; + var l = vals.length - 1; + var minDiff = (vals[l] - vals[0]) || 1; + var errDiff = minDiff / (l || 1) / 10000; + var v2 = [vals[0]]; for(var i = 0; i < l; i++) { // make sure values aren't just off by a rounding error @@ -99,13 +99,13 @@ exports.distinctVals = function(valsIn) { * binary search is probably overkill here... */ exports.roundUp = function(val, arrayIn, reverse) { - var low = 0, - high = arrayIn.length - 1, - mid, - c = 0, - dlow = reverse ? 0 : 1, - dhigh = reverse ? 1 : 0, - rounded = reverse ? Math.ceil : Math.floor; + var low = 0; + var high = arrayIn.length - 1; + var mid; + var c = 0; + var dlow = reverse ? 0 : 1; + var dhigh = reverse ? 1 : 0; + var rounded = reverse ? Math.ceil : Math.floor; // c is just to avoid infinite loops if there's an error while(low < high && c++ < 100) { mid = rounded((low + high) / 2); diff --git a/src/lib/svg_text_utils.js b/src/lib/svg_text_utils.js index 54f0a660962..f894ce73a55 100644 --- a/src/lib/svg_text_utils.js +++ b/src/lib/svg_text_utils.js @@ -116,13 +116,13 @@ exports.convertToTspans = function(_context, gd, _callback) { var fill = _context.node().style.fill || 'black'; newSvg.select('g').attr({fill: fill, stroke: fill}); - var newSvgW = getSize(newSvg, 'width'), - newSvgH = getSize(newSvg, 'height'), - newX = +_context.attr('x') - newSvgW * - {start: 0, middle: 0.5, end: 1}[_context.attr('text-anchor') || 'start'], - // font baseline is about 1/4 fontSize below centerline - textHeight = fontSize || getSize(_context, 'height'), - dy = -textHeight / 4; + var newSvgW = getSize(newSvg, 'width'); + var newSvgH = getSize(newSvg, 'height'); + var newX = +_context.attr('x') - newSvgW * + {start: 0, middle: 0.5, end: 1}[_context.attr('text-anchor') || 'start']; + // font baseline is about 1/4 fontSize below centerline + var textHeight = fontSize || getSize(_context, 'height'); + var dy = -textHeight / 4; if(svgClass[0] === 'y') { mathjaxGroup.attr({ @@ -612,13 +612,13 @@ exports.positionText = function positionText(s, x, y) { }; function alignHTMLWith(_base, container, options) { - var alignH = options.horizontalAlign, - alignV = options.verticalAlign || 'top', - bRect = _base.node().getBoundingClientRect(), - cRect = container.node().getBoundingClientRect(), - thisRect, - getTop, - getLeft; + var alignH = options.horizontalAlign; + var alignV = options.verticalAlign || 'top'; + var bRect = _base.node().getBoundingClientRect(); + var cRect = container.node().getBoundingClientRect(); + var thisRect; + var getTop; + var getLeft; if(alignV === 'bottom') { getTop = function() { return bRect.bottom - thisRect.height; }; @@ -676,8 +676,8 @@ exports.makeEditable = function(context, options) { appendEditable(); context.style({opacity: 0}); // also hide any mathjax svg - var svgClass = handlerElement.attr('class'), - mathjaxClass; + var svgClass = handlerElement.attr('class'); + var mathjaxClass; if(svgClass) mathjaxClass = '.' + svgClass.split(' ')[0] + '-math-group'; else mathjaxClass = '[class*=-math-group]'; if(mathjaxClass) { @@ -725,8 +725,8 @@ exports.makeEditable = function(context, options) { gd._editing = false; context.text(this.textContent) .style({opacity: 1}); - var svgClass = d3.select(this).attr('class'), - mathjaxClass; + var svgClass = d3.select(this).attr('class'); + var mathjaxClass; if(svgClass) mathjaxClass = '.' + svgClass.split(' ')[0] + '-math-group'; else mathjaxClass = '[class*=-math-group]'; if(mathjaxClass) { diff --git a/src/lib/topojson_utils.js b/src/lib/topojson_utils.js index b07a1301e45..1eb95e7772e 100644 --- a/src/lib/topojson_utils.js +++ b/src/lib/topojson_utils.js @@ -6,7 +6,6 @@ * LICENSE file in the root directory of this source tree. */ - 'use strict'; var topojsonUtils = module.exports = {}; @@ -14,7 +13,6 @@ var topojsonUtils = module.exports = {}; var locationmodeToLayer = require('../plots/geo/constants').locationmodeToLayer; var topojsonFeature = require('topojson-client').feature; - topojsonUtils.getTopojsonName = function(geoLayout) { return [ geoLayout.scope.replace(/ /g, '-'), '_', @@ -27,8 +25,8 @@ topojsonUtils.getTopojsonPath = function(topojsonURL, topojsonName) { }; topojsonUtils.getTopojsonFeatures = function(trace, topojson) { - var layer = locationmodeToLayer[trace.locationmode], - obj = topojson.objects[layer]; + var layer = locationmodeToLayer[trace.locationmode]; + var obj = topojson.objects[layer]; return topojsonFeature(topojson, obj).features; }; diff --git a/src/plot_api/container_array_match.js b/src/plot_api/container_array_match.js index 1fc7f1e8e8a..62a5b654a5e 100644 --- a/src/plot_api/container_array_match.js +++ b/src/plot_api/container_array_match.js @@ -25,11 +25,11 @@ var Registry = require('../registry'); * or the whole object) */ module.exports = function containerArrayMatch(astr) { - var rootContainers = Registry.layoutArrayContainers, - regexpContainers = Registry.layoutArrayRegexes, - rootPart = astr.split('[')[0], - arrayStr, - match; + var rootContainers = Registry.layoutArrayContainers; + var regexpContainers = Registry.layoutArrayRegexes; + var rootPart = astr.split('[')[0]; + var arrayStr; + var match; // look for regexp matches first, because they may be nested inside root matches // eg updatemenus[i].buttons is nested inside updatemenus diff --git a/src/plot_api/helpers.js b/src/plot_api/helpers.js index e2c244cbfd7..1b6cce24daf 100644 --- a/src/plot_api/helpers.js +++ b/src/plot_api/helpers.js @@ -121,11 +121,11 @@ exports.cleanLayout = function(layout) { var cameraposition = scene.cameraposition; if(Array.isArray(cameraposition) && cameraposition[0].length === 4) { - var rotation = cameraposition[0], - center = cameraposition[1], - radius = cameraposition[2], - mat = m4FromQuat([], rotation), - eye = []; + var rotation = cameraposition[0]; + var center = cameraposition[1]; + var radius = cameraposition[2]; + var mat = m4FromQuat([], rotation); + var eye = []; for(j = 0; j < 3; ++j) { eye[j] = center[j] + radius * mat[2 + 4 * j]; @@ -222,8 +222,8 @@ exports.cleanLayout = function(layout) { }; function cleanAxRef(container, attr) { - var valIn = container[attr], - axLetter = attr.charAt(0); + var valIn = container[attr]; + var axLetter = attr.charAt(0); if(valIn && valIn !== 'paper') { container[attr] = cleanId(valIn, axLetter); } @@ -289,9 +289,10 @@ exports.cleanData = function(data) { // error_y.opacity is obsolete - merge into color if(trace.error_y && 'opacity' in trace.error_y) { - var dc = Color.defaults, - yeColor = trace.error_y.color || - (Registry.traceIs(trace, 'bar') ? Color.defaultLine : dc[tracei % dc.length]); + var dc = Color.defaults; + var yeColor = trace.error_y.color || (Registry.traceIs(trace, 'bar') ? + Color.defaultLine : + dc[tracei % dc.length]); trace.error_y.color = Color.addOpacity( Color.rgb(yeColor), Color.opacity(yeColor) * trace.error_y.opacity); @@ -517,8 +518,8 @@ function commonPrefix(name1, name2, show1, show2) { // textposition - support partial attributes (ie just 'top') // and incorrect use of middle / center etc. function cleanTextPosition(textposition) { - var posY = 'middle', - posX = 'center'; + var posY = 'middle'; + var posX = 'center'; if(typeof textposition === 'string') { if(textposition.indexOf('top') !== -1) posY = 'top'; @@ -547,9 +548,10 @@ exports.swapXYData = function(trace) { else trace.transpose = true; } if(trace.error_x && trace.error_y) { - var errorY = trace.error_y, - copyYstyle = ('copy_ystyle' in errorY) ? errorY.copy_ystyle : - !(errorY.color || errorY.thickness || errorY.width); + var errorY = trace.error_y; + var copyYstyle = ('copy_ystyle' in errorY) ? + errorY.copy_ystyle : + !(errorY.color || errorY.thickness || errorY.width); Lib.swapAttrs(trace, ['error_?.copy_ystyle']); if(copyYstyle) { Lib.swapAttrs(trace, ['error_?.color', 'error_?.thickness', 'error_?.width']); @@ -601,10 +603,10 @@ exports.coerceTraceIndices = function(gd, traceIndices) { * */ exports.manageArrayContainers = function(np, newVal, undoit) { - var obj = np.obj, - parts = np.parts, - pLength = parts.length, - pLast = parts[pLength - 1]; + var obj = np.obj; + var parts = np.parts; + var pLength = parts.length; + var pLast = parts[pLength - 1]; var pLastIsNumber = isNumeric(pLast); @@ -612,8 +614,8 @@ exports.manageArrayContainers = function(np, newVal, undoit) { if(pLastIsNumber && newVal === null) { // Clear item in array container when new value is null - var contPath = parts.slice(0, pLength - 1).join('.'), - cont = Lib.nestedProperty(obj, contPath).get(); + var contPath = parts.slice(0, pLength - 1).join('.'); + var cont = Lib.nestedProperty(obj, contPath).get(); cont.splice(pLast, 1); // Note that nested property clears null / undefined at end of diff --git a/src/plot_api/manage_arrays.js b/src/plot_api/manage_arrays.js index 99def8f1508..885b4f1fed7 100644 --- a/src/plot_api/manage_arrays.js +++ b/src/plot_api/manage_arrays.js @@ -74,14 +74,13 @@ var isRemoveVal = exports.isRemoveVal = function isRemoveVal(val) { * `false` would mean the parent should replot. */ exports.applyContainerArrayChanges = function applyContainerArrayChanges(gd, np, edits, flags, _nestedProperty) { - var componentType = np.astr, - supplyComponentDefaults = Registry.getComponentMethod(componentType, 'supplyLayoutDefaults'), - draw = Registry.getComponentMethod(componentType, 'draw'), - drawOne = Registry.getComponentMethod(componentType, 'drawOne'), - replotLater = flags.replot || flags.recalc || (supplyComponentDefaults === noop) || - (draw === noop), - layout = gd.layout, - fullLayout = gd._fullLayout; + var componentType = np.astr; + var supplyComponentDefaults = Registry.getComponentMethod(componentType, 'supplyLayoutDefaults'); + var draw = Registry.getComponentMethod(componentType, 'draw'); + var drawOne = Registry.getComponentMethod(componentType, 'drawOne'); + var replotLater = flags.replot || flags.recalc || (supplyComponentDefaults === noop) || (draw === noop); + var layout = gd.layout; + var fullLayout = gd._fullLayout; if(edits['']) { if(Object.keys(edits).length > 1) { @@ -105,26 +104,26 @@ exports.applyContainerArrayChanges = function applyContainerArrayChanges(gd, np, return true; } - var componentNums = Object.keys(edits).map(Number).sort(sorterAsc), - componentArrayIn = np.get(), - componentArray = componentArrayIn || [], - // componentArrayFull is used just to keep splices in line between - // full and input arrays, so private keys can be copied over after - // redoing supplyDefaults - // TODO: this assumes componentArray is in gd.layout - which will not be - // true after we extend this to restyle - componentArrayFull = _nestedProperty(fullLayout, componentType).get(); - - var deletes = [], - firstIndexChange = -1, - maxIndex = componentArray.length, - i, - j, - componentNum, - objEdits, - objKeys, - objVal, - adding, prefix; + var componentNums = Object.keys(edits).map(Number).sort(sorterAsc); + var componentArrayIn = np.get(); + var componentArray = componentArrayIn || []; + // componentArrayFull is used just to keep splices in line between + // full and input arrays, so private keys can be copied over after + // redoing supplyDefaults + // TODO: this assumes componentArray is in gd.layout - which will not be + // true after we extend this to restyle + var componentArrayFull = _nestedProperty(fullLayout, componentType).get(); + + var deletes = []; + var firstIndexChange = -1; + var maxIndex = componentArray.length; + var i; + var j; + var componentNum; + var objEdits; + var objKeys; + var objVal; + var adding, prefix; // first make the add and edit changes for(i = 0; i < componentNums.length; i++) { diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 5107d512715..5400519d0ed 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -646,10 +646,10 @@ exports.newPlot = function(gd, data, layout, config) { * @param {Number} maxIndex The maximum index allowable (arr.length - 1) */ function positivifyIndices(indices, maxIndex) { - var parentLength = maxIndex + 1, - positiveIndices = [], - i, - index; + var parentLength = maxIndex + 1; + var positiveIndices = []; + var i; + var index; for(i = 0; i < indices.length; i++) { index = indices[i]; @@ -837,8 +837,8 @@ function assertExtendTracesArgs(gd, update, indices, maxPoints) { */ function getExtendProperties(gd, update, indices, maxPoints) { - var maxPointsIsObject = Lib.isPlainObject(maxPoints), - updateProps = []; + var maxPointsIsObject = Lib.isPlainObject(maxPoints); + var updateProps = []; var trace, target, prop, insert, maxp; // allow scalar index to represent a single trace position @@ -1091,13 +1091,13 @@ exports.prependTraces = function prependTraces(gd, update, indices, maxPoints) { exports.addTraces = function addTraces(gd, traces, newIndices) { gd = Lib.getGraphDiv(gd); - var currentIndices = [], - undoFunc = exports.deleteTraces, - redoFunc = addTraces, - undoArgs = [gd, currentIndices], - redoArgs = [gd, traces], // no newIndices here - i, - promise; + var currentIndices = []; + var undoFunc = exports.deleteTraces; + var redoFunc = addTraces; + var undoArgs = [gd, currentIndices]; + var redoArgs = [gd, traces]; // no newIndices here + var i; + var promise; // all validation is done elsewhere to remove clutter here checkAddTracesArgs(gd, traces, newIndices); @@ -1168,13 +1168,13 @@ exports.addTraces = function addTraces(gd, traces, newIndices) { exports.deleteTraces = function deleteTraces(gd, indices) { gd = Lib.getGraphDiv(gd); - var traces = [], - undoFunc = exports.addTraces, - redoFunc = deleteTraces, - undoArgs = [gd, traces, indices], - redoArgs = [gd, indices], - i, - deletedTrace; + var traces = []; + var undoFunc = exports.addTraces; + var redoFunc = deleteTraces; + var undoArgs = [gd, traces, indices]; + var redoArgs = [gd, indices]; + var i; + var deletedTrace; // make sure indices are defined if(typeof indices === 'undefined') { @@ -1234,13 +1234,13 @@ exports.deleteTraces = function deleteTraces(gd, indices) { exports.moveTraces = function moveTraces(gd, currentIndices, newIndices) { gd = Lib.getGraphDiv(gd); - var newData = [], - movingTraceMap = [], - undoFunc = moveTraces, - redoFunc = moveTraces, - undoArgs = [gd, newIndices, currentIndices], - redoArgs = [gd, currentIndices, newIndices], - i; + var newData = []; + var movingTraceMap = []; + var undoFunc = moveTraces; + var redoFunc = moveTraces; + var undoArgs = [gd, newIndices, currentIndices]; + var redoArgs = [gd, currentIndices, newIndices]; + var i; // to reduce complexity here, check args elsewhere // this throws errors where appropriate @@ -1485,9 +1485,9 @@ function _restyle(gd, aobj, traces) { // copies of the change (and previous values of anything affected) // for the undo / redo queue - var redoit = {}, - undoit = {}, - axlist; + var redoit = {}; + var undoit = {}; + var axlist; // make a new empty vals array for undoit function a0() { return traces.map(function() { return undefined; }); } @@ -1564,13 +1564,13 @@ function _restyle(gd, aobj, traces) { throw new Error('cannot set ' + ai + 'and a parent attribute simultaneously'); } - var vi = aobj[ai], - cont, - contFull, - param, - oldVal, - newVal, - valObject; + var vi = aobj[ai]; + var cont; + var contFull; + var param; + var oldVal; + var newVal; + var valObject; // Backward compatibility shim for turning histogram autobin on, // or freezing previous autobinned values. @@ -1649,8 +1649,8 @@ function _restyle(gd, aobj, traces) { } else if(ai === 'type' && (newVal === 'pie') !== (oldVal === 'pie')) { - var labelsTo = 'x', - valuesTo = 'y'; + var labelsTo = 'x'; + var valuesTo = 'y'; if((newVal === 'bar' || oldVal === 'bar') && cont.orientation === 'h') { labelsTo = 'y'; valuesTo = 'x'; @@ -1983,9 +1983,9 @@ function _relayout(gd, aobj) { for(i = 0; i < keys.length; i++) { if(keys[i].indexOf('allaxes') === 0) { for(j = 0; j < axes.length; j++) { - var scene = axes[j]._id.substr(1), - axisAttr = (scene.indexOf('scene') !== -1) ? (scene + '.') : '', - newkey = keys[i].replace('allaxes', axisAttr + axes[j]._name); + var scene = axes[j]._id.substr(1); + var axisAttr = (scene.indexOf('scene') !== -1) ? (scene + '.') : ''; + var newkey = keys[i].replace('allaxes', axisAttr + axes[j]._name); if(!aobj[newkey]) aobj[newkey] = aobj[keys[i]]; } @@ -1999,8 +1999,8 @@ function _relayout(gd, aobj) { // copies of the change (and previous values of anything affected) // for the undo / redo queue - var redoit = {}, - undoit = {}; + var redoit = {}; + var undoit = {}; // for attrs that interact (like scales & autoscales), save the // old vals before making the change @@ -2121,9 +2121,9 @@ function _relayout(gd, aobj) { // previously we did this for log <-> not-log, but now only do it // for log <-> linear if(pleaf === 'type') { - var ax = parentIn, - toLog = parentFull.type === 'linear' && vi === 'log', - fromLog = parentFull.type === 'log' && vi === 'linear'; + var ax = parentIn; + var toLog = parentFull.type === 'linear' && vi === 'log'; + var fromLog = parentFull.type === 'log' && vi === 'linear'; if(toLog || fromLog) { if(!ax || !ax.range) { @@ -2135,8 +2135,8 @@ function _relayout(gd, aobj) { else if(!parentFull.autorange) { // toggling log without autorange: need to also recalculate ranges // because log axes use linearized values for range endpoints - var r0 = ax.range[0], - r1 = ax.range[1]; + var r0 = ax.range[0]; + var r1 = ax.range[1]; if(toLog) { // if both limits are negative, autorange if(r0 <= 0 && r1 <= 0) { @@ -2184,8 +2184,8 @@ function _relayout(gd, aobj) { nestedProperty(fullLayout, ptrunk + '._inputRange').set(null); } else if(pleaf.match(AX_NAME_PATTERN)) { - var fullProp = nestedProperty(fullLayout, ai).get(), - newType = (vi || {}).type; + var fullProp = nestedProperty(fullLayout, ai).get(); + var newType = (vi || {}).type; // This can potentially cause strange behavior if the autotype is not // numeric (linear, because we don't auto-log) but the previous type @@ -2367,8 +2367,8 @@ function update(gd, traceUpdate, layoutUpdate, _traces) { var seq = []; if(restyleFlags.fullReplot && relayoutFlags.layoutReplot) { - var data = gd.data, - layout = gd.layout; + var data = gd.data; + var layout = gd.layout; // clear existing data/layout on gd // so that Plotly.plot doesn't try to extend them @@ -3558,10 +3558,10 @@ exports.addFrames = function(gd, frameList, indices) { } } - var undoFunc = Plots.modifyFrames, - redoFunc = Plots.modifyFrames, - undoArgs = [gd, revops], - redoArgs = [gd, ops]; + var undoFunc = Plots.modifyFrames; + var redoFunc = Plots.modifyFrames; + var undoArgs = [gd, revops]; + var redoArgs = [gd, ops]; if(Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); @@ -3605,10 +3605,10 @@ exports.deleteFrames = function(gd, frameList) { revops.unshift({type: 'insert', index: idx, value: _frames[idx]}); } - var undoFunc = Plots.modifyFrames, - redoFunc = Plots.modifyFrames, - undoArgs = [gd, revops], - redoArgs = [gd, ops]; + var undoFunc = Plots.modifyFrames; + var redoFunc = Plots.modifyFrames; + var undoArgs = [gd, revops]; + var redoArgs = [gd, ops]; if(Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); diff --git a/src/plot_api/plot_schema.js b/src/plot_api/plot_schema.js index c33538ee25e..265e8bf5d03 100644 --- a/src/plot_api/plot_schema.js +++ b/src/plot_api/plot_schema.js @@ -688,8 +688,8 @@ function assignPolarLayoutAttrs(layoutAttributes) { } function handleBasePlotModule(layoutAttributes, _module, astr) { - var np = Lib.nestedProperty(layoutAttributes, astr), - attrs = extendDeepAll({}, _module.layoutAttributes); + var np = Lib.nestedProperty(layoutAttributes, astr); + var attrs = extendDeepAll({}, _module.layoutAttributes); attrs[IS_SUBPLOT_OBJ] = true; np.set(attrs); diff --git a/src/plot_api/subroutines.js b/src/plot_api/subroutines.js index 3033462e785..9bb92c0c6e0 100644 --- a/src/plot_api/subroutines.js +++ b/src/plot_api/subroutines.js @@ -37,8 +37,8 @@ exports.layoutStyles = function(gd) { function overlappingDomain(xDomain, yDomain, domains) { for(var i = 0; i < domains.length; i++) { - var existingX = domains[i][0], - existingY = domains[i][1]; + var existingX = domains[i][0]; + var existingY = domains[i][1]; if(existingX[0] >= xDomain[1] || existingX[1] <= xDomain[0]) { continue; @@ -532,8 +532,8 @@ exports.doColorBars = function(gd) { var cdi0 = gd.calcdata[i][0]; if((cdi0.t || {}).cb) { - var trace = cdi0.trace, - cb = cdi0.t.cb; + var trace = cdi0.trace; + var cb = cdi0.t.cb; if(Registry.traceIs(trace, 'contour')) { cb.line({ diff --git a/src/plot_api/validate.js b/src/plot_api/validate.js index 995d7a4aa33..7c0f3dcac23 100644 --- a/src/plot_api/validate.js +++ b/src/plot_api/validate.js @@ -73,21 +73,21 @@ module.exports = function validate(data, layout) { Plots.supplyDefaults(gd); - var dataOut = gd._fullData, - len = dataIn.length; + var dataOut = gd._fullData; + var len = dataIn.length; for(var i = 0; i < len; i++) { - var traceIn = dataIn[i], - base = ['data', i]; + var traceIn = dataIn[i]; + var base = ['data', i]; if(!isPlainObject(traceIn)) { errorList.push(format('object', base)); continue; } - var traceOut = dataOut[i], - traceType = traceOut.type, - traceSchema = schema.traces[traceType].attributes; + var traceOut = dataOut[i]; + var traceType = traceOut.type; + var traceSchema = schema.traces[traceType].attributes; // PlotSchema does something fancy with trace 'type', reset it here // to make the trace schema compatible with Lib.validate. @@ -102,8 +102,8 @@ module.exports = function validate(data, layout) { crawl(traceIn, traceOut, traceSchema, errorList, base); - var transformsIn = traceIn.transforms, - transformsOut = traceOut.transforms; + var transformsIn = traceIn.transforms; + var transformsOut = traceOut.transforms; if(transformsIn) { if(!isArray(transformsIn)) { @@ -113,8 +113,8 @@ module.exports = function validate(data, layout) { base.push('transforms'); for(var j = 0; j < transformsIn.length; j++) { - var path = ['transforms', j], - transformType = transformsIn[j].type; + var path = ['transforms', j]; + var transformType = transformsIn[j].type; if(!isPlainObject(transformsIn[j])) { errorList.push(format('object', base, path)); @@ -136,8 +136,8 @@ module.exports = function validate(data, layout) { } } - var layoutOut = gd._fullLayout, - layoutSchema = fillLayoutSchema(schema, dataOut); + var layoutOut = gd._fullLayout; + var layoutSchema = fillLayoutSchema(schema, dataOut); crawl(layoutIn, layoutOut, layoutSchema, errorList, 'layout'); @@ -159,8 +159,8 @@ function crawl(objIn, objOut, schema, list, base, path) { var p = path.slice(); p.push(k); - var valIn = objIn[k], - valOut = objOut[k]; + var valIn = objIn[k]; + var valOut = objOut[k]; var nestedSchema = getNestedSchema(schema, k); var isInfoArray = (nestedSchema || {}).valType === 'info_array'; @@ -220,8 +220,8 @@ function crawl(objIn, objOut, schema, list, base, path) { } } else if(nestedSchema.items && !isInfoArray && isArray(valIn)) { - var _nestedSchema = items[Object.keys(items)[0]], - indexList = []; + var _nestedSchema = items[Object.keys(items)[0]]; + var indexList = []; var j, _p; @@ -392,9 +392,9 @@ function format(code, base, path, valIn, valOut) { } function isInSchema(schema, key) { - var parts = splitKey(key), - keyMinusId = parts.keyMinusId, - id = parts.id; + var parts = splitKey(key); + var keyMinusId = parts.keyMinusId; + var id = parts.id; if((keyMinusId in schema) && schema[keyMinusId]._isSubplotObj && id) { return true; diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 5f1ffe6a506..cb21644aab5 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -775,9 +775,9 @@ function autoTickRound(ax) { // not necessarily *all* the information in tick0 though, if it's really odd // minimal string length for tick0: 'd' is 10, 'M' is 16, 'S' is 19 // take off a leading minus (year < 0) and i (intercalary month) so length is consistent - var tick0ms = ax.r2l(ax.tick0), - tick0str = ax.l2r(tick0ms).replace(/(^-|i)/g, ''), - tick0len = tick0str.length; + var tick0ms = ax.r2l(ax.tick0); + var tick0str = ax.l2r(tick0ms).replace(/(^-|i)/g, ''); + var tick0len = tick0str.length; if(String(dtick).charAt(0) === 'M') { // any tick0 more specific than a year: alway show the full date @@ -835,8 +835,8 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) { if(isNumeric(dtick)) return x + axSign * dtick; // everything else is a string, one character plus a number - var tType = dtick.charAt(0), - dtSigned = axSign * Number(dtick.substr(1)); + var tType = dtick.charAt(0); + var dtSigned = axSign * Number(dtick.substr(1)); // Dates: months (or years - see Lib.incrementMonth) if(tType === 'M') return Lib.incrementMonth(x, dtSigned, calendar); @@ -847,9 +847,9 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) { // log10 of 2,5,10, or all digits (logs just have to be // close enough to round) else if(tType === 'D') { - var tickset = (dtick === 'D2') ? roundLog2 : roundLog1, - x2 = x + axSign * 0.01, - frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev); + var tickset = (dtick === 'D2') ? roundLog2 : roundLog1; + var x2 = x + axSign * 0.01; + var frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev); return Math.floor(x2) + Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10; @@ -912,8 +912,8 @@ axes.tickFirst = function(ax) { (Math.pow(10, r0) - tick0) / dtNum) * dtNum + tick0) / Math.LN10; } else if(tType === 'D') { - var tickset = (dtick === 'D2') ? roundLog2 : roundLog1, - frac = Lib.roundUp(Lib.mod(r0, 1), tickset, axrev); + var tickset = (dtick === 'D2') ? roundLog2 : roundLog1; + var frac = Lib.roundUp(Lib.mod(r0, 1), tickset, axrev); return Math.floor(r0) + Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10; @@ -2814,14 +2814,13 @@ axes.swap = function(gd, traces) { }; function makeAxisGroups(gd, traces) { - var groups = [], - i, - j; + var groups = []; + var i, j; for(i = 0; i < traces.length; i++) { - var groupsi = [], - xi = gd._fullData[traces[i]].xaxis, - yi = gd._fullData[traces[i]].yaxis; + var groupsi = []; + var xi = gd._fullData[traces[i]].xaxis; + var yi = gd._fullData[traces[i]].yaxis; if(!xi || !yi) continue; // not a 2D cartesian trace? for(j = 0; j < groups.length; j++) { @@ -2835,8 +2834,8 @@ function makeAxisGroups(gd, traces) { continue; } - var group0 = groups[groupsi[0]], - groupj; + var group0 = groups[groupsi[0]]; + var groupj; if(groupsi.length > 1) { for(j = 1; j < groupsi.length; j++) { diff --git a/src/plots/cartesian/dragbox.js b/src/plots/cartesian/dragbox.js index 806ae3b4ccc..ca933deda77 100644 --- a/src/plots/cartesian/dragbox.js +++ b/src/plots/cartesian/dragbox.js @@ -242,12 +242,12 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) { } } else if(numClicks === 1 && singleEnd) { - var ax = ns ? ya0 : xa0, - end = (ns === 's' || ew === 'w') ? 0 : 1, - attrStr = ax._name + '.range[' + end + ']', - initialText = getEndText(ax, end), - hAlign = 'left', - vAlign = 'middle'; + var ax = ns ? ya0 : xa0; + var end = (ns === 's' || ew === 'w') ? 0 : 1; + var attrStr = ax._name + '.range[' + end + ']'; + var initialText = getEndText(ax, end); + var hAlign = 'left'; + var vAlign = 'middle'; if(ax.fixedrange) return; @@ -316,10 +316,10 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) { return false; } - var x1 = Math.max(0, Math.min(pw, dx0 + x0)), - y1 = Math.max(0, Math.min(ph, dy0 + y0)), - dx = Math.abs(x1 - x0), - dy = Math.abs(y1 - y0); + var x1 = Math.max(0, Math.min(pw, dx0 + x0)); + var y1 = Math.max(0, Math.min(ph, dy0 + y0)); + var dx = Math.abs(x1 - x0); + var dy = Math.abs(y1 - y0); box.l = Math.min(x0, x1); box.r = Math.max(x0, x1); @@ -450,18 +450,17 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) { return; } - var zoom = Math.exp(-Math.min(Math.max(wheelDelta, -20), 20) / 200), - gbb = mainplot.draglayer.select('.nsewdrag') - .node().getBoundingClientRect(), - xfrac = (e.clientX - gbb.left) / gbb.width, - yfrac = (gbb.bottom - e.clientY) / gbb.height, - i; + var zoom = Math.exp(-Math.min(Math.max(wheelDelta, -20), 20) / 200); + var gbb = mainplot.draglayer.select('.nsewdrag').node().getBoundingClientRect(); + var xfrac = (e.clientX - gbb.left) / gbb.width; + var yfrac = (gbb.bottom - e.clientY) / gbb.height; + var i; function zoomWheelOneAxis(ax, centerFraction, zoom) { if(ax.fixedrange) return; - var axRange = Lib.simpleMap(ax.range, ax.r2l), - v0 = axRange[0] + (axRange[1] - axRange[0]) * centerFraction; + var axRange = Lib.simpleMap(ax.range, ax.r2l); + var v0 = axRange[0] + (axRange[1] - axRange[0]) * centerFraction; function doZoom(v) { return ax.l2r(v0 + (v - v0) * zoom); } ax.range = axRange.map(doZoom); } @@ -533,9 +532,9 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) { // TODO: this makes (generally non-fatal) errors when you get // near floating point limits function dz(axArray, end, d) { - var otherEnd = 1 - end, - movedAx, - newLinearizedEnd; + var otherEnd = 1 - end; + var movedAx; + var newLinearizedEnd; for(var i = 0; i < axArray.length; i++) { var axi = axArray[i]; if(axi.fixedrange) continue; @@ -601,8 +600,8 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) { // Draw ticks and annotations (and other components) when ranges change. // Also records the ranges that have changed for use by update at the end. function ticksAndAnnotations(ns, ew) { - var activeAxIds = [], - i; + var activeAxIds = []; + var i; function pushActiveAxIds(axList) { for(i = 0; i < axList.length; i++) { @@ -652,9 +651,9 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) { function doubleClick() { if(gd._transitioningWithDuration) return; - var doubleClickConfig = gd._context.doubleClick, - axList = (xActive ? xaxes : []).concat(yActive ? yaxes : []), - attrs = {}; + var doubleClickConfig = gd._context.doubleClick; + var axList = (xActive ? xaxes : []).concat(yActive ? yaxes : []); + var attrs = {}; var ax, i, rangeInitial; @@ -904,9 +903,9 @@ function isDirectionActive(axList, activeVal) { } function getEndText(ax, end) { - var initialVal = ax.range[end], - diff = Math.abs(initialVal - ax.range[1 - end]), - dig; + var initialVal = ax.range[end]; + var diff = Math.abs(initialVal - ax.range[1 - end]); + var dig; // TODO: this should basically be ax.r2d but we're doing extra // rounding here... can we clean up at all? diff --git a/src/plots/cartesian/graph_interact.js b/src/plots/cartesian/graph_interact.js index 69dc718bf50..94892c35bc9 100644 --- a/src/plots/cartesian/graph_interact.js +++ b/src/plots/cartesian/graph_interact.js @@ -33,8 +33,8 @@ exports.initInteractions = function initInteractions(gd) { // 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'); + var aParts = a.split('y'); + var 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)); diff --git a/src/plots/cartesian/layout_defaults.js b/src/plots/cartesian/layout_defaults.js index 6bf2f652fc6..3f070b4c6c8 100644 --- a/src/plots/cartesian/layout_defaults.js +++ b/src/plots/cartesian/layout_defaults.js @@ -102,12 +102,12 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) { // plot_bgcolor only makes sense if there's a (2D) plot! // TODO: bgcolor for each subplot, to inherit from the main one - var plot_bgcolor = Color.background; + var plotBgColor = Color.background; if(xIds.length && yIds.length) { - plot_bgcolor = Lib.coerce(layoutIn, layoutOut, basePlotLayoutAttributes, 'plot_bgcolor'); + plotBgColor = Lib.coerce(layoutIn, layoutOut, basePlotLayoutAttributes, 'plot_bgcolor'); } - var bgColor = Color.combine(plot_bgcolor, layoutOut.paper_bgcolor); + var bgColor = Color.combine(plotBgColor, layoutOut.paper_bgcolor); var axName, axLetter, axLayoutIn, axLayoutOut; @@ -183,12 +183,12 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) { handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions); handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut); - var spikecolor = coerce2('spikecolor'), - spikethickness = coerce2('spikethickness'), - spikedash = coerce2('spikedash'), - spikemode = coerce2('spikemode'), - spikesnap = coerce2('spikesnap'), - showSpikes = coerce('showspikes', !!spikecolor || !!spikethickness || !!spikedash || !!spikemode || !!spikesnap); + var spikecolor = coerce2('spikecolor'); + var spikethickness = coerce2('spikethickness'); + var spikedash = coerce2('spikedash'); + var spikemode = coerce2('spikemode'); + var spikesnap = coerce2('spikesnap'); + var showSpikes = coerce('showspikes', !!spikecolor || !!spikethickness || !!spikedash || !!spikemode || !!spikesnap); if(!showSpikes) { delete axLayoutOut.spikecolor; diff --git a/src/plots/cartesian/select.js b/src/plots/cartesian/select.js index f1efad89e54..c09ee3d0a9b 100644 --- a/src/plots/cartesian/select.js +++ b/src/plots/cartesian/select.js @@ -126,8 +126,8 @@ function prepSelect(e, startX, startY, dragOptions, mode) { x1 = Math.max(0, Math.min(pw, dx0 + x0)); y1 = Math.max(0, Math.min(ph, dy0 + y0)); - var dx = Math.abs(x1 - x0), - dy = Math.abs(y1 - y0); + var dx = Math.abs(x1 - x0); + var dy = Math.abs(y1 - y0); if(mode === 'select') { var direction = fullLayout.selectdirection; @@ -203,7 +203,9 @@ function prepSelect(e, startX, startY, dragOptions, mode) { function() { selection = []; - var thisSelection, traceSelections = [], traceSelection; + var thisSelection; + var traceSelections = []; + var traceSelection; for(i = 0; i < searchTraces.length; i++) { searchInfo = searchTraces[i]; diff --git a/src/plots/cartesian/set_convert.js b/src/plots/cartesian/set_convert.js index 8129d535188..dafc472c6db 100644 --- a/src/plots/cartesian/set_convert.js +++ b/src/plots/cartesian/set_convert.js @@ -71,8 +71,8 @@ module.exports = function setConvert(ax, fullLayout) { else if(v <= 0 && clip && ax.range && ax.range.length === 2) { // clip NaN (ie past negative infinity) to LOG_CLIP axis // length past the negative edge - var r0 = ax.range[0], - r1 = ax.range[1]; + var r0 = ax.range[0]; + var r1 = ax.range[1]; return 0.5 * (r0 + r1 - 2 * LOG_CLIP * Math.abs(r0 - r1)); } @@ -356,15 +356,15 @@ module.exports = function setConvert(ax, fullLayout) { // find the range value at the specified (linear) fraction of the axis ax.fraction2r = function(v) { - var rl0 = ax.r2l(ax.range[0]), - rl1 = ax.r2l(ax.range[1]); + var rl0 = ax.r2l(ax.range[0]); + var rl1 = ax.r2l(ax.range[1]); return ax.l2r(rl0 + v * (rl1 - rl0)); }; // find the fraction of the range at the specified range value ax.r2fraction = function(v) { - var rl0 = ax.r2l(ax.range[0]), - rl1 = ax.r2l(ax.range[1]); + var rl0 = ax.r2l(ax.range[0]); + var rl1 = ax.r2l(ax.range[1]); return (ax.r2l(v) - rl0) / (rl1 - rl0); }; @@ -457,12 +457,12 @@ module.exports = function setConvert(ax, fullLayout) { // issue if we transform the drawn layer *and* use the new axis range to // draw the data. This allows us to construct setConvert using the pre- // interaction values of the range: - var rangeAttr = (usePrivateRange && ax._r) ? '_r' : 'range', - calendar = ax.calendar; + var rangeAttr = (usePrivateRange && ax._r) ? '_r' : 'range'; + var calendar = ax.calendar; ax.cleanRange(rangeAttr); - var rl0 = ax.r2l(ax[rangeAttr][0], calendar), - rl1 = ax.r2l(ax[rangeAttr][1], calendar); + var rl0 = ax.r2l(ax[rangeAttr][0], calendar); + var rl1 = ax.r2l(ax[rangeAttr][1], calendar); if(axLetter === 'y') { ax._offset = gs.t + (1 - ax.domain[1]) * gs.h; diff --git a/src/plots/cartesian/tick_label_defaults.js b/src/plots/cartesian/tick_label_defaults.js index 446dbd6b7b2..1065860380a 100644 --- a/src/plots/cartesian/tick_label_defaults.js +++ b/src/plots/cartesian/tick_label_defaults.js @@ -71,15 +71,13 @@ module.exports = function handleTickLabelDefaults(containerIn, containerOut, coe * */ function getShowAttrDflt(containerIn) { - var showAttrsAll = ['showexponent', - 'showtickprefix', - 'showticksuffix'], - showAttrs = showAttrsAll.filter(function(a) { - return containerIn[a] !== undefined; - }), - sameVal = function(a) { - return containerIn[a] === containerIn[showAttrs[0]]; - }; + var showAttrsAll = ['showexponent', 'showtickprefix', 'showticksuffix']; + var showAttrs = showAttrsAll.filter(function(a) { + return containerIn[a] !== undefined; + }); + var sameVal = function(a) { + return containerIn[a] === containerIn[showAttrs[0]]; + }; if(showAttrs.every(sameVal) || showAttrs.length === 1) { return containerIn[showAttrs[0]]; diff --git a/src/plots/cartesian/tick_mark_defaults.js b/src/plots/cartesian/tick_mark_defaults.js index 82210ded37b..d11dd780022 100644 --- a/src/plots/cartesian/tick_mark_defaults.js +++ b/src/plots/cartesian/tick_mark_defaults.js @@ -18,10 +18,10 @@ var layoutAttributes = require('./layout_attributes'); * options: inherits outerTicks from axes.handleAxisDefaults */ module.exports = function handleTickDefaults(containerIn, containerOut, coerce, options) { - var tickLen = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'ticklen'), - tickWidth = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'tickwidth'), - tickColor = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'tickcolor', containerOut.color), - showTicks = coerce('ticks', (options.outerTicks || tickLen || tickWidth || tickColor) ? 'outside' : ''); + var tickLen = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'ticklen'); + var tickWidth = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'tickwidth'); + var tickColor = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'tickcolor', containerOut.color); + var showTicks = coerce('ticks', (options.outerTicks || tickLen || tickWidth || tickColor) ? 'outside' : ''); if(!showTicks) { delete containerOut.ticklen; diff --git a/src/plots/cartesian/transition_axes.js b/src/plots/cartesian/transition_axes.js index 33234acf0f8..bb6f30774fc 100644 --- a/src/plots/cartesian/transition_axes.js +++ b/src/plots/cartesian/transition_axes.js @@ -218,17 +218,17 @@ module.exports = function transitionAxes(gd, newLayout, transitionOpts, makeOnCo var editX = !!xUpdate; var editY = !!yUpdate; - var xScaleFactor = editX ? xa2._length / viewBox[2] : 1, - yScaleFactor = editY ? ya2._length / viewBox[3] : 1; + var xScaleFactor = editX ? xa2._length / viewBox[2] : 1; + var yScaleFactor = editY ? ya2._length / viewBox[3] : 1; - var clipDx = editX ? viewBox[0] : 0, - clipDy = editY ? viewBox[1] : 0; + var clipDx = editX ? viewBox[0] : 0; + var clipDy = editY ? viewBox[1] : 0; - var fracDx = editX ? (viewBox[0] / viewBox[2] * xa2._length) : 0, - fracDy = editY ? (viewBox[1] / viewBox[3] * ya2._length) : 0; + var fracDx = editX ? (viewBox[0] / viewBox[2] * xa2._length) : 0; + var fracDy = editY ? (viewBox[1] / viewBox[3] * ya2._length) : 0; - var plotDx = xa2._offset - fracDx, - plotDy = ya2._offset - fracDy; + var plotDx = xa2._offset - fracDx; + var plotDy = ya2._offset - fracDy; subplot.clipRect .call(Drawing.setTranslate, clipDx, clipDy) diff --git a/src/plots/geo/zoom.js b/src/plots/geo/zoom.js index 247ed1553c4..15d0d79ba27 100644 --- a/src/plots/geo/zoom.js +++ b/src/plots/geo/zoom.js @@ -190,22 +190,22 @@ function zoomNonClipped(geo, projection) { // zoom for clipped projections // inspired by https://www.jasondavies.com/maps/d3.geo.zoom.js function zoomClipped(geo, projection) { - var view = {r: projection.rotate(), k: projection.scale()}, - zoom = initZoom(geo, projection), - event = d3_eventDispatch(zoom, 'zoomstart', 'zoom', 'zoomend'), - zooming = 0, - zoomOn = zoom.on; + var view = {r: projection.rotate(), k: projection.scale()}; + var zoom = initZoom(geo, projection); + var event = d3eventDispatch(zoom, 'zoomstart', 'zoom', 'zoomend'); + var zooming = 0; + var zoomOn = zoom.on; var zoomPoint; zoom.on('zoomstart', function() { d3.select(this).style(zoomstartStyle); - var mouse0 = d3.mouse(this), - rotate0 = projection.rotate(), - lastRotate = rotate0, - translate0 = projection.translate(), - q = quaternionFromEuler(rotate0); + var mouse0 = d3.mouse(this); + var rotate0 = projection.rotate(); + var lastRotate = rotate0; + var translate0 = projection.translate(); + var q = quaternionFromEuler(rotate0); zoomPoint = position(projection, mouse0); @@ -232,10 +232,10 @@ function zoomClipped(geo, projection) { .translate(translate0); // calculate the new params - var point1 = position(projection, mouse1), - between = rotateBetween(zoomPoint, point1), - newEuler = eulerFromQuaternion(multiply(q, between)), - rotateAngles = view.r = unRoll(newEuler, zoomPoint, lastRotate); + var point1 = position(projection, mouse1); + var between = rotateBetween(zoomPoint, point1); + var newEuler = eulerFromQuaternion(multiply(q, between)); + var rotateAngles = view.r = unRoll(newEuler, zoomPoint, lastRotate); if(!isFinite(rotateAngles[0]) || !isFinite(rotateAngles[1]) || !isFinite(rotateAngles[2])) { @@ -291,12 +291,15 @@ function position(projection, point) { } function quaternionFromEuler(euler) { - var lambda = 0.5 * euler[0] * radians, - phi = 0.5 * euler[1] * radians, - gamma = 0.5 * euler[2] * radians, - sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda), - sinPhi = Math.sin(phi), cosPhi = Math.cos(phi), - sinGamma = Math.sin(gamma), cosGamma = Math.cos(gamma); + var lambda = 0.5 * euler[0] * radians; + var phi = 0.5 * euler[1] * radians; + var gamma = 0.5 * euler[2] * radians; + var sinLambda = Math.sin(lambda); + var cosLambda = Math.cos(lambda); + var sinPhi = Math.sin(phi); + var cosPhi = Math.cos(phi); + var sinGamma = Math.sin(gamma); + var cosGamma = Math.cos(gamma); return [ cosLambda * cosPhi * cosGamma + sinLambda * sinPhi * sinGamma, sinLambda * cosPhi * cosGamma - cosLambda * sinPhi * sinGamma, @@ -306,8 +309,14 @@ function quaternionFromEuler(euler) { } function multiply(a, b) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], - b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + var a0 = a[0]; + var a1 = a[1]; + var a2 = a[2]; + var a3 = a[3]; + var b0 = b[0]; + var b1 = b[1]; + var b2 = b[2]; + var b3 = b[3]; return [ a0 * b0 - a1 * b1 - a2 * b2 - a3 * b3, a0 * b1 + a1 * b0 + a2 * b3 - a3 * b2, @@ -318,10 +327,10 @@ function multiply(a, b) { function rotateBetween(a, b) { if(!a || !b) return; - var axis = cross(a, b), - norm = Math.sqrt(dot(axis, axis)), - halfgamma = 0.5 * Math.acos(Math.max(-1, Math.min(1, dot(a, b)))), - k = Math.sin(halfgamma) / norm; + var axis = cross(a, b); + var norm = Math.sqrt(dot(axis, axis)); + var halfgamma = 0.5 * Math.acos(Math.max(-1, Math.min(1, dot(a, b)))); + var k = Math.sin(halfgamma) / norm; return norm && [Math.cos(halfgamma), axis[2] * k, -axis[1] * k, axis[0] * k]; } @@ -341,20 +350,20 @@ function unRoll(rotateAngles, pt, lastRotate) { ptRotated = rotateCartesian(ptRotated, 1, rotateAngles[1]); ptRotated = rotateCartesian(ptRotated, 0, rotateAngles[2] - lastRotate[2]); - var x = pt[0], - y = pt[1], - z = pt[2], - f = ptRotated[0], - g = ptRotated[1], - h = ptRotated[2], - - // the following essentially solves: - // ptRotated = rotateCartesian(rotateCartesian(pt, 2, newYaw), 1, newPitch) - // for newYaw and newPitch, as best it can - theta = Math.atan2(y, x) * degrees, - a = Math.sqrt(x * x + y * y), - b, - newYaw1; + var x = pt[0]; + var y = pt[1]; + var z = pt[2]; + var f = ptRotated[0]; + var g = ptRotated[1]; + var h = ptRotated[2]; + + // the following essentially solves: + // ptRotated = rotateCartesian(rotateCartesian(pt, 2, newYaw), 1, newPitch) + // for newYaw and newPitch, as best it can + var theta = Math.atan2(y, x) * degrees; + var a = Math.sqrt(x * x + y * y); + var b; + var newYaw1; if(Math.abs(g) > a) { newYaw1 = (g > 0 ? 90 : -90) - theta; @@ -364,21 +373,21 @@ function unRoll(rotateAngles, pt, lastRotate) { b = Math.sqrt(a * a - g * g); } - 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; + var newYaw2 = 180 - newYaw1 - 2 * theta; + var newPitch1 = (Math.atan2(h, f) - Math.atan2(z, b)) * degrees; + var newPitch2 = (Math.atan2(h, f) - Math.atan2(z, -b)) * degrees; // which is closest to lastRotate[0,1]: newYaw/Pitch or newYaw2/Pitch2? - var dist1 = angleDistance(lastRotate[0], lastRotate[1], newYaw1, newPitch1), - dist2 = angleDistance(lastRotate[0], lastRotate[1], newYaw2, newPitch2); + var dist1 = angleDistance(lastRotate[0], lastRotate[1], newYaw1, newPitch1); + var dist2 = angleDistance(lastRotate[0], lastRotate[1], newYaw2, newPitch2); if(dist1 <= dist2) return [newYaw1, newPitch1, lastRotate[2]]; else return [newYaw2, newPitch2, lastRotate[2]]; } function angleDistance(yaw0, pitch0, yaw1, pitch1) { - var dYaw = angleMod(yaw1 - yaw0), - dPitch = angleMod(pitch1 - pitch0); + var dYaw = angleMod(yaw1 - yaw0); + var dPitch = angleMod(pitch1 - pitch0); return Math.sqrt(dYaw * dYaw + dPitch * dPitch); } @@ -391,12 +400,12 @@ function angleMod(angle) { // axis is 0 (x), 1 (y), or 2 (z) // angle is in degrees function rotateCartesian(vector, axis, angle) { - var angleRads = angle * radians, - vectorOut = vector.slice(), - ax1 = (axis === 0) ? 1 : 0, - ax2 = (axis === 2) ? 1 : 2, - cosa = Math.cos(angleRads), - sina = Math.sin(angleRads); + var angleRads = angle * radians; + var vectorOut = vector.slice(); + var ax1 = (axis === 0) ? 1 : 0; + var ax2 = (axis === 2) ? 1 : 2; + var cosa = Math.cos(angleRads); + var sina = Math.sin(angleRads); vectorOut[ax1] = vector[ax1] * cosa - vector[ax2] * sina; vectorOut[ax2] = vector[ax2] * cosa + vector[ax1] * sina; @@ -412,9 +421,9 @@ function eulerFromQuaternion(q) { } function cartesian(spherical) { - var lambda = spherical[0] * radians, - phi = spherical[1] * radians, - cosPhi = Math.cos(phi); + var lambda = spherical[0] * radians; + var phi = spherical[1] * radians; + var cosPhi = Math.cos(phi); return [ cosPhi * Math.cos(lambda), cosPhi * Math.sin(lambda), @@ -440,10 +449,10 @@ function cross(a, b) { // events have a target component (such as a brush), a target element (such as // the svg:g element containing the brush) and the standard arguments `d` (the // target element's data) and `i` (the selection index of the target element). -function d3_eventDispatch(target) { - var i = 0, - n = arguments.length, - argumentz = []; +function d3eventDispatch(target) { + var i = 0; + var n = arguments.length; + var argumentz = []; while(++i < n) argumentz.push(arguments[i]); diff --git a/src/plots/gl2d/camera.js b/src/plots/gl2d/camera.js index cad0080961d..af2b704ac69 100644 --- a/src/plots/gl2d/camera.js +++ b/src/plots/gl2d/camera.js @@ -33,9 +33,9 @@ function Camera2D(element, plot) { function createCamera(scene) { - var element = scene.mouseContainer, - plot = scene.glplot, - result = new Camera2D(element, plot); + var element = scene.mouseContainer; + var plot = scene.glplot; + var result = new Camera2D(element, plot); function unSetAutoRange() { scene.xaxis.autorange = false; @@ -81,11 +81,11 @@ function createCamera(scene) { }, hasPassive ? {passive: false} : false); function handleInteraction(buttons, x, y) { - var dataBox = scene.calcDataBox(), - viewBox = plot.viewBox; + var dataBox = scene.calcDataBox(); + var viewBox = plot.viewBox; - var lastX = result.lastPos[0], - lastY = result.lastPos[1]; + var lastX = result.lastPos[0]; + var lastY = result.lastPos[1]; var MINDRAG = cartesianConstants.MINDRAG * plot.pixelRatio; var MINZOOM = cartesianConstants.MINZOOM * plot.pixelRatio; @@ -99,8 +99,8 @@ function createCamera(scene) { y = (viewBox[3] - viewBox[1]) - y; function updateRange(i0, start, end) { - var range0 = Math.min(start, end), - range1 = Math.max(start, end); + var range0 = Math.min(start, end); + var range1 = Math.max(start, end); if(range0 !== range1) { dataBox[i0] = range0; @@ -265,11 +265,11 @@ function createCamera(scene) { result.wheelListener = mouseWheel(element, function(dx, dy) { if(!scene.scrollZoom) return false; - var dataBox = scene.calcDataBox(), - viewBox = plot.viewBox; + var dataBox = scene.calcDataBox(); + var viewBox = plot.viewBox; - var lastX = result.lastPos[0], - lastY = result.lastPos[1]; + var lastX = result.lastPos[0]; + var lastY = result.lastPos[1]; var scale = Math.exp(5.0 * dy / (viewBox[3] - viewBox[1])); diff --git a/src/plots/gl2d/convert.js b/src/plots/gl2d/convert.js index e8ba2054732..5255e5a9c27 100644 --- a/src/plots/gl2d/convert.js +++ b/src/plots/gl2d/convert.js @@ -207,9 +207,9 @@ proto.hasAxisInAltrPos = function(axisName, ax) { }; proto.getLabelPad = function(axisName, ax) { - var offsetBase = 1.5, - fontSize = ax.title.font.size, - showticklabels = ax.showticklabels; + var offsetBase = 1.5; + var fontSize = ax.title.font.size; + var showticklabels = ax.showticklabels; if(axisName === 'xaxis') { return (ax.side === 'top') ? diff --git a/src/plots/gl2d/index.js b/src/plots/gl2d/index.js index f56572b8bac..be1623e118a 100644 --- a/src/plots/gl2d/index.js +++ b/src/plots/gl2d/index.js @@ -58,9 +58,9 @@ exports.plot = function plotGl2d(gd) { var subplotIds = fullLayout._subplots.gl2d; for(var i = 0; i < subplotIds.length; i++) { - var subplotId = subplotIds[i], - subplotObj = fullLayout._plots[subplotId], - fullSubplotData = getSubplotData(fullData, 'gl2d', subplotId); + var subplotId = subplotIds[i]; + var subplotObj = fullLayout._plots[subplotId]; + var fullSubplotData = getSubplotData(fullData, 'gl2d', subplotId); // ref. to corresp. Scene instance var scene = subplotObj._scene2d; @@ -89,8 +89,8 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) var oldSceneKeys = oldFullLayout._subplots.gl2d || []; for(var i = 0; i < oldSceneKeys.length; i++) { - var id = oldSceneKeys[i], - oldSubplot = oldFullLayout._plots[id]; + var id = oldSceneKeys[i]; + var oldSubplot = oldFullLayout._plots[id]; // old subplot wasn't gl2d; nothing to do if(!oldSubplot._scene2d) continue; @@ -118,8 +118,8 @@ exports.toSVG = function(gd) { var subplotIds = fullLayout._subplots.gl2d; for(var i = 0; i < subplotIds.length; i++) { - var subplot = fullLayout._plots[subplotIds[i]], - scene = subplot._scene2d; + var subplot = fullLayout._plots[subplotIds[i]]; + var scene = subplot._scene2d; var imageData = scene.toImage('png'); var image = fullLayout._glimages.append('svg:image'); diff --git a/src/plots/gl2d/scene2d.js b/src/plots/gl2d/scene2d.js index 7cb2080c629..baaad8e97fe 100644 --- a/src/plots/gl2d/scene2d.js +++ b/src/plots/gl2d/scene2d.js @@ -193,9 +193,9 @@ proto.toImage = function(format) { // grab context and yank out pixels - var gl = this.glplot.gl, - w = gl.drawingBufferWidth, - h = gl.drawingBufferHeight; + var gl = this.glplot.gl; + var w = gl.drawingBufferWidth; + var h = gl.drawingBufferHeight; // force redraw gl.clearColor(1, 1, 1, 0); @@ -249,13 +249,13 @@ proto.toImage = function(format) { proto.updateSize = function(canvas) { if(!canvas) canvas = this.canvas; - var pixelRatio = this.pixelRatio, - fullLayout = this.fullLayout; + var pixelRatio = this.pixelRatio; + var fullLayout = this.fullLayout; - var width = fullLayout.width, - height = fullLayout.height, - pixelWidth = Math.ceil(pixelRatio * width) |0, - pixelHeight = Math.ceil(pixelRatio * height) |0; + var width = fullLayout.width; + var height = fullLayout.height; + var pixelWidth = Math.ceil(pixelRatio * width) |0; + var pixelHeight = Math.ceil(pixelRatio * height) |0; // check for resize if(canvas.width !== pixelWidth || canvas.height !== pixelHeight) { @@ -287,8 +287,8 @@ proto.computeTickMarks = function() { function compareTicks(a, b) { for(var i = 0; i < 2; ++i) { - var aticks = a[i], - bticks = b[i]; + var aticks = a[i]; + var bticks = b[i]; if(aticks.length !== bticks.length) return true; @@ -357,8 +357,8 @@ proto.cameraChanged = function() { }; proto.handleAnnotations = function() { - var gd = this.graphDiv, - annotations = this.fullLayout.annotations; + var gd = this.graphDiv; + var annotations = this.fullLayout.annotations; for(var i = 0; i < annotations.length; i++) { var ann = annotations[i]; @@ -403,8 +403,8 @@ proto.plot = function(fullData, calcData, fullLayout) { this.updateTraces(fullData, calcData); this.updateFx(fullLayout.dragmode); - var width = fullLayout.width, - height = fullLayout.height; + var width = fullLayout.width; + var height = fullLayout.height; this.updateSize(this.canvas); @@ -421,9 +421,9 @@ proto.plot = function(fullData, calcData, fullLayout) { cleanAxisConstraints(mockGraphDiv, this.xaxis); cleanAxisConstraints(mockGraphDiv, this.yaxis); - var size = fullLayout._size, - domainX = this.xaxis.domain, - domainY = this.yaxis.domain; + var size = fullLayout._size; + var domainX = this.xaxis.domain; + var domainY = this.yaxis.domain; options.viewBox = [ size.l + domainX[0] * size.w, @@ -462,21 +462,21 @@ proto.plot = function(fullData, calcData, fullLayout) { }; proto.calcDataBox = function() { - var xaxis = this.xaxis, - yaxis = this.yaxis, - xrange = xaxis.range, - yrange = yaxis.range, - xr2l = xaxis.r2l, - yr2l = yaxis.r2l; + var xaxis = this.xaxis; + var yaxis = this.yaxis; + var xrange = xaxis.range; + var yrange = yaxis.range; + var xr2l = xaxis.r2l; + var yr2l = yaxis.r2l; return [xr2l(xrange[0]), yr2l(yrange[0]), xr2l(xrange[1]), yr2l(yrange[1])]; }; proto.setRanges = function(dataBox) { - var xaxis = this.xaxis, - yaxis = this.yaxis, - xl2r = xaxis.l2r, - yl2r = yaxis.l2r; + var xaxis = this.xaxis; + var yaxis = this.yaxis; + var xl2r = xaxis.l2r; + var yl2r = yaxis.l2r; xaxis.range = [xl2r(dataBox[0]), xl2r(dataBox[2])]; yaxis.range = [yl2r(dataBox[1]), yl2r(dataBox[3])]; @@ -489,16 +489,16 @@ proto.updateTraces = function(fullData, calcData) { this.fullData = fullData; // remove empty traces - trace_id_loop: + traceIdLoop: for(i = 0; i < traceIds.length; i++) { - var oldUid = traceIds[i], - oldTrace = this.traces[oldUid]; + var oldUid = traceIds[i]; + var oldTrace = this.traces[oldUid]; for(j = 0; j < fullData.length; j++) { fullTrace = fullData[j]; if(fullTrace.uid === oldUid && fullTrace.type === oldTrace.type) { - continue trace_id_loop; + continue traceIdLoop; } } @@ -509,8 +509,8 @@ proto.updateTraces = function(fullData, calcData) { // update / create trace objects for(i = 0; i < fullData.length; i++) { fullTrace = fullData[i]; - var calcTrace = calcData[i], - traceObj = this.traces[fullTrace.uid]; + var calcTrace = calcData[i]; + var traceObj = this.traces[fullTrace.uid]; if(traceObj) traceObj.update(fullTrace, calcTrace); else { @@ -579,11 +579,11 @@ proto.draw = function() { requestAnimationFrame(this.redraw); - var glplot = this.glplot, - camera = this.camera, - mouseListener = camera.mouseListener, - mouseUp = this.lastButtonState === 1 && mouseListener.buttons === 0, - fullLayout = this.fullLayout; + var glplot = this.glplot; + var camera = this.camera; + var mouseListener = camera.mouseListener; + var mouseUp = this.lastButtonState === 1 && mouseListener.buttons === 0; + var fullLayout = this.fullLayout; this.lastButtonState = mouseListener.buttons; @@ -617,9 +617,9 @@ proto.draw = function() { else if(!camera.panning && this.isMouseOver) { this.selectBox.enabled = false; - var size = fullLayout._size, - domainX = this.xaxis.domain, - domainY = this.yaxis.domain; + var size = fullLayout._size; + var domainX = this.xaxis.domain; + var domainY = this.yaxis.domain; result = glplot.pick( (x / glplot.pixelRatio) + size.l + domainX[0] * size.w, diff --git a/src/plots/gl3d/camera.js b/src/plots/gl3d/camera.js index 3fe1f4ea570..cd115bbc823 100644 --- a/src/plots/gl3d/camera.js +++ b/src/plots/gl3d/camera.js @@ -181,7 +181,9 @@ function createCamera(element, options) { return false; }); - var lastX = 0, lastY = 0, lastMods = {shift: false, control: false, alt: false, meta: false}; + var lastX = 0; + var lastY = 0; + var lastMods = {shift: false, control: false, alt: false, meta: false}; camera.mouseListener = mouseChange(element, handleInteraction); // enable simple touch interactions diff --git a/src/plots/gl3d/index.js b/src/plots/gl3d/index.js index 3c4dccbfa2e..e86b6101d9f 100644 --- a/src/plots/gl3d/index.js +++ b/src/plots/gl3d/index.js @@ -45,10 +45,10 @@ exports.plot = function plotGl3d(gd) { var sceneIds = fullLayout._subplots[GL3D]; for(var i = 0; i < sceneIds.length; i++) { - var sceneId = sceneIds[i], - fullSceneData = getSubplotData(fullData, GL3D, sceneId), - sceneLayout = fullLayout[sceneId], - scene = sceneLayout._scene; + var sceneId = sceneIds[i]; + var fullSceneData = getSubplotData(fullData, GL3D, sceneId); + var sceneLayout = fullLayout[sceneId]; + var scene = sceneLayout._scene; if(!scene) { scene = new Scene({ diff --git a/src/plots/gl3d/layout/defaults.js b/src/plots/gl3d/layout/defaults.js index c38a3de222d..1df8de38972 100644 --- a/src/plots/gl3d/layout/defaults.js +++ b/src/plots/gl3d/layout/defaults.js @@ -58,8 +58,8 @@ function handleGl3dDefaults(sceneLayoutIn, sceneLayoutOut, coerce, opts) { * attributes like aspectratio can be written back dynamically. */ - var bgcolor = coerce('bgcolor'), - bgColorCombined = Color.combine(bgcolor, opts.paper_bgcolor); + var bgcolor = coerce('bgcolor'); + var bgColorCombined = Color.combine(bgcolor, opts.paper_bgcolor); var cameraKeys = ['up', 'center', 'eye']; diff --git a/src/plots/gl3d/scene.js b/src/plots/gl3d/scene.js index cfc7eee11bc..dea29d1ee99 100644 --- a/src/plots/gl3d/scene.js +++ b/src/plots/gl3d/scene.js @@ -37,7 +37,8 @@ function render(scene) { // update size of svg container var svgContainer = scene.svgContainer; var clientRect = scene.container.getBoundingClientRect(); - var width = clientRect.width, height = clientRect.height; + var width = clientRect.width; + var height = clientRect.height; svgContainer.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height); svgContainer.setAttributeNS(null, 'width', width); svgContainer.setAttributeNS(null, 'height', height); @@ -474,11 +475,11 @@ proto.plot = function(sceneData, fullLayout, layout) { // Remove empty traces var traceIds = Object.keys(this.traces); - trace_id_loop: + traceIdLoop: for(i = 0; i < traceIds.length; ++i) { for(j = 0; j < sceneData.length; ++j) { if(sceneData[j].uid === traceIds[i] && sceneData[j].visible === true) { - continue trace_id_loop; + continue traceIdLoop; } } trace = this.traces[traceIds[i]]; @@ -492,9 +493,9 @@ proto.plot = function(sceneData, fullLayout, layout) { }); // Update ranges (needs to be called *after* objects are added due to updates) - var sceneBounds = [[0, 0, 0], [0, 0, 0]], - axisDataRange = [], - axisTypeRatios = {}; + var sceneBounds = [[0, 0, 0], [0, 0, 0]]; + var axisDataRange = []; + var axisTypeRatios = {}; for(i = 0; i < 3; ++i) { axis = fullSceneLayout[axisProperties[i]]; @@ -641,8 +642,8 @@ proto.plot = function(sceneData, fullLayout, layout) { // Update frame position for multi plots - var domain = fullSceneLayout.domain || null, - size = fullLayout._size || null; + var domain = fullSceneLayout.domain || null; + var size = fullLayout._size || null; if(domain && size) { var containerStyle = this.container.style; @@ -707,8 +708,8 @@ proto.saveCamera = function saveCamera(layout) { var hasChanged = false; function same(x, y, i, j) { - var vectors = ['up', 'center', 'eye'], - components = ['x', 'y', 'z']; + var vectors = ['up', 'center', 'eye']; + var components = ['x', 'y', 'z']; return y[vectors[i]] && (x[vectors[i]][components[j]] === y[vectors[i]][components[j]]); } diff --git a/src/plots/mapbox/convert_text_opts.js b/src/plots/mapbox/convert_text_opts.js index a54e501f961..48ce6615b64 100644 --- a/src/plots/mapbox/convert_text_opts.js +++ b/src/plots/mapbox/convert_text_opts.js @@ -23,17 +23,17 @@ var Lib = require('../../lib'); * - offset */ module.exports = function convertTextOpts(textposition, iconSize) { - var parts = textposition.split(' '), - vPos = parts[0], - hPos = parts[1]; + var parts = textposition.split(' '); + var vPos = parts[0]; + var hPos = parts[1]; // ballpack values - var factor = Lib.isArrayOrTypedArray(iconSize) ? Lib.mean(iconSize) : iconSize, - xInc = 0.5 + (factor / 100), - yInc = 1.5 + (factor / 100); + var factor = Lib.isArrayOrTypedArray(iconSize) ? Lib.mean(iconSize) : iconSize; + var xInc = 0.5 + (factor / 100); + var yInc = 1.5 + (factor / 100); - var anchorVals = ['', ''], - offset = [0, 0]; + var anchorVals = ['', '']; + var offset = [0, 0]; switch(vPos) { case 'top': diff --git a/src/plots/mapbox/index.js b/src/plots/mapbox/index.js index cda8cd931cd..7838c3d1841 100644 --- a/src/plots/mapbox/index.js +++ b/src/plots/mapbox/index.js @@ -63,10 +63,10 @@ exports.plot = function plotMapbox(gd) { mapboxgl.accessToken = accessToken; for(var i = 0; i < mapboxIds.length; i++) { - var id = mapboxIds[i], - subplotCalcData = getSubplotCalcData(calcData, MAPBOX, id), - opts = fullLayout[id], - mapbox = opts._subplot; + var id = mapboxIds[i]; + var subplotCalcData = getSubplotCalcData(calcData, MAPBOX, id); + var opts = fullLayout[id]; + var mapbox = opts._subplot; if(!mapbox) { mapbox = createMapbox({ @@ -111,9 +111,9 @@ exports.toSVG = function(gd) { var size = fullLayout._size; for(var i = 0; i < subplotIds.length; i++) { - var opts = fullLayout[subplotIds[i]], - domain = opts.domain, - mapbox = opts._subplot; + var opts = fullLayout[subplotIds[i]]; + var domain = opts.domain; + var mapbox = opts._subplot; var imageData = mapbox.toImage('png'); var image = fullLayout._glimages.append('svg:image'); @@ -133,8 +133,8 @@ exports.toSVG = function(gd) { }; function findAccessToken(gd, mapboxIds) { - var fullLayout = gd._fullLayout, - context = gd._context; + var fullLayout = gd._fullLayout; + var context = gd._context; // special case for Mapbox Atlas users if(context.mapboxAccessToken === '') return ''; diff --git a/src/plots/mapbox/layers.js b/src/plots/mapbox/layers.js index 3c14483c1d1..016b3438c2e 100644 --- a/src/plots/mapbox/layers.js +++ b/src/plots/mapbox/layers.js @@ -134,8 +134,8 @@ function isVisible(opts) { } function convertOpts(opts) { - var layout = {}, - paint = {}; + var layout = {}; + var paint = {}; switch(opts.type) { @@ -166,8 +166,8 @@ function convertOpts(opts) { break; case 'symbol': - var symbol = opts.symbol, - textOpts = convertTextOpts(symbol.textposition, symbol.iconsize); + var symbol = opts.symbol; + var textOpts = convertTextOpts(symbol.textposition, symbol.iconsize); Lib.extendFlat(layout, { 'icon-image': symbol.icon + '-15', diff --git a/src/plots/mapbox/mapbox.js b/src/plots/mapbox/mapbox.js index f1ddfdb01dc..683085e7478 100644 --- a/src/plots/mapbox/mapbox.js +++ b/src/plots/mapbox/mapbox.js @@ -292,13 +292,13 @@ proto.updateData = function(calcData) { // remove empty trace objects var ids = Object.keys(traceHash); - id_loop: + idLoop: for(i = 0; i < ids.length; i++) { var id = ids[i]; for(j = 0; j < calcData.length; j++) { trace = calcData[j][0].trace; - if(id === trace.uid) continue id_loop; + if(id === trace.uid) continue idLoop; } traceObj = traceHash[id]; diff --git a/src/plots/plots.js b/src/plots/plots.js index ebf4d96628e..1cfea9b0e9f 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -171,9 +171,9 @@ plots.addLinks = function(gd) { linkContainer.attr(attrs); - var toolspan = linkContainer.select('.js-link-to-tool'), - spacespan = linkContainer.select('.js-link-spacer'), - sourcespan = linkContainer.select('.js-sourcelinks'); + var toolspan = linkContainer.select('.js-link-to-tool'); + var spacespan = linkContainer.select('.js-link-spacer'); + var sourcespan = linkContainer.select('.js-sourcelinks'); if(gd._context.showSources) gd._context.showSources(gd); @@ -341,8 +341,8 @@ plots.supplyDefaults = function(gd, opts) { if(oldFullLayout._initialAutoSizeIsDone) { // coerce the updated layout while preserving width and height - var oldWidth = oldFullLayout.width, - oldHeight = oldFullLayout.height; + var oldWidth = oldFullLayout.width; + var oldHeight = oldFullLayout.height; plots.supplyLayoutGlobalDefaults(newLayout, newFullLayout, formatObj); @@ -355,10 +355,10 @@ plots.supplyDefaults = function(gd, opts) { // coerce the updated layout and autosize if needed plots.supplyLayoutGlobalDefaults(newLayout, newFullLayout, formatObj); - var missingWidthOrHeight = (!newLayout.width || !newLayout.height), - autosize = newFullLayout.autosize, - autosizable = context.autosizable, - initialAutoSize = missingWidthOrHeight && (autosize || autosizable); + var missingWidthOrHeight = (!newLayout.width || !newLayout.height); + var autosize = newFullLayout.autosize; + var autosizable = context.autosizable; + var initialAutoSize = missingWidthOrHeight && (autosize || autosizable); if(initialAutoSize) plots.plotAutoSize(gd, newLayout, newFullLayout); else if(missingWidthOrHeight) plots.sanitizeMargins(newFullLayout); @@ -763,8 +763,8 @@ plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayou oldLoop: for(i = 0; i < oldFullData.length; i++) { - var oldTrace = oldFullData[i], - oldUid = oldTrace.uid; + var oldTrace = oldFullData[i]; + var oldUid = oldTrace.uid; for(j = 0; j < newFullData.length; j++) { var newTrace = newFullData[j]; @@ -1317,15 +1317,15 @@ plots.supplyTransformDefaults = function(traceIn, traceOut, layout) { if(!Array.isArray(traceIn.transforms) && globalTransforms.length === 0) return; - var containerIn = traceIn.transforms || [], - transformList = globalTransforms.concat(containerIn), - containerOut = traceOut.transforms = []; + var containerIn = traceIn.transforms || []; + var transformList = globalTransforms.concat(containerIn); + var containerOut = traceOut.transforms = []; for(var i = 0; i < transformList.length; i++) { - var transformIn = transformList[i], - type = transformIn.type, - _module = transformsRegistry[type], - transformOut; + var transformIn = transformList[i]; + var type = transformIn.type; + var _module = transformsRegistry[type]; + var transformOut; /* * Supply defaults may run twice. First pass runs all supply defaults steps @@ -1336,8 +1336,8 @@ plots.supplyTransformDefaults = function(traceIn, traceOut, layout) { * function it could not have generated any new traces and the second stage * is unnecessary. We detect this case with the following variables. */ - var isFirstStage = !(transformIn._module && transformIn._module === _module), - doLaterStages = _module && typeof _module.transform === 'function'; + var isFirstStage = !(transformIn._module && transformIn._module === _module); + var doLaterStages = _module && typeof _module.transform === 'function'; if(!_module) Lib.warn('Unrecognized transform type ' + type + '.'); @@ -1357,12 +1357,12 @@ plots.supplyTransformDefaults = function(traceIn, traceOut, layout) { }; function applyTransforms(fullTrace, fullData, layout, fullLayout) { - var container = fullTrace.transforms, - dataOut = [fullTrace]; + var container = fullTrace.transforms; + var dataOut = [fullTrace]; for(var i = 0; i < container.length; i++) { - var transform = container[i], - _module = transformsRegistry[transform.type]; + var transform = container[i]; + var _module = transformsRegistry[transform.type]; if(_module && _module.transform) { dataOut = _module.transform(dataOut, { @@ -1467,10 +1467,10 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) { }; plots.plotAutoSize = function plotAutoSize(gd, layout, fullLayout) { - var context = gd._context || {}, - frameMargins = context.frameMargins, - newWidth, - newHeight; + var context = gd._context || {}; + var frameMargins = context.frameMargins; + var newWidth; + var newHeight; var isPlotDiv = Lib.isPlotDiv(gd); @@ -1503,15 +1503,15 @@ plots.plotAutoSize = function plotAutoSize(gd, layout, fullLayout) { } } - var minWidth = plots.layoutAttributes.width.min, - minHeight = plots.layoutAttributes.height.min; + var minWidth = plots.layoutAttributes.width.min; + var minHeight = plots.layoutAttributes.height.min; if(newWidth < minWidth) newWidth = minWidth; if(newHeight < minHeight) newHeight = minHeight; var widthHasChanged = !layout.width && - (Math.abs(fullLayout.width - newWidth) > 1), - heightHasChanged = !layout.height && - (Math.abs(fullLayout.height - newHeight) > 1); + (Math.abs(fullLayout.width - newWidth) > 1); + var heightHasChanged = !layout.height && + (Math.abs(fullLayout.height - newHeight) > 1); if(heightHasChanged || widthHasChanged) { if(widthHasChanged) fullLayout.width = newWidth; @@ -1703,12 +1703,12 @@ plots.sanitizeMargins = function(fullLayout) { // polar doesn't do margins... if(!fullLayout || !fullLayout.margin) return; - var width = fullLayout.width, - height = fullLayout.height, - margin = fullLayout.margin, - plotWidth = width - (margin.l + margin.r), - plotHeight = height - (margin.t + margin.b), - correction; + var width = fullLayout.width; + var height = fullLayout.height; + var margin = fullLayout.margin; + var plotWidth = width - (margin.l + margin.r); + var plotHeight = height - (margin.t + margin.b); + var correction; // if margin.l + margin.r = 0 then plotWidth > 0 // as width >= 10 by supplyDefaults @@ -1849,23 +1849,23 @@ plots.doAutoMargin = function(gd) { for(var k1 in pushMargin) { - var pushleft = pushMargin[k1].l || {}, - pushbottom = pushMargin[k1].b || {}, - fl = pushleft.val, - pl = pushleft.size, - fb = pushbottom.val, - pb = pushbottom.size; + var pushleft = pushMargin[k1].l || {}; + var pushbottom = pushMargin[k1].b || {}; + var fl = pushleft.val; + var pl = pushleft.size; + var fb = pushbottom.val; + var pb = pushbottom.size; for(var k2 in pushMargin) { if(isNumeric(pl) && pushMargin[k2].r) { - var fr = pushMargin[k2].r.val, - pr = pushMargin[k2].r.size; + var fr = pushMargin[k2].r.val; + var pr = pushMargin[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); + (pr - fullLayout.width) * fl) / (fr - fl); + var newr = (pr * (1 - fl) + + (pl - fullLayout.width) * (1 - fr)) / (fr - fl); if(newl >= 0 && newr >= 0 && newl + newr > ml + mr) { ml = newl; mr = newr; @@ -1874,14 +1874,14 @@ plots.doAutoMargin = function(gd) { } if(isNumeric(pb) && pushMargin[k2].t) { - var ft = pushMargin[k2].t.val, - pt = pushMargin[k2].t.size; + var ft = pushMargin[k2].t.val; + var pt = pushMargin[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); + (pt - fullLayout.height) * fb) / (ft - fb); + var newt = (pt * (1 - fb) + + (pb - fullLayout.height) * (1 - ft)) / (ft - fb); if(newb >= 0 && newt >= 0 && newb + newt > mb + mt) { mb = newb; mt = newt; @@ -1943,16 +1943,17 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) { plots.supplyDefaults(gd); } - var data = (useDefaults) ? gd._fullData : gd.data, - layout = (useDefaults) ? gd._fullLayout : gd.layout, - frames = (gd._transitionData || {})._frames; + var data = (useDefaults) ? gd._fullData : gd.data; + var layout = (useDefaults) ? gd._fullLayout : gd.layout; + var frames = (gd._transitionData || {})._frames; function stripObj(d) { if(typeof d === 'function') { return null; } if(Lib.isPlainObject(d)) { - var o = {}, v, src; + var o = {}; + var v, src; for(v in d) { // remove private elements and functions // _ is for private, [ is a mistake ie [object Object] @@ -2745,8 +2746,8 @@ plots.generalUpdatePerTraceModule = function(gd, subplot, subplotCalcData, subpl // build up moduleName -> calcData hash for(i = 0; i < subplotCalcData.length; i++) { - var calcTraces = subplotCalcData[i], - trace = calcTraces[0].trace; + var calcTraces = subplotCalcData[i]; + var trace = calcTraces[0].trace; // skip over visible === false traces // as they don't have `_module` ref @@ -2761,8 +2762,8 @@ plots.generalUpdatePerTraceModule = function(gd, subplot, subplotCalcData, subpl // removed from the DOM. for(var moduleNameOld in traceHashOld) { if(!traceHash[moduleNameOld]) { - var fakeCalcTrace = traceHashOld[moduleNameOld][0], - fakeTrace = fakeCalcTrace[0].trace; + var fakeCalcTrace = traceHashOld[moduleNameOld][0]; + var fakeTrace = fakeCalcTrace[0].trace; fakeTrace.visible = false; traceHash[moduleNameOld] = [fakeCalcTrace]; diff --git a/src/plots/polar/legacy/micropolar_manager.js b/src/plots/polar/legacy/micropolar_manager.js index a3fa83e0d78..62c61128791 100644 --- a/src/plots/polar/legacy/micropolar_manager.js +++ b/src/plots/polar/legacy/micropolar_manager.js @@ -68,17 +68,17 @@ manager.framework = function(_gd) { }; manager.fillLayout = function(_gd) { - var container = d3.select(_gd).selectAll('.plot-container'), - paperDiv = container.selectAll('.svg-container'), - paper = _gd.framework && _gd.framework.svg && _gd.framework.svg(), - dflts = { - width: 800, - height: 600, - paper_bgcolor: Color.background, - _container: container, - _paperdiv: paperDiv, - _paper: paper - }; + var container = d3.select(_gd).selectAll('.plot-container'); + var paperDiv = container.selectAll('.svg-container'); + var paper = _gd.framework && _gd.framework.svg && _gd.framework.svg(); + var dflts = { + width: 800, + height: 600, + paper_bgcolor: Color.background, + _container: container, + _paperdiv: paperDiv, + _paper: paper + }; _gd._fullLayout = extendDeepAll(dflts, _gd.layout); }; diff --git a/src/plots/polar/legacy/undo_manager.js b/src/plots/polar/legacy/undo_manager.js index f6fb77ff620..58224c0d8e8 100644 --- a/src/plots/polar/legacy/undo_manager.js +++ b/src/plots/polar/legacy/undo_manager.js @@ -11,10 +11,10 @@ // Modified from https://github.com/ArthurClemens/Javascript-Undo-Manager // Copyright (c) 2010-2013 Arthur Clemens, arthur@visiblearea.com module.exports = function UndoManager() { - var undoCommands = [], - index = -1, - isExecuting = false, - callback; + var undoCommands = []; + var index = -1; + var isExecuting = false; + var callback; function execute(command, action) { if(!command) return this; diff --git a/src/plots/ternary/index.js b/src/plots/ternary/index.js index fd119f5f336..14771a2b2f1 100644 --- a/src/plots/ternary/index.js +++ b/src/plots/ternary/index.js @@ -47,9 +47,9 @@ exports.plot = function plotTernary(gd) { var ternaryIds = fullLayout._subplots[TERNARY]; for(var i = 0; i < ternaryIds.length; i++) { - var ternaryId = ternaryIds[i], - ternaryCalcData = getSubplotCalcData(calcData, TERNARY, ternaryId), - ternary = fullLayout[ternaryId]._subplot; + var ternaryId = ternaryIds[i]; + var ternaryCalcData = getSubplotCalcData(calcData, TERNARY, ternaryId); + var ternary = fullLayout[ternaryId]._subplot; // If ternary is not instantiated, create one! if(!ternary) { diff --git a/src/plots/ternary/layout_defaults.js b/src/plots/ternary/layout_defaults.js index d530175a2d9..8db5d4db789 100644 --- a/src/plots/ternary/layout_defaults.js +++ b/src/plots/ternary/layout_defaults.js @@ -52,9 +52,9 @@ function handleTernaryDefaults(ternaryLayoutIn, ternaryLayoutOut, coerce, option // if the min values contradict each other, set them all to default (0) // and delete *all* the inputs so the user doesn't get confused later by // changing one and having them all change. - var aaxis = ternaryLayoutOut.aaxis, - baxis = ternaryLayoutOut.baxis, - caxis = ternaryLayoutOut.caxis; + var aaxis = ternaryLayoutOut.aaxis; + var baxis = ternaryLayoutOut.baxis; + var caxis = ternaryLayoutOut.caxis; if(aaxis.min + baxis.min + caxis.min >= sum) { aaxis.min = 0; baxis.min = 0; @@ -81,9 +81,9 @@ function handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut // inherit from global font color in case that was provided. var dfltFontColor = (dfltColor !== axAttrs.color.dflt) ? dfltColor : options.font.color; - var axName = containerOut._name, - letterUpper = axName.charAt(0).toUpperCase(), - dfltTitle = 'Component ' + letterUpper; + var axName = containerOut._name; + var letterUpper = axName.charAt(0).toUpperCase(); + var dfltTitle = 'Component ' + letterUpper; var title = coerce('title.text', dfltTitle); containerOut._hovertitle = title === dfltTitle ? title : letterUpper; diff --git a/src/plots/ternary/ternary.js b/src/plots/ternary/ternary.js index 6d681b5f107..9810f16dcb1 100644 --- a/src/plots/ternary/ternary.js +++ b/src/plots/ternary/ternary.js @@ -166,31 +166,31 @@ proto.updateLayers = function(ternaryLayout) { toplevel.order(); }; -var w_over_h = Math.sqrt(4 / 3); +var whRatio = Math.sqrt(4 / 3); proto.adjustLayout = function(ternaryLayout, graphSize) { - var _this = this, - domain = ternaryLayout.domain, - xDomainCenter = (domain.x[0] + domain.x[1]) / 2, - yDomainCenter = (domain.y[0] + domain.y[1]) / 2, - xDomain = domain.x[1] - domain.x[0], - yDomain = domain.y[1] - domain.y[0], - wmax = xDomain * graphSize.w, - hmax = yDomain * graphSize.h, - sum = ternaryLayout.sum, - amin = ternaryLayout.aaxis.min, - bmin = ternaryLayout.baxis.min, - cmin = ternaryLayout.caxis.min; + var _this = this; + var domain = ternaryLayout.domain; + var xDomainCenter = (domain.x[0] + domain.x[1]) / 2; + var yDomainCenter = (domain.y[0] + domain.y[1]) / 2; + var xDomain = domain.x[1] - domain.x[0]; + var yDomain = domain.y[1] - domain.y[0]; + var wmax = xDomain * graphSize.w; + var hmax = yDomain * graphSize.h; + var sum = ternaryLayout.sum; + var amin = ternaryLayout.aaxis.min; + var bmin = ternaryLayout.baxis.min; + var cmin = ternaryLayout.caxis.min; var x0, y0, w, h, xDomainFinal, yDomainFinal; - if(wmax > w_over_h * hmax) { + if(wmax > whRatio * hmax) { h = hmax; - w = h * w_over_h; + w = h * whRatio; } else { w = wmax; - h = w / w_over_h; + h = w / whRatio; } xDomainFinal = xDomain * w / wmax; @@ -253,7 +253,7 @@ proto.adjustLayout = function(ternaryLayout, graphSize) { // tickangle = 'auto' means 0 anyway for a y axis, need to coerce to 0 here // so we can shift by 30. tickangle: (+ternaryLayout.aaxis.tickangle || 0) - 30, - domain: [yDomain0, yDomain0 + yDomainFinal * w_over_h], + domain: [yDomain0, yDomain0 + yDomainFinal * whRatio], anchor: 'free', position: 0, _id: 'y', @@ -282,7 +282,7 @@ proto.adjustLayout = function(ternaryLayout, graphSize) { range: [sum - amin - bmin, cmin], side: 'right', tickangle: (+ternaryLayout.caxis.tickangle || 0) + 30, - domain: [yDomain0, yDomain0 + yDomainFinal * w_over_h], + domain: [yDomain0, yDomain0 + yDomainFinal * whRatio], anchor: 'free', position: 0, _id: 'y', @@ -494,10 +494,10 @@ var STARTMARKER = 'm0.5,0.5h5v-2h-5v-5h-2v5h-5v2h5v5h2Z'; var SHOWZOOMOUTTIP = true; proto.initInteractions = function() { - var _this = this, - dragger = _this.layers.plotbg.select('path').node(), - gd = _this.graphDiv, - zoomContainer = gd._fullLayout._zoomlayer; + var _this = this; + var dragger = _this.layers.plotbg.select('path').node(); + var gd = _this.graphDiv; + var zoomContainer = gd._fullLayout._zoomlayer; // use plotbg for the main interactions var dragOptions = { @@ -610,17 +610,17 @@ proto.initInteractions = function() { function getCFrac(x, y) { return ((x - (_this.h - y) / Math.sqrt(3)) / _this.w); } function zoomMove(dx0, dy0) { - var x1 = x0 + dx0, - y1 = y0 + dy0, - afrac = Math.max(0, Math.min(1, getAFrac(x0, y0), getAFrac(x1, y1))), - bfrac = Math.max(0, Math.min(1, getBFrac(x0, y0), getBFrac(x1, y1))), - cfrac = Math.max(0, Math.min(1, getCFrac(x0, y0), getCFrac(x1, y1))), - xLeft = ((afrac / 2) + cfrac) * _this.w, - xRight = (1 - (afrac / 2) - bfrac) * _this.w, - xCenter = (xLeft + xRight) / 2, - xSpan = xRight - xLeft, - yBottom = (1 - afrac) * _this.h, - yTop = yBottom - xSpan / w_over_h; + var x1 = x0 + dx0; + var y1 = y0 + dy0; + var afrac = Math.max(0, Math.min(1, getAFrac(x0, y0), getAFrac(x1, y1))); + var bfrac = Math.max(0, Math.min(1, getBFrac(x0, y0), getBFrac(x1, y1))); + var cfrac = Math.max(0, Math.min(1, getCFrac(x0, y0), getCFrac(x1, y1))); + var xLeft = ((afrac / 2) + cfrac) * _this.w; + var xRight = (1 - (afrac / 2) - bfrac) * _this.w; + var xCenter = (xLeft + xRight) / 2; + var xSpan = xRight - xLeft; + var yBottom = (1 - afrac) * _this.h; + var yTop = yBottom - xSpan / whRatio; if(xSpan < constants.MINZOOM) { mins = mins0; @@ -677,19 +677,19 @@ proto.initInteractions = function() { } function plotDrag(dx, dy) { - var dxScaled = dx / _this.xaxis._m, - dyScaled = dy / _this.yaxis._m; + var dxScaled = dx / _this.xaxis._m; + var dyScaled = dy / _this.yaxis._m; mins = { a: mins0.a - dyScaled, b: mins0.b + (dxScaled + dyScaled) / 2, c: mins0.c - (dxScaled - dyScaled) / 2 }; - var minsorted = [mins.a, mins.b, mins.c].sort(), - minindices = { - a: minsorted.indexOf(mins.a), - b: minsorted.indexOf(mins.b), - c: minsorted.indexOf(mins.c) - }; + var minsorted = [mins.a, mins.b, mins.c].sort(); + var minindices = { + a: minsorted.indexOf(mins.a), + b: minsorted.indexOf(mins.b), + c: minsorted.indexOf(mins.c) + }; if(minsorted[0] < 0) { if(minsorted[1] + minsorted[0] / 2 < 0) { minsorted[2] += minsorted[0] + minsorted[1]; diff --git a/src/traces/bar/cross_trace_calc.js b/src/traces/bar/cross_trace_calc.js index ff300d24ca5..6ead1789d48 100644 --- a/src/traces/bar/cross_trace_calc.js +++ b/src/traces/bar/cross_trace_calc.js @@ -25,15 +25,15 @@ var Sieve = require('./sieve.js'); */ function crossTraceCalc(gd, plotinfo) { - var xa = plotinfo.xaxis, - ya = plotinfo.yaxis; - - var fullTraces = gd._fullData, - calcTraces = gd.calcdata, - calcTracesHorizontal = [], - calcTracesVertical = [], - i; - for(i = 0; i < fullTraces.length; i++) { + var xa = plotinfo.xaxis; + var ya = plotinfo.yaxis; + + var fullTraces = gd._fullData; + var calcTraces = gd.calcdata; + var calcTracesHorizontal = []; + var calcTracesVertical = []; + + for(var i = 0; i < fullTraces.length; i++) { var fullTrace = fullTraces[i]; if( fullTrace.visible === true && @@ -57,12 +57,12 @@ function crossTraceCalc(gd, plotinfo) { function setGroupPositions(gd, pa, sa, calcTraces) { if(!calcTraces.length) return; - var barmode = gd._fullLayout.barmode, - overlay = (barmode === 'overlay'), - group = (barmode === 'group'), - excluded, - included, - i, calcTrace, fullTrace; + var barmode = gd._fullLayout.barmode; + var overlay = (barmode === 'overlay'); + var group = (barmode === 'group'); + var excluded; + var included; + var i, calcTrace, fullTrace; initBase(gd, pa, sa, calcTraces); @@ -157,9 +157,9 @@ function initBase(gd, pa, sa, calcTraces) { function setGroupPositionsInOverlayMode(gd, pa, sa, calcTraces) { - var barnorm = gd._fullLayout.barnorm, - separateNegativeValues = false, - dontMergeOverlappingData = !barnorm; + var barnorm = gd._fullLayout.barnorm; + var separateNegativeValues = false; + var dontMergeOverlappingData = !barnorm; // update position axis and set bar offsets and widths for(var i = 0; i < calcTraces.length; i++) { @@ -189,13 +189,11 @@ function setGroupPositionsInOverlayMode(gd, pa, sa, calcTraces) { function setGroupPositionsInGroupMode(gd, pa, sa, calcTraces) { - var fullLayout = gd._fullLayout, - barnorm = fullLayout.barnorm, - separateNegativeValues = false, - dontMergeOverlappingData = !barnorm, - sieve = new Sieve( - calcTraces, separateNegativeValues, dontMergeOverlappingData - ); + var fullLayout = gd._fullLayout; + var barnorm = fullLayout.barnorm; + var separateNegativeValues = false; + var dontMergeOverlappingData = !barnorm; + var sieve = new Sieve(calcTraces, separateNegativeValues, dontMergeOverlappingData); // set bar offsets and widths, and update position axis setOffsetAndWidthInGroupMode(gd, pa, sieve); @@ -212,16 +210,14 @@ function setGroupPositionsInGroupMode(gd, pa, sa, calcTraces) { function setGroupPositionsInStackOrRelativeMode(gd, pa, sa, calcTraces) { - var fullLayout = gd._fullLayout, - barmode = fullLayout.barmode, - stack = (barmode === 'stack'), - relative = (barmode === 'relative'), - barnorm = gd._fullLayout.barnorm, - separateNegativeValues = relative, - dontMergeOverlappingData = !(barnorm || stack || relative), - sieve = new Sieve( - calcTraces, separateNegativeValues, dontMergeOverlappingData - ); + var fullLayout = gd._fullLayout; + var barmode = fullLayout.barmode; + var stack = (barmode === 'stack'); + var relative = (barmode === 'relative'); + var barnorm = gd._fullLayout.barnorm; + var separateNegativeValues = relative; + var dontMergeOverlappingData = !(barnorm || stack || relative); + var sieve = new Sieve(calcTraces, separateNegativeValues, dontMergeOverlappingData); // set bar offsets and widths, and update position axis setOffsetAndWidth(gd, pa, sieve); @@ -250,18 +246,18 @@ function setGroupPositionsInStackOrRelativeMode(gd, pa, sa, calcTraces) { function setOffsetAndWidth(gd, pa, sieve) { - var fullLayout = gd._fullLayout, - bargap = fullLayout.bargap, - bargroupgap = fullLayout.bargroupgap || 0, - minDiff = sieve.minDiff, - calcTraces = sieve.traces, - i, calcTrace, calcTrace0, - t; + var fullLayout = gd._fullLayout; + var bargap = fullLayout.bargap; + var bargroupgap = fullLayout.bargroupgap || 0; + var minDiff = sieve.minDiff; + var calcTraces = sieve.traces; + var i, calcTrace, calcTrace0; + var t; // set bar offsets and widths - var barGroupWidth = minDiff * (1 - bargap), - barWidthPlusGap = barGroupWidth, - barWidth = barWidthPlusGap * (1 - bargroupgap); + var barGroupWidth = minDiff * (1 - bargap); + var barWidthPlusGap = barGroupWidth; + var barWidth = barWidthPlusGap * (1 - bargroupgap); // computer bar group center and bar offset var offsetFromCenter = -barWidth / 2; @@ -293,24 +289,24 @@ function setOffsetAndWidth(gd, pa, sieve) { function setOffsetAndWidthInGroupMode(gd, pa, sieve) { - var fullLayout = gd._fullLayout, - bargap = fullLayout.bargap, - bargroupgap = fullLayout.bargroupgap || 0, - positions = sieve.positions, - distinctPositions = sieve.distinctPositions, - minDiff = sieve.minDiff, - calcTraces = sieve.traces, - i, calcTrace, calcTrace0, - t; + var fullLayout = gd._fullLayout; + var bargap = fullLayout.bargap; + var bargroupgap = fullLayout.bargroupgap || 0; + var positions = sieve.positions; + var distinctPositions = sieve.distinctPositions; + var minDiff = sieve.minDiff; + var calcTraces = sieve.traces; + var i, calcTrace, calcTrace0; + var t; // if there aren't any overlapping positions, // let them have full width even if mode is group var overlap = (positions.length !== distinctPositions.length); - var nTraces = calcTraces.length, - barGroupWidth = minDiff * (1 - bargap), - barWidthPlusGap = (overlap) ? barGroupWidth / nTraces : barGroupWidth, - barWidth = barWidthPlusGap * (1 - bargroupgap); + var nTraces = calcTraces.length; + var barGroupWidth = minDiff * (1 - bargap); + var barWidthPlusGap = (overlap) ? barGroupWidth / nTraces : barGroupWidth; + var barWidth = barWidthPlusGap * (1 - bargroupgap); for(i = 0; i < nTraces; i++) { calcTrace = calcTraces[i]; @@ -318,8 +314,8 @@ function setOffsetAndWidthInGroupMode(gd, pa, sieve) { // computer bar group center and bar offset var offsetFromCenter = (overlap) ? - ((2 * i + 1 - nTraces) * barWidthPlusGap - barWidth) / 2 : - -barWidth / 2; + ((2 * i + 1 - nTraces) * barWidthPlusGap - barWidth) / 2 : + -barWidth / 2; // store bar width and offset for this trace t = calcTrace0.t; @@ -344,10 +340,9 @@ function setOffsetAndWidthInGroupMode(gd, pa, sieve) { function applyAttributes(sieve) { - var calcTraces = sieve.traces, - i, calcTrace, calcTrace0, fullTrace, - j, - t; + var calcTraces = sieve.traces; + var i, j, calcTrace, calcTrace0, fullTrace; + var t; for(i = 0; i < calcTraces.length; i++) { calcTrace = calcTraces[i]; @@ -355,9 +350,9 @@ function applyAttributes(sieve) { fullTrace = calcTrace0.trace; t = calcTrace0.t; - var offset = fullTrace._offset || fullTrace.offset, - initialPoffset = t.poffset, - newPoffset; + var offset = fullTrace._offset || fullTrace.offset; + var initialPoffset = t.poffset; + var newPoffset; if(isArrayOrTypedArray(offset)) { // if offset is an array, then clone it into t.poffset. @@ -428,16 +423,16 @@ function applyAttributes(sieve) { function setBarCenterAndWidth(gd, pa, sieve) { - var calcTraces = sieve.traces, - pLetter = getAxisLetter(pa); + var calcTraces = sieve.traces; + var pLetter = getAxisLetter(pa); for(var i = 0; i < calcTraces.length; i++) { - var calcTrace = calcTraces[i], - t = calcTrace[0].t, - poffset = t.poffset, - poffsetIsArray = Array.isArray(poffset), - barwidth = t.barwidth, - barwidthIsArray = Array.isArray(barwidth); + var calcTrace = calcTraces[i]; + var t = calcTrace[0].t; + var poffset = t.poffset; + var poffsetIsArray = Array.isArray(poffset); + var barwidth = t.barwidth; + var barwidthIsArray = Array.isArray(barwidth); for(var j = 0; j < calcTrace.length; j++) { var calcBar = calcTrace[j]; @@ -455,11 +450,11 @@ function setBarCenterAndWidth(gd, pa, sieve) { function updatePositionAxis(gd, pa, sieve, allowMinDtick) { - var calcTraces = sieve.traces, - distinctPositions = sieve.distinctPositions, - distinctPositions0 = distinctPositions[0], - minDiff = sieve.minDiff, - vpad = minDiff / 2; + var calcTraces = sieve.traces; + var distinctPositions = sieve.distinctPositions; + var distinctPositions0 = distinctPositions[0]; + var minDiff = sieve.minDiff; + var vpad = minDiff / 2; Axes.minDtick(pa, minDiff, distinctPositions0, allowMinDtick); @@ -469,31 +464,31 @@ function updatePositionAxis(gd, pa, sieve, allowMinDtick) { // // Here, we compute pMin and pMax to expand the position axis, // so that all bars are fully within the axis range. - var pMin = Math.min.apply(Math, distinctPositions) - vpad, - pMax = Math.max.apply(Math, distinctPositions) + vpad; + var pMin = Math.min.apply(Math, distinctPositions) - vpad; + var pMax = Math.max.apply(Math, distinctPositions) + vpad; for(var i = 0; i < calcTraces.length; i++) { - var calcTrace = calcTraces[i], - calcTrace0 = calcTrace[0], - fullTrace = calcTrace0.trace; + var calcTrace = calcTraces[i]; + var calcTrace0 = calcTrace[0]; + var fullTrace = calcTrace0.trace; if(fullTrace.width === undefined && fullTrace.offset === undefined) { continue; } - var t = calcTrace0.t, - poffset = t.poffset, - barwidth = t.barwidth, - poffsetIsArray = Array.isArray(poffset), - barwidthIsArray = Array.isArray(barwidth); + var t = calcTrace0.t; + var poffset = t.poffset; + var barwidth = t.barwidth; + var poffsetIsArray = Array.isArray(poffset); + var barwidthIsArray = Array.isArray(barwidth); for(var j = 0; j < calcTrace.length; j++) { - var calcBar = calcTrace[j], - calcBarOffset = (poffsetIsArray) ? poffset[j] : poffset, - calcBarWidth = (barwidthIsArray) ? barwidth[j] : barwidth, - p = calcBar.p, - l = p + calcBarOffset, - r = l + calcBarWidth; + var calcBar = calcTrace[j]; + var calcBarOffset = (poffsetIsArray) ? poffset[j] : poffset; + var calcBarWidth = (barwidthIsArray) ? barwidth[j] : barwidth; + var p = calcBar.p; + var l = p + calcBarOffset; + var r = l + calcBarWidth; pMin = Math.min(pMin, l); pMax = Math.max(pMax, r); @@ -516,17 +511,17 @@ function setBaseAndTop(gd, sa, sieve) { // store these bar bases and tops in calcdata // and make sure the size axis includes zero, // along with the bases and tops of each bar. - var traces = sieve.traces, - sLetter = getAxisLetter(sa), - sRange = [null, null]; + var traces = sieve.traces; + var sLetter = getAxisLetter(sa); + var sRange = [null, null]; for(var i = 0; i < traces.length; i++) { var trace = traces[i]; for(var j = 0; j < trace.length; j++) { - var bar = trace[j], - barBase = bar.b, - barTop = barBase + bar.s; + var bar = trace[j]; + var barBase = bar.b; + var barTop = barBase + bar.s; bar[sLetter] = barTop; @@ -541,12 +536,12 @@ function setBaseAndTop(gd, sa, sieve) { function stackBars(gd, sa, sieve) { - var fullLayout = gd._fullLayout, - barnorm = fullLayout.barnorm, - sLetter = getAxisLetter(sa), - traces = sieve.traces, - i, trace, - j, bar; + var fullLayout = gd._fullLayout; + var barnorm = fullLayout.barnorm; + var sLetter = getAxisLetter(sa); + var traces = sieve.traces; + var i, trace; + var j, bar; var sRange = [null, null]; @@ -559,8 +554,8 @@ function stackBars(gd, sa, sieve) { if(bar.s === BADNUM) continue; // stack current bar and get previous sum - var barBase = sieve.put(bar.p, bar.b + bar.s), - barTop = barBase + bar.b + bar.s; + var barBase = sieve.put(bar.p, bar.b + bar.s); + var barTop = barBase + bar.b + bar.s; // store the bar base and top in each calcdata item bar.b = barBase; @@ -602,14 +597,14 @@ function normalizeBars(gd, sa, sieve) { // normalizeBars requires that either sieveBars or stackBars has been // previously invoked. - var traces = sieve.traces, - sLetter = getAxisLetter(sa), - sTop = (gd._fullLayout.barnorm === 'fraction') ? 1 : 100, - sTiny = sTop / 1e9, // in case of rounding error in sum - sMin = sa.l2c(sa.c2l(0)), - sMax = (gd._fullLayout.barmode === 'stack') ? sTop : sMin, - sRange = [sMin, sMax], - padded = false; + var traces = sieve.traces; + var sLetter = getAxisLetter(sa); + var sTop = (gd._fullLayout.barnorm === 'fraction') ? 1 : 100; + var sTiny = sTop / 1e9; // in case of rounding error in sum + var sMin = sa.l2c(sa.c2l(0)); + var sMax = (gd._fullLayout.barmode === 'stack') ? sTop : sMin; + var sRange = [sMin, sMax]; + var padded = false; function maybeExpand(newValue) { if(isNumeric(sa.c2l(newValue)) && @@ -632,8 +627,8 @@ function normalizeBars(gd, sa, sieve) { bar.b *= scale; bar.s *= scale; - var barBase = bar.b, - barTop = barBase + bar.s; + var barBase = bar.b; + var barTop = barBase + bar.s; bar[sLetter] = barTop; maybeExpand(barTop); diff --git a/src/traces/bar/defaults.js b/src/traces/bar/defaults.js index df9666a4cdd..cd86704e3d0 100644 --- a/src/traces/bar/defaults.js +++ b/src/traces/bar/defaults.js @@ -41,9 +41,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout var textPosition = coerce('textposition'); - var hasBoth = Array.isArray(textPosition) || textPosition === 'auto', - hasInside = hasBoth || textPosition === 'inside', - hasOutside = hasBoth || textPosition === 'outside'; + var hasBoth = Array.isArray(textPosition) || textPosition === 'auto'; + var hasInside = hasBoth || textPosition === 'inside'; + var hasOutside = hasBoth || textPosition === 'outside'; if(hasInside || hasOutside) { var textFont = coerceFont(coerce, 'textfont', layout.font); diff --git a/src/traces/bar/helpers.js b/src/traces/bar/helpers.js index b86a1b619ee..d7f3ad3b957 100644 --- a/src/traces/bar/helpers.js +++ b/src/traces/bar/helpers.js @@ -14,8 +14,7 @@ var tinycolor = require('tinycolor2'); exports.coerceString = function(attributeDefinition, value, defaultValue) { if(typeof value === 'string') { if(value || !attributeDefinition.noBlank) return value; - } - else if(typeof value === 'number') { + } else if(typeof value === 'number') { if(!attributeDefinition.strict) return String(value); } @@ -28,9 +27,9 @@ exports.coerceNumber = function(attributeDefinition, value, defaultValue) { if(isNumeric(value)) { value = +value; - var min = attributeDefinition.min, - max = attributeDefinition.max, - isOutOfBounds = (min !== undefined && value < min) || + var min = attributeDefinition.min; + var max = attributeDefinition.max; + var isOutOfBounds = (min !== undefined && value < min) || (max !== undefined && value > max); if(!isOutOfBounds) return value; diff --git a/src/traces/bar/layout_defaults.js b/src/traces/bar/layout_defaults.js index 4809ce1d035..bf9abf78097 100644 --- a/src/traces/bar/layout_defaults.js +++ b/src/traces/bar/layout_defaults.js @@ -21,10 +21,10 @@ module.exports = function(layoutIn, layoutOut, fullData) { return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt); } - var hasBars = false, - shouldBeGapless = false, - gappedAnyway = false, - usedSubplots = {}; + var hasBars = false; + var shouldBeGapless = false; + var gappedAnyway = false; + var usedSubplots = {}; for(var i = 0; i < fullData.length; i++) { var trace = fullData[i]; diff --git a/src/traces/bar/plot.js b/src/traces/bar/plot.js index 8bbb97fe668..0230b79b24a 100644 --- a/src/traces/bar/plot.js +++ b/src/traces/bar/plot.js @@ -19,9 +19,9 @@ var Color = require('../../components/color'); var Drawing = require('../../components/drawing'); var Registry = require('../../registry'); -var attributes = require('./attributes'), - attributeText = attributes.text, - attributeTextPosition = attributes.textposition; +var attributes = require('./attributes'); +var attributeText = attributes.text; +var attributeTextPosition = attributes.textposition; var helpers = require('./helpers'); var style = require('./style'); @@ -84,8 +84,8 @@ module.exports = function plot(gd, plotinfo, cdbar, barLayer) { } var lw = (di.mlw + 1 || trace.marker.line.width + 1 || - (di.trace ? di.trace.marker.line.width : 0) + 1) - 1, - offset = d3.round((lw / 2) % 1, 2); + (di.trace ? di.trace.marker.line.width : 0) + 1) - 1; + var offset = d3.round((lw / 2) % 1, 2); function roundWithLine(v) { // if there are explicit gaps, don't round, @@ -111,9 +111,8 @@ module.exports = function plot(gd, plotinfo, cdbar, barLayer) { // pixelation. if the bars ARE fully opaque and have // 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) ? - roundWithLine : expandToVisible; + var op = Color.opacity(di.mc || trace.marker.color); + var fixpx = (op < 1 || lw > 0.01) ? roundWithLine : expandToVisible; x0 = fixpx(x0, x1); x1 = fixpx(x1, x0); y0 = fixpx(y0, y1); @@ -164,8 +163,8 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) { } // get trace attributes - var trace = calcTrace[0].trace, - orientation = trace.orientation; + var trace = calcTrace[0].trace; + var orientation = trace.orientation; var text = getText(trace, i); textPosition = getTextPosition(trace, i); @@ -181,21 +180,21 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) { var outsideTextFont = style.getOutsideTextFont(trace, i, layoutFont); // compute text position - var barmode = gd._fullLayout.barmode, - inStackMode = (barmode === 'stack'), - inRelativeMode = (barmode === 'relative'), - inStackOrRelativeMode = inStackMode || inRelativeMode, + var barmode = gd._fullLayout.barmode; + var inStackMode = (barmode === 'stack'); + var inRelativeMode = (barmode === 'relative'); + var inStackOrRelativeMode = inStackMode || inRelativeMode; - calcBar = calcTrace[i], - isOutmostBar = !inStackOrRelativeMode || calcBar._outmost, + var calcBar = calcTrace[i]; + var isOutmostBar = !inStackOrRelativeMode || calcBar._outmost; - barWidth = Math.abs(x1 - x0) - 2 * TEXTPAD, // padding excluded - barHeight = Math.abs(y1 - y0) - 2 * TEXTPAD, // padding excluded + var barWidth = Math.abs(x1 - x0) - 2 * TEXTPAD; // padding excluded + var barHeight = Math.abs(y1 - y0) - 2 * TEXTPAD; // padding excluded - textSelection, - textBB, - textWidth, - textHeight; + var textSelection; + var textBB; + var textWidth; + var textHeight; if(textPosition === 'outside') { if(!isOutmostBar && !calcBar.hasB) textPosition = 'inside'; @@ -211,14 +210,13 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) { textWidth = textBB.width, textHeight = textBB.height; - var textHasSize = (textWidth > 0 && textHeight > 0), - fitsInside = - (textWidth <= barWidth && textHeight <= barHeight), - fitsInsideIfRotated = - (textWidth <= barHeight && textHeight <= barWidth), - fitsInsideIfShrunk = (orientation === 'h') ? - (barWidth >= textWidth * (barHeight / textHeight)) : - (barHeight >= textHeight * (barWidth / textWidth)); + var textHasSize = (textWidth > 0 && textHeight > 0); + var fitsInside = (textWidth <= barWidth && textHeight <= barHeight); + var fitsInsideIfRotated = (textWidth <= barHeight && textHeight <= barWidth); + var fitsInsideIfShrunk = (orientation === 'h') ? + (barWidth >= textWidth * (barHeight / textHeight)) : + (barHeight >= textHeight * (barWidth / textWidth)); + if(textHasSize && (fitsInside || fitsInsideIfRotated || fitsInsideIfShrunk)) { textPosition = 'inside'; @@ -265,16 +263,16 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) { function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, orientation, constrained) { // compute text and target positions - var textWidth = textBB.width, - textHeight = textBB.height, - textX = (textBB.left + textBB.right) / 2, - textY = (textBB.top + textBB.bottom) / 2, - barWidth = Math.abs(x1 - x0), - barHeight = Math.abs(y1 - y0), - targetWidth, - targetHeight, - targetX, - targetY; + var textWidth = textBB.width; + var textHeight = textBB.height; + var textX = (textBB.left + textBB.right) / 2; + var textY = (textBB.top + textBB.bottom) / 2; + var barWidth = Math.abs(x1 - x0); + var barHeight = Math.abs(y1 - y0); + var targetWidth; + var targetHeight; + var targetX; + var targetY; // apply text padding var textpad; @@ -350,9 +348,9 @@ function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, orientation, constr function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, orientation, constrained) { var barWidth = (orientation === 'h') ? - Math.abs(y1 - y0) : - Math.abs(x1 - x0), - textpad; + Math.abs(y1 - y0) : + Math.abs(x1 - x0); + var textpad; // Keep the padding so the text doesn't sit right against // the bars, but don't factor it into barWidth @@ -369,12 +367,12 @@ function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, orientation, const } // compute text and target positions - var textX = (textBB.left + textBB.right) / 2, - textY = (textBB.top + textBB.bottom) / 2, - targetWidth, - targetHeight, - targetX, - targetY; + var textX = (textBB.left + textBB.right) / 2; + var textY = (textBB.top + textBB.bottom) / 2; + var targetWidth; + var targetHeight; + var targetX; + var targetY; targetWidth = scale * textBB.width; targetHeight = scale * textBB.height; @@ -406,9 +404,9 @@ function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, orientation, const } function getTransform(textX, textY, targetX, targetY, scale, rotate) { - var transformScale, - transformRotate, - transformTranslate; + var transformScale; + var transformRotate; + var transformTranslate; if(scale < 1) transformScale = 'scale(' + scale + ') '; else { @@ -420,8 +418,8 @@ function getTransform(textX, textY, targetX, targetY, scale, rotate) { 'rotate(' + rotate + ' ' + textX + ' ' + textY + ') ' : ''; // Note that scaling also affects the center of the text box - var translateX = (targetX - scale * textX), - translateY = (targetY - scale * textY); + var translateX = (targetX - scale * textX); + var translateY = (targetY - scale * textY); transformTranslate = 'translate(' + translateX + ' ' + translateY + ')'; return transformTranslate + transformScale + transformRotate; diff --git a/src/traces/bar/sieve.js b/src/traces/bar/sieve.js index 854ecd98e55..fa3142a2fd0 100644 --- a/src/traces/bar/sieve.js +++ b/src/traces/bar/sieve.js @@ -65,8 +65,8 @@ function Sieve(traces, separateNegativeValues, dontMergeOverlappingData) { * @returns {number} Previous bin value */ Sieve.prototype.put = function put(position, value) { - var label = this.getLabel(position, value), - oldValue = this.bins[label] || 0; + var label = this.getLabel(position, value); + var oldValue = this.bins[label] || 0; this.bins[label] = oldValue + value; @@ -99,9 +99,9 @@ Sieve.prototype.get = function put(position, value) { * true; otherwise prefixed with '^') */ Sieve.prototype.getLabel = function getLabel(position, value) { - var prefix = (value < 0 && this.separateNegativeValues) ? 'v' : '^', - label = (this.dontMergeOverlappingData) ? - position : - Math.round(position / this.binWidth); + var prefix = (value < 0 && this.separateNegativeValues) ? 'v' : '^'; + var label = (this.dontMergeOverlappingData) ? + position : + Math.round(position / this.binWidth); return prefix + label; }; diff --git a/src/traces/bar/style.js b/src/traces/bar/style.js index df729416dc1..f395f95de89 100644 --- a/src/traces/bar/style.js +++ b/src/traces/bar/style.js @@ -15,10 +15,10 @@ var Drawing = require('../../components/drawing'); var Lib = require('../../lib'); var Registry = require('../../registry'); -var attributes = require('./attributes'), - attributeTextFont = attributes.textfont, - attributeInsideTextFont = attributes.insidetextfont, - attributeOutsideTextFont = attributes.outsidetextfont; +var attributes = require('./attributes'); +var attributeTextFont = attributes.textfont; +var attributeInsideTextFont = attributes.insidetextfont; +var attributeOutsideTextFont = attributes.outsidetextfont; var helpers = require('./helpers'); function style(gd, cd) { @@ -145,9 +145,9 @@ function getOutsideTextFont(trace, index, layoutFont) { function getFontValue(attributeDefinition, attributeValue, index, defaultValue) { attributeValue = attributeValue || {}; - var familyValue = helpers.getValue(attributeValue.family, index), - sizeValue = helpers.getValue(attributeValue.size, index), - colorValue = helpers.getValue(attributeValue.color, index); + var familyValue = helpers.getValue(attributeValue.family, index); + var sizeValue = helpers.getValue(attributeValue.size, index); + var colorValue = helpers.getValue(attributeValue.color, index); return { family: helpers.coerceString( diff --git a/src/traces/carpet/axis_defaults.js b/src/traces/carpet/axis_defaults.js index 59cd9c19948..e8b486a722c 100644 --- a/src/traces/carpet/axis_defaults.js +++ b/src/traces/carpet/axis_defaults.js @@ -32,9 +32,9 @@ var autoType = require('../../plots/cartesian/axis_autotype'); * bgColor: the plot background color, to calculate default gridline colors */ module.exports = function handleAxisDefaults(containerIn, containerOut, options) { - var letter = options.letter, - font = options.font || {}, - attributes = carpetAttrs[letter + 'axis']; + var letter = options.letter; + var font = options.font || {}; + var attributes = carpetAttrs[letter + 'axis']; function coerce(attr, dflt) { return Lib.coerce(containerIn, containerOut, attributes, attr, dflt); @@ -212,11 +212,11 @@ function setAutoType(ax, data) { // only autotype if type is '-' if(ax.type !== '-') return; - var id = ax._id, - axLetter = id.charAt(0); + var id = ax._id; + var axLetter = id.charAt(0); - var calAttr = axLetter + 'calendar', - calendar = ax[calAttr]; + var calAttr = axLetter + 'calendar'; + var calendar = ax[calAttr]; ax.type = autoType(data, calendar); } diff --git a/src/traces/carpet/catmull_rom.js b/src/traces/carpet/catmull_rom.js index 766149d484d..09aab00c0b5 100644 --- a/src/traces/carpet/catmull_rom.js +++ b/src/traces/carpet/catmull_rom.js @@ -20,16 +20,17 @@ */ var CatmullRomExp = 0.5; module.exports = function makeControlPoints(p0, p1, p2, smoothness) { - var d1x = p0[0] - p1[0], - d1y = p0[1] - p1[1], - d2x = p2[0] - p1[0], - d2y = p2[1] - p1[1], - d1a = Math.pow(d1x * d1x + d1y * d1y, CatmullRomExp / 2), - d2a = Math.pow(d2x * d2x + d2y * d2y, CatmullRomExp / 2), - numx = (d2a * d2a * d1x - d1a * d1a * d2x) * smoothness, - numy = (d2a * d2a * d1y - d1a * d1a * d2y) * smoothness, - denom1 = d2a * (d1a + d2a) * 3, - denom2 = d1a * (d1a + d2a) * 3; + var d1x = p0[0] - p1[0]; + var d1y = p0[1] - p1[1]; + var d2x = p2[0] - p1[0]; + var d2y = p2[1] - p1[1]; + var d1a = Math.pow(d1x * d1x + d1y * d1y, CatmullRomExp / 2); + var d2a = Math.pow(d2x * d2x + d2y * d2y, CatmullRomExp / 2); + var numx = (d2a * d2a * d1x - d1a * d1a * d2x) * smoothness; + var numy = (d2a * d2a * d1y - d1a * d1a * d2y) * smoothness; + var denom1 = d2a * (d1a + d2a) * 3; + var denom2 = d1a * (d1a + d2a) * 3; + return [[ p1[0] + (denom1 && numx / denom1), p1[1] + (denom1 && numy / denom1) diff --git a/src/traces/carpet/makepath.js b/src/traces/carpet/makepath.js index cf569215a1d..6a07744f648 100644 --- a/src/traces/carpet/makepath.js +++ b/src/traces/carpet/makepath.js @@ -12,7 +12,8 @@ module.exports = function makePath(xp, yp, isBicubic) { // Prevent d3 errors that would result otherwise: if(xp.length === 0) return ''; - var i, path = []; + var i; + var path = []; var stride = isBicubic ? 3 : 1; for(i = 0; i < xp.length; i += stride) { path.push(xp[i] + ',' + yp[i]); diff --git a/src/traces/contour/find_all_paths.js b/src/traces/contour/find_all_paths.js index d0746ac1e65..ef613dc11db 100644 --- a/src/traces/contour/find_all_paths.js +++ b/src/traces/contour/find_all_paths.js @@ -47,8 +47,8 @@ function equalPts(pt1, pt2, xtol, ytol) { // distance in index units - uses the 3rd and 4th items in points function ptDist(pt1, pt2) { - var dx = pt1[2] - pt2[2], - dy = pt1[3] - pt2[3]; + var dx = pt1[2] - pt2[2]; + var dy = pt1[3] - pt2[3]; return Math.sqrt(dx * dx + dy * dy); } @@ -90,8 +90,8 @@ function makePath(pi, loc, edgeflag, xtol, ytol) { locStr = loc.join(','); var atEdge = (marchStep[0] && (loc[0] < 0 || loc[0] > n - 2)) || - (marchStep[1] && (loc[1] < 0 || loc[1] > m - 2)), - closedLoop = (locStr === startLocStr) && (marchStep.join(',') === startStepStr); + (marchStep[1] && (loc[1] < 0 || loc[1] > m - 2)); + var closedLoop = (locStr === startLocStr) && (marchStep.join(',') === startStepStr); // have we completed a loop, or reached an edge? if((closedLoop) || (edgeflag && atEdge)) break; @@ -240,8 +240,8 @@ function makePath(pi, loc, edgeflag, xtol, ytol) { // special function to get the marching step of the // first point in the path (leading to loc) function startStep(mi, edgeflag, loc) { - var dx = 0, - dy = 0; + var dx = 0; + var dy = 0; if(mi > 20 && edgeflag) { // these saddles start at +/- x if(mi === 208 || mi === 1114) { @@ -276,11 +276,11 @@ function startStep(mi, edgeflag, loc) { * points into a path, because those routines require length-2 points. */ function getInterpPx(pi, loc, step) { - var locx = loc[0] + Math.max(step[0], 0), - locy = loc[1] + Math.max(step[1], 0), - zxy = pi.z[locy][locx], - xa = pi.xaxis, - ya = pi.yaxis; + var locx = loc[0] + Math.max(step[0], 0); + var locy = loc[1] + Math.max(step[1], 0); + var zxy = pi.z[locy][locx]; + var xa = pi.xaxis; + var ya = pi.yaxis; if(step[1]) { var dx = (pi.level - zxy) / (pi.z[locy][locx + 1] - zxy); diff --git a/src/traces/contour/make_color_map.js b/src/traces/contour/make_color_map.js index 825bf534caa..f049e8da4ae 100644 --- a/src/traces/contour/make_color_map.js +++ b/src/traces/contour/make_color_map.js @@ -14,12 +14,12 @@ var Colorscale = require('../../components/colorscale'); var endPlus = require('./end_plus'); module.exports = function makeColorMap(trace) { - var contours = trace.contours, - start = contours.start, - end = endPlus(contours), - cs = contours.size || 1, - nc = Math.floor((end - start) / cs) + 1, - extra = contours.coloring === 'lines' ? 0 : 1; + var contours = trace.contours; + var start = contours.start; + var end = endPlus(contours); + var cs = contours.size || 1; + var nc = Math.floor((end - start) / cs) + 1; + var extra = contours.coloring === 'lines' ? 0 : 1; if(!isFinite(cs)) { cs = 1; @@ -51,10 +51,14 @@ module.exports = function makeColorMap(trace) { // do the contours extend beyond the colorscale? // if so, extend the colorscale with constants - var zRange = d3.extent([trace.zmin, trace.zmax, contours.start, - contours.start + cs * (nc - 1)]), - zmin = zRange[trace.zmin < trace.zmax ? 0 : 1], - zmax = zRange[trace.zmin < trace.zmax ? 1 : 0]; + var zRange = d3.extent([ + trace.zmin, + trace.zmax, + contours.start, + contours.start + cs * (nc - 1) + ]); + var zmin = zRange[trace.zmin < trace.zmax ? 0 : 1]; + var zmax = zRange[trace.zmin < trace.zmax ? 1 : 0]; if(zmin !== trace.zmin) { domain.splice(0, 0, zmin); diff --git a/src/traces/contour/make_crossings.js b/src/traces/contour/make_crossings.js index 0d51d5c3a47..5c86dbecf16 100644 --- a/src/traces/contour/make_crossings.js +++ b/src/traces/contour/make_crossings.js @@ -15,19 +15,19 @@ var constants = require('./constants'); // at every intersection, rather than just following a path // TODO: shorten the inner loop to only the relevant levels module.exports = 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, - xi, - yi, - startIndices, - ystartIndices, - label, - corners, - mi, - pi, - i; + var z = pathinfo[0].z; + var m = z.length; + var n = z[0].length; // we already made sure z isn't ragged in interp2d + var twoWide = m === 2 || n === 2; + var xi; + var yi; + var startIndices; + var ystartIndices; + var label; + var corners; + var mi; + var pi; + var i; for(yi = 0; yi < m - 1; yi++) { ystartIndices = []; diff --git a/src/traces/contour/plot.js b/src/traces/contour/plot.js index 88ce634fb5d..cec17498a65 100644 --- a/src/traces/contour/plot.js +++ b/src/traces/contour/plot.js @@ -56,16 +56,16 @@ exports.plot = function plot(gd, plotinfo, cdcontours, contourLayer) { makeCrossings(pathinfo); findAllPaths(pathinfo); - var leftedge = xa.c2p(x[0], true), - rightedge = xa.c2p(x[x.length - 1], true), - bottomedge = ya.c2p(y[0], true), - topedge = ya.c2p(y[y.length - 1], true), - perimeter = [ - [leftedge, topedge], - [rightedge, topedge], - [rightedge, bottomedge], - [leftedge, bottomedge] - ]; + var leftedge = xa.c2p(x[0], true); + var rightedge = xa.c2p(x[x.length - 1], true); + var bottomedge = ya.c2p(y[0], true); + var topedge = ya.c2p(y[y.length - 1], true); + var perimeter = [ + [leftedge, topedge], + [rightedge, topedge], + [rightedge, bottomedge], + [leftedge, bottomedge] + ]; var fillPathinfo = pathinfo; if(contours.type === 'constraint') { @@ -129,16 +129,16 @@ function initFullPath(pi, perimeter) { } function joinAllPaths(pi, perimeter) { - var fullpath = initFullPath(pi, perimeter), - i = 0, - startsleft = pi.edgepaths.map(function(v, i) { return i; }), - newloop = true, - endpt, - newendpt, - cnt, - nexti, - possiblei, - addpath; + var fullpath = initFullPath(pi, perimeter); + var i = 0; + var startsleft = pi.edgepaths.map(function(v, i) { return i; }); + var newloop = true; + var endpt; + var newendpt; + var cnt; + var nexti; + var possiblei; + var addpath; function istop(pt) { return Math.abs(pt[1] - perimeter[0][1]) < 0.01; } function isbottom(pt) { return Math.abs(pt[1] - perimeter[2][1]) < 0.01; } @@ -664,13 +664,13 @@ function clipGaps(plotGroup, plotinfo, gd, cd0, perimeter) { } function makeClipMask(cd0) { - var empties = cd0.trace._emptypoints, - z = [], - m = cd0.z.length, - n = cd0.z[0].length, - i, - row = [], - emptyPoint; + var empties = cd0.trace._emptypoints; + var z = []; + var m = cd0.z.length; + var n = cd0.z[0].length; + var i; + var row = []; + var emptyPoint; for(i = 0; i < n; i++) row.push(1); for(i = 0; i < m; i++) z.push(row.slice()); diff --git a/src/traces/contour/set_contours.js b/src/traces/contour/set_contours.js index 91eaf715456..c8f28f3ff8e 100644 --- a/src/traces/contour/set_contours.js +++ b/src/traces/contour/set_contours.js @@ -55,9 +55,9 @@ module.exports = function setContours(trace) { } else if(contours.type !== 'constraint') { // sanity checks on manually-supplied start/end/size - var start = contours.start, - end = contours.end, - inputContours = trace._input.contours; + var start = contours.start; + var end = contours.end; + var inputContours = trace._input.contours; if(start > end) { contours.start = inputContours.start = end; diff --git a/src/traces/contourcarpet/calc.js b/src/traces/contourcarpet/calc.js index 878c481b8de..1825711f158 100644 --- a/src/traces/contourcarpet/calc.js +++ b/src/traces/contourcarpet/calc.js @@ -86,11 +86,11 @@ function heatmappishCalc(gd, trace) { interp2d(z, trace._emptypoints); // create arrays of brick boundaries, to be used by autorange and heatmap.plot - var xlen = Lib.maxRowLength(z), - xIn = trace.xtype === 'scaled' ? '' : a, - xArray = makeBoundArray(trace, xIn, a0, da, xlen, aax), - yIn = trace.ytype === 'scaled' ? '' : b, - yArray = makeBoundArray(trace, yIn, b0, db, z.length, bax); + var xlen = Lib.maxRowLength(z); + var xIn = trace.xtype === 'scaled' ? '' : a; + var xArray = makeBoundArray(trace, xIn, a0, da, xlen, aax); + var yIn = trace.ytype === 'scaled' ? '' : b; + var yArray = makeBoundArray(trace, yIn, b0, db, z.length, bax); var cd0 = { a: xArray, diff --git a/src/traces/contourgl/convert.js b/src/traces/contourgl/convert.js index 32632c5ee11..0ec0826549e 100644 --- a/src/traces/contourgl/convert.js +++ b/src/traces/contourgl/convert.js @@ -60,12 +60,12 @@ function Contour(scene, uid) { var proto = Contour.prototype; proto.handlePick = function(pickResult) { - var options = this.heatmapOptions, - shape = options.shape, - index = pickResult.pointId, - xIndex = index % shape[0], - yIndex = Math.floor(index / shape[0]), - zIndex = index; + var options = this.heatmapOptions; + var shape = options.shape; + var index = pickResult.pointId; + var xIndex = index % shape[0]; + var yIndex = Math.floor(index / shape[0]); + var zIndex = index; return { trace: this, @@ -90,10 +90,10 @@ proto.update = function(fullTrace, calcTrace) { this.hoverinfo = fullTrace.hoverinfo; // convert z from 2D -> 1D - var z = calcPt.z, - rowLen = z[0].length, - colLen = z.length, - colorOptions; + var z = calcPt.z; + var rowLen = z[0].length; + var colLen = z.length; + var colorOptions; this.contourOptions.z = flattenZ(z, rowLen, colLen); this.heatmapOptions.z = [].concat.apply([], z); @@ -150,17 +150,17 @@ function flattenZ(zIn, rowLen, colLen) { } function convertColorScale(fullTrace, options) { - var contours = fullTrace.contours, - start = contours.start, - end = contours.end, - cs = contours.size || 1, - fill = options.fill; + var contours = fullTrace.contours; + var start = contours.start; + var end = contours.end; + var cs = contours.size || 1; + var fill = options.fill; var colorMap = makeColorMap(fullTrace); - var N = Math.floor((end - start) / cs) + (fill ? 2 : 1), // for K thresholds (contour linees) there are K+1 areas - levels = new Array(N), - levelColors = new Array(4 * N); + var N = Math.floor((end - start) / cs) + (fill ? 2 : 1); // for K thresholds (contour linees) there are K+1 areas + var levels = new Array(N); + var levelColors = new Array(4 * N); for(var i = 0; i < N; i++) { var level = levels[i] = start + cs * (i) - (fill ? cs / 2 : 0); // in case of fill, use band midpoint diff --git a/src/traces/heatmap/calc.js b/src/traces/heatmap/calc.js index c6c9ad70b1d..8463654ed17 100644 --- a/src/traces/heatmap/calc.js +++ b/src/traces/heatmap/calc.js @@ -25,21 +25,21 @@ var makeBoundArray = require('./make_bound_array'); 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'), - isContour = Registry.traceIs(trace, 'contour'), - isHist = Registry.traceIs(trace, 'histogram'), - isGL2D = Registry.traceIs(trace, 'gl2d'), - zsmooth = isContour ? 'best' : trace.zsmooth, - x, - x0, - dx, - y, - y0, - dy, - z, - i, - binned; + var xa = Axes.getFromId(gd, trace.xaxis || 'x'); + var ya = Axes.getFromId(gd, trace.yaxis || 'y'); + var isContour = Registry.traceIs(trace, 'contour'); + var isHist = Registry.traceIs(trace, 'histogram'); + var isGL2D = Registry.traceIs(trace, 'gl2d'); + var zsmooth = isContour ? 'best' : trace.zsmooth; + var x; + var x0; + var dx; + var y; + var y0; + var dy; + var z; + var i; + var binned; // cancel minimum tick spacings (only applies to bars and boxes) xa._minDtick = 0; @@ -92,8 +92,8 @@ module.exports = function calc(gd, trace) { } else if(!isHist) { if(x.length) { - var avgdx = (x[x.length - 1] - x[0]) / (x.length - 1), - maxErrX = Math.abs(avgdx / 100); + var avgdx = (x[x.length - 1] - x[0]) / (x.length - 1); + var 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'); @@ -102,8 +102,8 @@ module.exports = function calc(gd, trace) { } } if(y.length && zsmooth === 'fast') { - var avgdy = (y[y.length - 1] - y[0]) / (y.length - 1), - maxErrY = Math.abs(avgdy / 100); + var avgdy = (y[y.length - 1] - y[0]) / (y.length - 1); + var 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'); diff --git a/src/traces/heatmap/find_empties.js b/src/traces/heatmap/find_empties.js index 27c9244a420..9f74f76c28c 100644 --- a/src/traces/heatmap/find_empties.js +++ b/src/traces/heatmap/find_empties.js @@ -18,21 +18,21 @@ var maxRowLength = require('../../lib').maxRowLength; * neighbors, and add a fractional neighborCount */ module.exports = function findEmpties(z) { - var empties = [], - neighborHash = {}, - noNeighborList = [], - nextRow = z[0], - row = [], - blank = [0, 0, 0], - rowLength = maxRowLength(z), - prevRow, - i, - j, - thisPt, - p, - neighborCount, - newNeighborHash, - foundNewNeighbors; + var empties = []; + var neighborHash = {}; + var noNeighborList = []; + var nextRow = z[0]; + var row = []; + var blank = [0, 0, 0]; + var rowLength = maxRowLength(z); + var prevRow; + var i; + var j; + var thisPt; + var p; + var neighborCount; + var newNeighborHash; + var foundNewNeighbors; for(i = 0; i < z.length; i++) { prevRow = row; diff --git a/src/traces/heatmap/hover.js b/src/traces/heatmap/hover.js index 21aa0d08145..b5d740c5ade 100644 --- a/src/traces/heatmap/hover.js +++ b/src/traces/heatmap/hover.js @@ -69,10 +69,10 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLay ny = Math.max(0, Math.min(y2.length - 2, Lib.findBin(yval, y2))); } - var x0 = xa.c2p(x[nx]), - x1 = xa.c2p(x[nx + 1]), - y0 = ya.c2p(y[ny]), - y1 = ya.c2p(y[ny + 1]); + var x0 = xa.c2p(x[nx]); + var x1 = xa.c2p(x[nx + 1]); + var y0 = ya.c2p(y[ny]); + var y1 = ya.c2p(y[ny + 1]); if(contour) { x1 = x0; diff --git a/src/traces/heatmap/interp2d.js b/src/traces/heatmap/interp2d.js index 785f3baad4e..11f3804e8f9 100644 --- a/src/traces/heatmap/interp2d.js +++ b/src/traces/heatmap/interp2d.js @@ -62,20 +62,20 @@ module.exports = function interp2d(z, emptyPoints) { }; function iterateInterp2d(z, emptyPoints, overshoot) { - var maxFractionalChange = 0, - thisPt, - i, - j, - p, - q, - neighborShift, - neighborRow, - neighborVal, - neighborCount, - neighborSum, - initialVal, - minNeighbor, - maxNeighbor; + var maxFractionalChange = 0; + var thisPt; + var i; + var j; + var p; + var q; + var neighborShift; + var neighborRow; + var neighborVal; + var neighborCount; + var neighborSum; + var initialVal; + var minNeighbor; + var maxNeighbor; for(p = 0; p < emptyPoints.length; p++) { thisPt = emptyPoints[p]; diff --git a/src/traces/heatmap/make_bound_array.js b/src/traces/heatmap/make_bound_array.js index ea3ec9a33a3..775db9a3ff9 100644 --- a/src/traces/heatmap/make_bound_array.js +++ b/src/traces/heatmap/make_bound_array.js @@ -12,13 +12,13 @@ var Registry = require('../../registry'); var isArrayOrTypedArray = require('../../lib').isArrayOrTypedArray; module.exports = function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, ax) { - var arrayOut = [], - isContour = Registry.traceIs(trace, 'contour'), - isHist = Registry.traceIs(trace, 'histogram'), - isGL2D = Registry.traceIs(trace, 'gl2d'), - v0, - dv, - i; + var arrayOut = []; + var isContour = Registry.traceIs(trace, 'contour'); + var isHist = Registry.traceIs(trace, 'histogram'); + var isGL2D = Registry.traceIs(trace, 'gl2d'); + var v0; + var dv; + var i; var isArrayOfTwoItemsOrMore = isArrayOrTypedArray(arrayIn) && arrayIn.length > 1; @@ -45,8 +45,8 @@ module.exports = function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, } if(len < numbricks) { - var lastPt = arrayOut[arrayOut.length - 1], - delta = lastPt - arrayOut[arrayOut.length - 2]; + var lastPt = arrayOut[arrayOut.length - 1]; + var delta = lastPt - arrayOut[arrayOut.length - 2]; for(i = len; i < numbricks; i++) { lastPt += delta; diff --git a/src/traces/heatmap/plot.js b/src/traces/heatmap/plot.js index d282504d854..297deb2d667 100644 --- a/src/traces/heatmap/plot.js +++ b/src/traces/heatmap/plot.js @@ -110,8 +110,8 @@ module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) { bottom = Math.min((1 + extra) * ya._length, bottom); } - var imageWidth = Math.round(right - left), - imageHeight = Math.round(bottom - top); + var imageWidth = Math.round(right - left); + var imageHeight = Math.round(bottom - top); // setup image nodes @@ -202,12 +202,12 @@ module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) { var z00 = r0[xinterp.bin0]; if(z00 === undefined) return setColor(undefined, 1); - var z01 = r0[xinterp.bin1], - z10 = r1[xinterp.bin0], - z11 = r1[xinterp.bin1], - dx = (z01 - z00) || 0, - dy = (z10 - z00) || 0, - dxy; + var z01 = r0[xinterp.bin1]; + var z10 = r1[xinterp.bin0]; + var z11 = r1[xinterp.bin1]; + var dx = (z01 - z00) || 0; + var dy = (z10 - z00) || 0; + var dxy; // the bilinear interpolation term needs different calculations // for all the different permutations of missing data @@ -229,13 +229,12 @@ module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) { } if(zsmooth) { // best or fast, works fastest with imageData - var pxIndex = 0, - pixels; + var pxIndex = 0; + var pixels; try { pixels = new Uint8Array(imageWidth * imageHeight * 4); - } - catch(e) { + } catch(e) { pixels = new Array(imageWidth * imageHeight * 4); } @@ -283,10 +282,9 @@ module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) { var imageData = context.createImageData(imageWidth, imageHeight); try { imageData.data.set(pixels); - } - catch(e) { - var pxArray = imageData.data, - dlen = pxArray.length; + } catch(e) { + var pxArray = imageData.data; + var dlen = pxArray.length; for(j = 0; j < dlen; j ++) { pxArray[j] = pixels[j]; } diff --git a/src/traces/heatmap/xyz_defaults.js b/src/traces/heatmap/xyz_defaults.js index 6bfafcbdbc1..1c7ae50a6a0 100644 --- a/src/traces/heatmap/xyz_defaults.js +++ b/src/traces/heatmap/xyz_defaults.js @@ -64,10 +64,10 @@ function coordDefaults(coordStr, coerce) { } function isValidZ(z) { - var allRowsAreArrays = true, - oneRowIsFilled = false, - hasOneNumber = false, - zi; + var allRowsAreArrays = true; + var oneRowIsFilled = false; + var hasOneNumber = false; + var zi; /* * Without this step: diff --git a/src/traces/heatmapgl/convert.js b/src/traces/heatmapgl/convert.js index 8fc9980fcfb..092745572ee 100644 --- a/src/traces/heatmapgl/convert.js +++ b/src/traces/heatmapgl/convert.js @@ -46,12 +46,12 @@ function Heatmap(scene, uid) { var proto = Heatmap.prototype; proto.handlePick = function(pickResult) { - var options = this.options, - shape = options.shape, - index = pickResult.pointId, - xIndex = index % shape[0], - yIndex = Math.floor(index / shape[0]), - zIndex = index; + var options = this.options; + var shape = options.shape; + var index = pickResult.pointId; + var xIndex = index % shape[0]; + var yIndex = Math.floor(index / shape[0]); + var zIndex = index; return { trace: this, @@ -79,8 +79,8 @@ proto.update = function(fullTrace, calcTrace) { var z = calcPt.z; this.options.z = [].concat.apply([], z); - var rowLen = z[0].length, - colLen = z.length; + var rowLen = z[0].length; + var colLen = z.length; this.options.shape = [rowLen, colLen]; this.options.x = calcPt.x; @@ -106,13 +106,13 @@ proto.dispose = function() { }; function convertColorscale(fullTrace) { - var scl = fullTrace.colorscale, - zmin = fullTrace.zmin, - zmax = fullTrace.zmax; + var scl = fullTrace.colorscale; + var zmin = fullTrace.zmin; + var zmax = fullTrace.zmax; - var N = scl.length, - domain = new Array(N), - range = new Array(4 * N); + var N = scl.length; + var domain = new Array(N); + var range = new Array(4 * N); for(var i = 0; i < N; i++) { var si = scl[i]; diff --git a/src/traces/histogram/average.js b/src/traces/histogram/average.js index 0f45479b08c..48eb7869174 100644 --- a/src/traces/histogram/average.js +++ b/src/traces/histogram/average.js @@ -11,8 +11,8 @@ module.exports = function doAvg(size, counts) { - var nMax = size.length, - total = 0; + var nMax = size.length; + var total = 0; for(var i = 0; i < nMax; i++) { if(counts[i]) { size[i] /= counts[i]; diff --git a/src/traces/histogram/norm_functions.js b/src/traces/histogram/norm_functions.js index 1fec7603e19..cf08f087e05 100644 --- a/src/traces/histogram/norm_functions.js +++ b/src/traces/histogram/norm_functions.js @@ -12,8 +12,8 @@ module.exports = { percent: function(size, total) { - var nMax = size.length, - norm = 100 / total; + var nMax = size.length; + var norm = 100 / total; for(var n = 0; n < nMax; n++) size[n] *= norm; }, probability: function(size, total) { diff --git a/src/traces/histogram2d/calc.js b/src/traces/histogram2d/calc.js index 7a221a8eb91..7aa0e96ee11 100644 --- a/src/traces/histogram2d/calc.js +++ b/src/traces/histogram2d/calc.js @@ -79,10 +79,10 @@ module.exports = function calc(gd, trace) { } // decrease end a little in case of rounding errors - var binSpec = trace.xbins, - binStart = xr2c(binSpec.start), - binEnd = xr2c(binSpec.end) + - (binStart - Axes.tickIncrement(binStart, binSpec.size, false, xcalendar)) / 1e6; + var binSpec = trace.xbins; + var binStart = xr2c(binSpec.start); + var binEnd = xr2c(binSpec.end) + + (binStart - Axes.tickIncrement(binStart, binSpec.size, false, xcalendar)) / 1e6; for(i = binStart; i < binEnd; i = Axes.tickIncrement(i, binSpec.size, false, xcalendar)) { onecol.push(sizeinit); diff --git a/src/traces/mesh3d/convert.js b/src/traces/mesh3d/convert.js index 0059e8dba64..323a122008e 100644 --- a/src/traces/mesh3d/convert.js +++ b/src/traces/mesh3d/convert.js @@ -56,8 +56,8 @@ function parseColorArray(colors) { } proto.update = function(data) { - var scene = this.scene, - layout = scene.fullSceneLayout; + var scene = this.scene; + var layout = scene.fullSceneLayout; this.data = data; diff --git a/src/traces/ohlc/calc.js b/src/traces/ohlc/calc.js index fe60922d525..54b522be487 100644 --- a/src/traces/ohlc/calc.js +++ b/src/traces/ohlc/calc.js @@ -120,8 +120,8 @@ function convertTickWidth(gd, xa, trace) { var minDiff = trace._minDiff; if(!minDiff) { - var fullData = gd._fullData, - ohlcTracesOnThisXaxis = []; + var fullData = gd._fullData; + var ohlcTracesOnThisXaxis = []; minDiff = Infinity; diff --git a/src/traces/parcats/calc.js b/src/traces/parcats/calc.js index 67d4b6c9217..5343ff096c2 100644 --- a/src/traces/parcats/calc.js +++ b/src/traces/parcats/calc.js @@ -397,9 +397,9 @@ function getUniqueInfo(values, uniqueValues) { } // Initialize Variables - var uniqueValueCounts = {}, - uniqueValueInds = {}, - inds = []; + var uniqueValueCounts = {}; + var uniqueValueInds = {}; + var inds = []; // Initialize uniqueValueCounts and uniqueValues.forEach(function(uniqueVal, valInd) { diff --git a/src/traces/parcats/parcats.js b/src/traces/parcats/parcats.js index 538cd797f66..37da77355c2 100644 --- a/src/traces/parcats/parcats.js +++ b/src/traces/parcats/parcats.js @@ -364,8 +364,8 @@ function key(d) { /** True if a category view model is in the right-most display dimension * @param {CategoryViewModel} d */ function catInRightDim(d) { - var numDims = d.parcatsViewModel.dimensions.length, - leftDimInd = d.parcatsViewModel.dimensions[numDims - 1].model.dimensionInd; + var numDims = d.parcatsViewModel.dimensions.length; + var leftDimInd = d.parcatsViewModel.dimensions[numDims - 1].model.dimensionInd; return d.model.dimensionInd === leftDimInd; } @@ -1058,9 +1058,9 @@ function dragDimension(d) { return; } - var dragDimInd = d.dragDimensionDisplayInd, - prevDimInd = dragDimInd - 1, - nextDimInd = dragDimInd + 1; + var dragDimInd = d.dragDimensionDisplayInd; + var prevDimInd = dragDimInd - 1; + var nextDimInd = dragDimInd + 1; var dragDimension = d.parcatsViewModel .dimensions[dragDimInd]; @@ -1456,14 +1456,14 @@ function createParcatsViewModel(graphDiv, layout, wrappedParcatsModel) { var margin = layout.margin || {l: 80, r: 80, t: 100, b: 80}; // Compute pixel position/extents - var trace = parcatsModel.trace, - domain = trace.domain, - figureWidth = layout.width, - figureHeight = layout.height, - traceWidth = Math.floor(figureWidth * (domain.x[1] - domain.x[0])), - traceHeight = Math.floor(figureHeight * (domain.y[1] - domain.y[0])), - traceX = domain.x[0] * figureWidth + margin.l, - traceY = layout.height - domain.y[1] * layout.height + margin.t; + var trace = parcatsModel.trace; + var domain = trace.domain; + var figureWidth = layout.width; + var figureHeight = layout.height; + var traceWidth = Math.floor(figureWidth * (domain.x[1] - domain.x[0])); + var traceHeight = Math.floor(figureHeight * (domain.y[1] - domain.y[0])); + var traceX = domain.x[0] * figureWidth + margin.l; + var traceY = layout.height - domain.y[1] * layout.height + margin.t; // Handle path shape // ----------------- @@ -1533,10 +1533,10 @@ function createParcatsViewModel(graphDiv, layout, wrappedParcatsModel) { function buildSvgPath(leftXPositions, pathYs, dimWidths, pathHeight, curvature) { // Compute the x midpoint of each path segment - var xRefPoints1 = [], - xRefPoints2 = [], - refInterpolator, - d; + var xRefPoints1 = []; + var xRefPoints2 = []; + var refInterpolator; + var d; for(d = 0; d < dimWidths.length - 1; d++) { refInterpolator = d3.interpolateNumber(dimWidths[d] + leftXPositions[d], leftXPositions[d + 1]); @@ -1681,12 +1681,11 @@ function updatePathViewModels(parcatsViewModel) { }); // Create path models - var pathViewModels = new Array(pathModels.length), - totalCount = dimensionViewModels[0].model.count, - totalHeight = dimensionViewModels[0].categories - .map(function(c) { - return c.height;}).reduce( - function(v1, v2) {return v1 + v2;}); + var pathViewModels = new Array(pathModels.length); + var totalCount = dimensionViewModels[0].model.count; + var totalHeight = dimensionViewModels[0].categories + .map(function(c) { return c.height; }) + .reduce(function(v1, v2) { return v1 + v2; }); for(var pathNumber = 0; pathNumber < pathModels.length; pathNumber++) { @@ -1807,15 +1806,15 @@ function updateDimensionViewModels(parcatsViewModel) { function createDimensionViewModel(parcatsViewModel, dimensionModel) { // Compute dimension x position - var categoryLabelPad = 40, - dimWidth = 16, - numDimensions = parcatsViewModel.model.dimensions.length, - displayInd = dimensionModel.displayInd; + var categoryLabelPad = 40; + var dimWidth = 16; + var numDimensions = parcatsViewModel.model.dimensions.length; + var displayInd = dimensionModel.displayInd; // Compute x coordinate values - var dimDx, - dimX0, - dimX; + var dimDx; + var dimX0; + var dimX; if(numDimensions > 1) { dimDx = (parcatsViewModel.width - 2 * categoryLabelPad - dimWidth) / (numDimensions - 1); @@ -1826,17 +1825,17 @@ function createDimensionViewModel(parcatsViewModel, dimensionModel) { dimX = dimX0 + dimDx * displayInd; // Compute categories - var categories = [], - maxCats = parcatsViewModel.model.maxCats, - numCats = dimensionModel.categories.length, - catSpacing = 8, - totalCount = dimensionModel.count, - totalHeight = parcatsViewModel.height - catSpacing * (maxCats - 1), - nextCatHeight, - nextCatModel, - nextCat, - catInd, - catDisplayInd; + var categories = []; + var maxCats = parcatsViewModel.model.maxCats; + var numCats = dimensionModel.categories.length; + var catSpacing = 8; + var totalCount = dimensionModel.count; + var totalHeight = parcatsViewModel.height - catSpacing * (maxCats - 1); + var nextCatHeight; + var nextCatModel; + var nextCat; + var catInd; + var catDisplayInd; // Compute starting Y offset var nextCatY = (maxCats - numCats) * catSpacing / 2.0; diff --git a/src/traces/parcats/plot.js b/src/traces/parcats/plot.js index 2b958b920c4..2991eda750b 100644 --- a/src/traces/parcats/plot.js +++ b/src/traces/parcats/plot.js @@ -18,9 +18,9 @@ var parcats = require('./parcats'); * @param {Array.} parcatsModels */ module.exports = function plot(graphDiv, parcatsModels, transitionOpts, makeOnCompleteCallback) { - var fullLayout = graphDiv._fullLayout, - svg = fullLayout._paper, - size = fullLayout._size; + var fullLayout = graphDiv._fullLayout; + var svg = fullLayout._paper; + var size = fullLayout._size; parcats( graphDiv, diff --git a/src/traces/parcoords/lines.js b/src/traces/parcoords/lines.js index 5861eaffa70..baf37cde0a9 100644 --- a/src/traces/parcoords/lines.js +++ b/src/traces/parcoords/lines.js @@ -450,7 +450,10 @@ module.exports = function(canvasGL, d) { var panelCount = panels.length; var I; - var leftmost, rightmost, lowestX = Infinity, highestX = -Infinity; + var leftmost; + var rightmost; + var lowestX = Infinity; + var highestX = -Infinity; for(I = 0; I < panelCount; I++) { if(panels[I].dim2.canvasX > highestX) { diff --git a/src/traces/parcoords/parcoords.js b/src/traces/parcoords/parcoords.js index 26d2da693aa..28acac87d18 100644 --- a/src/traces/parcoords/parcoords.js +++ b/src/traces/parcoords/parcoords.js @@ -130,17 +130,17 @@ function someFiltersActive(view) { } function model(layout, d, i) { - var cd0 = unwrap(d), - trace = cd0.trace, - lineColor = cd0.lineColor, - line = trace.line, - cscale = line.reversescale ? Colorscale.flipScale(cd0.cscale) : cd0.cscale, - domain = trace.domain, - dimensions = trace.dimensions, - width = layout.width, - labelFont = trace.labelfont, - tickFont = trace.tickfont, - rangeFont = trace.rangefont; + var cd0 = unwrap(d); + var trace = cd0.trace; + var lineColor = cd0.lineColor; + var line = trace.line; + var cscale = line.reversescale ? Colorscale.flipScale(cd0.cscale) : cd0.cscale; + var domain = trace.domain; + var dimensions = trace.dimensions; + var width = layout.width; + var labelFont = trace.labelfont; + var tickFont = trace.tickfont; + var rangeFont = trace.rangefont; var lines = Lib.extendDeepNoArrays({}, line, { color: lineColor.map(d3.scale.linear().domain(dimensionExtent({ diff --git a/src/traces/pie/defaults.js b/src/traces/pie/defaults.js index 2110884688c..ef47413f89d 100644 --- a/src/traces/pie/defaults.js +++ b/src/traces/pie/defaults.js @@ -54,10 +54,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout coerce('hovertemplate'); if(textInfo && textInfo !== 'none') { - var textPosition = coerce('textposition'), - hasBoth = Array.isArray(textPosition) || textPosition === 'auto', - hasInside = hasBoth || textPosition === 'inside', - hasOutside = hasBoth || textPosition === 'outside'; + var textPosition = coerce('textposition'); + var hasBoth = Array.isArray(textPosition) || textPosition === 'auto'; + var hasInside = hasBoth || textPosition === 'inside'; + var hasOutside = hasBoth || textPosition === 'outside'; if(hasInside || hasOutside) { var dfltFont = coerceFont(coerce, 'textfont', layout.font); diff --git a/src/traces/pie/plot.js b/src/traces/pie/plot.js index 5eff4d6fc07..2a63c5c959c 100644 --- a/src/traces/pie/plot.js +++ b/src/traces/pie/plot.js @@ -494,19 +494,19 @@ function transformInsideText(textBB, pt, cd0) { var textAspect = textBB.width / textBB.height; var halfAngle = Math.PI * Math.min(pt.v / cd0.vTotal, 0.5); var ring = 1 - cd0.trace.hole; - var rInscribed = getInscribedRadiusFraction(pt, cd0), - - // max size text can be inserted inside without rotating it - // this inscribes the text rectangle in a circle, which is then inscribed - // in the slice, so it will be an underestimate, which some day we may want - // to improve so this case can get more use - transform = { - scale: rInscribed * cd0.r * 2 / textDiameter, - - // and the center position and rotation in this case - rCenter: 1 - rInscribed, - rotate: 0 - }; + var rInscribed = getInscribedRadiusFraction(pt, cd0); + + // max size text can be inserted inside without rotating it + // this inscribes the text rectangle in a circle, which is then inscribed + // in the slice, so it will be an underestimate, which some day we may want + // to improve so this case can get more use + var transform = { + scale: rInscribed * cd0.r * 2 / textDiameter, + + // and the center position and rotation in this case + rCenter: 1 - rInscribed, + rotate: 0 + }; if(transform.scale >= 1) return transform; @@ -584,7 +584,10 @@ function positionTitleInside(cd0) { } function positionTitleOutside(cd0, plotSize) { - var scaleX = 1, scaleY = 1, maxWidth, maxPull; + var scaleX = 1; + var scaleY = 1; + var maxWidth, maxPull; + var trace = cd0.trace; // position of the baseline point of the text box in the plot, before scaling. // we anchored the text in the middle, so the baseline is on the bottom middle @@ -644,7 +647,8 @@ function getTitleSpace(cd0, plotSize) { } function getMaxPull(trace) { - var maxPull = trace.pull, j; + var maxPull = trace.pull; + var j; if(Array.isArray(maxPull)) { maxPull = 0; for(j = 0; j < trace.pull.length; j++) { diff --git a/src/traces/pointcloud/convert.js b/src/traces/pointcloud/convert.js index 9d7af610ab6..60205a13250 100644 --- a/src/traces/pointcloud/convert.js +++ b/src/traces/pointcloud/convert.js @@ -86,10 +86,10 @@ proto.updateFast = function(options) { var userBounds = options.xbounds && options.ybounds; var index = options.indices; - var len, - idToIndex, - positions, - bounds = this.bounds; + var len; + var idToIndex; + var positions; + var bounds = this.bounds; var xx, yy, i; @@ -167,9 +167,9 @@ proto.updateFast = function(options) { this.pointcloudOptions.positions = positions; - var markerColor = str2RGBArray(options.marker.color), - borderColor = str2RGBArray(options.marker.border.color), - opacity = options.opacity * options.marker.opacity; + var markerColor = str2RGBArray(options.marker.color); + var borderColor = str2RGBArray(options.marker.border.color); + var opacity = options.opacity * options.marker.opacity; markerColor[3] *= opacity; this.pointcloudOptions.color = markerColor; diff --git a/src/traces/sankey/defaults.js b/src/traces/sankey/defaults.js index 25a89c91dc2..d8c246ef83a 100644 --- a/src/traces/sankey/defaults.js +++ b/src/traces/sankey/defaults.js @@ -24,7 +24,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout var hoverlabelDefault = Lib.extendDeep(layout.hoverlabel, traceIn.hoverlabel); // node attributes - var nodeIn = traceIn.node, nodeOut = Template.newContainer(traceOut, 'node'); + var nodeIn = traceIn.node; + var nodeOut = Template.newContainer(traceOut, 'node'); + function coerceNode(attr, dflt) { return Lib.coerce(nodeIn, nodeOut, attributes.node, attr, dflt); } @@ -46,7 +48,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout })); // link attributes - var linkIn = traceIn.link, linkOut = Template.newContainer(traceOut, 'link'); + var linkIn = traceIn.link; + var linkOut = Template.newContainer(traceOut, 'link'); + function coerceLink(attr, dflt) { return Lib.coerce(linkIn, linkOut, attributes.link, attr, dflt); } diff --git a/src/traces/sankey/render.js b/src/traces/sankey/render.js index 2ec53241b9c..197273eed1e 100644 --- a/src/traces/sankey/render.js +++ b/src/traces/sankey/render.js @@ -26,7 +26,8 @@ var unwrap = gup.unwrap; // basic data utilities function persistOriginalPlace(nodes) { - var i, distinctLayerPositions = []; + var i; + var distinctLayerPositions = []; for(i = 0; i < nodes.length; i++) { nodes[i].originalX = nodes[i].x; nodes[i].originalY = nodes[i].y; @@ -152,7 +153,8 @@ function sankeyModel(layout, d, traceIndex) { Lib.warn('node.pad was reduced to ', sankey.nodePadding(), ' to fit within the figure.'); } - var node, sankeyNodes = sankey.nodes(); + var node; + var sankeyNodes = sankey.nodes(); for(var n = 0; n < sankeyNodes.length; n++) { node = sankeyNodes[n]; node.width = width; @@ -219,11 +221,11 @@ function linkModel(uniqueKeys, d, l) { } function nodeModel(uniqueKeys, d, n) { - var tc = tinycolor(n.color), - zoneThicknessPad = c.nodePadAcross, - zoneLengthPad = d.nodePad / 2, - visibleThickness = n.dx, - visibleLength = Math.max(0.5, n.dy); + var tc = tinycolor(n.color); + var zoneThicknessPad = c.nodePadAcross; + var zoneLengthPad = d.nodePad / 2; + var visibleThickness = n.dx; + var visibleLength = Math.max(0.5, n.dy); var basicKey = n.label; var foundKey = uniqueKeys[basicKey]; diff --git a/src/traces/scatter/fillcolor_defaults.js b/src/traces/scatter/fillcolor_defaults.js index baf2b6e37ea..6bbf65da885 100644 --- a/src/traces/scatter/fillcolor_defaults.js +++ b/src/traces/scatter/fillcolor_defaults.js @@ -17,8 +17,8 @@ module.exports = function fillColorDefaults(traceIn, traceOut, defaultColor, coe if(traceOut.marker) { // don't try to inherit a color array - var markerColor = traceOut.marker.color, - markerLineColor = (traceOut.marker.line || {}).color; + var markerColor = traceOut.marker.color; + var markerLineColor = (traceOut.marker.line || {}).color; if(markerColor && !isArrayOrTypedArray(markerColor)) { inheritColorFromMarker = markerColor; diff --git a/src/traces/scatter/get_trace_color.js b/src/traces/scatter/get_trace_color.js index fd074ed3a01..b3027c6b575 100644 --- a/src/traces/scatter/get_trace_color.js +++ b/src/traces/scatter/get_trace_color.js @@ -27,8 +27,8 @@ module.exports = function getTraceColor(trace, di) { return trace.fill ? trace.fillcolor : ''; } else { - var mc = di.mcc || (trace.marker || {}).color, - mlc = di.mlcc || ((trace.marker || {}).line || {}).color; + var mc = di.mcc || (trace.marker || {}).color; + var mlc = di.mlcc || ((trace.marker || {}).line || {}).color; tc = (mc && Color.opacity(mc)) ? mc : (mlc && Color.opacity(mlc) && diff --git a/src/traces/scatter/make_bubble_size_func.js b/src/traces/scatter/make_bubble_size_func.js index 4426dc92c7d..6aaa457a2ce 100644 --- a/src/traces/scatter/make_bubble_size_func.js +++ b/src/traces/scatter/make_bubble_size_func.js @@ -15,17 +15,17 @@ var isNumeric = require('fast-isnumeric'); // used in the drawing step for 'scatter' and 'scattegeo' and // in the convert step for 'scatter3d' module.exports = function makeBubbleSizeFn(trace) { - var marker = trace.marker, - sizeRef = marker.sizeref || 1, - sizeMin = marker.sizemin || 0; + var marker = trace.marker; + var sizeRef = marker.sizeref || 1; + var sizeMin = marker.sizemin || 0; // for bubble charts, allow scaling the provided value linearly // and by area or diameter. // Note this only applies to the array-value sizes var baseFn = (marker.sizemode === 'area') ? - function(v) { return Math.sqrt(v / sizeRef); } : - function(v) { return v / sizeRef; }; + function(v) { return Math.sqrt(v / sizeRef); } : + function(v) { return v / sizeRef; }; // TODO add support for position/negative bubbles? // TODO add 'sizeoffset' attribute? diff --git a/src/traces/scatter/marker_defaults.js b/src/traces/scatter/marker_defaults.js index 9af06648d25..904446f9b1a 100644 --- a/src/traces/scatter/marker_defaults.js +++ b/src/traces/scatter/marker_defaults.js @@ -21,9 +21,9 @@ var subTypes = require('./subtypes'); * noSelect: caller does not support selected/unselected attribute containers */ module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce, opts) { - var isBubble = subTypes.isBubble(traceIn), - lineColor = (traceIn.line || {}).color, - defaultMLC; + var isBubble = subTypes.isBubble(traceIn); + var lineColor = (traceIn.line || {}).color; + var defaultMLC; opts = opts || {}; diff --git a/src/traces/scatter/plot.js b/src/traces/scatter/plot.js index 291219ca30e..401038aec6b 100644 --- a/src/traces/scatter/plot.js +++ b/src/traces/scatter/plot.js @@ -127,8 +127,8 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition return hasTransition ? selection.transition() : selection; } - var xa = plotinfo.xaxis, - ya = plotinfo.yaxis; + var xa = plotinfo.xaxis; + var ya = plotinfo.yaxis; var trace = cdscatter[0].trace; var line = trace.line; @@ -164,21 +164,21 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition prevPolygons = prevtrace._polygons; } - var thispath, - thisrevpath, - // fullpath is all paths for this curve, joined together straight - // across gaps, for filling - fullpath = '', - // revpath is fullpath reversed, for fill-to-next - revpath = '', - // functions for converting a point array to a path - pathfn, revpathbase, revpathfn, - // variables used before and after the data join - pt0, lastSegment, pt1, thisPolygons; + var thispath; + var thisrevpath; + // fullpath is all paths for this curve, joined together straight + // across gaps, for filling + var fullpath = ''; + // revpath is fullpath reversed, for fill-to-next + var revpath = ''; + // functions for converting a point array to a path + var pathfn, revpathbase, revpathfn; + // variables used before and after the data join + var pt0, lastSegment, pt1, thisPolygons; // initialize line join data / method - var segments = [], - makeUpdate = Lib.noop; + var segments = []; + var makeUpdate = Lib.noop; ownFillEl3 = trace._ownFill; @@ -528,10 +528,10 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition } function selectMarkers(gd, idx, plotinfo, cdscatter, cdscatterAll) { - var xa = plotinfo.xaxis, - ya = plotinfo.yaxis, - xr = d3.extent(Lib.simpleMap(xa.range, xa.r2c)), - yr = d3.extent(Lib.simpleMap(ya.range, ya.r2c)); + var xa = plotinfo.xaxis; + var ya = plotinfo.yaxis; + var xr = d3.extent(Lib.simpleMap(xa.range, xa.r2c)); + var yr = d3.extent(Lib.simpleMap(ya.range, ya.r2c)); var trace = cdscatter[0].trace; if(!subTypes.hasMarkers(trace)) return; @@ -543,10 +543,10 @@ function selectMarkers(gd, idx, plotinfo, cdscatter, cdscatterAll) { if(mnum === 0) return; var cd = cdscatter.filter(function(v) { - 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; + return v.x >= xr[0] && v.x <= xr[1] && v.y >= yr[0] && v.y <= yr[1]; + }); + var inc = Math.ceil(cd.length / mnum); + var tnum = 0; cdscatterAll.forEach(function(cdj, j) { var tracei = cdj[0].trace; if(subTypes.hasMarkers(tracei) && diff --git a/src/traces/scatter/select.js b/src/traces/scatter/select.js index 79e1a689e41..9ecd3f3628f 100644 --- a/src/traces/scatter/select.js +++ b/src/traces/scatter/select.js @@ -12,15 +12,15 @@ var subtypes = require('./subtypes'); module.exports = function selectPoints(searchInfo, selectionTester) { - var cd = searchInfo.cd, - xa = searchInfo.xaxis, - ya = searchInfo.yaxis, - selection = [], - trace = cd[0].trace, - i, - di, - x, - y; + var cd = searchInfo.cd; + var xa = searchInfo.xaxis; + var ya = searchInfo.yaxis; + var selection = []; + var trace = cd[0].trace; + var i; + var di; + var x; + var y; var hasOnlyLines = (!subtypes.hasMarkers(trace) && !subtypes.hasText(trace)); if(hasOnlyLines) return []; diff --git a/src/traces/scatter3d/calc_errors.js b/src/traces/scatter3d/calc_errors.js index d9bc59e2667..68a3b477a43 100644 --- a/src/traces/scatter3d/calc_errors.js +++ b/src/traces/scatter3d/calc_errors.js @@ -21,8 +21,8 @@ function calculateAxisErrors(data, params, scaleFactor, axis) { if(axis.type === 'log') { var point = axis.c2l(data[i]); - var min = data[i] - errors[0], - max = data[i] + errors[1]; + var min = data[i] - errors[0]; + var max = data[i] + errors[1]; result[i] = [ (axis.c2l(min, true) - point) * scaleFactor, diff --git a/src/traces/scatter3d/convert.js b/src/traces/scatter3d/convert.js index 3a96c327c94..5dfe83fab45 100644 --- a/src/traces/scatter3d/convert.js +++ b/src/traces/scatter3d/convert.js @@ -114,9 +114,9 @@ function constructDelaunay(points, color, axis) { } function calculateErrorParams(errors) { - var capSize = [0.0, 0.0, 0.0], - color = [[0, 0, 0], [0, 0, 0], [0, 0, 0]], - lineWidth = [1.0, 1.0, 1.0]; + var capSize = [0.0, 0.0, 0.0]; + var color = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]; + var lineWidth = [1.0, 1.0, 1.0]; for(var i = 0; i < 3; i++) { var e = errors[i]; @@ -206,23 +206,24 @@ function formatParam(paramIn, len, calculate, dflt, extraFn) { function convertPlotlyOptions(scene, data) { - var params, i, - points = [], - sceneLayout = scene.fullSceneLayout, - scaleFactor = scene.dataScale, - xaxis = sceneLayout.xaxis, - yaxis = sceneLayout.yaxis, - zaxis = sceneLayout.zaxis, - marker = data.marker, - line = data.line, - xc, x = data.x || [], - yc, y = data.y || [], - zc, z = data.z || [], - len = x.length, - xcalendar = data.xcalendar, - ycalendar = data.ycalendar, - zcalendar = data.zcalendar, - text; + var points = []; + var sceneLayout = scene.fullSceneLayout; + var scaleFactor = scene.dataScale; + var xaxis = sceneLayout.xaxis; + var yaxis = sceneLayout.yaxis; + var zaxis = sceneLayout.zaxis; + var marker = data.marker; + var line = data.line; + var x = data.x || []; + var y = data.y || []; + var z = data.z || []; + var len = x.length; + var xcalendar = data.xcalendar; + var ycalendar = data.ycalendar; + var zcalendar = data.zcalendar; + var xc, yc, zc; + var params, i; + var text; // Convert points for(i = 0; i < len; i++) { @@ -313,12 +314,12 @@ function arrayToColor(color) { } proto.update = function(data) { - var gl = this.scene.glplot.gl, - lineOptions, - scatterOptions, - errorOptions, - textOptions, - dashPattern = DASH_PATTERNS.solid; + var gl = this.scene.glplot.gl; + var lineOptions; + var scatterOptions; + var errorOptions; + var textOptions; + var dashPattern = DASH_PATTERNS.solid; // Save data this.data = data; diff --git a/src/traces/scatter3d/defaults.js b/src/traces/scatter3d/defaults.js index fe1bea443da..d9fad9676a0 100644 --- a/src/traces/scatter3d/defaults.js +++ b/src/traces/scatter3d/defaults.js @@ -48,8 +48,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout handleTextDefaults(traceIn, traceOut, layout, coerce, {noSelect: true}); } - var lineColor = (traceOut.line || {}).color, - markerColor = (traceOut.marker || {}).color; + var lineColor = (traceOut.line || {}).color; + var markerColor = (traceOut.marker || {}).color; if(coerce('surfaceaxis') >= 0) coerce('surfacecolor', lineColor || markerColor); var dims = ['x', 'y', 'z']; @@ -68,10 +68,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout }; function handleXYZDefaults(traceIn, traceOut, coerce, layout) { - var len = 0, - x = coerce('x'), - y = coerce('y'), - z = coerce('z'); + var len = 0; + var x = coerce('x'); + var y = coerce('y'); + var z = coerce('z'); var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults'); handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout); diff --git a/src/traces/scattercarpet/attributes.js b/src/traces/scattercarpet/attributes.js index 60ca8852fee..5d1b2fa4f7e 100644 --- a/src/traces/scattercarpet/attributes.js +++ b/src/traces/scattercarpet/attributes.js @@ -15,9 +15,9 @@ var colorbarAttrs = require('../../components/colorbar/attributes'); var extendFlat = require('../../lib/extend').extendFlat; -var scatterMarkerAttrs = scatterAttrs.marker, - scatterLineAttrs = scatterAttrs.line, - scatterMarkerLineAttrs = scatterMarkerAttrs.line; +var scatterMarkerAttrs = scatterAttrs.marker; +var scatterLineAttrs = scatterAttrs.line; +var scatterMarkerLineAttrs = scatterMarkerAttrs.line; module.exports = { carpet: { diff --git a/src/traces/scattercarpet/hover.js b/src/traces/scattercarpet/hover.js index 68c14977237..a4175a00839 100644 --- a/src/traces/scattercarpet/hover.js +++ b/src/traces/scattercarpet/hover.js @@ -28,10 +28,10 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { // so easy and anyway we lost the information we would have needed to do // this inside scatterHover. if(newPointData.index === undefined) { - var yFracUp = 1 - (newPointData.y0 / pointData.ya._length), - xLen = pointData.xa._length, - xMin = xLen * yFracUp / 2, - xMax = xLen - xMin; + var yFracUp = 1 - (newPointData.y0 / pointData.ya._length); + var xLen = pointData.xa._length; + var xMin = xLen * yFracUp / 2; + var xMax = xLen - xMin; newPointData.x0 = Math.max(Math.min(newPointData.x0, xMax), xMin); newPointData.x1 = Math.max(Math.min(newPointData.x1, xMax), xMin); return scatterPointData; diff --git a/src/traces/scattergeo/attributes.js b/src/traces/scattergeo/attributes.js index 50960d04dce..ded607fe6e2 100644 --- a/src/traces/scattergeo/attributes.js +++ b/src/traces/scattergeo/attributes.js @@ -16,9 +16,9 @@ var dash = require('../../components/drawing/attributes').dash; var extendFlat = require('../../lib/extend').extendFlat; var overrideAll = require('../../plot_api/edit_types').overrideAll; -var scatterMarkerAttrs = scatterAttrs.marker, - scatterLineAttrs = scatterAttrs.line, - scatterMarkerLineAttrs = scatterMarkerAttrs.line; +var scatterMarkerAttrs = scatterAttrs.marker; +var scatterLineAttrs = scatterAttrs.line; +var scatterMarkerLineAttrs = scatterMarkerAttrs.line; module.exports = overrideAll({ lon: { diff --git a/src/traces/scattergeo/defaults.js b/src/traces/scattergeo/defaults.js index 4d8380d48af..00ebc5e5d82 100644 --- a/src/traces/scattergeo/defaults.js +++ b/src/traces/scattergeo/defaults.js @@ -57,8 +57,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout }; function handleLonLatLocDefaults(traceIn, traceOut, coerce) { - var len = 0, - locations = coerce('locations'); + var len = 0; + var locations = coerce('locations'); var lon, lat; diff --git a/src/traces/scattergl/index.js b/src/traces/scattergl/index.js index 3e5806fbcc7..a3ae9f9176f 100644 --- a/src/traces/scattergl/index.js +++ b/src/traces/scattergl/index.js @@ -504,7 +504,8 @@ function plot(gd, subplot, cdata) { pos = srcPos.slice(); for(i = Math.floor(nextPos.length / 2); i--;) { - var xx = nextPos[i * 2], yy = nextPos[i * 2 + 1]; + var xx = nextPos[i * 2]; + var yy = nextPos[i * 2 + 1]; if(isNaN(xx) || isNaN(yy)) continue; pos.push(xx, yy); } diff --git a/src/traces/scattermapbox/convert.js b/src/traces/scattermapbox/convert.js index 42f37e0cb9a..c592d43ec9e 100644 --- a/src/traces/scattermapbox/convert.js +++ b/src/traces/scattermapbox/convert.js @@ -109,8 +109,8 @@ module.exports = function convert(calcTrace) { } if(hasText) { - var iconSize = (trace.marker || {}).size, - textOpts = convertTextOpts(trace.textposition, iconSize); + var iconSize = (trace.marker || {}).size; + var textOpts = convertTextOpts(trace.textposition, iconSize); // all data-driven below !! @@ -234,17 +234,17 @@ function makeCircleOpts(calcTrace) { function makeSymbolGeoJSON(calcTrace) { var trace = calcTrace[0].trace; - var marker = trace.marker || {}, - symbol = marker.symbol, - text = trace.text; + var marker = trace.marker || {}; + var symbol = marker.symbol; + var text = trace.text; var fillSymbol = (symbol !== 'circle') ? - getFillFunc(symbol) : - blankFillFunc; + getFillFunc(symbol) : + blankFillFunc; var fillText = subTypes.hasText(trace) ? - getFillFunc(text) : - blankFillFunc; + getFillFunc(text) : + blankFillFunc; var features = []; diff --git a/src/traces/scatterternary/attributes.js b/src/traces/scatterternary/attributes.js index 1dee1c0d70d..01177fde2e2 100644 --- a/src/traces/scatterternary/attributes.js +++ b/src/traces/scatterternary/attributes.js @@ -16,9 +16,9 @@ var dash = require('../../components/drawing/attributes').dash; var extendFlat = require('../../lib/extend').extendFlat; -var scatterMarkerAttrs = scatterAttrs.marker, - scatterLineAttrs = scatterAttrs.line, - scatterMarkerLineAttrs = scatterMarkerAttrs.line; +var scatterMarkerAttrs = scatterAttrs.marker; +var scatterLineAttrs = scatterAttrs.line; +var scatterMarkerLineAttrs = scatterMarkerAttrs.line; module.exports = { a: { diff --git a/src/traces/scatterternary/defaults.js b/src/traces/scatterternary/defaults.js index a648bef144b..9de03b6e428 100644 --- a/src/traces/scatterternary/defaults.js +++ b/src/traces/scatterternary/defaults.js @@ -27,10 +27,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout return Lib.coerce(traceIn, traceOut, attributes, attr, dflt); } - var a = coerce('a'), - b = coerce('b'), - c = coerce('c'), - len; + var a = coerce('a'); + var b = coerce('b'); + var c = coerce('c'); + var len; // allow any one array to be missing, len is the minimum length of those // present. Note that after coerce data_array's are either Arrays (which diff --git a/src/traces/scatterternary/hover.js b/src/traces/scatterternary/hover.js index 808bc451ff8..5238d7b8911 100644 --- a/src/traces/scatterternary/hover.js +++ b/src/traces/scatterternary/hover.js @@ -30,10 +30,10 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { // so easy and anyway we lost the information we would have needed to do // this inside scatterHover. if(newPointData.index === undefined) { - var yFracUp = 1 - (newPointData.y0 / pointData.ya._length), - xLen = pointData.xa._length, - xMin = xLen * yFracUp / 2, - xMax = xLen - xMin; + var yFracUp = 1 - (newPointData.y0 / pointData.ya._length); + var xLen = pointData.xa._length; + var xMin = xLen * yFracUp / 2; + var xMax = xLen - xMin; newPointData.x0 = Math.max(Math.min(newPointData.x0, xMax), xMin); newPointData.x1 = Math.max(Math.min(newPointData.x1, xMax), xMin); return scatterPointData; diff --git a/src/traces/surface/convert.js b/src/traces/surface/convert.js index c7e5161afc3..3074ab7549b 100644 --- a/src/traces/surface/convert.js +++ b/src/traces/surface/convert.js @@ -117,8 +117,8 @@ proto.handlePick = function(selection) { }; function isColormapCircular(colormap) { - var first = colormap[0].rgb, - last = colormap[colormap.length - 1].rgb; + var first = colormap[0].rgb; + var last = colormap[colormap.length - 1].rgb; return ( first[0] === last[0] && @@ -360,15 +360,15 @@ proto.setContourLevels = function() { }; proto.update = function(data) { - var scene = this.scene, - sceneLayout = scene.fullSceneLayout, - surface = this.surface, - alpha = data.opacity, - colormap = parseColorScale(data.colorscale, alpha), - scaleFactor = scene.dataScale, - xlen = data.z[0].length, - ylen = data._ylength, - contourLevels = scene.contourLevels; + var scene = this.scene; + var sceneLayout = scene.fullSceneLayout; + var surface = this.surface; + var alpha = data.opacity; + var colormap = parseColorScale(data.colorscale, alpha); + var scaleFactor = scene.dataScale; + var xlen = data.z[0].length; + var ylen = data._ylength; + var contourLevels = scene.contourLevels; // Save data this.data = data; diff --git a/src/transforms/filter.js b/src/transforms/filter.js index 708bf5c7483..87a16701269 100644 --- a/src/transforms/filter.js +++ b/src/transforms/filter.js @@ -228,16 +228,16 @@ exports.calcTransform = function(gd, trace, opts) { }; function getFilterFunc(opts, d2c, targetCalendar) { - var operation = opts.operation, - value = opts.value, - hasArrayValue = Array.isArray(value); + var operation = opts.operation; + var value = opts.value; + var hasArrayValue = Array.isArray(value); function isOperationIn(array) { return array.indexOf(operation) !== -1; } - var d2cValue = function(v) { return d2c(v, 0, opts.valuecalendar); }, - d2cTarget = function(v) { return d2c(v, 0, targetCalendar); }; + var d2cValue = function(v) { return d2c(v, 0, opts.valuecalendar); }; + var d2cTarget = function(v) { return d2c(v, 0, targetCalendar); }; var coercedValue; diff --git a/src/transforms/groupby.js b/src/transforms/groupby.js index f10b26afd9d..611b98b3142 100644 --- a/src/transforms/groupby.js +++ b/src/transforms/groupby.js @@ -176,9 +176,9 @@ function transformOne(trace, state) { return [trace]; } - var groupNames = Lib.filterUnique(groups), - newData = new Array(groupNames.length), - len = groups.length; + var groupNames = Lib.filterUnique(groups); + var newData = new Array(groupNames.length); + var len = groups.length; var arrayAttrs = PlotSchema.findArrayAttributes(trace); diff --git a/tasks/stats.js b/tasks/stats.js index c746f1c9a60..9d676e0aadb 100644 --- a/tasks/stats.js +++ b/tasks/stats.js @@ -223,8 +223,8 @@ function makeBundleInfo(pathObj) { } function findSizes(pathObj) { - var codeDist = fs.readFileSync(pathObj.dist, ENC), - codeDistMin = fs.readFileSync(pathObj.distMin, ENC); + var codeDist = fs.readFileSync(pathObj.dist, ENC); + var codeDistMin = fs.readFileSync(pathObj.distMin, ENC); var sizes = { raw: prettySize(codeDist.length), diff --git a/tasks/util/common.js b/tasks/util/common.js index 4afa6b4f43a..c5947d312cb 100644 --- a/tasks/util/common.js +++ b/tasks/util/common.js @@ -54,8 +54,8 @@ exports.getTimeLastModified = function(filePath) { throw new Error(filePath + ' does not exist'); } - var stats = fs.statSync(filePath), - formattedTime = exports.formatTime(stats.mtime); + var stats = fs.statSync(filePath); + var formattedTime = exports.formatTime(stats.mtime); return formattedTime; }; diff --git a/tasks/util/pull_css.js b/tasks/util/pull_css.js index 145013b1994..6ac0fc4aa13 100644 --- a/tasks/util/pull_css.js +++ b/tasks/util/pull_css.js @@ -7,9 +7,9 @@ module.exports = function pullCSS(data, pathOut) { data.split(/\s*\}\s*/).forEach(function(chunk) { if(!chunk) return; - var parts = chunk.split(/\s*\{\s*/), - selectorList = parts[0], - rule = parts[1]; + var parts = chunk.split(/\s*\{\s*/); + var selectorList = parts[0]; + var rule = parts[1]; // take off ".js-plotly-plot .plotly", which should be on every selector selectorList.split(/,\s*/).forEach(function(selector) { diff --git a/tasks/util/pull_font_svg.js b/tasks/util/pull_font_svg.js index 5fe807d6de4..f0a38d0dded 100644 --- a/tasks/util/pull_font_svg.js +++ b/tasks/util/pull_font_svg.js @@ -8,20 +8,20 @@ module.exports = function pullFontSVG(data, pathOut) { parser.parseString(data, function(err, result) { if(err) throw err; - var font_obj = result.svg.defs[0].font[0], - default_width = Number(font_obj.$['horiz-adv-x']), - ascent = Number(font_obj['font-face'][0].$.ascent), - descent = Number(font_obj['font-face'][0].$.descent), - chars = {}; - - font_obj.glyph.forEach(function(glyph) { - var name = glyph.$['glyph-name'], - transform = name === 'spikeline' ? - 'matrix(1.5 0 0 -1.5 0 ' + ascent + ')' : - 'matrix(1 0 0 -1 0 ' + ascent + ')'; + var fontObj = result.svg.defs[0].font[0]; + var defaultWidth = Number(fontObj.$['horiz-adv-x']); + var ascent = Number(fontObj['font-face'][0].$.ascent); + var descent = Number(fontObj['font-face'][0].$.descent); + var chars = {}; + + fontObj.glyph.forEach(function(glyph) { + var name = glyph.$['glyph-name']; + var transform = name === 'spikeline' ? + 'matrix(1.5 0 0 -1.5 0 ' + ascent + ')' : + 'matrix(1 0 0 -1 0 ' + ascent + ')'; chars[name] = { - width: Number(glyph.$['horiz-adv-x']) || default_width, + width: Number(glyph.$['horiz-adv-x']) || defaultWidth, height: ascent - descent, path: glyph.$.d, transform: transform, diff --git a/tasks/util/wrap_locale.js b/tasks/util/wrap_locale.js index cfd86612fc7..ddad20ba313 100644 --- a/tasks/util/wrap_locale.js +++ b/tasks/util/wrap_locale.js @@ -18,7 +18,7 @@ var moduleMarker = 'module.exports = '; * * Logs basename of bundle when completed. */ -module.exports = function wrap_locale(pathToInput, pathToOutput) { +module.exports = function wrapLocale(pathToInput, pathToOutput) { fs.readFile(pathToInput, 'utf8', function(err, data) { var moduleStart = data.indexOf(moduleMarker) + moduleMarker.length; var moduleEnd = data.indexOf(';', moduleStart); diff --git a/test/image/compare_pixels_test.js b/test/image/compare_pixels_test.js index 5e1c8edbef1..5f23450e4f1 100644 --- a/test/image/compare_pixels_test.js +++ b/test/image/compare_pixels_test.js @@ -186,9 +186,9 @@ function runInQueue(mockList) { } function comparePixels(mockName, cb) { - var requestOpts = getRequestOpts({ mockName: mockName }), - imagePaths = getImagePaths(mockName), - saveImageStream = fs.createWriteStream(imagePaths.test); + var requestOpts = getRequestOpts({ mockName: mockName }); + var imagePaths = getImagePaths(mockName); + var saveImageStream = fs.createWriteStream(imagePaths.test); function log(msg) { process.stdout.write('Error for', mockName + ':', msg); diff --git a/test/image/export_test.js b/test/image/export_test.js index 69ac40d3a01..24802498d2e 100644 --- a/test/image/export_test.js +++ b/test/image/export_test.js @@ -111,9 +111,9 @@ function testExport(mockName, format, cb) { height: HEIGHT }; - var requestOpts = getRequestOpts(specs), - imagePaths = getImagePaths(mockName, format), - saveImageStream = fs.createWriteStream(imagePaths.test); + var requestOpts = getRequestOpts(specs); + var imagePaths = getImagePaths(mockName, format); + var saveImageStream = fs.createWriteStream(imagePaths.test); function checkExport(err) { if(err) throw err; diff --git a/test/image/make_baseline.js b/test/image/make_baseline.js index fea40dfc082..a8ce5971ef1 100644 --- a/test/image/make_baseline.js +++ b/test/image/make_baseline.js @@ -64,9 +64,9 @@ function runInQueue(mockList) { } function makeBaseline(mockName, cb) { - var requestOpts = getRequestOpts({ mockName: mockName }), - imagePaths = getImagePaths(mockName), - saveImageStream = fs.createWriteStream(imagePaths.baseline); + var requestOpts = getRequestOpts({ mockName: mockName }); + var imagePaths = getImagePaths(mockName); + var saveImageStream = fs.createWriteStream(imagePaths.baseline); function checkFormat(err, res) { if(err) throw err; diff --git a/test/jasmine/assets/check_event_data.js b/test/jasmine/assets/check_event_data.js index 9df72fd7b1f..8280491f53e 100644 --- a/test/jasmine/assets/check_event_data.js +++ b/test/jasmine/assets/check_event_data.js @@ -8,8 +8,8 @@ var hover = require('../assets/hover'); 'use strict'; module.exports = function checkEventData(mock, x, y, additionalFields) { - var mockCopy = Lib.extendDeep({}, mock), - gd; + var mockCopy = Lib.extendDeep({}, mock); + var gd; beforeEach(function(done) { gd = createGraphDiv(); diff --git a/test/jasmine/assets/drag.js b/test/jasmine/assets/drag.js index 1658ca9a288..64721d36151 100644 --- a/test/jasmine/assets/drag.js +++ b/test/jasmine/assets/drag.js @@ -37,8 +37,8 @@ function drag(node, dx, dy, edge, x0, y0, nsteps, noCover) { function waitForDragCover() { return new Promise(function(resolve) { - var interval = 5, - timeout = 5000; + var interval = 5; + var timeout = 5000; var id = setInterval(function() { var dragCoverNode = document.querySelector('.dragcover'); @@ -58,8 +58,8 @@ function waitForDragCover() { function waitForDragCoverRemoval() { return new Promise(function(resolve) { - var interval = 5, - timeout = 5000; + var interval = 5; + var timeout = 5000; var id = setInterval(function() { var dragCoverNode = document.querySelector('.dragcover'); diff --git a/test/jasmine/assets/get_client_position.js b/test/jasmine/assets/get_client_position.js index 71da9f50b00..f9a45cf36a3 100644 --- a/test/jasmine/assets/get_client_position.js +++ b/test/jasmine/assets/get_client_position.js @@ -1,10 +1,10 @@ module.exports = function getClientPosition(selector, index) { index = index || 0; - var selection = document.querySelectorAll(selector), - clientPos = selection[index].getBoundingClientRect(), - x = Math.floor((clientPos.left + clientPos.right) / 2), - y = Math.floor((clientPos.top + clientPos.bottom) / 2); + var selection = document.querySelectorAll(selector); + var clientPos = selection[index].getBoundingClientRect(); + var x = Math.floor((clientPos.left + clientPos.right) / 2); + var y = Math.floor((clientPos.top + clientPos.bottom) / 2); return [x, y]; }; diff --git a/test/jasmine/assets/get_node_coords.js b/test/jasmine/assets/get_node_coords.js index c2242cc755c..9bc9f86604d 100644 --- a/test/jasmine/assets/get_node_coords.js +++ b/test/jasmine/assets/get_node_coords.js @@ -5,8 +5,8 @@ */ module.exports = function(node, edge) { edge = edge || ''; - var bbox = node.getBoundingClientRect(), - x, y; + var bbox = node.getBoundingClientRect(); + var x, y; if(edge.indexOf('n') !== -1) y = bbox.top; else if(edge.indexOf('s') !== -1) y = bbox.bottom; diff --git a/test/jasmine/assets/mouse_event.js b/test/jasmine/assets/mouse_event.js index 647063fe3cd..781b68e6cae 100644 --- a/test/jasmine/assets/mouse_event.js +++ b/test/jasmine/assets/mouse_event.js @@ -33,8 +33,8 @@ module.exports = function(type, x, y, opts) { fullOpts.shiftKey = opts.shiftKey; } - var el = (opts && opts.element) || document.elementFromPoint(x, y), - ev; + var el = (opts && opts.element) || document.elementFromPoint(x, y); + var ev; if(type === 'scroll' || type === 'mousewheel') { // somehow table needs this to be mouswheel but others need wheel. diff --git a/test/jasmine/assets/touch_event.js b/test/jasmine/assets/touch_event.js index 52fdf444847..3513bf6617b 100644 --- a/test/jasmine/assets/touch_event.js +++ b/test/jasmine/assets/touch_event.js @@ -1,8 +1,8 @@ var Lib = require('../../../src/lib'); module.exports = function(type, x, y, opts) { - var el = (opts && opts.element) || document.elementFromPoint(x, y), - ev; + var el = (opts && opts.element) || document.elementFromPoint(x, y); + var ev; var touchObj = new Touch({ identifier: Date.now(), diff --git a/test/jasmine/bundle_tests/plotschema_test.js b/test/jasmine/bundle_tests/plotschema_test.js index 2e85825bb65..40b99b1a86a 100644 --- a/test/jasmine/bundle_tests/plotschema_test.js +++ b/test/jasmine/bundle_tests/plotschema_test.js @@ -18,11 +18,11 @@ var updatemenuAttrs = require('@src/components/updatemenus').layoutAttributes; describe('plot schema', function() { 'use strict'; - var plotSchema = Plotly.PlotSchema.get(), - valObjects = plotSchema.defs.valObjects; + var plotSchema = Plotly.PlotSchema.get(); + var valObjects = plotSchema.defs.valObjects; - var isValObject = Plotly.PlotSchema.isValObject, - isPlainObject = Lib.isPlainObject; + var isValObject = Plotly.PlotSchema.isValObject; + var isPlainObject = Lib.isPlainObject; var VALTYPES = Object.keys(valObjects); var ROLES = ['info', 'style', 'data']; @@ -112,14 +112,14 @@ describe('plot schema', function() { assertPlotSchema( function(attr) { if(isValObject(attr)) { - var valObject = valObjects[attr.valType], - opts = valObject.requiredOpts - .concat(valObject.otherOpts) - .concat([ - 'valType', 'description', 'role', - 'editType', 'impliedEdits', - '_compareAsJSON', '_noTemplating' - ]); + var valObject = valObjects[attr.valType]; + var opts = valObject.requiredOpts + .concat(valObject.otherOpts) + .concat([ + 'valType', 'description', 'role', + 'editType', 'impliedEdits', + '_compareAsJSON', '_noTemplating' + ]); Object.keys(attr).forEach(function(key) { expect(opts.indexOf(key) !== -1).toBe(true, key, attr); @@ -177,11 +177,11 @@ describe('plot schema', function() { plotSchema.layout.layoutAttributes, astr ); - var name = np.parts[np.parts.length - 1], - itemName = name.substr(0, name.length - 1); + var name = np.parts[np.parts.length - 1]; + var itemName = name.substr(0, name.length - 1); - var itemsObj = np.get().items, - itemObj = itemsObj[itemName]; + var itemsObj = np.get().items; + var itemObj = itemsObj[itemName]; // N.B. the specs below must be satisfied for plotly.py expect(isPlainObject(itemsObj)).toBe(true); @@ -284,8 +284,8 @@ describe('plot schema', function() { }); it('should work with registered transforms', function() { - var valObjects = plotSchema.transforms.filter.attributes, - attrNames = Object.keys(valObjects); + var valObjects = plotSchema.transforms.filter.attributes; + var attrNames = Object.keys(valObjects); ['operation', 'value', 'target'].forEach(function(k) { expect(attrNames).toContain(k); diff --git a/test/jasmine/tests/animate_test.js b/test/jasmine/tests/animate_test.js index 7762963f3e2..621378aa67b 100644 --- a/test/jasmine/tests/animate_test.js +++ b/test/jasmine/tests/animate_test.js @@ -313,7 +313,8 @@ describe('Test animate API', function() { it('emits plotly_animated as each animation in a sequence completes', function(done) { var completed = 0; - var test1 = 0, test2 = 0; + var test1 = 0; + var test2 = 0; gd.on('plotly_animated', function() { completed++; if(completed === 1) { diff --git a/test/jasmine/tests/annotations_test.js b/test/jasmine/tests/annotations_test.js index 7ac6b6d0cbe..65b46325dd1 100644 --- a/test/jasmine/tests/annotations_test.js +++ b/test/jasmine/tests/annotations_test.js @@ -180,8 +180,8 @@ describe('annotations relayout', function() { beforeEach(function(done) { gd = createGraphDiv(); - var mockData = Lib.extendDeep([], mock.data), - mockLayout = Lib.extendDeep({}, mock.layout); + var mockData = Lib.extendDeep([], mock.data); + var mockLayout = Lib.extendDeep({}, mock.layout); // insert some MathJax text - to make sure we fall back correctly // when MathJax is not provided (as is the case in our normal @@ -210,8 +210,8 @@ describe('annotations relayout', function() { } function assertText(index, expected) { - var query = '.annotation[data-index="' + index + '"]', - actual = d3.select(query).select('text').text(); + var query = '.annotation[data-index="' + index + '"]'; + var actual = d3.select(query).select('text').text(); expect(actual).toEqual(expected); } @@ -361,10 +361,10 @@ describe('annotations relayout', function() { it('can update several annotations and add and delete in one call', function(done) { expect(countAnnotations()).toEqual(len); - var annos = gd.layout.annotations, - anno0 = Lib.extendFlat(annos[0]), - anno1 = Lib.extendFlat(annos[1]), - anno3 = Lib.extendFlat(annos[3]); + var annos = gd.layout.annotations; + var anno0 = Lib.extendFlat(annos[0]); + var anno1 = Lib.extendFlat(annos[1]); + var anno3 = Lib.extendFlat(annos[3]); // store some (unused) private keys and make sure they are copied over // correctly during relayout @@ -386,8 +386,8 @@ describe('annotations relayout', function() { .then(function() { expect(countAnnotations()).toEqual(len); - var fullAnnosAfter = gd._fullLayout.annotations, - fullStr = JSON.stringify(fullAnnosAfter); + var fullAnnosAfter = gd._fullLayout.annotations; + var fullStr = JSON.stringify(fullAnnosAfter); assertText(0, 'tortilla'); anno0.text = 'tortilla'; @@ -506,8 +506,8 @@ describe('annotations log/linear axis changes', function() { beforeEach(function(done) { gd = createGraphDiv(); - var mockData = Lib.extendDeep([], mock.data), - mockLayout = Lib.extendDeep({}, mock.layout); + var mockData = Lib.extendDeep([], mock.data); + var mockLayout = Lib.extendDeep({}, mock.layout); Plotly.plot(gd, mockData, mockLayout).then(done); }); @@ -1113,11 +1113,11 @@ describe('annotation effects', function() { // for annotations with arrows: check that dragging the text moves only // ax and ay (and the textbox itself) function checkTextDrag() { - var ann = gd.layout.annotations[0], - x0 = ann.x, - y0 = ann.y, - ax0 = ann.ax, - ay0 = ann.ay; + var ann = gd.layout.annotations[0]; + var x0 = ann.x; + var y0 = ann.y; + var ax0 = ann.ax; + var ay0 = ann.ay; var bboxInitial = textBox().getBoundingClientRect(); diff --git a/test/jasmine/tests/axes_test.js b/test/jasmine/tests/axes_test.js index 81c5c16a42d..ce1fb445b93 100644 --- a/test/jasmine/tests/axes_test.js +++ b/test/jasmine/tests/axes_test.js @@ -51,13 +51,13 @@ describe('Test axes', function() { } } }; - var expectedYaxis = Lib.extendDeep({}, gd.layout.xaxis), - expectedXaxis = { - title: { - text: 'Click to enter X axis title' - }, - type: 'date' - }; + var expectedYaxis = Lib.extendDeep({}, gd.layout.xaxis); + var expectedXaxis = { + title: { + text: 'Click to enter X axis title' + }, + type: 'date' + }; supplyDefaults(gd); @@ -138,37 +138,37 @@ describe('Test axes', function() { } }; var expectedXaxis = { - type: 'category', - ticks: 'inside', - ticklen: 10, - tickcolor: '#f00', - tickwidth: 2, - showline: true, - side: 'top', - domain: [0, 0.45] - }, - expectedXaxis2 = { - type: 'category', - ticks: 'inside', - ticklen: 10, - tickcolor: '#f00', - tickwidth: 3, - showline: true, - side: 'top', - domain: [0.55, 1] - }, - expectedYaxis = { - type: 'linear', - ticks: 'outside', - ticklen: 5, - tickwidth: 4, - side: 'right' - }, - expectedAnnotations = [ - {x: 3, y: 2}, - {x: 4, y: 3, xref: 'x2', yref: 'y'}, - {x: 5, y: 0.5, xref: 'x', yref: 'paper'} - ]; + type: 'category', + ticks: 'inside', + ticklen: 10, + tickcolor: '#f00', + tickwidth: 2, + showline: true, + side: 'top', + domain: [0, 0.45] + }; + var expectedXaxis2 = { + type: 'category', + ticks: 'inside', + ticklen: 10, + tickcolor: '#f00', + tickwidth: 3, + showline: true, + side: 'top', + domain: [0.55, 1] + }; + var expectedYaxis = { + type: 'linear', + ticks: 'outside', + ticklen: 5, + tickwidth: 4, + side: 'right' + }; + var expectedAnnotations = [ + {x: 3, y: 2}, + {x: 4, y: 3, xref: 'x2', yref: 'y'}, + {x: 5, y: 0.5, xref: 'x', yref: 'paper'} + ]; supplyDefaults(gd); @@ -471,8 +471,8 @@ describe('Test axes', function() { layoutOut._subplots.cartesian.push('xy2'); layoutOut._subplots.yaxis.push('y2'); - var bgColor = Color.combine('yellow', 'green'), - frac = 100 * (0xe - 0x4) / (0xf - 0x4); + var bgColor = Color.combine('yellow', 'green'); + var frac = 100 * (0xe - 0x4) / (0xf - 0x4); supplyLayoutDefaults(layoutIn, layoutOut, fullData); expect(layoutOut.xaxis.gridcolor) @@ -1147,8 +1147,8 @@ describe('Test axes', function() { }); describe('handleTickDefaults', function() { - var data = [{ x: [1, 2, 3], y: [3, 4, 5] }], - gd; + var data = [{ x: [1, 2, 3], y: [3, 4, 5] }]; + var gd; beforeEach(function() { gd = createGraphDiv(); @@ -1229,8 +1229,8 @@ describe('Test axes', function() { } it('should set default tickmode correctly', function() { - var axIn = {}, - axOut = {}; + var axIn = {}; + var axOut = {}; mockSupplyDefaults(axIn, axOut, 'linear'); expect(axOut.tickmode).toBe('auto'); // and not push it back to axIn (which we used to do) @@ -1262,8 +1262,8 @@ describe('Test axes', function() { }); it('should set nticks iff tickmode=auto', function() { - var axIn = {}, - axOut = {}; + var axIn = {}; + var axOut = {}; mockSupplyDefaults(axIn, axOut, 'linear'); expect(axOut.nticks).toBe(0); @@ -1279,8 +1279,8 @@ describe('Test axes', function() { }); it('should set tick0 and dtick iff tickmode=linear', function() { - var axIn = {tickmode: 'auto', tick0: 1, dtick: 1}, - axOut = {}; + var axIn = {tickmode: 'auto', tick0: 1, dtick: 1}; + var axOut = {}; mockSupplyDefaults(axIn, axOut, 'linear'); expect(axOut.tick0).toBe(undefined); expect(axOut.dtick).toBe(undefined); @@ -1305,11 +1305,11 @@ describe('Test axes', function() { }); it('should handle tick0 and dtick for date axes', function() { - var someMs = 123456789, - someMsDate = Lib.ms2DateTimeLocal(someMs), - oneDay = 24 * 3600 * 1000, - axIn = {tick0: someMs, dtick: String(3 * oneDay)}, - axOut = {}; + var someMs = 123456789; + var someMsDate = Lib.ms2DateTimeLocal(someMs); + var oneDay = 24 * 3600 * 1000; + var axIn = {tick0: someMs, dtick: String(3 * oneDay)}; + var axOut = {}; mockSupplyDefaults(axIn, axOut, 'date'); expect(axOut.tick0).toBe(someMsDate); expect(axOut.dtick).toBe(3 * oneDay); @@ -1351,8 +1351,8 @@ describe('Test axes', function() { }); it('should handle tick0 and dtick for log axes', function() { - var axIn = {tick0: '0.2', dtick: 0.3}, - axOut = {}; + var axIn = {tick0: '0.2', dtick: 0.3}; + var axOut = {}; mockSupplyDefaults(axIn, axOut, 'log'); expect(axOut.tick0).toBe(0.2); expect(axOut.dtick).toBe(0.3); @@ -1397,8 +1397,8 @@ 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']}, - axOut = {}; + var axIn = {tickmode: 'auto', tickvals: [1, 2, 3], ticktext: ['4', '5', '6']}; + var axOut = {}; mockSupplyDefaults(axIn, axOut, 'linear'); expect(axOut.tickvals).toBe(undefined); expect(axOut.ticktext).toBe(undefined); @@ -2951,22 +2951,22 @@ describe('Test axes', function() { describe('automargin', function() { var data = [{ - x: [ - 'short label 1', 'loooooong label 1', - 'short label 2', 'loooooong label 2', - 'short label 3', 'loooooong label 3', - 'short label 4', 'loooooongloooooongloooooong label 4', - 'short label 5', 'loooooong label 5' - ], - y: [ - 'short label 1', 'loooooong label 1', - 'short label 2', 'loooooong label 2', - 'short label 3', 'loooooong label 3', - 'short label 4', 'loooooong label 4', - 'short label 5', 'loooooong label 5' - ] - }], - gd, initialSize, previousSize, savedBottom; + x: [ + 'short label 1', 'loooooong label 1', + 'short label 2', 'loooooong label 2', + 'short label 3', 'loooooong label 3', + 'short label 4', 'loooooongloooooongloooooong label 4', + 'short label 5', 'loooooong label 5' + ], + y: [ + 'short label 1', 'loooooong label 1', + 'short label 2', 'loooooong label 2', + 'short label 3', 'loooooong label 3', + 'short label 4', 'loooooong label 4', + 'short label 5', 'loooooong label 5' + ] + }]; + var gd, initialSize, previousSize, savedBottom; beforeEach(function() { gd = createGraphDiv(); diff --git a/test/jasmine/tests/bar_test.js b/test/jasmine/tests/bar_test.js index f2b4911222a..e79ea3627a5 100644 --- a/test/jasmine/tests/bar_test.js +++ b/test/jasmine/tests/bar_test.js @@ -731,8 +731,8 @@ describe('Bar.crossTraceCalc (formerly known as setPositions)', function() { expect(gd._fullLayout.barnorm).toBeUndefined(); - var xa = gd._fullLayout.xaxis, - ya = gd._fullLayout.yaxis; + var xa = gd._fullLayout.xaxis; + var ya = gd._fullLayout.yaxis; expect(Axes.getAutoRange(gd, xa)).toBeCloseToArray([-5, 14], undefined, '(xa.range)'); expect(Axes.getAutoRange(gd, ya)).toBeCloseToArray([-3.33, 3.33], undefined, '(ya.range)'); }); @@ -758,8 +758,8 @@ describe('Bar.crossTraceCalc (formerly known as setPositions)', function() { expect(gd._fullLayout.barnorm).toBeUndefined(); - var xa = gd._fullLayout.xaxis, - ya = gd._fullLayout.yaxis; + var xa = gd._fullLayout.xaxis; + var ya = gd._fullLayout.yaxis; expect(Axes.getAutoRange(gd, xa)).toBeCloseToArray([-0.5, 2.5], undefined, '(xa.range)'); expect(Axes.getAutoRange(gd, ya)).toBeCloseToArray([-11.11, 11.11], undefined, '(ya.range)'); }); @@ -781,8 +781,8 @@ describe('Bar.crossTraceCalc (formerly known as setPositions)', function() { expect(gd._fullLayout.barnorm).toBe(''); - var xa = gd._fullLayout.xaxis, - ya = gd._fullLayout.yaxis; + var xa = gd._fullLayout.xaxis; + var ya = gd._fullLayout.yaxis; expect(Axes.getAutoRange(gd, xa)).toBeCloseToArray([-0.5, 2.5], undefined, '(xa.range)'); expect(Axes.getAutoRange(gd, ya)).toBeCloseToArray([-4.44, 4.44], undefined, '(ya.range)'); }); @@ -804,8 +804,8 @@ describe('Bar.crossTraceCalc (formerly known as setPositions)', function() { expect(gd._fullLayout.barnorm).toBe('fraction'); - var xa = gd._fullLayout.xaxis, - ya = gd._fullLayout.yaxis; + var xa = gd._fullLayout.xaxis; + var ya = gd._fullLayout.yaxis; expect(Axes.getAutoRange(gd, xa)).toBeCloseToArray([-0.5, 2.5], undefined, '(xa.range)'); expect(Axes.getAutoRange(gd, ya)).toBeCloseToArray([-1.11, 1.11], undefined, '(ya.range)'); }); @@ -921,8 +921,8 @@ describe('A bar plot', function() { } function assertTextIsInsidePath(textNode, pathNode) { - var textBB = textNode.getBoundingClientRect(), - pathBB = pathNode.getBoundingClientRect(); + var textBB = textNode.getBoundingClientRect(); + var pathBB = pathNode.getBoundingClientRect(); expect(pathBB.left).not.toBeGreaterThan(textBB.left); expect(textBB.right).not.toBeGreaterThan(pathBB.right); @@ -931,22 +931,22 @@ describe('A bar plot', function() { } function assertTextIsAbovePath(textNode, pathNode) { - var textBB = textNode.getBoundingClientRect(), - pathBB = pathNode.getBoundingClientRect(); + var textBB = textNode.getBoundingClientRect(); + var pathBB = pathNode.getBoundingClientRect(); expect(textBB.bottom).not.toBeGreaterThan(pathBB.top); } function assertTextIsBelowPath(textNode, pathNode) { - var textBB = textNode.getBoundingClientRect(), - pathBB = pathNode.getBoundingClientRect(); + var textBB = textNode.getBoundingClientRect(); + var pathBB = pathNode.getBoundingClientRect(); expect(pathBB.bottom).not.toBeGreaterThan(textBB.top); } function assertTextIsAfterPath(textNode, pathNode) { - var textBB = textNode.getBoundingClientRect(), - pathBB = pathNode.getBoundingClientRect(); + var textBB = textNode.getBoundingClientRect(); + var pathBB = pathNode.getBoundingClientRect(); expect(pathBB.right).not.toBeGreaterThan(textBB.left); } @@ -961,8 +961,8 @@ describe('A bar plot', function() { } function assertTextIsBeforePath(textNode, pathNode) { - var textBB = textNode.getBoundingClientRect(), - pathBB = pathNode.getBoundingClientRect(); + var textBB = textNode.getBoundingClientRect(); + var pathBB = pathNode.getBoundingClientRect(); expect(textBB.right).not.toBeGreaterThan(pathBB.left); } @@ -1014,14 +1014,14 @@ describe('A bar plot', function() { var layout = {}; Plotly.plot(gd, data, layout).then(function() { - var traceNodes = getAllTraceNodes(gd), - barNodes = getAllBarNodes(traceNodes[0]), - foundTextNodes; + var traceNodes = getAllTraceNodes(gd); + var barNodes = getAllBarNodes(traceNodes[0]); + var foundTextNodes; for(var i = 0; i < barNodes.length; i++) { - var barNode = barNodes[i], - pathNode = barNode.querySelector('path'), - textNode = barNode.querySelector('text'); + var barNode = barNodes[i]; + var pathNode = barNode.querySelector('path'); + var textNode = barNode.querySelector('text'); if(textNode) { foundTextNodes = true; assertTextIsInsidePath(textNode, pathNode); @@ -1050,14 +1050,14 @@ describe('A bar plot', function() { var layout = {barmode: 'relative'}; Plotly.plot(gd, data, layout).then(function() { - var traceNodes = getAllTraceNodes(gd), - barNodes = getAllBarNodes(traceNodes[0]), - foundTextNodes; + var traceNodes = getAllTraceNodes(gd); + var barNodes = getAllBarNodes(traceNodes[0]); + var foundTextNodes; for(var i = 0; i < barNodes.length; i++) { - var barNode = barNodes[i], - pathNode = barNode.querySelector('path'), - textNode = barNode.querySelector('text'); + var barNode = barNodes[i]; + var pathNode = barNode.querySelector('path'); + var textNode = barNode.querySelector('text'); if(textNode) { foundTextNodes = true; assertTextIsInsidePath(textNode, pathNode); @@ -1087,14 +1087,14 @@ describe('A bar plot', function() { var layout = {barmode: 'relative'}; Plotly.plot(gd, data, layout).then(function() { - var traceNodes = getAllTraceNodes(gd), - barNodes = getAllBarNodes(traceNodes[0]), - foundTextNodes; + var traceNodes = getAllTraceNodes(gd); + var barNodes = getAllBarNodes(traceNodes[0]); + var foundTextNodes; for(var i = 0; i < barNodes.length; i++) { - var barNode = barNodes[i], - pathNode = barNode.querySelector('path'), - textNode = barNode.querySelector('text'); + var barNode = barNodes[i]; + var pathNode = barNode.querySelector('path'); + var textNode = barNode.querySelector('text'); if(textNode) { foundTextNodes = true; assertTextIsAbovePath(textNode, pathNode); @@ -1119,14 +1119,14 @@ describe('A bar plot', function() { }; Plotly.plot(gd, data, layout).then(function() { - var traceNodes = getAllTraceNodes(gd), - barNodes = getAllBarNodes(traceNodes[0]), - foundTextNodes; + var traceNodes = getAllTraceNodes(gd); + var barNodes = getAllBarNodes(traceNodes[0]); + var foundTextNodes; for(var i = 0; i < barNodes.length; i++) { - var barNode = barNodes[i], - pathNode = barNode.querySelector('path'), - textNode = barNode.querySelector('text'); + var barNode = barNodes[i]; + var pathNode = barNode.querySelector('path'); + var textNode = barNode.querySelector('text'); if(textNode) { foundTextNodes = true; if(data[0].y[i] > 0) assertTextIsAbovePath(textNode, pathNode); @@ -1150,14 +1150,14 @@ describe('A bar plot', function() { var layout = {}; Plotly.plot(gd, data, layout).then(function() { - var traceNodes = getAllTraceNodes(gd), - barNodes = getAllBarNodes(traceNodes[0]), - foundTextNodes; + var traceNodes = getAllTraceNodes(gd); + var barNodes = getAllBarNodes(traceNodes[0]); + var foundTextNodes; for(var i = 0; i < barNodes.length; i++) { - var barNode = barNodes[i], - pathNode = barNode.querySelector('path'), - textNode = barNode.querySelector('text'); + var barNode = barNodes[i]; + var pathNode = barNode.querySelector('path'); + var textNode = barNode.querySelector('text'); if(textNode) { foundTextNodes = true; if(data[0].x[i] > 0) assertTextIsAfterPath(textNode, pathNode); @@ -1184,14 +1184,14 @@ describe('A bar plot', function() { }; Plotly.plot(gd, data, layout).then(function() { - var traceNodes = getAllTraceNodes(gd), - barNodes = getAllBarNodes(traceNodes[0]), - foundTextNodes; + var traceNodes = getAllTraceNodes(gd); + var barNodes = getAllBarNodes(traceNodes[0]); + var foundTextNodes; for(var i = 0; i < barNodes.length; i++) { - var barNode = barNodes[i], - pathNode = barNode.querySelector('path'), - textNode = barNode.querySelector('text'); + var barNode = barNodes[i]; + var pathNode = barNode.querySelector('path'); + var textNode = barNode.querySelector('text'); if(textNode) { foundTextNodes = true; if(data[0].x[i] > 0) assertTextIsAfterPath(textNode, pathNode); @@ -1483,19 +1483,19 @@ describe('A bar plot', function() { expect(cd[3][0].t.poffset).toBe(0); assertTraceField(cd, 't.bargroupwidth', [0.8, 0.8, 0.8, 0.8]); - var traceNodes = getAllTraceNodes(gd), - trace0Bar3 = getAllBarNodes(traceNodes[0])[3], - path03 = trace0Bar3.querySelector('path'), - text03 = trace0Bar3.querySelector('text'), - trace1Bar2 = getAllBarNodes(traceNodes[1])[2], - path12 = trace1Bar2.querySelector('path'), - text12 = trace1Bar2.querySelector('text'), - trace2Bar0 = getAllBarNodes(traceNodes[2])[0], - path20 = trace2Bar0.querySelector('path'), - text20 = trace2Bar0.querySelector('text'), - trace3Bar0 = getAllBarNodes(traceNodes[3])[0], - path30 = trace3Bar0.querySelector('path'), - text30 = trace3Bar0.querySelector('text'); + var traceNodes = getAllTraceNodes(gd); + var trace0Bar3 = getAllBarNodes(traceNodes[0])[3]; + var path03 = trace0Bar3.querySelector('path'); + var text03 = trace0Bar3.querySelector('text'); + var trace1Bar2 = getAllBarNodes(traceNodes[1])[2]; + var path12 = trace1Bar2.querySelector('path'); + var text12 = trace1Bar2.querySelector('text'); + var trace2Bar0 = getAllBarNodes(traceNodes[2])[0]; + var path20 = trace2Bar0.querySelector('path'); + var text20 = trace2Bar0.querySelector('text'); + var trace3Bar0 = getAllBarNodes(traceNodes[3])[0]; + var path30 = trace3Bar0.querySelector('path'); + var text30 = trace3Bar0.querySelector('text'); expect(text03.textContent).toBe('4'); expect(text12.textContent).toBe('inside text'); @@ -1546,19 +1546,19 @@ describe('A bar plot', function() { expect(cd[3][0].t.poffset).toBe(0); assertTraceField(cd, 't.bargroupwidth', [0.8, 0.8, 0.8, 0.8]); - var traceNodes = getAllTraceNodes(gd), - trace0Bar3 = getAllBarNodes(traceNodes[0])[3], - path03 = trace0Bar3.querySelector('path'), - text03 = trace0Bar3.querySelector('text'), - trace1Bar2 = getAllBarNodes(traceNodes[1])[2], - path12 = trace1Bar2.querySelector('path'), - text12 = trace1Bar2.querySelector('text'), - trace2Bar0 = getAllBarNodes(traceNodes[2])[0], - path20 = trace2Bar0.querySelector('path'), - text20 = trace2Bar0.querySelector('text'), - trace3Bar0 = getAllBarNodes(traceNodes[3])[0], - path30 = trace3Bar0.querySelector('path'), - text30 = trace3Bar0.querySelector('text'); + var traceNodes = getAllTraceNodes(gd); + var trace0Bar3 = getAllBarNodes(traceNodes[0])[3]; + var path03 = trace0Bar3.querySelector('path'); + var text03 = trace0Bar3.querySelector('text'); + var trace1Bar2 = getAllBarNodes(traceNodes[1])[2]; + var path12 = trace1Bar2.querySelector('path'); + var text12 = trace1Bar2.querySelector('text'); + var trace2Bar0 = getAllBarNodes(traceNodes[2])[0]; + var path20 = trace2Bar0.querySelector('path'); + var text20 = trace2Bar0.querySelector('text'); + var trace3Bar0 = getAllBarNodes(traceNodes[3])[0]; + var path30 = trace3Bar0.querySelector('path'); + var text30 = trace3Bar0.querySelector('text'); expect(text03.textContent).toBe('4'); expect(text12.textContent).toBe('inside text'); @@ -1622,21 +1622,21 @@ describe('A bar plot', function() { }; Plotly.plot(gd, data, layout).then(function() { - var traceNodes = getAllTraceNodes(gd), - barNodes = getAllBarNodes(traceNodes[0]), - pathNodes = [ - barNodes[0].querySelector('path'), - barNodes[1].querySelector('path'), - barNodes[2].querySelector('path'), - barNodes[3].querySelector('path') - ], - textNodes = [ - barNodes[0].querySelector('text'), - barNodes[1].querySelector('text'), - barNodes[2].querySelector('text'), - barNodes[3].querySelector('text') - ], - i; + var traceNodes = getAllTraceNodes(gd); + var barNodes = getAllBarNodes(traceNodes[0]); + var pathNodes = [ + barNodes[0].querySelector('path'), + barNodes[1].querySelector('path'), + barNodes[2].querySelector('path'), + barNodes[3].querySelector('path') + ]; + var textNodes = [ + barNodes[0].querySelector('text'), + barNodes[1].querySelector('text'), + barNodes[2].querySelector('text'), + barNodes[3].querySelector('text') + ]; + var i; // assert bar texts for(i = 0; i < 3; i++) { @@ -1926,8 +1926,8 @@ describe('bar hover', function() { afterEach(destroyGraphDiv); function getPointData(gd) { - var cd = gd.calcdata, - subplot = gd._fullLayout._plots.xy; + var cd = gd.calcdata; + var subplot = gd._fullLayout._plots.xy; return { index: false, @@ -2000,31 +2000,31 @@ describe('bar hover', function() { }); it('should return the correct hover point data (case y)', function() { - var out = _hover(gd, 0.75, 0.15, 'y'), - subplot = gd._fullLayout._plots.xy, - xa = subplot.xaxis, - ya = subplot.yaxis, - barDelta = 1 * 0.8 / 2, - x0 = xa.c2p(0.5, true), - x1 = x0, - y0 = ya.c2p(0 - barDelta, true), - y1 = ya.c2p(0 + barDelta, true); + var out = _hover(gd, 0.75, 0.15, 'y'); + var subplot = gd._fullLayout._plots.xy; + var xa = subplot.xaxis; + var ya = subplot.yaxis; + var barDelta = 1 * 0.8 / 2; + var x0 = xa.c2p(0.5, true); + var x1 = x0; + var y0 = ya.c2p(0 - barDelta, true); + var y1 = ya.c2p(0 + barDelta, true); expect(out.style).toEqual([0, '#1f77b4', 0.5, 0]); assertPos(out.pos, [x0, x1, y0, y1]); }); it('should return the correct hover point data (case closest)', function() { - var out = _hover(gd, 0.75, -0.15, 'closest'), - subplot = gd._fullLayout._plots.xy, - xa = subplot.xaxis, - ya = subplot.yaxis, - barDelta = 1 * 0.8 / 2 / 2, - barPos = 0 - 1 * 0.8 / 2 + barDelta, - x0 = xa.c2p(0.5, true), - x1 = x0, - y0 = ya.c2p(barPos - barDelta, true), - y1 = ya.c2p(barPos + barDelta, true); + var out = _hover(gd, 0.75, -0.15, 'closest'); + var subplot = gd._fullLayout._plots.xy; + var xa = subplot.xaxis; + var ya = subplot.yaxis; + var barDelta = 1 * 0.8 / 2 / 2; + var barPos = 0 - 1 * 0.8 / 2 + barDelta; + var x0 = xa.c2p(0.5, true); + var x1 = x0; + var y0 = ya.c2p(barPos - barDelta, true); + var y1 = ya.c2p(barPos + barDelta, true); expect(out.style).toEqual([0, '#1f77b4', 0.5, 0]); assertPos(out.pos, [x0, x1, y0, y1]); diff --git a/test/jasmine/tests/carpet_test.js b/test/jasmine/tests/carpet_test.js index ffadb31317b..bc8954643a6 100644 --- a/test/jasmine/tests/carpet_test.js +++ b/test/jasmine/tests/carpet_test.js @@ -19,15 +19,15 @@ var supplyAllDefaults = require('../assets/supply_defaults'); describe('carpet supplyDefaults', function() { 'use strict'; - var traceIn, - traceOut; + var traceIn; + var traceOut; var supplyDefaults = Carpet.supplyDefaults; - var defaultColor = '#444', - layout = { - font: Plots.layoutAttributes.font - }; + var defaultColor = '#444'; + var layout = { + font: Plots.layoutAttributes.font + }; beforeEach(function() { traceOut = {}; diff --git a/test/jasmine/tests/cartesian_test.js b/test/jasmine/tests/cartesian_test.js index 93fb39367ed..a3194817e48 100644 --- a/test/jasmine/tests/cartesian_test.js +++ b/test/jasmine/tests/cartesian_test.js @@ -110,10 +110,10 @@ describe('restyle', function() { var mock = Lib.extendDeep({}, require('@mocks/text_chart_basic.json')); function assertScatterModeSizes(lineSize, pointSize, textSize) { - var gd3 = d3.select(gd), - lines = gd3.selectAll('g.scatter.trace .js-line'), - points = gd3.selectAll('g.scatter.trace path.point'), - texts = gd3.selectAll('g.scatter.trace text'); + var gd3 = d3.select(gd); + var lines = gd3.selectAll('g.scatter.trace .js-line'); + var points = gd3.selectAll('g.scatter.trace path.point'); + var texts = gd3.selectAll('g.scatter.trace text'); expect(lines.size()).toEqual(lineSize); expect(points.size()).toEqual(pointSize); @@ -280,9 +280,9 @@ describe('relayout', function() { function assertPointTranslate(pointT, textT) { var TOLERANCE = 10; - var gd3 = d3.select(gd), - points = gd3.selectAll('g.scatter.trace path.point'), - texts = gd3.selectAll('g.scatter.trace text'); + var gd3 = d3.select(gd); + var points = gd3.selectAll('g.scatter.trace path.point'); + var texts = gd3.selectAll('g.scatter.trace text'); expect(points.size()).toEqual(1); expect(texts.size()).toEqual(1); diff --git a/test/jasmine/tests/choropleth_test.js b/test/jasmine/tests/choropleth_test.js index f994387a459..8a2198f8c1d 100644 --- a/test/jasmine/tests/choropleth_test.js +++ b/test/jasmine/tests/choropleth_test.js @@ -18,14 +18,14 @@ describe('Test choropleth', function() { 'use strict'; describe('supplyDefaults', function() { - var traceIn, - traceOut; + var traceIn; + var traceOut; - var defaultColor = '#444', - layout = { - font: Plots.layoutAttributes.font, - _dfltTitle: {colorbar: 'cb'} - }; + var defaultColor = '#444'; + var layout = { + font: Plots.layoutAttributes.font, + _dfltTitle: {colorbar: 'cb'} + }; beforeEach(function() { traceOut = {}; diff --git a/test/jasmine/tests/click_test.js b/test/jasmine/tests/click_test.js index a15ac1d917e..4f471e5d20a 100644 --- a/test/jasmine/tests/click_test.js +++ b/test/jasmine/tests/click_test.js @@ -647,11 +647,11 @@ describe('Test click interactions:', function() { }); describe('double click interactions', function() { - var setRangeX = [-3, 1], - setRangeY = [-0.5, 1]; + var setRangeX = [-3, 1]; + var setRangeY = [-0.5, 1]; - var zoomRangeX = [-2, 0], - zoomRangeY = [0, 0.5]; + var zoomRangeX = [-2, 0]; + var zoomRangeY = [0, 0.5]; var update = { 'xaxis.range[0]': zoomRangeX[0], @@ -758,8 +758,8 @@ describe('Test click interactions:', function() { y: [[30, 0, 30]] }; - var newAutoRangeX = [-4.482371794871794, 3.4823717948717943], - newAutoRangeY = [-0.8892256657741471, 1.6689872212461876]; + var newAutoRangeX = [-4.482371794871794, 3.4823717948717943]; + var newAutoRangeY = [-0.8892256657741471, 1.6689872212461876]; Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() { expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX); @@ -1037,8 +1037,8 @@ describe('Test click interactions:', function() { } }; - var translate = Drawing.getTranslate(mockEl), - scale = Drawing.getScale(mockEl); + var translate = Drawing.getTranslate(mockEl); + var scale = Drawing.getScale(mockEl); expect([translate.x, translate.y]).toBeCloseToArray([13.93, 62.86]); expect([scale.x, scale.y]).toBeCloseToArray([1.105, 1.105]); @@ -1071,9 +1071,9 @@ describe('Test click interactions:', function() { it('should move the plot when panning', function() { - var start = 100, - end = 300, - plot = gd._fullLayout._plots.xy.plot; + var start = 100; + var end = 300; + var plot = gd._fullLayout._plots.xy.plot; mouseEvent('mousemove', start, start); mouseEvent('mousedown', start, start); diff --git a/test/jasmine/tests/colorbar_test.js b/test/jasmine/tests/colorbar_test.js index 1a4b2239078..9468df91489 100644 --- a/test/jasmine/tests/colorbar_test.js +++ b/test/jasmine/tests/colorbar_test.js @@ -44,8 +44,8 @@ describe('Test colorbar:', function() { }); describe('hasColorbar', function() { - var hasColorbar = Colorbar.hasColorbar, - trace; + var hasColorbar = Colorbar.hasColorbar; + var trace; it('should return true when marker colorbar is defined', function() { trace = { diff --git a/test/jasmine/tests/colorscale_test.js b/test/jasmine/tests/colorscale_test.js index 94ba6061dbd..75f6a61ad36 100644 --- a/test/jasmine/tests/colorscale_test.js +++ b/test/jasmine/tests/colorscale_test.js @@ -28,8 +28,8 @@ describe('Test colorscale:', function() { 'use strict'; describe('isValidScale', function() { - var isValidScale = Colorscale.isValidScale, - scl; + var isValidScale = Colorscale.isValidScale; + var scl; it('should accept colorscale strings', function() { expect(isValidScale('Earth')).toBe(true); @@ -84,8 +84,8 @@ describe('Test colorscale:', function() { }); describe('flipScale', function() { - var flipScale = Colorscale.flipScale, - scl; + var flipScale = Colorscale.flipScale; + var scl; it('should flip a colorscale', function() { scl = [[0, 'rgb(0, 0, 200)'], ['0.5', 'rgb(0, 0, 0)'], ['1.0', 'rgb(200, 0, 0)']]; @@ -97,8 +97,8 @@ describe('Test colorscale:', function() { }); describe('hasColorscale', function() { - var hasColorscale = Colorscale.hasColorscale, - trace; + var hasColorscale = Colorscale.hasColorscale; + var trace; it('should return false when marker is not defined', function() { var shouldBeFalse = [ @@ -247,12 +247,12 @@ describe('Test colorscale:', function() { }); describe('handleDefaults (heatmap-like version)', function() { - var handleDefaults = Colorscale.handleDefaults, - layout = { - font: Plots.layoutAttributes.font, - _dfltTitle: {colorbar: 'cb'} - }, - opts = {prefix: '', cLetter: 'z'}; + var handleDefaults = Colorscale.handleDefaults; + var layout = { + font: Plots.layoutAttributes.font, + _dfltTitle: {colorbar: 'cb'} + }; + var opts = {prefix: '', cLetter: 'z'}; var traceIn, traceOut; function coerce(attr, dflt) { @@ -318,12 +318,12 @@ describe('Test colorscale:', function() { }); describe('handleDefaults (scatter-like version)', function() { - var handleDefaults = Colorscale.handleDefaults, - layout = { - font: Plots.layoutAttributes.font, - _dfltTitle: {colorbar: 'cb'} - }, - opts = {prefix: 'marker.', cLetter: 'c'}; + var handleDefaults = Colorscale.handleDefaults; + var layout = { + font: Plots.layoutAttributes.font, + _dfltTitle: {colorbar: 'cb'} + }; + var opts = {prefix: 'marker.', cLetter: 'c'}; var traceIn, traceOut; function coerce(attr, dflt) { diff --git a/test/jasmine/tests/config_test.js b/test/jasmine/tests/config_test.js index 7054a849f88..2c8b10d8c39 100644 --- a/test/jasmine/tests/config_test.js +++ b/test/jasmine/tests/config_test.js @@ -549,8 +549,10 @@ describe('config argument', function() { }); describe('responsive figure', function() { - var gd, data = [{x: [1, 2, 3, 4], y: [5, 10, 2, 8]}]; - var width = 960, height = 800; + var gd; + var data = [{x: [1, 2, 3, 4], y: [5, 10, 2, 8]}]; + var width = 960; + var height = 800; var parent, elWidth, elHeight; @@ -701,7 +703,8 @@ describe('config argument', function() { }); it('@flaky should resize in both direction in a grid when responsive: true', function(done) { - var numCols = 2, numRows = 2; + var numCols = 2; + var numRows = 2; parent.style.display = 'grid'; parent.style.gridTemplateColumns = 'repeat(' + numCols + ', 1fr)'; parent.style.gridTemplateRows = 'repeat(' + numRows + ', 1fr)'; diff --git a/test/jasmine/tests/contour_test.js b/test/jasmine/tests/contour_test.js index 51d2de7add3..b695fa3fa5d 100644 --- a/test/jasmine/tests/contour_test.js +++ b/test/jasmine/tests/contour_test.js @@ -20,14 +20,14 @@ var supplyAllDefaults = require('../assets/supply_defaults'); describe('contour defaults', function() { 'use strict'; - var traceIn, - traceOut; + var traceIn; + var traceOut; - var defaultColor = '#444', - layout = { - font: Plots.layoutAttributes.font, - _dfltTitle: {colorbar: 'cb'} - }; + var defaultColor = '#444'; + var layout = { + font: Plots.layoutAttributes.font, + _dfltTitle: {colorbar: 'cb'} + }; var supplyDefaults = Contour.supplyDefaults; @@ -184,9 +184,9 @@ describe('contour calc', function() { 'use strict'; function _calc(opts) { - var base = { type: 'contour' }, - trace = Lib.extendFlat({}, base, opts), - gd = { data: [trace] }; + var base = { type: 'contour' }; + var trace = Lib.extendFlat({}, base, opts); + var gd = { data: [trace] }; supplyAllDefaults(gd); var fullTrace = gd._fullData[0]; @@ -326,9 +326,9 @@ describe('contour calc', function() { [spec.start, spec.end, 'normal'], [spec.end, spec.start, 'reversed'] ].forEach(function(v) { - var startIn = v[0], - endIn = v[1], - order = v[2]; + var startIn = v[0]; + var endIn = v[1]; + var order = v[2]; var out = _calc({ z: [[1, 2], [3, 4]], diff --git a/test/jasmine/tests/drawing_test.js b/test/jasmine/tests/drawing_test.js index 3229c386817..34249da0ab4 100644 --- a/test/jasmine/tests/drawing_test.js +++ b/test/jasmine/tests/drawing_test.js @@ -120,8 +120,8 @@ describe('Drawing', function() { }); it('should work with negative values', function() { - var el = document.createElement('div'), - el3 = d3.select(document.createElement('div')); + var el = document.createElement('div'); + var el3 = d3.select(document.createElement('div')); expect(Drawing.getTranslate(el)).toEqual({ x: 0, y: 0 }); @@ -142,10 +142,10 @@ describe('Drawing', function() { ]; for(var i = 0; i < testCases.length; i++) { - var testCase = testCases[i], - transform = testCase.transform, - x = testCase.x, - y = testCase.y; + var testCase = testCases[i]; + var transform = testCase.transform; + var x = testCase.x; + var y = testCase.y; el.setAttribute('transform', transform); expect(Drawing.getTranslate(el)).toEqual({ x: x, y: y }); diff --git a/test/jasmine/tests/extend_test.js b/test/jasmine/tests/extend_test.js index 7c4b50ce0a1..06d60fdca3f 100644 --- a/test/jasmine/tests/extend_test.js +++ b/test/jasmine/tests/extend_test.js @@ -4,10 +4,10 @@ var extendDeep = extendModule.extendDeep; var extendDeepAll = extendModule.extendDeepAll; var extendDeepNoArrays = extendModule.extendDeepNoArrays; -var str = 'me a test', - integer = 10, - arr = [1, 'what', new Date(81, 8, 4)], - date = new Date(81, 4, 13); +var str = 'me a test'; +var integer = 10; +var arr = [1, 'what', new Date(81, 8, 4)]; +var date = new Date(81, 4, 13); var Foo = function() {}; diff --git a/test/jasmine/tests/geo_test.js b/test/jasmine/tests/geo_test.js index 2f7adc53849..0c57fc6e444 100644 --- a/test/jasmine/tests/geo_test.js +++ b/test/jasmine/tests/geo_test.js @@ -846,11 +846,11 @@ describe('Test geo interactions', function() { var N_LOCATIONS_AT_START = mock.data[1].locations.length; - var lonQueue = [45, -45, 12, 20], - latQueue = [-75, 80, 5, 10], - textQueue = ['c', 'd', 'e', 'f'], - locationsQueue = ['AUS', 'FRA', 'DEU', 'MEX'], - zQueue = [100, 20, 30, 12]; + var lonQueue = [45, -45, 12, 20]; + var latQueue = [-75, 80, 5, 10]; + var textQueue = ['c', 'd', 'e', 'f']; + var locationsQueue = ['AUS', 'FRA', 'DEU', 'MEX']; + var zQueue = [100, 20, 30, 12]; beforeEach(function(done) { var update = { @@ -1259,9 +1259,9 @@ describe('Test event property of interactions on a geo plot:', function() { var mockCopy, gd; - var blankPos = [10, 10], - pointPos, - nearPos; + var blankPos = [10, 10]; + var pointPos; + var nearPos; beforeAll(function(done) { gd = createGraphDiv(); @@ -1301,8 +1301,8 @@ describe('Test event property of interactions on a geo plot:', function() { it('should contain the correct fields', function() { click(pointPos[0], pointPos[1]); - var pt = futureData.points[0], - evt = futureData.event; + var pt = futureData.points[0]; + var evt = futureData.event; expect(Object.keys(pt)).toEqual([ 'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex', @@ -1327,12 +1327,12 @@ describe('Test event property of interactions on a geo plot:', function() { describe('modified click events', function() { var clickOpts = { - altKey: true, - ctrlKey: true, - metaKey: true, - shiftKey: true - }, - futureData; + altKey: true, + ctrlKey: true, + metaKey: true, + shiftKey: true + }; + var futureData; beforeEach(function(done) { Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done); @@ -1398,8 +1398,8 @@ describe('Test event property of interactions on a geo plot:', function() { mouseEvent('mousemove', blankPos[0], blankPos[1]); mouseEvent('mousemove', pointPos[0], pointPos[1]); - var pt = futureData.points[0], - evt = futureData.event; + var pt = futureData.points[0]; + var evt = futureData.event; expect(Object.keys(pt)).toEqual([ 'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex', @@ -1435,8 +1435,8 @@ describe('Test event property of interactions on a geo plot:', function() { it('should contain the correct fields', function(done) { move(pointPos[0], pointPos[1], nearPos[0], nearPos[1], HOVERMINTIME + 10).then(function() { - var pt = futureData.points[0], - evt = futureData.event; + var pt = futureData.points[0]; + var evt = futureData.event; expect(Object.keys(pt)).toEqual([ 'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex', diff --git a/test/jasmine/tests/gl2d_plot_interact_test.js b/test/jasmine/tests/gl2d_plot_interact_test.js index 0b82b8f28e0..2ce6c4dcf07 100644 --- a/test/jasmine/tests/gl2d_plot_interact_test.js +++ b/test/jasmine/tests/gl2d_plot_interact_test.js @@ -553,7 +553,10 @@ describe('Test gl2d plots', function() { it('@noCI @gl should display selection of big number of regular points', function(done) { // generate large number of points - var x = [], y = [], n = 2e2, N = n * n; + var x = []; + var y = []; + var n = 2e2; + var N = n * n; for(var i = 0; i < N; i++) { x.push((i % n) / n); y.push(i / N); @@ -588,7 +591,13 @@ describe('Test gl2d plots', function() { ]; // generate large number of points - var x = [], y = [], n = 2e2, N = n * n, color = [], symbol = [], size = []; + var x = []; + var y = []; + var n = 2e2; + var N = n * n; + var color = []; + var symbol = []; + var size = []; for(var i = 0; i < N; i++) { x.push((i % n) / n); y.push(i / N); @@ -829,7 +838,8 @@ describe('Test gl2d plots', function() { } }; - var sceneTarget, relayoutCallback = jasmine.createSpy('relayoutCallback'); + var sceneTarget; + var relayoutCallback = jasmine.createSpy('relayoutCallback'); function scroll(target, amt) { return new Promise(function(resolve) { diff --git a/test/jasmine/tests/gl2d_scatterplot_contour_test.js b/test/jasmine/tests/gl2d_scatterplot_contour_test.js index 90d6ba54c7d..00cb9219ee4 100644 --- a/test/jasmine/tests/gl2d_scatterplot_contour_test.js +++ b/test/jasmine/tests/gl2d_scatterplot_contour_test.js @@ -105,7 +105,9 @@ function rotate(rad, point) { function generate(maxJitter) { var x = d3.range(-1, 1.5, 0.5); // left closed, right open interval var y = d3.range(-1, 1.5, 0.5); // left closed, right open interval - var i, j, p, z = new Array(x.length); + var z = new Array(x.length); + var i, j, p; + for(i = 0; i < x.length; i++) { z[i] = new Array(y.length); for(j = 0; j < y.length; j++) { @@ -187,8 +189,8 @@ describe('contourgl plots', function() { }); it('@gl render without raising an error', function(done) { - var mock = require('@mocks/simple_contour.json'), - mockCopy = Lib.extendDeep({}, mock); + var mock = require('@mocks/simple_contour.json'); + var mockCopy = Lib.extendDeep({}, mock); mockCopy.data[0].type = 'contourgl'; mockCopy.data[0].contours = { coloring: 'fill' }; diff --git a/test/jasmine/tests/gl3d_plot_interact_test.js b/test/jasmine/tests/gl3d_plot_interact_test.js index a44fc0e8eb8..65de62cce8f 100644 --- a/test/jasmine/tests/gl3d_plot_interact_test.js +++ b/test/jasmine/tests/gl3d_plot_interact_test.js @@ -845,8 +845,8 @@ describe('Test gl3d modebar handlers', function() { }); it('@gl button pan3d should updates the scene dragmode and dragmode button', function() { - var buttonTurntable = selectButton(modeBar, 'tableRotation'), - buttonPan3d = selectButton(modeBar, 'pan3d'); + var buttonTurntable = selectButton(modeBar, 'tableRotation'); + var buttonPan3d = selectButton(modeBar, 'pan3d'); assertScenes(gd._fullLayout, 'dragmode', 'turntable'); expect(buttonTurntable.isActive()).toBe(true); @@ -866,8 +866,8 @@ describe('Test gl3d modebar handlers', function() { }); it('@gl button orbitRotation should updates the scene dragmode and dragmode button', function() { - var buttonTurntable = selectButton(modeBar, 'tableRotation'), - buttonOrbit = selectButton(modeBar, 'orbitRotation'); + var buttonTurntable = selectButton(modeBar, 'tableRotation'); + var buttonOrbit = selectButton(modeBar, 'orbitRotation'); assertScenes(gd._fullLayout, 'dragmode', 'turntable'); expect(buttonTurntable.isActive()).toBe(true); @@ -1051,7 +1051,8 @@ describe('Test gl3d drag and wheel interactions', function() { } }; - var sceneTarget, relayoutCallback = jasmine.createSpy('relayoutCallback'); + var sceneTarget; + var relayoutCallback = jasmine.createSpy('relayoutCallback'); function assertEvent(e) { expect(e.defaultPrevented).toEqual(true); diff --git a/test/jasmine/tests/gl3dlayout_test.js b/test/jasmine/tests/gl3dlayout_test.js index dda88208001..6fb5bc7395d 100644 --- a/test/jasmine/tests/gl3dlayout_test.js +++ b/test/jasmine/tests/gl3dlayout_test.js @@ -261,8 +261,8 @@ describe('Test Gl3d layout defaults', function() { } }; - var bgColor = Color.combine('yellow', 'green'), - frac = 100 * (204 - 0x44) / (255 - 0x44); + var bgColor = Color.combine('yellow', 'green'); + var frac = 100 * (204 - 0x44) / (255 - 0x44); supplyLayoutDefaults(layoutIn, layoutOut, fullData); expect(layoutOut.scene.xaxis.gridcolor) diff --git a/test/jasmine/tests/heatmap_test.js b/test/jasmine/tests/heatmap_test.js index 7152e38429d..c6db00e0da5 100644 --- a/test/jasmine/tests/heatmap_test.js +++ b/test/jasmine/tests/heatmap_test.js @@ -16,15 +16,15 @@ var failTest = require('../assets/fail_test'); describe('heatmap supplyDefaults', function() { 'use strict'; - var traceIn, - traceOut; - - var defaultColor = '#444', - layout = { - font: Plots.layoutAttributes.font, - _dfltTitle: {colorbar: 'cb'}, - _subplots: {cartesian: ['xy'], xaxis: ['x'], yaxis: ['y']} - }; + var traceIn; + var traceOut; + + var defaultColor = '#444'; + var layout = { + font: Plots.layoutAttributes.font, + _dfltTitle: {colorbar: 'cb'}, + _subplots: {cartesian: ['xy'], xaxis: ['x'], yaxis: ['y']} + }; var supplyDefaults = Heatmap.supplyDefaults; @@ -288,9 +288,9 @@ describe('heatmap calc', function() { 'use strict'; function _calc(opts) { - var base = { type: 'heatmap' }, - trace = Lib.extendFlat({}, base, opts), - gd = { data: [trace] }; + var base = { type: 'heatmap' }; + var trace = Lib.extendFlat({}, base, opts); + var gd = { data: [trace] }; supplyAllDefaults(gd); var fullTrace = gd._fullData[0]; @@ -598,8 +598,8 @@ describe('heatmap plot', function() { return element; }); - var argumentsWithoutPadding = [], - argumentsWithPadding = []; + var argumentsWithoutPadding = []; + var argumentsWithPadding = []; Plotly.plot(gd, mockWithoutPadding.data, mockWithoutPadding.layout).then(function() { argumentsWithoutPadding = getContextStub.fillRect.calls.allArgs().slice(0); return Plotly.plot(gd, mockWithPadding.data, mockWithPadding.layout); @@ -660,9 +660,9 @@ describe('heatmap hover', function() { var gd; function _hover(gd, xval, yval) { - var fullLayout = gd._fullLayout, - calcData = gd.calcdata, - hoverData = []; + var fullLayout = gd._fullLayout; + var calcData = gd.calcdata; + var hoverData = []; for(var i = 0; i < calcData.length; i++) { var pointData = { @@ -693,8 +693,8 @@ describe('heatmap hover', function() { beforeAll(function(done) { gd = createGraphDiv(); - var mock = require('@mocks/heatmap_multi-trace.json'), - mockCopy = Lib.extendDeep({}, mock); + var mock = require('@mocks/heatmap_multi-trace.json'); + var mockCopy = Lib.extendDeep({}, mock); Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done); }); diff --git a/test/jasmine/tests/histogram2d_test.js b/test/jasmine/tests/histogram2d_test.js index 7893e18c767..e879588b53f 100644 --- a/test/jasmine/tests/histogram2d_test.js +++ b/test/jasmine/tests/histogram2d_test.js @@ -19,8 +19,8 @@ describe('Test histogram2d', function() { } describe('supplyDefaults', function() { - var traceIn, - traceOut; + var traceIn; + var traceOut; beforeEach(function() { traceOut = {}; @@ -117,9 +117,9 @@ describe('Test histogram2d', function() { describe('calc', function() { function _calc(opts) { - var base = { type: 'histogram2d' }, - trace = Lib.extendFlat({}, base, opts), - gd = { data: [trace] }; + var base = { type: 'histogram2d' }; + var trace = Lib.extendFlat({}, base, opts); + var gd = { data: [trace] }; supplyAllDefaults(gd); var fullTrace = gd._fullData[0]; diff --git a/test/jasmine/tests/histogram_test.js b/test/jasmine/tests/histogram_test.js index dd7fdf8ebb8..8e83a1530ea 100644 --- a/test/jasmine/tests/histogram_test.js +++ b/test/jasmine/tests/histogram_test.js @@ -296,10 +296,10 @@ describe('Test histogram', function() { nbinsx: 4 }); - var x0 = 0, - x1 = x0 + oneDay, - x2 = x1 + oneDay, - x3 = x2 + oneDay; + var x0 = 0; + var x1 = x0 + oneDay; + var x2 = x1 + oneDay; + var x3 = x2 + oneDay; expect(out).toEqual([ {i: 0, b: 0, p: x0, s: 2, pts: [0, 1], ph0: x0, ph1: x0}, @@ -628,8 +628,8 @@ describe('Test histogram', function() { ]; CDFs.forEach(function(CDF) { - var p = CDF.p, - s = CDF.s; + var p = CDF.p; + var s = CDF.s; it('handles direction=' + CDF.direction + ', currentbin=' + CDF.currentbin + ', histnorm=' + CDF.histnorm + ', histfunc=' + CDF.histfunc, function() { @@ -1043,11 +1043,11 @@ describe('getBinSpanLabelRound', function() { var cn8i = Lib.dateTime2ms('1995-08i-01', cn); var cn9 = Lib.dateTime2ms('1995-09-01', cn); - var cn1_00 = Lib.dateTime2ms('2000-01-01', cn); - var cn1_01 = Lib.dateTime2ms('2001-01-01', cn); - var cn1_02 = Lib.dateTime2ms('2002-01-01', cn); - var cn1_10 = Lib.dateTime2ms('2010-01-01', cn); - var cn1_20 = Lib.dateTime2ms('2020-01-01', cn); + var cn1x00 = Lib.dateTime2ms('2000-01-01', cn); + var cn1x01 = Lib.dateTime2ms('2001-01-01', cn); + var cn1x02 = Lib.dateTime2ms('2002-01-01', cn); + var cn1x10 = Lib.dateTime2ms('2010-01-01', cn); + var cn1x20 = Lib.dateTime2ms('2020-01-01', cn); _test(100, 2000, [cn8i, cn8i + 10000, cn8i + 20000], cn, [cn8i, cn8i + 9000, cn8i + 10000, cn8i + 19000]); @@ -1059,17 +1059,17 @@ describe('getBinSpanLabelRound', function() { _test(12 * hr, 12 * hr, [cn8 - 12 * hr, cn8i - 12 * hr, cn9 - 12 * hr], cn, [cn8, cn8i - day, cn8i, cn9 - day]); - _test(0, 28 * day, [cn1_00, cn1_01, cn1_02], cn, - [cn1_00, Lib.dateTime2ms('2000-12-01', cn), cn1_01, Lib.dateTime2ms('2001-12-01', cn)]); - _test(14 * day, 14 * day, [cn1_00 - 14 * day, cn1_01 - 14 * day, cn1_02 - 14 * day], cn, - [cn1_00, Lib.dateTime2ms('2000-12-01', cn), cn1_01, Lib.dateTime2ms('2001-12-01', cn)]); + _test(0, 28 * day, [cn1x00, cn1x01, cn1x02], cn, + [cn1x00, Lib.dateTime2ms('2000-12-01', cn), cn1x01, Lib.dateTime2ms('2001-12-01', cn)]); + _test(14 * day, 14 * day, [cn1x00 - 14 * day, cn1x01 - 14 * day, cn1x02 - 14 * day], cn, + [cn1x00, Lib.dateTime2ms('2000-12-01', cn), cn1x01, Lib.dateTime2ms('2001-12-01', cn)]); - _test(0, 353 * day, [cn1_00, cn1_10, cn1_20], cn, - [cn1_00, Lib.dateTime2ms('2009-01-01', cn), cn1_10, Lib.dateTime2ms('2019-01-01', cn)]); + _test(0, 353 * day, [cn1x00, cn1x10, cn1x20], cn, + [cn1x00, Lib.dateTime2ms('2009-01-01', cn), cn1x10, Lib.dateTime2ms('2019-01-01', cn)]); // occasionally we give extra precision for world dates (month when it should be year // or day when it should be month). That's better than doing the opposite... not going // to fix now, too many edge cases, better not to complicate the logic for them all. - _test(176 * day, 177 * day, [cn1_00 - 176 * day, cn1_10 - 176 * day, cn1_20 - 176 * day], cn, [ + _test(176 * day, 177 * day, [cn1x00 - 176 * day, cn1x10 - 176 * day, cn1x20 - 176 * day], cn, [ Lib.dateTime2ms('1999-08-01', cn), Lib.dateTime2ms('2009-07-01', cn), Lib.dateTime2ms('2009-08-01', cn), Lib.dateTime2ms('2019-07-01', cn) ]); diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index d2cc007bac6..3bae88b6024 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -1265,14 +1265,14 @@ describe('hover info', function() { describe('hoverformat', function() { var data = [{ - x: [1, 2, 3], - y: [0.12345, 0.23456, 0.34567] - }], - layout = { - yaxis: { showticklabels: true, hoverformat: ',.2r' }, - width: 600, - height: 400 - }; + x: [1, 2, 3], + y: [0.12345, 0.23456, 0.34567] + }]; + var layout = { + yaxis: { showticklabels: true, hoverformat: ',.2r' }, + width: 600, + height: 400 + }; beforeEach(function() { this.gd = createGraphDiv(); @@ -1302,16 +1302,16 @@ describe('hover info', function() { describe('textmode', function() { var data = [{ - x: [1, 2, 3, 4], - y: [2, 3, 4, 5], - mode: 'text', - hoverinfo: 'text', - text: ['test', null, 42, undefined] - }], - layout = { - width: 600, - height: 400 - }; + x: [1, 2, 3, 4], + y: [2, 3, 4, 5], + mode: 'text', + hoverinfo: 'text', + text: ['test', null, 42, undefined] + }]; + var layout = { + width: 600, + height: 400 + }; beforeEach(function(done) { Plotly.plot(createGraphDiv(), data, layout).then(done); diff --git a/test/jasmine/tests/hover_spikeline_test.js b/test/jasmine/tests/hover_spikeline_test.js index ebab394fdad..791dc28b738 100644 --- a/test/jasmine/tests/hover_spikeline_test.js +++ b/test/jasmine/tests/hover_spikeline_test.js @@ -37,11 +37,11 @@ describe('spikeline hover', function() { Lib.clearThrottle(); } - function _set_hovermode(hovermode) { + function _setHovermode(hovermode) { return Plotly.relayout(gd, 'hovermode', hovermode); } - function _set_spikedistance(spikedistance) { + function _setSpikedistance(spikedistance) { return Plotly.relayout(gd, 'spikedistance', spikedistance); } @@ -165,7 +165,7 @@ describe('spikeline hover', function() { Plotly.plot(gd, _mock) .then(function() { - _set_spikedistance(200); + _setSpikedistance(200); }) .then(function() { _hover({xpx: 120, ypx: 180}); @@ -200,7 +200,7 @@ describe('spikeline hover', function() { [] ); - _set_hovermode('x'); + _setHovermode('x'); }) .then(function() { _hover({xval: 2, yval: 3}); @@ -235,7 +235,7 @@ describe('spikeline hover', function() { [] ); - _set_spikedistance(200); + _setSpikedistance(200); }) .then(function() { _hover({xval: 1.6, yval: 2.6}); @@ -271,7 +271,7 @@ describe('spikeline hover', function() { [] ); - _set_spikedistance(-1); + _setSpikedistance(-1); }) .then(function() { _hover({xval: 1.6, yval: 2.6}); @@ -307,7 +307,7 @@ describe('spikeline hover', function() { [] ); - _set_spikedistance(0); + _setSpikedistance(0); }) .then(function() { _hover({xval: 2, yval: 3}); @@ -365,7 +365,7 @@ describe('spikeline hover', function() { type: 'bar', y: [2, 1] }], spikeLayout()) .then(_assertBarSpikes) - .then(function() { _set_hovermode('closest'); }) + .then(function() { _setHovermode('closest'); }) .then(_assertBarSpikes) .catch(failTest) .then(done); diff --git a/test/jasmine/tests/layout_images_test.js b/test/jasmine/tests/layout_images_test.js index ffd48139b1d..a665a25ae6d 100644 --- a/test/jasmine/tests/layout_images_test.js +++ b/test/jasmine/tests/layout_images_test.js @@ -84,8 +84,8 @@ describe('Layout images', function() { describe('drawing', function() { - var gd, - data = [{ x: [1, 2, 3], y: [1, 2, 3] }]; + var gd; + var data = [{ x: [1, 2, 3], y: [1, 2, 3] }]; beforeEach(function() { gd = createGraphDiv(); @@ -172,8 +172,8 @@ describe('Layout images', function() { sizing: sizing }]}); - var image = Plotly.d3.select('image'), - parValue = image.attr('preserveAspectRatio'); + var image = Plotly.d3.select('image'); + var parValue = image.attr('preserveAspectRatio'); expect(parValue).toBe(expected); } @@ -203,8 +203,8 @@ describe('Layout images', function() { }); describe('when the plot is dragged', function() { - var gd, - data = [{ x: [1, 2, 3], y: [1, 2, 3] }]; + var gd; + var data = [{ x: [1, 2, 3], y: [1, 2, 3] }]; beforeEach(function() { gd = createGraphDiv(); @@ -229,8 +229,8 @@ describe('Layout images', function() { width: 600, height: 400 }).then(function() { - var img = Plotly.d3.select('image').node(), - oldPos = img.getBoundingClientRect(); + var img = Plotly.d3.select('image').node(); + var oldPos = img.getBoundingClientRect(); mouseEvent('mousedown', 250, 200); mouseEvent('mousemove', 300, 250); @@ -261,8 +261,8 @@ describe('Layout images', function() { width: 600, height: 400 }).then(function() { - var img = Plotly.d3.select('image').node(), - oldPos = img.getBoundingClientRect(); + var img = Plotly.d3.select('image').node(); + var oldPos = img.getBoundingClientRect(); mouseEvent('mousedown', 250, 200); mouseEvent('mousemove', 300, 250); @@ -280,8 +280,8 @@ describe('Layout images', function() { describe('when relayout', function() { - var gd, - data = [{ x: [1, 2, 3], y: [1, 2, 3] }]; + var gd; + var data = [{ x: [1, 2, 3], y: [1, 2, 3] }]; beforeEach(function(done) { gd = createGraphDiv(); @@ -301,12 +301,12 @@ describe('Layout images', function() { afterEach(destroyGraphDiv); it('should update the image if changed', function(done) { - var img = Plotly.d3.select('image'), - url = img.attr('xlink:href'); + var img = Plotly.d3.select('image'); + var url = img.attr('xlink:href'); Plotly.relayout(gd, 'images[0].source', pythonLogo).then(function() { - var newImg = Plotly.d3.select('image'), - newUrl = newImg.attr('xlink:href'); + var newImg = Plotly.d3.select('image'); + var newUrl = newImg.attr('xlink:href'); expect(url).not.toBe(newUrl); }).then(done); }); @@ -344,9 +344,9 @@ describe('Layout images', function() { afterEach(destroyGraphDiv); it('should properly add and remove image', function(done) { - var gd = createGraphDiv(), - data = [{ x: [1, 2, 3], y: [1, 2, 3] }], - layout = { width: 500, height: 400 }; + var gd = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [1, 2, 3] }]; + var layout = { width: 500, height: 400 }; function makeImage(source, x, y) { return { @@ -449,8 +449,8 @@ describe('images log/linear axis changes', function() { beforeEach(function(done) { gd = createGraphDiv(); - var mockData = Lib.extendDeep([], mock.data), - mockLayout = Lib.extendDeep({}, mock.layout); + var mockData = Lib.extendDeep([], mock.data); + var mockLayout = Lib.extendDeep({}, mock.layout); Plotly.plot(gd, mockData, mockLayout).then(done); }); diff --git a/test/jasmine/tests/legend_scroll_test.js b/test/jasmine/tests/legend_scroll_test.js index 182aa0ba86f..6f431954c41 100644 --- a/test/jasmine/tests/legend_scroll_test.js +++ b/test/jasmine/tests/legend_scroll_test.js @@ -237,10 +237,10 @@ describe('The legend', function() { }); it('should keep the scrollbar position after a toggle event', function(done) { - var legend = getLegend(), - scrollBox = getScrollBox(), - toggle = getToggle(), - wheelDeltaY = 100; + var legend = getLegend(); + var scrollBox = getScrollBox(); + var toggle = getToggle(); + var wheelDeltaY = 100; legend.dispatchEvent(scrollTo(wheelDeltaY)); @@ -257,13 +257,13 @@ describe('The legend', function() { }); it('should be restored and functional after relayout', function(done) { - var wheelDeltaY = 100, - legend = getLegend(), - scrollBox, - scrollBar, - scrollBarX, - scrollBarY, - toggle; + var wheelDeltaY = 100; + var legend = getLegend(); + var scrollBox; + var scrollBar; + var scrollBarX; + var scrollBarY; + var toggle; legend.dispatchEvent(scrollTo(wheelDeltaY)); scrollBar = legend.getElementsByClassName('scrollbar')[0]; @@ -297,8 +297,8 @@ describe('The legend', function() { }); it('should constrain scrolling to the contents', function() { - var legend = getLegend(), - scrollBox = getScrollBox(); + var legend = getLegend(); + var scrollBox = getScrollBox(); legend.dispatchEvent(scrollTo(-100)); expect(scrollBox.getAttribute('transform')).toBe('translate(0, 0)'); @@ -308,9 +308,9 @@ describe('The legend', function() { }); it('should scale the scrollbar movement from top to bottom', function() { - var legend = getLegend(), - scrollBar = getScrollBar(), - legendHeight = getLegendHeight(gd); + var legend = getLegend(); + var scrollBar = getScrollBar(); + var legendHeight = getLegendHeight(gd); // The scrollbar is >20px tall and has 4px margins var scrollBarHeight = scrollBar.getBoundingClientRect().height; diff --git a/test/jasmine/tests/legend_test.js b/test/jasmine/tests/legend_test.js index 3f474fcc026..5c0b3b9cf28 100644 --- a/test/jasmine/tests/legend_test.js +++ b/test/jasmine/tests/legend_test.js @@ -711,9 +711,9 @@ describe('legend orientation change:', function() { afterEach(destroyGraphDiv); it('should update plot background', function(done) { - var mock = require('@mocks/legend_horizontal_autowrap.json'), - gd = createGraphDiv(), - initialLegendBGColor; + var mock = require('@mocks/legend_horizontal_autowrap.json'); + var gd = createGraphDiv(); + var initialLegendBGColor; Plotly.plot(gd, mock.data, mock.layout).then(function() { initialLegendBGColor = gd._fullLayout.legend.bgcolor; @@ -734,9 +734,9 @@ describe('legend restyle update', function() { afterEach(destroyGraphDiv); it('should update trace toggle background rectangle', function(done) { - var mock = require('@mocks/0.json'), - mockCopy = Lib.extendDeep({}, mock), - gd = createGraphDiv(); + var mock = require('@mocks/0.json'); + var mockCopy = Lib.extendDeep({}, mock); + var gd = createGraphDiv(); mockCopy.data[0].visible = false; mockCopy.data[0].showlegend = false; diff --git a/test/jasmine/tests/lib_date_test.js b/test/jasmine/tests/lib_date_test.js index 6bccb8a9865..00062d953bd 100644 --- a/test/jasmine/tests/lib_date_test.js +++ b/test/jasmine/tests/lib_date_test.js @@ -17,12 +17,12 @@ describe('dates', function() { // to near the present, but we accept them as part of 4-digit years d1c.setFullYear(13); - var thisYear = new Date().getFullYear(), - thisYear_2 = thisYear % 100, - nowMinus70 = thisYear - 70, - nowMinus70_2 = nowMinus70 % 100, - nowPlus29 = thisYear + 29, - nowPlus29_2 = nowPlus29 % 100; + var thisYear = new Date().getFullYear(); + var thisYear2 = thisYear % 100; + var nowMinus70 = thisYear - 70; + var nowMinus70x2 = nowMinus70 % 100; + var nowPlus29 = thisYear + 29; + var nowPlus29x2 = nowPlus29 % 100; function tweakedTZOffset(d) { var tzOffset = d.getTimezoneOffset() * 60000; @@ -73,9 +73,9 @@ describe('dates', function() { ['0013-1-1 1:00:00.60011111111', +d1c + 0.11111111], // 2-digit years get mapped to now-70 -> now+29 - [thisYear_2 + '-05', new Date(thisYear, 4, 1)], - [nowMinus70_2 + '-10-18', new Date(nowMinus70, 9, 18)], - [nowPlus29_2 + '-02-12 14:29:32', new Date(nowPlus29, 1, 12, 14, 29, 32)], + [thisYear2 + '-05', new Date(thisYear, 4, 1)], + [nowMinus70x2 + '-10-18', new Date(nowMinus70, 9, 18)], + [nowPlus29x2 + '-02-12 14:29:32', new Date(nowPlus29, 1, 12, 14, 29, 32)], // including timezone info (that we discard) ['2014-03-04 08:15Z', new Date(2014, 2, 4, 8, 15)], @@ -112,8 +112,8 @@ describe('dates', function() { [ [10, 2010], - [nowPlus29_2, nowPlus29], - [nowMinus70_2, nowMinus70], + [nowPlus29x2, nowPlus29], + [nowMinus70x2, nowMinus70], [99, 1999] ].forEach(function(v) { expect(Lib.dateTime2ms(v[0])).toBe(Date.UTC(v[1], 0, 1), v[0]); @@ -176,8 +176,8 @@ describe('dates', function() { it('should interpret JS dates by local time, not by its getTime()', function() { // not really part of the test, just to make sure the test is meaningful // the test should NOT be run in a UTC environment - var local0 = Number(new Date(1970, 0, 1)), - localjuly1 = Number(new Date(1970, 6, 1)); + var local0 = Number(new Date(1970, 0, 1)); + var localjuly1 = Number(new Date(1970, 6, 1)); expect([local0, localjuly1]).not.toEqual([0, JULY1MS], 'test must not run in UTC'); // verify that there *is* daylight saving time in the test environment @@ -256,11 +256,11 @@ describe('dates', function() { it('should work right with inputs beyond our precision', function() { for(var i = -1; i <= 1; i += 0.001) { - var tenths = Math.round(i * 10), - base = i < -0.05 ? '1969-12-31 23:59:59.99' : '1970-01-01 00:00:00.00', - expected = (base + String(tenths + 200).substr(1)) - .replace(/0+$/, '') - .replace(/ 00:00:00[\.]$/, ''); + var tenths = Math.round(i * 10); + var base = i < -0.05 ? '1969-12-31 23:59:59.99' : '1970-01-01 00:00:00.00'; + var expected = (base + String(tenths + 200).substr(1)) + .replace(/0+$/, '') + .replace(/ 00:00:00[\.]$/, ''); expect(Lib.ms2DateTime(i)).toBe(expected, i); } }); @@ -287,33 +287,33 @@ describe('dates', function() { ['thai', '2513-01-01'], ['ummalqura', '1389-10-23'] ].forEach(function(v) { - var calendar = v[0], - dateStr = v[1]; + var calendar = v[0]; + var dateStr = v[1]; expect(Lib.ms2DateTime(0, 0, calendar)).toBe(dateStr, calendar); expect(Lib.dateTime2ms(dateStr, calendar)).toBe(0, calendar); - var expected_p1ms = dateStr + ' 00:00:00.0001', - expected_1s = dateStr + ' 00:00:01', - expected_1m = dateStr + ' 00:01', - expected_1h = dateStr + ' 01:00', - expected_lastinstant = dateStr + ' 23:59:59.9999'; - - var oneSec = 1000, - oneMin = 60 * oneSec, - oneHour = 60 * oneMin, - lastInstant = 24 * oneHour - 0.1; - - expect(Lib.ms2DateTime(0.1, 0, calendar)).toBe(expected_p1ms, calendar); - expect(Lib.ms2DateTime(oneSec, 0, calendar)).toBe(expected_1s, calendar); - expect(Lib.ms2DateTime(oneMin, 0, calendar)).toBe(expected_1m, calendar); - expect(Lib.ms2DateTime(oneHour, 0, calendar)).toBe(expected_1h, calendar); - expect(Lib.ms2DateTime(lastInstant, 0, calendar)).toBe(expected_lastinstant, calendar); - - expect(Lib.dateTime2ms(expected_p1ms, calendar)).toBe(0.1, calendar); - expect(Lib.dateTime2ms(expected_1s, calendar)).toBe(oneSec, calendar); - expect(Lib.dateTime2ms(expected_1m, calendar)).toBe(oneMin, calendar); - expect(Lib.dateTime2ms(expected_1h, calendar)).toBe(oneHour, calendar); - expect(Lib.dateTime2ms(expected_lastinstant, calendar)).toBe(lastInstant, calendar); + var expectedPlus1ms = dateStr + ' 00:00:00.0001'; + var expected1s = dateStr + ' 00:00:01'; + var expected1m = dateStr + ' 00:01'; + var expected1h = dateStr + ' 01:00'; + var expectedLastInstant = dateStr + ' 23:59:59.9999'; + + var oneSec = 1000; + var oneMin = 60 * oneSec; + var oneHour = 60 * oneMin; + var lastInstant = 24 * oneHour - 0.1; + + expect(Lib.ms2DateTime(0.1, 0, calendar)).toBe(expectedPlus1ms, calendar); + expect(Lib.ms2DateTime(oneSec, 0, calendar)).toBe(expected1s, calendar); + expect(Lib.ms2DateTime(oneMin, 0, calendar)).toBe(expected1m, calendar); + expect(Lib.ms2DateTime(oneHour, 0, calendar)).toBe(expected1h, calendar); + expect(Lib.ms2DateTime(lastInstant, 0, calendar)).toBe(expectedLastInstant, calendar); + + expect(Lib.dateTime2ms(expectedPlus1ms, calendar)).toBe(0.1, calendar); + expect(Lib.dateTime2ms(expected1s, calendar)).toBe(oneSec, calendar); + expect(Lib.dateTime2ms(expected1m, calendar)).toBe(oneMin, calendar); + expect(Lib.dateTime2ms(expected1h, calendar)).toBe(oneHour, calendar); + expect(Lib.dateTime2ms(expectedLastInstant, calendar)).toBe(lastInstant, calendar); }); }); @@ -322,9 +322,9 @@ describe('dates', function() { return v !== 'gregorian'; }); - var canonicalTick = calComponent.CANONICAL_TICK, - canonicalSunday = calComponent.CANONICAL_SUNDAY, - dfltRange = calComponent.DFLTRANGE; + var canonicalTick = calComponent.CANONICAL_TICK; + var canonicalSunday = calComponent.CANONICAL_SUNDAY; + var dfltRange = calComponent.DFLTRANGE; expect(Object.keys(canonicalTick).length).toBe(calList.length); expect(Object.keys(canonicalSunday).length).toBe(calList.length); expect(Object.keys(dfltRange).length).toBe(calList.length); @@ -578,9 +578,9 @@ describe('dates', function() { ] ].forEach(function(v) { - var fmt = v[0], - expectedGregorian = v[1], - expectedCoptic = v[2]; + var fmt = v[0]; + var expectedGregorian = v[1]; + var expectedCoptic = v[2]; // tickround is irrelevant here... expect(Lib.formatDate(ms, fmt, 'y', utcFormat)) diff --git a/test/jasmine/tests/lib_test.js b/test/jasmine/tests/lib_test.js index 79b02b3efa0..0b9d0604e35 100644 --- a/test/jasmine/tests/lib_test.js +++ b/test/jasmine/tests/lib_test.js @@ -15,15 +15,15 @@ describe('Test lib.js:', function() { describe('interp() should', function() { it('return 1.75 as Q1 of [1, 2, 3, 4, 5]:', function() { - var input = [1, 2, 3, 4, 5], - res = Lib.interp(input, 0.25), - res0 = 1.75; + var input = [1, 2, 3, 4, 5]; + var res = Lib.interp(input, 0.25); + var res0 = 1.75; expect(res).toEqual(res0); }); it('return 4.25 as Q3 of [1, 2, 3, 4, 5]:', function() { - var input = [1, 2, 3, 4, 5], - res = Lib.interp(input, 0.75), - res0 = 4.25; + var input = [1, 2, 3, 4, 5]; + var res = Lib.interp(input, 0.75); + var res0 = 4.25; expect(res).toEqual(res0); }); it('error if second input argument is a string:', function() { @@ -33,16 +33,16 @@ describe('Test lib.js:', function() { }).toThrow('n should be a finite number'); }); it('error if second input argument is a date:', function() { - var in1 = [1, 2, 3, 4, 5], - in2 = new Date(2014, 11, 1); + var in1 = [1, 2, 3, 4, 5]; + var in2 = new Date(2014, 11, 1); expect(function() { Lib.interp(in1, in2); }).toThrow('n should be a finite number'); }); it('return the right boundary on input [-Inf, Inf]:', function() { - var input = [-Infinity, Infinity], - res = Lib.interp(input, 1), - res0 = Infinity; + var input = [-Infinity, Infinity]; + var res = Lib.interp(input, 1); + var res0 = Infinity; expect(res).toEqual(res0); }); }); @@ -50,15 +50,15 @@ describe('Test lib.js:', function() { describe('transposeRagged()', function() { it('should transpose and return a rectangular array', function() { var input = [ - [1], - [2, 3, 4], - [5, 6], - [7]], - output = [ - [1, 2, 5, 7], - [undefined, 3, 6, undefined], - [undefined, 4, undefined, undefined] - ]; + [1], + [2, 3, 4], + [5, 6], + [7]]; + var output = [ + [1, 2, 5, 7], + [undefined, 3, 6, undefined], + [undefined, 4, undefined, undefined] + ]; expect(Lib.transposeRagged(input)).toEqual(output); }); @@ -93,8 +93,8 @@ describe('Test lib.js:', function() { function summation(a, b) { return a + b; } it('should work with 1D and 2D inputs and ignore non-numerics', function() { - var in1D = [1, 2, 3, 4, 'goose!', 5, 6], - in2D = [[1, 2, 3], ['', 4], [5, 'hi!', 6]]; + var in1D = [1, 2, 3, 4, 'goose!', 5, 6]; + var in2D = [[1, 2, 3], ['', 4], [5, 'hi!', 6]]; expect(aggNums(Math.min, null, in1D)).toEqual(1); expect(aggNums(Math.min, null, in2D)).toEqual(1); @@ -109,100 +109,100 @@ describe('Test lib.js:', function() { describe('mean() should', function() { it('toss out non-numerics (strings)', function() { - var input = [1, 2, 'apple', 'orange'], - res = Lib.mean(input); + var input = [1, 2, 'apple', 'orange']; + var res = Lib.mean(input); expect(res).toEqual(1.5); }); it('toss out non-numerics (NaN)', function() { - var input = [1, 2, NaN], - res = Lib.mean(input); + var input = [1, 2, NaN]; + var res = Lib.mean(input); expect(res).toEqual(1.5); }); it('evaluate numbers which are passed around as text strings:', function() { - var input = ['1', '2'], - res = Lib.mean(input); + var input = ['1', '2']; + var res = Lib.mean(input); expect(res).toEqual(1.5); }); }); describe('midRange() should', function() { it('should calculate the arithmetic mean of the maximum and minimum value of a given array', function() { - var input = [1, 5.5, 6, 15, 10, 13], - res = Lib.midRange(input); + var input = [1, 5.5, 6, 15, 10, 13]; + var res = Lib.midRange(input); expect(res).toEqual(8); }); it('toss out non-numerics (strings)', function() { - var input = [1, 2, 'apple', 'orange'], - res = Lib.midRange(input); + var input = [1, 2, 'apple', 'orange']; + var res = Lib.midRange(input); expect(res).toEqual(1.5); }); it('toss out non-numerics (NaN)', function() { - var input = [1, 2, NaN], - res = Lib.midRange(input); + var input = [1, 2, NaN]; + var res = Lib.midRange(input); expect(res).toEqual(1.5); }); it('should be able to deal with array of length 1', function() { - var input = [10], - res = Lib.midRange(input); + var input = [10]; + var res = Lib.midRange(input); expect(res).toEqual(10); }); it('should return undefined for an empty array', function() { - var input = [], - res = Lib.midRange(input); + var input = []; + var res = Lib.midRange(input); expect(res).toBeUndefined(); }); }); describe('variance() should', function() { it('return 0 on input [2, 2, 2, 2, 2]:', function() { - var input = [2, 2, 2, 2], - res = Lib.variance(input); + var input = [2, 2, 2, 2]; + var res = Lib.variance(input); expect(res).toEqual(0); }); it('return 2/3 on input [-1, 0, 1]:', function() { - var input = [-1, 0, 1], - res = Lib.variance(input); + var input = [-1, 0, 1]; + var res = Lib.variance(input); expect(res).toEqual(2 / 3); }); it('toss out non-numerics (strings):', function() { - var input = [1, 2, 'apple', 'orange'], - res = Lib.variance(input); + var input = [1, 2, 'apple', 'orange']; + var res = Lib.variance(input); expect(res).toEqual(0.25); }); it('toss out non-numerics (NaN):', function() { - var input = [1, 2, NaN], - res = Lib.variance(input); + var input = [1, 2, NaN]; + var res = Lib.variance(input); expect(res).toEqual(0.25); }); }); describe('stdev() should', function() { it('return 0 on input [2, 2, 2, 2, 2]:', function() { - var input = [2, 2, 2, 2], - res = Lib.stdev(input); + var input = [2, 2, 2, 2]; + var res = Lib.stdev(input); expect(res).toEqual(0); }); it('return sqrt(2/3) on input [-1, 0, 1]:', function() { - var input = [-1, 0, 1], - res = Lib.stdev(input); + var input = [-1, 0, 1]; + var res = Lib.stdev(input); expect(res).toEqual(Math.sqrt(2 / 3)); }); it('toss out non-numerics (strings):', function() { - var input = [1, 2, 'apple', 'orange'], - res = Lib.stdev(input); + var input = [1, 2, 'apple', 'orange']; + var res = Lib.stdev(input); expect(res).toEqual(0.5); }); it('toss out non-numerics (NaN):', function() { - var input = [1, 2, NaN], - res = Lib.stdev(input); + var input = [1, 2, NaN]; + var res = Lib.stdev(input); expect(res).toEqual(0.5); }); }); describe('smooth()', function() { it('should not alter the input for FWHM < 1.5', function() { - var input = [1, 2, 1, 2, 1], - output = Lib.smooth(input.slice(), 1.49); + var input = [1, 2, 1, 2, 1]; + var output = Lib.smooth(input.slice(), 1.49); expect(output).toEqual(input); @@ -212,12 +212,12 @@ describe('Test lib.js:', function() { }); it('should preserve the length and integral even with multiple bounces', function() { - var input = [1, 2, 4, 8, 16, 8, 10, 12], - output2 = Lib.smooth(input.slice(), 2), - output30 = Lib.smooth(input.slice(), 30), - sumIn = 0, - sum2 = 0, - sum30 = 0; + var input = [1, 2, 4, 8, 16, 8, 10, 12]; + var output2 = Lib.smooth(input.slice(), 2); + var output30 = Lib.smooth(input.slice(), 30); + var sumIn = 0; + var sum2 = 0; + var sum30 = 0; for(var i = 0; i < input.length; i++) { sumIn += input[i]; @@ -232,15 +232,15 @@ describe('Test lib.js:', function() { }); it('should use a hann window and bounce', function() { - var input = [0, 0, 0, 7, 0, 0, 0], - out4 = Lib.smooth(input, 4), - out7 = Lib.smooth(input, 7), - expected4 = [ - 0.2562815664617711, 0.875, 1.4937184335382292, 1.75, - 1.493718433538229, 0.875, 0.25628156646177086 - ], - expected7 = [1, 1, 1, 1, 1, 1, 1], - i; + var input = [0, 0, 0, 7, 0, 0, 0]; + var out4 = Lib.smooth(input, 4); + var out7 = Lib.smooth(input, 7); + var expected4 = [ + 0.2562815664617711, 0.875, 1.4937184335382292, 1.75, + 1.493718433538229, 0.875, 0.25628156646177086 + ]; + var expected7 = [1, 1, 1, 1, 1, 1, 1]; + var i; for(i = 0; i < input.length; i++) { expect(out4[i]).toBeCloseTo(expected4[i], 6); @@ -253,9 +253,9 @@ describe('Test lib.js:', function() { var np = Lib.nestedProperty; it('should access simple objects', function() { - var obj = {a: 'b', c: 'd'}, - propA = np(obj, 'a'), - propB = np(obj, 'b'); + var obj = {a: 'b', c: 'd'}; + var propA = np(obj, 'a'); + var propB = np(obj, 'b'); expect(propA.get()).toBe('b'); // making and reading nestedProperties shouldn't change anything @@ -273,9 +273,9 @@ describe('Test lib.js:', function() { }); it('should access arrays', function() { - var arr = [1, 2, 3], - prop1 = np(arr, 1), - prop5 = np(arr, '5'); + var arr = [1, 2, 3]; + var prop1 = np(arr, 1); + var prop5 = np(arr, '5'); expect(prop1.get()).toBe(2); expect(arr).toEqual([1, 2, 3]); @@ -307,8 +307,8 @@ describe('Test lib.js:', function() { }); it('should access properties of objects in an array with index -1', function() { - var obj = {arr: [{a: 1}, {a: 2}, {b: 3}]}, - prop = np(obj, 'arr[-1].a'); + var obj = {arr: [{a: 1}, {a: 2}, {b: 3}]}; + var prop = np(obj, 'arr[-1].a'); expect(prop.get()).toEqual([1, 2, undefined]); expect(obj).toEqual({arr: [{a: 1}, {a: 2}, {b: 3}]}); @@ -341,9 +341,9 @@ describe('Test lib.js:', function() { }); it('should remove a property only with undefined or null', function() { - var obj = {a: 'b', c: 'd'}, - propA = np(obj, 'a'), - propC = np(obj, 'c'); + var obj = {a: 'b', c: 'd'}; + var propA = np(obj, 'a'); + var propC = np(obj, 'c'); propA.set(null); propC.set(undefined); @@ -358,18 +358,18 @@ describe('Test lib.js:', function() { it('should not remove arrays or empty objects inside container arrays', function() { var obj = { - annotations: [{a: [1, 2, 3]}], - c: [1, 2, 3], - domain: [1, 2], - range: [2, 3], - shapes: ['elephant'] - }, - propA = np(obj, 'annotations[-1].a'), - propC = np(obj, 'c'), - propD0 = np(obj, 'domain[0]'), - propD1 = np(obj, 'domain[1]'), - propR = np(obj, 'range'), - propS = np(obj, 'shapes[0]'); + annotations: [{a: [1, 2, 3]}], + c: [1, 2, 3], + domain: [1, 2], + range: [2, 3], + shapes: ['elephant'] + }; + var propA = np(obj, 'annotations[-1].a'); + var propC = np(obj, 'c'); + var propD0 = np(obj, 'domain[0]'); + var propD1 = np(obj, 'domain[1]'); + var propR = np(obj, 'range'); + var propS = np(obj, 'shapes[0]'); propA.set([[]]); propC.set([]); @@ -390,10 +390,10 @@ describe('Test lib.js:', function() { it('should allow empty object sub-containers', function() { - var obj = {}, - prop = np(obj, 'a[1].b.c'), - // we never set a value into a[0] so it doesn't even get {} - expectedArr = [undefined, {b: {c: 'pizza'}}]; + var obj = {}; + var prop = np(obj, 'a[1].b.c'); + // we never set a value into a[0] so it doesn't even get {} + var expectedArr = [undefined, {b: {c: 'pizza'}}]; expect(prop.get()).toBe(undefined); expect(obj).toEqual({}); @@ -408,8 +408,8 @@ describe('Test lib.js:', function() { }); it('does not prune inside `args` arrays', function() { - var obj = {}, - args = np(obj, 'args'); + var obj = {}; + var args = np(obj, 'args'); args.set([]); expect(obj.args).toEqual([]); @@ -664,20 +664,20 @@ describe('Test lib.js:', function() { }); describe('coerce', function() { - var coerce = Lib.coerce, - out; + var coerce = Lib.coerce; + var out; // TODO: I tested font and string because I changed them, but all the other types need tests still it('should set a value and return the value it sets', function() { - var aVal = 'aaaaah!', - cVal = {1: 2, 3: 4}, - attrs = {a: {valType: 'any', dflt: aVal}, b: {c: {valType: 'any'}}}, - obj = {b: {c: cVal}}, - outObj = {}, + var aVal = 'aaaaah!'; + var cVal = {1: 2, 3: 4}; + var attrs = {a: {valType: 'any', dflt: aVal}, b: {c: {valType: 'any'}}}; + var obj = {b: {c: cVal}}; + var outObj = {}; - aOut = coerce(obj, outObj, attrs, 'a'), - cOut = coerce(obj, outObj, attrs, 'b.c'); + var aOut = coerce(obj, outObj, attrs, 'a'); + var cOut = coerce(obj, outObj, attrs, 'b.c'); expect(aOut).toBe(aVal); expect(aOut).toBe(outObj.a); @@ -704,11 +704,11 @@ describe('Test lib.js:', function() { }); describe('string valType', function() { - var dflt = 'Jabberwock', - stringAttrs = { - s: {valType: 'string', dflt: dflt}, - noBlank: {valType: 'string', dflt: dflt, noBlank: true} - }; + var dflt = 'Jabberwock'; + var stringAttrs = { + s: {valType: 'string', dflt: dflt}, + noBlank: {valType: 'string', dflt: dflt, noBlank: true} + }; it('should insert the default if input is missing, or blank with noBlank', function() { out = coerce(undefined, {}, stringAttrs, 's'); @@ -746,14 +746,18 @@ describe('Test lib.js:', function() { var coerce2 = Lib.coerce2; it('should set a value and return the value it sets when user input is valid', function() { - var colVal = 'red', - sizeVal = 0, // 0 is valid but falsey - attrs = {testMarker: {testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'}, - testSize: {valType: 'number', dflt: 20}}}, - obj = {testMarker: {testColor: colVal, testSize: sizeVal}}, - outObj = {}, - colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor'), - sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize'); + var colVal = 'red'; + var sizeVal = 0; // 0 is valid but falsey + var attrs = { + testMarker: { + testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'}, + testSize: {valType: 'number', dflt: 20} + } + }; + var obj = {testMarker: {testColor: colVal, testSize: sizeVal}}; + var outObj = {}; + var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor'); + var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize'); expect(colOut).toBe(colVal); expect(colOut).toBe(outObj.testMarker.testColor); @@ -762,14 +766,18 @@ describe('Test lib.js:', function() { }); it('should set and return the default if the user input is not valid', function() { - var colVal = 'r', - sizeVal = 'aaaaah!', - attrs = {testMarker: {testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'}, - testSize: {valType: 'number', dflt: 20}}}, - obj = {testMarker: {testColor: colVal, testSize: sizeVal}}, - outObj = {}, - colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor'), - sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize'); + var colVal = 'r'; + var sizeVal = 'aaaaah!'; + var attrs = { + testMarker: { + testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'}, + testSize: {valType: 'number', dflt: 20} + } + }; + var obj = {testMarker: {testColor: colVal, testSize: sizeVal}}; + var outObj = {}; + var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor'); + var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize'); expect(colOut).toBe('rgba(0, 0, 0, 0)'); expect(sizeOut).toBe(outObj.testMarker.testSize); @@ -778,14 +786,18 @@ describe('Test lib.js:', function() { }); it('should return false if there is no user input', function() { - var colVal = null, - sizeVal, // undefined - attrs = {testMarker: {testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'}, - testSize: {valType: 'number', dflt: 20}}}, - obj = {testMarker: {testColor: colVal, testSize: sizeVal}}, - outObj = {}, - colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor'), - sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize'); + var colVal = null; + var sizeVal; // undefined + var attrs = { + testMarker: { + testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'}, + testSize: {valType: 'number', dflt: 20} + } + }; + var obj = {testMarker: {testColor: colVal, testSize: sizeVal}}; + var outObj = {}; + var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor'); + var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize'); expect(colOut).toBe(false); expect(sizeOut).toBe(false); @@ -1000,9 +1012,9 @@ describe('Test lib.js:', function() { }); describe('coerceFont', function() { - var fontAttrs = Plots.fontAttrs({}), - extendFlat = Lib.extendFlat, - coerceFont = Lib.coerceFont; + var fontAttrs = Plots.fontAttrs({}); + var extendFlat = Lib.extendFlat; + var coerceFont = Lib.coerceFont; var defaultFont = { family: '"Open sans", verdana, arial, sans-serif, DEFAULT', @@ -1048,12 +1060,12 @@ describe('Test lib.js:', function() { }); it('should pass through individual valid pieces', function() { - var goodFamily = 'A fish', // for now any non-blank string is OK - badFamily = 42, - goodSize = 123.456, - badSize = 'ginormous', - goodColor = 'red', - badColor = 'a dark and stormy night'; + var goodFamily = 'A fish'; // for now any non-blank string is OK + var badFamily = 42; + var goodSize = 123.456; + var badSize = 'ginormous'; + var goodColor = 'red'; + var badColor = 'a dark and stormy night'; containerIn = { fontWithDefault: {family: goodFamily, size: badSize, color: badColor} @@ -1099,8 +1111,8 @@ describe('Test lib.js:', function() { } it('should work for valType \'data_array\' where', function() { - var shouldPass = [[20], []], - shouldFail = ['a', {}, 20, undefined, null]; + var shouldPass = [[20], []]; + var shouldFail = ['a', {}, 20, undefined, null]; assert(shouldPass, shouldFail, { valType: 'data_array' @@ -1141,8 +1153,8 @@ describe('Test lib.js:', function() { }); it('should work for valType \'boolean\' where', function() { - var shouldPass = [true, false], - shouldFail = ['a', 1, {}, [], null, undefined, '']; + var shouldPass = [true, false]; + var shouldFail = ['a', 1, {}, [], null, undefined, '']; assert(shouldPass, shouldFail, { valType: 'boolean', @@ -1156,8 +1168,8 @@ describe('Test lib.js:', function() { }); it('should work for valType \'number\' where', function() { - var shouldPass = [20, '20', 1e6], - shouldFail = ['a', [], {}, null, undefined, '']; + var shouldPass = [20, '20', 1e6]; + var shouldFail = ['a', [], {}, null, undefined, '']; assert(shouldPass, shouldFail, { valType: 'number' @@ -1224,8 +1236,8 @@ describe('Test lib.js:', function() { }); it('should work for valType \'color\' where', function() { - var shouldPass = ['red', '#d3d3d3', 'rgba(0,255,255,0.1)'], - shouldFail = [1, {}, [], 'rgq(233,122,332,1)', null, undefined]; + var shouldPass = ['red', '#d3d3d3', 'rgba(0,255,255,0.1)']; + var shouldFail = [1, {}, [], 'rgq(233,122,332,1)', null, undefined]; assert(shouldPass, shouldFail, { valType: 'color' @@ -1233,8 +1245,8 @@ describe('Test lib.js:', function() { }); it('should work for valType \'colorlist\' where', function() { - var shouldPass = [['red'], ['#ffffff'], ['rgba(0,0,0,1)'], ['red', 'green', 'blue']], - shouldFail = [1, null, undefined, {}, [], 'red', ['red', null]]; + var shouldPass = [['red'], ['#ffffff'], ['rgba(0,0,0,1)'], ['red', 'green', 'blue']]; + var shouldFail = [1, null, undefined, {}, [], 'red', ['red', null]]; assert(shouldPass, shouldFail, { valType: 'colorlist' @@ -1242,14 +1254,14 @@ describe('Test lib.js:', function() { }); it('should work for valType \'colorscale\' where', function() { - var good = [ [0, 'red'], [1, 'blue'] ], - bad = [ [0.1, 'red'], [1, 'blue'] ], - bad2 = [ [0], [1] ], - bad3 = [ ['red'], ['blue']], - bad4 = ['red', 'blue']; + var good = [ [0, 'red'], [1, 'blue'] ]; + var bad = [ [0.1, 'red'], [1, 'blue'] ]; + var bad2 = [ [0], [1] ]; + var bad3 = [ ['red'], ['blue']]; + var bad4 = ['red', 'blue']; - var shouldPass = ['Viridis', 'Greens', good], - shouldFail = ['red', 1, undefined, null, {}, [], bad, bad2, bad3, bad4]; + var shouldPass = ['Viridis', 'Greens', good]; + var shouldFail = ['red', 1, undefined, null, {}, [], bad, bad2, bad3, bad4]; assert(shouldPass, shouldFail, { valType: 'colorscale' @@ -1257,8 +1269,8 @@ describe('Test lib.js:', function() { }); it('should work for valType \'angle\' where', function() { - var shouldPass = ['auto', '120', 270], - shouldFail = [{}, [], 'red', null, undefined, '']; + var shouldPass = ['auto', '120', 270]; + var shouldFail = [{}, [], 'red', null, undefined, '']; assert(shouldPass, shouldFail, { valType: 'angle', @@ -1267,8 +1279,8 @@ describe('Test lib.js:', function() { }); it('should work for valType \'subplotid\' where', function() { - var shouldPass = ['sp', 'sp4', 'sp10'], - shouldFail = [{}, [], 'sp1', 'sp0', 'spee1', null, undefined, true]; + var shouldPass = ['sp', 'sp4', 'sp10']; + var shouldFail = [{}, [], 'sp1', 'sp0', 'spee1', null, undefined, true]; assert(shouldPass, shouldFail, { valType: 'subplotid', @@ -1277,8 +1289,8 @@ describe('Test lib.js:', function() { }); it('should work for valType \'flaglist\' where', function() { - var shouldPass = ['a', 'b', 'a+b', 'b+a', 'c'], - shouldFail = [{}, [], 'red', null, undefined, '', 'a + b']; + var shouldPass = ['a', 'b', 'a+b', 'b+a', 'c']; + var shouldFail = [{}, [], 'red', null, undefined, '', 'a + b']; assert(shouldPass, shouldFail, { valType: 'flaglist', @@ -1288,8 +1300,8 @@ describe('Test lib.js:', function() { }); it('should work for valType \'any\' where', function() { - var shouldPass = ['', '120', null, false, {}, []], - shouldFail = [undefined]; + var shouldPass = ['', '120', null, false, {}, []]; + var shouldFail = [undefined]; assert(shouldPass, shouldFail, { valType: 'any' @@ -1297,12 +1309,12 @@ describe('Test lib.js:', function() { }); it('should work for valType \'info_array\' where', function() { - var shouldPass = [[1, 2], [-20, '20']], - shouldFail = [ - {}, [], [10], [null, 10], ['aads', null], - 'red', null, undefined, '', - [1, 10, null] - ]; + var shouldPass = [[1, 2], [-20, '20']]; + var shouldFail = [ + {}, [], [10], [null, 10], ['aads', null], + 'red', null, undefined, '', + [1, 10, null] + ]; assert(shouldPass, shouldFail, { valType: 'info_array', @@ -1480,8 +1492,8 @@ describe('Test lib.js:', function() { it('should recognize matching RegExps', function() { expect(this.array).toEqual(['a', 'b', 'c', { a: 'A' }]); - var r1 = /a/, - r2 = /a/; + var r1 = /a/; + var r2 = /a/; Lib.pushUnique(this.array, r1); expect(this.array).toEqual(['a', 'b', 'c', { a: 'A' }, r1]); @@ -2194,7 +2206,8 @@ describe('Test lib.js:', function() { }); it('uses the value from the first object with the specified key', function() { - var obj1 = {a: 'first'}, obj2 = {a: 'second', foo: {bar: 'bar'}}; + var obj1 = {a: 'first'}; + var obj2 = {a: 'second', foo: {bar: 'bar'}}; // Simple key expect(Lib.hovertemplateString('foo %{a}', {}, obj1, obj2)).toEqual('foo first'); diff --git a/test/jasmine/tests/localize_test.js b/test/jasmine/tests/localize_test.js index 34758cce2d9..92d2d0f556b 100644 --- a/test/jasmine/tests/localize_test.js +++ b/test/jasmine/tests/localize_test.js @@ -202,7 +202,7 @@ describe('localization', function() { // four locales, highest to lowest priority // hopefully nobody will supply this many conflicting locales, but // if they do, this is what should happen! - var ctx_fr_QC = { + var ctxFrQC = { dictionary: {a: 'a-ctx-QC'}, format: {decimal: '~'} }; @@ -212,7 +212,7 @@ describe('localization', function() { dictionary: {a: 'a-reg-QC', b: 'b-reg-QC'}, format: {decimal: 'X', thousands: '@'} }); - var ctx_fr = { + var ctxFr = { dictionary: {a: 'a-ctx', b: 'b-ctx', c: 'c-ctx'}, format: {decimal: 'X', thousands: 'X', shortMonths: monthNums} }; @@ -223,7 +223,7 @@ describe('localization', function() { format: {decimal: 'X', thousands: 'X', shortMonths: monthLetters, shortDays: dayLetters} }); - plot('fr-QC', {fr: ctx_fr, 'fr-QC': ctx_fr_QC}) + plot('fr-QC', {fr: ctxFr, 'fr-QC': ctxFrQC}) .then(function() { expect(_(gd, 'a')).toBe('a-ctx-QC'); expect(_(gd, 'b')).toBe('b-reg-QC'); diff --git a/test/jasmine/tests/mapbox_test.js b/test/jasmine/tests/mapbox_test.js index 558cb12f075..9d6f6f8e53a 100644 --- a/test/jasmine/tests/mapbox_test.js +++ b/test/jasmine/tests/mapbox_test.js @@ -300,11 +300,11 @@ describe('mapbox credentials', function() { describe('@noCI, mapbox plots', function() { 'use strict'; - var mock = require('@mocks/mapbox_0.json'), - gd; + var mock = require('@mocks/mapbox_0.json'); + var gd; - var pointPos = [579, 276], - blankPos = [650, 120]; + var pointPos = [579, 276]; + var blankPos = [650, 120]; beforeEach(function(done) { gd = createGraphDiv(); @@ -398,8 +398,8 @@ describe('@noCI, mapbox plots', function() { }, LONG_TIMEOUT_INTERVAL); it('should be able to restyle', function(done) { - var restyleCnt = 0, - relayoutCnt = 0; + var restyleCnt = 0; + var relayoutCnt = 0; gd.on('plotly_restyle', function() { restyleCnt++; @@ -457,8 +457,8 @@ describe('@noCI, mapbox plots', function() { }, LONG_TIMEOUT_INTERVAL); it('should be able to relayout', function(done) { - var restyleCnt = 0, - relayoutCnt = 0; + var restyleCnt = 0; + var relayoutCnt = 0; gd.on('plotly_restyle', function() { restyleCnt++; @@ -540,8 +540,8 @@ describe('@noCI, mapbox plots', function() { it('should be able to add, update and remove layers', function(done) { var mockWithLayers = require('@mocks/mapbox_layers'); - var layer0 = Lib.extendDeep({}, mockWithLayers.layout.mapbox.layers[0]), - layer1 = Lib.extendDeep({}, mockWithLayers.layout.mapbox.layers[1]); + var layer0 = Lib.extendDeep({}, mockWithLayers.layout.mapbox.layers[0]); + var layer1 = Lib.extendDeep({}, mockWithLayers.layout.mapbox.layers[1]); var mapUpdate = { 'mapbox.zoom': mockWithLayers.layout.mapbox.zoom, @@ -564,8 +564,8 @@ describe('@noCI, mapbox plots', function() { function countVisibleLayers(gd) { var mapInfo = getMapInfo(gd); - var sourceLen = mapInfo.layoutSources.length, - layerLen = mapInfo.layoutLayers.length; + var sourceLen = mapInfo.layoutSources.length; + var layerLen = mapInfo.layoutLayers.length; if(sourceLen !== layerLen) return null; @@ -577,9 +577,9 @@ describe('@noCI, mapbox plots', function() { } function assertLayerStyle(gd, expectations, index) { - var mapInfo = getMapInfo(gd), - layers = mapInfo.layers, - layerNames = mapInfo.layoutLayers; + var mapInfo = getMapInfo(gd); + var layers = mapInfo.layers; + var layerNames = mapInfo.layoutLayers; var layer = layers[layerNames[index]]; expect(layer).toBeDefined(layerNames[index]); @@ -762,8 +762,8 @@ describe('@noCI, mapbox plots', function() { it('should be able to update traces', function(done) { function assertDataPts(lengths) { - var lines = getGeoJsonData(gd, 'lines'), - markers = getGeoJsonData(gd, 'markers'); + var lines = getGeoJsonData(gd, 'lines'); + var markers = getGeoJsonData(gd, 'markers'); lines.forEach(function(obj, i) { expect(obj.coordinates[0].length).toEqual(lengths[i]); @@ -837,8 +837,8 @@ describe('@noCI, mapbox plots', function() { }, LONG_TIMEOUT_INTERVAL); it('should respond to hover interactions by', function(done) { - var hoverCnt = 0, - unhoverCnt = 0; + var hoverCnt = 0; + var unhoverCnt = 0; var hoverData, unhoverData; @@ -977,12 +977,12 @@ describe('@noCI, mapbox plots', function() { }, LONG_TIMEOUT_INTERVAL); function getMapInfo(gd) { - var subplot = gd._fullLayout.mapbox._subplot, - map = subplot.map; + var subplot = gd._fullLayout.mapbox._subplot; + var map = subplot.map; - var sources = map.style.sourceCaches, - layers = map.style._layers, - uid = subplot.uid; + var sources = map.style.sourceCaches; + var layers = map.style._layers; + var uid = subplot.uid; var traceSources = Object.keys(sources).filter(function(k) { return k.indexOf('-source-') !== -1; @@ -1016,8 +1016,8 @@ describe('@noCI, mapbox plots', function() { } function countVisibleTraces(gd, modes) { - var mapInfo = getMapInfo(gd), - cnts = []; + var mapInfo = getMapInfo(gd); + var cnts = []; // 'modes' are the ScatterMapbox layers names // e.g. 'fill', 'line', 'circle', 'symbol' @@ -1046,8 +1046,8 @@ describe('@noCI, mapbox plots', function() { } function getStyle(gd, mode, prop) { - var mapInfo = getMapInfo(gd), - values = []; + var mapInfo = getMapInfo(gd); + var values = []; mapInfo.traceLayers.forEach(function(l) { var info = mapInfo.layers[l]; @@ -1061,8 +1061,8 @@ describe('@noCI, mapbox plots', function() { } function getGeoJsonData(gd, mode) { - var mapInfo = getMapInfo(gd), - out = []; + var mapInfo = getMapInfo(gd); + var out = []; mapInfo.traceSources.forEach(function(s) { var info = mapInfo.sources[s]; diff --git a/test/jasmine/tests/modebar_test.js b/test/jasmine/tests/modebar_test.js index e14594e44ae..33f25db999f 100644 --- a/test/jasmine/tests/modebar_test.js +++ b/test/jasmine/tests/modebar_test.js @@ -820,8 +820,8 @@ describe('ModeBar', function() { var gd = setupGraphInfo(); manageModeBar(gd); - var initialGroupCount = countGroups(gd._fullLayout._modeBar), - initialButtonCount = countButtons(gd._fullLayout._modeBar); + var initialGroupCount = countGroups(gd._fullLayout._modeBar); + var initialButtonCount = countButtons(gd._fullLayout._modeBar); gd._context.modeBarButtonsToAdd = [{ name: 'some button', @@ -1032,10 +1032,10 @@ describe('ModeBar', function() { describe('buttons zoomIn2d, zoomOut2d, autoScale2d and resetScale2d', function() { it('should update axis ranges', function() { - var buttonZoomIn = selectButton(modeBar, 'zoomIn2d'), - buttonZoomOut = selectButton(modeBar, 'zoomOut2d'), - buttonAutoScale = selectButton(modeBar, 'autoScale2d'), - buttonResetScale = selectButton(modeBar, 'resetScale2d'); + var buttonZoomIn = selectButton(modeBar, 'zoomIn2d'); + var buttonZoomOut = selectButton(modeBar, 'zoomOut2d'); + var buttonAutoScale = selectButton(modeBar, 'autoScale2d'); + var buttonResetScale = selectButton(modeBar, 'resetScale2d'); assertRange('xaxis', ['2016-01-01', '2016-04-01']); assertRange('yaxis', [1, 3]); @@ -1071,11 +1071,11 @@ describe('ModeBar', function() { describe('buttons zoom2d, pan2d, select2d and lasso2d', function() { it('should update the layout dragmode', function() { - var zoom2d = selectButton(modeBar, 'zoom2d'), - pan2d = selectButton(modeBar, 'pan2d'), - select2d = selectButton(modeBar, 'select2d'), - lasso2d = selectButton(modeBar, 'lasso2d'), - buttons = [zoom2d, pan2d, select2d, lasso2d]; + var zoom2d = selectButton(modeBar, 'zoom2d'); + var pan2d = selectButton(modeBar, 'pan2d'); + var select2d = selectButton(modeBar, 'select2d'); + var lasso2d = selectButton(modeBar, 'lasso2d'); + var buttons = [zoom2d, pan2d, select2d, lasso2d]; expect(gd._fullLayout.dragmode).toBe('zoom'); assertActive(buttons, zoom2d); @@ -1270,9 +1270,10 @@ describe('ModeBar', function() { }); describe('modebar styling', function() { - var gd, - colors = ['rgba(128, 128, 128, 0.7)', 'rgba(255, 0, 128, 0.2)'], - targetBtn = 'pan2d', button, style; + var gd; + var colors = ['rgba(128, 128, 128, 0.7)', 'rgba(255, 0, 128, 0.2)']; + var targetBtn = 'pan2d'; + var button, style; beforeEach(function() { gd = createGraphDiv(); diff --git a/test/jasmine/tests/parcats_test.js b/test/jasmine/tests/parcats_test.js index c4c3fb92873..674555bccb7 100644 --- a/test/jasmine/tests/parcats_test.js +++ b/test/jasmine/tests/parcats_test.js @@ -12,14 +12,14 @@ var CALLBACK_DELAY = 500; // Testing constants // ================= -var basic_mock = Lib.extendDeep({}, require('@mocks/parcats_basic.json')); -var margin = basic_mock.layout.margin; -var domain = basic_mock.data[0].domain; +var basicMock = Lib.extendDeep({}, require('@mocks/parcats_basic.json')); +var margin = basicMock.layout.margin; +var domain = basicMock.data[0].domain; -var categoryLabelPad = 40, - dimWidth = 16, - catSpacing = 8, - dimDx = (256 - 2 * categoryLabelPad - dimWidth) / 2; +var categoryLabelPad = 40; +var dimWidth = 16; +var catSpacing = 8; +var dimDx = (256 - 2 * categoryLabelPad - dimWidth) / 2; // Validation helpers // ================== @@ -110,9 +110,9 @@ function checkParcatsSvg(gd) { .selectAll('g.dimension'); dimensionSelection.each(function(dimension, dimInd) { - var expectedX = categoryLabelPad + dimInd * dimDx, - expectedY = 0, - expectedTransform = makeTranslate(expectedX, expectedY); + var expectedX = categoryLabelPad + dimInd * dimDx; + var expectedY = 0; + var expectedTransform = makeTranslate(expectedX, expectedY); expect(d3.select(this).attr('transform')).toEqual(expectedTransform); }); @@ -123,23 +123,23 @@ function checkParcatsSvg(gd) { var nextY = (3 - categorySelection.size()) * catSpacing / 2; categorySelection.each(function(category) { - var catSel = d3.select(this), - catWidth = catSel.datum().width, - catHeight = catSel.datum().height; + var catSel = d3.select(this); + var catWidth = catSel.datum().width; + var catHeight = catSel.datum().height; var expectedTransform = 'translate(0, ' + nextY + ')'; expect(catSel.attr('transform')).toEqual(expectedTransform); nextY += category.height + catSpacing; // Check category label position - var isRightDim = dimDisplayInd === 2, - catLabel = catSel.select('text.catlabel'); + var isRightDim = dimDisplayInd === 2; + var catLabel = catSel.select('text.catlabel'); // Compute expected text properties based on // whether this is the right-most dimension - var expectedTextAnchor = isRightDim ? 'start' : 'end', - expectedX = isRightDim ? catWidth + 5 : -5, - expectedY = catHeight / 2; + var expectedTextAnchor = isRightDim ? 'start' : 'end'; + var expectedX = isRightDim ? catWidth + 5 : -5; + var expectedY = catHeight / 2; expect(catLabel.attr('text-anchor')).toEqual(expectedTextAnchor); expect(catLabel.attr('x')).toEqual(expectedX.toString()); @@ -160,8 +160,8 @@ describe('Basic parcats trace', function() { // Variable declarations // --------------------- // ### Trace level ### - var gd, - mock; + var gd; + var mock; // Fixtures // -------- @@ -175,7 +175,7 @@ describe('Basic parcats trace', function() { // Tests // ----- it('should create trace properly', function(done) { - Plotly.newPlot(gd, basic_mock) + Plotly.newPlot(gd, basicMock) .then(function() { // Check trace properties var trace = gd.data[0]; @@ -188,7 +188,7 @@ describe('Basic parcats trace', function() { }); it('should compute initial model properly', function(done) { - Plotly.newPlot(gd, basic_mock) + Plotly.newPlot(gd, basicMock) .then(function() { // Var check calc data @@ -271,18 +271,15 @@ describe('Basic parcats trace', function() { Plotly.newPlot(gd, mock) .then(function() { - // Var check calc data - var gd_traceData = gd.data[0]; - // Check that trace data matches input - expect(gd_traceData).toEqual(mock.data[0]); + expect(gd.data[0]).toEqual(mock.data[0]); }) .catch(failTest) .then(done); }); it('should compute initial fullData properly', function(done) { - Plotly.newPlot(gd, basic_mock) + Plotly.newPlot(gd, basicMock) .then(function() { // Check that some of the defaults are computed properly var fullTrace = gd._fullData[0]; @@ -296,7 +293,7 @@ describe('Basic parcats trace', function() { it('should compute initial model views properly', function(done) { - Plotly.newPlot(gd, basic_mock) + Plotly.newPlot(gd, basicMock) .then(function() { checkParcatsModelView(gd); }) @@ -306,7 +303,7 @@ describe('Basic parcats trace', function() { }); it('should compute initial svg properly', function(done) { - Plotly.newPlot(gd, basic_mock) + Plotly.newPlot(gd, basicMock) .then(function() { checkParcatsSvg(gd); }) @@ -320,8 +317,8 @@ describe('Dimension reordered parcats trace', function() { // Variable declarations // --------------------- // ### Trace level ### - var gd, - mock; + var gd; + var mock; // Fixtures // -------- @@ -495,9 +492,9 @@ describe('Drag to reordered dimensions', function() { // Variable declarations // --------------------- // ### Trace level ### - var gd, - restyleCallback, - mock; + var gd; + var restyleCallback; + var mock; // Fixtures // -------- @@ -514,20 +511,20 @@ describe('Drag to reordered dimensions', function() { // Start mouse in the middle of the dimension label on the // second dimensions (dimension display index 1) var dragDimStartX = parcatsViewModel.dimensions[1].x; - var mouseStartY = parcatsViewModel.y - 5, - mouseStartX = parcatsViewModel.x + dragDimStartX + dimWidth / 2; + var mouseStartY = parcatsViewModel.y - 5; + var mouseStartX = parcatsViewModel.x + dragDimStartX + dimWidth / 2; // Pause mouse half-way between the original location of // the first and second dimensions. Also move mosue // downward a bit to make sure drag 'sticks' - var mouseMidY = parcatsViewModel.y + 50, - mouseMidX = mouseStartX + dimDx / 2; + var mouseMidY = parcatsViewModel.y + 50; + var mouseMidX = mouseStartX + dimDx / 2; // End mouse drag in the middle of the original // position of the dimension label of the third dimension // (dimension display index 2) - var mouseEndY = parcatsViewModel.y + 100, - mouseEndX = parcatsViewModel.x + parcatsViewModel.dimensions[2].x + dimWidth / 2; + var mouseEndY = parcatsViewModel.y + 100; + var mouseEndX = parcatsViewModel.x + parcatsViewModel.dimensions[2].x + dimWidth / 2; return { mouseStartY: mouseStartY, mouseStartX: mouseStartX, @@ -784,9 +781,9 @@ describe('Drag to reordered categories', function() { // Variable declarations // --------------------- // ### Trace level ### - var gd, - restyleCallback, - mock; + var gd; + var restyleCallback; + var mock; // Fixtures // -------- @@ -800,20 +797,20 @@ describe('Drag to reordered categories', function() { function getDragPositions(parcatsViewModel) { var dragDimStartX = parcatsViewModel.dimensions[1].x; - var mouseStartY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10, - mouseStartX = parcatsViewModel.x + dragDimStartX + dimWidth / 2; + var mouseStartY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10; + var mouseStartX = parcatsViewModel.x + dragDimStartX + dimWidth / 2; // Pause mouse half-way between the original location of // the first and second dimensions. Also move mouse // upward enough to swap position with middle category - var mouseMidY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[1].y, - mouseMidX = mouseStartX + dimDx / 2; + var mouseMidY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[1].y; + var mouseMidX = mouseStartX + dimDx / 2; // End mouse drag in the middle of the original // position of the dimension label of the third dimension // (dimension display index 2), and at the height of the original top category - var mouseEndY = parcatsViewModel.y, - mouseEndX = parcatsViewModel.x + parcatsViewModel.dimensions[2].x + dimWidth / 2; + var mouseEndY = parcatsViewModel.y; + var mouseEndX = parcatsViewModel.x + parcatsViewModel.dimensions[2].x + dimWidth / 2; return { dragDimStartX: dragDimStartX, mouseStartY: mouseStartY, @@ -1165,8 +1162,8 @@ describe('Click events', function() { // Variable declarations // --------------------- // ### Trace level ### - var gd, - mock; + var gd; + var mock; // Fixtures // -------- @@ -1191,8 +1188,8 @@ describe('Click events', function() { // Click on the lowest category in the middle dimension (category "C") var dimStartX = parcatsViewModel.dimensions[1].x; - var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10, - mouseX = parcatsViewModel.x + dimStartX + dimWidth / 2; + var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10; + var mouseX = parcatsViewModel.x + dimStartX + dimWidth / 2; // Position mouse for start of drag // -------------------------------- @@ -1234,8 +1231,8 @@ describe('Click events', function() { // Click on the lowest category in the middle dimension (category "C") var dimStartX = parcatsViewModel.dimensions[1].x; - var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10, - mouseX = parcatsViewModel.x + dimStartX + dimWidth / 2; + var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10; + var mouseX = parcatsViewModel.x + dimStartX + dimWidth / 2; // Position mouse for start of drag // -------------------------------- @@ -1265,8 +1262,8 @@ describe('Click events', function() { // Click on the top path to the right of the lowest category in the middle dimension (category "C") var dimStartX = parcatsViewModel.dimensions[1].x; - var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10, - mouseX = parcatsViewModel.x + dimStartX + dimWidth + 10; + var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10; + var mouseX = parcatsViewModel.x + dimStartX + dimWidth + 10; // Position mouse for start of drag // -------------------------------- @@ -1307,8 +1304,8 @@ describe('Click events', function() { // Click on the top path to the right of the lowest category in the middle dimension (category "C") var dimStartX = parcatsViewModel.dimensions[1].x; - var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10, - mouseX = parcatsViewModel.x + dimStartX + dimWidth + 10; + var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10; + var mouseX = parcatsViewModel.x + dimStartX + dimWidth + 10; // Position mouse for start of drag // -------------------------------- @@ -1329,8 +1326,8 @@ describe('Click events with hoveron color', function() { // Variable declarations // --------------------- // ### Trace level ### - var gd, - mock; + var gd; + var mock; // Fixtures // -------- @@ -1355,8 +1352,8 @@ describe('Click events with hoveron color', function() { // Click on the top of the lowest category in the middle dimension (category "C") var dimStartX = parcatsViewModel.dimensions[1].x; - var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10, - mouseX = parcatsViewModel.x + dimStartX + dimWidth / 2; + var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10; + var mouseX = parcatsViewModel.x + dimStartX + dimWidth / 2; // Position mouse for start of drag // -------------------------------- @@ -1396,8 +1393,8 @@ describe('Click events with hoveron color', function() { // Click on the top path to the right of the lowest category in the middle dimension (category "C") var dimStartX = parcatsViewModel.dimensions[1].x; - var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10, - mouseX = parcatsViewModel.x + dimStartX + dimWidth + 10; + var mouseY = parcatsViewModel.y + parcatsViewModel.dimensions[1].categories[2].y + 10; + var mouseX = parcatsViewModel.x + dimStartX + dimWidth + 10; // Position mouse for start of drag // -------------------------------- @@ -1427,8 +1424,8 @@ describe('Hover events', function() { // Variable declarations // --------------------- // ### Trace level ### - var gd, - mock; + var gd; + var mock; // Fixtures // -------- @@ -1441,10 +1438,10 @@ describe('Hover events', function() { it('hover and unhover should fire on category', function(done) { - var hoverData, - unhoverData, - mouseY0, - mouseX0; + var hoverData; + var unhoverData; + var mouseY0; + var mouseX0; Plotly.newPlot(gd, mock) .then(function() { @@ -1512,10 +1509,10 @@ describe('Hover events', function() { it('hover and unhover should fire on path', function(done) { - var hoverData, - unhoverData, - mouseY0, - mouseX0; + var hoverData; + var unhoverData; + var mouseY0; + var mouseX0; Plotly.newPlot(gd, mock) .then(function() { @@ -1584,8 +1581,8 @@ describe('Hover events with hoveron color', function() { // Variable declarations // --------------------- // ### Trace level ### - var gd, - mock; + var gd; + var mock; // Fixtures // -------- @@ -1598,10 +1595,10 @@ describe('Hover events with hoveron color', function() { it('hover and unhover should fire on category hoveron color', function(done) { - var hoverData, - unhoverData, - mouseY0, - mouseX0; + var hoverData; + var unhoverData; + var mouseY0; + var mouseX0; Plotly.newPlot(gd, mock) .then(function() { @@ -1665,10 +1662,10 @@ describe('Hover events with hoveron color', function() { it('hover and unhover should fire on path hoveron color', function(done) { - var hoverData, - unhoverData, - mouseY0, - mouseX0; + var hoverData; + var unhoverData; + var mouseY0; + var mouseX0; Plotly.newPlot(gd, mock) .then(function() { diff --git a/test/jasmine/tests/parcoords_test.js b/test/jasmine/tests/parcoords_test.js index d70ed46ab6a..2b42b71983b 100644 --- a/test/jasmine/tests/parcoords_test.js +++ b/test/jasmine/tests/parcoords_test.js @@ -109,9 +109,9 @@ describe('parcoords initialization tests', function() { describe('parcoords defaults', function() { function _supply(traceIn) { - var traceOut = { visible: true }, - defaultColor = '#444', - layout = { font: Plots.layoutAttributes.font }; + var traceOut = { visible: true }; + var defaultColor = '#444'; + var layout = { font: Plots.layoutAttributes.font }; Parcoords.supplyDefaults(traceIn, traceOut, defaultColor, layout); @@ -850,7 +850,7 @@ describe('parcoords Lifecycle methods', function() { it('@gl line.color `Plotly.restyle` should not change context layer', function(done) { var testLayer = '.gl-canvas-context'; - var old_rgb, new_rgb; + var oldRGB, newRGB; Plotly.plot(gd, [{ type: 'parcoords', @@ -866,19 +866,19 @@ describe('parcoords Lifecycle methods', function() { }) .then(function() { var rgb = getAvgPixelByChannel(testLayer); - old_rgb = rgb[0] + rgb[1] + rgb[2] / 3.0; - expect(old_rgb).toBeGreaterThan(0, 'not all black'); - expect(old_rgb).toBeLessThan(255, 'not all white'); + oldRGB = rgb[0] + rgb[1] + rgb[2] / 3.0; + expect(oldRGB).toBeGreaterThan(0, 'not all black'); + expect(oldRGB).toBeLessThan(255, 'not all white'); return Plotly.restyle(gd, 'line.color', 'red'); }) .then(function() { var rgb = getAvgPixelByChannel(testLayer); - new_rgb = rgb[0] + rgb[1] + rgb[2] / 3.0; - expect(new_rgb).toBeGreaterThan(0, 'not all black'); - expect(new_rgb).toBeLessThan(255, 'not all white'); + newRGB = rgb[0] + rgb[1] + rgb[2] / 3.0; + expect(newRGB).toBeGreaterThan(0, 'not all black'); + expect(newRGB).toBeLessThan(255, 'not all white'); - expect(new_rgb).toBe(old_rgb, 'no change to context'); + expect(newRGB).toBe(oldRGB, 'no change to context'); }) .catch(failTest) .then(done); diff --git a/test/jasmine/tests/pie_test.js b/test/jasmine/tests/pie_test.js index e131248ce48..1d8a8f3fe12 100644 --- a/test/jasmine/tests/pie_test.js +++ b/test/jasmine/tests/pie_test.js @@ -824,8 +824,8 @@ describe('pie hovering', function() { var mock = require('@mocks/pie_simple.json'); describe('with hoverinfo set to none', function() { - var mockCopy = Lib.extendDeep({}, mock), - gd; + var mockCopy = Lib.extendDeep({}, mock); + var gd; mockCopy.data[0].hoverinfo = 'none'; @@ -839,8 +839,8 @@ describe('pie hovering', function() { afterEach(destroyGraphDiv); it('should fire hover event when moving from one slice to another', function(done) { - var count = 0, - hoverData = []; + var count = 0; + var hoverData = []; gd.on('plotly_hover', function(data) { count++; @@ -857,8 +857,8 @@ describe('pie hovering', function() { }); it('should fire unhover event when the mouse moves off the graph', function(done) { - var count = 0, - unhoverData = []; + var count = 0; + var unhoverData = []; gd.on('plotly_unhover', function(data) { count++; @@ -878,10 +878,10 @@ describe('pie hovering', function() { }); describe('event data', function() { - var mockCopy = Lib.extendDeep({}, mock), - width = mockCopy.layout.width, - height = mockCopy.layout.height, - gd; + var mockCopy = Lib.extendDeep({}, mock); + var width = mockCopy.layout.width; + var height = mockCopy.layout.height; + var gd; beforeEach(function(done) { gd = createGraphDiv(); @@ -893,10 +893,8 @@ describe('pie hovering', function() { afterEach(destroyGraphDiv); it('should contain the correct fields', function() { - - var hoverData, - unhoverData; - + var hoverData; + var unhoverData; gd.on('plotly_hover', function(data) { hoverData = data; @@ -927,8 +925,8 @@ describe('pie hovering', function() { }); it('should fire hover event when moving from one slice to another', function(done) { - var count = 0, - hoverData = []; + var count = 0; + var hoverData = []; gd.on('plotly_hover', function(data) { count++; @@ -945,8 +943,8 @@ describe('pie hovering', function() { }); it('should fire unhover event when the mouse moves off the graph', function(done) { - var count = 0, - unhoverData = []; + var count = 0; + var unhoverData = []; gd.on('plotly_unhover', function(data) { count++; @@ -1159,8 +1157,8 @@ describe('Test event data of interactions on a pie plot:', function() { var mockCopy, gd; - var blankPos = [10, 10], - pointPos; + var blankPos = [10, 10]; + var pointPos; beforeAll(function(done) { gd = createGraphDiv(); @@ -1249,12 +1247,12 @@ describe('Test event data of interactions on a pie plot:', function() { describe('modified click events', function() { var clickOpts = { - altKey: true, - ctrlKey: true, - metaKey: true, - shiftKey: true - }, - futureData; + altKey: true, + ctrlKey: true, + metaKey: true, + shiftKey: true + }; + var futureData; beforeEach(function(done) { Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done); diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index c42f9f62cf2..3475b06227d 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -140,10 +140,10 @@ describe('Test plot api', function() { .then(function() { var uid = gd._fullLayout._uid; - var plotClip = document.getElementById('clip' + uid + 'xyplot'), - clipRect = plotClip.children[0], - clipWidth = +clipRect.getAttribute('width'), - clipHeight = +clipRect.getAttribute('height'); + var plotClip = document.getElementById('clip' + uid + 'xyplot'); + var clipRect = plotClip.children[0]; + var clipWidth = +clipRect.getAttribute('width'); + var clipHeight = +clipRect.getAttribute('height'); expect(clipWidth).toBe(240); expect(clipHeight).toBe(220); @@ -2211,9 +2211,9 @@ describe('Test plot api', function() { afterEach(destroyGraphDiv); it('', function(done) { - var gd = createGraphDiv(), - initialData = [], - layout = { title: 'Redraw' }; + var gd = createGraphDiv(); + var initialData = []; + var layout = { title: 'Redraw' }; Plotly.newPlot(gd, initialData, layout); @@ -2378,8 +2378,8 @@ describe('Test plot api', function() { Plotly.plot(gd, data); - var trace0 = gd.data[0], - trace1 = gd.data[1]; + var trace0 = gd.data[0]; + var trace1 = gd.data[1]; expect(trace0.transforms.length).toEqual(2); expect(trace0.transforms[0].filtersrc).toBeUndefined(); @@ -2408,8 +2408,8 @@ describe('Test plot api', function() { Plotly.plot(gd, data); - var trace0 = gd.data[0], - trace1 = gd.data[1]; + var trace0 = gd.data[0]; + var trace1 = gd.data[1]; expect(trace0.transforms.length).toEqual(2); expect(trace0.transforms[0].calendar).toBeUndefined(); diff --git a/test/jasmine/tests/plot_interact_test.js b/test/jasmine/tests/plot_interact_test.js index 4f7078d1be2..d9d37aec3df 100644 --- a/test/jasmine/tests/plot_interact_test.js +++ b/test/jasmine/tests/plot_interact_test.js @@ -52,8 +52,8 @@ describe('Test plot structure', function() { beforeEach(function(done) { gd = createGraphDiv(); - var mockData = Lib.extendDeep([], mock.data), - mockLayout = Lib.extendDeep({}, mock.layout); + var mockData = Lib.extendDeep([], mock.data); + var mockLayout = Lib.extendDeep({}, mock.layout); Plotly.plot(gd, mockData, mockLayout).then(done); }); @@ -169,8 +169,8 @@ describe('Test plot structure', function() { var gd; function extendMock() { - var mockData = Lib.extendDeep([], mock.data), - mockLayout = Lib.extendDeep({}, mock.layout); + var mockData = Lib.extendDeep([], mock.data); + var mockLayout = Lib.extendDeep({}, mock.layout); // add a colorbar for testing mockData[0].showscale = true; @@ -404,8 +404,8 @@ describe('Test plot structure', function() { beforeEach(function(done) { gd = createGraphDiv(); - var mockData = Lib.extendDeep([], mock.data), - mockLayout = Lib.extendDeep({}, mock.layout); + var mockData = Lib.extendDeep([], mock.data); + var mockLayout = Lib.extendDeep({}, mock.layout); Plotly.plot(gd, mockData, mockLayout).then(done); }); diff --git a/test/jasmine/tests/plot_promise_test.js b/test/jasmine/tests/plot_promise_test.js index 57939eea702..82d42343b17 100644 --- a/test/jasmine/tests/plot_promise_test.js +++ b/test/jasmine/tests/plot_promise_test.js @@ -10,8 +10,8 @@ describe('Plotly.___ methods', function() { afterEach(destroyGraphDiv); describe('Plotly.plot promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; @@ -33,9 +33,9 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.plot promise', function() { - var gd, - promise, - promiseRejected = false; + var gd; + var promise; + var promiseRejected = false; beforeEach(function(done) { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; @@ -63,9 +63,9 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.plot promise', function() { - var gd, - promise, - promiseRejected = false; + var gd; + var promise; + var promiseRejected = false; beforeEach(function(done) { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; @@ -89,12 +89,12 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.redraw promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); @@ -115,8 +115,8 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.newPlot promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; @@ -138,12 +138,12 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.extendTraces promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); @@ -164,12 +164,12 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.prependTraces promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); @@ -190,12 +190,12 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.addTraces promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); @@ -216,12 +216,12 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.deleteTraces promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); @@ -246,8 +246,8 @@ describe('Plotly.___ methods', function() { promiseGd; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); @@ -268,15 +268,15 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.moveTraces promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { var data = [ - { x: [1, 2, 3], y: [4, 5, 6] }, - { x: [1, 2, 3], y: [6, 5, 4] } - ], - initialDiv = createGraphDiv(); + { x: [1, 2, 3], y: [4, 5, 6] }, + { x: [1, 2, 3], y: [6, 5, 4] } + ]; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); @@ -297,12 +297,12 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.restyle promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); @@ -323,12 +323,12 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.restyle promise', function() { - var promise, - promiseRejected = false; + var promise; + var promiseRejected = false; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); @@ -346,13 +346,13 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.relayout promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - layout = {hovermode: 'closest'}, - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var layout = {hovermode: 'closest'}; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, layout); @@ -373,13 +373,13 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.relayout promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - layout = {hovermode: 'closest'}, - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var layout = {hovermode: 'closest'}; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, layout); @@ -400,13 +400,13 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.relayout promise', function() { - var promise, - promiseGd; + var promise; + var promiseGd; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - layout = {hovermode: 'closest'}, - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var layout = {hovermode: 'closest'}; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, layout); @@ -427,13 +427,13 @@ describe('Plotly.___ methods', function() { }); describe('Plotly.relayout promise', function() { - var promise, - promiseRejected = false; + var promise; + var promiseRejected = false; beforeEach(function(done) { - var data = [{ x: [1, 2, 3], y: [4, 5, 6] }], - layout = {hovermode: 'closest'}, - initialDiv = createGraphDiv(); + var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; + var layout = {hovermode: 'closest'}; + var initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, layout); diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index 11db2d50a96..140daf9c2c0 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -13,12 +13,12 @@ describe('Test Plots', function() { describe('Plots.supplyDefaults', function() { it('should not throw an error when gd is a plain object', function() { - var height = 100, - gd = { - layout: { - height: height - } - }; + var height = 100; + var gd = { + layout: { + height: height + } + }; supplyAllDefaults(gd); expect(gd.layout.height).toBe(height); @@ -222,8 +222,8 @@ describe('Test Plots', function() { }); describe('Plots.supplyTraceDefaults', function() { - var supplyTraceDefaults = Plots.supplyTraceDefaults, - layout = {_subplots: {cartesian: ['xy'], xaxis: ['x'], yaxis: ['y']}}; + var supplyTraceDefaults = Plots.supplyTraceDefaults; + var layout = {_subplots: {cartesian: ['xy'], xaxis: ['x'], yaxis: ['y']}}; var traceIn, traceOut; @@ -298,10 +298,10 @@ describe('Test Plots', function() { it('should resize the plot clip', function() { var uid = gd._fullLayout._uid; - var plotClip = document.getElementById('clip' + uid + 'xyplot'), - clipRect = plotClip.children[0], - clipWidth = +clipRect.getAttribute('width'), - clipHeight = +clipRect.getAttribute('height'); + var plotClip = document.getElementById('clip' + uid + 'xyplot'); + var clipRect = plotClip.children[0]; + var clipWidth = +clipRect.getAttribute('width'); + var clipHeight = +clipRect.getAttribute('height'); expect(clipWidth).toBe(240); expect(clipHeight).toBe(220); @@ -312,9 +312,9 @@ describe('Test Plots', function() { expect(mainSvgs.length).toBe(2); for(var i = 0; i < mainSvgs.length; i++) { - var svg = mainSvgs[i], - svgWidth = +svg.getAttribute('width'), - svgHeight = +svg.getAttribute('height'); + var svg = mainSvgs[i]; + var svgWidth = +svg.getAttribute('width'); + var svgHeight = +svg.getAttribute('height'); expect(svgWidth).toBe(400); expect(svgHeight).toBe(400); @@ -325,8 +325,8 @@ describe('Test Plots', function() { var mainSvgs = document.getElementsByClassName('main-svg'); expect(mainSvgs.length).toBe(2); - var fullLayout = gd._fullLayout, - plotinfo = fullLayout._plots.xy; + var fullLayout = gd._fullLayout; + var plotinfo = fullLayout._plots.xy; expect(fullLayout.xaxis._length).toEqual(240); expect(fullLayout.yaxis._length).toEqual(220); diff --git a/test/jasmine/tests/polygon_test.js b/test/jasmine/tests/polygon_test.js index f9fc5536fd6..86f11ee3b14 100644 --- a/test/jasmine/tests/polygon_test.js +++ b/test/jasmine/tests/polygon_test.js @@ -1,57 +1,58 @@ -var polygon = require('@src/lib/polygon'), - polygonTester = polygon.tester, - isBent = polygon.isSegmentBent, - filter = polygon.filter; +var polygon = require('@src/lib/polygon'); + +var polygonTester = polygon.tester; +var isBent = polygon.isSegmentBent; +var filter = polygon.filter; describe('polygon.tester', function() { 'use strict'; - var squareCW = [[0, 0], [0, 1], [1, 1], [1, 0]], - squareCCW = [[0, 0], [1, 0], [1, 1], [0, 1]], - bowtie = [[0, 0], [0, 1], [1, 0], [1, 1]], - squareish = [ - [-0.123, -0.0456], - [0.12345, 1.2345], - [1.3456, 1.4567], - [1.5678, 0.21345]], - equilateralTriangle = [ - [0, Math.sqrt(3) / 3], - [-0.5, -Math.sqrt(3) / 6], - [0.5, -Math.sqrt(3) / 6]], - - zigzag = [ // 4 * - [0, 0], [2, 1], // \-. - [0, 1], [2, 2], // 3 * * - [1, 2], [3, 3], // ,-' | - [2, 4], [4, 3], // 2 *-* | - [4, 0]], // ,-' | + var squareCW = [[0, 0], [0, 1], [1, 1], [1, 0]]; + var squareCCW = [[0, 0], [1, 0], [1, 1], [0, 1]]; + var bowtie = [[0, 0], [0, 1], [1, 0], [1, 1]]; + var squareish = [ + [-0.123, -0.0456], + [0.12345, 1.2345], + [1.3456, 1.4567], + [1.5678, 0.21345]]; + var equilateralTriangle = [ + [0, Math.sqrt(3) / 3], + [-0.5, -Math.sqrt(3) / 6], + [0.5, -Math.sqrt(3) / 6]]; + + var zigzag = [ // 4 * + [0, 0], [2, 1], // \-. + [0, 1], [2, 2], // 3 * * + [1, 2], [3, 3], // ,-' | + [2, 4], [4, 3], // 2 *-* | + [4, 0]]; // ,-' | // 1 *---* | // ,-' | // 0 *-------* // 0 1 2 3 4 - inZigzag = [ - [0.5, 0.01], [1, 0.49], [1.5, 0.5], [2, 0.5], [2.5, 0.5], [3, 0.5], - [3.5, 0.5], [0.5, 1.01], [1, 1.49], [1.5, 1.5], [2, 1.5], [2.5, 1.5], - [3, 1.5], [3.5, 1.5], [1.5, 2.01], [2, 2.49], [2.5, 2.5], [3, 2.5], - [3.5, 2.5], [2.5, 3.51], [3, 3.49]], - notInZigzag = [ - [0, -0.01], [0, 0.01], [0, 0.99], [0, 1.01], [0.5, -0.01], [0.5, 0.26], - [0.5, 0.99], [0.5, 1.26], [1, -0.01], [1, 0.51], [1, 0.99], [1, 1.51], - [1, 1.99], [1, 2.01], [2, -0.01], [2, 2.51], [2, 3.99], [2, 4.01], - [3, -0.01], [2.99, 3], [3, 3.51], [4, -0.01], [4, 3.01]], - - donut = [ // inner CCW, outer CW // 3 *-----* - [3, 0], [0, 0], [0, 1], [2, 1], [2, 2], // | | - [1, 2], [1, 1], [0, 1], [0, 3], [3, 3]], // 2 | *-* | - donut2 = [ // inner CCW, outer CCW // | | | | - [3, 3], [0, 3], [0, 1], [2, 1], [2, 2], // 1 *-*-* | - [1, 2], [1, 1], [0, 1], [0, 0], [3, 0]], // | | - // 0 *-----* - // 0 1 2 3 - inDonut = [[0.5, 0.5], [1, 0.5], [1.5, 0.5], [2, 0.5], [2.5, 0.5], - [2.5, 1], [2.5, 1.5], [2.5, 2], [2.5, 2.5], [2, 2.5], [1.5, 2.5], - [1, 2.5], [0.5, 2.5], [0.5, 2], [0.5, 1.5], [0.5, 1]], - notInDonut = [[1.5, -0.5], [1.5, 1.5], [1.5, 3.5], [-0.5, 1.5], [3.5, 1.5]]; + var inZigzag = [ + [0.5, 0.01], [1, 0.49], [1.5, 0.5], [2, 0.5], [2.5, 0.5], [3, 0.5], + [3.5, 0.5], [0.5, 1.01], [1, 1.49], [1.5, 1.5], [2, 1.5], [2.5, 1.5], + [3, 1.5], [3.5, 1.5], [1.5, 2.01], [2, 2.49], [2.5, 2.5], [3, 2.5], + [3.5, 2.5], [2.5, 3.51], [3, 3.49]]; + var notInZigzag = [ + [0, -0.01], [0, 0.01], [0, 0.99], [0, 1.01], [0.5, -0.01], [0.5, 0.26], + [0.5, 0.99], [0.5, 1.26], [1, -0.01], [1, 0.51], [1, 0.99], [1, 1.51], + [1, 1.99], [1, 2.01], [2, -0.01], [2, 2.51], [2, 3.99], [2, 4.01], + [3, -0.01], [2.99, 3], [3, 3.51], [4, -0.01], [4, 3.01]]; + + var donut = [ // inner CCW, outer CW // 3 *-----* + [3, 0], [0, 0], [0, 1], [2, 1], [2, 2], // | | + [1, 2], [1, 1], [0, 1], [0, 3], [3, 3]]; // 2 | *-* | + var donut2 = [ // inner CCW, outer CCW // | | | | + [3, 3], [0, 3], [0, 1], [2, 1], [2, 2], // 1 *-*-* | + [1, 2], [1, 1], [0, 1], [0, 0], [3, 0]]; // | | + // 0 *-----* + // 0 1 2 3 + var inDonut = [[0.5, 0.5], [1, 0.5], [1.5, 0.5], [2, 0.5], [2.5, 0.5], + [2.5, 1], [2.5, 1.5], [2.5, 2], [2.5, 2.5], [2, 2.5], [1.5, 2.5], + [1, 2.5], [0.5, 2.5], [0.5, 2], [0.5, 1.5], [0.5, 1]]; + var notInDonut = [[1.5, -0.5], [1.5, 1.5], [1.5, 3.5], [-0.5, 1.5], [3.5, 1.5]]; it('should exclude points outside the bounding box', function() { var poly = polygonTester([[1, 2], [3, 4]]); @@ -68,9 +69,9 @@ describe('polygon.tester', function() { zigzag, donut, donut2]; polyPts.forEach(function(polyPt) { - var poly = polygonTester(polyPt), - xArray = polyPt.map(function(pt) { return pt[0]; }), - yArray = polyPt.map(function(pt) { return pt[1]; }); + var poly = polygonTester(polyPt); + var xArray = polyPt.map(function(pt) { return pt[0]; }); + var yArray = polyPt.map(function(pt) { return pt[1]; }); expect(poly.pts.length).toEqual(polyPt.length + 1); polyPt.forEach(function(pt, i) { @@ -99,8 +100,8 @@ describe('polygon.tester', function() { poly.pts.forEach(function(pt1, i) { if(!i) return; - var pt0 = poly.pts[i - 1], - j; + var pt0 = poly.pts[i - 1]; + var j; var testPts = [pt0, pt1]; for(j = 1; j < np; j++) { @@ -138,8 +139,8 @@ describe('polygon.tester', function() { expect(zzpoly.contains(pt)).toBe(false); }); - var donutpoly = polygonTester(donut), - donut2poly = polygonTester(donut2); + var donutpoly = polygonTester(donut); + var donut2poly = polygonTester(donut2); inDonut.forEach(function(pt) { expect(donutpoly.contains(pt)).toBe(true); expect(donut2poly.contains(pt)).toBe(true); @@ -199,8 +200,8 @@ describe('polygon.filter', function() { }); it('should give the right result if points are added one-by-one', function() { - var p = filter([pts[0]], 0.5), - i; + var p = filter([pts[0]], 0.5); + var i; // intermediate result (the last point isn't in the final) for(i = 1; i < 6; i++) p.addPt(pts[i]); diff --git a/test/jasmine/tests/range_slider_test.js b/test/jasmine/tests/range_slider_test.js index 9af77a25fb8..99941269ce5 100644 --- a/test/jasmine/tests/range_slider_test.js +++ b/test/jasmine/tests/range_slider_test.js @@ -69,8 +69,8 @@ describe('Visible rangesliders', function() { plotMock().then(function() { var bg = getRangeSliderChild(0); - var options = mock.layout.xaxis.rangeslider, - expectedWidth = gd._fullLayout._size.w + options.borderwidth; + var options = mock.layout.xaxis.rangeslider; + var expectedWidth = gd._fullLayout._size.w + options.borderwidth; // width incorporates border widths expect(+bg.getAttribute('width')).toEqual(expectedWidth); @@ -101,9 +101,9 @@ describe('Visible rangesliders', function() { }); it('should react to resizing the minimum handle', function(done) { - var start = 85, - end = 140, - diff = end - start; + var start = 85; + var end = 140; + var diff = end - start; plotMock().then(function() { expect(gd.layout.xaxis.range).toBeCloseToArray([0, 49]); @@ -111,8 +111,8 @@ describe('Visible rangesliders', function() { return slide(start, sliderY, end, sliderY); }) .then(function() { - var maskMin = getRangeSliderChild(2), - handleMin = getRangeSliderChild(5); + var maskMin = getRangeSliderChild(2); + var handleMin = getRangeSliderChild(5); expect(gd.layout.xaxis.range).toBeCloseToArray([4, 49], -0.5); expect(maskMin.getAttribute('width')).toEqual(String(diff)); @@ -137,8 +137,8 @@ describe('Visible rangesliders', function() { return slide(start, sliderY, end, sliderY); }) .then(function() { - var maskMax = getRangeSliderChild(3), - handleMax = getRangeSliderChild(6); + var maskMax = getRangeSliderChild(3); + var handleMax = getRangeSliderChild(6); expect(gd.layout.xaxis.range).toBeCloseToArray([0, 32.77], -0.5); expect(+maskMax.getAttribute('width')).toBeCloseTo(-diff); @@ -164,8 +164,8 @@ describe('Visible rangesliders', function() { return slide(start, sliderY, end, sliderY); }) .then(function() { - var maskMin = getRangeSliderChild(2), - handleMin = getRangeSliderChild(5); + var maskMin = getRangeSliderChild(2); + var handleMin = getRangeSliderChild(5); expect(gd.layout.xaxis.range).toBeCloseToArray([3.96, 49], -0.5); expect(+maskMin.getAttribute('width')).toBeCloseTo(String(diff)); @@ -190,8 +190,8 @@ describe('Visible rangesliders', function() { return slide(start, sliderY, end, sliderY); }) .then(function() { - var maskMax = getRangeSliderChild(3), - handleMax = getRangeSliderChild(6); + var maskMax = getRangeSliderChild(3); + var handleMax = getRangeSliderChild(6); expect(gd.layout.xaxis.range).toBeCloseToArray([0, 45.04], -0.5); expect(+maskMax.getAttribute('width')).toBeCloseTo(-diff); @@ -236,10 +236,10 @@ describe('Visible rangesliders', function() { return Plotly.relayout(gd, 'xaxis.range', [10, 20]); }) .then(function() { - var maskMin = getRangeSliderChild(2), - maskMax = getRangeSliderChild(3), - handleMin = getRangeSliderChild(5), - handleMax = getRangeSliderChild(6); + var maskMin = getRangeSliderChild(2); + var maskMax = getRangeSliderChild(3); + var handleMin = getRangeSliderChild(5); + var handleMax = getRangeSliderChild(6); expect(+maskMin.getAttribute('width')).toBeWithin(125, TOL); expect(+maskMax.getAttribute('width')).toBeWithin(365, TOL); @@ -255,10 +255,10 @@ describe('Visible rangesliders', function() { return Plotly.relayout(gd, 'xaxis.range[0]', 10); }) .then(function() { - var maskMin = getRangeSliderChild(2), - maskMax = getRangeSliderChild(3), - handleMin = getRangeSliderChild(5), - handleMax = getRangeSliderChild(6); + var maskMin = getRangeSliderChild(2); + var maskMax = getRangeSliderChild(3); + var handleMin = getRangeSliderChild(5); + var handleMax = getRangeSliderChild(6); expect(+maskMin.getAttribute('width')).toBeWithin(126, TOL); expect(+maskMax.getAttribute('width')).toEqual(0); @@ -333,8 +333,8 @@ describe('Visible rangesliders', function() { return Plotly.relayout(gd, 'xaxis.domain', [0.3, 0.7]); }) .then(function() { - var maskMin = getRangeSliderChild(2), - maskMax = getRangeSliderChild(3); + var maskMin = getRangeSliderChild(2); + var maskMax = getRangeSliderChild(3); expect(+maskMin.getAttribute('width')).toBeWithin(25.26, TOL); expect(+maskMax.getAttribute('width')).toBeWithin(197.06, TOL); @@ -342,8 +342,8 @@ describe('Visible rangesliders', function() { return Plotly.relayout(gd, 'width', 400); }) .then(function() { - var maskMin = getRangeSliderChild(2), - maskMax = getRangeSliderChild(3); + var maskMin = getRangeSliderChild(2); + var maskMax = getRangeSliderChild(3); expect(+maskMin.getAttribute('width')).toBeWithin(9.22, TOL); expect(+maskMax.getAttribute('width')).toBeWithin(71.95, TOL); @@ -573,9 +573,9 @@ describe('Rangeslider handleDefaults function', function() { } it('should not coerce anything if rangeslider isn\'t set', function() { - var layoutIn = { xaxis: {} }, - layoutOut = { xaxis: {} }, - expected = { xaxis: {} }; + var layoutIn = { xaxis: {} }; + var layoutOut = { xaxis: {} }; + var expected = { xaxis: {} }; _supply(layoutIn, layoutOut, 'xaxis'); expect(layoutIn).toEqual(expected); @@ -583,43 +583,43 @@ describe('Rangeslider handleDefaults function', function() { }); it('should not mutate layoutIn', function() { - var layoutIn = { xaxis: { rangeslider: { visible: true }} }, - layoutOut = { xaxis: { rangeslider: {}} }, - expected = { xaxis: { rangeslider: { visible: true}} }; + var layoutIn = { xaxis: { rangeslider: { visible: true }} }; + var layoutOut = { xaxis: { rangeslider: {}} }; + var expected = { xaxis: { rangeslider: { visible: true}} }; _supply(layoutIn, layoutOut, 'xaxis'); expect(layoutIn).toEqual(expected); }); it('should set defaults if rangeslider is set to anything truthy', function() { - var layoutIn = { xaxis: { rangeslider: {} }}, - layoutOut = { xaxis: {} }, - expected = { - visible: true, - autorange: true, - thickness: 0.15, - bgcolor: '#fff', - borderwidth: 0, - bordercolor: '#444', - _input: layoutIn.xaxis.rangeslider - }; + var layoutIn = { xaxis: { rangeslider: {} }}; + var layoutOut = { xaxis: {} }; + var expected = { + visible: true, + autorange: true, + thickness: 0.15, + bgcolor: '#fff', + borderwidth: 0, + bordercolor: '#444', + _input: layoutIn.xaxis.rangeslider + }; _supply(layoutIn, layoutOut, 'xaxis'); expect(layoutOut.xaxis.rangeslider).toEqual(jasmine.objectContaining(expected)); }); it('should set defaults if rangeslider is requested', function() { - var layoutIn = { xaxis: {}}, - layoutOut = { xaxis: {}, _requestRangeslider: {x: true} }, - expected = { - visible: true, - autorange: true, - thickness: 0.15, - bgcolor: '#fff', - borderwidth: 0, - bordercolor: '#444', - _input: {} - }; + var layoutIn = { xaxis: {}}; + var layoutOut = { xaxis: {}, _requestRangeslider: {x: true} }; + var expected = { + visible: true, + autorange: true, + thickness: 0.15, + bgcolor: '#fff', + borderwidth: 0, + bordercolor: '#444', + _input: {} + }; _supply(layoutIn, layoutOut, 'xaxis'); // in fact we DO mutate layoutIn - which we should probably try not to do, @@ -630,25 +630,25 @@ describe('Rangeslider handleDefaults function', function() { }); it('should set defaults if rangeslider.visible is true', function() { - var layoutIn = { xaxis: { rangeslider: { visible: true }} }, - layoutOut = { xaxis: { rangeslider: {}} }, - expected = { - visible: true, - autorange: true, - thickness: 0.15, - bgcolor: '#fff', - borderwidth: 0, - bordercolor: '#444', - _input: layoutIn.xaxis.rangeslider - }; + var layoutIn = { xaxis: { rangeslider: { visible: true }} }; + var layoutOut = { xaxis: { rangeslider: {}} }; + var expected = { + visible: true, + autorange: true, + thickness: 0.15, + bgcolor: '#fff', + borderwidth: 0, + bordercolor: '#444', + _input: layoutIn.xaxis.rangeslider + }; _supply(layoutIn, layoutOut, 'xaxis'); expect(layoutOut.xaxis.rangeslider).toEqual(jasmine.objectContaining(expected)); }); it('should return early if *visible: false*', function() { - var layoutIn = { xaxis: { rangeslider: { visible: false, range: [10, 20] }} }, - layoutOut = { xaxis: { rangeslider: {}} }; + var layoutIn = { xaxis: { rangeslider: { visible: false, range: [10, 20] }} }; + var layoutOut = { xaxis: { rangeslider: {}} }; _supply(layoutIn, layoutOut, 'xaxis'); expect(layoutOut.xaxis.rangeslider).toEqual(jasmine.objectContaining({ visible: false })); @@ -656,39 +656,39 @@ describe('Rangeslider handleDefaults function', function() { it('should set defaults if properties are invalid', function() { var layoutIn = { xaxis: { rangeslider: { - visible: 'invalid', - thickness: 'invalid', - bgcolor: 42, - bordercolor: 42, - borderwidth: 'superfat' - }}}, - layoutOut = { xaxis: {} }, - expected = { - visible: true, - autorange: true, - thickness: 0.15, - bgcolor: '#fff', - borderwidth: 0, - bordercolor: '#444', - _input: layoutIn.xaxis.rangeslider - }; + visible: 'invalid', + thickness: 'invalid', + bgcolor: 42, + bordercolor: 42, + borderwidth: 'superfat' + }}}; + var layoutOut = { xaxis: {} }; + var expected = { + visible: true, + autorange: true, + thickness: 0.15, + bgcolor: '#fff', + borderwidth: 0, + bordercolor: '#444', + _input: layoutIn.xaxis.rangeslider + }; _supply(layoutIn, layoutOut, 'xaxis'); expect(layoutOut.xaxis.rangeslider).toEqual(jasmine.objectContaining(expected)); }); it('should set autorange to true when range input is invalid', function() { - var layoutIn = { xaxis: { rangeslider: { range: 'not-gonna-work'}} }, - layoutOut = { xaxis: {} }, - expected = { - visible: true, - autorange: true, - thickness: 0.15, - bgcolor: '#fff', - borderwidth: 0, - bordercolor: '#444', - _input: layoutIn.xaxis.rangeslider - }; + var layoutIn = { xaxis: { rangeslider: { range: 'not-gonna-work'}} }; + var layoutOut = { xaxis: {} }; + var expected = { + visible: true, + autorange: true, + thickness: 0.15, + bgcolor: '#fff', + borderwidth: 0, + bordercolor: '#444', + _input: layoutIn.xaxis.rangeslider + }; _supply(layoutIn, layoutOut, 'xaxis'); expect(layoutOut.xaxis.rangeslider).toEqual(jasmine.objectContaining(expected)); diff --git a/test/jasmine/tests/sankey_test.js b/test/jasmine/tests/sankey_test.js index 4f881126619..27a19406860 100644 --- a/test/jasmine/tests/sankey_test.js +++ b/test/jasmine/tests/sankey_test.js @@ -19,9 +19,9 @@ describe('sankey tests', function() { 'use strict'; function _supply(traceIn) { - var traceOut = { visible: true }, - defaultColor = '#444', - layout = { colorway: defaultColors }; + var traceOut = { visible: true }; + var defaultColor = '#444'; + var layout = { colorway: defaultColors }; Sankey.supplyDefaults(traceIn, traceOut, defaultColor, layout); @@ -29,8 +29,8 @@ describe('sankey tests', function() { } function _supplyWithLayout(traceIn, layout) { - var traceOut = { visible: true }, - defaultColor = '#444'; + var traceOut = { visible: true }; + var defaultColor = '#444'; Sankey.supplyDefaults(traceIn, traceOut, defaultColor, Lib.extendFlat({colorway: defaultColors}, layout)); @@ -394,8 +394,8 @@ describe('sankey tests', function() { Lib.clearThrottle(); } - var node = [404, 302], - link = [450, 300]; + var node = [404, 302]; + var link = [450, 300]; it('should show the correct hover labels', function(done) { var gd = createGraphDiv(); diff --git a/test/jasmine/tests/scatter3d_test.js b/test/jasmine/tests/scatter3d_test.js index 7518da16166..0c610773274 100644 --- a/test/jasmine/tests/scatter3d_test.js +++ b/test/jasmine/tests/scatter3d_test.js @@ -9,8 +9,8 @@ describe('Scatter3D defaults', function() { var defaultColor = '#d3d3d3'; function _supply(traceIn, layoutEdits) { - var traceOut = { visible: true }, - layout = Lib.extendFlat({ _dataLength: 1 }, layoutEdits); + var traceOut = { visible: true }; + var layout = Lib.extendFlat({ _dataLength: 1 }, layoutEdits); Scatter3D.supplyDefaults(traceIn, traceOut, defaultColor, layout); return traceOut; diff --git a/test/jasmine/tests/scatter_test.js b/test/jasmine/tests/scatter_test.js index 6e97b1531b1..1ef16594a3d 100644 --- a/test/jasmine/tests/scatter_test.js +++ b/test/jasmine/tests/scatter_test.js @@ -30,11 +30,11 @@ describe('Test scatter', function() { 'use strict'; describe('supplyDefaults', function() { - var traceIn, - traceOut; + var traceIn; + var traceOut; - var defaultColor = '#444', - layout = {}; + var defaultColor = '#444'; + var layout = {}; var supplyDefaults = Scatter.supplyDefaults; @@ -274,44 +274,44 @@ describe('Test scatter', function() { describe('isBubble', function() { it('should return true when marker.size is an Array', function() { var trace = { - marker: { - size: [1, 4, 2, 10] - } - }, - isBubble = Scatter.isBubble(trace); + marker: { + size: [1, 4, 2, 10] + } + }; + var isBubble = Scatter.isBubble(trace); expect(isBubble).toBe(true); }); it('should return false when marker.size is an number', function() { var trace = { - marker: { - size: 10 - } - }, - isBubble = Scatter.isBubble(trace); + marker: { + size: 10 + } + }; + var isBubble = Scatter.isBubble(trace); expect(isBubble).toBe(false); }); it('should return false when marker.size is not defined', function() { var trace = { - marker: { - color: 'red' - } - }, - isBubble = Scatter.isBubble(trace); + marker: { + color: 'red' + } + }; + var isBubble = Scatter.isBubble(trace); expect(isBubble).toBe(false); }); it('should return false when marker is not defined', function() { var trace = { - line: { - color: 'red' - } - }, - isBubble = Scatter.isBubble(trace); + line: { + color: 'red' + } + }; + var isBubble = Scatter.isBubble(trace); expect(isBubble).toBe(false); }); @@ -320,10 +320,10 @@ describe('Test scatter', function() { describe('makeBubbleSizeFn', function() { var markerSizes = [ - 0, '1', 2.21321321, 'not-a-number', - 100, 1000.213213, 1e7, undefined, null, -100 - ], - trace = { marker: {} }; + 0, '1', 2.21321321, 'not-a-number', + 100, 1000.213213, 1e7, undefined, null, -100 + ]; + var trace = { marker: {} }; var sizeFn, expected; @@ -374,15 +374,15 @@ describe('Test scatter', function() { describe('linePoints', function() { // test axes are unit-scaled and 100 units long - var ax = {_length: 100, c2p: Lib.identity}, - baseOpts = { - xaxis: ax, - yaxis: ax, - connectGaps: false, - baseTolerance: 1, - shape: 'linear', - simplify: true - }; + var ax = {_length: 100, c2p: Lib.identity}; + var baseOpts = { + xaxis: ax, + yaxis: ax, + connectGaps: false, + baseTolerance: 1, + shape: 'linear', + simplify: true + }; function makeCalcData(ptsIn) { return ptsIn.map(function(pt) { diff --git a/test/jasmine/tests/scattergeo_test.js b/test/jasmine/tests/scattergeo_test.js index 50c70e48704..e8b76b1a34a 100644 --- a/test/jasmine/tests/scattergeo_test.js +++ b/test/jasmine/tests/scattergeo_test.js @@ -19,8 +19,8 @@ describe('Test scattergeo defaults', function() { var traceIn, traceOut; - var defaultColor = '#444', - layout = {}; + var defaultColor = '#444'; + var layout = {}; beforeEach(function() { traceOut = {}; diff --git a/test/jasmine/tests/scattermapbox_test.js b/test/jasmine/tests/scattermapbox_test.js index 7293b2bb5e5..aecc2480750 100644 --- a/test/jasmine/tests/scattermapbox_test.js +++ b/test/jasmine/tests/scattermapbox_test.js @@ -29,9 +29,9 @@ describe('scattermapbox defaults', function() { 'use strict'; function _supply(traceIn) { - var traceOut = { visible: true }, - defaultColor = '#444', - layout = { _dataLength: 1 }; + var traceOut = { visible: true }; + var defaultColor = '#444'; + var layout = { _dataLength: 1 }; ScatterMapbox.supplyDefaults(traceIn, traceOut, defaultColor, layout); @@ -418,11 +418,11 @@ describe('scattermapbox convert', function() { assertVisibility(opts, ['visible', 'visible', 'visible', 'none']); - var segment1 = [[10, 20], [20, 20], [30, 10]], - segment2 = [[20, 10], [10, 20]]; + var segment1 = [[10, 20], [20, 20], [30, 10]]; + var segment2 = [[20, 10], [10, 20]]; - var lineCoords = [segment1, segment2], - fillCoords = [[segment1], [segment2]]; + var lineCoords = [segment1, segment2]; + var fillCoords = [[segment1], [segment2]]; expect(opts.line.geojson.coordinates).toEqual(lineCoords, 'line coords'); expect(opts.fill.geojson.coordinates).toEqual(fillCoords, 'fill coords'); @@ -602,8 +602,8 @@ describe('@noCI scattermapbox hover', function() { } it('should generate hover label info (base case)', function() { - var xval = 11, - yval = 11; + var xval = 11; + var yval = 11; var out = hoverPoints(getPointData(gd), xval, yval)[0]; @@ -629,9 +629,9 @@ describe('@noCI scattermapbox hover', function() { }); it('should skip over blank and non-string text items', function(done) { - var xval = 11, - yval = 11, - out; + var xval = 11; + var yval = 11; + var out; Plotly.restyle(gd, 'text', [['', 'B', 'C']]).then(function() { out = hoverPoints(getPointData(gd), xval, yval)[0]; @@ -659,8 +659,8 @@ describe('@noCI scattermapbox hover', function() { }); it('should generate hover label info (positive winding case)', function() { - var xval = 11 + 720, - yval = 11; + var xval = 11 + 720; + var yval = 11; var out = hoverPoints(getPointData(gd), xval, yval)[0]; @@ -673,8 +673,8 @@ describe('@noCI scattermapbox hover', function() { }); it('should generate hover label info (negative winding case)', function() { - var xval = 11 - 1080, - yval = 11; + var xval = 11 - 1080; + var yval = 11; var out = hoverPoints(getPointData(gd), xval, yval)[0]; @@ -688,8 +688,8 @@ describe('@noCI scattermapbox hover', function() { it('should generate hover label info (hoverinfo: \'lon\' case)', function(done) { Plotly.restyle(gd, 'hoverinfo', 'lon').then(function() { - var xval = 11, - yval = 11; + var xval = 11; + var yval = 11; var out = hoverPoints(getPointData(gd), xval, yval)[0]; @@ -700,8 +700,8 @@ describe('@noCI scattermapbox hover', function() { it('should generate hover label info (hoverinfo: \'lat\' case)', function(done) { Plotly.restyle(gd, 'hoverinfo', 'lat').then(function() { - var xval = 11, - yval = 11; + var xval = 11; + var yval = 11; var out = hoverPoints(getPointData(gd), xval, yval)[0]; @@ -712,8 +712,8 @@ describe('@noCI scattermapbox hover', function() { it('should generate hover label info (hoverinfo: \'text\' + \'text\' array case)', function(done) { Plotly.restyle(gd, 'hoverinfo', 'text').then(function() { - var xval = 11, - yval = 11; + var xval = 11; + var yval = 11; var out = hoverPoints(getPointData(gd), xval, yval)[0]; @@ -724,8 +724,8 @@ describe('@noCI scattermapbox hover', function() { it('should generate hover label info (hoverinfo: \'text\' + \'hovertext\' array case)', function(done) { Plotly.restyle(gd, 'hovertext', ['Apple', 'Banana', 'Orange']).then(function() { - var xval = 11, - yval = 11; + var xval = 11; + var yval = 11; var out = hoverPoints(getPointData(gd), xval, yval)[0]; @@ -820,8 +820,8 @@ describe('@noCI Test plotly events on a scattermapbox plot:', function() { it('should contain the correct fields', function() { click(pointPos[0], pointPos[1]); - var pt = futureData.points[0], - evt = futureData.event; + var pt = futureData.points[0]; + var evt = futureData.event; expect(Object.keys(pt)).toEqual([ 'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex', 'lon', 'lat' diff --git a/test/jasmine/tests/scatterternary_test.js b/test/jasmine/tests/scatterternary_test.js index 03fcffc71c0..d5e10ae289d 100644 --- a/test/jasmine/tests/scatterternary_test.js +++ b/test/jasmine/tests/scatterternary_test.js @@ -19,8 +19,8 @@ describe('scatterternary defaults', function() { var traceIn, traceOut; - var defaultColor = '#444', - layout = {}; + var defaultColor = '#444'; + var layout = {}; beforeEach(function() { traceOut = {}; diff --git a/test/jasmine/tests/shapes_test.js b/test/jasmine/tests/shapes_test.js index b096b925570..0c0ef5d0956 100644 --- a/test/jasmine/tests/shapes_test.js +++ b/test/jasmine/tests/shapes_test.js @@ -98,8 +98,8 @@ describe('Test shapes defaults:', function() { Axes.setConvert(fullLayout.xaxis2); Axes.setConvert(fullLayout.yaxis2); - var shape1In = {type: 'rect'}, - shape2In = {type: 'circle', xref: 'x2', yref: 'y2'}; + var shape1In = {type: 'rect'}; + var shape2In = {type: 'circle', xref: 'x2', yref: 'y2'}; var layoutIn = { shapes: [shape1In, shape2In] @@ -107,8 +107,8 @@ describe('Test shapes defaults:', function() { _supply(layoutIn, fullLayout); - var shape1Out = fullLayout.shapes[0], - shape2Out = fullLayout.shapes[1]; + var shape1Out = fullLayout.shapes[0]; + var shape2Out = fullLayout.shapes[1]; // default positions are 1/4 and 3/4 of the full range of that axis expect(shape1Out.x0).toBe(5); @@ -190,8 +190,8 @@ describe('Test shapes:', function() { beforeEach(function(done) { gd = createGraphDiv(); - var mockData = Lib.extendDeep([], mock.data), - mockLayout = Lib.extendDeep({}, mock.layout); + var mockData = Lib.extendDeep([], mock.data); + var mockLayout = Lib.extendDeep({}, mock.layout); Plotly.plot(gd, mockData, mockLayout).then(done); }); @@ -384,11 +384,11 @@ describe('Test shapes:', function() { }); it('should be able to update a shape layer', function(done) { - var index = countShapes(gd), - astr = 'shapes[' + index + ']', - shape = getRandomShape(), - shapesInLowerLayer = countShapePathsInLowerLayer(), - shapesInUpperLayer = countShapePathsInUpperLayer(); + var index = countShapes(gd); + var astr = 'shapes[' + index + ']'; + var shape = getRandomShape(); + var shapesInLowerLayer = countShapePathsInLowerLayer(); + var shapesInUpperLayer = countShapePathsInUpperLayer(); shape.xref = 'paper'; shape.yref = 'paper'; @@ -1344,14 +1344,14 @@ describe('Test shapes', function() { function setupLayout(testCase, layoutShapes) { Lib.extendDeep(layout, testCase); - var xrange = testCase.xaxis ? testCase.xaxis.range : [0.25, 0.75], - yrange = testCase.yaxis ? testCase.yaxis.range : [0.25, 0.75], - xref = testCase.xaxis ? 'x' : 'paper', - yref = testCase.yaxis ? 'y' : 'paper', - x0 = xrange[0], - x1 = xrange[1], - y0 = yrange[0], - y1 = yrange[1]; + var xrange = testCase.xaxis ? testCase.xaxis.range : [0.25, 0.75]; + var yrange = testCase.yaxis ? testCase.yaxis.range : [0.25, 0.75]; + var xref = testCase.xaxis ? 'x' : 'paper'; + var yref = testCase.yaxis ? 'y' : 'paper'; + var x0 = xrange[0]; + var x1 = xrange[1]; + var y0 = yrange[0]; + var y1 = yrange[1]; if(testCase.xaxis && testCase.xaxis.type === 'log') { x0 = Math.pow(10, x0); @@ -1373,9 +1373,9 @@ describe('Test shapes', function() { y1 = 1; } - var x0y0 = x0 + ',' + y0, - x1y1 = x1 + ',' + y1, - x1y0 = x1 + ',' + y0; + var x0y0 = x0 + ',' + y0; + var x1y1 = x1 + ',' + y1; + var x1y0 = x1 + ',' + y0; layoutShapes.forEach(function(s) { s.xref = xref; @@ -1403,8 +1403,8 @@ describe('Test shapes', function() { expect(layoutShapes.length).toBe(4); // line, rect, circle and path layoutShapes.forEach(function(layoutShape, index) { - var dx = 100, - dy = 100; + var dx = 100; + var dy = 100; promise = promise.then(function() { var node = layoutShape.type === 'line' ? getMoveLineDragElement(index) : @@ -1432,8 +1432,8 @@ describe('Test shapes', function() { layoutShapes.forEach(function(layoutShape, index) { if(layoutShape.path) return; - var dx = dxToShrinkWidth[direction], - dy = dyToShrinkHeight[direction]; + var dx = dxToShrinkWidth[direction]; + var dy = dyToShrinkHeight[direction]; promise = promise.then(function() { var node = getShapeNode(index); @@ -1460,10 +1460,10 @@ describe('Test shapes', function() { } function testShapeDrag(dx, dy, layoutShape, node) { - var xa = Axes.getFromId(gd, layoutShape.xref), - ya = Axes.getFromId(gd, layoutShape.yref), - x2p = helpers.getDataToPixel(gd, xa), - y2p = helpers.getDataToPixel(gd, ya, true); + var xa = Axes.getFromId(gd, layoutShape.xref); + var ya = Axes.getFromId(gd, layoutShape.yref); + var x2p = helpers.getDataToPixel(gd, xa); + var y2p = helpers.getDataToPixel(gd, ya, true); var initialCoordinates = getShapeCoordinates(layoutShape, x2p, y2p); @@ -1487,25 +1487,25 @@ describe('Test shapes', function() { } function testPathDrag(dx, dy, layoutShape, node) { - var xa = Axes.getFromId(gd, layoutShape.xref), - ya = Axes.getFromId(gd, layoutShape.yref), - x2p = helpers.getDataToPixel(gd, xa), - y2p = helpers.getDataToPixel(gd, ya, true); + var xa = Axes.getFromId(gd, layoutShape.xref); + var ya = Axes.getFromId(gd, layoutShape.yref); + var x2p = helpers.getDataToPixel(gd, xa); + var y2p = helpers.getDataToPixel(gd, ya, true); - var initialPath = layoutShape.path, - initialCoordinates = getPathCoordinates(initialPath, x2p, y2p); + var initialPath = layoutShape.path; + var initialCoordinates = getPathCoordinates(initialPath, x2p, y2p); expect(initialCoordinates.length).toBe(6); return drag(node, dx, dy).then(function() { - var finalPath = layoutShape.path, - finalCoordinates = getPathCoordinates(finalPath, x2p, y2p); + var finalPath = layoutShape.path; + var finalCoordinates = getPathCoordinates(finalPath, x2p, y2p); expect(finalCoordinates.length).toBe(initialCoordinates.length); for(var i = 0; i < initialCoordinates.length; i++) { - var initialCoordinate = initialCoordinates[i], - finalCoordinate = finalCoordinates[i]; + var initialCoordinate = initialCoordinates[i]; + var finalCoordinate = finalCoordinates[i]; if(initialCoordinate.x) { expect(finalCoordinate.x - initialCoordinate.x) @@ -1520,10 +1520,10 @@ describe('Test shapes', function() { } function testShapeResize(direction, dx, dy, layoutShape, node) { - var xa = Axes.getFromId(gd, layoutShape.xref), - ya = Axes.getFromId(gd, layoutShape.yref), - x2p = helpers.getDataToPixel(gd, xa), - y2p = helpers.getDataToPixel(gd, ya, true); + var xa = Axes.getFromId(gd, layoutShape.xref); + var ya = Axes.getFromId(gd, layoutShape.yref); + var x2p = helpers.getDataToPixel(gd, xa); + var y2p = helpers.getDataToPixel(gd, ya, true); var initialCoordinates = getShapeCoordinates(layoutShape, x2p, y2p); @@ -1568,10 +1568,10 @@ describe('Test shapes', function() { var promise = Plotly.plot(gd, data, layout, config); var layoutShape = gd.layout.shapes[0]; - var xa = Axes.getFromId(gd, layoutShape.xref), - ya = Axes.getFromId(gd, layoutShape.yref), - x2p = helpers.getDataToPixel(gd, xa), - y2p = helpers.getDataToPixel(gd, ya, true); + var xa = Axes.getFromId(gd, layoutShape.xref); + var ya = Axes.getFromId(gd, layoutShape.yref); + var x2p = helpers.getDataToPixel(gd, xa); + var y2p = helpers.getDataToPixel(gd, ya, true); promise = promise.then(function() { @@ -1600,12 +1600,12 @@ describe('Test shapes', function() { var coordinates = []; pathString.match(constants.segmentRE).forEach(function(segment) { - var paramNumber = 0, - segmentType = segment.charAt(0), - xParams = constants.paramIsX[segmentType], - yParams = constants.paramIsY[segmentType], - nParams = constants.numParams[segmentType], - params = segment.substr(1).match(constants.paramRE); + var paramNumber = 0; + var segmentType = segment.charAt(0); + var xParams = constants.paramIsX[segmentType]; + var yParams = constants.paramIsY[segmentType]; + var nParams = constants.numParams[segmentType]; + var params = segment.substr(1).match(constants.paramRE); if(params) { params.forEach(function(param) { diff --git a/test/jasmine/tests/snapshot_test.js b/test/jasmine/tests/snapshot_test.js index d7da2aa9d52..3a094c8133c 100644 --- a/test/jasmine/tests/snapshot_test.js +++ b/test/jasmine/tests/snapshot_test.js @@ -207,8 +207,8 @@ describe('Plotly.Snapshot', function() { Plotly.plot(gd, subplotMock.data, subplotMock.layout).then(function() { return Plotly.Snapshot.toSVG(gd); }).then(function(svg) { - var svgDOM = parser.parseFromString(svg, 'image/svg+xml'), - svgElements = svgDOM.getElementsByTagName('svg'); + var svgDOM = parser.parseFromString(svg, 'image/svg+xml'); + var svgElements = svgDOM.getElementsByTagName('svg'); expect(svgElements.length).toBe(1); }).then(done); @@ -218,8 +218,8 @@ describe('Plotly.Snapshot', function() { Plotly.plot(gd, annotationMock.data, annotationMock.layout).then(function() { return Plotly.Snapshot.toSVG(gd); }).then(function(svg) { - var svgDOM = parser.parseFromString(svg, 'image/svg+xml'), - svgElements = svgDOM.getElementsByTagName('svg'); + var svgDOM = parser.parseFromString(svg, 'image/svg+xml'); + var svgElements = svgDOM.getElementsByTagName('svg'); expect(svgElements.length).toBe(1); }).then(done); @@ -240,8 +240,8 @@ describe('Plotly.Snapshot', function() { return Plotly.Snapshot.toSVG(gd); }) .then(function(svg) { - var svgDOM = parser.parseFromString(svg, 'image/svg+xml'), - textElements = svgDOM.getElementsByTagName('text'); + var svgDOM = parser.parseFromString(svg, 'image/svg+xml'); + var textElements = svgDOM.getElementsByTagName('text'); for(var i = 0; i < textElements.length; i++) { expect(textElements[i].style.visibility).toEqual(''); diff --git a/test/jasmine/tests/surface_test.js b/test/jasmine/tests/surface_test.js index d0a02db942d..943189c325b 100644 --- a/test/jasmine/tests/surface_test.js +++ b/test/jasmine/tests/surface_test.js @@ -13,8 +13,8 @@ describe('Test surface', function() { describe('supplyDefaults', function() { var supplyDefaults = Surface.supplyDefaults; - var defaultColor = '#444', - layout = {_dfltTitle: {colorbar: 'cb'}}; + var defaultColor = '#444'; + var layout = {_dfltTitle: {colorbar: 'cb'}}; var traceIn, traceOut; diff --git a/test/jasmine/tests/svg_text_utils_test.js b/test/jasmine/tests/svg_text_utils_test.js index 4720c27369a..3c49cd033d3 100644 --- a/test/jasmine/tests/svg_text_utils_test.js +++ b/test/jasmine/tests/svg_text_utils_test.js @@ -49,8 +49,8 @@ describe('svg+text utils', function() { if(!expectedAttrs) expectedAttrs = {}; - var WHITE_LIST = ['xlink:href', 'xlink:show', 'style', 'target', 'onclick'], - attrs = listAttributes(a.node()); + var WHITE_LIST = ['xlink:href', 'xlink:show', 'style', 'target', 'onclick']; + var attrs = listAttributes(a.node()); // check that no other attribute are found in anchor, // which can be lead to XSS attacks. diff --git a/test/jasmine/tests/table_test.js b/test/jasmine/tests/table_test.js index 4bcaaf8d369..6b15eeb37d5 100644 --- a/test/jasmine/tests/table_test.js +++ b/test/jasmine/tests/table_test.js @@ -69,9 +69,9 @@ describe('table initialization tests', function() { describe('table defaults', function() { function _supply(traceIn) { - var traceOut = { visible: true }, - defaultColor = '#777', - layout = { font: {family: '"Open Sans", verdana, arial, sans-serif', size: 12, color: '#444'} }; + var traceOut = { visible: true }; + var defaultColor = '#777'; + var layout = { font: {family: '"Open Sans", verdana, arial, sans-serif', size: 12, color: '#444'} }; Table.supplyDefaults(traceIn, traceOut, defaultColor, layout); diff --git a/test/jasmine/tests/ternary_test.js b/test/jasmine/tests/ternary_test.js index 7d209b41f8d..f6475dbab1a 100644 --- a/test/jasmine/tests/ternary_test.js +++ b/test/jasmine/tests/ternary_test.js @@ -174,8 +174,8 @@ describe('ternary plots', function() { }); it('should respond to hover interactions by', function() { - var hoverCnt = 0, - unhoverCnt = 0; + var hoverCnt = 0; + var unhoverCnt = 0; var hoverData, unhoverData; @@ -625,8 +625,8 @@ describe('Test event property of interactions on a ternary plot:', function() { var mockCopy, gd; - var blankPos = [10, 10], - pointPos; + var blankPos = [10, 10]; + var pointPos; beforeAll(function(done) { gd = createGraphDiv(); @@ -666,8 +666,8 @@ describe('Test event property of interactions on a ternary plot:', function() { it('should contain the correct fields', function() { click(pointPos[0], pointPos[1]); - var pt = futureData.points[0], - evt = futureData.event; + var pt = futureData.points[0]; + var evt = futureData.event; expect(Object.keys(pt)).toEqual([ 'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex', @@ -777,12 +777,12 @@ describe('Test event property of interactions on a ternary plot:', function() { mouseEvent('mousemove', blankPos[0], blankPos[1]); mouseEvent('mousemove', pointPos[0], pointPos[1]); - var pt = futureData.points[0], - evt = futureData.event, - xaxes0 = futureData.xaxes[0], - xvals0 = futureData.xvals[0], - yaxes0 = futureData.yaxes[0], - yvals0 = futureData.yvals[0]; + var pt = futureData.points[0]; + var evt = futureData.event; + var xaxes0 = futureData.xaxes[0]; + var xvals0 = futureData.xvals[0]; + var yaxes0 = futureData.yaxes[0]; + var yvals0 = futureData.yvals[0]; expect(Object.keys(pt)).toEqual([ 'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex', @@ -825,8 +825,8 @@ describe('Test event property of interactions on a ternary plot:', function() { mouseEvent('mousemove', pointPos[0], pointPos[1]); mouseEvent('mouseout', pointPos[0], pointPos[1]); - var pt = futureData.points[0], - evt = futureData.event; + var pt = futureData.points[0]; + var evt = futureData.event; expect(Object.keys(pt)).toEqual([ 'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex', diff --git a/test/jasmine/tests/titles_test.js b/test/jasmine/tests/titles_test.js index 6696cda814c..a5c99e9e230 100644 --- a/test/jasmine/tests/titles_test.js +++ b/test/jasmine/tests/titles_test.js @@ -1072,11 +1072,11 @@ describe('Editable titles', function() { expect(titleEl.text()).toBe(text); expect(+(titleEl.node().style.opacity || 1)).toBe(opacityOut); - var bb = titleEl.node().getBoundingClientRect(), - xCenter = (bb.left + bb.right) / 2, - yCenter = (bb.top + bb.bottom) / 2, - done, - promise = new Promise(function(resolve) { done = resolve; }); + var bb = titleEl.node().getBoundingClientRect(); + var xCenter = (bb.left + bb.right) / 2; + var yCenter = (bb.top + bb.bottom) / 2; + var done; + var promise = new Promise(function(resolve) { done = resolve; }); mouseEvent('mouseover', xCenter, yCenter); setTimeout(function() { diff --git a/test/jasmine/tests/updatemenus_test.js b/test/jasmine/tests/updatemenus_test.js index af376c3eafb..4513e128681 100644 --- a/test/jasmine/tests/updatemenus_test.js +++ b/test/jasmine/tests/updatemenus_test.js @@ -339,9 +339,9 @@ describe('update menus initialization', function() { describe('update menus interactions', function() { 'use strict'; - var mock = require('@mocks/updatemenus.json'), - bgColor = 'rgb(255, 255, 255)', - activeColor = 'rgb(244, 250, 255)'; + var mock = require('@mocks/updatemenus.json'); + var bgColor = 'rgb(255, 255, 255)'; + var activeColor = 'rgb(244, 250, 255)'; var gd; @@ -443,8 +443,8 @@ describe('update menus interactions', function() { }); it('should drop/fold buttons when clicking on header', function(done) { - var header0 = selectHeader(0), - header1 = selectHeader(1); + var header0 = selectHeader(0); + var header1 = selectHeader(1); click(header0).then(function() { assertMenus([3, 0]); @@ -578,8 +578,8 @@ describe('update menus interactions', function() { }); it('should apply update on button click', function(done) { - var header0 = selectHeader(0), - header1 = selectHeader(1); + var header0 = selectHeader(0); + var header1 = selectHeader(1); assertActive(gd, [1, 2]); @@ -650,8 +650,8 @@ describe('update menus interactions', function() { }); it('should change color on mouse over', function(done) { - var INDEX_0 = 2, - INDEX_1 = gd.layout.updatemenus[1].active; + var INDEX_0 = 2; + var INDEX_1 = gd.layout.updatemenus[1].active; var header0 = selectHeader(0); @@ -807,9 +807,9 @@ describe('update menus interactions', function() { assertNodeCount('.' + constants.containerClassName, 1); assertNodeCount('.' + constants.headerClassName, expectedMenus.length); - var gButton = d3.select('.' + constants.dropdownButtonGroupClassName), - actualActiveIndex = +gButton.attr(constants.menuIndexAttrName), - hasActive = false; + var gButton = d3.select('.' + constants.dropdownButtonGroupClassName); + var actualActiveIndex = +gButton.attr(constants.menuIndexAttrName); + var hasActive = false; expectedMenus.forEach(function(expected, i) { if(expected) { @@ -838,8 +838,8 @@ describe('update menus interactions', function() { } function assertItemDims(node, width, height) { - var rect = node.select('rect'), - actualWidth = +rect.attr('width'); + var rect = node.select('rect'); + var actualWidth = +rect.attr('width'); // must compare with a tolerance as the exact result // is browser/font dependent (via getBBox) @@ -868,14 +868,14 @@ describe('update menus interactions', function() { } function selectHeader(menuIndex) { - var headers = d3.selectAll('.' + constants.headerClassName), - header = d3.select(headers[0][menuIndex]); + var headers = d3.selectAll('.' + constants.headerClassName); + var header = d3.select(headers[0][menuIndex]); return header; } function selectButton(buttonIndex) { - var buttons = d3.selectAll('.' + constants.dropdownButtonClassName), - button = d3.select(buttons[0][buttonIndex]); + var buttons = d3.selectAll('.' + constants.dropdownButtonClassName); + var button = d3.select(buttons[0][buttonIndex]); return button; } }); @@ -1055,14 +1055,14 @@ describe('update menus interaction with scrollbox:', function() { }); it('scrollbox can be dragged', function() { - var deltaX = -50, - deltaY = -100, - scrollBox, - scrollBar, - scrollBoxTranslate0, - scrollBarTranslate0, - scrollBoxTranslate1, - scrollBarTranslate1; + var deltaX = -50; + var deltaY = -100; + var scrollBox; + var scrollBar; + var scrollBoxTranslate0; + var scrollBarTranslate0; + var scrollBoxTranslate1; + var scrollBarTranslate1; scrollBox = getScrollBox(); expect(scrollBox).toBeDefined(); @@ -1129,13 +1129,13 @@ describe('update menus interaction with scrollbox:', function() { }); it('scrollbox handles wheel events', function() { - var deltaY = 100, - scrollBox, - scrollBar, - scrollBoxTranslate0, - scrollBarTranslate0, - scrollBoxTranslate1, - scrollBarTranslate1; + var deltaY = 100; + var scrollBox; + var scrollBar; + var scrollBoxTranslate0; + var scrollBarTranslate0; + var scrollBoxTranslate1; + var scrollBarTranslate1; scrollBox = getScrollBox(); expect(scrollBox).toBeDefined(); @@ -1202,14 +1202,14 @@ describe('update menus interaction with scrollbox:', function() { }); it('scrollbar can be dragged', function() { - var deltaX = 20, - deltaY = 10, - scrollBox, - scrollBar, - scrollBoxPosition0, - scrollBarPosition0, - scrollBoxPosition1, - scrollBarPosition1; + var deltaX = 20; + var deltaY = 10; + var scrollBox; + var scrollBar; + var scrollBoxPosition0; + var scrollBarPosition0; + var scrollBoxPosition1; + var scrollBarPosition1; scrollBox = getScrollBox(); expect(scrollBox).toBeDefined(); @@ -1288,21 +1288,21 @@ describe('update menus interaction with scrollbox:', function() { } function getCenter(node) { - var bbox = getBBox(node), - x = bbox.x + 0.5 * bbox.width, - y = bbox.y + 0.5 * bbox.height; + var bbox = getBBox(node); + var x = bbox.x + 0.5 * bbox.width; + var y = bbox.y + 0.5 * bbox.height; return { x: x, y: y }; } function getScrollBarCenter(scrollBox, scrollBar) { - var scrollBoxTranslate = Drawing.getTranslate(scrollBox), - scrollBarTranslate = Drawing.getTranslate(scrollBar), - translateX = scrollBoxTranslate.x + scrollBarTranslate.x, - translateY = scrollBoxTranslate.y + scrollBarTranslate.y, - center = getCenter(scrollBar), - x = center.x + translateX, - y = center.y + translateY; + var scrollBoxTranslate = Drawing.getTranslate(scrollBox); + var scrollBarTranslate = Drawing.getTranslate(scrollBar); + var translateX = scrollBoxTranslate.x + scrollBarTranslate.x; + var translateY = scrollBoxTranslate.y + scrollBarTranslate.y; + var center = getCenter(scrollBar); + var x = center.x + translateX; + var y = center.y + translateY; return { x: x, y: y }; }