Skip to content

Commit 3be9569

Browse files
committed
adapt grid and cartesian axis logic for sploms
1 parent 8b5af93 commit 3be9569

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

src/components/grid/index.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,26 @@ var gridAttrs = {
165165
editType: 'plot'
166166
};
167167

168+
function getAxes(layout, grid, axLetter) {
169+
var gridVal = grid[axLetter + 'axes'];
170+
var splomVal = Object.keys((layout._splomAxes || {})[axLetter] || {});
171+
172+
if(Array.isArray(gridVal)) return gridVal;
173+
if(splomVal.length) return splomVal;
174+
}
175+
168176
// the shape of the grid - this needs to be done BEFORE supplyDataDefaults
169177
// so that non-subplot traces can place themselves in the grid
170178
function sizeDefaults(layoutIn, layoutOut) {
171-
var gridIn = layoutIn.grid;
172-
if(!gridIn) return;
179+
var gridIn = layoutIn.grid || {};
180+
var xAxes = getAxes(layoutOut, gridIn, 'x');
181+
var yAxes = getAxes(layoutOut, gridIn, 'y');
182+
183+
if(!layoutIn.grid && !xAxes && !yAxes) return;
173184

174185
var hasSubplotGrid = Array.isArray(gridIn.subplots) && Array.isArray(gridIn.subplots[0]);
175-
var hasXaxes = Array.isArray(gridIn.xaxes);
176-
var hasYaxes = Array.isArray(gridIn.yaxes);
186+
var hasXaxes = Array.isArray(xAxes);
187+
var hasYaxes = Array.isArray(yAxes);
177188

178189
var dfltRows, dfltColumns;
179190

@@ -182,8 +193,8 @@ function sizeDefaults(layoutIn, layoutOut) {
182193
dfltColumns = gridIn.subplots[0].length;
183194
}
184195
else {
185-
if(hasYaxes) dfltRows = gridIn.yaxes.length;
186-
if(hasXaxes) dfltColumns = gridIn.xaxes.length;
196+
if(hasYaxes) dfltRows = yAxes.length;
197+
if(hasXaxes) dfltColumns = xAxes.length;
187198
}
188199

189200
var gridOut = layoutOut.grid = {};
@@ -236,7 +247,7 @@ function contentDefaults(layoutIn, layoutOut) {
236247
// make sure we got to the end of handleGridSizing
237248
if(!gridOut || !gridOut._domains) return;
238249

239-
var gridIn = layoutIn.grid;
250+
var gridIn = layoutIn.grid || {};
240251
var subplots = layoutOut._subplots;
241252
var hasSubplotGrid = gridOut._hasSubplotGrid;
242253
var rows = gridOut.rows;
@@ -282,8 +293,10 @@ function contentDefaults(layoutIn, layoutOut) {
282293
}
283294
}
284295
else {
285-
gridOut.xaxes = fillGridAxes(gridIn.xaxes, subplots.xaxis, columns, axisMap, 'x');
286-
gridOut.yaxes = fillGridAxes(gridIn.yaxes, subplots.yaxis, rows, axisMap, 'y');
296+
var xAxes = getAxes(layoutOut, gridIn, 'x');
297+
var yAxes = getAxes(layoutOut, gridIn, 'y');
298+
gridOut.xaxes = fillGridAxes(xAxes, subplots.xaxis, columns, axisMap, 'x');
299+
gridOut.yaxes = fillGridAxes(yAxes, subplots.yaxis, rows, axisMap, 'y');
287300
}
288301

289302
var anchors = gridOut._anchors = {};

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: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ plots.supplyDefaults = function(gd) {
289289

290290
var context = gd._context || {};
291291

292-
var i;
292+
var i, j;
293293

294294
// Create all the storage space for frames, but only if doesn't already exist
295295
if(!gd._transitionData) plots.createTransitionData(gd);
@@ -321,7 +321,6 @@ plots.supplyDefaults = function(gd) {
321321

322322
// first fill in what we can of layout without looking at data
323323
// because fullData needs a few things from layout
324-
325324
if(oldFullLayout._initialAutoSizeIsDone) {
326325

327326
// coerce the updated layout while preserving width and height
@@ -371,6 +370,22 @@ plots.supplyDefaults = function(gd) {
371370
newFullLayout._globalTransforms = (gd._context || {}).globalTransforms;
372371
plots.supplyDataDefaults(newData, newFullData, newLayout, newFullLayout);
373372

373+
// redo grid size defaults with info about splom x/y axes,
374+
// and fill in generated cartesian axes and subplots
375+
var splomXa = Object.keys(splomAxes.x);
376+
var splomYa = Object.keys(splomAxes.y);
377+
if(splomXa.length > 1 && splomYa.length > 1) {
378+
Registry.getComponentMethod('grid', 'sizeDefaults')(newLayout, newFullLayout);
379+
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]);
385+
}
386+
}
387+
}
388+
374389
// attach helper method to check whether a plot type is present on graph
375390
newFullLayout._has = plots._hasPlotType.bind(newFullLayout);
376391

0 commit comments

Comments
 (0)