Skip to content

Commit

Permalink
clear axis types when restyling splom show(upper|lower)half
Browse files Browse the repository at this point in the history
.... and diagonal.visible
  • Loading branch information
etpinard committed Oct 2, 2018
1 parent 0aad7ea commit 078c086
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
43 changes: 27 additions & 16 deletions src/plot_api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var Plots = require('../plots/plots');
var AxisIds = require('../plots/cartesian/axis_ids');
var cleanId = AxisIds.cleanId;
var getFromTrace = AxisIds.getFromTrace;
var id2name = AxisIds.id2name;
var Color = require('../components/color');


Expand Down Expand Up @@ -570,25 +571,35 @@ exports.hasParent = function(aobj, attr) {
* @param {object} layoutUpdate: any update being done concurrently to the layout,
* which may supercede clearing the axis types
*/
var axLetters = ['x', 'y', 'z'];
var xy = ['x', 'y'];
var xyz = ['x', 'y', 'z'];
exports.clearAxisTypes = function(gd, traces, layoutUpdate) {
for(var i = 0; i < traces.length; i++) {
var trace = gd._fullData[i];
for(var j = 0; j < 3; j++) {
var ax = getFromTrace(gd, trace, axLetters[j]);

// do not clear log type - that's never an auto result so must have been intentional
if(ax && ax.type !== 'log') {
var axAttr = ax._name;
var sceneName = ax._id.substr(1);
if(sceneName.substr(0, 5) === 'scene') {
if(layoutUpdate[sceneName] !== undefined) continue;
axAttr = sceneName + '.' + axAttr;
}
var typeAttr = axAttr + '.type';

if(layoutUpdate[axAttr] === undefined && layoutUpdate[typeAttr] === undefined) {
Lib.nestedProperty(gd.layout, typeAttr).set(null);
var letters = Registry.traceIs(trace, 'gl3d') ? xyz : xy;

for(var j = 0; j < letters.length; j++) {
var l = letters[j];
var axes = trace.type === 'splom' ?
trace[l + 'axes'].map(function(id) { return gd._fullLayout[id2name(id)]; }) :
[getFromTrace(gd, trace, l)];

for(var k = 0; k < axes.length; k++) {
var ax = axes[k];

// do not clear log type - that's never an auto result so must have been intentional
if(ax && ax.type !== 'log') {
var axAttr = ax._name;
var sceneName = ax._id.substr(1);
if(sceneName.substr(0, 5) === 'scene') {
if(layoutUpdate[sceneName] !== undefined) continue;
axAttr = sceneName + '.' + axAttr;
}
var typeAttr = axAttr + '.type';

if(layoutUpdate[axAttr] === undefined && layoutUpdate[typeAttr] === undefined) {
Lib.nestedProperty(gd.layout, typeAttr).set(null);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/traces/splom/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module.exports = {
valType: 'boolean',
role: 'info',
dflt: true,
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Determines whether or not subplots on the diagonal are displayed.'
].join(' ')
Expand All @@ -142,7 +142,7 @@ module.exports = {
valType: 'boolean',
role: 'info',
dflt: true,
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Determines whether or not subplots on the upper half',
'from the diagonal are displayed.'
Expand All @@ -152,7 +152,7 @@ module.exports = {
valType: 'boolean',
role: 'info',
dflt: true,
editType: 'calc',
editType: 'calc+clearAxisTypes',
description: [
'Determines whether or not subplots on the lower half',
'from the diagonal are displayed.'
Expand Down
39 changes: 39 additions & 0 deletions test/jasmine/tests/splom_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,45 @@ describe('Test splom interactions:', function() {
.catch(failTest)
.then(done);
});

it('@gl should clear axis auto-types when changing subplot arrangement', function(done) {
var data = [{
type: 'splom',
showupperhalf: false,
diagonal: {visible: false},
dimensions: [{
values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}, {
values: ['lyndon', 'richard', 'gerald', 'jimmy', 'ronald', 'george', 'bill', 'georgeW', 'barack', 'donald']
}, {
values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}]
}];

Plotly.plot(gd, data).then(function() {
expect(gd.layout.xaxis.type).toBe('linear');
expect(gd.layout.xaxis2.type).toBe('category');
expect(gd.layout.xaxis3).toBeUndefined();
expect(gd.layout.yaxis.type).toBe('category');
expect(gd.layout.yaxis2.type).toBe('linear');
expect(gd.layout.yaxis3).toBeUndefined();

return Plotly.restyle(gd, {
'showupperhalf': true,
'diagonal.visible': true
});
})
.then(function() {
expect(gd.layout.xaxis.type).toBe('linear');
expect(gd.layout.xaxis2.type).toBe('category');
expect(gd.layout.xaxis3.type).toBe('linear');
expect(gd.layout.yaxis.type).toBe('linear');
expect(gd.layout.yaxis2.type).toBe('category');
expect(gd.layout.yaxis3.type).toBe('linear');
})
.catch(failTest)
.then(done);
});
});

describe('Test splom update switchboard:', function() {
Expand Down

0 comments on commit 078c086

Please sign in to comment.