Skip to content

Commit fb2ec1e

Browse files
committed
use gl-cone2d "vectorScale" to get better autorange pad value
1 parent 3dd6cf5 commit fb2ec1e

File tree

8 files changed

+15
-17
lines changed

8 files changed

+15
-17
lines changed

src/plots/gl3d/scene.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,7 @@ 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-
var fullTrace = obj._trace.data;
511-
var pad = fullTrace._pad || 0;
510+
var pad = obj._trace.data._pad || 0;
512511

513512
sceneBounds[0][i] = Math.min(sceneBounds[0][i], objBounds[0][i] / dataScale[i] - pad);
514513
sceneBounds[1][i] = Math.max(sceneBounds[1][i], objBounds[1][i] / dataScale[i] + pad);

src/traces/cone/calc.js

-5
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ module.exports = function calc(gd, trace) {
3333
compMax = Math.max(compMax, u2, v2, w2);
3434
}
3535

36-
// stash max norm value to convert cmix/cmax -> vertexIntensityBounds
3736
trace._normMax = normMax;
38-
// stash autorange pad using max 'component' value
39-
trace._pad = trace.sizemode === 'absolute' ?
40-
trace.sizeref :
41-
2 * (Math.sqrt(compMax) / (normMax || 1)) * trace.sizeref;
4237

4338
colorscaleCalc(trace, [normMin, normMax], '', 'c');
4439
};

src/traces/cone/convert.js

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function zip3(x, y, z) {
6363
var axisName2scaleIndex = {xaxis: 0, yaxis: 1, zaxis: 2};
6464
var sizeMode2sizeKey = {scaled: 'coneSize', absolute: 'absoluteConeSize'};
6565
var anchor2coneOffset = {tip: 1, tail: 0, cm: 0.25, center: 0.5};
66+
var anchor2coneSpan = {tip: 1, tail: 1, cm: 0.75, center: 0.5};
6667

6768
function convert(scene, trace) {
6869
var sceneLayout = scene.fullSceneLayout;
@@ -107,6 +108,9 @@ function convert(scene, trace) {
107108
meshData.fresnel = trace.lighting.fresnel;
108109
meshData.opacity = trace.opacity;
109110

111+
// stash autorange pad value
112+
trace._pad = anchor2coneSpan[trace.anchor] * meshData.vectorScale * trace._normMax * trace.sizeref;
113+
110114
return meshData;
111115
}
112116

-1.69 KB
Loading
19.8 KB
Loading
-7.28 KB
Loading
3.53 KB
Loading

test/jasmine/tests/cone_test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ describe('@gl Test cone autorange:', function() {
7474

7575
function _assertAxisRanges(msg, xrng, yrng, zrng) {
7676
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);
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);
8080
}
8181

8282
it('should add pad around cone position to make sure they fit on the scene', function(done) {
@@ -89,7 +89,7 @@ describe('@gl Test cone autorange:', function() {
8989

9090
Plotly.plot(gd, fig).then(function() {
9191
_assertAxisRanges('base',
92-
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
92+
[-0.66, 4.66], [-0.66, 4.66], [-0.66, 4.66]
9393
);
9494

9595
var trace = fig.data[0];
@@ -102,7 +102,7 @@ describe('@gl Test cone autorange:', function() {
102102
})
103103
.then(function() {
104104
_assertAxisRanges('scaled up',
105-
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
105+
[-0.66, 4.66], [-0.66, 4.66], [-0.66, 4.66]
106106
);
107107

108108
var trace = fig.data[0];
@@ -115,7 +115,7 @@ describe('@gl Test cone autorange:', function() {
115115
})
116116
.then(function() {
117117
_assertAxisRanges('scaled down',
118-
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
118+
[-0.66, 4.66], [-0.66, 4.66], [-0.66, 4.66]
119119
);
120120

121121
var trace = fig.data[0];
@@ -140,21 +140,21 @@ describe('@gl Test cone autorange:', function() {
140140
})
141141
.then(function() {
142142
_assertAxisRanges('after adding one cone outside range but with norm-0',
143-
[-0.45, 6.45], [-0.45, 6.45], [-0.45, 6.45]
143+
[-0.72, 6.72], [-0.72, 6.72], [-0.72, 6.72]
144144
);
145145

146146
return Plotly.restyle(gd, 'sizeref', 10);
147147
})
148148
.then(function() {
149149
_assertAxisRanges('after increasing sizeref',
150-
[-12.4, 18.4], [-12.4, 18.4], [-12.4, 18.4]
150+
[-15.06, 21.06], [-15.06, 21.06], [-15.06, 21.06]
151151
);
152152

153153
return Plotly.restyle(gd, 'sizeref', 0.1);
154154
})
155155
.then(function() {
156156
_assertAxisRanges('after decreasing sizeref',
157-
[0.74, 5.26], [0.74, 5.26], [0.74, 5.26]
157+
[0.72, 5.28], [0.72, 5.28], [0.72, 5.28]
158158
);
159159

160160
return Plotly.restyle(gd, {
@@ -164,7 +164,7 @@ describe('@gl Test cone autorange:', function() {
164164
})
165165
.then(function() {
166166
_assertAxisRanges('with sizemode absolute',
167-
[-1.25, 7.25], [-1.25, 7.25], [-1.25, 7.25]
167+
[-2.31, 8.31], [-2.31, 8.31], [-2.31, 8.31]
168168
);
169169
})
170170
.catch(failTest)

0 commit comments

Comments
 (0)