Skip to content

Commit e8ae349

Browse files
authored
Merge pull request #2868 from plotly/setpositions-2-crosstracecalc
setPositions -> crossTraceCalc
2 parents 6a6d1dc + e236038 commit e8ae349

File tree

13 files changed

+54
-34
lines changed

13 files changed

+54
-34
lines changed

src/plot_api/plot_api.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ exports.plot = function(gd, data, layout, config) {
292292
return;
293293
}
294294

295-
Plots.doSetPositions(gd);
295+
Plots.doCrossTraceCalc(gd);
296296

297297
// calc and autorange for errorbars
298298
Registry.getComponentMethod('errorbars', 'calc')(gd);
@@ -329,9 +329,13 @@ exports.plot = function(gd, data, layout, config) {
329329
marginPushers,
330330
marginPushersAgain
331331
];
332+
332333
if(hasCartesian) seq.push(positionAndAutorange);
334+
else seq.push(Plots.doCrossTraceCalc);
335+
333336
seq.push(subroutines.layoutStyles);
334337
if(hasCartesian) seq.push(drawAxes);
338+
335339
seq.push(
336340
subroutines.drawData,
337341
subroutines.finalDraw,

src/plots/plots.js

+27-11
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ plots.transition = function(gd, data, layout, traces, frameOpts, transitionOpts)
22362236

22372237
plots.supplyDefaults(gd);
22382238
plots.doCalcdata(gd);
2239-
plots.doSetPositions(gd);
2239+
plots.doCrossTraceCalc(gd);
22402240
Registry.getComponentMethod('errorbars', 'calc')(gd);
22412241

22422242
return Promise.resolve();
@@ -2564,26 +2564,42 @@ function clearAxesCalc(axList) {
25642564
}
25652565
}
25662566

2567-
plots.doSetPositions = function(gd) {
2567+
plots.doCrossTraceCalc = function(gd) {
25682568
var fullLayout = gd._fullLayout;
2569-
var subplots = fullLayout._subplots.cartesian;
25702569
var modules = fullLayout._visibleModules;
2571-
var methods = [];
2572-
var i, j;
2570+
var hash = {};
2571+
var i, j, k;
25732572

25742573
// position and range calculations for traces that
25752574
// depend on each other ie bars (stacked or grouped)
25762575
// and boxes (grouped) push each other out of the way
25772576

25782577
for(j = 0; j < modules.length; j++) {
2579-
Lib.pushUnique(methods, modules[j].setPositions);
2578+
var _module = modules[j];
2579+
var fn = _module.crossTraceCalc;
2580+
if(fn) {
2581+
var spType = _module.basePlotModule.name;
2582+
if(hash[spType]) {
2583+
Lib.pushUnique(hash[spType], fn);
2584+
} else {
2585+
hash[spType] = [fn];
2586+
}
2587+
}
25802588
}
2581-
if(!methods.length) return;
25822589

2583-
for(i = 0; i < subplots.length; i++) {
2584-
var subplotInfo = fullLayout._plots[subplots[i]];
2585-
for(j = 0; j < methods.length; j++) {
2586-
methods[j](gd, subplotInfo);
2590+
for(k in hash) {
2591+
var methods = hash[k];
2592+
var subplots = fullLayout._subplots[k];
2593+
2594+
for(i = 0; i < subplots.length; i++) {
2595+
var sp = subplots[i];
2596+
var spInfo = k === 'cartesian' ?
2597+
fullLayout._plots[sp] :
2598+
fullLayout[sp];
2599+
2600+
for(j = 0; j < methods.length; j++) {
2601+
methods[j](gd, spInfo);
2602+
}
25872603
}
25882604
}
25892605
};

src/traces/bar/set_positions.js renamed to src/traces/bar/cross_trace_calc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var Sieve = require('./sieve.js');
2424
* now doing this one subplot at a time
2525
*/
2626

27-
module.exports = function setPositions(gd, plotinfo) {
27+
module.exports = function crossTraceCalc(gd, plotinfo) {
2828
var xa = plotinfo.xaxis,
2929
ya = plotinfo.yaxis;
3030

src/traces/bar/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Bar.layoutAttributes = require('./layout_attributes');
1616
Bar.supplyDefaults = require('./defaults');
1717
Bar.supplyLayoutDefaults = require('./layout_defaults');
1818
Bar.calc = require('./calc');
19-
Bar.setPositions = require('./set_positions');
19+
Bar.crossTraceCalc = require('./cross_trace_calc');
2020
Bar.colorbar = require('../scatter/marker_colorbar');
2121
Bar.arraysToCalcdata = require('./arrays_to_calcdata');
2222
Bar.plot = require('./plot');

src/traces/box/set_positions.js renamed to src/traces/box/cross_trace_calc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var Lib = require('../../lib');
1313

1414
var orientations = ['v', 'h'];
1515

16-
function setPositions(gd, plotinfo) {
16+
function crossTraceCalc(gd, plotinfo) {
1717
var calcdata = gd.calcdata;
1818
var xa = plotinfo.xaxis;
1919
var ya = plotinfo.yaxis;
@@ -109,6 +109,6 @@ function setPositionOffset(traceType, gd, boxList, posAxis, pad) {
109109
}
110110

111111
module.exports = {
112-
setPositions: setPositions,
112+
crossTraceCalc: crossTraceCalc,
113113
setPositionOffset: setPositionOffset
114114
};

src/traces/box/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Box.layoutAttributes = require('./layout_attributes');
1515
Box.supplyDefaults = require('./defaults').supplyDefaults;
1616
Box.supplyLayoutDefaults = require('./layout_defaults').supplyLayoutDefaults;
1717
Box.calc = require('./calc');
18-
Box.setPositions = require('./set_positions').setPositions;
18+
Box.crossTraceCalc = require('./cross_trace_calc').crossTraceCalc;
1919
Box.plot = require('./plot').plot;
2020
Box.style = require('./style').style;
2121
Box.styleOnSelect = require('./style').styleOnSelect;

src/traces/candlestick/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232
attributes: require('./attributes'),
3333
layoutAttributes: require('../box/layout_attributes'),
3434
supplyLayoutDefaults: require('../box/layout_defaults').supplyLayoutDefaults,
35-
setPositions: require('../box/set_positions').setPositions,
35+
crossTraceCalc: require('../box/cross_trace_calc').crossTraceCalc,
3636
supplyDefaults: require('./defaults'),
3737
calc: require('./calc'),
3838
plot: require('../box/plot').plot,

src/traces/histogram/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* Histogram has its own attribute, defaults and calc steps,
1414
* but uses bar's plot to display
15-
* and bar's setPositions for stacking and grouping
15+
* and bar's crossTraceCalc (formerly known as setPositions) for stacking and grouping
1616
*/
1717

1818
/**
@@ -30,7 +30,7 @@ Histogram.layoutAttributes = require('../bar/layout_attributes');
3030
Histogram.supplyDefaults = require('./defaults');
3131
Histogram.supplyLayoutDefaults = require('../bar/layout_defaults');
3232
Histogram.calc = require('./calc');
33-
Histogram.setPositions = require('../bar/set_positions');
33+
Histogram.crossTraceCalc = require('../bar/cross_trace_calc');
3434
Histogram.plot = require('../bar/plot');
3535
Histogram.layerName = 'barlayer';
3636
Histogram.style = require('../bar/style').style;

src/traces/violin/set_positions.js renamed to src/traces/violin/cross_trace_calc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
'use strict';
1010

11-
var setPositionOffset = require('../box/set_positions').setPositionOffset;
11+
var setPositionOffset = require('../box/cross_trace_calc').setPositionOffset;
1212
var orientations = ['v', 'h'];
1313

14-
module.exports = function setPositions(gd, plotinfo) {
14+
module.exports = function crossTraceCalc(gd, plotinfo) {
1515
var calcdata = gd.calcdata;
1616
var xa = plotinfo.xaxis;
1717
var ya = plotinfo.yaxis;

src/traces/violin/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
supplyDefaults: require('./defaults'),
1515
supplyLayoutDefaults: require('./layout_defaults'),
1616
calc: require('./calc'),
17-
setPositions: require('./set_positions'),
17+
crossTraceCalc: require('./cross_trace_calc'),
1818
plot: require('./plot'),
1919
style: require('./style'),
2020
styleOnSelect: require('../scatter/style').styleOnSelect,

test/jasmine/tests/bar_test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describe('Bar.supplyDefaults', function() {
171171
});
172172
});
173173

174-
describe('bar calc / setPositions', function() {
174+
describe('bar calc / crossTraceCalc (formerly known as setPositions)', function() {
175175
'use strict';
176176

177177
it('should fill in calc pt fields (stack case)', function() {
@@ -337,7 +337,7 @@ describe('Bar.calc', function() {
337337
});
338338
});
339339

340-
describe('Bar.setPositions', function() {
340+
describe('Bar.crossTraceCalc (formerly known as setPositions)', function() {
341341
'use strict';
342342

343343
it('should guard against invalid offset items', function() {
@@ -1347,9 +1347,9 @@ describe('bar visibility toggling:', function() {
13471347
expect(fullLayout.xaxis.range).toBeCloseToArray(xrng, 2, msg + ' xrng');
13481348
expect(fullLayout.yaxis.range).toBeCloseToArray(yrng, 2, msg + ' yrng');
13491349

1350-
var setPositions = gd._fullData[0]._module.setPositions;
1351-
expect(setPositions).toHaveBeenCalledTimes(calls);
1352-
setPositions.calls.reset();
1350+
var crossTraceCalc = gd._fullData[0]._module.crossTraceCalc;
1351+
expect(crossTraceCalc).toHaveBeenCalledTimes(calls);
1352+
crossTraceCalc.calls.reset();
13531353
}
13541354

13551355
it('should update axis range according to visible edits (group case)', function(done) {
@@ -1358,7 +1358,7 @@ describe('bar visibility toggling:', function() {
13581358
{type: 'bar', x: [1, 2, 3], y: [-1, -2, -1]}
13591359
])
13601360
.then(function() {
1361-
spyOn(gd._fullData[0]._module, 'setPositions').and.callThrough();
1361+
spyOn(gd._fullData[0]._module, 'crossTraceCalc').and.callThrough();
13621362

13631363
_assert('base', [0.5, 3.5], [-2.222, 2.222], 0);
13641364
return Plotly.restyle(gd, 'visible', false, [1]);
@@ -1388,7 +1388,7 @@ describe('bar visibility toggling:', function() {
13881388
{type: 'bar', x: [1, 2, 3], y: [2, 3, 2]}
13891389
], {barmode: 'stack'})
13901390
.then(function() {
1391-
spyOn(gd._fullData[0]._module, 'setPositions').and.callThrough();
1391+
spyOn(gd._fullData[0]._module, 'crossTraceCalc').and.callThrough();
13921392

13931393
_assert('base', [0.5, 3.5], [0, 5.263], 0);
13941394
return Plotly.restyle(gd, 'visible', false, [1]);
@@ -1806,8 +1806,8 @@ function mockBarPlot(dataWithoutTraceType, layout) {
18061806
yaxis: gd._fullLayout.yaxis
18071807
};
18081808

1809-
// call Bar.setPositions
1810-
Bar.setPositions(gd, plotinfo);
1809+
// call Bar.crossTraceCalc
1810+
Bar.crossTraceCalc(gd, plotinfo);
18111811

18121812
return gd;
18131813
}

test/jasmine/tests/finance_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ describe('finance charts calc', function() {
380380
supplyAllDefaults(gd);
381381
Plots.doCalcdata(gd);
382382
gd.calcdata.forEach(function(cd) {
383-
// fill in some stuff that happens during setPositions or plot
383+
// fill in some stuff that happens during crossTraceCalc or plot
384384
if(cd[0].trace.type === 'candlestick') {
385385
var diff = cd[1].pos - cd[0].pos;
386386
cd[0].t.wHover = diff / 2;

test/jasmine/tests/histogram_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ describe('Test histogram', function() {
237237
var d73 = Date.UTC(1973, 0, 1);
238238
expect(out).toEqual([
239239
// full calcdata has x and y too (and t in the first one),
240-
// but those come later from setPositions.
240+
// but those come later from crossTraceCalc.
241241
{i: 0, b: 0, p: d70, s: 2, pts: [0, 1], p0: d70, p1: d70},
242242
{i: 1, b: 0, p: d71, s: 1, pts: [2], p0: d71, p1: d71},
243243
{i: 2, b: 0, p: d72, s: 0, pts: [], p0: d72, p1: d72},

0 commit comments

Comments
 (0)