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..9da1a3a2736 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