10000 Correct streamtube positions and colouring by archmoj · Pull Request #4271 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Correct streamtube positions and colouring #4271

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 16 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
use len instead of raw input lengths - empty distinct vals when len i…
…s zero
  • Loading branch information
archmoj committed Oct 12, 2019
commit c7bc82c4fa5222301c3b4c784d8cb4d186557552
35 changes: 22 additions & 13 deletions src/traces/streamtube/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,30 @@ module.exports = function calc(gd, trace) {
if(!filledY) gridFill += 'y';
if(!filledZ) gridFill += 'z';

var valsx = distinctVals(trace.x.slice(0, len));
var valsy = distinctVals(trace.y.slice(0, len));
var valsz = distinctVals(trace.z.slice(0, len));
var Xs = distinctVals(trace.x.slice(0, len));
var Ys = distinctVals(trace.y.slice(0, len));
var Zs = distinctVals(trace.z.slice(0, len));

var empty = function() {
len = 0;
Xs = [];
Ys = [];
Zs = [];
};

// Over-specified mesh case, this would error in tube2mesh
if(!len || len < Xs.length * Ys.length * Zs.length) empty();

var getArray = function(c) { return c === 'x' ? x : c === 'y' ? y : z; };
var getVals = function(c) { return c === 'x' ? valsx : c === 'y' ? valsy : valsz; };
var getLength = function(c) { return getVals(c).length; };
var getDir = function(c) { return (+(c[c.length - 1] - c[0])) * 2 + 1; };
var getVals = function(c) { return c === 'x' ? Xs : c === 'y' ? Ys : Zs; };
var getDir = function(c) { return (+(c[len - 1] - c[0])) * 2 + 1; };

var arrK = getArray(gridFill[0]);
var arrJ = getArray(gridFill[1]);
var arrI = getArray(gridFill[2]);
var nk = getLength(gridFill[0]);
var nj = getLength(gridFill[1]);
var ni = getLength(gridFill[2]);
var nk = getVals(gridFill[0]).length;
var nj = getVals(gridFill[1]).length;
var ni = getVals(gridFill[2]).length;

var arbitrary = false;

Expand Down Expand Up @@ -147,7 +156,7 @@ module.exports = function calc(gd, trace) {

if(arbitrary) {
Lib.warn('Encountered arbitrary coordinates! Unable to input data grid.');
len = 0;
empty();
}

for(i = 0; i < slen; i++) {
Expand All @@ -170,9 +179,9 @@ module.exports = function calc(gd, trace) {
trace._xbnds = [xMin, xMax];
trace._ybnds = [yMin, yMax];
trace._zbnds = [zMin, zMax];
trace._valsx = valsx;
trace._valsy = valsy;
trace._valsz = valsz;
trace._Xs = Xs;
trace._Ys = Ys;
trace._Zs = Zs;
trace._gridFill = gridFill;
};

Expand Down
17 changes: 8 additions & 9 deletions src/traces/streamtube/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,17 @@ function convert(scene, trace) {
len
);

var valsx = trace._valsx;
var valsy = trace._valsy;
var valsz = trace._valsz;

// Over-specified mesh case, this would error in tube2mesh
if(valsx.length * valsy.length * valsz.length > len) {
return {positions: [], cells: []};
if(!len) {
return {
positions: [],
cells: []
};
}

var meshx = toDataCoords(valsx, 'xaxis');
var meshy = toDataCoords(valsy, 'yaxis');
var meshz = toDataCoords(valsz, 'zaxis');
var meshx = toDataCoords(trace._Xs, 'xaxis');
var meshy = toDataCoords(trace._Ys, 'yaxis');
var meshz = toDataCoords(trace._Zs, 'zaxis');

tubeOpts.meshgrid = [meshx, meshy, meshz];
tubeOpts.gridFill = trace._gridFill;
Expand Down
0