Skip to content

Regression bug fix to draw 3d traces after heatmap #3360

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 7 commits into from
Dec 21, 2018
Merged
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
8 changes: 6 additions & 2 deletions src/plots/gl3d/layout/defaults.js
Original file line number Diff line number Diff line change
@@ -16,7 +16,9 @@ var Registry = require('../../../registry');
var handleSubplotDefaults = require('../../subplot_defaults');
var supplyGl3dAxisLayoutDefaults = require('./axis_defaults');
var layoutAttributes = require('./layout_attributes');
var getSubplotData = require('../../get_data').getSubplotData;

var GL3D = 'gl3d';

module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
var hasNon3D = layoutOut._basePlotModules.length > 1;
@@ -31,7 +33,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
}

handleSubplotDefaults(layoutIn, layoutOut, fullData, {
type: 'gl3d',
type: GL3D,
attributes: layoutAttributes,
handleDefaults: handleGl3dDefaults,
fullLayout: layoutOut,
@@ -97,10 +99,12 @@ function handleGl3dDefaults(sceneLayoutIn, sceneLayoutOut, coerce, opts) {
sceneLayoutIn.aspectmode = sceneLayoutOut.aspectmode;
}

var fullGl3dData = getSubplotData(opts.fullData, GL3D, opts.id);

supplyGl3dAxisLayoutDefaults(sceneLayoutIn, sceneLayoutOut, {
font: opts.font,
scene: opts.id,
data: opts.fullData,
data: fullGl3dData,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nicely done, but let's ♻️

/**
* Get the data trace(s) associated with a given subplot.
*
* @param {array} data plotly full data array.
* @param {string} type subplot type to look for.
* @param {string} subplotId subplot id to look for.
*
* @return {array} list of trace objects.
*
*/
exports.getSubplotData = function getSubplotData(data, type, subplotId) {
if(!Registry.subplotsRegistry[type]) return [];
var attr = Registry.subplotsRegistry[type].attr;
var subplotData = [];
var trace, subplotX, subplotY;
if(type === 'gl2d') {
var spmatch = subplotId.match(SUBPLOT_PATTERN);
subplotX = 'x' + spmatch[1];
subplotY = 'y' + spmatch[2];
}
for(var i = 0; i < data.length; i++) {
trace = data[i];
if(type === 'gl2d' && Registry.traceIs(trace, 'gl2d')) {
if(trace[attr[0]] === subplotX && trace[attr[1]] === subplotY) {
subplotData.push(trace);
}
}
else {
if(trace[attr] === subplotId) subplotData.push(trace);
}
}
return subplotData;
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etpinard The try to reuse the getSubPlotData function was not successful.
Could I revert this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Many thanks @etpinard for the help figuring this out!
Now the tests are all passed.

bgColor: bgColorCombined,
calendar: opts.calendar,
fullLayout: opts.fullLayout
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions test/image/mocks/gl3d_surface_after_heatmap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"data": [
{
"type": "heatmap",
"x": [0, 1, 2],
"y": [0, 1, 2],
"z": [
[0, 1, 0],
[1, 0, 1],
[0, 1, 0]
]
},
{
"type": "surface",
"x": [0, 1, 2],
"y": [0, 1, 2],
"z": [
[0, 1, 0],
[1, 0, 1],
[0, 1, 0]
]
}
],
"layout": {
"title": "Surface 3d plot on top of 2d heatmap!",
"width": 600,
"height": 400
}
}