Skip to content

Multi-axis-type sploms #2899

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 13 commits into from
Aug 15, 2018
Merged
2 changes: 1 addition & 1 deletion src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ exports.doModeBar = function(gd) {

for(var i = 0; i < fullLayout._basePlotModules.length; i++) {
var updateFx = fullLayout._basePlotModules[i].updateFx;
if(updateFx) updateFx(fullLayout);
if(updateFx) updateFx(gd);
}

return Plots.previousPromises(gd);
Expand Down
4 changes: 2 additions & 2 deletions src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var setConvert = require('./set_convert');
*/
module.exports = function handleAxisDefaults(containerIn, containerOut, coerce, options, layoutOut) {
var letter = options.letter;
var id = containerOut._id;
var font = options.font || {};
var splomStash = options.splomStash || {};

var visible = coerce('visible', !options.cheateronly);

Expand Down Expand Up @@ -66,7 +66,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
// template too.
var dfltFontColor = (dfltColor !== layoutAttributes.color.dflt) ? dfltColor : font.color;
// try to get default title from splom trace, fallback to graph-wide value
var dfltTitle = ((layoutOut._splomAxes || {})[letter] || {})[id] || layoutOut._dfltTitle[letter];
var dfltTitle = splomStash.label || layoutOut._dfltTitle[letter];

coerce('title', dfltTitle);
Lib.coerceFont(coerce, 'titlefont', {
Expand Down
5 changes: 3 additions & 2 deletions src/plots/cartesian/graph_interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,16 @@ exports.initInteractions = function initInteractions(gd) {
gd._fullLayout._lasthover.onmousedown(evt);
};

exports.updateFx(fullLayout);
exports.updateFx(gd);
};

// Minimal set of update needed on 'modebar' edits.
// We only need to update the <g .draglayer> cursor style.
//
// Note that changing the axis configuration and/or the fixedrange attribute
// should trigger a full initInteractions.
exports.updateFx = function(fullLayout) {
exports.updateFx = function(gd) {
var fullLayout = gd._fullLayout;
var cursor = fullLayout.dragmode === 'pan' ? 'move' : 'crosshair';
setCursor(fullLayout._draggers, cursor);
};
8 changes: 6 additions & 2 deletions src/plots/cartesian/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
axLayoutOut._annIndices = [];
axLayoutOut._shapeIndices = [];

handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, traces, axName);
// set up some private properties
axLayoutOut._name = axName;
var id = axLayoutOut._id = name2id(axName);

var overlayableAxes = getOverlayableAxes(axLetter, axName);

Expand All @@ -170,9 +172,11 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
bgColor: bgColor,
calendar: layoutOut.calendar,
automargin: true,
cheateronly: axLetter === 'x' && xaCheater[axName] && !xaNonCheater[axName]
cheateronly: axLetter === 'x' && xaCheater[axName] && !xaNonCheater[axName],
splomStash: ((layoutOut._splomAxes || {})[axLetter] || {})[id]
};

handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions);
handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut);

var spikecolor = coerce2('spikecolor'),
Expand Down
19 changes: 6 additions & 13 deletions src/plots/cartesian/type_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,24 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var Registry = require('../../registry');
var autoType = require('./axis_autotype');
var name2id = require('./axis_ids').name2id;

/*
* data: the plot data to use in choosing auto type
* name: axis object name (ie 'xaxis') if one should be stored
*/
module.exports = function handleTypeDefaults(containerIn, containerOut, coerce, data, name) {
// set up some private properties
if(name) {
containerOut._name = name;
containerOut._id = name2id(name);
}
module.exports = function handleTypeDefaults(containerIn, containerOut, coerce, options) {
var axType = coerce('type', (options.splomStash || {}).type);

var axType = coerce('type');
if(axType === '-') {
setAutoType(containerOut, data);
setAutoType(containerOut, options.data);

if(containerOut.type === '-') {
containerOut.type = 'linear';
}
else {
} else {
// copy autoType back to input axis
// note that if this object didn't exist
// in the input layout, we have to put it in
Expand Down Expand Up @@ -89,9 +81,10 @@ function setAutoType(ax, data) {
}
else if(d0.type === 'splom') {
var dimensions = d0.dimensions;
var diag = d0._diag;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Recall that _diag is:

// build list of [x,y] axis corresponding to each dimensions[i],
// very useful for passing options to regl-splom
var diag = traceOut._diag = new Array(dimLength);
// cases where showDiag and showLower or showUpper are false
// no special treatment as the xaxes and yaxes items no longer match
// the dimensions items 1-to-1
var xShift = !showDiag && !showLower ? -1 : 0;
var yShift = !showDiag && !showUpper ? -1 : 0;
for(i = 0; i < dimLength; i++) {
var dim = dimensions[i];
var xa = xaxes[i + xShift];
var ya = yaxes[i + yShift];
fillAxisStash(layout, xa, dim);
fillAxisStash(layout, ya, dim);
// note that some the entries here may be undefined
diag[i] = [xa, ya];
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah ok - a little confusing as usually xa is a full axis object, an id would be xId or something... but anyway nice fix!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cleaned up in -> f3c73db

for(i = 0; i < dimensions.length; i++) {
var dim = dimensions[i];
if(dim.visible) {
if(dim.visible && (diag[i][0] === id || diag[i][1] === id)) {
ax.type = autoType(dim.values, calendar);
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/plots/geo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
}
};

exports.updateFx = function(fullLayout) {
exports.updateFx = function(gd) {
var fullLayout = gd._fullLayout;
var subplotIds = fullLayout._subplots[GEO];

for(var i = 0; i < subplotIds.length; i++) {
Expand Down
3 changes: 2 additions & 1 deletion src/plots/gl2d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ exports.toSVG = function(gd) {
}
};

exports.updateFx = function(fullLayout) {
exports.updateFx = function(gd) {
var fullLayout = gd._fullLayout;
var subplotIds = fullLayout._subplots.gl2d;

for(var i = 0; i < subplotIds.length; i++) {
Expand Down
3 changes: 2 additions & 1 deletion src/plots/gl3d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ exports.cleanId = function cleanId(id) {
return SCENE + sceneNum;
};

exports.updateFx = function(fullLayout) {
exports.updateFx = function(gd) {
var fullLayout = gd._fullLayout;
var subplotIds = fullLayout._subplots[GL3D];

for(var i = 0; i < subplotIds.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/plots/gl3d/layout/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, options) {
containerOut._id = axName[0] + options.scene;
containerOut._name = axName;

handleTypeDefaults(containerIn, containerOut, coerce, options.data);
handleTypeDefaults(containerIn, containerOut, coerce, options);

handleAxisDefaults(
containerIn,
Expand Down
3 changes: 2 additions & 1 deletion src/plots/mapbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ function findAccessToken(gd, mapboxIds) {
throw new Error(constants.noAccessTokenErrorMsg);
}

exports.updateFx = function(fullLayout) {
exports.updateFx = function(gd) {
var fullLayout = gd._fullLayout;
var subplotIds = fullLayout._subplots[MAPBOX];

for(var i = 0; i < subplotIds.length; i++) {
Expand Down
17 changes: 17 additions & 0 deletions src/traces/splom/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ module.exports = {
description: 'Sets the dimension values to be plotted.'
},

axis: {
type: {
valType: 'enumerated',
values: ['linear', 'log', 'date', 'category'],
role: 'info',
editType: 'calc+clearAxisTypes',
description: [
'Sets the axis type for this dimension\'s generated',
'x and y axes.',
'Note that the axis `type` values set in layout take',
'precedence over this attribute.'
].join(' ')
},

editType: 'calc+clearAxisTypes'
},

// TODO should add an attribute to pin down x only vars and y only vars
// like https://seaborn.pydata.org/generated/seaborn.pairplot.html
// x_vars and y_vars
Expand Down
62 changes: 42 additions & 20 deletions src/traces/splom/base_plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,34 @@ function drag(gd) {
for(var i = 0; i < cd.length; i++) {
var cd0 = cd[i][0];
var trace = cd0.trace;
var scene = cd0.t._scene;
var stash = cd0.t;
var scene = stash._scene;

if(trace.type === 'splom' && scene && scene.matrix) {
dragOne(gd, trace, scene);
dragOne(gd, trace, stash, scene);
}
}
}

function dragOne(gd, trace, scene) {
var dimensions = trace.dimensions;
function dragOne(gd, trace, stash, scene) {
var visibleLength = scene.matrixOptions.data.length;
var visibleDims = stash.visibleDims;
var ranges = new Array(visibleLength);

for(var i = 0, k = 0; i < dimensions.length; i++) {
if(dimensions[i].visible) {
var rng = ranges[k] = new Array(4);
for(var k = 0; k < visibleDims.length; k++) {
var i = visibleDims[k];
var rng = ranges[k] = new Array(4);

var xa = AxisIDs.getFromId(gd, trace._diag[i][0]);
if(xa) {
rng[0] = xa.r2l(xa.range[0]);
rng[2] = xa.r2l(xa.range[1]);
}

var ya = AxisIDs.getFromId(gd, trace._diag[i][1]);
if(ya) {
rng[1] = ya.r2l(ya.range[0]);
rng[3] = ya.r2l(ya.range[1]);
}
var xa = AxisIDs.getFromId(gd, trace._diag[i][0]);
if(xa) {
rng[0] = xa.r2l(xa.range[0]);
rng[2] = xa.r2l(xa.range[1]);
}

k++;
var ya = AxisIDs.getFromId(gd, trace._diag[i][1]);
if(ya) {
rng[1] = ya.r2l(ya.range[0]);
rng[3] = ya.r2l(ya.range[1]);
}
}

Expand Down Expand Up @@ -229,6 +227,30 @@ function clean(newFullData, newFullLayout, oldFullData, oldFullLayout, oldCalcda
Cartesian.clean(newFullData, newFullLayout, oldFullData, oldFullLayout);
}

function updateFx(gd) {
Cartesian.updateFx(gd);

var fullLayout = gd._fullLayout;
var dragmode = fullLayout.dragmode;

// unset selection styles when coming out of a selection mode
if(dragmode === 'zoom' || dragmode === 'pan') {
var cd = gd.calcdata;

for(var i = 0; i < cd.length; i++) {
var cd0 = cd[i][0];
var trace = cd0.trace;

if(trace.type === 'splom') {
var scene = cd0.t._scene;
if(scene.selectBatch === null) {
scene.matrix.update(scene.matrixOptions, null);
}
}
}
}
}

module.exports = {
name: SPLOM,
attr: Cartesian.attr,
Expand All @@ -239,6 +261,6 @@ module.exports = {
plot: plot,
drag: drag,
clean: clean,
updateFx: Cartesian.updateFx,
updateFx: updateFx,
toSVG: Cartesian.toSVG
};
20 changes: 14 additions & 6 deletions src/traces/splom/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function dimensionDefaults(dimIn, dimOut) {

if(!(values && values.length)) dimOut.visible = false;
else coerce('visible');

coerce('axis.type');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. I committed the new lines in splom/attributes.js in 9039a8e by accident. My bad.

}

function handleAxisDefaults(traceIn, traceOut, layout, coerce) {
Expand Down Expand Up @@ -113,14 +115,14 @@ function handleAxisDefaults(traceIn, traceOut, layout, coerce) {

for(i = 0; i < dimLength; i++) {
var dim = dimensions[i];
var xa = xaxes[i + xShift];
var ya = yaxes[i + yShift];
var xaId = xaxes[i + xShift];
var yaId = yaxes[i + yShift];

fillAxisStash(layout, xa, dim);
fillAxisStash(layout, ya, dim);
fillAxisStash(layout, xaId, dim);
fillAxisStash(layout, yaId, dim);

// note that some the entries here may be undefined
diag[i] = [xa, ya];
diag[i] = [xaId, yaId];
}

// when lower half is omitted, override grid default
Expand Down Expand Up @@ -148,7 +150,13 @@ function fillAxisStash(layout, axId, dim) {
var stash = layout._splomAxes[axLetter];

if(!(axId in stash)) {
stash[axId] = (dim || {}).label || '';
var s = stash[axId] = {};
if(dim) {
s.label = dim.label || '';
if(dim.visible && dim.axis) {
s.type = dim.axis.type;
}
}
}
}

Expand Down
Loading