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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions src/traces/splom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,39 @@ function calc(gd, trace) {
// only differ here for log axes, pass ldata to createMatrix as 'data'
var cdata = opts.cdata = [];
var ldata = opts.data = [];
var i, k, dim;
var i, k, dim, xa, ya;

function makeCalcdata(ax, dim) {
// call makeCalcdata with fake input
var ccol = ax.makeCalcdata({
v: dim.values,
vcalendar: trace.calendar
}, 'v');

for(var i = 0; i < ccol.length; i++) {
ccol[i] = ccol[i] === BADNUM ? NaN : ccol[i];
}
cdata.push(ccol);
ldata.push(ax.type === 'log' ? Lib.simpleMap(ccol, ax.c2l) : ccol);
}

for(i = 0; i < dimensions.length; i++) {
dim = dimensions[i];

if(dim.visible) {
var axId = trace._diag[i][0] || trace._diag[i][1];
var ax = AxisIDs.getFromId(gd, axId);
if(ax) {
var ccol = makeCalcdata(ax, trace, dim);
var lcol = ax.type === 'log' ? Lib.simpleMap(ccol, ax.c2l) : ccol;
cdata.push(ccol);
ldata.push(lcol);
xa = AxisIDs.getFromId(gd, trace._diag[i][0]);
ya = AxisIDs.getFromId(gd, trace._diag[i][1]);

if(xa) {
makeCalcdata(xa, dim);
if(ya && ya.type === 'category') {
ya._categories = xa._categories.slice();
}
} else if(ya) {
makeCalcdata(ya, dim);
if(xa && xa.type === 'category') {
xa._categories = ya._categories.slice();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

How could you get here? if xa exists you'll skip the else if(ya) block entirely.

But this raises an interesting (if possibly nonsensical) point - what if xa.type !== ya.type? I guess this could happen if one is numeric or date and the other is categorical, or if one is linear and the other is log. If the answer is "all hell breaks loose", which wouldn't surprise me, it may be appropriate to just log a warning and hide that dimension entirely. That seems like an abuse of the concept of a splom.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How could you get here? if xa exists you'll skip the else if(ya) block entirely.

Good point. I wrote that up to preserve symmetry, but didn't bother checking. Thanks!

what if xa.type !== ya.type? I guess this could happen if one is numeric or date and the other is categorical, or if one is linear and the other is log.

I don't think this can happen on graphs with only 1 splom trace and no ax.type set in the layout. That's because (after this PR's 1st commit dd563bb), both x and y axes use the same data array in the axis autotype routine.

Scenarios where xa.type !== ya.type can happen if,

  • a trace before the splom trace in gd.data autotyped the axes
  • a users sets ax.type in the layout

which are things that don't happen by accident.

So, I yeah I think skipping that dimension entirely makes the most sense here. Thanks for bringing this up!

Copy link
Collaborator

Choose a reason for hiding this comment

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

a users sets ax.type in the layout
... [doesn't] happen by accident.

Hmm could happen in the editor though. @nicolaskruchten @VeraZab not sure how best to handle this. If we add dimension.type we should steer people there somehow when there's a splom on that axis. But if they still set an axis type directly would we want to find the corresponding opposite axis in the splom and set it to match, to avoid this error?

Copy link
Contributor

Choose a reason for hiding this comment

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

hoo boy. Well right now we don't support SPLOMs yet, and I'm thinking that when we do we should lock down axes/subplots quite tightly so that people can't break them too much :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Skipping dims with axes of conflicting types in b3d27bd

}
}
}
Expand All @@ -63,8 +83,8 @@ function calc(gd, trace) {
dim = dimensions[i];

if(dim.visible) {
var xa = AxisIDs.getFromId(gd, trace._diag[i][0]) || {};
var ya = AxisIDs.getFromId(gd, trace._diag[i][1]) || {};
xa = AxisIDs.getFromId(gd, trace._diag[i][0]) || {};
ya = AxisIDs.getFromId(gd, trace._diag[i][1]) || {};

// Reuse SVG scatter axis expansion routine.
// For graphs with very large number of points and array marker.size,
Expand All @@ -91,20 +111,6 @@ function calc(gd, trace) {
return [{x: false, y: false, t: stash, trace: trace}];
}

function makeCalcdata(ax, trace, dim) {
// call makeCalcdata with fake input
var ccol = ax.makeCalcdata({
v: dim.values,
vcalendar: trace.calendar
}, 'v');

for(var i = 0; i < ccol.length; i++) {
ccol[i] = ccol[i] === BADNUM ? NaN : ccol[i];
}

return ccol;
}

function sceneUpdate(gd, stash) {
var scene = stash._scene;

Expand Down