From 293186b2db26a199caf47d7f5e247d7833e07dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 3 Feb 2016 09:39:37 -0500 Subject: [PATCH 1/4] remove dep on internal Plotly in trace modules --- src/traces/bar/calc.js | 6 +-- src/traces/bar/hover.js | 17 ++++---- src/traces/bar/layout_defaults.js | 30 +++++++------- src/traces/bar/set_positions.js | 66 ++++++++++++++++--------------- src/traces/bar/style.js | 8 ++-- src/traces/box/calc.js | 8 ++-- src/traces/box/hover.js | 20 +++++----- src/traces/box/plot.js | 4 +- src/traces/box/set_positions.js | 13 +++--- src/traces/box/style.js | 9 +++-- src/traces/choropleth/plot.js | 11 +++--- src/traces/contour/calc.js | 12 +++--- src/traces/contour/colorbar.js | 6 +-- src/traces/contour/plot.js | 16 ++++---- src/traces/contour/style.js | 6 +-- src/traces/heatmap/calc.js | 19 ++++----- src/traces/heatmap/colorbar.js | 4 +- src/traces/heatmap/hover.js | 10 ++--- src/traces/heatmap/plot.js | 4 +- src/traces/histogram/calc.js | 10 ++--- src/traces/histogram2d/calc.js | 18 ++++----- src/traces/mesh3d/defaults.js | 4 +- src/traces/pie/plot.js | 23 ++++++----- src/traces/scatter/colorbar.js | 8 ++-- src/traces/scattergl/convert.js | 7 ++-- 25 files changed, 175 insertions(+), 164 deletions(-) diff --git a/src/traces/bar/calc.js b/src/traces/bar/calc.js index b60f05a0ef8..5bd3f7fe529 100644 --- a/src/traces/bar/calc.js +++ b/src/traces/bar/calc.js @@ -11,7 +11,7 @@ var isNumeric = require('fast-isnumeric'); -var Plotly = require('../../plotly'); +var Axes = require('../../plots/cartesian/axes'); var hasColorscale = require('../../components/colorscale/has_colorscale'); var colorscaleCalc = require('../../components/colorscale/calc'); @@ -22,8 +22,8 @@ module.exports = function calc(gd, trace) { // note: this logic for choosing orientation is // duplicated in graph_obj->setstyles - var xa = Plotly.Axes.getFromId(gd, trace.xaxis||'x'), - ya = Plotly.Axes.getFromId(gd, trace.yaxis||'y'), + var xa = Axes.getFromId(gd, trace.xaxis||'x'), + ya = Axes.getFromId(gd, trace.yaxis||'y'), orientation = trace.orientation || ((trace.x && !trace.y) ? 'h' : 'v'), pos, size, i; diff --git a/src/traces/bar/hover.js b/src/traces/bar/hover.js index bb3b46c0bae..5d431d8e5b6 100644 --- a/src/traces/bar/hover.js +++ b/src/traces/bar/hover.js @@ -9,7 +9,8 @@ 'use strict'; -var Plotly = require('../../plotly'); +var Fx = require('../../plots/cartesian/graph_interact'); +var ErrorBars = require('../../components/errorbars'); var Color = require('../../components/color'); @@ -32,25 +33,25 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { dx = function(di){ // add a gradient so hovering near the end of a // bar makes it a little closer match - return Plotly.Fx.inbox(di.b-xval, di.x-xval) + (di.x-xval)/(di.x-di.b); + return Fx.inbox(di.b-xval, di.x-xval) + (di.x-xval)/(di.x-di.b); }; dy = function(di){ var centerPos = barPos(di) - yval; - return Plotly.Fx.inbox(centerPos - barDelta, centerPos + barDelta); + return Fx.inbox(centerPos - barDelta, centerPos + barDelta); }; } else { dy = function(di){ - return Plotly.Fx.inbox(di.b-yval, di.y-yval) + (di.y-yval)/(di.y-di.b); + return Fx.inbox(di.b-yval, di.y-yval) + (di.y-yval)/(di.y-di.b); }; dx = function(di){ var centerPos = barPos(di) - xval; - return Plotly.Fx.inbox(centerPos - barDelta, centerPos + barDelta); + return Fx.inbox(centerPos - barDelta, centerPos + barDelta); }; } - var distfn = Plotly.Fx.getDistanceFunction(hovermode, dx, dy); - Plotly.Fx.getClosest(cd, distfn, pointData); + var distfn = Fx.getDistanceFunction(hovermode, dx, dy); + Fx.getClosest(cd, distfn, pointData); // skip the rest (for this trace) if we didn't find a close point if(pointData.index===false) return; @@ -82,7 +83,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { if(di.tx) pointData.text = di.tx; - Plotly.ErrorBars.hoverInfo(di, trace, pointData); + ErrorBars.hoverInfo(di, trace, pointData); return [pointData]; }; diff --git a/src/traces/bar/layout_defaults.js b/src/traces/bar/layout_defaults.js index e4ac480334e..e26b5d2ffd1 100644 --- a/src/traces/bar/layout_defaults.js +++ b/src/traces/bar/layout_defaults.js @@ -9,7 +9,8 @@ 'use strict'; -var Plotly = require('../../plotly'); +var Plots = require('../../plots/plots'); +var Axes = require('../../plots/cartesian/axes'); var Lib = require('../../lib'); var layoutAttributes = require('./layout_attributes'); @@ -23,36 +24,33 @@ module.exports = function(layoutIn, layoutOut, fullData) { var hasBars = false, shouldBeGapless = false, gappedAnyway = false, - usedSubplots = {}, - i, - trace, - subploti; - - for(i = 0; i < fullData.length; i++) { - trace = fullData[i]; - if(Plotly.Plots.traceIs(trace, 'bar')) hasBars = true; + usedSubplots = {}; + + for(var i = 0; i < fullData.length; i++) { + var trace = fullData[i]; + if(Plots.traceIs(trace, 'bar')) hasBars = true; else continue; // if we have at least 2 grouped bar traces on the same subplot, // we should default to a gap anyway, even if the data is histograms if(layoutIn.barmode !== 'overlay' && layoutIn.barmode !== 'stack') { - subploti = trace.xaxis + trace.yaxis; + var subploti = trace.xaxis + trace.yaxis; if(usedSubplots[subploti]) gappedAnyway = true; usedSubplots[subploti] = true; } - if(trace.visible && trace.type==='histogram') { - var pa = Plotly.Axes.getFromId({_fullLayout:layoutOut}, - trace[trace.orientation==='v' ? 'xaxis' : 'yaxis']); - if(pa.type!=='category') shouldBeGapless = true; + if(trace.visible && trace.type === 'histogram') { + var pa = Axes.getFromId({_fullLayout: layoutOut}, + trace[trace.orientation === 'v' ? 'xaxis' : 'yaxis']); + if(pa.type !== 'category') shouldBeGapless = true; } } if(!hasBars) return; var mode = coerce('barmode'); - if(mode!=='overlay') coerce('barnorm'); + if(mode !== 'overlay') coerce('barnorm'); - coerce('bargap', shouldBeGapless && !gappedAnyway ? 0 : 0.2); + coerce('bargap', (shouldBeGapless && !gappedAnyway) ? 0 : 0.2); coerce('bargroupgap'); }; diff --git a/src/traces/bar/set_positions.js b/src/traces/bar/set_positions.js index a8f3d05dc27..14ac0ed11dc 100644 --- a/src/traces/bar/set_positions.js +++ b/src/traces/bar/set_positions.js @@ -11,7 +11,8 @@ var isNumeric = require('fast-isnumeric'); -var Plotly = require('../../plotly'); +var Plots = require('../../plots/plots'); +var Axes = require('../../plots/cartesian/axes'); var Lib = require('../../lib'); /* @@ -27,22 +28,23 @@ module.exports = function setPositions(gd, plotinfo) { ya = plotinfo.y(), i, j; - ['v','h'].forEach(function(dir){ + ['v', 'h'].forEach(function(dir){ var bl = [], - pLetter = {v:'x',h:'y'}[dir], - sLetter = {v:'y',h:'x'}[dir], + pLetter = {v:'x', h:'y'}[dir], + sLetter = {v:'y', h:'x'}[dir], pa = plotinfo[pLetter](), sa = plotinfo[sLetter](); gd._fullData.forEach(function(trace,i) { if(trace.visible === true && - Plotly.Plots.traceIs(trace, 'bar') && + Plots.traceIs(trace, 'bar') && trace.orientation === dir && trace.xaxis === xa._id && trace.yaxis === ya._id) { bl.push(i); } }); + if(!bl.length) return; // bar position offset and width calculation @@ -53,9 +55,9 @@ module.exports = function setPositions(gd, plotinfo) { function barposition(bl1) { // find the min. difference between any points // in any traces in bl1 - var pvals=[]; + var pvals = []; bl1.forEach(function(i){ - gd.calcdata[i].forEach(function(v){ pvals.push(v.p); }); + gd.calcdata[i].forEach(function(v) { pvals.push(v.p); }); }); var dv = Lib.distinctVals(pvals), pv2 = dv.vals, @@ -65,7 +67,8 @@ module.exports = function setPositions(gd, plotinfo) { // if so, let them have full width even if mode is group var overlap = false, comparelist = []; - if(fullLayout.barmode==='group') { + + if(fullLayout.barmode === 'group') { bl1.forEach(function(i) { if(overlap) return; gd.calcdata[i].forEach(function(v) { @@ -82,36 +85,37 @@ module.exports = function setPositions(gd, plotinfo) { } // check forced minimum dtick - Plotly.Axes.minDtick(pa, barDiff, pv2[0], overlap); + Axes.minDtick(pa, barDiff, pv2[0], overlap); // position axis autorange - always tight fitting - Plotly.Axes.expand(pa, pv2, {vpad: barDiff/2}); + Axes.expand(pa, pv2, {vpad: barDiff / 2}); // bar widths and position offsets - barDiff *= 1-fullLayout.bargap; - if(overlap) barDiff/=bl.length; + barDiff *= 1 - fullLayout.bargap; + if(overlap) barDiff /= bl.length; var barCenter; function setBarCenter(v) { v[pLetter] = v.p + barCenter; } - for(var i=0; iPlotly.Fx.MAXDIST || - Plotly.Fx.inbox(yval-y[0], yval-y[y.length-1])>Plotly.Fx.MAXDIST) { + else if(Fx.inbox(xval-x[0], xval-x[x.length-1]) > Fx.MAXDIST || + Fx.inbox(yval-y[0], yval-y[y.length-1]) > Fx.MAXDIST) { return; } else { @@ -99,7 +99,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, contour) return [Lib.extendFlat(pointData, { index: [ny, nx], // never let a 2D override 1D type as closest point - distance: Plotly.Fx.MAXDIST+10, + distance: Fx.MAXDIST + 10, x0: x0, x1: x1, y0: y0, diff --git a/src/traces/heatmap/plot.js b/src/traces/heatmap/plot.js index 236fad50b74..7464185433e 100644 --- a/src/traces/heatmap/plot.js +++ b/src/traces/heatmap/plot.js @@ -12,8 +12,8 @@ var d3 = require('d3'); var tinycolor = require('tinycolor2'); -var Plotly = require('../../plotly'); var Lib = require('../../lib'); +var Plots = require('../../plots/plots'); var getColorscale = require('../../components/colorscale/get_scale'); var xmlnsNamespaces = require('../../constants/xmlns_namespaces'); @@ -52,7 +52,7 @@ function plotOne(gd, plotinfo, cd) { scl = getColorscale(trace.colorscale), x = cd[0].x, y = cd[0].y, - isContour = Plotly.Plots.traceIs(trace, 'contour'), + isContour = Plots.traceIs(trace, 'contour'), zsmooth = isContour ? 'best' : trace.zsmooth, // get z dims diff --git a/src/traces/histogram/calc.js b/src/traces/histogram/calc.js index 0c7e7ece7f4..ddd3e4d8a14 100644 --- a/src/traces/histogram/calc.js +++ b/src/traces/histogram/calc.js @@ -11,8 +11,8 @@ var isNumeric = require('fast-isnumeric'); -var Plotly = require('../../plotly'); var Lib = require('../../lib'); +var Axes = require('../../plots/cartesian/axes'); var binFunctions = require('./bin_functions'); var normFunctions = require('./norm_functions'); @@ -28,7 +28,7 @@ module.exports = function calc(gd, trace) { var pos = [], size = [], i, - pa = Plotly.Axes.getFromId(gd, + pa = Axes.getFromId(gd, trace.orientation==='h' ? (trace.yaxis || 'y') : (trace.xaxis || 'x')), maindata = trace.orientation==='h' ? 'y' : 'x', counterdata = {x: 'y', y: 'x'}[maindata]; @@ -37,7 +37,7 @@ module.exports = function calc(gd, trace) { var pos0 = pa.makeCalcdata(trace, maindata); // calculate the bins if((trace['autobin' + maindata]!==false) || !(maindata + 'bins' in trace)) { - trace[maindata + 'bins'] = Plotly.Axes.autoBin(pos0, pa, trace['nbins' + maindata]); + trace[maindata + 'bins'] = Axes.autoBin(pos0, pa, trace['nbins' + maindata]); // copy bin info back to the source data. trace._input[maindata + 'bins'] = trace[maindata + 'bins']; @@ -74,9 +74,9 @@ module.exports = function calc(gd, trace) { i = binspec.start; // decrease end a little in case of rounding errors binend = binspec.end + - (binspec.start - Plotly.Axes.tickIncrement(binspec.start, binspec.size)) / 1e6; + (binspec.start - Axes.tickIncrement(binspec.start, binspec.size)) / 1e6; while(i Date: Wed, 3 Feb 2016 12:26:07 -0500 Subject: [PATCH 2/4] use 'official' Plotly in test suite, instead of internal Plotly --- test/jasmine/tests/choropleth_test.js | 4 +- test/jasmine/tests/color_test.js | 18 ++--- test/jasmine/tests/colorscale_test.js | 11 +-- test/jasmine/tests/config_test.js | 2 +- test/jasmine/tests/is_plain_object_test.js | 4 +- test/jasmine/tests/legend_test.js | 11 +-- test/jasmine/tests/lib_test.js | 82 +++++++++++----------- test/jasmine/tests/plot_promise_test.js | 2 +- test/jasmine/tests/plots_test.js | 2 +- test/jasmine/tests/plotschema_test.js | 9 +-- test/jasmine/tests/register_test.js | 2 +- test/jasmine/tests/search_test.js | 34 ++++----- test/jasmine/tests/snapshot_clone_test.js | 14 ++-- 13 files changed, 100 insertions(+), 95 deletions(-) diff --git a/test/jasmine/tests/choropleth_test.js b/test/jasmine/tests/choropleth_test.js index ffaf31570bc..75e03d4533d 100644 --- a/test/jasmine/tests/choropleth_test.js +++ b/test/jasmine/tests/choropleth_test.js @@ -1,5 +1,5 @@ -var Plotly = require('@src/plotly'); var Choropleth = require('@src/traces/choropleth'); +var Plots = require('@src/plots/plots'); describe('Test choropleth', function() { @@ -11,7 +11,7 @@ describe('Test choropleth', function() { var defaultColor = '#444', layout = { - font: Plotly.Plots.layoutAttributes.font + font: Plots.layoutAttributes.font }; beforeEach(function() { diff --git a/test/jasmine/tests/color_test.js b/test/jasmine/tests/color_test.js index 816e85767ac..3b67c8ea3b7 100644 --- a/test/jasmine/tests/color_test.js +++ b/test/jasmine/tests/color_test.js @@ -1,4 +1,4 @@ -var Plotly = require('@src/plotly'); +var Color = require('@src/components/color'); describe('Test color:', function() { @@ -15,7 +15,7 @@ describe('Test color:', function() { rgbacolor: 'rgba(51, 102, 153, 0.8)' }; - Plotly.Color.clean(container); + Color.clean(container); expect(container).toEqual(expectedContainer); }); @@ -51,7 +51,7 @@ describe('Test color:', function() { ] }; - Plotly.Color.clean(container); + Color.clean(container); expect(container).toEqual(expectedContainer); }); @@ -70,7 +70,7 @@ describe('Test color:', function() { fractionrgbacolor: 'rgba(0, 102, 204, 1)' }; - Plotly.Color.clean(container); + Color.clean(container); expect(container).toEqual(expectedContainer); }); @@ -86,7 +86,7 @@ describe('Test color:', function() { rgbacolor: 'rgba(51, 102, 153, 0.8)' }; - Plotly.Color.clean(container); + Color.clean(container); expect(container).toEqual(expectedContainer); }); @@ -102,7 +102,7 @@ describe('Test color:', function() { rgba2color: 'rgba(26, 51, 128, 1)' }; - Plotly.Color.clean(container); + Color.clean(container); expect(container).toEqual(expectedContainer); }); @@ -117,7 +117,7 @@ describe('Test color:', function() { var expectedContainer = {}; Object.keys(container).forEach(function(k) { expectedContainer[k] = container[k]; }); - Plotly.Color.clean(container); + Color.clean(container); expect(container).toEqual(expectedContainer); }); @@ -125,7 +125,7 @@ describe('Test color:', function() { var container1 = null; var expectedContainer1 = null; - Plotly.Color.clean(container1); + Color.clean(container1); expect(container1).toEqual(expectedContainer1); var container2 = { @@ -141,7 +141,7 @@ describe('Test color:', function() { anarray: [null, {color: 'rgb(0.1, 0.1, 0.1)'}] }; - Plotly.Color.clean(container2); + Color.clean(container2); expect(container2).toEqual(expectedContainer2); }); }); diff --git a/test/jasmine/tests/colorscale_test.js b/test/jasmine/tests/colorscale_test.js index e5af0a26c70..a53849a2dbe 100644 --- a/test/jasmine/tests/colorscale_test.js +++ b/test/jasmine/tests/colorscale_test.js @@ -1,5 +1,6 @@ -var Plotly = require('@src/plotly'); var Colorscale = require('@src/components/colorscale'); +var Lib = require('@src/lib'); +var Plots = require('@src/plots/plots'); var Heatmap = require('@src/traces/heatmap'); var Scatter = require('@src/traces/scatter'); @@ -187,13 +188,13 @@ describe('Test colorscale:', function() { describe('handleDefaults (heatmap-like version)', function() { var handleDefaults = Colorscale.handleDefaults, layout = { - font: Plotly.Plots.layoutAttributes.font + font: Plots.layoutAttributes.font }, opts = {prefix: '', cLetter: 'z'}; var traceIn, traceOut; function coerce(attr, dflt) { - return Plotly.Lib.coerce(traceIn, traceOut, Heatmap.attributes, attr, dflt); + return Lib.coerce(traceIn, traceOut, Heatmap.attributes, attr, dflt); } beforeEach(function() { @@ -257,13 +258,13 @@ describe('Test colorscale:', function() { describe('handleDefaults (scatter-like version)', function() { var handleDefaults = Colorscale.handleDefaults, layout = { - font: Plotly.Plots.layoutAttributes.font + font: Plots.layoutAttributes.font }, opts = {prefix: 'marker.', cLetter: 'c'}; var traceIn, traceOut; function coerce(attr, dflt) { - return Plotly.Lib.coerce(traceIn, traceOut, Scatter.attributes, attr, dflt); + return Lib.coerce(traceIn, traceOut, Scatter.attributes, attr, dflt); } beforeEach(function() { diff --git a/test/jasmine/tests/config_test.js b/test/jasmine/tests/config_test.js index a8abcd1545c..b221c7f0cf5 100644 --- a/test/jasmine/tests/config_test.js +++ b/test/jasmine/tests/config_test.js @@ -1,4 +1,4 @@ -var Plotly = require('@src/plotly'); +var Plotly = require('@lib/index'); var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); diff --git a/test/jasmine/tests/is_plain_object_test.js b/test/jasmine/tests/is_plain_object_test.js index 5ce1e634da9..1a0058b7eb3 100644 --- a/test/jasmine/tests/is_plain_object_test.js +++ b/test/jasmine/tests/is_plain_object_test.js @@ -1,9 +1,9 @@ -var Plotly = require('@src/plotly'); +var Lib = require('@src/lib'); describe('isPlainObject', function() { 'use strict'; - var isPlainObject = Plotly.Lib.isPlainObject; + var isPlainObject = Lib.isPlainObject; function A() {} diff --git a/test/jasmine/tests/legend_test.js b/test/jasmine/tests/legend_test.js index a9514fbfc87..8de626b6c83 100644 --- a/test/jasmine/tests/legend_test.js +++ b/test/jasmine/tests/legend_test.js @@ -1,10 +1,11 @@ -var Plotly = require('@src/plotly'); +var Legend = require('@src/components/legend'); +var Plots = require('@src/plots/plots'); describe('Test legend:', function() { 'use strict'; describe('supplyLayoutDefaults', function() { - var supplyLayoutDefaults = Plotly.Legend.supplyLayoutDefaults; + var supplyLayoutDefaults = Legend.supplyLayoutDefaults; var layoutIn, layoutOut, fullData; @@ -13,8 +14,8 @@ describe('Test legend:', function() { showlegend: true }; layoutOut = { - font: Plotly.Plots.layoutAttributes.font, - bg_color: Plotly.Plots.layoutAttributes.bg_color + font: Plots.layoutAttributes.font, + bg_color: Plots.layoutAttributes.bg_color }; }); @@ -62,7 +63,7 @@ describe('Test legend:', function() { }); describe('getLegendData', function() { - var getLegendData = Plotly.Legend.getLegendData; + var getLegendData = Legend.getLegendData; var calcdata, opts, legendData, expected; diff --git a/test/jasmine/tests/lib_test.js b/test/jasmine/tests/lib_test.js index d5bb2c3b983..f51385bf608 100644 --- a/test/jasmine/tests/lib_test.js +++ b/test/jasmine/tests/lib_test.js @@ -1,36 +1,38 @@ -var Plotly = require('@src/plotly'); +var Lib = require('@src/lib'); +var Plots = require('@src/plots/plots'); + describe('Test lib.js:', function() { 'use strict'; describe('parseDate() should', function() { it('return false on bad (number) input:', function() { - expect(Plotly.Lib.parseDate(0)).toBe(false); + expect(Lib.parseDate(0)).toBe(false); }); it('return false on bad (string) input:', function() { - expect(Plotly.Lib.parseDate('toto')).toBe(false); + expect(Lib.parseDate('toto')).toBe(false); }); it('work with yyyy-mm-dd string input:', function() { var input = '2014-12-01', - res = Plotly.Lib.parseDate(input), + res = Lib.parseDate(input), res0 = new Date(2014, 11, 1); expect(res.getTime()).toEqual(res0.getTime()); }); it('work with mm/dd/yyyy string input:', function() { var input = '12/01/2014', - res = Plotly.Lib.parseDate(input), + res = Lib.parseDate(input), res0 = new Date(2014, 11, 1); expect(res.getTime()).toEqual(res0.getTime()); }); it('work with yyyy-mm-dd HH:MM:SS.sss string input:', function() { var input = '2014-12-01 09:50:05.124', - res = Plotly.Lib.parseDate(input), + res = Lib.parseDate(input), res0 = new Date(2014, 11, 1, 9, 50, 5, 124); expect(res.getTime()).toEqual(res0.getTime()); }); it('work with mm/dd/yyyy HH:MM:SS string input:', function() { var input = '2014-12-01 09:50:05', - res = Plotly.Lib.parseDate(input), + res = Lib.parseDate(input), res0 = new Date(2014, 11, 1, 9, 50, 5); expect(res.getTime()).toEqual(res0.getTime()); }); @@ -39,32 +41,32 @@ 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 = Plotly.Lib.interp(input, 0.25), + res = Lib.interp(input, 0.25), 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 = Plotly.Lib.interp(input, 0.75), + res = Lib.interp(input, 0.75), res0 = 4.25; expect(res).toEqual(res0); }); it('error if second input argument is a string:', function() { var input = [1, 2, 3, 4, 5]; expect(function() { - Plotly.Lib.interp(input, 'apple'); + Lib.interp(input, 'apple'); }).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); expect(function() { - Plotly.Lib.interp(in1, in2); + 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 = Plotly.Lib.interp(input, 1), + res = Lib.interp(input, 1), res0 = Infinity; expect(res).toEqual(res0); }); @@ -83,12 +85,12 @@ describe('Test lib.js:', function() { [undefined, 4, undefined, undefined] ]; - expect(Plotly.Lib.transposeRagged(input)).toEqual(output); + expect(Lib.transposeRagged(input)).toEqual(output); }); }); describe('dot()', function() { - var dot = Plotly.Lib.dot; + var dot = Lib.dot; it('should return null for empty or unequal-length inputs', function() { expect(dot([], [])).toBeNull(); @@ -111,7 +113,7 @@ describe('Test lib.js:', function() { }); describe('aggNums()', function() { - var aggNums = Plotly.Lib.aggNums; + var aggNums = Lib.aggNums; function summation(a, b) { return a + b; } @@ -133,17 +135,17 @@ describe('Test lib.js:', function() { describe('mean() should', function() { it('toss out non-numerics (strings):', function() { var input = [1, 2, 'apple', 'orange'], - res = Plotly.Lib.mean(input); + res = Lib.mean(input); expect(res).toEqual(1.5); }); it('toss out non-numerics (NaN):', function() { var input = [1, 2, NaN], - res = Plotly.Lib.mean(input); + 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 = Plotly.Lib.mean(input); + res = Lib.mean(input); expect(res).toEqual(1.5); }); }); @@ -151,22 +153,22 @@ describe('Test lib.js:', function() { describe('variance() should', function() { it('return 0 on input [2, 2, 2, 2, 2]:', function() { var input = [2, 2, 2, 2], - res = Plotly.Lib.variance(input); + res = Lib.variance(input); expect(res).toEqual(0); }); it('return 2/3 on input [-1, 0, 1]:', function() { var input = [-1, 0, 1], - res = Plotly.Lib.variance(input); + res = Lib.variance(input); expect(res).toEqual(2/3); }); it('toss out non-numerics (strings):', function() { var input = [1, 2, 'apple', 'orange'], - res = Plotly.Lib.variance(input); + res = Lib.variance(input); expect(res).toEqual(0.25); }); it('toss out non-numerics (NaN):', function() { var input = [1, 2, NaN], - res = Plotly.Lib.variance(input); + res = Lib.variance(input); expect(res).toEqual(0.25); }); }); @@ -174,22 +176,22 @@ describe('Test lib.js:', function() { describe('stdev() should', function() { it('return 0 on input [2, 2, 2, 2, 2]:', function() { var input = [2, 2, 2, 2], - res = Plotly.Lib.stdev(input); + 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 = Plotly.Lib.stdev(input); + 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 = Plotly.Lib.stdev(input); + res = Lib.stdev(input); expect(res).toEqual(0.5); }); it('toss out non-numerics (NaN):', function() { var input = [1, 2, NaN], - res = Plotly.Lib.stdev(input); + res = Lib.stdev(input); expect(res).toEqual(0.5); }); }); @@ -197,19 +199,19 @@ describe('Test lib.js:', function() { describe('smooth()', function() { it('should not alter the input for FWHM < 1.5', function() { var input = [1, 2, 1, 2, 1], - output = Plotly.Lib.smooth(input.slice(), 1.49); + output = Lib.smooth(input.slice(), 1.49); expect(output).toEqual(input); - output = Plotly.Lib.smooth(input.slice(), 'like butter'); + output = Lib.smooth(input.slice(), 'like butter'); expect(output).toEqual(input); }); it('should preserve the length and integral even with multiple bounces', function() { var input = [1, 2, 4, 8, 16, 8, 10, 12], - output2 = Plotly.Lib.smooth(input.slice(), 2), - output30 = Plotly.Lib.smooth(input.slice(), 30), + output2 = Lib.smooth(input.slice(), 2), + output30 = Lib.smooth(input.slice(), 30), sumIn = 0, sum2 = 0, sum30 = 0; @@ -228,8 +230,8 @@ describe('Test lib.js:', function() { it('should use a hann window and bounce', function() { var input = [0, 0, 0, 7, 0, 0, 0], - out4 = Plotly.Lib.smooth(input, 4), - out7 = Plotly.Lib.smooth(input, 7), + 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 @@ -245,7 +247,7 @@ describe('Test lib.js:', function() { }); describe('nestedProperty', function() { - var np = Plotly.Lib.nestedProperty; + var np = Lib.nestedProperty; it('should access simple objects', function() { var obj = {a: 'b', c: 'd'}, @@ -434,7 +436,7 @@ describe('Test lib.js:', function() { }); describe('coerce', function() { - var coerce = Plotly.Lib.coerce, + var coerce = Lib.coerce, out; // TODO: I tested font and string because I changed them, but all the other types need tests still @@ -495,7 +497,7 @@ describe('Test lib.js:', function() { }); describe('coerce2', function() { - var coerce2 = Plotly.Lib.coerce2; + var coerce2 = Lib.coerce2; it('should set a value and return the value it sets when user input is valid', function() { var colVal = 'red', @@ -589,9 +591,9 @@ describe('Test lib.js:', function() { }); describe('coerceFont', function() { - var fontAttrs = Plotly.Plots.fontAttrs, - extendFlat = Plotly.Lib.extendFlat, - coerceFont = Plotly.Lib.coerceFont; + var fontAttrs = Plots.fontAttrs, + extendFlat = Lib.extendFlat, + coerceFont = Lib.coerceFont; var defaultFont = { family: '"Open sans", verdana, arial, sans-serif, DEFAULT', @@ -611,7 +613,7 @@ describe('Test lib.js:', function() { var containerIn; function coerce(attr, dflt) { - return Plotly.Lib.coerce(containerIn, {}, attributes, attr, dflt); + return Lib.coerce(containerIn, {}, attributes, attr, dflt); } it('should insert the full default if no or empty input', function() { @@ -666,7 +668,7 @@ describe('Test lib.js:', function() { describe('init2dArray', function() { it('should initialize a 2d array with the correct dimenstions', function() { - var array = Plotly.Lib.init2dArray(4, 5); + var array = Lib.init2dArray(4, 5); expect(array.length).toEqual(4); expect(array[0].length).toEqual(5); expect(array[3].length).toEqual(5); diff --git a/test/jasmine/tests/plot_promise_test.js b/test/jasmine/tests/plot_promise_test.js index 56b822b3915..1cd4348077f 100644 --- a/test/jasmine/tests/plot_promise_test.js +++ b/test/jasmine/tests/plot_promise_test.js @@ -1,4 +1,4 @@ -var Plotly = require('@src/plotly'); +var Plotly = require('@lib/index'); var Events = require('@src/lib/events'); var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index a3c4cb7ae4a..ecd24f4fc6c 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -1,4 +1,4 @@ -var Plotly = require('@src/plotly'); +var Plotly = require('@lib/index'); var Plots = require('@src/plots/plots'); var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); diff --git a/test/jasmine/tests/plotschema_test.js b/test/jasmine/tests/plotschema_test.js index 570ecaefd35..9e7a9fcfc0d 100644 --- a/test/jasmine/tests/plotschema_test.js +++ b/test/jasmine/tests/plotschema_test.js @@ -1,4 +1,5 @@ -var Plotly = require('@src/plotly'); +var Plotly = require('@lib/index'); +var Lib = require('@src/lib'); describe('plot schema', function() { 'use strict'; @@ -7,7 +8,7 @@ describe('plot schema', function() { valObjects = plotSchema.defs.valObjects; var isValObject = Plotly.PlotSchema.isValObject, - isPlainObject = Plotly.Lib.isPlainObject; + isPlainObject = Lib.isPlainObject; var VALTYPES = Object.keys(valObjects), ROLES = ['info', 'style', 'data']; @@ -95,7 +96,7 @@ describe('plot schema', function() { // check if the subplot objects have '_isSubplotObj' astrs.forEach(function(astr) { expect( - Plotly.Lib.nestedProperty( + Lib.nestedProperty( plotSchema.layout.layoutAttributes, astr + '.' + IS_SUBPLOT_OBJ ).get() @@ -117,7 +118,7 @@ describe('plot schema', function() { astrs.forEach(function(astr) { expect( isPlainObject( - Plotly.Lib.nestedProperty( + Lib.nestedProperty( plotSchema.layout.layoutAttributes, astr ).get().items ) diff --git a/test/jasmine/tests/register_test.js b/test/jasmine/tests/register_test.js index c2f59013d01..80a2657f3e4 100644 --- a/test/jasmine/tests/register_test.js +++ b/test/jasmine/tests/register_test.js @@ -1,4 +1,4 @@ -var Plotly = require('@src/plotly'); +var Plotly = require('@lib/index'); describe('the register function', function() { diff --git a/test/jasmine/tests/search_test.js b/test/jasmine/tests/search_test.js index da9bd4c81b6..6b6b122c117 100644 --- a/test/jasmine/tests/search_test.js +++ b/test/jasmine/tests/search_test.js @@ -1,36 +1,36 @@ -var Plotly = require('@src/plotly'); +var Lib = require('@src/lib'); describe('Test search.js:', function() { 'use strict'; describe('findBin', function() { it('should work on ascending arrays', function() { - expect(Plotly.Lib.findBin(-10000, [0, 1, 3])).toBe(-1); - expect(Plotly.Lib.findBin(0.5, [0, 1, 3])).toBe(0); - expect(Plotly.Lib.findBin(2, [0, 1, 3])).toBe(1); - expect(Plotly.Lib.findBin(10000, [0, 1, 3])).toBe(2); + expect(Lib.findBin(-10000, [0, 1, 3])).toBe(-1); + expect(Lib.findBin(0.5, [0, 1, 3])).toBe(0); + expect(Lib.findBin(2, [0, 1, 3])).toBe(1); + expect(Lib.findBin(10000, [0, 1, 3])).toBe(2); // default: linelow falsey, so the line is in the higher bin - expect(Plotly.Lib.findBin(1, [0, 1, 3])).toBe(1); + expect(Lib.findBin(1, [0, 1, 3])).toBe(1); // linelow truthy, so the line is in the lower bin - expect(Plotly.Lib.findBin(1, [0, 1, 3], true)).toBe(0); + expect(Lib.findBin(1, [0, 1, 3], true)).toBe(0); }); it('should work on decending arrays', function() { - expect(Plotly.Lib.findBin(-10000, [3, 1, 0])).toBe(2); - expect(Plotly.Lib.findBin(0.5, [3, 1, 0])).toBe(1); - expect(Plotly.Lib.findBin(2, [3, 1, 0])).toBe(0); - expect(Plotly.Lib.findBin(10000, [3, 1, 0])).toBe(-1); + expect(Lib.findBin(-10000, [3, 1, 0])).toBe(2); + expect(Lib.findBin(0.5, [3, 1, 0])).toBe(1); + expect(Lib.findBin(2, [3, 1, 0])).toBe(0); + expect(Lib.findBin(10000, [3, 1, 0])).toBe(-1); - expect(Plotly.Lib.findBin(1, [3, 1, 0])).toBe(0); - expect(Plotly.Lib.findBin(1, [3, 1, 0], true)).toBe(1); + expect(Lib.findBin(1, [3, 1, 0])).toBe(0); + expect(Lib.findBin(1, [3, 1, 0], true)).toBe(1); }); it('should treat a length-1 array as ascending', function() { - expect(Plotly.Lib.findBin(-1, [0])).toBe(-1); - expect(Plotly.Lib.findBin(1, [0])).toBe(0); + expect(Lib.findBin(-1, [0])).toBe(-1); + expect(Lib.findBin(1, [0])).toBe(0); - expect(Plotly.Lib.findBin(0, [0])).toBe(0); - expect(Plotly.Lib.findBin(0, [0], true)).toBe(-1); + expect(Lib.findBin(0, [0])).toBe(0); + expect(Lib.findBin(0, [0], true)).toBe(-1); }); // TODO: didn't test bins as objects {start, stop, size} }); diff --git a/test/jasmine/tests/snapshot_clone_test.js b/test/jasmine/tests/snapshot_clone_test.js index 76941275723..3770c539666 100644 --- a/test/jasmine/tests/snapshot_clone_test.js +++ b/test/jasmine/tests/snapshot_clone_test.js @@ -1,4 +1,4 @@ -var Plotly = require('@src/plotly'); +var Snapshot = require('@src/snapshot'); describe('Test Snapshot.clone', function() { 'use strict'; @@ -76,7 +76,7 @@ describe('Test Snapshot.clone', function() { setBackground: 'opaque' }; - var themeTile = Plotly.Snapshot.clone(dummyGraphObj, themeOptions); + var themeTile = Snapshot.clone(dummyGraphObj, themeOptions); expect(themeTile.layout.height).toEqual(THEMETILE_DEFAULT_LAYOUT.height); expect(themeTile.layout.width).toEqual(THEMETILE_DEFAULT_LAYOUT.width); expect(themeTile.td.defaultLayout).toEqual(THEMETILE_DEFAULT_LAYOUT); @@ -101,7 +101,7 @@ describe('Test Snapshot.clone', function() { 'annotations': [] }; - var thumbTile = Plotly.Snapshot.clone(dummyGraphObj, thumbnailOptions); + var thumbTile = Snapshot.clone(dummyGraphObj, thumbnailOptions); expect(thumbTile.layout.hidesources).toEqual(THUMBNAIL_DEFAULT_LAYOUT.hidesources); expect(thumbTile.layout.showlegend).toEqual(THUMBNAIL_DEFAULT_LAYOUT.showlegend); expect(thumbTile.layout.borderwidth).toEqual(THUMBNAIL_DEFAULT_LAYOUT.borderwidth); @@ -115,7 +115,7 @@ describe('Test Snapshot.clone', function() { width: 888 }; - var customTile = Plotly.Snapshot.clone(dummyGraphObj, customOptions); + var customTile = Snapshot.clone(dummyGraphObj, customOptions); expect(customTile.layout.height).toEqual(customOptions.height); expect(customTile.layout.width).toEqual(customOptions.width); }); @@ -125,7 +125,7 @@ describe('Test Snapshot.clone', function() { tileClass: 'notarealclass' }; - var vanillaPlotTile = Plotly.Snapshot.clone(dummyGraphObj, vanillaOptions); + var vanillaPlotTile = Snapshot.clone(dummyGraphObj, vanillaOptions); expect(vanillaPlotTile.data[0].x).toEqual(data[0].x); expect(vanillaPlotTile.layout).toEqual(layout); expect(vanillaPlotTile.layout.height).toEqual(layout.height); @@ -133,12 +133,12 @@ describe('Test Snapshot.clone', function() { }); it('should set the background parameter appropriately', function() { - var pt = Plotly.Snapshot.clone(dummyGraphObj, { + var pt = Snapshot.clone(dummyGraphObj, { setBackground: 'transparent' }); expect(pt.config.setBackground).not.toBeDefined(); - pt = Plotly.Snapshot.clone(dummyGraphObj, { + pt = Snapshot.clone(dummyGraphObj, { setBackground: 'blue' }); expect(pt.config.setBackground).toEqual('blue'); From 0b443c2683d1f8bcb97f80320a2277a9fd156138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 3 Feb 2016 12:26:39 -0500 Subject: [PATCH 3/4] rm console.log --- test/jasmine/tests/config_test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/jasmine/tests/config_test.js b/test/jasmine/tests/config_test.js index b221c7f0cf5..b2d3e9d8d1b 100644 --- a/test/jasmine/tests/config_test.js +++ b/test/jasmine/tests/config_test.js @@ -32,7 +32,6 @@ describe('config argument', function() { var link = document.getElementsByClassName('js-plot-link-container')[0]; - console.log(link); expect(link.textContent).toBe('Edit chart ยป'); var bBox = link.getBoundingClientRect(); From 347ff550d8cf04fea7c8d809d6692491d24b1664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 3 Feb 2016 15:03:51 -0500 Subject: [PATCH 4/4] lint (infix spacing) --- src/traces/bar/set_positions.js | 4 ++-- src/traces/box/calc.js | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/traces/bar/set_positions.js b/src/traces/bar/set_positions.js index 14ac0ed11dc..9da1a3a2736 100644 --- a/src/traces/bar/set_positions.js +++ b/src/traces/bar/set_positions.js @@ -138,9 +138,9 @@ module.exports = function setPositions(gd, plotinfo) { ti, scale; - for(i = 0; i