Skip to content

Commit 120e560

Browse files
committed
contours on desired locations
1 parent 5051378 commit 120e560

File tree

6 files changed

+92
-12
lines changed

6 files changed

+92
-12
lines changed

src/traces/surface/attributes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ function makeContourAttr(axLetter) {
4343
'dimension are drawn.'
4444
].join(' ')
4545
},
46+
locations: {
47+
valType: 'data_array',
48+
dflt: [],
49+
role: 'info',
50+
description: [
51+
'Specifies the location(s) of contours on the', axLetter, 'axis.'
52+
].join(' ')
53+
},
4654
onpoints: {
4755
valType: 'number',
4856
role: 'info',

src/traces/surface/convert.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function SurfaceTrace(scene, surface, uid) {
2525
this.surface = surface;
2626
this.data = null;
2727
this.showContour = [false, false, false];
28+
this.contourLocations = [[], [], []];
2829
this.onPointsContour = [false, false]; // note: only available on x & y not z.
2930
this.minValues = [Infinity, Infinity, Infinity];
3031
this.maxValues = [-Infinity, -Infinity, -Infinity];
@@ -349,7 +350,18 @@ proto.setContourLevels = function() {
349350
var nlevels = [[], [], []];
350351
var needsUpdate = false;
351352

352-
var i, j;
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+
}
360+
}
361+
if(found === false) arr.push(newValue);
362+
}
363+
364+
var i, j, value;
353365

354366
for(i = 0; i < 3; ++i) {
355367
if(this.showContour[i]) {
@@ -374,7 +386,6 @@ proto.setContourLevels = function() {
374386
this.getXat(q, 0) * this.scene.dataScale[i] :
375387
this.getYat(0, q) * this.scene.dataScale[i];
376388

377-
var value;
378389
if(ratio < 1) {
379390
var prev = (i === 0) ?
380391
this.getXat(q - 1, 0) * this.scene.dataScale[i] :
@@ -385,17 +396,17 @@ proto.setContourLevels = function() {
385396
value = here;
386397
}
387398

388-
var found = false;
389-
for(j = 0; j < nlevels[i].length; j++) {
390-
if(value === nlevels[i][j]) {
391-
found = true;
392-
break;
393-
}
394-
}
395-
if(found === false) nlevels[i].push(value);
399+
insertIfNewLevel(nlevels[i], value);
396400
}
397401
}
398402

403+
var locations = this.contourLocations[i];
404+
if(locations.length) {
405+
for(j = 0; j < locations.length; j++) {
406+
value = locations[j] * this.scene.dataScale[i];
407+
insertIfNewLevel(nlevels[i], value);
408+
}
409+
}
399410
}
400411
}
401412

@@ -591,9 +602,11 @@ proto.update = function(data) {
591602
}
592603
params.contourWidth[i] = contourParams.width;
593604

605+
this.contourLocations[i] = contourParams.locations;
594606
if(i < 2) this.onPointsContour[i] = contourParams.onpoints;
595607
} else {
596608
this.showContour[i] = false;
609+
this.contourLocations[i] = [];
597610
if(i < 2) this.onPointsContour[i] = 0;
598611
}
599612

src/traces/surface/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
7474
coerce(contourDim + '.color');
7575
coerce(contourDim + '.width');
7676
coerce(contourDim + '.usecolormap');
77+
coerce(contourDim + '.locations');
7778
if(i < 2) coerce(contourDim + '.onpoints');
7879
}
7980

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"contours": {
66
"x": { "show": true, "onpoints": 1 },
77
"y": { "show": true, "onpoints": 1 },
8-
"z": { "show": false}
8+
"z": { "show": false }
99
},
1010
"x": [0, 0.25, 0.5, 0.75, 1],
1111
"y": [0, 0.25, 0.5, 0.75, 1],
@@ -22,7 +22,7 @@
2222
"contours": {
2323
"x": { "show": true, "onpoints": 0.5 },
2424
"y": { "show": true, "onpoints": 0.5 },
25-
"z": { "show": false}
25+
"z": { "show": false }
2626
},
2727
"x": [1.5, 1.75, 2, 2.25, 2.5],
2828
"y": [0, 0.25, 0.5, 0.75, 1],
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"data": [
3+
{
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+
]
19+
},
20+
{
21+
"type": "surface",
22+
"contours": {
23+
"x": { "show": true, "locations": [1.7, 1.75, 1.8] },
24+
"y": { "show": true, "locations": [0.5, 0.6, 0.8, 0.8] },
25+
"z": { "show": true, "locations": [0.2, 0.25, 0.3] }
26+
},
27+
"x": [1.5, 1.75, 2, 2.25, 2.5],
28+
"y": [0, 0.25, 0.5, 0.75, 1],
29+
"z": [
30+
[0, 1, 0, 1, 0],
31+
[1, 0, 1, 0, 1],
32+
[0, 1, 0, 1, 0],
33+
[1, 0, 1, 0, 1],
34+
[0, 1, 0, 1, 0]
35+
]
36+
}
37+
],
38+
"layout": {
39+
"title": "Surface contours on desired locations",
40+
"width": 900,
41+
"height": 600,
42+
"scene": {
43+
"xaxis": { "nticks": 1 },
44+
"yaxis": { "nticks": 1 },
45+
"zaxis": { "nticks": 1 },
46+
"camera": {
47+
"eye": { "x": 0, "y": -0.9, "z": 1.8 },
48+
"center": { "x": 0, "y": 0, "z": 0 }
49+
},
50+
"aspectratio": {
51+
"x": 2,
52+
"y": 1,
53+
"z": 1
54+
}
55+
}
56+
}
57+
}

test/jasmine/tests/surface_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('Test surface', function() {
6363
expect(traceOut.contours.y).toEqual(Lib.extendDeep({}, fullOpts, {
6464
show: true,
6565
onpoints: 0,
66+
locations: [],
6667
color: '#444',
6768
width: 2,
6869
usecolormap: false

0 commit comments

Comments
 (0)