Skip to content

3D streamtube traces #2658

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 41 commits into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
616d043
streamtube integration, first pass
kig May 20, 2018
2435a96
add gl-streamtube to package.json
kig May 20, 2018
355aed1
add gl-streamtube3d to package-lock
etpinard May 23, 2018
583499f
use gl-streamtube3d version that works on etpinard's laptop
etpinard May 23, 2018
39c254e
cleanup streamtube/
etpinard May 24, 2018
38a1310
add first streamtube mock
etpinard May 24, 2018
971351c
properly scaffold streamtube trace module
etpinard May 24, 2018
218dfc8
factor out zip3 into src/lib/
etpinard May 24, 2018
1367c07
Merge branch 'master' into streamtube-traces
etpinard May 24, 2018
8ea0c25
add 'sizeref'
etpinard May 29, 2018
3b1f809
fixup streamtube-thin baseline
etpinard May 29, 2018
b0cd99d
fixup cmin/cmax -> vertexIntensityBounds,
etpinard Jun 1, 2018
e99ffc9
expect x/y/z and u/v/w to have matching length + add tube bounds pad
etpinard Jun 1, 2018
e0ff37f
first cut streamtube hover
etpinard Jun 1, 2018
fbd7980
fixup hoverinfo 'norm'
etpinard Jun 1, 2018
f5c1160
add support for u/v/w hoverinfo flags
etpinard Jun 4, 2018
b9a6e3f
add cone + streamtube mock
etpinard Jun 4, 2018
80bcd84
use gl-streamtube3d 'tubeScale' to fit tubes inside scene
etpinard Jun 4, 2018
273292d
make startx/starty/startz optional
etpinard Jun 4, 2018
5da1c59
fix cone <-> streamtube restyle
etpinard Jun 4, 2018
8531e23
first cut streamtube jasmine tests
etpinard Jun 4, 2018
94f6195
add 'divergence' hoverinfo flag
etpinard Jun 4, 2018
c40dd6b
add support for 'text' (scalar value only)
etpinard Jun 5, 2018
8182cab
comment out 'sizemode' (for now)
etpinard Jun 5, 2018
62b90b5
hook in 'maxLength' as 'maxdisplayed'
etpinard Jun 5, 2018
dc0c5d7
improve streamtube attr descriptions
etpinard Jun 5, 2018
bf12d10
add streamtube to Plotly.react-noop suite
etpinard Jun 5, 2018
df7ccaa
emit custom event data for streamtube
etpinard Jun 5, 2018
ca7c022
typos in streamtube meta
alexcjohnson Jun 5, 2018
9a53250
fixup hoverinfo: 'all' for cone traces
etpinard Jun 6, 2018
22f0c7e
sub startx/starty/startz -> starts.(x|y|z)
etpinard Jun 6, 2018
d796bda
fixup 'starts' attribute declaration
etpinard Jun 6, 2018
2d1df2b
Merge branch 'master' into streamtube-traces
etpinard Jun 12, 2018
0093ac8
fixup streamtube after merge master
etpinard Jun 12, 2018
5c2ddfc
mv lib/zip3 -> plots/gl3d/zip3
etpinard Jun 18, 2018
9fa5ece
add 'len' argument to zip3
etpinard Jun 18, 2018
d33fc45
merge all colorscale attribute generator in one function
etpinard Jun 18, 2018
9e3c533
fix #2723 - list correct 'color' attribute in cone,
etpinard Jun 18, 2018
83f3bdc
improve auto starting position algo
etpinard Jun 19, 2018
f348ac3
Merge branch 'master' into streamtube-traces
etpinard Jul 5, 2018
966bc8d
use [email protected]
etpinard Jul 5, 2018
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
3 changes: 2 additions & 1 deletion lib/index-gl3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Plotly.register([
require('./scatter3d'),
require('./surface'),
require('./mesh3d'),
require('./cone')
require('./cone'),
require('./streamtube')
]);

module.exports = Plotly;
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Plotly.register([
require('./surface'),
require('./mesh3d'),
require('./cone'),
require('./streamtube'),

require('./scattergeo'),
require('./choropleth'),
Expand Down
11 changes: 11 additions & 0 deletions lib/streamtube.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright 2012-2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = require('../src/traces/streamtube');
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"gl-select-box": "^1.0.2",
"gl-spikes2d": "^1.0.1",
"gl-surface3d": "^1.3.4",
"gl-streamtube3d": "[email protected]:gl-vis/gl-streamtube3d#ad17c0af85eda664297d881d5743ed19b7509dc0",
"glslify": "^6.1.1",
"has-hover": "^1.0.1",
"has-passive-events": "^1.0.0",
Expand Down
17 changes: 17 additions & 0 deletions src/lib/zip3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright 2012-2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = function zip3(x, y, z) {
var result = new Array(x.length);
for(var i = 0; i < x.length; i++) {
result[i] = [x[i], y[i], z[i]];
}
return result;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice to pull this into lib but are we moving away from the model of including all of these in lib/index and using them from there?

Copy link
Contributor Author

@etpinard etpinard Jun 5, 2018

Choose a reason for hiding this comment

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

I like to keep subplot-specific lib functions out of Lib (zip3 only makes sense for gl3d traces), but maybe it would less confusing to make src/lib/index.js collect everything in src/lib/. I don't have a strong opinion here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's true, it's nice not to be carrying code in every build if only one subplot type uses it... but then, if it's really only gl3d, does it belong in plots/gl3d/zip3.js? You nailed my concern anyway, that I don't want to have to wonder every time I use a lib function whether I need to pull it in directly or if I can just require lib/index and pull all the pieces I need out from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 5c2ddfc

32 changes: 23 additions & 9 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,27 @@ function render(scene) {

var tx;

if(trace.type === 'cone') {
var coneTx = [];
if(trace.type === 'cone' || trace.type === 'streamtube') {
var vectorTx = [];
if(isHoverinfoAll || hoverinfoParts.indexOf('u') !== -1) {
coneTx.push('u: ' + formatter('xaxis', selection.traceCoordinate[3]));
vectorTx.push('u: ' + formatter('xaxis', selection.traceCoordinate[3]));
}
if(isHoverinfoAll || hoverinfoParts.indexOf('v') !== -1) {
coneTx.push('v: ' + formatter('yaxis', selection.traceCoordinate[4]));
vectorTx.push('v: ' + formatter('yaxis', selection.traceCoordinate[4]));
}
if(isHoverinfoAll || hoverinfoParts.indexOf('w') !== -1) {
coneTx.push('w: ' + formatter('zaxis', selection.traceCoordinate[5]));
vectorTx.push('w: ' + formatter('zaxis', selection.traceCoordinate[5]));
}
if(isHoverinfoAll || hoverinfoParts.indexOf('norm') !== -1) {
coneTx.push('norm: ' + selection.traceCoordinate[6].toPrecision(3));
vectorTx.push('norm: ' + selection.traceCoordinate[6].toPrecision(3));
}
if(isHoverinfoAll || hoverinfoParts.indexOf('divergence') !== -1) {
vectorTx.push('divergence: ' + selection.traceCoordinate[7].toPrecision(3));
Copy link
Collaborator

Choose a reason for hiding this comment

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

cone with hoverinfo:'all'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 9a53250

}
if(selection.textLabel) {
coneTx.push(selection.textLabel);
vectorTx.push(selection.textLabel);
}
tx = coneTx.join('<br>');
tx = vectorTx.join('<br>');
} else {
tx = selection.textLabel;
}
Expand All @@ -130,6 +133,7 @@ function render(scene) {
});
}

// TODO not sure if streamtube x/y/z should be emitted as x/y/z
var pointData = {
x: selection.traceCoordinate[0],
y: selection.traceCoordinate[1],
Expand All @@ -140,6 +144,10 @@ function render(scene) {
pointNumber: ptNumber
};

if(trace._module.eventData) {
pointData = trace._module.eventData(pointData, selection, trace, {}, ptNumber);
}

Fx.appendArrayPointValue(pointData, trace, ptNumber);

var eventData = {points: [pointData]};
Expand Down Expand Up @@ -448,7 +456,13 @@ proto.plot = function(sceneData, fullLayout, layout) {
}
trace = this.traces[data.uid];
if(trace) {
trace.update(data);
if(trace.data.type === data.type) {
trace.update(data);
} else {
trace.dispose();
trace = data._module.plot(this, data);
this.traces[data.uid] = trace;
}
} else {
trace = data._module.plot(this, data);
this.traces[data.uid] = trace;
Expand Down
9 changes: 1 addition & 8 deletions src/traces/cone/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var createConeMesh = require('gl-cone3d').createConeMesh;

var simpleMap = require('../../lib').simpleMap;
var parseColorScale = require('../../lib/gl_format_color').parseColorScale;
var zip3 = require('../../lib/zip3');

function Cone(scene, uid) {
this.scene = scene;
Expand Down Expand Up @@ -52,14 +53,6 @@ proto.handlePick = function(selection) {
}
};

function zip3(x, y, z) {
var result = new Array(x.length);
for(var i = 0; i < x.length; i++) {
result[i] = [x[i], y[i], z[i]];
}
return result;
}

var axisName2scaleIndex = {xaxis: 0, yaxis: 1, zaxis: 2};
var sizeMode2sizeKey = {scaled: 'coneSize', absolute: 'absoluteConeSize'};
var anchor2coneOffset = {tip: 1, tail: 0, cm: 0.25, center: 0.5};
Expand Down
9 changes: 1 addition & 8 deletions src/traces/mesh3d/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var convexHull = require('convex-hull');

var parseColorScale = require('../../lib/gl_format_color').parseColorScale;
var str2RgbaArray = require('../../lib/str2rgbarray');
var zip3 = require('../../lib/zip3');

function Mesh3DTrace(scene, mesh, uid) {
this.scene = scene;
Expand Down Expand Up @@ -54,14 +55,6 @@ function parseColorArray(colors) {
return colors.map(str2RgbaArray);
}

function zip3(x, y, z) {
var result = new Array(x.length);
for(var i = 0; i < x.length; ++i) {
result[i] = [x[i], y[i], z[i]];
}
return result;
}

proto.update = function(data) {
var scene = this.scene,
layout = scene.fullSceneLayout;
Expand Down
151 changes: 151 additions & 0 deletions src/traces/streamtube/attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/**
* Copyright 2012-2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var colorAttrs = require('../../components/colorscale/color_attributes');
var colorscaleAttrs = require('../../components/colorscale/attributes');
var colorbarAttrs = require('../../components/colorbar/attributes');
var mesh3dAttrs = require('../mesh3d/attributes');
var baseAttrs = require('../../plots/attributes');

var extendFlat = require('../../lib/extend').extendFlat;

var attrs = {
x: {
valType: 'data_array',
role: 'info',
editType: 'calc+clearAxisTypes',
description: 'Sets the x coordinates of the vector field.'
},
y: {
valType: 'data_array',
role: 'info',
editType: 'calc+clearAxisTypes',
description: 'Sets the y coordinates of the vector field.'
},
z: {
valType: 'data_array',
role: 'info',
editType: 'calc+clearAxisTypes',
description: 'Sets the z coordinates of the vector field.'
},

u: {
valType: 'data_array',
editType: 'calc',
description: 'Sets the x components of the vector field.'
},
v: {
valType: 'data_array',
editType: 'calc',
description: 'Sets the y components of the vector field.'
},
w: {
valType: 'data_array',
editType: 'calc',
description: 'Sets the z components of the vector field.'
},

startx: {
valType: 'data_array',
editType: 'calc',
description: [
'Sets the x components of the starting position of the streamtubes',
].join(' ')
},
starty: {
valType: 'data_array',
editType: 'calc',
description: [
'Sets the y components of the starting position of the streamtubes',
].join(' ')
},
startz: {
valType: 'data_array',
editType: 'calc',
description: [
'Sets the z components of the starting position of the streamtubes',
].join(' ')
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

would this be better as starts: {x, y, z}? I can imagine later on when we figure out automatic starts wanting to tweak them with some other attributes that might be nice to collect all in a sub-container.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 22f0c7e


maxdisplayed: {
valType: 'integer',
min: 0,
dflt: 1000,
role: 'info',
editType: 'calc',
description: [
'The maximum number of displayed segments in a streamtube.'
].join(' ')
},

// TODO
//
// Should add 'absolute' (like cone traces have), but currently gl-streamtube3d's
// `absoluteTubeSize` doesn't behave well enough for our needs.
//
// 'fixed' would be a nice addition to plot stream 'lines', see
// https://github.com/plotly/plotly.js/commit/812be20750e21e0a1831975001c248d365850f73#r29129877
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the 📚 - you're collecting these for a "streamtubes open items" issue?

//
// sizemode: {
// valType: 'enumerated',
// values: ['scaled', 'absolute', 'fixed'],
// dflt: 'scaled',
// role: 'info',
// editType: 'calc',
// description: [
// 'Sets the mode by which the streamtubes are sized.'
// ].join(' ')
// },

sizeref: {
valType: 'number',
role: 'info',
editType: 'calc',
min: 0,
dflt: 1,
description: [
'The scaling factor for the streamtubes.',
'The default is 1, which avoids two max divergence tubes from touching',
'at adjacent starting positions.'
].join(' ')
},

text: {
valType: 'string',
role: 'info',
dflt: '',
editType: 'calc',
description: [
'Sets a text element associated with this trace.',
'If trace `hoverinfo` contains a *text* flag,',
'this text element will be seen in all hover labels.',
'Note that streamtube traces do not support array `text` values.'
].join(' ')
}
};

extendFlat(attrs, colorAttrs('', 'calc', true), {
showscale: colorscaleAttrs.showscale,
colorbar: colorbarAttrs
});
delete attrs.color;

var fromMesh3d = ['opacity', 'lightposition', 'lighting'];
fromMesh3d.forEach(function(k) {
attrs[k] = mesh3dAttrs[k];
});

attrs.hoverinfo = extendFlat({}, baseAttrs.hoverinfo, {
editType: 'calc',
flags: ['x', 'y', 'z', 'u', 'v', 'w', 'norm', 'divergence', 'text', 'name'],
dflt: 'x+y+z+norm+text+name'
});

module.exports = attrs;
Loading