Skip to content

Streamtubes [WIP] #701

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

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Core.register([
require('./pie'),
require('./contour'),
require('./scatter3d'),
require('./streamtube'),
require('./surface'),
require('./mesh3d'),
require('./scattergeo'),
Expand Down
9 changes: 9 additions & 0 deletions lib/streamtube.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright 2012-2016, 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.
*/

module.exports = require('../src/traces/streamtube');
2 changes: 1 addition & 1 deletion src/traces/mesh3d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Mesh3D.colorbar = require('../heatmap/colorbar');
Mesh3D.plot = require('./convert');

Mesh3D.moduleType = 'trace';
Mesh3D.name = 'mesh3d',
Mesh3D.name = 'mesh3d';
Copy link
Contributor

Choose a reason for hiding this comment

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

good 👀

Mesh3D.basePlotModule = require('../../plots/gl3d');
Mesh3D.categories = ['gl3d'];
Mesh3D.meta = {
Expand Down
33 changes: 33 additions & 0 deletions src/traces/scatter/basic_line_defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2012-2016, 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 hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleDefaults = require('../../components/colorscale/defaults');


// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
module.exports = function lineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {

var markerColor = (traceIn.marker || {}).color;

coerce('line.color', defaultColor);
if(hasColorscale(traceIn, 'line')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'}
);
} else {
coerce('line.color', (Array.isArray(markerColor) ? false : markerColor) ||
defaultColor);
}


coerce('line.width');
};
17 changes: 2 additions & 15 deletions src/traces/scatter/line_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,13 @@

'use strict';

var hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var basicLineDefaults = require('./basic_line_defaults');


// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
module.exports = function lineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {

var markerColor = (traceIn.marker || {}).color;
basicLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);

coerce('line.color', defaultColor);
if(hasColorscale(traceIn, 'line')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'}
);
} else {
coerce('line.color', (Array.isArray(markerColor) ? false : markerColor) ||
defaultColor);
}


coerce('line.width');
coerce('line.dash');
};
42 changes: 42 additions & 0 deletions src/traces/scatter/marker_basic_defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright 2012-2016, 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 hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleDefaults = require('../../components/colorscale/defaults');

var subTypes = require('./subtypes');


// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
var isBubble = subTypes.isBubble(traceIn),
lineColor = !Array.isArray(traceIn.line) ? (traceIn.line || {}).color : undefined;

if(lineColor) defaultColor = lineColor;

coerce('marker.opacity', isBubble ? 0.7 : 1);
coerce('marker.size');

coerce('marker.color', defaultColor);
if(hasColorscale(traceIn, 'marker')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
);
}

if(isBubble) {
coerce('marker.sizeref');
coerce('marker.sizemin');
coerce('marker.sizemode');
}

return lineColor;
};
26 changes: 7 additions & 19 deletions src/traces/scatter/marker_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,22 @@

'use strict';

var markerBasicDefaults = require('./marker_basic_defaults');
var Color = require('../../components/color');
var hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleDefaults = require('../../components/colorscale/defaults');

var subTypes = require('./subtypes');


// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
var isBubble = subTypes.isBubble(traceIn),
lineColor = !Array.isArray(traceIn.line) ? (traceIn.line || {}).color : undefined,
defaultMLC;

if(lineColor) defaultColor = lineColor;
var defaultMLC;

coerce('marker.symbol');
coerce('marker.opacity', isBubble ? 0.7 : 1);
coerce('marker.size');
var isBubble = subTypes.isBubble(traceIn);
var lineColor = markerBasicDefaults(traceIn, traceOut, defaultColor, layout, coerce);

coerce('marker.color', defaultColor);
if(hasColorscale(traceIn, 'marker')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
);
}
coerce('marker.symbol');

// if there's a line with a different color than the marker, use
// that line color as the default marker line color
Expand All @@ -45,6 +36,7 @@ module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout
else defaultMLC = Color.defaultLine;

coerce('marker.line.color', defaultMLC);

if(hasColorscale(traceIn, 'marker.line')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'}
Expand All @@ -53,9 +45,5 @@ module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout

coerce('marker.line.width', isBubble ? 1 : 0);

if(isBubble) {
coerce('marker.sizeref');
coerce('marker.sizemin');
coerce('marker.sizemode');
}

};
125 changes: 125 additions & 0 deletions src/traces/streamtube/attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* Copyright 2012-2016, 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 scatterAttrs = require('../scatter/attributes');
var colorAttributes = require('../../components/colorscale/color_attributes');

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

var scatterLineAttrs = scatterAttrs.line,
scatterMarkerAttrs = scatterAttrs.marker;

function makeProjectionAttr(axLetter) {
return {
show: {
valType: 'boolean',
role: 'info',
dflt: false,
description: [
'Sets whether or not projections are shown along the',
axLetter, 'axis.'
].join(' ')
},
opacity: {
valType: 'number',
role: 'style',
min: 0,
max: 1,
dflt: 1,
description: 'Sets the projection color.'
},
scale: {
valType: 'number',
role: 'style',
min: 0,
max: 10,
dflt: 2 / 3,
description: [
'Sets the scale factor determining the size of the',
'projection marker points.'
].join(' ')
}
};
}

module.exports = {
x: {
valType: 'data_array',
description: 'Sets the x coordinates.'
},
y: {
valType: 'data_array',
description: 'Sets the y coordinates.'
},
z: {
valType: 'data_array',
description: 'Sets the z coordinates.'
},
text: extendFlat({}, scatterAttrs.text, {
description: [
'Sets text elements associated with each (x,y,z) triplet.',
'If a single string, the same string appears over',
'all the data points.',
'If an array of string, the items are mapped in order to the',
'this trace\'s (x,y,z) coordinates.'
].join(' ')
}),
mode: extendFlat({}, scatterAttrs.mode, // shouldn't this be on-par with 2D?
{dflt: 'lines+markers'}),
projection: {
x: makeProjectionAttr('x'),
y: makeProjectionAttr('y'),
z: makeProjectionAttr('z')
},
connectgaps: scatterAttrs.connectgaps,
line: extendFlat({}, {
width: scatterLineAttrs.width,
connectionradius: extendFlat({}, scatterMarkerAttrs.size, {
dflt: 1,
description: 'Sets the radius of the line connection. Either a number, or an array with as many elements as the number of points.'
Copy link
Contributor

Choose a reason for hiding this comment

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

@monfera what are the units here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etpinard it should be in terms of the data domain, e.g. in a 100 x 100 x 100 cube a radius of 1 should mean 1/100th of the box edge

Copy link
Contributor

Choose a reason for hiding this comment

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

Great. This is perfectly reasonable mode (how should we call it? 'axis' maybe?) In future development we could add other modes e.g. 'constant' (which would make the streamtubes appear cylindrical regardless of the scene aspectratio) and 'data' (which would correspond to a data array).

By the way, @monfera would you be ok with renaming connectionradius -> size or just radius ?

Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify the current behaviour:

Starting from:

image

then Plotly.relayout(gd, 'scene.zaxis.range', [-10, 10]); yields:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. In this case, the light reflection can be more of a distraction than a positive. So with this type of use, it's good to avoid using a specular light component.

}),
showscale: {
valType: 'boolean',
role: 'info',
dflt: false,
description: [
'Has an effect only if `line.color` is set to a numerical array.',
'Determines whether or not a colorbar is displayed.'
].join(' ')
}
},
colorAttributes('line')
),
marker: extendFlat({}, {
size: extendFlat({}, scatterMarkerAttrs.size, {dflt: 8}),
sizeref: scatterMarkerAttrs.sizeref,
sizemin: scatterMarkerAttrs.sizemin,
sizemode: scatterMarkerAttrs.sizemode,
opacity: extendFlat({}, scatterMarkerAttrs.opacity, {
arrayOk: false,
description: [
'Sets the marker opacity.',
'Note that the marker opacity for scatter3d traces',
'must be a scalar value for performance reasons.',
'To set a blending opacity value',
'(i.e. which is not transparent), set *marker.color*',
'to an rgba color and use its alpha channel.'
].join(' ')
}),
showscale: scatterMarkerAttrs.showscale
},
colorAttributes('marker')
),
textposition: extendFlat({}, scatterAttrs.textposition, {dflt: 'top center'}),
textfont: scatterAttrs.textfont,
_nestedModules: {
'marker.colorbar': 'Colorbar'
}
};
27 changes: 27 additions & 0 deletions src/traces/streamtube/calc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2012-2016, 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 arraysToCalcdata = require('../scatter/arrays_to_calcdata');
var calcColorscales = require('../scatter/colorscale_calc');


/**
* This is a kludge to put the array attributes into
* calcdata the way Scatter.plot does, so that legends and
* popovers know what to do with them.
*/
module.exports = function calc(gd, trace) {
var cd = [{x: false, y: false, trace: trace, t: {}}];

arraysToCalcdata(cd);
calcColorscales(trace);

return cd;
};
Loading