Skip to content

Commit 669662f

Browse files
committed
separated nticks contours and locations if locations are empty then disable nticks if false draw ntick contours
1 parent bd498ea commit 669662f

File tree

4 files changed

+135
-62
lines changed

4 files changed

+135
-62
lines changed

src/traces/surface/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function makeContourAttr(axLetter) {
4545
},
4646
locations: {
4747
valType: 'data_array',
48-
dflt: [],
48+
dflt: false,
4949
role: 'info',
5050
description: [
5151
'Specifies the location(s) of contours on the', axLetter, 'axis.'

src/traces/surface/convert.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -346,33 +346,32 @@ proto.refineCoords = function(coords) {
346346
}
347347
};
348348

349-
proto.setContourLevels = function() {
350-
var nlevels = [[], [], []];
351-
var needsUpdate = false;
352-
353-
function insertIfNewLevel(arr, newValue) {
354-
var found = false;
355-
for(var k = 0; k < arr.length; k++) {
356-
if(newValue === arr[k]) {
357-
found = true;
358-
break;
359-
}
349+
function insertIfNewLevel(arr, newValue) {
350+
var found = false;
351+
for(var k = 0; k < arr.length; k++) {
352+
if(newValue === arr[k]) {
353+
found = true;
354+
break;
360355
}
361-
if(found === false) arr.push(newValue);
362356
}
357+
if(found === false) arr.push(newValue);
358+
}
359+
360+
proto.setContourLevels = function() {
361+
var newLevels = [[], [], []];
362+
var needsUpdate = false;
363+
var useNewLevels = [false, false, false];
363364

364365
var i, j, value;
365366

366367
for(i = 0; i < 3; ++i) {
367368
if(this.showContour[i]) {
368369
needsUpdate = true;
369370

370-
nlevels[i] = [];
371-
for(j = 0; j < this.scene.contourLevels[i].length; j++) {
372-
nlevels[i][j] = this.scene.contourLevels[i][j];
373-
}
371+
newLevels[i] = [];
374372

375373
if(i < 2 && this.onPointsContour[i] !== 0) {
374+
useNewLevels[i] = true;
376375

377376
var ratio = this.onPointsContour[i];
378377

@@ -396,22 +395,28 @@ proto.setContourLevels = function() {
396395
value = here;
397396
}
398397

399-
insertIfNewLevel(nlevels[i], value);
398+
insertIfNewLevel(newLevels[i], value);
400399
}
401400
}
402401

403402
var locations = this.contourLocations[i];
403+
if(locations !== false) useNewLevels[i] = true;
404404
if(locations.length) {
405405
for(j = 0; j < locations.length; j++) {
406406
value = locations[j] * this.scene.dataScale[i];
407-
insertIfNewLevel(nlevels[i], value);
407+
408+
insertIfNewLevel(newLevels[i], value);
408409
}
409410
}
410411
}
411412
}
412413

413414
if(needsUpdate) {
414-
this.surface.update({ levels: nlevels });
415+
var levels = [];
416+
for(i = 0; i < 3; ++i) {
417+
levels[i] = (useNewLevels[i]) ? newLevels[i] : this.scene.contourLevels[i];
418+
}
419+
this.surface.update({ levels: levels });
415420
}
416421
};
417422

test/image/mocks/gl3d_surface_contour_on-xy-data-points.json

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
22
"data": [
33
{
4-
"type": "surface",
5-
"contours": {
6-
"x": { "show": true, "onpoints": 1 },
7-
"y": { "show": true, "onpoints": 1 },
8-
"z": { "show": false }
9-
},
10-
"x": [0, 0.25, 0.5, 0.75, 1],
11-
"y": [0, 0.25, 0.5, 0.75, 1],
12-
"z": [
13-
[0, 1, 0, 1, 0],
14-
[1, 0, 1, 0, 1],
15-
[0, 1, 0, 1, 0],
16-
[1, 0, 1, 0, 1],
17-
[0, 1, 0, 1, 0]
18-
]
4+
"type": "surface",
5+
"contours": {
6+
"x": { "show": true, "onpoints": 1 },
7+
"y": { "show": true, "onpoints": 1 },
8+
"z": { "show": false }
9+
},
10+
"x": [0, 0.25, 0.5, 0.75, 1],
11+
"y": [0, 0.25, 0.5, 0.75, 1],
12+
"z": [
13+
[0, 1, 0, 1, 0],
14+
[1, 0, 1, 0, 1],
15+
[0, 1, 0, 1, 0],
16+
[1, 0, 1, 0, 1],
17+
[0, 1, 0, 1, 0]
18+
]
1919
},
2020
{
2121
"type": "surface",
@@ -33,24 +33,58 @@
3333
[1, 0, 1, 0, 1],
3434
[0, 1, 0, 1, 0]
3535
]
36+
},
37+
{
38+
"type": "surface",
39+
"contours": {
40+
"x": { "show": true },
41+
"y": { "show": true },
42+
"z": { "show": true }
43+
},
44+
"x": [0, 0.25, 0.5, 0.75, 1],
45+
"y": [1.5, 1.75, 2, 2.25, 2.5],
46+
"z": [
47+
[0, 1, 0, 1, 0],
48+
[1, 0, 1, 0, 1],
49+
[0, 1, 0, 1, 0],
50+
[1, 0, 1, 0, 1],
51+
[0, 1, 0, 1, 0]
52+
]
53+
},
54+
{
55+
"type": "surface",
56+
"contours": {
57+
"x": { "show": true, "locations": [] },
58+
"y": { "show": true, "locations": [] },
59+
"z": { "show": true, "locations": [] }
60+
},
61+
"x": [1.5, 1.75, 2, 2.25, 2.5],
62+
"y": [1.5, 1.75, 2, 2.25, 2.5],
63+
"z": [
64+
[0, 1, 0, 1, 0],
65+
[1, 0, 1, 0, 1],
66+
[0, 1, 0, 1, 0],
67+
[1, 0, 1, 0, 1],
68+
[0, 1, 0, 1, 0]
69+
]
3670
}
3771
],
3872
"layout": {
3973
"title": "Surface contours on or between all x & y data points",
4074
"width": 900,
4175
"height": 600,
4276
"scene": {
43-
"xaxis": { "nticks": 1 },
44-
"yaxis": { "nticks": 1 },
45-
"zaxis": { "nticks": 1 },
77+
"xaxis": { "nticks": 12 },
78+
"yaxis": { "nticks": 12 },
79+
"zaxis": { "nticks": 12 },
4680
"camera": {
47-
"eye": { "x": 0, "y": -0.9, "z": 1.8 },
81+
"eye": { "x": 0, "y": -1, "z": 0.75 },
4882
"center": { "x": 0, "y": 0, "z": 0 }
4983
},
5084
"aspectratio": {
51-
"x": 2,
85+
"x": 1,
5286
"y": 1,
53-
"z": 1
87+
"z": 0.2
5488
}
5589
}
5690
}

test/image/mocks/gl3d_surface_contour_on-xyz-locations.json

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
22
"data": [
33
{
4-
"type": "surface",
5-
"contours": {
6-
"x": { "show": true, "locations": [0.2, 0.25, 0.3, 0.35, 0.4] },
7-
"y": { "show": true, "locations": [0.2, 0.3, 0.4, 0.5] },
8-
"z": { "show": true, "locations": [0.7, 0.75, 0.8] }
9-
},
10-
"x": [0, 0.25, 0.5, 0.75, 1],
11-
"y": [0, 0.25, 0.5, 0.75, 1],
12-
"z": [
13-
[0, 1, 0, 1, 0],
14-
[1, 0, 1, 0, 1],
15-
[0, 1, 0, 1, 0],
16-
[1, 0, 1, 0, 1],
17-
[0, 1, 0, 1, 0]
18-
]
4+
"type": "surface",
5+
"contours": {
6+
"x": { "show": true, "locations": [0.2, 0.25, 0.3, 0.35, 0.4] },
7+
"y": { "show": true, "locations": [0.2, 0.3, 0.4, 0.5] },
8+
"z": { "show": true, "locations": [0.7, 0.75, 0.8] }
9+
},
10+
"x": [0, 0.25, 0.5, 0.75, 1],
11+
"y": [0, 0.25, 0.5, 0.75, 1],
12+
"z": [
13+
[0, 1, 0, 1, 0],
14+
[1, 0, 1, 0, 1],
15+
[0, 1, 0, 1, 0],
16+
[1, 0, 1, 0, 1],
17+
[0, 1, 0, 1, 0]
18+
]
1919
},
2020
{
2121
"type": "surface",
@@ -33,24 +33,58 @@
3333
[1, 0, 1, 0, 1],
3434
[0, 1, 0, 1, 0]
3535
]
36+
},
37+
{
38+
"type": "surface",
39+
"contours": {
40+
"x": { "show": true },
41+
"y": { "show": true },
42+
"z": { "show": true }
43+
},
44+
"x": [0, 0.25, 0.5, 0.75, 1],
45+
"y": [1.5, 1.75, 2, 2.25, 2.5],
46+
"z": [
47+
[0, 1, 0, 1, 0],
48+
[1, 0, 1, 0, 1],
49+
[0, 1, 0, 1, 0],
50+
[1, 0, 1, 0, 1],
51+
[0, 1, 0, 1, 0]
52+
]
53+
},
54+
{
55+
"type": "surface",
56+
"contours": {
57+
"x": { "show": true, "locations": [] },
58+
"y": { "show": true, "locations": [] },
59+
"z": { "show": true, "locations": [] }
60+
},
61+
"x": [1.5, 1.75, 2, 2.25, 2.5],
62+
"y": [1.5, 1.75, 2, 2.25, 2.5],
63+
"z": [
64+
[0, 1, 0, 1, 0],
65+
[1, 0, 1, 0, 1],
66+
[0, 1, 0, 1, 0],
67+
[1, 0, 1, 0, 1],
68+
[0, 1, 0, 1, 0]
69+
]
3670
}
3771
],
3872
"layout": {
3973
"title": "Surface contours on desired locations",
4074
"width": 900,
4175
"height": 600,
4276
"scene": {
43-
"xaxis": { "nticks": 1 },
44-
"yaxis": { "nticks": 1 },
45-
"zaxis": { "nticks": 1 },
77+
"xaxis": { "nticks": 12 },
78+
"yaxis": { "nticks": 12 },
79+
"zaxis": { "nticks": 12 },
4680
"camera": {
47-
"eye": { "x": 0, "y": -0.9, "z": 1.8 },
81+
"eye": { "x": 0, "y": -1, "z": 0.75 },
4882
"center": { "x": 0, "y": 0, "z": 0 }
4983
},
5084
"aspectratio": {
51-
"x": 2,
85+
"x": 1,
5286
"y": 1,
53-
"z": 1
87+
"z": 0.2
5488
}
5589
}
5690
}

0 commit comments

Comments
 (0)