Skip to content

Commit 8583693

Browse files
committed
added start end and size attributes
1 parent 15caa05 commit 8583693

File tree

5 files changed

+136
-11
lines changed

5 files changed

+136
-11
lines changed

package-lock.json

Lines changed: 30 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/traces/surface/attributes.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,40 @@ function makeContourAttr(axLetter) {
4343
'dimension are drawn.'
4444
].join(' ')
4545
},
46+
start: {
47+
valType: 'number',
48+
dflt: null,
49+
role: 'style',
50+
editType: 'plot',
51+
// impliedEdits: {'^autocontour': false},
52+
description: [
53+
'Sets the starting contour level value.',
54+
'Must be less than `contours.end`'
55+
].join(' ')
56+
},
57+
end: {
58+
valType: 'number',
59+
dflt: null,
60+
role: 'style',
61+
editType: 'plot',
62+
// impliedEdits: {'^autocontour': false},
63+
description: [
64+
'Sets the end contour level value.',
65+
'Must be more than `contours.start`'
66+
].join(' ')
67+
},
68+
size: {
69+
valType: 'number',
70+
dflt: null,
71+
min: 0,
72+
role: 'style',
73+
editType: 'plot',
74+
// impliedEdits: {'^autocontour': false},
75+
description: [
76+
'Sets the step between each contour level.',
77+
'Must be positive.'
78+
].join(' ')
79+
},
4680
locations: {
4781
valType: 'data_array',
4882
dflt: false,

src/traces/surface/convert.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ function SurfaceTrace(scene, surface, uid) {
2525
this.surface = surface;
2626
this.data = null;
2727
this.showContour = [false, false, false];
28+
this.contourStart = [null, null, null];
29+
this.contourEnd = [null, null, null];
30+
this.contourSize = [0, 0, 0];
2831
this.contourLocations = [[], [], []];
2932
this.contourRelative = [0, 0]; // note: only available on x & y not z.
3033
this.minValues = [Infinity, Infinity, Infinity];
@@ -412,6 +415,22 @@ proto.setContourLevels = function() {
412415
insertIfNewLevel(newLevels[i], value);
413416
}
414417
}
418+
419+
if(
420+
this.contourSize[i] > 0 &&
421+
this.contourStart[i] !== null &&
422+
this.contourEnd[i] !== null &&
423+
this.contourEnd[i] > this.contourStart[i]
424+
) {
425+
useNewLevels[i] = true;
426+
427+
for(j = this.contourStart[i]; j < this.contourEnd[i]; j += this.contourSize[i]) {
428+
value = j * this.scene.dataScale[i];
429+
430+
insertIfNewLevel(newLevels[i], value);
431+
}
432+
}
433+
415434
}
416435
}
417436

@@ -613,10 +632,19 @@ proto.update = function(data) {
613632
}
614633
params.contourWidth[i] = contourParams.width;
615634

635+
this.contourStart[i] = contourParams.start;
636+
this.contourEnd[i] = contourParams.end;
637+
this.contourSize[i] = contourParams.size;
638+
616639
this.contourLocations[i] = contourParams.locations;
617640
if(i < 2) this.contourRelative[i] = contourParams.relative;
618641
} else {
619642
this.showContour[i] = false;
643+
644+
this.contourStart[i] = null;
645+
this.contourEnd[i] = null;
646+
this.contourSize[i] = 0;
647+
620648
this.contourLocations[i] = [];
621649
if(i < 2) this.contourRelative[i] = 0;
622650
}

src/traces/surface/defaults.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
8282
coerce(contourDim + '.highlightcolor');
8383
coerce(contourDim + '.highlightwidth');
8484
}
85+
86+
coerce(contourDim + '.start');
87+
coerce(contourDim + '.end');
88+
coerce(contourDim + '.size');
8589
}
8690

8791
// backward compatibility block
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"data": [
3+
{
4+
"type": "surface",
5+
"contours": {
6+
"x": { "show": true, "start": 0.1, "end": 0.4, "size": 0.05 },
7+
"y": { "show": true, "start": 0.1, "end": 0.4, "size": 0.05 },
8+
"z": { "show": true, "start": 0.1, "end": 0.4, "size": 0.05 }
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+
"layout": {
22+
"title": "Surface contours using start, end and size",
23+
"width": 900,
24+
"height": 600,
25+
"scene": {
26+
"xaxis": { "nticks": 12 },
27+
"yaxis": { "nticks": 12 },
28+
"zaxis": { "nticks": 4 },
29+
"camera": {
30+
"eye": { "x": 0, "y": -1, "z": 0.75 },
31+
"center": { "x": 0, "y": 0, "z": 0 }
32+
},
33+
"aspectratio": {
34+
"x": 1,
35+
"y": 1,
36+
"z": 0.2
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)