Skip to content
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

Implementation of connectgaps for the surface trace #3638

Merged
merged 4 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 additions & 0 deletions src/traces/surface/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ var attrs = module.exports = overrideAll(extendFlat({
},
hovertemplate: hovertemplateAttrs(),

connectgaps: {
valType: 'boolean',
dflt: false,
role: 'info',
editType: 'calc',
description: [
'Determines whether or not gaps',
'(i.e. {nan} or missing values)',
'in the `z` data are filled in.'
].join(' ')
},

surfacecolor: {
valType: 'data_array',
description: [
Expand Down
25 changes: 22 additions & 3 deletions src/traces/surface/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var isArrayOrTypedArray = require('../../lib').isArrayOrTypedArray;
var parseColorScale = require('../../lib/gl_format_color').parseColorScale;
var str2RgbaArray = require('../../lib/str2rgbarray');

var interp2d = require('../heatmap/interp2d');
var findEmpties = require('../heatmap/find_empties');

function SurfaceTrace(scene, surface, uid) {
this.scene = scene;
this.uid = uid;
Expand All @@ -30,6 +33,7 @@ function SurfaceTrace(scene, surface, uid) {
this.dataScaleX = 1.0;
this.dataScaleY = 1.0;
this.refineData = true;
this._interpolatedZ = false;
}

var proto = SurfaceTrace.prototype;
Expand Down Expand Up @@ -59,9 +63,11 @@ proto.getYat = function(a, b, calendar, axis) {
};

proto.getZat = function(a, b, calendar, axis) {
var v = (
this.data.z[b][a]
);
var v = this.data.z[b][a];

if(v === null && this.data.connectgaps && this.data._interpolatedZ) {
v = this.data._interpolatedZ[b][a];
Copy link
Contributor

@etpinard etpinard Mar 20, 2019

Choose a reason for hiding this comment

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

Looks good. Now that gl3d jasmine tests are behaving better, let's add one 🔒 ing this down!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Done in afe36a6.

}

return (calendar === undefined) ? v : axis.d2l(v, 0, calendar);
};
Expand Down Expand Up @@ -404,6 +410,19 @@ proto.update = function(data) {
}
}

if(data.connectgaps) {
data._emptypoints = findEmpties(rawCoords[2]);
interp2d(rawCoords[2], data._emptypoints);

data._interpolatedZ = [];
for(j = 0; j < xlen; j++) {
data._interpolatedZ[j] = [];
for(k = 0; k < ylen; k++) {
data._interpolatedZ[j][k] = rawCoords[2][j][k];
}
}
}

// Note: log axes are not defined in surfaces yet.
// but they could be defined here...

Expand Down
1 change: 1 addition & 0 deletions src/traces/surface/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
'lightposition.y',
'lightposition.z',
'hidesurface',
'connectgaps',
'opacity'
].forEach(function(x) { coerce(x); });

Expand Down
Binary file added test/image/baselines/gl3d_surface_connectgaps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions test/image/mocks/gl3d_surface_connectgaps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"data": [
{
"type": "surface",
"connectgaps": true,
"x": [0, 1, 2, 3, 4],
"y": [0, 1, 2, 3],
"z": [
[null, 2, 1, 1, 1],
[2, 1, null, 2, null],
[2, 1, 1, 1],
[1, null, 0, null]
]
}
],
"layout": {
"title": "Surface plot with interpolated gaps<br>(connectgaps: true)",
"width": 600,
"height": 400
}
}