Skip to content

Commit c48386c

Browse files
committed
revised relative contours now arrayOk
1 parent 669662f commit c48386c

7 files changed

+53
-45
lines changed

src/traces/surface/attributes.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,21 @@ function makeContourAttr(axLetter) {
4848
dflt: false,
4949
role: 'info',
5050
description: [
51-
'Specifies the location(s) of contours on the', axLetter, 'axis.'
51+
'Specifies the world location(s) of contours on the', axLetter, 'axis.'
5252
].join(' ')
5353
},
54-
onpoints: {
54+
relative: {
5555
valType: 'number',
56+
arrayOk: true,
5657
role: 'info',
57-
max: 1,
58-
min: 0,
5958
dflt: 0,
59+
min: 0,
60+
max: 1,
6061
description: [
61-
'Determines whether or contour lines about the', axLetter,
62-
'dimension are drawn on all data points. Ratios between 0 and 1',
63-
'e.g. 0.5 could also be applied to locate contours between data points'
62+
'Specifies the local location(s) of contours on the', axLetter, 'axis.',
63+
'For exampe 1.0 could also be applied to locate contours on data points.',
64+
'Or 0.5 could also be applied to locate contours between data points.',
65+
'Values less than or equal to zero and greater than one would be ignored.'
6466
].join(' ')
6567
},
6668
project: {
@@ -277,4 +279,4 @@ colorscaleAttrs('', {
277279

278280
attrs.x.editType = attrs.y.editType = attrs.z.editType = 'calc+clearAxisTypes';
279281
attrs.transforms = undefined;
280-
delete attrs.contours.z.onpoints;
282+
delete attrs.contours.z.relative;

src/traces/surface/convert.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function SurfaceTrace(scene, surface, uid) {
2626
this.data = null;
2727
this.showContour = [false, false, false];
2828
this.contourLocations = [[], [], []];
29-
this.onPointsContour = [false, false]; // note: only available on x & y not z.
29+
this.contourRelative = [0, 0]; // note: only available on x & y not z.
3030
this.minValues = [Infinity, Infinity, Infinity];
3131
this.maxValues = [-Infinity, -Infinity, -Infinity];
3232
this.dataScaleX = 1.0;
@@ -359,43 +359,47 @@ function insertIfNewLevel(arr, newValue) {
359359

360360
proto.setContourLevels = function() {
361361
var newLevels = [[], [], []];
362-
var needsUpdate = false;
363362
var useNewLevels = [false, false, false];
363+
var needsUpdate = false;
364364

365365
var i, j, value;
366366

367367
for(i = 0; i < 3; ++i) {
368368
if(this.showContour[i]) {
369369
needsUpdate = true;
370370

371-
newLevels[i] = [];
371+
if(i < 2) {
372+
var ratios = Array.isArray(this.contourRelative[i]) ?
373+
this.contourRelative[i] : [this.contourRelative[i]];
372374

373-
if(i < 2 && this.onPointsContour[i] !== 0) {
374-
useNewLevels[i] = true;
375+
for(var k = 0; k < ratios.length; k++) {
376+
var ratio = ratios[k];
377+
if(ratio !== 0) {
375378

376-
var ratio = this.onPointsContour[i];
379+
var len = (i === 0) ?
380+
this.data.z[0].length :
381+
this.data._ylength;
377382

378-
var len = (i === 0) ?
379-
this.data.z[0].length :
380-
this.data._ylength;
383+
for(var q = (ratio < 1) ? 1 : 0; q < len; q++) {
381384

382-
for(var q = (ratio < 1) ? 1 : 0; q < len; q++) {
385+
var here = (i === 0) ?
386+
this.getXat(q, 0) * this.scene.dataScale[i] :
387+
this.getYat(0, q) * this.scene.dataScale[i];
383388

384-
var here = (i === 0) ?
385-
this.getXat(q, 0) * this.scene.dataScale[i] :
386-
this.getYat(0, q) * this.scene.dataScale[i];
389+
if(ratio < 1) {
390+
var prev = (i === 0) ?
391+
this.getXat(q - 1, 0) * this.scene.dataScale[i] :
392+
this.getYat(0, q - 1) * this.scene.dataScale[i];
387393

388-
if(ratio < 1) {
389-
var prev = (i === 0) ?
390-
this.getXat(q - 1, 0) * this.scene.dataScale[i] :
391-
this.getYat(0, q - 1) * this.scene.dataScale[i];
394+
value = here * ratio + prev * (1 - ratio);
395+
} else {
396+
value = here;
397+
}
392398

393-
value = here * ratio + prev * (1 - ratio);
394-
} else {
395-
value = here;
399+
insertIfNewLevel(newLevels[i], value);
400+
useNewLevels[i] = true;
401+
}
396402
}
397-
398-
insertIfNewLevel(newLevels[i], value);
399403
}
400404
}
401405

@@ -412,11 +416,13 @@ proto.setContourLevels = function() {
412416
}
413417

414418
if(needsUpdate) {
415-
var levels = [];
419+
var allLevels = [[], [], []];
416420
for(i = 0; i < 3; ++i) {
417-
levels[i] = (useNewLevels[i]) ? newLevels[i] : this.scene.contourLevels[i];
421+
if(this.showContour[i]) {
422+
allLevels[i] = useNewLevels[i] ? newLevels[i] : this.scene.contourLevels[i];
423+
}
418424
}
419-
this.surface.update({ levels: levels });
425+
this.surface.update({ levels: allLevels });
420426
}
421427
};
422428

@@ -608,11 +614,11 @@ proto.update = function(data) {
608614
params.contourWidth[i] = contourParams.width;
609615

610616
this.contourLocations[i] = contourParams.locations;
611-
if(i < 2) this.onPointsContour[i] = contourParams.onpoints;
617+
if(i < 2) this.contourRelative[i] = contourParams.relative;
612618
} else {
613619
this.showContour[i] = false;
614620
this.contourLocations[i] = [];
615-
if(i < 2) this.onPointsContour[i] = 0;
621+
if(i < 2) this.contourRelative[i] = 0;
616622
}
617623

618624
if(contourParams.highlight) {

src/traces/surface/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
7575
coerce(contourDim + '.width');
7676
coerce(contourDim + '.usecolormap');
7777
coerce(contourDim + '.locations');
78-
if(i < 2) coerce(contourDim + '.onpoints');
78+
if(i < 2) coerce(contourDim + '.relative');
7979
}
8080

8181
if(highlight) {
Loading
Binary file not shown.
Loading

test/image/mocks/gl3d_surface_contour_on-xy-data-points.json renamed to test/image/mocks/gl3d_surface_contour_between-xy-data-points.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{
44
"type": "surface",
55
"contours": {
6-
"x": { "show": true, "onpoints": 1 },
7-
"y": { "show": true, "onpoints": 1 },
6+
"x": { "show": true, "relative": 1 },
7+
"y": { "show": true, "relative": 1 },
88
"z": { "show": false }
99
},
1010
"x": [0, 0.25, 0.5, 0.75, 1],
@@ -20,8 +20,8 @@
2020
{
2121
"type": "surface",
2222
"contours": {
23-
"x": { "show": true, "onpoints": 0.5 },
24-
"y": { "show": true, "onpoints": 0.5 },
23+
"x": { "show": true, "relative": 0.5 },
24+
"y": { "show": true, "relative": 0.5 },
2525
"z": { "show": false }
2626
},
2727
"x": [1.5, 1.75, 2, 2.25, 2.5],
@@ -39,7 +39,7 @@
3939
"contours": {
4040
"x": { "show": true },
4141
"y": { "show": true },
42-
"z": { "show": true }
42+
"z": { "show": false }
4343
},
4444
"x": [0, 0.25, 0.5, 0.75, 1],
4545
"y": [1.5, 1.75, 2, 2.25, 2.5],
@@ -54,9 +54,9 @@
5454
{
5555
"type": "surface",
5656
"contours": {
57-
"x": { "show": true, "locations": [] },
58-
"y": { "show": true, "locations": [] },
59-
"z": { "show": true, "locations": [] }
57+
"x": { "show": true, "relative": [0.25, 0.75] },
58+
"y": { "show": true, "relative": [0.333, 0.666] },
59+
"z": { "show": false }
6060
},
6161
"x": [1.5, 1.75, 2, 2.25, 2.5],
6262
"y": [1.5, 1.75, 2, 2.25, 2.5],
@@ -78,7 +78,7 @@
7878
"yaxis": { "nticks": 12 },
7979
"zaxis": { "nticks": 12 },
8080
"camera": {
81-
"eye": { "x": 0, "y": -1, "z": 0.75 },
81+
"eye": { "x": 1, "y": 0, "z": 0.75 },
8282
"center": { "x": 0, "y": 0, "z": 0 }
8383
},
8484
"aspectratio": {

0 commit comments

Comments
 (0)