Skip to content

Commit

Permalink
keep track of visible dimensions using visibleDims list
Browse files Browse the repository at this point in the history
... which simplifies logic downstream
  • Loading branch information
etpinard committed Aug 14, 2018
1 parent b3d27bd commit 9039a8e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 88 deletions.
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
36 changes: 17 additions & 19 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
132 changes: 63 additions & 69 deletions src/traces/splom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function calc(gd, trace) {
// only differ here for log axes, pass ldata to createMatrix as 'data'
var cdata = opts.cdata = [];
var ldata = opts.data = [];
// keep track of visible dimensions
var visibleDims = stash.visibleDims = [];
var i, k, dim, xa, ya;

function makeCalcdata(ax, dim) {
Expand Down Expand Up @@ -71,6 +73,8 @@ function calc(gd, trace) {
// should not make it here, if both xa and ya undefined
makeCalcdata(ya, dim);
}

visibleDims.push(i);
}
}

Expand All @@ -80,26 +84,24 @@ function calc(gd, trace) {
var visibleLength = cdata.length;
var hasTooManyPoints = (visibleLength * commonLength) > TOO_MANY_POINTS;

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

if(dim.visible) {
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,
// use average marker size instead to speed things up.
var ppad;
if(hasTooManyPoints) {
ppad = 2 * (opts.sizeAvg || Math.max(opts.size, 3));
} else {
ppad = calcMarkerSize(trace, commonLength);
}

calcAxisExpansion(gd, trace, xa, ya, cdata[k], cdata[k], ppad);
k++;
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,
// use average marker size instead to speed things up.
var ppad;
if(hasTooManyPoints) {
ppad = 2 * (opts.sizeAvg || Math.max(opts.size, 3));
} else {
ppad = calcMarkerSize(trace, commonLength);
}

calcAxisExpansion(gd, trace, xa, ya, cdata[k], cdata[k], ppad);
}

var scene = stash._scene = sceneUpdate(gd, stash);
Expand Down Expand Up @@ -133,9 +135,7 @@ function sceneUpdate(gd, stash) {
// draw traces in selection mode
if(scene.matrix && scene.selectBatch) {
scene.matrix.draw(scene.unselectBatch, scene.selectBatch);
}

else if(scene.matrix) {
} else if(scene.matrix) {
scene.matrix.draw();
}

Expand Down Expand Up @@ -191,34 +191,32 @@ function plotOne(gd, cd0) {
matrixOpts.upper = trace.showlowerhalf;
matrixOpts.diagonal = trace.diagonal.visible;

var dimensions = trace.dimensions;
var visibleDims = stash.visibleDims;
var visibleLength = cdata.length;
var viewOpts = {};
viewOpts.ranges = new Array(visibleLength);
viewOpts.domains = new Array(visibleLength);

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

xa = AxisIDs.getFromId(gd, trace._diag[i][0]);
if(xa) {
rng[0] = xa._rl[0];
rng[2] = xa._rl[1];
dmn[0] = xa.domain[0];
dmn[2] = xa.domain[1];
}
var rng = viewOpts.ranges[k] = new Array(4);
var dmn = viewOpts.domains[k] = new Array(4);

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

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

Expand Down Expand Up @@ -260,25 +258,23 @@ function plotOne(gd, cd0) {
var xpx = stash.xpx = new Array(visibleLength);
var ypx = stash.ypx = new Array(visibleLength);

for(i = 0, k = 0; i < dimensions.length; i++) {
if(trace.dimensions[i].visible) {
xa = AxisIDs.getFromId(gd, trace._diag[i][0]);
if(xa) {
xpx[k] = new Array(commonLength);
for(j = 0; j < commonLength; j++) {
xpx[k][j] = xa.c2p(cdata[k][j]);
}
}
for(k = 0; k < visibleDims.length; k++) {
i = visibleDims[k];

ya = AxisIDs.getFromId(gd, trace._diag[i][1]);
if(ya) {
ypx[k] = new Array(commonLength);
for(j = 0; j < commonLength; j++) {
ypx[k][j] = ya.c2p(cdata[k][j]);
}
xa = AxisIDs.getFromId(gd, trace._diag[i][0]);
if(xa) {
xpx[k] = new Array(commonLength);
for(j = 0; j < commonLength; j++) {
xpx[k][j] = xa.c2p(cdata[k][j]);
}
}

k++;
ya = AxisIDs.getFromId(gd, trace._diag[i][1]);
if(ya) {
ypx[k] = new Array(commonLength);
for(j = 0; j < commonLength; j++) {
ypx[k][j] = ya.c2p(cdata[k][j]);
}
}
}

Expand All @@ -293,8 +289,8 @@ function plotOne(gd, cd0) {
}
}
else {
scene.matrix.update(matrixOpts);
scene.matrix.update(viewOpts);
scene.matrix.update(matrixOpts, null);
scene.matrix.update(viewOpts, null);
stash.xpx = stash.ypx = null;
}

Expand All @@ -313,8 +309,8 @@ function hoverPoints(pointData, xval, yval) {
var ypx = ya.c2p(yval);
var maxDistance = pointData.distance;

var xi = getDimIndex(trace, xa);
var yi = getDimIndex(trace, ya);
var xi = getDimIndex(trace, stash, xa);
var yi = getDimIndex(trace, stash, ya);
if(xi === false || yi === false) return [pointData];

var x = cdata[xi];
Expand Down Expand Up @@ -363,8 +359,8 @@ function selectPoints(searchInfo, polygon) {
var hasOnlyLines = (!subTypes.hasMarkers(trace) && !subTypes.hasText(trace));
if(trace.visible !== true || hasOnlyLines) return selection;

var xi = getDimIndex(trace, xa);
var yi = getDimIndex(trace, ya);
var xi = getDimIndex(trace, stash, xa);
var yi = getDimIndex(trace, stash, ya);
if(xi === false || yi === false) return selection;

var xpx = stash.xpx[xi];
Expand Down Expand Up @@ -445,17 +441,15 @@ function style(gd, cds) {
}
}

function getDimIndex(trace, ax) {
function getDimIndex(trace, stash, ax) {
var axId = ax._id;
var axLetter = axId.charAt(0);
var ind = {x: 0, y: 1}[axLetter];
var dimensions = trace.dimensions;
var visibleDims = stash.visibleDims;

for(var i = 0, k = 0; i < dimensions.length; i++) {
if(dimensions[i].visible) {
if(trace._diag[i][ind] === axId) return k;
k++;
}
for(var k = 0; k < visibleDims.length; k++) {
var i = visibleDims[k];
if(trace._diag[i][ind] === axId) return k;
}
return false;
}
Expand Down
1 change: 1 addition & 0 deletions test/jasmine/tests/splom_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ describe('Test splom trace calc step:', function() {
var cd = gd.calcdata[0][0];

expect(cd.t._scene.matrixOptions.data).toBeCloseTo2DArray([[2, 1, 2]]);
expect(cd.t.visibleDims).toEqual([1]);
});
});

Expand Down

0 comments on commit 9039a8e

Please sign in to comment.