Skip to content

Commit a33be40

Browse files
committed
use splom label to default splom ax titles
++ fix and lock 1-dimension splom bug
1 parent bdf4094 commit a33be40

File tree

5 files changed

+51
-18
lines changed

5 files changed

+51
-18
lines changed

src/components/grid/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ var gridAttrs = {
167167

168168
function getAxes(layout, grid, axLetter) {
169169
var gridVal = grid[axLetter + 'axes'];
170-
var splomVal = layout[{x: '_splomXaxes', y: '_splomYaxes'}[axLetter]] || [];
170+
var splomVal = Object.keys((layout._splomAxes || {})[axLetter] || {});
171171

172172
if(Array.isArray(gridVal)) return gridVal;
173173
if(splomVal.length) return splomVal;

src/plots/cartesian/axis_defaults.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var orderedCategories = require('./ordered_categories');
3434
*/
3535
module.exports = function handleAxisDefaults(containerIn, containerOut, coerce, options, layoutOut) {
3636
var letter = options.letter;
37+
var id = containerOut._id;
3738
var font = options.font || {};
3839

3940
var visible = coerce('visible', !options.cheateronly);
@@ -74,8 +75,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
7475
// if axis.color was provided, use it for fonts too; otherwise,
7576
// inherit from global font color in case that was provided.
7677
var dfltFontColor = (dfltColor === containerIn.color) ? dfltColor : font.color;
78+
// try to get default title from splom trace, fallback to graph-wide value
79+
var dfltTitle = ((layoutOut._splomAxes || {})[letter] || {})[id] || layoutOut._dfltTitle[letter];
7780

78-
coerce('title', layoutOut._dfltTitle[letter]);
81+
coerce('title', dfltTitle);
7982
Lib.coerceFont(coerce, 'titlefont', {
8083
family: font.family,
8184
size: Math.round(font.size * 1.2),

src/plots/plots.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,23 +364,24 @@ plots.supplyDefaults = function(gd) {
364364
newFullLayout._modules = [];
365365
newFullLayout._basePlotModules = [];
366366
var subplots = newFullLayout._subplots = emptySubplotLists();
367-
var splomXaxes = newFullLayout._splomXaxes = [];
368-
var splomYaxes = newFullLayout._splomYaxes = [];
367+
var splomAxes = newFullLayout._splomAxes = {x: {}, y: {}};
369368

370369
// then do the data
371370
newFullLayout._globalTransforms = (gd._context || {}).globalTransforms;
372371
plots.supplyDataDefaults(newData, newFullData, newLayout, newFullLayout);
373372

374373
// redo grid size defaults with info about splom x/y axes,
375374
// and fill in generated cartesian axes and subplots
376-
if(splomXaxes.length && splomYaxes.length) {
375+
var splomXa = Object.keys(splomAxes.x);
376+
var splomYa = Object.keys(splomAxes.y);
377+
if(splomXa.length > 1 && splomYa.length > 1) {
377378
Registry.getComponentMethod('grid', 'sizeDefaults')(newLayout, newFullLayout);
378379

379-
for(i = 0; i < splomXaxes.length; i++) {
380-
Lib.pushUnique(subplots.xaxis, splomXaxes[i]);
381-
for(j = 0; j < splomYaxes.length; j++) {
382-
if(i === 0) Lib.pushUnique(subplots.yaxis, splomYaxes[j]);
383-
Lib.pushUnique(subplots.cartesian, splomXaxes[i] + splomYaxes[j]);
380+
for(i = 0; i < splomXa.length; i++) {
381+
Lib.pushUnique(subplots.xaxis, splomXa[i]);
382+
for(j = 0; j < splomYa.length; j++) {
383+
if(i === 0) Lib.pushUnique(subplots.yaxis, splomYa[j]);
384+
Lib.pushUnique(subplots.cartesian, splomXa[i] + splomYa[j]);
384385
}
385386
}
386387
}

src/traces/splom/defaults.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ function handleDimensionsDefaults(traceIn, traceOut) {
101101
}
102102

103103
function handleAxisDefaults(traceIn, traceOut, layout, coerce) {
104-
var dimLength = traceOut.dimensions.length;
104+
var dimensions = traceOut.dimensions;
105+
var dimLength = dimensions.length;
105106
var xaxesDflt = new Array(dimLength);
106107
var yaxesDflt = new Array(dimLength);
107108
var i;
@@ -116,10 +117,16 @@ function handleAxisDefaults(traceIn, traceOut, layout, coerce) {
116117

117118
// TODO what to do when xaxes.length or yaxes.length !== dimLength ???
118119

119-
for(i = 0; i < xaxes.length; i++) {
120-
Lib.pushUnique(layout._splomXaxes, xaxes[i]);
121-
}
122-
for(i = 0; i < yaxes.length; i++) {
123-
Lib.pushUnique(layout._splomYaxes, yaxes[i]);
120+
for(i = 0; i < dimLength; i++) {
121+
var dim = dimensions[i];
122+
var xa = xaxes[i];
123+
var ya = yaxes[i];
124+
125+
if(!(xa in layout._splomAxes.x)) {
126+
layout._splomAxes.x[xa] = dim.label || '';
127+
}
128+
if(!(ya in layout._splomAxes.y)) {
129+
layout._splomAxes.y[ya] = dim.label || '';
130+
}
124131
}
125132
}

test/jasmine/tests/splom_test.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ describe('Test splom trace defaults:', function() {
3636
});
3737

3838
it('should work with only one dimensions', function() {
39-
// TODO this breaks at the moment
39+
_supply({
40+
dimensions: [
41+
{values: [2, 1, 2]}
42+
]
43+
});
44+
45+
var fullLayout = gd._fullLayout;
46+
expect(fullLayout.xaxis.domain).toBeCloseToArray([0, 1]);
47+
expect(fullLayout.yaxis.domain).toBeCloseToArray([0, 1]);
4048
});
4149

4250
it('should set `grid.xaxes` and `grid.yaxes` default using the new of dimensions', function() {
@@ -102,7 +110,21 @@ describe('Test splom trace defaults:', function() {
102110
});
103111

104112
it('should set axis title default using dimensions *label*', function() {
105-
// TODO
113+
_supply({
114+
dimensions: [{
115+
label: 'A',
116+
values: [2, 3, 1]
117+
}, {
118+
label: 'B',
119+
values: [1, 2, 1]
120+
}]
121+
});
122+
123+
var fullLayout = gd._fullLayout;
124+
expect(fullLayout.xaxis.title).toBe('A');
125+
expect(fullLayout.yaxis.title).toBe('A');
126+
expect(fullLayout.xaxis2.title).toBe('B');
127+
expect(fullLayout.yaxis2.title).toBe('B');
106128
});
107129

108130
it('should lead to correct axis auto type value', function() {

0 commit comments

Comments
 (0)