-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
3D streamtube traces #2658
Changes from 28 commits
616d043
2435a96
355aed1
583499f
39c254e
38a1310
971351c
218dfc8
1367c07
8ea0c25
3b1f809
b0cd99d
e99ffc9
e0ff37f
fbd7980
f5c1160
b9a6e3f
80bcd84
273292d
5da1c59
8531e23
94f6195
c40dd6b
8182cab
62b90b5
dc0c5d7
bf12d10
df7ccaa
ca7c022
9a53250
22f0c7e
d796bda
2d1df2b
0093ac8
5c2ddfc
9fa5ece
d33fc45
9e3c533
83f3bdc
f348ac3
966bc8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
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; | ||
}; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
@@ -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], | ||
|
@@ -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]}; | ||
|
@@ -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; | ||
|
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(' ') | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would this be better as There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
There was a problem hiding this comment.
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 inlib/index
and using them from there?There was a problem hiding this comment.
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 makesrc/lib/index.js
collect everything insrc/lib/
. I don't have a strong opinion here.There was a problem hiding this comment.
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 inplots/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 requirelib/index
and pull all the pieces I need out from there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 5c2ddfc