Skip to content

Commit 3d26d47

Browse files
committed
fixup cone autorange pad computation
1 parent 8dca9ae commit 3d26d47

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

Diff for: src/plots/gl3d/scene.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,9 @@ proto.plot = function(sceneData, fullLayout, layout) {
507507
for(j = 0; j < objects.length; j++) {
508508
var obj = objects[j];
509509
var objBounds = obj.bounds;
510-
// add worse-case pad for cone traces
511-
var pad = 0.75 * (obj._trace.data._compMax || 0) * dataScale[i];
510+
var fullTrace = obj._trace.data;
511+
var pad = fullTrace._pad ? fullTrace._pad / dataScale[i] : 0;
512+
512513
sceneBounds[0][i] = Math.min(sceneBounds[0][i], objBounds[0][i] / dataScale[i] - pad);
513514
sceneBounds[1][i] = Math.max(sceneBounds[1][i], objBounds[1][i] / dataScale[i] + pad);
514515
}

Diff for: src/traces/cone/calc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ module.exports = function calc(gd, trace) {
3535

3636
// stash max norm value to convert cmix/cmax -> vertexIntensityBounds
3737
trace._normMax = normMax;
38-
// stash max 'component' value for autorange pad
39-
trace._compMax = Math.sqrt(compMax);
38+
// stash autorange pad using max 'component' value
39+
trace._pad = Math.sqrt(compMax) / (normMax || 1);
4040

4141
colorscaleCalc(trace, [normMin, normMax], '', 'c');
4242
};

Diff for: test/jasmine/tests/cone_test.js

+63
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,69 @@ describe('Test cone defaults', function() {
6060
});
6161
});
6262

63+
describe('@gl Test cone autorange', function() {
64+
var gd;
65+
66+
beforeEach(function() {
67+
gd = createGraphDiv();
68+
});
69+
70+
afterEach(function() {
71+
Plotly.purge(gd);
72+
destroyGraphDiv();
73+
});
74+
75+
function _assertAxisRanges(msg, xrng, yrng, zrng) {
76+
var sceneLayout = gd._fullLayout.scene;
77+
expect(sceneLayout.xaxis.range).toBeCloseToArray(xrng, 2, 'xaxis range -' + msg);
78+
expect(sceneLayout.yaxis.range).toBeCloseToArray(yrng, 2, 'yaxis range -' + msg);
79+
expect(sceneLayout.zaxis.range).toBeCloseToArray(zrng, 2, 'zaxis range -' + msg);
80+
}
81+
82+
it('should add pad around cone position to make sure they fit on the scene', function(done) {
83+
var fig = Lib.extendDeep({}, require('@mocks/gl3d_cone-autorange.json'));
84+
85+
// the resulting image should be independent of what I multiply by here
86+
function makeScaleFn(s) {
87+
return function(v) { return v * s; };
88+
}
89+
90+
Plotly.plot(gd, fig).then(function() {
91+
_assertAxisRanges('base',
92+
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
93+
);
94+
95+
var trace = fig.data[0];
96+
var m = makeScaleFn(10);
97+
var u = trace.u.map(m);
98+
var v = trace.v.map(m);
99+
var w = trace.w.map(m);
100+
101+
return Plotly.restyle(gd, {u: [u], v: [v], w: [w]});
102+
})
103+
.then(function() {
104+
_assertAxisRanges('scaled up',
105+
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
106+
);
107+
108+
var trace = fig.data[0];
109+
var m = makeScaleFn(0.2);
110+
var u = trace.u.map(m);
111+
var v = trace.v.map(m);
112+
var w = trace.w.map(m);
113+
114+
return Plotly.restyle(gd, {u: [u], v: [v], w: [w]});
115+
})
116+
.then(function() {
117+
_assertAxisRanges('scaled down',
118+
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
119+
);
120+
})
121+
.catch(failTest)
122+
.then(done);
123+
});
124+
});
125+
63126
describe('@gl Test cone interactions', function() {
64127
var gd;
65128

0 commit comments

Comments
 (0)