Skip to content

Make surface contour levels configurable #3469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/traces/isosurface/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function makeSliceAttr(axLetter) {
role: 'info',
description: [
'Specifies the location(s) of slices on the axis.',
'When not locations specified slices would be created for',
'When not specified slices would be created for',
'all points of the axis', axLetter, 'except start and end.'
].join(' ')
},
Expand Down
34 changes: 34 additions & 0 deletions src/traces/surface/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,40 @@ function makeContourAttr(axLetter) {
'dimension are drawn.'
].join(' ')
},
start: {
valType: 'number',
dflt: null,
role: 'style',
editType: 'plot',
// impliedEdits: {'^autocontour': false},
description: [
'Sets the starting contour level value.',
'Must be less than `contours.end`'
].join(' ')
},
end: {
valType: 'number',
dflt: null,
role: 'style',
editType: 'plot',
// impliedEdits: {'^autocontour': false},
description: [
'Sets the end contour level value.',
'Must be more than `contours.start`'
].join(' ')
},
size: {
valType: 'number',
dflt: null,
min: 0,
role: 'style',
editType: 'plot',
// impliedEdits: {'^autocontour': false},
description: [
'Sets the step between each contour level.',
'Must be positive.'
].join(' ')
},
project: {
x: makeContourProjAttr('x'),
y: makeContourProjAttr('y'),
Expand Down
66 changes: 54 additions & 12 deletions src/traces/surface/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ function SurfaceTrace(scene, surface, uid) {
this.surface = surface;
this.data = null;
this.showContour = [false, false, false];
this.contourStart = [null, null, null];
this.contourEnd = [null, null, null];
this.contourSize = [0, 0, 0];
this.minValues = [Infinity, Infinity, Infinity];
this.maxValues = [-Infinity, -Infinity, -Infinity];
this.dataScaleX = 1.0;
this.dataScaleY = 1.0;
this.refineData = true;
this._interpolatedZ = false;
this.objectOffset = [0, 0, 0];
}

var proto = SurfaceTrace.prototype;
Expand Down Expand Up @@ -349,19 +352,54 @@ proto.refineCoords = function(coords) {
}
};

function insertIfNewLevel(arr, newValue) {
var found = false;
for(var k = 0; k < arr.length; k++) {
if(newValue === arr[k]) {
found = true;
break;
}
}
if(found === false) arr.push(newValue);
}

proto.setContourLevels = function() {
var nlevels = [[], [], []];
var newLevels = [[], [], []];
var useNewLevels = [false, false, false];
var needsUpdate = false;

for(var i = 0; i < 3; ++i) {
var i, j, value;

for(i = 0; i < 3; ++i) {
if(this.showContour[i]) {
needsUpdate = true;
nlevels[i] = this.scene.contourLevels[i];

if(
this.contourSize[i] > 0 &&
this.contourStart[i] !== null &&
this.contourEnd[i] !== null &&
this.contourEnd[i] > this.contourStart[i]
) {
useNewLevels[i] = true;

for(j = this.contourStart[i]; j < this.contourEnd[i]; j += this.contourSize[i]) {
value = j * this.scene.dataScale[i];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried re-using setContours? It probably gives similar results, but it would be nice to double-check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that on a different branch. Also wanted to add autocontours and ncontours in this PR.
But unfortunately that could add too much complexity while surface contours are in 3 directions not only z.


insertIfNewLevel(newLevels[i], value);
}
}

}
}

if(needsUpdate) {
this.surface.update({ levels: nlevels });
var allLevels = [[], [], []];
for(i = 0; i < 3; ++i) {
if(this.showContour[i]) {
allLevels[i] = useNewLevels[i] ? newLevels[i] : this.scene.contourLevels[i];
}
}
this.surface.update({ levels: allLevels });
}
};

Expand Down Expand Up @@ -456,15 +494,15 @@ proto.update = function(data) {
}

for(i = 0; i < 3; i++) {
data._objectOffset[i] = 0.5 * (this.minValues[i] + this.maxValues[i]);
this.objectOffset[i] = 0.5 * (this.minValues[i] + this.maxValues[i]);
}

for(i = 0; i < 3; i++) {
for(j = 0; j < xlen; j++) {
for(k = 0; k < ylen; k++) {
v = rawCoords[i][j][k];
if(v !== null && v !== undefined) {
rawCoords[i][j][k] -= data._objectOffset[i];
rawCoords[i][j][k] -= this.objectOffset[i];
}
}
}
Expand Down Expand Up @@ -564,8 +602,16 @@ proto.update = function(data) {
surface.highlightTint[i] = params.contourTint[i] = 1;
}
params.contourWidth[i] = contourParams.width;

this.contourStart[i] = contourParams.start;
this.contourEnd[i] = contourParams.end;
this.contourSize[i] = contourParams.size;
} else {
this.showContour[i] = false;

this.contourStart[i] = null;
this.contourEnd[i] = null;
this.contourSize[i] = 0;
}

if(contourParams.highlight) {
Expand All @@ -579,11 +625,7 @@ proto.update = function(data) {
params.vertexColor = true;
}

params.objectOffset = [
data._objectOffset[0],
data._objectOffset[1],
data._objectOffset[2]
];
params.objectOffset = this.objectOffset;

params.coords = coords;
surface.update(params);
Expand Down
6 changes: 4 additions & 2 deletions src/traces/surface/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
traceOut._xlength = (Array.isArray(x) && Lib.isArrayOrTypedArray(x[0])) ? z.length : z[0].length;
traceOut._ylength = z.length;

traceOut._objectOffset = [0, 0, 0];

var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);

Expand Down Expand Up @@ -85,6 +83,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce(contourDim + '.highlightcolor');
coerce(contourDim + '.highlightwidth');
}

coerce(contourDim + '.start');
coerce(contourDim + '.end');
coerce(contourDim + '.size');
}

// backward compatibility block
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading