Skip to content

Commit 078c086

Browse files
committed
clear axis types when restyling splom show(upper|lower)half
.... and diagonal.visible
1 parent 0aad7ea commit 078c086

File tree

3 files changed

+69
-19
lines changed

3 files changed

+69
-19
lines changed

Diff for: src/plot_api/helpers.js

+27-16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var Plots = require('../plots/plots');
1818
var AxisIds = require('../plots/cartesian/axis_ids');
1919
var cleanId = AxisIds.cleanId;
2020
var getFromTrace = AxisIds.getFromTrace;
21+
var id2name = AxisIds.id2name;
2122
var Color = require('../components/color');
2223

2324

@@ -570,25 +571,35 @@ exports.hasParent = function(aobj, attr) {
570571
* @param {object} layoutUpdate: any update being done concurrently to the layout,
571572
* which may supercede clearing the axis types
572573
*/
573-
var axLetters = ['x', 'y', 'z'];
574+
var xy = ['x', 'y'];
575+
var xyz = ['x', 'y', 'z'];
574576
exports.clearAxisTypes = function(gd, traces, layoutUpdate) {
575577
for(var i = 0; i < traces.length; i++) {
576578
var trace = gd._fullData[i];
577-
for(var j = 0; j < 3; j++) {
578-
var ax = getFromTrace(gd, trace, axLetters[j]);
579-
580-
// do not clear log type - that's never an auto result so must have been intentional
581-
if(ax && ax.type !== 'log') {
582-
var axAttr = ax._name;
583-
var sceneName = ax._id.substr(1);
584-
if(sceneName.substr(0, 5) === 'scene') {
585-
if(layoutUpdate[sceneName] !== undefined) continue;
586-
axAttr = sceneName + '.' + axAttr;
587-
}
588-
var typeAttr = axAttr + '.type';
589-
590-
if(layoutUpdate[axAttr] === undefined && layoutUpdate[typeAttr] === undefined) {
591-
Lib.nestedProperty(gd.layout, typeAttr).set(null);
579+
var letters = Registry.traceIs(trace, 'gl3d') ? xyz : xy;
580+
581+
for(var j = 0; j < letters.length; j++) {
582+
var l = letters[j];
583+
var axes = trace.type === 'splom' ?
584+
trace[l + 'axes'].map(function(id) { return gd._fullLayout[id2name(id)]; }) :
585+
[getFromTrace(gd, trace, l)];
586+
587+
for(var k = 0; k < axes.length; k++) {
588+
var ax = axes[k];
589+
590+
// do not clear log type - that's never an auto result so must have been intentional
591+
if(ax && ax.type !== 'log') {
592+
var axAttr = ax._name;
593+
var sceneName = ax._id.substr(1);
594+
if(sceneName.substr(0, 5) === 'scene') {
595+
if(layoutUpdate[sceneName] !== undefined) continue;
596+
axAttr = sceneName + '.' + axAttr;
597+
}
598+
var typeAttr = axAttr + '.type';
599+
600+
if(layoutUpdate[axAttr] === undefined && layoutUpdate[typeAttr] === undefined) {
601+
Lib.nestedProperty(gd.layout, typeAttr).set(null);
602+
}
592603
}
593604
}
594605
}

Diff for: src/traces/splom/attributes.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ module.exports = {
125125
valType: 'boolean',
126126
role: 'info',
127127
dflt: true,
128-
editType: 'calc',
128+
editType: 'calc+clearAxisTypes',
129129
description: [
130130
'Determines whether or not subplots on the diagonal are displayed.'
131131
].join(' ')
@@ -142,7 +142,7 @@ module.exports = {
142142
valType: 'boolean',
143143
role: 'info',
144144
dflt: true,
145-
editType: 'calc',
145+
editType: 'calc+clearAxisTypes',
146146
description: [
147147
'Determines whether or not subplots on the upper half',
148148
'from the diagonal are displayed.'
@@ -152,7 +152,7 @@ module.exports = {
152152
valType: 'boolean',
153153
role: 'info',
154154
dflt: true,
155-
editType: 'calc',
155+
editType: 'calc+clearAxisTypes',
156156
description: [
157157
'Determines whether or not subplots on the lower half',
158158
'from the diagonal are displayed.'

Diff for: test/jasmine/tests/splom_test.js

+39
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,45 @@ describe('Test splom interactions:', function() {
774774
.catch(failTest)
775775
.then(done);
776776
});
777+
778+
it('@gl should clear axis auto-types when changing subplot arrangement', function(done) {
779+
var data = [{
780+
type: 'splom',
781+
showupperhalf: false,
782+
diagonal: {visible: false},
783+
dimensions: [{
784+
values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
785+
}, {
786+
values: ['lyndon', 'richard', 'gerald', 'jimmy', 'ronald', 'george', 'bill', 'georgeW', 'barack', 'donald']
787+
}, {
788+
values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
789+
}]
790+
}];
791+
792+
Plotly.plot(gd, data).then(function() {
793+
expect(gd.layout.xaxis.type).toBe('linear');
794+
expect(gd.layout.xaxis2.type).toBe('category');
795+
expect(gd.layout.xaxis3).toBeUndefined();
796+
expect(gd.layout.yaxis.type).toBe('category');
797+
expect(gd.layout.yaxis2.type).toBe('linear');
798+
expect(gd.layout.yaxis3).toBeUndefined();
799+
800+
return Plotly.restyle(gd, {
801+
'showupperhalf': true,
802+
'diagonal.visible': true
803+
});
804+
})
805+
.then(function() {
806+
expect(gd.layout.xaxis.type).toBe('linear');
807+
expect(gd.layout.xaxis2.type).toBe('category');
808+
expect(gd.layout.xaxis3.type).toBe('linear');
809+
expect(gd.layout.yaxis.type).toBe('linear');
810+
expect(gd.layout.yaxis2.type).toBe('category');
811+
expect(gd.layout.yaxis3.type).toBe('linear');
812+
})
813+
.catch(failTest)
814+
.then(done);
815+
});
777816
});
778817

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

0 commit comments

Comments
 (0)